repo_name
string
path
string
copies
string
size
string
content
string
license
string
iamjy/beaglebone-kernel
drivers/mfd/sec-core.c
189
4977
/* * sec-core.c * * Copyright (c) 2012 Samsung Electronics Co., Ltd * http://www.samsung.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/module.h> #include <linux/moduleparam.h> #include <linux/init.h> #include <linux/err.h> #include <linux/slab.h> #include <linux/i2c.h> #include <linux/interrupt.h> #include <linux/pm_runtime.h> #include <linux/mutex.h> #include <linux/mfd/core.h> #include <linux/mfd/samsung/core.h> #include <linux/mfd/samsung/irq.h> #include <linux/mfd/samsung/rtc.h> #include <linux/regmap.h> static struct mfd_cell s5m8751_devs[] = { { .name = "s5m8751-pmic", }, { .name = "s5m-charger", }, { .name = "s5m8751-codec", }, }; static struct mfd_cell s5m8763_devs[] = { { .name = "s5m8763-pmic", }, { .name = "s5m-rtc", }, { .name = "s5m-charger", }, }; static struct mfd_cell s5m8767_devs[] = { { .name = "s5m8767-pmic", }, { .name = "s5m-rtc", }, }; static struct mfd_cell s2mps11_devs[] = { { .name = "s2mps11-pmic", }, }; int sec_reg_read(struct sec_pmic_dev *sec_pmic, u8 reg, void *dest) { return regmap_read(sec_pmic->regmap, reg, dest); } EXPORT_SYMBOL_GPL(sec_reg_read); int sec_bulk_read(struct sec_pmic_dev *sec_pmic, u8 reg, int count, u8 *buf) { return regmap_bulk_read(sec_pmic->regmap, reg, buf, count); } EXPORT_SYMBOL_GPL(sec_bulk_read); int sec_reg_write(struct sec_pmic_dev *sec_pmic, u8 reg, u8 value) { return regmap_write(sec_pmic->regmap, reg, value); } EXPORT_SYMBOL_GPL(sec_reg_write); int sec_bulk_write(struct sec_pmic_dev *sec_pmic, u8 reg, int count, u8 *buf) { return regmap_raw_write(sec_pmic->regmap, reg, buf, count); } EXPORT_SYMBOL_GPL(sec_bulk_write); int sec_reg_update(struct sec_pmic_dev *sec_pmic, u8 reg, u8 val, u8 mask) { return regmap_update_bits(sec_pmic->regmap, reg, mask, val); } EXPORT_SYMBOL_GPL(sec_reg_update); static struct regmap_config sec_regmap_config = { .reg_bits = 8, .val_bits = 8, }; static int sec_pmic_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct sec_platform_data *pdata = i2c->dev.platform_data; struct sec_pmic_dev *sec_pmic; int ret; sec_pmic = devm_kzalloc(&i2c->dev, sizeof(struct sec_pmic_dev), GFP_KERNEL); if (sec_pmic == NULL) return -ENOMEM; i2c_set_clientdata(i2c, sec_pmic); sec_pmic->dev = &i2c->dev; sec_pmic->i2c = i2c; sec_pmic->irq = i2c->irq; sec_pmic->type = id->driver_data; if (pdata) { sec_pmic->device_type = pdata->device_type; sec_pmic->ono = pdata->ono; sec_pmic->irq_base = pdata->irq_base; sec_pmic->wakeup = pdata->wakeup; } sec_pmic->regmap = devm_regmap_init_i2c(i2c, &sec_regmap_config); if (IS_ERR(sec_pmic->regmap)) { ret = PTR_ERR(sec_pmic->regmap); dev_err(&i2c->dev, "Failed to allocate register map: %d\n", ret); return ret; } sec_pmic->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR); i2c_set_clientdata(sec_pmic->rtc, sec_pmic); if (pdata && pdata->cfg_pmic_irq) pdata->cfg_pmic_irq(); sec_irq_init(sec_pmic); pm_runtime_set_active(sec_pmic->dev); switch (sec_pmic->device_type) { case S5M8751X: ret = mfd_add_devices(sec_pmic->dev, -1, s5m8751_devs, ARRAY_SIZE(s5m8751_devs), NULL, 0, NULL); break; case S5M8763X: ret = mfd_add_devices(sec_pmic->dev, -1, s5m8763_devs, ARRAY_SIZE(s5m8763_devs), NULL, 0, NULL); break; case S5M8767X: ret = mfd_add_devices(sec_pmic->dev, -1, s5m8767_devs, ARRAY_SIZE(s5m8767_devs), NULL, 0, NULL); break; case S2MPS11X: ret = mfd_add_devices(sec_pmic->dev, -1, s2mps11_devs, ARRAY_SIZE(s2mps11_devs), NULL, 0, NULL); break; default: /* If this happens the probe function is problem */ BUG(); } if (ret < 0) goto err; return ret; err: mfd_remove_devices(sec_pmic->dev); sec_irq_exit(sec_pmic); i2c_unregister_device(sec_pmic->rtc); return ret; } static int sec_pmic_remove(struct i2c_client *i2c) { struct sec_pmic_dev *sec_pmic = i2c_get_clientdata(i2c); mfd_remove_devices(sec_pmic->dev); sec_irq_exit(sec_pmic); i2c_unregister_device(sec_pmic->rtc); return 0; } static const struct i2c_device_id sec_pmic_id[] = { { "sec_pmic", 0 }, { } }; MODULE_DEVICE_TABLE(i2c, sec_pmic_id); static struct i2c_driver sec_pmic_driver = { .driver = { .name = "sec_pmic", .owner = THIS_MODULE, }, .probe = sec_pmic_probe, .remove = sec_pmic_remove, .id_table = sec_pmic_id, }; static int __init sec_pmic_init(void) { return i2c_add_driver(&sec_pmic_driver); } subsys_initcall(sec_pmic_init); static void __exit sec_pmic_exit(void) { i2c_del_driver(&sec_pmic_driver); } module_exit(sec_pmic_exit); MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); MODULE_DESCRIPTION("Core support for the S5M MFD"); MODULE_LICENSE("GPL");
gpl-2.0
venkatarajasekhar/kernel_raybst
drivers/iommu/msm_iommu_dev.c
445
9388
/* Copyright (c) 2010-2012, 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. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/kernel.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/io.h> #include <linux/clk.h> #include <linux/iommu.h> #include <linux/interrupt.h> #include <linux/err.h> #include <linux/slab.h> #include <mach/iommu_hw-8xxx.h> #include <mach/iommu.h> struct iommu_ctx_iter_data { /* input */ const char *name; /* output */ struct device *dev; }; struct platform_device *msm_iommu_root_dev; static int each_iommu_ctx(struct device *dev, void *data) { struct iommu_ctx_iter_data *res = data; struct msm_iommu_ctx_drvdata *c; c = dev_get_drvdata(dev); if (!res || !c || !c->name || !res->name) return -EINVAL; if (!strcmp(res->name, c->name)) { res->dev = dev; return 1; } return 0; } static int each_iommu(struct device *dev, void *data) { return device_for_each_child(dev, data, each_iommu_ctx); } struct device *msm_iommu_get_ctx(const char *ctx_name) { struct iommu_ctx_iter_data r; int found; if (!msm_iommu_root_dev) { pr_err("No root IOMMU device.\n"); goto fail; } r.name = ctx_name; found = device_for_each_child(&msm_iommu_root_dev->dev, &r, each_iommu); if (found <= 0 || !dev_get_drvdata(r.dev)) { pr_err("Could not find context <%s>\n", ctx_name); goto fail; } return r.dev; fail: return NULL; } EXPORT_SYMBOL(msm_iommu_get_ctx); static void msm_iommu_reset(void __iomem *base, int ncb) { int ctx; SET_RPUE(base, 0); SET_RPUEIE(base, 0); SET_ESRRESTORE(base, 0); SET_TBE(base, 0); SET_CR(base, 0); SET_SPDMBE(base, 0); SET_TESTBUSCR(base, 0); SET_TLBRSW(base, 0); SET_GLOBAL_TLBIALL(base, 0); SET_RPU_ACR(base, 0); SET_TLBLKCRWE(base, 1); for (ctx = 0; ctx < ncb; ctx++) { SET_BPRCOSH(base, ctx, 0); SET_BPRCISH(base, ctx, 0); SET_BPRCNSH(base, ctx, 0); SET_BPSHCFG(base, ctx, 0); SET_BPMTCFG(base, ctx, 0); SET_ACTLR(base, ctx, 0); SET_SCTLR(base, ctx, 0); SET_FSRRESTORE(base, ctx, 0); SET_TTBR0(base, ctx, 0); SET_TTBR1(base, ctx, 0); SET_TTBCR(base, ctx, 0); SET_BFBCR(base, ctx, 0); SET_PAR(base, ctx, 0); SET_FAR(base, ctx, 0); SET_TLBFLPTER(base, ctx, 0); SET_TLBSLPTER(base, ctx, 0); SET_TLBLKCR(base, ctx, 0); SET_CTX_TLBIALL(base, ctx, 0); SET_TLBIVA(base, ctx, 0); SET_PRRR(base, ctx, 0); SET_NMRR(base, ctx, 0); SET_CONTEXTIDR(base, ctx, 0); } mb(); } static int msm_iommu_probe(struct platform_device *pdev) { struct resource *r, *r2; struct clk *iommu_clk = NULL; struct clk *iommu_pclk = NULL; struct msm_iommu_drvdata *drvdata; struct msm_iommu_dev *iommu_dev = pdev->dev.platform_data; void __iomem *regs_base; resource_size_t len; int ret, par; if (pdev->id == -1) { msm_iommu_root_dev = pdev; return 0; } drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); if (!drvdata) { ret = -ENOMEM; goto fail; } if (!iommu_dev) { ret = -ENODEV; goto fail; } iommu_pclk = clk_get_sys("msm_iommu", "iface_clk"); if (IS_ERR(iommu_pclk)) { ret = -ENODEV; goto fail; } ret = clk_prepare_enable(iommu_pclk); if (ret) goto fail_enable; iommu_clk = clk_get(&pdev->dev, "core_clk"); if (!IS_ERR(iommu_clk)) { if (clk_get_rate(iommu_clk) == 0) { ret = clk_round_rate(iommu_clk, 1); clk_set_rate(iommu_clk, ret); } ret = clk_prepare_enable(iommu_clk); if (ret) { clk_put(iommu_clk); goto fail_pclk; } } else iommu_clk = NULL; r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "physbase"); if (!r) { ret = -ENODEV; goto fail_clk; } len = resource_size(r); r2 = request_mem_region(r->start, len, r->name); if (!r2) { pr_err("Could not request memory region: start=%p, len=%d\n", (void *) r->start, len); ret = -EBUSY; goto fail_clk; } regs_base = ioremap(r2->start, len); if (!regs_base) { pr_err("Could not ioremap: start=%p, len=%d\n", (void *) r2->start, len); ret = -EBUSY; goto fail_mem; } msm_iommu_reset(regs_base, iommu_dev->ncb); SET_M(regs_base, 0, 1); SET_PAR(regs_base, 0, 0); SET_V2PCFG(regs_base, 0, 1); SET_V2PPR(regs_base, 0, 0); mb(); par = GET_PAR(regs_base, 0); SET_V2PCFG(regs_base, 0, 0); SET_M(regs_base, 0, 0); mb(); if (!par) { pr_err("%s: Invalid PAR value detected\n", iommu_dev->name); ret = -ENODEV; goto fail_io; } drvdata->pclk = iommu_pclk; drvdata->clk = iommu_clk; drvdata->base = regs_base; drvdata->ncb = iommu_dev->ncb; drvdata->ttbr_split = iommu_dev->ttbr_split; drvdata->name = iommu_dev->name; pr_info("device %s mapped at %p, with %d ctx banks\n", iommu_dev->name, regs_base, iommu_dev->ncb); platform_set_drvdata(pdev, drvdata); if (iommu_clk) clk_disable_unprepare(iommu_clk); clk_disable_unprepare(iommu_pclk); return 0; fail_io: iounmap(regs_base); fail_mem: release_mem_region(r->start, len); fail_clk: if (iommu_clk) { clk_disable_unprepare(iommu_clk); clk_put(iommu_clk); } fail_pclk: clk_disable_unprepare(iommu_pclk); fail_enable: clk_put(iommu_pclk); fail: kfree(drvdata); return ret; } static int msm_iommu_remove(struct platform_device *pdev) { struct msm_iommu_drvdata *drv = NULL; drv = platform_get_drvdata(pdev); if (drv) { if (drv->clk) clk_put(drv->clk); clk_put(drv->pclk); memset(drv, 0, sizeof(*drv)); kfree(drv); platform_set_drvdata(pdev, NULL); } return 0; } static int msm_iommu_ctx_probe(struct platform_device *pdev) { struct msm_iommu_ctx_dev *c = pdev->dev.platform_data; struct msm_iommu_drvdata *drvdata; struct msm_iommu_ctx_drvdata *ctx_drvdata = NULL; int i, ret, irq; if (!c || !pdev->dev.parent) { ret = -EINVAL; goto fail; } drvdata = dev_get_drvdata(pdev->dev.parent); if (!drvdata) { ret = -ENODEV; goto fail; } ctx_drvdata = kzalloc(sizeof(*ctx_drvdata), GFP_KERNEL); if (!ctx_drvdata) { ret = -ENOMEM; goto fail; } ctx_drvdata->num = c->num; ctx_drvdata->pdev = pdev; ctx_drvdata->name = c->name; irq = platform_get_irq_byname(to_platform_device(pdev->dev.parent), "nonsecure_irq"); if (irq < 0) { ret = -ENODEV; goto fail; } ret = request_threaded_irq(irq, NULL, msm_iommu_fault_handler, IRQF_ONESHOT | IRQF_SHARED, "msm_iommu_nonsecure_irq", ctx_drvdata); if (ret) { pr_err("request_threaded_irq %d failed: %d\n", irq, ret); goto fail; } INIT_LIST_HEAD(&ctx_drvdata->attached_elm); platform_set_drvdata(pdev, ctx_drvdata); ret = clk_prepare_enable(drvdata->pclk); if (ret) goto fail; if (drvdata->clk) { ret = clk_prepare_enable(drvdata->clk); if (ret) { clk_disable_unprepare(drvdata->pclk); goto fail; } } /* Program the M2V tables for this context */ for (i = 0; i < MAX_NUM_MIDS; i++) { int mid = c->mids[i]; if (mid == -1) break; SET_M2VCBR_N(drvdata->base, mid, 0); SET_CBACR_N(drvdata->base, c->num, 0); /* Route page faults to the non-secure interrupt */ SET_IRPTNDX(drvdata->base, c->num, 1); /* Set VMID = 0 */ SET_VMID(drvdata->base, mid, 0); /* Set the context number for that MID to this context */ SET_CBNDX(drvdata->base, mid, c->num); /* Set MID associated with this context bank to 0 */ SET_CBVMID(drvdata->base, c->num, 0); /* Set the ASID for TLB tagging for this context to 0 */ SET_CONTEXTIDR_ASID(drvdata->base, c->num, 0); /* Set security bit override to be Non-secure */ SET_NSCFG(drvdata->base, mid, 3); } mb(); if (drvdata->clk) clk_disable_unprepare(drvdata->clk); clk_disable_unprepare(drvdata->pclk); dev_info(&pdev->dev, "context %s using bank %d\n", c->name, c->num); return 0; fail: kfree(ctx_drvdata); return ret; } static int msm_iommu_ctx_remove(struct platform_device *pdev) { struct msm_iommu_ctx_drvdata *drv = NULL; drv = platform_get_drvdata(pdev); if (drv) { memset(drv, 0, sizeof(struct msm_iommu_ctx_drvdata)); kfree(drv); platform_set_drvdata(pdev, NULL); } return 0; } static struct platform_driver msm_iommu_driver = { .driver = { .name = "msm_iommu", }, .probe = msm_iommu_probe, .remove = msm_iommu_remove, }; static struct platform_driver msm_iommu_ctx_driver = { .driver = { .name = "msm_iommu_ctx", }, .probe = msm_iommu_ctx_probe, .remove = msm_iommu_ctx_remove, }; static int __init msm_iommu_driver_init(void) { int ret; ret = platform_driver_register(&msm_iommu_driver); if (ret != 0) { pr_err("Failed to register IOMMU driver\n"); goto error; } ret = platform_driver_register(&msm_iommu_ctx_driver); if (ret != 0) { pr_err("Failed to register IOMMU context driver\n"); goto error; } error: return ret; } static void __exit msm_iommu_driver_exit(void) { platform_driver_unregister(&msm_iommu_ctx_driver); platform_driver_unregister(&msm_iommu_driver); } subsys_initcall(msm_iommu_driver_init); module_exit(msm_iommu_driver_exit); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Stepan Moskovchenko <stepanm@codeaurora.org>");
gpl-2.0
onyx-intl/ak98_kernel
drivers/infiniband/hw/ipath/ipath_sd7220.c
701
41900
/* * Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved. * Copyright (c) 2003, 2004, 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. */ /* * This file contains all of the code that is specific to the SerDes * on the InfiniPath 7220 chip. */ #include <linux/pci.h> #include <linux/delay.h> #include "ipath_kernel.h" #include "ipath_registers.h" #include "ipath_7220.h" /* * The IBSerDesMappTable is a memory that holds values to be stored in * various SerDes registers by IBC. It is not part of the normal kregs * map and is used in exactly one place, hence the #define below. */ #define KR_IBSerDesMappTable (0x94000 / (sizeof(uint64_t))) /* * Below used for sdnum parameter, selecting one of the two sections * used for PCIe, or the single SerDes used for IB. */ #define PCIE_SERDES0 0 #define PCIE_SERDES1 1 /* * The EPB requires addressing in a particular form. EPB_LOC() is intended * to make #definitions a little more readable. */ #define EPB_ADDR_SHF 8 #define EPB_LOC(chn, elt, reg) \ (((elt & 0xf) | ((chn & 7) << 4) | ((reg & 0x3f) << 9)) << \ EPB_ADDR_SHF) #define EPB_IB_QUAD0_CS_SHF (25) #define EPB_IB_QUAD0_CS (1U << EPB_IB_QUAD0_CS_SHF) #define EPB_IB_UC_CS_SHF (26) #define EPB_PCIE_UC_CS_SHF (27) #define EPB_GLOBAL_WR (1U << (EPB_ADDR_SHF + 8)) /* Forward declarations. */ static int ipath_sd7220_reg_mod(struct ipath_devdata *dd, int sdnum, u32 loc, u32 data, u32 mask); static int ibsd_mod_allchnls(struct ipath_devdata *dd, int loc, int val, int mask); static int ipath_sd_trimdone_poll(struct ipath_devdata *dd); static void ipath_sd_trimdone_monitor(struct ipath_devdata *dd, const char *where); static int ipath_sd_setvals(struct ipath_devdata *dd); static int ipath_sd_early(struct ipath_devdata *dd); static int ipath_sd_dactrim(struct ipath_devdata *dd); /* Set the registers that IBC may muck with to their default "preset" values */ int ipath_sd7220_presets(struct ipath_devdata *dd); static int ipath_internal_presets(struct ipath_devdata *dd); /* Tweak the register (CMUCTRL5) that contains the TRIMSELF controls */ static int ipath_sd_trimself(struct ipath_devdata *dd, int val); static int epb_access(struct ipath_devdata *dd, int sdnum, int claim); void ipath_set_relock_poll(struct ipath_devdata *dd, int ibup); /* * Below keeps track of whether the "once per power-on" initialization has * been done, because uC code Version 1.32.17 or higher allows the uC to * be reset at will, and Automatic Equalization may require it. So the * state of the reset "pin", as reflected in was_reset parameter to * ipath_sd7220_init() is no longer valid. Instead, we check for the * actual uC code having been loaded. */ static int ipath_ibsd_ucode_loaded(struct ipath_devdata *dd) { if (!dd->serdes_first_init_done && (ipath_sd7220_ib_vfy(dd) > 0)) dd->serdes_first_init_done = 1; return dd->serdes_first_init_done; } /* repeat #define for local use. "Real" #define is in ipath_iba7220.c */ #define INFINIPATH_HWE_IB_UC_MEMORYPARITYERR 0x0000004000000000ULL #define IB_MPREG5 (EPB_LOC(6, 0, 0xE) | (1L << EPB_IB_UC_CS_SHF)) #define IB_MPREG6 (EPB_LOC(6, 0, 0xF) | (1U << EPB_IB_UC_CS_SHF)) #define UC_PAR_CLR_D 8 #define UC_PAR_CLR_M 0xC #define IB_CTRL2(chn) (EPB_LOC(chn, 7, 3) | EPB_IB_QUAD0_CS) #define START_EQ1(chan) EPB_LOC(chan, 7, 0x27) void ipath_sd7220_clr_ibpar(struct ipath_devdata *dd) { int ret; /* clear, then re-enable parity errs */ ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, IB_MPREG6, UC_PAR_CLR_D, UC_PAR_CLR_M); if (ret < 0) { ipath_dev_err(dd, "Failed clearing IBSerDes Parity err\n"); goto bail; } ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, IB_MPREG6, 0, UC_PAR_CLR_M); ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch); udelay(4); ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear, INFINIPATH_HWE_IB_UC_MEMORYPARITYERR); ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch); bail: return; } /* * After a reset or other unusual event, the epb interface may need * to be re-synchronized, between the host and the uC. * returns <0 for failure to resync within IBSD_RESYNC_TRIES (not expected) */ #define IBSD_RESYNC_TRIES 3 #define IB_PGUDP(chn) (EPB_LOC((chn), 2, 1) | EPB_IB_QUAD0_CS) #define IB_CMUDONE(chn) (EPB_LOC((chn), 7, 0xF) | EPB_IB_QUAD0_CS) static int ipath_resync_ibepb(struct ipath_devdata *dd) { int ret, pat, tries, chn; u32 loc; ret = -1; chn = 0; for (tries = 0; tries < (4 * IBSD_RESYNC_TRIES); ++tries) { loc = IB_PGUDP(chn); ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, loc, 0, 0); if (ret < 0) { ipath_dev_err(dd, "Failed read in resync\n"); continue; } if (ret != 0xF0 && ret != 0x55 && tries == 0) ipath_dev_err(dd, "unexpected pattern in resync\n"); pat = ret ^ 0xA5; /* alternate F0 and 55 */ ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, loc, pat, 0xFF); if (ret < 0) { ipath_dev_err(dd, "Failed write in resync\n"); continue; } ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, loc, 0, 0); if (ret < 0) { ipath_dev_err(dd, "Failed re-read in resync\n"); continue; } if (ret != pat) { ipath_dev_err(dd, "Failed compare1 in resync\n"); continue; } loc = IB_CMUDONE(chn); ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, loc, 0, 0); if (ret < 0) { ipath_dev_err(dd, "Failed CMUDONE rd in resync\n"); continue; } if ((ret & 0x70) != ((chn << 4) | 0x40)) { ipath_dev_err(dd, "Bad CMUDONE value %02X, chn %d\n", ret, chn); continue; } if (++chn == 4) break; /* Success */ } ipath_cdbg(VERBOSE, "Resync in %d tries\n", tries); return (ret > 0) ? 0 : ret; } /* * Localize the stuff that should be done to change IB uC reset * returns <0 for errors. */ static int ipath_ibsd_reset(struct ipath_devdata *dd, int assert_rst) { u64 rst_val; int ret = 0; unsigned long flags; rst_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibserdesctrl); if (assert_rst) { /* * Vendor recommends "interrupting" uC before reset, to * minimize possible glitches. */ spin_lock_irqsave(&dd->ipath_sdepb_lock, flags); epb_access(dd, IB_7220_SERDES, 1); rst_val |= 1ULL; /* Squelch possible parity error from _asserting_ reset */ ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask, dd->ipath_hwerrmask & ~INFINIPATH_HWE_IB_UC_MEMORYPARITYERR); ipath_write_kreg(dd, dd->ipath_kregs->kr_ibserdesctrl, rst_val); /* flush write, delay to ensure it took effect */ ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch); udelay(2); /* once it's reset, can remove interrupt */ epb_access(dd, IB_7220_SERDES, -1); spin_unlock_irqrestore(&dd->ipath_sdepb_lock, flags); } else { /* * Before we de-assert reset, we need to deal with * possible glitch on the Parity-error line. * Suppress it around the reset, both in chip-level * hwerrmask and in IB uC control reg. uC will allow * it again during startup. */ u64 val; rst_val &= ~(1ULL); ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask, dd->ipath_hwerrmask & ~INFINIPATH_HWE_IB_UC_MEMORYPARITYERR); ret = ipath_resync_ibepb(dd); if (ret < 0) ipath_dev_err(dd, "unable to re-sync IB EPB\n"); /* set uC control regs to suppress parity errs */ ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, IB_MPREG5, 1, 1); if (ret < 0) goto bail; /* IB uC code past Version 1.32.17 allow suppression of wdog */ ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, IB_MPREG6, 0x80, 0x80); if (ret < 0) { ipath_dev_err(dd, "Failed to set WDOG disable\n"); goto bail; } ipath_write_kreg(dd, dd->ipath_kregs->kr_ibserdesctrl, rst_val); /* flush write, delay for startup */ ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch); udelay(1); /* clear, then re-enable parity errs */ ipath_sd7220_clr_ibpar(dd); val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus); if (val & INFINIPATH_HWE_IB_UC_MEMORYPARITYERR) { ipath_dev_err(dd, "IBUC Parity still set after RST\n"); dd->ipath_hwerrmask &= ~INFINIPATH_HWE_IB_UC_MEMORYPARITYERR; } ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask, dd->ipath_hwerrmask); } bail: return ret; } static void ipath_sd_trimdone_monitor(struct ipath_devdata *dd, const char *where) { int ret, chn, baduns; u64 val; if (!where) where = "?"; /* give time for reset to settle out in EPB */ udelay(2); ret = ipath_resync_ibepb(dd); if (ret < 0) ipath_dev_err(dd, "not able to re-sync IB EPB (%s)\n", where); /* Do "sacrificial read" to get EPB in sane state after reset */ ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, IB_CTRL2(0), 0, 0); if (ret < 0) ipath_dev_err(dd, "Failed TRIMDONE 1st read, (%s)\n", where); /* Check/show "summary" Trim-done bit in IBCStatus */ val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus); if (val & (1ULL << 11)) ipath_cdbg(VERBOSE, "IBCS TRIMDONE set (%s)\n", where); else ipath_dev_err(dd, "IBCS TRIMDONE clear (%s)\n", where); udelay(2); ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, IB_MPREG6, 0x80, 0x80); if (ret < 0) ipath_dev_err(dd, "Failed Dummy RMW, (%s)\n", where); udelay(10); baduns = 0; for (chn = 3; chn >= 0; --chn) { /* Read CTRL reg for each channel to check TRIMDONE */ ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, IB_CTRL2(chn), 0, 0); if (ret < 0) ipath_dev_err(dd, "Failed checking TRIMDONE, chn %d" " (%s)\n", chn, where); if (!(ret & 0x10)) { int probe; baduns |= (1 << chn); ipath_dev_err(dd, "TRIMDONE cleared on chn %d (%02X)." " (%s)\n", chn, ret, where); probe = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, IB_PGUDP(0), 0, 0); ipath_dev_err(dd, "probe is %d (%02X)\n", probe, probe); probe = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, IB_CTRL2(chn), 0, 0); ipath_dev_err(dd, "re-read: %d (%02X)\n", probe, probe); ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, IB_CTRL2(chn), 0x10, 0x10); if (ret < 0) ipath_dev_err(dd, "Err on TRIMDONE rewrite1\n"); } } for (chn = 3; chn >= 0; --chn) { /* Read CTRL reg for each channel to check TRIMDONE */ if (baduns & (1 << chn)) { ipath_dev_err(dd, "Reseting TRIMDONE on chn %d (%s)\n", chn, where); ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, IB_CTRL2(chn), 0x10, 0x10); if (ret < 0) ipath_dev_err(dd, "Failed re-setting " "TRIMDONE, chn %d (%s)\n", chn, where); } } } /* * Below is portion of IBA7220-specific bringup_serdes() that actually * deals with registers and memory within the SerDes itself. * Post IB uC code version 1.32.17, was_reset being 1 is not really * informative, so we double-check. */ int ipath_sd7220_init(struct ipath_devdata *dd, int was_reset) { int ret = 1; /* default to failure */ int first_reset; int val_stat; if (!was_reset) { /* entered with reset not asserted, we need to do it */ ipath_ibsd_reset(dd, 1); ipath_sd_trimdone_monitor(dd, "Driver-reload"); } /* Substitute our deduced value for was_reset */ ret = ipath_ibsd_ucode_loaded(dd); if (ret < 0) { ret = 1; goto done; } first_reset = !ret; /* First reset if IBSD uCode not yet loaded */ /* * Alter some regs per vendor latest doc, reset-defaults * are not right for IB. */ ret = ipath_sd_early(dd); if (ret < 0) { ipath_dev_err(dd, "Failed to set IB SERDES early defaults\n"); ret = 1; goto done; } /* * Set DAC manual trim IB. * We only do this once after chip has been reset (usually * same as once per system boot). */ if (first_reset) { ret = ipath_sd_dactrim(dd); if (ret < 0) { ipath_dev_err(dd, "Failed IB SERDES DAC trim\n"); ret = 1; goto done; } } /* * Set various registers (DDS and RXEQ) that will be * controlled by IBC (in 1.2 mode) to reasonable preset values * Calling the "internal" version avoids the "check for needed" * and "trimdone monitor" that might be counter-productive. */ ret = ipath_internal_presets(dd); if (ret < 0) { ipath_dev_err(dd, "Failed to set IB SERDES presets\n"); ret = 1; goto done; } ret = ipath_sd_trimself(dd, 0x80); if (ret < 0) { ipath_dev_err(dd, "Failed to set IB SERDES TRIMSELF\n"); ret = 1; goto done; } /* Load image, then try to verify */ ret = 0; /* Assume success */ if (first_reset) { int vfy; int trim_done; ipath_dbg("SerDes uC was reset, reloading PRAM\n"); ret = ipath_sd7220_ib_load(dd); if (ret < 0) { ipath_dev_err(dd, "Failed to load IB SERDES image\n"); ret = 1; goto done; } /* Loaded image, try to verify */ vfy = ipath_sd7220_ib_vfy(dd); if (vfy != ret) { ipath_dev_err(dd, "SERDES PRAM VFY failed\n"); ret = 1; goto done; } /* * Loaded and verified. Almost good... * hold "success" in ret */ ret = 0; /* * Prev steps all worked, continue bringup * De-assert RESET to uC, only in first reset, to allow * trimming. * * Since our default setup sets START_EQ1 to * PRESET, we need to clear that for this very first run. */ ret = ibsd_mod_allchnls(dd, START_EQ1(0), 0, 0x38); if (ret < 0) { ipath_dev_err(dd, "Failed clearing START_EQ1\n"); ret = 1; goto done; } ipath_ibsd_reset(dd, 0); /* * If this is not the first reset, trimdone should be set * already. */ trim_done = ipath_sd_trimdone_poll(dd); /* * Whether or not trimdone succeeded, we need to put the * uC back into reset to avoid a possible fight with the * IBC state-machine. */ ipath_ibsd_reset(dd, 1); if (!trim_done) { ipath_dev_err(dd, "No TRIMDONE seen\n"); ret = 1; goto done; } ipath_sd_trimdone_monitor(dd, "First-reset"); /* Remember so we do not re-do the load, dactrim, etc. */ dd->serdes_first_init_done = 1; } /* * Setup for channel training and load values for * RxEq and DDS in tables used by IBC in IB1.2 mode */ val_stat = ipath_sd_setvals(dd); if (val_stat < 0) ret = 1; done: /* start relock timer regardless, but start at 1 second */ ipath_set_relock_poll(dd, -1); return ret; } #define EPB_ACC_REQ 1 #define EPB_ACC_GNT 0x100 #define EPB_DATA_MASK 0xFF #define EPB_RD (1ULL << 24) #define EPB_TRANS_RDY (1ULL << 31) #define EPB_TRANS_ERR (1ULL << 30) #define EPB_TRANS_TRIES 5 /* * query, claim, release ownership of the EPB (External Parallel Bus) * for a specified SERDES. * the "claim" parameter is >0 to claim, <0 to release, 0 to query. * Returns <0 for errors, >0 if we had ownership, else 0. */ static int epb_access(struct ipath_devdata *dd, int sdnum, int claim) { u16 acc; u64 accval; int owned = 0; u64 oct_sel = 0; switch (sdnum) { case IB_7220_SERDES : /* * The IB SERDES "ownership" is fairly simple. A single each * request/grant. */ acc = dd->ipath_kregs->kr_ib_epbacc; break; case PCIE_SERDES0 : case PCIE_SERDES1 : /* PCIe SERDES has two "octants", need to select which */ acc = dd->ipath_kregs->kr_pcie_epbacc; oct_sel = (2 << (sdnum - PCIE_SERDES0)); break; default : return 0; } /* Make sure any outstanding transaction was seen */ ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch); udelay(15); accval = ipath_read_kreg32(dd, acc); owned = !!(accval & EPB_ACC_GNT); if (claim < 0) { /* Need to release */ u64 pollval; /* * The only writeable bits are the request and CS. * Both should be clear */ u64 newval = 0; ipath_write_kreg(dd, acc, newval); /* First read after write is not trustworthy */ pollval = ipath_read_kreg32(dd, acc); udelay(5); pollval = ipath_read_kreg32(dd, acc); if (pollval & EPB_ACC_GNT) owned = -1; } else if (claim > 0) { /* Need to claim */ u64 pollval; u64 newval = EPB_ACC_REQ | oct_sel; ipath_write_kreg(dd, acc, newval); /* First read after write is not trustworthy */ pollval = ipath_read_kreg32(dd, acc); udelay(5); pollval = ipath_read_kreg32(dd, acc); if (!(pollval & EPB_ACC_GNT)) owned = -1; } return owned; } /* * Lemma to deal with race condition of write..read to epb regs */ static int epb_trans(struct ipath_devdata *dd, u16 reg, u64 i_val, u64 *o_vp) { int tries; u64 transval; ipath_write_kreg(dd, reg, i_val); /* Throw away first read, as RDY bit may be stale */ transval = ipath_read_kreg64(dd, reg); for (tries = EPB_TRANS_TRIES; tries; --tries) { transval = ipath_read_kreg32(dd, reg); if (transval & EPB_TRANS_RDY) break; udelay(5); } if (transval & EPB_TRANS_ERR) return -1; if (tries > 0 && o_vp) *o_vp = transval; return tries; } /** * * ipath_sd7220_reg_mod - modify SERDES register * @dd: the infinipath device * @sdnum: which SERDES to access * @loc: location - channel, element, register, as packed by EPB_LOC() macro. * @wd: Write Data - value to set in register * @mask: ones where data should be spliced into reg. * * Basic register read/modify/write, with un-needed acesses elided. That is, * a mask of zero will prevent write, while a mask of 0xFF will prevent read. * returns current (presumed, if a write was done) contents of selected * register, or <0 if errors. */ static int ipath_sd7220_reg_mod(struct ipath_devdata *dd, int sdnum, u32 loc, u32 wd, u32 mask) { u16 trans; u64 transval; int owned; int tries, ret; unsigned long flags; switch (sdnum) { case IB_7220_SERDES : trans = dd->ipath_kregs->kr_ib_epbtrans; break; case PCIE_SERDES0 : case PCIE_SERDES1 : trans = dd->ipath_kregs->kr_pcie_epbtrans; break; default : return -1; } /* * All access is locked in software (vs other host threads) and * hardware (vs uC access). */ spin_lock_irqsave(&dd->ipath_sdepb_lock, flags); owned = epb_access(dd, sdnum, 1); if (owned < 0) { spin_unlock_irqrestore(&dd->ipath_sdepb_lock, flags); return -1; } ret = 0; for (tries = EPB_TRANS_TRIES; tries; --tries) { transval = ipath_read_kreg32(dd, trans); if (transval & EPB_TRANS_RDY) break; udelay(5); } if (tries > 0) { tries = 1; /* to make read-skip work */ if (mask != 0xFF) { /* * Not a pure write, so need to read. * loc encodes chip-select as well as address */ transval = loc | EPB_RD; tries = epb_trans(dd, trans, transval, &transval); } if (tries > 0 && mask != 0) { /* * Not a pure read, so need to write. */ wd = (wd & mask) | (transval & ~mask); transval = loc | (wd & EPB_DATA_MASK); tries = epb_trans(dd, trans, transval, &transval); } } /* else, failed to see ready, what error-handling? */ /* * Release bus. Failure is an error. */ if (epb_access(dd, sdnum, -1) < 0) ret = -1; else ret = transval & EPB_DATA_MASK; spin_unlock_irqrestore(&dd->ipath_sdepb_lock, flags); if (tries <= 0) ret = -1; return ret; } #define EPB_ROM_R (2) #define EPB_ROM_W (1) /* * Below, all uC-related, use appropriate UC_CS, depending * on which SerDes is used. */ #define EPB_UC_CTL EPB_LOC(6, 0, 0) #define EPB_MADDRL EPB_LOC(6, 0, 2) #define EPB_MADDRH EPB_LOC(6, 0, 3) #define EPB_ROMDATA EPB_LOC(6, 0, 4) #define EPB_RAMDATA EPB_LOC(6, 0, 5) /* Transfer date to/from uC Program RAM of IB or PCIe SerDes */ static int ipath_sd7220_ram_xfer(struct ipath_devdata *dd, int sdnum, u32 loc, u8 *buf, int cnt, int rd_notwr) { u16 trans; u64 transval; u64 csbit; int owned; int tries; int sofar; int addr; int ret; unsigned long flags; const char *op; /* Pick appropriate transaction reg and "Chip select" for this serdes */ switch (sdnum) { case IB_7220_SERDES : csbit = 1ULL << EPB_IB_UC_CS_SHF; trans = dd->ipath_kregs->kr_ib_epbtrans; break; case PCIE_SERDES0 : case PCIE_SERDES1 : /* PCIe SERDES has uC "chip select" in different bit, too */ csbit = 1ULL << EPB_PCIE_UC_CS_SHF; trans = dd->ipath_kregs->kr_pcie_epbtrans; break; default : return -1; } op = rd_notwr ? "Rd" : "Wr"; spin_lock_irqsave(&dd->ipath_sdepb_lock, flags); owned = epb_access(dd, sdnum, 1); if (owned < 0) { spin_unlock_irqrestore(&dd->ipath_sdepb_lock, flags); ipath_dbg("Could not get %s access to %s EPB: %X, loc %X\n", op, (sdnum == IB_7220_SERDES) ? "IB" : "PCIe", owned, loc); return -1; } /* * In future code, we may need to distinguish several address ranges, * and select various memories based on this. For now, just trim * "loc" (location including address and memory select) to * "addr" (address within memory). we will only support PRAM * The memory is 8KB. */ addr = loc & 0x1FFF; for (tries = EPB_TRANS_TRIES; tries; --tries) { transval = ipath_read_kreg32(dd, trans); if (transval & EPB_TRANS_RDY) break; udelay(5); } sofar = 0; if (tries <= 0) ipath_dbg("No initial RDY on EPB access request\n"); else { /* * Every "memory" access is doubly-indirect. * We set two bytes of address, then read/write * one or mores bytes of data. */ /* First, we set control to "Read" or "Write" */ transval = csbit | EPB_UC_CTL | (rd_notwr ? EPB_ROM_R : EPB_ROM_W); tries = epb_trans(dd, trans, transval, &transval); if (tries <= 0) ipath_dbg("No EPB response to uC %s cmd\n", op); while (tries > 0 && sofar < cnt) { if (!sofar) { /* Only set address at start of chunk */ int addrbyte = (addr + sofar) >> 8; transval = csbit | EPB_MADDRH | addrbyte; tries = epb_trans(dd, trans, transval, &transval); if (tries <= 0) { ipath_dbg("No EPB response ADDRH\n"); break; } addrbyte = (addr + sofar) & 0xFF; transval = csbit | EPB_MADDRL | addrbyte; tries = epb_trans(dd, trans, transval, &transval); if (tries <= 0) { ipath_dbg("No EPB response ADDRL\n"); break; } } if (rd_notwr) transval = csbit | EPB_ROMDATA | EPB_RD; else transval = csbit | EPB_ROMDATA | buf[sofar]; tries = epb_trans(dd, trans, transval, &transval); if (tries <= 0) { ipath_dbg("No EPB response DATA\n"); break; } if (rd_notwr) buf[sofar] = transval & EPB_DATA_MASK; ++sofar; } /* Finally, clear control-bit for Read or Write */ transval = csbit | EPB_UC_CTL; tries = epb_trans(dd, trans, transval, &transval); if (tries <= 0) ipath_dbg("No EPB response to drop of uC %s cmd\n", op); } ret = sofar; /* Release bus. Failure is an error */ if (epb_access(dd, sdnum, -1) < 0) ret = -1; spin_unlock_irqrestore(&dd->ipath_sdepb_lock, flags); if (tries <= 0) { ipath_dbg("SERDES PRAM %s failed after %d bytes\n", op, sofar); ret = -1; } return ret; } #define PROG_CHUNK 64 int ipath_sd7220_prog_ld(struct ipath_devdata *dd, int sdnum, u8 *img, int len, int offset) { int cnt, sofar, req; sofar = 0; while (sofar < len) { req = len - sofar; if (req > PROG_CHUNK) req = PROG_CHUNK; cnt = ipath_sd7220_ram_xfer(dd, sdnum, offset + sofar, img + sofar, req, 0); if (cnt < req) { sofar = -1; break; } sofar += req; } return sofar; } #define VFY_CHUNK 64 #define SD_PRAM_ERROR_LIMIT 42 int ipath_sd7220_prog_vfy(struct ipath_devdata *dd, int sdnum, const u8 *img, int len, int offset) { int cnt, sofar, req, idx, errors; unsigned char readback[VFY_CHUNK]; errors = 0; sofar = 0; while (sofar < len) { req = len - sofar; if (req > VFY_CHUNK) req = VFY_CHUNK; cnt = ipath_sd7220_ram_xfer(dd, sdnum, sofar + offset, readback, req, 1); if (cnt < req) { /* failed in read itself */ sofar = -1; break; } for (idx = 0; idx < cnt; ++idx) { if (readback[idx] != img[idx+sofar]) ++errors; } sofar += cnt; } return errors ? -errors : sofar; } /* IRQ not set up at this point in init, so we poll. */ #define IB_SERDES_TRIM_DONE (1ULL << 11) #define TRIM_TMO (30) static int ipath_sd_trimdone_poll(struct ipath_devdata *dd) { int trim_tmo, ret; uint64_t val; /* * Default to failure, so IBC will not start * without IB_SERDES_TRIM_DONE. */ ret = 0; for (trim_tmo = 0; trim_tmo < TRIM_TMO; ++trim_tmo) { val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus); if (val & IB_SERDES_TRIM_DONE) { ipath_cdbg(VERBOSE, "TRIMDONE after %d\n", trim_tmo); ret = 1; break; } msleep(10); } if (trim_tmo >= TRIM_TMO) { ipath_dev_err(dd, "No TRIMDONE in %d tries\n", trim_tmo); ret = 0; } return ret; } #define TX_FAST_ELT (9) /* * Set the "negotiation" values for SERDES. These are used by the IB1.2 * link negotiation. Macros below are attempt to keep the values a * little more human-editable. * First, values related to Drive De-emphasis Settings. */ #define NUM_DDS_REGS 6 #define DDS_REG_MAP 0x76A910 /* LSB-first list of regs (in elt 9) to mod */ #define DDS_VAL(amp_d, main_d, ipst_d, ipre_d, amp_s, main_s, ipst_s, ipre_s) \ { { ((amp_d & 0x1F) << 1) | 1, ((amp_s & 0x1F) << 1) | 1, \ (main_d << 3) | 4 | (ipre_d >> 2), \ (main_s << 3) | 4 | (ipre_s >> 2), \ ((ipst_d & 0xF) << 1) | ((ipre_d & 3) << 6) | 0x21, \ ((ipst_s & 0xF) << 1) | ((ipre_s & 3) << 6) | 0x21 } } static struct dds_init { uint8_t reg_vals[NUM_DDS_REGS]; } dds_init_vals[] = { /* DDR(FDR) SDR(HDR) */ /* Vendor recommends below for 3m cable */ #define DDS_3M 0 DDS_VAL(31, 19, 12, 0, 29, 22, 9, 0), DDS_VAL(31, 12, 15, 4, 31, 15, 15, 1), DDS_VAL(31, 13, 15, 3, 31, 16, 15, 0), DDS_VAL(31, 14, 15, 2, 31, 17, 14, 0), DDS_VAL(31, 15, 15, 1, 31, 18, 13, 0), DDS_VAL(31, 16, 15, 0, 31, 19, 12, 0), DDS_VAL(31, 17, 14, 0, 31, 20, 11, 0), DDS_VAL(31, 18, 13, 0, 30, 21, 10, 0), DDS_VAL(31, 20, 11, 0, 28, 23, 8, 0), DDS_VAL(31, 21, 10, 0, 27, 24, 7, 0), DDS_VAL(31, 22, 9, 0, 26, 25, 6, 0), DDS_VAL(30, 23, 8, 0, 25, 26, 5, 0), DDS_VAL(29, 24, 7, 0, 23, 27, 4, 0), /* Vendor recommends below for 1m cable */ #define DDS_1M 13 DDS_VAL(28, 25, 6, 0, 21, 28, 3, 0), DDS_VAL(27, 26, 5, 0, 19, 29, 2, 0), DDS_VAL(25, 27, 4, 0, 17, 30, 1, 0) }; /* * Next, values related to Receive Equalization. * In comments, FDR (Full) is IB DDR, HDR (Half) is IB SDR */ /* Hardware packs an element number and register address thus: */ #define RXEQ_INIT_RDESC(elt, addr) (((elt) & 0xF) | ((addr) << 4)) #define RXEQ_VAL(elt, adr, val0, val1, val2, val3) \ {RXEQ_INIT_RDESC((elt), (adr)), {(val0), (val1), (val2), (val3)} } #define RXEQ_VAL_ALL(elt, adr, val) \ {RXEQ_INIT_RDESC((elt), (adr)), {(val), (val), (val), (val)} } #define RXEQ_SDR_DFELTH 0 #define RXEQ_SDR_TLTH 0 #define RXEQ_SDR_G1CNT_Z1CNT 0x11 #define RXEQ_SDR_ZCNT 23 static struct rxeq_init { u16 rdesc; /* in form used in SerDesDDSRXEQ */ u8 rdata[4]; } rxeq_init_vals[] = { /* Set Rcv Eq. to Preset node */ RXEQ_VAL_ALL(7, 0x27, 0x10), /* Set DFELTHFDR/HDR thresholds */ RXEQ_VAL(7, 8, 0, 0, 0, 0), /* FDR */ RXEQ_VAL(7, 0x21, 0, 0, 0, 0), /* HDR */ /* Set TLTHFDR/HDR theshold */ RXEQ_VAL(7, 9, 2, 2, 2, 2), /* FDR */ RXEQ_VAL(7, 0x23, 2, 2, 2, 2), /* HDR */ /* Set Preamp setting 2 (ZFR/ZCNT) */ RXEQ_VAL(7, 0x1B, 12, 12, 12, 12), /* FDR */ RXEQ_VAL(7, 0x1C, 12, 12, 12, 12), /* HDR */ /* Set Preamp DC gain and Setting 1 (GFR/GHR) */ RXEQ_VAL(7, 0x1E, 0x10, 0x10, 0x10, 0x10), /* FDR */ RXEQ_VAL(7, 0x1F, 0x10, 0x10, 0x10, 0x10), /* HDR */ /* Toggle RELOCK (in VCDL_CTRL0) to lock to data */ RXEQ_VAL_ALL(6, 6, 0x20), /* Set D5 High */ RXEQ_VAL_ALL(6, 6, 0), /* Set D5 Low */ }; /* There are 17 values from vendor, but IBC only accesses the first 16 */ #define DDS_ROWS (16) #define RXEQ_ROWS ARRAY_SIZE(rxeq_init_vals) static int ipath_sd_setvals(struct ipath_devdata *dd) { int idx, midx; int min_idx; /* Minimum index for this portion of table */ uint32_t dds_reg_map; u64 __iomem *taddr, *iaddr; uint64_t data; uint64_t sdctl; taddr = dd->ipath_kregbase + KR_IBSerDesMappTable; iaddr = dd->ipath_kregbase + dd->ipath_kregs->kr_ib_ddsrxeq; /* * Init the DDS section of the table. * Each "row" of the table provokes NUM_DDS_REG writes, to the * registers indicated in DDS_REG_MAP. */ sdctl = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibserdesctrl); sdctl = (sdctl & ~(0x1f << 8)) | (NUM_DDS_REGS << 8); sdctl = (sdctl & ~(0x1f << 13)) | (RXEQ_ROWS << 13); ipath_write_kreg(dd, dd->ipath_kregs->kr_ibserdesctrl, sdctl); /* * Iterate down table within loop for each register to store. */ dds_reg_map = DDS_REG_MAP; for (idx = 0; idx < NUM_DDS_REGS; ++idx) { data = ((dds_reg_map & 0xF) << 4) | TX_FAST_ELT; writeq(data, iaddr + idx); mmiowb(); ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch); dds_reg_map >>= 4; for (midx = 0; midx < DDS_ROWS; ++midx) { u64 __iomem *daddr = taddr + ((midx << 4) + idx); data = dds_init_vals[midx].reg_vals[idx]; writeq(data, daddr); mmiowb(); ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch); } /* End inner for (vals for this reg, each row) */ } /* end outer for (regs to be stored) */ /* * Init the RXEQ section of the table. As explained above the table * rxeq_init_vals[], this runs in a different order, as the pattern * of register references is more complex, but there are only * four "data" values per register. */ min_idx = idx; /* RXEQ indices pick up where DDS left off */ taddr += 0x100; /* RXEQ data is in second half of table */ /* Iterate through RXEQ register addresses */ for (idx = 0; idx < RXEQ_ROWS; ++idx) { int didx; /* "destination" */ int vidx; /* didx is offset by min_idx to address RXEQ range of regs */ didx = idx + min_idx; /* Store the next RXEQ register address */ writeq(rxeq_init_vals[idx].rdesc, iaddr + didx); mmiowb(); ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch); /* Iterate through RXEQ values */ for (vidx = 0; vidx < 4; vidx++) { data = rxeq_init_vals[idx].rdata[vidx]; writeq(data, taddr + (vidx << 6) + idx); mmiowb(); ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch); } } /* end outer for (Reg-writes for RXEQ) */ return 0; } #define CMUCTRL5 EPB_LOC(7, 0, 0x15) #define RXHSCTRL0(chan) EPB_LOC(chan, 6, 0) #define VCDL_DAC2(chan) EPB_LOC(chan, 6, 5) #define VCDL_CTRL0(chan) EPB_LOC(chan, 6, 6) #define VCDL_CTRL2(chan) EPB_LOC(chan, 6, 8) #define START_EQ2(chan) EPB_LOC(chan, 7, 0x28) static int ibsd_sto_noisy(struct ipath_devdata *dd, int loc, int val, int mask) { int ret = -1; int sloc; /* shifted loc, for messages */ loc |= (1U << EPB_IB_QUAD0_CS_SHF); sloc = loc >> EPB_ADDR_SHF; ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, loc, val, mask); if (ret < 0) ipath_dev_err(dd, "Write failed: elt %d," " addr 0x%X, chnl %d, val 0x%02X, mask 0x%02X\n", (sloc & 0xF), (sloc >> 9) & 0x3f, (sloc >> 4) & 7, val & 0xFF, mask & 0xFF); return ret; } /* * Repeat a "store" across all channels of the IB SerDes. * Although nominally it inherits the "read value" of the last * channel it modified, the only really useful return is <0 for * failure, >= 0 for success. The parameter 'loc' is assumed to * be the location for the channel-0 copy of the register to * be modified. */ static int ibsd_mod_allchnls(struct ipath_devdata *dd, int loc, int val, int mask) { int ret = -1; int chnl; if (loc & EPB_GLOBAL_WR) { /* * Our caller has assured us that we can set all four * channels at once. Trust that. If mask is not 0xFF, * we will read the _specified_ channel for our starting * value. */ loc |= (1U << EPB_IB_QUAD0_CS_SHF); chnl = (loc >> (4 + EPB_ADDR_SHF)) & 7; if (mask != 0xFF) { ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, loc & ~EPB_GLOBAL_WR, 0, 0); if (ret < 0) { int sloc = loc >> EPB_ADDR_SHF; ipath_dev_err(dd, "pre-read failed: elt %d," " addr 0x%X, chnl %d\n", (sloc & 0xF), (sloc >> 9) & 0x3f, chnl); return ret; } val = (ret & ~mask) | (val & mask); } loc &= ~(7 << (4+EPB_ADDR_SHF)); ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, loc, val, 0xFF); if (ret < 0) { int sloc = loc >> EPB_ADDR_SHF; ipath_dev_err(dd, "Global WR failed: elt %d," " addr 0x%X, val %02X\n", (sloc & 0xF), (sloc >> 9) & 0x3f, val); } return ret; } /* Clear "channel" and set CS so we can simply iterate */ loc &= ~(7 << (4+EPB_ADDR_SHF)); loc |= (1U << EPB_IB_QUAD0_CS_SHF); for (chnl = 0; chnl < 4; ++chnl) { int cloc; cloc = loc | (chnl << (4+EPB_ADDR_SHF)); ret = ipath_sd7220_reg_mod(dd, IB_7220_SERDES, cloc, val, mask); if (ret < 0) { int sloc = loc >> EPB_ADDR_SHF; ipath_dev_err(dd, "Write failed: elt %d," " addr 0x%X, chnl %d, val 0x%02X," " mask 0x%02X\n", (sloc & 0xF), (sloc >> 9) & 0x3f, chnl, val & 0xFF, mask & 0xFF); break; } } return ret; } /* * Set the Tx values normally modified by IBC in IB1.2 mode to default * values, as gotten from first row of init table. */ static int set_dds_vals(struct ipath_devdata *dd, struct dds_init *ddi) { int ret; int idx, reg, data; uint32_t regmap; regmap = DDS_REG_MAP; for (idx = 0; idx < NUM_DDS_REGS; ++idx) { reg = (regmap & 0xF); regmap >>= 4; data = ddi->reg_vals[idx]; /* Vendor says RMW not needed for these regs, use 0xFF mask */ ret = ibsd_mod_allchnls(dd, EPB_LOC(0, 9, reg), data, 0xFF); if (ret < 0) break; } return ret; } /* * Set the Rx values normally modified by IBC in IB1.2 mode to default * values, as gotten from selected column of init table. */ static int set_rxeq_vals(struct ipath_devdata *dd, int vsel) { int ret; int ridx; int cnt = ARRAY_SIZE(rxeq_init_vals); for (ridx = 0; ridx < cnt; ++ridx) { int elt, reg, val, loc; elt = rxeq_init_vals[ridx].rdesc & 0xF; reg = rxeq_init_vals[ridx].rdesc >> 4; loc = EPB_LOC(0, elt, reg); val = rxeq_init_vals[ridx].rdata[vsel]; /* mask of 0xFF, because hardware does full-byte store. */ ret = ibsd_mod_allchnls(dd, loc, val, 0xFF); if (ret < 0) break; } return ret; } /* * Set the default values (row 0) for DDR Driver Demphasis. * we do this initially and whenever we turn off IB-1.2 * The "default" values for Rx equalization are also stored to * SerDes registers. Formerly (and still default), we used set 2. * For experimenting with cables and link-partners, we allow changing * that via a module parameter. */ static unsigned ipath_rxeq_set = 2; module_param_named(rxeq_default_set, ipath_rxeq_set, uint, S_IWUSR | S_IRUGO); MODULE_PARM_DESC(rxeq_default_set, "Which set [0..3] of Rx Equalization values is default"); static int ipath_internal_presets(struct ipath_devdata *dd) { int ret = 0; ret = set_dds_vals(dd, dds_init_vals + DDS_3M); if (ret < 0) ipath_dev_err(dd, "Failed to set default DDS values\n"); ret = set_rxeq_vals(dd, ipath_rxeq_set & 3); if (ret < 0) ipath_dev_err(dd, "Failed to set default RXEQ values\n"); return ret; } int ipath_sd7220_presets(struct ipath_devdata *dd) { int ret = 0; if (!dd->ipath_presets_needed) return ret; dd->ipath_presets_needed = 0; /* Assert uC reset, so we don't clash with it. */ ipath_ibsd_reset(dd, 1); udelay(2); ipath_sd_trimdone_monitor(dd, "link-down"); ret = ipath_internal_presets(dd); return ret; } static int ipath_sd_trimself(struct ipath_devdata *dd, int val) { return ibsd_sto_noisy(dd, CMUCTRL5, val, 0xFF); } static int ipath_sd_early(struct ipath_devdata *dd) { int ret = -1; /* Default failed */ int chnl; for (chnl = 0; chnl < 4; ++chnl) { ret = ibsd_sto_noisy(dd, RXHSCTRL0(chnl), 0xD4, 0xFF); if (ret < 0) goto bail; } for (chnl = 0; chnl < 4; ++chnl) { ret = ibsd_sto_noisy(dd, VCDL_DAC2(chnl), 0x2D, 0xFF); if (ret < 0) goto bail; } /* more fine-tuning of what will be default */ for (chnl = 0; chnl < 4; ++chnl) { ret = ibsd_sto_noisy(dd, VCDL_CTRL2(chnl), 3, 0xF); if (ret < 0) goto bail; } for (chnl = 0; chnl < 4; ++chnl) { ret = ibsd_sto_noisy(dd, START_EQ1(chnl), 0x10, 0xFF); if (ret < 0) goto bail; } for (chnl = 0; chnl < 4; ++chnl) { ret = ibsd_sto_noisy(dd, START_EQ2(chnl), 0x30, 0xFF); if (ret < 0) goto bail; } bail: return ret; } #define BACTRL(chnl) EPB_LOC(chnl, 6, 0x0E) #define LDOUTCTRL1(chnl) EPB_LOC(chnl, 7, 6) #define RXHSSTATUS(chnl) EPB_LOC(chnl, 6, 0xF) static int ipath_sd_dactrim(struct ipath_devdata *dd) { int ret = -1; /* Default failed */ int chnl; for (chnl = 0; chnl < 4; ++chnl) { ret = ibsd_sto_noisy(dd, BACTRL(chnl), 0x40, 0xFF); if (ret < 0) goto bail; } for (chnl = 0; chnl < 4; ++chnl) { ret = ibsd_sto_noisy(dd, LDOUTCTRL1(chnl), 0x04, 0xFF); if (ret < 0) goto bail; } for (chnl = 0; chnl < 4; ++chnl) { ret = ibsd_sto_noisy(dd, RXHSSTATUS(chnl), 0x04, 0xFF); if (ret < 0) goto bail; } /* * delay for max possible number of steps, with slop. * Each step is about 4usec. */ udelay(415); for (chnl = 0; chnl < 4; ++chnl) { ret = ibsd_sto_noisy(dd, LDOUTCTRL1(chnl), 0x00, 0xFF); if (ret < 0) goto bail; } bail: return ret; } #define RELOCK_FIRST_MS 3 #define RXLSPPM(chan) EPB_LOC(chan, 0, 2) void ipath_toggle_rclkrls(struct ipath_devdata *dd) { int loc = RXLSPPM(0) | EPB_GLOBAL_WR; int ret; ret = ibsd_mod_allchnls(dd, loc, 0, 0x80); if (ret < 0) ipath_dev_err(dd, "RCLKRLS failed to clear D7\n"); else { udelay(1); ibsd_mod_allchnls(dd, loc, 0x80, 0x80); } /* And again for good measure */ udelay(1); ret = ibsd_mod_allchnls(dd, loc, 0, 0x80); if (ret < 0) ipath_dev_err(dd, "RCLKRLS failed to clear D7\n"); else { udelay(1); ibsd_mod_allchnls(dd, loc, 0x80, 0x80); } /* Now reset xgxs and IBC to complete the recovery */ dd->ipath_f_xgxs_reset(dd); } /* * Shut down the timer that polls for relock occasions, if needed * this is "hooked" from ipath_7220_quiet_serdes(), which is called * just before ipath_shutdown_device() in ipath_driver.c shuts down all * the other timers */ void ipath_shutdown_relock_poll(struct ipath_devdata *dd) { struct ipath_relock *irp = &dd->ipath_relock_singleton; if (atomic_read(&irp->ipath_relock_timer_active)) { del_timer_sync(&irp->ipath_relock_timer); atomic_set(&irp->ipath_relock_timer_active, 0); } } static unsigned ipath_relock_by_timer = 1; module_param_named(relock_by_timer, ipath_relock_by_timer, uint, S_IWUSR | S_IRUGO); MODULE_PARM_DESC(relock_by_timer, "Allow relock attempt if link not up"); static void ipath_run_relock(unsigned long opaque) { struct ipath_devdata *dd = (struct ipath_devdata *)opaque; struct ipath_relock *irp = &dd->ipath_relock_singleton; u64 val, ltstate; if (!(dd->ipath_flags & IPATH_INITTED)) { /* Not yet up, just reenable the timer for later */ irp->ipath_relock_interval = HZ; mod_timer(&irp->ipath_relock_timer, jiffies + HZ); return; } /* * Check link-training state for "stuck" state. * if found, try relock and schedule another try at * exponentially growing delay, maxed at one second. * if not stuck, our work is done. */ val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus); ltstate = ipath_ib_linktrstate(dd, val); if (ltstate <= INFINIPATH_IBCS_LT_STATE_CFGWAITRMT && ltstate != INFINIPATH_IBCS_LT_STATE_LINKUP) { int timeoff; /* Not up yet. Try again, if allowed by module-param */ if (ipath_relock_by_timer) { if (dd->ipath_flags & IPATH_IB_AUTONEG_INPROG) ipath_cdbg(VERBOSE, "Skip RELOCK in AUTONEG\n"); else if (!(dd->ipath_flags & IPATH_IB_LINK_DISABLED)) { ipath_cdbg(VERBOSE, "RELOCK\n"); ipath_toggle_rclkrls(dd); } } /* re-set timer for next check */ timeoff = irp->ipath_relock_interval << 1; if (timeoff > HZ) timeoff = HZ; irp->ipath_relock_interval = timeoff; mod_timer(&irp->ipath_relock_timer, jiffies + timeoff); } else { /* Up, so no more need to check so often */ mod_timer(&irp->ipath_relock_timer, jiffies + HZ); } } void ipath_set_relock_poll(struct ipath_devdata *dd, int ibup) { struct ipath_relock *irp = &dd->ipath_relock_singleton; if (ibup > 0) { /* we are now up, so relax timer to 1 second interval */ if (atomic_read(&irp->ipath_relock_timer_active)) mod_timer(&irp->ipath_relock_timer, jiffies + HZ); } else { /* Transition to down, (re-)set timer to short interval. */ int timeout; timeout = (HZ * ((ibup == -1) ? 1000 : RELOCK_FIRST_MS))/1000; if (timeout == 0) timeout = 1; /* If timer has not yet been started, do so. */ if (atomic_inc_return(&irp->ipath_relock_timer_active) == 1) { init_timer(&irp->ipath_relock_timer); irp->ipath_relock_timer.function = ipath_run_relock; irp->ipath_relock_timer.data = (unsigned long) dd; irp->ipath_relock_interval = timeout; irp->ipath_relock_timer.expires = jiffies + timeout; add_timer(&irp->ipath_relock_timer); } else { irp->ipath_relock_interval = timeout; mod_timer(&irp->ipath_relock_timer, jiffies + timeout); atomic_dec(&irp->ipath_relock_timer_active); } } }
gpl-2.0
HerroYou/android_kernel_samsung_msm7x27
sound/soc/davinci/davinci-mcasp.c
701
26288
/* * ALSA SoC McASP Audio Layer for TI DAVINCI processor * * Multi-channel Audio Serial Port Driver * * Author: Nirmal Pandey <n-pandey@ti.com>, * Suresh Rajashekara <suresh.r@ti.com> * Steve Chen <schen@.mvista.com> * * Copyright: (C) 2009 MontaVista Software, Inc., <source@mvista.com> * Copyright: (C) 2009 Texas Instruments, India * * 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/init.h> #include <linux/module.h> #include <linux/device.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/io.h> #include <linux/clk.h> #include <sound/core.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/initval.h> #include <sound/soc.h> #include "davinci-pcm.h" #include "davinci-mcasp.h" /* * McASP register definitions */ #define DAVINCI_MCASP_PID_REG 0x00 #define DAVINCI_MCASP_PWREMUMGT_REG 0x04 #define DAVINCI_MCASP_PFUNC_REG 0x10 #define DAVINCI_MCASP_PDIR_REG 0x14 #define DAVINCI_MCASP_PDOUT_REG 0x18 #define DAVINCI_MCASP_PDSET_REG 0x1c #define DAVINCI_MCASP_PDCLR_REG 0x20 #define DAVINCI_MCASP_TLGC_REG 0x30 #define DAVINCI_MCASP_TLMR_REG 0x34 #define DAVINCI_MCASP_GBLCTL_REG 0x44 #define DAVINCI_MCASP_AMUTE_REG 0x48 #define DAVINCI_MCASP_LBCTL_REG 0x4c #define DAVINCI_MCASP_TXDITCTL_REG 0x50 #define DAVINCI_MCASP_GBLCTLR_REG 0x60 #define DAVINCI_MCASP_RXMASK_REG 0x64 #define DAVINCI_MCASP_RXFMT_REG 0x68 #define DAVINCI_MCASP_RXFMCTL_REG 0x6c #define DAVINCI_MCASP_ACLKRCTL_REG 0x70 #define DAVINCI_MCASP_AHCLKRCTL_REG 0x74 #define DAVINCI_MCASP_RXTDM_REG 0x78 #define DAVINCI_MCASP_EVTCTLR_REG 0x7c #define DAVINCI_MCASP_RXSTAT_REG 0x80 #define DAVINCI_MCASP_RXTDMSLOT_REG 0x84 #define DAVINCI_MCASP_RXCLKCHK_REG 0x88 #define DAVINCI_MCASP_REVTCTL_REG 0x8c #define DAVINCI_MCASP_GBLCTLX_REG 0xa0 #define DAVINCI_MCASP_TXMASK_REG 0xa4 #define DAVINCI_MCASP_TXFMT_REG 0xa8 #define DAVINCI_MCASP_TXFMCTL_REG 0xac #define DAVINCI_MCASP_ACLKXCTL_REG 0xb0 #define DAVINCI_MCASP_AHCLKXCTL_REG 0xb4 #define DAVINCI_MCASP_TXTDM_REG 0xb8 #define DAVINCI_MCASP_EVTCTLX_REG 0xbc #define DAVINCI_MCASP_TXSTAT_REG 0xc0 #define DAVINCI_MCASP_TXTDMSLOT_REG 0xc4 #define DAVINCI_MCASP_TXCLKCHK_REG 0xc8 #define DAVINCI_MCASP_XEVTCTL_REG 0xcc /* Left(even TDM Slot) Channel Status Register File */ #define DAVINCI_MCASP_DITCSRA_REG 0x100 /* Right(odd TDM slot) Channel Status Register File */ #define DAVINCI_MCASP_DITCSRB_REG 0x118 /* Left(even TDM slot) User Data Register File */ #define DAVINCI_MCASP_DITUDRA_REG 0x130 /* Right(odd TDM Slot) User Data Register File */ #define DAVINCI_MCASP_DITUDRB_REG 0x148 /* Serializer n Control Register */ #define DAVINCI_MCASP_XRSRCTL_BASE_REG 0x180 #define DAVINCI_MCASP_XRSRCTL_REG(n) (DAVINCI_MCASP_XRSRCTL_BASE_REG + \ (n << 2)) /* Transmit Buffer for Serializer n */ #define DAVINCI_MCASP_TXBUF_REG 0x200 /* Receive Buffer for Serializer n */ #define DAVINCI_MCASP_RXBUF_REG 0x280 /* McASP FIFO Registers */ #define DAVINCI_MCASP_WFIFOCTL (0x1010) #define DAVINCI_MCASP_WFIFOSTS (0x1014) #define DAVINCI_MCASP_RFIFOCTL (0x1018) #define DAVINCI_MCASP_RFIFOSTS (0x101C) /* * DAVINCI_MCASP_PWREMUMGT_REG - Power Down and Emulation Management * Register Bits */ #define MCASP_FREE BIT(0) #define MCASP_SOFT BIT(1) /* * DAVINCI_MCASP_PFUNC_REG - Pin Function / GPIO Enable Register Bits */ #define AXR(n) (1<<n) #define PFUNC_AMUTE BIT(25) #define ACLKX BIT(26) #define AHCLKX BIT(27) #define AFSX BIT(28) #define ACLKR BIT(29) #define AHCLKR BIT(30) #define AFSR BIT(31) /* * DAVINCI_MCASP_PDIR_REG - Pin Direction Register Bits */ #define AXR(n) (1<<n) #define PDIR_AMUTE BIT(25) #define ACLKX BIT(26) #define AHCLKX BIT(27) #define AFSX BIT(28) #define ACLKR BIT(29) #define AHCLKR BIT(30) #define AFSR BIT(31) /* * DAVINCI_MCASP_TXDITCTL_REG - Transmit DIT Control Register Bits */ #define DITEN BIT(0) /* Transmit DIT mode enable/disable */ #define VA BIT(2) #define VB BIT(3) /* * DAVINCI_MCASP_TXFMT_REG - Transmit Bitstream Format Register Bits */ #define TXROT(val) (val) #define TXSEL BIT(3) #define TXSSZ(val) (val<<4) #define TXPBIT(val) (val<<8) #define TXPAD(val) (val<<13) #define TXORD BIT(15) #define FSXDLY(val) (val<<16) /* * DAVINCI_MCASP_RXFMT_REG - Receive Bitstream Format Register Bits */ #define RXROT(val) (val) #define RXSEL BIT(3) #define RXSSZ(val) (val<<4) #define RXPBIT(val) (val<<8) #define RXPAD(val) (val<<13) #define RXORD BIT(15) #define FSRDLY(val) (val<<16) /* * DAVINCI_MCASP_TXFMCTL_REG - Transmit Frame Control Register Bits */ #define FSXPOL BIT(0) #define AFSXE BIT(1) #define FSXDUR BIT(4) #define FSXMOD(val) (val<<7) /* * DAVINCI_MCASP_RXFMCTL_REG - Receive Frame Control Register Bits */ #define FSRPOL BIT(0) #define AFSRE BIT(1) #define FSRDUR BIT(4) #define FSRMOD(val) (val<<7) /* * DAVINCI_MCASP_ACLKXCTL_REG - Transmit Clock Control Register Bits */ #define ACLKXDIV(val) (val) #define ACLKXE BIT(5) #define TX_ASYNC BIT(6) #define ACLKXPOL BIT(7) /* * DAVINCI_MCASP_ACLKRCTL_REG Receive Clock Control Register Bits */ #define ACLKRDIV(val) (val) #define ACLKRE BIT(5) #define RX_ASYNC BIT(6) #define ACLKRPOL BIT(7) /* * DAVINCI_MCASP_AHCLKXCTL_REG - High Frequency Transmit Clock Control * Register Bits */ #define AHCLKXDIV(val) (val) #define AHCLKXPOL BIT(14) #define AHCLKXE BIT(15) /* * DAVINCI_MCASP_AHCLKRCTL_REG - High Frequency Receive Clock Control * Register Bits */ #define AHCLKRDIV(val) (val) #define AHCLKRPOL BIT(14) #define AHCLKRE BIT(15) /* * DAVINCI_MCASP_XRSRCTL_BASE_REG - Serializer Control Register Bits */ #define MODE(val) (val) #define DISMOD (val)(val<<2) #define TXSTATE BIT(4) #define RXSTATE BIT(5) /* * DAVINCI_MCASP_LBCTL_REG - Loop Back Control Register Bits */ #define LBEN BIT(0) #define LBORD BIT(1) #define LBGENMODE(val) (val<<2) /* * DAVINCI_MCASP_TXTDMSLOT_REG - Transmit TDM Slot Register configuration */ #define TXTDMS(n) (1<<n) /* * DAVINCI_MCASP_RXTDMSLOT_REG - Receive TDM Slot Register configuration */ #define RXTDMS(n) (1<<n) /* * DAVINCI_MCASP_GBLCTL_REG - Global Control Register Bits */ #define RXCLKRST BIT(0) /* Receiver Clock Divider Reset */ #define RXHCLKRST BIT(1) /* Receiver High Frequency Clock Divider */ #define RXSERCLR BIT(2) /* Receiver Serializer Clear */ #define RXSMRST BIT(3) /* Receiver State Machine Reset */ #define RXFSRST BIT(4) /* Frame Sync Generator Reset */ #define TXCLKRST BIT(8) /* Transmitter Clock Divider Reset */ #define TXHCLKRST BIT(9) /* Transmitter High Frequency Clock Divider*/ #define TXSERCLR BIT(10) /* Transmit Serializer Clear */ #define TXSMRST BIT(11) /* Transmitter State Machine Reset */ #define TXFSRST BIT(12) /* Frame Sync Generator Reset */ /* * DAVINCI_MCASP_AMUTE_REG - Mute Control Register Bits */ #define MUTENA(val) (val) #define MUTEINPOL BIT(2) #define MUTEINENA BIT(3) #define MUTEIN BIT(4) #define MUTER BIT(5) #define MUTEX BIT(6) #define MUTEFSR BIT(7) #define MUTEFSX BIT(8) #define MUTEBADCLKR BIT(9) #define MUTEBADCLKX BIT(10) #define MUTERXDMAERR BIT(11) #define MUTETXDMAERR BIT(12) /* * DAVINCI_MCASP_REVTCTL_REG - Receiver DMA Event Control Register bits */ #define RXDATADMADIS BIT(0) /* * DAVINCI_MCASP_XEVTCTL_REG - Transmitter DMA Event Control Register bits */ #define TXDATADMADIS BIT(0) /* * DAVINCI_MCASP_W[R]FIFOCTL - Write/Read FIFO Control Register bits */ #define FIFO_ENABLE BIT(16) #define NUMEVT_MASK (0xFF << 8) #define NUMDMA_MASK (0xFF) #define DAVINCI_MCASP_NUM_SERIALIZER 16 static inline void mcasp_set_bits(void __iomem *reg, u32 val) { __raw_writel(__raw_readl(reg) | val, reg); } static inline void mcasp_clr_bits(void __iomem *reg, u32 val) { __raw_writel((__raw_readl(reg) & ~(val)), reg); } static inline void mcasp_mod_bits(void __iomem *reg, u32 val, u32 mask) { __raw_writel((__raw_readl(reg) & ~mask) | val, reg); } static inline void mcasp_set_reg(void __iomem *reg, u32 val) { __raw_writel(val, reg); } static inline u32 mcasp_get_reg(void __iomem *reg) { return (unsigned int)__raw_readl(reg); } static inline void mcasp_set_ctl_reg(void __iomem *regs, u32 val) { int i = 0; mcasp_set_bits(regs, val); /* programming GBLCTL needs to read back from GBLCTL and verfiy */ /* loop count is to avoid the lock-up */ for (i = 0; i < 1000; i++) { if ((mcasp_get_reg(regs) & val) == val) break; } if (i == 1000 && ((mcasp_get_reg(regs) & val) != val)) printk(KERN_ERR "GBLCTL write error\n"); } static void mcasp_start_rx(struct davinci_audio_dev *dev) { mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST); mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXCLKRST); mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXSERCLR); mcasp_set_reg(dev->base + DAVINCI_MCASP_RXBUF_REG, 0); mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXSMRST); mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXFSRST); mcasp_set_reg(dev->base + DAVINCI_MCASP_RXBUF_REG, 0); mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXSMRST); mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXFSRST); } static void mcasp_start_tx(struct davinci_audio_dev *dev) { u8 offset = 0, i; u32 cnt; mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST); mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST); mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXSERCLR); mcasp_set_reg(dev->base + DAVINCI_MCASP_TXBUF_REG, 0); mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXSMRST); mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXFSRST); mcasp_set_reg(dev->base + DAVINCI_MCASP_TXBUF_REG, 0); for (i = 0; i < dev->num_serializer; i++) { if (dev->serial_dir[i] == TX_MODE) { offset = i; break; } } /* wait for TX ready */ cnt = 0; while (!(mcasp_get_reg(dev->base + DAVINCI_MCASP_XRSRCTL_REG(offset)) & TXSTATE) && (cnt < 100000)) cnt++; mcasp_set_reg(dev->base + DAVINCI_MCASP_TXBUF_REG, 0); } static void davinci_mcasp_start(struct davinci_audio_dev *dev, int stream) { if (stream == SNDRV_PCM_STREAM_PLAYBACK) { if (dev->txnumevt) /* enable FIFO */ mcasp_set_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE); mcasp_start_tx(dev); } else { if (dev->rxnumevt) /* enable FIFO */ mcasp_set_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE); mcasp_start_rx(dev); } } static void mcasp_stop_rx(struct davinci_audio_dev *dev) { mcasp_set_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, 0); mcasp_set_reg(dev->base + DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); } static void mcasp_stop_tx(struct davinci_audio_dev *dev) { mcasp_set_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, 0); mcasp_set_reg(dev->base + DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF); } static void davinci_mcasp_stop(struct davinci_audio_dev *dev, int stream) { if (stream == SNDRV_PCM_STREAM_PLAYBACK) { if (dev->txnumevt) /* disable FIFO */ mcasp_clr_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE); mcasp_stop_tx(dev); } else { if (dev->rxnumevt) /* disable FIFO */ mcasp_clr_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE); mcasp_stop_rx(dev); } } static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) { struct davinci_audio_dev *dev = cpu_dai->private_data; void __iomem *base = dev->base; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBS_CFS: /* codec is clock and frame slave */ mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE); mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE); mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, (0x7 << 26)); break; case SND_SOC_DAIFMT_CBM_CFS: /* codec is clock master and frame slave */ mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE); mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE); mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, (0x2d << 26)); break; case SND_SOC_DAIFMT_CBM_CFM: /* codec is clock and frame master */ mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE); mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE); mcasp_clr_bits(base + DAVINCI_MCASP_PDIR_REG, (0x3f << 26)); break; default: return -EINVAL; } switch (fmt & SND_SOC_DAIFMT_INV_MASK) { case SND_SOC_DAIFMT_IB_NF: mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); break; case SND_SOC_DAIFMT_NB_IF: mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); break; case SND_SOC_DAIFMT_IB_IF: mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); break; case SND_SOC_DAIFMT_NB_NF: mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); break; default: return -EINVAL; } return 0; } static int davinci_config_channel_size(struct davinci_audio_dev *dev, int channel_size) { u32 fmt = 0; u32 mask, rotate; switch (channel_size) { case DAVINCI_AUDIO_WORD_8: fmt = 0x03; rotate = 6; mask = 0x000000ff; break; case DAVINCI_AUDIO_WORD_12: fmt = 0x05; rotate = 5; mask = 0x00000fff; break; case DAVINCI_AUDIO_WORD_16: fmt = 0x07; rotate = 4; mask = 0x0000ffff; break; case DAVINCI_AUDIO_WORD_20: fmt = 0x09; rotate = 3; mask = 0x000fffff; break; case DAVINCI_AUDIO_WORD_24: fmt = 0x0B; rotate = 2; mask = 0x00ffffff; break; case DAVINCI_AUDIO_WORD_28: fmt = 0x0D; rotate = 1; mask = 0x0fffffff; break; case DAVINCI_AUDIO_WORD_32: fmt = 0x0F; rotate = 0; mask = 0xffffffff; break; default: return -EINVAL; } mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, RXSSZ(fmt), RXSSZ(0x0F)); mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, TXSSZ(fmt), TXSSZ(0x0F)); mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, TXROT(rotate), TXROT(7)); mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, RXROT(rotate), RXROT(7)); mcasp_set_reg(dev->base + DAVINCI_MCASP_TXMASK_REG, mask); mcasp_set_reg(dev->base + DAVINCI_MCASP_RXMASK_REG, mask); return 0; } static void davinci_hw_common_param(struct davinci_audio_dev *dev, int stream) { int i; u8 tx_ser = 0; u8 rx_ser = 0; /* Default configuration */ mcasp_set_bits(dev->base + DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT); /* All PINS as McASP */ mcasp_set_reg(dev->base + DAVINCI_MCASP_PFUNC_REG, 0x00000000); if (stream == SNDRV_PCM_STREAM_PLAYBACK) { mcasp_set_reg(dev->base + DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF); mcasp_clr_bits(dev->base + DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS); } else { mcasp_set_reg(dev->base + DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); mcasp_clr_bits(dev->base + DAVINCI_MCASP_REVTCTL_REG, RXDATADMADIS); } for (i = 0; i < dev->num_serializer; i++) { mcasp_set_bits(dev->base + DAVINCI_MCASP_XRSRCTL_REG(i), dev->serial_dir[i]); if (dev->serial_dir[i] == TX_MODE) { mcasp_set_bits(dev->base + DAVINCI_MCASP_PDIR_REG, AXR(i)); tx_ser++; } else if (dev->serial_dir[i] == RX_MODE) { mcasp_clr_bits(dev->base + DAVINCI_MCASP_PDIR_REG, AXR(i)); rx_ser++; } } if (dev->txnumevt && stream == SNDRV_PCM_STREAM_PLAYBACK) { if (dev->txnumevt * tx_ser > 64) dev->txnumevt = 1; mcasp_mod_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, tx_ser, NUMDMA_MASK); mcasp_mod_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, ((dev->txnumevt * tx_ser) << 8), NUMEVT_MASK); } if (dev->rxnumevt && stream == SNDRV_PCM_STREAM_CAPTURE) { if (dev->rxnumevt * rx_ser > 64) dev->rxnumevt = 1; mcasp_mod_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, rx_ser, NUMDMA_MASK); mcasp_mod_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, ((dev->rxnumevt * rx_ser) << 8), NUMEVT_MASK); } } static void davinci_hw_param(struct davinci_audio_dev *dev, int stream) { int i, active_slots; u32 mask = 0; active_slots = (dev->tdm_slots > 31) ? 32 : dev->tdm_slots; for (i = 0; i < active_slots; i++) mask |= (1 << i); mcasp_clr_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC); if (stream == SNDRV_PCM_STREAM_PLAYBACK) { /* bit stream is MSB first with no delay */ /* DSP_B mode */ mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE); mcasp_set_reg(dev->base + DAVINCI_MCASP_TXTDM_REG, mask); mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, TXORD); if ((dev->tdm_slots >= 2) || (dev->tdm_slots <= 32)) mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, FSXMOD(dev->tdm_slots), FSXMOD(0x1FF)); else printk(KERN_ERR "playback tdm slot %d not supported\n", dev->tdm_slots); mcasp_clr_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR); } else { /* bit stream is MSB first with no delay */ /* DSP_B mode */ mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, RXORD); mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); mcasp_set_reg(dev->base + DAVINCI_MCASP_RXTDM_REG, mask); if ((dev->tdm_slots >= 2) || (dev->tdm_slots <= 32)) mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, FSRMOD(dev->tdm_slots), FSRMOD(0x1FF)); else printk(KERN_ERR "capture tdm slot %d not supported\n", dev->tdm_slots); mcasp_clr_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR); } } /* S/PDIF */ static void davinci_hw_dit_param(struct davinci_audio_dev *dev) { /* Set the PDIR for Serialiser as output */ mcasp_set_bits(dev->base + DAVINCI_MCASP_PDIR_REG, AFSX); /* TXMASK for 24 bits */ mcasp_set_reg(dev->base + DAVINCI_MCASP_TXMASK_REG, 0x00FFFFFF); /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0 and LSB first */ mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, TXROT(6) | TXSSZ(15)); /* Set TX frame synch : DIT Mode, 1 bit width, internal, rising edge */ mcasp_set_reg(dev->base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE | FSXMOD(0x180)); /* Set the TX tdm : for all the slots */ mcasp_set_reg(dev->base + DAVINCI_MCASP_TXTDM_REG, 0xFFFFFFFF); /* Set the TX clock controls : div = 1 and internal */ mcasp_set_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE | TX_ASYNC); mcasp_clr_bits(dev->base + DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS); /* Only 44100 and 48000 are valid, both have the same setting */ mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXDIV(3)); /* Enable the DIT */ mcasp_set_bits(dev->base + DAVINCI_MCASP_TXDITCTL_REG, DITEN); } static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *cpu_dai) { struct davinci_audio_dev *dev = cpu_dai->private_data; struct davinci_pcm_dma_params *dma_params = &dev->dma_params[substream->stream]; int word_length; u8 fifo_level; davinci_hw_common_param(dev, substream->stream); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) fifo_level = dev->txnumevt; else fifo_level = dev->rxnumevt; if (dev->op_mode == DAVINCI_MCASP_DIT_MODE) davinci_hw_dit_param(dev); else davinci_hw_param(dev, substream->stream); switch (params_format(params)) { case SNDRV_PCM_FORMAT_S8: dma_params->data_type = 1; word_length = DAVINCI_AUDIO_WORD_8; break; case SNDRV_PCM_FORMAT_S16_LE: dma_params->data_type = 2; word_length = DAVINCI_AUDIO_WORD_16; break; case SNDRV_PCM_FORMAT_S32_LE: dma_params->data_type = 4; word_length = DAVINCI_AUDIO_WORD_32; break; default: printk(KERN_WARNING "davinci-mcasp: unsupported PCM format"); return -EINVAL; } if (dev->version == MCASP_VERSION_2 && !fifo_level) dma_params->acnt = 4; else dma_params->acnt = dma_params->data_type; dma_params->fifo_level = fifo_level; davinci_config_channel_size(dev, word_length); return 0; } static int davinci_mcasp_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *cpu_dai) { struct snd_soc_pcm_runtime *rtd = substream->private_data; struct davinci_audio_dev *dev = rtd->dai->cpu_dai->private_data; int ret = 0; switch (cmd) { case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: if (!dev->clk_active) { clk_enable(dev->clk); dev->clk_active = 1; } davinci_mcasp_start(dev, substream->stream); break; case SNDRV_PCM_TRIGGER_SUSPEND: davinci_mcasp_stop(dev, substream->stream); if (dev->clk_active) { clk_disable(dev->clk); dev->clk_active = 0; } break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: davinci_mcasp_stop(dev, substream->stream); break; default: ret = -EINVAL; } return ret; } static struct snd_soc_dai_ops davinci_mcasp_dai_ops = { .trigger = davinci_mcasp_trigger, .hw_params = davinci_mcasp_hw_params, .set_fmt = davinci_mcasp_set_dai_fmt, }; struct snd_soc_dai davinci_mcasp_dai[] = { { .name = "davinci-i2s", .id = 0, .playback = { .channels_min = 2, .channels_max = 2, .rates = DAVINCI_MCASP_RATES, .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, }, .capture = { .channels_min = 2, .channels_max = 2, .rates = DAVINCI_MCASP_RATES, .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, }, .ops = &davinci_mcasp_dai_ops, }, { .name = "davinci-dit", .id = 1, .playback = { .channels_min = 1, .channels_max = 384, .rates = DAVINCI_MCASP_RATES, .formats = SNDRV_PCM_FMTBIT_S16_LE, }, .ops = &davinci_mcasp_dai_ops, }, }; EXPORT_SYMBOL_GPL(davinci_mcasp_dai); static int davinci_mcasp_probe(struct platform_device *pdev) { struct davinci_pcm_dma_params *dma_data; struct resource *mem, *ioarea, *res; struct snd_platform_data *pdata; struct davinci_audio_dev *dev; int ret = 0; dev = kzalloc(sizeof(struct davinci_audio_dev), GFP_KERNEL); if (!dev) return -ENOMEM; mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!mem) { dev_err(&pdev->dev, "no mem resource?\n"); ret = -ENODEV; goto err_release_data; } ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1, pdev->name); if (!ioarea) { dev_err(&pdev->dev, "Audio region already claimed\n"); ret = -EBUSY; goto err_release_data; } pdata = pdev->dev.platform_data; dev->clk = clk_get(&pdev->dev, NULL); if (IS_ERR(dev->clk)) { ret = -ENODEV; goto err_release_region; } clk_enable(dev->clk); dev->clk_active = 1; dev->base = (void __iomem *)IO_ADDRESS(mem->start); dev->op_mode = pdata->op_mode; dev->tdm_slots = pdata->tdm_slots; dev->num_serializer = pdata->num_serializer; dev->serial_dir = pdata->serial_dir; dev->codec_fmt = pdata->codec_fmt; dev->version = pdata->version; dev->txnumevt = pdata->txnumevt; dev->rxnumevt = pdata->rxnumevt; dma_data = &dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]; dma_data->eventq_no = pdata->eventq_no; dma_data->dma_addr = (dma_addr_t) (pdata->tx_dma_offset + io_v2p(dev->base)); /* first TX, then RX */ res = platform_get_resource(pdev, IORESOURCE_DMA, 0); if (!res) { dev_err(&pdev->dev, "no DMA resource\n"); goto err_release_region; } dma_data->channel = res->start; dma_data = &dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]; dma_data->eventq_no = pdata->eventq_no; dma_data->dma_addr = (dma_addr_t)(pdata->rx_dma_offset + io_v2p(dev->base)); res = platform_get_resource(pdev, IORESOURCE_DMA, 1); if (!res) { dev_err(&pdev->dev, "no DMA resource\n"); goto err_release_region; } dma_data->channel = res->start; davinci_mcasp_dai[pdata->op_mode].private_data = dev; davinci_mcasp_dai[pdata->op_mode].capture.dma_data = dev->dma_params; davinci_mcasp_dai[pdata->op_mode].playback.dma_data = dev->dma_params; davinci_mcasp_dai[pdata->op_mode].dev = &pdev->dev; ret = snd_soc_register_dai(&davinci_mcasp_dai[pdata->op_mode]); if (ret != 0) goto err_release_region; return 0; err_release_region: release_mem_region(mem->start, (mem->end - mem->start) + 1); err_release_data: kfree(dev); return ret; } static int davinci_mcasp_remove(struct platform_device *pdev) { struct snd_platform_data *pdata = pdev->dev.platform_data; struct davinci_audio_dev *dev; struct resource *mem; snd_soc_unregister_dai(&davinci_mcasp_dai[pdata->op_mode]); dev = davinci_mcasp_dai[pdata->op_mode].private_data; clk_disable(dev->clk); clk_put(dev->clk); dev->clk = NULL; mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); release_mem_region(mem->start, (mem->end - mem->start) + 1); kfree(dev); return 0; } static struct platform_driver davinci_mcasp_driver = { .probe = davinci_mcasp_probe, .remove = davinci_mcasp_remove, .driver = { .name = "davinci-mcasp", .owner = THIS_MODULE, }, }; static int __init davinci_mcasp_init(void) { return platform_driver_register(&davinci_mcasp_driver); } module_init(davinci_mcasp_init); static void __exit davinci_mcasp_exit(void) { platform_driver_unregister(&davinci_mcasp_driver); } module_exit(davinci_mcasp_exit); MODULE_AUTHOR("Steve Chen"); MODULE_DESCRIPTION("TI DAVINCI McASP SoC Interface"); MODULE_LICENSE("GPL");
gpl-2.0
JonnyH/pyra-kernel
drivers/parport/share.c
957
29870
/* * Parallel-port resource manager code. * * Authors: David Campbell <campbell@tirian.che.curtin.edu.au> * Tim Waugh <tim@cyberelk.demon.co.uk> * Jose Renau <renau@acm.org> * Philip Blundell <philb@gnu.org> * Andrea Arcangeli * * based on work by Grant Guenther <grant@torque.net> * and Philip Blundell * * Any part of this program may be used in documents licensed under * the GNU Free Documentation License, Version 1.1 or any later version * published by the Free Software Foundation. */ #undef PARPORT_DEBUG_SHARING /* undef for production */ #include <linux/module.h> #include <linux/string.h> #include <linux/threads.h> #include <linux/parport.h> #include <linux/delay.h> #include <linux/errno.h> #include <linux/interrupt.h> #include <linux/ioport.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/sched.h> #include <linux/kmod.h> #include <linux/spinlock.h> #include <linux/mutex.h> #include <asm/irq.h> #undef PARPORT_PARANOID #define PARPORT_DEFAULT_TIMESLICE (HZ/5) unsigned long parport_default_timeslice = PARPORT_DEFAULT_TIMESLICE; int parport_default_spintime = DEFAULT_SPIN_TIME; static LIST_HEAD(portlist); static DEFINE_SPINLOCK(parportlist_lock); /* list of all allocated ports, sorted by ->number */ static LIST_HEAD(all_ports); static DEFINE_SPINLOCK(full_list_lock); static LIST_HEAD(drivers); static DEFINE_MUTEX(registration_lock); /* What you can do to a port that's gone away.. */ static void dead_write_lines (struct parport *p, unsigned char b){} static unsigned char dead_read_lines (struct parport *p) { return 0; } static unsigned char dead_frob_lines (struct parport *p, unsigned char b, unsigned char c) { return 0; } static void dead_onearg (struct parport *p){} static void dead_initstate (struct pardevice *d, struct parport_state *s) { } static void dead_state (struct parport *p, struct parport_state *s) { } static size_t dead_write (struct parport *p, const void *b, size_t l, int f) { return 0; } static size_t dead_read (struct parport *p, void *b, size_t l, int f) { return 0; } static struct parport_operations dead_ops = { .write_data = dead_write_lines, /* data */ .read_data = dead_read_lines, .write_control = dead_write_lines, /* control */ .read_control = dead_read_lines, .frob_control = dead_frob_lines, .read_status = dead_read_lines, /* status */ .enable_irq = dead_onearg, /* enable_irq */ .disable_irq = dead_onearg, /* disable_irq */ .data_forward = dead_onearg, /* data_forward */ .data_reverse = dead_onearg, /* data_reverse */ .init_state = dead_initstate, /* init_state */ .save_state = dead_state, .restore_state = dead_state, .epp_write_data = dead_write, /* epp */ .epp_read_data = dead_read, .epp_write_addr = dead_write, .epp_read_addr = dead_read, .ecp_write_data = dead_write, /* ecp */ .ecp_read_data = dead_read, .ecp_write_addr = dead_write, .compat_write_data = dead_write, /* compat */ .nibble_read_data = dead_read, /* nibble */ .byte_read_data = dead_read, /* byte */ .owner = NULL, }; /* Call attach(port) for each registered driver. */ static void attach_driver_chain(struct parport *port) { /* caller has exclusive registration_lock */ struct parport_driver *drv; list_for_each_entry(drv, &drivers, list) drv->attach(port); } /* Call detach(port) for each registered driver. */ static void detach_driver_chain(struct parport *port) { struct parport_driver *drv; /* caller has exclusive registration_lock */ list_for_each_entry(drv, &drivers, list) drv->detach (port); } /* Ask kmod for some lowlevel drivers. */ static void get_lowlevel_driver (void) { /* There is no actual module called this: you should set * up an alias for modutils. */ request_module ("parport_lowlevel"); } /** * parport_register_driver - register a parallel port device driver * @drv: structure describing the driver * * This can be called by a parallel port device driver in order * to receive notifications about ports being found in the * system, as well as ports no longer available. * * The @drv structure is allocated by the caller and must not be * deallocated until after calling parport_unregister_driver(). * * The driver's attach() function may block. The port that * attach() is given will be valid for the duration of the * callback, but if the driver wants to take a copy of the * pointer it must call parport_get_port() to do so. Calling * parport_register_device() on that port will do this for you. * * The driver's detach() function may block. The port that * detach() is given will be valid for the duration of the * callback, but if the driver wants to take a copy of the * pointer it must call parport_get_port() to do so. * * Returns 0 on success. Currently it always succeeds. **/ int parport_register_driver (struct parport_driver *drv) { struct parport *port; if (list_empty(&portlist)) get_lowlevel_driver (); mutex_lock(&registration_lock); list_for_each_entry(port, &portlist, list) drv->attach(port); list_add(&drv->list, &drivers); mutex_unlock(&registration_lock); return 0; } /** * parport_unregister_driver - deregister a parallel port device driver * @drv: structure describing the driver that was given to * parport_register_driver() * * This should be called by a parallel port device driver that * has registered itself using parport_register_driver() when it * is about to be unloaded. * * When it returns, the driver's attach() routine will no longer * be called, and for each port that attach() was called for, the * detach() routine will have been called. * * All the driver's attach() and detach() calls are guaranteed to have * finished by the time this function returns. **/ void parport_unregister_driver (struct parport_driver *drv) { struct parport *port; mutex_lock(&registration_lock); list_del_init(&drv->list); list_for_each_entry(port, &portlist, list) drv->detach(port); mutex_unlock(&registration_lock); } static void free_port (struct parport *port) { int d; spin_lock(&full_list_lock); list_del(&port->full_list); spin_unlock(&full_list_lock); for (d = 0; d < 5; d++) { kfree(port->probe_info[d].class_name); kfree(port->probe_info[d].mfr); kfree(port->probe_info[d].model); kfree(port->probe_info[d].cmdset); kfree(port->probe_info[d].description); } kfree(port->name); kfree(port); } /** * parport_get_port - increment a port's reference count * @port: the port * * This ensures that a struct parport pointer remains valid * until the matching parport_put_port() call. **/ struct parport *parport_get_port (struct parport *port) { atomic_inc (&port->ref_count); return port; } /** * parport_put_port - decrement a port's reference count * @port: the port * * This should be called once for each call to parport_get_port(), * once the port is no longer needed. **/ void parport_put_port (struct parport *port) { if (atomic_dec_and_test (&port->ref_count)) /* Can destroy it now. */ free_port (port); return; } /** * parport_register_port - register a parallel port * @base: base I/O address * @irq: IRQ line * @dma: DMA channel * @ops: pointer to the port driver's port operations structure * * When a parallel port (lowlevel) driver finds a port that * should be made available to parallel port device drivers, it * should call parport_register_port(). The @base, @irq, and * @dma parameters are for the convenience of port drivers, and * for ports where they aren't meaningful needn't be set to * anything special. They can be altered afterwards by adjusting * the relevant members of the parport structure that is returned * and represents the port. They should not be tampered with * after calling parport_announce_port, however. * * If there are parallel port device drivers in the system that * have registered themselves using parport_register_driver(), * they are not told about the port at this time; that is done by * parport_announce_port(). * * The @ops structure is allocated by the caller, and must not be * deallocated before calling parport_remove_port(). * * If there is no memory to allocate a new parport structure, * this function will return %NULL. **/ struct parport *parport_register_port(unsigned long base, int irq, int dma, struct parport_operations *ops) { struct list_head *l; struct parport *tmp; int num; int device; char *name; tmp = kzalloc(sizeof(struct parport), GFP_KERNEL); if (!tmp) { printk(KERN_WARNING "parport: memory squeeze\n"); return NULL; } /* Init our structure */ tmp->base = base; tmp->irq = irq; tmp->dma = dma; tmp->muxport = tmp->daisy = tmp->muxsel = -1; tmp->modes = 0; INIT_LIST_HEAD(&tmp->list); tmp->devices = tmp->cad = NULL; tmp->flags = 0; tmp->ops = ops; tmp->physport = tmp; memset (tmp->probe_info, 0, 5 * sizeof (struct parport_device_info)); rwlock_init(&tmp->cad_lock); spin_lock_init(&tmp->waitlist_lock); spin_lock_init(&tmp->pardevice_lock); tmp->ieee1284.mode = IEEE1284_MODE_COMPAT; tmp->ieee1284.phase = IEEE1284_PH_FWD_IDLE; sema_init(&tmp->ieee1284.irq, 0); tmp->spintime = parport_default_spintime; atomic_set (&tmp->ref_count, 1); INIT_LIST_HEAD(&tmp->full_list); name = kmalloc(15, GFP_KERNEL); if (!name) { printk(KERN_ERR "parport: memory squeeze\n"); kfree(tmp); return NULL; } /* Search for the lowest free parport number. */ spin_lock(&full_list_lock); for (l = all_ports.next, num = 0; l != &all_ports; l = l->next, num++) { struct parport *p = list_entry(l, struct parport, full_list); if (p->number != num) break; } tmp->portnum = tmp->number = num; list_add_tail(&tmp->full_list, l); spin_unlock(&full_list_lock); /* * Now that the portnum is known finish doing the Init. */ sprintf(name, "parport%d", tmp->portnum = tmp->number); tmp->name = name; for (device = 0; device < 5; device++) /* assume the worst */ tmp->probe_info[device].class = PARPORT_CLASS_LEGACY; tmp->waithead = tmp->waittail = NULL; return tmp; } /** * parport_announce_port - tell device drivers about a parallel port * @port: parallel port to announce * * After a port driver has registered a parallel port with * parport_register_port, and performed any necessary * initialisation or adjustments, it should call * parport_announce_port() in order to notify all device drivers * that have called parport_register_driver(). Their attach() * functions will be called, with @port as the parameter. **/ void parport_announce_port (struct parport *port) { int i; #ifdef CONFIG_PARPORT_1284 /* Analyse the IEEE1284.3 topology of the port. */ parport_daisy_init(port); #endif if (!port->dev) printk(KERN_WARNING "%s: fix this legacy " "no-device port driver!\n", port->name); parport_proc_register(port); mutex_lock(&registration_lock); spin_lock_irq(&parportlist_lock); list_add_tail(&port->list, &portlist); for (i = 1; i < 3; i++) { struct parport *slave = port->slaves[i-1]; if (slave) list_add_tail(&slave->list, &portlist); } spin_unlock_irq(&parportlist_lock); /* Let drivers know that new port(s) has arrived. */ attach_driver_chain (port); for (i = 1; i < 3; i++) { struct parport *slave = port->slaves[i-1]; if (slave) attach_driver_chain(slave); } mutex_unlock(&registration_lock); } /** * parport_remove_port - deregister a parallel port * @port: parallel port to deregister * * When a parallel port driver is forcibly unloaded, or a * parallel port becomes inaccessible, the port driver must call * this function in order to deal with device drivers that still * want to use it. * * The parport structure associated with the port has its * operations structure replaced with one containing 'null' * operations that return errors or just don't do anything. * * Any drivers that have registered themselves using * parport_register_driver() are notified that the port is no * longer accessible by having their detach() routines called * with @port as the parameter. **/ void parport_remove_port(struct parport *port) { int i; mutex_lock(&registration_lock); /* Spread the word. */ detach_driver_chain (port); #ifdef CONFIG_PARPORT_1284 /* Forget the IEEE1284.3 topology of the port. */ parport_daisy_fini(port); for (i = 1; i < 3; i++) { struct parport *slave = port->slaves[i-1]; if (!slave) continue; detach_driver_chain(slave); parport_daisy_fini(slave); } #endif port->ops = &dead_ops; spin_lock(&parportlist_lock); list_del_init(&port->list); for (i = 1; i < 3; i++) { struct parport *slave = port->slaves[i-1]; if (slave) list_del_init(&slave->list); } spin_unlock(&parportlist_lock); mutex_unlock(&registration_lock); parport_proc_unregister(port); for (i = 1; i < 3; i++) { struct parport *slave = port->slaves[i-1]; if (slave) parport_put_port(slave); } } /** * parport_register_device - register a device on a parallel port * @port: port to which the device is attached * @name: a name to refer to the device * @pf: preemption callback * @kf: kick callback (wake-up) * @irq_func: interrupt handler * @flags: registration flags * @handle: data for callback functions * * This function, called by parallel port device drivers, * declares that a device is connected to a port, and tells the * system all it needs to know. * * The @name is allocated by the caller and must not be * deallocated until the caller calls @parport_unregister_device * for that device. * * The preemption callback function, @pf, is called when this * device driver has claimed access to the port but another * device driver wants to use it. It is given @handle as its * parameter, and should return zero if it is willing for the * system to release the port to another driver on its behalf. * If it wants to keep control of the port it should return * non-zero, and no action will be taken. It is good manners for * the driver to try to release the port at the earliest * opportunity after its preemption callback rejects a preemption * attempt. Note that if a preemption callback is happy for * preemption to go ahead, there is no need to release the port; * it is done automatically. This function may not block, as it * may be called from interrupt context. If the device driver * does not support preemption, @pf can be %NULL. * * The wake-up ("kick") callback function, @kf, is called when * the port is available to be claimed for exclusive access; that * is, parport_claim() is guaranteed to succeed when called from * inside the wake-up callback function. If the driver wants to * claim the port it should do so; otherwise, it need not take * any action. This function may not block, as it may be called * from interrupt context. If the device driver does not want to * be explicitly invited to claim the port in this way, @kf can * be %NULL. * * The interrupt handler, @irq_func, is called when an interrupt * arrives from the parallel port. Note that if a device driver * wants to use interrupts it should use parport_enable_irq(), * and can also check the irq member of the parport structure * representing the port. * * The parallel port (lowlevel) driver is the one that has called * request_irq() and whose interrupt handler is called first. * This handler does whatever needs to be done to the hardware to * acknowledge the interrupt (for PC-style ports there is nothing * special to be done). It then tells the IEEE 1284 code about * the interrupt, which may involve reacting to an IEEE 1284 * event depending on the current IEEE 1284 phase. After this, * it calls @irq_func. Needless to say, @irq_func will be called * from interrupt context, and may not block. * * The %PARPORT_DEV_EXCL flag is for preventing port sharing, and * so should only be used when sharing the port with other device * drivers is impossible and would lead to incorrect behaviour. * Use it sparingly! Normally, @flags will be zero. * * This function returns a pointer to a structure that represents * the device on the port, or %NULL if there is not enough memory * to allocate space for that structure. **/ struct pardevice * parport_register_device(struct parport *port, const char *name, int (*pf)(void *), void (*kf)(void *), void (*irq_func)(void *), int flags, void *handle) { struct pardevice *tmp; if (port->physport->flags & PARPORT_FLAG_EXCL) { /* An exclusive device is registered. */ printk (KERN_DEBUG "%s: no more devices allowed\n", port->name); return NULL; } if (flags & PARPORT_DEV_LURK) { if (!pf || !kf) { printk(KERN_INFO "%s: refused to register lurking device (%s) without callbacks\n", port->name, name); return NULL; } } /* We up our own module reference count, and that of the port on which a device is to be registered, to ensure that neither of us gets unloaded while we sleep in (e.g.) kmalloc. */ if (!try_module_get(port->ops->owner)) { return NULL; } parport_get_port (port); tmp = kmalloc(sizeof(struct pardevice), GFP_KERNEL); if (tmp == NULL) { printk(KERN_WARNING "%s: memory squeeze, couldn't register %s.\n", port->name, name); goto out; } tmp->state = kmalloc(sizeof(struct parport_state), GFP_KERNEL); if (tmp->state == NULL) { printk(KERN_WARNING "%s: memory squeeze, couldn't register %s.\n", port->name, name); goto out_free_pardevice; } tmp->name = name; tmp->port = port; tmp->daisy = -1; tmp->preempt = pf; tmp->wakeup = kf; tmp->private = handle; tmp->flags = flags; tmp->irq_func = irq_func; tmp->waiting = 0; tmp->timeout = 5 * HZ; /* Chain this onto the list */ tmp->prev = NULL; /* * This function must not run from an irq handler so we don' t need * to clear irq on the local CPU. -arca */ spin_lock(&port->physport->pardevice_lock); if (flags & PARPORT_DEV_EXCL) { if (port->physport->devices) { spin_unlock (&port->physport->pardevice_lock); printk (KERN_DEBUG "%s: cannot grant exclusive access for " "device %s\n", port->name, name); goto out_free_all; } port->flags |= PARPORT_FLAG_EXCL; } tmp->next = port->physport->devices; wmb(); /* Make sure that tmp->next is written before it's added to the list; see comments marked 'no locking required' */ if (port->physport->devices) port->physport->devices->prev = tmp; port->physport->devices = tmp; spin_unlock(&port->physport->pardevice_lock); init_waitqueue_head(&tmp->wait_q); tmp->timeslice = parport_default_timeslice; tmp->waitnext = tmp->waitprev = NULL; /* * This has to be run as last thing since init_state may need other * pardevice fields. -arca */ port->ops->init_state(tmp, tmp->state); if (!test_and_set_bit(PARPORT_DEVPROC_REGISTERED, &port->devflags)) { port->proc_device = tmp; parport_device_proc_register(tmp); } return tmp; out_free_all: kfree(tmp->state); out_free_pardevice: kfree(tmp); out: parport_put_port (port); module_put(port->ops->owner); return NULL; } /** * parport_unregister_device - deregister a device on a parallel port * @dev: pointer to structure representing device * * This undoes the effect of parport_register_device(). **/ void parport_unregister_device(struct pardevice *dev) { struct parport *port; #ifdef PARPORT_PARANOID if (dev == NULL) { printk(KERN_ERR "parport_unregister_device: passed NULL\n"); return; } #endif port = dev->port->physport; if (port->proc_device == dev) { port->proc_device = NULL; clear_bit(PARPORT_DEVPROC_REGISTERED, &port->devflags); parport_device_proc_unregister(dev); } if (port->cad == dev) { printk(KERN_DEBUG "%s: %s forgot to release port\n", port->name, dev->name); parport_release (dev); } spin_lock(&port->pardevice_lock); if (dev->next) dev->next->prev = dev->prev; if (dev->prev) dev->prev->next = dev->next; else port->devices = dev->next; if (dev->flags & PARPORT_DEV_EXCL) port->flags &= ~PARPORT_FLAG_EXCL; spin_unlock(&port->pardevice_lock); /* Make sure we haven't left any pointers around in the wait * list. */ spin_lock_irq(&port->waitlist_lock); if (dev->waitprev || dev->waitnext || port->waithead == dev) { if (dev->waitprev) dev->waitprev->waitnext = dev->waitnext; else port->waithead = dev->waitnext; if (dev->waitnext) dev->waitnext->waitprev = dev->waitprev; else port->waittail = dev->waitprev; } spin_unlock_irq(&port->waitlist_lock); kfree(dev->state); kfree(dev); module_put(port->ops->owner); parport_put_port (port); } /** * parport_find_number - find a parallel port by number * @number: parallel port number * * This returns the parallel port with the specified number, or * %NULL if there is none. * * There is an implicit parport_get_port() done already; to throw * away the reference to the port that parport_find_number() * gives you, use parport_put_port(). */ struct parport *parport_find_number (int number) { struct parport *port, *result = NULL; if (list_empty(&portlist)) get_lowlevel_driver (); spin_lock (&parportlist_lock); list_for_each_entry(port, &portlist, list) { if (port->number == number) { result = parport_get_port (port); break; } } spin_unlock (&parportlist_lock); return result; } /** * parport_find_base - find a parallel port by base address * @base: base I/O address * * This returns the parallel port with the specified base * address, or %NULL if there is none. * * There is an implicit parport_get_port() done already; to throw * away the reference to the port that parport_find_base() * gives you, use parport_put_port(). */ struct parport *parport_find_base (unsigned long base) { struct parport *port, *result = NULL; if (list_empty(&portlist)) get_lowlevel_driver (); spin_lock (&parportlist_lock); list_for_each_entry(port, &portlist, list) { if (port->base == base) { result = parport_get_port (port); break; } } spin_unlock (&parportlist_lock); return result; } /** * parport_claim - claim access to a parallel port device * @dev: pointer to structure representing a device on the port * * This function will not block and so can be used from interrupt * context. If parport_claim() succeeds in claiming access to * the port it returns zero and the port is available to use. It * may fail (returning non-zero) if the port is in use by another * driver and that driver is not willing to relinquish control of * the port. **/ int parport_claim(struct pardevice *dev) { struct pardevice *oldcad; struct parport *port = dev->port->physport; unsigned long flags; if (port->cad == dev) { printk(KERN_INFO "%s: %s already owner\n", dev->port->name,dev->name); return 0; } /* Preempt any current device */ write_lock_irqsave (&port->cad_lock, flags); if ((oldcad = port->cad) != NULL) { if (oldcad->preempt) { if (oldcad->preempt(oldcad->private)) goto blocked; port->ops->save_state(port, dev->state); } else goto blocked; if (port->cad != oldcad) { /* I think we'll actually deadlock rather than get here, but just in case.. */ printk(KERN_WARNING "%s: %s released port when preempted!\n", port->name, oldcad->name); if (port->cad) goto blocked; } } /* Can't fail from now on, so mark ourselves as no longer waiting. */ if (dev->waiting & 1) { dev->waiting = 0; /* Take ourselves out of the wait list again. */ spin_lock_irq (&port->waitlist_lock); if (dev->waitprev) dev->waitprev->waitnext = dev->waitnext; else port->waithead = dev->waitnext; if (dev->waitnext) dev->waitnext->waitprev = dev->waitprev; else port->waittail = dev->waitprev; spin_unlock_irq (&port->waitlist_lock); dev->waitprev = dev->waitnext = NULL; } /* Now we do the change of devices */ port->cad = dev; #ifdef CONFIG_PARPORT_1284 /* If it's a mux port, select it. */ if (dev->port->muxport >= 0) { /* FIXME */ port->muxsel = dev->port->muxport; } /* If it's a daisy chain device, select it. */ if (dev->daisy >= 0) { /* This could be lazier. */ if (!parport_daisy_select (port, dev->daisy, IEEE1284_MODE_COMPAT)) port->daisy = dev->daisy; } #endif /* IEEE1284.3 support */ /* Restore control registers */ port->ops->restore_state(port, dev->state); write_unlock_irqrestore(&port->cad_lock, flags); dev->time = jiffies; return 0; blocked: /* If this is the first time we tried to claim the port, register an interest. This is only allowed for devices sleeping in parport_claim_or_block(), or those with a wakeup function. */ /* The cad_lock is still held for writing here */ if (dev->waiting & 2 || dev->wakeup) { spin_lock (&port->waitlist_lock); if (test_and_set_bit(0, &dev->waiting) == 0) { /* First add ourselves to the end of the wait list. */ dev->waitnext = NULL; dev->waitprev = port->waittail; if (port->waittail) { port->waittail->waitnext = dev; port->waittail = dev; } else port->waithead = port->waittail = dev; } spin_unlock (&port->waitlist_lock); } write_unlock_irqrestore (&port->cad_lock, flags); return -EAGAIN; } /** * parport_claim_or_block - claim access to a parallel port device * @dev: pointer to structure representing a device on the port * * This behaves like parport_claim(), but will block if necessary * to wait for the port to be free. A return value of 1 * indicates that it slept; 0 means that it succeeded without * needing to sleep. A negative error code indicates failure. **/ int parport_claim_or_block(struct pardevice *dev) { int r; /* Signal to parport_claim() that we can wait even without a wakeup function. */ dev->waiting = 2; /* Try to claim the port. If this fails, we need to sleep. */ r = parport_claim(dev); if (r == -EAGAIN) { #ifdef PARPORT_DEBUG_SHARING printk(KERN_DEBUG "%s: parport_claim() returned -EAGAIN\n", dev->name); #endif /* * FIXME!!! Use the proper locking for dev->waiting, * and make this use the "wait_event_interruptible()" * interfaces. The cli/sti that used to be here * did nothing. * * See also parport_release() */ /* If dev->waiting is clear now, an interrupt gave us the port and we would deadlock if we slept. */ if (dev->waiting) { wait_event_interruptible(dev->wait_q, !dev->waiting); if (signal_pending (current)) { return -EINTR; } r = 1; } else { r = 0; #ifdef PARPORT_DEBUG_SHARING printk(KERN_DEBUG "%s: didn't sleep in parport_claim_or_block()\n", dev->name); #endif } #ifdef PARPORT_DEBUG_SHARING if (dev->port->physport->cad != dev) printk(KERN_DEBUG "%s: exiting parport_claim_or_block " "but %s owns port!\n", dev->name, dev->port->physport->cad ? dev->port->physport->cad->name:"nobody"); #endif } dev->waiting = 0; return r; } /** * parport_release - give up access to a parallel port device * @dev: pointer to structure representing parallel port device * * This function cannot fail, but it should not be called without * the port claimed. Similarly, if the port is already claimed * you should not try claiming it again. **/ void parport_release(struct pardevice *dev) { struct parport *port = dev->port->physport; struct pardevice *pd; unsigned long flags; /* Make sure that dev is the current device */ write_lock_irqsave(&port->cad_lock, flags); if (port->cad != dev) { write_unlock_irqrestore (&port->cad_lock, flags); printk(KERN_WARNING "%s: %s tried to release parport " "when not owner\n", port->name, dev->name); return; } #ifdef CONFIG_PARPORT_1284 /* If this is on a mux port, deselect it. */ if (dev->port->muxport >= 0) { /* FIXME */ port->muxsel = -1; } /* If this is a daisy device, deselect it. */ if (dev->daisy >= 0) { parport_daisy_deselect_all (port); port->daisy = -1; } #endif port->cad = NULL; write_unlock_irqrestore(&port->cad_lock, flags); /* Save control registers */ port->ops->save_state(port, dev->state); /* If anybody is waiting, find out who's been there longest and then wake them up. (Note: no locking required) */ /* !!! LOCKING IS NEEDED HERE */ for (pd = port->waithead; pd; pd = pd->waitnext) { if (pd->waiting & 2) { /* sleeping in claim_or_block */ parport_claim(pd); if (waitqueue_active(&pd->wait_q)) wake_up_interruptible(&pd->wait_q); return; } else if (pd->wakeup) { pd->wakeup(pd->private); if (dev->port->cad) /* racy but no matter */ return; } else { printk(KERN_ERR "%s: don't know how to wake %s\n", port->name, pd->name); } } /* Nobody was waiting, so walk the list to see if anyone is interested in being woken up. (Note: no locking required) */ /* !!! LOCKING IS NEEDED HERE */ for (pd = port->devices; (port->cad == NULL) && pd; pd = pd->next) { if (pd->wakeup && pd != dev) pd->wakeup(pd->private); } } irqreturn_t parport_irq_handler(int irq, void *dev_id) { struct parport *port = dev_id; parport_generic_irq(port); return IRQ_HANDLED; } /* Exported symbols for modules. */ EXPORT_SYMBOL(parport_claim); EXPORT_SYMBOL(parport_claim_or_block); EXPORT_SYMBOL(parport_release); EXPORT_SYMBOL(parport_register_port); EXPORT_SYMBOL(parport_announce_port); EXPORT_SYMBOL(parport_remove_port); EXPORT_SYMBOL(parport_register_driver); EXPORT_SYMBOL(parport_unregister_driver); EXPORT_SYMBOL(parport_register_device); EXPORT_SYMBOL(parport_unregister_device); EXPORT_SYMBOL(parport_get_port); EXPORT_SYMBOL(parport_put_port); EXPORT_SYMBOL(parport_find_number); EXPORT_SYMBOL(parport_find_base); EXPORT_SYMBOL(parport_irq_handler); MODULE_LICENSE("GPL");
gpl-2.0
dblessing/linux
drivers/usb/core/hcd-pci.c
957
17649
/* * (C) Copyright David Brownell 2000-2002 * * 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/pci.h> #include <linux/usb.h> #include <linux/usb/hcd.h> #include <asm/io.h> #include <asm/irq.h> #ifdef CONFIG_PPC_PMAC #include <asm/machdep.h> #include <asm/pmac_feature.h> #include <asm/pci-bridge.h> #include <asm/prom.h> #endif #include "usb.h" /* PCI-based HCs are common, but plenty of non-PCI HCs are used too */ /* * Coordinate handoffs between EHCI and companion controllers * during EHCI probing and system resume. */ static DECLARE_RWSEM(companions_rwsem); #define CL_UHCI PCI_CLASS_SERIAL_USB_UHCI #define CL_OHCI PCI_CLASS_SERIAL_USB_OHCI #define CL_EHCI PCI_CLASS_SERIAL_USB_EHCI static inline int is_ohci_or_uhci(struct pci_dev *pdev) { return pdev->class == CL_OHCI || pdev->class == CL_UHCI; } typedef void (*companion_fn)(struct pci_dev *pdev, struct usb_hcd *hcd, struct pci_dev *companion, struct usb_hcd *companion_hcd); /* Iterate over PCI devices in the same slot as pdev and call fn for each */ static void for_each_companion(struct pci_dev *pdev, struct usb_hcd *hcd, companion_fn fn) { struct pci_dev *companion; struct usb_hcd *companion_hcd; unsigned int slot = PCI_SLOT(pdev->devfn); /* * Iterate through other PCI functions in the same slot. * If the function's drvdata isn't set then it isn't bound to * a USB host controller driver, so skip it. */ companion = NULL; for_each_pci_dev(companion) { if (companion->bus != pdev->bus || PCI_SLOT(companion->devfn) != slot) continue; companion_hcd = pci_get_drvdata(companion); if (!companion_hcd || !companion_hcd->self.root_hub) continue; fn(pdev, hcd, companion, companion_hcd); } } /* * We're about to add an EHCI controller, which will unceremoniously grab * all the port connections away from its companions. To prevent annoying * error messages, lock the companion's root hub and gracefully unconfigure * it beforehand. Leave it locked until the EHCI controller is all set. */ static void ehci_pre_add(struct pci_dev *pdev, struct usb_hcd *hcd, struct pci_dev *companion, struct usb_hcd *companion_hcd) { struct usb_device *udev; if (is_ohci_or_uhci(companion)) { udev = companion_hcd->self.root_hub; usb_lock_device(udev); usb_set_configuration(udev, 0); } } /* * Adding the EHCI controller has either succeeded or failed. Set the * companion pointer accordingly, and in either case, reconfigure and * unlock the root hub. */ static void ehci_post_add(struct pci_dev *pdev, struct usb_hcd *hcd, struct pci_dev *companion, struct usb_hcd *companion_hcd) { struct usb_device *udev; if (is_ohci_or_uhci(companion)) { if (dev_get_drvdata(&pdev->dev)) { /* Succeeded */ dev_dbg(&pdev->dev, "HS companion for %s\n", dev_name(&companion->dev)); companion_hcd->self.hs_companion = &hcd->self; } udev = companion_hcd->self.root_hub; usb_set_configuration(udev, 1); usb_unlock_device(udev); } } /* * We just added a non-EHCI controller. Find the EHCI controller to * which it is a companion, and store a pointer to the bus structure. */ static void non_ehci_add(struct pci_dev *pdev, struct usb_hcd *hcd, struct pci_dev *companion, struct usb_hcd *companion_hcd) { if (is_ohci_or_uhci(pdev) && companion->class == CL_EHCI) { dev_dbg(&pdev->dev, "FS/LS companion for %s\n", dev_name(&companion->dev)); hcd->self.hs_companion = &companion_hcd->self; } } /* We are removing an EHCI controller. Clear the companions' pointers. */ static void ehci_remove(struct pci_dev *pdev, struct usb_hcd *hcd, struct pci_dev *companion, struct usb_hcd *companion_hcd) { if (is_ohci_or_uhci(companion)) companion_hcd->self.hs_companion = NULL; } #ifdef CONFIG_PM /* An EHCI controller must wait for its companions before resuming. */ static void ehci_wait_for_companions(struct pci_dev *pdev, struct usb_hcd *hcd, struct pci_dev *companion, struct usb_hcd *companion_hcd) { if (is_ohci_or_uhci(companion)) device_pm_wait_for_dev(&pdev->dev, &companion->dev); } #endif /* CONFIG_PM */ /*-------------------------------------------------------------------------*/ /* configure so an HC device and id are always provided */ /* always called with process context; sleeping is OK */ /** * usb_hcd_pci_probe - initialize PCI-based HCDs * @dev: USB Host Controller being probed * @id: pci hotplug id connecting controller to HCD framework * Context: !in_interrupt() * * Allocates basic PCI resources for this USB host controller, and * then invokes the start() method for the HCD associated with it * through the hotplug entry's driver_data. * * Store this function in the HCD's struct pci_driver as probe(). * * Return: 0 if successful. */ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { struct hc_driver *driver; struct usb_hcd *hcd; int retval; int hcd_irq = 0; if (usb_disabled()) return -ENODEV; if (!id) return -EINVAL; driver = (struct hc_driver *)id->driver_data; if (!driver) return -EINVAL; if (pci_enable_device(dev) < 0) return -ENODEV; /* * The xHCI driver has its own irq management * make sure irq setup is not touched for xhci in generic hcd code */ if ((driver->flags & HCD_MASK) != HCD_USB3) { if (!dev->irq) { dev_err(&dev->dev, "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", pci_name(dev)); retval = -ENODEV; goto disable_pci; } hcd_irq = dev->irq; } hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); if (!hcd) { retval = -ENOMEM; goto disable_pci; } hcd->amd_resume_bug = (usb_hcd_amd_remote_wakeup_quirk(dev) && driver->flags & (HCD_USB11 | HCD_USB3)) ? 1 : 0; if (driver->flags & HCD_MEMORY) { /* EHCI, OHCI */ hcd->rsrc_start = pci_resource_start(dev, 0); hcd->rsrc_len = pci_resource_len(dev, 0); if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, driver->description)) { dev_dbg(&dev->dev, "controller already in use\n"); retval = -EBUSY; goto put_hcd; } hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); if (hcd->regs == NULL) { dev_dbg(&dev->dev, "error mapping memory\n"); retval = -EFAULT; goto release_mem_region; } } else { /* UHCI */ int region; for (region = 0; region < PCI_ROM_RESOURCE; region++) { if (!(pci_resource_flags(dev, region) & IORESOURCE_IO)) continue; hcd->rsrc_start = pci_resource_start(dev, region); hcd->rsrc_len = pci_resource_len(dev, region); if (request_region(hcd->rsrc_start, hcd->rsrc_len, driver->description)) break; } if (region == PCI_ROM_RESOURCE) { dev_dbg(&dev->dev, "no i/o regions available\n"); retval = -EBUSY; goto put_hcd; } } pci_set_master(dev); /* Note: dev_set_drvdata must be called while holding the rwsem */ if (dev->class == CL_EHCI) { down_write(&companions_rwsem); dev_set_drvdata(&dev->dev, hcd); for_each_companion(dev, hcd, ehci_pre_add); retval = usb_add_hcd(hcd, hcd_irq, IRQF_SHARED); if (retval != 0) dev_set_drvdata(&dev->dev, NULL); for_each_companion(dev, hcd, ehci_post_add); up_write(&companions_rwsem); } else { down_read(&companions_rwsem); dev_set_drvdata(&dev->dev, hcd); retval = usb_add_hcd(hcd, hcd_irq, IRQF_SHARED); if (retval != 0) dev_set_drvdata(&dev->dev, NULL); else for_each_companion(dev, hcd, non_ehci_add); up_read(&companions_rwsem); } if (retval != 0) goto unmap_registers; device_wakeup_enable(hcd->self.controller); if (pci_dev_run_wake(dev)) pm_runtime_put_noidle(&dev->dev); return retval; unmap_registers: if (driver->flags & HCD_MEMORY) { iounmap(hcd->regs); release_mem_region: release_mem_region(hcd->rsrc_start, hcd->rsrc_len); } else release_region(hcd->rsrc_start, hcd->rsrc_len); put_hcd: usb_put_hcd(hcd); disable_pci: pci_disable_device(dev); dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); return retval; } EXPORT_SYMBOL_GPL(usb_hcd_pci_probe); /* may be called without controller electrically present */ /* may be called with controller, bus, and devices active */ /** * usb_hcd_pci_remove - shutdown processing for PCI-based HCDs * @dev: USB Host Controller being removed * Context: !in_interrupt() * * Reverses the effect of usb_hcd_pci_probe(), first invoking * the HCD's stop() method. It is always called from a thread * context, normally "rmmod", "apmd", or something similar. * * Store this function in the HCD's struct pci_driver as remove(). */ void usb_hcd_pci_remove(struct pci_dev *dev) { struct usb_hcd *hcd; hcd = pci_get_drvdata(dev); if (!hcd) return; if (pci_dev_run_wake(dev)) pm_runtime_get_noresume(&dev->dev); /* Fake an interrupt request in order to give the driver a chance * to test whether the controller hardware has been removed (e.g., * cardbus physical eject). */ local_irq_disable(); usb_hcd_irq(0, hcd); local_irq_enable(); /* Note: dev_set_drvdata must be called while holding the rwsem */ if (dev->class == CL_EHCI) { down_write(&companions_rwsem); for_each_companion(dev, hcd, ehci_remove); usb_remove_hcd(hcd); dev_set_drvdata(&dev->dev, NULL); up_write(&companions_rwsem); } else { /* Not EHCI; just clear the companion pointer */ down_read(&companions_rwsem); hcd->self.hs_companion = NULL; usb_remove_hcd(hcd); dev_set_drvdata(&dev->dev, NULL); up_read(&companions_rwsem); } if (hcd->driver->flags & HCD_MEMORY) { iounmap(hcd->regs); release_mem_region(hcd->rsrc_start, hcd->rsrc_len); } else { release_region(hcd->rsrc_start, hcd->rsrc_len); } usb_put_hcd(hcd); pci_disable_device(dev); } EXPORT_SYMBOL_GPL(usb_hcd_pci_remove); /** * usb_hcd_pci_shutdown - shutdown host controller * @dev: USB Host Controller being shutdown */ void usb_hcd_pci_shutdown(struct pci_dev *dev) { struct usb_hcd *hcd; hcd = pci_get_drvdata(dev); if (!hcd) return; if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && hcd->driver->shutdown) { hcd->driver->shutdown(hcd); if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0) free_irq(hcd->irq, hcd); pci_disable_device(dev); } } EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown); #ifdef CONFIG_PM #ifdef CONFIG_PPC_PMAC static void powermac_set_asic(struct pci_dev *pci_dev, int enable) { /* Enanble or disable ASIC clocks for USB */ if (machine_is(powermac)) { struct device_node *of_node; of_node = pci_device_to_OF_node(pci_dev); if (of_node) pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, enable); } } #else static inline void powermac_set_asic(struct pci_dev *pci_dev, int enable) {} #endif /* CONFIG_PPC_PMAC */ static int check_root_hub_suspended(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); struct usb_hcd *hcd = pci_get_drvdata(pci_dev); if (HCD_RH_RUNNING(hcd)) { dev_warn(dev, "Root hub is not suspended\n"); return -EBUSY; } if (hcd->shared_hcd) { hcd = hcd->shared_hcd; if (HCD_RH_RUNNING(hcd)) { dev_warn(dev, "Secondary root hub is not suspended\n"); return -EBUSY; } } return 0; } static int suspend_common(struct device *dev, bool do_wakeup) { struct pci_dev *pci_dev = to_pci_dev(dev); struct usb_hcd *hcd = pci_get_drvdata(pci_dev); int retval; /* Root hub suspend should have stopped all downstream traffic, * and all bus master traffic. And done so for both the interface * and the stub usb_device (which we check here). But maybe it * didn't; writing sysfs power/state files ignores such rules... */ retval = check_root_hub_suspended(dev); if (retval) return retval; if (hcd->driver->pci_suspend && !HCD_DEAD(hcd)) { /* Optimization: Don't suspend if a root-hub wakeup is * pending and it would cause the HCD to wake up anyway. */ if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) return -EBUSY; if (do_wakeup && hcd->shared_hcd && HCD_WAKEUP_PENDING(hcd->shared_hcd)) return -EBUSY; retval = hcd->driver->pci_suspend(hcd, do_wakeup); suspend_report_result(hcd->driver->pci_suspend, retval); /* Check again in case wakeup raced with pci_suspend */ if ((retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) || (retval == 0 && do_wakeup && hcd->shared_hcd && HCD_WAKEUP_PENDING(hcd->shared_hcd))) { if (hcd->driver->pci_resume) hcd->driver->pci_resume(hcd, false); retval = -EBUSY; } if (retval) return retval; } /* If MSI-X is enabled, the driver will have synchronized all vectors * in pci_suspend(). If MSI or legacy PCI is enabled, that will be * synchronized here. */ if (!hcd->msix_enabled) synchronize_irq(pci_dev->irq); /* Downstream ports from this root hub should already be quiesced, so * there will be no DMA activity. Now we can shut down the upstream * link (except maybe for PME# resume signaling). We'll enter a * low power state during suspend_noirq, if the hardware allows. */ pci_disable_device(pci_dev); return retval; } static int resume_common(struct device *dev, int event) { struct pci_dev *pci_dev = to_pci_dev(dev); struct usb_hcd *hcd = pci_get_drvdata(pci_dev); int retval; if (HCD_RH_RUNNING(hcd) || (hcd->shared_hcd && HCD_RH_RUNNING(hcd->shared_hcd))) { dev_dbg(dev, "can't resume, not suspended!\n"); return 0; } retval = pci_enable_device(pci_dev); if (retval < 0) { dev_err(dev, "can't re-enable after resume, %d!\n", retval); return retval; } pci_set_master(pci_dev); if (hcd->driver->pci_resume && !HCD_DEAD(hcd)) { /* * Only EHCI controllers have to wait for their companions. * No locking is needed because PCI controller drivers do not * get unbound during system resume. */ if (pci_dev->class == CL_EHCI && event != PM_EVENT_AUTO_RESUME) for_each_companion(pci_dev, hcd, ehci_wait_for_companions); retval = hcd->driver->pci_resume(hcd, event == PM_EVENT_RESTORE); if (retval) { dev_err(dev, "PCI post-resume error %d!\n", retval); if (hcd->shared_hcd) usb_hc_died(hcd->shared_hcd); usb_hc_died(hcd); } } return retval; } #ifdef CONFIG_PM_SLEEP static int hcd_pci_suspend(struct device *dev) { return suspend_common(dev, device_may_wakeup(dev)); } static int hcd_pci_suspend_noirq(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); struct usb_hcd *hcd = pci_get_drvdata(pci_dev); int retval; retval = check_root_hub_suspended(dev); if (retval) return retval; pci_save_state(pci_dev); /* If the root hub is dead rather than suspended, disallow remote * wakeup. usb_hc_died() should ensure that both hosts are marked as * dying, so we only need to check the primary roothub. */ if (HCD_DEAD(hcd)) device_set_wakeup_enable(dev, 0); dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev)); /* Possibly enable remote wakeup, * choose the appropriate low-power state, and go to that state. */ retval = pci_prepare_to_sleep(pci_dev); if (retval == -EIO) { /* Low-power not supported */ dev_dbg(dev, "--> PCI D0 legacy\n"); retval = 0; } else if (retval == 0) { dev_dbg(dev, "--> PCI %s\n", pci_power_name(pci_dev->current_state)); } else { suspend_report_result(pci_prepare_to_sleep, retval); return retval; } powermac_set_asic(pci_dev, 0); return retval; } static int hcd_pci_resume_noirq(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); powermac_set_asic(pci_dev, 1); /* Go back to D0 and disable remote wakeup */ pci_back_from_sleep(pci_dev); return 0; } static int hcd_pci_resume(struct device *dev) { return resume_common(dev, PM_EVENT_RESUME); } static int hcd_pci_restore(struct device *dev) { return resume_common(dev, PM_EVENT_RESTORE); } #else #define hcd_pci_suspend NULL #define hcd_pci_suspend_noirq NULL #define hcd_pci_resume_noirq NULL #define hcd_pci_resume NULL #define hcd_pci_restore NULL #endif /* CONFIG_PM_SLEEP */ static int hcd_pci_runtime_suspend(struct device *dev) { int retval; retval = suspend_common(dev, true); if (retval == 0) powermac_set_asic(to_pci_dev(dev), 0); dev_dbg(dev, "hcd_pci_runtime_suspend: %d\n", retval); return retval; } static int hcd_pci_runtime_resume(struct device *dev) { int retval; powermac_set_asic(to_pci_dev(dev), 1); retval = resume_common(dev, PM_EVENT_AUTO_RESUME); dev_dbg(dev, "hcd_pci_runtime_resume: %d\n", retval); return retval; } const struct dev_pm_ops usb_hcd_pci_pm_ops = { .suspend = hcd_pci_suspend, .suspend_noirq = hcd_pci_suspend_noirq, .resume_noirq = hcd_pci_resume_noirq, .resume = hcd_pci_resume, .freeze = check_root_hub_suspended, .freeze_noirq = check_root_hub_suspended, .thaw_noirq = NULL, .thaw = NULL, .poweroff = hcd_pci_suspend, .poweroff_noirq = hcd_pci_suspend_noirq, .restore_noirq = hcd_pci_resume_noirq, .restore = hcd_pci_restore, .runtime_suspend = hcd_pci_runtime_suspend, .runtime_resume = hcd_pci_runtime_resume, }; EXPORT_SYMBOL_GPL(usb_hcd_pci_pm_ops); #endif /* CONFIG_PM */
gpl-2.0
adrianguenter/linux-odroidc2
sound/pci/emu10k1/emuproc.c
957
21057
/* * Copyright (c) by Jaroslav Kysela <perex@perex.cz> * Creative Labs, Inc. * Routines for control of EMU10K1 chips / proc interface routines * * Copyright (c) by James Courtier-Dutton <James@superbug.co.uk> * Added EMU 1010 support. * * BUGS: * -- * * TODO: * -- * * 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 <linux/slab.h> #include <linux/init.h> #include <sound/core.h> #include <sound/emu10k1.h> #include "p16v.h" static void snd_emu10k1_proc_spdif_status(struct snd_emu10k1 * emu, struct snd_info_buffer *buffer, char *title, int status_reg, int rate_reg) { static char *clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" }; static int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; static char *channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" }; static char *emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" }; unsigned int status, rate = 0; status = snd_emu10k1_ptr_read(emu, status_reg, 0); snd_iprintf(buffer, "\n%s\n", title); if (status != 0xffffffff) { snd_iprintf(buffer, "Professional Mode : %s\n", (status & SPCS_PROFESSIONAL) ? "yes" : "no"); snd_iprintf(buffer, "Not Audio Data : %s\n", (status & SPCS_NOTAUDIODATA) ? "yes" : "no"); snd_iprintf(buffer, "Copyright : %s\n", (status & SPCS_COPYRIGHT) ? "yes" : "no"); snd_iprintf(buffer, "Emphasis : %s\n", emphasis[(status & SPCS_EMPHASISMASK) >> 3]); snd_iprintf(buffer, "Mode : %i\n", (status & SPCS_MODEMASK) >> 6); snd_iprintf(buffer, "Category Code : 0x%x\n", (status & SPCS_CATEGORYCODEMASK) >> 8); snd_iprintf(buffer, "Generation Status : %s\n", status & SPCS_GENERATIONSTATUS ? "original" : "copy"); snd_iprintf(buffer, "Source Mask : %i\n", (status & SPCS_SOURCENUMMASK) >> 16); snd_iprintf(buffer, "Channel Number : %s\n", channel[(status & SPCS_CHANNELNUMMASK) >> 20]); snd_iprintf(buffer, "Sample Rate : %iHz\n", samplerate[(status & SPCS_SAMPLERATEMASK) >> 24]); snd_iprintf(buffer, "Clock Accuracy : %s\n", clkaccy[(status & SPCS_CLKACCYMASK) >> 28]); if (rate_reg > 0) { rate = snd_emu10k1_ptr_read(emu, rate_reg, 0); snd_iprintf(buffer, "S/PDIF Valid : %s\n", rate & SRCS_SPDIFVALID ? "on" : "off"); snd_iprintf(buffer, "S/PDIF Locked : %s\n", rate & SRCS_SPDIFLOCKED ? "on" : "off"); snd_iprintf(buffer, "Rate Locked : %s\n", rate & SRCS_RATELOCKED ? "on" : "off"); /* From ((Rate * 48000 ) / 262144); */ snd_iprintf(buffer, "Estimated Sample Rate : %d\n", ((rate & 0xFFFFF ) * 375) >> 11); } } else { snd_iprintf(buffer, "No signal detected.\n"); } } static void snd_emu10k1_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { /* FIXME - output names are in emufx.c too */ static char *creative_outs[32] = { /* 00 */ "AC97 Left", /* 01 */ "AC97 Right", /* 02 */ "Optical IEC958 Left", /* 03 */ "Optical IEC958 Right", /* 04 */ "Center", /* 05 */ "LFE", /* 06 */ "Headphone Left", /* 07 */ "Headphone Right", /* 08 */ "Surround Left", /* 09 */ "Surround Right", /* 10 */ "PCM Capture Left", /* 11 */ "PCM Capture Right", /* 12 */ "MIC Capture", /* 13 */ "AC97 Surround Left", /* 14 */ "AC97 Surround Right", /* 15 */ "???", /* 16 */ "???", /* 17 */ "Analog Center", /* 18 */ "Analog LFE", /* 19 */ "???", /* 20 */ "???", /* 21 */ "???", /* 22 */ "???", /* 23 */ "???", /* 24 */ "???", /* 25 */ "???", /* 26 */ "???", /* 27 */ "???", /* 28 */ "???", /* 29 */ "???", /* 30 */ "???", /* 31 */ "???" }; static char *audigy_outs[64] = { /* 00 */ "Digital Front Left", /* 01 */ "Digital Front Right", /* 02 */ "Digital Center", /* 03 */ "Digital LEF", /* 04 */ "Headphone Left", /* 05 */ "Headphone Right", /* 06 */ "Digital Rear Left", /* 07 */ "Digital Rear Right", /* 08 */ "Front Left", /* 09 */ "Front Right", /* 10 */ "Center", /* 11 */ "LFE", /* 12 */ "???", /* 13 */ "???", /* 14 */ "Rear Left", /* 15 */ "Rear Right", /* 16 */ "AC97 Front Left", /* 17 */ "AC97 Front Right", /* 18 */ "ADC Caputre Left", /* 19 */ "ADC Capture Right", /* 20 */ "???", /* 21 */ "???", /* 22 */ "???", /* 23 */ "???", /* 24 */ "???", /* 25 */ "???", /* 26 */ "???", /* 27 */ "???", /* 28 */ "???", /* 29 */ "???", /* 30 */ "???", /* 31 */ "???", /* 32 */ "FXBUS2_0", /* 33 */ "FXBUS2_1", /* 34 */ "FXBUS2_2", /* 35 */ "FXBUS2_3", /* 36 */ "FXBUS2_4", /* 37 */ "FXBUS2_5", /* 38 */ "FXBUS2_6", /* 39 */ "FXBUS2_7", /* 40 */ "FXBUS2_8", /* 41 */ "FXBUS2_9", /* 42 */ "FXBUS2_10", /* 43 */ "FXBUS2_11", /* 44 */ "FXBUS2_12", /* 45 */ "FXBUS2_13", /* 46 */ "FXBUS2_14", /* 47 */ "FXBUS2_15", /* 48 */ "FXBUS2_16", /* 49 */ "FXBUS2_17", /* 50 */ "FXBUS2_18", /* 51 */ "FXBUS2_19", /* 52 */ "FXBUS2_20", /* 53 */ "FXBUS2_21", /* 54 */ "FXBUS2_22", /* 55 */ "FXBUS2_23", /* 56 */ "FXBUS2_24", /* 57 */ "FXBUS2_25", /* 58 */ "FXBUS2_26", /* 59 */ "FXBUS2_27", /* 60 */ "FXBUS2_28", /* 61 */ "FXBUS2_29", /* 62 */ "FXBUS2_30", /* 63 */ "FXBUS2_31" }; struct snd_emu10k1 *emu = entry->private_data; unsigned int val, val1; int nefx = emu->audigy ? 64 : 32; char **outputs = emu->audigy ? audigy_outs : creative_outs; int idx; snd_iprintf(buffer, "EMU10K1\n\n"); snd_iprintf(buffer, "Card : %s\n", emu->audigy ? "Audigy" : (emu->card_capabilities->ecard ? "EMU APS" : "Creative")); snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size); snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", (int)emu->fx8010.etram_pages.bytes / 2); snd_iprintf(buffer, "\n"); snd_iprintf(buffer, "Effect Send Routing :\n"); for (idx = 0; idx < NUM_G; idx++) { val = emu->audigy ? snd_emu10k1_ptr_read(emu, A_FXRT1, idx) : snd_emu10k1_ptr_read(emu, FXRT, idx); val1 = emu->audigy ? snd_emu10k1_ptr_read(emu, A_FXRT2, idx) : 0; if (emu->audigy) { snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i, ", idx, val & 0x3f, (val >> 8) & 0x3f, (val >> 16) & 0x3f, (val >> 24) & 0x3f); snd_iprintf(buffer, "E=%i, F=%i, G=%i, H=%i\n", val1 & 0x3f, (val1 >> 8) & 0x3f, (val1 >> 16) & 0x3f, (val1 >> 24) & 0x3f); } else { snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i\n", idx, (val >> 16) & 0x0f, (val >> 20) & 0x0f, (val >> 24) & 0x0f, (val >> 28) & 0x0f); } } snd_iprintf(buffer, "\nCaptured FX Outputs :\n"); for (idx = 0; idx < nefx; idx++) { if (emu->efx_voices_mask[idx/32] & (1 << (idx%32))) snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]); } snd_iprintf(buffer, "\nAll FX Outputs :\n"); for (idx = 0; idx < (emu->audigy ? 64 : 32); idx++) snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]); } static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_emu10k1 *emu = entry->private_data; u32 value; u32 value2; u32 rate; if (emu->card_capabilities->emu_model) { snd_emu1010_fpga_read(emu, 0x38, &value); if ((value & 0x1) == 0) { snd_emu1010_fpga_read(emu, 0x2a, &value); snd_emu1010_fpga_read(emu, 0x2b, &value2); rate = 0x1770000 / (((value << 5) | value2)+1); snd_iprintf(buffer, "ADAT Locked : %u\n", rate); } else { snd_iprintf(buffer, "ADAT Unlocked\n"); } snd_emu1010_fpga_read(emu, 0x20, &value); if ((value & 0x4) == 0) { snd_emu1010_fpga_read(emu, 0x28, &value); snd_emu1010_fpga_read(emu, 0x29, &value2); rate = 0x1770000 / (((value << 5) | value2)+1); snd_iprintf(buffer, "SPDIF Locked : %d\n", rate); } else { snd_iprintf(buffer, "SPDIF Unlocked\n"); } } else { snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF In", CDCS, CDSRCS); snd_emu10k1_proc_spdif_status(emu, buffer, "Optical or Coax S/PDIF In", GPSCS, GPSRCS); } #if 0 val = snd_emu10k1_ptr_read(emu, ZVSRCS, 0); snd_iprintf(buffer, "\nZoomed Video\n"); snd_iprintf(buffer, "Rate Locked : %s\n", val & SRCS_RATELOCKED ? "on" : "off"); snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", val & SRCS_ESTSAMPLERATE); #endif } static void snd_emu10k1_proc_rates_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { static int samplerate[8] = { 44100, 48000, 96000, 192000, 4, 5, 6, 7 }; struct snd_emu10k1 *emu = entry->private_data; unsigned int val, tmp, n; val = snd_emu10k1_ptr20_read(emu, CAPTURE_RATE_STATUS, 0); tmp = (val >> 16) & 0x8; for (n = 0; n < 4; n++) { tmp = val >> (16 + (n*4)); if (tmp & 0x8) snd_iprintf(buffer, "Channel %d: Rate=%d\n", n, samplerate[tmp & 0x7]); else snd_iprintf(buffer, "Channel %d: No input\n", n); } } static void snd_emu10k1_proc_acode_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { u32 pc; struct snd_emu10k1 *emu = entry->private_data; snd_iprintf(buffer, "FX8010 Instruction List '%s'\n", emu->fx8010.name); snd_iprintf(buffer, " Code dump :\n"); for (pc = 0; pc < (emu->audigy ? 1024 : 512); pc++) { u32 low, high; low = snd_emu10k1_efx_read(emu, pc * 2); high = snd_emu10k1_efx_read(emu, pc * 2 + 1); if (emu->audigy) snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n", (high >> 24) & 0x0f, (high >> 12) & 0x7ff, (high >> 0) & 0x7ff, (low >> 12) & 0x7ff, (low >> 0) & 0x7ff, pc, high, low); else snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n", (high >> 20) & 0x0f, (high >> 10) & 0x3ff, (high >> 0) & 0x3ff, (low >> 10) & 0x3ff, (low >> 0) & 0x3ff, pc, high, low); } } #define TOTAL_SIZE_GPR (0x100*4) #define A_TOTAL_SIZE_GPR (0x200*4) #define TOTAL_SIZE_TANKMEM_DATA (0xa0*4) #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4) #define A_TOTAL_SIZE_TANKMEM_DATA (0x100*4) #define A_TOTAL_SIZE_TANKMEM_ADDR (0x100*4) #define TOTAL_SIZE_CODE (0x200*8) #define A_TOTAL_SIZE_CODE (0x400*8) static ssize_t snd_emu10k1_fx8010_read(struct snd_info_entry *entry, void *file_private_data, struct file *file, char __user *buf, size_t count, loff_t pos) { struct snd_emu10k1 *emu = entry->private_data; unsigned int offset; int tram_addr = 0; unsigned int *tmp; long res; unsigned int idx; if (!strcmp(entry->name, "fx8010_tram_addr")) { offset = TANKMEMADDRREGBASE; tram_addr = 1; } else if (!strcmp(entry->name, "fx8010_tram_data")) { offset = TANKMEMDATAREGBASE; } else if (!strcmp(entry->name, "fx8010_code")) { offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE; } else { offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE; } tmp = kmalloc(count + 8, GFP_KERNEL); if (!tmp) return -ENOMEM; for (idx = 0; idx < ((pos & 3) + count + 3) >> 2; idx++) { unsigned int val; val = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0); if (tram_addr && emu->audigy) { val >>= 11; val |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20; } tmp[idx] = val; } if (copy_to_user(buf, ((char *)tmp) + (pos & 3), count)) res = -EFAULT; else res = count; kfree(tmp); return res; } static void snd_emu10k1_proc_voices_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_emu10k1 *emu = entry->private_data; struct snd_emu10k1_voice *voice; int idx; snd_iprintf(buffer, "ch\tuse\tpcm\tefx\tsynth\tmidi\n"); for (idx = 0; idx < NUM_G; idx++) { voice = &emu->voices[idx]; snd_iprintf(buffer, "%i\t%i\t%i\t%i\t%i\t%i\n", idx, voice->use, voice->pcm, voice->efx, voice->synth, voice->midi); } } #ifdef CONFIG_SND_DEBUG static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_emu10k1 *emu = entry->private_data; u32 value; int i; snd_iprintf(buffer, "EMU1010 Registers:\n\n"); for(i = 0; i < 0x40; i+=1) { snd_emu1010_fpga_read(emu, i, &value); snd_iprintf(buffer, "%02X: %08X, %02X\n", i, value, (value >> 8) & 0x7f); } } static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_emu10k1 *emu = entry->private_data; unsigned long value; unsigned long flags; int i; snd_iprintf(buffer, "IO Registers:\n\n"); for(i = 0; i < 0x40; i+=4) { spin_lock_irqsave(&emu->emu_lock, flags); value = inl(emu->port + i); spin_unlock_irqrestore(&emu->emu_lock, flags); snd_iprintf(buffer, "%02X: %08lX\n", i, value); } } static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_emu10k1 *emu = entry->private_data; unsigned long flags; char line[64]; u32 reg, val; while (!snd_info_get_line(buffer, line, sizeof(line))) { if (sscanf(line, "%x %x", &reg, &val) != 2) continue; if (reg < 0x40 && val <= 0xffffffff) { spin_lock_irqsave(&emu->emu_lock, flags); outl(val, emu->port + (reg & 0xfffffffc)); spin_unlock_irqrestore(&emu->emu_lock, flags); } } } static unsigned int snd_ptr_read(struct snd_emu10k1 * emu, unsigned int iobase, unsigned int reg, unsigned int chn) { unsigned long flags; unsigned int regptr, val; regptr = (reg << 16) | chn; spin_lock_irqsave(&emu->emu_lock, flags); outl(regptr, emu->port + iobase + PTR); val = inl(emu->port + iobase + DATA); spin_unlock_irqrestore(&emu->emu_lock, flags); return val; } static void snd_ptr_write(struct snd_emu10k1 *emu, unsigned int iobase, unsigned int reg, unsigned int chn, unsigned int data) { unsigned int regptr; unsigned long flags; regptr = (reg << 16) | chn; spin_lock_irqsave(&emu->emu_lock, flags); outl(regptr, emu->port + iobase + PTR); outl(data, emu->port + iobase + DATA); spin_unlock_irqrestore(&emu->emu_lock, flags); } static void snd_emu_proc_ptr_reg_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer, int iobase, int offset, int length, int voices) { struct snd_emu10k1 *emu = entry->private_data; unsigned long value; int i,j; if (offset+length > 0xa0) { snd_iprintf(buffer, "Input values out of range\n"); return; } snd_iprintf(buffer, "Registers 0x%x\n", iobase); for(i = offset; i < offset+length; i++) { snd_iprintf(buffer, "%02X: ",i); for (j = 0; j < voices; j++) { if(iobase == 0) value = snd_ptr_read(emu, 0, i, j); else value = snd_ptr_read(emu, 0x20, i, j); snd_iprintf(buffer, "%08lX ", value); } snd_iprintf(buffer, "\n"); } } static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer, int iobase) { struct snd_emu10k1 *emu = entry->private_data; char line[64]; unsigned int reg, channel_id , val; while (!snd_info_get_line(buffer, line, sizeof(line))) { if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3) continue; if (reg < 0xa0 && val <= 0xffffffff && channel_id <= 3) snd_ptr_write(emu, iobase, reg, channel_id, val); } } static void snd_emu_proc_ptr_reg_write00(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { snd_emu_proc_ptr_reg_write(entry, buffer, 0); } static void snd_emu_proc_ptr_reg_write20(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { snd_emu_proc_ptr_reg_write(entry, buffer, 0x20); } static void snd_emu_proc_ptr_reg_read00a(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64); } static void snd_emu_proc_ptr_reg_read00b(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64); } static void snd_emu_proc_ptr_reg_read20a(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4); } static void snd_emu_proc_ptr_reg_read20b(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4); } static void snd_emu_proc_ptr_reg_read20c(struct snd_info_entry *entry, struct snd_info_buffer * buffer) { snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x80, 0x20, 4); } #endif static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = { .read = snd_emu10k1_fx8010_read, }; int snd_emu10k1_proc_init(struct snd_emu10k1 *emu) { struct snd_info_entry *entry; #ifdef CONFIG_SND_DEBUG if (emu->card_capabilities->emu_model) { if (! snd_card_proc_new(emu->card, "emu1010_regs", &entry)) snd_info_set_text_ops(entry, emu, snd_emu_proc_emu1010_reg_read); } if (! snd_card_proc_new(emu->card, "io_regs", &entry)) { snd_info_set_text_ops(entry, emu, snd_emu_proc_io_reg_read); entry->c.text.write = snd_emu_proc_io_reg_write; entry->mode |= S_IWUSR; } if (! snd_card_proc_new(emu->card, "ptr_regs00a", &entry)) { snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read00a); entry->c.text.write = snd_emu_proc_ptr_reg_write00; entry->mode |= S_IWUSR; } if (! snd_card_proc_new(emu->card, "ptr_regs00b", &entry)) { snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read00b); entry->c.text.write = snd_emu_proc_ptr_reg_write00; entry->mode |= S_IWUSR; } if (! snd_card_proc_new(emu->card, "ptr_regs20a", &entry)) { snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20a); entry->c.text.write = snd_emu_proc_ptr_reg_write20; entry->mode |= S_IWUSR; } if (! snd_card_proc_new(emu->card, "ptr_regs20b", &entry)) { snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20b); entry->c.text.write = snd_emu_proc_ptr_reg_write20; entry->mode |= S_IWUSR; } if (! snd_card_proc_new(emu->card, "ptr_regs20c", &entry)) { snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20c); entry->c.text.write = snd_emu_proc_ptr_reg_write20; entry->mode |= S_IWUSR; } #endif if (! snd_card_proc_new(emu->card, "emu10k1", &entry)) snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_read); if (emu->card_capabilities->emu10k2_chip) { if (! snd_card_proc_new(emu->card, "spdif-in", &entry)) snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_spdif_read); } if (emu->card_capabilities->ca0151_chip) { if (! snd_card_proc_new(emu->card, "capture-rates", &entry)) snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_rates_read); } if (! snd_card_proc_new(emu->card, "voices", &entry)) snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_voices_read); if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) { entry->content = SNDRV_INFO_CONTENT_DATA; entry->private_data = emu; entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/; entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR; entry->c.ops = &snd_emu10k1_proc_ops_fx8010; } if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) { entry->content = SNDRV_INFO_CONTENT_DATA; entry->private_data = emu; entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/; entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ; entry->c.ops = &snd_emu10k1_proc_ops_fx8010; } if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) { entry->content = SNDRV_INFO_CONTENT_DATA; entry->private_data = emu; entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/; entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ; entry->c.ops = &snd_emu10k1_proc_ops_fx8010; } if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) { entry->content = SNDRV_INFO_CONTENT_DATA; entry->private_data = emu; entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/; entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE; entry->c.ops = &snd_emu10k1_proc_ops_fx8010; } if (! snd_card_proc_new(emu->card, "fx8010_acode", &entry)) { entry->content = SNDRV_INFO_CONTENT_TEXT; entry->private_data = emu; entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/; entry->c.text.read = snd_emu10k1_proc_acode_read; } return 0; }
gpl-2.0
DirtyUnicorns/android_kernel_oppo_n1
drivers/usb/otg/gpio_vbus.c
1981
10157
/* * gpio-vbus.c - simple GPIO VBUS sensing driver for B peripheral devices * * Copyright (c) 2008 Philipp Zabel <philipp.zabel@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/kernel.h> #include <linux/platform_device.h> #include <linux/gpio.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/interrupt.h> #include <linux/usb.h> #include <linux/workqueue.h> #include <linux/regulator/consumer.h> #include <linux/usb/gadget.h> #include <linux/usb/gpio_vbus.h> #include <linux/usb/otg.h> /* * A simple GPIO VBUS sensing driver for B peripheral only devices * with internal transceivers. It can control a D+ pullup GPIO and * a regulator to limit the current drawn from VBUS. * * Needs to be loaded before the UDC driver that will use it. */ struct gpio_vbus_data { struct usb_phy phy; struct device *dev; struct regulator *vbus_draw; int vbus_draw_enabled; unsigned mA; struct delayed_work work; }; /* * This driver relies on "both edges" triggering. VBUS has 100 msec to * stabilize, so the peripheral controller driver may need to cope with * some bouncing due to current surges (e.g. charging local capacitance) * and contact chatter. * * REVISIT in desperate straits, toggling between rising and falling * edges might be workable. */ #define VBUS_IRQ_FLAGS \ ( IRQF_SAMPLE_RANDOM | IRQF_SHARED \ | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING ) /* interface to regulator framework */ static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA) { struct regulator *vbus_draw = gpio_vbus->vbus_draw; int enabled; if (!vbus_draw) return; enabled = gpio_vbus->vbus_draw_enabled; if (mA) { regulator_set_current_limit(vbus_draw, 0, 1000 * mA); if (!enabled) { regulator_enable(vbus_draw); gpio_vbus->vbus_draw_enabled = 1; } } else { if (enabled) { regulator_disable(vbus_draw); gpio_vbus->vbus_draw_enabled = 0; } } gpio_vbus->mA = mA; } static int is_vbus_powered(struct gpio_vbus_mach_info *pdata) { int vbus; vbus = gpio_get_value(pdata->gpio_vbus); if (pdata->gpio_vbus_inverted) vbus = !vbus; return vbus; } static void gpio_vbus_work(struct work_struct *work) { struct gpio_vbus_data *gpio_vbus = container_of(work, struct gpio_vbus_data, work.work); struct gpio_vbus_mach_info *pdata = gpio_vbus->dev->platform_data; int gpio, status; if (!gpio_vbus->phy.otg->gadget) return; /* Peripheral controllers which manage the pullup themselves won't have * gpio_pullup configured here. If it's configured here, we'll do what * isp1301_omap::b_peripheral() does and enable the pullup here... although * that may complicate usb_gadget_{,dis}connect() support. */ gpio = pdata->gpio_pullup; if (is_vbus_powered(pdata)) { status = USB_EVENT_VBUS; gpio_vbus->phy.state = OTG_STATE_B_PERIPHERAL; gpio_vbus->phy.last_event = status; usb_gadget_vbus_connect(gpio_vbus->phy.otg->gadget); /* drawing a "unit load" is *always* OK, except for OTG */ set_vbus_draw(gpio_vbus, 100); /* optionally enable D+ pullup */ if (gpio_is_valid(gpio)) gpio_set_value(gpio, !pdata->gpio_pullup_inverted); atomic_notifier_call_chain(&gpio_vbus->phy.notifier, status, gpio_vbus->phy.otg->gadget); } else { /* optionally disable D+ pullup */ if (gpio_is_valid(gpio)) gpio_set_value(gpio, pdata->gpio_pullup_inverted); set_vbus_draw(gpio_vbus, 0); usb_gadget_vbus_disconnect(gpio_vbus->phy.otg->gadget); status = USB_EVENT_NONE; gpio_vbus->phy.state = OTG_STATE_B_IDLE; gpio_vbus->phy.last_event = status; atomic_notifier_call_chain(&gpio_vbus->phy.notifier, status, gpio_vbus->phy.otg->gadget); } } /* VBUS change IRQ handler */ static irqreturn_t gpio_vbus_irq(int irq, void *data) { struct platform_device *pdev = data; struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); struct usb_otg *otg = gpio_vbus->phy.otg; dev_dbg(&pdev->dev, "VBUS %s (gadget: %s)\n", is_vbus_powered(pdata) ? "supplied" : "inactive", otg->gadget ? otg->gadget->name : "none"); if (otg->gadget) schedule_delayed_work(&gpio_vbus->work, msecs_to_jiffies(100)); return IRQ_HANDLED; } /* OTG transceiver interface */ /* bind/unbind the peripheral controller */ static int gpio_vbus_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) { struct gpio_vbus_data *gpio_vbus; struct gpio_vbus_mach_info *pdata; struct platform_device *pdev; int gpio, irq; gpio_vbus = container_of(otg->phy, struct gpio_vbus_data, phy); pdev = to_platform_device(gpio_vbus->dev); pdata = gpio_vbus->dev->platform_data; irq = gpio_to_irq(pdata->gpio_vbus); gpio = pdata->gpio_pullup; if (!gadget) { dev_dbg(&pdev->dev, "unregistering gadget '%s'\n", otg->gadget->name); /* optionally disable D+ pullup */ if (gpio_is_valid(gpio)) gpio_set_value(gpio, pdata->gpio_pullup_inverted); set_vbus_draw(gpio_vbus, 0); usb_gadget_vbus_disconnect(otg->gadget); otg->phy->state = OTG_STATE_UNDEFINED; otg->gadget = NULL; return 0; } otg->gadget = gadget; dev_dbg(&pdev->dev, "registered gadget '%s'\n", gadget->name); /* initialize connection state */ gpio_vbus_irq(irq, pdev); return 0; } /* effective for B devices, ignored for A-peripheral */ static int gpio_vbus_set_power(struct usb_phy *phy, unsigned mA) { struct gpio_vbus_data *gpio_vbus; gpio_vbus = container_of(phy, struct gpio_vbus_data, phy); if (phy->state == OTG_STATE_B_PERIPHERAL) set_vbus_draw(gpio_vbus, mA); return 0; } /* for non-OTG B devices: set/clear transceiver suspend mode */ static int gpio_vbus_set_suspend(struct usb_phy *phy, int suspend) { struct gpio_vbus_data *gpio_vbus; gpio_vbus = container_of(phy, struct gpio_vbus_data, phy); /* draw max 0 mA from vbus in suspend mode; or the previously * recorded amount of current if not suspended * * NOTE: high powered configs (mA > 100) may draw up to 2.5 mA * if they're wake-enabled ... we don't handle that yet. */ return gpio_vbus_set_power(phy, suspend ? 0 : gpio_vbus->mA); } /* platform driver interface */ static int __init gpio_vbus_probe(struct platform_device *pdev) { struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; struct gpio_vbus_data *gpio_vbus; struct resource *res; int err, gpio, irq; if (!pdata || !gpio_is_valid(pdata->gpio_vbus)) return -EINVAL; gpio = pdata->gpio_vbus; gpio_vbus = kzalloc(sizeof(struct gpio_vbus_data), GFP_KERNEL); if (!gpio_vbus) return -ENOMEM; gpio_vbus->phy.otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL); if (!gpio_vbus->phy.otg) { kfree(gpio_vbus); return -ENOMEM; } platform_set_drvdata(pdev, gpio_vbus); gpio_vbus->dev = &pdev->dev; gpio_vbus->phy.label = "gpio-vbus"; gpio_vbus->phy.set_power = gpio_vbus_set_power; gpio_vbus->phy.set_suspend = gpio_vbus_set_suspend; gpio_vbus->phy.state = OTG_STATE_UNDEFINED; gpio_vbus->phy.otg->phy = &gpio_vbus->phy; gpio_vbus->phy.otg->set_peripheral = gpio_vbus_set_peripheral; err = gpio_request(gpio, "vbus_detect"); if (err) { dev_err(&pdev->dev, "can't request vbus gpio %d, err: %d\n", gpio, err); goto err_gpio; } gpio_direction_input(gpio); res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (res) { irq = res->start; res->flags &= IRQF_TRIGGER_MASK; res->flags |= IRQF_SAMPLE_RANDOM | IRQF_SHARED; } else irq = gpio_to_irq(gpio); /* if data line pullup is in use, initialize it to "not pulling up" */ gpio = pdata->gpio_pullup; if (gpio_is_valid(gpio)) { err = gpio_request(gpio, "udc_pullup"); if (err) { dev_err(&pdev->dev, "can't request pullup gpio %d, err: %d\n", gpio, err); gpio_free(pdata->gpio_vbus); goto err_gpio; } gpio_direction_output(gpio, pdata->gpio_pullup_inverted); } err = request_irq(irq, gpio_vbus_irq, VBUS_IRQ_FLAGS, "vbus_detect", pdev); if (err) { dev_err(&pdev->dev, "can't request irq %i, err: %d\n", irq, err); goto err_irq; } ATOMIC_INIT_NOTIFIER_HEAD(&gpio_vbus->phy.notifier); INIT_DELAYED_WORK(&gpio_vbus->work, gpio_vbus_work); gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw"); if (IS_ERR(gpio_vbus->vbus_draw)) { dev_dbg(&pdev->dev, "can't get vbus_draw regulator, err: %ld\n", PTR_ERR(gpio_vbus->vbus_draw)); gpio_vbus->vbus_draw = NULL; } /* only active when a gadget is registered */ err = usb_set_transceiver(&gpio_vbus->phy); if (err) { dev_err(&pdev->dev, "can't register transceiver, err: %d\n", err); goto err_otg; } return 0; err_otg: free_irq(irq, &pdev->dev); err_irq: if (gpio_is_valid(pdata->gpio_pullup)) gpio_free(pdata->gpio_pullup); gpio_free(pdata->gpio_vbus); err_gpio: platform_set_drvdata(pdev, NULL); kfree(gpio_vbus->phy.otg); kfree(gpio_vbus); return err; } static int __exit gpio_vbus_remove(struct platform_device *pdev) { struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; int gpio = pdata->gpio_vbus; regulator_put(gpio_vbus->vbus_draw); usb_set_transceiver(NULL); free_irq(gpio_to_irq(gpio), &pdev->dev); if (gpio_is_valid(pdata->gpio_pullup)) gpio_free(pdata->gpio_pullup); gpio_free(gpio); platform_set_drvdata(pdev, NULL); kfree(gpio_vbus->phy.otg); kfree(gpio_vbus); return 0; } /* NOTE: the gpio-vbus device may *NOT* be hotplugged */ MODULE_ALIAS("platform:gpio-vbus"); static struct platform_driver gpio_vbus_driver = { .driver = { .name = "gpio-vbus", .owner = THIS_MODULE, }, .remove = __exit_p(gpio_vbus_remove), }; static int __init gpio_vbus_init(void) { return platform_driver_probe(&gpio_vbus_driver, gpio_vbus_probe); } module_init(gpio_vbus_init); static void __exit gpio_vbus_exit(void) { platform_driver_unregister(&gpio_vbus_driver); } module_exit(gpio_vbus_exit); MODULE_DESCRIPTION("simple GPIO controlled OTG transceiver driver"); MODULE_AUTHOR("Philipp Zabel"); MODULE_LICENSE("GPL");
gpl-2.0
profglavcho/test
arch/mips/alchemy/devboards/db1000.c
2237
15800
/* * DBAu1000/1500/1100 PBAu1100/1500 board support * * Copyright 2000, 2008 MontaVista Software Inc. * Author: MontaVista Software, Inc. <source@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 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/dma-mapping.h> #include <linux/gpio.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/leds.h> #include <linux/mmc/host.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/pm.h> #include <linux/spi/spi.h> #include <linux/spi/spi_gpio.h> #include <linux/spi/ads7846.h> #include <asm/mach-au1x00/au1000.h> #include <asm/mach-au1x00/au1000_dma.h> #include <asm/mach-au1x00/au1100_mmc.h> #include <asm/mach-db1x00/bcsr.h> #include <asm/reboot.h> #include <prom.h> #include "platform.h" #define F_SWAPPED (bcsr_read(BCSR_STATUS) & BCSR_STATUS_DB1000_SWAPBOOT) struct pci_dev; static const char *board_type_str(void) { switch (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI))) { case BCSR_WHOAMI_DB1000: return "DB1000"; case BCSR_WHOAMI_DB1500: return "DB1500"; case BCSR_WHOAMI_DB1100: return "DB1100"; case BCSR_WHOAMI_PB1500: case BCSR_WHOAMI_PB1500R2: return "PB1500"; case BCSR_WHOAMI_PB1100: return "PB1100"; default: return "(unknown)"; } } const char *get_system_type(void) { return board_type_str(); } void __init board_setup(void) { /* initialize board register space */ bcsr_init(DB1000_BCSR_PHYS_ADDR, DB1000_BCSR_PHYS_ADDR + DB1000_BCSR_HEXLED_OFS); printk(KERN_INFO "AMD Alchemy %s Board\n", board_type_str()); } static int db1500_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin) { if ((slot < 12) || (slot > 13) || pin == 0) return -1; if (slot == 12) return (pin == 1) ? AU1500_PCI_INTA : 0xff; if (slot == 13) { switch (pin) { case 1: return AU1500_PCI_INTA; case 2: return AU1500_PCI_INTB; case 3: return AU1500_PCI_INTC; case 4: return AU1500_PCI_INTD; } } return -1; } static struct resource alchemy_pci_host_res[] = { [0] = { .start = AU1500_PCI_PHYS_ADDR, .end = AU1500_PCI_PHYS_ADDR + 0xfff, .flags = IORESOURCE_MEM, }, }; static struct alchemy_pci_platdata db1500_pci_pd = { .board_map_irq = db1500_map_pci_irq, }; static struct platform_device db1500_pci_host_dev = { .dev.platform_data = &db1500_pci_pd, .name = "alchemy-pci", .id = 0, .num_resources = ARRAY_SIZE(alchemy_pci_host_res), .resource = alchemy_pci_host_res, }; static int __init db1500_pci_init(void) { int id = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)); if ((id == BCSR_WHOAMI_DB1500) || (id == BCSR_WHOAMI_PB1500) || (id == BCSR_WHOAMI_PB1500R2)) return platform_device_register(&db1500_pci_host_dev); return 0; } /* must be arch_initcall; MIPS PCI scans busses in a subsys_initcall */ arch_initcall(db1500_pci_init); static struct resource au1100_lcd_resources[] = { [0] = { .start = AU1100_LCD_PHYS_ADDR, .end = AU1100_LCD_PHYS_ADDR + 0x800 - 1, .flags = IORESOURCE_MEM, }, [1] = { .start = AU1100_LCD_INT, .end = AU1100_LCD_INT, .flags = IORESOURCE_IRQ, } }; static u64 au1100_lcd_dmamask = DMA_BIT_MASK(32); static struct platform_device au1100_lcd_device = { .name = "au1100-lcd", .id = 0, .dev = { .dma_mask = &au1100_lcd_dmamask, .coherent_dma_mask = DMA_BIT_MASK(32), }, .num_resources = ARRAY_SIZE(au1100_lcd_resources), .resource = au1100_lcd_resources, }; static struct resource alchemy_ac97c_res[] = { [0] = { .start = AU1000_AC97_PHYS_ADDR, .end = AU1000_AC97_PHYS_ADDR + 0xfff, .flags = IORESOURCE_MEM, }, [1] = { .start = DMA_ID_AC97C_TX, .end = DMA_ID_AC97C_TX, .flags = IORESOURCE_DMA, }, [2] = { .start = DMA_ID_AC97C_RX, .end = DMA_ID_AC97C_RX, .flags = IORESOURCE_DMA, }, }; static struct platform_device alchemy_ac97c_dev = { .name = "alchemy-ac97c", .id = -1, .resource = alchemy_ac97c_res, .num_resources = ARRAY_SIZE(alchemy_ac97c_res), }; static struct platform_device alchemy_ac97c_dma_dev = { .name = "alchemy-pcm-dma", .id = 0, }; static struct platform_device db1x00_codec_dev = { .name = "ac97-codec", .id = -1, }; static struct platform_device db1x00_audio_dev = { .name = "db1000-audio", }; /******************************************************************************/ static irqreturn_t db1100_mmc_cd(int irq, void *ptr) { void (*mmc_cd)(struct mmc_host *, unsigned long); /* link against CONFIG_MMC=m */ mmc_cd = symbol_get(mmc_detect_change); mmc_cd(ptr, msecs_to_jiffies(500)); symbol_put(mmc_detect_change); return IRQ_HANDLED; } static int db1100_mmc_cd_setup(void *mmc_host, int en) { int ret = 0, irq; if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100) irq = AU1100_GPIO19_INT; else irq = AU1100_GPIO14_INT; /* PB1100 SD0 CD# */ if (en) { irq_set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); ret = request_irq(irq, db1100_mmc_cd, 0, "sd0_cd", mmc_host); } else free_irq(irq, mmc_host); return ret; } static int db1100_mmc1_cd_setup(void *mmc_host, int en) { int ret = 0, irq; if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100) irq = AU1100_GPIO20_INT; else irq = AU1100_GPIO15_INT; /* PB1100 SD1 CD# */ if (en) { irq_set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); ret = request_irq(irq, db1100_mmc_cd, 0, "sd1_cd", mmc_host); } else free_irq(irq, mmc_host); return ret; } static int db1100_mmc_card_readonly(void *mmc_host) { /* testing suggests that this bit is inverted */ return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD0WP) ? 0 : 1; } static int db1100_mmc_card_inserted(void *mmc_host) { return !alchemy_gpio_get_value(19); } static void db1100_mmc_set_power(void *mmc_host, int state) { int bit; if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100) bit = BCSR_BOARD_SD0PWR; else bit = BCSR_BOARD_PB1100_SD0PWR; if (state) { bcsr_mod(BCSR_BOARD, 0, bit); msleep(400); /* stabilization time */ } else bcsr_mod(BCSR_BOARD, bit, 0); } static void db1100_mmcled_set(struct led_classdev *led, enum led_brightness b) { if (b != LED_OFF) bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED0, 0); else bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED0); } static struct led_classdev db1100_mmc_led = { .brightness_set = db1100_mmcled_set, }; static int db1100_mmc1_card_readonly(void *mmc_host) { return (bcsr_read(BCSR_BOARD) & BCSR_BOARD_SD1WP) ? 1 : 0; } static int db1100_mmc1_card_inserted(void *mmc_host) { return !alchemy_gpio_get_value(20); } static void db1100_mmc1_set_power(void *mmc_host, int state) { int bit; if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100) bit = BCSR_BOARD_SD1PWR; else bit = BCSR_BOARD_PB1100_SD1PWR; if (state) { bcsr_mod(BCSR_BOARD, 0, bit); msleep(400); /* stabilization time */ } else bcsr_mod(BCSR_BOARD, bit, 0); } static void db1100_mmc1led_set(struct led_classdev *led, enum led_brightness b) { if (b != LED_OFF) bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED1, 0); else bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED1); } static struct led_classdev db1100_mmc1_led = { .brightness_set = db1100_mmc1led_set, }; static struct au1xmmc_platform_data db1100_mmc_platdata[2] = { [0] = { .cd_setup = db1100_mmc_cd_setup, .set_power = db1100_mmc_set_power, .card_inserted = db1100_mmc_card_inserted, .card_readonly = db1100_mmc_card_readonly, .led = &db1100_mmc_led, }, [1] = { .cd_setup = db1100_mmc1_cd_setup, .set_power = db1100_mmc1_set_power, .card_inserted = db1100_mmc1_card_inserted, .card_readonly = db1100_mmc1_card_readonly, .led = &db1100_mmc1_led, }, }; static struct resource au1100_mmc0_resources[] = { [0] = { .start = AU1100_SD0_PHYS_ADDR, .end = AU1100_SD0_PHYS_ADDR + 0xfff, .flags = IORESOURCE_MEM, }, [1] = { .start = AU1100_SD_INT, .end = AU1100_SD_INT, .flags = IORESOURCE_IRQ, }, [2] = { .start = DMA_ID_SD0_TX, .end = DMA_ID_SD0_TX, .flags = IORESOURCE_DMA, }, [3] = { .start = DMA_ID_SD0_RX, .end = DMA_ID_SD0_RX, .flags = IORESOURCE_DMA, } }; static u64 au1xxx_mmc_dmamask = DMA_BIT_MASK(32); static struct platform_device db1100_mmc0_dev = { .name = "au1xxx-mmc", .id = 0, .dev = { .dma_mask = &au1xxx_mmc_dmamask, .coherent_dma_mask = DMA_BIT_MASK(32), .platform_data = &db1100_mmc_platdata[0], }, .num_resources = ARRAY_SIZE(au1100_mmc0_resources), .resource = au1100_mmc0_resources, }; static struct resource au1100_mmc1_res[] = { [0] = { .start = AU1100_SD1_PHYS_ADDR, .end = AU1100_SD1_PHYS_ADDR + 0xfff, .flags = IORESOURCE_MEM, }, [1] = { .start = AU1100_SD_INT, .end = AU1100_SD_INT, .flags = IORESOURCE_IRQ, }, [2] = { .start = DMA_ID_SD1_TX, .end = DMA_ID_SD1_TX, .flags = IORESOURCE_DMA, }, [3] = { .start = DMA_ID_SD1_RX, .end = DMA_ID_SD1_RX, .flags = IORESOURCE_DMA, } }; static struct platform_device db1100_mmc1_dev = { .name = "au1xxx-mmc", .id = 1, .dev = { .dma_mask = &au1xxx_mmc_dmamask, .coherent_dma_mask = DMA_BIT_MASK(32), .platform_data = &db1100_mmc_platdata[1], }, .num_resources = ARRAY_SIZE(au1100_mmc1_res), .resource = au1100_mmc1_res, }; /******************************************************************************/ static void db1000_irda_set_phy_mode(int mode) { unsigned short mask = BCSR_RESETS_IRDA_MODE_MASK | BCSR_RESETS_FIR_SEL; switch (mode) { case AU1000_IRDA_PHY_MODE_OFF: bcsr_mod(BCSR_RESETS, mask, BCSR_RESETS_IRDA_MODE_OFF); break; case AU1000_IRDA_PHY_MODE_SIR: bcsr_mod(BCSR_RESETS, mask, BCSR_RESETS_IRDA_MODE_FULL); break; case AU1000_IRDA_PHY_MODE_FIR: bcsr_mod(BCSR_RESETS, mask, BCSR_RESETS_IRDA_MODE_FULL | BCSR_RESETS_FIR_SEL); break; } } static struct au1k_irda_platform_data db1000_irda_platdata = { .set_phy_mode = db1000_irda_set_phy_mode, }; static struct resource au1000_irda_res[] = { [0] = { .start = AU1000_IRDA_PHYS_ADDR, .end = AU1000_IRDA_PHYS_ADDR + 0x0fff, .flags = IORESOURCE_MEM, }, [1] = { .start = AU1000_IRDA_TX_INT, .end = AU1000_IRDA_TX_INT, .flags = IORESOURCE_IRQ, }, [2] = { .start = AU1000_IRDA_RX_INT, .end = AU1000_IRDA_RX_INT, .flags = IORESOURCE_IRQ, }, }; static struct platform_device db1000_irda_dev = { .name = "au1000-irda", .id = -1, .dev = { .platform_data = &db1000_irda_platdata, }, .resource = au1000_irda_res, .num_resources = ARRAY_SIZE(au1000_irda_res), }; /******************************************************************************/ static struct ads7846_platform_data db1100_touch_pd = { .model = 7846, .vref_mv = 3300, .gpio_pendown = 21, }; static struct spi_gpio_platform_data db1100_spictl_pd = { .sck = 209, .mosi = 208, .miso = 207, .num_chipselect = 1, }; static struct spi_board_info db1100_spi_info[] __initdata = { [0] = { .modalias = "ads7846", .max_speed_hz = 3250000, .bus_num = 0, .chip_select = 0, .mode = 0, .irq = AU1100_GPIO21_INT, .platform_data = &db1100_touch_pd, .controller_data = (void *)210, /* for spi_gpio: CS# GPIO210 */ }, }; static struct platform_device db1100_spi_dev = { .name = "spi_gpio", .id = 0, .dev = { .platform_data = &db1100_spictl_pd, }, }; static struct platform_device *db1x00_devs[] = { &db1x00_codec_dev, &alchemy_ac97c_dma_dev, &alchemy_ac97c_dev, &db1x00_audio_dev, }; static struct platform_device *db1000_devs[] = { &db1000_irda_dev, }; static struct platform_device *db1100_devs[] = { &au1100_lcd_device, &db1100_mmc0_dev, &db1100_mmc1_dev, &db1000_irda_dev, }; static int __init db1000_dev_init(void) { int board = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)); int c0, c1, d0, d1, s0, s1, flashsize = 32, twosocks = 1; unsigned long pfc; if (board == BCSR_WHOAMI_DB1500) { c0 = AU1500_GPIO2_INT; c1 = AU1500_GPIO5_INT; d0 = AU1500_GPIO0_INT; d1 = AU1500_GPIO3_INT; s0 = AU1500_GPIO1_INT; s1 = AU1500_GPIO4_INT; } else if (board == BCSR_WHOAMI_DB1100) { c0 = AU1100_GPIO2_INT; c1 = AU1100_GPIO5_INT; d0 = AU1100_GPIO0_INT; d1 = AU1100_GPIO3_INT; s0 = AU1100_GPIO1_INT; s1 = AU1100_GPIO4_INT; gpio_direction_input(19); /* sd0 cd# */ gpio_direction_input(20); /* sd1 cd# */ gpio_direction_input(21); /* touch pendown# */ gpio_direction_input(207); /* SPI MISO */ gpio_direction_output(208, 0); /* SPI MOSI */ gpio_direction_output(209, 1); /* SPI SCK */ gpio_direction_output(210, 1); /* SPI CS# */ /* spi_gpio on SSI0 pins */ pfc = __raw_readl((void __iomem *)SYS_PINFUNC); pfc |= (1 << 0); /* SSI0 pins as GPIOs */ __raw_writel(pfc, (void __iomem *)SYS_PINFUNC); wmb(); spi_register_board_info(db1100_spi_info, ARRAY_SIZE(db1100_spi_info)); platform_add_devices(db1100_devs, ARRAY_SIZE(db1100_devs)); platform_device_register(&db1100_spi_dev); } else if (board == BCSR_WHOAMI_DB1000) { c0 = AU1000_GPIO2_INT; c1 = AU1000_GPIO5_INT; d0 = AU1000_GPIO0_INT; d1 = AU1000_GPIO3_INT; s0 = AU1000_GPIO1_INT; s1 = AU1000_GPIO4_INT; platform_add_devices(db1000_devs, ARRAY_SIZE(db1000_devs)); } else if ((board == BCSR_WHOAMI_PB1500) || (board == BCSR_WHOAMI_PB1500R2)) { c0 = AU1500_GPIO203_INT; d0 = AU1500_GPIO201_INT; s0 = AU1500_GPIO202_INT; twosocks = 0; flashsize = 64; /* RTC and daughtercard irqs */ irq_set_irq_type(AU1500_GPIO204_INT, IRQ_TYPE_LEVEL_LOW); irq_set_irq_type(AU1500_GPIO205_INT, IRQ_TYPE_LEVEL_LOW); /* EPSON S1D13806 0x1b000000 * SRAM 1MB/2MB 0x1a000000 * DS1693 RTC 0x0c000000 */ } else if (board == BCSR_WHOAMI_PB1100) { c0 = AU1100_GPIO11_INT; d0 = AU1100_GPIO9_INT; s0 = AU1100_GPIO10_INT; twosocks = 0; flashsize = 64; /* pendown, rtc, daughtercard irqs */ irq_set_irq_type(AU1100_GPIO8_INT, IRQ_TYPE_LEVEL_LOW); irq_set_irq_type(AU1100_GPIO12_INT, IRQ_TYPE_LEVEL_LOW); irq_set_irq_type(AU1100_GPIO13_INT, IRQ_TYPE_LEVEL_LOW); /* EPSON S1D13806 0x1b000000 * SRAM 1MB/2MB 0x1a000000 * DiskOnChip 0x0d000000 * DS1693 RTC 0x0c000000 */ platform_add_devices(db1100_devs, ARRAY_SIZE(db1100_devs)); } else return 0; /* unknown board, no further dev setup to do */ irq_set_irq_type(d0, IRQ_TYPE_EDGE_BOTH); irq_set_irq_type(c0, IRQ_TYPE_LEVEL_LOW); irq_set_irq_type(s0, IRQ_TYPE_LEVEL_LOW); db1x_register_pcmcia_socket( AU1000_PCMCIA_ATTR_PHYS_ADDR, AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x000400000 - 1, AU1000_PCMCIA_MEM_PHYS_ADDR, AU1000_PCMCIA_MEM_PHYS_ADDR + 0x000400000 - 1, AU1000_PCMCIA_IO_PHYS_ADDR, AU1000_PCMCIA_IO_PHYS_ADDR + 0x000010000 - 1, c0, d0, /*s0*/0, 0, 0); if (twosocks) { irq_set_irq_type(d1, IRQ_TYPE_EDGE_BOTH); irq_set_irq_type(c1, IRQ_TYPE_LEVEL_LOW); irq_set_irq_type(s1, IRQ_TYPE_LEVEL_LOW); db1x_register_pcmcia_socket( AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004000000, AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004400000 - 1, AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004000000, AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004400000 - 1, AU1000_PCMCIA_IO_PHYS_ADDR + 0x004000000, AU1000_PCMCIA_IO_PHYS_ADDR + 0x004010000 - 1, c1, d1, /*s1*/0, 0, 1); } platform_add_devices(db1x00_devs, ARRAY_SIZE(db1x00_devs)); db1x_register_norflash(flashsize << 20, 4 /* 32bit */, F_SWAPPED); return 0; } device_initcall(db1000_dev_init);
gpl-2.0
Kahlo007/cm_kernel_lenovo_kai
kernel/time/tick-common.c
2237
9750
/* * linux/kernel/time/tick-common.c * * This file contains the base functions to manage periodic tick * related events. * * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de> * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar * Copyright(C) 2006-2007, Timesys Corp., Thomas Gleixner * * This code is licenced under the GPL version 2. For details see * kernel-base/COPYING. */ #include <linux/cpu.h> #include <linux/err.h> #include <linux/hrtimer.h> #include <linux/interrupt.h> #include <linux/percpu.h> #include <linux/profile.h> #include <linux/sched.h> #include <asm/irq_regs.h> #include "tick-internal.h" /* * Tick devices */ DEFINE_PER_CPU(struct tick_device, tick_cpu_device); /* * Tick next event: keeps track of the tick time */ ktime_t tick_next_period; ktime_t tick_period; int tick_do_timer_cpu __read_mostly = TICK_DO_TIMER_BOOT; static DEFINE_RAW_SPINLOCK(tick_device_lock); /* * Debugging: see timer_list.c */ struct tick_device *tick_get_device(int cpu) { return &per_cpu(tick_cpu_device, cpu); } /** * tick_is_oneshot_available - check for a oneshot capable event device */ int tick_is_oneshot_available(void) { struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev); if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT)) return 0; if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) return 1; return tick_broadcast_oneshot_available(); } /* * Periodic tick */ static void tick_periodic(int cpu) { if (tick_do_timer_cpu == cpu) { write_seqlock(&xtime_lock); /* Keep track of the next tick event */ tick_next_period = ktime_add(tick_next_period, tick_period); do_timer(1); write_sequnlock(&xtime_lock); } update_process_times(user_mode(get_irq_regs())); profile_tick(CPU_PROFILING); } /* * Event handler for periodic ticks */ void tick_handle_periodic(struct clock_event_device *dev) { int cpu = smp_processor_id(); ktime_t next; tick_periodic(cpu); if (dev->mode != CLOCK_EVT_MODE_ONESHOT) return; /* * Setup the next period for devices, which do not have * periodic mode: */ next = ktime_add(dev->next_event, tick_period); for (;;) { if (!clockevents_program_event(dev, next, ktime_get())) return; /* * Have to be careful here. If we're in oneshot mode, * before we call tick_periodic() in a loop, we need * to be sure we're using a real hardware clocksource. * Otherwise we could get trapped in an infinite * loop, as the tick_periodic() increments jiffies, * when then will increment time, posibly causing * the loop to trigger again and again. */ if (timekeeping_valid_for_hres()) tick_periodic(cpu); next = ktime_add(next, tick_period); } } /* * Setup the device for a periodic tick */ void tick_setup_periodic(struct clock_event_device *dev, int broadcast) { tick_set_periodic_handler(dev, broadcast); /* Broadcast setup ? */ if (!tick_device_is_functional(dev)) return; if ((dev->features & CLOCK_EVT_FEAT_PERIODIC) && !tick_broadcast_oneshot_active()) { clockevents_set_mode(dev, CLOCK_EVT_MODE_PERIODIC); } else { unsigned long seq; ktime_t next; do { seq = read_seqbegin(&xtime_lock); next = tick_next_period; } while (read_seqretry(&xtime_lock, seq)); clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT); for (;;) { if (!clockevents_program_event(dev, next, ktime_get())) return; next = ktime_add(next, tick_period); } } } /* * Setup the tick device */ static void tick_setup_device(struct tick_device *td, struct clock_event_device *newdev, int cpu, const struct cpumask *cpumask) { ktime_t next_event; void (*handler)(struct clock_event_device *) = NULL; /* * First device setup ? */ if (!td->evtdev) { /* * If no cpu took the do_timer update, assign it to * this cpu: */ if (tick_do_timer_cpu == TICK_DO_TIMER_BOOT) { tick_do_timer_cpu = cpu; tick_next_period = ktime_get(); tick_period = ktime_set(0, NSEC_PER_SEC / HZ); } /* * Startup in periodic mode first. */ td->mode = TICKDEV_MODE_PERIODIC; } else { handler = td->evtdev->event_handler; next_event = td->evtdev->next_event; td->evtdev->event_handler = clockevents_handle_noop; } td->evtdev = newdev; /* * When the device is not per cpu, pin the interrupt to the * current cpu: */ if (!cpumask_equal(newdev->cpumask, cpumask)) irq_set_affinity(newdev->irq, cpumask); /* * When global broadcasting is active, check if the current * device is registered as a placeholder for broadcast mode. * This allows us to handle this x86 misfeature in a generic * way. */ if (tick_device_uses_broadcast(newdev, cpu)) return; if (td->mode == TICKDEV_MODE_PERIODIC) tick_setup_periodic(newdev, 0); else tick_setup_oneshot(newdev, handler, next_event); } /* * Check, if the new registered device should be used. */ static int tick_check_new_device(struct clock_event_device *newdev) { struct clock_event_device *curdev; struct tick_device *td; int cpu, ret = NOTIFY_OK; unsigned long flags; raw_spin_lock_irqsave(&tick_device_lock, flags); cpu = smp_processor_id(); if (!cpumask_test_cpu(cpu, newdev->cpumask)) goto out_bc; td = &per_cpu(tick_cpu_device, cpu); curdev = td->evtdev; /* cpu local device ? */ if (!cpumask_equal(newdev->cpumask, cpumask_of(cpu))) { /* * If the cpu affinity of the device interrupt can not * be set, ignore it. */ if (!irq_can_set_affinity(newdev->irq)) goto out_bc; /* * If we have a cpu local device already, do not replace it * by a non cpu local device */ if (curdev && cpumask_equal(curdev->cpumask, cpumask_of(cpu))) goto out_bc; } /* * If we have an active device, then check the rating and the oneshot * feature. */ if (curdev) { /* * Prefer one shot capable devices ! */ if ((curdev->features & CLOCK_EVT_FEAT_ONESHOT) && !(newdev->features & CLOCK_EVT_FEAT_ONESHOT)) goto out_bc; /* * Check the rating */ if (curdev->rating >= newdev->rating) goto out_bc; } /* * Replace the eventually existing device by the new * device. If the current device is the broadcast device, do * not give it back to the clockevents layer ! */ if (tick_is_broadcast_device(curdev)) { clockevents_shutdown(curdev); curdev = NULL; } clockevents_exchange_device(curdev, newdev); tick_setup_device(td, newdev, cpu, cpumask_of(cpu)); if (newdev->features & CLOCK_EVT_FEAT_ONESHOT) tick_oneshot_notify(); raw_spin_unlock_irqrestore(&tick_device_lock, flags); return NOTIFY_STOP; out_bc: /* * Can the new device be used as a broadcast device ? */ if (tick_check_broadcast_device(newdev)) ret = NOTIFY_STOP; raw_spin_unlock_irqrestore(&tick_device_lock, flags); return ret; } /* * Transfer the do_timer job away from a dying cpu. * * Called with interrupts disabled. */ static void tick_handover_do_timer(int *cpup) { if (*cpup == tick_do_timer_cpu) { int cpu = cpumask_first(cpu_online_mask); tick_do_timer_cpu = (cpu < nr_cpu_ids) ? cpu : TICK_DO_TIMER_NONE; } } /* * Shutdown an event device on a given cpu: * * This is called on a life CPU, when a CPU is dead. So we cannot * access the hardware device itself. * We just set the mode and remove it from the lists. */ static void tick_shutdown(unsigned int *cpup) { struct tick_device *td = &per_cpu(tick_cpu_device, *cpup); struct clock_event_device *dev = td->evtdev; unsigned long flags; raw_spin_lock_irqsave(&tick_device_lock, flags); td->mode = TICKDEV_MODE_PERIODIC; if (dev) { /* * Prevent that the clock events layer tries to call * the set mode function! */ dev->mode = CLOCK_EVT_MODE_UNUSED; clockevents_exchange_device(dev, NULL); td->evtdev = NULL; } raw_spin_unlock_irqrestore(&tick_device_lock, flags); } static void tick_suspend(void) { struct tick_device *td = &__get_cpu_var(tick_cpu_device); unsigned long flags; raw_spin_lock_irqsave(&tick_device_lock, flags); clockevents_shutdown(td->evtdev); raw_spin_unlock_irqrestore(&tick_device_lock, flags); } static void tick_resume(void) { struct tick_device *td = &__get_cpu_var(tick_cpu_device); unsigned long flags; int broadcast = tick_resume_broadcast(); raw_spin_lock_irqsave(&tick_device_lock, flags); clockevents_set_mode(td->evtdev, CLOCK_EVT_MODE_RESUME); if (!broadcast) { if (td->mode == TICKDEV_MODE_PERIODIC) tick_setup_periodic(td->evtdev, 0); else tick_resume_oneshot(); } raw_spin_unlock_irqrestore(&tick_device_lock, flags); } /* * Notification about clock event devices */ static int tick_notify(struct notifier_block *nb, unsigned long reason, void *dev) { switch (reason) { case CLOCK_EVT_NOTIFY_ADD: return tick_check_new_device(dev); case CLOCK_EVT_NOTIFY_BROADCAST_ON: case CLOCK_EVT_NOTIFY_BROADCAST_OFF: case CLOCK_EVT_NOTIFY_BROADCAST_FORCE: tick_broadcast_on_off(reason, dev); break; case CLOCK_EVT_NOTIFY_BROADCAST_ENTER: case CLOCK_EVT_NOTIFY_BROADCAST_EXIT: tick_broadcast_oneshot_control(reason); break; case CLOCK_EVT_NOTIFY_CPU_DYING: tick_handover_do_timer(dev); break; case CLOCK_EVT_NOTIFY_CPU_DEAD: tick_shutdown_broadcast_oneshot(dev); tick_shutdown_broadcast(dev); tick_shutdown(dev); break; case CLOCK_EVT_NOTIFY_SUSPEND: tick_suspend(); tick_suspend_broadcast(); break; case CLOCK_EVT_NOTIFY_RESUME: tick_resume(); break; default: break; } return NOTIFY_OK; } static struct notifier_block tick_notifier = { .notifier_call = tick_notify, }; /** * tick_init - initialize the tick control * * Register the notifier with the clockevents framework */ void __init tick_init(void) { clockevents_register_notifier(&tick_notifier); }
gpl-2.0
GustavoRD78/78Kernel-5.1.1-23.4.A.0.546
arch/arm/mach-gemini/irq.c
4797
3066
/* * Interrupt routines for Gemini * * Copyright (C) 2001-2006 Storlink, Corp. * Copyright (C) 2008-2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt> * * 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/init.h> #include <linux/io.h> #include <linux/ioport.h> #include <linux/stddef.h> #include <linux/list.h> #include <linux/sched.h> #include <asm/irq.h> #include <asm/mach/irq.h> #include <mach/hardware.h> #define IRQ_SOURCE(base_addr) (base_addr + 0x00) #define IRQ_MASK(base_addr) (base_addr + 0x04) #define IRQ_CLEAR(base_addr) (base_addr + 0x08) #define IRQ_TMODE(base_addr) (base_addr + 0x0C) #define IRQ_TLEVEL(base_addr) (base_addr + 0x10) #define IRQ_STATUS(base_addr) (base_addr + 0x14) #define FIQ_SOURCE(base_addr) (base_addr + 0x20) #define FIQ_MASK(base_addr) (base_addr + 0x24) #define FIQ_CLEAR(base_addr) (base_addr + 0x28) #define FIQ_TMODE(base_addr) (base_addr + 0x2C) #define FIQ_LEVEL(base_addr) (base_addr + 0x30) #define FIQ_STATUS(base_addr) (base_addr + 0x34) static void gemini_ack_irq(struct irq_data *d) { __raw_writel(1 << d->irq, IRQ_CLEAR(IO_ADDRESS(GEMINI_INTERRUPT_BASE))); } static void gemini_mask_irq(struct irq_data *d) { unsigned int mask; mask = __raw_readl(IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE))); mask &= ~(1 << d->irq); __raw_writel(mask, IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE))); } static void gemini_unmask_irq(struct irq_data *d) { unsigned int mask; mask = __raw_readl(IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE))); mask |= (1 << d->irq); __raw_writel(mask, IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE))); } static struct irq_chip gemini_irq_chip = { .name = "INTC", .irq_ack = gemini_ack_irq, .irq_mask = gemini_mask_irq, .irq_unmask = gemini_unmask_irq, }; static struct resource irq_resource = { .name = "irq_handler", .start = IO_ADDRESS(GEMINI_INTERRUPT_BASE), .end = IO_ADDRESS(FIQ_STATUS(GEMINI_INTERRUPT_BASE)) + 4, }; void __init gemini_init_irq(void) { unsigned int i, mode = 0, level = 0; /* * Disable the idle handler by default since it is buggy * For more info see arch/arm/mach-gemini/idle.c */ disable_hlt(); request_resource(&iomem_resource, &irq_resource); for (i = 0; i < NR_IRQS; i++) { irq_set_chip(i, &gemini_irq_chip); if((i >= IRQ_TIMER1 && i <= IRQ_TIMER3) || (i >= IRQ_SERIRQ0 && i <= IRQ_SERIRQ1)) { irq_set_handler(i, handle_edge_irq); mode |= 1 << i; level |= 1 << i; } else { irq_set_handler(i, handle_level_irq); } set_irq_flags(i, IRQF_VALID | IRQF_PROBE); } /* Disable all interrupts */ __raw_writel(0, IRQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE))); __raw_writel(0, FIQ_MASK(IO_ADDRESS(GEMINI_INTERRUPT_BASE))); /* Set interrupt mode */ __raw_writel(mode, IRQ_TMODE(IO_ADDRESS(GEMINI_INTERRUPT_BASE))); __raw_writel(level, IRQ_TLEVEL(IO_ADDRESS(GEMINI_INTERRUPT_BASE))); }
gpl-2.0
jmztaylor/android_kernel_htc_m4
drivers/scsi/pm8001/pm8001_hwi.c
4797
154311
/* * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver * * Copyright (c) 2008-2009 USI Co., Ltd. * 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 <linux/slab.h> #include "pm8001_sas.h" #include "pm8001_hwi.h" #include "pm8001_chips.h" #include "pm8001_ctl.h" /** * read_main_config_table - read the configure table and save it. * @pm8001_ha: our hba card information */ static void __devinit read_main_config_table(struct pm8001_hba_info *pm8001_ha) { void __iomem *address = pm8001_ha->main_cfg_tbl_addr; pm8001_ha->main_cfg_tbl.signature = pm8001_mr32(address, 0x00); pm8001_ha->main_cfg_tbl.interface_rev = pm8001_mr32(address, 0x04); pm8001_ha->main_cfg_tbl.firmware_rev = pm8001_mr32(address, 0x08); pm8001_ha->main_cfg_tbl.max_out_io = pm8001_mr32(address, 0x0C); pm8001_ha->main_cfg_tbl.max_sgl = pm8001_mr32(address, 0x10); pm8001_ha->main_cfg_tbl.ctrl_cap_flag = pm8001_mr32(address, 0x14); pm8001_ha->main_cfg_tbl.gst_offset = pm8001_mr32(address, 0x18); pm8001_ha->main_cfg_tbl.inbound_queue_offset = pm8001_mr32(address, MAIN_IBQ_OFFSET); pm8001_ha->main_cfg_tbl.outbound_queue_offset = pm8001_mr32(address, MAIN_OBQ_OFFSET); pm8001_ha->main_cfg_tbl.hda_mode_flag = pm8001_mr32(address, MAIN_HDA_FLAGS_OFFSET); /* read analog Setting offset from the configuration table */ pm8001_ha->main_cfg_tbl.anolog_setup_table_offset = pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET); /* read Error Dump Offset and Length */ pm8001_ha->main_cfg_tbl.fatal_err_dump_offset0 = pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET); pm8001_ha->main_cfg_tbl.fatal_err_dump_length0 = pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH); pm8001_ha->main_cfg_tbl.fatal_err_dump_offset1 = pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET); pm8001_ha->main_cfg_tbl.fatal_err_dump_length1 = pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH); } /** * read_general_status_table - read the general status table and save it. * @pm8001_ha: our hba card information */ static void __devinit read_general_status_table(struct pm8001_hba_info *pm8001_ha) { void __iomem *address = pm8001_ha->general_stat_tbl_addr; pm8001_ha->gs_tbl.gst_len_mpistate = pm8001_mr32(address, 0x00); pm8001_ha->gs_tbl.iq_freeze_state0 = pm8001_mr32(address, 0x04); pm8001_ha->gs_tbl.iq_freeze_state1 = pm8001_mr32(address, 0x08); pm8001_ha->gs_tbl.msgu_tcnt = pm8001_mr32(address, 0x0C); pm8001_ha->gs_tbl.iop_tcnt = pm8001_mr32(address, 0x10); pm8001_ha->gs_tbl.reserved = pm8001_mr32(address, 0x14); pm8001_ha->gs_tbl.phy_state[0] = pm8001_mr32(address, 0x18); pm8001_ha->gs_tbl.phy_state[1] = pm8001_mr32(address, 0x1C); pm8001_ha->gs_tbl.phy_state[2] = pm8001_mr32(address, 0x20); pm8001_ha->gs_tbl.phy_state[3] = pm8001_mr32(address, 0x24); pm8001_ha->gs_tbl.phy_state[4] = pm8001_mr32(address, 0x28); pm8001_ha->gs_tbl.phy_state[5] = pm8001_mr32(address, 0x2C); pm8001_ha->gs_tbl.phy_state[6] = pm8001_mr32(address, 0x30); pm8001_ha->gs_tbl.phy_state[7] = pm8001_mr32(address, 0x34); pm8001_ha->gs_tbl.reserved1 = pm8001_mr32(address, 0x38); pm8001_ha->gs_tbl.reserved2 = pm8001_mr32(address, 0x3C); pm8001_ha->gs_tbl.reserved3 = pm8001_mr32(address, 0x40); pm8001_ha->gs_tbl.recover_err_info[0] = pm8001_mr32(address, 0x44); pm8001_ha->gs_tbl.recover_err_info[1] = pm8001_mr32(address, 0x48); pm8001_ha->gs_tbl.recover_err_info[2] = pm8001_mr32(address, 0x4C); pm8001_ha->gs_tbl.recover_err_info[3] = pm8001_mr32(address, 0x50); pm8001_ha->gs_tbl.recover_err_info[4] = pm8001_mr32(address, 0x54); pm8001_ha->gs_tbl.recover_err_info[5] = pm8001_mr32(address, 0x58); pm8001_ha->gs_tbl.recover_err_info[6] = pm8001_mr32(address, 0x5C); pm8001_ha->gs_tbl.recover_err_info[7] = pm8001_mr32(address, 0x60); } /** * read_inbnd_queue_table - read the inbound queue table and save it. * @pm8001_ha: our hba card information */ static void __devinit read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha) { int inbQ_num = 1; int i; void __iomem *address = pm8001_ha->inbnd_q_tbl_addr; for (i = 0; i < inbQ_num; i++) { u32 offset = i * 0x20; pm8001_ha->inbnd_q_tbl[i].pi_pci_bar = get_pci_bar_index(pm8001_mr32(address, (offset + 0x14))); pm8001_ha->inbnd_q_tbl[i].pi_offset = pm8001_mr32(address, (offset + 0x18)); } } /** * read_outbnd_queue_table - read the outbound queue table and save it. * @pm8001_ha: our hba card information */ static void __devinit read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha) { int outbQ_num = 1; int i; void __iomem *address = pm8001_ha->outbnd_q_tbl_addr; for (i = 0; i < outbQ_num; i++) { u32 offset = i * 0x24; pm8001_ha->outbnd_q_tbl[i].ci_pci_bar = get_pci_bar_index(pm8001_mr32(address, (offset + 0x14))); pm8001_ha->outbnd_q_tbl[i].ci_offset = pm8001_mr32(address, (offset + 0x18)); } } /** * init_default_table_values - init the default table. * @pm8001_ha: our hba card information */ static void __devinit init_default_table_values(struct pm8001_hba_info *pm8001_ha) { int qn = 1; int i; u32 offsetib, offsetob; void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr; void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr; pm8001_ha->main_cfg_tbl.inbound_q_nppd_hppd = 0; pm8001_ha->main_cfg_tbl.outbound_hw_event_pid0_3 = 0; pm8001_ha->main_cfg_tbl.outbound_hw_event_pid4_7 = 0; pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid0_3 = 0; pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid4_7 = 0; pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid0_3 = 0; pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid4_7 = 0; pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid0_3 = 0; pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid4_7 = 0; pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid0_3 = 0; pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid4_7 = 0; pm8001_ha->main_cfg_tbl.upper_event_log_addr = pm8001_ha->memoryMap.region[AAP1].phys_addr_hi; pm8001_ha->main_cfg_tbl.lower_event_log_addr = pm8001_ha->memoryMap.region[AAP1].phys_addr_lo; pm8001_ha->main_cfg_tbl.event_log_size = PM8001_EVENT_LOG_SIZE; pm8001_ha->main_cfg_tbl.event_log_option = 0x01; pm8001_ha->main_cfg_tbl.upper_iop_event_log_addr = pm8001_ha->memoryMap.region[IOP].phys_addr_hi; pm8001_ha->main_cfg_tbl.lower_iop_event_log_addr = pm8001_ha->memoryMap.region[IOP].phys_addr_lo; pm8001_ha->main_cfg_tbl.iop_event_log_size = PM8001_EVENT_LOG_SIZE; pm8001_ha->main_cfg_tbl.iop_event_log_option = 0x01; pm8001_ha->main_cfg_tbl.fatal_err_interrupt = 0x01; for (i = 0; i < qn; i++) { pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt = 0x00000100 | (0x00000040 << 16) | (0x00<<30); pm8001_ha->inbnd_q_tbl[i].upper_base_addr = pm8001_ha->memoryMap.region[IB].phys_addr_hi; pm8001_ha->inbnd_q_tbl[i].lower_base_addr = pm8001_ha->memoryMap.region[IB].phys_addr_lo; pm8001_ha->inbnd_q_tbl[i].base_virt = (u8 *)pm8001_ha->memoryMap.region[IB].virt_ptr; pm8001_ha->inbnd_q_tbl[i].total_length = pm8001_ha->memoryMap.region[IB].total_len; pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr = pm8001_ha->memoryMap.region[CI].phys_addr_hi; pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr = pm8001_ha->memoryMap.region[CI].phys_addr_lo; pm8001_ha->inbnd_q_tbl[i].ci_virt = pm8001_ha->memoryMap.region[CI].virt_ptr; offsetib = i * 0x20; pm8001_ha->inbnd_q_tbl[i].pi_pci_bar = get_pci_bar_index(pm8001_mr32(addressib, (offsetib + 0x14))); pm8001_ha->inbnd_q_tbl[i].pi_offset = pm8001_mr32(addressib, (offsetib + 0x18)); pm8001_ha->inbnd_q_tbl[i].producer_idx = 0; pm8001_ha->inbnd_q_tbl[i].consumer_index = 0; } for (i = 0; i < qn; i++) { pm8001_ha->outbnd_q_tbl[i].element_size_cnt = 256 | (64 << 16) | (1<<30); pm8001_ha->outbnd_q_tbl[i].upper_base_addr = pm8001_ha->memoryMap.region[OB].phys_addr_hi; pm8001_ha->outbnd_q_tbl[i].lower_base_addr = pm8001_ha->memoryMap.region[OB].phys_addr_lo; pm8001_ha->outbnd_q_tbl[i].base_virt = (u8 *)pm8001_ha->memoryMap.region[OB].virt_ptr; pm8001_ha->outbnd_q_tbl[i].total_length = pm8001_ha->memoryMap.region[OB].total_len; pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr = pm8001_ha->memoryMap.region[PI].phys_addr_hi; pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr = pm8001_ha->memoryMap.region[PI].phys_addr_lo; pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay = 0 | (10 << 16) | (0 << 24); pm8001_ha->outbnd_q_tbl[i].pi_virt = pm8001_ha->memoryMap.region[PI].virt_ptr; offsetob = i * 0x24; pm8001_ha->outbnd_q_tbl[i].ci_pci_bar = get_pci_bar_index(pm8001_mr32(addressob, offsetob + 0x14)); pm8001_ha->outbnd_q_tbl[i].ci_offset = pm8001_mr32(addressob, (offsetob + 0x18)); pm8001_ha->outbnd_q_tbl[i].consumer_idx = 0; pm8001_ha->outbnd_q_tbl[i].producer_index = 0; } } /** * update_main_config_table - update the main default table to the HBA. * @pm8001_ha: our hba card information */ static void __devinit update_main_config_table(struct pm8001_hba_info *pm8001_ha) { void __iomem *address = pm8001_ha->main_cfg_tbl_addr; pm8001_mw32(address, 0x24, pm8001_ha->main_cfg_tbl.inbound_q_nppd_hppd); pm8001_mw32(address, 0x28, pm8001_ha->main_cfg_tbl.outbound_hw_event_pid0_3); pm8001_mw32(address, 0x2C, pm8001_ha->main_cfg_tbl.outbound_hw_event_pid4_7); pm8001_mw32(address, 0x30, pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid0_3); pm8001_mw32(address, 0x34, pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid4_7); pm8001_mw32(address, 0x38, pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid0_3); pm8001_mw32(address, 0x3C, pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid4_7); pm8001_mw32(address, 0x40, pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid0_3); pm8001_mw32(address, 0x44, pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid4_7); pm8001_mw32(address, 0x48, pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid0_3); pm8001_mw32(address, 0x4C, pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid4_7); pm8001_mw32(address, 0x50, pm8001_ha->main_cfg_tbl.upper_event_log_addr); pm8001_mw32(address, 0x54, pm8001_ha->main_cfg_tbl.lower_event_log_addr); pm8001_mw32(address, 0x58, pm8001_ha->main_cfg_tbl.event_log_size); pm8001_mw32(address, 0x5C, pm8001_ha->main_cfg_tbl.event_log_option); pm8001_mw32(address, 0x60, pm8001_ha->main_cfg_tbl.upper_iop_event_log_addr); pm8001_mw32(address, 0x64, pm8001_ha->main_cfg_tbl.lower_iop_event_log_addr); pm8001_mw32(address, 0x68, pm8001_ha->main_cfg_tbl.iop_event_log_size); pm8001_mw32(address, 0x6C, pm8001_ha->main_cfg_tbl.iop_event_log_option); pm8001_mw32(address, 0x70, pm8001_ha->main_cfg_tbl.fatal_err_interrupt); } /** * update_inbnd_queue_table - update the inbound queue table to the HBA. * @pm8001_ha: our hba card information */ static void __devinit update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha, int number) { void __iomem *address = pm8001_ha->inbnd_q_tbl_addr; u16 offset = number * 0x20; pm8001_mw32(address, offset + 0x00, pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt); pm8001_mw32(address, offset + 0x04, pm8001_ha->inbnd_q_tbl[number].upper_base_addr); pm8001_mw32(address, offset + 0x08, pm8001_ha->inbnd_q_tbl[number].lower_base_addr); pm8001_mw32(address, offset + 0x0C, pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr); pm8001_mw32(address, offset + 0x10, pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr); } /** * update_outbnd_queue_table - update the outbound queue table to the HBA. * @pm8001_ha: our hba card information */ static void __devinit update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha, int number) { void __iomem *address = pm8001_ha->outbnd_q_tbl_addr; u16 offset = number * 0x24; pm8001_mw32(address, offset + 0x00, pm8001_ha->outbnd_q_tbl[number].element_size_cnt); pm8001_mw32(address, offset + 0x04, pm8001_ha->outbnd_q_tbl[number].upper_base_addr); pm8001_mw32(address, offset + 0x08, pm8001_ha->outbnd_q_tbl[number].lower_base_addr); pm8001_mw32(address, offset + 0x0C, pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr); pm8001_mw32(address, offset + 0x10, pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr); pm8001_mw32(address, offset + 0x1C, pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay); } /** * pm8001_bar4_shift - function is called to shift BAR base address * @pm8001_ha : our hba card infomation * @shiftValue : shifting value in memory bar. */ int pm8001_bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue) { u32 regVal; unsigned long start; /* program the inbound AXI translation Lower Address */ pm8001_cw32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW, shiftValue); /* confirm the setting is written */ start = jiffies + HZ; /* 1 sec */ do { regVal = pm8001_cr32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW); } while ((regVal != shiftValue) && time_before(jiffies, start)); if (regVal != shiftValue) { PM8001_INIT_DBG(pm8001_ha, pm8001_printk("TIMEOUT:SPC_IBW_AXI_TRANSLATION_LOW" " = 0x%x\n", regVal)); return -1; } return 0; } /** * mpi_set_phys_g3_with_ssc * @pm8001_ha: our hba card information * @SSCbit: set SSCbit to 0 to disable all phys ssc; 1 to enable all phys ssc. */ static void __devinit mpi_set_phys_g3_with_ssc(struct pm8001_hba_info *pm8001_ha, u32 SSCbit) { u32 value, offset, i; unsigned long flags; #define SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR 0x00030000 #define SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR 0x00040000 #define SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET 0x1074 #define SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET 0x1074 #define PHY_G3_WITHOUT_SSC_BIT_SHIFT 12 #define PHY_G3_WITH_SSC_BIT_SHIFT 13 #define SNW3_PHY_CAPABILITIES_PARITY 31 /* * Using shifted destination address 0x3_0000:0x1074 + 0x4000*N (N=0:3) * Using shifted destination address 0x4_0000:0x1074 + 0x4000*(N-4) (N=4:7) */ spin_lock_irqsave(&pm8001_ha->lock, flags); if (-1 == pm8001_bar4_shift(pm8001_ha, SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); return; } for (i = 0; i < 4; i++) { offset = SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET + 0x4000 * i; pm8001_cw32(pm8001_ha, 2, offset, 0x80001501); } /* shift membase 3 for SAS2_SETTINGS_LOCAL_PHY 4 - 7 */ if (-1 == pm8001_bar4_shift(pm8001_ha, SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); return; } for (i = 4; i < 8; i++) { offset = SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET + 0x4000 * (i-4); pm8001_cw32(pm8001_ha, 2, offset, 0x80001501); } /************************************************************* Change the SSC upspreading value to 0x0 so that upspreading is disabled. Device MABC SMOD0 Controls Address: (via MEMBASE-III): Using shifted destination address 0x0_0000: with Offset 0xD8 31:28 R/W Reserved Do not change 27:24 R/W SAS_SMOD_SPRDUP 0000 23:20 R/W SAS_SMOD_SPRDDN 0000 19:0 R/W Reserved Do not change Upon power-up this register will read as 0x8990c016, and I would like you to change the SAS_SMOD_SPRDUP bits to 0b0000 so that the written value will be 0x8090c016. This will ensure only down-spreading SSC is enabled on the SPC. *************************************************************/ value = pm8001_cr32(pm8001_ha, 2, 0xd8); pm8001_cw32(pm8001_ha, 2, 0xd8, 0x8000C016); /*set the shifted destination address to 0x0 to avoid error operation */ pm8001_bar4_shift(pm8001_ha, 0x0); spin_unlock_irqrestore(&pm8001_ha->lock, flags); return; } /** * mpi_set_open_retry_interval_reg * @pm8001_ha: our hba card information * @interval - interval time for each OPEN_REJECT (RETRY). The units are in 1us. */ static void __devinit mpi_set_open_retry_interval_reg(struct pm8001_hba_info *pm8001_ha, u32 interval) { u32 offset; u32 value; u32 i; unsigned long flags; #define OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR 0x00030000 #define OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR 0x00040000 #define OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET 0x30B4 #define OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET 0x30B4 #define OPEN_RETRY_INTERVAL_REG_MASK 0x0000FFFF value = interval & OPEN_RETRY_INTERVAL_REG_MASK; spin_lock_irqsave(&pm8001_ha->lock, flags); /* shift bar and set the OPEN_REJECT(RETRY) interval time of PHY 0 -3.*/ if (-1 == pm8001_bar4_shift(pm8001_ha, OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); return; } for (i = 0; i < 4; i++) { offset = OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET + 0x4000 * i; pm8001_cw32(pm8001_ha, 2, offset, value); } if (-1 == pm8001_bar4_shift(pm8001_ha, OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); return; } for (i = 4; i < 8; i++) { offset = OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET + 0x4000 * (i-4); pm8001_cw32(pm8001_ha, 2, offset, value); } /*set the shifted destination address to 0x0 to avoid error operation */ pm8001_bar4_shift(pm8001_ha, 0x0); spin_unlock_irqrestore(&pm8001_ha->lock, flags); return; } /** * mpi_init_check - check firmware initialization status. * @pm8001_ha: our hba card information */ static int mpi_init_check(struct pm8001_hba_info *pm8001_ha) { u32 max_wait_count; u32 value; u32 gst_len_mpistate; /* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the table is updated */ pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_UPDATE); /* wait until Inbound DoorBell Clear Register toggled */ max_wait_count = 1 * 1000 * 1000;/* 1 sec */ do { udelay(1); value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET); value &= SPC_MSGU_CFG_TABLE_UPDATE; } while ((value != 0) && (--max_wait_count)); if (!max_wait_count) return -1; /* check the MPI-State for initialization */ gst_len_mpistate = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, GST_GSTLEN_MPIS_OFFSET); if (GST_MPI_STATE_INIT != (gst_len_mpistate & GST_MPI_STATE_MASK)) return -1; /* check MPI Initialization error */ gst_len_mpistate = gst_len_mpistate >> 16; if (0x0000 != gst_len_mpistate) return -1; return 0; } /** * check_fw_ready - The LLDD check if the FW is ready, if not, return error. * @pm8001_ha: our hba card information */ static int check_fw_ready(struct pm8001_hba_info *pm8001_ha) { u32 value, value1; u32 max_wait_count; /* check error state */ value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2); /* check AAP error */ if (SCRATCH_PAD1_ERR == (value & SCRATCH_PAD_STATE_MASK)) { /* error state */ value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0); return -1; } /* check IOP error */ if (SCRATCH_PAD2_ERR == (value1 & SCRATCH_PAD_STATE_MASK)) { /* error state */ value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3); return -1; } /* bit 4-31 of scratch pad1 should be zeros if it is not in error state*/ if (value & SCRATCH_PAD1_STATE_MASK) { /* error case */ pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0); return -1; } /* bit 2, 4-31 of scratch pad2 should be zeros if it is not in error state */ if (value1 & SCRATCH_PAD2_STATE_MASK) { /* error case */ return -1; } max_wait_count = 1 * 1000 * 1000;/* 1 sec timeout */ /* wait until scratch pad 1 and 2 registers in ready state */ do { udelay(1); value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) & SCRATCH_PAD1_RDY; value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) & SCRATCH_PAD2_RDY; if ((--max_wait_count) == 0) return -1; } while ((value != SCRATCH_PAD1_RDY) || (value1 != SCRATCH_PAD2_RDY)); return 0; } static void init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha) { void __iomem *base_addr; u32 value; u32 offset; u32 pcibar; u32 pcilogic; value = pm8001_cr32(pm8001_ha, 0, 0x44); offset = value & 0x03FFFFFF; PM8001_INIT_DBG(pm8001_ha, pm8001_printk("Scratchpad 0 Offset: %x\n", offset)); pcilogic = (value & 0xFC000000) >> 26; pcibar = get_pci_bar_index(pcilogic); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("Scratchpad 0 PCI BAR: %d\n", pcibar)); pm8001_ha->main_cfg_tbl_addr = base_addr = pm8001_ha->io_mem[pcibar].memvirtaddr + offset; pm8001_ha->general_stat_tbl_addr = base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x18); pm8001_ha->inbnd_q_tbl_addr = base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C); pm8001_ha->outbnd_q_tbl_addr = base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x20); } /** * pm8001_chip_init - the main init function that initialize whole PM8001 chip. * @pm8001_ha: our hba card information */ static int __devinit pm8001_chip_init(struct pm8001_hba_info *pm8001_ha) { /* check the firmware status */ if (-1 == check_fw_ready(pm8001_ha)) { PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Firmware is not ready!\n")); return -EBUSY; } /* Initialize pci space address eg: mpi offset */ init_pci_device_addresses(pm8001_ha); init_default_table_values(pm8001_ha); read_main_config_table(pm8001_ha); read_general_status_table(pm8001_ha); read_inbnd_queue_table(pm8001_ha); read_outbnd_queue_table(pm8001_ha); /* update main config table ,inbound table and outbound table */ update_main_config_table(pm8001_ha); update_inbnd_queue_table(pm8001_ha, 0); update_outbnd_queue_table(pm8001_ha, 0); mpi_set_phys_g3_with_ssc(pm8001_ha, 0); /* 7->130ms, 34->500ms, 119->1.5s */ mpi_set_open_retry_interval_reg(pm8001_ha, 119); /* notify firmware update finished and check initialization status */ if (0 == mpi_init_check(pm8001_ha)) { PM8001_INIT_DBG(pm8001_ha, pm8001_printk("MPI initialize successful!\n")); } else return -EBUSY; /*This register is a 16-bit timer with a resolution of 1us. This is the timer used for interrupt delay/coalescing in the PCIe Application Layer. Zero is not a valid value. A value of 1 in the register will cause the interrupts to be normal. A value greater than 1 will cause coalescing delays.*/ pm8001_cw32(pm8001_ha, 1, 0x0033c0, 0x1); pm8001_cw32(pm8001_ha, 1, 0x0033c4, 0x0); return 0; } static int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha) { u32 max_wait_count; u32 value; u32 gst_len_mpistate; init_pci_device_addresses(pm8001_ha); /* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the table is stop */ pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_RESET); /* wait until Inbound DoorBell Clear Register toggled */ max_wait_count = 1 * 1000 * 1000;/* 1 sec */ do { udelay(1); value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET); value &= SPC_MSGU_CFG_TABLE_RESET; } while ((value != 0) && (--max_wait_count)); if (!max_wait_count) { PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("TIMEOUT:IBDB value/=0x%x\n", value)); return -1; } /* check the MPI-State for termination in progress */ /* wait until Inbound DoorBell Clear Register toggled */ max_wait_count = 1 * 1000 * 1000; /* 1 sec */ do { udelay(1); gst_len_mpistate = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, GST_GSTLEN_MPIS_OFFSET); if (GST_MPI_STATE_UNINIT == (gst_len_mpistate & GST_MPI_STATE_MASK)) break; } while (--max_wait_count); if (!max_wait_count) { PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(" TIME OUT MPI State = 0x%x\n", gst_len_mpistate & GST_MPI_STATE_MASK)); return -1; } return 0; } /** * soft_reset_ready_check - Function to check FW is ready for soft reset. * @pm8001_ha: our hba card information */ static u32 soft_reset_ready_check(struct pm8001_hba_info *pm8001_ha) { u32 regVal, regVal1, regVal2; if (mpi_uninit_check(pm8001_ha) != 0) { PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("MPI state is not ready\n")); return -1; } /* read the scratch pad 2 register bit 2 */ regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) & SCRATCH_PAD2_FWRDY_RST; if (regVal == SCRATCH_PAD2_FWRDY_RST) { PM8001_INIT_DBG(pm8001_ha, pm8001_printk("Firmware is ready for reset .\n")); } else { unsigned long flags; /* Trigger NMI twice via RB6 */ spin_lock_irqsave(&pm8001_ha->lock, flags); if (-1 == pm8001_bar4_shift(pm8001_ha, RB6_ACCESS_REG)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Shift Bar4 to 0x%x failed\n", RB6_ACCESS_REG)); return -1; } pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET, RB6_MAGIC_NUMBER_RST); pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET, RB6_MAGIC_NUMBER_RST); /* wait for 100 ms */ mdelay(100); regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) & SCRATCH_PAD2_FWRDY_RST; if (regVal != SCRATCH_PAD2_FWRDY_RST) { regVal1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); regVal2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("TIMEOUT:MSGU_SCRATCH_PAD1" "=0x%x, MSGU_SCRATCH_PAD2=0x%x\n", regVal1, regVal2)); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("SCRATCH_PAD0 value = 0x%x\n", pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0))); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("SCRATCH_PAD3 value = 0x%x\n", pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3))); spin_unlock_irqrestore(&pm8001_ha->lock, flags); return -1; } spin_unlock_irqrestore(&pm8001_ha->lock, flags); } return 0; } /** * pm8001_chip_soft_rst - soft reset the PM8001 chip, so that the clear all * the FW register status to the originated status. * @pm8001_ha: our hba card information * @signature: signature in host scratch pad0 register. */ static int pm8001_chip_soft_rst(struct pm8001_hba_info *pm8001_ha, u32 signature) { u32 regVal, toggleVal; u32 max_wait_count; u32 regVal1, regVal2, regVal3; unsigned long flags; /* step1: Check FW is ready for soft reset */ if (soft_reset_ready_check(pm8001_ha) != 0) { PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("FW is not ready\n")); return -1; } /* step 2: clear NMI status register on AAP1 and IOP, write the same value to clear */ /* map 0x60000 to BAR4(0x20), BAR2(win) */ spin_lock_irqsave(&pm8001_ha->lock, flags); if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_AAP1_ADDR_BASE)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Shift Bar4 to 0x%x failed\n", MBIC_AAP1_ADDR_BASE)); return -1; } regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("MBIC - NMI Enable VPE0 (IOP)= 0x%x\n", regVal)); pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP, 0x0); /* map 0x70000 to BAR4(0x20), BAR2(win) */ if (-1 == pm8001_bar4_shift(pm8001_ha, MBIC_IOP_ADDR_BASE)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Shift Bar4 to 0x%x failed\n", MBIC_IOP_ADDR_BASE)); return -1; } regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("MBIC - NMI Enable VPE0 (AAP1)= 0x%x\n", regVal)); pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1, 0x0); regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("PCIE -Event Interrupt Enable = 0x%x\n", regVal)); pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE, 0x0); regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("PCIE - Event Interrupt = 0x%x\n", regVal)); pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT, regVal); regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("PCIE -Error Interrupt Enable = 0x%x\n", regVal)); pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE, 0x0); regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("PCIE - Error Interrupt = 0x%x\n", regVal)); pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT, regVal); /* read the scratch pad 1 register bit 2 */ regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) & SCRATCH_PAD1_RST; toggleVal = regVal ^ SCRATCH_PAD1_RST; /* set signature in host scratch pad0 register to tell SPC that the host performs the soft reset */ pm8001_cw32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_0, signature); /* read required registers for confirmming */ /* map 0x0700000 to BAR4(0x20), BAR2(win) */ if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Shift Bar4 to 0x%x failed\n", GSM_ADDR_BASE)); return -1; } PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x0(0x00007b88)-GSM Configuration and" " Reset = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET))); /* step 3: host read GSM Configuration and Reset register */ regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET); /* Put those bits to low */ /* GSM XCBI offset = 0x70 0000 0x00 Bit 13 COM_SLV_SW_RSTB 1 0x00 Bit 12 QSSP_SW_RSTB 1 0x00 Bit 11 RAAE_SW_RSTB 1 0x00 Bit 9 RB_1_SW_RSTB 1 0x00 Bit 8 SM_SW_RSTB 1 */ regVal &= ~(0x00003b00); /* host write GSM Configuration and Reset register */ pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x0 (0x00007b88 ==> 0x00004088) - GSM " "Configuration and Reset is set to = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET))); /* step 4: */ /* disable GSM - Read Address Parity Check */ regVal1 = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x700038 - Read Address Parity Check " "Enable = 0x%x\n", regVal1)); pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, 0x0); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x700038 - Read Address Parity Check Enable" "is set to = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK))); /* disable GSM - Write Address Parity Check */ regVal2 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x700040 - Write Address Parity Check" " Enable = 0x%x\n", regVal2)); pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, 0x0); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x700040 - Write Address Parity Check " "Enable is set to = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK))); /* disable GSM - Write Data Parity Check */ regVal3 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x300048 - Write Data Parity Check" " Enable = 0x%x\n", regVal3)); pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, 0x0); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x300048 - Write Data Parity Check Enable" "is set to = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK))); /* step 5: delay 10 usec */ udelay(10); /* step 5-b: set GPIO-0 output control to tristate anyway */ if (-1 == pm8001_bar4_shift(pm8001_ha, GPIO_ADDR_BASE)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("Shift Bar4 to 0x%x failed\n", GPIO_ADDR_BASE)); return -1; } regVal = pm8001_cr32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GPIO Output Control Register:" " = 0x%x\n", regVal)); /* set GPIO-0 output control to tri-state */ regVal &= 0xFFFFFFFC; pm8001_cw32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET, regVal); /* Step 6: Reset the IOP and AAP1 */ /* map 0x00000 to BAR4(0x20), BAR2(win) */ if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("SPC Shift Bar4 to 0x%x failed\n", SPC_TOP_LEVEL_ADDR_BASE)); return -1; } regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("Top Register before resetting IOP/AAP1" ":= 0x%x\n", regVal)); regVal &= ~(SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS); pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal); /* step 7: Reset the BDMA/OSSP */ regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("Top Register before resetting BDMA/OSSP" ": = 0x%x\n", regVal)); regVal &= ~(SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP); pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal); /* step 8: delay 10 usec */ udelay(10); /* step 9: bring the BDMA and OSSP out of reset */ regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("Top Register before bringing up BDMA/OSSP" ":= 0x%x\n", regVal)); regVal |= (SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP); pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal); /* step 10: delay 10 usec */ udelay(10); /* step 11: reads and sets the GSM Configuration and Reset Register */ /* map 0x0700000 to BAR4(0x20), BAR2(win) */ if (-1 == pm8001_bar4_shift(pm8001_ha, GSM_ADDR_BASE)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("SPC Shift Bar4 to 0x%x failed\n", GSM_ADDR_BASE)); return -1; } PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x0 (0x00007b88)-GSM Configuration and " "Reset = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET))); regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET); /* Put those bits to high */ /* GSM XCBI offset = 0x70 0000 0x00 Bit 13 COM_SLV_SW_RSTB 1 0x00 Bit 12 QSSP_SW_RSTB 1 0x00 Bit 11 RAAE_SW_RSTB 1 0x00 Bit 9 RB_1_SW_RSTB 1 0x00 Bit 8 SM_SW_RSTB 1 */ regVal |= (GSM_CONFIG_RESET_VALUE); pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM (0x00004088 ==> 0x00007b88) - GSM" " Configuration and Reset is set to = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET))); /* step 12: Restore GSM - Read Address Parity Check */ regVal = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK); /* just for debugging */ PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x700038 - Read Address Parity Check Enable" " = 0x%x\n", regVal)); pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, regVal1); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x700038 - Read Address Parity" " Check Enable is set to = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK))); /* Restore GSM - Write Address Parity Check */ regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK); pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, regVal2); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x700040 - Write Address Parity Check" " Enable is set to = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK))); /* Restore GSM - Write Data Parity Check */ regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK); pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, regVal3); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("GSM 0x700048 - Write Data Parity Check Enable" "is set to = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK))); /* step 13: bring the IOP and AAP1 out of reset */ /* map 0x00000 to BAR4(0x20), BAR2(win) */ if (-1 == pm8001_bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Shift Bar4 to 0x%x failed\n", SPC_TOP_LEVEL_ADDR_BASE)); return -1; } regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET); regVal |= (SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS); pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal); /* step 14: delay 10 usec - Normal Mode */ udelay(10); /* check Soft Reset Normal mode or Soft Reset HDA mode */ if (signature == SPC_SOFT_RESET_SIGNATURE) { /* step 15 (Normal Mode): wait until scratch pad1 register bit 2 toggled */ max_wait_count = 2 * 1000 * 1000;/* 2 sec */ do { udelay(1); regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) & SCRATCH_PAD1_RST; } while ((regVal != toggleVal) && (--max_wait_count)); if (!max_wait_count) { regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("TIMEOUT : ToggleVal 0x%x," "MSGU_SCRATCH_PAD1 = 0x%x\n", toggleVal, regVal)); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("SCRATCH_PAD0 value = 0x%x\n", pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0))); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("SCRATCH_PAD2 value = 0x%x\n", pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2))); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("SCRATCH_PAD3 value = 0x%x\n", pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3))); spin_unlock_irqrestore(&pm8001_ha->lock, flags); return -1; } /* step 16 (Normal) - Clear ODMR and ODCR */ pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL); pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL); /* step 17 (Normal Mode): wait for the FW and IOP to get ready - 1 sec timeout */ /* Wait for the SPC Configuration Table to be ready */ if (check_fw_ready(pm8001_ha) == -1) { regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1); /* return error if MPI Configuration Table not ready */ PM8001_INIT_DBG(pm8001_ha, pm8001_printk("FW not ready SCRATCH_PAD1" " = 0x%x\n", regVal)); regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2); /* return error if MPI Configuration Table not ready */ PM8001_INIT_DBG(pm8001_ha, pm8001_printk("FW not ready SCRATCH_PAD2" " = 0x%x\n", regVal)); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("SCRATCH_PAD0 value = 0x%x\n", pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0))); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("SCRATCH_PAD3 value = 0x%x\n", pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3))); spin_unlock_irqrestore(&pm8001_ha->lock, flags); return -1; } } pm8001_bar4_shift(pm8001_ha, 0); spin_unlock_irqrestore(&pm8001_ha->lock, flags); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("SPC soft reset Complete\n")); return 0; } static void pm8001_hw_chip_rst(struct pm8001_hba_info *pm8001_ha) { u32 i; u32 regVal; PM8001_INIT_DBG(pm8001_ha, pm8001_printk("chip reset start\n")); /* do SPC chip reset. */ regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET); regVal &= ~(SPC_REG_RESET_DEVICE); pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal); /* delay 10 usec */ udelay(10); /* bring chip reset out of reset */ regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET); regVal |= SPC_REG_RESET_DEVICE; pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal); /* delay 10 usec */ udelay(10); /* wait for 20 msec until the firmware gets reloaded */ i = 20; do { mdelay(1); } while ((--i) != 0); PM8001_INIT_DBG(pm8001_ha, pm8001_printk("chip reset finished\n")); } /** * pm8001_chip_iounmap - which maped when initialized. * @pm8001_ha: our hba card information */ static void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha) { s8 bar, logical = 0; for (bar = 0; bar < 6; bar++) { /* ** logical BARs for SPC: ** bar 0 and 1 - logical BAR0 ** bar 2 and 3 - logical BAR1 ** bar4 - logical BAR2 ** bar5 - logical BAR3 ** Skip the appropriate assignments: */ if ((bar == 1) || (bar == 3)) continue; if (pm8001_ha->io_mem[logical].memvirtaddr) { iounmap(pm8001_ha->io_mem[logical].memvirtaddr); logical++; } } } /** * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt * @pm8001_ha: our hba card information */ static void pm8001_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha) { pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL); pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL); } /** * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt * @pm8001_ha: our hba card information */ static void pm8001_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha) { pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_MASK_ALL); } /** * pm8001_chip_msix_interrupt_enable - enable PM8001 chip interrupt * @pm8001_ha: our hba card information */ static void pm8001_chip_msix_interrupt_enable(struct pm8001_hba_info *pm8001_ha, u32 int_vec_idx) { u32 msi_index; u32 value; msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE; msi_index += MSIX_TABLE_BASE; pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_ENABLE); value = (1 << int_vec_idx); pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, value); } /** * pm8001_chip_msix_interrupt_disable - disable PM8001 chip interrupt * @pm8001_ha: our hba card information */ static void pm8001_chip_msix_interrupt_disable(struct pm8001_hba_info *pm8001_ha, u32 int_vec_idx) { u32 msi_index; msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE; msi_index += MSIX_TABLE_BASE; pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_DISABLE); } /** * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt * @pm8001_ha: our hba card information */ static void pm8001_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha) { #ifdef PM8001_USE_MSIX pm8001_chip_msix_interrupt_enable(pm8001_ha, 0); return; #endif pm8001_chip_intx_interrupt_enable(pm8001_ha); } /** * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt * @pm8001_ha: our hba card information */ static void pm8001_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha) { #ifdef PM8001_USE_MSIX pm8001_chip_msix_interrupt_disable(pm8001_ha, 0); return; #endif pm8001_chip_intx_interrupt_disable(pm8001_ha); } /** * mpi_msg_free_get- get the free message buffer for transfer inbound queue. * @circularQ: the inbound queue we want to transfer to HBA. * @messageSize: the message size of this transfer, normally it is 64 bytes * @messagePtr: the pointer to message. */ static int mpi_msg_free_get(struct inbound_queue_table *circularQ, u16 messageSize, void **messagePtr) { u32 offset, consumer_index; struct mpi_msg_hdr *msgHeader; u8 bcCount = 1; /* only support single buffer */ /* Checks is the requested message size can be allocated in this queue*/ if (messageSize > 64) { *messagePtr = NULL; return -1; } /* Stores the new consumer index */ consumer_index = pm8001_read_32(circularQ->ci_virt); circularQ->consumer_index = cpu_to_le32(consumer_index); if (((circularQ->producer_idx + bcCount) % 256) == le32_to_cpu(circularQ->consumer_index)) { *messagePtr = NULL; return -1; } /* get memory IOMB buffer address */ offset = circularQ->producer_idx * 64; /* increment to next bcCount element */ circularQ->producer_idx = (circularQ->producer_idx + bcCount) % 256; /* Adds that distance to the base of the region virtual address plus the message header size*/ msgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt + offset); *messagePtr = ((void *)msgHeader) + sizeof(struct mpi_msg_hdr); return 0; } /** * mpi_build_cmd- build the message queue for transfer, update the PI to FW * to tell the fw to get this message from IOMB. * @pm8001_ha: our hba card information * @circularQ: the inbound queue we want to transfer to HBA. * @opCode: the operation code represents commands which LLDD and fw recognized. * @payload: the command payload of each operation command. */ static int mpi_build_cmd(struct pm8001_hba_info *pm8001_ha, struct inbound_queue_table *circularQ, u32 opCode, void *payload) { u32 Header = 0, hpriority = 0, bc = 1, category = 0x02; u32 responseQueue = 0; void *pMessage; if (mpi_msg_free_get(circularQ, 64, &pMessage) < 0) { PM8001_IO_DBG(pm8001_ha, pm8001_printk("No free mpi buffer\n")); return -1; } BUG_ON(!payload); /*Copy to the payload*/ memcpy(pMessage, payload, (64 - sizeof(struct mpi_msg_hdr))); /*Build the header*/ Header = ((1 << 31) | (hpriority << 30) | ((bc & 0x1f) << 24) | ((responseQueue & 0x3F) << 16) | ((category & 0xF) << 12) | (opCode & 0xFFF)); pm8001_write_32((pMessage - 4), 0, cpu_to_le32(Header)); /*Update the PI to the firmware*/ pm8001_cw32(pm8001_ha, circularQ->pi_pci_bar, circularQ->pi_offset, circularQ->producer_idx); PM8001_IO_DBG(pm8001_ha, pm8001_printk("after PI= %d CI= %d\n", circularQ->producer_idx, circularQ->consumer_index)); return 0; } static u32 mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg, struct outbound_queue_table *circularQ, u8 bc) { u32 producer_index; struct mpi_msg_hdr *msgHeader; struct mpi_msg_hdr *pOutBoundMsgHeader; msgHeader = (struct mpi_msg_hdr *)(pMsg - sizeof(struct mpi_msg_hdr)); pOutBoundMsgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt + circularQ->consumer_idx * 64); if (pOutBoundMsgHeader != msgHeader) { PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("consumer_idx = %d msgHeader = %p\n", circularQ->consumer_idx, msgHeader)); /* Update the producer index from SPC */ producer_index = pm8001_read_32(circularQ->pi_virt); circularQ->producer_index = cpu_to_le32(producer_index); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("consumer_idx = %d producer_index = %d" "msgHeader = %p\n", circularQ->consumer_idx, circularQ->producer_index, msgHeader)); return 0; } /* free the circular queue buffer elements associated with the message*/ circularQ->consumer_idx = (circularQ->consumer_idx + bc) % 256; /* update the CI of outbound queue */ pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, circularQ->ci_offset, circularQ->consumer_idx); /* Update the producer index from SPC*/ producer_index = pm8001_read_32(circularQ->pi_virt); circularQ->producer_index = cpu_to_le32(producer_index); PM8001_IO_DBG(pm8001_ha, pm8001_printk(" CI=%d PI=%d\n", circularQ->consumer_idx, circularQ->producer_index)); return 0; } /** * mpi_msg_consume- get the MPI message from outbound queue message table. * @pm8001_ha: our hba card information * @circularQ: the outbound queue table. * @messagePtr1: the message contents of this outbound message. * @pBC: the message size. */ static u32 mpi_msg_consume(struct pm8001_hba_info *pm8001_ha, struct outbound_queue_table *circularQ, void **messagePtr1, u8 *pBC) { struct mpi_msg_hdr *msgHeader; __le32 msgHeader_tmp; u32 header_tmp; do { /* If there are not-yet-delivered messages ... */ if (le32_to_cpu(circularQ->producer_index) != circularQ->consumer_idx) { /*Get the pointer to the circular queue buffer element*/ msgHeader = (struct mpi_msg_hdr *) (circularQ->base_virt + circularQ->consumer_idx * 64); /* read header */ header_tmp = pm8001_read_32(msgHeader); msgHeader_tmp = cpu_to_le32(header_tmp); if (0 != (le32_to_cpu(msgHeader_tmp) & 0x80000000)) { if (OPC_OUB_SKIP_ENTRY != (le32_to_cpu(msgHeader_tmp) & 0xfff)) { *messagePtr1 = ((u8 *)msgHeader) + sizeof(struct mpi_msg_hdr); *pBC = (u8)((le32_to_cpu(msgHeader_tmp) >> 24) & 0x1f); PM8001_IO_DBG(pm8001_ha, pm8001_printk(": CI=%d PI=%d " "msgHeader=%x\n", circularQ->consumer_idx, circularQ->producer_index, msgHeader_tmp)); return MPI_IO_STATUS_SUCCESS; } else { circularQ->consumer_idx = (circularQ->consumer_idx + ((le32_to_cpu(msgHeader_tmp) >> 24) & 0x1f)) % 256; msgHeader_tmp = 0; pm8001_write_32(msgHeader, 0, 0); /* update the CI of outbound queue */ pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, circularQ->ci_offset, circularQ->consumer_idx); } } else { circularQ->consumer_idx = (circularQ->consumer_idx + ((le32_to_cpu(msgHeader_tmp) >> 24) & 0x1f)) % 256; msgHeader_tmp = 0; pm8001_write_32(msgHeader, 0, 0); /* update the CI of outbound queue */ pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, circularQ->ci_offset, circularQ->consumer_idx); return MPI_IO_STATUS_FAIL; } } else { u32 producer_index; void *pi_virt = circularQ->pi_virt; /* Update the producer index from SPC */ producer_index = pm8001_read_32(pi_virt); circularQ->producer_index = cpu_to_le32(producer_index); } } while (le32_to_cpu(circularQ->producer_index) != circularQ->consumer_idx); /* while we don't have any more not-yet-delivered message */ /* report empty */ return MPI_IO_STATUS_BUSY; } static void pm8001_work_fn(struct work_struct *work) { struct pm8001_work *pw = container_of(work, struct pm8001_work, work); struct pm8001_device *pm8001_dev; struct domain_device *dev; /* * So far, all users of this stash an associated structure here. * If we get here, and this pointer is null, then the action * was cancelled. This nullification happens when the device * goes away. */ pm8001_dev = pw->data; /* Most stash device structure */ if ((pm8001_dev == NULL) || ((pw->handler != IO_XFER_ERROR_BREAK) && (pm8001_dev->dev_type == NO_DEVICE))) { kfree(pw); return; } switch (pw->handler) { case IO_XFER_ERROR_BREAK: { /* This one stashes the sas_task instead */ struct sas_task *t = (struct sas_task *)pm8001_dev; u32 tag; struct pm8001_ccb_info *ccb; struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha; unsigned long flags, flags1; struct task_status_struct *ts; int i; if (pm8001_query_task(t) == TMF_RESP_FUNC_SUCC) break; /* Task still on lu */ spin_lock_irqsave(&pm8001_ha->lock, flags); spin_lock_irqsave(&t->task_state_lock, flags1); if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) { spin_unlock_irqrestore(&t->task_state_lock, flags1); spin_unlock_irqrestore(&pm8001_ha->lock, flags); break; /* Task got completed by another */ } spin_unlock_irqrestore(&t->task_state_lock, flags1); /* Search for a possible ccb that matches the task */ for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) { ccb = &pm8001_ha->ccb_info[i]; tag = ccb->ccb_tag; if ((tag != 0xFFFFFFFF) && (ccb->task == t)) break; } if (!ccb) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); break; /* Task got freed by another */ } ts = &t->task_status; ts->resp = SAS_TASK_COMPLETE; /* Force the midlayer to retry */ ts->stat = SAS_QUEUE_FULL; pm8001_dev = ccb->device; if (pm8001_dev) pm8001_dev->running_req--; spin_lock_irqsave(&t->task_state_lock, flags1); t->task_state_flags &= ~SAS_TASK_STATE_PENDING; t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; t->task_state_flags |= SAS_TASK_STATE_DONE; if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { spin_unlock_irqrestore(&t->task_state_lock, flags1); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p" " done with event 0x%x resp 0x%x stat 0x%x but" " aborted by upper layer!\n", t, pw->handler, ts->resp, ts->stat)); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); spin_unlock_irqrestore(&pm8001_ha->lock, flags); } else { spin_unlock_irqrestore(&t->task_state_lock, flags1); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/* in order to force CPU ordering */ spin_unlock_irqrestore(&pm8001_ha->lock, flags); t->task_done(t); } } break; case IO_XFER_OPEN_RETRY_TIMEOUT: { /* This one stashes the sas_task instead */ struct sas_task *t = (struct sas_task *)pm8001_dev; u32 tag; struct pm8001_ccb_info *ccb; struct pm8001_hba_info *pm8001_ha = pw->pm8001_ha; unsigned long flags, flags1; int i, ret = 0; PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n")); ret = pm8001_query_task(t); PM8001_IO_DBG(pm8001_ha, switch (ret) { case TMF_RESP_FUNC_SUCC: pm8001_printk("...Task on lu\n"); break; case TMF_RESP_FUNC_COMPLETE: pm8001_printk("...Task NOT on lu\n"); break; default: pm8001_printk("...query task failed!!!\n"); break; }); spin_lock_irqsave(&pm8001_ha->lock, flags); spin_lock_irqsave(&t->task_state_lock, flags1); if (unlikely((t->task_state_flags & SAS_TASK_STATE_DONE))) { spin_unlock_irqrestore(&t->task_state_lock, flags1); spin_unlock_irqrestore(&pm8001_ha->lock, flags); if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */ (void)pm8001_abort_task(t); break; /* Task got completed by another */ } spin_unlock_irqrestore(&t->task_state_lock, flags1); /* Search for a possible ccb that matches the task */ for (i = 0; ccb = NULL, i < PM8001_MAX_CCB; i++) { ccb = &pm8001_ha->ccb_info[i]; tag = ccb->ccb_tag; if ((tag != 0xFFFFFFFF) && (ccb->task == t)) break; } if (!ccb) { spin_unlock_irqrestore(&pm8001_ha->lock, flags); if (ret == TMF_RESP_FUNC_SUCC) /* task on lu */ (void)pm8001_abort_task(t); break; /* Task got freed by another */ } pm8001_dev = ccb->device; dev = pm8001_dev->sas_device; switch (ret) { case TMF_RESP_FUNC_SUCC: /* task on lu */ ccb->open_retry = 1; /* Snub completion */ spin_unlock_irqrestore(&pm8001_ha->lock, flags); ret = pm8001_abort_task(t); ccb->open_retry = 0; switch (ret) { case TMF_RESP_FUNC_SUCC: case TMF_RESP_FUNC_COMPLETE: break; default: /* device misbehavior */ ret = TMF_RESP_FUNC_FAILED; PM8001_IO_DBG(pm8001_ha, pm8001_printk("...Reset phy\n")); pm8001_I_T_nexus_reset(dev); break; } break; case TMF_RESP_FUNC_COMPLETE: /* task not on lu */ spin_unlock_irqrestore(&pm8001_ha->lock, flags); /* Do we need to abort the task locally? */ break; default: /* device misbehavior */ spin_unlock_irqrestore(&pm8001_ha->lock, flags); ret = TMF_RESP_FUNC_FAILED; PM8001_IO_DBG(pm8001_ha, pm8001_printk("...Reset phy\n")); pm8001_I_T_nexus_reset(dev); } if (ret == TMF_RESP_FUNC_FAILED) t = NULL; pm8001_open_reject_retry(pm8001_ha, t, pm8001_dev); PM8001_IO_DBG(pm8001_ha, pm8001_printk("...Complete\n")); } break; case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: dev = pm8001_dev->sas_device; pm8001_I_T_nexus_reset(dev); break; case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY: dev = pm8001_dev->sas_device; pm8001_I_T_nexus_reset(dev); break; case IO_DS_IN_ERROR: dev = pm8001_dev->sas_device; pm8001_I_T_nexus_reset(dev); break; case IO_DS_NON_OPERATIONAL: dev = pm8001_dev->sas_device; pm8001_I_T_nexus_reset(dev); break; } kfree(pw); } static int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, void *data, int handler) { struct pm8001_work *pw; int ret = 0; pw = kmalloc(sizeof(struct pm8001_work), GFP_ATOMIC); if (pw) { pw->pm8001_ha = pm8001_ha; pw->data = data; pw->handler = handler; INIT_WORK(&pw->work, pm8001_work_fn); queue_work(pm8001_wq, &pw->work); } else ret = -ENOMEM; return ret; } /** * mpi_ssp_completion- process the event that FW response to the SSP request. * @pm8001_ha: our hba card information * @piomb: the message contents of this outbound message. * * When FW has completed a ssp request for example a IO request, after it has * filled the SG data with the data, it will trigger this event represent * that he has finished the job,please check the coresponding buffer. * So we will tell the caller who maybe waiting the result to tell upper layer * that the task has been finished. */ static void mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb) { struct sas_task *t; struct pm8001_ccb_info *ccb; unsigned long flags; u32 status; u32 param; u32 tag; struct ssp_completion_resp *psspPayload; struct task_status_struct *ts; struct ssp_response_iu *iu; struct pm8001_device *pm8001_dev; psspPayload = (struct ssp_completion_resp *)(piomb + 4); status = le32_to_cpu(psspPayload->status); tag = le32_to_cpu(psspPayload->tag); ccb = &pm8001_ha->ccb_info[tag]; if ((status == IO_ABORTED) && ccb->open_retry) { /* Being completed by another */ ccb->open_retry = 0; return; } pm8001_dev = ccb->device; param = le32_to_cpu(psspPayload->param); t = ccb->task; if (status && status != IO_UNDERFLOW) PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("sas IO status 0x%x\n", status)); if (unlikely(!t || !t->lldd_task || !t->dev)) return; ts = &t->task_status; switch (status) { case IO_SUCCESS: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS" ",param = %d\n", param)); if (param == 0) { ts->resp = SAS_TASK_COMPLETE; ts->stat = SAM_STAT_GOOD; } else { ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_PROTO_RESPONSE; ts->residual = param; iu = &psspPayload->ssp_resp_iu; sas_ssp_task_response(pm8001_ha->dev, t, iu); } if (pm8001_dev) pm8001_dev->running_req--; break; case IO_ABORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_ABORTED IOMB Tag\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_ABORTED_TASK; break; case IO_UNDERFLOW: /* SSP Completion with error */ PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW" ",param = %d\n", param)); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_UNDERRUN; ts->residual = param; if (pm8001_dev) pm8001_dev->running_req--; break; case IO_NO_DEVICE: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_NO_DEVICE\n")); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_PHY_DOWN; break; case IO_XFER_ERROR_BREAK: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_BREAK\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; /* Force the midlayer to retry */ ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_XFER_ERROR_PHY_NOT_READY: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_EPROTO; break; case IO_OPEN_CNX_ERROR_ZONE_VIOLATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_UNKNOWN; break; case IO_OPEN_CNX_ERROR_BREAK: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_UNKNOWN; if (!t->uldd_task) pm8001_handle_event(pm8001_ha, pm8001_dev, IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); break; case IO_OPEN_CNX_ERROR_BAD_DESTINATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_BAD_DEST; break; case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_" "NOT_SUPPORTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_CONN_RATE; break; case IO_OPEN_CNX_ERROR_WRONG_DESTINATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n")); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_WRONG_DEST; break; case IO_XFER_ERROR_NAK_RECEIVED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_XFER_ERROR_ACK_NAK_TIMEOUT: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_NAK_R_ERR; break; case IO_XFER_ERROR_DMA: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_DMA\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; break; case IO_XFER_OPEN_RETRY_TIMEOUT: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_XFER_ERROR_OFFSET_MISMATCH: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; break; case IO_PORT_IN_RESET: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_PORT_IN_RESET\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; break; case IO_DS_NON_OPERATIONAL: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_DS_NON_OPERATIONAL\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; if (!t->uldd_task) pm8001_handle_event(pm8001_ha, pm8001_dev, IO_DS_NON_OPERATIONAL); break; case IO_DS_IN_RECOVERY: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_DS_IN_RECOVERY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; break; case IO_TM_TAG_NOT_FOUND: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_TM_TAG_NOT_FOUND\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; break; case IO_SSP_EXT_IU_ZERO_LEN_ERROR: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SSP_EXT_IU_ZERO_LEN_ERROR\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; break; case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; default: PM8001_IO_DBG(pm8001_ha, pm8001_printk("Unknown status 0x%x\n", status)); /* not allowed case. Therefore, return failed status */ ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; break; } PM8001_IO_DBG(pm8001_ha, pm8001_printk("scsi_status = %x \n ", psspPayload->ssp_resp_iu.status)); spin_lock_irqsave(&t->task_state_lock, flags); t->task_state_flags &= ~SAS_TASK_STATE_PENDING; t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; t->task_state_flags |= SAS_TASK_STATE_DONE; if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { spin_unlock_irqrestore(&t->task_state_lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with" " io_status 0x%x resp 0x%x " "stat 0x%x but aborted by upper layer!\n", t, status, ts->resp, ts->stat)); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); } else { spin_unlock_irqrestore(&t->task_state_lock, flags); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/* in order to force CPU ordering */ t->task_done(t); } } /*See the comments for mpi_ssp_completion */ static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb) { struct sas_task *t; unsigned long flags; struct task_status_struct *ts; struct pm8001_ccb_info *ccb; struct pm8001_device *pm8001_dev; struct ssp_event_resp *psspPayload = (struct ssp_event_resp *)(piomb + 4); u32 event = le32_to_cpu(psspPayload->event); u32 tag = le32_to_cpu(psspPayload->tag); u32 port_id = le32_to_cpu(psspPayload->port_id); u32 dev_id = le32_to_cpu(psspPayload->device_id); ccb = &pm8001_ha->ccb_info[tag]; t = ccb->task; pm8001_dev = ccb->device; if (event) PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("sas IO status 0x%x\n", event)); if (unlikely(!t || !t->lldd_task || !t->dev)) return; ts = &t->task_status; PM8001_IO_DBG(pm8001_ha, pm8001_printk("port_id = %x,device_id = %x\n", port_id, dev_id)); switch (event) { case IO_OVERFLOW: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n");) ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_OVERRUN; ts->residual = 0; if (pm8001_dev) pm8001_dev->running_req--; break; case IO_XFER_ERROR_BREAK: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_BREAK\n")); pm8001_handle_event(pm8001_ha, t, IO_XFER_ERROR_BREAK); return; case IO_XFER_ERROR_PHY_NOT_READY: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT" "_SUPPORTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_EPROTO; break; case IO_OPEN_CNX_ERROR_ZONE_VIOLATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_UNKNOWN; break; case IO_OPEN_CNX_ERROR_BREAK: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_UNKNOWN; if (!t->uldd_task) pm8001_handle_event(pm8001_ha, pm8001_dev, IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); break; case IO_OPEN_CNX_ERROR_BAD_DESTINATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_BAD_DEST; break; case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_" "NOT_SUPPORTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_CONN_RATE; break; case IO_OPEN_CNX_ERROR_WRONG_DESTINATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_WRONG_DEST; break; case IO_XFER_ERROR_NAK_RECEIVED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_XFER_ERROR_ACK_NAK_TIMEOUT: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_NAK_R_ERR; break; case IO_XFER_OPEN_RETRY_TIMEOUT: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n")); pm8001_handle_event(pm8001_ha, t, IO_XFER_OPEN_RETRY_TIMEOUT); return; case IO_XFER_ERROR_UNEXPECTED_PHASE: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_OVERRUN; break; case IO_XFER_ERROR_XFER_RDY_OVERRUN: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_OVERRUN; break; case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_OVERRUN; break; case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_OVERRUN; break; case IO_XFER_ERROR_OFFSET_MISMATCH: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_OVERRUN; break; case IO_XFER_ERROR_XFER_ZERO_DATA_LEN: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_OVERRUN; break; case IO_XFER_CMD_FRAME_ISSUED: PM8001_IO_DBG(pm8001_ha, pm8001_printk(" IO_XFER_CMD_FRAME_ISSUED\n")); return; default: PM8001_IO_DBG(pm8001_ha, pm8001_printk("Unknown status 0x%x\n", event)); /* not allowed case. Therefore, return failed status */ ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_OVERRUN; break; } spin_lock_irqsave(&t->task_state_lock, flags); t->task_state_flags &= ~SAS_TASK_STATE_PENDING; t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; t->task_state_flags |= SAS_TASK_STATE_DONE; if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { spin_unlock_irqrestore(&t->task_state_lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with" " event 0x%x resp 0x%x " "stat 0x%x but aborted by upper layer!\n", t, event, ts->resp, ts->stat)); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); } else { spin_unlock_irqrestore(&t->task_state_lock, flags); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/* in order to force CPU ordering */ t->task_done(t); } } /*See the comments for mpi_ssp_completion */ static void mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) { struct sas_task *t; struct pm8001_ccb_info *ccb; u32 param; u32 status; u32 tag; struct sata_completion_resp *psataPayload; struct task_status_struct *ts; struct ata_task_resp *resp ; u32 *sata_resp; struct pm8001_device *pm8001_dev; unsigned long flags; psataPayload = (struct sata_completion_resp *)(piomb + 4); status = le32_to_cpu(psataPayload->status); tag = le32_to_cpu(psataPayload->tag); ccb = &pm8001_ha->ccb_info[tag]; param = le32_to_cpu(psataPayload->param); t = ccb->task; ts = &t->task_status; pm8001_dev = ccb->device; if (status) PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("sata IO status 0x%x\n", status)); if (unlikely(!t || !t->lldd_task || !t->dev)) return; switch (status) { case IO_SUCCESS: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n")); if (param == 0) { ts->resp = SAS_TASK_COMPLETE; ts->stat = SAM_STAT_GOOD; } else { u8 len; ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_PROTO_RESPONSE; ts->residual = param; PM8001_IO_DBG(pm8001_ha, pm8001_printk("SAS_PROTO_RESPONSE len = %d\n", param)); sata_resp = &psataPayload->sata_resp[0]; resp = (struct ata_task_resp *)ts->buf; if (t->ata_task.dma_xfer == 0 && t->data_dir == PCI_DMA_FROMDEVICE) { len = sizeof(struct pio_setup_fis); PM8001_IO_DBG(pm8001_ha, pm8001_printk("PIO read len = %d\n", len)); } else if (t->ata_task.use_ncq) { len = sizeof(struct set_dev_bits_fis); PM8001_IO_DBG(pm8001_ha, pm8001_printk("FPDMA len = %d\n", len)); } else { len = sizeof(struct dev_to_host_fis); PM8001_IO_DBG(pm8001_ha, pm8001_printk("other len = %d\n", len)); } if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) { resp->frame_len = len; memcpy(&resp->ending_fis[0], sata_resp, len); ts->buf_valid_size = sizeof(*resp); } else PM8001_IO_DBG(pm8001_ha, pm8001_printk("response to large\n")); } if (pm8001_dev) pm8001_dev->running_req--; break; case IO_ABORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_ABORTED IOMB Tag\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_ABORTED_TASK; if (pm8001_dev) pm8001_dev->running_req--; break; /* following cases are to do cases */ case IO_UNDERFLOW: /* SATA Completion with error */ PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW param = %d\n", param)); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_UNDERRUN; ts->residual = param; if (pm8001_dev) pm8001_dev->running_req--; break; case IO_NO_DEVICE: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_NO_DEVICE\n")); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_PHY_DOWN; break; case IO_XFER_ERROR_BREAK: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_BREAK\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_INTERRUPTED; break; case IO_XFER_ERROR_PHY_NOT_READY: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT" "_SUPPORTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_EPROTO; break; case IO_OPEN_CNX_ERROR_ZONE_VIOLATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_UNKNOWN; break; case IO_OPEN_CNX_ERROR_BREAK: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_CONT0; break; case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DEV_NO_RESPONSE; if (!t->uldd_task) { pm8001_handle_event(pm8001_ha, pm8001_dev, IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_QUEUE_FULL; pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/*in order to force CPU ordering*/ spin_unlock_irq(&pm8001_ha->lock); t->task_done(t); spin_lock_irq(&pm8001_ha->lock); return; } break; case IO_OPEN_CNX_ERROR_BAD_DESTINATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n")); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_BAD_DEST; if (!t->uldd_task) { pm8001_handle_event(pm8001_ha, pm8001_dev, IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_QUEUE_FULL; pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/*ditto*/ spin_unlock_irq(&pm8001_ha->lock); t->task_done(t); spin_lock_irq(&pm8001_ha->lock); return; } break; case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_" "NOT_SUPPORTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_CONN_RATE; break; case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_STP_RESOURCES" "_BUSY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DEV_NO_RESPONSE; if (!t->uldd_task) { pm8001_handle_event(pm8001_ha, pm8001_dev, IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_QUEUE_FULL; pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/* ditto*/ spin_unlock_irq(&pm8001_ha->lock); t->task_done(t); spin_lock_irq(&pm8001_ha->lock); return; } break; case IO_OPEN_CNX_ERROR_WRONG_DESTINATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_WRONG_DEST; break; case IO_XFER_ERROR_NAK_RECEIVED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_NAK_R_ERR; break; case IO_XFER_ERROR_ACK_NAK_TIMEOUT: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_NAK_R_ERR; break; case IO_XFER_ERROR_DMA: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_DMA\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_ABORTED_TASK; break; case IO_XFER_ERROR_SATA_LINK_TIMEOUT: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_SATA_LINK_TIMEOUT\n")); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_DEV_NO_RESPONSE; break; case IO_XFER_ERROR_REJECTED_NCQ_MODE: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_UNDERRUN; break; case IO_XFER_OPEN_RETRY_TIMEOUT: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_TO; break; case IO_PORT_IN_RESET: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_PORT_IN_RESET\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DEV_NO_RESPONSE; break; case IO_DS_NON_OPERATIONAL: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_DS_NON_OPERATIONAL\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DEV_NO_RESPONSE; if (!t->uldd_task) { pm8001_handle_event(pm8001_ha, pm8001_dev, IO_DS_NON_OPERATIONAL); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_QUEUE_FULL; pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/*ditto*/ spin_unlock_irq(&pm8001_ha->lock); t->task_done(t); spin_lock_irq(&pm8001_ha->lock); return; } break; case IO_DS_IN_RECOVERY: PM8001_IO_DBG(pm8001_ha, pm8001_printk(" IO_DS_IN_RECOVERY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DEV_NO_RESPONSE; break; case IO_DS_IN_ERROR: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_DS_IN_ERROR\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DEV_NO_RESPONSE; if (!t->uldd_task) { pm8001_handle_event(pm8001_ha, pm8001_dev, IO_DS_IN_ERROR); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_QUEUE_FULL; pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/*ditto*/ spin_unlock_irq(&pm8001_ha->lock); t->task_done(t); spin_lock_irq(&pm8001_ha->lock); return; } break; case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; default: PM8001_IO_DBG(pm8001_ha, pm8001_printk("Unknown status 0x%x\n", status)); /* not allowed case. Therefore, return failed status */ ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DEV_NO_RESPONSE; break; } spin_lock_irqsave(&t->task_state_lock, flags); t->task_state_flags &= ~SAS_TASK_STATE_PENDING; t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; t->task_state_flags |= SAS_TASK_STATE_DONE; if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { spin_unlock_irqrestore(&t->task_state_lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with io_status 0x%x" " resp 0x%x stat 0x%x but aborted by upper layer!\n", t, status, ts->resp, ts->stat)); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); } else if (t->uldd_task) { spin_unlock_irqrestore(&t->task_state_lock, flags); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/* ditto */ spin_unlock_irq(&pm8001_ha->lock); t->task_done(t); spin_lock_irq(&pm8001_ha->lock); } else if (!t->uldd_task) { spin_unlock_irqrestore(&t->task_state_lock, flags); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/*ditto*/ spin_unlock_irq(&pm8001_ha->lock); t->task_done(t); spin_lock_irq(&pm8001_ha->lock); } } /*See the comments for mpi_ssp_completion */ static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb) { struct sas_task *t; struct task_status_struct *ts; struct pm8001_ccb_info *ccb; struct pm8001_device *pm8001_dev; struct sata_event_resp *psataPayload = (struct sata_event_resp *)(piomb + 4); u32 event = le32_to_cpu(psataPayload->event); u32 tag = le32_to_cpu(psataPayload->tag); u32 port_id = le32_to_cpu(psataPayload->port_id); u32 dev_id = le32_to_cpu(psataPayload->device_id); unsigned long flags; ccb = &pm8001_ha->ccb_info[tag]; t = ccb->task; pm8001_dev = ccb->device; if (event) PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("sata IO status 0x%x\n", event)); if (unlikely(!t || !t->lldd_task || !t->dev)) return; ts = &t->task_status; PM8001_IO_DBG(pm8001_ha, pm8001_printk("port_id = %x,device_id = %x\n", port_id, dev_id)); switch (event) { case IO_OVERFLOW: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_OVERRUN; ts->residual = 0; if (pm8001_dev) pm8001_dev->running_req--; break; case IO_XFER_ERROR_BREAK: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_BREAK\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_INTERRUPTED; break; case IO_XFER_ERROR_PHY_NOT_READY: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT" "_SUPPORTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_EPROTO; break; case IO_OPEN_CNX_ERROR_ZONE_VIOLATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_UNKNOWN; break; case IO_OPEN_CNX_ERROR_BREAK: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_CONT0; break; case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n")); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_DEV_NO_RESPONSE; if (!t->uldd_task) { pm8001_handle_event(pm8001_ha, pm8001_dev, IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_QUEUE_FULL; pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/*ditto*/ spin_unlock_irq(&pm8001_ha->lock); t->task_done(t); spin_lock_irq(&pm8001_ha->lock); return; } break; case IO_OPEN_CNX_ERROR_BAD_DESTINATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n")); ts->resp = SAS_TASK_UNDELIVERED; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_BAD_DEST; break; case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_" "NOT_SUPPORTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_CONN_RATE; break; case IO_OPEN_CNX_ERROR_WRONG_DESTINATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_WRONG_DEST; break; case IO_XFER_ERROR_NAK_RECEIVED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_NAK_R_ERR; break; case IO_XFER_ERROR_PEER_ABORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_PEER_ABORTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_NAK_R_ERR; break; case IO_XFER_ERROR_REJECTED_NCQ_MODE: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_UNDERRUN; break; case IO_XFER_OPEN_RETRY_TIMEOUT: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_TO; break; case IO_XFER_ERROR_UNEXPECTED_PHASE: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_TO; break; case IO_XFER_ERROR_XFER_RDY_OVERRUN: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_TO; break; case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_TO; break; case IO_XFER_ERROR_OFFSET_MISMATCH: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_TO; break; case IO_XFER_ERROR_XFER_ZERO_DATA_LEN: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_TO; break; case IO_XFER_CMD_FRAME_ISSUED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_CMD_FRAME_ISSUED\n")); break; case IO_XFER_PIO_SETUP_ERROR: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_PIO_SETUP_ERROR\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_TO; break; default: PM8001_IO_DBG(pm8001_ha, pm8001_printk("Unknown status 0x%x\n", event)); /* not allowed case. Therefore, return failed status */ ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_TO; break; } spin_lock_irqsave(&t->task_state_lock, flags); t->task_state_flags &= ~SAS_TASK_STATE_PENDING; t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; t->task_state_flags |= SAS_TASK_STATE_DONE; if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { spin_unlock_irqrestore(&t->task_state_lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with io_status 0x%x" " resp 0x%x stat 0x%x but aborted by upper layer!\n", t, event, ts->resp, ts->stat)); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); } else if (t->uldd_task) { spin_unlock_irqrestore(&t->task_state_lock, flags); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/* ditto */ spin_unlock_irq(&pm8001_ha->lock); t->task_done(t); spin_lock_irq(&pm8001_ha->lock); } else if (!t->uldd_task) { spin_unlock_irqrestore(&t->task_state_lock, flags); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/*ditto*/ spin_unlock_irq(&pm8001_ha->lock); t->task_done(t); spin_lock_irq(&pm8001_ha->lock); } } /*See the comments for mpi_ssp_completion */ static void mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb) { u32 param; struct sas_task *t; struct pm8001_ccb_info *ccb; unsigned long flags; u32 status; u32 tag; struct smp_completion_resp *psmpPayload; struct task_status_struct *ts; struct pm8001_device *pm8001_dev; psmpPayload = (struct smp_completion_resp *)(piomb + 4); status = le32_to_cpu(psmpPayload->status); tag = le32_to_cpu(psmpPayload->tag); ccb = &pm8001_ha->ccb_info[tag]; param = le32_to_cpu(psmpPayload->param); t = ccb->task; ts = &t->task_status; pm8001_dev = ccb->device; if (status) PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("smp IO status 0x%x\n", status)); if (unlikely(!t || !t->lldd_task || !t->dev)) return; switch (status) { case IO_SUCCESS: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAM_STAT_GOOD; if (pm8001_dev) pm8001_dev->running_req--; break; case IO_ABORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_ABORTED IOMB\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_ABORTED_TASK; if (pm8001_dev) pm8001_dev->running_req--; break; case IO_OVERFLOW: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DATA_OVERRUN; ts->residual = 0; if (pm8001_dev) pm8001_dev->running_req--; break; case IO_NO_DEVICE: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_NO_DEVICE\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_PHY_DOWN; break; case IO_ERROR_HW_TIMEOUT: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_ERROR_HW_TIMEOUT\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAM_STAT_BUSY; break; case IO_XFER_ERROR_BREAK: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_BREAK\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAM_STAT_BUSY; break; case IO_XFER_ERROR_PHY_NOT_READY: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAM_STAT_BUSY; break; case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_UNKNOWN; break; case IO_OPEN_CNX_ERROR_ZONE_VIOLATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_UNKNOWN; break; case IO_OPEN_CNX_ERROR_BREAK: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_CONT0; break; case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_UNKNOWN; pm8001_handle_event(pm8001_ha, pm8001_dev, IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS); break; case IO_OPEN_CNX_ERROR_BAD_DESTINATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_BAD_DEST; break; case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_" "NOT_SUPPORTED\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_CONN_RATE; break; case IO_OPEN_CNX_ERROR_WRONG_DESTINATION: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_WRONG_DEST; break; case IO_XFER_ERROR_RX_FRAME: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_ERROR_RX_FRAME\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DEV_NO_RESPONSE; break; case IO_XFER_OPEN_RETRY_TIMEOUT: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_ERROR_INTERNAL_SMP_RESOURCE: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_ERROR_INTERNAL_SMP_RESOURCE\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_QUEUE_FULL; break; case IO_PORT_IN_RESET: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_PORT_IN_RESET\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_DS_NON_OPERATIONAL: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_DS_NON_OPERATIONAL\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DEV_NO_RESPONSE; break; case IO_DS_IN_RECOVERY: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_DS_IN_RECOVERY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY: PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_OPEN_REJECT; ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; break; default: PM8001_IO_DBG(pm8001_ha, pm8001_printk("Unknown status 0x%x\n", status)); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAS_DEV_NO_RESPONSE; /* not allowed case. Therefore, return failed status */ break; } spin_lock_irqsave(&t->task_state_lock, flags); t->task_state_flags &= ~SAS_TASK_STATE_PENDING; t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; t->task_state_flags |= SAS_TASK_STATE_DONE; if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) { spin_unlock_irqrestore(&t->task_state_lock, flags); PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with" " io_status 0x%x resp 0x%x " "stat 0x%x but aborted by upper layer!\n", t, status, ts->resp, ts->stat)); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); } else { spin_unlock_irqrestore(&t->task_state_lock, flags); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb();/* in order to force CPU ordering */ t->task_done(t); } } static void mpi_set_dev_state_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) { struct set_dev_state_resp *pPayload = (struct set_dev_state_resp *)(piomb + 4); u32 tag = le32_to_cpu(pPayload->tag); struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag]; struct pm8001_device *pm8001_dev = ccb->device; u32 status = le32_to_cpu(pPayload->status); u32 device_id = le32_to_cpu(pPayload->device_id); u8 pds = le32_to_cpu(pPayload->pds_nds) | PDS_BITS; u8 nds = le32_to_cpu(pPayload->pds_nds) | NDS_BITS; PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Set device id = 0x%x state " "from 0x%x to 0x%x status = 0x%x!\n", device_id, pds, nds, status)); complete(pm8001_dev->setds_completion); ccb->task = NULL; ccb->ccb_tag = 0xFFFFFFFF; pm8001_ccb_free(pm8001_ha, tag); } static void mpi_set_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) { struct get_nvm_data_resp *pPayload = (struct get_nvm_data_resp *)(piomb + 4); u32 tag = le32_to_cpu(pPayload->tag); struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag]; u32 dlen_status = le32_to_cpu(pPayload->dlen_status); complete(pm8001_ha->nvmd_completion); PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Set nvm data complete!\n")); if ((dlen_status & NVMD_STAT) != 0) { PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Set nvm data error!\n")); return; } ccb->task = NULL; ccb->ccb_tag = 0xFFFFFFFF; pm8001_ccb_free(pm8001_ha, tag); } static void mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) { struct fw_control_ex *fw_control_context; struct get_nvm_data_resp *pPayload = (struct get_nvm_data_resp *)(piomb + 4); u32 tag = le32_to_cpu(pPayload->tag); struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag]; u32 dlen_status = le32_to_cpu(pPayload->dlen_status); u32 ir_tds_bn_dps_das_nvm = le32_to_cpu(pPayload->ir_tda_bn_dps_das_nvm); void *virt_addr = pm8001_ha->memoryMap.region[NVMD].virt_ptr; fw_control_context = ccb->fw_control_context; PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Get nvm data complete!\n")); if ((dlen_status & NVMD_STAT) != 0) { PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Get nvm data error!\n")); complete(pm8001_ha->nvmd_completion); return; } if (ir_tds_bn_dps_das_nvm & IPMode) { /* indirect mode - IR bit set */ PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Get NVMD success, IR=1\n")); if ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == TWI_DEVICE) { if (ir_tds_bn_dps_das_nvm == 0x80a80200) { memcpy(pm8001_ha->sas_addr, ((u8 *)virt_addr + 4), SAS_ADDR_SIZE); PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Get SAS address" " from VPD successfully!\n")); } } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == C_SEEPROM) || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == VPD_FLASH) || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == EXPAN_ROM)) { ; } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == AAP1_RDUMP) || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == IOP_RDUMP)) { ; } else { /* Should not be happened*/ PM8001_MSG_DBG(pm8001_ha, pm8001_printk("(IR=1)Wrong Device type 0x%x\n", ir_tds_bn_dps_das_nvm)); } } else /* direct mode */{ PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Get NVMD success, IR=0, dataLen=%d\n", (dlen_status & NVMD_LEN) >> 24)); } memcpy(fw_control_context->usrAddr, pm8001_ha->memoryMap.region[NVMD].virt_ptr, fw_control_context->len); complete(pm8001_ha->nvmd_completion); ccb->task = NULL; ccb->ccb_tag = 0xFFFFFFFF; pm8001_ccb_free(pm8001_ha, tag); } static int mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb) { struct local_phy_ctl_resp *pPayload = (struct local_phy_ctl_resp *)(piomb + 4); u32 status = le32_to_cpu(pPayload->status); u32 phy_id = le32_to_cpu(pPayload->phyop_phyid) & ID_BITS; u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS; if (status != 0) { PM8001_MSG_DBG(pm8001_ha, pm8001_printk("%x phy execute %x phy op failed!\n", phy_id, phy_op)); } else PM8001_MSG_DBG(pm8001_ha, pm8001_printk("%x phy execute %x phy op success!\n", phy_id, phy_op)); return 0; } /** * pm8001_bytes_dmaed - one of the interface function communication with libsas * @pm8001_ha: our hba card information * @i: which phy that received the event. * * when HBA driver received the identify done event or initiate FIS received * event(for SATA), it will invoke this function to notify the sas layer that * the sas toplogy has formed, please discover the the whole sas domain, * while receive a broadcast(change) primitive just tell the sas * layer to discover the changed domain rather than the whole domain. */ static void pm8001_bytes_dmaed(struct pm8001_hba_info *pm8001_ha, int i) { struct pm8001_phy *phy = &pm8001_ha->phy[i]; struct asd_sas_phy *sas_phy = &phy->sas_phy; struct sas_ha_struct *sas_ha; if (!phy->phy_attached) return; sas_ha = pm8001_ha->sas; if (sas_phy->phy) { struct sas_phy *sphy = sas_phy->phy; sphy->negotiated_linkrate = sas_phy->linkrate; sphy->minimum_linkrate = phy->minimum_linkrate; sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; sphy->maximum_linkrate = phy->maximum_linkrate; sphy->maximum_linkrate_hw = phy->maximum_linkrate; } if (phy->phy_type & PORT_TYPE_SAS) { struct sas_identify_frame *id; id = (struct sas_identify_frame *)phy->frame_rcvd; id->dev_type = phy->identify.device_type; id->initiator_bits = SAS_PROTOCOL_ALL; id->target_bits = phy->identify.target_port_protocols; } else if (phy->phy_type & PORT_TYPE_SATA) { /*Nothing*/ } PM8001_MSG_DBG(pm8001_ha, pm8001_printk("phy %d byte dmaded.\n", i)); sas_phy->frame_rcvd_size = phy->frame_rcvd_size; pm8001_ha->sas->notify_port_event(sas_phy, PORTE_BYTES_DMAED); } /* Get the link rate speed */ static void get_lrate_mode(struct pm8001_phy *phy, u8 link_rate) { struct sas_phy *sas_phy = phy->sas_phy.phy; switch (link_rate) { case PHY_SPEED_60: phy->sas_phy.linkrate = SAS_LINK_RATE_6_0_GBPS; phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS; break; case PHY_SPEED_30: phy->sas_phy.linkrate = SAS_LINK_RATE_3_0_GBPS; phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS; break; case PHY_SPEED_15: phy->sas_phy.linkrate = SAS_LINK_RATE_1_5_GBPS; phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS; break; } sas_phy->negotiated_linkrate = phy->sas_phy.linkrate; sas_phy->maximum_linkrate_hw = SAS_LINK_RATE_6_0_GBPS; sas_phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; sas_phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS; sas_phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS; } /** * asd_get_attached_sas_addr -- extract/generate attached SAS address * @phy: pointer to asd_phy * @sas_addr: pointer to buffer where the SAS address is to be written * * This function extracts the SAS address from an IDENTIFY frame * received. If OOB is SATA, then a SAS address is generated from the * HA tables. * * LOCKING: the frame_rcvd_lock needs to be held since this parses the frame * buffer. */ static void pm8001_get_attached_sas_addr(struct pm8001_phy *phy, u8 *sas_addr) { if (phy->sas_phy.frame_rcvd[0] == 0x34 && phy->sas_phy.oob_mode == SATA_OOB_MODE) { struct pm8001_hba_info *pm8001_ha = phy->sas_phy.ha->lldd_ha; /* FIS device-to-host */ u64 addr = be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr); addr += phy->sas_phy.id; *(__be64 *)sas_addr = cpu_to_be64(addr); } else { struct sas_identify_frame *idframe = (void *) phy->sas_phy.frame_rcvd; memcpy(sas_addr, idframe->sas_addr, SAS_ADDR_SIZE); } } /** * pm8001_hw_event_ack_req- For PM8001,some events need to acknowage to FW. * @pm8001_ha: our hba card information * @Qnum: the outbound queue message number. * @SEA: source of event to ack * @port_id: port id. * @phyId: phy id. * @param0: parameter 0. * @param1: parameter 1. */ static void pm8001_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha, u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1) { struct hw_event_ack_req payload; u32 opc = OPC_INB_SAS_HW_EVENT_ACK; struct inbound_queue_table *circularQ; memset((u8 *)&payload, 0, sizeof(payload)); circularQ = &pm8001_ha->inbnd_q_tbl[Qnum]; payload.tag = cpu_to_le32(1); payload.sea_phyid_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) | ((phyId & 0x0F) << 4) | (port_id & 0x0F)); payload.param0 = cpu_to_le32(param0); payload.param1 = cpu_to_le32(param1); mpi_build_cmd(pm8001_ha, circularQ, opc, &payload); } static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha, u32 phyId, u32 phy_op); /** * hw_event_sas_phy_up -FW tells me a SAS phy up event. * @pm8001_ha: our hba card information * @piomb: IO message buffer */ static void hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb) { struct hw_event_resp *pPayload = (struct hw_event_resp *)(piomb + 4); u32 lr_evt_status_phyid_portid = le32_to_cpu(pPayload->lr_evt_status_phyid_portid); u8 link_rate = (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28); u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F); u8 phy_id = (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4); u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate); u8 portstate = (u8)(npip_portstate & 0x0000000F); struct pm8001_port *port = &pm8001_ha->port[port_id]; struct sas_ha_struct *sas_ha = pm8001_ha->sas; struct pm8001_phy *phy = &pm8001_ha->phy[phy_id]; unsigned long flags; u8 deviceType = pPayload->sas_identify.dev_type; port->port_state = portstate; PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_SAS_PHY_UP port id = %d, phy id = %d\n", port_id, phy_id)); switch (deviceType) { case SAS_PHY_UNUSED: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("device type no device.\n")); break; case SAS_END_DEVICE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("end device.\n")); pm8001_chip_phy_ctl_req(pm8001_ha, phy_id, PHY_NOTIFY_ENABLE_SPINUP); port->port_attached = 1; get_lrate_mode(phy, link_rate); break; case SAS_EDGE_EXPANDER_DEVICE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("expander device.\n")); port->port_attached = 1; get_lrate_mode(phy, link_rate); break; case SAS_FANOUT_EXPANDER_DEVICE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("fanout expander device.\n")); port->port_attached = 1; get_lrate_mode(phy, link_rate); break; default: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("unknown device type(%x)\n", deviceType)); break; } phy->phy_type |= PORT_TYPE_SAS; phy->identify.device_type = deviceType; phy->phy_attached = 1; if (phy->identify.device_type == SAS_END_DEVICE) phy->identify.target_port_protocols = SAS_PROTOCOL_SSP; else if (phy->identify.device_type != SAS_PHY_UNUSED) phy->identify.target_port_protocols = SAS_PROTOCOL_SMP; phy->sas_phy.oob_mode = SAS_OOB_MODE; sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE); spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags); memcpy(phy->frame_rcvd, &pPayload->sas_identify, sizeof(struct sas_identify_frame)-4); phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4; pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr); spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags); if (pm8001_ha->flags == PM8001F_RUN_TIME) mdelay(200);/*delay a moment to wait disk to spinup*/ pm8001_bytes_dmaed(pm8001_ha, phy_id); } /** * hw_event_sata_phy_up -FW tells me a SATA phy up event. * @pm8001_ha: our hba card information * @piomb: IO message buffer */ static void hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb) { struct hw_event_resp *pPayload = (struct hw_event_resp *)(piomb + 4); u32 lr_evt_status_phyid_portid = le32_to_cpu(pPayload->lr_evt_status_phyid_portid); u8 link_rate = (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28); u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F); u8 phy_id = (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4); u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate); u8 portstate = (u8)(npip_portstate & 0x0000000F); struct pm8001_port *port = &pm8001_ha->port[port_id]; struct sas_ha_struct *sas_ha = pm8001_ha->sas; struct pm8001_phy *phy = &pm8001_ha->phy[phy_id]; unsigned long flags; PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_SATA_PHY_UP port id = %d," " phy id = %d\n", port_id, phy_id)); port->port_state = portstate; port->port_attached = 1; get_lrate_mode(phy, link_rate); phy->phy_type |= PORT_TYPE_SATA; phy->phy_attached = 1; phy->sas_phy.oob_mode = SATA_OOB_MODE; sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE); spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags); memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4), sizeof(struct dev_to_host_fis)); phy->frame_rcvd_size = sizeof(struct dev_to_host_fis); phy->identify.target_port_protocols = SAS_PROTOCOL_SATA; phy->identify.device_type = SATA_DEV; pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr); spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags); pm8001_bytes_dmaed(pm8001_ha, phy_id); } /** * hw_event_phy_down -we should notify the libsas the phy is down. * @pm8001_ha: our hba card information * @piomb: IO message buffer */ static void hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb) { struct hw_event_resp *pPayload = (struct hw_event_resp *)(piomb + 4); u32 lr_evt_status_phyid_portid = le32_to_cpu(pPayload->lr_evt_status_phyid_portid); u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F); u8 phy_id = (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4); u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate); u8 portstate = (u8)(npip_portstate & 0x0000000F); struct pm8001_port *port = &pm8001_ha->port[port_id]; struct pm8001_phy *phy = &pm8001_ha->phy[phy_id]; port->port_state = portstate; phy->phy_type = 0; phy->identify.device_type = 0; phy->phy_attached = 0; memset(&phy->dev_sas_addr, 0, SAS_ADDR_SIZE); switch (portstate) { case PORT_VALID: break; case PORT_INVALID: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(" PortInvalid portID %d\n", port_id)); PM8001_MSG_DBG(pm8001_ha, pm8001_printk(" Last phy Down and port invalid\n")); port->port_attached = 0; pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN, port_id, phy_id, 0, 0); break; case PORT_IN_RESET: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(" Port In Reset portID %d\n", port_id)); break; case PORT_NOT_ESTABLISHED: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(" phy Down and PORT_NOT_ESTABLISHED\n")); port->port_attached = 0; break; case PORT_LOSTCOMM: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(" phy Down and PORT_LOSTCOMM\n")); PM8001_MSG_DBG(pm8001_ha, pm8001_printk(" Last phy Down and port invalid\n")); port->port_attached = 0; pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN, port_id, phy_id, 0, 0); break; default: port->port_attached = 0; PM8001_MSG_DBG(pm8001_ha, pm8001_printk(" phy Down and(default) = %x\n", portstate)); break; } } /** * mpi_reg_resp -process register device ID response. * @pm8001_ha: our hba card information * @piomb: IO message buffer * * when sas layer find a device it will notify LLDD, then the driver register * the domain device to FW, this event is the return device ID which the FW * has assigned, from now,inter-communication with FW is no longer using the * SAS address, use device ID which FW assigned. */ static int mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) { u32 status; u32 device_id; u32 htag; struct pm8001_ccb_info *ccb; struct pm8001_device *pm8001_dev; struct dev_reg_resp *registerRespPayload = (struct dev_reg_resp *)(piomb + 4); htag = le32_to_cpu(registerRespPayload->tag); ccb = &pm8001_ha->ccb_info[htag]; pm8001_dev = ccb->device; status = le32_to_cpu(registerRespPayload->status); device_id = le32_to_cpu(registerRespPayload->device_id); PM8001_MSG_DBG(pm8001_ha, pm8001_printk(" register device is status = %d\n", status)); switch (status) { case DEVREG_SUCCESS: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_SUCCESS\n")); pm8001_dev->device_id = device_id; break; case DEVREG_FAILURE_OUT_OF_RESOURCE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_FAILURE_OUT_OF_RESOURCE\n")); break; case DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED\n")); break; case DEVREG_FAILURE_INVALID_PHY_ID: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_FAILURE_INVALID_PHY_ID\n")); break; case DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED\n")); break; case DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE\n")); break; case DEVREG_FAILURE_PORT_NOT_VALID_STATE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_FAILURE_PORT_NOT_VALID_STATE\n")); break; case DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID\n")); break; default: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_UNSORPORTED\n")); break; } complete(pm8001_dev->dcompletion); ccb->task = NULL; ccb->ccb_tag = 0xFFFFFFFF; pm8001_ccb_free(pm8001_ha, htag); return 0; } static int mpi_dereg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) { u32 status; u32 device_id; struct dev_reg_resp *registerRespPayload = (struct dev_reg_resp *)(piomb + 4); status = le32_to_cpu(registerRespPayload->status); device_id = le32_to_cpu(registerRespPayload->device_id); if (status != 0) PM8001_MSG_DBG(pm8001_ha, pm8001_printk(" deregister device failed ,status = %x" ", device_id = %x\n", status, device_id)); return 0; } static int mpi_fw_flash_update_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) { u32 status; struct fw_control_ex fw_control_context; struct fw_flash_Update_resp *ppayload = (struct fw_flash_Update_resp *)(piomb + 4); u32 tag = ppayload->tag; struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag]; status = le32_to_cpu(ppayload->status); memcpy(&fw_control_context, ccb->fw_control_context, sizeof(fw_control_context)); switch (status) { case FLASH_UPDATE_COMPLETE_PENDING_REBOOT: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(": FLASH_UPDATE_COMPLETE_PENDING_REBOOT\n")); break; case FLASH_UPDATE_IN_PROGRESS: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(": FLASH_UPDATE_IN_PROGRESS\n")); break; case FLASH_UPDATE_HDR_ERR: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(": FLASH_UPDATE_HDR_ERR\n")); break; case FLASH_UPDATE_OFFSET_ERR: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(": FLASH_UPDATE_OFFSET_ERR\n")); break; case FLASH_UPDATE_CRC_ERR: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(": FLASH_UPDATE_CRC_ERR\n")); break; case FLASH_UPDATE_LENGTH_ERR: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(": FLASH_UPDATE_LENGTH_ERR\n")); break; case FLASH_UPDATE_HW_ERR: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(": FLASH_UPDATE_HW_ERR\n")); break; case FLASH_UPDATE_DNLD_NOT_SUPPORTED: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(": FLASH_UPDATE_DNLD_NOT_SUPPORTED\n")); break; case FLASH_UPDATE_DISABLED: PM8001_MSG_DBG(pm8001_ha, pm8001_printk(": FLASH_UPDATE_DISABLED\n")); break; default: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("No matched status = %d\n", status)); break; } ccb->fw_control_context->fw_control->retcode = status; pci_free_consistent(pm8001_ha->pdev, fw_control_context.len, fw_control_context.virtAddr, fw_control_context.phys_addr); complete(pm8001_ha->nvmd_completion); ccb->task = NULL; ccb->ccb_tag = 0xFFFFFFFF; pm8001_ccb_free(pm8001_ha, tag); return 0; } static int mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb) { u32 status; int i; struct general_event_resp *pPayload = (struct general_event_resp *)(piomb + 4); status = le32_to_cpu(pPayload->status); PM8001_MSG_DBG(pm8001_ha, pm8001_printk(" status = 0x%x\n", status)); for (i = 0; i < GENERAL_EVENT_PAYLOAD; i++) PM8001_MSG_DBG(pm8001_ha, pm8001_printk("inb_IOMB_payload[0x%x] 0x%x,\n", i, pPayload->inb_IOMB_payload[i])); return 0; } static int mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb) { struct sas_task *t; struct pm8001_ccb_info *ccb; unsigned long flags; u32 status ; u32 tag, scp; struct task_status_struct *ts; struct task_abort_resp *pPayload = (struct task_abort_resp *)(piomb + 4); status = le32_to_cpu(pPayload->status); tag = le32_to_cpu(pPayload->tag); scp = le32_to_cpu(pPayload->scp); ccb = &pm8001_ha->ccb_info[tag]; t = ccb->task; PM8001_IO_DBG(pm8001_ha, pm8001_printk(" status = 0x%x\n", status)); if (t == NULL) return -1; ts = &t->task_status; if (status != 0) PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task abort failed status 0x%x ," "tag = 0x%x, scp= 0x%x\n", status, tag, scp)); switch (status) { case IO_SUCCESS: PM8001_EH_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n")); ts->resp = SAS_TASK_COMPLETE; ts->stat = SAM_STAT_GOOD; break; case IO_NOT_VALID: PM8001_EH_DBG(pm8001_ha, pm8001_printk("IO_NOT_VALID\n")); ts->resp = TMF_RESP_FUNC_FAILED; break; } spin_lock_irqsave(&t->task_state_lock, flags); t->task_state_flags &= ~SAS_TASK_STATE_PENDING; t->task_state_flags &= ~SAS_TASK_AT_INITIATOR; t->task_state_flags |= SAS_TASK_STATE_DONE; spin_unlock_irqrestore(&t->task_state_lock, flags); pm8001_ccb_task_free(pm8001_ha, t, ccb, tag); mb(); t->task_done(t); return 0; } /** * mpi_hw_event -The hw event has come. * @pm8001_ha: our hba card information * @piomb: IO message buffer */ static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void* piomb) { unsigned long flags; struct hw_event_resp *pPayload = (struct hw_event_resp *)(piomb + 4); u32 lr_evt_status_phyid_portid = le32_to_cpu(pPayload->lr_evt_status_phyid_portid); u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F); u8 phy_id = (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4); u16 eventType = (u16)((lr_evt_status_phyid_portid & 0x00FFFF00) >> 8); u8 status = (u8)((lr_evt_status_phyid_portid & 0x0F000000) >> 24); struct sas_ha_struct *sas_ha = pm8001_ha->sas; struct pm8001_phy *phy = &pm8001_ha->phy[phy_id]; struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id]; PM8001_MSG_DBG(pm8001_ha, pm8001_printk("outbound queue HW event & event type : ")); switch (eventType) { case HW_EVENT_PHY_START_STATUS: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_PHY_START_STATUS" " status = %x\n", status)); if (status == 0) { phy->phy_state = 1; if (pm8001_ha->flags == PM8001F_RUN_TIME) complete(phy->enable_completion); } break; case HW_EVENT_SAS_PHY_UP: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_PHY_START_STATUS\n")); hw_event_sas_phy_up(pm8001_ha, piomb); break; case HW_EVENT_SATA_PHY_UP: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_SATA_PHY_UP\n")); hw_event_sata_phy_up(pm8001_ha, piomb); break; case HW_EVENT_PHY_STOP_STATUS: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_PHY_STOP_STATUS " "status = %x\n", status)); if (status == 0) phy->phy_state = 0; break; case HW_EVENT_SATA_SPINUP_HOLD: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_SATA_SPINUP_HOLD\n")); sas_ha->notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD); break; case HW_EVENT_PHY_DOWN: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_PHY_DOWN\n")); sas_ha->notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL); phy->phy_attached = 0; phy->phy_state = 0; hw_event_phy_down(pm8001_ha, piomb); break; case HW_EVENT_PORT_INVALID: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_PORT_INVALID\n")); sas_phy_disconnected(sas_phy); phy->phy_attached = 0; sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); break; /* the broadcast change primitive received, tell the LIBSAS this event to revalidate the sas domain*/ case HW_EVENT_BROADCAST_CHANGE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_BROADCAST_CHANGE\n")); pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE, port_id, phy_id, 1, 0); spin_lock_irqsave(&sas_phy->sas_prim_lock, flags); sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE; spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags); sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); break; case HW_EVENT_PHY_ERROR: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_PHY_ERROR\n")); sas_phy_disconnected(&phy->sas_phy); phy->phy_attached = 0; sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR); break; case HW_EVENT_BROADCAST_EXP: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_BROADCAST_EXP\n")); spin_lock_irqsave(&sas_phy->sas_prim_lock, flags); sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP; spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags); sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); break; case HW_EVENT_LINK_ERR_INVALID_DWORD: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_LINK_ERR_INVALID_DWORD\n")); pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0); sas_phy_disconnected(sas_phy); phy->phy_attached = 0; sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); break; case HW_EVENT_LINK_ERR_DISPARITY_ERROR: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_LINK_ERR_DISPARITY_ERROR\n")); pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_LINK_ERR_DISPARITY_ERROR, port_id, phy_id, 0, 0); sas_phy_disconnected(sas_phy); phy->phy_attached = 0; sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); break; case HW_EVENT_LINK_ERR_CODE_VIOLATION: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_LINK_ERR_CODE_VIOLATION\n")); pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_LINK_ERR_CODE_VIOLATION, port_id, phy_id, 0, 0); sas_phy_disconnected(sas_phy); phy->phy_attached = 0; sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); break; case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n")); pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH, port_id, phy_id, 0, 0); sas_phy_disconnected(sas_phy); phy->phy_attached = 0; sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); break; case HW_EVENT_MALFUNCTION: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_MALFUNCTION\n")); break; case HW_EVENT_BROADCAST_SES: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_BROADCAST_SES\n")); spin_lock_irqsave(&sas_phy->sas_prim_lock, flags); sas_phy->sas_prim = HW_EVENT_BROADCAST_SES; spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags); sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); break; case HW_EVENT_INBOUND_CRC_ERROR: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_INBOUND_CRC_ERROR\n")); pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_INBOUND_CRC_ERROR, port_id, phy_id, 0, 0); break; case HW_EVENT_HARD_RESET_RECEIVED: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_HARD_RESET_RECEIVED\n")); sas_ha->notify_port_event(sas_phy, PORTE_HARD_RESET); break; case HW_EVENT_ID_FRAME_TIMEOUT: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_ID_FRAME_TIMEOUT\n")); sas_phy_disconnected(sas_phy); phy->phy_attached = 0; sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); break; case HW_EVENT_LINK_ERR_PHY_RESET_FAILED: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_LINK_ERR_PHY_RESET_FAILED\n")); pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_LINK_ERR_PHY_RESET_FAILED, port_id, phy_id, 0, 0); sas_phy_disconnected(sas_phy); phy->phy_attached = 0; sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); break; case HW_EVENT_PORT_RESET_TIMER_TMO: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_PORT_RESET_TIMER_TMO\n")); sas_phy_disconnected(sas_phy); phy->phy_attached = 0; sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); break; case HW_EVENT_PORT_RECOVERY_TIMER_TMO: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_PORT_RECOVERY_TIMER_TMO\n")); sas_phy_disconnected(sas_phy); phy->phy_attached = 0; sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR); break; case HW_EVENT_PORT_RECOVER: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_PORT_RECOVER\n")); break; case HW_EVENT_PORT_RESET_COMPLETE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("HW_EVENT_PORT_RESET_COMPLETE\n")); break; case EVENT_BROADCAST_ASYNCH_EVENT: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("EVENT_BROADCAST_ASYNCH_EVENT\n")); break; default: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Unknown event type = %x\n", eventType)); break; } return 0; } /** * process_one_iomb - process one outbound Queue memory block * @pm8001_ha: our hba card information * @piomb: IO message buffer */ static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb) { u32 pHeader = (u32)*(u32 *)piomb; u8 opc = (u8)(pHeader & 0xFFF); PM8001_MSG_DBG(pm8001_ha, pm8001_printk("process_one_iomb:")); switch (opc) { case OPC_OUB_ECHO: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_ECHO\n")); break; case OPC_OUB_HW_EVENT: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_HW_EVENT\n")); mpi_hw_event(pm8001_ha, piomb); break; case OPC_OUB_SSP_COMP: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SSP_COMP\n")); mpi_ssp_completion(pm8001_ha, piomb); break; case OPC_OUB_SMP_COMP: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SMP_COMP\n")); mpi_smp_completion(pm8001_ha, piomb); break; case OPC_OUB_LOCAL_PHY_CNTRL: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_LOCAL_PHY_CNTRL\n")); mpi_local_phy_ctl(pm8001_ha, piomb); break; case OPC_OUB_DEV_REGIST: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_DEV_REGIST\n")); mpi_reg_resp(pm8001_ha, piomb); break; case OPC_OUB_DEREG_DEV: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("unregister the device\n")); mpi_dereg_resp(pm8001_ha, piomb); break; case OPC_OUB_GET_DEV_HANDLE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_GET_DEV_HANDLE\n")); break; case OPC_OUB_SATA_COMP: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SATA_COMP\n")); mpi_sata_completion(pm8001_ha, piomb); break; case OPC_OUB_SATA_EVENT: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SATA_EVENT\n")); mpi_sata_event(pm8001_ha, piomb); break; case OPC_OUB_SSP_EVENT: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SSP_EVENT\n")); mpi_ssp_event(pm8001_ha, piomb); break; case OPC_OUB_DEV_HANDLE_ARRIV: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_DEV_HANDLE_ARRIV\n")); /*This is for target*/ break; case OPC_OUB_SSP_RECV_EVENT: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SSP_RECV_EVENT\n")); /*This is for target*/ break; case OPC_OUB_DEV_INFO: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_DEV_INFO\n")); break; case OPC_OUB_FW_FLASH_UPDATE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_FW_FLASH_UPDATE\n")); mpi_fw_flash_update_resp(pm8001_ha, piomb); break; case OPC_OUB_GPIO_RESPONSE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_GPIO_RESPONSE\n")); break; case OPC_OUB_GPIO_EVENT: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_GPIO_EVENT\n")); break; case OPC_OUB_GENERAL_EVENT: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_GENERAL_EVENT\n")); mpi_general_event(pm8001_ha, piomb); break; case OPC_OUB_SSP_ABORT_RSP: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SSP_ABORT_RSP\n")); mpi_task_abort_resp(pm8001_ha, piomb); break; case OPC_OUB_SATA_ABORT_RSP: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SATA_ABORT_RSP\n")); mpi_task_abort_resp(pm8001_ha, piomb); break; case OPC_OUB_SAS_DIAG_MODE_START_END: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SAS_DIAG_MODE_START_END\n")); break; case OPC_OUB_SAS_DIAG_EXECUTE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SAS_DIAG_EXECUTE\n")); break; case OPC_OUB_GET_TIME_STAMP: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_GET_TIME_STAMP\n")); break; case OPC_OUB_SAS_HW_EVENT_ACK: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SAS_HW_EVENT_ACK\n")); break; case OPC_OUB_PORT_CONTROL: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_PORT_CONTROL\n")); break; case OPC_OUB_SMP_ABORT_RSP: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SMP_ABORT_RSP\n")); mpi_task_abort_resp(pm8001_ha, piomb); break; case OPC_OUB_GET_NVMD_DATA: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_GET_NVMD_DATA\n")); mpi_get_nvmd_resp(pm8001_ha, piomb); break; case OPC_OUB_SET_NVMD_DATA: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SET_NVMD_DATA\n")); mpi_set_nvmd_resp(pm8001_ha, piomb); break; case OPC_OUB_DEVICE_HANDLE_REMOVAL: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_DEVICE_HANDLE_REMOVAL\n")); break; case OPC_OUB_SET_DEVICE_STATE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SET_DEVICE_STATE\n")); mpi_set_dev_state_resp(pm8001_ha, piomb); break; case OPC_OUB_GET_DEVICE_STATE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_GET_DEVICE_STATE\n")); break; case OPC_OUB_SET_DEV_INFO: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SET_DEV_INFO\n")); break; case OPC_OUB_SAS_RE_INITIALIZE: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_SAS_RE_INITIALIZE\n")); break; default: PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Unknown outbound Queue IOMB OPC = %x\n", opc)); break; } } static int process_oq(struct pm8001_hba_info *pm8001_ha) { struct outbound_queue_table *circularQ; void *pMsg1 = NULL; u8 uninitialized_var(bc); u32 ret = MPI_IO_STATUS_FAIL; unsigned long flags; spin_lock_irqsave(&pm8001_ha->lock, flags); circularQ = &pm8001_ha->outbnd_q_tbl[0]; do { ret = mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc); if (MPI_IO_STATUS_SUCCESS == ret) { /* process the outbound message */ process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4)); /* free the message from the outbound circular buffer */ mpi_msg_free_set(pm8001_ha, pMsg1, circularQ, bc); } if (MPI_IO_STATUS_BUSY == ret) { /* Update the producer index from SPC */ circularQ->producer_index = cpu_to_le32(pm8001_read_32(circularQ->pi_virt)); if (le32_to_cpu(circularQ->producer_index) == circularQ->consumer_idx) /* OQ is empty */ break; } } while (1); spin_unlock_irqrestore(&pm8001_ha->lock, flags); return ret; } /* PCI_DMA_... to our direction translation. */ static const u8 data_dir_flags[] = { [PCI_DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT,/* UNSPECIFIED */ [PCI_DMA_TODEVICE] = DATA_DIR_OUT,/* OUTBOUND */ [PCI_DMA_FROMDEVICE] = DATA_DIR_IN,/* INBOUND */ [PCI_DMA_NONE] = DATA_DIR_NONE,/* NO TRANSFER */ }; static void pm8001_chip_make_sg(struct scatterlist *scatter, int nr, void *prd) { int i; struct scatterlist *sg; struct pm8001_prd *buf_prd = prd; for_each_sg(scatter, sg, nr, i) { buf_prd->addr = cpu_to_le64(sg_dma_address(sg)); buf_prd->im_len.len = cpu_to_le32(sg_dma_len(sg)); buf_prd->im_len.e = 0; buf_prd++; } } static void build_smp_cmd(u32 deviceID, __le32 hTag, struct smp_req *psmp_cmd) { psmp_cmd->tag = hTag; psmp_cmd->device_id = cpu_to_le32(deviceID); psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1)); } /** * pm8001_chip_smp_req - send a SMP task to FW * @pm8001_ha: our hba card information. * @ccb: the ccb information this request used. */ static int pm8001_chip_smp_req(struct pm8001_hba_info *pm8001_ha, struct pm8001_ccb_info *ccb) { int elem, rc; struct sas_task *task = ccb->task; struct domain_device *dev = task->dev; struct pm8001_device *pm8001_dev = dev->lldd_dev; struct scatterlist *sg_req, *sg_resp; u32 req_len, resp_len; struct smp_req smp_cmd; u32 opc; struct inbound_queue_table *circularQ; memset(&smp_cmd, 0, sizeof(smp_cmd)); /* * DMA-map SMP request, response buffers */ sg_req = &task->smp_task.smp_req; elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, PCI_DMA_TODEVICE); if (!elem) return -ENOMEM; req_len = sg_dma_len(sg_req); sg_resp = &task->smp_task.smp_resp; elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, PCI_DMA_FROMDEVICE); if (!elem) { rc = -ENOMEM; goto err_out; } resp_len = sg_dma_len(sg_resp); /* must be in dwords */ if ((req_len & 0x3) || (resp_len & 0x3)) { rc = -EINVAL; goto err_out_2; } opc = OPC_INB_SMP_REQUEST; circularQ = &pm8001_ha->inbnd_q_tbl[0]; smp_cmd.tag = cpu_to_le32(ccb->ccb_tag); smp_cmd.long_smp_req.long_req_addr = cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req)); smp_cmd.long_smp_req.long_req_size = cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4); smp_cmd.long_smp_req.long_resp_addr = cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_resp)); smp_cmd.long_smp_req.long_resp_size = cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_resp)-4); build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag, &smp_cmd); mpi_build_cmd(pm8001_ha, circularQ, opc, (u32 *)&smp_cmd); return 0; err_out_2: dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1, PCI_DMA_FROMDEVICE); err_out: dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1, PCI_DMA_TODEVICE); return rc; } /** * pm8001_chip_ssp_io_req - send a SSP task to FW * @pm8001_ha: our hba card information. * @ccb: the ccb information this request used. */ static int pm8001_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha, struct pm8001_ccb_info *ccb) { struct sas_task *task = ccb->task; struct domain_device *dev = task->dev; struct pm8001_device *pm8001_dev = dev->lldd_dev; struct ssp_ini_io_start_req ssp_cmd; u32 tag = ccb->ccb_tag; int ret; u64 phys_addr; struct inbound_queue_table *circularQ; u32 opc = OPC_INB_SSPINIIOSTART; memset(&ssp_cmd, 0, sizeof(ssp_cmd)); memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8); ssp_cmd.dir_m_tlr = cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);/*0 for SAS 1.1 compatible TLR*/ ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len); ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id); ssp_cmd.tag = cpu_to_le32(tag); if (task->ssp_task.enable_first_burst) ssp_cmd.ssp_iu.efb_prio_attr |= 0x80; ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3); ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7); memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cdb, 16); circularQ = &pm8001_ha->inbnd_q_tbl[0]; /* fill in PRD (scatter/gather) table, if any */ if (task->num_scatter > 1) { pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd); phys_addr = ccb->ccb_dma_handle + offsetof(struct pm8001_ccb_info, buf_prd[0]); ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(phys_addr)); ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(phys_addr)); ssp_cmd.esgl = cpu_to_le32(1<<31); } else if (task->num_scatter == 1) { u64 dma_addr = sg_dma_address(task->scatter); ssp_cmd.addr_low = cpu_to_le32(lower_32_bits(dma_addr)); ssp_cmd.addr_high = cpu_to_le32(upper_32_bits(dma_addr)); ssp_cmd.len = cpu_to_le32(task->total_xfer_len); ssp_cmd.esgl = 0; } else if (task->num_scatter == 0) { ssp_cmd.addr_low = 0; ssp_cmd.addr_high = 0; ssp_cmd.len = cpu_to_le32(task->total_xfer_len); ssp_cmd.esgl = 0; } ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &ssp_cmd); return ret; } static int pm8001_chip_sata_req(struct pm8001_hba_info *pm8001_ha, struct pm8001_ccb_info *ccb) { struct sas_task *task = ccb->task; struct domain_device *dev = task->dev; struct pm8001_device *pm8001_ha_dev = dev->lldd_dev; u32 tag = ccb->ccb_tag; int ret; struct sata_start_req sata_cmd; u32 hdr_tag, ncg_tag = 0; u64 phys_addr; u32 ATAP = 0x0; u32 dir; struct inbound_queue_table *circularQ; u32 opc = OPC_INB_SATA_HOST_OPSTART; memset(&sata_cmd, 0, sizeof(sata_cmd)); circularQ = &pm8001_ha->inbnd_q_tbl[0]; if (task->data_dir == PCI_DMA_NONE) { ATAP = 0x04; /* no data*/ PM8001_IO_DBG(pm8001_ha, pm8001_printk("no data\n")); } else if (likely(!task->ata_task.device_control_reg_update)) { if (task->ata_task.dma_xfer) { ATAP = 0x06; /* DMA */ PM8001_IO_DBG(pm8001_ha, pm8001_printk("DMA\n")); } else { ATAP = 0x05; /* PIO*/ PM8001_IO_DBG(pm8001_ha, pm8001_printk("PIO\n")); } if (task->ata_task.use_ncq && dev->sata_dev.command_set != ATAPI_COMMAND_SET) { ATAP = 0x07; /* FPDMA */ PM8001_IO_DBG(pm8001_ha, pm8001_printk("FPDMA\n")); } } if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag)) ncg_tag = hdr_tag; dir = data_dir_flags[task->data_dir] << 8; sata_cmd.tag = cpu_to_le32(tag); sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id); sata_cmd.data_len = cpu_to_le32(task->total_xfer_len); sata_cmd.ncqtag_atap_dir_m = cpu_to_le32(((ncg_tag & 0xff)<<16)|((ATAP & 0x3f) << 10) | dir); sata_cmd.sata_fis = task->ata_task.fis; if (likely(!task->ata_task.device_control_reg_update)) sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */ sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */ /* fill in PRD (scatter/gather) table, if any */ if (task->num_scatter > 1) { pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd); phys_addr = ccb->ccb_dma_handle + offsetof(struct pm8001_ccb_info, buf_prd[0]); sata_cmd.addr_low = lower_32_bits(phys_addr); sata_cmd.addr_high = upper_32_bits(phys_addr); sata_cmd.esgl = cpu_to_le32(1 << 31); } else if (task->num_scatter == 1) { u64 dma_addr = sg_dma_address(task->scatter); sata_cmd.addr_low = lower_32_bits(dma_addr); sata_cmd.addr_high = upper_32_bits(dma_addr); sata_cmd.len = cpu_to_le32(task->total_xfer_len); sata_cmd.esgl = 0; } else if (task->num_scatter == 0) { sata_cmd.addr_low = 0; sata_cmd.addr_high = 0; sata_cmd.len = cpu_to_le32(task->total_xfer_len); sata_cmd.esgl = 0; } ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd); return ret; } /** * pm8001_chip_phy_start_req - start phy via PHY_START COMMAND * @pm8001_ha: our hba card information. * @num: the inbound queue number * @phy_id: the phy id which we wanted to start up. */ static int pm8001_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id) { struct phy_start_req payload; struct inbound_queue_table *circularQ; int ret; u32 tag = 0x01; u32 opcode = OPC_INB_PHYSTART; circularQ = &pm8001_ha->inbnd_q_tbl[0]; memset(&payload, 0, sizeof(payload)); payload.tag = cpu_to_le32(tag); /* ** [0:7] PHY Identifier ** [8:11] link rate 1.5G, 3G, 6G ** [12:13] link mode 01b SAS mode; 10b SATA mode; 11b both ** [14] 0b disable spin up hold; 1b enable spin up hold */ payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE | LINKMODE_AUTO | LINKRATE_15 | LINKRATE_30 | LINKRATE_60 | phy_id); payload.sas_identify.dev_type = SAS_END_DEV; payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL; memcpy(payload.sas_identify.sas_addr, pm8001_ha->sas_addr, SAS_ADDR_SIZE); payload.sas_identify.phy_id = phy_id; ret = mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload); return ret; } /** * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND * @pm8001_ha: our hba card information. * @num: the inbound queue number * @phy_id: the phy id which we wanted to start up. */ static int pm8001_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id) { struct phy_stop_req payload; struct inbound_queue_table *circularQ; int ret; u32 tag = 0x01; u32 opcode = OPC_INB_PHYSTOP; circularQ = &pm8001_ha->inbnd_q_tbl[0]; memset(&payload, 0, sizeof(payload)); payload.tag = cpu_to_le32(tag); payload.phy_id = cpu_to_le32(phy_id); ret = mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload); return ret; } /** * see comments on mpi_reg_resp. */ static int pm8001_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha, struct pm8001_device *pm8001_dev, u32 flag) { struct reg_dev_req payload; u32 opc; u32 stp_sspsmp_sata = 0x4; struct inbound_queue_table *circularQ; u32 linkrate, phy_id; int rc, tag = 0xdeadbeef; struct pm8001_ccb_info *ccb; u8 retryFlag = 0x1; u16 firstBurstSize = 0; u16 ITNT = 2000; struct domain_device *dev = pm8001_dev->sas_device; struct domain_device *parent_dev = dev->parent; circularQ = &pm8001_ha->inbnd_q_tbl[0]; memset(&payload, 0, sizeof(payload)); rc = pm8001_tag_alloc(pm8001_ha, &tag); if (rc) return rc; ccb = &pm8001_ha->ccb_info[tag]; ccb->device = pm8001_dev; ccb->ccb_tag = tag; payload.tag = cpu_to_le32(tag); if (flag == 1) stp_sspsmp_sata = 0x02; /*direct attached sata */ else { if (pm8001_dev->dev_type == SATA_DEV) stp_sspsmp_sata = 0x00; /* stp*/ else if (pm8001_dev->dev_type == SAS_END_DEV || pm8001_dev->dev_type == EDGE_DEV || pm8001_dev->dev_type == FANOUT_DEV) stp_sspsmp_sata = 0x01; /*ssp or smp*/ } if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type)) phy_id = parent_dev->ex_dev.ex_phy->phy_id; else phy_id = pm8001_dev->attached_phy; opc = OPC_INB_REG_DEV; linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ? pm8001_dev->sas_device->linkrate : dev->port->linkrate; payload.phyid_portid = cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0x0F) | ((phy_id & 0x0F) << 4)); payload.dtype_dlr_retry = cpu_to_le32((retryFlag & 0x01) | ((linkrate & 0x0F) * 0x1000000) | ((stp_sspsmp_sata & 0x03) * 0x10000000)); payload.firstburstsize_ITNexustimeout = cpu_to_le32(ITNT | (firstBurstSize * 0x10000)); memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr, SAS_ADDR_SIZE); rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload); return rc; } /** * see comments on mpi_reg_resp. */ static int pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha, u32 device_id) { struct dereg_dev_req payload; u32 opc = OPC_INB_DEREG_DEV_HANDLE; int ret; struct inbound_queue_table *circularQ; circularQ = &pm8001_ha->inbnd_q_tbl[0]; memset(&payload, 0, sizeof(payload)); payload.tag = cpu_to_le32(1); payload.device_id = cpu_to_le32(device_id); PM8001_MSG_DBG(pm8001_ha, pm8001_printk("unregister device device_id = %d\n", device_id)); ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload); return ret; } /** * pm8001_chip_phy_ctl_req - support the local phy operation * @pm8001_ha: our hba card information. * @num: the inbound queue number * @phy_id: the phy id which we wanted to operate * @phy_op: */ static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha, u32 phyId, u32 phy_op) { struct local_phy_ctl_req payload; struct inbound_queue_table *circularQ; int ret; u32 opc = OPC_INB_LOCAL_PHY_CONTROL; memset(&payload, 0, sizeof(payload)); circularQ = &pm8001_ha->inbnd_q_tbl[0]; payload.tag = cpu_to_le32(1); payload.phyop_phyid = cpu_to_le32(((phy_op & 0xff) << 8) | (phyId & 0x0F)); ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload); return ret; } static u32 pm8001_chip_is_our_interupt(struct pm8001_hba_info *pm8001_ha) { u32 value; #ifdef PM8001_USE_MSIX return 1; #endif value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR); if (value) return 1; return 0; } /** * pm8001_chip_isr - PM8001 isr handler. * @pm8001_ha: our hba card information. * @irq: irq number. * @stat: stat. */ static irqreturn_t pm8001_chip_isr(struct pm8001_hba_info *pm8001_ha) { pm8001_chip_interrupt_disable(pm8001_ha); process_oq(pm8001_ha); pm8001_chip_interrupt_enable(pm8001_ha); return IRQ_HANDLED; } static int send_task_abort(struct pm8001_hba_info *pm8001_ha, u32 opc, u32 dev_id, u8 flag, u32 task_tag, u32 cmd_tag) { struct task_abort_req task_abort; struct inbound_queue_table *circularQ; int ret; circularQ = &pm8001_ha->inbnd_q_tbl[0]; memset(&task_abort, 0, sizeof(task_abort)); if (ABORT_SINGLE == (flag & ABORT_MASK)) { task_abort.abort_all = 0; task_abort.device_id = cpu_to_le32(dev_id); task_abort.tag_to_abort = cpu_to_le32(task_tag); task_abort.tag = cpu_to_le32(cmd_tag); } else if (ABORT_ALL == (flag & ABORT_MASK)) { task_abort.abort_all = cpu_to_le32(1); task_abort.device_id = cpu_to_le32(dev_id); task_abort.tag = cpu_to_le32(cmd_tag); } ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort); return ret; } /** * pm8001_chip_abort_task - SAS abort task when error or exception happened. * @task: the task we wanted to aborted. * @flag: the abort flag. */ static int pm8001_chip_abort_task(struct pm8001_hba_info *pm8001_ha, struct pm8001_device *pm8001_dev, u8 flag, u32 task_tag, u32 cmd_tag) { u32 opc, device_id; int rc = TMF_RESP_FUNC_FAILED; PM8001_EH_DBG(pm8001_ha, pm8001_printk("cmd_tag = %x, abort task tag" " = %x", cmd_tag, task_tag)); if (pm8001_dev->dev_type == SAS_END_DEV) opc = OPC_INB_SSP_ABORT; else if (pm8001_dev->dev_type == SATA_DEV) opc = OPC_INB_SATA_ABORT; else opc = OPC_INB_SMP_ABORT;/* SMP */ device_id = pm8001_dev->device_id; rc = send_task_abort(pm8001_ha, opc, device_id, flag, task_tag, cmd_tag); if (rc != TMF_RESP_FUNC_COMPLETE) PM8001_EH_DBG(pm8001_ha, pm8001_printk("rc= %d\n", rc)); return rc; } /** * pm8001_chip_ssp_tm_req - built the task management command. * @pm8001_ha: our hba card information. * @ccb: the ccb information. * @tmf: task management function. */ static int pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha, struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf) { struct sas_task *task = ccb->task; struct domain_device *dev = task->dev; struct pm8001_device *pm8001_dev = dev->lldd_dev; u32 opc = OPC_INB_SSPINITMSTART; struct inbound_queue_table *circularQ; struct ssp_ini_tm_start_req sspTMCmd; int ret; memset(&sspTMCmd, 0, sizeof(sspTMCmd)); sspTMCmd.device_id = cpu_to_le32(pm8001_dev->device_id); sspTMCmd.relate_tag = cpu_to_le32(tmf->tag_of_task_to_be_managed); sspTMCmd.tmf = cpu_to_le32(tmf->tmf); memcpy(sspTMCmd.lun, task->ssp_task.LUN, 8); sspTMCmd.tag = cpu_to_le32(ccb->ccb_tag); circularQ = &pm8001_ha->inbnd_q_tbl[0]; ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &sspTMCmd); return ret; } static int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha, void *payload) { u32 opc = OPC_INB_GET_NVMD_DATA; u32 nvmd_type; int rc; u32 tag; struct pm8001_ccb_info *ccb; struct inbound_queue_table *circularQ; struct get_nvm_data_req nvmd_req; struct fw_control_ex *fw_control_context; struct pm8001_ioctl_payload *ioctl_payload = payload; nvmd_type = ioctl_payload->minor_function; fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL); if (!fw_control_context) return -ENOMEM; fw_control_context->usrAddr = (u8 *)&ioctl_payload->func_specific[0]; fw_control_context->len = ioctl_payload->length; circularQ = &pm8001_ha->inbnd_q_tbl[0]; memset(&nvmd_req, 0, sizeof(nvmd_req)); rc = pm8001_tag_alloc(pm8001_ha, &tag); if (rc) { kfree(fw_control_context); return rc; } ccb = &pm8001_ha->ccb_info[tag]; ccb->ccb_tag = tag; ccb->fw_control_context = fw_control_context; nvmd_req.tag = cpu_to_le32(tag); switch (nvmd_type) { case TWI_DEVICE: { u32 twi_addr, twi_page_size; twi_addr = 0xa8; twi_page_size = 2; nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 | twi_page_size << 8 | TWI_DEVICE); nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length); nvmd_req.resp_addr_hi = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); nvmd_req.resp_addr_lo = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); break; } case C_SEEPROM: { nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM); nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length); nvmd_req.resp_addr_hi = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); nvmd_req.resp_addr_lo = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); break; } case VPD_FLASH: { nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH); nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length); nvmd_req.resp_addr_hi = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); nvmd_req.resp_addr_lo = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); break; } case EXPAN_ROM: { nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM); nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length); nvmd_req.resp_addr_hi = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); nvmd_req.resp_addr_lo = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); break; } default: break; } rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req); return rc; } static int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha, void *payload) { u32 opc = OPC_INB_SET_NVMD_DATA; u32 nvmd_type; int rc; u32 tag; struct pm8001_ccb_info *ccb; struct inbound_queue_table *circularQ; struct set_nvm_data_req nvmd_req; struct fw_control_ex *fw_control_context; struct pm8001_ioctl_payload *ioctl_payload = payload; nvmd_type = ioctl_payload->minor_function; fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL); if (!fw_control_context) return -ENOMEM; circularQ = &pm8001_ha->inbnd_q_tbl[0]; memcpy(pm8001_ha->memoryMap.region[NVMD].virt_ptr, ioctl_payload->func_specific, ioctl_payload->length); memset(&nvmd_req, 0, sizeof(nvmd_req)); rc = pm8001_tag_alloc(pm8001_ha, &tag); if (rc) { kfree(fw_control_context); return rc; } ccb = &pm8001_ha->ccb_info[tag]; ccb->fw_control_context = fw_control_context; ccb->ccb_tag = tag; nvmd_req.tag = cpu_to_le32(tag); switch (nvmd_type) { case TWI_DEVICE: { u32 twi_addr, twi_page_size; twi_addr = 0xa8; twi_page_size = 2; nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98); nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 | twi_page_size << 8 | TWI_DEVICE); nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length); nvmd_req.resp_addr_hi = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); nvmd_req.resp_addr_lo = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); break; } case C_SEEPROM: nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM); nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length); nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98); nvmd_req.resp_addr_hi = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); nvmd_req.resp_addr_lo = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); break; case VPD_FLASH: nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH); nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length); nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98); nvmd_req.resp_addr_hi = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); nvmd_req.resp_addr_lo = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); break; case EXPAN_ROM: nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM); nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length); nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98); nvmd_req.resp_addr_hi = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi); nvmd_req.resp_addr_lo = cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo); break; default: break; } rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req); return rc; } /** * pm8001_chip_fw_flash_update_build - support the firmware update operation * @pm8001_ha: our hba card information. * @fw_flash_updata_info: firmware flash update param */ static int pm8001_chip_fw_flash_update_build(struct pm8001_hba_info *pm8001_ha, void *fw_flash_updata_info, u32 tag) { struct fw_flash_Update_req payload; struct fw_flash_updata_info *info; struct inbound_queue_table *circularQ; int ret; u32 opc = OPC_INB_FW_FLASH_UPDATE; memset(&payload, 0, sizeof(struct fw_flash_Update_req)); circularQ = &pm8001_ha->inbnd_q_tbl[0]; info = fw_flash_updata_info; payload.tag = cpu_to_le32(tag); payload.cur_image_len = cpu_to_le32(info->cur_image_len); payload.cur_image_offset = cpu_to_le32(info->cur_image_offset); payload.total_image_len = cpu_to_le32(info->total_image_len); payload.len = info->sgl.im_len.len ; payload.sgl_addr_lo = cpu_to_le32(lower_32_bits(le64_to_cpu(info->sgl.addr))); payload.sgl_addr_hi = cpu_to_le32(upper_32_bits(le64_to_cpu(info->sgl.addr))); ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload); return ret; } static int pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha, void *payload) { struct fw_flash_updata_info flash_update_info; struct fw_control_info *fw_control; struct fw_control_ex *fw_control_context; int rc; u32 tag; struct pm8001_ccb_info *ccb; void *buffer = NULL; dma_addr_t phys_addr; u32 phys_addr_hi; u32 phys_addr_lo; struct pm8001_ioctl_payload *ioctl_payload = payload; fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL); if (!fw_control_context) return -ENOMEM; fw_control = (struct fw_control_info *)&ioctl_payload->func_specific[0]; if (fw_control->len != 0) { if (pm8001_mem_alloc(pm8001_ha->pdev, (void **)&buffer, &phys_addr, &phys_addr_hi, &phys_addr_lo, fw_control->len, 0) != 0) { PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("Mem alloc failure\n")); kfree(fw_control_context); return -ENOMEM; } } memcpy(buffer, fw_control->buffer, fw_control->len); flash_update_info.sgl.addr = cpu_to_le64(phys_addr); flash_update_info.sgl.im_len.len = cpu_to_le32(fw_control->len); flash_update_info.sgl.im_len.e = 0; flash_update_info.cur_image_offset = fw_control->offset; flash_update_info.cur_image_len = fw_control->len; flash_update_info.total_image_len = fw_control->size; fw_control_context->fw_control = fw_control; fw_control_context->virtAddr = buffer; fw_control_context->len = fw_control->len; rc = pm8001_tag_alloc(pm8001_ha, &tag); if (rc) { kfree(fw_control_context); return rc; } ccb = &pm8001_ha->ccb_info[tag]; ccb->fw_control_context = fw_control_context; ccb->ccb_tag = tag; rc = pm8001_chip_fw_flash_update_build(pm8001_ha, &flash_update_info, tag); return rc; } static int pm8001_chip_set_dev_state_req(struct pm8001_hba_info *pm8001_ha, struct pm8001_device *pm8001_dev, u32 state) { struct set_dev_state_req payload; struct inbound_queue_table *circularQ; struct pm8001_ccb_info *ccb; int rc; u32 tag; u32 opc = OPC_INB_SET_DEVICE_STATE; memset(&payload, 0, sizeof(payload)); rc = pm8001_tag_alloc(pm8001_ha, &tag); if (rc) return -1; ccb = &pm8001_ha->ccb_info[tag]; ccb->ccb_tag = tag; ccb->device = pm8001_dev; circularQ = &pm8001_ha->inbnd_q_tbl[0]; payload.tag = cpu_to_le32(tag); payload.device_id = cpu_to_le32(pm8001_dev->device_id); payload.nds = cpu_to_le32(state); rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload); return rc; } static int pm8001_chip_sas_re_initialization(struct pm8001_hba_info *pm8001_ha) { struct sas_re_initialization_req payload; struct inbound_queue_table *circularQ; struct pm8001_ccb_info *ccb; int rc; u32 tag; u32 opc = OPC_INB_SAS_RE_INITIALIZE; memset(&payload, 0, sizeof(payload)); rc = pm8001_tag_alloc(pm8001_ha, &tag); if (rc) return -1; ccb = &pm8001_ha->ccb_info[tag]; ccb->ccb_tag = tag; circularQ = &pm8001_ha->inbnd_q_tbl[0]; payload.tag = cpu_to_le32(tag); payload.SSAHOLT = cpu_to_le32(0xd << 25); payload.sata_hol_tmo = cpu_to_le32(80); payload.open_reject_cmdretries_data_retries = cpu_to_le32(0xff00ff); rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload); return rc; } const struct pm8001_dispatch pm8001_8001_dispatch = { .name = "pmc8001", .chip_init = pm8001_chip_init, .chip_soft_rst = pm8001_chip_soft_rst, .chip_rst = pm8001_hw_chip_rst, .chip_iounmap = pm8001_chip_iounmap, .isr = pm8001_chip_isr, .is_our_interupt = pm8001_chip_is_our_interupt, .isr_process_oq = process_oq, .interrupt_enable = pm8001_chip_interrupt_enable, .interrupt_disable = pm8001_chip_interrupt_disable, .make_prd = pm8001_chip_make_sg, .smp_req = pm8001_chip_smp_req, .ssp_io_req = pm8001_chip_ssp_io_req, .sata_req = pm8001_chip_sata_req, .phy_start_req = pm8001_chip_phy_start_req, .phy_stop_req = pm8001_chip_phy_stop_req, .reg_dev_req = pm8001_chip_reg_dev_req, .dereg_dev_req = pm8001_chip_dereg_dev_req, .phy_ctl_req = pm8001_chip_phy_ctl_req, .task_abort = pm8001_chip_abort_task, .ssp_tm_req = pm8001_chip_ssp_tm_req, .get_nvmd_req = pm8001_chip_get_nvmd_req, .set_nvmd_req = pm8001_chip_set_nvmd_req, .fw_flash_update_req = pm8001_chip_fw_flash_update_req, .set_dev_state_req = pm8001_chip_set_dev_state_req, .sas_re_init_req = pm8001_chip_sas_re_initialization, };
gpl-2.0
karltsou/maxtouch-v3.x
drivers/char/hw_random/ixp4xx-rng.c
5053
1664
/* * drivers/char/hw_random/ixp4xx-rng.c * * RNG driver for Intel IXP4xx family of NPUs * * Author: Deepak Saxena <dsaxena@plexity.net> * * Copyright 2005 (c) MontaVista Software, Inc. * * Fixes by Michael Buesch * * 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/types.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> #include <linux/bitops.h> #include <linux/hw_random.h> #include <asm/io.h> #include <mach/hardware.h> static int ixp4xx_rng_data_read(struct hwrng *rng, u32 *buffer) { void __iomem * rng_base = (void __iomem *)rng->priv; *buffer = __raw_readl(rng_base); return 4; } static struct hwrng ixp4xx_rng_ops = { .name = "ixp4xx", .data_read = ixp4xx_rng_data_read, }; static int __init ixp4xx_rng_init(void) { void __iomem * rng_base; int err; if (!cpu_is_ixp46x()) /* includes IXP455 */ return -ENOSYS; rng_base = ioremap(0x70002100, 4); if (!rng_base) return -ENOMEM; ixp4xx_rng_ops.priv = (unsigned long)rng_base; err = hwrng_register(&ixp4xx_rng_ops); if (err) iounmap(rng_base); return err; } static void __exit ixp4xx_rng_exit(void) { void __iomem * rng_base = (void __iomem *)ixp4xx_rng_ops.priv; hwrng_unregister(&ixp4xx_rng_ops); iounmap(rng_base); } module_init(ixp4xx_rng_init); module_exit(ixp4xx_rng_exit); MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>"); MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x"); MODULE_LICENSE("GPL");
gpl-2.0
mrimp/N910TUVU1ANIH_kernel
drivers/char/hw_random/ixp4xx-rng.c
5053
1664
/* * drivers/char/hw_random/ixp4xx-rng.c * * RNG driver for Intel IXP4xx family of NPUs * * Author: Deepak Saxena <dsaxena@plexity.net> * * Copyright 2005 (c) MontaVista Software, Inc. * * Fixes by Michael Buesch * * 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/types.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> #include <linux/bitops.h> #include <linux/hw_random.h> #include <asm/io.h> #include <mach/hardware.h> static int ixp4xx_rng_data_read(struct hwrng *rng, u32 *buffer) { void __iomem * rng_base = (void __iomem *)rng->priv; *buffer = __raw_readl(rng_base); return 4; } static struct hwrng ixp4xx_rng_ops = { .name = "ixp4xx", .data_read = ixp4xx_rng_data_read, }; static int __init ixp4xx_rng_init(void) { void __iomem * rng_base; int err; if (!cpu_is_ixp46x()) /* includes IXP455 */ return -ENOSYS; rng_base = ioremap(0x70002100, 4); if (!rng_base) return -ENOMEM; ixp4xx_rng_ops.priv = (unsigned long)rng_base; err = hwrng_register(&ixp4xx_rng_ops); if (err) iounmap(rng_base); return err; } static void __exit ixp4xx_rng_exit(void) { void __iomem * rng_base = (void __iomem *)ixp4xx_rng_ops.priv; hwrng_unregister(&ixp4xx_rng_ops); iounmap(rng_base); } module_init(ixp4xx_rng_init); module_exit(ixp4xx_rng_exit); MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>"); MODULE_DESCRIPTION("H/W Pseudo-Random Number Generator (RNG) driver for IXP45x/46x"); MODULE_LICENSE("GPL");
gpl-2.0
danielpanzella/P900-kernel-source
arch/arm/mach-sa1100/ssp.c
9661
4892
/* * linux/arch/arm/mach-sa1100/ssp.c * * Copyright (C) 2003 Russell King. * * 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. * * Generic SSP driver. This provides the generic core for simple * IO-based SSP applications. */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/errno.h> #include <linux/interrupt.h> #include <linux/ioport.h> #include <linux/init.h> #include <linux/io.h> #include <mach/hardware.h> #include <mach/irqs.h> #include <asm/hardware/ssp.h> #define TIMEOUT 100000 static irqreturn_t ssp_interrupt(int irq, void *dev_id) { unsigned int status = Ser4SSSR; if (status & SSSR_ROR) printk(KERN_WARNING "SSP: receiver overrun\n"); Ser4SSSR = SSSR_ROR; return status ? IRQ_HANDLED : IRQ_NONE; } /** * ssp_write_word - write a word to the SSP port * @data: 16-bit, MSB justified data to write. * * Wait for a free entry in the SSP transmit FIFO, and write a data * word to the SSP port. Wait for the SSP port to start sending * the data. * * The caller is expected to perform the necessary locking. * * Returns: * %-ETIMEDOUT timeout occurred * 0 success */ int ssp_write_word(u16 data) { int timeout = TIMEOUT; while (!(Ser4SSSR & SSSR_TNF)) { if (!--timeout) return -ETIMEDOUT; cpu_relax(); } Ser4SSDR = data; timeout = TIMEOUT; while (!(Ser4SSSR & SSSR_BSY)) { if (!--timeout) return -ETIMEDOUT; cpu_relax(); } return 0; } /** * ssp_read_word - read a word from the SSP port * * Wait for a data word in the SSP receive FIFO, and return the * received data. Data is LSB justified. * * Note: Currently, if data is not expected to be received, this * function will wait for ever. * * The caller is expected to perform the necessary locking. * * Returns: * %-ETIMEDOUT timeout occurred * 16-bit data success */ int ssp_read_word(u16 *data) { int timeout = TIMEOUT; while (!(Ser4SSSR & SSSR_RNE)) { if (!--timeout) return -ETIMEDOUT; cpu_relax(); } *data = (u16)Ser4SSDR; return 0; } /** * ssp_flush - flush the transmit and receive FIFOs * * Wait for the SSP to idle, and ensure that the receive FIFO * is empty. * * The caller is expected to perform the necessary locking. * * Returns: * %-ETIMEDOUT timeout occurred * 0 success */ int ssp_flush(void) { int timeout = TIMEOUT * 2; do { while (Ser4SSSR & SSSR_RNE) { if (!--timeout) return -ETIMEDOUT; (void) Ser4SSDR; } if (!--timeout) return -ETIMEDOUT; } while (Ser4SSSR & SSSR_BSY); return 0; } /** * ssp_enable - enable the SSP port * * Turn on the SSP port. */ void ssp_enable(void) { Ser4SSCR0 |= SSCR0_SSE; } /** * ssp_disable - shut down the SSP port * * Turn off the SSP port, optionally powering it down. */ void ssp_disable(void) { Ser4SSCR0 &= ~SSCR0_SSE; } /** * ssp_save_state - save the SSP configuration * @ssp: pointer to structure to save SSP configuration * * Save the configured SSP state for suspend. */ void ssp_save_state(struct ssp_state *ssp) { ssp->cr0 = Ser4SSCR0; ssp->cr1 = Ser4SSCR1; Ser4SSCR0 &= ~SSCR0_SSE; } /** * ssp_restore_state - restore a previously saved SSP configuration * @ssp: pointer to configuration saved by ssp_save_state * * Restore the SSP configuration saved previously by ssp_save_state. */ void ssp_restore_state(struct ssp_state *ssp) { Ser4SSSR = SSSR_ROR; Ser4SSCR0 = ssp->cr0 & ~SSCR0_SSE; Ser4SSCR1 = ssp->cr1; Ser4SSCR0 = ssp->cr0; } /** * ssp_init - setup the SSP port * * initialise and claim resources for the SSP port. * * Returns: * %-ENODEV if the SSP port is unavailable * %-EBUSY if the resources are already in use * %0 on success */ int ssp_init(void) { int ret; if (!(PPAR & PPAR_SPR) && (Ser4MCCR0 & MCCR0_MCE)) return -ENODEV; if (!request_mem_region(__PREG(Ser4SSCR0), 0x18, "SSP")) { return -EBUSY; } Ser4SSSR = SSSR_ROR; ret = request_irq(IRQ_Ser4SSP, ssp_interrupt, 0, "SSP", NULL); if (ret) goto out_region; return 0; out_region: release_mem_region(__PREG(Ser4SSCR0), 0x18); return ret; } /** * ssp_exit - undo the effects of ssp_init * * release and free resources for the SSP port. */ void ssp_exit(void) { Ser4SSCR0 &= ~SSCR0_SSE; free_irq(IRQ_Ser4SSP, NULL); release_mem_region(__PREG(Ser4SSCR0), 0x18); } MODULE_AUTHOR("Russell King"); MODULE_DESCRIPTION("SA11x0 SSP PIO driver"); MODULE_LICENSE("GPL"); EXPORT_SYMBOL(ssp_write_word); EXPORT_SYMBOL(ssp_read_word); EXPORT_SYMBOL(ssp_flush); EXPORT_SYMBOL(ssp_enable); EXPORT_SYMBOL(ssp_disable); EXPORT_SYMBOL(ssp_save_state); EXPORT_SYMBOL(ssp_restore_state); EXPORT_SYMBOL(ssp_init); EXPORT_SYMBOL(ssp_exit);
gpl-2.0
ingmar-k/Buffalo-Linkstation-Kirkwood-Kernel
drivers/media/pci/mantis/mantis_ioc.c
10429
3192
/* Mantis PCI bridge driver Copyright (C) Manu Abraham (abraham.manu@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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/kernel.h> #include <linux/i2c.h> #include <linux/signal.h> #include <linux/sched.h> #include <linux/interrupt.h> #include <asm/io.h> #include "dmxdev.h" #include "dvbdev.h" #include "dvb_demux.h" #include "dvb_frontend.h" #include "dvb_net.h" #include "mantis_common.h" #include "mantis_reg.h" #include "mantis_ioc.h" static int read_eeprom_bytes(struct mantis_pci *mantis, u8 reg, u8 *data, u8 length) { struct i2c_adapter *adapter = &mantis->adapter; int err; u8 buf = reg; struct i2c_msg msg[] = { { .addr = 0x50, .flags = 0, .buf = &buf, .len = 1 }, { .addr = 0x50, .flags = I2C_M_RD, .buf = data, .len = length }, }; err = i2c_transfer(adapter, msg, 2); if (err < 0) { dprintk(MANTIS_ERROR, 1, "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >", err, data[0], data[1]); return err; } return 0; } int mantis_get_mac(struct mantis_pci *mantis) { int err; u8 mac_addr[6] = {0}; err = read_eeprom_bytes(mantis, 0x08, mac_addr, 6); if (err < 0) { dprintk(MANTIS_ERROR, 1, "ERROR: Mantis EEPROM read error <%d>", err); return err; } dprintk(MANTIS_ERROR, 0, " MAC Address=[%pM]\n", mac_addr); return 0; } EXPORT_SYMBOL_GPL(mantis_get_mac); /* Turn the given bit on or off. */ void mantis_gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value) { u32 cur; dprintk(MANTIS_DEBUG, 1, "Set Bit <%d> to <%d>", bitpos, value); cur = mmread(MANTIS_GPIF_ADDR); if (value) mantis->gpio_status = cur | (1 << bitpos); else mantis->gpio_status = cur & (~(1 << bitpos)); dprintk(MANTIS_DEBUG, 1, "GPIO Value <%02x>", mantis->gpio_status); mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR); mmwrite(0x00, MANTIS_GPIF_DOUT); } EXPORT_SYMBOL_GPL(mantis_gpio_set_bits); int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl) { u32 reg; reg = mmread(MANTIS_CONTROL); switch (stream_ctl) { case STREAM_TO_HIF: dprintk(MANTIS_DEBUG, 1, "Set stream to HIF"); reg &= 0xff - MANTIS_BYPASS; mmwrite(reg, MANTIS_CONTROL); reg |= MANTIS_BYPASS; mmwrite(reg, MANTIS_CONTROL); break; case STREAM_TO_CAM: dprintk(MANTIS_DEBUG, 1, "Set stream to CAM"); reg |= MANTIS_BYPASS; mmwrite(reg, MANTIS_CONTROL); reg &= 0xff - MANTIS_BYPASS; mmwrite(reg, MANTIS_CONTROL); break; default: dprintk(MANTIS_ERROR, 1, "Unknown MODE <%02x>", stream_ctl); return -1; } return 0; } EXPORT_SYMBOL_GPL(mantis_stream_control);
gpl-2.0
macressler/parallella-linux
arch/m32r/kernel/align.c
13757
12025
/* * align.c - address exception handler for M32R * * Copyright (c) 2003 Hitoshi Yamamoto */ #include <asm/ptrace.h> #include <asm/uaccess.h> static int get_reg(struct pt_regs *regs, int nr) { int val; if (nr < 4) val = *(unsigned long *)(&regs->r0 + nr); else if (nr < 7) val = *(unsigned long *)(&regs->r4 + (nr - 4)); else if (nr < 13) val = *(unsigned long *)(&regs->r7 + (nr - 7)); else val = *(unsigned long *)(&regs->fp + (nr - 13)); return val; } static void set_reg(struct pt_regs *regs, int nr, int val) { if (nr < 4) *(unsigned long *)(&regs->r0 + nr) = val; else if (nr < 7) *(unsigned long *)(&regs->r4 + (nr - 4)) = val; else if (nr < 13) *(unsigned long *)(&regs->r7 + (nr - 7)) = val; else *(unsigned long *)(&regs->fp + (nr - 13)) = val; } #define REG1(insn) (((insn) & 0x0f00) >> 8) #define REG2(insn) ((insn) & 0x000f) #define PSW_BC 0x100 /* O- instruction */ #define ISA_LD1 0x20c0 /* ld Rdest, @Rsrc */ #define ISA_LD2 0x20e0 /* ld Rdest, @Rsrc+ */ #define ISA_LDH 0x20a0 /* ldh Rdest, @Rsrc */ #define ISA_LDUH 0x20b0 /* lduh Rdest, @Rsrc */ #define ISA_ST1 0x2040 /* st Rsrc1, @Rsrc2 */ #define ISA_ST2 0x2060 /* st Rsrc1, @+Rsrc2 */ #define ISA_ST3 0x2070 /* st Rsrc1, @-Rsrc2 */ #define ISA_STH1 0x2020 /* sth Rsrc1, @Rsrc2 */ #define ISA_STH2 0x2030 /* sth Rsrc1, @Rsrc2+ */ #ifdef CONFIG_ISA_DUAL_ISSUE /* OS instruction */ #define ISA_ADD 0x00a0 /* add Rdest, Rsrc */ #define ISA_ADDI 0x4000 /* addi Rdest, #imm8 */ #define ISA_ADDX 0x0090 /* addx Rdest, Rsrc */ #define ISA_AND 0x00c0 /* and Rdest, Rsrc */ #define ISA_CMP 0x0040 /* cmp Rsrc1, Rsrc2 */ #define ISA_CMPEQ 0x0060 /* cmpeq Rsrc1, Rsrc2 */ #define ISA_CMPU 0x0050 /* cmpu Rsrc1, Rsrc2 */ #define ISA_CMPZ 0x0070 /* cmpz Rsrc */ #define ISA_LDI 0x6000 /* ldi Rdest, #imm8 */ #define ISA_MV 0x1080 /* mv Rdest, Rsrc */ #define ISA_NEG 0x0030 /* neg Rdest, Rsrc */ #define ISA_NOP 0x7000 /* nop */ #define ISA_NOT 0x00b0 /* not Rdest, Rsrc */ #define ISA_OR 0x00e0 /* or Rdest, Rsrc */ #define ISA_SUB 0x0020 /* sub Rdest, Rsrc */ #define ISA_SUBX 0x0010 /* subx Rdest, Rsrc */ #define ISA_XOR 0x00d0 /* xor Rdest, Rsrc */ /* -S instruction */ #define ISA_MUL 0x1060 /* mul Rdest, Rsrc */ #define ISA_MULLO_A0 0x3010 /* mullo Rsrc1, Rsrc2, A0 */ #define ISA_MULLO_A1 0x3090 /* mullo Rsrc1, Rsrc2, A1 */ #define ISA_MVFACMI_A0 0x50f2 /* mvfacmi Rdest, A0 */ #define ISA_MVFACMI_A1 0x50f6 /* mvfacmi Rdest, A1 */ static int emu_addi(unsigned short insn, struct pt_regs *regs) { char imm = (char)(insn & 0xff); int dest = REG1(insn); int val; val = get_reg(regs, dest); val += imm; set_reg(regs, dest, val); return 0; } static int emu_ldi(unsigned short insn, struct pt_regs *regs) { char imm = (char)(insn & 0xff); set_reg(regs, REG1(insn), (int)imm); return 0; } static int emu_add(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); int src = REG2(insn); int val; val = get_reg(regs, dest); val += get_reg(regs, src); set_reg(regs, dest, val); return 0; } static int emu_addx(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); unsigned int val, tmp; val = regs->psw & PSW_BC ? 1 : 0; tmp = get_reg(regs, dest); val += tmp; val += (unsigned int)get_reg(regs, REG2(insn)); set_reg(regs, dest, val); /* C bit set */ if (val < tmp) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_and(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); int val; val = get_reg(regs, dest); val &= get_reg(regs, REG2(insn)); set_reg(regs, dest, val); return 0; } static int emu_cmp(unsigned short insn, struct pt_regs *regs) { if (get_reg(regs, REG1(insn)) < get_reg(regs, REG2(insn))) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_cmpeq(unsigned short insn, struct pt_regs *regs) { if (get_reg(regs, REG1(insn)) == get_reg(regs, REG2(insn))) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_cmpu(unsigned short insn, struct pt_regs *regs) { if ((unsigned int)get_reg(regs, REG1(insn)) < (unsigned int)get_reg(regs, REG2(insn))) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_cmpz(unsigned short insn, struct pt_regs *regs) { if (!get_reg(regs, REG2(insn))) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_mv(unsigned short insn, struct pt_regs *regs) { int val; val = get_reg(regs, REG2(insn)); set_reg(regs, REG1(insn), val); return 0; } static int emu_neg(unsigned short insn, struct pt_regs *regs) { int val; val = get_reg(regs, REG2(insn)); set_reg(regs, REG1(insn), 0 - val); return 0; } static int emu_not(unsigned short insn, struct pt_regs *regs) { int val; val = get_reg(regs, REG2(insn)); set_reg(regs, REG1(insn), ~val); return 0; } static int emu_or(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); int val; val = get_reg(regs, dest); val |= get_reg(regs, REG2(insn)); set_reg(regs, dest, val); return 0; } static int emu_sub(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); int val; val = get_reg(regs, dest); val -= get_reg(regs, REG2(insn)); set_reg(regs, dest, val); return 0; } static int emu_subx(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); unsigned int val, tmp; val = tmp = get_reg(regs, dest); val -= (unsigned int)get_reg(regs, REG2(insn)); val -= regs->psw & PSW_BC ? 1 : 0; set_reg(regs, dest, val); /* C bit set */ if (val > tmp) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_xor(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); unsigned int val; val = (unsigned int)get_reg(regs, dest); val ^= (unsigned int)get_reg(regs, REG2(insn)); set_reg(regs, dest, val); return 0; } static int emu_mul(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); int reg1, reg2; reg1 = get_reg(regs, dest); reg2 = get_reg(regs, REG2(insn)); __asm__ __volatile__ ( "mul %0, %1; \n\t" : "+r" (reg1) : "r" (reg2) ); set_reg(regs, dest, reg1); return 0; } static int emu_mullo_a0(unsigned short insn, struct pt_regs *regs) { int reg1, reg2; reg1 = get_reg(regs, REG1(insn)); reg2 = get_reg(regs, REG2(insn)); __asm__ __volatile__ ( "mullo %0, %1, a0; \n\t" "mvfachi %0, a0; \n\t" "mvfaclo %1, a0; \n\t" : "+r" (reg1), "+r" (reg2) ); regs->acc0h = reg1; regs->acc0l = reg2; return 0; } static int emu_mullo_a1(unsigned short insn, struct pt_regs *regs) { int reg1, reg2; reg1 = get_reg(regs, REG1(insn)); reg2 = get_reg(regs, REG2(insn)); __asm__ __volatile__ ( "mullo %0, %1, a0; \n\t" "mvfachi %0, a0; \n\t" "mvfaclo %1, a0; \n\t" : "+r" (reg1), "+r" (reg2) ); regs->acc1h = reg1; regs->acc1l = reg2; return 0; } static int emu_mvfacmi_a0(unsigned short insn, struct pt_regs *regs) { unsigned long val; val = (regs->acc0h << 16) | (regs->acc0l >> 16); set_reg(regs, REG1(insn), (int)val); return 0; } static int emu_mvfacmi_a1(unsigned short insn, struct pt_regs *regs) { unsigned long val; val = (regs->acc1h << 16) | (regs->acc1l >> 16); set_reg(regs, REG1(insn), (int)val); return 0; } static int emu_m32r2(unsigned short insn, struct pt_regs *regs) { int res = -1; if ((insn & 0x7fff) == ISA_NOP) /* nop */ return 0; switch(insn & 0x7000) { case ISA_ADDI: /* addi Rdest, #imm8 */ res = emu_addi(insn, regs); break; case ISA_LDI: /* ldi Rdest, #imm8 */ res = emu_ldi(insn, regs); break; default: break; } if (!res) return 0; switch(insn & 0x70f0) { case ISA_ADD: /* add Rdest, Rsrc */ res = emu_add(insn, regs); break; case ISA_ADDX: /* addx Rdest, Rsrc */ res = emu_addx(insn, regs); break; case ISA_AND: /* and Rdest, Rsrc */ res = emu_and(insn, regs); break; case ISA_CMP: /* cmp Rsrc1, Rsrc2 */ res = emu_cmp(insn, regs); break; case ISA_CMPEQ: /* cmpeq Rsrc1, Rsrc2 */ res = emu_cmpeq(insn, regs); break; case ISA_CMPU: /* cmpu Rsrc1, Rsrc2 */ res = emu_cmpu(insn, regs); break; case ISA_CMPZ: /* cmpz Rsrc */ res = emu_cmpz(insn, regs); break; case ISA_MV: /* mv Rdest, Rsrc */ res = emu_mv(insn, regs); break; case ISA_NEG: /* neg Rdest, Rsrc */ res = emu_neg(insn, regs); break; case ISA_NOT: /* not Rdest, Rsrc */ res = emu_not(insn, regs); break; case ISA_OR: /* or Rdest, Rsrc */ res = emu_or(insn, regs); break; case ISA_SUB: /* sub Rdest, Rsrc */ res = emu_sub(insn, regs); break; case ISA_SUBX: /* subx Rdest, Rsrc */ res = emu_subx(insn, regs); break; case ISA_XOR: /* xor Rdest, Rsrc */ res = emu_xor(insn, regs); break; case ISA_MUL: /* mul Rdest, Rsrc */ res = emu_mul(insn, regs); break; case ISA_MULLO_A0: /* mullo Rsrc1, Rsrc2 */ res = emu_mullo_a0(insn, regs); break; case ISA_MULLO_A1: /* mullo Rsrc1, Rsrc2 */ res = emu_mullo_a1(insn, regs); break; default: break; } if (!res) return 0; switch(insn & 0x70ff) { case ISA_MVFACMI_A0: /* mvfacmi Rdest */ res = emu_mvfacmi_a0(insn, regs); break; case ISA_MVFACMI_A1: /* mvfacmi Rdest */ res = emu_mvfacmi_a1(insn, regs); break; default: break; } return res; } #endif /* CONFIG_ISA_DUAL_ISSUE */ /* * ld : ?010 dest 1100 src * 0010 dest 1110 src : ld Rdest, @Rsrc+ * ldh : ?010 dest 1010 src * lduh : ?010 dest 1011 src * st : ?010 src1 0100 src2 * 0010 src1 0110 src2 : st Rsrc1, @+Rsrc2 * 0010 src1 0111 src2 : st Rsrc1, @-Rsrc2 * sth : ?010 src1 0010 src2 */ static int insn_check(unsigned long insn, struct pt_regs *regs, unsigned char **ucp) { int res = 0; /* * 32bit insn * ld Rdest, @(disp16, Rsrc) * st Rdest, @(disp16, Rsrc) */ if (insn & 0x80000000) { /* 32bit insn */ *ucp += (short)(insn & 0x0000ffff); regs->bpc += 4; } else { /* 16bit insn */ #ifdef CONFIG_ISA_DUAL_ISSUE /* parallel exec check */ if (!(regs->bpc & 0x2) && insn & 0x8000) { res = emu_m32r2((unsigned short)insn, regs); regs->bpc += 4; } else #endif /* CONFIG_ISA_DUAL_ISSUE */ regs->bpc += 2; } return res; } static int emu_ld(unsigned long insn32, struct pt_regs *regs) { unsigned char *ucp; unsigned long val; unsigned short insn16; int size, src; insn16 = insn32 >> 16; src = REG2(insn16); ucp = (unsigned char *)get_reg(regs, src); if (insn_check(insn32, regs, &ucp)) return -1; size = insn16 & 0x0040 ? 4 : 2; if (copy_from_user(&val, ucp, size)) return -1; if (size == 2) val >>= 16; /* ldh sign check */ if ((insn16 & 0x00f0) == 0x00a0 && (val & 0x8000)) val |= 0xffff0000; set_reg(regs, REG1(insn16), val); /* ld increment check */ if ((insn16 & 0xf0f0) == ISA_LD2) /* ld Rdest, @Rsrc+ */ set_reg(regs, src, (unsigned long)(ucp + 4)); return 0; } static int emu_st(unsigned long insn32, struct pt_regs *regs) { unsigned char *ucp; unsigned long val; unsigned short insn16; int size, src2; insn16 = insn32 >> 16; src2 = REG2(insn16); ucp = (unsigned char *)get_reg(regs, src2); if (insn_check(insn32, regs, &ucp)) return -1; size = insn16 & 0x0040 ? 4 : 2; val = get_reg(regs, REG1(insn16)); if (size == 2) val <<= 16; /* st inc/dec check */ if ((insn16 & 0xf0e0) == 0x2060) { if (insn16 & 0x0010) ucp -= 4; else ucp += 4; set_reg(regs, src2, (unsigned long)ucp); } if (copy_to_user(ucp, &val, size)) return -1; /* sth inc check */ if ((insn16 & 0xf0f0) == ISA_STH2) { ucp += 2; set_reg(regs, src2, (unsigned long)ucp); } return 0; } int handle_unaligned_access(unsigned long insn32, struct pt_regs *regs) { unsigned short insn16; int res; insn16 = insn32 >> 16; /* ld or st check */ if ((insn16 & 0x7000) != 0x2000) return -1; /* insn alignment check */ if ((insn16 & 0x8000) && (regs->bpc & 3)) return -1; if (insn16 & 0x0080) /* ld */ res = emu_ld(insn32, regs); else /* st */ res = emu_st(insn32, regs); return res; }
gpl-2.0
siljaer/android_kernel_cyanogen_msm8916
arch/alpha/boot/tools/mkbb.c
13757
3562
/* This utility makes a bootblock suitable for the SRM console/miniloader */ /* Usage: * mkbb <device> <lxboot> * * Where <device> is the name of the device to install the bootblock on, * and <lxboot> is the name of a bootblock to merge in. This bootblock * contains the offset and size of the bootloader. It must be exactly * 512 bytes long. */ #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> /* Minimal definition of disklabel, so we don't have to include * asm/disklabel.h (confuses make) */ #ifndef MAXPARTITIONS #define MAXPARTITIONS 8 /* max. # of partitions */ #endif #ifndef u8 #define u8 unsigned char #endif #ifndef u16 #define u16 unsigned short #endif #ifndef u32 #define u32 unsigned int #endif struct disklabel { u32 d_magic; /* must be DISKLABELMAGIC */ u16 d_type, d_subtype; u8 d_typename[16]; u8 d_packname[16]; u32 d_secsize; u32 d_nsectors; u32 d_ntracks; u32 d_ncylinders; u32 d_secpercyl; u32 d_secprtunit; u16 d_sparespertrack; u16 d_sparespercyl; u32 d_acylinders; u16 d_rpm, d_interleave, d_trackskew, d_cylskew; u32 d_headswitch, d_trkseek, d_flags; u32 d_drivedata[5]; u32 d_spare[5]; u32 d_magic2; /* must be DISKLABELMAGIC */ u16 d_checksum; u16 d_npartitions; u32 d_bbsize, d_sbsize; struct d_partition { u32 p_size; u32 p_offset; u32 p_fsize; u8 p_fstype; u8 p_frag; u16 p_cpg; } d_partitions[MAXPARTITIONS]; }; typedef union __bootblock { struct { char __pad1[64]; struct disklabel __label; } __u1; struct { unsigned long __pad2[63]; unsigned long __checksum; } __u2; char bootblock_bytes[512]; unsigned long bootblock_quadwords[64]; } bootblock; #define bootblock_label __u1.__label #define bootblock_checksum __u2.__checksum int main(int argc, char ** argv) { bootblock bootblock_from_disk; bootblock bootloader_image; int dev, fd; int i; int nread; /* Make sure of the arg count */ if(argc != 3) { fprintf(stderr, "Usage: %s device lxboot\n", argv[0]); exit(0); } /* First, open the device and make sure it's accessible */ dev = open(argv[1], O_RDWR); if(dev < 0) { perror(argv[1]); exit(0); } /* Now open the lxboot and make sure it's reasonable */ fd = open(argv[2], O_RDONLY); if(fd < 0) { perror(argv[2]); close(dev); exit(0); } /* Read in the lxboot */ nread = read(fd, &bootloader_image, sizeof(bootblock)); if(nread != sizeof(bootblock)) { perror("lxboot read"); fprintf(stderr, "expected %zd, got %d\n", sizeof(bootblock), nread); exit(0); } /* Read in the bootblock from disk. */ nread = read(dev, &bootblock_from_disk, sizeof(bootblock)); if(nread != sizeof(bootblock)) { perror("bootblock read"); fprintf(stderr, "expected %zd, got %d\n", sizeof(bootblock), nread); exit(0); } /* Swap the bootblock's disklabel into the bootloader */ bootloader_image.bootblock_label = bootblock_from_disk.bootblock_label; /* Calculate the bootblock checksum */ bootloader_image.bootblock_checksum = 0; for(i = 0; i < 63; i++) { bootloader_image.bootblock_checksum += bootloader_image.bootblock_quadwords[i]; } /* Write the whole thing out! */ lseek(dev, 0L, SEEK_SET); if(write(dev, &bootloader_image, sizeof(bootblock)) != sizeof(bootblock)) { perror("bootblock write"); exit(0); } close(fd); close(dev); exit(0); }
gpl-2.0
rkharwar/ubuntu-saucy-powerpc
arch/m32r/kernel/align.c
13757
12025
/* * align.c - address exception handler for M32R * * Copyright (c) 2003 Hitoshi Yamamoto */ #include <asm/ptrace.h> #include <asm/uaccess.h> static int get_reg(struct pt_regs *regs, int nr) { int val; if (nr < 4) val = *(unsigned long *)(&regs->r0 + nr); else if (nr < 7) val = *(unsigned long *)(&regs->r4 + (nr - 4)); else if (nr < 13) val = *(unsigned long *)(&regs->r7 + (nr - 7)); else val = *(unsigned long *)(&regs->fp + (nr - 13)); return val; } static void set_reg(struct pt_regs *regs, int nr, int val) { if (nr < 4) *(unsigned long *)(&regs->r0 + nr) = val; else if (nr < 7) *(unsigned long *)(&regs->r4 + (nr - 4)) = val; else if (nr < 13) *(unsigned long *)(&regs->r7 + (nr - 7)) = val; else *(unsigned long *)(&regs->fp + (nr - 13)) = val; } #define REG1(insn) (((insn) & 0x0f00) >> 8) #define REG2(insn) ((insn) & 0x000f) #define PSW_BC 0x100 /* O- instruction */ #define ISA_LD1 0x20c0 /* ld Rdest, @Rsrc */ #define ISA_LD2 0x20e0 /* ld Rdest, @Rsrc+ */ #define ISA_LDH 0x20a0 /* ldh Rdest, @Rsrc */ #define ISA_LDUH 0x20b0 /* lduh Rdest, @Rsrc */ #define ISA_ST1 0x2040 /* st Rsrc1, @Rsrc2 */ #define ISA_ST2 0x2060 /* st Rsrc1, @+Rsrc2 */ #define ISA_ST3 0x2070 /* st Rsrc1, @-Rsrc2 */ #define ISA_STH1 0x2020 /* sth Rsrc1, @Rsrc2 */ #define ISA_STH2 0x2030 /* sth Rsrc1, @Rsrc2+ */ #ifdef CONFIG_ISA_DUAL_ISSUE /* OS instruction */ #define ISA_ADD 0x00a0 /* add Rdest, Rsrc */ #define ISA_ADDI 0x4000 /* addi Rdest, #imm8 */ #define ISA_ADDX 0x0090 /* addx Rdest, Rsrc */ #define ISA_AND 0x00c0 /* and Rdest, Rsrc */ #define ISA_CMP 0x0040 /* cmp Rsrc1, Rsrc2 */ #define ISA_CMPEQ 0x0060 /* cmpeq Rsrc1, Rsrc2 */ #define ISA_CMPU 0x0050 /* cmpu Rsrc1, Rsrc2 */ #define ISA_CMPZ 0x0070 /* cmpz Rsrc */ #define ISA_LDI 0x6000 /* ldi Rdest, #imm8 */ #define ISA_MV 0x1080 /* mv Rdest, Rsrc */ #define ISA_NEG 0x0030 /* neg Rdest, Rsrc */ #define ISA_NOP 0x7000 /* nop */ #define ISA_NOT 0x00b0 /* not Rdest, Rsrc */ #define ISA_OR 0x00e0 /* or Rdest, Rsrc */ #define ISA_SUB 0x0020 /* sub Rdest, Rsrc */ #define ISA_SUBX 0x0010 /* subx Rdest, Rsrc */ #define ISA_XOR 0x00d0 /* xor Rdest, Rsrc */ /* -S instruction */ #define ISA_MUL 0x1060 /* mul Rdest, Rsrc */ #define ISA_MULLO_A0 0x3010 /* mullo Rsrc1, Rsrc2, A0 */ #define ISA_MULLO_A1 0x3090 /* mullo Rsrc1, Rsrc2, A1 */ #define ISA_MVFACMI_A0 0x50f2 /* mvfacmi Rdest, A0 */ #define ISA_MVFACMI_A1 0x50f6 /* mvfacmi Rdest, A1 */ static int emu_addi(unsigned short insn, struct pt_regs *regs) { char imm = (char)(insn & 0xff); int dest = REG1(insn); int val; val = get_reg(regs, dest); val += imm; set_reg(regs, dest, val); return 0; } static int emu_ldi(unsigned short insn, struct pt_regs *regs) { char imm = (char)(insn & 0xff); set_reg(regs, REG1(insn), (int)imm); return 0; } static int emu_add(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); int src = REG2(insn); int val; val = get_reg(regs, dest); val += get_reg(regs, src); set_reg(regs, dest, val); return 0; } static int emu_addx(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); unsigned int val, tmp; val = regs->psw & PSW_BC ? 1 : 0; tmp = get_reg(regs, dest); val += tmp; val += (unsigned int)get_reg(regs, REG2(insn)); set_reg(regs, dest, val); /* C bit set */ if (val < tmp) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_and(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); int val; val = get_reg(regs, dest); val &= get_reg(regs, REG2(insn)); set_reg(regs, dest, val); return 0; } static int emu_cmp(unsigned short insn, struct pt_regs *regs) { if (get_reg(regs, REG1(insn)) < get_reg(regs, REG2(insn))) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_cmpeq(unsigned short insn, struct pt_regs *regs) { if (get_reg(regs, REG1(insn)) == get_reg(regs, REG2(insn))) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_cmpu(unsigned short insn, struct pt_regs *regs) { if ((unsigned int)get_reg(regs, REG1(insn)) < (unsigned int)get_reg(regs, REG2(insn))) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_cmpz(unsigned short insn, struct pt_regs *regs) { if (!get_reg(regs, REG2(insn))) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_mv(unsigned short insn, struct pt_regs *regs) { int val; val = get_reg(regs, REG2(insn)); set_reg(regs, REG1(insn), val); return 0; } static int emu_neg(unsigned short insn, struct pt_regs *regs) { int val; val = get_reg(regs, REG2(insn)); set_reg(regs, REG1(insn), 0 - val); return 0; } static int emu_not(unsigned short insn, struct pt_regs *regs) { int val; val = get_reg(regs, REG2(insn)); set_reg(regs, REG1(insn), ~val); return 0; } static int emu_or(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); int val; val = get_reg(regs, dest); val |= get_reg(regs, REG2(insn)); set_reg(regs, dest, val); return 0; } static int emu_sub(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); int val; val = get_reg(regs, dest); val -= get_reg(regs, REG2(insn)); set_reg(regs, dest, val); return 0; } static int emu_subx(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); unsigned int val, tmp; val = tmp = get_reg(regs, dest); val -= (unsigned int)get_reg(regs, REG2(insn)); val -= regs->psw & PSW_BC ? 1 : 0; set_reg(regs, dest, val); /* C bit set */ if (val > tmp) regs->psw |= PSW_BC; else regs->psw &= ~(PSW_BC); return 0; } static int emu_xor(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); unsigned int val; val = (unsigned int)get_reg(regs, dest); val ^= (unsigned int)get_reg(regs, REG2(insn)); set_reg(regs, dest, val); return 0; } static int emu_mul(unsigned short insn, struct pt_regs *regs) { int dest = REG1(insn); int reg1, reg2; reg1 = get_reg(regs, dest); reg2 = get_reg(regs, REG2(insn)); __asm__ __volatile__ ( "mul %0, %1; \n\t" : "+r" (reg1) : "r" (reg2) ); set_reg(regs, dest, reg1); return 0; } static int emu_mullo_a0(unsigned short insn, struct pt_regs *regs) { int reg1, reg2; reg1 = get_reg(regs, REG1(insn)); reg2 = get_reg(regs, REG2(insn)); __asm__ __volatile__ ( "mullo %0, %1, a0; \n\t" "mvfachi %0, a0; \n\t" "mvfaclo %1, a0; \n\t" : "+r" (reg1), "+r" (reg2) ); regs->acc0h = reg1; regs->acc0l = reg2; return 0; } static int emu_mullo_a1(unsigned short insn, struct pt_regs *regs) { int reg1, reg2; reg1 = get_reg(regs, REG1(insn)); reg2 = get_reg(regs, REG2(insn)); __asm__ __volatile__ ( "mullo %0, %1, a0; \n\t" "mvfachi %0, a0; \n\t" "mvfaclo %1, a0; \n\t" : "+r" (reg1), "+r" (reg2) ); regs->acc1h = reg1; regs->acc1l = reg2; return 0; } static int emu_mvfacmi_a0(unsigned short insn, struct pt_regs *regs) { unsigned long val; val = (regs->acc0h << 16) | (regs->acc0l >> 16); set_reg(regs, REG1(insn), (int)val); return 0; } static int emu_mvfacmi_a1(unsigned short insn, struct pt_regs *regs) { unsigned long val; val = (regs->acc1h << 16) | (regs->acc1l >> 16); set_reg(regs, REG1(insn), (int)val); return 0; } static int emu_m32r2(unsigned short insn, struct pt_regs *regs) { int res = -1; if ((insn & 0x7fff) == ISA_NOP) /* nop */ return 0; switch(insn & 0x7000) { case ISA_ADDI: /* addi Rdest, #imm8 */ res = emu_addi(insn, regs); break; case ISA_LDI: /* ldi Rdest, #imm8 */ res = emu_ldi(insn, regs); break; default: break; } if (!res) return 0; switch(insn & 0x70f0) { case ISA_ADD: /* add Rdest, Rsrc */ res = emu_add(insn, regs); break; case ISA_ADDX: /* addx Rdest, Rsrc */ res = emu_addx(insn, regs); break; case ISA_AND: /* and Rdest, Rsrc */ res = emu_and(insn, regs); break; case ISA_CMP: /* cmp Rsrc1, Rsrc2 */ res = emu_cmp(insn, regs); break; case ISA_CMPEQ: /* cmpeq Rsrc1, Rsrc2 */ res = emu_cmpeq(insn, regs); break; case ISA_CMPU: /* cmpu Rsrc1, Rsrc2 */ res = emu_cmpu(insn, regs); break; case ISA_CMPZ: /* cmpz Rsrc */ res = emu_cmpz(insn, regs); break; case ISA_MV: /* mv Rdest, Rsrc */ res = emu_mv(insn, regs); break; case ISA_NEG: /* neg Rdest, Rsrc */ res = emu_neg(insn, regs); break; case ISA_NOT: /* not Rdest, Rsrc */ res = emu_not(insn, regs); break; case ISA_OR: /* or Rdest, Rsrc */ res = emu_or(insn, regs); break; case ISA_SUB: /* sub Rdest, Rsrc */ res = emu_sub(insn, regs); break; case ISA_SUBX: /* subx Rdest, Rsrc */ res = emu_subx(insn, regs); break; case ISA_XOR: /* xor Rdest, Rsrc */ res = emu_xor(insn, regs); break; case ISA_MUL: /* mul Rdest, Rsrc */ res = emu_mul(insn, regs); break; case ISA_MULLO_A0: /* mullo Rsrc1, Rsrc2 */ res = emu_mullo_a0(insn, regs); break; case ISA_MULLO_A1: /* mullo Rsrc1, Rsrc2 */ res = emu_mullo_a1(insn, regs); break; default: break; } if (!res) return 0; switch(insn & 0x70ff) { case ISA_MVFACMI_A0: /* mvfacmi Rdest */ res = emu_mvfacmi_a0(insn, regs); break; case ISA_MVFACMI_A1: /* mvfacmi Rdest */ res = emu_mvfacmi_a1(insn, regs); break; default: break; } return res; } #endif /* CONFIG_ISA_DUAL_ISSUE */ /* * ld : ?010 dest 1100 src * 0010 dest 1110 src : ld Rdest, @Rsrc+ * ldh : ?010 dest 1010 src * lduh : ?010 dest 1011 src * st : ?010 src1 0100 src2 * 0010 src1 0110 src2 : st Rsrc1, @+Rsrc2 * 0010 src1 0111 src2 : st Rsrc1, @-Rsrc2 * sth : ?010 src1 0010 src2 */ static int insn_check(unsigned long insn, struct pt_regs *regs, unsigned char **ucp) { int res = 0; /* * 32bit insn * ld Rdest, @(disp16, Rsrc) * st Rdest, @(disp16, Rsrc) */ if (insn & 0x80000000) { /* 32bit insn */ *ucp += (short)(insn & 0x0000ffff); regs->bpc += 4; } else { /* 16bit insn */ #ifdef CONFIG_ISA_DUAL_ISSUE /* parallel exec check */ if (!(regs->bpc & 0x2) && insn & 0x8000) { res = emu_m32r2((unsigned short)insn, regs); regs->bpc += 4; } else #endif /* CONFIG_ISA_DUAL_ISSUE */ regs->bpc += 2; } return res; } static int emu_ld(unsigned long insn32, struct pt_regs *regs) { unsigned char *ucp; unsigned long val; unsigned short insn16; int size, src; insn16 = insn32 >> 16; src = REG2(insn16); ucp = (unsigned char *)get_reg(regs, src); if (insn_check(insn32, regs, &ucp)) return -1; size = insn16 & 0x0040 ? 4 : 2; if (copy_from_user(&val, ucp, size)) return -1; if (size == 2) val >>= 16; /* ldh sign check */ if ((insn16 & 0x00f0) == 0x00a0 && (val & 0x8000)) val |= 0xffff0000; set_reg(regs, REG1(insn16), val); /* ld increment check */ if ((insn16 & 0xf0f0) == ISA_LD2) /* ld Rdest, @Rsrc+ */ set_reg(regs, src, (unsigned long)(ucp + 4)); return 0; } static int emu_st(unsigned long insn32, struct pt_regs *regs) { unsigned char *ucp; unsigned long val; unsigned short insn16; int size, src2; insn16 = insn32 >> 16; src2 = REG2(insn16); ucp = (unsigned char *)get_reg(regs, src2); if (insn_check(insn32, regs, &ucp)) return -1; size = insn16 & 0x0040 ? 4 : 2; val = get_reg(regs, REG1(insn16)); if (size == 2) val <<= 16; /* st inc/dec check */ if ((insn16 & 0xf0e0) == 0x2060) { if (insn16 & 0x0010) ucp -= 4; else ucp += 4; set_reg(regs, src2, (unsigned long)ucp); } if (copy_to_user(ucp, &val, size)) return -1; /* sth inc check */ if ((insn16 & 0xf0f0) == ISA_STH2) { ucp += 2; set_reg(regs, src2, (unsigned long)ucp); } return 0; } int handle_unaligned_access(unsigned long insn32, struct pt_regs *regs) { unsigned short insn16; int res; insn16 = insn32 >> 16; /* ld or st check */ if ((insn16 & 0x7000) != 0x2000) return -1; /* insn alignment check */ if ((insn16 & 0x8000) && (regs->bpc & 3)) return -1; if (insn16 & 0x0080) /* ld */ res = emu_ld(insn32, regs); else /* st */ res = emu_st(insn32, regs); return res; }
gpl-2.0
shizhai/wprobe
build_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/gcc-linaro-4.6-2012.12/gcc/testsuite/gfortran.fortran-torture/execute/entry_6.f90
190
2436
! Test alternate entry points for functions when the result types ! of all entry points match function f1 (a) integer, dimension (2, 2) :: a, b, f1, e1 f1 (:, :) = 15 + a (1, 1) return entry e1 (b) e1 (:, :) = 42 + b (1, 1) end function function f2 () real, dimension (2, 2) :: f2, e2 entry e2 () e2 (:, :) = 45 end function function f3 () double precision, dimension (2, 2) :: a, b, f3, e3 entry e3 () f3 (:, :) = 47 end function function f4 (a) result (r) double precision, dimension (2, 2) :: a, b, r, s r (:, :) = 15 + a (1, 1) return entry e4 (b) result (s) s (:, :) = 42 + b (1, 1) end function function f5 () result (r) integer, dimension (2, 2) :: r, s entry e5 () result (s) r (:, :) = 45 end function function f6 () result (r) real, dimension (2, 2) :: r, s entry e6 () result (s) s (:, :) = 47 end function program entrytest interface function f1 (a) integer, dimension (2, 2) :: a, f1 end function function e1 (b) integer, dimension (2, 2) :: b, e1 end function function f2 () real, dimension (2, 2) :: f2 end function function e2 () real, dimension (2, 2) :: e2 end function function f3 () double precision, dimension (2, 2) :: f3 end function function e3 () double precision, dimension (2, 2) :: e3 end function function f4 (a) double precision, dimension (2, 2) :: a, f4 end function function e4 (b) double precision, dimension (2, 2) :: b, e4 end function function f5 () integer, dimension (2, 2) :: f5 end function function e5 () integer, dimension (2, 2) :: e5 end function function f6 () real, dimension (2, 2) :: f6 end function function e6 () real, dimension (2, 2) :: e6 end function end interface integer, dimension (2, 2) :: i, j real, dimension (2, 2) :: r double precision, dimension (2, 2) :: d, e i (:, :) = 6 j = f1 (i) if (any (j .ne. 21)) call abort () i (:, :) = 7 j = e1 (i) j (:, :) = 49 if (any (j .ne. 49)) call abort () r = f2 () if (any (r .ne. 45)) call abort () r = e2 () if (any (r .ne. 45)) call abort () e = f3 () if (any (e .ne. 47)) call abort () e = e3 () if (any (e .ne. 47)) call abort () d (:, :) = 17 e = f4 (d) if (any (e .ne. 32)) call abort () e = e4 (d) if (any (e .ne. 59)) call abort () j = f5 () if (any (j .ne. 45)) call abort () j = e5 () if (any (j .ne. 45)) call abort () r = f6 () if (any (r .ne. 47)) call abort () r = e6 () if (any (r .ne. 47)) call abort () end
gpl-2.0
thepasto/liquid_chocolate_ics_kernel
arch/arm/mach-netx/generic.c
190
4335
/* * arch/arm/mach-netx/generic.c * * Copyright (C) 2005 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/device.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/io.h> #include <mach/hardware.h> #include <asm/mach/map.h> #include <asm/hardware/vic.h> #include <mach/netx-regs.h> #include <asm/mach/irq.h> static struct map_desc netx_io_desc[] __initdata = { { .virtual = NETX_IO_VIRT, .pfn = __phys_to_pfn(NETX_IO_PHYS), .length = NETX_IO_SIZE, .type = MT_DEVICE } }; void __init netx_map_io(void) { iotable_init(netx_io_desc, ARRAY_SIZE(netx_io_desc)); } static struct resource netx_rtc_resources[] = { [0] = { .start = 0x00101200, .end = 0x00101220, .flags = IORESOURCE_MEM, }, }; static struct platform_device netx_rtc_device = { .name = "netx-rtc", .id = 0, .num_resources = ARRAY_SIZE(netx_rtc_resources), .resource = netx_rtc_resources, }; static struct platform_device *devices[] __initdata = { &netx_rtc_device, }; #if 0 #define DEBUG_IRQ(fmt...) printk(fmt) #else #define DEBUG_IRQ(fmt...) while (0) {} #endif static void netx_hif_demux_handler(unsigned int irq_unused, struct irq_desc *desc) { unsigned int irq = NETX_IRQ_HIF_CHAINED(0); unsigned int stat; stat = ((readl(NETX_DPMAS_INT_EN) & readl(NETX_DPMAS_INT_STAT)) >> 24) & 0x1f; while (stat) { if (stat & 1) { DEBUG_IRQ("handling irq %d\n", irq); generic_handle_irq(irq); } irq++; stat >>= 1; } } static int netx_hif_irq_type(unsigned int _irq, unsigned int type) { unsigned int val, irq; val = readl(NETX_DPMAS_IF_CONF1); irq = _irq - NETX_IRQ_HIF_CHAINED(0); if (type & IRQ_TYPE_EDGE_RISING) { DEBUG_IRQ("rising edges\n"); val |= (1 << 26) << irq; } if (type & IRQ_TYPE_EDGE_FALLING) { DEBUG_IRQ("falling edges\n"); val &= ~((1 << 26) << irq); } if (type & IRQ_TYPE_LEVEL_LOW) { DEBUG_IRQ("low level\n"); val &= ~((1 << 26) << irq); } if (type & IRQ_TYPE_LEVEL_HIGH) { DEBUG_IRQ("high level\n"); val |= (1 << 26) << irq; } writel(val, NETX_DPMAS_IF_CONF1); return 0; } static void netx_hif_ack_irq(unsigned int _irq) { unsigned int val, irq; irq = _irq - NETX_IRQ_HIF_CHAINED(0); writel((1 << 24) << irq, NETX_DPMAS_INT_STAT); val = readl(NETX_DPMAS_INT_EN); val &= ~((1 << 24) << irq); writel(val, NETX_DPMAS_INT_EN); DEBUG_IRQ("%s: irq %d\n", __func__, _irq); } static void netx_hif_mask_irq(unsigned int _irq) { unsigned int val, irq; irq = _irq - NETX_IRQ_HIF_CHAINED(0); val = readl(NETX_DPMAS_INT_EN); val &= ~((1 << 24) << irq); writel(val, NETX_DPMAS_INT_EN); DEBUG_IRQ("%s: irq %d\n", __func__, _irq); } static void netx_hif_unmask_irq(unsigned int _irq) { unsigned int val, irq; irq = _irq - NETX_IRQ_HIF_CHAINED(0); val = readl(NETX_DPMAS_INT_EN); val |= (1 << 24) << irq; writel(val, NETX_DPMAS_INT_EN); DEBUG_IRQ("%s: irq %d\n", __func__, _irq); } static struct irq_chip netx_hif_chip = { .ack = netx_hif_ack_irq, .mask = netx_hif_mask_irq, .unmask = netx_hif_unmask_irq, .set_type = netx_hif_irq_type, }; void __init netx_init_irq(void) { int irq; vic_init(__io(io_p2v(NETX_PA_VIC)), 0, ~0); for (irq = NETX_IRQ_HIF_CHAINED(0); irq <= NETX_IRQ_HIF_LAST; irq++) { set_irq_chip(irq, &netx_hif_chip); set_irq_handler(irq, handle_level_irq); set_irq_flags(irq, IRQF_VALID); } writel(NETX_DPMAS_INT_EN_GLB_EN, NETX_DPMAS_INT_EN); set_irq_chained_handler(NETX_IRQ_HIF, netx_hif_demux_handler); } static int __init netx_init(void) { return platform_add_devices(devices, ARRAY_SIZE(devices)); } subsys_initcall(netx_init);
gpl-2.0
Brainiarc7/XenGT-Preview-kernel
net/sched/sch_tbf.c
190
14194
/* * net/sched/sch_tbf.c Token Bucket Filter 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: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> * Dmitry Torokhov <dtor@mail.ru> - allow attaching inner qdiscs - * original idea by Martin Devera * */ #include <linux/module.h> #include <linux/types.h> #include <linux/kernel.h> #include <linux/string.h> #include <linux/errno.h> #include <linux/skbuff.h> #include <net/netlink.h> #include <net/sch_generic.h> #include <net/pkt_sched.h> /* Simple Token Bucket Filter. ======================================= SOURCE. ------- None. Description. ------------ A data flow obeys TBF with rate R and depth B, if for any time interval t_i...t_f the number of transmitted bits does not exceed B + R*(t_f-t_i). Packetized version of this definition: The sequence of packets of sizes s_i served at moments t_i obeys TBF, if for any i<=k: s_i+....+s_k <= B + R*(t_k - t_i) Algorithm. ---------- Let N(t_i) be B/R initially and N(t) grow continuously with time as: N(t+delta) = min{B/R, N(t) + delta} If the first packet in queue has length S, it may be transmitted only at the time t_* when S/R <= N(t_*), and in this case N(t) jumps: N(t_* + 0) = N(t_* - 0) - S/R. Actually, QoS requires two TBF to be applied to a data stream. One of them controls steady state burst size, another one with rate P (peak rate) and depth M (equal to link MTU) limits bursts at a smaller time scale. It is easy to see that P>R, and B>M. If P is infinity, this double TBF is equivalent to a single one. When TBF works in reshaping mode, latency is estimated as: lat = max ((L-B)/R, (L-M)/P) NOTES. ------ If TBF throttles, it starts a watchdog timer, which will wake it up when it is ready to transmit. Note that the minimal timer resolution is 1/HZ. If no new packets arrive during this period, or if the device is not awaken by EOI for some previous packet, TBF can stop its activity for 1/HZ. This means, that with depth B, the maximal rate is R_crit = B*HZ F.e. for 10Mbit ethernet and HZ=100 the minimal allowed B is ~10Kbytes. Note that the peak rate TBF is much more tough: with MTU 1500 P_crit = 150Kbytes/sec. So, if you need greater peak rates, use alpha with HZ=1000 :-) With classful TBF, limit is just kept for backwards compatibility. It is passed to the default bfifo qdisc - if the inner qdisc is changed the limit is not effective anymore. */ struct tbf_sched_data { /* Parameters */ u32 limit; /* Maximal length of backlog: bytes */ u32 max_size; s64 buffer; /* Token bucket depth/rate: MUST BE >= MTU/B */ s64 mtu; struct psched_ratecfg rate; struct psched_ratecfg peak; /* Variables */ s64 tokens; /* Current number of B tokens */ s64 ptokens; /* Current number of P tokens */ s64 t_c; /* Time check-point */ struct Qdisc *qdisc; /* Inner qdisc, default - bfifo queue */ struct qdisc_watchdog watchdog; /* Watchdog timer */ }; /* Time to Length, convert time in ns to length in bytes * to determinate how many bytes can be sent in given time. */ static u64 psched_ns_t2l(const struct psched_ratecfg *r, u64 time_in_ns) { /* The formula is : * len = (time_in_ns * r->rate_bytes_ps) / NSEC_PER_SEC */ u64 len = time_in_ns * r->rate_bytes_ps; do_div(len, NSEC_PER_SEC); if (unlikely(r->linklayer == TC_LINKLAYER_ATM)) { do_div(len, 53); len = len * 48; } if (len > r->overhead) len -= r->overhead; else len = 0; return len; } /* * Return length of individual segments of a gso packet, * including all headers (MAC, IP, TCP/UDP) */ static unsigned int skb_gso_mac_seglen(const struct sk_buff *skb) { unsigned int hdr_len = skb_transport_header(skb) - skb_mac_header(skb); return hdr_len + skb_gso_transport_seglen(skb); } /* GSO packet is too big, segment it so that tbf can transmit * each segment in time */ static int tbf_segment(struct sk_buff *skb, struct Qdisc *sch) { struct tbf_sched_data *q = qdisc_priv(sch); struct sk_buff *segs, *nskb; netdev_features_t features = netif_skb_features(skb); int ret, nb; segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK); if (IS_ERR_OR_NULL(segs)) return qdisc_reshape_fail(skb, sch); nb = 0; while (segs) { nskb = segs->next; segs->next = NULL; qdisc_skb_cb(segs)->pkt_len = segs->len; ret = qdisc_enqueue(segs, q->qdisc); if (ret != NET_XMIT_SUCCESS) { if (net_xmit_drop_count(ret)) sch->qstats.drops++; } else { nb++; } segs = nskb; } sch->q.qlen += nb; if (nb > 1) qdisc_tree_decrease_qlen(sch, 1 - nb); consume_skb(skb); return nb > 0 ? NET_XMIT_SUCCESS : NET_XMIT_DROP; } static int tbf_enqueue(struct sk_buff *skb, struct Qdisc *sch) { struct tbf_sched_data *q = qdisc_priv(sch); int ret; if (qdisc_pkt_len(skb) > q->max_size) { if (skb_is_gso(skb) && skb_gso_mac_seglen(skb) <= q->max_size) return tbf_segment(skb, sch); return qdisc_reshape_fail(skb, sch); } ret = qdisc_enqueue(skb, q->qdisc); if (ret != NET_XMIT_SUCCESS) { if (net_xmit_drop_count(ret)) sch->qstats.drops++; return ret; } sch->q.qlen++; return NET_XMIT_SUCCESS; } static unsigned int tbf_drop(struct Qdisc *sch) { struct tbf_sched_data *q = qdisc_priv(sch); unsigned int len = 0; if (q->qdisc->ops->drop && (len = q->qdisc->ops->drop(q->qdisc)) != 0) { sch->q.qlen--; sch->qstats.drops++; } return len; } static bool tbf_peak_present(const struct tbf_sched_data *q) { return q->peak.rate_bytes_ps; } static struct sk_buff *tbf_dequeue(struct Qdisc *sch) { struct tbf_sched_data *q = qdisc_priv(sch); struct sk_buff *skb; skb = q->qdisc->ops->peek(q->qdisc); if (skb) { s64 now; s64 toks; s64 ptoks = 0; unsigned int len = qdisc_pkt_len(skb); now = ktime_to_ns(ktime_get()); toks = min_t(s64, now - q->t_c, q->buffer); if (tbf_peak_present(q)) { ptoks = toks + q->ptokens; if (ptoks > q->mtu) ptoks = q->mtu; ptoks -= (s64) psched_l2t_ns(&q->peak, len); } toks += q->tokens; if (toks > q->buffer) toks = q->buffer; toks -= (s64) psched_l2t_ns(&q->rate, len); if ((toks|ptoks) >= 0) { skb = qdisc_dequeue_peeked(q->qdisc); if (unlikely(!skb)) return NULL; q->t_c = now; q->tokens = toks; q->ptokens = ptoks; sch->q.qlen--; qdisc_unthrottled(sch); qdisc_bstats_update(sch, skb); return skb; } qdisc_watchdog_schedule_ns(&q->watchdog, now + max_t(long, -toks, -ptoks)); /* Maybe we have a shorter packet in the queue, which can be sent now. It sounds cool, but, however, this is wrong in principle. We MUST NOT reorder packets under these circumstances. Really, if we split the flow into independent subflows, it would be a very good solution. This is the main idea of all FQ algorithms (cf. CSZ, HPFQ, HFSC) */ sch->qstats.overlimits++; } return NULL; } static void tbf_reset(struct Qdisc *sch) { struct tbf_sched_data *q = qdisc_priv(sch); qdisc_reset(q->qdisc); sch->q.qlen = 0; q->t_c = ktime_to_ns(ktime_get()); q->tokens = q->buffer; q->ptokens = q->mtu; qdisc_watchdog_cancel(&q->watchdog); } static const struct nla_policy tbf_policy[TCA_TBF_MAX + 1] = { [TCA_TBF_PARMS] = { .len = sizeof(struct tc_tbf_qopt) }, [TCA_TBF_RTAB] = { .type = NLA_BINARY, .len = TC_RTAB_SIZE }, [TCA_TBF_PTAB] = { .type = NLA_BINARY, .len = TC_RTAB_SIZE }, [TCA_TBF_RATE64] = { .type = NLA_U64 }, [TCA_TBF_PRATE64] = { .type = NLA_U64 }, [TCA_TBF_BURST] = { .type = NLA_U32 }, [TCA_TBF_PBURST] = { .type = NLA_U32 }, }; static int tbf_change(struct Qdisc *sch, struct nlattr *opt) { int err; struct tbf_sched_data *q = qdisc_priv(sch); struct nlattr *tb[TCA_TBF_MAX + 1]; struct tc_tbf_qopt *qopt; struct Qdisc *child = NULL; struct psched_ratecfg rate; struct psched_ratecfg peak; u64 max_size; s64 buffer, mtu; u64 rate64 = 0, prate64 = 0; err = nla_parse_nested(tb, TCA_TBF_MAX, opt, tbf_policy); if (err < 0) return err; err = -EINVAL; if (tb[TCA_TBF_PARMS] == NULL) goto done; qopt = nla_data(tb[TCA_TBF_PARMS]); if (qopt->rate.linklayer == TC_LINKLAYER_UNAWARE) qdisc_put_rtab(qdisc_get_rtab(&qopt->rate, tb[TCA_TBF_RTAB])); if (qopt->peakrate.linklayer == TC_LINKLAYER_UNAWARE) qdisc_put_rtab(qdisc_get_rtab(&qopt->peakrate, tb[TCA_TBF_PTAB])); buffer = min_t(u64, PSCHED_TICKS2NS(qopt->buffer), ~0U); mtu = min_t(u64, PSCHED_TICKS2NS(qopt->mtu), ~0U); if (tb[TCA_TBF_RATE64]) rate64 = nla_get_u64(tb[TCA_TBF_RATE64]); psched_ratecfg_precompute(&rate, &qopt->rate, rate64); if (tb[TCA_TBF_BURST]) { max_size = nla_get_u32(tb[TCA_TBF_BURST]); buffer = psched_l2t_ns(&rate, max_size); } else { max_size = min_t(u64, psched_ns_t2l(&rate, buffer), ~0U); } if (qopt->peakrate.rate) { if (tb[TCA_TBF_PRATE64]) prate64 = nla_get_u64(tb[TCA_TBF_PRATE64]); psched_ratecfg_precompute(&peak, &qopt->peakrate, prate64); if (peak.rate_bytes_ps <= rate.rate_bytes_ps) { pr_warn_ratelimited("sch_tbf: peakrate %llu is lower than or equals to rate %llu !\n", peak.rate_bytes_ps, rate.rate_bytes_ps); err = -EINVAL; goto done; } if (tb[TCA_TBF_PBURST]) { u32 pburst = nla_get_u32(tb[TCA_TBF_PBURST]); max_size = min_t(u32, max_size, pburst); mtu = psched_l2t_ns(&peak, pburst); } else { max_size = min_t(u64, max_size, psched_ns_t2l(&peak, mtu)); } } else { memset(&peak, 0, sizeof(peak)); } if (max_size < psched_mtu(qdisc_dev(sch))) pr_warn_ratelimited("sch_tbf: burst %llu is lower than device %s mtu (%u) !\n", max_size, qdisc_dev(sch)->name, psched_mtu(qdisc_dev(sch))); if (!max_size) { err = -EINVAL; goto done; } if (q->qdisc != &noop_qdisc) { err = fifo_set_limit(q->qdisc, qopt->limit); if (err) goto done; } else if (qopt->limit > 0) { child = fifo_create_dflt(sch, &bfifo_qdisc_ops, qopt->limit); if (IS_ERR(child)) { err = PTR_ERR(child); goto done; } } sch_tree_lock(sch); if (child) { qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen); qdisc_destroy(q->qdisc); q->qdisc = child; } q->limit = qopt->limit; if (tb[TCA_TBF_PBURST]) q->mtu = mtu; else q->mtu = PSCHED_TICKS2NS(qopt->mtu); q->max_size = max_size; if (tb[TCA_TBF_BURST]) q->buffer = buffer; else q->buffer = PSCHED_TICKS2NS(qopt->buffer); q->tokens = q->buffer; q->ptokens = q->mtu; memcpy(&q->rate, &rate, sizeof(struct psched_ratecfg)); memcpy(&q->peak, &peak, sizeof(struct psched_ratecfg)); sch_tree_unlock(sch); err = 0; done: return err; } static int tbf_init(struct Qdisc *sch, struct nlattr *opt) { struct tbf_sched_data *q = qdisc_priv(sch); if (opt == NULL) return -EINVAL; q->t_c = ktime_to_ns(ktime_get()); qdisc_watchdog_init(&q->watchdog, sch); q->qdisc = &noop_qdisc; return tbf_change(sch, opt); } static void tbf_destroy(struct Qdisc *sch) { struct tbf_sched_data *q = qdisc_priv(sch); qdisc_watchdog_cancel(&q->watchdog); qdisc_destroy(q->qdisc); } static int tbf_dump(struct Qdisc *sch, struct sk_buff *skb) { struct tbf_sched_data *q = qdisc_priv(sch); struct nlattr *nest; struct tc_tbf_qopt opt; sch->qstats.backlog = q->qdisc->qstats.backlog; nest = nla_nest_start(skb, TCA_OPTIONS); if (nest == NULL) goto nla_put_failure; opt.limit = q->limit; psched_ratecfg_getrate(&opt.rate, &q->rate); if (tbf_peak_present(q)) psched_ratecfg_getrate(&opt.peakrate, &q->peak); else memset(&opt.peakrate, 0, sizeof(opt.peakrate)); opt.mtu = PSCHED_NS2TICKS(q->mtu); opt.buffer = PSCHED_NS2TICKS(q->buffer); if (nla_put(skb, TCA_TBF_PARMS, sizeof(opt), &opt)) goto nla_put_failure; if (q->rate.rate_bytes_ps >= (1ULL << 32) && nla_put_u64(skb, TCA_TBF_RATE64, q->rate.rate_bytes_ps)) goto nla_put_failure; if (tbf_peak_present(q) && q->peak.rate_bytes_ps >= (1ULL << 32) && nla_put_u64(skb, TCA_TBF_PRATE64, q->peak.rate_bytes_ps)) goto nla_put_failure; return nla_nest_end(skb, nest); nla_put_failure: nla_nest_cancel(skb, nest); return -1; } static int tbf_dump_class(struct Qdisc *sch, unsigned long cl, struct sk_buff *skb, struct tcmsg *tcm) { struct tbf_sched_data *q = qdisc_priv(sch); tcm->tcm_handle |= TC_H_MIN(1); tcm->tcm_info = q->qdisc->handle; return 0; } static int tbf_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, struct Qdisc **old) { struct tbf_sched_data *q = qdisc_priv(sch); if (new == NULL) new = &noop_qdisc; sch_tree_lock(sch); *old = q->qdisc; q->qdisc = new; qdisc_tree_decrease_qlen(*old, (*old)->q.qlen); qdisc_reset(*old); sch_tree_unlock(sch); return 0; } static struct Qdisc *tbf_leaf(struct Qdisc *sch, unsigned long arg) { struct tbf_sched_data *q = qdisc_priv(sch); return q->qdisc; } static unsigned long tbf_get(struct Qdisc *sch, u32 classid) { return 1; } static void tbf_put(struct Qdisc *sch, unsigned long arg) { } static void tbf_walk(struct Qdisc *sch, struct qdisc_walker *walker) { if (!walker->stop) { if (walker->count >= walker->skip) if (walker->fn(sch, 1, walker) < 0) { walker->stop = 1; return; } walker->count++; } } static const struct Qdisc_class_ops tbf_class_ops = { .graft = tbf_graft, .leaf = tbf_leaf, .get = tbf_get, .put = tbf_put, .walk = tbf_walk, .dump = tbf_dump_class, }; static struct Qdisc_ops tbf_qdisc_ops __read_mostly = { .next = NULL, .cl_ops = &tbf_class_ops, .id = "tbf", .priv_size = sizeof(struct tbf_sched_data), .enqueue = tbf_enqueue, .dequeue = tbf_dequeue, .peek = qdisc_peek_dequeued, .drop = tbf_drop, .init = tbf_init, .reset = tbf_reset, .destroy = tbf_destroy, .change = tbf_change, .dump = tbf_dump, .owner = THIS_MODULE, }; static int __init tbf_module_init(void) { return register_qdisc(&tbf_qdisc_ops); } static void __exit tbf_module_exit(void) { unregister_qdisc(&tbf_qdisc_ops); } module_init(tbf_module_init) module_exit(tbf_module_exit) MODULE_LICENSE("GPL");
gpl-2.0
ls2uper/linux
drivers/input/gameport/gameport.c
702
20386
/* * Generic gameport layer * * Copyright (c) 1999-2002 Vojtech Pavlik * Copyright (c) 2005 Dmitry Torokhov */ /* * 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. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/stddef.h> #include <linux/module.h> #include <linux/ioport.h> #include <linux/init.h> #include <linux/gameport.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/workqueue.h> #include <linux/sched.h> /* HZ */ #include <linux/mutex.h> #include <linux/timekeeping.h> /*#include <asm/io.h>*/ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); MODULE_DESCRIPTION("Generic gameport layer"); MODULE_LICENSE("GPL"); static bool use_ktime = true; module_param(use_ktime, bool, 0400); MODULE_PARM_DESC(use_ktime, "Use ktime for measuring I/O speed"); /* * gameport_mutex protects entire gameport subsystem and is taken * every time gameport port or driver registrered or unregistered. */ static DEFINE_MUTEX(gameport_mutex); static LIST_HEAD(gameport_list); static struct bus_type gameport_bus; static void gameport_add_port(struct gameport *gameport); static void gameport_attach_driver(struct gameport_driver *drv); static void gameport_reconnect_port(struct gameport *gameport); static void gameport_disconnect_port(struct gameport *gameport); #if defined(__i386__) #include <linux/i8253.h> #define DELTA(x,y) ((y)-(x)+((y)<(x)?1193182/HZ:0)) #define GET_TIME(x) do { x = get_time_pit(); } while (0) static unsigned int get_time_pit(void) { unsigned long flags; unsigned int count; raw_spin_lock_irqsave(&i8253_lock, flags); outb_p(0x00, 0x43); count = inb_p(0x40); count |= inb_p(0x40) << 8; raw_spin_unlock_irqrestore(&i8253_lock, flags); return count; } #endif /* * gameport_measure_speed() measures the gameport i/o speed. */ static int gameport_measure_speed(struct gameport *gameport) { unsigned int i, t, tx; u64 t1, t2, t3; unsigned long flags; if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW)) return 0; tx = ~0; for (i = 0; i < 50; i++) { local_irq_save(flags); t1 = ktime_get_ns(); for (t = 0; t < 50; t++) gameport_read(gameport); t2 = ktime_get_ns(); t3 = ktime_get_ns(); local_irq_restore(flags); udelay(i * 10); t = (t2 - t1) - (t3 - t2); if (t < tx) tx = t; } gameport_close(gameport); t = 1000000 * 50; if (tx) t /= tx; return t; } static int old_gameport_measure_speed(struct gameport *gameport) { #if defined(__i386__) unsigned int i, t, t1, t2, t3, tx; unsigned long flags; if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW)) return 0; tx = 1 << 30; for(i = 0; i < 50; i++) { local_irq_save(flags); GET_TIME(t1); for (t = 0; t < 50; t++) gameport_read(gameport); GET_TIME(t2); GET_TIME(t3); local_irq_restore(flags); udelay(i * 10); if ((t = DELTA(t2,t1) - DELTA(t3,t2)) < tx) tx = t; } gameport_close(gameport); return 59659 / (tx < 1 ? 1 : tx); #elif defined (__x86_64__) unsigned int i, t; unsigned long tx, t1, t2, flags; if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW)) return 0; tx = 1 << 30; for(i = 0; i < 50; i++) { local_irq_save(flags); rdtscl(t1); for (t = 0; t < 50; t++) gameport_read(gameport); rdtscl(t2); local_irq_restore(flags); udelay(i * 10); if (t2 - t1 < tx) tx = t2 - t1; } gameport_close(gameport); return (this_cpu_read(cpu_info.loops_per_jiffy) * (unsigned long)HZ / (1000 / 50)) / (tx < 1 ? 1 : tx); #else unsigned int j, t = 0; if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW)) return 0; j = jiffies; while (j == jiffies); j = jiffies; while (j == jiffies) { t++; gameport_read(gameport); } gameport_close(gameport); return t * HZ / 1000; #endif } void gameport_start_polling(struct gameport *gameport) { spin_lock(&gameport->timer_lock); if (!gameport->poll_cnt++) { BUG_ON(!gameport->poll_handler); BUG_ON(!gameport->poll_interval); mod_timer(&gameport->poll_timer, jiffies + msecs_to_jiffies(gameport->poll_interval)); } spin_unlock(&gameport->timer_lock); } EXPORT_SYMBOL(gameport_start_polling); void gameport_stop_polling(struct gameport *gameport) { spin_lock(&gameport->timer_lock); if (!--gameport->poll_cnt) del_timer(&gameport->poll_timer); spin_unlock(&gameport->timer_lock); } EXPORT_SYMBOL(gameport_stop_polling); static void gameport_run_poll_handler(unsigned long d) { struct gameport *gameport = (struct gameport *)d; gameport->poll_handler(gameport); if (gameport->poll_cnt) mod_timer(&gameport->poll_timer, jiffies + msecs_to_jiffies(gameport->poll_interval)); } /* * Basic gameport -> driver core mappings */ static int gameport_bind_driver(struct gameport *gameport, struct gameport_driver *drv) { int error; gameport->dev.driver = &drv->driver; if (drv->connect(gameport, drv)) { gameport->dev.driver = NULL; return -ENODEV; } error = device_bind_driver(&gameport->dev); if (error) { dev_warn(&gameport->dev, "device_bind_driver() failed for %s (%s) and %s, error: %d\n", gameport->phys, gameport->name, drv->description, error); drv->disconnect(gameport); gameport->dev.driver = NULL; return error; } return 0; } static void gameport_find_driver(struct gameport *gameport) { int error; error = device_attach(&gameport->dev); if (error < 0) dev_warn(&gameport->dev, "device_attach() failed for %s (%s), error: %d\n", gameport->phys, gameport->name, error); } /* * Gameport event processing. */ enum gameport_event_type { GAMEPORT_REGISTER_PORT, GAMEPORT_ATTACH_DRIVER, }; struct gameport_event { enum gameport_event_type type; void *object; struct module *owner; struct list_head node; }; static DEFINE_SPINLOCK(gameport_event_lock); /* protects gameport_event_list */ static LIST_HEAD(gameport_event_list); static struct gameport_event *gameport_get_event(void) { struct gameport_event *event = NULL; unsigned long flags; spin_lock_irqsave(&gameport_event_lock, flags); if (!list_empty(&gameport_event_list)) { event = list_first_entry(&gameport_event_list, struct gameport_event, node); list_del_init(&event->node); } spin_unlock_irqrestore(&gameport_event_lock, flags); return event; } static void gameport_free_event(struct gameport_event *event) { module_put(event->owner); kfree(event); } static void gameport_remove_duplicate_events(struct gameport_event *event) { struct gameport_event *e, *next; unsigned long flags; spin_lock_irqsave(&gameport_event_lock, flags); list_for_each_entry_safe(e, next, &gameport_event_list, node) { if (event->object == e->object) { /* * If this event is of different type we should not * look further - we only suppress duplicate events * that were sent back-to-back. */ if (event->type != e->type) break; list_del_init(&e->node); gameport_free_event(e); } } spin_unlock_irqrestore(&gameport_event_lock, flags); } static void gameport_handle_events(struct work_struct *work) { struct gameport_event *event; mutex_lock(&gameport_mutex); /* * Note that we handle only one event here to give swsusp * a chance to freeze kgameportd thread. Gameport events * should be pretty rare so we are not concerned about * taking performance hit. */ if ((event = gameport_get_event())) { switch (event->type) { case GAMEPORT_REGISTER_PORT: gameport_add_port(event->object); break; case GAMEPORT_ATTACH_DRIVER: gameport_attach_driver(event->object); break; } gameport_remove_duplicate_events(event); gameport_free_event(event); } mutex_unlock(&gameport_mutex); } static DECLARE_WORK(gameport_event_work, gameport_handle_events); static int gameport_queue_event(void *object, struct module *owner, enum gameport_event_type event_type) { unsigned long flags; struct gameport_event *event; int retval = 0; spin_lock_irqsave(&gameport_event_lock, flags); /* * Scan event list for the other events for the same gameport port, * starting with the most recent one. If event is the same we * do not need add new one. If event is of different type we * need to add this event and should not look further because * we need to preserve sequence of distinct events. */ list_for_each_entry_reverse(event, &gameport_event_list, node) { if (event->object == object) { if (event->type == event_type) goto out; break; } } event = kmalloc(sizeof(struct gameport_event), GFP_ATOMIC); if (!event) { pr_err("Not enough memory to queue event %d\n", event_type); retval = -ENOMEM; goto out; } if (!try_module_get(owner)) { pr_warning("Can't get module reference, dropping event %d\n", event_type); kfree(event); retval = -EINVAL; goto out; } event->type = event_type; event->object = object; event->owner = owner; list_add_tail(&event->node, &gameport_event_list); queue_work(system_long_wq, &gameport_event_work); out: spin_unlock_irqrestore(&gameport_event_lock, flags); return retval; } /* * Remove all events that have been submitted for a given object, * be it a gameport port or a driver. */ static void gameport_remove_pending_events(void *object) { struct gameport_event *event, *next; unsigned long flags; spin_lock_irqsave(&gameport_event_lock, flags); list_for_each_entry_safe(event, next, &gameport_event_list, node) { if (event->object == object) { list_del_init(&event->node); gameport_free_event(event); } } spin_unlock_irqrestore(&gameport_event_lock, flags); } /* * Destroy child gameport port (if any) that has not been fully registered yet. * * Note that we rely on the fact that port can have only one child and therefore * only one child registration request can be pending. Additionally, children * are registered by driver's connect() handler so there can't be a grandchild * pending registration together with a child. */ static struct gameport *gameport_get_pending_child(struct gameport *parent) { struct gameport_event *event; struct gameport *gameport, *child = NULL; unsigned long flags; spin_lock_irqsave(&gameport_event_lock, flags); list_for_each_entry(event, &gameport_event_list, node) { if (event->type == GAMEPORT_REGISTER_PORT) { gameport = event->object; if (gameport->parent == parent) { child = gameport; break; } } } spin_unlock_irqrestore(&gameport_event_lock, flags); return child; } /* * Gameport port operations */ static ssize_t gameport_description_show(struct device *dev, struct device_attribute *attr, char *buf) { struct gameport *gameport = to_gameport_port(dev); return sprintf(buf, "%s\n", gameport->name); } static DEVICE_ATTR(description, S_IRUGO, gameport_description_show, NULL); static ssize_t drvctl_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct gameport *gameport = to_gameport_port(dev); struct device_driver *drv; int error; error = mutex_lock_interruptible(&gameport_mutex); if (error) return error; if (!strncmp(buf, "none", count)) { gameport_disconnect_port(gameport); } else if (!strncmp(buf, "reconnect", count)) { gameport_reconnect_port(gameport); } else if (!strncmp(buf, "rescan", count)) { gameport_disconnect_port(gameport); gameport_find_driver(gameport); } else if ((drv = driver_find(buf, &gameport_bus)) != NULL) { gameport_disconnect_port(gameport); error = gameport_bind_driver(gameport, to_gameport_driver(drv)); } else { error = -EINVAL; } mutex_unlock(&gameport_mutex); return error ? error : count; } static DEVICE_ATTR_WO(drvctl); static struct attribute *gameport_device_attrs[] = { &dev_attr_description.attr, &dev_attr_drvctl.attr, NULL, }; ATTRIBUTE_GROUPS(gameport_device); static void gameport_release_port(struct device *dev) { struct gameport *gameport = to_gameport_port(dev); kfree(gameport); module_put(THIS_MODULE); } void gameport_set_phys(struct gameport *gameport, const char *fmt, ...) { va_list args; va_start(args, fmt); vsnprintf(gameport->phys, sizeof(gameport->phys), fmt, args); va_end(args); } EXPORT_SYMBOL(gameport_set_phys); /* * Prepare gameport port for registration. */ static void gameport_init_port(struct gameport *gameport) { static atomic_t gameport_no = ATOMIC_INIT(-1); __module_get(THIS_MODULE); mutex_init(&gameport->drv_mutex); device_initialize(&gameport->dev); dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no)); gameport->dev.bus = &gameport_bus; gameport->dev.release = gameport_release_port; if (gameport->parent) gameport->dev.parent = &gameport->parent->dev; INIT_LIST_HEAD(&gameport->node); spin_lock_init(&gameport->timer_lock); init_timer(&gameport->poll_timer); gameport->poll_timer.function = gameport_run_poll_handler; gameport->poll_timer.data = (unsigned long)gameport; } /* * Complete gameport port registration. * Driver core will attempt to find appropriate driver for the port. */ static void gameport_add_port(struct gameport *gameport) { int error; if (gameport->parent) gameport->parent->child = gameport; gameport->speed = use_ktime ? gameport_measure_speed(gameport) : old_gameport_measure_speed(gameport); list_add_tail(&gameport->node, &gameport_list); if (gameport->io) dev_info(&gameport->dev, "%s is %s, io %#x, speed %dkHz\n", gameport->name, gameport->phys, gameport->io, gameport->speed); else dev_info(&gameport->dev, "%s is %s, speed %dkHz\n", gameport->name, gameport->phys, gameport->speed); error = device_add(&gameport->dev); if (error) dev_err(&gameport->dev, "device_add() failed for %s (%s), error: %d\n", gameport->phys, gameport->name, error); } /* * gameport_destroy_port() completes deregistration process and removes * port from the system */ static void gameport_destroy_port(struct gameport *gameport) { struct gameport *child; child = gameport_get_pending_child(gameport); if (child) { gameport_remove_pending_events(child); put_device(&child->dev); } if (gameport->parent) { gameport->parent->child = NULL; gameport->parent = NULL; } if (device_is_registered(&gameport->dev)) device_del(&gameport->dev); list_del_init(&gameport->node); gameport_remove_pending_events(gameport); put_device(&gameport->dev); } /* * Reconnect gameport port and all its children (re-initialize attached devices) */ static void gameport_reconnect_port(struct gameport *gameport) { do { if (!gameport->drv || !gameport->drv->reconnect || gameport->drv->reconnect(gameport)) { gameport_disconnect_port(gameport); gameport_find_driver(gameport); /* Ok, old children are now gone, we are done */ break; } gameport = gameport->child; } while (gameport); } /* * gameport_disconnect_port() unbinds a port from its driver. As a side effect * all child ports are unbound and destroyed. */ static void gameport_disconnect_port(struct gameport *gameport) { struct gameport *s, *parent; if (gameport->child) { /* * Children ports should be disconnected and destroyed * first, staring with the leaf one, since we don't want * to do recursion */ for (s = gameport; s->child; s = s->child) /* empty */; do { parent = s->parent; device_release_driver(&s->dev); gameport_destroy_port(s); } while ((s = parent) != gameport); } /* * Ok, no children left, now disconnect this port */ device_release_driver(&gameport->dev); } /* * Submits register request to kgameportd for subsequent execution. * Note that port registration is always asynchronous. */ void __gameport_register_port(struct gameport *gameport, struct module *owner) { gameport_init_port(gameport); gameport_queue_event(gameport, owner, GAMEPORT_REGISTER_PORT); } EXPORT_SYMBOL(__gameport_register_port); /* * Synchronously unregisters gameport port. */ void gameport_unregister_port(struct gameport *gameport) { mutex_lock(&gameport_mutex); gameport_disconnect_port(gameport); gameport_destroy_port(gameport); mutex_unlock(&gameport_mutex); } EXPORT_SYMBOL(gameport_unregister_port); /* * Gameport driver operations */ static ssize_t description_show(struct device_driver *drv, char *buf) { struct gameport_driver *driver = to_gameport_driver(drv); return sprintf(buf, "%s\n", driver->description ? driver->description : "(none)"); } static DRIVER_ATTR_RO(description); static struct attribute *gameport_driver_attrs[] = { &driver_attr_description.attr, NULL }; ATTRIBUTE_GROUPS(gameport_driver); static int gameport_driver_probe(struct device *dev) { struct gameport *gameport = to_gameport_port(dev); struct gameport_driver *drv = to_gameport_driver(dev->driver); drv->connect(gameport, drv); return gameport->drv ? 0 : -ENODEV; } static int gameport_driver_remove(struct device *dev) { struct gameport *gameport = to_gameport_port(dev); struct gameport_driver *drv = to_gameport_driver(dev->driver); drv->disconnect(gameport); return 0; } static void gameport_attach_driver(struct gameport_driver *drv) { int error; error = driver_attach(&drv->driver); if (error) pr_err("driver_attach() failed for %s, error: %d\n", drv->driver.name, error); } int __gameport_register_driver(struct gameport_driver *drv, struct module *owner, const char *mod_name) { int error; drv->driver.bus = &gameport_bus; drv->driver.owner = owner; drv->driver.mod_name = mod_name; /* * Temporarily disable automatic binding because probing * takes long time and we are better off doing it in kgameportd */ drv->ignore = true; error = driver_register(&drv->driver); if (error) { pr_err("driver_register() failed for %s, error: %d\n", drv->driver.name, error); return error; } /* * Reset ignore flag and let kgameportd bind the driver to free ports */ drv->ignore = false; error = gameport_queue_event(drv, NULL, GAMEPORT_ATTACH_DRIVER); if (error) { driver_unregister(&drv->driver); return error; } return 0; } EXPORT_SYMBOL(__gameport_register_driver); void gameport_unregister_driver(struct gameport_driver *drv) { struct gameport *gameport; mutex_lock(&gameport_mutex); drv->ignore = true; /* so gameport_find_driver ignores it */ gameport_remove_pending_events(drv); start_over: list_for_each_entry(gameport, &gameport_list, node) { if (gameport->drv == drv) { gameport_disconnect_port(gameport); gameport_find_driver(gameport); /* we could've deleted some ports, restart */ goto start_over; } } driver_unregister(&drv->driver); mutex_unlock(&gameport_mutex); } EXPORT_SYMBOL(gameport_unregister_driver); static int gameport_bus_match(struct device *dev, struct device_driver *drv) { struct gameport_driver *gameport_drv = to_gameport_driver(drv); return !gameport_drv->ignore; } static struct bus_type gameport_bus = { .name = "gameport", .dev_groups = gameport_device_groups, .drv_groups = gameport_driver_groups, .match = gameport_bus_match, .probe = gameport_driver_probe, .remove = gameport_driver_remove, }; static void gameport_set_drv(struct gameport *gameport, struct gameport_driver *drv) { mutex_lock(&gameport->drv_mutex); gameport->drv = drv; mutex_unlock(&gameport->drv_mutex); } int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode) { if (gameport->open) { if (gameport->open(gameport, mode)) { return -1; } } else { if (mode != GAMEPORT_MODE_RAW) return -1; } gameport_set_drv(gameport, drv); return 0; } EXPORT_SYMBOL(gameport_open); void gameport_close(struct gameport *gameport) { del_timer_sync(&gameport->poll_timer); gameport->poll_handler = NULL; gameport->poll_interval = 0; gameport_set_drv(gameport, NULL); if (gameport->close) gameport->close(gameport); } EXPORT_SYMBOL(gameport_close); static int __init gameport_init(void) { int error; error = bus_register(&gameport_bus); if (error) { pr_err("failed to register gameport bus, error: %d\n", error); return error; } return 0; } static void __exit gameport_exit(void) { bus_unregister(&gameport_bus); /* * There should not be any outstanding events but work may * still be scheduled so simply cancel it. */ cancel_work_sync(&gameport_event_work); } subsys_initcall(gameport_init); module_exit(gameport_exit);
gpl-2.0
tcp209/kernel_samsung_epic4gtouch
arch/arm/mach-pxa/cm-x255.c
958
4936
/* * linux/arch/arm/mach-pxa/cm-x255.c * * Copyright (C) 2007, 2008 CompuLab, Ltd. * Mike Rapoport <mike@compulab.co.il> * * 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/platform_device.h> #include <linux/irq.h> #include <linux/gpio.h> #include <linux/mtd/partitions.h> #include <linux/mtd/physmap.h> #include <linux/mtd/nand-gpio.h> #include <linux/spi/spi.h> #include <asm/mach/arch.h> #include <asm/mach-types.h> #include <asm/mach/map.h> #include <mach/pxa25x.h> #include <mach/pxa2xx_spi.h> #include "generic.h" #define GPIO_NAND_CS (5) #define GPIO_NAND_ALE (4) #define GPIO_NAND_CLE (3) #define GPIO_NAND_RB (10) static unsigned long cmx255_pin_config[] = { /* AC'97 */ GPIO28_AC97_BITCLK, GPIO29_AC97_SDATA_IN_0, GPIO30_AC97_SDATA_OUT, GPIO31_AC97_SYNC, /* BTUART */ GPIO42_BTUART_RXD, GPIO43_BTUART_TXD, GPIO44_BTUART_CTS, GPIO45_BTUART_RTS, /* STUART */ GPIO46_STUART_RXD, GPIO47_STUART_TXD, /* LCD */ GPIOxx_LCD_TFT_16BPP, /* SSP1 */ GPIO23_SSP1_SCLK, GPIO24_SSP1_SFRM, GPIO25_SSP1_TXD, GPIO26_SSP1_RXD, /* SSP2 */ GPIO81_SSP2_CLK_OUT, GPIO82_SSP2_FRM_OUT, GPIO83_SSP2_TXD, GPIO84_SSP2_RXD, /* PC Card */ GPIO48_nPOE, GPIO49_nPWE, GPIO50_nPIOR, GPIO51_nPIOW, GPIO52_nPCE_1, GPIO53_nPCE_2, GPIO54_nPSKTSEL, GPIO55_nPREG, GPIO56_nPWAIT, GPIO57_nIOIS16, /* SDRAM and local bus */ GPIO15_nCS_1, GPIO78_nCS_2, GPIO79_nCS_3, GPIO80_nCS_4, GPIO33_nCS_5, GPIO18_RDY, /* GPIO */ GPIO0_GPIO | WAKEUP_ON_EDGE_BOTH, GPIO9_GPIO, /* PC card reset */ /* NAND controls */ GPIO5_GPIO | MFP_LPM_DRIVE_HIGH, /* NAND CE# */ GPIO4_GPIO | MFP_LPM_DRIVE_LOW, /* NAND ALE */ GPIO3_GPIO | MFP_LPM_DRIVE_LOW, /* NAND CLE */ GPIO10_GPIO, /* NAND Ready/Busy */ /* interrupts */ GPIO22_GPIO, /* DM9000 interrupt */ }; #if defined(CONFIG_SPI_PXA2XX) static struct pxa2xx_spi_master pxa_ssp_master_info = { .num_chipselect = 1, }; static struct spi_board_info spi_board_info[] __initdata = { [0] = { .modalias = "rtc-max6902", .max_speed_hz = 1000000, .bus_num = 1, .chip_select = 0, }, }; static void __init cmx255_init_rtc(void) { pxa2xx_set_spi_info(1, &pxa_ssp_master_info); spi_register_board_info(ARRAY_AND_SIZE(spi_board_info)); } #else static inline void cmx255_init_rtc(void) {} #endif #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE) static struct mtd_partition cmx255_nor_partitions[] = { { .name = "ARMmon", .size = 0x00030000, .offset = 0, .mask_flags = MTD_WRITEABLE /* force read-only */ } , { .name = "ARMmon setup block", .size = 0x00010000, .offset = MTDPART_OFS_APPEND, .mask_flags = MTD_WRITEABLE /* force read-only */ } , { .name = "kernel", .size = 0x00160000, .offset = MTDPART_OFS_APPEND, } , { .name = "ramdisk", .size = MTDPART_SIZ_FULL, .offset = MTDPART_OFS_APPEND } }; static struct physmap_flash_data cmx255_nor_flash_data[] = { { .width = 2, /* bankwidth in bytes */ .parts = cmx255_nor_partitions, .nr_parts = ARRAY_SIZE(cmx255_nor_partitions) } }; static struct resource cmx255_nor_resource = { .start = PXA_CS0_PHYS, .end = PXA_CS0_PHYS + SZ_8M - 1, .flags = IORESOURCE_MEM, }; static struct platform_device cmx255_nor = { .name = "physmap-flash", .id = -1, .dev = { .platform_data = cmx255_nor_flash_data, }, .resource = &cmx255_nor_resource, .num_resources = 1, }; static void __init cmx255_init_nor(void) { platform_device_register(&cmx255_nor); } #else static inline void cmx255_init_nor(void) {} #endif #if defined(CONFIG_MTD_NAND_GPIO) || defined(CONFIG_MTD_NAND_GPIO_MODULE) static struct resource cmx255_nand_resource[] = { [0] = { .start = PXA_CS1_PHYS, .end = PXA_CS1_PHYS + 11, .flags = IORESOURCE_MEM, }, [1] = { .start = PXA_CS5_PHYS, .end = PXA_CS5_PHYS + 3, .flags = IORESOURCE_MEM, }, }; static struct mtd_partition cmx255_nand_parts[] = { [0] = { .name = "cmx255-nand", .size = MTDPART_SIZ_FULL, .offset = 0, }, }; static struct gpio_nand_platdata cmx255_nand_platdata = { .gpio_nce = GPIO_NAND_CS, .gpio_cle = GPIO_NAND_CLE, .gpio_ale = GPIO_NAND_ALE, .gpio_rdy = GPIO_NAND_RB, .gpio_nwp = -1, .parts = cmx255_nand_parts, .num_parts = ARRAY_SIZE(cmx255_nand_parts), .chip_delay = 25, }; static struct platform_device cmx255_nand = { .name = "gpio-nand", .num_resources = ARRAY_SIZE(cmx255_nand_resource), .resource = cmx255_nand_resource, .id = -1, .dev = { .platform_data = &cmx255_nand_platdata, } }; static void __init cmx255_init_nand(void) { platform_device_register(&cmx255_nand); } #else static inline void cmx255_init_nand(void) {} #endif void __init cmx255_init(void) { pxa2xx_mfp_config(ARRAY_AND_SIZE(cmx255_pin_config)); cmx255_init_rtc(); cmx255_init_nor(); cmx255_init_nand(); }
gpl-2.0
haodongdong9999/vyos_kernel
fs/reiserfs/do_balan.c
1982
55567
/* * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README */ /* * Now we have all buffers that must be used in balancing of the tree * Further calculations can not cause schedule(), and thus the buffer * tree will be stable until the balancing will be finished * balance the tree according to the analysis made before, * and using buffers obtained after all above. */ #include <linux/uaccess.h> #include <linux/time.h> #include "reiserfs.h" #include <linux/buffer_head.h> #include <linux/kernel.h> static inline void buffer_info_init_left(struct tree_balance *tb, struct buffer_info *bi) { bi->tb = tb; bi->bi_bh = tb->L[0]; bi->bi_parent = tb->FL[0]; bi->bi_position = get_left_neighbor_position(tb, 0); } static inline void buffer_info_init_right(struct tree_balance *tb, struct buffer_info *bi) { bi->tb = tb; bi->bi_bh = tb->R[0]; bi->bi_parent = tb->FR[0]; bi->bi_position = get_right_neighbor_position(tb, 0); } static inline void buffer_info_init_tbS0(struct tree_balance *tb, struct buffer_info *bi) { bi->tb = tb; bi->bi_bh = PATH_PLAST_BUFFER(tb->tb_path); bi->bi_parent = PATH_H_PPARENT(tb->tb_path, 0); bi->bi_position = PATH_H_POSITION(tb->tb_path, 1); } static inline void buffer_info_init_bh(struct tree_balance *tb, struct buffer_info *bi, struct buffer_head *bh) { bi->tb = tb; bi->bi_bh = bh; bi->bi_parent = NULL; bi->bi_position = 0; } inline void do_balance_mark_leaf_dirty(struct tree_balance *tb, struct buffer_head *bh, int flag) { journal_mark_dirty(tb->transaction_handle, bh); } #define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty #define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty /* * summary: * if deleting something ( tb->insert_size[0] < 0 ) * return(balance_leaf_when_delete()); (flag d handled here) * else * if lnum is larger than 0 we put items into the left node * if rnum is larger than 0 we put items into the right node * if snum1 is larger than 0 we put items into the new node s1 * if snum2 is larger than 0 we put items into the new node s2 * Note that all *num* count new items being created. */ static void balance_leaf_when_delete_del(struct tree_balance *tb) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int item_pos = PATH_LAST_POSITION(tb->tb_path); struct buffer_info bi; #ifdef CONFIG_REISERFS_CHECK struct item_head *ih = item_head(tbS0, item_pos); #endif RFALSE(ih_item_len(ih) + IH_SIZE != -tb->insert_size[0], "vs-12013: mode Delete, insert size %d, ih to be deleted %h", -tb->insert_size[0], ih); buffer_info_init_tbS0(tb, &bi); leaf_delete_items(&bi, 0, item_pos, 1, -1); if (!item_pos && tb->CFL[0]) { if (B_NR_ITEMS(tbS0)) { replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0); } else { if (!PATH_H_POSITION(tb->tb_path, 1)) replace_key(tb, tb->CFL[0], tb->lkey[0], PATH_H_PPARENT(tb->tb_path, 0), 0); } } RFALSE(!item_pos && !tb->CFL[0], "PAP-12020: tb->CFL[0]==%p, tb->L[0]==%p", tb->CFL[0], tb->L[0]); } /* cut item in S[0] */ static void balance_leaf_when_delete_cut(struct tree_balance *tb) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int item_pos = PATH_LAST_POSITION(tb->tb_path); struct item_head *ih = item_head(tbS0, item_pos); int pos_in_item = tb->tb_path->pos_in_item; struct buffer_info bi; buffer_info_init_tbS0(tb, &bi); if (is_direntry_le_ih(ih)) { /* * UFS unlink semantics are such that you can only * delete one directory entry at a time. * * when we cut a directory tb->insert_size[0] means * number of entries to be cut (always 1) */ tb->insert_size[0] = -1; leaf_cut_from_buffer(&bi, item_pos, pos_in_item, -tb->insert_size[0]); RFALSE(!item_pos && !pos_in_item && !tb->CFL[0], "PAP-12030: can not change delimiting key. CFL[0]=%p", tb->CFL[0]); if (!item_pos && !pos_in_item && tb->CFL[0]) replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0); } else { leaf_cut_from_buffer(&bi, item_pos, pos_in_item, -tb->insert_size[0]); RFALSE(!ih_item_len(ih), "PAP-12035: cut must leave non-zero dynamic " "length of item"); } } static int balance_leaf_when_delete_left(struct tree_balance *tb) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int n = B_NR_ITEMS(tbS0); /* L[0] must be joined with S[0] */ if (tb->lnum[0] == -1) { /* R[0] must be also joined with S[0] */ if (tb->rnum[0] == -1) { if (tb->FR[0] == PATH_H_PPARENT(tb->tb_path, 0)) { /* * all contents of all the * 3 buffers will be in L[0] */ if (PATH_H_POSITION(tb->tb_path, 1) == 0 && 1 < B_NR_ITEMS(tb->FR[0])) replace_key(tb, tb->CFL[0], tb->lkey[0], tb->FR[0], 1); leaf_move_items(LEAF_FROM_S_TO_L, tb, n, -1, NULL); leaf_move_items(LEAF_FROM_R_TO_L, tb, B_NR_ITEMS(tb->R[0]), -1, NULL); reiserfs_invalidate_buffer(tb, tbS0); reiserfs_invalidate_buffer(tb, tb->R[0]); return 0; } /* all contents of all the 3 buffers will be in R[0] */ leaf_move_items(LEAF_FROM_S_TO_R, tb, n, -1, NULL); leaf_move_items(LEAF_FROM_L_TO_R, tb, B_NR_ITEMS(tb->L[0]), -1, NULL); /* right_delimiting_key is correct in R[0] */ replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0); reiserfs_invalidate_buffer(tb, tbS0); reiserfs_invalidate_buffer(tb, tb->L[0]); return -1; } RFALSE(tb->rnum[0] != 0, "PAP-12045: rnum must be 0 (%d)", tb->rnum[0]); /* all contents of L[0] and S[0] will be in L[0] */ leaf_shift_left(tb, n, -1); reiserfs_invalidate_buffer(tb, tbS0); return 0; } /* * a part of contents of S[0] will be in L[0] and * the rest part of S[0] will be in R[0] */ RFALSE((tb->lnum[0] + tb->rnum[0] < n) || (tb->lnum[0] + tb->rnum[0] > n + 1), "PAP-12050: rnum(%d) and lnum(%d) and item " "number(%d) in S[0] are not consistent", tb->rnum[0], tb->lnum[0], n); RFALSE((tb->lnum[0] + tb->rnum[0] == n) && (tb->lbytes != -1 || tb->rbytes != -1), "PAP-12055: bad rbytes (%d)/lbytes (%d) " "parameters when items are not split", tb->rbytes, tb->lbytes); RFALSE((tb->lnum[0] + tb->rnum[0] == n + 1) && (tb->lbytes < 1 || tb->rbytes != -1), "PAP-12060: bad rbytes (%d)/lbytes (%d) " "parameters when items are split", tb->rbytes, tb->lbytes); leaf_shift_left(tb, tb->lnum[0], tb->lbytes); leaf_shift_right(tb, tb->rnum[0], tb->rbytes); reiserfs_invalidate_buffer(tb, tbS0); return 0; } /* * Balance leaf node in case of delete or cut: insert_size[0] < 0 * * lnum, rnum can have values >= -1 * -1 means that the neighbor must be joined with S * 0 means that nothing should be done with the neighbor * >0 means to shift entirely or partly the specified number of items * to the neighbor */ static int balance_leaf_when_delete(struct tree_balance *tb, int flag) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int item_pos = PATH_LAST_POSITION(tb->tb_path); struct buffer_info bi; int n; struct item_head *ih; RFALSE(tb->FR[0] && B_LEVEL(tb->FR[0]) != DISK_LEAF_NODE_LEVEL + 1, "vs- 12000: level: wrong FR %z", tb->FR[0]); RFALSE(tb->blknum[0] > 1, "PAP-12005: tb->blknum == %d, can not be > 1", tb->blknum[0]); RFALSE(!tb->blknum[0] && !PATH_H_PPARENT(tb->tb_path, 0), "PAP-12010: tree can not be empty"); ih = item_head(tbS0, item_pos); buffer_info_init_tbS0(tb, &bi); /* Delete or truncate the item */ BUG_ON(flag != M_DELETE && flag != M_CUT); if (flag == M_DELETE) balance_leaf_when_delete_del(tb); else /* M_CUT */ balance_leaf_when_delete_cut(tb); /* * the rule is that no shifting occurs unless by shifting * a node can be freed */ n = B_NR_ITEMS(tbS0); /* L[0] takes part in balancing */ if (tb->lnum[0]) return balance_leaf_when_delete_left(tb); if (tb->rnum[0] == -1) { /* all contents of R[0] and S[0] will be in R[0] */ leaf_shift_right(tb, n, -1); reiserfs_invalidate_buffer(tb, tbS0); return 0; } RFALSE(tb->rnum[0], "PAP-12065: bad rnum parameter must be 0 (%d)", tb->rnum[0]); return 0; } static unsigned int balance_leaf_insert_left(struct tree_balance *tb, struct item_head *const ih, const char * const body) { int ret; struct buffer_info bi; int n = B_NR_ITEMS(tb->L[0]); unsigned body_shift_bytes = 0; if (tb->item_pos == tb->lnum[0] - 1 && tb->lbytes != -1) { /* part of new item falls into L[0] */ int new_item_len, shift; int version; ret = leaf_shift_left(tb, tb->lnum[0] - 1, -1); /* Calculate item length to insert to S[0] */ new_item_len = ih_item_len(ih) - tb->lbytes; /* Calculate and check item length to insert to L[0] */ put_ih_item_len(ih, ih_item_len(ih) - new_item_len); RFALSE(ih_item_len(ih) <= 0, "PAP-12080: there is nothing to insert into L[0]: " "ih_item_len=%d", ih_item_len(ih)); /* Insert new item into L[0] */ buffer_info_init_left(tb, &bi); leaf_insert_into_buf(&bi, n + tb->item_pos - ret, ih, body, min_t(int, tb->zeroes_num, ih_item_len(ih))); version = ih_version(ih); /* * Calculate key component, item length and body to * insert into S[0] */ shift = 0; if (is_indirect_le_ih(ih)) shift = tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT; add_le_ih_k_offset(ih, tb->lbytes << shift); put_ih_item_len(ih, new_item_len); if (tb->lbytes > tb->zeroes_num) { body_shift_bytes = tb->lbytes - tb->zeroes_num; tb->zeroes_num = 0; } else tb->zeroes_num -= tb->lbytes; RFALSE(ih_item_len(ih) <= 0, "PAP-12085: there is nothing to insert into S[0]: " "ih_item_len=%d", ih_item_len(ih)); } else { /* new item in whole falls into L[0] */ /* Shift lnum[0]-1 items to L[0] */ ret = leaf_shift_left(tb, tb->lnum[0] - 1, tb->lbytes); /* Insert new item into L[0] */ buffer_info_init_left(tb, &bi); leaf_insert_into_buf(&bi, n + tb->item_pos - ret, ih, body, tb->zeroes_num); tb->insert_size[0] = 0; tb->zeroes_num = 0; } return body_shift_bytes; } static void balance_leaf_paste_left_shift_dirent(struct tree_balance *tb, struct item_head * const ih, const char * const body) { int n = B_NR_ITEMS(tb->L[0]); struct buffer_info bi; RFALSE(tb->zeroes_num, "PAP-12090: invalid parameter in case of a directory"); /* directory item */ if (tb->lbytes > tb->pos_in_item) { /* new directory entry falls into L[0] */ struct item_head *pasted; int ret, l_pos_in_item = tb->pos_in_item; /* * Shift lnum[0] - 1 items in whole. * Shift lbytes - 1 entries from given directory item */ ret = leaf_shift_left(tb, tb->lnum[0], tb->lbytes - 1); if (ret && !tb->item_pos) { pasted = item_head(tb->L[0], B_NR_ITEMS(tb->L[0]) - 1); l_pos_in_item += ih_entry_count(pasted) - (tb->lbytes - 1); } /* Append given directory entry to directory item */ buffer_info_init_left(tb, &bi); leaf_paste_in_buffer(&bi, n + tb->item_pos - ret, l_pos_in_item, tb->insert_size[0], body, tb->zeroes_num); /* * previous string prepared space for pasting new entry, * following string pastes this entry */ /* * when we have merge directory item, pos_in_item * has been changed too */ /* paste new directory entry. 1 is entry number */ leaf_paste_entries(&bi, n + tb->item_pos - ret, l_pos_in_item, 1, (struct reiserfs_de_head *) body, body + DEH_SIZE, tb->insert_size[0]); tb->insert_size[0] = 0; } else { /* new directory item doesn't fall into L[0] */ /* * Shift lnum[0]-1 items in whole. Shift lbytes * directory entries from directory item number lnum[0] */ leaf_shift_left(tb, tb->lnum[0], tb->lbytes); } /* Calculate new position to append in item body */ tb->pos_in_item -= tb->lbytes; } static unsigned int balance_leaf_paste_left_shift(struct tree_balance *tb, struct item_head * const ih, const char * const body) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int n = B_NR_ITEMS(tb->L[0]); struct buffer_info bi; int body_shift_bytes = 0; if (is_direntry_le_ih(item_head(tbS0, tb->item_pos))) { balance_leaf_paste_left_shift_dirent(tb, ih, body); return 0; } RFALSE(tb->lbytes <= 0, "PAP-12095: there is nothing to shift to L[0]. " "lbytes=%d", tb->lbytes); RFALSE(tb->pos_in_item != ih_item_len(item_head(tbS0, tb->item_pos)), "PAP-12100: incorrect position to paste: " "item_len=%d, pos_in_item=%d", ih_item_len(item_head(tbS0, tb->item_pos)), tb->pos_in_item); /* appended item will be in L[0] in whole */ if (tb->lbytes >= tb->pos_in_item) { struct item_head *tbS0_pos_ih, *tbL0_ih; struct item_head *tbS0_0_ih; struct reiserfs_key *left_delim_key; int ret, l_n, version, temp_l; tbS0_pos_ih = item_head(tbS0, tb->item_pos); tbS0_0_ih = item_head(tbS0, 0); /* * this bytes number must be appended * to the last item of L[h] */ l_n = tb->lbytes - tb->pos_in_item; /* Calculate new insert_size[0] */ tb->insert_size[0] -= l_n; RFALSE(tb->insert_size[0] <= 0, "PAP-12105: there is nothing to paste into " "L[0]. insert_size=%d", tb->insert_size[0]); ret = leaf_shift_left(tb, tb->lnum[0], ih_item_len(tbS0_pos_ih)); tbL0_ih = item_head(tb->L[0], n + tb->item_pos - ret); /* Append to body of item in L[0] */ buffer_info_init_left(tb, &bi); leaf_paste_in_buffer(&bi, n + tb->item_pos - ret, ih_item_len(tbL0_ih), l_n, body, min_t(int, l_n, tb->zeroes_num)); /* * 0-th item in S0 can be only of DIRECT type * when l_n != 0 */ temp_l = l_n; RFALSE(ih_item_len(tbS0_0_ih), "PAP-12106: item length must be 0"); RFALSE(comp_short_le_keys(&tbS0_0_ih->ih_key, leaf_key(tb->L[0], n + tb->item_pos - ret)), "PAP-12107: items must be of the same file"); if (is_indirect_le_ih(tbL0_ih)) { int shift = tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT; temp_l = l_n << shift; } /* update key of first item in S0 */ version = ih_version(tbS0_0_ih); add_le_key_k_offset(version, &tbS0_0_ih->ih_key, temp_l); /* update left delimiting key */ left_delim_key = internal_key(tb->CFL[0], tb->lkey[0]); add_le_key_k_offset(version, left_delim_key, temp_l); /* * Calculate new body, position in item and * insert_size[0] */ if (l_n > tb->zeroes_num) { body_shift_bytes = l_n - tb->zeroes_num; tb->zeroes_num = 0; } else tb->zeroes_num -= l_n; tb->pos_in_item = 0; RFALSE(comp_short_le_keys(&tbS0_0_ih->ih_key, leaf_key(tb->L[0], B_NR_ITEMS(tb->L[0]) - 1)) || !op_is_left_mergeable(leaf_key(tbS0, 0), tbS0->b_size) || !op_is_left_mergeable(left_delim_key, tbS0->b_size), "PAP-12120: item must be merge-able with left " "neighboring item"); } else { /* only part of the appended item will be in L[0] */ /* Calculate position in item for append in S[0] */ tb->pos_in_item -= tb->lbytes; RFALSE(tb->pos_in_item <= 0, "PAP-12125: no place for paste. pos_in_item=%d", tb->pos_in_item); /* * Shift lnum[0] - 1 items in whole. * Shift lbytes - 1 byte from item number lnum[0] */ leaf_shift_left(tb, tb->lnum[0], tb->lbytes); } return body_shift_bytes; } /* appended item will be in L[0] in whole */ static void balance_leaf_paste_left_whole(struct tree_balance *tb, struct item_head * const ih, const char * const body) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int n = B_NR_ITEMS(tb->L[0]); struct buffer_info bi; struct item_head *pasted; int ret; /* if we paste into first item of S[0] and it is left mergable */ if (!tb->item_pos && op_is_left_mergeable(leaf_key(tbS0, 0), tbS0->b_size)) { /* * then increment pos_in_item by the size of the * last item in L[0] */ pasted = item_head(tb->L[0], n - 1); if (is_direntry_le_ih(pasted)) tb->pos_in_item += ih_entry_count(pasted); else tb->pos_in_item += ih_item_len(pasted); } /* * Shift lnum[0] - 1 items in whole. * Shift lbytes - 1 byte from item number lnum[0] */ ret = leaf_shift_left(tb, tb->lnum[0], tb->lbytes); /* Append to body of item in L[0] */ buffer_info_init_left(tb, &bi); leaf_paste_in_buffer(&bi, n + tb->item_pos - ret, tb->pos_in_item, tb->insert_size[0], body, tb->zeroes_num); /* if appended item is directory, paste entry */ pasted = item_head(tb->L[0], n + tb->item_pos - ret); if (is_direntry_le_ih(pasted)) leaf_paste_entries(&bi, n + tb->item_pos - ret, tb->pos_in_item, 1, (struct reiserfs_de_head *)body, body + DEH_SIZE, tb->insert_size[0]); /* * if appended item is indirect item, put unformatted node * into un list */ if (is_indirect_le_ih(pasted)) set_ih_free_space(pasted, 0); tb->insert_size[0] = 0; tb->zeroes_num = 0; } static unsigned int balance_leaf_paste_left(struct tree_balance *tb, struct item_head * const ih, const char * const body) { /* we must shift the part of the appended item */ if (tb->item_pos == tb->lnum[0] - 1 && tb->lbytes != -1) return balance_leaf_paste_left_shift(tb, ih, body); else balance_leaf_paste_left_whole(tb, ih, body); return 0; } /* Shift lnum[0] items from S[0] to the left neighbor L[0] */ static unsigned int balance_leaf_left(struct tree_balance *tb, struct item_head * const ih, const char * const body, int flag) { if (tb->lnum[0] <= 0) return 0; /* new item or it part falls to L[0], shift it too */ if (tb->item_pos < tb->lnum[0]) { BUG_ON(flag != M_INSERT && flag != M_PASTE); if (flag == M_INSERT) return balance_leaf_insert_left(tb, ih, body); else /* M_PASTE */ return balance_leaf_paste_left(tb, ih, body); } else /* new item doesn't fall into L[0] */ leaf_shift_left(tb, tb->lnum[0], tb->lbytes); return 0; } static void balance_leaf_insert_right(struct tree_balance *tb, struct item_head * const ih, const char * const body) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int n = B_NR_ITEMS(tbS0); struct buffer_info bi; int ret; /* new item or part of it doesn't fall into R[0] */ if (n - tb->rnum[0] >= tb->item_pos) { leaf_shift_right(tb, tb->rnum[0], tb->rbytes); return; } /* new item or its part falls to R[0] */ /* part of new item falls into R[0] */ if (tb->item_pos == n - tb->rnum[0] + 1 && tb->rbytes != -1) { loff_t old_key_comp, old_len, r_zeroes_number; const char *r_body; int version, shift; loff_t offset; leaf_shift_right(tb, tb->rnum[0] - 1, -1); version = ih_version(ih); /* Remember key component and item length */ old_key_comp = le_ih_k_offset(ih); old_len = ih_item_len(ih); /* * Calculate key component and item length to insert * into R[0] */ shift = 0; if (is_indirect_le_ih(ih)) shift = tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT; offset = le_ih_k_offset(ih) + ((old_len - tb->rbytes) << shift); set_le_ih_k_offset(ih, offset); put_ih_item_len(ih, tb->rbytes); /* Insert part of the item into R[0] */ buffer_info_init_right(tb, &bi); if ((old_len - tb->rbytes) > tb->zeroes_num) { r_zeroes_number = 0; r_body = body + (old_len - tb->rbytes) - tb->zeroes_num; } else { r_body = body; r_zeroes_number = tb->zeroes_num - (old_len - tb->rbytes); tb->zeroes_num -= r_zeroes_number; } leaf_insert_into_buf(&bi, 0, ih, r_body, r_zeroes_number); /* Replace right delimiting key by first key in R[0] */ replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0); /* * Calculate key component and item length to * insert into S[0] */ set_le_ih_k_offset(ih, old_key_comp); put_ih_item_len(ih, old_len - tb->rbytes); tb->insert_size[0] -= tb->rbytes; } else { /* whole new item falls into R[0] */ /* Shift rnum[0]-1 items to R[0] */ ret = leaf_shift_right(tb, tb->rnum[0] - 1, tb->rbytes); /* Insert new item into R[0] */ buffer_info_init_right(tb, &bi); leaf_insert_into_buf(&bi, tb->item_pos - n + tb->rnum[0] - 1, ih, body, tb->zeroes_num); if (tb->item_pos - n + tb->rnum[0] - 1 == 0) replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0); tb->zeroes_num = tb->insert_size[0] = 0; } } static void balance_leaf_paste_right_shift_dirent(struct tree_balance *tb, struct item_head * const ih, const char * const body) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); struct buffer_info bi; int entry_count; RFALSE(tb->zeroes_num, "PAP-12145: invalid parameter in case of a directory"); entry_count = ih_entry_count(item_head(tbS0, tb->item_pos)); /* new directory entry falls into R[0] */ if (entry_count - tb->rbytes < tb->pos_in_item) { int paste_entry_position; RFALSE(tb->rbytes - 1 >= entry_count || !tb->insert_size[0], "PAP-12150: no enough of entries to shift to R[0]: " "rbytes=%d, entry_count=%d", tb->rbytes, entry_count); /* * Shift rnum[0]-1 items in whole. * Shift rbytes-1 directory entries from directory * item number rnum[0] */ leaf_shift_right(tb, tb->rnum[0], tb->rbytes - 1); /* Paste given directory entry to directory item */ paste_entry_position = tb->pos_in_item - entry_count + tb->rbytes - 1; buffer_info_init_right(tb, &bi); leaf_paste_in_buffer(&bi, 0, paste_entry_position, tb->insert_size[0], body, tb->zeroes_num); /* paste entry */ leaf_paste_entries(&bi, 0, paste_entry_position, 1, (struct reiserfs_de_head *) body, body + DEH_SIZE, tb->insert_size[0]); /* change delimiting keys */ if (paste_entry_position == 0) replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0); tb->insert_size[0] = 0; tb->pos_in_item++; } else { /* new directory entry doesn't fall into R[0] */ leaf_shift_right(tb, tb->rnum[0], tb->rbytes); } } static void balance_leaf_paste_right_shift(struct tree_balance *tb, struct item_head * const ih, const char * const body) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int n_shift, n_rem, r_zeroes_number, version; unsigned long temp_rem; const char *r_body; struct buffer_info bi; /* we append to directory item */ if (is_direntry_le_ih(item_head(tbS0, tb->item_pos))) { balance_leaf_paste_right_shift_dirent(tb, ih, body); return; } /* regular object */ /* * Calculate number of bytes which must be shifted * from appended item */ n_shift = tb->rbytes - tb->insert_size[0]; if (n_shift < 0) n_shift = 0; RFALSE(tb->pos_in_item != ih_item_len(item_head(tbS0, tb->item_pos)), "PAP-12155: invalid position to paste. ih_item_len=%d, " "pos_in_item=%d", tb->pos_in_item, ih_item_len(item_head(tbS0, tb->item_pos))); leaf_shift_right(tb, tb->rnum[0], n_shift); /* * Calculate number of bytes which must remain in body * after appending to R[0] */ n_rem = tb->insert_size[0] - tb->rbytes; if (n_rem < 0) n_rem = 0; temp_rem = n_rem; version = ih_version(item_head(tb->R[0], 0)); if (is_indirect_le_key(version, leaf_key(tb->R[0], 0))) { int shift = tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT; temp_rem = n_rem << shift; } add_le_key_k_offset(version, leaf_key(tb->R[0], 0), temp_rem); add_le_key_k_offset(version, internal_key(tb->CFR[0], tb->rkey[0]), temp_rem); do_balance_mark_internal_dirty(tb, tb->CFR[0], 0); /* Append part of body into R[0] */ buffer_info_init_right(tb, &bi); if (n_rem > tb->zeroes_num) { r_zeroes_number = 0; r_body = body + n_rem - tb->zeroes_num; } else { r_body = body; r_zeroes_number = tb->zeroes_num - n_rem; tb->zeroes_num -= r_zeroes_number; } leaf_paste_in_buffer(&bi, 0, n_shift, tb->insert_size[0] - n_rem, r_body, r_zeroes_number); if (is_indirect_le_ih(item_head(tb->R[0], 0))) set_ih_free_space(item_head(tb->R[0], 0), 0); tb->insert_size[0] = n_rem; if (!n_rem) tb->pos_in_item++; } static void balance_leaf_paste_right_whole(struct tree_balance *tb, struct item_head * const ih, const char * const body) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int n = B_NR_ITEMS(tbS0); struct item_head *pasted; struct buffer_info bi; buffer_info_init_right(tb, &bi); leaf_shift_right(tb, tb->rnum[0], tb->rbytes); /* append item in R[0] */ if (tb->pos_in_item >= 0) { buffer_info_init_right(tb, &bi); leaf_paste_in_buffer(&bi, tb->item_pos - n + tb->rnum[0], tb->pos_in_item, tb->insert_size[0], body, tb->zeroes_num); } /* paste new entry, if item is directory item */ pasted = item_head(tb->R[0], tb->item_pos - n + tb->rnum[0]); if (is_direntry_le_ih(pasted) && tb->pos_in_item >= 0) { leaf_paste_entries(&bi, tb->item_pos - n + tb->rnum[0], tb->pos_in_item, 1, (struct reiserfs_de_head *)body, body + DEH_SIZE, tb->insert_size[0]); if (!tb->pos_in_item) { RFALSE(tb->item_pos - n + tb->rnum[0], "PAP-12165: directory item must be first " "item of node when pasting is in 0th position"); /* update delimiting keys */ replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0); } } if (is_indirect_le_ih(pasted)) set_ih_free_space(pasted, 0); tb->zeroes_num = tb->insert_size[0] = 0; } static void balance_leaf_paste_right(struct tree_balance *tb, struct item_head * const ih, const char * const body) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int n = B_NR_ITEMS(tbS0); /* new item doesn't fall into R[0] */ if (n - tb->rnum[0] > tb->item_pos) { leaf_shift_right(tb, tb->rnum[0], tb->rbytes); return; } /* pasted item or part of it falls to R[0] */ if (tb->item_pos == n - tb->rnum[0] && tb->rbytes != -1) /* we must shift the part of the appended item */ balance_leaf_paste_right_shift(tb, ih, body); else /* pasted item in whole falls into R[0] */ balance_leaf_paste_right_whole(tb, ih, body); } /* shift rnum[0] items from S[0] to the right neighbor R[0] */ static void balance_leaf_right(struct tree_balance *tb, struct item_head * const ih, const char * const body, int flag) { if (tb->rnum[0] <= 0) return; BUG_ON(flag != M_INSERT && flag != M_PASTE); if (flag == M_INSERT) balance_leaf_insert_right(tb, ih, body); else /* M_PASTE */ balance_leaf_paste_right(tb, ih, body); } static void balance_leaf_new_nodes_insert(struct tree_balance *tb, struct item_head * const ih, const char * const body, struct item_head *insert_key, struct buffer_head **insert_ptr, int i) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int n = B_NR_ITEMS(tbS0); struct buffer_info bi; int shift; /* new item or it part don't falls into S_new[i] */ if (n - tb->snum[i] >= tb->item_pos) { leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, tb->snum[i], tb->sbytes[i], tb->S_new[i]); return; } /* new item or it's part falls to first new node S_new[i] */ /* part of new item falls into S_new[i] */ if (tb->item_pos == n - tb->snum[i] + 1 && tb->sbytes[i] != -1) { int old_key_comp, old_len, r_zeroes_number; const char *r_body; int version; /* Move snum[i]-1 items from S[0] to S_new[i] */ leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, tb->snum[i] - 1, -1, tb->S_new[i]); /* Remember key component and item length */ version = ih_version(ih); old_key_comp = le_ih_k_offset(ih); old_len = ih_item_len(ih); /* * Calculate key component and item length to insert * into S_new[i] */ shift = 0; if (is_indirect_le_ih(ih)) shift = tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT; set_le_ih_k_offset(ih, le_ih_k_offset(ih) + ((old_len - tb->sbytes[i]) << shift)); put_ih_item_len(ih, tb->sbytes[i]); /* Insert part of the item into S_new[i] before 0-th item */ buffer_info_init_bh(tb, &bi, tb->S_new[i]); if ((old_len - tb->sbytes[i]) > tb->zeroes_num) { r_zeroes_number = 0; r_body = body + (old_len - tb->sbytes[i]) - tb->zeroes_num; } else { r_body = body; r_zeroes_number = tb->zeroes_num - (old_len - tb->sbytes[i]); tb->zeroes_num -= r_zeroes_number; } leaf_insert_into_buf(&bi, 0, ih, r_body, r_zeroes_number); /* * Calculate key component and item length to * insert into S[i] */ set_le_ih_k_offset(ih, old_key_comp); put_ih_item_len(ih, old_len - tb->sbytes[i]); tb->insert_size[0] -= tb->sbytes[i]; } else { /* whole new item falls into S_new[i] */ /* * Shift snum[0] - 1 items to S_new[i] * (sbytes[i] of split item) */ leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, tb->snum[i] - 1, tb->sbytes[i], tb->S_new[i]); /* Insert new item into S_new[i] */ buffer_info_init_bh(tb, &bi, tb->S_new[i]); leaf_insert_into_buf(&bi, tb->item_pos - n + tb->snum[i] - 1, ih, body, tb->zeroes_num); tb->zeroes_num = tb->insert_size[0] = 0; } } /* we append to directory item */ static void balance_leaf_new_nodes_paste_dirent(struct tree_balance *tb, struct item_head * const ih, const char * const body, struct item_head *insert_key, struct buffer_head **insert_ptr, int i) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); struct item_head *aux_ih = item_head(tbS0, tb->item_pos); int entry_count = ih_entry_count(aux_ih); struct buffer_info bi; if (entry_count - tb->sbytes[i] < tb->pos_in_item && tb->pos_in_item <= entry_count) { /* new directory entry falls into S_new[i] */ RFALSE(!tb->insert_size[0], "PAP-12215: insert_size is already 0"); RFALSE(tb->sbytes[i] - 1 >= entry_count, "PAP-12220: there are no so much entries (%d), only %d", tb->sbytes[i] - 1, entry_count); /* * Shift snum[i]-1 items in whole. * Shift sbytes[i] directory entries * from directory item number snum[i] */ leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, tb->snum[i], tb->sbytes[i] - 1, tb->S_new[i]); /* * Paste given directory entry to * directory item */ buffer_info_init_bh(tb, &bi, tb->S_new[i]); leaf_paste_in_buffer(&bi, 0, tb->pos_in_item - entry_count + tb->sbytes[i] - 1, tb->insert_size[0], body, tb->zeroes_num); /* paste new directory entry */ leaf_paste_entries(&bi, 0, tb->pos_in_item - entry_count + tb->sbytes[i] - 1, 1, (struct reiserfs_de_head *) body, body + DEH_SIZE, tb->insert_size[0]); tb->insert_size[0] = 0; tb->pos_in_item++; } else { /* new directory entry doesn't fall into S_new[i] */ leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, tb->snum[i], tb->sbytes[i], tb->S_new[i]); } } static void balance_leaf_new_nodes_paste_shift(struct tree_balance *tb, struct item_head * const ih, const char * const body, struct item_head *insert_key, struct buffer_head **insert_ptr, int i) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); struct item_head *aux_ih = item_head(tbS0, tb->item_pos); int n_shift, n_rem, r_zeroes_number, shift; const char *r_body; struct item_head *tmp; struct buffer_info bi; RFALSE(ih, "PAP-12210: ih must be 0"); if (is_direntry_le_ih(aux_ih)) { balance_leaf_new_nodes_paste_dirent(tb, ih, body, insert_key, insert_ptr, i); return; } /* regular object */ RFALSE(tb->pos_in_item != ih_item_len(item_head(tbS0, tb->item_pos)) || tb->insert_size[0] <= 0, "PAP-12225: item too short or insert_size <= 0"); /* * Calculate number of bytes which must be shifted from appended item */ n_shift = tb->sbytes[i] - tb->insert_size[0]; if (n_shift < 0) n_shift = 0; leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, tb->snum[i], n_shift, tb->S_new[i]); /* * Calculate number of bytes which must remain in body after * append to S_new[i] */ n_rem = tb->insert_size[0] - tb->sbytes[i]; if (n_rem < 0) n_rem = 0; /* Append part of body into S_new[0] */ buffer_info_init_bh(tb, &bi, tb->S_new[i]); if (n_rem > tb->zeroes_num) { r_zeroes_number = 0; r_body = body + n_rem - tb->zeroes_num; } else { r_body = body; r_zeroes_number = tb->zeroes_num - n_rem; tb->zeroes_num -= r_zeroes_number; } leaf_paste_in_buffer(&bi, 0, n_shift, tb->insert_size[0] - n_rem, r_body, r_zeroes_number); tmp = item_head(tb->S_new[i], 0); shift = 0; if (is_indirect_le_ih(tmp)) { set_ih_free_space(tmp, 0); shift = tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT; } add_le_ih_k_offset(tmp, n_rem << shift); tb->insert_size[0] = n_rem; if (!n_rem) tb->pos_in_item++; } static void balance_leaf_new_nodes_paste_whole(struct tree_balance *tb, struct item_head * const ih, const char * const body, struct item_head *insert_key, struct buffer_head **insert_ptr, int i) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int n = B_NR_ITEMS(tbS0); int leaf_mi; struct item_head *pasted; struct buffer_info bi; #ifdef CONFIG_REISERFS_CHECK struct item_head *ih_check = item_head(tbS0, tb->item_pos); if (!is_direntry_le_ih(ih_check) && (tb->pos_in_item != ih_item_len(ih_check) || tb->insert_size[0] <= 0)) reiserfs_panic(tb->tb_sb, "PAP-12235", "pos_in_item must be equal to ih_item_len"); #endif leaf_mi = leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, tb->snum[i], tb->sbytes[i], tb->S_new[i]); RFALSE(leaf_mi, "PAP-12240: unexpected value returned by leaf_move_items (%d)", leaf_mi); /* paste into item */ buffer_info_init_bh(tb, &bi, tb->S_new[i]); leaf_paste_in_buffer(&bi, tb->item_pos - n + tb->snum[i], tb->pos_in_item, tb->insert_size[0], body, tb->zeroes_num); pasted = item_head(tb->S_new[i], tb->item_pos - n + tb->snum[i]); if (is_direntry_le_ih(pasted)) leaf_paste_entries(&bi, tb->item_pos - n + tb->snum[i], tb->pos_in_item, 1, (struct reiserfs_de_head *)body, body + DEH_SIZE, tb->insert_size[0]); /* if we paste to indirect item update ih_free_space */ if (is_indirect_le_ih(pasted)) set_ih_free_space(pasted, 0); tb->zeroes_num = tb->insert_size[0] = 0; } static void balance_leaf_new_nodes_paste(struct tree_balance *tb, struct item_head * const ih, const char * const body, struct item_head *insert_key, struct buffer_head **insert_ptr, int i) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); int n = B_NR_ITEMS(tbS0); /* pasted item doesn't fall into S_new[i] */ if (n - tb->snum[i] > tb->item_pos) { leaf_move_items(LEAF_FROM_S_TO_SNEW, tb, tb->snum[i], tb->sbytes[i], tb->S_new[i]); return; } /* pasted item or part if it falls to S_new[i] */ if (tb->item_pos == n - tb->snum[i] && tb->sbytes[i] != -1) /* we must shift part of the appended item */ balance_leaf_new_nodes_paste_shift(tb, ih, body, insert_key, insert_ptr, i); else /* item falls wholly into S_new[i] */ balance_leaf_new_nodes_paste_whole(tb, ih, body, insert_key, insert_ptr, i); } /* Fill new nodes that appear in place of S[0] */ static void balance_leaf_new_nodes(struct tree_balance *tb, struct item_head * const ih, const char * const body, struct item_head *insert_key, struct buffer_head **insert_ptr, int flag) { int i; for (i = tb->blknum[0] - 2; i >= 0; i--) { BUG_ON(flag != M_INSERT && flag != M_PASTE); RFALSE(!tb->snum[i], "PAP-12200: snum[%d] == %d. Must be > 0", i, tb->snum[i]); /* here we shift from S to S_new nodes */ tb->S_new[i] = get_FEB(tb); /* initialized block type and tree level */ set_blkh_level(B_BLK_HEAD(tb->S_new[i]), DISK_LEAF_NODE_LEVEL); if (flag == M_INSERT) balance_leaf_new_nodes_insert(tb, ih, body, insert_key, insert_ptr, i); else /* M_PASTE */ balance_leaf_new_nodes_paste(tb, ih, body, insert_key, insert_ptr, i); memcpy(insert_key + i, leaf_key(tb->S_new[i], 0), KEY_SIZE); insert_ptr[i] = tb->S_new[i]; RFALSE(!buffer_journaled(tb->S_new[i]) || buffer_journal_dirty(tb->S_new[i]) || buffer_dirty(tb->S_new[i]), "PAP-12247: S_new[%d] : (%b)", i, tb->S_new[i]); } } static void balance_leaf_finish_node_insert(struct tree_balance *tb, struct item_head * const ih, const char * const body) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); struct buffer_info bi; buffer_info_init_tbS0(tb, &bi); leaf_insert_into_buf(&bi, tb->item_pos, ih, body, tb->zeroes_num); /* If we insert the first key change the delimiting key */ if (tb->item_pos == 0) { if (tb->CFL[0]) /* can be 0 in reiserfsck */ replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0); } } static void balance_leaf_finish_node_paste_dirent(struct tree_balance *tb, struct item_head * const ih, const char * const body) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); struct item_head *pasted = item_head(tbS0, tb->item_pos); struct buffer_info bi; if (tb->pos_in_item >= 0 && tb->pos_in_item <= ih_entry_count(pasted)) { RFALSE(!tb->insert_size[0], "PAP-12260: insert_size is 0 already"); /* prepare space */ buffer_info_init_tbS0(tb, &bi); leaf_paste_in_buffer(&bi, tb->item_pos, tb->pos_in_item, tb->insert_size[0], body, tb->zeroes_num); /* paste entry */ leaf_paste_entries(&bi, tb->item_pos, tb->pos_in_item, 1, (struct reiserfs_de_head *)body, body + DEH_SIZE, tb->insert_size[0]); if (!tb->item_pos && !tb->pos_in_item) { RFALSE(!tb->CFL[0] || !tb->L[0], "PAP-12270: CFL[0]/L[0] must be specified"); if (tb->CFL[0]) replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0); } tb->insert_size[0] = 0; } } static void balance_leaf_finish_node_paste(struct tree_balance *tb, struct item_head * const ih, const char * const body) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); struct buffer_info bi; struct item_head *pasted = item_head(tbS0, tb->item_pos); /* when directory, may be new entry already pasted */ if (is_direntry_le_ih(pasted)) { balance_leaf_finish_node_paste_dirent(tb, ih, body); return; } /* regular object */ if (tb->pos_in_item == ih_item_len(pasted)) { RFALSE(tb->insert_size[0] <= 0, "PAP-12275: insert size must not be %d", tb->insert_size[0]); buffer_info_init_tbS0(tb, &bi); leaf_paste_in_buffer(&bi, tb->item_pos, tb->pos_in_item, tb->insert_size[0], body, tb->zeroes_num); if (is_indirect_le_ih(pasted)) set_ih_free_space(pasted, 0); tb->insert_size[0] = 0; } #ifdef CONFIG_REISERFS_CHECK else if (tb->insert_size[0]) { print_cur_tb("12285"); reiserfs_panic(tb->tb_sb, "PAP-12285", "insert_size must be 0 (%d)", tb->insert_size[0]); } #endif } /* * if the affected item was not wholly shifted then we * perform all necessary operations on that part or whole * of the affected item which remains in S */ static void balance_leaf_finish_node(struct tree_balance *tb, struct item_head * const ih, const char * const body, int flag) { /* if we must insert or append into buffer S[0] */ if (0 <= tb->item_pos && tb->item_pos < tb->s0num) { if (flag == M_INSERT) balance_leaf_finish_node_insert(tb, ih, body); else /* M_PASTE */ balance_leaf_finish_node_paste(tb, ih, body); } } /** * balance_leaf - reiserfs tree balancing algorithm * @tb: tree balance state * @ih: item header of inserted item (little endian) * @body: body of inserted item or bytes to paste * @flag: i - insert, d - delete, c - cut, p - paste (see do_balance) * passed back: * @insert_key: key to insert new nodes * @insert_ptr: array of nodes to insert at the next level * * In our processing of one level we sometimes determine what must be * inserted into the next higher level. This insertion consists of a * key or two keys and their corresponding pointers. */ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, const char *body, int flag, struct item_head *insert_key, struct buffer_head **insert_ptr) { struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); PROC_INFO_INC(tb->tb_sb, balance_at[0]); /* Make balance in case insert_size[0] < 0 */ if (tb->insert_size[0] < 0) return balance_leaf_when_delete(tb, flag); tb->item_pos = PATH_LAST_POSITION(tb->tb_path), tb->pos_in_item = tb->tb_path->pos_in_item, tb->zeroes_num = 0; if (flag == M_INSERT && !body) tb->zeroes_num = ih_item_len(ih); /* * for indirect item pos_in_item is measured in unformatted node * pointers. Recalculate to bytes */ if (flag != M_INSERT && is_indirect_le_ih(item_head(tbS0, tb->item_pos))) tb->pos_in_item *= UNFM_P_SIZE; body += balance_leaf_left(tb, ih, body, flag); /* tb->lnum[0] > 0 */ /* Calculate new item position */ tb->item_pos -= (tb->lnum[0] - ((tb->lbytes != -1) ? 1 : 0)); balance_leaf_right(tb, ih, body, flag); /* tb->rnum[0] > 0 */ RFALSE(tb->blknum[0] > 3, "PAP-12180: blknum can not be %d. It must be <= 3", tb->blknum[0]); RFALSE(tb->blknum[0] < 0, "PAP-12185: blknum can not be %d. It must be >= 0", tb->blknum[0]); /* * if while adding to a node we discover that it is possible to split * it in two, and merge the left part into the left neighbor and the * right part into the right neighbor, eliminating the node */ if (tb->blknum[0] == 0) { /* node S[0] is empty now */ RFALSE(!tb->lnum[0] || !tb->rnum[0], "PAP-12190: lnum and rnum must not be zero"); /* * if insertion was done before 0-th position in R[0], right * delimiting key of the tb->L[0]'s and left delimiting key are * not set correctly */ if (tb->CFL[0]) { if (!tb->CFR[0]) reiserfs_panic(tb->tb_sb, "vs-12195", "CFR not initialized"); copy_key(internal_key(tb->CFL[0], tb->lkey[0]), internal_key(tb->CFR[0], tb->rkey[0])); do_balance_mark_internal_dirty(tb, tb->CFL[0], 0); } reiserfs_invalidate_buffer(tb, tbS0); return 0; } balance_leaf_new_nodes(tb, ih, body, insert_key, insert_ptr, flag); balance_leaf_finish_node(tb, ih, body, flag); #ifdef CONFIG_REISERFS_CHECK if (flag == M_PASTE && tb->insert_size[0]) { print_cur_tb("12290"); reiserfs_panic(tb->tb_sb, "PAP-12290", "insert_size is still not 0 (%d)", tb->insert_size[0]); } #endif /* Leaf level of the tree is balanced (end of balance_leaf) */ return 0; } /* Make empty node */ void make_empty_node(struct buffer_info *bi) { struct block_head *blkh; RFALSE(bi->bi_bh == NULL, "PAP-12295: pointer to the buffer is NULL"); blkh = B_BLK_HEAD(bi->bi_bh); set_blkh_nr_item(blkh, 0); set_blkh_free_space(blkh, MAX_CHILD_SIZE(bi->bi_bh)); if (bi->bi_parent) B_N_CHILD(bi->bi_parent, bi->bi_position)->dc_size = 0; /* Endian safe if 0 */ } /* Get first empty buffer */ struct buffer_head *get_FEB(struct tree_balance *tb) { int i; struct buffer_info bi; for (i = 0; i < MAX_FEB_SIZE; i++) if (tb->FEB[i] != NULL) break; if (i == MAX_FEB_SIZE) reiserfs_panic(tb->tb_sb, "vs-12300", "FEB list is empty"); buffer_info_init_bh(tb, &bi, tb->FEB[i]); make_empty_node(&bi); set_buffer_uptodate(tb->FEB[i]); tb->used[i] = tb->FEB[i]; tb->FEB[i] = NULL; return tb->used[i]; } /* This is now used because reiserfs_free_block has to be able to schedule. */ static void store_thrown(struct tree_balance *tb, struct buffer_head *bh) { int i; if (buffer_dirty(bh)) reiserfs_warning(tb->tb_sb, "reiserfs-12320", "called with dirty buffer"); for (i = 0; i < ARRAY_SIZE(tb->thrown); i++) if (!tb->thrown[i]) { tb->thrown[i] = bh; get_bh(bh); /* free_thrown puts this */ return; } reiserfs_warning(tb->tb_sb, "reiserfs-12321", "too many thrown buffers"); } static void free_thrown(struct tree_balance *tb) { int i; b_blocknr_t blocknr; for (i = 0; i < ARRAY_SIZE(tb->thrown); i++) { if (tb->thrown[i]) { blocknr = tb->thrown[i]->b_blocknr; if (buffer_dirty(tb->thrown[i])) reiserfs_warning(tb->tb_sb, "reiserfs-12322", "called with dirty buffer %d", blocknr); brelse(tb->thrown[i]); /* incremented in store_thrown */ reiserfs_free_block(tb->transaction_handle, NULL, blocknr, 0); } } } void reiserfs_invalidate_buffer(struct tree_balance *tb, struct buffer_head *bh) { struct block_head *blkh; blkh = B_BLK_HEAD(bh); set_blkh_level(blkh, FREE_LEVEL); set_blkh_nr_item(blkh, 0); clear_buffer_dirty(bh); store_thrown(tb, bh); } /* Replace n_dest'th key in buffer dest by n_src'th key of buffer src.*/ void replace_key(struct tree_balance *tb, struct buffer_head *dest, int n_dest, struct buffer_head *src, int n_src) { RFALSE(dest == NULL || src == NULL, "vs-12305: source or destination buffer is 0 (src=%p, dest=%p)", src, dest); RFALSE(!B_IS_KEYS_LEVEL(dest), "vs-12310: invalid level (%z) for destination buffer. dest must be leaf", dest); RFALSE(n_dest < 0 || n_src < 0, "vs-12315: src(%d) or dest(%d) key number < 0", n_src, n_dest); RFALSE(n_dest >= B_NR_ITEMS(dest) || n_src >= B_NR_ITEMS(src), "vs-12320: src(%d(%d)) or dest(%d(%d)) key number is too big", n_src, B_NR_ITEMS(src), n_dest, B_NR_ITEMS(dest)); if (B_IS_ITEMS_LEVEL(src)) /* source buffer contains leaf node */ memcpy(internal_key(dest, n_dest), item_head(src, n_src), KEY_SIZE); else memcpy(internal_key(dest, n_dest), internal_key(src, n_src), KEY_SIZE); do_balance_mark_internal_dirty(tb, dest, 0); } int get_left_neighbor_position(struct tree_balance *tb, int h) { int Sh_position = PATH_H_POSITION(tb->tb_path, h + 1); RFALSE(PATH_H_PPARENT(tb->tb_path, h) == NULL || tb->FL[h] == NULL, "vs-12325: FL[%d](%p) or F[%d](%p) does not exist", h, tb->FL[h], h, PATH_H_PPARENT(tb->tb_path, h)); if (Sh_position == 0) return B_NR_ITEMS(tb->FL[h]); else return Sh_position - 1; } int get_right_neighbor_position(struct tree_balance *tb, int h) { int Sh_position = PATH_H_POSITION(tb->tb_path, h + 1); RFALSE(PATH_H_PPARENT(tb->tb_path, h) == NULL || tb->FR[h] == NULL, "vs-12330: F[%d](%p) or FR[%d](%p) does not exist", h, PATH_H_PPARENT(tb->tb_path, h), h, tb->FR[h]); if (Sh_position == B_NR_ITEMS(PATH_H_PPARENT(tb->tb_path, h))) return 0; else return Sh_position + 1; } #ifdef CONFIG_REISERFS_CHECK int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value); static void check_internal_node(struct super_block *s, struct buffer_head *bh, char *mes) { struct disk_child *dc; int i; RFALSE(!bh, "PAP-12336: bh == 0"); if (!bh || !B_IS_IN_TREE(bh)) return; RFALSE(!buffer_dirty(bh) && !(buffer_journaled(bh) || buffer_journal_dirty(bh)), "PAP-12337: buffer (%b) must be dirty", bh); dc = B_N_CHILD(bh, 0); for (i = 0; i <= B_NR_ITEMS(bh); i++, dc++) { if (!is_reusable(s, dc_block_number(dc), 1)) { print_cur_tb(mes); reiserfs_panic(s, "PAP-12338", "invalid child pointer %y in %b", dc, bh); } } } static int locked_or_not_in_tree(struct tree_balance *tb, struct buffer_head *bh, char *which) { if ((!buffer_journal_prepared(bh) && buffer_locked(bh)) || !B_IS_IN_TREE(bh)) { reiserfs_warning(tb->tb_sb, "vs-12339", "%s (%b)", which, bh); return 1; } return 0; } static int check_before_balancing(struct tree_balance *tb) { int retval = 0; if (REISERFS_SB(tb->tb_sb)->cur_tb) { reiserfs_panic(tb->tb_sb, "vs-12335", "suspect that schedule " "occurred based on cur_tb not being null at " "this point in code. do_balance cannot properly " "handle concurrent tree accesses on a same " "mount point."); } /* * double check that buffers that we will modify are unlocked. * (fix_nodes should already have prepped all of these for us). */ if (tb->lnum[0]) { retval |= locked_or_not_in_tree(tb, tb->L[0], "L[0]"); retval |= locked_or_not_in_tree(tb, tb->FL[0], "FL[0]"); retval |= locked_or_not_in_tree(tb, tb->CFL[0], "CFL[0]"); check_leaf(tb->L[0]); } if (tb->rnum[0]) { retval |= locked_or_not_in_tree(tb, tb->R[0], "R[0]"); retval |= locked_or_not_in_tree(tb, tb->FR[0], "FR[0]"); retval |= locked_or_not_in_tree(tb, tb->CFR[0], "CFR[0]"); check_leaf(tb->R[0]); } retval |= locked_or_not_in_tree(tb, PATH_PLAST_BUFFER(tb->tb_path), "S[0]"); check_leaf(PATH_PLAST_BUFFER(tb->tb_path)); return retval; } static void check_after_balance_leaf(struct tree_balance *tb) { if (tb->lnum[0]) { if (B_FREE_SPACE(tb->L[0]) != MAX_CHILD_SIZE(tb->L[0]) - dc_size(B_N_CHILD (tb->FL[0], get_left_neighbor_position(tb, 0)))) { print_cur_tb("12221"); reiserfs_panic(tb->tb_sb, "PAP-12355", "shift to left was incorrect"); } } if (tb->rnum[0]) { if (B_FREE_SPACE(tb->R[0]) != MAX_CHILD_SIZE(tb->R[0]) - dc_size(B_N_CHILD (tb->FR[0], get_right_neighbor_position(tb, 0)))) { print_cur_tb("12222"); reiserfs_panic(tb->tb_sb, "PAP-12360", "shift to right was incorrect"); } } if (PATH_H_PBUFFER(tb->tb_path, 1) && (B_FREE_SPACE(PATH_H_PBUFFER(tb->tb_path, 0)) != (MAX_CHILD_SIZE(PATH_H_PBUFFER(tb->tb_path, 0)) - dc_size(B_N_CHILD(PATH_H_PBUFFER(tb->tb_path, 1), PATH_H_POSITION(tb->tb_path, 1)))))) { int left = B_FREE_SPACE(PATH_H_PBUFFER(tb->tb_path, 0)); int right = (MAX_CHILD_SIZE(PATH_H_PBUFFER(tb->tb_path, 0)) - dc_size(B_N_CHILD(PATH_H_PBUFFER(tb->tb_path, 1), PATH_H_POSITION(tb->tb_path, 1)))); print_cur_tb("12223"); reiserfs_warning(tb->tb_sb, "reiserfs-12363", "B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) = %d; " "MAX_CHILD_SIZE (%d) - dc_size( %y, %d ) [%d] = %d", left, MAX_CHILD_SIZE(PATH_H_PBUFFER(tb->tb_path, 0)), PATH_H_PBUFFER(tb->tb_path, 1), PATH_H_POSITION(tb->tb_path, 1), dc_size(B_N_CHILD (PATH_H_PBUFFER(tb->tb_path, 1), PATH_H_POSITION(tb->tb_path, 1))), right); reiserfs_panic(tb->tb_sb, "PAP-12365", "S is incorrect"); } } static void check_leaf_level(struct tree_balance *tb) { check_leaf(tb->L[0]); check_leaf(tb->R[0]); check_leaf(PATH_PLAST_BUFFER(tb->tb_path)); } static void check_internal_levels(struct tree_balance *tb) { int h; /* check all internal nodes */ for (h = 1; tb->insert_size[h]; h++) { check_internal_node(tb->tb_sb, PATH_H_PBUFFER(tb->tb_path, h), "BAD BUFFER ON PATH"); if (tb->lnum[h]) check_internal_node(tb->tb_sb, tb->L[h], "BAD L"); if (tb->rnum[h]) check_internal_node(tb->tb_sb, tb->R[h], "BAD R"); } } #endif /* * Now we have all of the buffers that must be used in balancing of * the tree. We rely on the assumption that schedule() will not occur * while do_balance works. ( Only interrupt handlers are acceptable.) * We balance the tree according to the analysis made before this, * using buffers already obtained. For SMP support it will someday be * necessary to add ordered locking of tb. */ /* * Some interesting rules of balancing: * we delete a maximum of two nodes per level per balancing: we never * delete R, when we delete two of three nodes L, S, R then we move * them into R. * * we only delete L if we are deleting two nodes, if we delete only * one node we delete S * * if we shift leaves then we shift as much as we can: this is a * deliberate policy of extremism in node packing which results in * higher average utilization after repeated random balance operations * at the cost of more memory copies and more balancing as a result of * small insertions to full nodes. * * if we shift internal nodes we try to evenly balance the node * utilization, with consequent less balancing at the cost of lower * utilization. * * one could argue that the policy for directories in leaves should be * that of internal nodes, but we will wait until another day to * evaluate this.... It would be nice to someday measure and prove * these assumptions as to what is optimal.... */ static inline void do_balance_starts(struct tree_balance *tb) { /* use print_cur_tb() to see initial state of struct tree_balance */ /* store_print_tb (tb); */ /* do not delete, just comment it out */ /* print_tb(flag, PATH_LAST_POSITION(tb->tb_path), tb->tb_path->pos_in_item, tb, "check"); */ RFALSE(check_before_balancing(tb), "PAP-12340: locked buffers in TB"); #ifdef CONFIG_REISERFS_CHECK REISERFS_SB(tb->tb_sb)->cur_tb = tb; #endif } static inline void do_balance_completed(struct tree_balance *tb) { #ifdef CONFIG_REISERFS_CHECK check_leaf_level(tb); check_internal_levels(tb); REISERFS_SB(tb->tb_sb)->cur_tb = NULL; #endif /* * reiserfs_free_block is no longer schedule safe. So, we need to * put the buffers we want freed on the thrown list during do_balance, * and then free them now */ REISERFS_SB(tb->tb_sb)->s_do_balance++; /* release all nodes hold to perform the balancing */ unfix_nodes(tb); free_thrown(tb); } /* * do_balance - balance the tree * * @tb: tree_balance structure * @ih: item header of inserted item * @body: body of inserted item or bytes to paste * @flag: 'i' - insert, 'd' - delete, 'c' - cut, 'p' paste * * Cut means delete part of an item (includes removing an entry from a * directory). * * Delete means delete whole item. * * Insert means add a new item into the tree. * * Paste means to append to the end of an existing file or to * insert a directory entry. */ void do_balance(struct tree_balance *tb, struct item_head *ih, const char *body, int flag) { int child_pos; /* position of a child node in its parent */ int h; /* level of the tree being processed */ /* * in our processing of one level we sometimes determine what * must be inserted into the next higher level. This insertion * consists of a key or two keys and their corresponding * pointers */ struct item_head insert_key[2]; /* inserted node-ptrs for the next level */ struct buffer_head *insert_ptr[2]; tb->tb_mode = flag; tb->need_balance_dirty = 0; if (FILESYSTEM_CHANGED_TB(tb)) { reiserfs_panic(tb->tb_sb, "clm-6000", "fs generation has " "changed"); } /* if we have no real work to do */ if (!tb->insert_size[0]) { reiserfs_warning(tb->tb_sb, "PAP-12350", "insert_size == 0, mode == %c", flag); unfix_nodes(tb); return; } atomic_inc(&fs_generation(tb->tb_sb)); do_balance_starts(tb); /* * balance_leaf returns 0 except if combining L R and S into * one node. see balance_internal() for explanation of this * line of code. */ child_pos = PATH_H_B_ITEM_ORDER(tb->tb_path, 0) + balance_leaf(tb, ih, body, flag, insert_key, insert_ptr); #ifdef CONFIG_REISERFS_CHECK check_after_balance_leaf(tb); #endif /* Balance internal level of the tree. */ for (h = 1; h < MAX_HEIGHT && tb->insert_size[h]; h++) child_pos = balance_internal(tb, h, child_pos, insert_key, insert_ptr); do_balance_completed(tb); }
gpl-2.0
zarboz/s2w-VilleZ
arch/arm/mach-omap2/board-n8x0.c
1982
15956
/* * linux/arch/arm/mach-omap2/board-n8x0.c * * Copyright (C) 2005-2009 Nokia Corporation * Author: Juha Yrjola <juha.yrjola@nokia.com> * * Modified from mach-omap2/board-generic.c * * 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/gpio.h> #include <linux/init.h> #include <linux/io.h> #include <linux/stddef.h> #include <linux/i2c.h> #include <linux/spi/spi.h> #include <linux/usb/musb.h> #include <sound/tlv320aic3x.h> #include <asm/mach/arch.h> #include <asm/mach-types.h> #include <plat/board.h> #include <plat/common.h> #include <plat/menelaus.h> #include <mach/irqs.h> #include <plat/mcspi.h> #include <plat/onenand.h> #include <plat/mmc.h> #include <plat/serial.h> #include "mux.h" static int slot1_cover_open; static int slot2_cover_open; static struct device *mmc_device; #define TUSB6010_ASYNC_CS 1 #define TUSB6010_SYNC_CS 4 #define TUSB6010_GPIO_INT 58 #define TUSB6010_GPIO_ENABLE 0 #define TUSB6010_DMACHAN 0x3f #ifdef CONFIG_USB_MUSB_TUSB6010 /* * Enable or disable power to TUSB6010. When enabling, turn on 3.3 V and * 1.5 V voltage regulators of PM companion chip. Companion chip will then * provide then PGOOD signal to TUSB6010 which will release it from reset. */ static int tusb_set_power(int state) { int i, retval = 0; if (state) { gpio_set_value(TUSB6010_GPIO_ENABLE, 1); msleep(1); /* Wait until TUSB6010 pulls INT pin down */ i = 100; while (i && gpio_get_value(TUSB6010_GPIO_INT)) { msleep(1); i--; } if (!i) { printk(KERN_ERR "tusb: powerup failed\n"); retval = -ENODEV; } } else { gpio_set_value(TUSB6010_GPIO_ENABLE, 0); msleep(10); } return retval; } static struct musb_hdrc_config musb_config = { .multipoint = 1, .dyn_fifo = 1, .num_eps = 16, .ram_bits = 12, }; static struct musb_hdrc_platform_data tusb_data = { #if defined(CONFIG_USB_MUSB_OTG) .mode = MUSB_OTG, #elif defined(CONFIG_USB_MUSB_PERIPHERAL) .mode = MUSB_PERIPHERAL, #else /* defined(CONFIG_USB_MUSB_HOST) */ .mode = MUSB_HOST, #endif .set_power = tusb_set_power, .min_power = 25, /* x2 = 50 mA drawn from VBUS as peripheral */ .power = 100, /* Max 100 mA VBUS for host mode */ .config = &musb_config, }; static void __init n8x0_usb_init(void) { int ret = 0; static char announce[] __initdata = KERN_INFO "TUSB 6010\n"; /* PM companion chip power control pin */ ret = gpio_request_one(TUSB6010_GPIO_ENABLE, GPIOF_OUT_INIT_LOW, "TUSB6010 enable"); if (ret != 0) { printk(KERN_ERR "Could not get TUSB power GPIO%i\n", TUSB6010_GPIO_ENABLE); return; } tusb_set_power(0); ret = tusb6010_setup_interface(&tusb_data, TUSB6010_REFCLK_19, 2, TUSB6010_ASYNC_CS, TUSB6010_SYNC_CS, TUSB6010_GPIO_INT, TUSB6010_DMACHAN); if (ret != 0) goto err; printk(announce); return; err: gpio_free(TUSB6010_GPIO_ENABLE); } #else static void __init n8x0_usb_init(void) {} #endif /*CONFIG_USB_MUSB_TUSB6010 */ static struct omap2_mcspi_device_config p54spi_mcspi_config = { .turbo_mode = 0, .single_channel = 1, }; static struct spi_board_info n800_spi_board_info[] __initdata = { { .modalias = "p54spi", .bus_num = 2, .chip_select = 0, .max_speed_hz = 48000000, .controller_data = &p54spi_mcspi_config, }, }; #if defined(CONFIG_MTD_ONENAND_OMAP2) || \ defined(CONFIG_MTD_ONENAND_OMAP2_MODULE) static struct mtd_partition onenand_partitions[] = { { .name = "bootloader", .offset = 0, .size = 0x20000, .mask_flags = MTD_WRITEABLE, /* Force read-only */ }, { .name = "config", .offset = MTDPART_OFS_APPEND, .size = 0x60000, }, { .name = "kernel", .offset = MTDPART_OFS_APPEND, .size = 0x200000, }, { .name = "initfs", .offset = MTDPART_OFS_APPEND, .size = 0x400000, }, { .name = "rootfs", .offset = MTDPART_OFS_APPEND, .size = MTDPART_SIZ_FULL, }, }; static struct omap_onenand_platform_data board_onenand_data[] = { { .cs = 0, .gpio_irq = 26, .parts = onenand_partitions, .nr_parts = ARRAY_SIZE(onenand_partitions), .flags = ONENAND_SYNC_READ, } }; #endif #if defined(CONFIG_MENELAUS) && \ (defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)) /* * On both N800 and N810, only the first of the two MMC controllers is in use. * The two MMC slots are multiplexed via Menelaus companion chip over I2C. * On N800, both slots are powered via Menelaus. On N810, only one of the * slots is powered via Menelaus. The N810 EMMC is powered via GPIO. * * VMMC slot 1 on both N800 and N810 * VDCDC3_APE and VMCS2_APE slot 2 on N800 * GPIO23 and GPIO9 slot 2 EMMC on N810 * */ #define N8X0_SLOT_SWITCH_GPIO 96 #define N810_EMMC_VSD_GPIO 23 #define N810_EMMC_VIO_GPIO 9 static int n8x0_mmc_switch_slot(struct device *dev, int slot) { #ifdef CONFIG_MMC_DEBUG dev_dbg(dev, "Choose slot %d\n", slot + 1); #endif gpio_set_value(N8X0_SLOT_SWITCH_GPIO, slot); return 0; } static int n8x0_mmc_set_power_menelaus(struct device *dev, int slot, int power_on, int vdd) { int mV; #ifdef CONFIG_MMC_DEBUG dev_dbg(dev, "Set slot %d power: %s (vdd %d)\n", slot + 1, power_on ? "on" : "off", vdd); #endif if (slot == 0) { if (!power_on) return menelaus_set_vmmc(0); switch (1 << vdd) { case MMC_VDD_33_34: case MMC_VDD_32_33: case MMC_VDD_31_32: mV = 3100; break; case MMC_VDD_30_31: mV = 3000; break; case MMC_VDD_28_29: mV = 2800; break; case MMC_VDD_165_195: mV = 1850; break; default: BUG(); } return menelaus_set_vmmc(mV); } else { if (!power_on) return menelaus_set_vdcdc(3, 0); switch (1 << vdd) { case MMC_VDD_33_34: case MMC_VDD_32_33: mV = 3300; break; case MMC_VDD_30_31: case MMC_VDD_29_30: mV = 3000; break; case MMC_VDD_28_29: case MMC_VDD_27_28: mV = 2800; break; case MMC_VDD_24_25: case MMC_VDD_23_24: mV = 2400; break; case MMC_VDD_22_23: case MMC_VDD_21_22: mV = 2200; break; case MMC_VDD_20_21: mV = 2000; break; case MMC_VDD_165_195: mV = 1800; break; default: BUG(); } return menelaus_set_vdcdc(3, mV); } return 0; } static void n810_set_power_emmc(struct device *dev, int power_on) { dev_dbg(dev, "Set EMMC power %s\n", power_on ? "on" : "off"); if (power_on) { gpio_set_value(N810_EMMC_VSD_GPIO, 1); msleep(1); gpio_set_value(N810_EMMC_VIO_GPIO, 1); msleep(1); } else { gpio_set_value(N810_EMMC_VIO_GPIO, 0); msleep(50); gpio_set_value(N810_EMMC_VSD_GPIO, 0); msleep(50); } } static int n8x0_mmc_set_power(struct device *dev, int slot, int power_on, int vdd) { if (machine_is_nokia_n800() || slot == 0) return n8x0_mmc_set_power_menelaus(dev, slot, power_on, vdd); n810_set_power_emmc(dev, power_on); return 0; } static int n8x0_mmc_set_bus_mode(struct device *dev, int slot, int bus_mode) { int r; dev_dbg(dev, "Set slot %d bus mode %s\n", slot + 1, bus_mode == MMC_BUSMODE_OPENDRAIN ? "open-drain" : "push-pull"); BUG_ON(slot != 0 && slot != 1); slot++; switch (bus_mode) { case MMC_BUSMODE_OPENDRAIN: r = menelaus_set_mmc_opendrain(slot, 1); break; case MMC_BUSMODE_PUSHPULL: r = menelaus_set_mmc_opendrain(slot, 0); break; default: BUG(); } if (r != 0 && printk_ratelimit()) dev_err(dev, "MMC: unable to set bus mode for slot %d\n", slot); return r; } static int n8x0_mmc_get_cover_state(struct device *dev, int slot) { slot++; BUG_ON(slot != 1 && slot != 2); if (slot == 1) return slot1_cover_open; else return slot2_cover_open; } static void n8x0_mmc_callback(void *data, u8 card_mask) { int bit, *openp, index; if (machine_is_nokia_n800()) { bit = 1 << 1; openp = &slot2_cover_open; index = 1; } else { bit = 1; openp = &slot1_cover_open; index = 0; } if (card_mask & bit) *openp = 1; else *openp = 0; omap_mmc_notify_cover_event(mmc_device, index, *openp); } static int n8x0_mmc_late_init(struct device *dev) { int r, bit, *openp; int vs2sel; mmc_device = dev; r = menelaus_set_slot_sel(1); if (r < 0) return r; if (machine_is_nokia_n800()) vs2sel = 0; else vs2sel = 2; r = menelaus_set_mmc_slot(2, 0, vs2sel, 1); if (r < 0) return r; n8x0_mmc_set_power(dev, 0, MMC_POWER_ON, 16); /* MMC_VDD_28_29 */ n8x0_mmc_set_power(dev, 1, MMC_POWER_ON, 16); r = menelaus_set_mmc_slot(1, 1, 0, 1); if (r < 0) return r; r = menelaus_set_mmc_slot(2, 1, vs2sel, 1); if (r < 0) return r; r = menelaus_get_slot_pin_states(); if (r < 0) return r; if (machine_is_nokia_n800()) { bit = 1 << 1; openp = &slot2_cover_open; } else { bit = 1; openp = &slot1_cover_open; slot2_cover_open = 0; } /* All slot pin bits seem to be inversed until first switch change */ if (r == 0xf || r == (0xf & ~bit)) r = ~r; if (r & bit) *openp = 1; else *openp = 0; r = menelaus_register_mmc_callback(n8x0_mmc_callback, NULL); return r; } static void n8x0_mmc_shutdown(struct device *dev) { int vs2sel; if (machine_is_nokia_n800()) vs2sel = 0; else vs2sel = 2; menelaus_set_mmc_slot(1, 0, 0, 0); menelaus_set_mmc_slot(2, 0, vs2sel, 0); } static void n8x0_mmc_cleanup(struct device *dev) { menelaus_unregister_mmc_callback(); gpio_free(N8X0_SLOT_SWITCH_GPIO); if (machine_is_nokia_n810()) { gpio_free(N810_EMMC_VSD_GPIO); gpio_free(N810_EMMC_VIO_GPIO); } } /* * MMC controller1 has two slots that are multiplexed via I2C. * MMC controller2 is not in use. */ static struct omap_mmc_platform_data mmc1_data = { .nr_slots = 2, .switch_slot = n8x0_mmc_switch_slot, .init = n8x0_mmc_late_init, .cleanup = n8x0_mmc_cleanup, .shutdown = n8x0_mmc_shutdown, .max_freq = 24000000, .dma_mask = 0xffffffff, .slots[0] = { .wires = 4, .set_power = n8x0_mmc_set_power, .set_bus_mode = n8x0_mmc_set_bus_mode, .get_cover_state = n8x0_mmc_get_cover_state, .ocr_mask = MMC_VDD_165_195 | MMC_VDD_30_31 | MMC_VDD_32_33 | MMC_VDD_33_34, .name = "internal", }, .slots[1] = { .set_power = n8x0_mmc_set_power, .set_bus_mode = n8x0_mmc_set_bus_mode, .get_cover_state = n8x0_mmc_get_cover_state, .ocr_mask = MMC_VDD_165_195 | MMC_VDD_20_21 | MMC_VDD_21_22 | MMC_VDD_22_23 | MMC_VDD_23_24 | MMC_VDD_24_25 | MMC_VDD_27_28 | MMC_VDD_28_29 | MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_32_33 | MMC_VDD_33_34, .name = "external", }, }; static struct omap_mmc_platform_data *mmc_data[OMAP24XX_NR_MMC]; static struct gpio n810_emmc_gpios[] __initdata = { { N810_EMMC_VSD_GPIO, GPIOF_OUT_INIT_LOW, "MMC slot 2 Vddf" }, { N810_EMMC_VIO_GPIO, GPIOF_OUT_INIT_LOW, "MMC slot 2 Vdd" }, }; static void __init n8x0_mmc_init(void) { int err; if (machine_is_nokia_n810()) { mmc1_data.slots[0].name = "external"; /* * Some Samsung Movinand chips do not like open-ended * multi-block reads and fall to braind-dead state * while doing so. Reducing the number of blocks in * the transfer or delays in clock disable do not help */ mmc1_data.slots[1].name = "internal"; mmc1_data.slots[1].ban_openended = 1; } err = gpio_request_one(N8X0_SLOT_SWITCH_GPIO, GPIOF_OUT_INIT_LOW, "MMC slot switch"); if (err) return; if (machine_is_nokia_n810()) { err = gpio_request_array(n810_emmc_gpios, ARRAY_SIZE(n810_emmc_gpios)); if (err) { gpio_free(N8X0_SLOT_SWITCH_GPIO); return; } } mmc_data[0] = &mmc1_data; omap242x_init_mmc(mmc_data); } #else void __init n8x0_mmc_init(void) { } #endif /* CONFIG_MMC_OMAP */ #ifdef CONFIG_MENELAUS static int n8x0_auto_sleep_regulators(void) { u32 val; int ret; val = EN_VPLL_SLEEP | EN_VMMC_SLEEP \ | EN_VAUX_SLEEP | EN_VIO_SLEEP \ | EN_VMEM_SLEEP | EN_DC3_SLEEP \ | EN_VC_SLEEP | EN_DC2_SLEEP; ret = menelaus_set_regulator_sleep(1, val); if (ret < 0) { printk(KERN_ERR "Could not set regulators to sleep on " "menelaus: %u\n", ret); return ret; } return 0; } static int n8x0_auto_voltage_scale(void) { int ret; ret = menelaus_set_vcore_hw(1400, 1050); if (ret < 0) { printk(KERN_ERR "Could not set VCORE voltage on " "menelaus: %u\n", ret); return ret; } return 0; } static int n8x0_menelaus_late_init(struct device *dev) { int ret; ret = n8x0_auto_voltage_scale(); if (ret < 0) return ret; ret = n8x0_auto_sleep_regulators(); if (ret < 0) return ret; return 0; } #else static int n8x0_menelaus_late_init(struct device *dev) { return 0; } #endif static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = { .late_init = n8x0_menelaus_late_init, }; static struct i2c_board_info __initdata n8x0_i2c_board_info_1[] __initdata = { { I2C_BOARD_INFO("menelaus", 0x72), .irq = INT_24XX_SYS_NIRQ, .platform_data = &n8x0_menelaus_platform_data, }, }; static struct aic3x_pdata n810_aic33_data __initdata = { .gpio_reset = 118, }; static struct i2c_board_info n810_i2c_board_info_2[] __initdata = { { I2C_BOARD_INFO("tlv320aic3x", 0x18), .platform_data = &n810_aic33_data, }, }; static void __init n8x0_map_io(void) { omap2_set_globals_242x(); omap242x_map_common_io(); } static void __init n8x0_init_early(void) { omap2_init_common_infrastructure(); omap2_init_common_devices(NULL, NULL); } #ifdef CONFIG_OMAP_MUX static struct omap_board_mux board_mux[] __initdata = { /* I2S codec port pins for McBSP block */ OMAP2420_MUX(EAC_AC_SCLK, OMAP_MUX_MODE1 | OMAP_PIN_INPUT), OMAP2420_MUX(EAC_AC_FS, OMAP_MUX_MODE1 | OMAP_PIN_INPUT), OMAP2420_MUX(EAC_AC_DIN, OMAP_MUX_MODE1 | OMAP_PIN_INPUT), OMAP2420_MUX(EAC_AC_DOUT, OMAP_MUX_MODE1 | OMAP_PIN_OUTPUT), { .reg_offset = OMAP_MUX_TERMINATOR }, }; static struct omap_device_pad serial2_pads[] __initdata = { { .name = "uart3_rx_irrx.uart3_rx_irrx", .flags = OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP, .enable = OMAP_MUX_MODE0, .idle = OMAP_MUX_MODE3 /* Mux as GPIO for idle */ }, }; static inline void board_serial_init(void) { struct omap_board_data bdata; bdata.flags = 0; bdata.pads = NULL; bdata.pads_cnt = 0; bdata.id = 0; omap_serial_init_port(&bdata); bdata.id = 1; omap_serial_init_port(&bdata); bdata.id = 2; bdata.pads = serial2_pads; bdata.pads_cnt = ARRAY_SIZE(serial2_pads); omap_serial_init_port(&bdata); } #else static inline void board_serial_init(void) { omap_serial_init(); } #endif static void __init n8x0_init_machine(void) { omap2420_mux_init(board_mux, OMAP_PACKAGE_ZAC); /* FIXME: add n810 spi devices */ spi_register_board_info(n800_spi_board_info, ARRAY_SIZE(n800_spi_board_info)); omap_register_i2c_bus(1, 400, n8x0_i2c_board_info_1, ARRAY_SIZE(n8x0_i2c_board_info_1)); omap_register_i2c_bus(2, 400, NULL, 0); if (machine_is_nokia_n810()) i2c_register_board_info(2, n810_i2c_board_info_2, ARRAY_SIZE(n810_i2c_board_info_2)); board_serial_init(); gpmc_onenand_init(board_onenand_data); n8x0_mmc_init(); n8x0_usb_init(); } MACHINE_START(NOKIA_N800, "Nokia N800") .boot_params = 0x80000100, .reserve = omap_reserve, .map_io = n8x0_map_io, .init_early = n8x0_init_early, .init_irq = omap_init_irq, .init_machine = n8x0_init_machine, .timer = &omap_timer, MACHINE_END MACHINE_START(NOKIA_N810, "Nokia N810") .boot_params = 0x80000100, .reserve = omap_reserve, .map_io = n8x0_map_io, .init_early = n8x0_init_early, .init_irq = omap_init_irq, .init_machine = n8x0_init_machine, .timer = &omap_timer, MACHINE_END MACHINE_START(NOKIA_N810_WIMAX, "Nokia N810 WiMAX") .boot_params = 0x80000100, .reserve = omap_reserve, .map_io = n8x0_map_io, .init_early = n8x0_init_early, .init_irq = omap_init_irq, .init_machine = n8x0_init_machine, .timer = &omap_timer, MACHINE_END
gpl-2.0
upndwn4par/android_kernel_moto_shamu
drivers/net/ethernet/sis/sis190.c
2238
47273
/* sis190.c: Silicon Integrated Systems SiS190 ethernet driver Copyright (c) 2003 K.M. Liu <kmliu@sis.com> Copyright (c) 2003, 2004 Jeff Garzik <jgarzik@pobox.com> Copyright (c) 2003, 2004, 2005 Francois Romieu <romieu@fr.zoreil.com> Based on r8169.c, tg3.c, 8139cp.c, skge.c, epic100.c and SiS 190/191 genuine driver. This software may be used and distributed according to the terms of the GNU General Public License (GPL), incorporated herein by reference. Drivers based on or derived from this code fall under the GPL and must retain the authorship, copyright and license notice. This file is not a complete program and may only be used when the entire operating system is licensed under the GPL. See the file COPYING in this distribution for more information. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/interrupt.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/netdevice.h> #include <linux/rtnetlink.h> #include <linux/etherdevice.h> #include <linux/ethtool.h> #include <linux/pci.h> #include <linux/mii.h> #include <linux/delay.h> #include <linux/crc32.h> #include <linux/dma-mapping.h> #include <linux/slab.h> #include <asm/irq.h> #define PHY_MAX_ADDR 32 #define PHY_ID_ANY 0x1f #define MII_REG_ANY 0x1f #define DRV_VERSION "1.4" #define DRV_NAME "sis190" #define SIS190_DRIVER_NAME DRV_NAME " Gigabit Ethernet driver " DRV_VERSION #define sis190_rx_skb netif_rx #define sis190_rx_quota(count, quota) count #define NUM_TX_DESC 64 /* [8..1024] */ #define NUM_RX_DESC 64 /* [8..8192] */ #define TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) #define RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) #define RX_BUF_SIZE 1536 #define RX_BUF_MASK 0xfff8 #define SIS190_REGS_SIZE 0x80 #define SIS190_TX_TIMEOUT (6*HZ) #define SIS190_PHY_TIMEOUT (10*HZ) #define SIS190_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | \ NETIF_MSG_LINK | NETIF_MSG_IFUP | \ NETIF_MSG_IFDOWN) /* Enhanced PHY access register bit definitions */ #define EhnMIIread 0x0000 #define EhnMIIwrite 0x0020 #define EhnMIIdataShift 16 #define EhnMIIpmdShift 6 /* 7016 only */ #define EhnMIIregShift 11 #define EhnMIIreq 0x0010 #define EhnMIInotDone 0x0010 /* Write/read MMIO register */ #define SIS_W8(reg, val) writeb ((val), ioaddr + (reg)) #define SIS_W16(reg, val) writew ((val), ioaddr + (reg)) #define SIS_W32(reg, val) writel ((val), ioaddr + (reg)) #define SIS_R8(reg) readb (ioaddr + (reg)) #define SIS_R16(reg) readw (ioaddr + (reg)) #define SIS_R32(reg) readl (ioaddr + (reg)) #define SIS_PCI_COMMIT() SIS_R32(IntrControl) enum sis190_registers { TxControl = 0x00, TxDescStartAddr = 0x04, rsv0 = 0x08, // reserved TxSts = 0x0c, // unused (Control/Status) RxControl = 0x10, RxDescStartAddr = 0x14, rsv1 = 0x18, // reserved RxSts = 0x1c, // unused IntrStatus = 0x20, IntrMask = 0x24, IntrControl = 0x28, IntrTimer = 0x2c, // unused (Interrupt Timer) PMControl = 0x30, // unused (Power Mgmt Control/Status) rsv2 = 0x34, // reserved ROMControl = 0x38, ROMInterface = 0x3c, StationControl = 0x40, GMIIControl = 0x44, GIoCR = 0x48, // unused (GMAC IO Compensation) GIoCtrl = 0x4c, // unused (GMAC IO Control) TxMacControl = 0x50, TxLimit = 0x54, // unused (Tx MAC Timer/TryLimit) RGDelay = 0x58, // unused (RGMII Tx Internal Delay) rsv3 = 0x5c, // reserved RxMacControl = 0x60, RxMacAddr = 0x62, RxHashTable = 0x68, // Undocumented = 0x6c, RxWolCtrl = 0x70, RxWolData = 0x74, // unused (Rx WOL Data Access) RxMPSControl = 0x78, // unused (Rx MPS Control) rsv4 = 0x7c, // reserved }; enum sis190_register_content { /* IntrStatus */ SoftInt = 0x40000000, // unused Timeup = 0x20000000, // unused PauseFrame = 0x00080000, // unused MagicPacket = 0x00040000, // unused WakeupFrame = 0x00020000, // unused LinkChange = 0x00010000, RxQEmpty = 0x00000080, RxQInt = 0x00000040, TxQ1Empty = 0x00000020, // unused TxQ1Int = 0x00000010, TxQ0Empty = 0x00000008, // unused TxQ0Int = 0x00000004, RxHalt = 0x00000002, TxHalt = 0x00000001, /* {Rx/Tx}CmdBits */ CmdReset = 0x10, CmdRxEnb = 0x08, // unused CmdTxEnb = 0x01, RxBufEmpty = 0x01, // unused /* Cfg9346Bits */ Cfg9346_Lock = 0x00, // unused Cfg9346_Unlock = 0xc0, // unused /* RxMacControl */ AcceptErr = 0x20, // unused AcceptRunt = 0x10, // unused AcceptBroadcast = 0x0800, AcceptMulticast = 0x0400, AcceptMyPhys = 0x0200, AcceptAllPhys = 0x0100, /* RxConfigBits */ RxCfgFIFOShift = 13, RxCfgDMAShift = 8, // 0x1a in RxControl ? /* TxConfigBits */ TxInterFrameGapShift = 24, TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ LinkStatus = 0x02, // unused FullDup = 0x01, // unused /* TBICSRBit */ TBILinkOK = 0x02000000, // unused }; struct TxDesc { __le32 PSize; __le32 status; __le32 addr; __le32 size; }; struct RxDesc { __le32 PSize; __le32 status; __le32 addr; __le32 size; }; enum _DescStatusBit { /* _Desc.status */ OWNbit = 0x80000000, // RXOWN/TXOWN INTbit = 0x40000000, // RXINT/TXINT CRCbit = 0x00020000, // CRCOFF/CRCEN PADbit = 0x00010000, // PREADD/PADEN /* _Desc.size */ RingEnd = 0x80000000, /* TxDesc.status */ LSEN = 0x08000000, // TSO ? -- FR IPCS = 0x04000000, TCPCS = 0x02000000, UDPCS = 0x01000000, BSTEN = 0x00800000, EXTEN = 0x00400000, DEFEN = 0x00200000, BKFEN = 0x00100000, CRSEN = 0x00080000, COLEN = 0x00040000, THOL3 = 0x30000000, THOL2 = 0x20000000, THOL1 = 0x10000000, THOL0 = 0x00000000, WND = 0x00080000, TABRT = 0x00040000, FIFO = 0x00020000, LINK = 0x00010000, ColCountMask = 0x0000ffff, /* RxDesc.status */ IPON = 0x20000000, TCPON = 0x10000000, UDPON = 0x08000000, Wakup = 0x00400000, Magic = 0x00200000, Pause = 0x00100000, DEFbit = 0x00200000, BCAST = 0x000c0000, MCAST = 0x00080000, UCAST = 0x00040000, /* RxDesc.PSize */ TAGON = 0x80000000, RxDescCountMask = 0x7f000000, // multi-desc pkt when > 1 ? -- FR ABORT = 0x00800000, SHORT = 0x00400000, LIMIT = 0x00200000, MIIER = 0x00100000, OVRUN = 0x00080000, NIBON = 0x00040000, COLON = 0x00020000, CRCOK = 0x00010000, RxSizeMask = 0x0000ffff /* * The asic could apparently do vlan, TSO, jumbo (sis191 only) and * provide two (unused with Linux) Tx queues. No publicly * available documentation alas. */ }; enum sis190_eeprom_access_register_bits { EECS = 0x00000001, // unused EECLK = 0x00000002, // unused EEDO = 0x00000008, // unused EEDI = 0x00000004, // unused EEREQ = 0x00000080, EEROP = 0x00000200, EEWOP = 0x00000100 // unused }; /* EEPROM Addresses */ enum sis190_eeprom_address { EEPROMSignature = 0x00, EEPROMCLK = 0x01, // unused EEPROMInfo = 0x02, EEPROMMACAddr = 0x03 }; enum sis190_feature { F_HAS_RGMII = 1, F_PHY_88E1111 = 2, F_PHY_BCM5461 = 4 }; struct sis190_private { void __iomem *mmio_addr; struct pci_dev *pci_dev; struct net_device *dev; spinlock_t lock; u32 rx_buf_sz; u32 cur_rx; u32 cur_tx; u32 dirty_rx; u32 dirty_tx; dma_addr_t rx_dma; dma_addr_t tx_dma; struct RxDesc *RxDescRing; struct TxDesc *TxDescRing; struct sk_buff *Rx_skbuff[NUM_RX_DESC]; struct sk_buff *Tx_skbuff[NUM_TX_DESC]; struct work_struct phy_task; struct timer_list timer; u32 msg_enable; struct mii_if_info mii_if; struct list_head first_phy; u32 features; u32 negotiated_lpa; enum { LNK_OFF, LNK_ON, LNK_AUTONEG, } link_status; }; struct sis190_phy { struct list_head list; int phy_id; u16 id[2]; u16 status; u8 type; }; enum sis190_phy_type { UNKNOWN = 0x00, HOME = 0x01, LAN = 0x02, MIX = 0x03 }; static struct mii_chip_info { const char *name; u16 id[2]; unsigned int type; u32 feature; } mii_chip_table[] = { { "Atheros PHY", { 0x004d, 0xd010 }, LAN, 0 }, { "Atheros PHY AR8012", { 0x004d, 0xd020 }, LAN, 0 }, { "Broadcom PHY BCM5461", { 0x0020, 0x60c0 }, LAN, F_PHY_BCM5461 }, { "Broadcom PHY AC131", { 0x0143, 0xbc70 }, LAN, 0 }, { "Agere PHY ET1101B", { 0x0282, 0xf010 }, LAN, 0 }, { "Marvell PHY 88E1111", { 0x0141, 0x0cc0 }, LAN, F_PHY_88E1111 }, { "Realtek PHY RTL8201", { 0x0000, 0x8200 }, LAN, 0 }, { NULL, } }; static const struct { const char *name; } sis_chip_info[] = { { "SiS 190 PCI Fast Ethernet adapter" }, { "SiS 191 PCI Gigabit Ethernet adapter" }, }; static DEFINE_PCI_DEVICE_TABLE(sis190_pci_tbl) = { { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x0190), 0, 0, 0 }, { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x0191), 0, 0, 1 }, { 0, }, }; MODULE_DEVICE_TABLE(pci, sis190_pci_tbl); static int rx_copybreak = 200; static struct { u32 msg_enable; } debug = { -1 }; MODULE_DESCRIPTION("SiS sis190/191 Gigabit Ethernet driver"); module_param(rx_copybreak, int, 0); MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames"); module_param_named(debug, debug.msg_enable, int, 0); MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); MODULE_AUTHOR("K.M. Liu <kmliu@sis.com>, Ueimor <romieu@fr.zoreil.com>"); MODULE_VERSION(DRV_VERSION); MODULE_LICENSE("GPL"); static const u32 sis190_intr_mask = RxQEmpty | RxQInt | TxQ1Int | TxQ0Int | RxHalt | TxHalt | LinkChange; /* * Maximum number of multicast addresses to filter (vs. Rx-all-multicast). * The chips use a 64 element hash table based on the Ethernet CRC. */ static const int multicast_filter_limit = 32; static void __mdio_cmd(void __iomem *ioaddr, u32 ctl) { unsigned int i; SIS_W32(GMIIControl, ctl); msleep(1); for (i = 0; i < 100; i++) { if (!(SIS_R32(GMIIControl) & EhnMIInotDone)) break; msleep(1); } if (i > 99) pr_err("PHY command failed !\n"); } static void mdio_write(void __iomem *ioaddr, int phy_id, int reg, int val) { __mdio_cmd(ioaddr, EhnMIIreq | EhnMIIwrite | (((u32) reg) << EhnMIIregShift) | (phy_id << EhnMIIpmdShift) | (((u32) val) << EhnMIIdataShift)); } static int mdio_read(void __iomem *ioaddr, int phy_id, int reg) { __mdio_cmd(ioaddr, EhnMIIreq | EhnMIIread | (((u32) reg) << EhnMIIregShift) | (phy_id << EhnMIIpmdShift)); return (u16) (SIS_R32(GMIIControl) >> EhnMIIdataShift); } static void __mdio_write(struct net_device *dev, int phy_id, int reg, int val) { struct sis190_private *tp = netdev_priv(dev); mdio_write(tp->mmio_addr, phy_id, reg, val); } static int __mdio_read(struct net_device *dev, int phy_id, int reg) { struct sis190_private *tp = netdev_priv(dev); return mdio_read(tp->mmio_addr, phy_id, reg); } static u16 mdio_read_latched(void __iomem *ioaddr, int phy_id, int reg) { mdio_read(ioaddr, phy_id, reg); return mdio_read(ioaddr, phy_id, reg); } static u16 sis190_read_eeprom(void __iomem *ioaddr, u32 reg) { u16 data = 0xffff; unsigned int i; if (!(SIS_R32(ROMControl) & 0x0002)) return 0; SIS_W32(ROMInterface, EEREQ | EEROP | (reg << 10)); for (i = 0; i < 200; i++) { if (!(SIS_R32(ROMInterface) & EEREQ)) { data = (SIS_R32(ROMInterface) & 0xffff0000) >> 16; break; } msleep(1); } return data; } static void sis190_irq_mask_and_ack(void __iomem *ioaddr) { SIS_W32(IntrMask, 0x00); SIS_W32(IntrStatus, 0xffffffff); SIS_PCI_COMMIT(); } static void sis190_asic_down(void __iomem *ioaddr) { /* Stop the chip's Tx and Rx DMA processes. */ SIS_W32(TxControl, 0x1a00); SIS_W32(RxControl, 0x1a00); sis190_irq_mask_and_ack(ioaddr); } static void sis190_mark_as_last_descriptor(struct RxDesc *desc) { desc->size |= cpu_to_le32(RingEnd); } static inline void sis190_give_to_asic(struct RxDesc *desc, u32 rx_buf_sz) { u32 eor = le32_to_cpu(desc->size) & RingEnd; desc->PSize = 0x0; desc->size = cpu_to_le32((rx_buf_sz & RX_BUF_MASK) | eor); wmb(); desc->status = cpu_to_le32(OWNbit | INTbit); } static inline void sis190_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, u32 rx_buf_sz) { desc->addr = cpu_to_le32(mapping); sis190_give_to_asic(desc, rx_buf_sz); } static inline void sis190_make_unusable_by_asic(struct RxDesc *desc) { desc->PSize = 0x0; desc->addr = cpu_to_le32(0xdeadbeef); desc->size &= cpu_to_le32(RingEnd); wmb(); desc->status = 0x0; } static struct sk_buff *sis190_alloc_rx_skb(struct sis190_private *tp, struct RxDesc *desc) { u32 rx_buf_sz = tp->rx_buf_sz; struct sk_buff *skb; dma_addr_t mapping; skb = netdev_alloc_skb(tp->dev, rx_buf_sz); if (unlikely(!skb)) goto skb_alloc_failed; mapping = pci_map_single(tp->pci_dev, skb->data, tp->rx_buf_sz, PCI_DMA_FROMDEVICE); if (pci_dma_mapping_error(tp->pci_dev, mapping)) goto out; sis190_map_to_asic(desc, mapping, rx_buf_sz); return skb; out: dev_kfree_skb_any(skb); skb_alloc_failed: sis190_make_unusable_by_asic(desc); return NULL; } static u32 sis190_rx_fill(struct sis190_private *tp, struct net_device *dev, u32 start, u32 end) { u32 cur; for (cur = start; cur < end; cur++) { unsigned int i = cur % NUM_RX_DESC; if (tp->Rx_skbuff[i]) continue; tp->Rx_skbuff[i] = sis190_alloc_rx_skb(tp, tp->RxDescRing + i); if (!tp->Rx_skbuff[i]) break; } return cur - start; } static bool sis190_try_rx_copy(struct sis190_private *tp, struct sk_buff **sk_buff, int pkt_size, dma_addr_t addr) { struct sk_buff *skb; bool done = false; if (pkt_size >= rx_copybreak) goto out; skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size); if (!skb) goto out; pci_dma_sync_single_for_cpu(tp->pci_dev, addr, tp->rx_buf_sz, PCI_DMA_FROMDEVICE); skb_copy_to_linear_data(skb, sk_buff[0]->data, pkt_size); *sk_buff = skb; done = true; out: return done; } static inline int sis190_rx_pkt_err(u32 status, struct net_device_stats *stats) { #define ErrMask (OVRUN | SHORT | LIMIT | MIIER | NIBON | COLON | ABORT) if ((status & CRCOK) && !(status & ErrMask)) return 0; if (!(status & CRCOK)) stats->rx_crc_errors++; else if (status & OVRUN) stats->rx_over_errors++; else if (status & (SHORT | LIMIT)) stats->rx_length_errors++; else if (status & (MIIER | NIBON | COLON)) stats->rx_frame_errors++; stats->rx_errors++; return -1; } static int sis190_rx_interrupt(struct net_device *dev, struct sis190_private *tp, void __iomem *ioaddr) { struct net_device_stats *stats = &dev->stats; u32 rx_left, cur_rx = tp->cur_rx; u32 delta, count; rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx; rx_left = sis190_rx_quota(rx_left, (u32) dev->quota); for (; rx_left > 0; rx_left--, cur_rx++) { unsigned int entry = cur_rx % NUM_RX_DESC; struct RxDesc *desc = tp->RxDescRing + entry; u32 status; if (le32_to_cpu(desc->status) & OWNbit) break; status = le32_to_cpu(desc->PSize); //netif_info(tp, intr, dev, "Rx PSize = %08x\n", status); if (sis190_rx_pkt_err(status, stats) < 0) sis190_give_to_asic(desc, tp->rx_buf_sz); else { struct sk_buff *skb = tp->Rx_skbuff[entry]; dma_addr_t addr = le32_to_cpu(desc->addr); int pkt_size = (status & RxSizeMask) - 4; struct pci_dev *pdev = tp->pci_dev; if (unlikely(pkt_size > tp->rx_buf_sz)) { netif_info(tp, intr, dev, "(frag) status = %08x\n", status); stats->rx_dropped++; stats->rx_length_errors++; sis190_give_to_asic(desc, tp->rx_buf_sz); continue; } if (sis190_try_rx_copy(tp, &skb, pkt_size, addr)) { pci_dma_sync_single_for_device(pdev, addr, tp->rx_buf_sz, PCI_DMA_FROMDEVICE); sis190_give_to_asic(desc, tp->rx_buf_sz); } else { pci_unmap_single(pdev, addr, tp->rx_buf_sz, PCI_DMA_FROMDEVICE); tp->Rx_skbuff[entry] = NULL; sis190_make_unusable_by_asic(desc); } skb_put(skb, pkt_size); skb->protocol = eth_type_trans(skb, dev); sis190_rx_skb(skb); stats->rx_packets++; stats->rx_bytes += pkt_size; if ((status & BCAST) == MCAST) stats->multicast++; } } count = cur_rx - tp->cur_rx; tp->cur_rx = cur_rx; delta = sis190_rx_fill(tp, dev, tp->dirty_rx, tp->cur_rx); if (!delta && count) netif_info(tp, intr, dev, "no Rx buffer allocated\n"); tp->dirty_rx += delta; if ((tp->dirty_rx + NUM_RX_DESC) == tp->cur_rx) netif_emerg(tp, intr, dev, "Rx buffers exhausted\n"); return count; } static void sis190_unmap_tx_skb(struct pci_dev *pdev, struct sk_buff *skb, struct TxDesc *desc) { unsigned int len; len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len; pci_unmap_single(pdev, le32_to_cpu(desc->addr), len, PCI_DMA_TODEVICE); memset(desc, 0x00, sizeof(*desc)); } static inline int sis190_tx_pkt_err(u32 status, struct net_device_stats *stats) { #define TxErrMask (WND | TABRT | FIFO | LINK) if (!unlikely(status & TxErrMask)) return 0; if (status & WND) stats->tx_window_errors++; if (status & TABRT) stats->tx_aborted_errors++; if (status & FIFO) stats->tx_fifo_errors++; if (status & LINK) stats->tx_carrier_errors++; stats->tx_errors++; return -1; } static void sis190_tx_interrupt(struct net_device *dev, struct sis190_private *tp, void __iomem *ioaddr) { struct net_device_stats *stats = &dev->stats; u32 pending, dirty_tx = tp->dirty_tx; /* * It would not be needed if queueing was allowed to be enabled * again too early (hint: think preempt and unclocked smp systems). */ unsigned int queue_stopped; smp_rmb(); pending = tp->cur_tx - dirty_tx; queue_stopped = (pending == NUM_TX_DESC); for (; pending; pending--, dirty_tx++) { unsigned int entry = dirty_tx % NUM_TX_DESC; struct TxDesc *txd = tp->TxDescRing + entry; u32 status = le32_to_cpu(txd->status); struct sk_buff *skb; if (status & OWNbit) break; skb = tp->Tx_skbuff[entry]; if (likely(sis190_tx_pkt_err(status, stats) == 0)) { stats->tx_packets++; stats->tx_bytes += skb->len; stats->collisions += ((status & ColCountMask) - 1); } sis190_unmap_tx_skb(tp->pci_dev, skb, txd); tp->Tx_skbuff[entry] = NULL; dev_kfree_skb_irq(skb); } if (tp->dirty_tx != dirty_tx) { tp->dirty_tx = dirty_tx; smp_wmb(); if (queue_stopped) netif_wake_queue(dev); } } /* * The interrupt handler does all of the Rx thread work and cleans up after * the Tx thread. */ static irqreturn_t sis190_irq(int irq, void *__dev) { struct net_device *dev = __dev; struct sis190_private *tp = netdev_priv(dev); void __iomem *ioaddr = tp->mmio_addr; unsigned int handled = 0; u32 status; status = SIS_R32(IntrStatus); if ((status == 0xffffffff) || !status) goto out; handled = 1; if (unlikely(!netif_running(dev))) { sis190_asic_down(ioaddr); goto out; } SIS_W32(IntrStatus, status); // netif_info(tp, intr, dev, "status = %08x\n", status); if (status & LinkChange) { netif_info(tp, intr, dev, "link change\n"); del_timer(&tp->timer); schedule_work(&tp->phy_task); } if (status & RxQInt) sis190_rx_interrupt(dev, tp, ioaddr); if (status & TxQ0Int) sis190_tx_interrupt(dev, tp, ioaddr); out: return IRQ_RETVAL(handled); } #ifdef CONFIG_NET_POLL_CONTROLLER static void sis190_netpoll(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); const int irq = tp->pci_dev->irq; disable_irq(irq); sis190_irq(irq, dev); enable_irq(irq); } #endif static void sis190_free_rx_skb(struct sis190_private *tp, struct sk_buff **sk_buff, struct RxDesc *desc) { struct pci_dev *pdev = tp->pci_dev; pci_unmap_single(pdev, le32_to_cpu(desc->addr), tp->rx_buf_sz, PCI_DMA_FROMDEVICE); dev_kfree_skb(*sk_buff); *sk_buff = NULL; sis190_make_unusable_by_asic(desc); } static void sis190_rx_clear(struct sis190_private *tp) { unsigned int i; for (i = 0; i < NUM_RX_DESC; i++) { if (!tp->Rx_skbuff[i]) continue; sis190_free_rx_skb(tp, tp->Rx_skbuff + i, tp->RxDescRing + i); } } static void sis190_init_ring_indexes(struct sis190_private *tp) { tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0; } static int sis190_init_ring(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); sis190_init_ring_indexes(tp); memset(tp->Tx_skbuff, 0x0, NUM_TX_DESC * sizeof(struct sk_buff *)); memset(tp->Rx_skbuff, 0x0, NUM_RX_DESC * sizeof(struct sk_buff *)); if (sis190_rx_fill(tp, dev, 0, NUM_RX_DESC) != NUM_RX_DESC) goto err_rx_clear; sis190_mark_as_last_descriptor(tp->RxDescRing + NUM_RX_DESC - 1); return 0; err_rx_clear: sis190_rx_clear(tp); return -ENOMEM; } static void sis190_set_rx_mode(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); void __iomem *ioaddr = tp->mmio_addr; unsigned long flags; u32 mc_filter[2]; /* Multicast hash filter */ u16 rx_mode; if (dev->flags & IFF_PROMISC) { rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys | AcceptAllPhys; mc_filter[1] = mc_filter[0] = 0xffffffff; } else if ((netdev_mc_count(dev) > multicast_filter_limit) || (dev->flags & IFF_ALLMULTI)) { /* Too many to filter perfectly -- accept all multicasts. */ rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; mc_filter[1] = mc_filter[0] = 0xffffffff; } else { struct netdev_hw_addr *ha; rx_mode = AcceptBroadcast | AcceptMyPhys; mc_filter[1] = mc_filter[0] = 0; netdev_for_each_mc_addr(ha, dev) { int bit_nr = ether_crc(ETH_ALEN, ha->addr) & 0x3f; mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); rx_mode |= AcceptMulticast; } } spin_lock_irqsave(&tp->lock, flags); SIS_W16(RxMacControl, rx_mode | 0x2); SIS_W32(RxHashTable, mc_filter[0]); SIS_W32(RxHashTable + 4, mc_filter[1]); spin_unlock_irqrestore(&tp->lock, flags); } static void sis190_soft_reset(void __iomem *ioaddr) { SIS_W32(IntrControl, 0x8000); SIS_PCI_COMMIT(); SIS_W32(IntrControl, 0x0); sis190_asic_down(ioaddr); } static void sis190_hw_start(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); void __iomem *ioaddr = tp->mmio_addr; sis190_soft_reset(ioaddr); SIS_W32(TxDescStartAddr, tp->tx_dma); SIS_W32(RxDescStartAddr, tp->rx_dma); SIS_W32(IntrStatus, 0xffffffff); SIS_W32(IntrMask, 0x0); SIS_W32(GMIIControl, 0x0); SIS_W32(TxMacControl, 0x60); SIS_W16(RxMacControl, 0x02); SIS_W32(RxHashTable, 0x0); SIS_W32(0x6c, 0x0); SIS_W32(RxWolCtrl, 0x0); SIS_W32(RxWolData, 0x0); SIS_PCI_COMMIT(); sis190_set_rx_mode(dev); /* Enable all known interrupts by setting the interrupt mask. */ SIS_W32(IntrMask, sis190_intr_mask); SIS_W32(TxControl, 0x1a00 | CmdTxEnb); SIS_W32(RxControl, 0x1a1d); netif_start_queue(dev); } static void sis190_phy_task(struct work_struct *work) { struct sis190_private *tp = container_of(work, struct sis190_private, phy_task); struct net_device *dev = tp->dev; void __iomem *ioaddr = tp->mmio_addr; int phy_id = tp->mii_if.phy_id; u16 val; rtnl_lock(); if (!netif_running(dev)) goto out_unlock; val = mdio_read(ioaddr, phy_id, MII_BMCR); if (val & BMCR_RESET) { // FIXME: needlessly high ? -- FR 02/07/2005 mod_timer(&tp->timer, jiffies + HZ/10); goto out_unlock; } val = mdio_read_latched(ioaddr, phy_id, MII_BMSR); if (!(val & BMSR_ANEGCOMPLETE) && tp->link_status != LNK_AUTONEG) { netif_carrier_off(dev); netif_warn(tp, link, dev, "auto-negotiating...\n"); tp->link_status = LNK_AUTONEG; } else if ((val & BMSR_LSTATUS) && tp->link_status != LNK_ON) { /* Rejoice ! */ struct { int val; u32 ctl; const char *msg; } reg31[] = { { LPA_1000FULL, 0x07000c00 | 0x00001000, "1000 Mbps Full Duplex" }, { LPA_1000HALF, 0x07000c00, "1000 Mbps Half Duplex" }, { LPA_100FULL, 0x04000800 | 0x00001000, "100 Mbps Full Duplex" }, { LPA_100HALF, 0x04000800, "100 Mbps Half Duplex" }, { LPA_10FULL, 0x04000400 | 0x00001000, "10 Mbps Full Duplex" }, { LPA_10HALF, 0x04000400, "10 Mbps Half Duplex" }, { 0, 0x04000400, "unknown" } }, *p = NULL; u16 adv, autoexp, gigadv, gigrec; val = mdio_read(ioaddr, phy_id, 0x1f); netif_info(tp, link, dev, "mii ext = %04x\n", val); val = mdio_read(ioaddr, phy_id, MII_LPA); adv = mdio_read(ioaddr, phy_id, MII_ADVERTISE); autoexp = mdio_read(ioaddr, phy_id, MII_EXPANSION); netif_info(tp, link, dev, "mii lpa=%04x adv=%04x exp=%04x\n", val, adv, autoexp); if (val & LPA_NPAGE && autoexp & EXPANSION_NWAY) { /* check for gigabit speed */ gigadv = mdio_read(ioaddr, phy_id, MII_CTRL1000); gigrec = mdio_read(ioaddr, phy_id, MII_STAT1000); val = (gigadv & (gigrec >> 2)); if (val & ADVERTISE_1000FULL) p = reg31; else if (val & ADVERTISE_1000HALF) p = reg31 + 1; } if (!p) { val &= adv; for (p = reg31; p->val; p++) { if ((val & p->val) == p->val) break; } } p->ctl |= SIS_R32(StationControl) & ~0x0f001c00; if ((tp->features & F_HAS_RGMII) && (tp->features & F_PHY_BCM5461)) { // Set Tx Delay in RGMII mode. mdio_write(ioaddr, phy_id, 0x18, 0xf1c7); udelay(200); mdio_write(ioaddr, phy_id, 0x1c, 0x8c00); p->ctl |= 0x03000000; } SIS_W32(StationControl, p->ctl); if (tp->features & F_HAS_RGMII) { SIS_W32(RGDelay, 0x0441); SIS_W32(RGDelay, 0x0440); } tp->negotiated_lpa = p->val; netif_info(tp, link, dev, "link on %s mode\n", p->msg); netif_carrier_on(dev); tp->link_status = LNK_ON; } else if (!(val & BMSR_LSTATUS) && tp->link_status != LNK_AUTONEG) tp->link_status = LNK_OFF; mod_timer(&tp->timer, jiffies + SIS190_PHY_TIMEOUT); out_unlock: rtnl_unlock(); } static void sis190_phy_timer(unsigned long __opaque) { struct net_device *dev = (struct net_device *)__opaque; struct sis190_private *tp = netdev_priv(dev); if (likely(netif_running(dev))) schedule_work(&tp->phy_task); } static inline void sis190_delete_timer(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); del_timer_sync(&tp->timer); } static inline void sis190_request_timer(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); struct timer_list *timer = &tp->timer; init_timer(timer); timer->expires = jiffies + SIS190_PHY_TIMEOUT; timer->data = (unsigned long)dev; timer->function = sis190_phy_timer; add_timer(timer); } static void sis190_set_rxbufsize(struct sis190_private *tp, struct net_device *dev) { unsigned int mtu = dev->mtu; tp->rx_buf_sz = (mtu > RX_BUF_SIZE) ? mtu + ETH_HLEN + 8 : RX_BUF_SIZE; /* RxDesc->size has a licence to kill the lower bits */ if (tp->rx_buf_sz & 0x07) { tp->rx_buf_sz += 8; tp->rx_buf_sz &= RX_BUF_MASK; } } static int sis190_open(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); struct pci_dev *pdev = tp->pci_dev; int rc = -ENOMEM; sis190_set_rxbufsize(tp, dev); /* * Rx and Tx descriptors need 256 bytes alignment. * pci_alloc_consistent() guarantees a stronger alignment. */ tp->TxDescRing = pci_alloc_consistent(pdev, TX_RING_BYTES, &tp->tx_dma); if (!tp->TxDescRing) goto out; tp->RxDescRing = pci_alloc_consistent(pdev, RX_RING_BYTES, &tp->rx_dma); if (!tp->RxDescRing) goto err_free_tx_0; rc = sis190_init_ring(dev); if (rc < 0) goto err_free_rx_1; sis190_request_timer(dev); rc = request_irq(pdev->irq, sis190_irq, IRQF_SHARED, dev->name, dev); if (rc < 0) goto err_release_timer_2; sis190_hw_start(dev); out: return rc; err_release_timer_2: sis190_delete_timer(dev); sis190_rx_clear(tp); err_free_rx_1: pci_free_consistent(pdev, RX_RING_BYTES, tp->RxDescRing, tp->rx_dma); err_free_tx_0: pci_free_consistent(pdev, TX_RING_BYTES, tp->TxDescRing, tp->tx_dma); goto out; } static void sis190_tx_clear(struct sis190_private *tp) { unsigned int i; for (i = 0; i < NUM_TX_DESC; i++) { struct sk_buff *skb = tp->Tx_skbuff[i]; if (!skb) continue; sis190_unmap_tx_skb(tp->pci_dev, skb, tp->TxDescRing + i); tp->Tx_skbuff[i] = NULL; dev_kfree_skb(skb); tp->dev->stats.tx_dropped++; } tp->cur_tx = tp->dirty_tx = 0; } static void sis190_down(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); void __iomem *ioaddr = tp->mmio_addr; unsigned int poll_locked = 0; sis190_delete_timer(dev); netif_stop_queue(dev); do { spin_lock_irq(&tp->lock); sis190_asic_down(ioaddr); spin_unlock_irq(&tp->lock); synchronize_irq(tp->pci_dev->irq); if (!poll_locked) poll_locked++; synchronize_sched(); } while (SIS_R32(IntrMask)); sis190_tx_clear(tp); sis190_rx_clear(tp); } static int sis190_close(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); struct pci_dev *pdev = tp->pci_dev; sis190_down(dev); free_irq(pdev->irq, dev); pci_free_consistent(pdev, TX_RING_BYTES, tp->TxDescRing, tp->tx_dma); pci_free_consistent(pdev, RX_RING_BYTES, tp->RxDescRing, tp->rx_dma); tp->TxDescRing = NULL; tp->RxDescRing = NULL; return 0; } static netdev_tx_t sis190_start_xmit(struct sk_buff *skb, struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); void __iomem *ioaddr = tp->mmio_addr; u32 len, entry, dirty_tx; struct TxDesc *desc; dma_addr_t mapping; if (unlikely(skb->len < ETH_ZLEN)) { if (skb_padto(skb, ETH_ZLEN)) { dev->stats.tx_dropped++; goto out; } len = ETH_ZLEN; } else { len = skb->len; } entry = tp->cur_tx % NUM_TX_DESC; desc = tp->TxDescRing + entry; if (unlikely(le32_to_cpu(desc->status) & OWNbit)) { netif_stop_queue(dev); netif_err(tp, tx_err, dev, "BUG! Tx Ring full when queue awake!\n"); return NETDEV_TX_BUSY; } mapping = pci_map_single(tp->pci_dev, skb->data, len, PCI_DMA_TODEVICE); if (pci_dma_mapping_error(tp->pci_dev, mapping)) { netif_err(tp, tx_err, dev, "PCI mapping failed, dropping packet"); return NETDEV_TX_BUSY; } tp->Tx_skbuff[entry] = skb; desc->PSize = cpu_to_le32(len); desc->addr = cpu_to_le32(mapping); desc->size = cpu_to_le32(len); if (entry == (NUM_TX_DESC - 1)) desc->size |= cpu_to_le32(RingEnd); wmb(); desc->status = cpu_to_le32(OWNbit | INTbit | DEFbit | CRCbit | PADbit); if (tp->negotiated_lpa & (LPA_1000HALF | LPA_100HALF | LPA_10HALF)) { /* Half Duplex */ desc->status |= cpu_to_le32(COLEN | CRSEN | BKFEN); if (tp->negotiated_lpa & (LPA_1000HALF | LPA_1000FULL)) desc->status |= cpu_to_le32(EXTEN | BSTEN); /* gigabit HD */ } tp->cur_tx++; smp_wmb(); SIS_W32(TxControl, 0x1a00 | CmdReset | CmdTxEnb); dirty_tx = tp->dirty_tx; if ((tp->cur_tx - NUM_TX_DESC) == dirty_tx) { netif_stop_queue(dev); smp_rmb(); if (dirty_tx != tp->dirty_tx) netif_wake_queue(dev); } out: return NETDEV_TX_OK; } static void sis190_free_phy(struct list_head *first_phy) { struct sis190_phy *cur, *next; list_for_each_entry_safe(cur, next, first_phy, list) { kfree(cur); } } /** * sis190_default_phy - Select default PHY for sis190 mac. * @dev: the net device to probe for * * Select first detected PHY with link as default. * If no one is link on, select PHY whose types is HOME as default. * If HOME doesn't exist, select LAN. */ static u16 sis190_default_phy(struct net_device *dev) { struct sis190_phy *phy, *phy_home, *phy_default, *phy_lan; struct sis190_private *tp = netdev_priv(dev); struct mii_if_info *mii_if = &tp->mii_if; void __iomem *ioaddr = tp->mmio_addr; u16 status; phy_home = phy_default = phy_lan = NULL; list_for_each_entry(phy, &tp->first_phy, list) { status = mdio_read_latched(ioaddr, phy->phy_id, MII_BMSR); // Link ON & Not select default PHY & not ghost PHY. if ((status & BMSR_LSTATUS) && !phy_default && (phy->type != UNKNOWN)) { phy_default = phy; } else { status = mdio_read(ioaddr, phy->phy_id, MII_BMCR); mdio_write(ioaddr, phy->phy_id, MII_BMCR, status | BMCR_ANENABLE | BMCR_ISOLATE); if (phy->type == HOME) phy_home = phy; else if (phy->type == LAN) phy_lan = phy; } } if (!phy_default) { if (phy_home) phy_default = phy_home; else if (phy_lan) phy_default = phy_lan; else phy_default = list_first_entry(&tp->first_phy, struct sis190_phy, list); } if (mii_if->phy_id != phy_default->phy_id) { mii_if->phy_id = phy_default->phy_id; if (netif_msg_probe(tp)) pr_info("%s: Using transceiver at address %d as default\n", pci_name(tp->pci_dev), mii_if->phy_id); } status = mdio_read(ioaddr, mii_if->phy_id, MII_BMCR); status &= (~BMCR_ISOLATE); mdio_write(ioaddr, mii_if->phy_id, MII_BMCR, status); status = mdio_read_latched(ioaddr, mii_if->phy_id, MII_BMSR); return status; } static void sis190_init_phy(struct net_device *dev, struct sis190_private *tp, struct sis190_phy *phy, unsigned int phy_id, u16 mii_status) { void __iomem *ioaddr = tp->mmio_addr; struct mii_chip_info *p; INIT_LIST_HEAD(&phy->list); phy->status = mii_status; phy->phy_id = phy_id; phy->id[0] = mdio_read(ioaddr, phy_id, MII_PHYSID1); phy->id[1] = mdio_read(ioaddr, phy_id, MII_PHYSID2); for (p = mii_chip_table; p->type; p++) { if ((p->id[0] == phy->id[0]) && (p->id[1] == (phy->id[1] & 0xfff0))) { break; } } if (p->id[1]) { phy->type = (p->type == MIX) ? ((mii_status & (BMSR_100FULL | BMSR_100HALF)) ? LAN : HOME) : p->type; tp->features |= p->feature; if (netif_msg_probe(tp)) pr_info("%s: %s transceiver at address %d\n", pci_name(tp->pci_dev), p->name, phy_id); } else { phy->type = UNKNOWN; if (netif_msg_probe(tp)) pr_info("%s: unknown PHY 0x%x:0x%x transceiver at address %d\n", pci_name(tp->pci_dev), phy->id[0], (phy->id[1] & 0xfff0), phy_id); } } static void sis190_mii_probe_88e1111_fixup(struct sis190_private *tp) { if (tp->features & F_PHY_88E1111) { void __iomem *ioaddr = tp->mmio_addr; int phy_id = tp->mii_if.phy_id; u16 reg[2][2] = { { 0x808b, 0x0ce1 }, { 0x808f, 0x0c60 } }, *p; p = (tp->features & F_HAS_RGMII) ? reg[0] : reg[1]; mdio_write(ioaddr, phy_id, 0x1b, p[0]); udelay(200); mdio_write(ioaddr, phy_id, 0x14, p[1]); udelay(200); } } /** * sis190_mii_probe - Probe MII PHY for sis190 * @dev: the net device to probe for * * Search for total of 32 possible mii phy addresses. * Identify and set current phy if found one, * return error if it failed to found. */ static int sis190_mii_probe(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); struct mii_if_info *mii_if = &tp->mii_if; void __iomem *ioaddr = tp->mmio_addr; int phy_id; int rc = 0; INIT_LIST_HEAD(&tp->first_phy); for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) { struct sis190_phy *phy; u16 status; status = mdio_read_latched(ioaddr, phy_id, MII_BMSR); // Try next mii if the current one is not accessible. if (status == 0xffff || status == 0x0000) continue; phy = kmalloc(sizeof(*phy), GFP_KERNEL); if (!phy) { sis190_free_phy(&tp->first_phy); rc = -ENOMEM; goto out; } sis190_init_phy(dev, tp, phy, phy_id, status); list_add(&tp->first_phy, &phy->list); } if (list_empty(&tp->first_phy)) { if (netif_msg_probe(tp)) pr_info("%s: No MII transceivers found!\n", pci_name(tp->pci_dev)); rc = -EIO; goto out; } /* Select default PHY for mac */ sis190_default_phy(dev); sis190_mii_probe_88e1111_fixup(tp); mii_if->dev = dev; mii_if->mdio_read = __mdio_read; mii_if->mdio_write = __mdio_write; mii_if->phy_id_mask = PHY_ID_ANY; mii_if->reg_num_mask = MII_REG_ANY; out: return rc; } static void sis190_mii_remove(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); sis190_free_phy(&tp->first_phy); } static void sis190_release_board(struct pci_dev *pdev) { struct net_device *dev = pci_get_drvdata(pdev); struct sis190_private *tp = netdev_priv(dev); iounmap(tp->mmio_addr); pci_release_regions(pdev); pci_disable_device(pdev); free_netdev(dev); } static struct net_device *sis190_init_board(struct pci_dev *pdev) { struct sis190_private *tp; struct net_device *dev; void __iomem *ioaddr; int rc; dev = alloc_etherdev(sizeof(*tp)); if (!dev) { rc = -ENOMEM; goto err_out_0; } SET_NETDEV_DEV(dev, &pdev->dev); tp = netdev_priv(dev); tp->dev = dev; tp->msg_enable = netif_msg_init(debug.msg_enable, SIS190_MSG_DEFAULT); rc = pci_enable_device(pdev); if (rc < 0) { if (netif_msg_probe(tp)) pr_err("%s: enable failure\n", pci_name(pdev)); goto err_free_dev_1; } rc = -ENODEV; if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { if (netif_msg_probe(tp)) pr_err("%s: region #0 is no MMIO resource\n", pci_name(pdev)); goto err_pci_disable_2; } if (pci_resource_len(pdev, 0) < SIS190_REGS_SIZE) { if (netif_msg_probe(tp)) pr_err("%s: invalid PCI region size(s)\n", pci_name(pdev)); goto err_pci_disable_2; } rc = pci_request_regions(pdev, DRV_NAME); if (rc < 0) { if (netif_msg_probe(tp)) pr_err("%s: could not request regions\n", pci_name(pdev)); goto err_pci_disable_2; } rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); if (rc < 0) { if (netif_msg_probe(tp)) pr_err("%s: DMA configuration failed\n", pci_name(pdev)); goto err_free_res_3; } pci_set_master(pdev); ioaddr = ioremap(pci_resource_start(pdev, 0), SIS190_REGS_SIZE); if (!ioaddr) { if (netif_msg_probe(tp)) pr_err("%s: cannot remap MMIO, aborting\n", pci_name(pdev)); rc = -EIO; goto err_free_res_3; } tp->pci_dev = pdev; tp->mmio_addr = ioaddr; tp->link_status = LNK_OFF; sis190_irq_mask_and_ack(ioaddr); sis190_soft_reset(ioaddr); out: return dev; err_free_res_3: pci_release_regions(pdev); err_pci_disable_2: pci_disable_device(pdev); err_free_dev_1: free_netdev(dev); err_out_0: dev = ERR_PTR(rc); goto out; } static void sis190_tx_timeout(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); void __iomem *ioaddr = tp->mmio_addr; u8 tmp8; /* Disable Tx, if not already */ tmp8 = SIS_R8(TxControl); if (tmp8 & CmdTxEnb) SIS_W8(TxControl, tmp8 & ~CmdTxEnb); netif_info(tp, tx_err, dev, "Transmit timeout, status %08x %08x\n", SIS_R32(TxControl), SIS_R32(TxSts)); /* Disable interrupts by clearing the interrupt mask. */ SIS_W32(IntrMask, 0x0000); /* Stop a shared interrupt from scavenging while we are. */ spin_lock_irq(&tp->lock); sis190_tx_clear(tp); spin_unlock_irq(&tp->lock); /* ...and finally, reset everything. */ sis190_hw_start(dev); netif_wake_queue(dev); } static void sis190_set_rgmii(struct sis190_private *tp, u8 reg) { tp->features |= (reg & 0x80) ? F_HAS_RGMII : 0; } static int sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev, struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); void __iomem *ioaddr = tp->mmio_addr; u16 sig; int i; if (netif_msg_probe(tp)) pr_info("%s: Read MAC address from EEPROM\n", pci_name(pdev)); /* Check to see if there is a sane EEPROM */ sig = (u16) sis190_read_eeprom(ioaddr, EEPROMSignature); if ((sig == 0xffff) || (sig == 0x0000)) { if (netif_msg_probe(tp)) pr_info("%s: Error EEPROM read %x\n", pci_name(pdev), sig); return -EIO; } /* Get MAC address from EEPROM */ for (i = 0; i < ETH_ALEN / 2; i++) { u16 w = sis190_read_eeprom(ioaddr, EEPROMMACAddr + i); ((__le16 *)dev->dev_addr)[i] = cpu_to_le16(w); } sis190_set_rgmii(tp, sis190_read_eeprom(ioaddr, EEPROMInfo)); return 0; } /** * sis190_get_mac_addr_from_apc - Get MAC address for SiS96x model * @pdev: PCI device * @dev: network device to get address for * * SiS96x model, use APC CMOS RAM to store MAC address. * APC CMOS RAM is accessed through ISA bridge. * MAC address is read into @net_dev->dev_addr. */ static int sis190_get_mac_addr_from_apc(struct pci_dev *pdev, struct net_device *dev) { static const u16 ids[] = { 0x0965, 0x0966, 0x0968 }; struct sis190_private *tp = netdev_priv(dev); struct pci_dev *isa_bridge; u8 reg, tmp8; unsigned int i; if (netif_msg_probe(tp)) pr_info("%s: Read MAC address from APC\n", pci_name(pdev)); for (i = 0; i < ARRAY_SIZE(ids); i++) { isa_bridge = pci_get_device(PCI_VENDOR_ID_SI, ids[i], NULL); if (isa_bridge) break; } if (!isa_bridge) { if (netif_msg_probe(tp)) pr_info("%s: Can not find ISA bridge\n", pci_name(pdev)); return -EIO; } /* Enable port 78h & 79h to access APC Registers. */ pci_read_config_byte(isa_bridge, 0x48, &tmp8); reg = (tmp8 & ~0x02); pci_write_config_byte(isa_bridge, 0x48, reg); udelay(50); pci_read_config_byte(isa_bridge, 0x48, &reg); for (i = 0; i < ETH_ALEN; i++) { outb(0x9 + i, 0x78); dev->dev_addr[i] = inb(0x79); } outb(0x12, 0x78); reg = inb(0x79); sis190_set_rgmii(tp, reg); /* Restore the value to ISA Bridge */ pci_write_config_byte(isa_bridge, 0x48, tmp8); pci_dev_put(isa_bridge); return 0; } /** * sis190_init_rxfilter - Initialize the Rx filter * @dev: network device to initialize * * Set receive filter address to our MAC address * and enable packet filtering. */ static inline void sis190_init_rxfilter(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); void __iomem *ioaddr = tp->mmio_addr; u16 ctl; int i; ctl = SIS_R16(RxMacControl); /* * Disable packet filtering before setting filter. * Note: SiS's driver writes 32 bits but RxMacControl is 16 bits * only and followed by RxMacAddr (6 bytes). Strange. -- FR */ SIS_W16(RxMacControl, ctl & ~0x0f00); for (i = 0; i < ETH_ALEN; i++) SIS_W8(RxMacAddr + i, dev->dev_addr[i]); SIS_W16(RxMacControl, ctl); SIS_PCI_COMMIT(); } static int sis190_get_mac_addr(struct pci_dev *pdev, struct net_device *dev) { int rc; rc = sis190_get_mac_addr_from_eeprom(pdev, dev); if (rc < 0) { u8 reg; pci_read_config_byte(pdev, 0x73, &reg); if (reg & 0x00000001) rc = sis190_get_mac_addr_from_apc(pdev, dev); } return rc; } static void sis190_set_speed_auto(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); void __iomem *ioaddr = tp->mmio_addr; int phy_id = tp->mii_if.phy_id; int val; netif_info(tp, link, dev, "Enabling Auto-negotiation\n"); val = mdio_read(ioaddr, phy_id, MII_ADVERTISE); // Enable 10/100 Full/Half Mode, leave MII_ADVERTISE bit4:0 // unchanged. mdio_write(ioaddr, phy_id, MII_ADVERTISE, (val & ADVERTISE_SLCT) | ADVERTISE_100FULL | ADVERTISE_10FULL | ADVERTISE_100HALF | ADVERTISE_10HALF); // Enable 1000 Full Mode. mdio_write(ioaddr, phy_id, MII_CTRL1000, ADVERTISE_1000FULL); // Enable auto-negotiation and restart auto-negotiation. mdio_write(ioaddr, phy_id, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART | BMCR_RESET); } static int sis190_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) { struct sis190_private *tp = netdev_priv(dev); return mii_ethtool_gset(&tp->mii_if, cmd); } static int sis190_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) { struct sis190_private *tp = netdev_priv(dev); return mii_ethtool_sset(&tp->mii_if, cmd); } static void sis190_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) { struct sis190_private *tp = netdev_priv(dev); strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); strlcpy(info->version, DRV_VERSION, sizeof(info->version)); strlcpy(info->bus_info, pci_name(tp->pci_dev), sizeof(info->bus_info)); } static int sis190_get_regs_len(struct net_device *dev) { return SIS190_REGS_SIZE; } static void sis190_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p) { struct sis190_private *tp = netdev_priv(dev); unsigned long flags; if (regs->len > SIS190_REGS_SIZE) regs->len = SIS190_REGS_SIZE; spin_lock_irqsave(&tp->lock, flags); memcpy_fromio(p, tp->mmio_addr, regs->len); spin_unlock_irqrestore(&tp->lock, flags); } static int sis190_nway_reset(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); return mii_nway_restart(&tp->mii_if); } static u32 sis190_get_msglevel(struct net_device *dev) { struct sis190_private *tp = netdev_priv(dev); return tp->msg_enable; } static void sis190_set_msglevel(struct net_device *dev, u32 value) { struct sis190_private *tp = netdev_priv(dev); tp->msg_enable = value; } static const struct ethtool_ops sis190_ethtool_ops = { .get_settings = sis190_get_settings, .set_settings = sis190_set_settings, .get_drvinfo = sis190_get_drvinfo, .get_regs_len = sis190_get_regs_len, .get_regs = sis190_get_regs, .get_link = ethtool_op_get_link, .get_msglevel = sis190_get_msglevel, .set_msglevel = sis190_set_msglevel, .nway_reset = sis190_nway_reset, }; static int sis190_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { struct sis190_private *tp = netdev_priv(dev); return !netif_running(dev) ? -EINVAL : generic_mii_ioctl(&tp->mii_if, if_mii(ifr), cmd, NULL); } static int sis190_mac_addr(struct net_device *dev, void *p) { int rc; rc = eth_mac_addr(dev, p); if (!rc) sis190_init_rxfilter(dev); return rc; } static const struct net_device_ops sis190_netdev_ops = { .ndo_open = sis190_open, .ndo_stop = sis190_close, .ndo_do_ioctl = sis190_ioctl, .ndo_start_xmit = sis190_start_xmit, .ndo_tx_timeout = sis190_tx_timeout, .ndo_set_rx_mode = sis190_set_rx_mode, .ndo_change_mtu = eth_change_mtu, .ndo_set_mac_address = sis190_mac_addr, .ndo_validate_addr = eth_validate_addr, #ifdef CONFIG_NET_POLL_CONTROLLER .ndo_poll_controller = sis190_netpoll, #endif }; static int sis190_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { static int printed_version = 0; struct sis190_private *tp; struct net_device *dev; void __iomem *ioaddr; int rc; if (!printed_version) { if (netif_msg_drv(&debug)) pr_info(SIS190_DRIVER_NAME " loaded\n"); printed_version = 1; } dev = sis190_init_board(pdev); if (IS_ERR(dev)) { rc = PTR_ERR(dev); goto out; } pci_set_drvdata(pdev, dev); tp = netdev_priv(dev); ioaddr = tp->mmio_addr; rc = sis190_get_mac_addr(pdev, dev); if (rc < 0) goto err_release_board; sis190_init_rxfilter(dev); INIT_WORK(&tp->phy_task, sis190_phy_task); dev->netdev_ops = &sis190_netdev_ops; SET_ETHTOOL_OPS(dev, &sis190_ethtool_ops); dev->watchdog_timeo = SIS190_TX_TIMEOUT; spin_lock_init(&tp->lock); rc = sis190_mii_probe(dev); if (rc < 0) goto err_release_board; rc = register_netdev(dev); if (rc < 0) goto err_remove_mii; if (netif_msg_probe(tp)) { netdev_info(dev, "%s: %s at %p (IRQ: %d), %pM\n", pci_name(pdev), sis_chip_info[ent->driver_data].name, ioaddr, pdev->irq, dev->dev_addr); netdev_info(dev, "%s mode.\n", (tp->features & F_HAS_RGMII) ? "RGMII" : "GMII"); } netif_carrier_off(dev); sis190_set_speed_auto(dev); out: return rc; err_remove_mii: sis190_mii_remove(dev); err_release_board: sis190_release_board(pdev); goto out; } static void sis190_remove_one(struct pci_dev *pdev) { struct net_device *dev = pci_get_drvdata(pdev); struct sis190_private *tp = netdev_priv(dev); sis190_mii_remove(dev); cancel_work_sync(&tp->phy_task); unregister_netdev(dev); sis190_release_board(pdev); pci_set_drvdata(pdev, NULL); } static struct pci_driver sis190_pci_driver = { .name = DRV_NAME, .id_table = sis190_pci_tbl, .probe = sis190_init_one, .remove = sis190_remove_one, }; static int __init sis190_init_module(void) { return pci_register_driver(&sis190_pci_driver); } static void __exit sis190_cleanup_module(void) { pci_unregister_driver(&sis190_pci_driver); } module_init(sis190_init_module); module_exit(sis190_cleanup_module);
gpl-2.0
NebulaOy/linux
drivers/isdn/i4l/isdn_tty.c
2750
91354
/* * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel). * * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de) * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg * * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * */ #undef ISDN_TTY_STAT_DEBUG #include <linux/isdn.h> #include <linux/serial.h> /* ASYNC_* flags */ #include <linux/slab.h> #include <linux/delay.h> #include <linux/mutex.h> #include "isdn_common.h" #include "isdn_tty.h" #ifdef CONFIG_ISDN_AUDIO #include "isdn_audio.h" #define VBUF 0x3e0 #define VBUFX (VBUF/16) #endif #define FIX_FILE_TRANSFER #define DUMMY_HAYES_AT /* Prototypes */ static DEFINE_MUTEX(modem_info_mutex); static int isdn_tty_edit_at(const char *, int, modem_info *); static void isdn_tty_check_esc(const u_char *, u_char, int, int *, u_long *); static void isdn_tty_modem_reset_regs(modem_info *, int); static void isdn_tty_cmd_ATA(modem_info *); static void isdn_tty_flush_buffer(struct tty_struct *); static void isdn_tty_modem_result(int, modem_info *); #ifdef CONFIG_ISDN_AUDIO static int isdn_tty_countDLE(unsigned char *, int); #endif /* Leave this unchanged unless you know what you do! */ #define MODEM_PARANOIA_CHECK #define MODEM_DO_RESTART static int bit2si[8] = {1, 5, 7, 7, 7, 7, 7, 7}; static int si2bit[8] = {4, 1, 4, 4, 4, 4, 4, 4}; /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb() * to stuff incoming data directly into a tty's flip-buffer. This * is done to speed up tty-receiving if the receive-queue is empty. * This routine MUST be called with interrupts off. * Return: * 1 = Success * 0 = Failure, data has to be buffered and later processed by * isdn_tty_readmodem(). */ static int isdn_tty_try_read(modem_info *info, struct sk_buff *skb) { struct tty_port *port = &info->port; int c; int len; char last; if (!info->online) return 0; if (!(info->mcr & UART_MCR_RTS)) return 0; len = skb->len #ifdef CONFIG_ISDN_AUDIO + ISDN_AUDIO_SKB_DLECOUNT(skb) #endif ; c = tty_buffer_request_room(port, len); if (c < len) return 0; #ifdef CONFIG_ISDN_AUDIO if (ISDN_AUDIO_SKB_DLECOUNT(skb)) { int l = skb->len; unsigned char *dp = skb->data; while (--l) { if (*dp == DLE) tty_insert_flip_char(port, DLE, 0); tty_insert_flip_char(port, *dp++, 0); } if (*dp == DLE) tty_insert_flip_char(port, DLE, 0); last = *dp; } else { #endif if (len > 1) tty_insert_flip_string(port, skb->data, len - 1); last = skb->data[len - 1]; #ifdef CONFIG_ISDN_AUDIO } #endif if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP) tty_insert_flip_char(port, last, 0xFF); else tty_insert_flip_char(port, last, TTY_NORMAL); tty_flip_buffer_push(port); kfree_skb(skb); return 1; } /* isdn_tty_readmodem() is called periodically from within timer-interrupt. * It tries getting received data from the receive queue an stuff it into * the tty's flip-buffer. */ void isdn_tty_readmodem(void) { int resched = 0; int midx; int i; int r; modem_info *info; for (i = 0; i < ISDN_MAX_CHANNELS; i++) { midx = dev->m_idx[i]; if (midx < 0) continue; info = &dev->mdm.info[midx]; if (!info->online) continue; r = 0; #ifdef CONFIG_ISDN_AUDIO isdn_audio_eval_dtmf(info); if ((info->vonline & 1) && (info->emu.vpar[1])) isdn_audio_eval_silence(info); #endif if (info->mcr & UART_MCR_RTS) { /* CISCO AsyncPPP Hack */ if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP)) r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, &info->port, 0); else r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, &info->port, 1); if (r) tty_flip_buffer_push(&info->port); } else r = 1; if (r) { info->rcvsched = 0; resched = 1; } else info->rcvsched = 1; } if (!resched) isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0); } int isdn_tty_rcv_skb(int i, int di, int channel, struct sk_buff *skb) { ulong flags; int midx; #ifdef CONFIG_ISDN_AUDIO int ifmt; #endif modem_info *info; if ((midx = dev->m_idx[i]) < 0) { /* if midx is invalid, packet is not for tty */ return 0; } info = &dev->mdm.info[midx]; #ifdef CONFIG_ISDN_AUDIO ifmt = 1; if ((info->vonline) && (!info->emu.vpar[4])) isdn_audio_calc_dtmf(info, skb->data, skb->len, ifmt); if ((info->vonline & 1) && (info->emu.vpar[1])) isdn_audio_calc_silence(info, skb->data, skb->len, ifmt); #endif if ((info->online < 2) #ifdef CONFIG_ISDN_AUDIO && (!(info->vonline & 1)) #endif ) { /* If Modem not listening, drop data */ kfree_skb(skb); return 1; } if (info->emu.mdmreg[REG_T70] & BIT_T70) { if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) { /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */ if (skb->data[0] == 3) /* pure data packet -> 4 byte headers */ skb_pull(skb, 4); else if (skb->data[0] == 1) /* keepalive packet -> 2 byte hdr */ skb_pull(skb, 2); } else /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */ if ((skb->data[0] == 1) && ((skb->data[1] == 0) || (skb->data[1] == 1))) skb_pull(skb, 4); } #ifdef CONFIG_ISDN_AUDIO ISDN_AUDIO_SKB_DLECOUNT(skb) = 0; ISDN_AUDIO_SKB_LOCK(skb) = 0; if (info->vonline & 1) { /* voice conversion/compression */ switch (info->emu.vpar[3]) { case 2: case 3: case 4: /* adpcm * Since compressed data takes less * space, we can overwrite the buffer. */ skb_trim(skb, isdn_audio_xlaw2adpcm(info->adpcmr, ifmt, skb->data, skb->data, skb->len)); break; case 5: /* a-law */ if (!ifmt) isdn_audio_ulaw2alaw(skb->data, skb->len); break; case 6: /* u-law */ if (ifmt) isdn_audio_alaw2ulaw(skb->data, skb->len); break; } ISDN_AUDIO_SKB_DLECOUNT(skb) = isdn_tty_countDLE(skb->data, skb->len); } #ifdef CONFIG_ISDN_TTY_FAX else { if (info->faxonline & 2) { isdn_tty_fax_bitorder(info, skb); ISDN_AUDIO_SKB_DLECOUNT(skb) = isdn_tty_countDLE(skb->data, skb->len); } } #endif #endif /* Try to deliver directly via tty-buf if queue is empty */ spin_lock_irqsave(&info->readlock, flags); if (skb_queue_empty(&dev->drv[di]->rpqueue[channel])) if (isdn_tty_try_read(info, skb)) { spin_unlock_irqrestore(&info->readlock, flags); return 1; } /* Direct deliver failed or queue wasn't empty. * Queue up for later dequeueing via timer-irq. */ __skb_queue_tail(&dev->drv[di]->rpqueue[channel], skb); dev->drv[di]->rcvcount[channel] += (skb->len #ifdef CONFIG_ISDN_AUDIO + ISDN_AUDIO_SKB_DLECOUNT(skb) #endif ); spin_unlock_irqrestore(&info->readlock, flags); /* Schedule dequeuing */ if ((dev->modempoll) && (info->rcvsched)) isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1); return 1; } static void isdn_tty_cleanup_xmit(modem_info *info) { skb_queue_purge(&info->xmit_queue); #ifdef CONFIG_ISDN_AUDIO skb_queue_purge(&info->dtmf_queue); #endif } static void isdn_tty_tint(modem_info *info) { struct sk_buff *skb = skb_dequeue(&info->xmit_queue); int len, slen; if (!skb) return; len = skb->len; if ((slen = isdn_writebuf_skb_stub(info->isdn_driver, info->isdn_channel, 1, skb)) == len) { struct tty_struct *tty = info->port.tty; info->send_outstanding++; info->msr &= ~UART_MSR_CTS; info->lsr &= ~UART_LSR_TEMT; tty_wakeup(tty); return; } if (slen < 0) { /* Error: no channel, already shutdown, or wrong parameter */ dev_kfree_skb(skb); return; } skb_queue_head(&info->xmit_queue, skb); } #ifdef CONFIG_ISDN_AUDIO static int isdn_tty_countDLE(unsigned char *buf, int len) { int count = 0; while (len--) if (*buf++ == DLE) count++; return count; } /* This routine is called from within isdn_tty_write() to perform * DLE-decoding when sending audio-data. */ static int isdn_tty_handleDLEdown(modem_info *info, atemu *m, int len) { unsigned char *p = &info->port.xmit_buf[info->xmit_count]; int count = 0; while (len > 0) { if (m->lastDLE) { m->lastDLE = 0; switch (*p) { case DLE: /* Escape code */ if (len > 1) memmove(p, p + 1, len - 1); p--; count++; break; case ETX: /* End of data */ info->vonline |= 4; return count; case DC4: /* Abort RX */ info->vonline &= ~1; #ifdef ISDN_DEBUG_MODEM_VOICE printk(KERN_DEBUG "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n", info->line); #endif isdn_tty_at_cout("\020\003", info); if (!info->vonline) { #ifdef ISDN_DEBUG_MODEM_VOICE printk(KERN_DEBUG "DLEdown: send VCON on ttyI%d\n", info->line); #endif isdn_tty_at_cout("\r\nVCON\r\n", info); } /* Fall through */ case 'q': case 's': /* Silence */ if (len > 1) memmove(p, p + 1, len - 1); p--; break; } } else { if (*p == DLE) m->lastDLE = 1; else count++; } p++; len--; } if (len < 0) { printk(KERN_WARNING "isdn_tty: len<0 in DLEdown\n"); return 0; } return count; } /* This routine is called from within isdn_tty_write() when receiving * audio-data. It interrupts receiving, if an character other than * ^S or ^Q is sent. */ static int isdn_tty_end_vrx(const char *buf, int c) { char ch; while (c--) { ch = *buf; if ((ch != 0x11) && (ch != 0x13)) return 1; buf++; } return 0; } static int voice_cf[7] = {0, 0, 4, 3, 2, 0, 0}; #endif /* CONFIG_ISDN_AUDIO */ /* isdn_tty_senddown() is called either directly from within isdn_tty_write() * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls * outgoing data from the tty's xmit-buffer, handles voice-decompression or * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint. */ static void isdn_tty_senddown(modem_info *info) { int buflen; int skb_res; #ifdef CONFIG_ISDN_AUDIO int audio_len; #endif struct sk_buff *skb; #ifdef CONFIG_ISDN_AUDIO if (info->vonline & 4) { info->vonline &= ~6; if (!info->vonline) { #ifdef ISDN_DEBUG_MODEM_VOICE printk(KERN_DEBUG "senddown: send VCON on ttyI%d\n", info->line); #endif isdn_tty_at_cout("\r\nVCON\r\n", info); } } #endif if (!(buflen = info->xmit_count)) return; if ((info->emu.mdmreg[REG_CTS] & BIT_CTS) != 0) info->msr &= ~UART_MSR_CTS; info->lsr &= ~UART_LSR_TEMT; /* info->xmit_count is modified here and in isdn_tty_write(). * So we return here if isdn_tty_write() is in the * critical section. */ atomic_inc(&info->xmit_lock); if (!(atomic_dec_and_test(&info->xmit_lock))) return; if (info->isdn_driver < 0) { info->xmit_count = 0; return; } skb_res = dev->drv[info->isdn_driver]->interface->hl_hdrlen + 4; #ifdef CONFIG_ISDN_AUDIO if (info->vonline & 2) audio_len = buflen * voice_cf[info->emu.vpar[3]]; else audio_len = 0; skb = dev_alloc_skb(skb_res + buflen + audio_len); #else skb = dev_alloc_skb(skb_res + buflen); #endif if (!skb) { printk(KERN_WARNING "isdn_tty: Out of memory in ttyI%d senddown\n", info->line); return; } skb_reserve(skb, skb_res); memcpy(skb_put(skb, buflen), info->port.xmit_buf, buflen); info->xmit_count = 0; #ifdef CONFIG_ISDN_AUDIO if (info->vonline & 2) { /* For now, ifmt is fixed to 1 (alaw), since this * is used with ISDN everywhere in the world, except * US, Canada and Japan. * Later, when US-ISDN protocols are implemented, * this setting will depend on the D-channel protocol. */ int ifmt = 1; /* voice conversion/decompression */ switch (info->emu.vpar[3]) { case 2: case 3: case 4: /* adpcm, compatible to ZyXel 1496 modem * with ROM revision 6.01 */ audio_len = isdn_audio_adpcm2xlaw(info->adpcms, ifmt, skb->data, skb_put(skb, audio_len), buflen); skb_pull(skb, buflen); skb_trim(skb, audio_len); break; case 5: /* a-law */ if (!ifmt) isdn_audio_alaw2ulaw(skb->data, buflen); break; case 6: /* u-law */ if (ifmt) isdn_audio_ulaw2alaw(skb->data, buflen); break; } } #endif /* CONFIG_ISDN_AUDIO */ if (info->emu.mdmreg[REG_T70] & BIT_T70) { /* Add T.70 simplified header */ if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) memcpy(skb_push(skb, 2), "\1\0", 2); else memcpy(skb_push(skb, 4), "\1\0\1\0", 4); } skb_queue_tail(&info->xmit_queue, skb); } /************************************************************ * * Modem-functions * * mostly "stolen" from original Linux-serial.c and friends. * ************************************************************/ /* The next routine is called once from within timer-interrupt * triggered within isdn_tty_modem_ncarrier(). It calls * isdn_tty_modem_result() to stuff a "NO CARRIER" Message * into the tty's buffer. */ static void isdn_tty_modem_do_ncarrier(unsigned long data) { modem_info *info = (modem_info *) data; isdn_tty_modem_result(RESULT_NO_CARRIER, info); } /* Next routine is called, whenever the DTR-signal is raised. * It checks the ncarrier-flag, and triggers the above routine * when necessary. The ncarrier-flag is set, whenever DTR goes * low. */ static void isdn_tty_modem_ncarrier(modem_info *info) { if (info->ncarrier) { info->nc_timer.expires = jiffies + HZ; add_timer(&info->nc_timer); } } /* * return the usage calculated by si and layer 2 protocol */ static int isdn_calc_usage(int si, int l2) { int usg = ISDN_USAGE_MODEM; #ifdef CONFIG_ISDN_AUDIO if (si == 1) { switch (l2) { case ISDN_PROTO_L2_MODEM: usg = ISDN_USAGE_MODEM; break; #ifdef CONFIG_ISDN_TTY_FAX case ISDN_PROTO_L2_FAX: usg = ISDN_USAGE_FAX; break; #endif case ISDN_PROTO_L2_TRANS: default: usg = ISDN_USAGE_VOICE; break; } } #endif return (usg); } /* isdn_tty_dial() performs dialing of a tty an the necessary * setup of the lower levels before that. */ static void isdn_tty_dial(char *n, modem_info *info, atemu *m) { int usg = ISDN_USAGE_MODEM; int si = 7; int l2 = m->mdmreg[REG_L2PROT]; u_long flags; isdn_ctrl cmd; int i; int j; for (j = 7; j >= 0; j--) if (m->mdmreg[REG_SI1] & (1 << j)) { si = bit2si[j]; break; } usg = isdn_calc_usage(si, l2); #ifdef CONFIG_ISDN_AUDIO if ((si == 1) && (l2 != ISDN_PROTO_L2_MODEM) #ifdef CONFIG_ISDN_TTY_FAX && (l2 != ISDN_PROTO_L2_FAX) #endif ) { l2 = ISDN_PROTO_L2_TRANS; usg = ISDN_USAGE_VOICE; } #endif m->mdmreg[REG_SI1I] = si2bit[si]; spin_lock_irqsave(&dev->lock, flags); i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn); if (i < 0) { spin_unlock_irqrestore(&dev->lock, flags); isdn_tty_modem_result(RESULT_NO_DIALTONE, info); } else { info->isdn_driver = dev->drvmap[i]; info->isdn_channel = dev->chanmap[i]; info->drv_index = i; dev->m_idx[i] = info->line; dev->usage[i] |= ISDN_USAGE_OUTGOING; info->last_dir = 1; strcpy(info->last_num, n); isdn_info_update(); spin_unlock_irqrestore(&dev->lock, flags); cmd.driver = info->isdn_driver; cmd.arg = info->isdn_channel; cmd.command = ISDN_CMD_CLREAZ; isdn_command(&cmd); strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver)); cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_SETEAZ; isdn_command(&cmd); cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_SETL2; info->last_l2 = l2; cmd.arg = info->isdn_channel + (l2 << 8); isdn_command(&cmd); cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_SETL3; cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); #ifdef CONFIG_ISDN_TTY_FAX if (l2 == ISDN_PROTO_L2_FAX) { cmd.parm.fax = info->fax; info->fax->direction = ISDN_TTY_FAX_CONN_OUT; } #endif isdn_command(&cmd); cmd.driver = info->isdn_driver; cmd.arg = info->isdn_channel; sprintf(cmd.parm.setup.phone, "%s", n); sprintf(cmd.parm.setup.eazmsn, "%s", isdn_map_eaz2msn(m->msn, info->isdn_driver)); cmd.parm.setup.si1 = si; cmd.parm.setup.si2 = m->mdmreg[REG_SI2]; cmd.command = ISDN_CMD_DIAL; info->dialing = 1; info->emu.carrierwait = 0; strcpy(dev->num[i], n); isdn_info_update(); isdn_command(&cmd); isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1); } } /* isdn_tty_hangup() disassociates a tty from the real * ISDN-line (hangup). The usage-status is cleared * and some cleanup is done also. */ void isdn_tty_modem_hup(modem_info *info, int local) { isdn_ctrl cmd; int di, ch; if (!info) return; di = info->isdn_driver; ch = info->isdn_channel; if (di < 0 || ch < 0) return; info->isdn_driver = -1; info->isdn_channel = -1; #ifdef ISDN_DEBUG_MODEM_HUP printk(KERN_DEBUG "Mhup ttyI%d\n", info->line); #endif info->rcvsched = 0; isdn_tty_flush_buffer(info->port.tty); if (info->online) { info->last_lhup = local; info->online = 0; isdn_tty_modem_result(RESULT_NO_CARRIER, info); } #ifdef CONFIG_ISDN_AUDIO info->vonline = 0; #ifdef CONFIG_ISDN_TTY_FAX info->faxonline = 0; info->fax->phase = ISDN_FAX_PHASE_IDLE; #endif info->emu.vpar[4] = 0; info->emu.vpar[5] = 8; kfree(info->dtmf_state); info->dtmf_state = NULL; kfree(info->silence_state); info->silence_state = NULL; kfree(info->adpcms); info->adpcms = NULL; kfree(info->adpcmr); info->adpcmr = NULL; #endif if ((info->msr & UART_MSR_RI) && (info->emu.mdmreg[REG_RUNG] & BIT_RUNG)) isdn_tty_modem_result(RESULT_RUNG, info); info->msr &= ~(UART_MSR_DCD | UART_MSR_RI); info->lsr |= UART_LSR_TEMT; if (local) { cmd.driver = di; cmd.command = ISDN_CMD_HANGUP; cmd.arg = ch; isdn_command(&cmd); } isdn_all_eaz(di, ch); info->emu.mdmreg[REG_RINGCNT] = 0; isdn_free_channel(di, ch, 0); if (info->drv_index >= 0) { dev->m_idx[info->drv_index] = -1; info->drv_index = -1; } } /* * Begin of a CAPI like interface, currently used only for * supplementary service (CAPI 2.0 part III) */ #include <linux/isdn/capicmd.h> #include <linux/module.h> int isdn_tty_capi_facility(capi_msg *cm) { return (-1); /* dummy */ } /* isdn_tty_suspend() tries to suspend the current tty connection */ static void isdn_tty_suspend(char *id, modem_info *info, atemu *m) { isdn_ctrl cmd; int l; if (!info) return; #ifdef ISDN_DEBUG_MODEM_SERVICES printk(KERN_DEBUG "Msusp ttyI%d\n", info->line); #endif l = strlen(id); if ((info->isdn_driver >= 0)) { cmd.parm.cmsg.Length = l + 18; cmd.parm.cmsg.Command = CAPI_FACILITY; cmd.parm.cmsg.Subcommand = CAPI_REQ; cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1; cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */ cmd.parm.cmsg.para[1] = 0; cmd.parm.cmsg.para[2] = l + 3; cmd.parm.cmsg.para[3] = 4; /* 16 bit 0x0004 Suspend */ cmd.parm.cmsg.para[4] = 0; cmd.parm.cmsg.para[5] = l; strncpy(&cmd.parm.cmsg.para[6], id, l); cmd.command = CAPI_PUT_MESSAGE; cmd.driver = info->isdn_driver; cmd.arg = info->isdn_channel; isdn_command(&cmd); } } /* isdn_tty_resume() tries to resume a suspended call * setup of the lower levels before that. unfortunately here is no * checking for compatibility of used protocols implemented by Q931 * It does the same things like isdn_tty_dial, the last command * is different, may be we can merge it. */ static void isdn_tty_resume(char *id, modem_info *info, atemu *m) { int usg = ISDN_USAGE_MODEM; int si = 7; int l2 = m->mdmreg[REG_L2PROT]; isdn_ctrl cmd; ulong flags; int i; int j; int l; l = strlen(id); for (j = 7; j >= 0; j--) if (m->mdmreg[REG_SI1] & (1 << j)) { si = bit2si[j]; break; } usg = isdn_calc_usage(si, l2); #ifdef CONFIG_ISDN_AUDIO if ((si == 1) && (l2 != ISDN_PROTO_L2_MODEM) #ifdef CONFIG_ISDN_TTY_FAX && (l2 != ISDN_PROTO_L2_FAX) #endif ) { l2 = ISDN_PROTO_L2_TRANS; usg = ISDN_USAGE_VOICE; } #endif m->mdmreg[REG_SI1I] = si2bit[si]; spin_lock_irqsave(&dev->lock, flags); i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn); if (i < 0) { spin_unlock_irqrestore(&dev->lock, flags); isdn_tty_modem_result(RESULT_NO_DIALTONE, info); } else { info->isdn_driver = dev->drvmap[i]; info->isdn_channel = dev->chanmap[i]; info->drv_index = i; dev->m_idx[i] = info->line; dev->usage[i] |= ISDN_USAGE_OUTGOING; info->last_dir = 1; // strcpy(info->last_num, n); isdn_info_update(); spin_unlock_irqrestore(&dev->lock, flags); cmd.driver = info->isdn_driver; cmd.arg = info->isdn_channel; cmd.command = ISDN_CMD_CLREAZ; isdn_command(&cmd); strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver)); cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_SETEAZ; isdn_command(&cmd); cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_SETL2; info->last_l2 = l2; cmd.arg = info->isdn_channel + (l2 << 8); isdn_command(&cmd); cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_SETL3; cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); isdn_command(&cmd); cmd.driver = info->isdn_driver; cmd.arg = info->isdn_channel; cmd.parm.cmsg.Length = l + 18; cmd.parm.cmsg.Command = CAPI_FACILITY; cmd.parm.cmsg.Subcommand = CAPI_REQ; cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1; cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */ cmd.parm.cmsg.para[1] = 0; cmd.parm.cmsg.para[2] = l + 3; cmd.parm.cmsg.para[3] = 5; /* 16 bit 0x0005 Resume */ cmd.parm.cmsg.para[4] = 0; cmd.parm.cmsg.para[5] = l; strncpy(&cmd.parm.cmsg.para[6], id, l); cmd.command = CAPI_PUT_MESSAGE; info->dialing = 1; // strcpy(dev->num[i], n); isdn_info_update(); isdn_command(&cmd); isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1); } } /* isdn_tty_send_msg() sends a message to a HL driver * This is used for hybrid modem cards to send AT commands to it */ static void isdn_tty_send_msg(modem_info *info, atemu *m, char *msg) { int usg = ISDN_USAGE_MODEM; int si = 7; int l2 = m->mdmreg[REG_L2PROT]; isdn_ctrl cmd; ulong flags; int i; int j; int l; l = min(strlen(msg), sizeof(cmd.parm) - sizeof(cmd.parm.cmsg) + sizeof(cmd.parm.cmsg.para) - 2); if (!l) { isdn_tty_modem_result(RESULT_ERROR, info); return; } for (j = 7; j >= 0; j--) if (m->mdmreg[REG_SI1] & (1 << j)) { si = bit2si[j]; break; } usg = isdn_calc_usage(si, l2); #ifdef CONFIG_ISDN_AUDIO if ((si == 1) && (l2 != ISDN_PROTO_L2_MODEM) #ifdef CONFIG_ISDN_TTY_FAX && (l2 != ISDN_PROTO_L2_FAX) #endif ) { l2 = ISDN_PROTO_L2_TRANS; usg = ISDN_USAGE_VOICE; } #endif m->mdmreg[REG_SI1I] = si2bit[si]; spin_lock_irqsave(&dev->lock, flags); i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn); if (i < 0) { spin_unlock_irqrestore(&dev->lock, flags); isdn_tty_modem_result(RESULT_NO_DIALTONE, info); } else { info->isdn_driver = dev->drvmap[i]; info->isdn_channel = dev->chanmap[i]; info->drv_index = i; dev->m_idx[i] = info->line; dev->usage[i] |= ISDN_USAGE_OUTGOING; info->last_dir = 1; isdn_info_update(); spin_unlock_irqrestore(&dev->lock, flags); cmd.driver = info->isdn_driver; cmd.arg = info->isdn_channel; cmd.command = ISDN_CMD_CLREAZ; isdn_command(&cmd); strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver)); cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_SETEAZ; isdn_command(&cmd); cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_SETL2; info->last_l2 = l2; cmd.arg = info->isdn_channel + (l2 << 8); isdn_command(&cmd); cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_SETL3; cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); isdn_command(&cmd); cmd.driver = info->isdn_driver; cmd.arg = info->isdn_channel; cmd.parm.cmsg.Length = l + 14; cmd.parm.cmsg.Command = CAPI_MANUFACTURER; cmd.parm.cmsg.Subcommand = CAPI_REQ; cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1; cmd.parm.cmsg.para[0] = l + 1; strncpy(&cmd.parm.cmsg.para[1], msg, l); cmd.parm.cmsg.para[l + 1] = 0xd; cmd.command = CAPI_PUT_MESSAGE; /* info->dialing = 1; strcpy(dev->num[i], n); isdn_info_update(); */ isdn_command(&cmd); } } static inline int isdn_tty_paranoia_check(modem_info *info, char *name, const char *routine) { #ifdef MODEM_PARANOIA_CHECK if (!info) { printk(KERN_WARNING "isdn_tty: null info_struct for %s in %s\n", name, routine); return 1; } if (info->magic != ISDN_ASYNC_MAGIC) { printk(KERN_WARNING "isdn_tty: bad magic for modem struct %s in %s\n", name, routine); return 1; } #endif return 0; } /* * This routine is called to set the UART divisor registers to match * the specified baud rate for a serial port. */ static void isdn_tty_change_speed(modem_info *info) { struct tty_port *port = &info->port; uint cflag, cval, quot; int i; if (!port->tty) return; cflag = port->tty->termios.c_cflag; quot = i = cflag & CBAUD; if (i & CBAUDEX) { i &= ~CBAUDEX; if (i < 1 || i > 2) port->tty->termios.c_cflag &= ~CBAUDEX; else i += 15; } if (quot) { info->mcr |= UART_MCR_DTR; isdn_tty_modem_ncarrier(info); } else { info->mcr &= ~UART_MCR_DTR; if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { #ifdef ISDN_DEBUG_MODEM_HUP printk(KERN_DEBUG "Mhup in changespeed\n"); #endif if (info->online) info->ncarrier = 1; isdn_tty_modem_reset_regs(info, 0); isdn_tty_modem_hup(info, 1); } return; } /* byte size and parity */ cval = cflag & (CSIZE | CSTOPB); cval >>= 4; if (cflag & PARENB) cval |= UART_LCR_PARITY; if (!(cflag & PARODD)) cval |= UART_LCR_EPAR; /* CTS flow control flag and modem status interrupts */ if (cflag & CRTSCTS) { port->flags |= ASYNC_CTS_FLOW; } else port->flags &= ~ASYNC_CTS_FLOW; if (cflag & CLOCAL) port->flags &= ~ASYNC_CHECK_CD; else { port->flags |= ASYNC_CHECK_CD; } } static int isdn_tty_startup(modem_info *info) { if (info->port.flags & ASYNC_INITIALIZED) return 0; isdn_lock_drivers(); #ifdef ISDN_DEBUG_MODEM_OPEN printk(KERN_DEBUG "starting up ttyi%d ...\n", info->line); #endif /* * Now, initialize the UART */ info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2; if (info->port.tty) clear_bit(TTY_IO_ERROR, &info->port.tty->flags); /* * and set the speed of the serial port */ isdn_tty_change_speed(info); info->port.flags |= ASYNC_INITIALIZED; info->msr |= (UART_MSR_DSR | UART_MSR_CTS); info->send_outstanding = 0; return 0; } /* * This routine will shutdown a serial port; interrupts are disabled, and * DTR is dropped if the hangup on close termio flag is on. */ static void isdn_tty_shutdown(modem_info *info) { if (!(info->port.flags & ASYNC_INITIALIZED)) return; #ifdef ISDN_DEBUG_MODEM_OPEN printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line); #endif isdn_unlock_drivers(); info->msr &= ~UART_MSR_RI; if (!info->port.tty || (info->port.tty->termios.c_cflag & HUPCL)) { info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS); if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { isdn_tty_modem_reset_regs(info, 0); #ifdef ISDN_DEBUG_MODEM_HUP printk(KERN_DEBUG "Mhup in isdn_tty_shutdown\n"); #endif isdn_tty_modem_hup(info, 1); } } if (info->port.tty) set_bit(TTY_IO_ERROR, &info->port.tty->flags); info->port.flags &= ~ASYNC_INITIALIZED; } /* isdn_tty_write() is the main send-routine. It is called from the upper * levels within the kernel to perform sending data. Depending on the * online-flag it either directs output to the at-command-interpreter or * to the lower level. Additional tasks done here: * - If online, check for escape-sequence (+++) * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes. * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed. * - If dialing, abort dial. */ static int isdn_tty_write(struct tty_struct *tty, const u_char *buf, int count) { int c; int total = 0; modem_info *info = (modem_info *) tty->driver_data; atemu *m = &info->emu; if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write")) return 0; /* See isdn_tty_senddown() */ atomic_inc(&info->xmit_lock); while (1) { c = count; if (c > info->xmit_size - info->xmit_count) c = info->xmit_size - info->xmit_count; if (info->isdn_driver >= 0 && c > dev->drv[info->isdn_driver]->maxbufsize) c = dev->drv[info->isdn_driver]->maxbufsize; if (c <= 0) break; if ((info->online > 1) #ifdef CONFIG_ISDN_AUDIO || (info->vonline & 3) #endif ) { #ifdef CONFIG_ISDN_AUDIO if (!info->vonline) #endif isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c, &(m->pluscount), &(m->lastplus)); memcpy(&info->port.xmit_buf[info->xmit_count], buf, c); #ifdef CONFIG_ISDN_AUDIO if (info->vonline) { int cc = isdn_tty_handleDLEdown(info, m, c); if (info->vonline & 2) { if (!cc) { /* If DLE decoding results in zero-transmit, but * c originally was non-zero, do a wakeup. */ tty_wakeup(tty); info->msr |= UART_MSR_CTS; info->lsr |= UART_LSR_TEMT; } info->xmit_count += cc; } if ((info->vonline & 3) == 1) { /* Do NOT handle Ctrl-Q or Ctrl-S * when in full-duplex audio mode. */ if (isdn_tty_end_vrx(buf, c)) { info->vonline &= ~1; #ifdef ISDN_DEBUG_MODEM_VOICE printk(KERN_DEBUG "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n", info->line); #endif isdn_tty_at_cout("\020\003\r\nVCON\r\n", info); } } } else if (TTY_IS_FCLASS1(info)) { int cc = isdn_tty_handleDLEdown(info, m, c); if (info->vonline & 4) { /* ETX seen */ isdn_ctrl c; c.command = ISDN_CMD_FAXCMD; c.driver = info->isdn_driver; c.arg = info->isdn_channel; c.parm.aux.cmd = ISDN_FAX_CLASS1_CTRL; c.parm.aux.subcmd = ETX; isdn_command(&c); } info->vonline = 0; #ifdef ISDN_DEBUG_MODEM_VOICE printk(KERN_DEBUG "fax dle cc/c %d/%d\n", cc, c); #endif info->xmit_count += cc; } else #endif info->xmit_count += c; } else { info->msr |= UART_MSR_CTS; info->lsr |= UART_LSR_TEMT; if (info->dialing) { info->dialing = 0; #ifdef ISDN_DEBUG_MODEM_HUP printk(KERN_DEBUG "Mhup in isdn_tty_write\n"); #endif isdn_tty_modem_result(RESULT_NO_CARRIER, info); isdn_tty_modem_hup(info, 1); } else c = isdn_tty_edit_at(buf, c, info); } buf += c; count -= c; total += c; } atomic_dec(&info->xmit_lock); if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue)) { if (m->mdmreg[REG_DXMT] & BIT_DXMT) { isdn_tty_senddown(info); isdn_tty_tint(info); } isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1); } return total; } static int isdn_tty_write_room(struct tty_struct *tty) { modem_info *info = (modem_info *) tty->driver_data; int ret; if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write_room")) return 0; if (!info->online) return info->xmit_size; ret = info->xmit_size - info->xmit_count; return (ret < 0) ? 0 : ret; } static int isdn_tty_chars_in_buffer(struct tty_struct *tty) { modem_info *info = (modem_info *) tty->driver_data; if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_chars_in_buffer")) return 0; if (!info->online) return 0; return (info->xmit_count); } static void isdn_tty_flush_buffer(struct tty_struct *tty) { modem_info *info; if (!tty) { return; } info = (modem_info *) tty->driver_data; if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_buffer")) { return; } isdn_tty_cleanup_xmit(info); info->xmit_count = 0; tty_wakeup(tty); } static void isdn_tty_flush_chars(struct tty_struct *tty) { modem_info *info = (modem_info *) tty->driver_data; if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_chars")) return; if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue)) isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1); } /* * ------------------------------------------------------------ * isdn_tty_throttle() * * This routine is called by the upper-layer tty layer to signal that * incoming characters should be throttled. * ------------------------------------------------------------ */ static void isdn_tty_throttle(struct tty_struct *tty) { modem_info *info = (modem_info *) tty->driver_data; if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_throttle")) return; if (I_IXOFF(tty)) info->x_char = STOP_CHAR(tty); info->mcr &= ~UART_MCR_RTS; } static void isdn_tty_unthrottle(struct tty_struct *tty) { modem_info *info = (modem_info *) tty->driver_data; if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_unthrottle")) return; if (I_IXOFF(tty)) { if (info->x_char) info->x_char = 0; else info->x_char = START_CHAR(tty); } info->mcr |= UART_MCR_RTS; } /* * ------------------------------------------------------------ * isdn_tty_ioctl() and friends * ------------------------------------------------------------ */ /* * isdn_tty_get_lsr_info - get line status register info * * Purpose: Let user call ioctl() to get info when the UART physically * is emptied. On bus types like RS485, the transmitter must * release the bus after transmitting. This must be done when * the transmit shift register is empty, not be done when the * transmit holding register is empty. This functionality * allows RS485 driver to be written in user space. */ static int isdn_tty_get_lsr_info(modem_info *info, uint __user *value) { u_char status; uint result; status = info->lsr; result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0); return put_user(result, value); } static int isdn_tty_tiocmget(struct tty_struct *tty) { modem_info *info = (modem_info *) tty->driver_data; u_char control, status; if (isdn_tty_paranoia_check(info, tty->name, __func__)) return -ENODEV; if (tty->flags & (1 << TTY_IO_ERROR)) return -EIO; mutex_lock(&modem_info_mutex); #ifdef ISDN_DEBUG_MODEM_IOCTL printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line); #endif control = info->mcr; status = info->msr; mutex_unlock(&modem_info_mutex); return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) | ((status & UART_MSR_RI) ? TIOCM_RNG : 0) | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0); } static int isdn_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) { modem_info *info = (modem_info *) tty->driver_data; if (isdn_tty_paranoia_check(info, tty->name, __func__)) return -ENODEV; if (tty->flags & (1 << TTY_IO_ERROR)) return -EIO; #ifdef ISDN_DEBUG_MODEM_IOCTL printk(KERN_DEBUG "ttyI%d ioctl TIOCMxxx: %x %x\n", info->line, set, clear); #endif mutex_lock(&modem_info_mutex); if (set & TIOCM_RTS) info->mcr |= UART_MCR_RTS; if (set & TIOCM_DTR) { info->mcr |= UART_MCR_DTR; isdn_tty_modem_ncarrier(info); } if (clear & TIOCM_RTS) info->mcr &= ~UART_MCR_RTS; if (clear & TIOCM_DTR) { info->mcr &= ~UART_MCR_DTR; if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { isdn_tty_modem_reset_regs(info, 0); #ifdef ISDN_DEBUG_MODEM_HUP printk(KERN_DEBUG "Mhup in TIOCMSET\n"); #endif if (info->online) info->ncarrier = 1; isdn_tty_modem_hup(info, 1); } } mutex_unlock(&modem_info_mutex); return 0; } static int isdn_tty_ioctl(struct tty_struct *tty, uint cmd, ulong arg) { modem_info *info = (modem_info *) tty->driver_data; int retval; if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_ioctl")) return -ENODEV; if (tty->flags & (1 << TTY_IO_ERROR)) return -EIO; switch (cmd) { case TCSBRK: /* SVID version: non-zero arg --> no break */ #ifdef ISDN_DEBUG_MODEM_IOCTL printk(KERN_DEBUG "ttyI%d ioctl TCSBRK\n", info->line); #endif retval = tty_check_change(tty); if (retval) return retval; tty_wait_until_sent(tty, 0); return 0; case TCSBRKP: /* support for POSIX tcsendbreak() */ #ifdef ISDN_DEBUG_MODEM_IOCTL printk(KERN_DEBUG "ttyI%d ioctl TCSBRKP\n", info->line); #endif retval = tty_check_change(tty); if (retval) return retval; tty_wait_until_sent(tty, 0); return 0; case TIOCSERGETLSR: /* Get line status register */ #ifdef ISDN_DEBUG_MODEM_IOCTL printk(KERN_DEBUG "ttyI%d ioctl TIOCSERGETLSR\n", info->line); #endif return isdn_tty_get_lsr_info(info, (uint __user *) arg); default: #ifdef ISDN_DEBUG_MODEM_IOCTL printk(KERN_DEBUG "UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd, info->line); #endif return -ENOIOCTLCMD; } return 0; } static void isdn_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios) { modem_info *info = (modem_info *) tty->driver_data; if (!old_termios) isdn_tty_change_speed(info); else { if (tty->termios.c_cflag == old_termios->c_cflag && tty->termios.c_ispeed == old_termios->c_ispeed && tty->termios.c_ospeed == old_termios->c_ospeed) return; isdn_tty_change_speed(info); } } /* * ------------------------------------------------------------ * isdn_tty_open() and friends * ------------------------------------------------------------ */ static int isdn_tty_install(struct tty_driver *driver, struct tty_struct *tty) { modem_info *info = &dev->mdm.info[tty->index]; if (isdn_tty_paranoia_check(info, tty->name, __func__)) return -ENODEV; tty->driver_data = info; return tty_port_install(&info->port, driver, tty); } /* * This routine is called whenever a serial port is opened. It * enables interrupts for a serial port, linking in its async structure into * the IRQ chain. It also performs the serial-specific * initialization for the tty structure. */ static int isdn_tty_open(struct tty_struct *tty, struct file *filp) { modem_info *info = tty->driver_data; struct tty_port *port = &info->port; int retval; #ifdef ISDN_DEBUG_MODEM_OPEN printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name, port->count); #endif port->count++; port->tty = tty; /* * Start up serial port */ retval = isdn_tty_startup(info); if (retval) { #ifdef ISDN_DEBUG_MODEM_OPEN printk(KERN_DEBUG "isdn_tty_open return after startup\n"); #endif return retval; } retval = tty_port_block_til_ready(port, tty, filp); if (retval) { #ifdef ISDN_DEBUG_MODEM_OPEN printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n"); #endif return retval; } #ifdef ISDN_DEBUG_MODEM_OPEN printk(KERN_DEBUG "isdn_tty_open ttyi%d successful...\n", info->line); #endif dev->modempoll++; #ifdef ISDN_DEBUG_MODEM_OPEN printk(KERN_DEBUG "isdn_tty_open normal exit\n"); #endif return 0; } static void isdn_tty_close(struct tty_struct *tty, struct file *filp) { modem_info *info = (modem_info *) tty->driver_data; struct tty_port *port = &info->port; ulong timeout; if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close")) return; if (tty_hung_up_p(filp)) { #ifdef ISDN_DEBUG_MODEM_OPEN printk(KERN_DEBUG "isdn_tty_close return after tty_hung_up_p\n"); #endif return; } if ((tty->count == 1) && (port->count != 1)) { /* * Uh, oh. tty->count is 1, which means that the tty * structure will be freed. Info->count should always * be one in these conditions. If it's greater than * one, we've got real problems, since it means the * serial port won't be shutdown. */ printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, " "info->count is %d\n", port->count); port->count = 1; } if (--port->count < 0) { printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n", info->line, port->count); port->count = 0; } if (port->count) { #ifdef ISDN_DEBUG_MODEM_OPEN printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n"); #endif return; } port->flags |= ASYNC_CLOSING; tty->closing = 1; /* * At this point we stop accepting input. To do this, we * disable the receive line status interrupts, and tell the * interrupt driver to stop checking the data ready bit in the * line status register. */ if (port->flags & ASYNC_INITIALIZED) { tty_wait_until_sent_from_close(tty, 3000); /* 30 seconds timeout */ /* * Before we drop DTR, make sure the UART transmitter * has completely drained; this is especially * important if there is a transmit FIFO! */ timeout = jiffies + HZ; while (!(info->lsr & UART_LSR_TEMT)) { schedule_timeout_interruptible(20); if (time_after(jiffies, timeout)) break; } } dev->modempoll--; isdn_tty_shutdown(info); isdn_tty_flush_buffer(tty); tty_ldisc_flush(tty); port->tty = NULL; info->ncarrier = 0; tty_port_close_end(port, tty); #ifdef ISDN_DEBUG_MODEM_OPEN printk(KERN_DEBUG "isdn_tty_close normal exit\n"); #endif } /* * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled. */ static void isdn_tty_hangup(struct tty_struct *tty) { modem_info *info = (modem_info *) tty->driver_data; struct tty_port *port = &info->port; if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup")) return; isdn_tty_shutdown(info); port->count = 0; port->flags &= ~ASYNC_NORMAL_ACTIVE; port->tty = NULL; wake_up_interruptible(&port->open_wait); } /* This routine initializes all emulator-data. */ static void isdn_tty_reset_profile(atemu *m) { m->profile[0] = 0; m->profile[1] = 0; m->profile[2] = 43; m->profile[3] = 13; m->profile[4] = 10; m->profile[5] = 8; m->profile[6] = 3; m->profile[7] = 60; m->profile[8] = 2; m->profile[9] = 6; m->profile[10] = 7; m->profile[11] = 70; m->profile[12] = 0x45; m->profile[13] = 4; m->profile[14] = ISDN_PROTO_L2_X75I; m->profile[15] = ISDN_PROTO_L3_TRANS; m->profile[16] = ISDN_SERIAL_XMIT_SIZE / 16; m->profile[17] = ISDN_MODEM_WINSIZE; m->profile[18] = 4; m->profile[19] = 0; m->profile[20] = 0; m->profile[23] = 0; m->pmsn[0] = '\0'; m->plmsn[0] = '\0'; } #ifdef CONFIG_ISDN_AUDIO static void isdn_tty_modem_reset_vpar(atemu *m) { m->vpar[0] = 2; /* Voice-device (2 = phone line) */ m->vpar[1] = 0; /* Silence detection level (0 = none ) */ m->vpar[2] = 70; /* Silence interval (7 sec. ) */ m->vpar[3] = 2; /* Compression type (1 = ADPCM-2 ) */ m->vpar[4] = 0; /* DTMF detection level (0 = softcode ) */ m->vpar[5] = 8; /* DTMF interval (8 * 5 ms. ) */ } #endif #ifdef CONFIG_ISDN_TTY_FAX static void isdn_tty_modem_reset_faxpar(modem_info *info) { T30_s *f = info->fax; f->code = 0; f->phase = ISDN_FAX_PHASE_IDLE; f->direction = 0; f->resolution = 1; /* fine */ f->rate = 5; /* 14400 bit/s */ f->width = 0; f->length = 0; f->compression = 0; f->ecm = 0; f->binary = 0; f->scantime = 0; memset(&f->id[0], 32, FAXIDLEN - 1); f->id[FAXIDLEN - 1] = 0; f->badlin = 0; f->badmul = 0; f->bor = 0; f->nbc = 0; f->cq = 0; f->cr = 0; f->ctcrty = 0; f->minsp = 0; f->phcto = 30; f->rel = 0; memset(&f->pollid[0], 32, FAXIDLEN - 1); f->pollid[FAXIDLEN - 1] = 0; } #endif static void isdn_tty_modem_reset_regs(modem_info *info, int force) { atemu *m = &info->emu; if ((m->mdmreg[REG_DTRR] & BIT_DTRR) || force) { memcpy(m->mdmreg, m->profile, ISDN_MODEM_NUMREG); memcpy(m->msn, m->pmsn, ISDN_MSNLEN); memcpy(m->lmsn, m->plmsn, ISDN_LMSNLEN); info->xmit_size = m->mdmreg[REG_PSIZE] * 16; } #ifdef CONFIG_ISDN_AUDIO isdn_tty_modem_reset_vpar(m); #endif #ifdef CONFIG_ISDN_TTY_FAX isdn_tty_modem_reset_faxpar(info); #endif m->mdmcmdl = 0; } static void modem_write_profile(atemu *m) { memcpy(m->profile, m->mdmreg, ISDN_MODEM_NUMREG); memcpy(m->pmsn, m->msn, ISDN_MSNLEN); memcpy(m->plmsn, m->lmsn, ISDN_LMSNLEN); if (dev->profd) send_sig(SIGIO, dev->profd, 1); } static const struct tty_operations modem_ops = { .install = isdn_tty_install, .open = isdn_tty_open, .close = isdn_tty_close, .write = isdn_tty_write, .flush_chars = isdn_tty_flush_chars, .write_room = isdn_tty_write_room, .chars_in_buffer = isdn_tty_chars_in_buffer, .flush_buffer = isdn_tty_flush_buffer, .ioctl = isdn_tty_ioctl, .throttle = isdn_tty_throttle, .unthrottle = isdn_tty_unthrottle, .set_termios = isdn_tty_set_termios, .hangup = isdn_tty_hangup, .tiocmget = isdn_tty_tiocmget, .tiocmset = isdn_tty_tiocmset, }; static int isdn_tty_carrier_raised(struct tty_port *port) { modem_info *info = container_of(port, modem_info, port); return info->msr & UART_MSR_DCD; } static const struct tty_port_operations isdn_tty_port_ops = { .carrier_raised = isdn_tty_carrier_raised, }; int isdn_tty_modem_init(void) { isdn_modem_t *m; int i, retval; modem_info *info; m = &dev->mdm; m->tty_modem = alloc_tty_driver(ISDN_MAX_CHANNELS); if (!m->tty_modem) return -ENOMEM; m->tty_modem->name = "ttyI"; m->tty_modem->major = ISDN_TTY_MAJOR; m->tty_modem->minor_start = 0; m->tty_modem->type = TTY_DRIVER_TYPE_SERIAL; m->tty_modem->subtype = SERIAL_TYPE_NORMAL; m->tty_modem->init_termios = tty_std_termios; m->tty_modem->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; m->tty_modem->flags = TTY_DRIVER_REAL_RAW; m->tty_modem->driver_name = "isdn_tty"; tty_set_operations(m->tty_modem, &modem_ops); retval = tty_register_driver(m->tty_modem); if (retval) { printk(KERN_WARNING "isdn_tty: Couldn't register modem-device\n"); goto err; } for (i = 0; i < ISDN_MAX_CHANNELS; i++) { info = &m->info[i]; #ifdef CONFIG_ISDN_TTY_FAX if (!(info->fax = kmalloc(sizeof(T30_s), GFP_KERNEL))) { printk(KERN_ERR "Could not allocate fax t30-buffer\n"); retval = -ENOMEM; goto err_unregister; } #endif tty_port_init(&info->port); info->port.ops = &isdn_tty_port_ops; spin_lock_init(&info->readlock); sprintf(info->last_cause, "0000"); sprintf(info->last_num, "none"); info->last_dir = 0; info->last_lhup = 1; info->last_l2 = -1; info->last_si = 0; isdn_tty_reset_profile(&info->emu); isdn_tty_modem_reset_regs(info, 1); info->magic = ISDN_ASYNC_MAGIC; info->line = i; info->x_char = 0; info->isdn_driver = -1; info->isdn_channel = -1; info->drv_index = -1; info->xmit_size = ISDN_SERIAL_XMIT_SIZE; init_timer(&info->nc_timer); info->nc_timer.function = isdn_tty_modem_do_ncarrier; info->nc_timer.data = (unsigned long) info; skb_queue_head_init(&info->xmit_queue); #ifdef CONFIG_ISDN_AUDIO skb_queue_head_init(&info->dtmf_queue); #endif info->port.xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, GFP_KERNEL); if (!info->port.xmit_buf) { printk(KERN_ERR "Could not allocate modem xmit-buffer\n"); retval = -ENOMEM; goto err_unregister; } /* Make room for T.70 header */ info->port.xmit_buf += 4; } return 0; err_unregister: for (i--; i >= 0; i--) { info = &m->info[i]; #ifdef CONFIG_ISDN_TTY_FAX kfree(info->fax); #endif kfree(info->port.xmit_buf - 4); info->port.xmit_buf = NULL; tty_port_destroy(&info->port); } tty_unregister_driver(m->tty_modem); err: put_tty_driver(m->tty_modem); m->tty_modem = NULL; return retval; } void isdn_tty_exit(void) { modem_info *info; int i; for (i = 0; i < ISDN_MAX_CHANNELS; i++) { info = &dev->mdm.info[i]; isdn_tty_cleanup_xmit(info); #ifdef CONFIG_ISDN_TTY_FAX kfree(info->fax); #endif kfree(info->port.xmit_buf - 4); info->port.xmit_buf = NULL; tty_port_destroy(&info->port); } tty_unregister_driver(dev->mdm.tty_modem); put_tty_driver(dev->mdm.tty_modem); dev->mdm.tty_modem = NULL; } /* * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx) * match the MSN against the MSNs (glob patterns) defined for tty_emulator, * and return 0 for match, 1 for no match, 2 if MSN could match if longer. */ static int isdn_tty_match_icall(char *cid, atemu *emu, int di) { #ifdef ISDN_DEBUG_MODEM_ICALL printk(KERN_DEBUG "m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n", emu->msn, emu->lmsn, isdn_map_eaz2msn(emu->msn, di), emu->mdmreg[REG_SI1], emu->mdmreg[REG_SI2]); #endif if (strlen(emu->lmsn)) { char *p = emu->lmsn; char *q; int tmp; int ret = 0; while (1) { if ((q = strchr(p, ';'))) *q = '\0'; if ((tmp = isdn_msncmp(cid, isdn_map_eaz2msn(p, di))) > ret) ret = tmp; #ifdef ISDN_DEBUG_MODEM_ICALL printk(KERN_DEBUG "m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n", p, isdn_map_eaz2msn(emu->msn, di), tmp); #endif if (q) { *q = ';'; p = q; p++; } if (!tmp) return 0; if (!q) break; } return ret; } else { int tmp; tmp = isdn_msncmp(cid, isdn_map_eaz2msn(emu->msn, di)); #ifdef ISDN_DEBUG_MODEM_ICALL printk(KERN_DEBUG "m_fi: mmsn=%s -> tmp=%d\n", isdn_map_eaz2msn(emu->msn, di), tmp); #endif return tmp; } } /* * An incoming call-request has arrived. * Search the tty-devices for an appropriate device and bind * it to the ISDN-Channel. * Return: * * 0 = No matching device found. * 1 = A matching device found. * 3 = No match found, but eventually would match, if * CID is longer. */ int isdn_tty_find_icall(int di, int ch, setup_parm *setup) { char *eaz; int i; int wret; int idx; int si1; int si2; char *nr; ulong flags; if (!setup->phone[0]) { nr = "0"; printk(KERN_INFO "isdn_tty: Incoming call without OAD, assuming '0'\n"); } else nr = setup->phone; si1 = (int) setup->si1; si2 = (int) setup->si2; if (!setup->eazmsn[0]) { printk(KERN_WARNING "isdn_tty: Incoming call without CPN, assuming '0'\n"); eaz = "0"; } else eaz = setup->eazmsn; #ifdef ISDN_DEBUG_MODEM_ICALL printk(KERN_DEBUG "m_fi: eaz=%s si1=%d si2=%d\n", eaz, si1, si2); #endif wret = 0; spin_lock_irqsave(&dev->lock, flags); for (i = 0; i < ISDN_MAX_CHANNELS; i++) { modem_info *info = &dev->mdm.info[i]; if (info->port.count == 0) continue; if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */ (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */ idx = isdn_dc2minor(di, ch); #ifdef ISDN_DEBUG_MODEM_ICALL printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret); printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx, info->port.flags, info->isdn_driver, info->isdn_channel, dev->usage[idx]); #endif if ( #ifndef FIX_FILE_TRANSFER (info->port.flags & ASYNC_NORMAL_ACTIVE) && #endif (info->isdn_driver == -1) && (info->isdn_channel == -1) && (USG_NONE(dev->usage[idx]))) { int matchret; if ((matchret = isdn_tty_match_icall(eaz, &info->emu, di)) > wret) wret = matchret; if (!matchret) { /* EAZ is matching */ info->isdn_driver = di; info->isdn_channel = ch; info->drv_index = idx; dev->m_idx[idx] = info->line; dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE; dev->usage[idx] |= isdn_calc_usage(si1, info->emu.mdmreg[REG_L2PROT]); strcpy(dev->num[idx], nr); strcpy(info->emu.cpn, eaz); info->emu.mdmreg[REG_SI1I] = si2bit[si1]; info->emu.mdmreg[REG_PLAN] = setup->plan; info->emu.mdmreg[REG_SCREEN] = setup->screen; isdn_info_update(); spin_unlock_irqrestore(&dev->lock, flags); printk(KERN_INFO "isdn_tty: call from %s, -> RING on ttyI%d\n", nr, info->line); info->msr |= UART_MSR_RI; isdn_tty_modem_result(RESULT_RING, info); isdn_timer_ctrl(ISDN_TIMER_MODEMRING, 1); return 1; } } } } spin_unlock_irqrestore(&dev->lock, flags); printk(KERN_INFO "isdn_tty: call from %s -> %s %s\n", nr, eaz, ((dev->drv[di]->flags & DRV_FLAG_REJBUS) && (wret != 2)) ? "rejected" : "ignored"); return (wret == 2) ? 3 : 0; } #define TTY_IS_ACTIVE(info) (info->port.flags & ASYNC_NORMAL_ACTIVE) int isdn_tty_stat_callback(int i, isdn_ctrl *c) { int mi; modem_info *info; char *e; if (i < 0) return 0; if ((mi = dev->m_idx[i]) >= 0) { info = &dev->mdm.info[mi]; switch (c->command) { case ISDN_STAT_CINF: printk(KERN_DEBUG "CHARGEINFO on ttyI%d: %ld %s\n", info->line, c->arg, c->parm.num); info->emu.charge = (unsigned) simple_strtoul(c->parm.num, &e, 10); if (e == (char *)c->parm.num) info->emu.charge = 0; break; case ISDN_STAT_BSENT: #ifdef ISDN_TTY_STAT_DEBUG printk(KERN_DEBUG "tty_STAT_BSENT ttyI%d\n", info->line); #endif if ((info->isdn_driver == c->driver) && (info->isdn_channel == c->arg)) { info->msr |= UART_MSR_CTS; if (info->send_outstanding) if (!(--info->send_outstanding)) info->lsr |= UART_LSR_TEMT; isdn_tty_tint(info); return 1; } break; case ISDN_STAT_CAUSE: #ifdef ISDN_TTY_STAT_DEBUG printk(KERN_DEBUG "tty_STAT_CAUSE ttyI%d\n", info->line); #endif /* Signal cause to tty-device */ strncpy(info->last_cause, c->parm.num, 5); return 1; case ISDN_STAT_DISPLAY: #ifdef ISDN_TTY_STAT_DEBUG printk(KERN_DEBUG "tty_STAT_DISPLAY ttyI%d\n", info->line); #endif /* Signal display to tty-device */ if ((info->emu.mdmreg[REG_DISPLAY] & BIT_DISPLAY) && !(info->emu.mdmreg[REG_RESPNUM] & BIT_RESPNUM)) { isdn_tty_at_cout("\r\n", info); isdn_tty_at_cout("DISPLAY: ", info); isdn_tty_at_cout(c->parm.display, info); isdn_tty_at_cout("\r\n", info); } return 1; case ISDN_STAT_DCONN: #ifdef ISDN_TTY_STAT_DEBUG printk(KERN_DEBUG "tty_STAT_DCONN ttyI%d\n", info->line); #endif if (TTY_IS_ACTIVE(info)) { if (info->dialing == 1) { info->dialing = 2; return 1; } } break; case ISDN_STAT_DHUP: #ifdef ISDN_TTY_STAT_DEBUG printk(KERN_DEBUG "tty_STAT_DHUP ttyI%d\n", info->line); #endif if (TTY_IS_ACTIVE(info)) { if (info->dialing == 1) isdn_tty_modem_result(RESULT_BUSY, info); if (info->dialing > 1) isdn_tty_modem_result(RESULT_NO_CARRIER, info); info->dialing = 0; #ifdef ISDN_DEBUG_MODEM_HUP printk(KERN_DEBUG "Mhup in ISDN_STAT_DHUP\n"); #endif isdn_tty_modem_hup(info, 0); return 1; } break; case ISDN_STAT_BCONN: #ifdef ISDN_TTY_STAT_DEBUG printk(KERN_DEBUG "tty_STAT_BCONN ttyI%d\n", info->line); #endif /* Wake up any processes waiting * for incoming call of this device when * DCD follow the state of incoming carrier */ if (info->port.blocked_open && (info->emu.mdmreg[REG_DCD] & BIT_DCD)) { wake_up_interruptible(&info->port.open_wait); } /* Schedule CONNECT-Message to any tty * waiting for it and * set DCD-bit of its modem-status. */ if (TTY_IS_ACTIVE(info) || (info->port.blocked_open && (info->emu.mdmreg[REG_DCD] & BIT_DCD))) { info->msr |= UART_MSR_DCD; info->emu.charge = 0; if (info->dialing & 0xf) info->last_dir = 1; else info->last_dir = 0; info->dialing = 0; info->rcvsched = 1; if (USG_MODEM(dev->usage[i])) { if (info->emu.mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) { strcpy(info->emu.connmsg, c->parm.num); isdn_tty_modem_result(RESULT_CONNECT, info); } else isdn_tty_modem_result(RESULT_CONNECT64000, info); } if (USG_VOICE(dev->usage[i])) isdn_tty_modem_result(RESULT_VCON, info); return 1; } break; case ISDN_STAT_BHUP: #ifdef ISDN_TTY_STAT_DEBUG printk(KERN_DEBUG "tty_STAT_BHUP ttyI%d\n", info->line); #endif if (TTY_IS_ACTIVE(info)) { #ifdef ISDN_DEBUG_MODEM_HUP printk(KERN_DEBUG "Mhup in ISDN_STAT_BHUP\n"); #endif isdn_tty_modem_hup(info, 0); return 1; } break; case ISDN_STAT_NODCH: #ifdef ISDN_TTY_STAT_DEBUG printk(KERN_DEBUG "tty_STAT_NODCH ttyI%d\n", info->line); #endif if (TTY_IS_ACTIVE(info)) { if (info->dialing) { info->dialing = 0; info->last_l2 = -1; info->last_si = 0; sprintf(info->last_cause, "0000"); isdn_tty_modem_result(RESULT_NO_DIALTONE, info); } isdn_tty_modem_hup(info, 0); return 1; } break; case ISDN_STAT_UNLOAD: #ifdef ISDN_TTY_STAT_DEBUG printk(KERN_DEBUG "tty_STAT_UNLOAD ttyI%d\n", info->line); #endif for (i = 0; i < ISDN_MAX_CHANNELS; i++) { info = &dev->mdm.info[i]; if (info->isdn_driver == c->driver) { if (info->online) isdn_tty_modem_hup(info, 1); } } return 1; #ifdef CONFIG_ISDN_TTY_FAX case ISDN_STAT_FAXIND: if (TTY_IS_ACTIVE(info)) { isdn_tty_fax_command(info, c); } break; #endif #ifdef CONFIG_ISDN_AUDIO case ISDN_STAT_AUDIO: if (TTY_IS_ACTIVE(info)) { switch (c->parm.num[0]) { case ISDN_AUDIO_DTMF: if (info->vonline) { isdn_audio_put_dle_code(info, c->parm.num[1]); } break; } } break; #endif } } return 0; } /********************************************************************* Modem-Emulator-Routines *********************************************************************/ #define cmdchar(c) ((c >= ' ') && (c <= 0x7f)) /* * Put a message from the AT-emulator into receive-buffer of tty, * convert CR, LF, and BS to values in modem-registers 3, 4 and 5. */ void isdn_tty_at_cout(char *msg, modem_info *info) { struct tty_port *port = &info->port; atemu *m = &info->emu; char *p; char c; u_long flags; struct sk_buff *skb = NULL; char *sp = NULL; int l; if (!msg) { printk(KERN_WARNING "isdn_tty: Null-Message in isdn_tty_at_cout\n"); return; } l = strlen(msg); spin_lock_irqsave(&info->readlock, flags); if (port->flags & ASYNC_CLOSING) { spin_unlock_irqrestore(&info->readlock, flags); return; } /* use queue instead of direct, if online and */ /* data is in queue or buffer is full */ if (info->online && ((tty_buffer_request_room(port, l) < l) || !skb_queue_empty(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel]))) { skb = alloc_skb(l, GFP_ATOMIC); if (!skb) { spin_unlock_irqrestore(&info->readlock, flags); return; } sp = skb_put(skb, l); #ifdef CONFIG_ISDN_AUDIO ISDN_AUDIO_SKB_DLECOUNT(skb) = 0; ISDN_AUDIO_SKB_LOCK(skb) = 0; #endif } for (p = msg; *p; p++) { switch (*p) { case '\r': c = m->mdmreg[REG_CR]; break; case '\n': c = m->mdmreg[REG_LF]; break; case '\b': c = m->mdmreg[REG_BS]; break; default: c = *p; } if (skb) { *sp++ = c; } else { if (tty_insert_flip_char(port, c, TTY_NORMAL) == 0) break; } } if (skb) { __skb_queue_tail(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel], skb); dev->drv[info->isdn_driver]->rcvcount[info->isdn_channel] += skb->len; spin_unlock_irqrestore(&info->readlock, flags); /* Schedule dequeuing */ if (dev->modempoll && info->rcvsched) isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1); } else { spin_unlock_irqrestore(&info->readlock, flags); tty_flip_buffer_push(port); } } /* * Perform ATH Hangup */ static void isdn_tty_on_hook(modem_info *info) { if (info->isdn_channel >= 0) { #ifdef ISDN_DEBUG_MODEM_HUP printk(KERN_DEBUG "Mhup in isdn_tty_on_hook\n"); #endif isdn_tty_modem_hup(info, 1); } } static void isdn_tty_off_hook(void) { printk(KERN_DEBUG "isdn_tty_off_hook\n"); } #define PLUSWAIT1 (HZ / 2) /* 0.5 sec. */ #define PLUSWAIT2 (HZ * 3 / 2) /* 1.5 sec */ /* * Check Buffer for Modem-escape-sequence, activate timer-callback to * isdn_tty_modem_escape() if sequence found. * * Parameters: * p pointer to databuffer * plus escape-character * count length of buffer * pluscount count of valid escape-characters so far * lastplus timestamp of last character */ static void isdn_tty_check_esc(const u_char *p, u_char plus, int count, int *pluscount, u_long *lastplus) { if (plus > 127) return; if (count > 3) { p += count - 3; count = 3; *pluscount = 0; } while (count > 0) { if (*(p++) == plus) { if ((*pluscount)++) { /* Time since last '+' > 0.5 sec. ? */ if (time_after(jiffies, *lastplus + PLUSWAIT1)) *pluscount = 1; } else { /* Time since last non-'+' < 1.5 sec. ? */ if (time_before(jiffies, *lastplus + PLUSWAIT2)) *pluscount = 0; } if ((*pluscount == 3) && (count == 1)) isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, 1); if (*pluscount > 3) *pluscount = 1; } else *pluscount = 0; *lastplus = jiffies; count--; } } /* * Return result of AT-emulator to tty-receive-buffer, depending on * modem-register 12, bit 0 and 1. * For CONNECT-messages also switch to online-mode. * For RING-message handle auto-ATA if register 0 != 0 */ static void isdn_tty_modem_result(int code, modem_info *info) { atemu *m = &info->emu; static char *msg[] = {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR", "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER", "RINGING", "NO MSN/EAZ", "VCON", "RUNG"}; char s[ISDN_MSNLEN + 10]; switch (code) { case RESULT_RING: m->mdmreg[REG_RINGCNT]++; if (m->mdmreg[REG_RINGCNT] == m->mdmreg[REG_RINGATA]) /* Automatically accept incoming call */ isdn_tty_cmd_ATA(info); break; case RESULT_NO_CARRIER: #ifdef ISDN_DEBUG_MODEM_HUP printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n", (info->port.flags & ASYNC_CLOSING), (!info->port.tty)); #endif m->mdmreg[REG_RINGCNT] = 0; del_timer(&info->nc_timer); info->ncarrier = 0; if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty)) return; #ifdef CONFIG_ISDN_AUDIO if (info->vonline & 1) { #ifdef ISDN_DEBUG_MODEM_VOICE printk(KERN_DEBUG "res3: send DLE-ETX on ttyI%d\n", info->line); #endif /* voice-recording, add DLE-ETX */ isdn_tty_at_cout("\020\003", info); } if (info->vonline & 2) { #ifdef ISDN_DEBUG_MODEM_VOICE printk(KERN_DEBUG "res3: send DLE-DC4 on ttyI%d\n", info->line); #endif /* voice-playing, add DLE-DC4 */ isdn_tty_at_cout("\020\024", info); } #endif break; case RESULT_CONNECT: case RESULT_CONNECT64000: sprintf(info->last_cause, "0000"); if (!info->online) info->online = 2; break; case RESULT_VCON: #ifdef ISDN_DEBUG_MODEM_VOICE printk(KERN_DEBUG "res3: send VCON on ttyI%d\n", info->line); #endif sprintf(info->last_cause, "0000"); if (!info->online) info->online = 1; break; } /* switch (code) */ if (m->mdmreg[REG_RESP] & BIT_RESP) { /* Show results */ if (m->mdmreg[REG_RESPNUM] & BIT_RESPNUM) { /* Show numeric results only */ sprintf(s, "\r\n%d\r\n", code); isdn_tty_at_cout(s, info); } else { if (code == RESULT_RING) { /* return if "show RUNG" and ringcounter>1 */ if ((m->mdmreg[REG_RUNG] & BIT_RUNG) && (m->mdmreg[REG_RINGCNT] > 1)) return; /* print CID, _before_ _every_ ring */ if (!(m->mdmreg[REG_CIDONCE] & BIT_CIDONCE)) { isdn_tty_at_cout("\r\nCALLER NUMBER: ", info); isdn_tty_at_cout(dev->num[info->drv_index], info); if (m->mdmreg[REG_CDN] & BIT_CDN) { isdn_tty_at_cout("\r\nCALLED NUMBER: ", info); isdn_tty_at_cout(info->emu.cpn, info); } } } isdn_tty_at_cout("\r\n", info); isdn_tty_at_cout(msg[code], info); switch (code) { case RESULT_CONNECT: switch (m->mdmreg[REG_L2PROT]) { case ISDN_PROTO_L2_MODEM: isdn_tty_at_cout(" ", info); isdn_tty_at_cout(m->connmsg, info); break; } break; case RESULT_RING: /* Append CPN, if enabled */ if ((m->mdmreg[REG_CPN] & BIT_CPN)) { sprintf(s, "/%s", m->cpn); isdn_tty_at_cout(s, info); } /* Print CID only once, _after_ 1st RING */ if ((m->mdmreg[REG_CIDONCE] & BIT_CIDONCE) && (m->mdmreg[REG_RINGCNT] == 1)) { isdn_tty_at_cout("\r\n", info); isdn_tty_at_cout("CALLER NUMBER: ", info); isdn_tty_at_cout(dev->num[info->drv_index], info); if (m->mdmreg[REG_CDN] & BIT_CDN) { isdn_tty_at_cout("\r\nCALLED NUMBER: ", info); isdn_tty_at_cout(info->emu.cpn, info); } } break; case RESULT_NO_CARRIER: case RESULT_NO_DIALTONE: case RESULT_BUSY: case RESULT_NO_ANSWER: m->mdmreg[REG_RINGCNT] = 0; /* Append Cause-Message if enabled */ if (m->mdmreg[REG_RESPXT] & BIT_RESPXT) { sprintf(s, "/%s", info->last_cause); isdn_tty_at_cout(s, info); } break; case RESULT_CONNECT64000: /* Append Protocol to CONNECT message */ switch (m->mdmreg[REG_L2PROT]) { case ISDN_PROTO_L2_X75I: case ISDN_PROTO_L2_X75UI: case ISDN_PROTO_L2_X75BUI: isdn_tty_at_cout("/X.75", info); break; case ISDN_PROTO_L2_HDLC: isdn_tty_at_cout("/HDLC", info); break; case ISDN_PROTO_L2_V11096: isdn_tty_at_cout("/V110/9600", info); break; case ISDN_PROTO_L2_V11019: isdn_tty_at_cout("/V110/19200", info); break; case ISDN_PROTO_L2_V11038: isdn_tty_at_cout("/V110/38400", info); break; } if (m->mdmreg[REG_T70] & BIT_T70) { isdn_tty_at_cout("/T.70", info); if (m->mdmreg[REG_T70] & BIT_T70_EXT) isdn_tty_at_cout("+", info); } break; } isdn_tty_at_cout("\r\n", info); } } if (code == RESULT_NO_CARRIER) { if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty)) return; if (info->port.flags & ASYNC_CHECK_CD) tty_hangup(info->port.tty); } } /* * Display a modem-register-value. */ static void isdn_tty_show_profile(int ridx, modem_info *info) { char v[6]; sprintf(v, "\r\n%d", info->emu.mdmreg[ridx]); isdn_tty_at_cout(v, info); } /* * Get MSN-string from char-pointer, set pointer to end of number */ static void isdn_tty_get_msnstr(char *n, char **p) { int limit = ISDN_MSNLEN - 1; while (((*p[0] >= '0' && *p[0] <= '9') || /* Why a comma ??? */ (*p[0] == ',') || (*p[0] == ':')) && (limit--)) *n++ = *p[0]++; *n = '\0'; } /* * Get phone-number from modem-commandbuffer */ static void isdn_tty_getdial(char *p, char *q, int cnt) { int first = 1; int limit = ISDN_MSNLEN - 1; /* MUST match the size of interface var to avoid buffer overflow */ while (strchr(" 0123456789,#.*WPTSR-", *p) && *p && --cnt > 0) { if ((*p >= '0' && *p <= '9') || ((*p == 'S') && first) || ((*p == 'R') && first) || (*p == '*') || (*p == '#')) { *q++ = *p; limit--; } if (!limit) break; p++; first = 0; } *q = 0; } #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; } #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; } static void isdn_tty_report(modem_info *info) { atemu *m = &info->emu; char s[80]; isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info); sprintf(s, " Remote Number: %s\r\n", info->last_num); isdn_tty_at_cout(s, info); sprintf(s, " Direction: %s\r\n", info->last_dir ? "outgoing" : "incoming"); isdn_tty_at_cout(s, info); isdn_tty_at_cout(" Layer-2 Protocol: ", info); switch (info->last_l2) { case ISDN_PROTO_L2_X75I: isdn_tty_at_cout("X.75i", info); break; case ISDN_PROTO_L2_X75UI: isdn_tty_at_cout("X.75ui", info); break; case ISDN_PROTO_L2_X75BUI: isdn_tty_at_cout("X.75bui", info); break; case ISDN_PROTO_L2_HDLC: isdn_tty_at_cout("HDLC", info); break; case ISDN_PROTO_L2_V11096: isdn_tty_at_cout("V.110 9600 Baud", info); break; case ISDN_PROTO_L2_V11019: isdn_tty_at_cout("V.110 19200 Baud", info); break; case ISDN_PROTO_L2_V11038: isdn_tty_at_cout("V.110 38400 Baud", info); break; case ISDN_PROTO_L2_TRANS: isdn_tty_at_cout("transparent", info); break; case ISDN_PROTO_L2_MODEM: isdn_tty_at_cout("modem", info); break; case ISDN_PROTO_L2_FAX: isdn_tty_at_cout("fax", info); break; default: isdn_tty_at_cout("unknown", info); break; } if (m->mdmreg[REG_T70] & BIT_T70) { isdn_tty_at_cout("/T.70", info); if (m->mdmreg[REG_T70] & BIT_T70_EXT) isdn_tty_at_cout("+", info); } isdn_tty_at_cout("\r\n", info); isdn_tty_at_cout(" Service: ", info); switch (info->last_si) { case 1: isdn_tty_at_cout("audio\r\n", info); break; case 5: isdn_tty_at_cout("btx\r\n", info); break; case 7: isdn_tty_at_cout("data\r\n", info); break; default: sprintf(s, "%d\r\n", info->last_si); isdn_tty_at_cout(s, info); break; } sprintf(s, " Hangup location: %s\r\n", info->last_lhup ? "local" : "remote"); isdn_tty_at_cout(s, info); sprintf(s, " Last cause: %s\r\n", info->last_cause); isdn_tty_at_cout(s, info); } /* * Parse AT&.. commands. */ static int isdn_tty_cmd_ATand(char **p, modem_info *info) { atemu *m = &info->emu; int i; char rb[100]; #define MAXRB (sizeof(rb) - 1) switch (*p[0]) { case 'B': /* &B - Set Buffersize */ p[0]++; i = isdn_getnum(p); if ((i < 0) || (i > ISDN_SERIAL_XMIT_MAX)) PARSE_ERROR1; #ifdef CONFIG_ISDN_AUDIO if ((m->mdmreg[REG_SI1] & 1) && (i > VBUF)) PARSE_ERROR1; #endif m->mdmreg[REG_PSIZE] = i / 16; info->xmit_size = m->mdmreg[REG_PSIZE] * 16; switch (m->mdmreg[REG_L2PROT]) { case ISDN_PROTO_L2_V11096: case ISDN_PROTO_L2_V11019: case ISDN_PROTO_L2_V11038: info->xmit_size /= 10; } break; case 'C': /* &C - DCD Status */ p[0]++; switch (isdn_getnum(p)) { case 0: m->mdmreg[REG_DCD] &= ~BIT_DCD; break; case 1: m->mdmreg[REG_DCD] |= BIT_DCD; break; default: PARSE_ERROR1 } break; case 'D': /* &D - Set DTR-Low-behavior */ p[0]++; switch (isdn_getnum(p)) { case 0: m->mdmreg[REG_DTRHUP] &= ~BIT_DTRHUP; m->mdmreg[REG_DTRR] &= ~BIT_DTRR; break; case 2: m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP; m->mdmreg[REG_DTRR] &= ~BIT_DTRR; break; case 3: m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP; m->mdmreg[REG_DTRR] |= BIT_DTRR; break; default: PARSE_ERROR1 } break; case 'E': /* &E -Set EAZ/MSN */ p[0]++; isdn_tty_get_msnstr(m->msn, p); break; case 'F': /* &F -Set Factory-Defaults */ p[0]++; if (info->msr & UART_MSR_DCD) PARSE_ERROR1; isdn_tty_reset_profile(m); isdn_tty_modem_reset_regs(info, 1); break; #ifdef DUMMY_HAYES_AT case 'K': /* only for be compilant with common scripts */ /* &K Flowcontrol - no function */ p[0]++; isdn_getnum(p); break; #endif case 'L': /* &L -Set Numbers to listen on */ p[0]++; i = 0; while (*p[0] && (strchr("0123456789,-*[]?;", *p[0])) && (i < ISDN_LMSNLEN - 1)) m->lmsn[i++] = *p[0]++; m->lmsn[i] = '\0'; break; case 'R': /* &R - Set V.110 bitrate adaption */ p[0]++; i = isdn_getnum(p); switch (i) { case 0: /* Switch off V.110, back to X.75 */ m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; m->mdmreg[REG_SI2] = 0; info->xmit_size = m->mdmreg[REG_PSIZE] * 16; break; case 9600: m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11096; m->mdmreg[REG_SI2] = 197; info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10; break; case 19200: m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11019; m->mdmreg[REG_SI2] = 199; info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10; break; case 38400: m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11038; m->mdmreg[REG_SI2] = 198; /* no existing standard for this */ info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10; break; default: PARSE_ERROR1; } /* Switch off T.70 */ m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT); /* Set Service 7 */ m->mdmreg[REG_SI1] |= 4; break; case 'S': /* &S - Set Windowsize */ p[0]++; i = isdn_getnum(p); if ((i > 0) && (i < 9)) m->mdmreg[REG_WSIZE] = i; else PARSE_ERROR1; break; case 'V': /* &V - Show registers */ p[0]++; isdn_tty_at_cout("\r\n", info); for (i = 0; i < ISDN_MODEM_NUMREG; i++) { sprintf(rb, "S%02d=%03d%s", i, m->mdmreg[i], ((i + 1) % 10) ? " " : "\r\n"); isdn_tty_at_cout(rb, info); } sprintf(rb, "\r\nEAZ/MSN: %.50s\r\n", strlen(m->msn) ? m->msn : "None"); isdn_tty_at_cout(rb, info); if (strlen(m->lmsn)) { isdn_tty_at_cout("\r\nListen: ", info); isdn_tty_at_cout(m->lmsn, info); isdn_tty_at_cout("\r\n", info); } break; case 'W': /* &W - Write Profile */ p[0]++; switch (*p[0]) { case '0': p[0]++; modem_write_profile(m); break; default: PARSE_ERROR1; } break; case 'X': /* &X - Switch to BTX-Mode and T.70 */ p[0]++; switch (isdn_getnum(p)) { case 0: m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT); info->xmit_size = m->mdmreg[REG_PSIZE] * 16; break; case 1: m->mdmreg[REG_T70] |= BIT_T70; m->mdmreg[REG_T70] &= ~BIT_T70_EXT; m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; info->xmit_size = 112; m->mdmreg[REG_SI1] = 4; m->mdmreg[REG_SI2] = 0; break; case 2: m->mdmreg[REG_T70] |= (BIT_T70 | BIT_T70_EXT); m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; info->xmit_size = 112; m->mdmreg[REG_SI1] = 4; m->mdmreg[REG_SI2] = 0; break; default: PARSE_ERROR1; } break; default: PARSE_ERROR1; } return 0; } static int isdn_tty_check_ats(int mreg, int mval, modem_info *info, atemu *m) { /* Some plausibility checks */ switch (mreg) { case REG_L2PROT: if (mval > ISDN_PROTO_L2_MAX) return 1; break; case REG_PSIZE: if ((mval * 16) > ISDN_SERIAL_XMIT_MAX) return 1; #ifdef CONFIG_ISDN_AUDIO if ((m->mdmreg[REG_SI1] & 1) && (mval > VBUFX)) return 1; #endif info->xmit_size = mval * 16; switch (m->mdmreg[REG_L2PROT]) { case ISDN_PROTO_L2_V11096: case ISDN_PROTO_L2_V11019: case ISDN_PROTO_L2_V11038: info->xmit_size /= 10; } break; case REG_SI1I: case REG_PLAN: case REG_SCREEN: /* readonly registers */ return 1; } return 0; } /* * Perform ATS command */ static int isdn_tty_cmd_ATS(char **p, modem_info *info) { atemu *m = &info->emu; int bitpos; int mreg; int mval; int bval; mreg = isdn_getnum(p); if (mreg < 0 || mreg >= ISDN_MODEM_NUMREG) PARSE_ERROR1; switch (*p[0]) { case '=': p[0]++; mval = isdn_getnum(p); if (mval < 0 || mval > 255) PARSE_ERROR1; if (isdn_tty_check_ats(mreg, mval, info, m)) PARSE_ERROR1; m->mdmreg[mreg] = mval; break; case '.': /* Set/Clear a single bit */ p[0]++; bitpos = isdn_getnum(p); if ((bitpos < 0) || (bitpos > 7)) PARSE_ERROR1; switch (*p[0]) { case '=': p[0]++; bval = isdn_getnum(p); if (bval < 0 || bval > 1) PARSE_ERROR1; if (bval) mval = m->mdmreg[mreg] | (1 << bitpos); else mval = m->mdmreg[mreg] & ~(1 << bitpos); if (isdn_tty_check_ats(mreg, mval, info, m)) PARSE_ERROR1; m->mdmreg[mreg] = mval; break; case '?': p[0]++; isdn_tty_at_cout("\r\n", info); isdn_tty_at_cout((m->mdmreg[mreg] & (1 << bitpos)) ? "1" : "0", info); break; default: PARSE_ERROR1; } break; case '?': p[0]++; isdn_tty_show_profile(mreg, info); break; default: PARSE_ERROR1; break; } return 0; } /* * Perform ATA command */ static void isdn_tty_cmd_ATA(modem_info *info) { atemu *m = &info->emu; isdn_ctrl cmd; int l2; if (info->msr & UART_MSR_RI) { /* Accept incoming call */ info->last_dir = 0; strcpy(info->last_num, dev->num[info->drv_index]); m->mdmreg[REG_RINGCNT] = 0; info->msr &= ~UART_MSR_RI; l2 = m->mdmreg[REG_L2PROT]; #ifdef CONFIG_ISDN_AUDIO /* If more than one bit set in reg18, autoselect Layer2 */ if ((m->mdmreg[REG_SI1] & m->mdmreg[REG_SI1I]) != m->mdmreg[REG_SI1]) { if (m->mdmreg[REG_SI1I] == 1) { if ((l2 != ISDN_PROTO_L2_MODEM) && (l2 != ISDN_PROTO_L2_FAX)) l2 = ISDN_PROTO_L2_TRANS; } else l2 = ISDN_PROTO_L2_X75I; } #endif cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_SETL2; cmd.arg = info->isdn_channel + (l2 << 8); info->last_l2 = l2; isdn_command(&cmd); cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_SETL3; cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8); #ifdef CONFIG_ISDN_TTY_FAX if (l2 == ISDN_PROTO_L2_FAX) { cmd.parm.fax = info->fax; info->fax->direction = ISDN_TTY_FAX_CONN_IN; } #endif isdn_command(&cmd); cmd.driver = info->isdn_driver; cmd.arg = info->isdn_channel; cmd.command = ISDN_CMD_ACCEPTD; info->dialing = 16; info->emu.carrierwait = 0; isdn_command(&cmd); isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1); } else isdn_tty_modem_result(RESULT_NO_ANSWER, info); } #ifdef CONFIG_ISDN_AUDIO /* * Parse AT+F.. commands */ static int isdn_tty_cmd_PLUSF(char **p, modem_info *info) { atemu *m = &info->emu; char rs[20]; if (!strncmp(p[0], "CLASS", 5)) { p[0] += 5; switch (*p[0]) { case '?': p[0]++; sprintf(rs, "\r\n%d", (m->mdmreg[REG_SI1] & 1) ? 8 : 0); #ifdef CONFIG_ISDN_TTY_FAX if (TTY_IS_FCLASS2(info)) sprintf(rs, "\r\n2"); else if (TTY_IS_FCLASS1(info)) sprintf(rs, "\r\n1"); #endif isdn_tty_at_cout(rs, info); break; case '=': p[0]++; switch (*p[0]) { case '0': p[0]++; m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS; m->mdmreg[REG_SI1] = 4; info->xmit_size = m->mdmreg[REG_PSIZE] * 16; break; #ifdef CONFIG_ISDN_TTY_FAX case '1': p[0]++; if (!(dev->global_features & ISDN_FEATURE_L3_FCLASS1)) PARSE_ERROR1; m->mdmreg[REG_SI1] = 1; m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX; m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS1; info->xmit_size = m->mdmreg[REG_PSIZE] * 16; break; case '2': p[0]++; if (!(dev->global_features & ISDN_FEATURE_L3_FCLASS2)) PARSE_ERROR1; m->mdmreg[REG_SI1] = 1; m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX; m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS2; info->xmit_size = m->mdmreg[REG_PSIZE] * 16; break; #endif case '8': p[0]++; /* L2 will change on dialout with si=1 */ m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I; m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS; m->mdmreg[REG_SI1] = 5; info->xmit_size = VBUF; break; case '?': p[0]++; strcpy(rs, "\r\n0,"); #ifdef CONFIG_ISDN_TTY_FAX if (dev->global_features & ISDN_FEATURE_L3_FCLASS1) strcat(rs, "1,"); if (dev->global_features & ISDN_FEATURE_L3_FCLASS2) strcat(rs, "2,"); #endif strcat(rs, "8"); isdn_tty_at_cout(rs, info); break; default: PARSE_ERROR1; } break; default: PARSE_ERROR1; } return 0; } #ifdef CONFIG_ISDN_TTY_FAX return (isdn_tty_cmd_PLUSF_FAX(p, info)); #else PARSE_ERROR1; #endif } /* * Parse AT+V.. commands */ static int isdn_tty_cmd_PLUSV(char **p, modem_info *info) { atemu *m = &info->emu; isdn_ctrl cmd; static char *vcmd[] = {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL}; int i; int par1; int par2; char rs[20]; i = 0; while (vcmd[i]) { if (!strncmp(vcmd[i], p[0], 2)) { p[0] += 2; break; } i++; } switch (i) { case 0: /* AT+VNH - Auto hangup feature */ switch (*p[0]) { case '?': p[0]++; isdn_tty_at_cout("\r\n1", info); break; case '=': p[0]++; switch (*p[0]) { case '1': p[0]++; break; case '?': p[0]++; isdn_tty_at_cout("\r\n1", info); break; default: PARSE_ERROR1; } break; default: PARSE_ERROR1; } break; case 1: /* AT+VIP - Reset all voice parameters */ isdn_tty_modem_reset_vpar(m); break; case 2: /* AT+VLS - Select device, accept incoming call */ switch (*p[0]) { case '?': p[0]++; sprintf(rs, "\r\n%d", m->vpar[0]); isdn_tty_at_cout(rs, info); break; case '=': p[0]++; switch (*p[0]) { case '0': p[0]++; m->vpar[0] = 0; break; case '2': p[0]++; m->vpar[0] = 2; break; case '?': p[0]++; isdn_tty_at_cout("\r\n0,2", info); break; default: PARSE_ERROR1; } break; default: PARSE_ERROR1; } break; case 3: /* AT+VRX - Start recording */ if (!m->vpar[0]) PARSE_ERROR1; if (info->online != 1) { isdn_tty_modem_result(RESULT_NO_ANSWER, info); return 1; } info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state); if (!info->dtmf_state) { printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n"); PARSE_ERROR1; } info->silence_state = isdn_audio_silence_init(info->silence_state); if (!info->silence_state) { printk(KERN_WARNING "isdn_tty: Couldn't malloc silence state\n"); PARSE_ERROR1; } if (m->vpar[3] < 5) { info->adpcmr = isdn_audio_adpcm_init(info->adpcmr, m->vpar[3]); if (!info->adpcmr) { printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n"); PARSE_ERROR1; } } #ifdef ISDN_DEBUG_AT printk(KERN_DEBUG "AT: +VRX\n"); #endif info->vonline |= 1; isdn_tty_modem_result(RESULT_CONNECT, info); return 0; break; case 4: /* AT+VSD - Silence detection */ switch (*p[0]) { case '?': p[0]++; sprintf(rs, "\r\n<%d>,<%d>", m->vpar[1], m->vpar[2]); isdn_tty_at_cout(rs, info); break; case '=': p[0]++; if ((*p[0] >= '0') && (*p[0] <= '9')) { par1 = isdn_getnum(p); if ((par1 < 0) || (par1 > 31)) PARSE_ERROR1; if (*p[0] != ',') PARSE_ERROR1; p[0]++; par2 = isdn_getnum(p); if ((par2 < 0) || (par2 > 255)) PARSE_ERROR1; m->vpar[1] = par1; m->vpar[2] = par2; break; } else if (*p[0] == '?') { p[0]++; isdn_tty_at_cout("\r\n<0-31>,<0-255>", info); break; } else PARSE_ERROR1; break; default: PARSE_ERROR1; } break; case 5: /* AT+VSM - Select compression */ switch (*p[0]) { case '?': p[0]++; sprintf(rs, "\r\n<%d>,<%d><8000>", m->vpar[3], m->vpar[1]); isdn_tty_at_cout(rs, info); break; case '=': p[0]++; switch (*p[0]) { case '2': case '3': case '4': case '5': case '6': par1 = isdn_getnum(p); if ((par1 < 2) || (par1 > 6)) PARSE_ERROR1; m->vpar[3] = par1; break; case '?': p[0]++; isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n", info); isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n", info); isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n", info); isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n", info); isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n", info); break; default: PARSE_ERROR1; } break; default: PARSE_ERROR1; } break; case 6: /* AT+VTX - Start sending */ if (!m->vpar[0]) PARSE_ERROR1; if (info->online != 1) { isdn_tty_modem_result(RESULT_NO_ANSWER, info); return 1; } info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state); if (!info->dtmf_state) { printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n"); PARSE_ERROR1; } if (m->vpar[3] < 5) { info->adpcms = isdn_audio_adpcm_init(info->adpcms, m->vpar[3]); if (!info->adpcms) { printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n"); PARSE_ERROR1; } } #ifdef ISDN_DEBUG_AT printk(KERN_DEBUG "AT: +VTX\n"); #endif m->lastDLE = 0; info->vonline |= 2; isdn_tty_modem_result(RESULT_CONNECT, info); return 0; break; case 7: /* AT+VDD - DTMF detection */ switch (*p[0]) { case '?': p[0]++; sprintf(rs, "\r\n<%d>,<%d>", m->vpar[4], m->vpar[5]); isdn_tty_at_cout(rs, info); break; case '=': p[0]++; if ((*p[0] >= '0') && (*p[0] <= '9')) { if (info->online != 1) PARSE_ERROR1; par1 = isdn_getnum(p); if ((par1 < 0) || (par1 > 15)) PARSE_ERROR1; if (*p[0] != ',') PARSE_ERROR1; p[0]++; par2 = isdn_getnum(p); if ((par2 < 0) || (par2 > 255)) PARSE_ERROR1; m->vpar[4] = par1; m->vpar[5] = par2; cmd.driver = info->isdn_driver; cmd.command = ISDN_CMD_AUDIO; cmd.arg = info->isdn_channel + (ISDN_AUDIO_SETDD << 8); cmd.parm.num[0] = par1; cmd.parm.num[1] = par2; isdn_command(&cmd); break; } else if (*p[0] == '?') { p[0]++; isdn_tty_at_cout("\r\n<0-15>,<0-255>", info); break; } else PARSE_ERROR1; break; default: PARSE_ERROR1; } break; default: PARSE_ERROR1; } return 0; } #endif /* CONFIG_ISDN_AUDIO */ /* * Parse and perform an AT-command-line. */ static void isdn_tty_parse_at(modem_info *info) { atemu *m = &info->emu; char *p; char ds[ISDN_MSNLEN]; #ifdef ISDN_DEBUG_AT printk(KERN_DEBUG "AT: '%s'\n", m->mdmcmd); #endif for (p = &m->mdmcmd[2]; *p;) { switch (*p) { case ' ': p++; break; case 'A': /* A - Accept incoming call */ p++; isdn_tty_cmd_ATA(info); return; case 'D': /* D - Dial */ if (info->msr & UART_MSR_DCD) PARSE_ERROR; if (info->msr & UART_MSR_RI) { isdn_tty_modem_result(RESULT_NO_CARRIER, info); return; } isdn_tty_getdial(++p, ds, sizeof ds); p += strlen(p); if (!strlen(m->msn)) isdn_tty_modem_result(RESULT_NO_MSN_EAZ, info); else if (strlen(ds)) isdn_tty_dial(ds, info, m); else PARSE_ERROR; return; case 'E': /* E - Turn Echo on/off */ p++; switch (isdn_getnum(&p)) { case 0: m->mdmreg[REG_ECHO] &= ~BIT_ECHO; break; case 1: m->mdmreg[REG_ECHO] |= BIT_ECHO; break; default: PARSE_ERROR; } break; case 'H': /* H - On/Off-hook */ p++; switch (*p) { case '0': p++; isdn_tty_on_hook(info); break; case '1': p++; isdn_tty_off_hook(); break; default: isdn_tty_on_hook(info); break; } break; case 'I': /* I - Information */ p++; isdn_tty_at_cout("\r\nLinux ISDN", info); switch (*p) { case '0': case '1': p++; break; case '2': p++; isdn_tty_report(info); break; case '3': p++; snprintf(ds, sizeof(ds), "\r\n%d", info->emu.charge); isdn_tty_at_cout(ds, info); break; default:; } break; #ifdef DUMMY_HAYES_AT case 'L': case 'M': /* only for be compilant with common scripts */ /* no function */ p++; isdn_getnum(&p); break; #endif case 'O': /* O - Go online */ p++; if (info->msr & UART_MSR_DCD) /* if B-Channel is up */ isdn_tty_modem_result((m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) ? RESULT_CONNECT : RESULT_CONNECT64000, info); else isdn_tty_modem_result(RESULT_NO_CARRIER, info); return; case 'Q': /* Q - Turn Emulator messages on/off */ p++; switch (isdn_getnum(&p)) { case 0: m->mdmreg[REG_RESP] |= BIT_RESP; break; case 1: m->mdmreg[REG_RESP] &= ~BIT_RESP; break; default: PARSE_ERROR; } break; case 'S': /* S - Set/Get Register */ p++; if (isdn_tty_cmd_ATS(&p, info)) return; break; case 'V': /* V - Numeric or ASCII Emulator-messages */ p++; switch (isdn_getnum(&p)) { case 0: m->mdmreg[REG_RESP] |= BIT_RESPNUM; break; case 1: m->mdmreg[REG_RESP] &= ~BIT_RESPNUM; break; default: PARSE_ERROR; } break; case 'Z': /* Z - Load Registers from Profile */ p++; if (info->msr & UART_MSR_DCD) { info->online = 0; isdn_tty_on_hook(info); } isdn_tty_modem_reset_regs(info, 1); break; case '+': p++; switch (*p) { #ifdef CONFIG_ISDN_AUDIO case 'F': p++; if (isdn_tty_cmd_PLUSF(&p, info)) return; break; case 'V': if ((!(m->mdmreg[REG_SI1] & 1)) || (m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM)) PARSE_ERROR; p++; if (isdn_tty_cmd_PLUSV(&p, info)) return; break; #endif /* CONFIG_ISDN_AUDIO */ case 'S': /* SUSPEND */ p++; isdn_tty_get_msnstr(ds, &p); isdn_tty_suspend(ds, info, m); break; case 'R': /* RESUME */ p++; isdn_tty_get_msnstr(ds, &p); isdn_tty_resume(ds, info, m); break; case 'M': /* MESSAGE */ p++; isdn_tty_send_msg(info, m, p); break; default: PARSE_ERROR; } break; case '&': p++; if (isdn_tty_cmd_ATand(&p, info)) return; break; default: PARSE_ERROR; } } #ifdef CONFIG_ISDN_AUDIO if (!info->vonline) #endif isdn_tty_modem_result(RESULT_OK, info); } /* Need own toupper() because standard-toupper is not available * within modules. */ #define my_toupper(c) (((c >= 'a') && (c <= 'z')) ? (c & 0xdf) : c) /* * Perform line-editing of AT-commands * * Parameters: * p inputbuffer * count length of buffer * channel index to line (minor-device) */ static int isdn_tty_edit_at(const char *p, int count, modem_info *info) { atemu *m = &info->emu; int total = 0; u_char c; char eb[2]; int cnt; for (cnt = count; cnt > 0; p++, cnt--) { c = *p; total++; if (c == m->mdmreg[REG_CR] || c == m->mdmreg[REG_LF]) { /* Separator (CR or LF) */ m->mdmcmd[m->mdmcmdl] = 0; if (m->mdmreg[REG_ECHO] & BIT_ECHO) { eb[0] = c; eb[1] = 0; isdn_tty_at_cout(eb, info); } if ((m->mdmcmdl >= 2) && (!(strncmp(m->mdmcmd, "AT", 2)))) isdn_tty_parse_at(info); m->mdmcmdl = 0; continue; } if (c == m->mdmreg[REG_BS] && m->mdmreg[REG_BS] < 128) { /* Backspace-Function */ if ((m->mdmcmdl > 2) || (!m->mdmcmdl)) { if (m->mdmcmdl) m->mdmcmdl--; if (m->mdmreg[REG_ECHO] & BIT_ECHO) isdn_tty_at_cout("\b", info); } continue; } if (cmdchar(c)) { if (m->mdmreg[REG_ECHO] & BIT_ECHO) { eb[0] = c; eb[1] = 0; isdn_tty_at_cout(eb, info); } if (m->mdmcmdl < 255) { c = my_toupper(c); switch (m->mdmcmdl) { case 1: if (c == 'T') { m->mdmcmd[m->mdmcmdl] = c; m->mdmcmd[++m->mdmcmdl] = 0; break; } else m->mdmcmdl = 0; /* Fall through, check for 'A' */ case 0: if (c == 'A') { m->mdmcmd[m->mdmcmdl] = c; m->mdmcmd[++m->mdmcmdl] = 0; } break; default: m->mdmcmd[m->mdmcmdl] = c; m->mdmcmd[++m->mdmcmdl] = 0; } } } } return total; } /* * Switch all modem-channels who are online and got a valid * escape-sequence 1.5 seconds ago, to command-mode. * This function is called every second via timer-interrupt from within * timer-dispatcher isdn_timer_function() */ void isdn_tty_modem_escape(void) { int ton = 0; int i; int midx; for (i = 0; i < ISDN_MAX_CHANNELS; i++) if (USG_MODEM(dev->usage[i]) && (midx = dev->m_idx[i]) >= 0) { modem_info *info = &dev->mdm.info[midx]; if (info->online) { ton = 1; if ((info->emu.pluscount == 3) && time_after(jiffies, info->emu.lastplus + PLUSWAIT2)) { info->emu.pluscount = 0; info->online = 0; isdn_tty_modem_result(RESULT_OK, info); } } } isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton); } /* * Put a RING-message to all modem-channels who have the RI-bit set. * This function is called every second via timer-interrupt from within * timer-dispatcher isdn_timer_function() */ void isdn_tty_modem_ring(void) { int ton = 0; int i; for (i = 0; i < ISDN_MAX_CHANNELS; i++) { modem_info *info = &dev->mdm.info[i]; if (info->msr & UART_MSR_RI) { ton = 1; isdn_tty_modem_result(RESULT_RING, info); } } isdn_timer_ctrl(ISDN_TIMER_MODEMRING, ton); } /* * For all online tty's, try sending data to * the lower levels. */ void isdn_tty_modem_xmit(void) { int ton = 1; int i; for (i = 0; i < ISDN_MAX_CHANNELS; i++) { modem_info *info = &dev->mdm.info[i]; if (info->online) { ton = 1; isdn_tty_senddown(info); isdn_tty_tint(info); } } isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, ton); } /* * Check all channels if we have a 'no carrier' timeout. * Timeout value is set by Register S7. */ void isdn_tty_carrier_timeout(void) { int ton = 0; int i; for (i = 0; i < ISDN_MAX_CHANNELS; i++) { modem_info *info = &dev->mdm.info[i]; if (!info->dialing) continue; if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) { info->dialing = 0; isdn_tty_modem_result(RESULT_NO_CARRIER, info); isdn_tty_modem_hup(info, 1); } else ton = 1; } isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton); }
gpl-2.0
jpoirier/linux
arch/mips/pnx833x/stb22x/board.c
4542
3849
/* * board.c: STB225 board support. * * Copyright 2008 NXP Semiconductors * Chris Steel <chris.steel@nxp.com> * Daniel Laird <daniel.j.laird@nxp.com> * * Based on software written by: * Nikita Youshchenko <yoush@debian.org>, based on PNX8550 code. * * 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/init.h> #include <asm/bootinfo.h> #include <linux/mm.h> #include <pnx833x.h> #include <gpio.h> /* endianess twiddlers */ #define PNX8335_DEBUG0 0x4400 #define PNX8335_DEBUG1 0x4404 #define PNX8335_DEBUG2 0x4408 #define PNX8335_DEBUG3 0x440c #define PNX8335_DEBUG4 0x4410 #define PNX8335_DEBUG5 0x4414 #define PNX8335_DEBUG6 0x4418 #define PNX8335_DEBUG7 0x441c int prom_argc; char **prom_argv, **prom_envp; extern void prom_init_cmdline(void); extern char *prom_getenv(char *envname); const char *get_system_type(void) { return "NXP STB22x"; } static inline unsigned long env_or_default(char *env, unsigned long dfl) { char *str = prom_getenv(env); return str ? simple_strtol(str, 0, 0) : dfl; } void __init prom_init(void) { unsigned long memsize; prom_argc = fw_arg0; prom_argv = (char **)fw_arg1; prom_envp = (char **)fw_arg2; prom_init_cmdline(); memsize = env_or_default("memsize", 0x02000000); add_memory_region(0, memsize, BOOT_MEM_RAM); } void __init pnx833x_board_setup(void) { pnx833x_gpio_select_function_alt(4); pnx833x_gpio_select_output(4); pnx833x_gpio_select_function_alt(5); pnx833x_gpio_select_input(5); pnx833x_gpio_select_function_alt(6); pnx833x_gpio_select_input(6); pnx833x_gpio_select_function_alt(7); pnx833x_gpio_select_output(7); pnx833x_gpio_select_function_alt(25); pnx833x_gpio_select_function_alt(26); pnx833x_gpio_select_function_alt(27); pnx833x_gpio_select_function_alt(28); pnx833x_gpio_select_function_alt(29); pnx833x_gpio_select_function_alt(30); pnx833x_gpio_select_function_alt(31); pnx833x_gpio_select_function_alt(32); pnx833x_gpio_select_function_alt(33); #if IS_ENABLED(CONFIG_MTD_NAND_PLATFORM) /* Setup MIU for NAND access on CS0... * * (it seems that we must also configure CS1 for reliable operation, * otherwise the first read ID command will fail if it's read as 4 bytes * but pass if it's read as 1 word.) */ /* Setup MIU CS0 & CS1 timing */ PNX833X_MIU_SEL0 = 0; PNX833X_MIU_SEL1 = 0; PNX833X_MIU_SEL0_TIMING = 0x50003081; PNX833X_MIU_SEL1_TIMING = 0x50003081; /* Setup GPIO 00 for use as MIU CS1 (CS0 is not multiplexed, so does not need this) */ pnx833x_gpio_select_function_alt(0); /* Setup GPIO 04 to input NAND read/busy signal */ pnx833x_gpio_select_function_io(4); pnx833x_gpio_select_input(4); /* Setup GPIO 05 to disable NAND write protect */ pnx833x_gpio_select_function_io(5); pnx833x_gpio_select_output(5); pnx833x_gpio_write(1, 5); #elif IS_ENABLED(CONFIG_MTD_CFI) /* Set up MIU for 16-bit NOR access on CS0 and CS1... */ /* Setup MIU CS0 & CS1 timing */ PNX833X_MIU_SEL0 = 1; PNX833X_MIU_SEL1 = 1; PNX833X_MIU_SEL0_TIMING = 0x6A08D082; PNX833X_MIU_SEL1_TIMING = 0x6A08D082; /* Setup GPIO 00 for use as MIU CS1 (CS0 is not multiplexed, so does not need this) */ pnx833x_gpio_select_function_alt(0); #endif }
gpl-2.0
ptmr3/GalaxyS2-GalaxyNote_Kernel
net/ipv4/netfilter/ip_tables.c
4542
56134
/* * Packet matching code. * * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling * Copyright (C) 2000-2005 Netfilter Core Team <coreteam@netfilter.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. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/cache.h> #include <linux/capability.h> #include <linux/skbuff.h> #include <linux/kmod.h> #include <linux/vmalloc.h> #include <linux/netdevice.h> #include <linux/module.h> #include <linux/icmp.h> #include <net/ip.h> #include <net/compat.h> #include <asm/uaccess.h> #include <linux/mutex.h> #include <linux/proc_fs.h> #include <linux/err.h> #include <linux/cpumask.h> #include <linux/netfilter/x_tables.h> #include <linux/netfilter_ipv4/ip_tables.h> #include <net/netfilter/nf_log.h> #include "../../netfilter/xt_repldata.h" MODULE_LICENSE("GPL"); MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); MODULE_DESCRIPTION("IPv4 packet filter"); /*#define DEBUG_IP_FIREWALL*/ /*#define DEBUG_ALLOW_ALL*/ /* Useful for remote debugging */ /*#define DEBUG_IP_FIREWALL_USER*/ #ifdef DEBUG_IP_FIREWALL #define dprintf(format, args...) pr_info(format , ## args) #else #define dprintf(format, args...) #endif #ifdef DEBUG_IP_FIREWALL_USER #define duprintf(format, args...) pr_info(format , ## args) #else #define duprintf(format, args...) #endif #ifdef CONFIG_NETFILTER_DEBUG #define IP_NF_ASSERT(x) WARN_ON(!(x)) #else #define IP_NF_ASSERT(x) #endif #if 0 /* All the better to debug you with... */ #define static #define inline #endif void *ipt_alloc_initial_table(const struct xt_table *info) { return xt_alloc_initial_table(ipt, IPT); } EXPORT_SYMBOL_GPL(ipt_alloc_initial_table); /* Returns whether matches rule or not. */ /* Performance critical - called for every packet */ static inline bool ip_packet_match(const struct iphdr *ip, const char *indev, const char *outdev, const struct ipt_ip *ipinfo, int isfrag) { unsigned long ret; #define FWINV(bool, invflg) ((bool) ^ !!(ipinfo->invflags & (invflg))) if (FWINV((ip->saddr&ipinfo->smsk.s_addr) != ipinfo->src.s_addr, IPT_INV_SRCIP) || FWINV((ip->daddr&ipinfo->dmsk.s_addr) != ipinfo->dst.s_addr, IPT_INV_DSTIP)) { dprintf("Source or dest mismatch.\n"); dprintf("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n", &ip->saddr, &ipinfo->smsk.s_addr, &ipinfo->src.s_addr, ipinfo->invflags & IPT_INV_SRCIP ? " (INV)" : ""); dprintf("DST: %pI4 Mask: %pI4 Target: %pI4.%s\n", &ip->daddr, &ipinfo->dmsk.s_addr, &ipinfo->dst.s_addr, ipinfo->invflags & IPT_INV_DSTIP ? " (INV)" : ""); return false; } ret = ifname_compare_aligned(indev, ipinfo->iniface, ipinfo->iniface_mask); if (FWINV(ret != 0, IPT_INV_VIA_IN)) { dprintf("VIA in mismatch (%s vs %s).%s\n", indev, ipinfo->iniface, ipinfo->invflags&IPT_INV_VIA_IN ?" (INV)":""); return false; } ret = ifname_compare_aligned(outdev, ipinfo->outiface, ipinfo->outiface_mask); if (FWINV(ret != 0, IPT_INV_VIA_OUT)) { dprintf("VIA out mismatch (%s vs %s).%s\n", outdev, ipinfo->outiface, ipinfo->invflags&IPT_INV_VIA_OUT ?" (INV)":""); return false; } /* Check specific protocol */ if (ipinfo->proto && FWINV(ip->protocol != ipinfo->proto, IPT_INV_PROTO)) { dprintf("Packet protocol %hi does not match %hi.%s\n", ip->protocol, ipinfo->proto, ipinfo->invflags&IPT_INV_PROTO ? " (INV)":""); return false; } /* If we have a fragment rule but the packet is not a fragment * then we return zero */ if (FWINV((ipinfo->flags&IPT_F_FRAG) && !isfrag, IPT_INV_FRAG)) { dprintf("Fragment rule but not fragment.%s\n", ipinfo->invflags & IPT_INV_FRAG ? " (INV)" : ""); return false; } return true; } static bool ip_checkentry(const struct ipt_ip *ip) { if (ip->flags & ~IPT_F_MASK) { duprintf("Unknown flag bits set: %08X\n", ip->flags & ~IPT_F_MASK); return false; } if (ip->invflags & ~IPT_INV_MASK) { duprintf("Unknown invflag bits set: %08X\n", ip->invflags & ~IPT_INV_MASK); return false; } return true; } static unsigned int ipt_error(struct sk_buff *skb, const struct xt_action_param *par) { if (net_ratelimit()) pr_info("error: `%s'\n", (const char *)par->targinfo); return NF_DROP; } /* Performance critical */ static inline struct ipt_entry * get_entry(const void *base, unsigned int offset) { return (struct ipt_entry *)(base + offset); } /* All zeroes == unconditional rule. */ /* Mildly perf critical (only if packet tracing is on) */ static inline bool unconditional(const struct ipt_ip *ip) { static const struct ipt_ip uncond; return memcmp(ip, &uncond, sizeof(uncond)) == 0; #undef FWINV } /* for const-correctness */ static inline const struct xt_entry_target * ipt_get_target_c(const struct ipt_entry *e) { return ipt_get_target((struct ipt_entry *)e); } #if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE) static const char *const hooknames[] = { [NF_INET_PRE_ROUTING] = "PREROUTING", [NF_INET_LOCAL_IN] = "INPUT", [NF_INET_FORWARD] = "FORWARD", [NF_INET_LOCAL_OUT] = "OUTPUT", [NF_INET_POST_ROUTING] = "POSTROUTING", }; enum nf_ip_trace_comments { NF_IP_TRACE_COMMENT_RULE, NF_IP_TRACE_COMMENT_RETURN, NF_IP_TRACE_COMMENT_POLICY, }; static const char *const comments[] = { [NF_IP_TRACE_COMMENT_RULE] = "rule", [NF_IP_TRACE_COMMENT_RETURN] = "return", [NF_IP_TRACE_COMMENT_POLICY] = "policy", }; static struct nf_loginfo trace_loginfo = { .type = NF_LOG_TYPE_LOG, .u = { .log = { .level = 4, .logflags = NF_LOG_MASK, }, }, }; /* Mildly perf critical (only if packet tracing is on) */ static inline int get_chainname_rulenum(const struct ipt_entry *s, const struct ipt_entry *e, const char *hookname, const char **chainname, const char **comment, unsigned int *rulenum) { const struct xt_standard_target *t = (void *)ipt_get_target_c(s); if (strcmp(t->target.u.kernel.target->name, XT_ERROR_TARGET) == 0) { /* Head of user chain: ERROR target with chainname */ *chainname = t->target.data; (*rulenum) = 0; } else if (s == e) { (*rulenum)++; if (s->target_offset == sizeof(struct ipt_entry) && strcmp(t->target.u.kernel.target->name, XT_STANDARD_TARGET) == 0 && t->verdict < 0 && unconditional(&s->ip)) { /* Tail of chains: STANDARD target (return/policy) */ *comment = *chainname == hookname ? comments[NF_IP_TRACE_COMMENT_POLICY] : comments[NF_IP_TRACE_COMMENT_RETURN]; } return 1; } else (*rulenum)++; return 0; } static void trace_packet(const struct sk_buff *skb, unsigned int hook, const struct net_device *in, const struct net_device *out, const char *tablename, const struct xt_table_info *private, const struct ipt_entry *e) { const void *table_base; const struct ipt_entry *root; const char *hookname, *chainname, *comment; const struct ipt_entry *iter; unsigned int rulenum = 0; table_base = private->entries[smp_processor_id()]; root = get_entry(table_base, private->hook_entry[hook]); hookname = chainname = hooknames[hook]; comment = comments[NF_IP_TRACE_COMMENT_RULE]; xt_entry_foreach(iter, root, private->size - private->hook_entry[hook]) if (get_chainname_rulenum(iter, e, hookname, &chainname, &comment, &rulenum) != 0) break; nf_log_packet(AF_INET, hook, skb, in, out, &trace_loginfo, "TRACE: %s:%s:%s:%u ", tablename, chainname, comment, rulenum); } #endif static inline __pure struct ipt_entry *ipt_next_entry(const struct ipt_entry *entry) { return (void *)entry + entry->next_offset; } /* Returns one of the generic firewall policies, like NF_ACCEPT. */ unsigned int ipt_do_table(struct sk_buff *skb, unsigned int hook, const struct net_device *in, const struct net_device *out, struct xt_table *table) { static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long)))); const struct iphdr *ip; /* Initializing verdict to NF_DROP keeps gcc happy. */ unsigned int verdict = NF_DROP; const char *indev, *outdev; const void *table_base; struct ipt_entry *e, **jumpstack; unsigned int *stackptr, origptr, cpu; const struct xt_table_info *private; struct xt_action_param acpar; unsigned int addend; /* Initialization */ ip = ip_hdr(skb); indev = in ? in->name : nulldevname; outdev = out ? out->name : nulldevname; /* We handle fragments by dealing with the first fragment as * if it was a normal packet. All other fragments are treated * normally, except that they will NEVER match rules that ask * things we don't know, ie. tcp syn flag or ports). If the * rule is also a fragment-specific rule, non-fragments won't * match it. */ acpar.fragoff = ntohs(ip->frag_off) & IP_OFFSET; acpar.thoff = ip_hdrlen(skb); acpar.hotdrop = false; acpar.in = in; acpar.out = out; acpar.family = NFPROTO_IPV4; acpar.hooknum = hook; IP_NF_ASSERT(table->valid_hooks & (1 << hook)); local_bh_disable(); addend = xt_write_recseq_begin(); private = table->private; cpu = smp_processor_id(); table_base = private->entries[cpu]; jumpstack = (struct ipt_entry **)private->jumpstack[cpu]; stackptr = per_cpu_ptr(private->stackptr, cpu); origptr = *stackptr; e = get_entry(table_base, private->hook_entry[hook]); pr_debug("Entering %s(hook %u); sp at %u (UF %p)\n", table->name, hook, origptr, get_entry(table_base, private->underflow[hook])); do { const struct xt_entry_target *t; const struct xt_entry_match *ematch; IP_NF_ASSERT(e); if (!ip_packet_match(ip, indev, outdev, &e->ip, acpar.fragoff)) { no_match: e = ipt_next_entry(e); continue; } xt_ematch_foreach(ematch, e) { acpar.match = ematch->u.kernel.match; acpar.matchinfo = ematch->data; if (!acpar.match->match(skb, &acpar)) goto no_match; } ADD_COUNTER(e->counters, skb->len, 1); t = ipt_get_target(e); IP_NF_ASSERT(t->u.kernel.target); #if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE) /* The packet is traced: log it */ if (unlikely(skb->nf_trace)) trace_packet(skb, hook, in, out, table->name, private, e); #endif /* Standard target? */ if (!t->u.kernel.target->target) { int v; v = ((struct xt_standard_target *)t)->verdict; if (v < 0) { /* Pop from stack? */ if (v != XT_RETURN) { verdict = (unsigned)(-v) - 1; break; } if (*stackptr <= origptr) { e = get_entry(table_base, private->underflow[hook]); pr_debug("Underflow (this is normal) " "to %p\n", e); } else { e = jumpstack[--*stackptr]; pr_debug("Pulled %p out from pos %u\n", e, *stackptr); e = ipt_next_entry(e); } continue; } if (table_base + v != ipt_next_entry(e) && !(e->ip.flags & IPT_F_GOTO)) { if (*stackptr >= private->stacksize) { verdict = NF_DROP; break; } jumpstack[(*stackptr)++] = e; pr_debug("Pushed %p into pos %u\n", e, *stackptr - 1); } e = get_entry(table_base, v); continue; } acpar.target = t->u.kernel.target; acpar.targinfo = t->data; verdict = t->u.kernel.target->target(skb, &acpar); /* Target might have changed stuff. */ ip = ip_hdr(skb); if (verdict == XT_CONTINUE) e = ipt_next_entry(e); else /* Verdict */ break; } while (!acpar.hotdrop); pr_debug("Exiting %s; resetting sp from %u to %u\n", __func__, *stackptr, origptr); *stackptr = origptr; xt_write_recseq_end(addend); local_bh_enable(); #ifdef DEBUG_ALLOW_ALL return NF_ACCEPT; #else if (acpar.hotdrop) return NF_DROP; else return verdict; #endif } /* Figures out from what hook each rule can be called: returns 0 if there are loops. Puts hook bitmask in comefrom. */ static int mark_source_chains(const struct xt_table_info *newinfo, unsigned int valid_hooks, void *entry0) { unsigned int hook; /* No recursion; use packet counter to save back ptrs (reset to 0 as we leave), and comefrom to save source hook bitmask */ for (hook = 0; hook < NF_INET_NUMHOOKS; hook++) { unsigned int pos = newinfo->hook_entry[hook]; struct ipt_entry *e = (struct ipt_entry *)(entry0 + pos); if (!(valid_hooks & (1 << hook))) continue; /* Set initial back pointer. */ e->counters.pcnt = pos; for (;;) { const struct xt_standard_target *t = (void *)ipt_get_target_c(e); int visited = e->comefrom & (1 << hook); if (e->comefrom & (1 << NF_INET_NUMHOOKS)) { pr_err("iptables: loop hook %u pos %u %08X.\n", hook, pos, e->comefrom); return 0; } e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS)); /* Unconditional return/END. */ if ((e->target_offset == sizeof(struct ipt_entry) && (strcmp(t->target.u.user.name, XT_STANDARD_TARGET) == 0) && t->verdict < 0 && unconditional(&e->ip)) || visited) { unsigned int oldpos, size; if ((strcmp(t->target.u.user.name, XT_STANDARD_TARGET) == 0) && t->verdict < -NF_MAX_VERDICT - 1) { duprintf("mark_source_chains: bad " "negative verdict (%i)\n", t->verdict); return 0; } /* Return: backtrack through the last big jump. */ do { e->comefrom ^= (1<<NF_INET_NUMHOOKS); #ifdef DEBUG_IP_FIREWALL_USER if (e->comefrom & (1 << NF_INET_NUMHOOKS)) { duprintf("Back unset " "on hook %u " "rule %u\n", hook, pos); } #endif oldpos = pos; pos = e->counters.pcnt; e->counters.pcnt = 0; /* We're at the start. */ if (pos == oldpos) goto next; e = (struct ipt_entry *) (entry0 + pos); } while (oldpos == pos + e->next_offset); /* Move along one */ size = e->next_offset; e = (struct ipt_entry *) (entry0 + pos + size); e->counters.pcnt = pos; pos += size; } else { int newpos = t->verdict; if (strcmp(t->target.u.user.name, XT_STANDARD_TARGET) == 0 && newpos >= 0) { if (newpos > newinfo->size - sizeof(struct ipt_entry)) { duprintf("mark_source_chains: " "bad verdict (%i)\n", newpos); return 0; } /* This a jump; chase it. */ duprintf("Jump rule %u -> %u\n", pos, newpos); } else { /* ... this is a fallthru */ newpos = pos + e->next_offset; } e = (struct ipt_entry *) (entry0 + newpos); e->counters.pcnt = pos; pos = newpos; } } next: duprintf("Finished chain %u\n", hook); } return 1; } static void cleanup_match(struct xt_entry_match *m, struct net *net) { struct xt_mtdtor_param par; par.net = net; par.match = m->u.kernel.match; par.matchinfo = m->data; par.family = NFPROTO_IPV4; if (par.match->destroy != NULL) par.match->destroy(&par); module_put(par.match->me); } static int check_entry(const struct ipt_entry *e, const char *name) { const struct xt_entry_target *t; if (!ip_checkentry(&e->ip)) { duprintf("ip check failed %p %s.\n", e, name); return -EINVAL; } if (e->target_offset + sizeof(struct xt_entry_target) > e->next_offset) return -EINVAL; t = ipt_get_target_c(e); if (e->target_offset + t->u.target_size > e->next_offset) return -EINVAL; return 0; } static int check_match(struct xt_entry_match *m, struct xt_mtchk_param *par) { const struct ipt_ip *ip = par->entryinfo; int ret; par->match = m->u.kernel.match; par->matchinfo = m->data; ret = xt_check_match(par, m->u.match_size - sizeof(*m), ip->proto, ip->invflags & IPT_INV_PROTO); if (ret < 0) { duprintf("check failed for `%s'.\n", par->match->name); return ret; } return 0; } static int find_check_match(struct xt_entry_match *m, struct xt_mtchk_param *par) { struct xt_match *match; int ret; match = xt_request_find_match(NFPROTO_IPV4, m->u.user.name, m->u.user.revision); if (IS_ERR(match)) { duprintf("find_check_match: `%s' not found\n", m->u.user.name); return PTR_ERR(match); } m->u.kernel.match = match; ret = check_match(m, par); if (ret) goto err; return 0; err: module_put(m->u.kernel.match->me); return ret; } static int check_target(struct ipt_entry *e, struct net *net, const char *name) { struct xt_entry_target *t = ipt_get_target(e); struct xt_tgchk_param par = { .net = net, .table = name, .entryinfo = e, .target = t->u.kernel.target, .targinfo = t->data, .hook_mask = e->comefrom, .family = NFPROTO_IPV4, }; int ret; ret = xt_check_target(&par, t->u.target_size - sizeof(*t), e->ip.proto, e->ip.invflags & IPT_INV_PROTO); if (ret < 0) { duprintf("check failed for `%s'.\n", t->u.kernel.target->name); return ret; } return 0; } static int find_check_entry(struct ipt_entry *e, struct net *net, const char *name, unsigned int size) { struct xt_entry_target *t; struct xt_target *target; int ret; unsigned int j; struct xt_mtchk_param mtpar; struct xt_entry_match *ematch; ret = check_entry(e, name); if (ret) return ret; j = 0; mtpar.net = net; mtpar.table = name; mtpar.entryinfo = &e->ip; mtpar.hook_mask = e->comefrom; mtpar.family = NFPROTO_IPV4; xt_ematch_foreach(ematch, e) { ret = find_check_match(ematch, &mtpar); if (ret != 0) goto cleanup_matches; ++j; } t = ipt_get_target(e); target = xt_request_find_target(NFPROTO_IPV4, t->u.user.name, t->u.user.revision); if (IS_ERR(target)) { duprintf("find_check_entry: `%s' not found\n", t->u.user.name); ret = PTR_ERR(target); goto cleanup_matches; } t->u.kernel.target = target; ret = check_target(e, net, name); if (ret) goto err; return 0; err: module_put(t->u.kernel.target->me); cleanup_matches: xt_ematch_foreach(ematch, e) { if (j-- == 0) break; cleanup_match(ematch, net); } return ret; } static bool check_underflow(const struct ipt_entry *e) { const struct xt_entry_target *t; unsigned int verdict; if (!unconditional(&e->ip)) return false; t = ipt_get_target_c(e); if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0) return false; verdict = ((struct xt_standard_target *)t)->verdict; verdict = -verdict - 1; return verdict == NF_DROP || verdict == NF_ACCEPT; } static int check_entry_size_and_hooks(struct ipt_entry *e, struct xt_table_info *newinfo, const unsigned char *base, const unsigned char *limit, const unsigned int *hook_entries, const unsigned int *underflows, unsigned int valid_hooks) { unsigned int h; if ((unsigned long)e % __alignof__(struct ipt_entry) != 0 || (unsigned char *)e + sizeof(struct ipt_entry) >= limit) { duprintf("Bad offset %p\n", e); return -EINVAL; } if (e->next_offset < sizeof(struct ipt_entry) + sizeof(struct xt_entry_target)) { duprintf("checking: element %p size %u\n", e, e->next_offset); return -EINVAL; } /* Check hooks & underflows */ for (h = 0; h < NF_INET_NUMHOOKS; h++) { if (!(valid_hooks & (1 << h))) continue; if ((unsigned char *)e - base == hook_entries[h]) newinfo->hook_entry[h] = hook_entries[h]; if ((unsigned char *)e - base == underflows[h]) { if (!check_underflow(e)) { pr_err("Underflows must be unconditional and " "use the STANDARD target with " "ACCEPT/DROP\n"); return -EINVAL; } newinfo->underflow[h] = underflows[h]; } } /* Clear counters and comefrom */ e->counters = ((struct xt_counters) { 0, 0 }); e->comefrom = 0; return 0; } static void cleanup_entry(struct ipt_entry *e, struct net *net) { struct xt_tgdtor_param par; struct xt_entry_target *t; struct xt_entry_match *ematch; /* Cleanup all matches */ xt_ematch_foreach(ematch, e) cleanup_match(ematch, net); t = ipt_get_target(e); par.net = net; par.target = t->u.kernel.target; par.targinfo = t->data; par.family = NFPROTO_IPV4; if (par.target->destroy != NULL) par.target->destroy(&par); module_put(par.target->me); } /* Checks and translates the user-supplied table segment (held in newinfo) */ static int translate_table(struct net *net, struct xt_table_info *newinfo, void *entry0, const struct ipt_replace *repl) { struct ipt_entry *iter; unsigned int i; int ret = 0; newinfo->size = repl->size; newinfo->number = repl->num_entries; /* Init all hooks to impossible value. */ for (i = 0; i < NF_INET_NUMHOOKS; i++) { newinfo->hook_entry[i] = 0xFFFFFFFF; newinfo->underflow[i] = 0xFFFFFFFF; } duprintf("translate_table: size %u\n", newinfo->size); i = 0; /* Walk through entries, checking offsets. */ xt_entry_foreach(iter, entry0, newinfo->size) { ret = check_entry_size_and_hooks(iter, newinfo, entry0, entry0 + repl->size, repl->hook_entry, repl->underflow, repl->valid_hooks); if (ret != 0) return ret; ++i; if (strcmp(ipt_get_target(iter)->u.user.name, XT_ERROR_TARGET) == 0) ++newinfo->stacksize; } if (i != repl->num_entries) { duprintf("translate_table: %u not %u entries\n", i, repl->num_entries); return -EINVAL; } /* Check hooks all assigned */ for (i = 0; i < NF_INET_NUMHOOKS; i++) { /* Only hooks which are valid */ if (!(repl->valid_hooks & (1 << i))) continue; if (newinfo->hook_entry[i] == 0xFFFFFFFF) { duprintf("Invalid hook entry %u %u\n", i, repl->hook_entry[i]); return -EINVAL; } if (newinfo->underflow[i] == 0xFFFFFFFF) { duprintf("Invalid underflow %u %u\n", i, repl->underflow[i]); return -EINVAL; } } if (!mark_source_chains(newinfo, repl->valid_hooks, entry0)) return -ELOOP; /* Finally, each sanity check must pass */ i = 0; xt_entry_foreach(iter, entry0, newinfo->size) { ret = find_check_entry(iter, net, repl->name, repl->size); if (ret != 0) break; ++i; } if (ret != 0) { xt_entry_foreach(iter, entry0, newinfo->size) { if (i-- == 0) break; cleanup_entry(iter, net); } return ret; } /* And one copy for every other CPU */ for_each_possible_cpu(i) { if (newinfo->entries[i] && newinfo->entries[i] != entry0) memcpy(newinfo->entries[i], entry0, newinfo->size); } return ret; } static void get_counters(const struct xt_table_info *t, struct xt_counters counters[]) { struct ipt_entry *iter; unsigned int cpu; unsigned int i; for_each_possible_cpu(cpu) { seqcount_t *s = &per_cpu(xt_recseq, cpu); i = 0; xt_entry_foreach(iter, t->entries[cpu], t->size) { u64 bcnt, pcnt; unsigned int start; do { start = read_seqcount_begin(s); bcnt = iter->counters.bcnt; pcnt = iter->counters.pcnt; } while (read_seqcount_retry(s, start)); ADD_COUNTER(counters[i], bcnt, pcnt); ++i; /* macro does multi eval of i */ } } } static struct xt_counters *alloc_counters(const struct xt_table *table) { unsigned int countersize; struct xt_counters *counters; const struct xt_table_info *private = table->private; /* We need atomic snapshot of counters: rest doesn't change (other than comefrom, which userspace doesn't care about). */ countersize = sizeof(struct xt_counters) * private->number; counters = vzalloc(countersize); if (counters == NULL) return ERR_PTR(-ENOMEM); get_counters(private, counters); return counters; } static int copy_entries_to_user(unsigned int total_size, const struct xt_table *table, void __user *userptr) { unsigned int off, num; const struct ipt_entry *e; struct xt_counters *counters; const struct xt_table_info *private = table->private; int ret = 0; const void *loc_cpu_entry; counters = alloc_counters(table); if (IS_ERR(counters)) return PTR_ERR(counters); /* choose the copy that is on our node/cpu, ... * This choice is lazy (because current thread is * allowed to migrate to another cpu) */ loc_cpu_entry = private->entries[raw_smp_processor_id()]; if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) { ret = -EFAULT; goto free_counters; } /* FIXME: use iterator macros --RR */ /* ... then go back and fix counters and names */ for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){ unsigned int i; const struct xt_entry_match *m; const struct xt_entry_target *t; e = (struct ipt_entry *)(loc_cpu_entry + off); if (copy_to_user(userptr + off + offsetof(struct ipt_entry, counters), &counters[num], sizeof(counters[num])) != 0) { ret = -EFAULT; goto free_counters; } for (i = sizeof(struct ipt_entry); i < e->target_offset; i += m->u.match_size) { m = (void *)e + i; if (copy_to_user(userptr + off + i + offsetof(struct xt_entry_match, u.user.name), m->u.kernel.match->name, strlen(m->u.kernel.match->name)+1) != 0) { ret = -EFAULT; goto free_counters; } } t = ipt_get_target_c(e); if (copy_to_user(userptr + off + e->target_offset + offsetof(struct xt_entry_target, u.user.name), t->u.kernel.target->name, strlen(t->u.kernel.target->name)+1) != 0) { ret = -EFAULT; goto free_counters; } } free_counters: vfree(counters); return ret; } #ifdef CONFIG_COMPAT static void compat_standard_from_user(void *dst, const void *src) { int v = *(compat_int_t *)src; if (v > 0) v += xt_compat_calc_jump(AF_INET, v); memcpy(dst, &v, sizeof(v)); } static int compat_standard_to_user(void __user *dst, const void *src) { compat_int_t cv = *(int *)src; if (cv > 0) cv -= xt_compat_calc_jump(AF_INET, cv); return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0; } static int compat_calc_entry(const struct ipt_entry *e, const struct xt_table_info *info, const void *base, struct xt_table_info *newinfo) { const struct xt_entry_match *ematch; const struct xt_entry_target *t; unsigned int entry_offset; int off, i, ret; off = sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry); entry_offset = (void *)e - base; xt_ematch_foreach(ematch, e) off += xt_compat_match_offset(ematch->u.kernel.match); t = ipt_get_target_c(e); off += xt_compat_target_offset(t->u.kernel.target); newinfo->size -= off; ret = xt_compat_add_offset(AF_INET, entry_offset, off); if (ret) return ret; for (i = 0; i < NF_INET_NUMHOOKS; i++) { if (info->hook_entry[i] && (e < (struct ipt_entry *)(base + info->hook_entry[i]))) newinfo->hook_entry[i] -= off; if (info->underflow[i] && (e < (struct ipt_entry *)(base + info->underflow[i]))) newinfo->underflow[i] -= off; } return 0; } static int compat_table_info(const struct xt_table_info *info, struct xt_table_info *newinfo) { struct ipt_entry *iter; void *loc_cpu_entry; int ret; if (!newinfo || !info) return -EINVAL; /* we dont care about newinfo->entries[] */ memcpy(newinfo, info, offsetof(struct xt_table_info, entries)); newinfo->initial_entries = 0; loc_cpu_entry = info->entries[raw_smp_processor_id()]; xt_compat_init_offsets(AF_INET, info->number); xt_entry_foreach(iter, loc_cpu_entry, info->size) { ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo); if (ret != 0) return ret; } return 0; } #endif static int get_info(struct net *net, void __user *user, const int *len, int compat) { char name[XT_TABLE_MAXNAMELEN]; struct xt_table *t; int ret; if (*len != sizeof(struct ipt_getinfo)) { duprintf("length %u != %zu\n", *len, sizeof(struct ipt_getinfo)); return -EINVAL; } if (copy_from_user(name, user, sizeof(name)) != 0) return -EFAULT; name[XT_TABLE_MAXNAMELEN-1] = '\0'; #ifdef CONFIG_COMPAT if (compat) xt_compat_lock(AF_INET); #endif t = try_then_request_module(xt_find_table_lock(net, AF_INET, name), "iptable_%s", name); if (t && !IS_ERR(t)) { struct ipt_getinfo info; const struct xt_table_info *private = t->private; #ifdef CONFIG_COMPAT struct xt_table_info tmp; if (compat) { ret = compat_table_info(private, &tmp); xt_compat_flush_offsets(AF_INET); private = &tmp; } #endif memset(&info, 0, sizeof(info)); info.valid_hooks = t->valid_hooks; memcpy(info.hook_entry, private->hook_entry, sizeof(info.hook_entry)); memcpy(info.underflow, private->underflow, sizeof(info.underflow)); info.num_entries = private->number; info.size = private->size; strcpy(info.name, name); if (copy_to_user(user, &info, *len) != 0) ret = -EFAULT; else ret = 0; xt_table_unlock(t); module_put(t->me); } else ret = t ? PTR_ERR(t) : -ENOENT; #ifdef CONFIG_COMPAT if (compat) xt_compat_unlock(AF_INET); #endif return ret; } static int get_entries(struct net *net, struct ipt_get_entries __user *uptr, const int *len) { int ret; struct ipt_get_entries get; struct xt_table *t; if (*len < sizeof(get)) { duprintf("get_entries: %u < %zu\n", *len, sizeof(get)); return -EINVAL; } if (copy_from_user(&get, uptr, sizeof(get)) != 0) return -EFAULT; if (*len != sizeof(struct ipt_get_entries) + get.size) { duprintf("get_entries: %u != %zu\n", *len, sizeof(get) + get.size); return -EINVAL; } t = xt_find_table_lock(net, AF_INET, get.name); if (t && !IS_ERR(t)) { const struct xt_table_info *private = t->private; duprintf("t->private->number = %u\n", private->number); if (get.size == private->size) ret = copy_entries_to_user(private->size, t, uptr->entrytable); else { duprintf("get_entries: I've got %u not %u!\n", private->size, get.size); ret = -EAGAIN; } module_put(t->me); xt_table_unlock(t); } else ret = t ? PTR_ERR(t) : -ENOENT; return ret; } static int __do_replace(struct net *net, const char *name, unsigned int valid_hooks, struct xt_table_info *newinfo, unsigned int num_counters, void __user *counters_ptr) { int ret; struct xt_table *t; struct xt_table_info *oldinfo; struct xt_counters *counters; void *loc_cpu_old_entry; struct ipt_entry *iter; ret = 0; counters = vzalloc(num_counters * sizeof(struct xt_counters)); if (!counters) { ret = -ENOMEM; goto out; } t = try_then_request_module(xt_find_table_lock(net, AF_INET, name), "iptable_%s", name); if (!t || IS_ERR(t)) { ret = t ? PTR_ERR(t) : -ENOENT; goto free_newinfo_counters_untrans; } /* You lied! */ if (valid_hooks != t->valid_hooks) { duprintf("Valid hook crap: %08X vs %08X\n", valid_hooks, t->valid_hooks); ret = -EINVAL; goto put_module; } oldinfo = xt_replace_table(t, num_counters, newinfo, &ret); if (!oldinfo) goto put_module; /* Update module usage count based on number of rules */ duprintf("do_replace: oldnum=%u, initnum=%u, newnum=%u\n", oldinfo->number, oldinfo->initial_entries, newinfo->number); if ((oldinfo->number > oldinfo->initial_entries) || (newinfo->number <= oldinfo->initial_entries)) module_put(t->me); if ((oldinfo->number > oldinfo->initial_entries) && (newinfo->number <= oldinfo->initial_entries)) module_put(t->me); /* Get the old counters, and synchronize with replace */ get_counters(oldinfo, counters); /* Decrease module usage counts and free resource */ loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()]; xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size) cleanup_entry(iter, net); xt_free_table_info(oldinfo); if (copy_to_user(counters_ptr, counters, sizeof(struct xt_counters) * num_counters) != 0) ret = -EFAULT; vfree(counters); xt_table_unlock(t); return ret; put_module: module_put(t->me); xt_table_unlock(t); free_newinfo_counters_untrans: vfree(counters); out: return ret; } static int do_replace(struct net *net, const void __user *user, unsigned int len) { int ret; struct ipt_replace tmp; struct xt_table_info *newinfo; void *loc_cpu_entry; struct ipt_entry *iter; if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) return -EFAULT; /* overflow check */ if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) return -ENOMEM; tmp.name[sizeof(tmp.name)-1] = 0; newinfo = xt_alloc_table_info(tmp.size); if (!newinfo) return -ENOMEM; /* choose the copy that is on our node/cpu */ loc_cpu_entry = newinfo->entries[raw_smp_processor_id()]; if (copy_from_user(loc_cpu_entry, user + sizeof(tmp), tmp.size) != 0) { ret = -EFAULT; goto free_newinfo; } ret = translate_table(net, newinfo, loc_cpu_entry, &tmp); if (ret != 0) goto free_newinfo; duprintf("Translated table\n"); ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo, tmp.num_counters, tmp.counters); if (ret) goto free_newinfo_untrans; return 0; free_newinfo_untrans: xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) cleanup_entry(iter, net); free_newinfo: xt_free_table_info(newinfo); return ret; } static int do_add_counters(struct net *net, const void __user *user, unsigned int len, int compat) { unsigned int i, curcpu; struct xt_counters_info tmp; struct xt_counters *paddc; unsigned int num_counters; const char *name; int size; void *ptmp; struct xt_table *t; const struct xt_table_info *private; int ret = 0; void *loc_cpu_entry; struct ipt_entry *iter; unsigned int addend; #ifdef CONFIG_COMPAT struct compat_xt_counters_info compat_tmp; if (compat) { ptmp = &compat_tmp; size = sizeof(struct compat_xt_counters_info); } else #endif { ptmp = &tmp; size = sizeof(struct xt_counters_info); } if (copy_from_user(ptmp, user, size) != 0) return -EFAULT; #ifdef CONFIG_COMPAT if (compat) { num_counters = compat_tmp.num_counters; name = compat_tmp.name; } else #endif { num_counters = tmp.num_counters; name = tmp.name; } if (len != size + num_counters * sizeof(struct xt_counters)) return -EINVAL; paddc = vmalloc(len - size); if (!paddc) return -ENOMEM; if (copy_from_user(paddc, user + size, len - size) != 0) { ret = -EFAULT; goto free; } t = xt_find_table_lock(net, AF_INET, name); if (!t || IS_ERR(t)) { ret = t ? PTR_ERR(t) : -ENOENT; goto free; } local_bh_disable(); private = t->private; if (private->number != num_counters) { ret = -EINVAL; goto unlock_up_free; } i = 0; /* Choose the copy that is on our node */ curcpu = smp_processor_id(); loc_cpu_entry = private->entries[curcpu]; addend = xt_write_recseq_begin(); xt_entry_foreach(iter, loc_cpu_entry, private->size) { ADD_COUNTER(iter->counters, paddc[i].bcnt, paddc[i].pcnt); ++i; } xt_write_recseq_end(addend); unlock_up_free: local_bh_enable(); xt_table_unlock(t); module_put(t->me); free: vfree(paddc); return ret; } #ifdef CONFIG_COMPAT struct compat_ipt_replace { char name[XT_TABLE_MAXNAMELEN]; u32 valid_hooks; u32 num_entries; u32 size; u32 hook_entry[NF_INET_NUMHOOKS]; u32 underflow[NF_INET_NUMHOOKS]; u32 num_counters; compat_uptr_t counters; /* struct xt_counters * */ struct compat_ipt_entry entries[0]; }; static int compat_copy_entry_to_user(struct ipt_entry *e, void __user **dstptr, unsigned int *size, struct xt_counters *counters, unsigned int i) { struct xt_entry_target *t; struct compat_ipt_entry __user *ce; u_int16_t target_offset, next_offset; compat_uint_t origsize; const struct xt_entry_match *ematch; int ret = 0; origsize = *size; ce = (struct compat_ipt_entry __user *)*dstptr; if (copy_to_user(ce, e, sizeof(struct ipt_entry)) != 0 || copy_to_user(&ce->counters, &counters[i], sizeof(counters[i])) != 0) return -EFAULT; *dstptr += sizeof(struct compat_ipt_entry); *size -= sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry); xt_ematch_foreach(ematch, e) { ret = xt_compat_match_to_user(ematch, dstptr, size); if (ret != 0) return ret; } target_offset = e->target_offset - (origsize - *size); t = ipt_get_target(e); ret = xt_compat_target_to_user(t, dstptr, size); if (ret) return ret; next_offset = e->next_offset - (origsize - *size); if (put_user(target_offset, &ce->target_offset) != 0 || put_user(next_offset, &ce->next_offset) != 0) return -EFAULT; return 0; } static int compat_find_calc_match(struct xt_entry_match *m, const char *name, const struct ipt_ip *ip, unsigned int hookmask, int *size) { struct xt_match *match; match = xt_request_find_match(NFPROTO_IPV4, m->u.user.name, m->u.user.revision); if (IS_ERR(match)) { duprintf("compat_check_calc_match: `%s' not found\n", m->u.user.name); return PTR_ERR(match); } m->u.kernel.match = match; *size += xt_compat_match_offset(match); return 0; } static void compat_release_entry(struct compat_ipt_entry *e) { struct xt_entry_target *t; struct xt_entry_match *ematch; /* Cleanup all matches */ xt_ematch_foreach(ematch, e) module_put(ematch->u.kernel.match->me); t = compat_ipt_get_target(e); module_put(t->u.kernel.target->me); } static int check_compat_entry_size_and_hooks(struct compat_ipt_entry *e, struct xt_table_info *newinfo, unsigned int *size, const unsigned char *base, const unsigned char *limit, const unsigned int *hook_entries, const unsigned int *underflows, const char *name) { struct xt_entry_match *ematch; struct xt_entry_target *t; struct xt_target *target; unsigned int entry_offset; unsigned int j; int ret, off, h; duprintf("check_compat_entry_size_and_hooks %p\n", e); if ((unsigned long)e % __alignof__(struct compat_ipt_entry) != 0 || (unsigned char *)e + sizeof(struct compat_ipt_entry) >= limit) { duprintf("Bad offset %p, limit = %p\n", e, limit); return -EINVAL; } if (e->next_offset < sizeof(struct compat_ipt_entry) + sizeof(struct compat_xt_entry_target)) { duprintf("checking: element %p size %u\n", e, e->next_offset); return -EINVAL; } /* For purposes of check_entry casting the compat entry is fine */ ret = check_entry((struct ipt_entry *)e, name); if (ret) return ret; off = sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry); entry_offset = (void *)e - (void *)base; j = 0; xt_ematch_foreach(ematch, e) { ret = compat_find_calc_match(ematch, name, &e->ip, e->comefrom, &off); if (ret != 0) goto release_matches; ++j; } t = compat_ipt_get_target(e); target = xt_request_find_target(NFPROTO_IPV4, t->u.user.name, t->u.user.revision); if (IS_ERR(target)) { duprintf("check_compat_entry_size_and_hooks: `%s' not found\n", t->u.user.name); ret = PTR_ERR(target); goto release_matches; } t->u.kernel.target = target; off += xt_compat_target_offset(target); *size += off; ret = xt_compat_add_offset(AF_INET, entry_offset, off); if (ret) goto out; /* Check hooks & underflows */ for (h = 0; h < NF_INET_NUMHOOKS; h++) { if ((unsigned char *)e - base == hook_entries[h]) newinfo->hook_entry[h] = hook_entries[h]; if ((unsigned char *)e - base == underflows[h]) newinfo->underflow[h] = underflows[h]; } /* Clear counters and comefrom */ memset(&e->counters, 0, sizeof(e->counters)); e->comefrom = 0; return 0; out: module_put(t->u.kernel.target->me); release_matches: xt_ematch_foreach(ematch, e) { if (j-- == 0) break; module_put(ematch->u.kernel.match->me); } return ret; } static int compat_copy_entry_from_user(struct compat_ipt_entry *e, void **dstptr, unsigned int *size, const char *name, struct xt_table_info *newinfo, unsigned char *base) { struct xt_entry_target *t; struct xt_target *target; struct ipt_entry *de; unsigned int origsize; int ret, h; struct xt_entry_match *ematch; ret = 0; origsize = *size; de = (struct ipt_entry *)*dstptr; memcpy(de, e, sizeof(struct ipt_entry)); memcpy(&de->counters, &e->counters, sizeof(e->counters)); *dstptr += sizeof(struct ipt_entry); *size += sizeof(struct ipt_entry) - sizeof(struct compat_ipt_entry); xt_ematch_foreach(ematch, e) { ret = xt_compat_match_from_user(ematch, dstptr, size); if (ret != 0) return ret; } de->target_offset = e->target_offset - (origsize - *size); t = compat_ipt_get_target(e); target = t->u.kernel.target; xt_compat_target_from_user(t, dstptr, size); de->next_offset = e->next_offset - (origsize - *size); for (h = 0; h < NF_INET_NUMHOOKS; h++) { if ((unsigned char *)de - base < newinfo->hook_entry[h]) newinfo->hook_entry[h] -= origsize - *size; if ((unsigned char *)de - base < newinfo->underflow[h]) newinfo->underflow[h] -= origsize - *size; } return ret; } static int compat_check_entry(struct ipt_entry *e, struct net *net, const char *name) { struct xt_entry_match *ematch; struct xt_mtchk_param mtpar; unsigned int j; int ret = 0; j = 0; mtpar.net = net; mtpar.table = name; mtpar.entryinfo = &e->ip; mtpar.hook_mask = e->comefrom; mtpar.family = NFPROTO_IPV4; xt_ematch_foreach(ematch, e) { ret = check_match(ematch, &mtpar); if (ret != 0) goto cleanup_matches; ++j; } ret = check_target(e, net, name); if (ret) goto cleanup_matches; return 0; cleanup_matches: xt_ematch_foreach(ematch, e) { if (j-- == 0) break; cleanup_match(ematch, net); } return ret; } static int translate_compat_table(struct net *net, const char *name, unsigned int valid_hooks, struct xt_table_info **pinfo, void **pentry0, unsigned int total_size, unsigned int number, unsigned int *hook_entries, unsigned int *underflows) { unsigned int i, j; struct xt_table_info *newinfo, *info; void *pos, *entry0, *entry1; struct compat_ipt_entry *iter0; struct ipt_entry *iter1; unsigned int size; int ret; info = *pinfo; entry0 = *pentry0; size = total_size; info->number = number; /* Init all hooks to impossible value. */ for (i = 0; i < NF_INET_NUMHOOKS; i++) { info->hook_entry[i] = 0xFFFFFFFF; info->underflow[i] = 0xFFFFFFFF; } duprintf("translate_compat_table: size %u\n", info->size); j = 0; xt_compat_lock(AF_INET); xt_compat_init_offsets(AF_INET, number); /* Walk through entries, checking offsets. */ xt_entry_foreach(iter0, entry0, total_size) { ret = check_compat_entry_size_and_hooks(iter0, info, &size, entry0, entry0 + total_size, hook_entries, underflows, name); if (ret != 0) goto out_unlock; ++j; } ret = -EINVAL; if (j != number) { duprintf("translate_compat_table: %u not %u entries\n", j, number); goto out_unlock; } /* Check hooks all assigned */ for (i = 0; i < NF_INET_NUMHOOKS; i++) { /* Only hooks which are valid */ if (!(valid_hooks & (1 << i))) continue; if (info->hook_entry[i] == 0xFFFFFFFF) { duprintf("Invalid hook entry %u %u\n", i, hook_entries[i]); goto out_unlock; } if (info->underflow[i] == 0xFFFFFFFF) { duprintf("Invalid underflow %u %u\n", i, underflows[i]); goto out_unlock; } } ret = -ENOMEM; newinfo = xt_alloc_table_info(size); if (!newinfo) goto out_unlock; newinfo->number = number; for (i = 0; i < NF_INET_NUMHOOKS; i++) { newinfo->hook_entry[i] = info->hook_entry[i]; newinfo->underflow[i] = info->underflow[i]; } entry1 = newinfo->entries[raw_smp_processor_id()]; pos = entry1; size = total_size; xt_entry_foreach(iter0, entry0, total_size) { ret = compat_copy_entry_from_user(iter0, &pos, &size, name, newinfo, entry1); if (ret != 0) break; } xt_compat_flush_offsets(AF_INET); xt_compat_unlock(AF_INET); if (ret) goto free_newinfo; ret = -ELOOP; if (!mark_source_chains(newinfo, valid_hooks, entry1)) goto free_newinfo; i = 0; xt_entry_foreach(iter1, entry1, newinfo->size) { ret = compat_check_entry(iter1, net, name); if (ret != 0) break; ++i; if (strcmp(ipt_get_target(iter1)->u.user.name, XT_ERROR_TARGET) == 0) ++newinfo->stacksize; } if (ret) { /* * The first i matches need cleanup_entry (calls ->destroy) * because they had called ->check already. The other j-i * entries need only release. */ int skip = i; j -= i; xt_entry_foreach(iter0, entry0, newinfo->size) { if (skip-- > 0) continue; if (j-- == 0) break; compat_release_entry(iter0); } xt_entry_foreach(iter1, entry1, newinfo->size) { if (i-- == 0) break; cleanup_entry(iter1, net); } xt_free_table_info(newinfo); return ret; } /* And one copy for every other CPU */ for_each_possible_cpu(i) if (newinfo->entries[i] && newinfo->entries[i] != entry1) memcpy(newinfo->entries[i], entry1, newinfo->size); *pinfo = newinfo; *pentry0 = entry1; xt_free_table_info(info); return 0; free_newinfo: xt_free_table_info(newinfo); out: xt_entry_foreach(iter0, entry0, total_size) { if (j-- == 0) break; compat_release_entry(iter0); } return ret; out_unlock: xt_compat_flush_offsets(AF_INET); xt_compat_unlock(AF_INET); goto out; } static int compat_do_replace(struct net *net, void __user *user, unsigned int len) { int ret; struct compat_ipt_replace tmp; struct xt_table_info *newinfo; void *loc_cpu_entry; struct ipt_entry *iter; if (copy_from_user(&tmp, user, sizeof(tmp)) != 0) return -EFAULT; /* overflow check */ if (tmp.size >= INT_MAX / num_possible_cpus()) return -ENOMEM; if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) return -ENOMEM; tmp.name[sizeof(tmp.name)-1] = 0; newinfo = xt_alloc_table_info(tmp.size); if (!newinfo) return -ENOMEM; /* choose the copy that is on our node/cpu */ loc_cpu_entry = newinfo->entries[raw_smp_processor_id()]; if (copy_from_user(loc_cpu_entry, user + sizeof(tmp), tmp.size) != 0) { ret = -EFAULT; goto free_newinfo; } ret = translate_compat_table(net, tmp.name, tmp.valid_hooks, &newinfo, &loc_cpu_entry, tmp.size, tmp.num_entries, tmp.hook_entry, tmp.underflow); if (ret != 0) goto free_newinfo; duprintf("compat_do_replace: Translated table\n"); ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo, tmp.num_counters, compat_ptr(tmp.counters)); if (ret) goto free_newinfo_untrans; return 0; free_newinfo_untrans: xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) cleanup_entry(iter, net); free_newinfo: xt_free_table_info(newinfo); return ret; } static int compat_do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) { int ret; if (!capable(CAP_NET_ADMIN)) return -EPERM; switch (cmd) { case IPT_SO_SET_REPLACE: ret = compat_do_replace(sock_net(sk), user, len); break; case IPT_SO_SET_ADD_COUNTERS: ret = do_add_counters(sock_net(sk), user, len, 1); break; default: duprintf("do_ipt_set_ctl: unknown request %i\n", cmd); ret = -EINVAL; } return ret; } struct compat_ipt_get_entries { char name[XT_TABLE_MAXNAMELEN]; compat_uint_t size; struct compat_ipt_entry entrytable[0]; }; static int compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table, void __user *userptr) { struct xt_counters *counters; const struct xt_table_info *private = table->private; void __user *pos; unsigned int size; int ret = 0; const void *loc_cpu_entry; unsigned int i = 0; struct ipt_entry *iter; counters = alloc_counters(table); if (IS_ERR(counters)) return PTR_ERR(counters); /* choose the copy that is on our node/cpu, ... * This choice is lazy (because current thread is * allowed to migrate to another cpu) */ loc_cpu_entry = private->entries[raw_smp_processor_id()]; pos = userptr; size = total_size; xt_entry_foreach(iter, loc_cpu_entry, total_size) { ret = compat_copy_entry_to_user(iter, &pos, &size, counters, i++); if (ret != 0) break; } vfree(counters); return ret; } static int compat_get_entries(struct net *net, struct compat_ipt_get_entries __user *uptr, int *len) { int ret; struct compat_ipt_get_entries get; struct xt_table *t; if (*len < sizeof(get)) { duprintf("compat_get_entries: %u < %zu\n", *len, sizeof(get)); return -EINVAL; } if (copy_from_user(&get, uptr, sizeof(get)) != 0) return -EFAULT; if (*len != sizeof(struct compat_ipt_get_entries) + get.size) { duprintf("compat_get_entries: %u != %zu\n", *len, sizeof(get) + get.size); return -EINVAL; } xt_compat_lock(AF_INET); t = xt_find_table_lock(net, AF_INET, get.name); if (t && !IS_ERR(t)) { const struct xt_table_info *private = t->private; struct xt_table_info info; duprintf("t->private->number = %u\n", private->number); ret = compat_table_info(private, &info); if (!ret && get.size == info.size) { ret = compat_copy_entries_to_user(private->size, t, uptr->entrytable); } else if (!ret) { duprintf("compat_get_entries: I've got %u not %u!\n", private->size, get.size); ret = -EAGAIN; } xt_compat_flush_offsets(AF_INET); module_put(t->me); xt_table_unlock(t); } else ret = t ? PTR_ERR(t) : -ENOENT; xt_compat_unlock(AF_INET); return ret; } static int do_ipt_get_ctl(struct sock *, int, void __user *, int *); static int compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) { int ret; if (!capable(CAP_NET_ADMIN)) return -EPERM; switch (cmd) { case IPT_SO_GET_INFO: ret = get_info(sock_net(sk), user, len, 1); break; case IPT_SO_GET_ENTRIES: ret = compat_get_entries(sock_net(sk), user, len); break; default: ret = do_ipt_get_ctl(sk, cmd, user, len); } return ret; } #endif static int do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) { int ret; if (!capable(CAP_NET_ADMIN)) return -EPERM; switch (cmd) { case IPT_SO_SET_REPLACE: ret = do_replace(sock_net(sk), user, len); break; case IPT_SO_SET_ADD_COUNTERS: ret = do_add_counters(sock_net(sk), user, len, 0); break; default: duprintf("do_ipt_set_ctl: unknown request %i\n", cmd); ret = -EINVAL; } return ret; } static int do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) { int ret; if (!capable(CAP_NET_ADMIN)) return -EPERM; switch (cmd) { case IPT_SO_GET_INFO: ret = get_info(sock_net(sk), user, len, 0); break; case IPT_SO_GET_ENTRIES: ret = get_entries(sock_net(sk), user, len); break; case IPT_SO_GET_REVISION_MATCH: case IPT_SO_GET_REVISION_TARGET: { struct xt_get_revision rev; int target; if (*len != sizeof(rev)) { ret = -EINVAL; break; } if (copy_from_user(&rev, user, sizeof(rev)) != 0) { ret = -EFAULT; break; } rev.name[sizeof(rev.name)-1] = 0; if (cmd == IPT_SO_GET_REVISION_TARGET) target = 1; else target = 0; try_then_request_module(xt_find_revision(AF_INET, rev.name, rev.revision, target, &ret), "ipt_%s", rev.name); break; } default: duprintf("do_ipt_get_ctl: unknown request %i\n", cmd); ret = -EINVAL; } return ret; } struct xt_table *ipt_register_table(struct net *net, const struct xt_table *table, const struct ipt_replace *repl) { int ret; struct xt_table_info *newinfo; struct xt_table_info bootstrap = {0}; void *loc_cpu_entry; struct xt_table *new_table; newinfo = xt_alloc_table_info(repl->size); if (!newinfo) { ret = -ENOMEM; goto out; } /* choose the copy on our node/cpu, but dont care about preemption */ loc_cpu_entry = newinfo->entries[raw_smp_processor_id()]; memcpy(loc_cpu_entry, repl->entries, repl->size); ret = translate_table(net, newinfo, loc_cpu_entry, repl); if (ret != 0) goto out_free; new_table = xt_register_table(net, table, &bootstrap, newinfo); if (IS_ERR(new_table)) { ret = PTR_ERR(new_table); goto out_free; } return new_table; out_free: xt_free_table_info(newinfo); out: return ERR_PTR(ret); } void ipt_unregister_table(struct net *net, struct xt_table *table) { struct xt_table_info *private; void *loc_cpu_entry; struct module *table_owner = table->me; struct ipt_entry *iter; private = xt_unregister_table(table); /* Decrease module usage counts and free resources */ loc_cpu_entry = private->entries[raw_smp_processor_id()]; xt_entry_foreach(iter, loc_cpu_entry, private->size) cleanup_entry(iter, net); if (private->number > private->initial_entries) module_put(table_owner); xt_free_table_info(private); } /* Returns 1 if the type and code is matched by the range, 0 otherwise */ static inline bool icmp_type_code_match(u_int8_t test_type, u_int8_t min_code, u_int8_t max_code, u_int8_t type, u_int8_t code, bool invert) { return ((test_type == 0xFF) || (type == test_type && code >= min_code && code <= max_code)) ^ invert; } static bool icmp_match(const struct sk_buff *skb, struct xt_action_param *par) { const struct icmphdr *ic; struct icmphdr _icmph; const struct ipt_icmp *icmpinfo = par->matchinfo; /* Must not be a fragment. */ if (par->fragoff != 0) return false; ic = skb_header_pointer(skb, par->thoff, sizeof(_icmph), &_icmph); if (ic == NULL) { /* We've been asked to examine this packet, and we * can't. Hence, no choice but to drop. */ duprintf("Dropping evil ICMP tinygram.\n"); par->hotdrop = true; return false; } return icmp_type_code_match(icmpinfo->type, icmpinfo->code[0], icmpinfo->code[1], ic->type, ic->code, !!(icmpinfo->invflags&IPT_ICMP_INV)); } static int icmp_checkentry(const struct xt_mtchk_param *par) { const struct ipt_icmp *icmpinfo = par->matchinfo; /* Must specify no unknown invflags */ return (icmpinfo->invflags & ~IPT_ICMP_INV) ? -EINVAL : 0; } static struct xt_target ipt_builtin_tg[] __read_mostly = { { .name = XT_STANDARD_TARGET, .targetsize = sizeof(int), .family = NFPROTO_IPV4, #ifdef CONFIG_COMPAT .compatsize = sizeof(compat_int_t), .compat_from_user = compat_standard_from_user, .compat_to_user = compat_standard_to_user, #endif }, { .name = XT_ERROR_TARGET, .target = ipt_error, .targetsize = XT_FUNCTION_MAXNAMELEN, .family = NFPROTO_IPV4, }, }; static struct nf_sockopt_ops ipt_sockopts = { .pf = PF_INET, .set_optmin = IPT_BASE_CTL, .set_optmax = IPT_SO_SET_MAX+1, .set = do_ipt_set_ctl, #ifdef CONFIG_COMPAT .compat_set = compat_do_ipt_set_ctl, #endif .get_optmin = IPT_BASE_CTL, .get_optmax = IPT_SO_GET_MAX+1, .get = do_ipt_get_ctl, #ifdef CONFIG_COMPAT .compat_get = compat_do_ipt_get_ctl, #endif .owner = THIS_MODULE, }; static struct xt_match ipt_builtin_mt[] __read_mostly = { { .name = "icmp", .match = icmp_match, .matchsize = sizeof(struct ipt_icmp), .checkentry = icmp_checkentry, .proto = IPPROTO_ICMP, .family = NFPROTO_IPV4, }, }; static int __net_init ip_tables_net_init(struct net *net) { return xt_proto_init(net, NFPROTO_IPV4); } static void __net_exit ip_tables_net_exit(struct net *net) { xt_proto_fini(net, NFPROTO_IPV4); } static struct pernet_operations ip_tables_net_ops = { .init = ip_tables_net_init, .exit = ip_tables_net_exit, }; static int __init ip_tables_init(void) { int ret; ret = register_pernet_subsys(&ip_tables_net_ops); if (ret < 0) goto err1; /* No one else will be downing sem now, so we won't sleep */ ret = xt_register_targets(ipt_builtin_tg, ARRAY_SIZE(ipt_builtin_tg)); if (ret < 0) goto err2; ret = xt_register_matches(ipt_builtin_mt, ARRAY_SIZE(ipt_builtin_mt)); if (ret < 0) goto err4; /* Register setsockopt */ ret = nf_register_sockopt(&ipt_sockopts); if (ret < 0) goto err5; pr_info("(C) 2000-2006 Netfilter Core Team\n"); return 0; err5: xt_unregister_matches(ipt_builtin_mt, ARRAY_SIZE(ipt_builtin_mt)); err4: xt_unregister_targets(ipt_builtin_tg, ARRAY_SIZE(ipt_builtin_tg)); err2: unregister_pernet_subsys(&ip_tables_net_ops); err1: return ret; } static void __exit ip_tables_fini(void) { nf_unregister_sockopt(&ipt_sockopts); xt_unregister_matches(ipt_builtin_mt, ARRAY_SIZE(ipt_builtin_mt)); xt_unregister_targets(ipt_builtin_tg, ARRAY_SIZE(ipt_builtin_tg)); unregister_pernet_subsys(&ip_tables_net_ops); } EXPORT_SYMBOL(ipt_register_table); EXPORT_SYMBOL(ipt_unregister_table); EXPORT_SYMBOL(ipt_do_table); module_init(ip_tables_init); module_exit(ip_tables_fini);
gpl-2.0
Sohamlad7/kernel
arch/mips/pnx833x/stb22x/board.c
4542
3849
/* * board.c: STB225 board support. * * Copyright 2008 NXP Semiconductors * Chris Steel <chris.steel@nxp.com> * Daniel Laird <daniel.j.laird@nxp.com> * * Based on software written by: * Nikita Youshchenko <yoush@debian.org>, based on PNX8550 code. * * 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/init.h> #include <asm/bootinfo.h> #include <linux/mm.h> #include <pnx833x.h> #include <gpio.h> /* endianess twiddlers */ #define PNX8335_DEBUG0 0x4400 #define PNX8335_DEBUG1 0x4404 #define PNX8335_DEBUG2 0x4408 #define PNX8335_DEBUG3 0x440c #define PNX8335_DEBUG4 0x4410 #define PNX8335_DEBUG5 0x4414 #define PNX8335_DEBUG6 0x4418 #define PNX8335_DEBUG7 0x441c int prom_argc; char **prom_argv, **prom_envp; extern void prom_init_cmdline(void); extern char *prom_getenv(char *envname); const char *get_system_type(void) { return "NXP STB22x"; } static inline unsigned long env_or_default(char *env, unsigned long dfl) { char *str = prom_getenv(env); return str ? simple_strtol(str, 0, 0) : dfl; } void __init prom_init(void) { unsigned long memsize; prom_argc = fw_arg0; prom_argv = (char **)fw_arg1; prom_envp = (char **)fw_arg2; prom_init_cmdline(); memsize = env_or_default("memsize", 0x02000000); add_memory_region(0, memsize, BOOT_MEM_RAM); } void __init pnx833x_board_setup(void) { pnx833x_gpio_select_function_alt(4); pnx833x_gpio_select_output(4); pnx833x_gpio_select_function_alt(5); pnx833x_gpio_select_input(5); pnx833x_gpio_select_function_alt(6); pnx833x_gpio_select_input(6); pnx833x_gpio_select_function_alt(7); pnx833x_gpio_select_output(7); pnx833x_gpio_select_function_alt(25); pnx833x_gpio_select_function_alt(26); pnx833x_gpio_select_function_alt(27); pnx833x_gpio_select_function_alt(28); pnx833x_gpio_select_function_alt(29); pnx833x_gpio_select_function_alt(30); pnx833x_gpio_select_function_alt(31); pnx833x_gpio_select_function_alt(32); pnx833x_gpio_select_function_alt(33); #if IS_ENABLED(CONFIG_MTD_NAND_PLATFORM) /* Setup MIU for NAND access on CS0... * * (it seems that we must also configure CS1 for reliable operation, * otherwise the first read ID command will fail if it's read as 4 bytes * but pass if it's read as 1 word.) */ /* Setup MIU CS0 & CS1 timing */ PNX833X_MIU_SEL0 = 0; PNX833X_MIU_SEL1 = 0; PNX833X_MIU_SEL0_TIMING = 0x50003081; PNX833X_MIU_SEL1_TIMING = 0x50003081; /* Setup GPIO 00 for use as MIU CS1 (CS0 is not multiplexed, so does not need this) */ pnx833x_gpio_select_function_alt(0); /* Setup GPIO 04 to input NAND read/busy signal */ pnx833x_gpio_select_function_io(4); pnx833x_gpio_select_input(4); /* Setup GPIO 05 to disable NAND write protect */ pnx833x_gpio_select_function_io(5); pnx833x_gpio_select_output(5); pnx833x_gpio_write(1, 5); #elif IS_ENABLED(CONFIG_MTD_CFI) /* Set up MIU for 16-bit NOR access on CS0 and CS1... */ /* Setup MIU CS0 & CS1 timing */ PNX833X_MIU_SEL0 = 1; PNX833X_MIU_SEL1 = 1; PNX833X_MIU_SEL0_TIMING = 0x6A08D082; PNX833X_MIU_SEL1_TIMING = 0x6A08D082; /* Setup GPIO 00 for use as MIU CS1 (CS0 is not multiplexed, so does not need this) */ pnx833x_gpio_select_function_alt(0); #endif }
gpl-2.0
DirtyUnicorns/android_kernel_htc_m7
net/tipc/link.c
4798
83312
/* * net/tipc/link.c: TIPC link code * * Copyright (c) 1996-2007, Ericsson AB * Copyright (c) 2004-2007, 2010-2011, Wind River Systems * 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. * 2. 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. * 3. Neither the names of the copyright holders nor the names of its * 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. * * 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. */ #include "core.h" #include "link.h" #include "port.h" #include "name_distr.h" #include "discover.h" #include "config.h" /* * Out-of-range value for link session numbers */ #define INVALID_SESSION 0x10000 /* * Link state events: */ #define STARTING_EVT 856384768 /* link processing trigger */ #define TRAFFIC_MSG_EVT 560815u /* rx'd ??? */ #define TIMEOUT_EVT 560817u /* link timer expired */ /* * The following two 'message types' is really just implementation * data conveniently stored in the message header. * They must not be considered part of the protocol */ #define OPEN_MSG 0 #define CLOSED_MSG 1 /* * State value stored in 'exp_msg_count' */ #define START_CHANGEOVER 100000u /** * struct tipc_link_name - deconstructed link name * @addr_local: network address of node at this end * @if_local: name of interface at this end * @addr_peer: network address of node at far end * @if_peer: name of interface at far end */ struct tipc_link_name { u32 addr_local; char if_local[TIPC_MAX_IF_NAME]; u32 addr_peer; char if_peer[TIPC_MAX_IF_NAME]; }; static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, struct sk_buff *buf); static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf); static int link_recv_changeover_msg(struct tipc_link **l_ptr, struct sk_buff **buf); static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance); static int link_send_sections_long(struct tipc_port *sender, struct iovec const *msg_sect, u32 num_sect, unsigned int total_len, u32 destnode); static void link_check_defragm_bufs(struct tipc_link *l_ptr); static void link_state_event(struct tipc_link *l_ptr, u32 event); static void link_reset_statistics(struct tipc_link *l_ptr); static void link_print(struct tipc_link *l_ptr, const char *str); static void link_start(struct tipc_link *l_ptr); static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf); /* * Simple link routines */ static unsigned int align(unsigned int i) { return (i + 3) & ~3u; } static void link_init_max_pkt(struct tipc_link *l_ptr) { u32 max_pkt; max_pkt = (l_ptr->b_ptr->mtu & ~3); if (max_pkt > MAX_MSG_SIZE) max_pkt = MAX_MSG_SIZE; l_ptr->max_pkt_target = max_pkt; if (l_ptr->max_pkt_target < MAX_PKT_DEFAULT) l_ptr->max_pkt = l_ptr->max_pkt_target; else l_ptr->max_pkt = MAX_PKT_DEFAULT; l_ptr->max_pkt_probes = 0; } static u32 link_next_sent(struct tipc_link *l_ptr) { if (l_ptr->next_out) return buf_seqno(l_ptr->next_out); return mod(l_ptr->next_out_no); } static u32 link_last_sent(struct tipc_link *l_ptr) { return mod(link_next_sent(l_ptr) - 1); } /* * Simple non-static link routines (i.e. referenced outside this file) */ int tipc_link_is_up(struct tipc_link *l_ptr) { if (!l_ptr) return 0; return link_working_working(l_ptr) || link_working_unknown(l_ptr); } int tipc_link_is_active(struct tipc_link *l_ptr) { return (l_ptr->owner->active_links[0] == l_ptr) || (l_ptr->owner->active_links[1] == l_ptr); } /** * link_name_validate - validate & (optionally) deconstruct tipc_link name * @name - ptr to link name string * @name_parts - ptr to area for link name components (or NULL if not needed) * * Returns 1 if link name is valid, otherwise 0. */ static int link_name_validate(const char *name, struct tipc_link_name *name_parts) { char name_copy[TIPC_MAX_LINK_NAME]; char *addr_local; char *if_local; char *addr_peer; char *if_peer; char dummy; u32 z_local, c_local, n_local; u32 z_peer, c_peer, n_peer; u32 if_local_len; u32 if_peer_len; /* copy link name & ensure length is OK */ name_copy[TIPC_MAX_LINK_NAME - 1] = 0; /* need above in case non-Posix strncpy() doesn't pad with nulls */ strncpy(name_copy, name, TIPC_MAX_LINK_NAME); if (name_copy[TIPC_MAX_LINK_NAME - 1] != 0) return 0; /* ensure all component parts of link name are present */ addr_local = name_copy; if_local = strchr(addr_local, ':'); if (if_local == NULL) return 0; *(if_local++) = 0; addr_peer = strchr(if_local, '-'); if (addr_peer == NULL) return 0; *(addr_peer++) = 0; if_local_len = addr_peer - if_local; if_peer = strchr(addr_peer, ':'); if (if_peer == NULL) return 0; *(if_peer++) = 0; if_peer_len = strlen(if_peer) + 1; /* validate component parts of link name */ if ((sscanf(addr_local, "%u.%u.%u%c", &z_local, &c_local, &n_local, &dummy) != 3) || (sscanf(addr_peer, "%u.%u.%u%c", &z_peer, &c_peer, &n_peer, &dummy) != 3) || (z_local > 255) || (c_local > 4095) || (n_local > 4095) || (z_peer > 255) || (c_peer > 4095) || (n_peer > 4095) || (if_local_len <= 1) || (if_local_len > TIPC_MAX_IF_NAME) || (if_peer_len <= 1) || (if_peer_len > TIPC_MAX_IF_NAME) || (strspn(if_local, tipc_alphabet) != (if_local_len - 1)) || (strspn(if_peer, tipc_alphabet) != (if_peer_len - 1))) return 0; /* return link name components, if necessary */ if (name_parts) { name_parts->addr_local = tipc_addr(z_local, c_local, n_local); strcpy(name_parts->if_local, if_local); name_parts->addr_peer = tipc_addr(z_peer, c_peer, n_peer); strcpy(name_parts->if_peer, if_peer); } return 1; } /** * link_timeout - handle expiration of link timer * @l_ptr: pointer to link * * This routine must not grab "tipc_net_lock" to avoid a potential deadlock conflict * with tipc_link_delete(). (There is no risk that the node will be deleted by * another thread because tipc_link_delete() always cancels the link timer before * tipc_node_delete() is called.) */ static void link_timeout(struct tipc_link *l_ptr) { tipc_node_lock(l_ptr->owner); /* update counters used in statistical profiling of send traffic */ l_ptr->stats.accu_queue_sz += l_ptr->out_queue_size; l_ptr->stats.queue_sz_counts++; if (l_ptr->first_out) { struct tipc_msg *msg = buf_msg(l_ptr->first_out); u32 length = msg_size(msg); if ((msg_user(msg) == MSG_FRAGMENTER) && (msg_type(msg) == FIRST_FRAGMENT)) { length = msg_size(msg_get_wrapped(msg)); } if (length) { l_ptr->stats.msg_lengths_total += length; l_ptr->stats.msg_length_counts++; if (length <= 64) l_ptr->stats.msg_length_profile[0]++; else if (length <= 256) l_ptr->stats.msg_length_profile[1]++; else if (length <= 1024) l_ptr->stats.msg_length_profile[2]++; else if (length <= 4096) l_ptr->stats.msg_length_profile[3]++; else if (length <= 16384) l_ptr->stats.msg_length_profile[4]++; else if (length <= 32768) l_ptr->stats.msg_length_profile[5]++; else l_ptr->stats.msg_length_profile[6]++; } } /* do all other link processing performed on a periodic basis */ link_check_defragm_bufs(l_ptr); link_state_event(l_ptr, TIMEOUT_EVT); if (l_ptr->next_out) tipc_link_push_queue(l_ptr); tipc_node_unlock(l_ptr->owner); } static void link_set_timer(struct tipc_link *l_ptr, u32 time) { k_start_timer(&l_ptr->timer, time); } /** * tipc_link_create - create a new link * @n_ptr: pointer to associated node * @b_ptr: pointer to associated bearer * @media_addr: media address to use when sending messages over link * * Returns pointer to link. */ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, struct tipc_bearer *b_ptr, const struct tipc_media_addr *media_addr) { struct tipc_link *l_ptr; struct tipc_msg *msg; char *if_name; char addr_string[16]; u32 peer = n_ptr->addr; if (n_ptr->link_cnt >= 2) { tipc_addr_string_fill(addr_string, n_ptr->addr); err("Attempt to establish third link to %s\n", addr_string); return NULL; } if (n_ptr->links[b_ptr->identity]) { tipc_addr_string_fill(addr_string, n_ptr->addr); err("Attempt to establish second link on <%s> to %s\n", b_ptr->name, addr_string); return NULL; } l_ptr = kzalloc(sizeof(*l_ptr), GFP_ATOMIC); if (!l_ptr) { warn("Link creation failed, no memory\n"); return NULL; } l_ptr->addr = peer; if_name = strchr(b_ptr->name, ':') + 1; sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown", tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr), tipc_node(tipc_own_addr), if_name, tipc_zone(peer), tipc_cluster(peer), tipc_node(peer)); /* note: peer i/f name is updated by reset/activate message */ memcpy(&l_ptr->media_addr, media_addr, sizeof(*media_addr)); l_ptr->owner = n_ptr; l_ptr->checkpoint = 1; l_ptr->peer_session = INVALID_SESSION; l_ptr->b_ptr = b_ptr; link_set_supervision_props(l_ptr, b_ptr->tolerance); l_ptr->state = RESET_UNKNOWN; l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg; msg = l_ptr->pmsg; tipc_msg_init(msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, l_ptr->addr); msg_set_size(msg, sizeof(l_ptr->proto_msg)); msg_set_session(msg, (tipc_random & 0xffff)); msg_set_bearer_id(msg, b_ptr->identity); strcpy((char *)msg_data(msg), if_name); l_ptr->priority = b_ptr->priority; tipc_link_set_queue_limits(l_ptr, b_ptr->window); link_init_max_pkt(l_ptr); l_ptr->next_out_no = 1; INIT_LIST_HEAD(&l_ptr->waiting_ports); link_reset_statistics(l_ptr); tipc_node_attach_link(n_ptr, l_ptr); k_init_timer(&l_ptr->timer, (Handler)link_timeout, (unsigned long)l_ptr); list_add_tail(&l_ptr->link_list, &b_ptr->links); tipc_k_signal((Handler)link_start, (unsigned long)l_ptr); return l_ptr; } /** * tipc_link_delete - delete a link * @l_ptr: pointer to link * * Note: 'tipc_net_lock' is write_locked, bearer is locked. * This routine must not grab the node lock until after link timer cancellation * to avoid a potential deadlock situation. */ void tipc_link_delete(struct tipc_link *l_ptr) { if (!l_ptr) { err("Attempt to delete non-existent link\n"); return; } k_cancel_timer(&l_ptr->timer); tipc_node_lock(l_ptr->owner); tipc_link_reset(l_ptr); tipc_node_detach_link(l_ptr->owner, l_ptr); tipc_link_stop(l_ptr); list_del_init(&l_ptr->link_list); tipc_node_unlock(l_ptr->owner); k_term_timer(&l_ptr->timer); kfree(l_ptr); } static void link_start(struct tipc_link *l_ptr) { tipc_node_lock(l_ptr->owner); link_state_event(l_ptr, STARTING_EVT); tipc_node_unlock(l_ptr->owner); } /** * link_schedule_port - schedule port for deferred sending * @l_ptr: pointer to link * @origport: reference to sending port * @sz: amount of data to be sent * * Schedules port for renewed sending of messages after link congestion * has abated. */ static int link_schedule_port(struct tipc_link *l_ptr, u32 origport, u32 sz) { struct tipc_port *p_ptr; spin_lock_bh(&tipc_port_list_lock); p_ptr = tipc_port_lock(origport); if (p_ptr) { if (!p_ptr->wakeup) goto exit; if (!list_empty(&p_ptr->wait_list)) goto exit; p_ptr->congested = 1; p_ptr->waiting_pkts = 1 + ((sz - 1) / l_ptr->max_pkt); list_add_tail(&p_ptr->wait_list, &l_ptr->waiting_ports); l_ptr->stats.link_congs++; exit: tipc_port_unlock(p_ptr); } spin_unlock_bh(&tipc_port_list_lock); return -ELINKCONG; } void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all) { struct tipc_port *p_ptr; struct tipc_port *temp_p_ptr; int win = l_ptr->queue_limit[0] - l_ptr->out_queue_size; if (all) win = 100000; if (win <= 0) return; if (!spin_trylock_bh(&tipc_port_list_lock)) return; if (link_congested(l_ptr)) goto exit; list_for_each_entry_safe(p_ptr, temp_p_ptr, &l_ptr->waiting_ports, wait_list) { if (win <= 0) break; list_del_init(&p_ptr->wait_list); spin_lock_bh(p_ptr->lock); p_ptr->congested = 0; p_ptr->wakeup(p_ptr); win -= p_ptr->waiting_pkts; spin_unlock_bh(p_ptr->lock); } exit: spin_unlock_bh(&tipc_port_list_lock); } /** * link_release_outqueue - purge link's outbound message queue * @l_ptr: pointer to link */ static void link_release_outqueue(struct tipc_link *l_ptr) { struct sk_buff *buf = l_ptr->first_out; struct sk_buff *next; while (buf) { next = buf->next; kfree_skb(buf); buf = next; } l_ptr->first_out = NULL; l_ptr->out_queue_size = 0; } /** * tipc_link_reset_fragments - purge link's inbound message fragments queue * @l_ptr: pointer to link */ void tipc_link_reset_fragments(struct tipc_link *l_ptr) { struct sk_buff *buf = l_ptr->defragm_buf; struct sk_buff *next; while (buf) { next = buf->next; kfree_skb(buf); buf = next; } l_ptr->defragm_buf = NULL; } /** * tipc_link_stop - purge all inbound and outbound messages associated with link * @l_ptr: pointer to link */ void tipc_link_stop(struct tipc_link *l_ptr) { struct sk_buff *buf; struct sk_buff *next; buf = l_ptr->oldest_deferred_in; while (buf) { next = buf->next; kfree_skb(buf); buf = next; } buf = l_ptr->first_out; while (buf) { next = buf->next; kfree_skb(buf); buf = next; } tipc_link_reset_fragments(l_ptr); kfree_skb(l_ptr->proto_msg_queue); l_ptr->proto_msg_queue = NULL; } void tipc_link_reset(struct tipc_link *l_ptr) { struct sk_buff *buf; u32 prev_state = l_ptr->state; u32 checkpoint = l_ptr->next_in_no; int was_active_link = tipc_link_is_active(l_ptr); msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff)); /* Link is down, accept any session */ l_ptr->peer_session = INVALID_SESSION; /* Prepare for max packet size negotiation */ link_init_max_pkt(l_ptr); l_ptr->state = RESET_UNKNOWN; if ((prev_state == RESET_UNKNOWN) || (prev_state == RESET_RESET)) return; tipc_node_link_down(l_ptr->owner, l_ptr); tipc_bearer_remove_dest(l_ptr->b_ptr, l_ptr->addr); if (was_active_link && tipc_node_active_links(l_ptr->owner) && l_ptr->owner->permit_changeover) { l_ptr->reset_checkpoint = checkpoint; l_ptr->exp_msg_count = START_CHANGEOVER; } /* Clean up all queues: */ link_release_outqueue(l_ptr); kfree_skb(l_ptr->proto_msg_queue); l_ptr->proto_msg_queue = NULL; buf = l_ptr->oldest_deferred_in; while (buf) { struct sk_buff *next = buf->next; kfree_skb(buf); buf = next; } if (!list_empty(&l_ptr->waiting_ports)) tipc_link_wakeup_ports(l_ptr, 1); l_ptr->retransm_queue_head = 0; l_ptr->retransm_queue_size = 0; l_ptr->last_out = NULL; l_ptr->first_out = NULL; l_ptr->next_out = NULL; l_ptr->unacked_window = 0; l_ptr->checkpoint = 1; l_ptr->next_out_no = 1; l_ptr->deferred_inqueue_sz = 0; l_ptr->oldest_deferred_in = NULL; l_ptr->newest_deferred_in = NULL; l_ptr->fsm_msg_cnt = 0; l_ptr->stale_count = 0; link_reset_statistics(l_ptr); } static void link_activate(struct tipc_link *l_ptr) { l_ptr->next_in_no = l_ptr->stats.recv_info = 1; tipc_node_link_up(l_ptr->owner, l_ptr); tipc_bearer_add_dest(l_ptr->b_ptr, l_ptr->addr); } /** * link_state_event - link finite state machine * @l_ptr: pointer to link * @event: state machine event to process */ static void link_state_event(struct tipc_link *l_ptr, unsigned event) { struct tipc_link *other; u32 cont_intv = l_ptr->continuity_interval; if (!l_ptr->started && (event != STARTING_EVT)) return; /* Not yet. */ if (link_blocked(l_ptr)) { if (event == TIMEOUT_EVT) link_set_timer(l_ptr, cont_intv); return; /* Changeover going on */ } switch (l_ptr->state) { case WORKING_WORKING: switch (event) { case TRAFFIC_MSG_EVT: case ACTIVATE_MSG: break; case TIMEOUT_EVT: if (l_ptr->next_in_no != l_ptr->checkpoint) { l_ptr->checkpoint = l_ptr->next_in_no; if (tipc_bclink_acks_missing(l_ptr->owner)) { tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; } else if (l_ptr->max_pkt < l_ptr->max_pkt_target) { tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; } link_set_timer(l_ptr, cont_intv); break; } l_ptr->state = WORKING_UNKNOWN; l_ptr->fsm_msg_cnt = 0; tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; link_set_timer(l_ptr, cont_intv / 4); break; case RESET_MSG: info("Resetting link <%s>, requested by peer\n", l_ptr->name); tipc_link_reset(l_ptr); l_ptr->state = RESET_RESET; l_ptr->fsm_msg_cnt = 0; tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; link_set_timer(l_ptr, cont_intv); break; default: err("Unknown link event %u in WW state\n", event); } break; case WORKING_UNKNOWN: switch (event) { case TRAFFIC_MSG_EVT: case ACTIVATE_MSG: l_ptr->state = WORKING_WORKING; l_ptr->fsm_msg_cnt = 0; link_set_timer(l_ptr, cont_intv); break; case RESET_MSG: info("Resetting link <%s>, requested by peer " "while probing\n", l_ptr->name); tipc_link_reset(l_ptr); l_ptr->state = RESET_RESET; l_ptr->fsm_msg_cnt = 0; tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; link_set_timer(l_ptr, cont_intv); break; case TIMEOUT_EVT: if (l_ptr->next_in_no != l_ptr->checkpoint) { l_ptr->state = WORKING_WORKING; l_ptr->fsm_msg_cnt = 0; l_ptr->checkpoint = l_ptr->next_in_no; if (tipc_bclink_acks_missing(l_ptr->owner)) { tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; } link_set_timer(l_ptr, cont_intv); } else if (l_ptr->fsm_msg_cnt < l_ptr->abort_limit) { tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; link_set_timer(l_ptr, cont_intv / 4); } else { /* Link has failed */ warn("Resetting link <%s>, peer not responding\n", l_ptr->name); tipc_link_reset(l_ptr); l_ptr->state = RESET_UNKNOWN; l_ptr->fsm_msg_cnt = 0; tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; link_set_timer(l_ptr, cont_intv); } break; default: err("Unknown link event %u in WU state\n", event); } break; case RESET_UNKNOWN: switch (event) { case TRAFFIC_MSG_EVT: break; case ACTIVATE_MSG: other = l_ptr->owner->active_links[0]; if (other && link_working_unknown(other)) break; l_ptr->state = WORKING_WORKING; l_ptr->fsm_msg_cnt = 0; link_activate(l_ptr); tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; link_set_timer(l_ptr, cont_intv); break; case RESET_MSG: l_ptr->state = RESET_RESET; l_ptr->fsm_msg_cnt = 0; tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 1, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; link_set_timer(l_ptr, cont_intv); break; case STARTING_EVT: l_ptr->started = 1; /* fall through */ case TIMEOUT_EVT: tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; link_set_timer(l_ptr, cont_intv); break; default: err("Unknown link event %u in RU state\n", event); } break; case RESET_RESET: switch (event) { case TRAFFIC_MSG_EVT: case ACTIVATE_MSG: other = l_ptr->owner->active_links[0]; if (other && link_working_unknown(other)) break; l_ptr->state = WORKING_WORKING; l_ptr->fsm_msg_cnt = 0; link_activate(l_ptr); tipc_link_send_proto_msg(l_ptr, STATE_MSG, 1, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; link_set_timer(l_ptr, cont_intv); break; case RESET_MSG: break; case TIMEOUT_EVT: tipc_link_send_proto_msg(l_ptr, ACTIVATE_MSG, 0, 0, 0, 0, 0); l_ptr->fsm_msg_cnt++; link_set_timer(l_ptr, cont_intv); break; default: err("Unknown link event %u in RR state\n", event); } break; default: err("Unknown link state %u/%u\n", l_ptr->state, event); } } /* * link_bundle_buf(): Append contents of a buffer to * the tail of an existing one. */ static int link_bundle_buf(struct tipc_link *l_ptr, struct sk_buff *bundler, struct sk_buff *buf) { struct tipc_msg *bundler_msg = buf_msg(bundler); struct tipc_msg *msg = buf_msg(buf); u32 size = msg_size(msg); u32 bundle_size = msg_size(bundler_msg); u32 to_pos = align(bundle_size); u32 pad = to_pos - bundle_size; if (msg_user(bundler_msg) != MSG_BUNDLER) return 0; if (msg_type(bundler_msg) != OPEN_MSG) return 0; if (skb_tailroom(bundler) < (pad + size)) return 0; if (l_ptr->max_pkt < (to_pos + size)) return 0; skb_put(bundler, pad + size); skb_copy_to_linear_data_offset(bundler, to_pos, buf->data, size); msg_set_size(bundler_msg, to_pos + size); msg_set_msgcnt(bundler_msg, msg_msgcnt(bundler_msg) + 1); kfree_skb(buf); l_ptr->stats.sent_bundled++; return 1; } static void link_add_to_outqueue(struct tipc_link *l_ptr, struct sk_buff *buf, struct tipc_msg *msg) { u32 ack = mod(l_ptr->next_in_no - 1); u32 seqno = mod(l_ptr->next_out_no++); msg_set_word(msg, 2, ((ack << 16) | seqno)); msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); buf->next = NULL; if (l_ptr->first_out) { l_ptr->last_out->next = buf; l_ptr->last_out = buf; } else l_ptr->first_out = l_ptr->last_out = buf; l_ptr->out_queue_size++; if (l_ptr->out_queue_size > l_ptr->stats.max_queue_sz) l_ptr->stats.max_queue_sz = l_ptr->out_queue_size; } static void link_add_chain_to_outqueue(struct tipc_link *l_ptr, struct sk_buff *buf_chain, u32 long_msgno) { struct sk_buff *buf; struct tipc_msg *msg; if (!l_ptr->next_out) l_ptr->next_out = buf_chain; while (buf_chain) { buf = buf_chain; buf_chain = buf_chain->next; msg = buf_msg(buf); msg_set_long_msgno(msg, long_msgno); link_add_to_outqueue(l_ptr, buf, msg); } } /* * tipc_link_send_buf() is the 'full path' for messages, called from * inside TIPC when the 'fast path' in tipc_send_buf * has failed, and from link_send() */ int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf) { struct tipc_msg *msg = buf_msg(buf); u32 size = msg_size(msg); u32 dsz = msg_data_sz(msg); u32 queue_size = l_ptr->out_queue_size; u32 imp = tipc_msg_tot_importance(msg); u32 queue_limit = l_ptr->queue_limit[imp]; u32 max_packet = l_ptr->max_pkt; /* Match msg importance against queue limits: */ if (unlikely(queue_size >= queue_limit)) { if (imp <= TIPC_CRITICAL_IMPORTANCE) { link_schedule_port(l_ptr, msg_origport(msg), size); kfree_skb(buf); return -ELINKCONG; } kfree_skb(buf); if (imp > CONN_MANAGER) { warn("Resetting link <%s>, send queue full", l_ptr->name); tipc_link_reset(l_ptr); } return dsz; } /* Fragmentation needed ? */ if (size > max_packet) return link_send_long_buf(l_ptr, buf); /* Packet can be queued or sent: */ if (likely(!tipc_bearer_congested(l_ptr->b_ptr, l_ptr) && !link_congested(l_ptr))) { link_add_to_outqueue(l_ptr, buf, msg); if (likely(tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr))) { l_ptr->unacked_window = 0; } else { tipc_bearer_schedule(l_ptr->b_ptr, l_ptr); l_ptr->stats.bearer_congs++; l_ptr->next_out = buf; } return dsz; } /* Congestion: can message be bundled ?: */ if ((msg_user(msg) != CHANGEOVER_PROTOCOL) && (msg_user(msg) != MSG_FRAGMENTER)) { /* Try adding message to an existing bundle */ if (l_ptr->next_out && link_bundle_buf(l_ptr, l_ptr->last_out, buf)) { tipc_bearer_resolve_congestion(l_ptr->b_ptr, l_ptr); return dsz; } /* Try creating a new bundle */ if (size <= max_packet * 2 / 3) { struct sk_buff *bundler = tipc_buf_acquire(max_packet); struct tipc_msg bundler_hdr; if (bundler) { tipc_msg_init(&bundler_hdr, MSG_BUNDLER, OPEN_MSG, INT_H_SIZE, l_ptr->addr); skb_copy_to_linear_data(bundler, &bundler_hdr, INT_H_SIZE); skb_trim(bundler, INT_H_SIZE); link_bundle_buf(l_ptr, bundler, buf); buf = bundler; msg = buf_msg(buf); l_ptr->stats.sent_bundles++; } } } if (!l_ptr->next_out) l_ptr->next_out = buf; link_add_to_outqueue(l_ptr, buf, msg); tipc_bearer_resolve_congestion(l_ptr->b_ptr, l_ptr); return dsz; } /* * tipc_link_send(): same as tipc_link_send_buf(), but the link to use has * not been selected yet, and the the owner node is not locked * Called by TIPC internal users, e.g. the name distributor */ int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector) { struct tipc_link *l_ptr; struct tipc_node *n_ptr; int res = -ELINKCONG; read_lock_bh(&tipc_net_lock); n_ptr = tipc_node_find(dest); if (n_ptr) { tipc_node_lock(n_ptr); l_ptr = n_ptr->active_links[selector & 1]; if (l_ptr) res = tipc_link_send_buf(l_ptr, buf); else kfree_skb(buf); tipc_node_unlock(n_ptr); } else { kfree_skb(buf); } read_unlock_bh(&tipc_net_lock); return res; } /* * tipc_link_send_names - send name table entries to new neighbor * * Send routine for bulk delivery of name table messages when contact * with a new neighbor occurs. No link congestion checking is performed * because name table messages *must* be delivered. The messages must be * small enough not to require fragmentation. * Called without any locks held. */ void tipc_link_send_names(struct list_head *message_list, u32 dest) { struct tipc_node *n_ptr; struct tipc_link *l_ptr; struct sk_buff *buf; struct sk_buff *temp_buf; if (list_empty(message_list)) return; read_lock_bh(&tipc_net_lock); n_ptr = tipc_node_find(dest); if (n_ptr) { tipc_node_lock(n_ptr); l_ptr = n_ptr->active_links[0]; if (l_ptr) { /* convert circular list to linear list */ ((struct sk_buff *)message_list->prev)->next = NULL; link_add_chain_to_outqueue(l_ptr, (struct sk_buff *)message_list->next, 0); tipc_link_push_queue(l_ptr); INIT_LIST_HEAD(message_list); } tipc_node_unlock(n_ptr); } read_unlock_bh(&tipc_net_lock); /* discard the messages if they couldn't be sent */ list_for_each_safe(buf, temp_buf, ((struct sk_buff *)message_list)) { list_del((struct list_head *)buf); kfree_skb(buf); } } /* * link_send_buf_fast: Entry for data messages where the * destination link is known and the header is complete, * inclusive total message length. Very time critical. * Link is locked. Returns user data length. */ static int link_send_buf_fast(struct tipc_link *l_ptr, struct sk_buff *buf, u32 *used_max_pkt) { struct tipc_msg *msg = buf_msg(buf); int res = msg_data_sz(msg); if (likely(!link_congested(l_ptr))) { if (likely(msg_size(msg) <= l_ptr->max_pkt)) { if (likely(list_empty(&l_ptr->b_ptr->cong_links))) { link_add_to_outqueue(l_ptr, buf, msg); if (likely(tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr))) { l_ptr->unacked_window = 0; return res; } tipc_bearer_schedule(l_ptr->b_ptr, l_ptr); l_ptr->stats.bearer_congs++; l_ptr->next_out = buf; return res; } } else *used_max_pkt = l_ptr->max_pkt; } return tipc_link_send_buf(l_ptr, buf); /* All other cases */ } /* * tipc_send_buf_fast: Entry for data messages where the * destination node is known and the header is complete, * inclusive total message length. * Returns user data length. */ int tipc_send_buf_fast(struct sk_buff *buf, u32 destnode) { struct tipc_link *l_ptr; struct tipc_node *n_ptr; int res; u32 selector = msg_origport(buf_msg(buf)) & 1; u32 dummy; read_lock_bh(&tipc_net_lock); n_ptr = tipc_node_find(destnode); if (likely(n_ptr)) { tipc_node_lock(n_ptr); l_ptr = n_ptr->active_links[selector]; if (likely(l_ptr)) { res = link_send_buf_fast(l_ptr, buf, &dummy); tipc_node_unlock(n_ptr); read_unlock_bh(&tipc_net_lock); return res; } tipc_node_unlock(n_ptr); } read_unlock_bh(&tipc_net_lock); res = msg_data_sz(buf_msg(buf)); tipc_reject_msg(buf, TIPC_ERR_NO_NODE); return res; } /* * tipc_link_send_sections_fast: Entry for messages where the * destination processor is known and the header is complete, * except for total message length. * Returns user data length or errno. */ int tipc_link_send_sections_fast(struct tipc_port *sender, struct iovec const *msg_sect, const u32 num_sect, unsigned int total_len, u32 destaddr) { struct tipc_msg *hdr = &sender->phdr; struct tipc_link *l_ptr; struct sk_buff *buf; struct tipc_node *node; int res; u32 selector = msg_origport(hdr) & 1; again: /* * Try building message using port's max_pkt hint. * (Must not hold any locks while building message.) */ res = tipc_msg_build(hdr, msg_sect, num_sect, total_len, sender->max_pkt, !sender->user_port, &buf); read_lock_bh(&tipc_net_lock); node = tipc_node_find(destaddr); if (likely(node)) { tipc_node_lock(node); l_ptr = node->active_links[selector]; if (likely(l_ptr)) { if (likely(buf)) { res = link_send_buf_fast(l_ptr, buf, &sender->max_pkt); exit: tipc_node_unlock(node); read_unlock_bh(&tipc_net_lock); return res; } /* Exit if build request was invalid */ if (unlikely(res < 0)) goto exit; /* Exit if link (or bearer) is congested */ if (link_congested(l_ptr) || !list_empty(&l_ptr->b_ptr->cong_links)) { res = link_schedule_port(l_ptr, sender->ref, res); goto exit; } /* * Message size exceeds max_pkt hint; update hint, * then re-try fast path or fragment the message */ sender->max_pkt = l_ptr->max_pkt; tipc_node_unlock(node); read_unlock_bh(&tipc_net_lock); if ((msg_hdr_sz(hdr) + res) <= sender->max_pkt) goto again; return link_send_sections_long(sender, msg_sect, num_sect, total_len, destaddr); } tipc_node_unlock(node); } read_unlock_bh(&tipc_net_lock); /* Couldn't find a link to the destination node */ if (buf) return tipc_reject_msg(buf, TIPC_ERR_NO_NODE); if (res >= 0) return tipc_port_reject_sections(sender, hdr, msg_sect, num_sect, total_len, TIPC_ERR_NO_NODE); return res; } /* * link_send_sections_long(): Entry for long messages where the * destination node is known and the header is complete, * inclusive total message length. * Link and bearer congestion status have been checked to be ok, * and are ignored if they change. * * Note that fragments do not use the full link MTU so that they won't have * to undergo refragmentation if link changeover causes them to be sent * over another link with an additional tunnel header added as prefix. * (Refragmentation will still occur if the other link has a smaller MTU.) * * Returns user data length or errno. */ static int link_send_sections_long(struct tipc_port *sender, struct iovec const *msg_sect, u32 num_sect, unsigned int total_len, u32 destaddr) { struct tipc_link *l_ptr; struct tipc_node *node; struct tipc_msg *hdr = &sender->phdr; u32 dsz = total_len; u32 max_pkt, fragm_sz, rest; struct tipc_msg fragm_hdr; struct sk_buff *buf, *buf_chain, *prev; u32 fragm_crs, fragm_rest, hsz, sect_rest; const unchar *sect_crs; int curr_sect; u32 fragm_no; again: fragm_no = 1; max_pkt = sender->max_pkt - INT_H_SIZE; /* leave room for tunnel header in case of link changeover */ fragm_sz = max_pkt - INT_H_SIZE; /* leave room for fragmentation header in each fragment */ rest = dsz; fragm_crs = 0; fragm_rest = 0; sect_rest = 0; sect_crs = NULL; curr_sect = -1; /* Prepare reusable fragment header: */ tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT, INT_H_SIZE, msg_destnode(hdr)); msg_set_size(&fragm_hdr, max_pkt); msg_set_fragm_no(&fragm_hdr, 1); /* Prepare header of first fragment: */ buf_chain = buf = tipc_buf_acquire(max_pkt); if (!buf) return -ENOMEM; buf->next = NULL; skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE); hsz = msg_hdr_sz(hdr); skb_copy_to_linear_data_offset(buf, INT_H_SIZE, hdr, hsz); /* Chop up message: */ fragm_crs = INT_H_SIZE + hsz; fragm_rest = fragm_sz - hsz; do { /* For all sections */ u32 sz; if (!sect_rest) { sect_rest = msg_sect[++curr_sect].iov_len; sect_crs = (const unchar *)msg_sect[curr_sect].iov_base; } if (sect_rest < fragm_rest) sz = sect_rest; else sz = fragm_rest; if (likely(!sender->user_port)) { if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) { error: for (; buf_chain; buf_chain = buf) { buf = buf_chain->next; kfree_skb(buf_chain); } return -EFAULT; } } else skb_copy_to_linear_data_offset(buf, fragm_crs, sect_crs, sz); sect_crs += sz; sect_rest -= sz; fragm_crs += sz; fragm_rest -= sz; rest -= sz; if (!fragm_rest && rest) { /* Initiate new fragment: */ if (rest <= fragm_sz) { fragm_sz = rest; msg_set_type(&fragm_hdr, LAST_FRAGMENT); } else { msg_set_type(&fragm_hdr, FRAGMENT); } msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE); msg_set_fragm_no(&fragm_hdr, ++fragm_no); prev = buf; buf = tipc_buf_acquire(fragm_sz + INT_H_SIZE); if (!buf) goto error; buf->next = NULL; prev->next = buf; skb_copy_to_linear_data(buf, &fragm_hdr, INT_H_SIZE); fragm_crs = INT_H_SIZE; fragm_rest = fragm_sz; } } while (rest > 0); /* * Now we have a buffer chain. Select a link and check * that packet size is still OK */ node = tipc_node_find(destaddr); if (likely(node)) { tipc_node_lock(node); l_ptr = node->active_links[sender->ref & 1]; if (!l_ptr) { tipc_node_unlock(node); goto reject; } if (l_ptr->max_pkt < max_pkt) { sender->max_pkt = l_ptr->max_pkt; tipc_node_unlock(node); for (; buf_chain; buf_chain = buf) { buf = buf_chain->next; kfree_skb(buf_chain); } goto again; } } else { reject: for (; buf_chain; buf_chain = buf) { buf = buf_chain->next; kfree_skb(buf_chain); } return tipc_port_reject_sections(sender, hdr, msg_sect, num_sect, total_len, TIPC_ERR_NO_NODE); } /* Append chain of fragments to send queue & send them */ l_ptr->long_msg_seq_no++; link_add_chain_to_outqueue(l_ptr, buf_chain, l_ptr->long_msg_seq_no); l_ptr->stats.sent_fragments += fragm_no; l_ptr->stats.sent_fragmented++; tipc_link_push_queue(l_ptr); tipc_node_unlock(node); return dsz; } /* * tipc_link_push_packet: Push one unsent packet to the media */ u32 tipc_link_push_packet(struct tipc_link *l_ptr) { struct sk_buff *buf = l_ptr->first_out; u32 r_q_size = l_ptr->retransm_queue_size; u32 r_q_head = l_ptr->retransm_queue_head; /* Step to position where retransmission failed, if any, */ /* consider that buffers may have been released in meantime */ if (r_q_size && buf) { u32 last = lesser(mod(r_q_head + r_q_size), link_last_sent(l_ptr)); u32 first = buf_seqno(buf); while (buf && less(first, r_q_head)) { first = mod(first + 1); buf = buf->next; } l_ptr->retransm_queue_head = r_q_head = first; l_ptr->retransm_queue_size = r_q_size = mod(last - first); } /* Continue retransmission now, if there is anything: */ if (r_q_size && buf) { msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1)); msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in); if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) { l_ptr->retransm_queue_head = mod(++r_q_head); l_ptr->retransm_queue_size = --r_q_size; l_ptr->stats.retransmitted++; return 0; } else { l_ptr->stats.bearer_congs++; return PUSH_FAILED; } } /* Send deferred protocol message, if any: */ buf = l_ptr->proto_msg_queue; if (buf) { msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1)); msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in); if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) { l_ptr->unacked_window = 0; kfree_skb(buf); l_ptr->proto_msg_queue = NULL; return 0; } else { l_ptr->stats.bearer_congs++; return PUSH_FAILED; } } /* Send one deferred data message, if send window not full: */ buf = l_ptr->next_out; if (buf) { struct tipc_msg *msg = buf_msg(buf); u32 next = msg_seqno(msg); u32 first = buf_seqno(l_ptr->first_out); if (mod(next - first) < l_ptr->queue_limit[0]) { msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) { if (msg_user(msg) == MSG_BUNDLER) msg_set_type(msg, CLOSED_MSG); l_ptr->next_out = buf->next; return 0; } else { l_ptr->stats.bearer_congs++; return PUSH_FAILED; } } } return PUSH_FINISHED; } /* * push_queue(): push out the unsent messages of a link where * congestion has abated. Node is locked */ void tipc_link_push_queue(struct tipc_link *l_ptr) { u32 res; if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) return; do { res = tipc_link_push_packet(l_ptr); } while (!res); if (res == PUSH_FAILED) tipc_bearer_schedule(l_ptr->b_ptr, l_ptr); } static void link_reset_all(unsigned long addr) { struct tipc_node *n_ptr; char addr_string[16]; u32 i; read_lock_bh(&tipc_net_lock); n_ptr = tipc_node_find((u32)addr); if (!n_ptr) { read_unlock_bh(&tipc_net_lock); return; /* node no longer exists */ } tipc_node_lock(n_ptr); warn("Resetting all links to %s\n", tipc_addr_string_fill(addr_string, n_ptr->addr)); for (i = 0; i < MAX_BEARERS; i++) { if (n_ptr->links[i]) { link_print(n_ptr->links[i], "Resetting link\n"); tipc_link_reset(n_ptr->links[i]); } } tipc_node_unlock(n_ptr); read_unlock_bh(&tipc_net_lock); } static void link_retransmit_failure(struct tipc_link *l_ptr, struct sk_buff *buf) { struct tipc_msg *msg = buf_msg(buf); warn("Retransmission failure on link <%s>\n", l_ptr->name); if (l_ptr->addr) { /* Handle failure on standard link */ link_print(l_ptr, "Resetting link\n"); tipc_link_reset(l_ptr); } else { /* Handle failure on broadcast link */ struct tipc_node *n_ptr; char addr_string[16]; info("Msg seq number: %u, ", msg_seqno(msg)); info("Outstanding acks: %lu\n", (unsigned long) TIPC_SKB_CB(buf)->handle); n_ptr = tipc_bclink_retransmit_to(); tipc_node_lock(n_ptr); tipc_addr_string_fill(addr_string, n_ptr->addr); info("Broadcast link info for %s\n", addr_string); info("Supportable: %d, ", n_ptr->bclink.supportable); info("Supported: %d, ", n_ptr->bclink.supported); info("Acked: %u\n", n_ptr->bclink.acked); info("Last in: %u, ", n_ptr->bclink.last_in); info("Oos state: %u, ", n_ptr->bclink.oos_state); info("Last sent: %u\n", n_ptr->bclink.last_sent); tipc_k_signal((Handler)link_reset_all, (unsigned long)n_ptr->addr); tipc_node_unlock(n_ptr); l_ptr->stale_count = 0; } } void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *buf, u32 retransmits) { struct tipc_msg *msg; if (!buf) return; msg = buf_msg(buf); if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) { if (l_ptr->retransm_queue_size == 0) { l_ptr->retransm_queue_head = msg_seqno(msg); l_ptr->retransm_queue_size = retransmits; } else { err("Unexpected retransmit on link %s (qsize=%d)\n", l_ptr->name, l_ptr->retransm_queue_size); } return; } else { /* Detect repeated retransmit failures on uncongested bearer */ if (l_ptr->last_retransmitted == msg_seqno(msg)) { if (++l_ptr->stale_count > 100) { link_retransmit_failure(l_ptr, buf); return; } } else { l_ptr->last_retransmitted = msg_seqno(msg); l_ptr->stale_count = 1; } } while (retransmits && (buf != l_ptr->next_out) && buf) { msg = buf_msg(buf); msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) { buf = buf->next; retransmits--; l_ptr->stats.retransmitted++; } else { tipc_bearer_schedule(l_ptr->b_ptr, l_ptr); l_ptr->stats.bearer_congs++; l_ptr->retransm_queue_head = buf_seqno(buf); l_ptr->retransm_queue_size = retransmits; return; } } l_ptr->retransm_queue_head = l_ptr->retransm_queue_size = 0; } /** * link_insert_deferred_queue - insert deferred messages back into receive chain */ static struct sk_buff *link_insert_deferred_queue(struct tipc_link *l_ptr, struct sk_buff *buf) { u32 seq_no; if (l_ptr->oldest_deferred_in == NULL) return buf; seq_no = buf_seqno(l_ptr->oldest_deferred_in); if (seq_no == mod(l_ptr->next_in_no)) { l_ptr->newest_deferred_in->next = buf; buf = l_ptr->oldest_deferred_in; l_ptr->oldest_deferred_in = NULL; l_ptr->deferred_inqueue_sz = 0; } return buf; } /** * link_recv_buf_validate - validate basic format of received message * * This routine ensures a TIPC message has an acceptable header, and at least * as much data as the header indicates it should. The routine also ensures * that the entire message header is stored in the main fragment of the message * buffer, to simplify future access to message header fields. * * Note: Having extra info present in the message header or data areas is OK. * TIPC will ignore the excess, under the assumption that it is optional info * introduced by a later release of the protocol. */ static int link_recv_buf_validate(struct sk_buff *buf) { static u32 min_data_hdr_size[8] = { SHORT_H_SIZE, MCAST_H_SIZE, NAMED_H_SIZE, BASIC_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE, MAX_H_SIZE }; struct tipc_msg *msg; u32 tipc_hdr[2]; u32 size; u32 hdr_size; u32 min_hdr_size; if (unlikely(buf->len < MIN_H_SIZE)) return 0; msg = skb_header_pointer(buf, 0, sizeof(tipc_hdr), tipc_hdr); if (msg == NULL) return 0; if (unlikely(msg_version(msg) != TIPC_VERSION)) return 0; size = msg_size(msg); hdr_size = msg_hdr_sz(msg); min_hdr_size = msg_isdata(msg) ? min_data_hdr_size[msg_type(msg)] : INT_H_SIZE; if (unlikely((hdr_size < min_hdr_size) || (size < hdr_size) || (buf->len < size) || (size - hdr_size > TIPC_MAX_USER_MSG_SIZE))) return 0; return pskb_may_pull(buf, hdr_size); } /** * tipc_recv_msg - process TIPC messages arriving from off-node * @head: pointer to message buffer chain * @tb_ptr: pointer to bearer message arrived on * * Invoked with no locks held. Bearer pointer must point to a valid bearer * structure (i.e. cannot be NULL), but bearer can be inactive. */ void tipc_recv_msg(struct sk_buff *head, struct tipc_bearer *b_ptr) { read_lock_bh(&tipc_net_lock); while (head) { struct tipc_node *n_ptr; struct tipc_link *l_ptr; struct sk_buff *crs; struct sk_buff *buf = head; struct tipc_msg *msg; u32 seq_no; u32 ackd; u32 released = 0; int type; head = head->next; /* Ensure bearer is still enabled */ if (unlikely(!b_ptr->active)) goto cont; /* Ensure message is well-formed */ if (unlikely(!link_recv_buf_validate(buf))) goto cont; /* Ensure message data is a single contiguous unit */ if (unlikely(skb_linearize(buf))) goto cont; /* Handle arrival of a non-unicast link message */ msg = buf_msg(buf); if (unlikely(msg_non_seq(msg))) { if (msg_user(msg) == LINK_CONFIG) tipc_disc_recv_msg(buf, b_ptr); else tipc_bclink_recv_pkt(buf); continue; } /* Discard unicast link messages destined for another node */ if (unlikely(!msg_short(msg) && (msg_destnode(msg) != tipc_own_addr))) goto cont; /* Locate neighboring node that sent message */ n_ptr = tipc_node_find(msg_prevnode(msg)); if (unlikely(!n_ptr)) goto cont; tipc_node_lock(n_ptr); /* Locate unicast link endpoint that should handle message */ l_ptr = n_ptr->links[b_ptr->identity]; if (unlikely(!l_ptr)) { tipc_node_unlock(n_ptr); goto cont; } /* Verify that communication with node is currently allowed */ if ((n_ptr->block_setup & WAIT_PEER_DOWN) && msg_user(msg) == LINK_PROTOCOL && (msg_type(msg) == RESET_MSG || msg_type(msg) == ACTIVATE_MSG) && !msg_redundant_link(msg)) n_ptr->block_setup &= ~WAIT_PEER_DOWN; if (n_ptr->block_setup) { tipc_node_unlock(n_ptr); goto cont; } /* Validate message sequence number info */ seq_no = msg_seqno(msg); ackd = msg_ack(msg); /* Release acked messages */ if (n_ptr->bclink.supported) tipc_bclink_acknowledge(n_ptr, msg_bcast_ack(msg)); crs = l_ptr->first_out; while ((crs != l_ptr->next_out) && less_eq(buf_seqno(crs), ackd)) { struct sk_buff *next = crs->next; kfree_skb(crs); crs = next; released++; } if (released) { l_ptr->first_out = crs; l_ptr->out_queue_size -= released; } /* Try sending any messages link endpoint has pending */ if (unlikely(l_ptr->next_out)) tipc_link_push_queue(l_ptr); if (unlikely(!list_empty(&l_ptr->waiting_ports))) tipc_link_wakeup_ports(l_ptr, 0); if (unlikely(++l_ptr->unacked_window >= TIPC_MIN_LINK_WIN)) { l_ptr->stats.sent_acks++; tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); } /* Now (finally!) process the incoming message */ protocol_check: if (likely(link_working_working(l_ptr))) { if (likely(seq_no == mod(l_ptr->next_in_no))) { l_ptr->next_in_no++; if (unlikely(l_ptr->oldest_deferred_in)) head = link_insert_deferred_queue(l_ptr, head); deliver: if (likely(msg_isdata(msg))) { tipc_node_unlock(n_ptr); tipc_port_recv_msg(buf); continue; } switch (msg_user(msg)) { int ret; case MSG_BUNDLER: l_ptr->stats.recv_bundles++; l_ptr->stats.recv_bundled += msg_msgcnt(msg); tipc_node_unlock(n_ptr); tipc_link_recv_bundle(buf); continue; case NAME_DISTRIBUTOR: tipc_node_unlock(n_ptr); tipc_named_recv(buf); continue; case CONN_MANAGER: tipc_node_unlock(n_ptr); tipc_port_recv_proto_msg(buf); continue; case MSG_FRAGMENTER: l_ptr->stats.recv_fragments++; ret = tipc_link_recv_fragment( &l_ptr->defragm_buf, &buf, &msg); if (ret == 1) { l_ptr->stats.recv_fragmented++; goto deliver; } if (ret == -1) l_ptr->next_in_no--; break; case CHANGEOVER_PROTOCOL: type = msg_type(msg); if (link_recv_changeover_msg(&l_ptr, &buf)) { msg = buf_msg(buf); seq_no = msg_seqno(msg); if (type == ORIGINAL_MSG) goto deliver; goto protocol_check; } break; default: kfree_skb(buf); buf = NULL; break; } tipc_node_unlock(n_ptr); tipc_net_route_msg(buf); continue; } link_handle_out_of_seq_msg(l_ptr, buf); head = link_insert_deferred_queue(l_ptr, head); tipc_node_unlock(n_ptr); continue; } if (msg_user(msg) == LINK_PROTOCOL) { link_recv_proto_msg(l_ptr, buf); head = link_insert_deferred_queue(l_ptr, head); tipc_node_unlock(n_ptr); continue; } link_state_event(l_ptr, TRAFFIC_MSG_EVT); if (link_working_working(l_ptr)) { /* Re-insert in front of queue */ buf->next = head; head = buf; tipc_node_unlock(n_ptr); continue; } tipc_node_unlock(n_ptr); cont: kfree_skb(buf); } read_unlock_bh(&tipc_net_lock); } /* * tipc_link_defer_pkt - Add out-of-sequence message to deferred reception queue * * Returns increase in queue length (i.e. 0 or 1) */ u32 tipc_link_defer_pkt(struct sk_buff **head, struct sk_buff **tail, struct sk_buff *buf) { struct sk_buff *queue_buf; struct sk_buff **prev; u32 seq_no = buf_seqno(buf); buf->next = NULL; /* Empty queue ? */ if (*head == NULL) { *head = *tail = buf; return 1; } /* Last ? */ if (less(buf_seqno(*tail), seq_no)) { (*tail)->next = buf; *tail = buf; return 1; } /* Locate insertion point in queue, then insert; discard if duplicate */ prev = head; queue_buf = *head; for (;;) { u32 curr_seqno = buf_seqno(queue_buf); if (seq_no == curr_seqno) { kfree_skb(buf); return 0; } if (less(seq_no, curr_seqno)) break; prev = &queue_buf->next; queue_buf = queue_buf->next; } buf->next = queue_buf; *prev = buf; return 1; } /* * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet */ static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, struct sk_buff *buf) { u32 seq_no = buf_seqno(buf); if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) { link_recv_proto_msg(l_ptr, buf); return; } /* Record OOS packet arrival (force mismatch on next timeout) */ l_ptr->checkpoint--; /* * Discard packet if a duplicate; otherwise add it to deferred queue * and notify peer of gap as per protocol specification */ if (less(seq_no, mod(l_ptr->next_in_no))) { l_ptr->stats.duplicates++; kfree_skb(buf); return; } if (tipc_link_defer_pkt(&l_ptr->oldest_deferred_in, &l_ptr->newest_deferred_in, buf)) { l_ptr->deferred_inqueue_sz++; l_ptr->stats.deferred_recv++; if ((l_ptr->deferred_inqueue_sz % 16) == 1) tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); } else l_ptr->stats.duplicates++; } /* * Send protocol message to the other endpoint. */ void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ, int probe_msg, u32 gap, u32 tolerance, u32 priority, u32 ack_mtu) { struct sk_buff *buf = NULL; struct tipc_msg *msg = l_ptr->pmsg; u32 msg_size = sizeof(l_ptr->proto_msg); int r_flag; /* Discard any previous message that was deferred due to congestion */ if (l_ptr->proto_msg_queue) { kfree_skb(l_ptr->proto_msg_queue); l_ptr->proto_msg_queue = NULL; } if (link_blocked(l_ptr)) return; /* Abort non-RESET send if communication with node is prohibited */ if ((l_ptr->owner->block_setup) && (msg_typ != RESET_MSG)) return; /* Create protocol message with "out-of-sequence" sequence number */ msg_set_type(msg, msg_typ); msg_set_net_plane(msg, l_ptr->b_ptr->net_plane); msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); msg_set_last_bcast(msg, tipc_bclink_get_last_sent()); if (msg_typ == STATE_MSG) { u32 next_sent = mod(l_ptr->next_out_no); if (!tipc_link_is_up(l_ptr)) return; if (l_ptr->next_out) next_sent = buf_seqno(l_ptr->next_out); msg_set_next_sent(msg, next_sent); if (l_ptr->oldest_deferred_in) { u32 rec = buf_seqno(l_ptr->oldest_deferred_in); gap = mod(rec - mod(l_ptr->next_in_no)); } msg_set_seq_gap(msg, gap); if (gap) l_ptr->stats.sent_nacks++; msg_set_link_tolerance(msg, tolerance); msg_set_linkprio(msg, priority); msg_set_max_pkt(msg, ack_mtu); msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); msg_set_probe(msg, probe_msg != 0); if (probe_msg) { u32 mtu = l_ptr->max_pkt; if ((mtu < l_ptr->max_pkt_target) && link_working_working(l_ptr) && l_ptr->fsm_msg_cnt) { msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3; if (l_ptr->max_pkt_probes == 10) { l_ptr->max_pkt_target = (msg_size - 4); l_ptr->max_pkt_probes = 0; msg_size = (mtu + (l_ptr->max_pkt_target - mtu)/2 + 2) & ~3; } l_ptr->max_pkt_probes++; } l_ptr->stats.sent_probes++; } l_ptr->stats.sent_states++; } else { /* RESET_MSG or ACTIVATE_MSG */ msg_set_ack(msg, mod(l_ptr->reset_checkpoint - 1)); msg_set_seq_gap(msg, 0); msg_set_next_sent(msg, 1); msg_set_probe(msg, 0); msg_set_link_tolerance(msg, l_ptr->tolerance); msg_set_linkprio(msg, l_ptr->priority); msg_set_max_pkt(msg, l_ptr->max_pkt_target); } r_flag = (l_ptr->owner->working_links > tipc_link_is_up(l_ptr)); msg_set_redundant_link(msg, r_flag); msg_set_linkprio(msg, l_ptr->priority); msg_set_size(msg, msg_size); msg_set_seqno(msg, mod(l_ptr->next_out_no + (0xffff/2))); buf = tipc_buf_acquire(msg_size); if (!buf) return; skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg)); /* Defer message if bearer is already congested */ if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) { l_ptr->proto_msg_queue = buf; return; } /* Defer message if attempting to send results in bearer congestion */ if (!tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) { tipc_bearer_schedule(l_ptr->b_ptr, l_ptr); l_ptr->proto_msg_queue = buf; l_ptr->stats.bearer_congs++; return; } /* Discard message if it was sent successfully */ l_ptr->unacked_window = 0; kfree_skb(buf); } /* * Receive protocol message : * Note that network plane id propagates through the network, and may * change at any time. The node with lowest address rules */ static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf) { u32 rec_gap = 0; u32 max_pkt_info; u32 max_pkt_ack; u32 msg_tol; struct tipc_msg *msg = buf_msg(buf); if (link_blocked(l_ptr)) goto exit; /* record unnumbered packet arrival (force mismatch on next timeout) */ l_ptr->checkpoint--; if (l_ptr->b_ptr->net_plane != msg_net_plane(msg)) if (tipc_own_addr > msg_prevnode(msg)) l_ptr->b_ptr->net_plane = msg_net_plane(msg); l_ptr->owner->permit_changeover = msg_redundant_link(msg); switch (msg_type(msg)) { case RESET_MSG: if (!link_working_unknown(l_ptr) && (l_ptr->peer_session != INVALID_SESSION)) { if (less_eq(msg_session(msg), l_ptr->peer_session)) break; /* duplicate or old reset: ignore */ } if (!msg_redundant_link(msg) && (link_working_working(l_ptr) || link_working_unknown(l_ptr))) { /* * peer has lost contact -- don't allow peer's links * to reactivate before we recognize loss & clean up */ l_ptr->owner->block_setup = WAIT_NODE_DOWN; } link_state_event(l_ptr, RESET_MSG); /* fall thru' */ case ACTIVATE_MSG: /* Update link settings according other endpoint's values */ strcpy((strrchr(l_ptr->name, ':') + 1), (char *)msg_data(msg)); msg_tol = msg_link_tolerance(msg); if (msg_tol > l_ptr->tolerance) link_set_supervision_props(l_ptr, msg_tol); if (msg_linkprio(msg) > l_ptr->priority) l_ptr->priority = msg_linkprio(msg); max_pkt_info = msg_max_pkt(msg); if (max_pkt_info) { if (max_pkt_info < l_ptr->max_pkt_target) l_ptr->max_pkt_target = max_pkt_info; if (l_ptr->max_pkt > l_ptr->max_pkt_target) l_ptr->max_pkt = l_ptr->max_pkt_target; } else { l_ptr->max_pkt = l_ptr->max_pkt_target; } l_ptr->owner->bclink.supportable = (max_pkt_info != 0); /* Synchronize broadcast link info, if not done previously */ if (!tipc_node_is_up(l_ptr->owner)) { l_ptr->owner->bclink.last_sent = l_ptr->owner->bclink.last_in = msg_last_bcast(msg); l_ptr->owner->bclink.oos_state = 0; } l_ptr->peer_session = msg_session(msg); l_ptr->peer_bearer_id = msg_bearer_id(msg); if (msg_type(msg) == ACTIVATE_MSG) link_state_event(l_ptr, ACTIVATE_MSG); break; case STATE_MSG: msg_tol = msg_link_tolerance(msg); if (msg_tol) link_set_supervision_props(l_ptr, msg_tol); if (msg_linkprio(msg) && (msg_linkprio(msg) != l_ptr->priority)) { warn("Resetting link <%s>, priority change %u->%u\n", l_ptr->name, l_ptr->priority, msg_linkprio(msg)); l_ptr->priority = msg_linkprio(msg); tipc_link_reset(l_ptr); /* Enforce change to take effect */ break; } link_state_event(l_ptr, TRAFFIC_MSG_EVT); l_ptr->stats.recv_states++; if (link_reset_unknown(l_ptr)) break; if (less_eq(mod(l_ptr->next_in_no), msg_next_sent(msg))) { rec_gap = mod(msg_next_sent(msg) - mod(l_ptr->next_in_no)); } max_pkt_ack = msg_max_pkt(msg); if (max_pkt_ack > l_ptr->max_pkt) { l_ptr->max_pkt = max_pkt_ack; l_ptr->max_pkt_probes = 0; } max_pkt_ack = 0; if (msg_probe(msg)) { l_ptr->stats.recv_probes++; if (msg_size(msg) > sizeof(l_ptr->proto_msg)) max_pkt_ack = msg_size(msg); } /* Protocol message before retransmits, reduce loss risk */ if (l_ptr->owner->bclink.supported) tipc_bclink_update_link_state(l_ptr->owner, msg_last_bcast(msg)); if (rec_gap || (msg_probe(msg))) { tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, rec_gap, 0, 0, max_pkt_ack); } if (msg_seq_gap(msg)) { l_ptr->stats.recv_nacks++; tipc_link_retransmit(l_ptr, l_ptr->first_out, msg_seq_gap(msg)); } break; } exit: kfree_skb(buf); } /* * tipc_link_tunnel(): Send one message via a link belonging to * another bearer. Owner node is locked. */ static void tipc_link_tunnel(struct tipc_link *l_ptr, struct tipc_msg *tunnel_hdr, struct tipc_msg *msg, u32 selector) { struct tipc_link *tunnel; struct sk_buff *buf; u32 length = msg_size(msg); tunnel = l_ptr->owner->active_links[selector & 1]; if (!tipc_link_is_up(tunnel)) { warn("Link changeover error, " "tunnel link no longer available\n"); return; } msg_set_size(tunnel_hdr, length + INT_H_SIZE); buf = tipc_buf_acquire(length + INT_H_SIZE); if (!buf) { warn("Link changeover error, " "unable to send tunnel msg\n"); return; } skb_copy_to_linear_data(buf, tunnel_hdr, INT_H_SIZE); skb_copy_to_linear_data_offset(buf, INT_H_SIZE, msg, length); tipc_link_send_buf(tunnel, buf); } /* * changeover(): Send whole message queue via the remaining link * Owner node is locked. */ void tipc_link_changeover(struct tipc_link *l_ptr) { u32 msgcount = l_ptr->out_queue_size; struct sk_buff *crs = l_ptr->first_out; struct tipc_link *tunnel = l_ptr->owner->active_links[0]; struct tipc_msg tunnel_hdr; int split_bundles; if (!tunnel) return; if (!l_ptr->owner->permit_changeover) { warn("Link changeover error, " "peer did not permit changeover\n"); return; } tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr); msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); msg_set_msgcnt(&tunnel_hdr, msgcount); if (!l_ptr->first_out) { struct sk_buff *buf; buf = tipc_buf_acquire(INT_H_SIZE); if (buf) { skb_copy_to_linear_data(buf, &tunnel_hdr, INT_H_SIZE); msg_set_size(&tunnel_hdr, INT_H_SIZE); tipc_link_send_buf(tunnel, buf); } else { warn("Link changeover error, " "unable to send changeover msg\n"); } return; } split_bundles = (l_ptr->owner->active_links[0] != l_ptr->owner->active_links[1]); while (crs) { struct tipc_msg *msg = buf_msg(crs); if ((msg_user(msg) == MSG_BUNDLER) && split_bundles) { struct tipc_msg *m = msg_get_wrapped(msg); unchar *pos = (unchar *)m; msgcount = msg_msgcnt(msg); while (msgcount--) { msg_set_seqno(m, msg_seqno(msg)); tipc_link_tunnel(l_ptr, &tunnel_hdr, m, msg_link_selector(m)); pos += align(msg_size(m)); m = (struct tipc_msg *)pos; } } else { tipc_link_tunnel(l_ptr, &tunnel_hdr, msg, msg_link_selector(msg)); } crs = crs->next; } } void tipc_link_send_duplicate(struct tipc_link *l_ptr, struct tipc_link *tunnel) { struct sk_buff *iter; struct tipc_msg tunnel_hdr; tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr); msg_set_msgcnt(&tunnel_hdr, l_ptr->out_queue_size); msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); iter = l_ptr->first_out; while (iter) { struct sk_buff *outbuf; struct tipc_msg *msg = buf_msg(iter); u32 length = msg_size(msg); if (msg_user(msg) == MSG_BUNDLER) msg_set_type(msg, CLOSED_MSG); msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); /* Update */ msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); msg_set_size(&tunnel_hdr, length + INT_H_SIZE); outbuf = tipc_buf_acquire(length + INT_H_SIZE); if (outbuf == NULL) { warn("Link changeover error, " "unable to send duplicate msg\n"); return; } skb_copy_to_linear_data(outbuf, &tunnel_hdr, INT_H_SIZE); skb_copy_to_linear_data_offset(outbuf, INT_H_SIZE, iter->data, length); tipc_link_send_buf(tunnel, outbuf); if (!tipc_link_is_up(l_ptr)) return; iter = iter->next; } } /** * buf_extract - extracts embedded TIPC message from another message * @skb: encapsulating message buffer * @from_pos: offset to extract from * * Returns a new message buffer containing an embedded message. The * encapsulating message itself is left unchanged. */ static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos) { struct tipc_msg *msg = (struct tipc_msg *)(skb->data + from_pos); u32 size = msg_size(msg); struct sk_buff *eb; eb = tipc_buf_acquire(size); if (eb) skb_copy_to_linear_data(eb, msg, size); return eb; } /* * link_recv_changeover_msg(): Receive tunneled packet sent * via other link. Node is locked. Return extracted buffer. */ static int link_recv_changeover_msg(struct tipc_link **l_ptr, struct sk_buff **buf) { struct sk_buff *tunnel_buf = *buf; struct tipc_link *dest_link; struct tipc_msg *msg; struct tipc_msg *tunnel_msg = buf_msg(tunnel_buf); u32 msg_typ = msg_type(tunnel_msg); u32 msg_count = msg_msgcnt(tunnel_msg); dest_link = (*l_ptr)->owner->links[msg_bearer_id(tunnel_msg)]; if (!dest_link) goto exit; if (dest_link == *l_ptr) { err("Unexpected changeover message on link <%s>\n", (*l_ptr)->name); goto exit; } *l_ptr = dest_link; msg = msg_get_wrapped(tunnel_msg); if (msg_typ == DUPLICATE_MSG) { if (less(msg_seqno(msg), mod(dest_link->next_in_no))) goto exit; *buf = buf_extract(tunnel_buf, INT_H_SIZE); if (*buf == NULL) { warn("Link changeover error, duplicate msg dropped\n"); goto exit; } kfree_skb(tunnel_buf); return 1; } /* First original message ?: */ if (tipc_link_is_up(dest_link)) { info("Resetting link <%s>, changeover initiated by peer\n", dest_link->name); tipc_link_reset(dest_link); dest_link->exp_msg_count = msg_count; if (!msg_count) goto exit; } else if (dest_link->exp_msg_count == START_CHANGEOVER) { dest_link->exp_msg_count = msg_count; if (!msg_count) goto exit; } /* Receive original message */ if (dest_link->exp_msg_count == 0) { warn("Link switchover error, " "got too many tunnelled messages\n"); goto exit; } dest_link->exp_msg_count--; if (less(msg_seqno(msg), dest_link->reset_checkpoint)) { goto exit; } else { *buf = buf_extract(tunnel_buf, INT_H_SIZE); if (*buf != NULL) { kfree_skb(tunnel_buf); return 1; } else { warn("Link changeover error, original msg dropped\n"); } } exit: *buf = NULL; kfree_skb(tunnel_buf); return 0; } /* * Bundler functionality: */ void tipc_link_recv_bundle(struct sk_buff *buf) { u32 msgcount = msg_msgcnt(buf_msg(buf)); u32 pos = INT_H_SIZE; struct sk_buff *obuf; while (msgcount--) { obuf = buf_extract(buf, pos); if (obuf == NULL) { warn("Link unable to unbundle message(s)\n"); break; } pos += align(msg_size(buf_msg(obuf))); tipc_net_route_msg(obuf); } kfree_skb(buf); } /* * Fragmentation/defragmentation: */ /* * link_send_long_buf: Entry for buffers needing fragmentation. * The buffer is complete, inclusive total message length. * Returns user data length. */ static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf) { struct sk_buff *buf_chain = NULL; struct sk_buff *buf_chain_tail = (struct sk_buff *)&buf_chain; struct tipc_msg *inmsg = buf_msg(buf); struct tipc_msg fragm_hdr; u32 insize = msg_size(inmsg); u32 dsz = msg_data_sz(inmsg); unchar *crs = buf->data; u32 rest = insize; u32 pack_sz = l_ptr->max_pkt; u32 fragm_sz = pack_sz - INT_H_SIZE; u32 fragm_no = 0; u32 destaddr; if (msg_short(inmsg)) destaddr = l_ptr->addr; else destaddr = msg_destnode(inmsg); /* Prepare reusable fragment header: */ tipc_msg_init(&fragm_hdr, MSG_FRAGMENTER, FIRST_FRAGMENT, INT_H_SIZE, destaddr); /* Chop up message: */ while (rest > 0) { struct sk_buff *fragm; if (rest <= fragm_sz) { fragm_sz = rest; msg_set_type(&fragm_hdr, LAST_FRAGMENT); } fragm = tipc_buf_acquire(fragm_sz + INT_H_SIZE); if (fragm == NULL) { kfree_skb(buf); while (buf_chain) { buf = buf_chain; buf_chain = buf_chain->next; kfree_skb(buf); } return -ENOMEM; } msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE); fragm_no++; msg_set_fragm_no(&fragm_hdr, fragm_no); skb_copy_to_linear_data(fragm, &fragm_hdr, INT_H_SIZE); skb_copy_to_linear_data_offset(fragm, INT_H_SIZE, crs, fragm_sz); buf_chain_tail->next = fragm; buf_chain_tail = fragm; rest -= fragm_sz; crs += fragm_sz; msg_set_type(&fragm_hdr, FRAGMENT); } kfree_skb(buf); /* Append chain of fragments to send queue & send them */ l_ptr->long_msg_seq_no++; link_add_chain_to_outqueue(l_ptr, buf_chain, l_ptr->long_msg_seq_no); l_ptr->stats.sent_fragments += fragm_no; l_ptr->stats.sent_fragmented++; tipc_link_push_queue(l_ptr); return dsz; } /* * A pending message being re-assembled must store certain values * to handle subsequent fragments correctly. The following functions * help storing these values in unused, available fields in the * pending message. This makes dynamic memory allocation unnecessary. */ static void set_long_msg_seqno(struct sk_buff *buf, u32 seqno) { msg_set_seqno(buf_msg(buf), seqno); } static u32 get_fragm_size(struct sk_buff *buf) { return msg_ack(buf_msg(buf)); } static void set_fragm_size(struct sk_buff *buf, u32 sz) { msg_set_ack(buf_msg(buf), sz); } static u32 get_expected_frags(struct sk_buff *buf) { return msg_bcast_ack(buf_msg(buf)); } static void set_expected_frags(struct sk_buff *buf, u32 exp) { msg_set_bcast_ack(buf_msg(buf), exp); } static u32 get_timer_cnt(struct sk_buff *buf) { return msg_reroute_cnt(buf_msg(buf)); } static void incr_timer_cnt(struct sk_buff *buf) { msg_incr_reroute_cnt(buf_msg(buf)); } /* * tipc_link_recv_fragment(): Called with node lock on. Returns * the reassembled buffer if message is complete. */ int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb, struct tipc_msg **m) { struct sk_buff *prev = NULL; struct sk_buff *fbuf = *fb; struct tipc_msg *fragm = buf_msg(fbuf); struct sk_buff *pbuf = *pending; u32 long_msg_seq_no = msg_long_msgno(fragm); *fb = NULL; /* Is there an incomplete message waiting for this fragment? */ while (pbuf && ((buf_seqno(pbuf) != long_msg_seq_no) || (msg_orignode(fragm) != msg_orignode(buf_msg(pbuf))))) { prev = pbuf; pbuf = pbuf->next; } if (!pbuf && (msg_type(fragm) == FIRST_FRAGMENT)) { struct tipc_msg *imsg = (struct tipc_msg *)msg_data(fragm); u32 msg_sz = msg_size(imsg); u32 fragm_sz = msg_data_sz(fragm); u32 exp_fragm_cnt = msg_sz/fragm_sz + !!(msg_sz % fragm_sz); u32 max = TIPC_MAX_USER_MSG_SIZE + NAMED_H_SIZE; if (msg_type(imsg) == TIPC_MCAST_MSG) max = TIPC_MAX_USER_MSG_SIZE + MCAST_H_SIZE; if (msg_size(imsg) > max) { kfree_skb(fbuf); return 0; } pbuf = tipc_buf_acquire(msg_size(imsg)); if (pbuf != NULL) { pbuf->next = *pending; *pending = pbuf; skb_copy_to_linear_data(pbuf, imsg, msg_data_sz(fragm)); /* Prepare buffer for subsequent fragments. */ set_long_msg_seqno(pbuf, long_msg_seq_no); set_fragm_size(pbuf, fragm_sz); set_expected_frags(pbuf, exp_fragm_cnt - 1); } else { dbg("Link unable to reassemble fragmented message\n"); kfree_skb(fbuf); return -1; } kfree_skb(fbuf); return 0; } else if (pbuf && (msg_type(fragm) != FIRST_FRAGMENT)) { u32 dsz = msg_data_sz(fragm); u32 fsz = get_fragm_size(pbuf); u32 crs = ((msg_fragm_no(fragm) - 1) * fsz); u32 exp_frags = get_expected_frags(pbuf) - 1; skb_copy_to_linear_data_offset(pbuf, crs, msg_data(fragm), dsz); kfree_skb(fbuf); /* Is message complete? */ if (exp_frags == 0) { if (prev) prev->next = pbuf->next; else *pending = pbuf->next; msg_reset_reroute_cnt(buf_msg(pbuf)); *fb = pbuf; *m = buf_msg(pbuf); return 1; } set_expected_frags(pbuf, exp_frags); return 0; } kfree_skb(fbuf); return 0; } /** * link_check_defragm_bufs - flush stale incoming message fragments * @l_ptr: pointer to link */ static void link_check_defragm_bufs(struct tipc_link *l_ptr) { struct sk_buff *prev = NULL; struct sk_buff *next = NULL; struct sk_buff *buf = l_ptr->defragm_buf; if (!buf) return; if (!link_working_working(l_ptr)) return; while (buf) { u32 cnt = get_timer_cnt(buf); next = buf->next; if (cnt < 4) { incr_timer_cnt(buf); prev = buf; } else { if (prev) prev->next = buf->next; else l_ptr->defragm_buf = buf->next; kfree_skb(buf); } buf = next; } } static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance) { if ((tolerance < TIPC_MIN_LINK_TOL) || (tolerance > TIPC_MAX_LINK_TOL)) return; l_ptr->tolerance = tolerance; l_ptr->continuity_interval = ((tolerance / 4) > 500) ? 500 : tolerance / 4; l_ptr->abort_limit = tolerance / (l_ptr->continuity_interval / 4); } void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window) { /* Data messages from this node, inclusive FIRST_FRAGM */ l_ptr->queue_limit[TIPC_LOW_IMPORTANCE] = window; l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE] = (window / 3) * 4; l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE] = (window / 3) * 5; l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE] = (window / 3) * 6; /* Transiting data messages,inclusive FIRST_FRAGM */ l_ptr->queue_limit[TIPC_LOW_IMPORTANCE + 4] = 300; l_ptr->queue_limit[TIPC_MEDIUM_IMPORTANCE + 4] = 600; l_ptr->queue_limit[TIPC_HIGH_IMPORTANCE + 4] = 900; l_ptr->queue_limit[TIPC_CRITICAL_IMPORTANCE + 4] = 1200; l_ptr->queue_limit[CONN_MANAGER] = 1200; l_ptr->queue_limit[CHANGEOVER_PROTOCOL] = 2500; l_ptr->queue_limit[NAME_DISTRIBUTOR] = 3000; /* FRAGMENT and LAST_FRAGMENT packets */ l_ptr->queue_limit[MSG_FRAGMENTER] = 4000; } /** * link_find_link - locate link by name * @name - ptr to link name string * @node - ptr to area to be filled with ptr to associated node * * Caller must hold 'tipc_net_lock' to ensure node and bearer are not deleted; * this also prevents link deletion. * * Returns pointer to link (or 0 if invalid link name). */ static struct tipc_link *link_find_link(const char *name, struct tipc_node **node) { struct tipc_link_name link_name_parts; struct tipc_bearer *b_ptr; struct tipc_link *l_ptr; if (!link_name_validate(name, &link_name_parts)) return NULL; b_ptr = tipc_bearer_find_interface(link_name_parts.if_local); if (!b_ptr) return NULL; *node = tipc_node_find(link_name_parts.addr_peer); if (!*node) return NULL; l_ptr = (*node)->links[b_ptr->identity]; if (!l_ptr || strcmp(l_ptr->name, name)) return NULL; return l_ptr; } /** * link_value_is_valid -- validate proposed link tolerance/priority/window * * @cmd - value type (TIPC_CMD_SET_LINK_*) * @new_value - the new value * * Returns 1 if value is within range, 0 if not. */ static int link_value_is_valid(u16 cmd, u32 new_value) { switch (cmd) { case TIPC_CMD_SET_LINK_TOL: return (new_value >= TIPC_MIN_LINK_TOL) && (new_value <= TIPC_MAX_LINK_TOL); case TIPC_CMD_SET_LINK_PRI: return (new_value <= TIPC_MAX_LINK_PRI); case TIPC_CMD_SET_LINK_WINDOW: return (new_value >= TIPC_MIN_LINK_WIN) && (new_value <= TIPC_MAX_LINK_WIN); } return 0; } /** * link_cmd_set_value - change priority/tolerance/window for link/bearer/media * @name - ptr to link, bearer, or media name * @new_value - new value of link, bearer, or media setting * @cmd - which link, bearer, or media attribute to set (TIPC_CMD_SET_LINK_*) * * Caller must hold 'tipc_net_lock' to ensure link/bearer/media is not deleted. * * Returns 0 if value updated and negative value on error. */ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd) { struct tipc_node *node; struct tipc_link *l_ptr; struct tipc_bearer *b_ptr; struct tipc_media *m_ptr; l_ptr = link_find_link(name, &node); if (l_ptr) { /* * acquire node lock for tipc_link_send_proto_msg(). * see "TIPC locking policy" in net.c. */ tipc_node_lock(node); switch (cmd) { case TIPC_CMD_SET_LINK_TOL: link_set_supervision_props(l_ptr, new_value); tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, new_value, 0, 0); break; case TIPC_CMD_SET_LINK_PRI: l_ptr->priority = new_value; tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, new_value, 0); break; case TIPC_CMD_SET_LINK_WINDOW: tipc_link_set_queue_limits(l_ptr, new_value); break; } tipc_node_unlock(node); return 0; } b_ptr = tipc_bearer_find(name); if (b_ptr) { switch (cmd) { case TIPC_CMD_SET_LINK_TOL: b_ptr->tolerance = new_value; return 0; case TIPC_CMD_SET_LINK_PRI: b_ptr->priority = new_value; return 0; case TIPC_CMD_SET_LINK_WINDOW: b_ptr->window = new_value; return 0; } return -EINVAL; } m_ptr = tipc_media_find(name); if (!m_ptr) return -ENODEV; switch (cmd) { case TIPC_CMD_SET_LINK_TOL: m_ptr->tolerance = new_value; return 0; case TIPC_CMD_SET_LINK_PRI: m_ptr->priority = new_value; return 0; case TIPC_CMD_SET_LINK_WINDOW: m_ptr->window = new_value; return 0; } return -EINVAL; } struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space, u16 cmd) { struct tipc_link_config *args; u32 new_value; int res; if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_CONFIG)) return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); args = (struct tipc_link_config *)TLV_DATA(req_tlv_area); new_value = ntohl(args->value); if (!link_value_is_valid(cmd, new_value)) return tipc_cfg_reply_error_string( "cannot change, value invalid"); if (!strcmp(args->name, tipc_bclink_name)) { if ((cmd == TIPC_CMD_SET_LINK_WINDOW) && (tipc_bclink_set_queue_limits(new_value) == 0)) return tipc_cfg_reply_none(); return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED " (cannot change setting on broadcast link)"); } read_lock_bh(&tipc_net_lock); res = link_cmd_set_value(args->name, new_value, cmd); read_unlock_bh(&tipc_net_lock); if (res) return tipc_cfg_reply_error_string("cannot change link setting"); return tipc_cfg_reply_none(); } /** * link_reset_statistics - reset link statistics * @l_ptr: pointer to link */ static void link_reset_statistics(struct tipc_link *l_ptr) { memset(&l_ptr->stats, 0, sizeof(l_ptr->stats)); l_ptr->stats.sent_info = l_ptr->next_out_no; l_ptr->stats.recv_info = l_ptr->next_in_no; } struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_space) { char *link_name; struct tipc_link *l_ptr; struct tipc_node *node; if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME)) return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); link_name = (char *)TLV_DATA(req_tlv_area); if (!strcmp(link_name, tipc_bclink_name)) { if (tipc_bclink_reset_stats()) return tipc_cfg_reply_error_string("link not found"); return tipc_cfg_reply_none(); } read_lock_bh(&tipc_net_lock); l_ptr = link_find_link(link_name, &node); if (!l_ptr) { read_unlock_bh(&tipc_net_lock); return tipc_cfg_reply_error_string("link not found"); } tipc_node_lock(node); link_reset_statistics(l_ptr); tipc_node_unlock(node); read_unlock_bh(&tipc_net_lock); return tipc_cfg_reply_none(); } /** * percent - convert count to a percentage of total (rounding up or down) */ static u32 percent(u32 count, u32 total) { return (count * 100 + (total / 2)) / total; } /** * tipc_link_stats - print link statistics * @name: link name * @buf: print buffer area * @buf_size: size of print buffer area * * Returns length of print buffer data string (or 0 if error) */ static int tipc_link_stats(const char *name, char *buf, const u32 buf_size) { struct print_buf pb; struct tipc_link *l_ptr; struct tipc_node *node; char *status; u32 profile_total = 0; if (!strcmp(name, tipc_bclink_name)) return tipc_bclink_stats(buf, buf_size); tipc_printbuf_init(&pb, buf, buf_size); read_lock_bh(&tipc_net_lock); l_ptr = link_find_link(name, &node); if (!l_ptr) { read_unlock_bh(&tipc_net_lock); return 0; } tipc_node_lock(node); if (tipc_link_is_active(l_ptr)) status = "ACTIVE"; else if (tipc_link_is_up(l_ptr)) status = "STANDBY"; else status = "DEFUNCT"; tipc_printf(&pb, "Link <%s>\n" " %s MTU:%u Priority:%u Tolerance:%u ms" " Window:%u packets\n", l_ptr->name, status, l_ptr->max_pkt, l_ptr->priority, l_ptr->tolerance, l_ptr->queue_limit[0]); tipc_printf(&pb, " RX packets:%u fragments:%u/%u bundles:%u/%u\n", l_ptr->next_in_no - l_ptr->stats.recv_info, l_ptr->stats.recv_fragments, l_ptr->stats.recv_fragmented, l_ptr->stats.recv_bundles, l_ptr->stats.recv_bundled); tipc_printf(&pb, " TX packets:%u fragments:%u/%u bundles:%u/%u\n", l_ptr->next_out_no - l_ptr->stats.sent_info, l_ptr->stats.sent_fragments, l_ptr->stats.sent_fragmented, l_ptr->stats.sent_bundles, l_ptr->stats.sent_bundled); profile_total = l_ptr->stats.msg_length_counts; if (!profile_total) profile_total = 1; tipc_printf(&pb, " TX profile sample:%u packets average:%u octets\n" " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% " "-16384:%u%% -32768:%u%% -66000:%u%%\n", l_ptr->stats.msg_length_counts, l_ptr->stats.msg_lengths_total / profile_total, percent(l_ptr->stats.msg_length_profile[0], profile_total), percent(l_ptr->stats.msg_length_profile[1], profile_total), percent(l_ptr->stats.msg_length_profile[2], profile_total), percent(l_ptr->stats.msg_length_profile[3], profile_total), percent(l_ptr->stats.msg_length_profile[4], profile_total), percent(l_ptr->stats.msg_length_profile[5], profile_total), percent(l_ptr->stats.msg_length_profile[6], profile_total)); tipc_printf(&pb, " RX states:%u probes:%u naks:%u defs:%u dups:%u\n", l_ptr->stats.recv_states, l_ptr->stats.recv_probes, l_ptr->stats.recv_nacks, l_ptr->stats.deferred_recv, l_ptr->stats.duplicates); tipc_printf(&pb, " TX states:%u probes:%u naks:%u acks:%u dups:%u\n", l_ptr->stats.sent_states, l_ptr->stats.sent_probes, l_ptr->stats.sent_nacks, l_ptr->stats.sent_acks, l_ptr->stats.retransmitted); tipc_printf(&pb, " Congestion bearer:%u link:%u Send queue max:%u avg:%u\n", l_ptr->stats.bearer_congs, l_ptr->stats.link_congs, l_ptr->stats.max_queue_sz, l_ptr->stats.queue_sz_counts ? (l_ptr->stats.accu_queue_sz / l_ptr->stats.queue_sz_counts) : 0); tipc_node_unlock(node); read_unlock_bh(&tipc_net_lock); return tipc_printbuf_validate(&pb); } #define MAX_LINK_STATS_INFO 2000 struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_space) { struct sk_buff *buf; struct tlv_desc *rep_tlv; int str_len; if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_LINK_NAME)) return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_LINK_STATS_INFO)); if (!buf) return NULL; rep_tlv = (struct tlv_desc *)buf->data; str_len = tipc_link_stats((char *)TLV_DATA(req_tlv_area), (char *)TLV_DATA(rep_tlv), MAX_LINK_STATS_INFO); if (!str_len) { kfree_skb(buf); return tipc_cfg_reply_error_string("link not found"); } skb_put(buf, TLV_SPACE(str_len)); TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); return buf; } /** * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination * @dest: network address of destination node * @selector: used to select from set of active links * * If no active link can be found, uses default maximum packet size. */ u32 tipc_link_get_max_pkt(u32 dest, u32 selector) { struct tipc_node *n_ptr; struct tipc_link *l_ptr; u32 res = MAX_PKT_DEFAULT; if (dest == tipc_own_addr) return MAX_MSG_SIZE; read_lock_bh(&tipc_net_lock); n_ptr = tipc_node_find(dest); if (n_ptr) { tipc_node_lock(n_ptr); l_ptr = n_ptr->active_links[selector & 1]; if (l_ptr) res = l_ptr->max_pkt; tipc_node_unlock(n_ptr); } read_unlock_bh(&tipc_net_lock); return res; } static void link_print(struct tipc_link *l_ptr, const char *str) { char print_area[256]; struct print_buf pb; struct print_buf *buf = &pb; tipc_printbuf_init(buf, print_area, sizeof(print_area)); tipc_printf(buf, str); tipc_printf(buf, "Link %x<%s>:", l_ptr->addr, l_ptr->b_ptr->name); #ifdef CONFIG_TIPC_DEBUG if (link_reset_reset(l_ptr) || link_reset_unknown(l_ptr)) goto print_state; tipc_printf(buf, ": NXO(%u):", mod(l_ptr->next_out_no)); tipc_printf(buf, "NXI(%u):", mod(l_ptr->next_in_no)); tipc_printf(buf, "SQUE"); if (l_ptr->first_out) { tipc_printf(buf, "[%u..", buf_seqno(l_ptr->first_out)); if (l_ptr->next_out) tipc_printf(buf, "%u..", buf_seqno(l_ptr->next_out)); tipc_printf(buf, "%u]", buf_seqno(l_ptr->last_out)); if ((mod(buf_seqno(l_ptr->last_out) - buf_seqno(l_ptr->first_out)) != (l_ptr->out_queue_size - 1)) || (l_ptr->last_out->next != NULL)) { tipc_printf(buf, "\nSend queue inconsistency\n"); tipc_printf(buf, "first_out= %p ", l_ptr->first_out); tipc_printf(buf, "next_out= %p ", l_ptr->next_out); tipc_printf(buf, "last_out= %p ", l_ptr->last_out); } } else tipc_printf(buf, "[]"); tipc_printf(buf, "SQSIZ(%u)", l_ptr->out_queue_size); if (l_ptr->oldest_deferred_in) { u32 o = buf_seqno(l_ptr->oldest_deferred_in); u32 n = buf_seqno(l_ptr->newest_deferred_in); tipc_printf(buf, ":RQUE[%u..%u]", o, n); if (l_ptr->deferred_inqueue_sz != mod((n + 1) - o)) { tipc_printf(buf, ":RQSIZ(%u)", l_ptr->deferred_inqueue_sz); } } print_state: #endif if (link_working_unknown(l_ptr)) tipc_printf(buf, ":WU"); else if (link_reset_reset(l_ptr)) tipc_printf(buf, ":RR"); else if (link_reset_unknown(l_ptr)) tipc_printf(buf, ":RU"); else if (link_working_working(l_ptr)) tipc_printf(buf, ":WW"); tipc_printf(buf, "\n"); tipc_printbuf_validate(buf); info("%s", print_area); }
gpl-2.0
f1vefour/mako
drivers/mtd/nand/h1910.c
4798
4046
/* * drivers/mtd/nand/h1910.c * * Copyright (C) 2003 Joshua Wise (joshua@joshuawise.com) * * Derived from drivers/mtd/nand/edb7312.c * Copyright (C) 2002 Marius Gröger (mag@sysgo.de) * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.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. * * Overview: * This is a device driver for the NAND flash device found on the * iPAQ h1910 board which utilizes the Samsung K9F2808 part. This is * a 128Mibit (16MiB x 8 bits) NAND flash device. */ #include <linux/slab.h> #include <linux/init.h> #include <linux/module.h> #include <linux/mtd/mtd.h> #include <linux/mtd/nand.h> #include <linux/mtd/partitions.h> #include <asm/io.h> #include <mach/hardware.h> /* for CLPS7111_VIRT_BASE */ #include <asm/sizes.h> #include <mach/h1900-gpio.h> #include <mach/ipaq.h> /* * MTD structure for EDB7312 board */ static struct mtd_info *h1910_nand_mtd = NULL; /* * Module stuff */ /* * Define static partitions for flash device */ static struct mtd_partition partition_info[] = { {name:"h1910 NAND Flash", offset:0, size:16 * 1024 * 1024} }; #define NUM_PARTITIONS 1 /* * hardware specific access to control-lines * * NAND_NCE: bit 0 - don't care * NAND_CLE: bit 1 - address bit 2 * NAND_ALE: bit 2 - address bit 3 */ static void h1910_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) { struct nand_chip *chip = mtd->priv; if (cmd != NAND_CMD_NONE) writeb(cmd, chip->IO_ADDR_W | ((ctrl & 0x6) << 1)); } /* * read device ready pin */ #if 0 static int h1910_device_ready(struct mtd_info *mtd) { return (GPLR(55) & GPIO_bit(55)); } #endif /* * Main initialization routine */ static int __init h1910_init(void) { struct nand_chip *this; void __iomem *nandaddr; if (!machine_is_h1900()) return -ENODEV; nandaddr = ioremap(0x08000000, 0x1000); if (!nandaddr) { printk("Failed to ioremap nand flash.\n"); return -ENOMEM; } /* Allocate memory for MTD device structure and private data */ h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); if (!h1910_nand_mtd) { printk("Unable to allocate h1910 NAND MTD device structure.\n"); iounmap((void *)nandaddr); return -ENOMEM; } /* Get pointer to private data */ this = (struct nand_chip *)(&h1910_nand_mtd[1]); /* Initialize structures */ memset(h1910_nand_mtd, 0, sizeof(struct mtd_info)); memset(this, 0, sizeof(struct nand_chip)); /* Link the private data with the MTD structure */ h1910_nand_mtd->priv = this; h1910_nand_mtd->owner = THIS_MODULE; /* * Enable VPEN */ GPSR(37) = GPIO_bit(37); /* insert callbacks */ this->IO_ADDR_R = nandaddr; this->IO_ADDR_W = nandaddr; this->cmd_ctrl = h1910_hwcontrol; this->dev_ready = NULL; /* unknown whether that was correct or not so we will just do it like this */ /* 15 us command delay time */ this->chip_delay = 50; this->ecc.mode = NAND_ECC_SOFT; this->options = NAND_NO_AUTOINCR; /* Scan to find existence of the device */ if (nand_scan(h1910_nand_mtd, 1)) { printk(KERN_NOTICE "No NAND device - returning -ENXIO\n"); kfree(h1910_nand_mtd); iounmap((void *)nandaddr); return -ENXIO; } /* Register the partitions */ mtd_device_parse_register(h1910_nand_mtd, NULL, NULL, partition_info, NUM_PARTITIONS); /* Return happy */ return 0; } module_init(h1910_init); /* * Clean up routine */ static void __exit h1910_cleanup(void) { struct nand_chip *this = (struct nand_chip *)&h1910_nand_mtd[1]; /* Release resources, unregister device */ nand_release(h1910_nand_mtd); /* Release io resource */ iounmap((void *)this->IO_ADDR_W); /* Free the MTD device structure */ kfree(h1910_nand_mtd); } module_exit(h1910_cleanup); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>"); MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910");
gpl-2.0
chevanlol360/Kernel_LGE_X5
drivers/net/wireless/wl12xx/debugfs.c
4798
32840
/* * This file is part of wl1271 * * Copyright (C) 2009 Nokia Corporation * * Contact: Luciano Coelho <luciano.coelho@nokia.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 "debugfs.h" #include <linux/skbuff.h> #include <linux/slab.h> #include "wl12xx.h" #include "debug.h" #include "acx.h" #include "ps.h" #include "io.h" #include "tx.h" /* ms */ #define WL1271_DEBUGFS_STATS_LIFETIME 1000 /* debugfs macros idea from mac80211 */ #define DEBUGFS_FORMAT_BUFFER_SIZE 100 static int wl1271_format_buffer(char __user *userbuf, size_t count, loff_t *ppos, char *fmt, ...) { va_list args; char buf[DEBUGFS_FORMAT_BUFFER_SIZE]; int res; va_start(args, fmt); res = vscnprintf(buf, sizeof(buf), fmt, args); va_end(args); return simple_read_from_buffer(userbuf, count, ppos, buf, res); } #define DEBUGFS_READONLY_FILE(name, fmt, value...) \ static ssize_t name## _read(struct file *file, char __user *userbuf, \ size_t count, loff_t *ppos) \ { \ struct wl1271 *wl = file->private_data; \ return wl1271_format_buffer(userbuf, count, ppos, \ fmt "\n", ##value); \ } \ \ static const struct file_operations name## _ops = { \ .read = name## _read, \ .open = simple_open, \ .llseek = generic_file_llseek, \ }; #define DEBUGFS_ADD(name, parent) \ entry = debugfs_create_file(#name, 0400, parent, \ wl, &name## _ops); \ if (!entry || IS_ERR(entry)) \ goto err; \ #define DEBUGFS_ADD_PREFIX(prefix, name, parent) \ do { \ entry = debugfs_create_file(#name, 0400, parent, \ wl, &prefix## _## name## _ops); \ if (!entry || IS_ERR(entry)) \ goto err; \ } while (0); #define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \ static ssize_t sub## _ ##name## _read(struct file *file, \ char __user *userbuf, \ size_t count, loff_t *ppos) \ { \ struct wl1271 *wl = file->private_data; \ \ wl1271_debugfs_update_stats(wl); \ \ return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \ wl->stats.fw_stats->sub.name); \ } \ \ static const struct file_operations sub## _ ##name## _ops = { \ .read = sub## _ ##name## _read, \ .open = simple_open, \ .llseek = generic_file_llseek, \ }; #define DEBUGFS_FWSTATS_ADD(sub, name) \ DEBUGFS_ADD(sub## _ ##name, stats) static void wl1271_debugfs_update_stats(struct wl1271 *wl) { int ret; mutex_lock(&wl->mutex); ret = wl1271_ps_elp_wakeup(wl); if (ret < 0) goto out; if (wl->state == WL1271_STATE_ON && !wl->plt && time_after(jiffies, wl->stats.fw_stats_update + msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) { wl1271_acx_statistics(wl, wl->stats.fw_stats); wl->stats.fw_stats_update = jiffies; } wl1271_ps_elp_sleep(wl); out: mutex_unlock(&wl->mutex); } DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u"); DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u"); DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u"); DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u"); DEBUGFS_FWSTATS_FILE(rx, dropped, "%u"); DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u"); DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u"); DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u"); DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u"); DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u"); DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u"); DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u"); DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u"); DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u"); DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u"); DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u"); DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u"); DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u"); DEBUGFS_FWSTATS_FILE(isr, irqs, "%u"); DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u"); DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u"); DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u"); DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u"); DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u"); DEBUGFS_FWSTATS_FILE(isr, commands, "%u"); DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u"); DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u"); DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u"); DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u"); DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u"); DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u"); DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u"); DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u"); /* skipping wep.reserved */ DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u"); DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u"); DEBUGFS_FWSTATS_FILE(wep, packets, "%u"); DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u"); DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u"); DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u"); DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u"); DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u"); DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u"); DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u"); DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u"); DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u"); DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u"); DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u"); DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u"); DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u"); /* skipping cont_miss_bcns_spread for now */ DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u"); DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u"); DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u"); DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u"); DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u"); DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u"); DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u"); DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u"); DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u"); DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u"); DEBUGFS_FWSTATS_FILE(event, calibration, "%u"); DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u"); DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u"); DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u"); DEBUGFS_FWSTATS_FILE(event, oom_late, "%u"); DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u"); DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u"); DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u"); DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u"); DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u"); DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u"); DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u"); DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u"); DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u"); DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u"); DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u"); DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u"); DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u"); DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u"); DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count); DEBUGFS_READONLY_FILE(excessive_retries, "%u", wl->stats.excessive_retries); static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; u32 queue_len; char buf[20]; int res; queue_len = wl1271_tx_total_queue_count(wl); res = scnprintf(buf, sizeof(buf), "%u\n", queue_len); return simple_read_from_buffer(userbuf, count, ppos, buf, res); } static const struct file_operations tx_queue_len_ops = { .read = tx_queue_len_read, .open = simple_open, .llseek = default_llseek, }; static ssize_t gpio_power_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); int res; char buf[10]; res = scnprintf(buf, sizeof(buf), "%d\n", state); return simple_read_from_buffer(user_buf, count, ppos, buf, res); } static ssize_t gpio_power_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; unsigned long value; int ret; ret = kstrtoul_from_user(user_buf, count, 10, &value); if (ret < 0) { wl1271_warning("illegal value in gpio_power"); return -EINVAL; } mutex_lock(&wl->mutex); if (value) wl1271_power_on(wl); else wl1271_power_off(wl); mutex_unlock(&wl->mutex); return count; } static const struct file_operations gpio_power_ops = { .read = gpio_power_read, .write = gpio_power_write, .open = simple_open, .llseek = default_llseek, }; static ssize_t start_recovery_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; mutex_lock(&wl->mutex); wl12xx_queue_recovery_work(wl); mutex_unlock(&wl->mutex); return count; } static const struct file_operations start_recovery_ops = { .write = start_recovery_write, .open = simple_open, .llseek = default_llseek, }; static ssize_t dynamic_ps_timeout_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; return wl1271_format_buffer(user_buf, count, ppos, "%d\n", wl->conf.conn.dynamic_ps_timeout); } static ssize_t dynamic_ps_timeout_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; struct wl12xx_vif *wlvif; unsigned long value; int ret; ret = kstrtoul_from_user(user_buf, count, 10, &value); if (ret < 0) { wl1271_warning("illegal value in dynamic_ps"); return -EINVAL; } if (value < 1 || value > 65535) { wl1271_warning("dyanmic_ps_timeout is not in valid range"); return -ERANGE; } mutex_lock(&wl->mutex); wl->conf.conn.dynamic_ps_timeout = value; if (wl->state == WL1271_STATE_OFF) goto out; ret = wl1271_ps_elp_wakeup(wl); if (ret < 0) goto out; /* In case we're already in PSM, trigger it again to set new timeout * immediately without waiting for re-association */ wl12xx_for_each_wlvif_sta(wl, wlvif) { if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) wl1271_ps_set_mode(wl, wlvif, STATION_AUTO_PS_MODE); } wl1271_ps_elp_sleep(wl); out: mutex_unlock(&wl->mutex); return count; } static const struct file_operations dynamic_ps_timeout_ops = { .read = dynamic_ps_timeout_read, .write = dynamic_ps_timeout_write, .open = simple_open, .llseek = default_llseek, }; static ssize_t forced_ps_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; return wl1271_format_buffer(user_buf, count, ppos, "%d\n", wl->conf.conn.forced_ps); } static ssize_t forced_ps_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; struct wl12xx_vif *wlvif; unsigned long value; int ret, ps_mode; ret = kstrtoul_from_user(user_buf, count, 10, &value); if (ret < 0) { wl1271_warning("illegal value in forced_ps"); return -EINVAL; } if (value != 1 && value != 0) { wl1271_warning("forced_ps should be either 0 or 1"); return -ERANGE; } mutex_lock(&wl->mutex); if (wl->conf.conn.forced_ps == value) goto out; wl->conf.conn.forced_ps = value; if (wl->state == WL1271_STATE_OFF) goto out; ret = wl1271_ps_elp_wakeup(wl); if (ret < 0) goto out; /* In case we're already in PSM, trigger it again to switch mode * immediately without waiting for re-association */ ps_mode = value ? STATION_POWER_SAVE_MODE : STATION_AUTO_PS_MODE; wl12xx_for_each_wlvif_sta(wl, wlvif) { if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) wl1271_ps_set_mode(wl, wlvif, ps_mode); } wl1271_ps_elp_sleep(wl); out: mutex_unlock(&wl->mutex); return count; } static const struct file_operations forced_ps_ops = { .read = forced_ps_read, .write = forced_ps_write, .open = simple_open, .llseek = default_llseek, }; static ssize_t split_scan_timeout_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; return wl1271_format_buffer(user_buf, count, ppos, "%d\n", wl->conf.scan.split_scan_timeout / 1000); } static ssize_t split_scan_timeout_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; unsigned long value; int ret; ret = kstrtoul_from_user(user_buf, count, 10, &value); if (ret < 0) { wl1271_warning("illegal value in split_scan_timeout"); return -EINVAL; } if (value == 0) wl1271_info("split scan will be disabled"); mutex_lock(&wl->mutex); wl->conf.scan.split_scan_timeout = value * 1000; mutex_unlock(&wl->mutex); return count; } static const struct file_operations split_scan_timeout_ops = { .read = split_scan_timeout_read, .write = split_scan_timeout_write, .open = simple_open, .llseek = default_llseek, }; static ssize_t driver_state_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; int res = 0; ssize_t ret; char *buf; #define DRIVER_STATE_BUF_LEN 1024 buf = kmalloc(DRIVER_STATE_BUF_LEN, GFP_KERNEL); if (!buf) return -ENOMEM; mutex_lock(&wl->mutex); #define DRIVER_STATE_PRINT(x, fmt) \ (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\ #x " = " fmt "\n", wl->x)) #define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld") #define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d") #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s") #define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx") #define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x") DRIVER_STATE_PRINT_INT(tx_blocks_available); DRIVER_STATE_PRINT_INT(tx_allocated_blocks); DRIVER_STATE_PRINT_INT(tx_allocated_pkts[0]); DRIVER_STATE_PRINT_INT(tx_allocated_pkts[1]); DRIVER_STATE_PRINT_INT(tx_allocated_pkts[2]); DRIVER_STATE_PRINT_INT(tx_allocated_pkts[3]); DRIVER_STATE_PRINT_INT(tx_frames_cnt); DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]); DRIVER_STATE_PRINT_INT(tx_queue_count[0]); DRIVER_STATE_PRINT_INT(tx_queue_count[1]); DRIVER_STATE_PRINT_INT(tx_queue_count[2]); DRIVER_STATE_PRINT_INT(tx_queue_count[3]); DRIVER_STATE_PRINT_INT(tx_packets_count); DRIVER_STATE_PRINT_INT(tx_results_count); DRIVER_STATE_PRINT_LHEX(flags); DRIVER_STATE_PRINT_INT(tx_blocks_freed); DRIVER_STATE_PRINT_INT(rx_counter); DRIVER_STATE_PRINT_INT(state); DRIVER_STATE_PRINT_INT(channel); DRIVER_STATE_PRINT_INT(band); DRIVER_STATE_PRINT_INT(power_level); DRIVER_STATE_PRINT_INT(sg_enabled); DRIVER_STATE_PRINT_INT(enable_11a); DRIVER_STATE_PRINT_INT(noise); DRIVER_STATE_PRINT_HEX(ap_fw_ps_map); DRIVER_STATE_PRINT_LHEX(ap_ps_map); DRIVER_STATE_PRINT_HEX(quirks); DRIVER_STATE_PRINT_HEX(irq); DRIVER_STATE_PRINT_HEX(ref_clock); DRIVER_STATE_PRINT_HEX(tcxo_clock); DRIVER_STATE_PRINT_HEX(hw_pg_ver); DRIVER_STATE_PRINT_HEX(platform_quirks); DRIVER_STATE_PRINT_HEX(chip.id); DRIVER_STATE_PRINT_STR(chip.fw_ver_str); DRIVER_STATE_PRINT_INT(sched_scanning); #undef DRIVER_STATE_PRINT_INT #undef DRIVER_STATE_PRINT_LONG #undef DRIVER_STATE_PRINT_HEX #undef DRIVER_STATE_PRINT_LHEX #undef DRIVER_STATE_PRINT_STR #undef DRIVER_STATE_PRINT #undef DRIVER_STATE_BUF_LEN mutex_unlock(&wl->mutex); ret = simple_read_from_buffer(user_buf, count, ppos, buf, res); kfree(buf); return ret; } static const struct file_operations driver_state_ops = { .read = driver_state_read, .open = simple_open, .llseek = default_llseek, }; static ssize_t vifs_state_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; struct wl12xx_vif *wlvif; int ret, res = 0; const int buf_size = 4096; char *buf; char tmp_buf[64]; buf = kzalloc(buf_size, GFP_KERNEL); if (!buf) return -ENOMEM; mutex_lock(&wl->mutex); #define VIF_STATE_PRINT(x, fmt) \ (res += scnprintf(buf + res, buf_size - res, \ #x " = " fmt "\n", wlvif->x)) #define VIF_STATE_PRINT_LONG(x) VIF_STATE_PRINT(x, "%ld") #define VIF_STATE_PRINT_INT(x) VIF_STATE_PRINT(x, "%d") #define VIF_STATE_PRINT_STR(x) VIF_STATE_PRINT(x, "%s") #define VIF_STATE_PRINT_LHEX(x) VIF_STATE_PRINT(x, "0x%lx") #define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx") #define VIF_STATE_PRINT_HEX(x) VIF_STATE_PRINT(x, "0x%x") #define VIF_STATE_PRINT_NSTR(x, len) \ do { \ memset(tmp_buf, 0, sizeof(tmp_buf)); \ memcpy(tmp_buf, wlvif->x, \ min_t(u8, len, sizeof(tmp_buf) - 1)); \ res += scnprintf(buf + res, buf_size - res, \ #x " = %s\n", tmp_buf); \ } while (0) wl12xx_for_each_wlvif(wl, wlvif) { VIF_STATE_PRINT_INT(role_id); VIF_STATE_PRINT_INT(bss_type); VIF_STATE_PRINT_LHEX(flags); VIF_STATE_PRINT_INT(p2p); VIF_STATE_PRINT_INT(dev_role_id); VIF_STATE_PRINT_INT(dev_hlid); if (wlvif->bss_type == BSS_TYPE_STA_BSS || wlvif->bss_type == BSS_TYPE_IBSS) { VIF_STATE_PRINT_INT(sta.hlid); VIF_STATE_PRINT_INT(sta.ba_rx_bitmap); VIF_STATE_PRINT_INT(sta.basic_rate_idx); VIF_STATE_PRINT_INT(sta.ap_rate_idx); VIF_STATE_PRINT_INT(sta.p2p_rate_idx); VIF_STATE_PRINT_INT(sta.qos); } else { VIF_STATE_PRINT_INT(ap.global_hlid); VIF_STATE_PRINT_INT(ap.bcast_hlid); VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]); VIF_STATE_PRINT_INT(ap.mgmt_rate_idx); VIF_STATE_PRINT_INT(ap.bcast_rate_idx); VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]); VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]); VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]); VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]); } VIF_STATE_PRINT_INT(last_tx_hlid); VIF_STATE_PRINT_LHEX(links_map[0]); VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len); VIF_STATE_PRINT_INT(band); VIF_STATE_PRINT_INT(channel); VIF_STATE_PRINT_HEX(bitrate_masks[0]); VIF_STATE_PRINT_HEX(bitrate_masks[1]); VIF_STATE_PRINT_HEX(basic_rate_set); VIF_STATE_PRINT_HEX(basic_rate); VIF_STATE_PRINT_HEX(rate_set); VIF_STATE_PRINT_INT(beacon_int); VIF_STATE_PRINT_INT(default_key); VIF_STATE_PRINT_INT(aid); VIF_STATE_PRINT_INT(session_counter); VIF_STATE_PRINT_INT(psm_entry_retry); VIF_STATE_PRINT_INT(power_level); VIF_STATE_PRINT_INT(rssi_thold); VIF_STATE_PRINT_INT(last_rssi_event); VIF_STATE_PRINT_INT(ba_support); VIF_STATE_PRINT_INT(ba_allowed); VIF_STATE_PRINT_LLHEX(tx_security_seq); VIF_STATE_PRINT_INT(tx_security_last_seq_lsb); } #undef VIF_STATE_PRINT_INT #undef VIF_STATE_PRINT_LONG #undef VIF_STATE_PRINT_HEX #undef VIF_STATE_PRINT_LHEX #undef VIF_STATE_PRINT_LLHEX #undef VIF_STATE_PRINT_STR #undef VIF_STATE_PRINT_NSTR #undef VIF_STATE_PRINT mutex_unlock(&wl->mutex); ret = simple_read_from_buffer(user_buf, count, ppos, buf, res); kfree(buf); return ret; } static const struct file_operations vifs_state_ops = { .read = vifs_state_read, .open = simple_open, .llseek = default_llseek, }; static ssize_t dtim_interval_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; u8 value; if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM || wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM) value = wl->conf.conn.listen_interval; else value = 0; return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value); } static ssize_t dtim_interval_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; unsigned long value; int ret; ret = kstrtoul_from_user(user_buf, count, 10, &value); if (ret < 0) { wl1271_warning("illegal value for dtim_interval"); return -EINVAL; } if (value < 1 || value > 10) { wl1271_warning("dtim value is not in valid range"); return -ERANGE; } mutex_lock(&wl->mutex); wl->conf.conn.listen_interval = value; /* for some reason there are different event types for 1 and >1 */ if (value == 1) wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM; else wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM; /* * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only * take effect on the next time we enter psm. */ mutex_unlock(&wl->mutex); return count; } static const struct file_operations dtim_interval_ops = { .read = dtim_interval_read, .write = dtim_interval_write, .open = simple_open, .llseek = default_llseek, }; static ssize_t suspend_dtim_interval_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; u8 value; if (wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_DTIM || wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM) value = wl->conf.conn.suspend_listen_interval; else value = 0; return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value); } static ssize_t suspend_dtim_interval_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; unsigned long value; int ret; ret = kstrtoul_from_user(user_buf, count, 10, &value); if (ret < 0) { wl1271_warning("illegal value for suspend_dtim_interval"); return -EINVAL; } if (value < 1 || value > 10) { wl1271_warning("suspend_dtim value is not in valid range"); return -ERANGE; } mutex_lock(&wl->mutex); wl->conf.conn.suspend_listen_interval = value; /* for some reason there are different event types for 1 and >1 */ if (value == 1) wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_DTIM; else wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM; mutex_unlock(&wl->mutex); return count; } static const struct file_operations suspend_dtim_interval_ops = { .read = suspend_dtim_interval_read, .write = suspend_dtim_interval_write, .open = simple_open, .llseek = default_llseek, }; static ssize_t beacon_interval_read(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; u8 value; if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON || wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS) value = wl->conf.conn.listen_interval; else value = 0; return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value); } static ssize_t beacon_interval_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; unsigned long value; int ret; ret = kstrtoul_from_user(user_buf, count, 10, &value); if (ret < 0) { wl1271_warning("illegal value for beacon_interval"); return -EINVAL; } if (value < 1 || value > 255) { wl1271_warning("beacon interval value is not in valid range"); return -ERANGE; } mutex_lock(&wl->mutex); wl->conf.conn.listen_interval = value; /* for some reason there are different event types for 1 and >1 */ if (value == 1) wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON; else wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS; /* * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only * take effect on the next time we enter psm. */ mutex_unlock(&wl->mutex); return count; } static const struct file_operations beacon_interval_ops = { .read = beacon_interval_read, .write = beacon_interval_write, .open = simple_open, .llseek = default_llseek, }; static ssize_t rx_streaming_interval_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; struct wl12xx_vif *wlvif; unsigned long value; int ret; ret = kstrtoul_from_user(user_buf, count, 10, &value); if (ret < 0) { wl1271_warning("illegal value in rx_streaming_interval!"); return -EINVAL; } /* valid values: 0, 10-100 */ if (value && (value < 10 || value > 100)) { wl1271_warning("value is not in range!"); return -ERANGE; } mutex_lock(&wl->mutex); wl->conf.rx_streaming.interval = value; ret = wl1271_ps_elp_wakeup(wl); if (ret < 0) goto out; wl12xx_for_each_wlvif_sta(wl, wlvif) { wl1271_recalc_rx_streaming(wl, wlvif); } wl1271_ps_elp_sleep(wl); out: mutex_unlock(&wl->mutex); return count; } static ssize_t rx_streaming_interval_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; return wl1271_format_buffer(userbuf, count, ppos, "%d\n", wl->conf.rx_streaming.interval); } static const struct file_operations rx_streaming_interval_ops = { .read = rx_streaming_interval_read, .write = rx_streaming_interval_write, .open = simple_open, .llseek = default_llseek, }; static ssize_t rx_streaming_always_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; struct wl12xx_vif *wlvif; unsigned long value; int ret; ret = kstrtoul_from_user(user_buf, count, 10, &value); if (ret < 0) { wl1271_warning("illegal value in rx_streaming_write!"); return -EINVAL; } /* valid values: 0, 10-100 */ if (!(value == 0 || value == 1)) { wl1271_warning("value is not in valid!"); return -EINVAL; } mutex_lock(&wl->mutex); wl->conf.rx_streaming.always = value; ret = wl1271_ps_elp_wakeup(wl); if (ret < 0) goto out; wl12xx_for_each_wlvif_sta(wl, wlvif) { wl1271_recalc_rx_streaming(wl, wlvif); } wl1271_ps_elp_sleep(wl); out: mutex_unlock(&wl->mutex); return count; } static ssize_t rx_streaming_always_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; return wl1271_format_buffer(userbuf, count, ppos, "%d\n", wl->conf.rx_streaming.always); } static const struct file_operations rx_streaming_always_ops = { .read = rx_streaming_always_read, .write = rx_streaming_always_write, .open = simple_open, .llseek = default_llseek, }; static ssize_t beacon_filtering_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { struct wl1271 *wl = file->private_data; struct wl12xx_vif *wlvif; char buf[10]; size_t len; unsigned long value; int ret; len = min(count, sizeof(buf) - 1); if (copy_from_user(buf, user_buf, len)) return -EFAULT; buf[len] = '\0'; ret = kstrtoul(buf, 0, &value); if (ret < 0) { wl1271_warning("illegal value for beacon_filtering!"); return -EINVAL; } mutex_lock(&wl->mutex); ret = wl1271_ps_elp_wakeup(wl); if (ret < 0) goto out; wl12xx_for_each_wlvif(wl, wlvif) { ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value); } wl1271_ps_elp_sleep(wl); out: mutex_unlock(&wl->mutex); return count; } static const struct file_operations beacon_filtering_ops = { .write = beacon_filtering_write, .open = simple_open, .llseek = default_llseek, }; static int wl1271_debugfs_add_files(struct wl1271 *wl, struct dentry *rootdir) { int ret = 0; struct dentry *entry, *stats, *streaming; stats = debugfs_create_dir("fw-statistics", rootdir); if (!stats || IS_ERR(stats)) { entry = stats; goto err; } DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow); DEBUGFS_FWSTATS_ADD(rx, out_of_mem); DEBUGFS_FWSTATS_ADD(rx, hdr_overflow); DEBUGFS_FWSTATS_ADD(rx, hw_stuck); DEBUGFS_FWSTATS_ADD(rx, dropped); DEBUGFS_FWSTATS_ADD(rx, fcs_err); DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig); DEBUGFS_FWSTATS_ADD(rx, path_reset); DEBUGFS_FWSTATS_ADD(rx, reset_counter); DEBUGFS_FWSTATS_ADD(dma, rx_requested); DEBUGFS_FWSTATS_ADD(dma, rx_errors); DEBUGFS_FWSTATS_ADD(dma, tx_requested); DEBUGFS_FWSTATS_ADD(dma, tx_errors); DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt); DEBUGFS_FWSTATS_ADD(isr, fiqs); DEBUGFS_FWSTATS_ADD(isr, rx_headers); DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow); DEBUGFS_FWSTATS_ADD(isr, rx_rdys); DEBUGFS_FWSTATS_ADD(isr, irqs); DEBUGFS_FWSTATS_ADD(isr, tx_procs); DEBUGFS_FWSTATS_ADD(isr, decrypt_done); DEBUGFS_FWSTATS_ADD(isr, dma0_done); DEBUGFS_FWSTATS_ADD(isr, dma1_done); DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete); DEBUGFS_FWSTATS_ADD(isr, commands); DEBUGFS_FWSTATS_ADD(isr, rx_procs); DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes); DEBUGFS_FWSTATS_ADD(isr, host_acknowledges); DEBUGFS_FWSTATS_ADD(isr, pci_pm); DEBUGFS_FWSTATS_ADD(isr, wakeups); DEBUGFS_FWSTATS_ADD(isr, low_rssi); DEBUGFS_FWSTATS_ADD(wep, addr_key_count); DEBUGFS_FWSTATS_ADD(wep, default_key_count); /* skipping wep.reserved */ DEBUGFS_FWSTATS_ADD(wep, key_not_found); DEBUGFS_FWSTATS_ADD(wep, decrypt_fail); DEBUGFS_FWSTATS_ADD(wep, packets); DEBUGFS_FWSTATS_ADD(wep, interrupt); DEBUGFS_FWSTATS_ADD(pwr, ps_enter); DEBUGFS_FWSTATS_ADD(pwr, elp_enter); DEBUGFS_FWSTATS_ADD(pwr, missing_bcns); DEBUGFS_FWSTATS_ADD(pwr, wake_on_host); DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp); DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps); DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps); DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons); DEBUGFS_FWSTATS_ADD(pwr, power_save_off); DEBUGFS_FWSTATS_ADD(pwr, enable_ps); DEBUGFS_FWSTATS_ADD(pwr, disable_ps); DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps); /* skipping cont_miss_bcns_spread for now */ DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons); DEBUGFS_FWSTATS_ADD(mic, rx_pkts); DEBUGFS_FWSTATS_ADD(mic, calc_failure); DEBUGFS_FWSTATS_ADD(aes, encrypt_fail); DEBUGFS_FWSTATS_ADD(aes, decrypt_fail); DEBUGFS_FWSTATS_ADD(aes, encrypt_packets); DEBUGFS_FWSTATS_ADD(aes, decrypt_packets); DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt); DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt); DEBUGFS_FWSTATS_ADD(event, heart_beat); DEBUGFS_FWSTATS_ADD(event, calibration); DEBUGFS_FWSTATS_ADD(event, rx_mismatch); DEBUGFS_FWSTATS_ADD(event, rx_mem_empty); DEBUGFS_FWSTATS_ADD(event, rx_pool); DEBUGFS_FWSTATS_ADD(event, oom_late); DEBUGFS_FWSTATS_ADD(event, phy_transmit_error); DEBUGFS_FWSTATS_ADD(event, tx_stuck); DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts); DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts); DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime); DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn); DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn); DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization); DEBUGFS_FWSTATS_ADD(ps, upsd_utilization); DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop); DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data); DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data); DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data); DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data); DEBUGFS_ADD(tx_queue_len, rootdir); DEBUGFS_ADD(retry_count, rootdir); DEBUGFS_ADD(excessive_retries, rootdir); DEBUGFS_ADD(gpio_power, rootdir); DEBUGFS_ADD(start_recovery, rootdir); DEBUGFS_ADD(driver_state, rootdir); DEBUGFS_ADD(vifs_state, rootdir); DEBUGFS_ADD(dtim_interval, rootdir); DEBUGFS_ADD(suspend_dtim_interval, rootdir); DEBUGFS_ADD(beacon_interval, rootdir); DEBUGFS_ADD(beacon_filtering, rootdir); DEBUGFS_ADD(dynamic_ps_timeout, rootdir); DEBUGFS_ADD(forced_ps, rootdir); DEBUGFS_ADD(split_scan_timeout, rootdir); streaming = debugfs_create_dir("rx_streaming", rootdir); if (!streaming || IS_ERR(streaming)) goto err; DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming); DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming); return 0; err: if (IS_ERR(entry)) ret = PTR_ERR(entry); else ret = -ENOMEM; return ret; } void wl1271_debugfs_reset(struct wl1271 *wl) { if (!wl->stats.fw_stats) return; memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats)); wl->stats.retry_count = 0; wl->stats.excessive_retries = 0; } int wl1271_debugfs_init(struct wl1271 *wl) { int ret; struct dentry *rootdir; rootdir = debugfs_create_dir(KBUILD_MODNAME, wl->hw->wiphy->debugfsdir); if (IS_ERR(rootdir)) { ret = PTR_ERR(rootdir); goto err; } wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats), GFP_KERNEL); if (!wl->stats.fw_stats) { ret = -ENOMEM; goto err_fw; } wl->stats.fw_stats_update = jiffies; ret = wl1271_debugfs_add_files(wl, rootdir); if (ret < 0) goto err_file; return 0; err_file: kfree(wl->stats.fw_stats); wl->stats.fw_stats = NULL; err_fw: debugfs_remove_recursive(rootdir); err: return ret; } void wl1271_debugfs_exit(struct wl1271 *wl) { kfree(wl->stats.fw_stats); wl->stats.fw_stats = NULL; }
gpl-2.0
pacificIT/linux-imx6-1
net/ipv6/protocol.c
7870
1598
/* * INET An implementation of the TCP/IP protocol suite for the LINUX * operating system. INET is implemented using the BSD Socket * interface as the means of communication with the user level. * * PF_INET6 protocol dispatch tables. * * Authors: Pedro Roque <roque@di.fc.ul.pt> * * 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. */ /* * Changes: * * Vince Laviano (vince@cs.stanford.edu) 16 May 2001 * - Removed unused variable 'inet6_protocol_base' * - Modified inet6_del_protocol() to correctly maintain copy bit. */ #include <linux/module.h> #include <linux/netdevice.h> #include <linux/spinlock.h> #include <net/protocol.h> const struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS] __read_mostly; int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char protocol) { int hash = protocol & (MAX_INET_PROTOS - 1); return !cmpxchg((const struct inet6_protocol **)&inet6_protos[hash], NULL, prot) ? 0 : -1; } EXPORT_SYMBOL(inet6_add_protocol); /* * Remove a protocol from the hash tables. */ int inet6_del_protocol(const struct inet6_protocol *prot, unsigned char protocol) { int ret, hash = protocol & (MAX_INET_PROTOS - 1); ret = (cmpxchg((const struct inet6_protocol **)&inet6_protos[hash], prot, NULL) == prot) ? 0 : -1; synchronize_net(); return ret; } EXPORT_SYMBOL(inet6_del_protocol);
gpl-2.0
CyanogenMod/android_kernel_lge_dory
drivers/video/via/via_aux_sii164.c
9662
1505
/* * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.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, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; 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. */ /* * driver for Silicon Image SiI 164 PanelLink Transmitter */ #include <linux/slab.h> #include "via_aux.h" static const char *name = "SiI 164 PanelLink Transmitter"; static void probe(struct via_aux_bus *bus, u8 addr) { struct via_aux_drv drv = { .bus = bus, .addr = addr, .name = name}; /* check vendor id and device id */ const u8 id[] = {0x01, 0x00, 0x06, 0x00}, len = ARRAY_SIZE(id); u8 tmp[len]; if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len)) return; printk(KERN_INFO "viafb: Found %s at address 0x%x\n", name, addr); via_aux_add(&drv); } void via_aux_sii164_probe(struct via_aux_bus *bus) { u8 i; for (i = 0x38; i <= 0x3F; i++) probe(bus, i); }
gpl-2.0
changbindu/linux-ok6410
drivers/video/fbdev/via/via_aux_vt1632.c
9662
1481
/* * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.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, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; 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. */ /* * driver for VIA VT1632 DVI Transmitter */ #include <linux/slab.h> #include "via_aux.h" static const char *name = "VT1632 DVI Transmitter"; static void probe(struct via_aux_bus *bus, u8 addr) { struct via_aux_drv drv = { .bus = bus, .addr = addr, .name = name}; /* check vendor id and device id */ const u8 id[] = {0x06, 0x11, 0x92, 0x31}, len = ARRAY_SIZE(id); u8 tmp[len]; if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len)) return; printk(KERN_INFO "viafb: Found %s at address 0x%x\n", name, addr); via_aux_add(&drv); } void via_aux_vt1632_probe(struct via_aux_bus *bus) { u8 i; for (i = 0x08; i <= 0x0F; i++) probe(bus, i); }
gpl-2.0
DeltaDroidTeam/android_kernel_lenovo_msm8x25q
drivers/video/via/via_aux_vt1632.c
9662
1481
/* * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.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, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; 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. */ /* * driver for VIA VT1632 DVI Transmitter */ #include <linux/slab.h> #include "via_aux.h" static const char *name = "VT1632 DVI Transmitter"; static void probe(struct via_aux_bus *bus, u8 addr) { struct via_aux_drv drv = { .bus = bus, .addr = addr, .name = name}; /* check vendor id and device id */ const u8 id[] = {0x06, 0x11, 0x92, 0x31}, len = ARRAY_SIZE(id); u8 tmp[len]; if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len)) return; printk(KERN_INFO "viafb: Found %s at address 0x%x\n", name, addr); via_aux_add(&drv); } void via_aux_vt1632_probe(struct via_aux_bus *bus) { u8 i; for (i = 0x08; i <= 0x0F; i++) probe(bus, i); }
gpl-2.0
alexax66/CM12.1_kernel_serranodsxx
drivers/input/keyboard/newtonkbd.c
9918
4968
/* * Copyright (c) 2000 Justin Cormack */ /* * Newton keyboard driver for Linux */ /* * 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 * * Should you need to contact me, the author, you can do so either by * e-mail - mail your message to <j.cormack@doc.ic.ac.uk>, or by paper mail: * Justin Cormack, 68 Dartmouth Park Road, London NW5 1SN, UK. */ #include <linux/slab.h> #include <linux/module.h> #include <linux/input.h> #include <linux/init.h> #include <linux/serio.h> #define DRIVER_DESC "Newton keyboard driver" MODULE_AUTHOR("Justin Cormack <j.cormack@doc.ic.ac.uk>"); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); #define NKBD_KEY 0x7f #define NKBD_PRESS 0x80 static unsigned char nkbd_keycode[128] = { KEY_A, KEY_S, KEY_D, KEY_F, KEY_H, KEY_G, KEY_Z, KEY_X, KEY_C, KEY_V, 0, KEY_B, KEY_Q, KEY_W, KEY_E, KEY_R, KEY_Y, KEY_T, KEY_1, KEY_2, KEY_3, KEY_4, KEY_6, KEY_5, KEY_EQUAL, KEY_9, KEY_7, KEY_MINUS, KEY_8, KEY_0, KEY_RIGHTBRACE, KEY_O, KEY_U, KEY_LEFTBRACE, KEY_I, KEY_P, KEY_ENTER, KEY_L, KEY_J, KEY_APOSTROPHE, KEY_K, KEY_SEMICOLON, KEY_BACKSLASH, KEY_COMMA, KEY_SLASH, KEY_N, KEY_M, KEY_DOT, KEY_TAB, KEY_SPACE, KEY_GRAVE, KEY_DELETE, 0, 0, 0, KEY_LEFTMETA, KEY_LEFTSHIFT, KEY_CAPSLOCK, KEY_LEFTALT, KEY_LEFTCTRL, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP, 0 }; struct nkbd { unsigned char keycode[128]; struct input_dev *dev; struct serio *serio; char phys[32]; }; static irqreturn_t nkbd_interrupt(struct serio *serio, unsigned char data, unsigned int flags) { struct nkbd *nkbd = serio_get_drvdata(serio); /* invalid scan codes are probably the init sequence, so we ignore them */ if (nkbd->keycode[data & NKBD_KEY]) { input_report_key(nkbd->dev, nkbd->keycode[data & NKBD_KEY], data & NKBD_PRESS); input_sync(nkbd->dev); } else if (data == 0xe7) /* end of init sequence */ printk(KERN_INFO "input: %s on %s\n", nkbd->dev->name, serio->phys); return IRQ_HANDLED; } static int nkbd_connect(struct serio *serio, struct serio_driver *drv) { struct nkbd *nkbd; struct input_dev *input_dev; int err = -ENOMEM; int i; nkbd = kzalloc(sizeof(struct nkbd), GFP_KERNEL); input_dev = input_allocate_device(); if (!nkbd || !input_dev) goto fail1; nkbd->serio = serio; nkbd->dev = input_dev; snprintf(nkbd->phys, sizeof(nkbd->phys), "%s/input0", serio->phys); memcpy(nkbd->keycode, nkbd_keycode, sizeof(nkbd->keycode)); input_dev->name = "Newton Keyboard"; input_dev->phys = nkbd->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_NEWTON; input_dev->id.product = 0x0001; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); input_dev->keycode = nkbd->keycode; input_dev->keycodesize = sizeof(unsigned char); input_dev->keycodemax = ARRAY_SIZE(nkbd_keycode); for (i = 0; i < 128; i++) set_bit(nkbd->keycode[i], input_dev->keybit); clear_bit(0, input_dev->keybit); serio_set_drvdata(serio, nkbd); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(nkbd->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(nkbd); return err; } static void nkbd_disconnect(struct serio *serio) { struct nkbd *nkbd = serio_get_drvdata(serio); serio_close(serio); serio_set_drvdata(serio, NULL); input_unregister_device(nkbd->dev); kfree(nkbd); } static struct serio_device_id nkbd_serio_ids[] = { { .type = SERIO_RS232, .proto = SERIO_NEWTON, .id = SERIO_ANY, .extra = SERIO_ANY, }, { 0 } }; MODULE_DEVICE_TABLE(serio, nkbd_serio_ids); static struct serio_driver nkbd_drv = { .driver = { .name = "newtonkbd", }, .description = DRIVER_DESC, .id_table = nkbd_serio_ids, .interrupt = nkbd_interrupt, .connect = nkbd_connect, .disconnect = nkbd_disconnect, }; static int __init nkbd_init(void) { return serio_register_driver(&nkbd_drv); } static void __exit nkbd_exit(void) { serio_unregister_driver(&nkbd_drv); } module_init(nkbd_init); module_exit(nkbd_exit);
gpl-2.0
friedrich420/HTC-ONE-M7-AEL-Kernel-5.0.2
sound/pci/echoaudio/indigoio_dsp.c
12478
3459
/**************************************************************************** Copyright Echo Digital Audio Corporation (c) 1998 - 2004 All rights reserved www.echoaudio.com This file is part of Echo Digital Audio's generic driver library. Echo Digital Audio's generic driver 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. 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. ************************************************************************* Translation from C++ and adaptation for use in ALSA-Driver were made by Giuliano Pochini <pochini@shiny.it> ****************************************************************************/ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe, int gain); static int update_vmixer_level(struct echoaudio *chip); static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id) { int err; DE_INIT(("init_hw() - Indigo IO\n")); if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_IO)) return -ENODEV; if ((err = init_dsp_comm_page(chip))) { DE_INIT(("init_hw - could not initialize DSP comm page\n")); return err; } chip->device_id = device_id; chip->subdevice_id = subdevice_id; chip->bad_board = TRUE; chip->dsp_code_to_load = FW_INDIGO_IO_DSP; /* Since this card has no ASIC, mark it as loaded so everything works OK */ chip->asic_loaded = TRUE; chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL; if ((err = load_firmware(chip)) < 0) return err; chip->bad_board = FALSE; DE_INIT(("init_hw done\n")); return err; } static int set_mixer_defaults(struct echoaudio *chip) { return init_line_levels(chip); } static u32 detect_input_clocks(const struct echoaudio *chip) { return ECHO_CLOCK_BIT_INTERNAL; } /* The IndigoIO has no ASIC. Just do nothing */ static int load_asic(struct echoaudio *chip) { return 0; } static int set_sample_rate(struct echoaudio *chip, u32 rate) { if (wait_handshake(chip)) return -EIO; chip->sample_rate = rate; chip->comm_page->sample_rate = cpu_to_le32(rate); clear_handshake(chip); return send_vector(chip, DSP_VC_UPDATE_CLOCKS); } /* This function routes the sound from a virtual channel to a real output */ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe, int gain) { int index; if (snd_BUG_ON(pipe >= num_pipes_out(chip) || output >= num_busses_out(chip))) return -EINVAL; if (wait_handshake(chip)) return -EIO; chip->vmixer_gain[output][pipe] = gain; index = output * num_pipes_out(chip) + pipe; chip->comm_page->vmixer[index] = gain; DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain)); return 0; } /* Tell the DSP to read and update virtual mixer levels in comm page. */ static int update_vmixer_level(struct echoaudio *chip) { if (wait_handshake(chip)) return -EIO; clear_handshake(chip); return send_vector(chip, DSP_VC_SET_VMIXER_GAIN); }
gpl-2.0
mer-hybris/android_kernel_motorola_titan-OLD
drivers/usb/class/cdc-acm.c
447
49246
/* * cdc-acm.c * * Copyright (c) 1999 Armin Fuerst <fuerst@in.tum.de> * Copyright (c) 1999 Pavel Machek <pavel@ucw.cz> * Copyright (c) 1999 Johannes Erdfelt <johannes@erdfelt.com> * Copyright (c) 2000 Vojtech Pavlik <vojtech@suse.cz> * Copyright (c) 2004 Oliver Neukum <oliver@neukum.name> * Copyright (c) 2005 David Kubicek <dave@awk.cz> * Copyright (c) 2011 Johan Hovold <jhovold@gmail.com> * * USB Abstract Control Model driver for USB modems and ISDN adapters * * Sponsored by SuSE * * 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 */ #undef DEBUG #undef VERBOSE_DEBUG #include <linux/kernel.h> #include <linux/errno.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/tty.h> #include <linux/serial.h> #include <linux/tty_driver.h> #include <linux/tty_flip.h> #include <linux/serial.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/uaccess.h> #include <linux/usb.h> #include <linux/usb/cdc.h> #include <asm/byteorder.h> #include <asm/unaligned.h> #include <linux/list.h> #include "cdc-acm.h" #define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek, Johan Hovold" #define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters" static struct usb_driver acm_driver; static struct tty_driver *acm_tty_driver; static struct acm *acm_table[ACM_TTY_MINORS]; static DEFINE_MUTEX(acm_table_lock); /* * acm_table accessors */ /* * Look up an ACM structure by index. If found and not disconnected, increment * its refcount and return it with its mutex held. */ static struct acm *acm_get_by_index(unsigned index) { struct acm *acm; mutex_lock(&acm_table_lock); acm = acm_table[index]; if (acm) { mutex_lock(&acm->mutex); if (acm->disconnected) { mutex_unlock(&acm->mutex); acm = NULL; } else { tty_port_get(&acm->port); mutex_unlock(&acm->mutex); } } mutex_unlock(&acm_table_lock); return acm; } /* * Try to find an available minor number and if found, associate it with 'acm'. */ static int acm_alloc_minor(struct acm *acm) { int minor; mutex_lock(&acm_table_lock); for (minor = 0; minor < ACM_TTY_MINORS; minor++) { if (!acm_table[minor]) { acm_table[minor] = acm; break; } } mutex_unlock(&acm_table_lock); return minor; } /* Release the minor number associated with 'acm'. */ static void acm_release_minor(struct acm *acm) { mutex_lock(&acm_table_lock); acm_table[acm->minor] = NULL; mutex_unlock(&acm_table_lock); } /* * Functions for ACM control messages. */ static int acm_ctrl_msg(struct acm *acm, int request, int value, void *buf, int len) { int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), request, USB_RT_ACM, value, acm->control->altsetting[0].desc.bInterfaceNumber, buf, len, 5000); dev_dbg(&acm->control->dev, "%s - rq 0x%02x, val %#x, len %#x, result %d\n", __func__, request, value, len, retval); return retval < 0 ? retval : 0; } /* devices aren't required to support these requests. * the cdc acm descriptor tells whether they do... */ #define acm_set_control(acm, control) \ acm_ctrl_msg(acm, USB_CDC_REQ_SET_CONTROL_LINE_STATE, control, NULL, 0) #define acm_set_line(acm, line) \ acm_ctrl_msg(acm, USB_CDC_REQ_SET_LINE_CODING, 0, line, sizeof *(line)) #define acm_send_break(acm, ms) \ acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0) /* * Write buffer management. * All of these assume proper locks taken by the caller. */ static int acm_wb_alloc(struct acm *acm) { int i, wbn; struct acm_wb *wb; wbn = 0; i = 0; for (;;) { wb = &acm->wb[wbn]; if (!wb->use) { wb->use = 1; return wbn; } wbn = (wbn + 1) % ACM_NW; if (++i >= ACM_NW) return -1; } } static int acm_wb_is_avail(struct acm *acm) { int i, n; unsigned long flags; n = ACM_NW; spin_lock_irqsave(&acm->write_lock, flags); for (i = 0; i < ACM_NW; i++) n -= acm->wb[i].use; spin_unlock_irqrestore(&acm->write_lock, flags); return n; } /* * Finish write. Caller must hold acm->write_lock */ static void acm_write_done(struct acm *acm, struct acm_wb *wb) { wb->use = 0; acm->transmitting--; usb_autopm_put_interface_async(acm->control); } /* * Poke write. * * the caller is responsible for locking */ static int acm_start_wb(struct acm *acm, struct acm_wb *wb) { int rc; acm->transmitting++; wb->urb->transfer_buffer = wb->buf; wb->urb->transfer_dma = wb->dmah; wb->urb->transfer_buffer_length = wb->len; wb->urb->dev = acm->dev; rc = usb_submit_urb(wb->urb, GFP_ATOMIC); if (rc < 0) { dev_err(&acm->data->dev, "%s - usb_submit_urb(write bulk) failed: %d\n", __func__, rc); acm_write_done(acm, wb); } return rc; } static int acm_write_start(struct acm *acm, int wbn) { unsigned long flags; struct acm_wb *wb = &acm->wb[wbn]; int rc; spin_lock_irqsave(&acm->write_lock, flags); if (!acm->dev) { wb->use = 0; spin_unlock_irqrestore(&acm->write_lock, flags); return -ENODEV; } dev_vdbg(&acm->data->dev, "%s - susp_count %d\n", __func__, acm->susp_count); usb_autopm_get_interface_async(acm->control); if (acm->susp_count) { if (!acm->delayed_wb) acm->delayed_wb = wb; else usb_autopm_put_interface_async(acm->control); spin_unlock_irqrestore(&acm->write_lock, flags); return 0; /* A white lie */ } usb_mark_last_busy(acm->dev); rc = acm_start_wb(acm, wb); spin_unlock_irqrestore(&acm->write_lock, flags); return rc; } /* * attributes exported through sysfs */ static ssize_t show_caps (struct device *dev, struct device_attribute *attr, char *buf) { struct usb_interface *intf = to_usb_interface(dev); struct acm *acm = usb_get_intfdata(intf); return sprintf(buf, "%d", acm->ctrl_caps); } static DEVICE_ATTR(bmCapabilities, S_IRUGO, show_caps, NULL); static ssize_t show_country_codes (struct device *dev, struct device_attribute *attr, char *buf) { struct usb_interface *intf = to_usb_interface(dev); struct acm *acm = usb_get_intfdata(intf); memcpy(buf, acm->country_codes, acm->country_code_size); return acm->country_code_size; } static DEVICE_ATTR(wCountryCodes, S_IRUGO, show_country_codes, NULL); static ssize_t show_country_rel_date (struct device *dev, struct device_attribute *attr, char *buf) { struct usb_interface *intf = to_usb_interface(dev); struct acm *acm = usb_get_intfdata(intf); return sprintf(buf, "%d", acm->country_rel_date); } static DEVICE_ATTR(iCountryCodeRelDate, S_IRUGO, show_country_rel_date, NULL); /* * Interrupt handlers for various ACM device responses */ /* control interface reports status changes with "interrupt" transfers */ static void acm_ctrl_irq(struct urb *urb) { struct acm *acm = urb->context; struct usb_cdc_notification *dr = urb->transfer_buffer; struct tty_struct *tty; unsigned char *data; int newctrl; int retval; int status = urb->status; switch (status) { case 0: /* success */ break; case -ECONNRESET: case -ENOENT: case -ESHUTDOWN: /* this urb is terminated, clean up */ dev_dbg(&acm->control->dev, "%s - urb shutting down with status: %d\n", __func__, status); return; default: dev_dbg(&acm->control->dev, "%s - nonzero urb status received: %d\n", __func__, status); goto exit; } usb_mark_last_busy(acm->dev); data = (unsigned char *)(dr + 1); switch (dr->bNotificationType) { case USB_CDC_NOTIFY_NETWORK_CONNECTION: dev_dbg(&acm->control->dev, "%s - network connection: %d\n", __func__, dr->wValue); break; case USB_CDC_NOTIFY_SERIAL_STATE: tty = tty_port_tty_get(&acm->port); newctrl = get_unaligned_le16(data); if (tty) { if (!acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { dev_dbg(&acm->control->dev, "%s - calling hangup\n", __func__); tty_hangup(tty); } tty_kref_put(tty); } acm->ctrlin = newctrl; dev_dbg(&acm->control->dev, "%s - input control lines: dcd%c dsr%c break%c " "ring%c framing%c parity%c overrun%c\n", __func__, acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', acm->ctrlin & ACM_CTRL_DSR ? '+' : '-', acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', acm->ctrlin & ACM_CTRL_RI ? '+' : '-', acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-', acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-'); break; default: dev_dbg(&acm->control->dev, "%s - unknown notification %d received: index %d " "len %d data0 %d data1 %d\n", __func__, dr->bNotificationType, dr->wIndex, dr->wLength, data[0], data[1]); break; } exit: retval = usb_submit_urb(urb, GFP_ATOMIC); if (retval) dev_err(&acm->control->dev, "%s - usb_submit_urb failed: %d\n", __func__, retval); } static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags) { int res; if (!test_and_clear_bit(index, &acm->read_urbs_free)) return 0; dev_vdbg(&acm->data->dev, "%s - urb %d\n", __func__, index); res = usb_submit_urb(acm->read_urbs[index], mem_flags); if (res) { if (res != -EPERM) { dev_err(&acm->data->dev, "%s - usb_submit_urb failed: %d\n", __func__, res); } set_bit(index, &acm->read_urbs_free); return res; } return 0; } static int acm_submit_read_urbs(struct acm *acm, gfp_t mem_flags) { int res; int i; for (i = 0; i < acm->rx_buflimit; ++i) { res = acm_submit_read_urb(acm, i, mem_flags); if (res) return res; } return 0; } static void acm_process_read_urb(struct acm *acm, struct urb *urb) { struct tty_struct *tty; if (!urb->actual_length) return; tty = tty_port_tty_get(&acm->port); if (!tty) return; tty_insert_flip_string(tty, urb->transfer_buffer, urb->actual_length); tty_flip_buffer_push(tty); tty_kref_put(tty); } static void acm_read_bulk_callback(struct urb *urb) { struct acm_rb *rb = urb->context; struct acm *acm = rb->instance; unsigned long flags; dev_vdbg(&acm->data->dev, "%s - urb %d, len %d\n", __func__, rb->index, urb->actual_length); set_bit(rb->index, &acm->read_urbs_free); if (!acm->dev) { dev_dbg(&acm->data->dev, "%s - disconnected\n", __func__); return; } usb_mark_last_busy(acm->dev); if (urb->status) { dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n", __func__, urb->status); return; } acm_process_read_urb(acm, urb); /* throttle device if requested by tty */ spin_lock_irqsave(&acm->read_lock, flags); acm->throttled = acm->throttle_req; if (!acm->throttled && !acm->susp_count) { spin_unlock_irqrestore(&acm->read_lock, flags); acm_submit_read_urb(acm, rb->index, GFP_ATOMIC); } else { spin_unlock_irqrestore(&acm->read_lock, flags); } } /* data interface wrote those outgoing bytes */ static void acm_write_bulk(struct urb *urb) { struct acm_wb *wb = urb->context; struct acm *acm = wb->instance; unsigned long flags; if (urb->status || (urb->actual_length != urb->transfer_buffer_length)) dev_vdbg(&acm->data->dev, "%s - len %d/%d, status %d\n", __func__, urb->actual_length, urb->transfer_buffer_length, urb->status); spin_lock_irqsave(&acm->write_lock, flags); acm_write_done(acm, wb); spin_unlock_irqrestore(&acm->write_lock, flags); schedule_work(&acm->work); } static void acm_softint(struct work_struct *work) { struct acm *acm = container_of(work, struct acm, work); struct tty_struct *tty; dev_vdbg(&acm->data->dev, "%s\n", __func__); tty = tty_port_tty_get(&acm->port); if (!tty) return; tty_wakeup(tty); tty_kref_put(tty); } /* * TTY handlers */ static int acm_tty_install(struct tty_driver *driver, struct tty_struct *tty) { struct acm *acm; int retval; dev_dbg(tty->dev, "%s\n", __func__); acm = acm_get_by_index(tty->index); if (!acm) return -ENODEV; retval = tty_standard_install(driver, tty); if (retval) goto error_init_termios; tty->driver_data = acm; return 0; error_init_termios: tty_port_put(&acm->port); return retval; } static int acm_tty_open(struct tty_struct *tty, struct file *filp) { struct acm *acm = tty->driver_data; dev_dbg(tty->dev, "%s\n", __func__); return tty_port_open(&acm->port, tty, filp); } static int acm_port_activate(struct tty_port *port, struct tty_struct *tty) { struct acm *acm = container_of(port, struct acm, port); int retval = -ENODEV; dev_dbg(&acm->control->dev, "%s\n", __func__); mutex_lock(&acm->mutex); if (acm->disconnected) goto disconnected; retval = usb_autopm_get_interface(acm->control); if (retval) goto error_get_interface; /* * FIXME: Why do we need this? Allocating 64K of physically contiguous * memory is really nasty... */ set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); acm->control->needs_remote_wakeup = 1; acm->ctrlurb->dev = acm->dev; if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { dev_err(&acm->control->dev, "%s - usb_submit_urb(ctrl irq) failed\n", __func__); goto error_submit_urb; } acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS; if (acm_set_control(acm, acm->ctrlout) < 0 && (acm->ctrl_caps & USB_CDC_CAP_LINE)) goto error_set_control; usb_autopm_put_interface(acm->control); /* * Unthrottle device in case the TTY was closed while throttled. */ spin_lock_irq(&acm->read_lock); acm->throttled = 0; acm->throttle_req = 0; spin_unlock_irq(&acm->read_lock); if (acm_submit_read_urbs(acm, GFP_KERNEL)) goto error_submit_read_urbs; mutex_unlock(&acm->mutex); return 0; error_submit_read_urbs: acm->ctrlout = 0; acm_set_control(acm, acm->ctrlout); error_set_control: usb_kill_urb(acm->ctrlurb); error_submit_urb: usb_autopm_put_interface(acm->control); error_get_interface: disconnected: mutex_unlock(&acm->mutex); return retval; } static void acm_port_destruct(struct tty_port *port) { struct acm *acm = container_of(port, struct acm, port); dev_dbg(&acm->control->dev, "%s\n", __func__); acm_release_minor(acm); usb_put_intf(acm->control); kfree(acm->country_codes); kfree(acm); } static void acm_port_shutdown(struct tty_port *port) { struct acm *acm = container_of(port, struct acm, port); int i; dev_dbg(&acm->control->dev, "%s\n", __func__); mutex_lock(&acm->mutex); if (!acm->disconnected) { usb_autopm_get_interface(acm->control); acm_set_control(acm, acm->ctrlout = 0); usb_kill_urb(acm->ctrlurb); for (i = 0; i < ACM_NW; i++) usb_kill_urb(acm->wb[i].urb); for (i = 0; i < acm->rx_buflimit; i++) usb_kill_urb(acm->read_urbs[i]); acm->control->needs_remote_wakeup = 0; usb_autopm_put_interface(acm->control); } mutex_unlock(&acm->mutex); } static void acm_tty_cleanup(struct tty_struct *tty) { struct acm *acm = tty->driver_data; dev_dbg(&acm->control->dev, "%s\n", __func__); tty_port_put(&acm->port); } static void acm_tty_hangup(struct tty_struct *tty) { struct acm *acm = tty->driver_data; dev_dbg(&acm->control->dev, "%s\n", __func__); tty_port_hangup(&acm->port); } static void acm_tty_close(struct tty_struct *tty, struct file *filp) { struct acm *acm = tty->driver_data; dev_dbg(&acm->control->dev, "%s\n", __func__); tty_port_close(&acm->port, tty, filp); } static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct acm *acm = tty->driver_data; int stat; unsigned long flags; int wbn; struct acm_wb *wb; if (!count) return 0; dev_vdbg(&acm->data->dev, "%s - count %d\n", __func__, count); spin_lock_irqsave(&acm->write_lock, flags); wbn = acm_wb_alloc(acm); if (wbn < 0) { spin_unlock_irqrestore(&acm->write_lock, flags); return 0; } wb = &acm->wb[wbn]; count = (count > acm->writesize) ? acm->writesize : count; dev_vdbg(&acm->data->dev, "%s - write %d\n", __func__, count); memcpy(wb->buf, buf, count); wb->len = count; spin_unlock_irqrestore(&acm->write_lock, flags); stat = acm_write_start(acm, wbn); if (stat < 0) return stat; return count; } static int acm_tty_write_room(struct tty_struct *tty) { struct acm *acm = tty->driver_data; /* * Do not let the line discipline to know that we have a reserve, * or it might get too enthusiastic. */ return acm_wb_is_avail(acm) ? acm->writesize : 0; } static int acm_tty_chars_in_buffer(struct tty_struct *tty) { struct acm *acm = tty->driver_data; /* * if the device was unplugged then any remaining characters fell out * of the connector ;) */ if (acm->disconnected) return 0; /* * This is inaccurate (overcounts), but it works. */ return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize; } static void acm_tty_throttle(struct tty_struct *tty) { struct acm *acm = tty->driver_data; spin_lock_irq(&acm->read_lock); acm->throttle_req = 1; spin_unlock_irq(&acm->read_lock); } static void acm_tty_unthrottle(struct tty_struct *tty) { struct acm *acm = tty->driver_data; unsigned int was_throttled; spin_lock_irq(&acm->read_lock); was_throttled = acm->throttled; acm->throttled = 0; acm->throttle_req = 0; spin_unlock_irq(&acm->read_lock); if (was_throttled) acm_submit_read_urbs(acm, GFP_KERNEL); } static int acm_tty_break_ctl(struct tty_struct *tty, int state) { struct acm *acm = tty->driver_data; int retval; retval = acm_send_break(acm, state ? 0xffff : 0); if (retval < 0) dev_dbg(&acm->control->dev, "%s - send break failed\n", __func__); return retval; } static int acm_tty_tiocmget(struct tty_struct *tty) { struct acm *acm = tty->driver_data; return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) | (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) | (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) | (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) | (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) | TIOCM_CTS; } static int acm_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) { struct acm *acm = tty->driver_data; unsigned int newctrl; newctrl = acm->ctrlout; set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); newctrl = (newctrl & ~clear) | set; if (acm->ctrlout == newctrl) return 0; return acm_set_control(acm, acm->ctrlout = newctrl); } static int get_serial_info(struct acm *acm, struct serial_struct __user *info) { struct serial_struct tmp; if (!info) return -EINVAL; memset(&tmp, 0, sizeof(tmp)); tmp.flags = ASYNC_LOW_LATENCY; tmp.xmit_fifo_size = acm->writesize; tmp.baud_base = le32_to_cpu(acm->line.dwDTERate); tmp.close_delay = acm->port.close_delay / 10; tmp.closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? ASYNC_CLOSING_WAIT_NONE : acm->port.closing_wait / 10; if (copy_to_user(info, &tmp, sizeof(tmp))) return -EFAULT; else return 0; } static int set_serial_info(struct acm *acm, struct serial_struct __user *newinfo) { struct serial_struct new_serial; unsigned int closing_wait, close_delay; int retval = 0; if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) return -EFAULT; close_delay = new_serial.close_delay * 10; closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ? ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10; mutex_lock(&acm->port.mutex); if (!capable(CAP_SYS_ADMIN)) { if ((close_delay != acm->port.close_delay) || (closing_wait != acm->port.closing_wait)) retval = -EPERM; else retval = -EOPNOTSUPP; } else { acm->port.close_delay = close_delay; acm->port.closing_wait = closing_wait; } mutex_unlock(&acm->port.mutex); return retval; } static int acm_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) { struct acm *acm = tty->driver_data; int rv = -ENOIOCTLCMD; switch (cmd) { case TIOCGSERIAL: /* gets serial port data */ rv = get_serial_info(acm, (struct serial_struct __user *) arg); break; case TIOCSSERIAL: rv = set_serial_info(acm, (struct serial_struct __user *) arg); break; } return rv; } static const __u32 acm_tty_speed[] = { 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000 }; static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old) { struct acm *acm = tty->driver_data; struct ktermios *termios = tty->termios; struct usb_cdc_line_coding newline; int newctrl = acm->ctrlout; newline.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty)); newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; newline.bParityType = termios->c_cflag & PARENB ? (termios->c_cflag & PARODD ? 1 : 2) + (termios->c_cflag & CMSPAR ? 2 : 0) : 0; switch (termios->c_cflag & CSIZE) { case CS5: newline.bDataBits = 5; break; case CS6: newline.bDataBits = 6; break; case CS7: newline.bDataBits = 7; break; case CS8: default: newline.bDataBits = 8; break; } /* FIXME: Needs to clear unsupported bits in the termios */ acm->clocal = ((termios->c_cflag & CLOCAL) != 0); if (!newline.dwDTERate) { newline.dwDTERate = acm->line.dwDTERate; newctrl &= ~ACM_CTRL_DTR; } else newctrl |= ACM_CTRL_DTR; if (newctrl != acm->ctrlout) acm_set_control(acm, acm->ctrlout = newctrl); if (memcmp(&acm->line, &newline, sizeof newline)) { memcpy(&acm->line, &newline, sizeof newline); dev_dbg(&acm->control->dev, "%s - set line: %d %d %d %d\n", __func__, le32_to_cpu(newline.dwDTERate), newline.bCharFormat, newline.bParityType, newline.bDataBits); acm_set_line(acm, &acm->line); } } static const struct tty_port_operations acm_port_ops = { .shutdown = acm_port_shutdown, .activate = acm_port_activate, .destruct = acm_port_destruct, }; /* * USB probe and disconnect routines. */ /* Little helpers: write/read buffers free */ static void acm_write_buffers_free(struct acm *acm) { int i; struct acm_wb *wb; struct usb_device *usb_dev = interface_to_usbdev(acm->control); for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) usb_free_coherent(usb_dev, acm->writesize, wb->buf, wb->dmah); } static void acm_read_buffers_free(struct acm *acm) { struct usb_device *usb_dev = interface_to_usbdev(acm->control); int i; for (i = 0; i < acm->rx_buflimit; i++) usb_free_coherent(usb_dev, acm->readsize, acm->read_buffers[i].base, acm->read_buffers[i].dma); } /* Little helper: write buffers allocate */ static int acm_write_buffers_alloc(struct acm *acm) { int i; struct acm_wb *wb; for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { wb->buf = usb_alloc_coherent(acm->dev, acm->writesize, GFP_KERNEL, &wb->dmah); if (!wb->buf) { while (i != 0) { --i; --wb; usb_free_coherent(acm->dev, acm->writesize, wb->buf, wb->dmah); } return -ENOMEM; } } return 0; } static int acm_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_cdc_union_desc *union_header = NULL; struct usb_cdc_country_functional_desc *cfd = NULL; unsigned char *buffer = intf->altsetting->extra; int buflen = intf->altsetting->extralen; struct usb_interface *control_interface; struct usb_interface *data_interface; struct usb_endpoint_descriptor *epctrl = NULL; struct usb_endpoint_descriptor *epread = NULL; struct usb_endpoint_descriptor *epwrite = NULL; struct usb_device *usb_dev = interface_to_usbdev(intf); struct acm *acm; int minor; int ctrlsize, readsize; u8 *buf; u8 ac_management_function = 0; u8 call_management_function = 0; int call_interface_num = -1; int data_interface_num = -1; unsigned long quirks; int num_rx_buf; int i; int combined_interfaces = 0; /* normal quirks */ quirks = (unsigned long)id->driver_info; num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR; /* handle quirks deadly to normal probing*/ if (quirks == NO_UNION_NORMAL) { data_interface = usb_ifnum_to_if(usb_dev, 1); control_interface = usb_ifnum_to_if(usb_dev, 0); goto skip_normal_probe; } /* normal probing*/ if (!buffer) { dev_err(&intf->dev, "Weird descriptor references\n"); return -EINVAL; } if (!buflen) { if (intf->cur_altsetting->endpoint && intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) { dev_dbg(&intf->dev, "Seeking extra descriptors on endpoint\n"); buflen = intf->cur_altsetting->endpoint->extralen; buffer = intf->cur_altsetting->endpoint->extra; } else { dev_err(&intf->dev, "Zero length descriptor references\n"); return -EINVAL; } } while (buflen > 0) { if (buffer[1] != USB_DT_CS_INTERFACE) { dev_err(&intf->dev, "skipping garbage\n"); goto next_desc; } switch (buffer[2]) { case USB_CDC_UNION_TYPE: /* we've found it */ if (union_header) { dev_err(&intf->dev, "More than one " "union descriptor, skipping ...\n"); goto next_desc; } union_header = (struct usb_cdc_union_desc *)buffer; break; case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ cfd = (struct usb_cdc_country_functional_desc *)buffer; break; case USB_CDC_HEADER_TYPE: /* maybe check version */ break; /* for now we ignore it */ case USB_CDC_ACM_TYPE: ac_management_function = buffer[3]; break; case USB_CDC_CALL_MANAGEMENT_TYPE: call_management_function = buffer[3]; call_interface_num = buffer[4]; if ( (quirks & NOT_A_MODEM) == 0 && (call_management_function & 3) != 3) dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n"); break; default: /* there are LOTS more CDC descriptors that * could legitimately be found here. */ dev_dbg(&intf->dev, "Ignoring descriptor: " "type %02x, length %d\n", buffer[2], buffer[0]); break; } next_desc: buflen -= buffer[0]; buffer += buffer[0]; } if (!union_header) { if (call_interface_num > 0) { dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n"); /* quirks for Droids MuIn LCD */ if (quirks & NO_DATA_INTERFACE) data_interface = usb_ifnum_to_if(usb_dev, 0); else data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); control_interface = intf; } else { if (intf->cur_altsetting->desc.bNumEndpoints != 3) { dev_dbg(&intf->dev,"No union descriptor, giving up\n"); return -ENODEV; } else { dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n"); combined_interfaces = 1; control_interface = data_interface = intf; goto look_for_collapsed_interface; } } } else { control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); if (!control_interface || !data_interface) { dev_dbg(&intf->dev, "no interfaces\n"); return -ENODEV; } } if (data_interface_num != call_interface_num) dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); if (control_interface == data_interface) { /* some broken devices designed for windows work this way */ dev_warn(&intf->dev,"Control and data interfaces are not separated!\n"); combined_interfaces = 1; /* a popular other OS doesn't use it */ quirks |= NO_CAP_LINE; if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) { dev_err(&intf->dev, "This needs exactly 3 endpoints\n"); return -EINVAL; } look_for_collapsed_interface: for (i = 0; i < 3; i++) { struct usb_endpoint_descriptor *ep; ep = &data_interface->cur_altsetting->endpoint[i].desc; if (usb_endpoint_is_int_in(ep)) epctrl = ep; else if (usb_endpoint_is_bulk_out(ep)) epwrite = ep; else if (usb_endpoint_is_bulk_in(ep)) epread = ep; else return -EINVAL; } if (!epctrl || !epread || !epwrite) return -ENODEV; else goto made_compressed_probe; } skip_normal_probe: /*workaround for switched interfaces */ if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) { if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) { struct usb_interface *t; dev_dbg(&intf->dev, "Your device has switched interfaces.\n"); t = control_interface; control_interface = data_interface; data_interface = t; } else { return -EINVAL; } } /* Accept probe requests only for the control interface */ if (!combined_interfaces && intf != control_interface) return -ENODEV; if (!combined_interfaces && usb_interface_claimed(data_interface)) { /* valid in this context */ dev_dbg(&intf->dev, "The data interface isn't available\n"); return -EBUSY; } if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 || control_interface->cur_altsetting->desc.bNumEndpoints == 0) return -EINVAL; epctrl = &control_interface->cur_altsetting->endpoint[0].desc; epread = &data_interface->cur_altsetting->endpoint[0].desc; epwrite = &data_interface->cur_altsetting->endpoint[1].desc; /* workaround for switched endpoints */ if (!usb_endpoint_dir_in(epread)) { /* descriptors are swapped */ struct usb_endpoint_descriptor *t; dev_dbg(&intf->dev, "The data interface has switched endpoints\n"); t = epread; epread = epwrite; epwrite = t; } made_compressed_probe: dev_dbg(&intf->dev, "interfaces are valid\n"); acm = kzalloc(sizeof(struct acm), GFP_KERNEL); if (acm == NULL) { dev_err(&intf->dev, "out of memory (acm kzalloc)\n"); goto alloc_fail; } minor = acm_alloc_minor(acm); if (minor == ACM_TTY_MINORS) { dev_err(&intf->dev, "no more free acm devices\n"); kfree(acm); return -ENODEV; } ctrlsize = usb_endpoint_maxp(epctrl); readsize = usb_endpoint_maxp(epread) * (quirks == SINGLE_RX_URB ? 1 : 2); acm->combined_interfaces = combined_interfaces; acm->writesize = usb_endpoint_maxp(epwrite) * 20; acm->control = control_interface; acm->data = data_interface; acm->minor = minor; acm->dev = usb_dev; acm->ctrl_caps = ac_management_function; if (quirks & NO_CAP_LINE) acm->ctrl_caps &= ~USB_CDC_CAP_LINE; acm->ctrlsize = ctrlsize; acm->readsize = readsize; acm->rx_buflimit = num_rx_buf; INIT_WORK(&acm->work, acm_softint); spin_lock_init(&acm->write_lock); spin_lock_init(&acm->read_lock); mutex_init(&acm->mutex); acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); acm->is_int_ep = usb_endpoint_xfer_int(epread); if (acm->is_int_ep) acm->bInterval = epread->bInterval; tty_port_init(&acm->port); acm->port.ops = &acm_port_ops; buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); if (!buf) { dev_err(&intf->dev, "out of memory (ctrl buffer alloc)\n"); goto alloc_fail2; } acm->ctrl_buffer = buf; if (acm_write_buffers_alloc(acm) < 0) { dev_err(&intf->dev, "out of memory (write buffer alloc)\n"); goto alloc_fail4; } acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); if (!acm->ctrlurb) { dev_err(&intf->dev, "out of memory (ctrlurb kmalloc)\n"); goto alloc_fail5; } for (i = 0; i < num_rx_buf; i++) { struct acm_rb *rb = &(acm->read_buffers[i]); struct urb *urb; rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL, &rb->dma); if (!rb->base) { dev_err(&intf->dev, "out of memory " "(read bufs usb_alloc_coherent)\n"); goto alloc_fail6; } rb->index = i; rb->instance = acm; urb = usb_alloc_urb(0, GFP_KERNEL); if (!urb) { dev_err(&intf->dev, "out of memory (read urbs usb_alloc_urb)\n"); goto alloc_fail6; } urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; urb->transfer_dma = rb->dma; if (acm->is_int_ep) { usb_fill_int_urb(urb, acm->dev, acm->rx_endpoint, rb->base, acm->readsize, acm_read_bulk_callback, rb, acm->bInterval); } else { usb_fill_bulk_urb(urb, acm->dev, acm->rx_endpoint, rb->base, acm->readsize, acm_read_bulk_callback, rb); } acm->read_urbs[i] = urb; __set_bit(i, &acm->read_urbs_free); } for (i = 0; i < ACM_NW; i++) { struct acm_wb *snd = &(acm->wb[i]); snd->urb = usb_alloc_urb(0, GFP_KERNEL); if (snd->urb == NULL) { dev_err(&intf->dev, "out of memory (write urbs usb_alloc_urb)\n"); goto alloc_fail7; } if (usb_endpoint_xfer_int(epwrite)) usb_fill_int_urb(snd->urb, usb_dev, usb_sndintpipe(usb_dev, epwrite->bEndpointAddress), NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval); else usb_fill_bulk_urb(snd->urb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), NULL, acm->writesize, acm_write_bulk, snd); snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; snd->instance = acm; } usb_set_intfdata(intf, acm); i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); if (i < 0) goto alloc_fail7; if (cfd) { /* export the country data */ acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL); if (!acm->country_codes) goto skip_countries; acm->country_code_size = cfd->bLength - 4; memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4); acm->country_rel_date = cfd->iCountryCodeRelDate; i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); if (i < 0) { kfree(acm->country_codes); acm->country_codes = NULL; acm->country_code_size = 0; goto skip_countries; } i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate); if (i < 0) { device_remove_file(&intf->dev, &dev_attr_wCountryCodes); kfree(acm->country_codes); acm->country_codes = NULL; acm->country_code_size = 0; goto skip_countries; } } skip_countries: usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, /* works around buggy devices */ epctrl->bInterval ? epctrl->bInterval : 0xff); acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; acm->ctrlurb->transfer_dma = acm->ctrl_dma; dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); acm_set_control(acm, acm->ctrlout); acm->line.dwDTERate = cpu_to_le32(9600); acm->line.bDataBits = 8; acm_set_line(acm, &acm->line); usb_driver_claim_interface(&acm_driver, data_interface, acm); usb_set_intfdata(data_interface, acm); usb_get_intf(control_interface); tty_register_device(acm_tty_driver, minor, &control_interface->dev); return 0; alloc_fail7: for (i = 0; i < ACM_NW; i++) usb_free_urb(acm->wb[i].urb); alloc_fail6: for (i = 0; i < num_rx_buf; i++) usb_free_urb(acm->read_urbs[i]); acm_read_buffers_free(acm); usb_free_urb(acm->ctrlurb); alloc_fail5: acm_write_buffers_free(acm); alloc_fail4: usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); alloc_fail2: acm_release_minor(acm); kfree(acm); alloc_fail: return -ENOMEM; } static void stop_data_traffic(struct acm *acm) { int i; dev_dbg(&acm->control->dev, "%s\n", __func__); usb_kill_urb(acm->ctrlurb); for (i = 0; i < ACM_NW; i++) usb_kill_urb(acm->wb[i].urb); for (i = 0; i < acm->rx_buflimit; i++) usb_kill_urb(acm->read_urbs[i]); cancel_work_sync(&acm->work); } static void acm_disconnect(struct usb_interface *intf) { struct acm *acm = usb_get_intfdata(intf); struct usb_device *usb_dev = interface_to_usbdev(intf); struct tty_struct *tty; int i; dev_dbg(&intf->dev, "%s\n", __func__); /* sibling interface is already cleaning up */ if (!acm) return; mutex_lock(&acm->mutex); acm->disconnected = true; if (acm->country_codes) { device_remove_file(&acm->control->dev, &dev_attr_wCountryCodes); device_remove_file(&acm->control->dev, &dev_attr_iCountryCodeRelDate); } device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); usb_set_intfdata(acm->control, NULL); usb_set_intfdata(acm->data, NULL); mutex_unlock(&acm->mutex); tty = tty_port_tty_get(&acm->port); if (tty) { tty_vhangup(tty); tty_kref_put(tty); } stop_data_traffic(acm); tty_unregister_device(acm_tty_driver, acm->minor); usb_free_urb(acm->ctrlurb); for (i = 0; i < ACM_NW; i++) usb_free_urb(acm->wb[i].urb); for (i = 0; i < acm->rx_buflimit; i++) usb_free_urb(acm->read_urbs[i]); acm_write_buffers_free(acm); usb_free_coherent(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); acm_read_buffers_free(acm); if (!acm->combined_interfaces) usb_driver_release_interface(&acm_driver, intf == acm->control ? acm->data : acm->control); tty_port_put(&acm->port); } #ifdef CONFIG_PM static int acm_suspend(struct usb_interface *intf, pm_message_t message) { struct acm *acm = usb_get_intfdata(intf); int cnt; if (PMSG_IS_AUTO(message)) { int b; spin_lock_irq(&acm->write_lock); b = acm->transmitting; spin_unlock_irq(&acm->write_lock); if (b) return -EBUSY; } spin_lock_irq(&acm->read_lock); spin_lock(&acm->write_lock); cnt = acm->susp_count++; spin_unlock(&acm->write_lock); spin_unlock_irq(&acm->read_lock); if (cnt) return 0; if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) stop_data_traffic(acm); return 0; } static int acm_resume(struct usb_interface *intf) { struct acm *acm = usb_get_intfdata(intf); struct acm_wb *wb; int rv = 0; int cnt; spin_lock_irq(&acm->read_lock); acm->susp_count -= 1; cnt = acm->susp_count; spin_unlock_irq(&acm->read_lock); if (cnt) return 0; if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) { rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); spin_lock_irq(&acm->write_lock); if (acm->delayed_wb) { wb = acm->delayed_wb; acm->delayed_wb = NULL; spin_unlock_irq(&acm->write_lock); acm_start_wb(acm, wb); } else { spin_unlock_irq(&acm->write_lock); } /* * delayed error checking because we must * do the write path at all cost */ if (rv < 0) goto err_out; rv = acm_submit_read_urbs(acm, GFP_NOIO); } err_out: return rv; } static int acm_reset_resume(struct usb_interface *intf) { struct acm *acm = usb_get_intfdata(intf); struct tty_struct *tty; if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) { tty = tty_port_tty_get(&acm->port); if (tty) { tty_hangup(tty); tty_kref_put(tty); } } return acm_resume(intf); } #endif /* CONFIG_PM */ #define NOKIA_PCSUITE_ACM_INFO(x) \ USB_DEVICE_AND_INTERFACE_INFO(0x0421, x, \ USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \ USB_CDC_ACM_PROTO_VENDOR) #define SAMSUNG_PCSUITE_ACM_INFO(x) \ USB_DEVICE_AND_INTERFACE_INFO(0x04e7, x, \ USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \ USB_CDC_ACM_PROTO_VENDOR) /* * USB driver structure. */ static const struct usb_device_id acm_ids[] = { /* quirky and broken devices */ { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, { USB_DEVICE(0x0ace, 0x1602), /* ZyDAS 56K USB MODEM */ .driver_info = SINGLE_RX_URB, }, { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */ .driver_info = SINGLE_RX_URB, /* firmware bug */ }, { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */ .driver_info = SINGLE_RX_URB, /* firmware bug */ }, { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, { USB_DEVICE(0x0572, 0x1321), /* Conexant USB MODEM CX93010 */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */ .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ }, { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */ }, /* Motorola H24 HSPA module: */ { USB_DEVICE(0x22b8, 0x2d91) }, /* modem */ { USB_DEVICE(0x22b8, 0x2d92) }, /* modem + diagnostics */ { USB_DEVICE(0x22b8, 0x2d93) }, /* modem + AT port */ { USB_DEVICE(0x22b8, 0x2d95) }, /* modem + AT port + diagnostics */ { USB_DEVICE(0x22b8, 0x2d96) }, /* modem + NMEA */ { USB_DEVICE(0x22b8, 0x2d97) }, /* modem + diagnostics + NMEA */ { USB_DEVICE(0x22b8, 0x2d99) }, /* modem + AT port + NMEA */ { USB_DEVICE(0x22b8, 0x2d9a) }, /* modem + AT port + diagnostics + NMEA */ { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */ .driver_info = NO_UNION_NORMAL, /* union descriptor misplaced on data interface instead of communications interface. Maybe we should define a new quirk for this. */ }, { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */ .driver_info = NO_UNION_NORMAL, }, { USB_DEVICE(0x05f9, 0x4002), /* PSC Scanning, Magellan 800i */ .driver_info = NO_UNION_NORMAL, }, { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */ .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */ }, { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */ .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */ }, /* Nokia S60 phones expose two ACM channels. The first is * a modem and is picked up by the standard AT-command * information below. The second is 'vendor-specific' but * is treated as a serial device at the S60 end, so we want * to expose it on Linux too. */ { NOKIA_PCSUITE_ACM_INFO(0x042D), }, /* Nokia 3250 */ { NOKIA_PCSUITE_ACM_INFO(0x04D8), }, /* Nokia 5500 Sport */ { NOKIA_PCSUITE_ACM_INFO(0x04C9), }, /* Nokia E50 */ { NOKIA_PCSUITE_ACM_INFO(0x0419), }, /* Nokia E60 */ { NOKIA_PCSUITE_ACM_INFO(0x044D), }, /* Nokia E61 */ { NOKIA_PCSUITE_ACM_INFO(0x0001), }, /* Nokia E61i */ { NOKIA_PCSUITE_ACM_INFO(0x0475), }, /* Nokia E62 */ { NOKIA_PCSUITE_ACM_INFO(0x0508), }, /* Nokia E65 */ { NOKIA_PCSUITE_ACM_INFO(0x0418), }, /* Nokia E70 */ { NOKIA_PCSUITE_ACM_INFO(0x0425), }, /* Nokia N71 */ { NOKIA_PCSUITE_ACM_INFO(0x0486), }, /* Nokia N73 */ { NOKIA_PCSUITE_ACM_INFO(0x04DF), }, /* Nokia N75 */ { NOKIA_PCSUITE_ACM_INFO(0x000e), }, /* Nokia N77 */ { NOKIA_PCSUITE_ACM_INFO(0x0445), }, /* Nokia N80 */ { NOKIA_PCSUITE_ACM_INFO(0x042F), }, /* Nokia N91 & N91 8GB */ { NOKIA_PCSUITE_ACM_INFO(0x048E), }, /* Nokia N92 */ { NOKIA_PCSUITE_ACM_INFO(0x0420), }, /* Nokia N93 */ { NOKIA_PCSUITE_ACM_INFO(0x04E6), }, /* Nokia N93i */ { NOKIA_PCSUITE_ACM_INFO(0x04B2), }, /* Nokia 5700 XpressMusic */ { NOKIA_PCSUITE_ACM_INFO(0x0134), }, /* Nokia 6110 Navigator (China) */ { NOKIA_PCSUITE_ACM_INFO(0x046E), }, /* Nokia 6110 Navigator */ { NOKIA_PCSUITE_ACM_INFO(0x002f), }, /* Nokia 6120 classic & */ { NOKIA_PCSUITE_ACM_INFO(0x0088), }, /* Nokia 6121 classic */ { NOKIA_PCSUITE_ACM_INFO(0x00fc), }, /* Nokia 6124 classic */ { NOKIA_PCSUITE_ACM_INFO(0x0042), }, /* Nokia E51 */ { NOKIA_PCSUITE_ACM_INFO(0x00b0), }, /* Nokia E66 */ { NOKIA_PCSUITE_ACM_INFO(0x00ab), }, /* Nokia E71 */ { NOKIA_PCSUITE_ACM_INFO(0x0481), }, /* Nokia N76 */ { NOKIA_PCSUITE_ACM_INFO(0x0007), }, /* Nokia N81 & N81 8GB */ { NOKIA_PCSUITE_ACM_INFO(0x0071), }, /* Nokia N82 */ { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */ { NOKIA_PCSUITE_ACM_INFO(0x0070), }, /* Nokia N95 8GB */ { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */ { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */ { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */ { NOKIA_PCSUITE_ACM_INFO(0x008f), }, /* Nokia 6220 Classic */ { NOKIA_PCSUITE_ACM_INFO(0x00a0), }, /* Nokia 6650 */ { NOKIA_PCSUITE_ACM_INFO(0x007b), }, /* Nokia N78 */ { NOKIA_PCSUITE_ACM_INFO(0x0094), }, /* Nokia N85 */ { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */ { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */ { NOKIA_PCSUITE_ACM_INFO(0x0108), }, /* Nokia 5320 XpressMusic 2G */ { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */ { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */ { NOKIA_PCSUITE_ACM_INFO(0x0178), }, /* Nokia E63 */ { NOKIA_PCSUITE_ACM_INFO(0x010e), }, /* Nokia E75 */ { NOKIA_PCSUITE_ACM_INFO(0x02d9), }, /* Nokia 6760 Slide */ { NOKIA_PCSUITE_ACM_INFO(0x01d0), }, /* Nokia E52 */ { NOKIA_PCSUITE_ACM_INFO(0x0223), }, /* Nokia E72 */ { NOKIA_PCSUITE_ACM_INFO(0x0275), }, /* Nokia X6 */ { NOKIA_PCSUITE_ACM_INFO(0x026c), }, /* Nokia N97 Mini */ { NOKIA_PCSUITE_ACM_INFO(0x0154), }, /* Nokia 5800 XpressMusic */ { NOKIA_PCSUITE_ACM_INFO(0x04ce), }, /* Nokia E90 */ { NOKIA_PCSUITE_ACM_INFO(0x01d4), }, /* Nokia E55 */ { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */ { NOKIA_PCSUITE_ACM_INFO(0x0335), }, /* Nokia E7 */ { NOKIA_PCSUITE_ACM_INFO(0x03cd), }, /* Nokia C7 */ { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */ /* Support for Owen devices */ { USB_DEVICE(0x03eb, 0x0030), }, /* Owen SI30 */ /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */ /* Support Lego NXT using pbLua firmware */ { USB_DEVICE(0x0694, 0xff00), .driver_info = NOT_A_MODEM, }, /* Support for Droids MuIn LCD */ { USB_DEVICE(0x04d8, 0x000b), .driver_info = NO_DATA_INTERFACE, }, /* control interfaces without any protocol set */ { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, USB_CDC_PROTO_NONE) }, /* control interfaces with various AT-command sets */ { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, USB_CDC_ACM_PROTO_AT_V25TER) }, { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, USB_CDC_ACM_PROTO_AT_PCCA101) }, { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, USB_CDC_ACM_PROTO_AT_PCCA101_WAKE) }, { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, USB_CDC_ACM_PROTO_AT_GSM) }, { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, USB_CDC_ACM_PROTO_AT_3G) }, { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, USB_CDC_ACM_PROTO_AT_CDMA) }, { } }; MODULE_DEVICE_TABLE(usb, acm_ids); static struct usb_driver acm_driver = { .name = "cdc_acm", .probe = acm_probe, .disconnect = acm_disconnect, #ifdef CONFIG_PM .suspend = acm_suspend, .resume = acm_resume, .reset_resume = acm_reset_resume, #endif .id_table = acm_ids, #ifdef CONFIG_PM .supports_autosuspend = 1, #endif }; /* * TTY driver structures. */ static const struct tty_operations acm_ops = { .install = acm_tty_install, .open = acm_tty_open, .close = acm_tty_close, .cleanup = acm_tty_cleanup, .hangup = acm_tty_hangup, .write = acm_tty_write, .write_room = acm_tty_write_room, .ioctl = acm_tty_ioctl, .throttle = acm_tty_throttle, .unthrottle = acm_tty_unthrottle, .chars_in_buffer = acm_tty_chars_in_buffer, .break_ctl = acm_tty_break_ctl, .set_termios = acm_tty_set_termios, .tiocmget = acm_tty_tiocmget, .tiocmset = acm_tty_tiocmset, }; /* * Init / exit. */ static int __init acm_init(void) { int retval; acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS); if (!acm_tty_driver) return -ENOMEM; acm_tty_driver->driver_name = "acm", acm_tty_driver->name = "ttyACM", acm_tty_driver->major = ACM_TTY_MAJOR, acm_tty_driver->minor_start = 0, acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL, acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; acm_tty_driver->init_termios = tty_std_termios; acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; tty_set_operations(acm_tty_driver, &acm_ops); retval = tty_register_driver(acm_tty_driver); if (retval) { put_tty_driver(acm_tty_driver); return retval; } retval = usb_register(&acm_driver); if (retval) { tty_unregister_driver(acm_tty_driver); put_tty_driver(acm_tty_driver); return retval; } printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n"); return 0; } static void __exit acm_exit(void) { usb_deregister(&acm_driver); tty_unregister_driver(acm_tty_driver); put_tty_driver(acm_tty_driver); } module_init(acm_init); module_exit(acm_exit); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR);
gpl-2.0
avisconti/prova
arch/arm/mach-msm/qdsp6v2/apr_tal.c
703
7106
/* Copyright (c) 2010-2011, 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/kernel.h> #include <linux/module.h> #include <linux/types.h> #include <linux/uaccess.h> #include <linux/spinlock.h> #include <linux/mutex.h> #include <linux/list.h> #include <linux/sched.h> #include <linux/wait.h> #include <linux/errno.h> #include <linux/fs.h> #include <linux/debugfs.h> #include <linux/platform_device.h> #include <linux/delay.h> #include <linux/clk.h> #include <mach/msm_smd.h> #include <mach/qdsp6v2/apr_tal.h> static char *svc_names[APR_DEST_MAX][APR_CLIENT_MAX] = { { "apr_audio_svc", "apr_voice_svc", }, { "apr_audio_svc", "apr_voice_svc", }, }; struct apr_svc_ch_dev apr_svc_ch[APR_DL_MAX][APR_DEST_MAX][APR_CLIENT_MAX]; int __apr_tal_write(struct apr_svc_ch_dev *apr_ch, void *data, int len) { int w_len; unsigned long flags; spin_lock_irqsave(&apr_ch->w_lock, flags); if (smd_write_avail(apr_ch->ch) < len) { spin_unlock_irqrestore(&apr_ch->w_lock, flags); return -EAGAIN; } w_len = smd_write(apr_ch->ch, data, len); spin_unlock_irqrestore(&apr_ch->w_lock, flags); pr_debug("apr_tal:w_len = %d\n", w_len); if (w_len != len) { pr_err("apr_tal: Error in write\n"); return -ENETRESET; } return w_len; } int apr_tal_write(struct apr_svc_ch_dev *apr_ch, void *data, int len) { int rc = 0, retries = 0; if (!apr_ch->ch) return -EINVAL; do { if (rc == -EAGAIN) udelay(50); rc = __apr_tal_write(apr_ch, data, len); } while (rc == -EAGAIN && retries++ < 300); if (rc == -EAGAIN) pr_err("apr_tal: TIMEOUT for write\n"); return rc; } static void apr_tal_notify(void *priv, unsigned event) { struct apr_svc_ch_dev *apr_ch = priv; int len, r_len, sz; int pkt_cnt = 0; unsigned long flags; pr_debug("event = %d\n", event); switch (event) { case SMD_EVENT_DATA: pkt_cnt = 0; spin_lock_irqsave(&apr_ch->lock, flags); check_pending: len = smd_read_avail(apr_ch->ch); if (len < 0) { pr_err("apr_tal: Invalid Read Event :%d\n", len); spin_unlock_irqrestore(&apr_ch->lock, flags); return; } sz = smd_cur_packet_size(apr_ch->ch); if (sz < 0) { pr_debug("pkt size is zero\n"); spin_unlock_irqrestore(&apr_ch->lock, flags); return; } if (!len && !sz && !pkt_cnt) goto check_write_avail; if (!len) { pr_debug("len = %d pkt_cnt = %d\n", len, pkt_cnt); spin_unlock_irqrestore(&apr_ch->lock, flags); return; } r_len = smd_read_from_cb(apr_ch->ch, apr_ch->data, len); if (len != r_len) { pr_err("apr_tal: Invalid Read\n"); spin_unlock_irqrestore(&apr_ch->lock, flags); return; } pkt_cnt++; pr_debug("%d %d %d\n", len, sz, pkt_cnt); if (apr_ch->func) apr_ch->func(apr_ch->data, r_len, apr_ch->priv); goto check_pending; check_write_avail: if (smd_write_avail(apr_ch->ch)) wake_up(&apr_ch->wait); spin_unlock_irqrestore(&apr_ch->lock, flags); break; case SMD_EVENT_OPEN: pr_debug("apr_tal: SMD_EVENT_OPEN\n"); apr_ch->smd_state = 1; wake_up(&apr_ch->wait); break; case SMD_EVENT_CLOSE: pr_debug("apr_tal: SMD_EVENT_CLOSE\n"); break; } } struct apr_svc_ch_dev *apr_tal_open(uint32_t svc, uint32_t dest, uint32_t dl, apr_svc_cb_fn func, void *priv) { int rc; if ((svc >= APR_CLIENT_MAX) || (dest >= APR_DEST_MAX) || (dl >= APR_DL_MAX)) { pr_err("apr_tal: Invalid params\n"); return NULL; } if (apr_svc_ch[dl][dest][svc].ch) { pr_err("apr_tal: This channel alreday openend\n"); return NULL; } mutex_lock(&apr_svc_ch[dl][dest][svc].m_lock); if (!apr_svc_ch[dl][dest][svc].dest_state) { rc = wait_event_timeout(apr_svc_ch[dl][dest][svc].dest, apr_svc_ch[dl][dest][svc].dest_state, msecs_to_jiffies(APR_OPEN_TIMEOUT_MS)); if (rc == 0) { pr_err("apr_tal:open timeout\n"); mutex_unlock(&apr_svc_ch[dl][dest][svc].m_lock); return NULL; } pr_debug("apr_tal:Wakeup done\n"); apr_svc_ch[dl][dest][svc].dest_state = 0; } rc = smd_named_open_on_edge(svc_names[dest][svc], dest, &apr_svc_ch[dl][dest][svc].ch, &apr_svc_ch[dl][dest][svc], apr_tal_notify); if (rc < 0) { pr_err("apr_tal: smd_open failed %s\n", svc_names[dest][svc]); mutex_unlock(&apr_svc_ch[dl][dest][svc].m_lock); return NULL; } rc = wait_event_timeout(apr_svc_ch[dl][dest][svc].wait, (apr_svc_ch[dl][dest][svc].smd_state == 1), 5 * HZ); if (rc == 0) { pr_err("apr_tal:TIMEOUT for OPEN event\n"); mutex_unlock(&apr_svc_ch[dl][dest][svc].m_lock); apr_tal_close(&apr_svc_ch[dl][dest][svc]); return NULL; } if (!apr_svc_ch[dl][dest][svc].dest_state) { apr_svc_ch[dl][dest][svc].dest_state = 1; pr_debug("apr_tal:Waiting for apr svc init\n"); msleep(200); pr_debug("apr_tal:apr svc init done\n"); } apr_svc_ch[dl][dest][svc].smd_state = 0; apr_svc_ch[dl][dest][svc].func = func; apr_svc_ch[dl][dest][svc].priv = priv; mutex_unlock(&apr_svc_ch[dl][dest][svc].m_lock); return &apr_svc_ch[dl][dest][svc]; } int apr_tal_close(struct apr_svc_ch_dev *apr_ch) { int r; if (!apr_ch->ch) return -EINVAL; mutex_lock(&apr_ch->m_lock); r = smd_close(apr_ch->ch); apr_ch->ch = NULL; apr_ch->func = NULL; apr_ch->priv = NULL; mutex_unlock(&apr_ch->m_lock); return r; } static int apr_smd_probe(struct platform_device *pdev) { int dest; int clnt; if (pdev->id == APR_DEST_MODEM) { pr_info("apr_tal:Modem Is Up\n"); dest = APR_DEST_MODEM; clnt = APR_CLIENT_VOICE; apr_svc_ch[APR_DL_SMD][dest][clnt].dest_state = 1; wake_up(&apr_svc_ch[APR_DL_SMD][dest][clnt].dest); } else if (pdev->id == APR_DEST_QDSP6) { pr_info("apr_tal:Q6 Is Up\n"); dest = APR_DEST_QDSP6; clnt = APR_CLIENT_AUDIO; apr_svc_ch[APR_DL_SMD][dest][clnt].dest_state = 1; wake_up(&apr_svc_ch[APR_DL_SMD][dest][clnt].dest); } else pr_err("apr_tal:Invalid Dest Id: %d\n", pdev->id); return 0; } static struct platform_driver apr_q6_driver = { .probe = apr_smd_probe, .driver = { .name = "apr_audio_svc", .owner = THIS_MODULE, }, }; static struct platform_driver apr_modem_driver = { .probe = apr_smd_probe, .driver = { .name = "apr_voice_svc", .owner = THIS_MODULE, }, }; static int __init apr_tal_init(void) { int i, j, k; for (i = 0; i < APR_DL_MAX; i++) for (j = 0; j < APR_DEST_MAX; j++) for (k = 0; k < APR_CLIENT_MAX; k++) { init_waitqueue_head(&apr_svc_ch[i][j][k].wait); init_waitqueue_head(&apr_svc_ch[i][j][k].dest); spin_lock_init(&apr_svc_ch[i][j][k].lock); spin_lock_init(&apr_svc_ch[i][j][k].w_lock); mutex_init(&apr_svc_ch[i][j][k].m_lock); } platform_driver_register(&apr_q6_driver); platform_driver_register(&apr_modem_driver); return 0; } device_initcall(apr_tal_init);
gpl-2.0
Combitech/simcom-linux-kernel
sound/pci/emu10k1/emumixer.c
703
66204
/* * Copyright (c) by Jaroslav Kysela <perex@perex.cz>, * Takashi Iwai <tiwai@suse.de> * Creative Labs, Inc. * Routines for control of EMU10K1 chips / mixer routines * Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com> * * Copyright (c) by James Courtier-Dutton <James@superbug.co.uk> * Added EMU 1010 support. * * BUGS: * -- * * TODO: * -- * * 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 <linux/time.h> #include <linux/init.h> #include <sound/core.h> #include <sound/emu10k1.h> #include <linux/delay.h> #include <sound/tlv.h> #include "p17v.h" #define AC97_ID_STAC9758 0x83847658 static const DECLARE_TLV_DB_SCALE(snd_audigy_db_scale2, -10350, 50, 1); /* WM8775 gain scale */ static int snd_emu10k1_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int snd_emu10k1_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); unsigned long flags; /* Limit: emu->spdif_bits */ if (idx >= 3) return -EINVAL; spin_lock_irqsave(&emu->reg_lock, flags); ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff; ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff; ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff; ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff; spin_unlock_irqrestore(&emu->reg_lock, flags); return 0; } static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { ucontrol->value.iec958.status[0] = 0xff; ucontrol->value.iec958.status[1] = 0xff; ucontrol->value.iec958.status[2] = 0xff; ucontrol->value.iec958.status[3] = 0xff; return 0; } /* * Items labels in enum mixer controls assigning source data to * each destination */ static char *emu1010_src_texts[] = { "Silence", "Dock Mic A", "Dock Mic B", "Dock ADC1 Left", "Dock ADC1 Right", "Dock ADC2 Left", "Dock ADC2 Right", "Dock ADC3 Left", "Dock ADC3 Right", "0202 ADC Left", "0202 ADC Right", "0202 SPDIF Left", "0202 SPDIF Right", "ADAT 0", "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4", "ADAT 5", "ADAT 6", "ADAT 7", "DSP 0", "DSP 1", "DSP 2", "DSP 3", "DSP 4", "DSP 5", "DSP 6", "DSP 7", "DSP 8", "DSP 9", "DSP 10", "DSP 11", "DSP 12", "DSP 13", "DSP 14", "DSP 15", "DSP 16", "DSP 17", "DSP 18", "DSP 19", "DSP 20", "DSP 21", "DSP 22", "DSP 23", "DSP 24", "DSP 25", "DSP 26", "DSP 27", "DSP 28", "DSP 29", "DSP 30", "DSP 31", }; /* 1616(m) cardbus */ static char *emu1616_src_texts[] = { "Silence", "Dock Mic A", "Dock Mic B", "Dock ADC1 Left", "Dock ADC1 Right", "Dock ADC2 Left", "Dock ADC2 Right", "Dock SPDIF Left", "Dock SPDIF Right", "ADAT 0", "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4", "ADAT 5", "ADAT 6", "ADAT 7", "DSP 0", "DSP 1", "DSP 2", "DSP 3", "DSP 4", "DSP 5", "DSP 6", "DSP 7", "DSP 8", "DSP 9", "DSP 10", "DSP 11", "DSP 12", "DSP 13", "DSP 14", "DSP 15", "DSP 16", "DSP 17", "DSP 18", "DSP 19", "DSP 20", "DSP 21", "DSP 22", "DSP 23", "DSP 24", "DSP 25", "DSP 26", "DSP 27", "DSP 28", "DSP 29", "DSP 30", "DSP 31", }; /* * List of data sources available for each destination */ static unsigned int emu1010_src_regs[] = { EMU_SRC_SILENCE,/* 0 */ EMU_SRC_DOCK_MIC_A1, /* 1 */ EMU_SRC_DOCK_MIC_B1, /* 2 */ EMU_SRC_DOCK_ADC1_LEFT1, /* 3 */ EMU_SRC_DOCK_ADC1_RIGHT1, /* 4 */ EMU_SRC_DOCK_ADC2_LEFT1, /* 5 */ EMU_SRC_DOCK_ADC2_RIGHT1, /* 6 */ EMU_SRC_DOCK_ADC3_LEFT1, /* 7 */ EMU_SRC_DOCK_ADC3_RIGHT1, /* 8 */ EMU_SRC_HAMOA_ADC_LEFT1, /* 9 */ EMU_SRC_HAMOA_ADC_RIGHT1, /* 10 */ EMU_SRC_HANA_SPDIF_LEFT1, /* 11 */ EMU_SRC_HANA_SPDIF_RIGHT1, /* 12 */ EMU_SRC_HANA_ADAT, /* 13 */ EMU_SRC_HANA_ADAT+1, /* 14 */ EMU_SRC_HANA_ADAT+2, /* 15 */ EMU_SRC_HANA_ADAT+3, /* 16 */ EMU_SRC_HANA_ADAT+4, /* 17 */ EMU_SRC_HANA_ADAT+5, /* 18 */ EMU_SRC_HANA_ADAT+6, /* 19 */ EMU_SRC_HANA_ADAT+7, /* 20 */ EMU_SRC_ALICE_EMU32A, /* 21 */ EMU_SRC_ALICE_EMU32A+1, /* 22 */ EMU_SRC_ALICE_EMU32A+2, /* 23 */ EMU_SRC_ALICE_EMU32A+3, /* 24 */ EMU_SRC_ALICE_EMU32A+4, /* 25 */ EMU_SRC_ALICE_EMU32A+5, /* 26 */ EMU_SRC_ALICE_EMU32A+6, /* 27 */ EMU_SRC_ALICE_EMU32A+7, /* 28 */ EMU_SRC_ALICE_EMU32A+8, /* 29 */ EMU_SRC_ALICE_EMU32A+9, /* 30 */ EMU_SRC_ALICE_EMU32A+0xa, /* 31 */ EMU_SRC_ALICE_EMU32A+0xb, /* 32 */ EMU_SRC_ALICE_EMU32A+0xc, /* 33 */ EMU_SRC_ALICE_EMU32A+0xd, /* 34 */ EMU_SRC_ALICE_EMU32A+0xe, /* 35 */ EMU_SRC_ALICE_EMU32A+0xf, /* 36 */ EMU_SRC_ALICE_EMU32B, /* 37 */ EMU_SRC_ALICE_EMU32B+1, /* 38 */ EMU_SRC_ALICE_EMU32B+2, /* 39 */ EMU_SRC_ALICE_EMU32B+3, /* 40 */ EMU_SRC_ALICE_EMU32B+4, /* 41 */ EMU_SRC_ALICE_EMU32B+5, /* 42 */ EMU_SRC_ALICE_EMU32B+6, /* 43 */ EMU_SRC_ALICE_EMU32B+7, /* 44 */ EMU_SRC_ALICE_EMU32B+8, /* 45 */ EMU_SRC_ALICE_EMU32B+9, /* 46 */ EMU_SRC_ALICE_EMU32B+0xa, /* 47 */ EMU_SRC_ALICE_EMU32B+0xb, /* 48 */ EMU_SRC_ALICE_EMU32B+0xc, /* 49 */ EMU_SRC_ALICE_EMU32B+0xd, /* 50 */ EMU_SRC_ALICE_EMU32B+0xe, /* 51 */ EMU_SRC_ALICE_EMU32B+0xf, /* 52 */ }; /* 1616(m) cardbus */ static unsigned int emu1616_src_regs[] = { EMU_SRC_SILENCE, EMU_SRC_DOCK_MIC_A1, EMU_SRC_DOCK_MIC_B1, EMU_SRC_DOCK_ADC1_LEFT1, EMU_SRC_DOCK_ADC1_RIGHT1, EMU_SRC_DOCK_ADC2_LEFT1, EMU_SRC_DOCK_ADC2_RIGHT1, EMU_SRC_MDOCK_SPDIF_LEFT1, EMU_SRC_MDOCK_SPDIF_RIGHT1, EMU_SRC_MDOCK_ADAT, EMU_SRC_MDOCK_ADAT+1, EMU_SRC_MDOCK_ADAT+2, EMU_SRC_MDOCK_ADAT+3, EMU_SRC_MDOCK_ADAT+4, EMU_SRC_MDOCK_ADAT+5, EMU_SRC_MDOCK_ADAT+6, EMU_SRC_MDOCK_ADAT+7, EMU_SRC_ALICE_EMU32A, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3, EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7, EMU_SRC_ALICE_EMU32A+8, EMU_SRC_ALICE_EMU32A+9, EMU_SRC_ALICE_EMU32A+0xa, EMU_SRC_ALICE_EMU32A+0xb, EMU_SRC_ALICE_EMU32A+0xc, EMU_SRC_ALICE_EMU32A+0xd, EMU_SRC_ALICE_EMU32A+0xe, EMU_SRC_ALICE_EMU32A+0xf, EMU_SRC_ALICE_EMU32B, EMU_SRC_ALICE_EMU32B+1, EMU_SRC_ALICE_EMU32B+2, EMU_SRC_ALICE_EMU32B+3, EMU_SRC_ALICE_EMU32B+4, EMU_SRC_ALICE_EMU32B+5, EMU_SRC_ALICE_EMU32B+6, EMU_SRC_ALICE_EMU32B+7, EMU_SRC_ALICE_EMU32B+8, EMU_SRC_ALICE_EMU32B+9, EMU_SRC_ALICE_EMU32B+0xa, EMU_SRC_ALICE_EMU32B+0xb, EMU_SRC_ALICE_EMU32B+0xc, EMU_SRC_ALICE_EMU32B+0xd, EMU_SRC_ALICE_EMU32B+0xe, EMU_SRC_ALICE_EMU32B+0xf, }; /* * Data destinations - physical EMU outputs. * Each destination has an enum mixer control to choose a data source */ static unsigned int emu1010_output_dst[] = { EMU_DST_DOCK_DAC1_LEFT1, /* 0 */ EMU_DST_DOCK_DAC1_RIGHT1, /* 1 */ EMU_DST_DOCK_DAC2_LEFT1, /* 2 */ EMU_DST_DOCK_DAC2_RIGHT1, /* 3 */ EMU_DST_DOCK_DAC3_LEFT1, /* 4 */ EMU_DST_DOCK_DAC3_RIGHT1, /* 5 */ EMU_DST_DOCK_DAC4_LEFT1, /* 6 */ EMU_DST_DOCK_DAC4_RIGHT1, /* 7 */ EMU_DST_DOCK_PHONES_LEFT1, /* 8 */ EMU_DST_DOCK_PHONES_RIGHT1, /* 9 */ EMU_DST_DOCK_SPDIF_LEFT1, /* 10 */ EMU_DST_DOCK_SPDIF_RIGHT1, /* 11 */ EMU_DST_HANA_SPDIF_LEFT1, /* 12 */ EMU_DST_HANA_SPDIF_RIGHT1, /* 13 */ EMU_DST_HAMOA_DAC_LEFT1, /* 14 */ EMU_DST_HAMOA_DAC_RIGHT1, /* 15 */ EMU_DST_HANA_ADAT, /* 16 */ EMU_DST_HANA_ADAT+1, /* 17 */ EMU_DST_HANA_ADAT+2, /* 18 */ EMU_DST_HANA_ADAT+3, /* 19 */ EMU_DST_HANA_ADAT+4, /* 20 */ EMU_DST_HANA_ADAT+5, /* 21 */ EMU_DST_HANA_ADAT+6, /* 22 */ EMU_DST_HANA_ADAT+7, /* 23 */ }; /* 1616(m) cardbus */ static unsigned int emu1616_output_dst[] = { EMU_DST_DOCK_DAC1_LEFT1, EMU_DST_DOCK_DAC1_RIGHT1, EMU_DST_DOCK_DAC2_LEFT1, EMU_DST_DOCK_DAC2_RIGHT1, EMU_DST_DOCK_DAC3_LEFT1, EMU_DST_DOCK_DAC3_RIGHT1, EMU_DST_MDOCK_SPDIF_LEFT1, EMU_DST_MDOCK_SPDIF_RIGHT1, EMU_DST_MDOCK_ADAT, EMU_DST_MDOCK_ADAT+1, EMU_DST_MDOCK_ADAT+2, EMU_DST_MDOCK_ADAT+3, EMU_DST_MDOCK_ADAT+4, EMU_DST_MDOCK_ADAT+5, EMU_DST_MDOCK_ADAT+6, EMU_DST_MDOCK_ADAT+7, EMU_DST_MANA_DAC_LEFT, EMU_DST_MANA_DAC_RIGHT, }; /* * Data destinations - HANA outputs going to Alice2 (audigy) for * capture (EMU32 + I2S links) * Each destination has an enum mixer control to choose a data source */ static unsigned int emu1010_input_dst[] = { EMU_DST_ALICE2_EMU32_0, EMU_DST_ALICE2_EMU32_1, EMU_DST_ALICE2_EMU32_2, EMU_DST_ALICE2_EMU32_3, EMU_DST_ALICE2_EMU32_4, EMU_DST_ALICE2_EMU32_5, EMU_DST_ALICE2_EMU32_6, EMU_DST_ALICE2_EMU32_7, EMU_DST_ALICE2_EMU32_8, EMU_DST_ALICE2_EMU32_9, EMU_DST_ALICE2_EMU32_A, EMU_DST_ALICE2_EMU32_B, EMU_DST_ALICE2_EMU32_C, EMU_DST_ALICE2_EMU32_D, EMU_DST_ALICE2_EMU32_E, EMU_DST_ALICE2_EMU32_F, EMU_DST_ALICE_I2S0_LEFT, EMU_DST_ALICE_I2S0_RIGHT, EMU_DST_ALICE_I2S1_LEFT, EMU_DST_ALICE_I2S1_RIGHT, EMU_DST_ALICE_I2S2_LEFT, EMU_DST_ALICE_I2S2_RIGHT, }; static int snd_emu1010_input_output_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); char **items; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616) { uinfo->value.enumerated.items = 49; items = emu1616_src_texts; } else { uinfo->value.enumerated.items = 53; items = emu1010_src_texts; } if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; strcpy(uinfo->value.enumerated.name, items[uinfo->value.enumerated.item]); return 0; } static int snd_emu1010_output_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int channel; channel = (kcontrol->private_value) & 0xff; /* Limit: emu1010_output_dst, emu->emu1010.output_source */ if (channel >= 24 || (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616 && channel >= 18)) return -EINVAL; ucontrol->value.enumerated.item[0] = emu->emu1010.output_source[channel]; return 0; } static int snd_emu1010_output_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int val; unsigned int channel; val = ucontrol->value.enumerated.item[0]; if (val >= 53 || (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616 && val >= 49)) return -EINVAL; channel = (kcontrol->private_value) & 0xff; /* Limit: emu1010_output_dst, emu->emu1010.output_source */ if (channel >= 24 || (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616 && channel >= 18)) return -EINVAL; if (emu->emu1010.output_source[channel] == val) return 0; emu->emu1010.output_source[channel] = val; if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616) snd_emu1010_fpga_link_dst_src_write(emu, emu1616_output_dst[channel], emu1616_src_regs[val]); else snd_emu1010_fpga_link_dst_src_write(emu, emu1010_output_dst[channel], emu1010_src_regs[val]); return 1; } static int snd_emu1010_input_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int channel; channel = (kcontrol->private_value) & 0xff; /* Limit: emu1010_input_dst, emu->emu1010.input_source */ if (channel >= 22) return -EINVAL; ucontrol->value.enumerated.item[0] = emu->emu1010.input_source[channel]; return 0; } static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int val; unsigned int channel; val = ucontrol->value.enumerated.item[0]; if (val >= 53 || (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616 && val >= 49)) return -EINVAL; channel = (kcontrol->private_value) & 0xff; /* Limit: emu1010_input_dst, emu->emu1010.input_source */ if (channel >= 22) return -EINVAL; if (emu->emu1010.input_source[channel] == val) return 0; emu->emu1010.input_source[channel] = val; if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616) snd_emu1010_fpga_link_dst_src_write(emu, emu1010_input_dst[channel], emu1616_src_regs[val]); else snd_emu1010_fpga_link_dst_src_write(emu, emu1010_input_dst[channel], emu1010_src_regs[val]); return 1; } #define EMU1010_SOURCE_OUTPUT(xname,chid) \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ .info = snd_emu1010_input_output_source_info, \ .get = snd_emu1010_output_source_get, \ .put = snd_emu1010_output_source_put, \ .private_value = chid \ } static struct snd_kcontrol_new snd_emu1010_output_enum_ctls[] __devinitdata = { EMU1010_SOURCE_OUTPUT("Dock DAC1 Left Playback Enum", 0), EMU1010_SOURCE_OUTPUT("Dock DAC1 Right Playback Enum", 1), EMU1010_SOURCE_OUTPUT("Dock DAC2 Left Playback Enum", 2), EMU1010_SOURCE_OUTPUT("Dock DAC2 Right Playback Enum", 3), EMU1010_SOURCE_OUTPUT("Dock DAC3 Left Playback Enum", 4), EMU1010_SOURCE_OUTPUT("Dock DAC3 Right Playback Enum", 5), EMU1010_SOURCE_OUTPUT("Dock DAC4 Left Playback Enum", 6), EMU1010_SOURCE_OUTPUT("Dock DAC4 Right Playback Enum", 7), EMU1010_SOURCE_OUTPUT("Dock Phones Left Playback Enum", 8), EMU1010_SOURCE_OUTPUT("Dock Phones Right Playback Enum", 9), EMU1010_SOURCE_OUTPUT("Dock SPDIF Left Playback Enum", 0xa), EMU1010_SOURCE_OUTPUT("Dock SPDIF Right Playback Enum", 0xb), EMU1010_SOURCE_OUTPUT("1010 SPDIF Left Playback Enum", 0xc), EMU1010_SOURCE_OUTPUT("1010 SPDIF Right Playback Enum", 0xd), EMU1010_SOURCE_OUTPUT("0202 DAC Left Playback Enum", 0xe), EMU1010_SOURCE_OUTPUT("0202 DAC Right Playback Enum", 0xf), EMU1010_SOURCE_OUTPUT("1010 ADAT 0 Playback Enum", 0x10), EMU1010_SOURCE_OUTPUT("1010 ADAT 1 Playback Enum", 0x11), EMU1010_SOURCE_OUTPUT("1010 ADAT 2 Playback Enum", 0x12), EMU1010_SOURCE_OUTPUT("1010 ADAT 3 Playback Enum", 0x13), EMU1010_SOURCE_OUTPUT("1010 ADAT 4 Playback Enum", 0x14), EMU1010_SOURCE_OUTPUT("1010 ADAT 5 Playback Enum", 0x15), EMU1010_SOURCE_OUTPUT("1010 ADAT 6 Playback Enum", 0x16), EMU1010_SOURCE_OUTPUT("1010 ADAT 7 Playback Enum", 0x17), }; /* 1616(m) cardbus */ static struct snd_kcontrol_new snd_emu1616_output_enum_ctls[] __devinitdata = { EMU1010_SOURCE_OUTPUT("Dock DAC1 Left Playback Enum", 0), EMU1010_SOURCE_OUTPUT("Dock DAC1 Right Playback Enum", 1), EMU1010_SOURCE_OUTPUT("Dock DAC2 Left Playback Enum", 2), EMU1010_SOURCE_OUTPUT("Dock DAC2 Right Playback Enum", 3), EMU1010_SOURCE_OUTPUT("Dock DAC3 Left Playback Enum", 4), EMU1010_SOURCE_OUTPUT("Dock DAC3 Right Playback Enum", 5), EMU1010_SOURCE_OUTPUT("Dock SPDIF Left Playback Enum", 6), EMU1010_SOURCE_OUTPUT("Dock SPDIF Right Playback Enum", 7), EMU1010_SOURCE_OUTPUT("Dock ADAT 0 Playback Enum", 8), EMU1010_SOURCE_OUTPUT("Dock ADAT 1 Playback Enum", 9), EMU1010_SOURCE_OUTPUT("Dock ADAT 2 Playback Enum", 0xa), EMU1010_SOURCE_OUTPUT("Dock ADAT 3 Playback Enum", 0xb), EMU1010_SOURCE_OUTPUT("Dock ADAT 4 Playback Enum", 0xc), EMU1010_SOURCE_OUTPUT("Dock ADAT 5 Playback Enum", 0xd), EMU1010_SOURCE_OUTPUT("Dock ADAT 6 Playback Enum", 0xe), EMU1010_SOURCE_OUTPUT("Dock ADAT 7 Playback Enum", 0xf), EMU1010_SOURCE_OUTPUT("Mana DAC Left Playback Enum", 0x10), EMU1010_SOURCE_OUTPUT("Mana DAC Right Playback Enum", 0x11), }; #define EMU1010_SOURCE_INPUT(xname,chid) \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ .info = snd_emu1010_input_output_source_info, \ .get = snd_emu1010_input_source_get, \ .put = snd_emu1010_input_source_put, \ .private_value = chid \ } static struct snd_kcontrol_new snd_emu1010_input_enum_ctls[] __devinitdata = { EMU1010_SOURCE_INPUT("DSP 0 Capture Enum", 0), EMU1010_SOURCE_INPUT("DSP 1 Capture Enum", 1), EMU1010_SOURCE_INPUT("DSP 2 Capture Enum", 2), EMU1010_SOURCE_INPUT("DSP 3 Capture Enum", 3), EMU1010_SOURCE_INPUT("DSP 4 Capture Enum", 4), EMU1010_SOURCE_INPUT("DSP 5 Capture Enum", 5), EMU1010_SOURCE_INPUT("DSP 6 Capture Enum", 6), EMU1010_SOURCE_INPUT("DSP 7 Capture Enum", 7), EMU1010_SOURCE_INPUT("DSP 8 Capture Enum", 8), EMU1010_SOURCE_INPUT("DSP 9 Capture Enum", 9), EMU1010_SOURCE_INPUT("DSP A Capture Enum", 0xa), EMU1010_SOURCE_INPUT("DSP B Capture Enum", 0xb), EMU1010_SOURCE_INPUT("DSP C Capture Enum", 0xc), EMU1010_SOURCE_INPUT("DSP D Capture Enum", 0xd), EMU1010_SOURCE_INPUT("DSP E Capture Enum", 0xe), EMU1010_SOURCE_INPUT("DSP F Capture Enum", 0xf), EMU1010_SOURCE_INPUT("DSP 10 Capture Enum", 0x10), EMU1010_SOURCE_INPUT("DSP 11 Capture Enum", 0x11), EMU1010_SOURCE_INPUT("DSP 12 Capture Enum", 0x12), EMU1010_SOURCE_INPUT("DSP 13 Capture Enum", 0x13), EMU1010_SOURCE_INPUT("DSP 14 Capture Enum", 0x14), EMU1010_SOURCE_INPUT("DSP 15 Capture Enum", 0x15), }; #define snd_emu1010_adc_pads_info snd_ctl_boolean_mono_info static int snd_emu1010_adc_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int mask = kcontrol->private_value & 0xff; ucontrol->value.integer.value[0] = (emu->emu1010.adc_pads & mask) ? 1 : 0; return 0; } static int snd_emu1010_adc_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int mask = kcontrol->private_value & 0xff; unsigned int val, cache; val = ucontrol->value.integer.value[0]; cache = emu->emu1010.adc_pads; if (val == 1) cache = cache | mask; else cache = cache & ~mask; if (cache != emu->emu1010.adc_pads) { snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, cache ); emu->emu1010.adc_pads = cache; } return 0; } #define EMU1010_ADC_PADS(xname,chid) \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ .info = snd_emu1010_adc_pads_info, \ .get = snd_emu1010_adc_pads_get, \ .put = snd_emu1010_adc_pads_put, \ .private_value = chid \ } static struct snd_kcontrol_new snd_emu1010_adc_pads[] __devinitdata = { EMU1010_ADC_PADS("ADC1 14dB PAD Audio Dock Capture Switch", EMU_HANA_DOCK_ADC_PAD1), EMU1010_ADC_PADS("ADC2 14dB PAD Audio Dock Capture Switch", EMU_HANA_DOCK_ADC_PAD2), EMU1010_ADC_PADS("ADC3 14dB PAD Audio Dock Capture Switch", EMU_HANA_DOCK_ADC_PAD3), EMU1010_ADC_PADS("ADC1 14dB PAD 0202 Capture Switch", EMU_HANA_0202_ADC_PAD1), }; #define snd_emu1010_dac_pads_info snd_ctl_boolean_mono_info static int snd_emu1010_dac_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int mask = kcontrol->private_value & 0xff; ucontrol->value.integer.value[0] = (emu->emu1010.dac_pads & mask) ? 1 : 0; return 0; } static int snd_emu1010_dac_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int mask = kcontrol->private_value & 0xff; unsigned int val, cache; val = ucontrol->value.integer.value[0]; cache = emu->emu1010.dac_pads; if (val == 1) cache = cache | mask; else cache = cache & ~mask; if (cache != emu->emu1010.dac_pads) { snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, cache ); emu->emu1010.dac_pads = cache; } return 0; } #define EMU1010_DAC_PADS(xname,chid) \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \ .info = snd_emu1010_dac_pads_info, \ .get = snd_emu1010_dac_pads_get, \ .put = snd_emu1010_dac_pads_put, \ .private_value = chid \ } static struct snd_kcontrol_new snd_emu1010_dac_pads[] __devinitdata = { EMU1010_DAC_PADS("DAC1 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD1), EMU1010_DAC_PADS("DAC2 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD2), EMU1010_DAC_PADS("DAC3 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD3), EMU1010_DAC_PADS("DAC4 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD4), EMU1010_DAC_PADS("DAC1 0202 14dB PAD Playback Switch", EMU_HANA_0202_DAC_PAD1), }; static int snd_emu1010_internal_clock_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static char *texts[4] = { "44100", "48000", "SPDIF", "ADAT" }; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = 4; if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0; } static int snd_emu1010_internal_clock_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = emu->emu1010.internal_clock; return 0; } static int snd_emu1010_internal_clock_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int val; int change = 0; val = ucontrol->value.enumerated.item[0] ; /* Limit: uinfo->value.enumerated.items = 4; */ if (val >= 4) return -EINVAL; change = (emu->emu1010.internal_clock != val); if (change) { emu->emu1010.internal_clock = val; switch (val) { case 0: /* 44100 */ /* Mute all */ snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE ); /* Default fallback clock 48kHz */ snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_44_1K ); /* Word Clock source, Internal 44.1kHz x1 */ snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_44_1K | EMU_HANA_WCLOCK_1X ); /* Set LEDs on Audio Dock */ snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, EMU_HANA_DOCK_LEDS_2_44K | EMU_HANA_DOCK_LEDS_2_LOCK ); /* Allow DLL to settle */ msleep(10); /* Unmute all */ snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE ); break; case 1: /* 48000 */ /* Mute all */ snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE ); /* Default fallback clock 48kHz */ snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K ); /* Word Clock source, Internal 48kHz x1 */ snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_1X ); /* Set LEDs on Audio Dock */ snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, EMU_HANA_DOCK_LEDS_2_48K | EMU_HANA_DOCK_LEDS_2_LOCK ); /* Allow DLL to settle */ msleep(10); /* Unmute all */ snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE ); break; case 2: /* Take clock from S/PDIF IN */ /* Mute all */ snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE ); /* Default fallback clock 48kHz */ snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K ); /* Word Clock source, sync to S/PDIF input */ snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_HANA_SPDIF_IN | EMU_HANA_WCLOCK_1X ); /* Set LEDs on Audio Dock */ snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, EMU_HANA_DOCK_LEDS_2_EXT | EMU_HANA_DOCK_LEDS_2_LOCK ); /* FIXME: We should set EMU_HANA_DOCK_LEDS_2_LOCK only when clock signal is present and valid */ /* Allow DLL to settle */ msleep(10); /* Unmute all */ snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE ); break; case 3: /* Take clock from ADAT IN */ /* Mute all */ snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE ); /* Default fallback clock 48kHz */ snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K ); /* Word Clock source, sync to ADAT input */ snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_HANA_ADAT_IN | EMU_HANA_WCLOCK_1X ); /* Set LEDs on Audio Dock */ snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, EMU_HANA_DOCK_LEDS_2_EXT | EMU_HANA_DOCK_LEDS_2_LOCK ); /* FIXME: We should set EMU_HANA_DOCK_LEDS_2_LOCK only when clock signal is present and valid */ /* Allow DLL to settle */ msleep(10); /* Unmute all */ snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE ); break; } } return change; } static struct snd_kcontrol_new snd_emu1010_internal_clock = { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Clock Internal Rate", .count = 1, .info = snd_emu1010_internal_clock_info, .get = snd_emu1010_internal_clock_get, .put = snd_emu1010_internal_clock_put }; static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { #if 0 static char *texts[4] = { "Unknown1", "Unknown2", "Mic", "Line" }; #endif static char *texts[2] = { "Mic", "Line" }; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = 2; if (uinfo->value.enumerated.item > 1) uinfo->value.enumerated.item = 1; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0; } static int snd_audigy_i2c_capture_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = emu->i2c_capture_source; return 0; } static int snd_audigy_i2c_capture_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int source_id; unsigned int ngain, ogain; u32 gpio; int change = 0; unsigned long flags; u32 source; /* If the capture source has changed, * update the capture volume from the cached value * for the particular source. */ source_id = ucontrol->value.enumerated.item[0]; /* Limit: uinfo->value.enumerated.items = 2; */ /* emu->i2c_capture_volume */ if (source_id >= 2) return -EINVAL; change = (emu->i2c_capture_source != source_id); if (change) { snd_emu10k1_i2c_write(emu, ADC_MUX, 0); /* Mute input */ spin_lock_irqsave(&emu->emu_lock, flags); gpio = inl(emu->port + A_IOCFG); if (source_id==0) outl(gpio | 0x4, emu->port + A_IOCFG); else outl(gpio & ~0x4, emu->port + A_IOCFG); spin_unlock_irqrestore(&emu->emu_lock, flags); ngain = emu->i2c_capture_volume[source_id][0]; /* Left */ ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */ if (ngain != ogain) snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff)); ngain = emu->i2c_capture_volume[source_id][1]; /* Right */ ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Right */ if (ngain != ogain) snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff)); source = 1 << (source_id + 2); snd_emu10k1_i2c_write(emu, ADC_MUX, source); /* Set source */ emu->i2c_capture_source = source_id; } return change; } static struct snd_kcontrol_new snd_audigy_i2c_capture_source = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Capture Source", .info = snd_audigy_i2c_capture_source_info, .get = snd_audigy_i2c_capture_source_get, .put = snd_audigy_i2c_capture_source_put }; static int snd_audigy_i2c_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = 255; return 0; } static int snd_audigy_i2c_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int source_id; source_id = kcontrol->private_value; /* Limit: emu->i2c_capture_volume */ /* capture_source: uinfo->value.enumerated.items = 2 */ if (source_id >= 2) return -EINVAL; ucontrol->value.integer.value[0] = emu->i2c_capture_volume[source_id][0]; ucontrol->value.integer.value[1] = emu->i2c_capture_volume[source_id][1]; return 0; } static int snd_audigy_i2c_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int ogain; unsigned int ngain; unsigned int source_id; int change = 0; source_id = kcontrol->private_value; /* Limit: emu->i2c_capture_volume */ /* capture_source: uinfo->value.enumerated.items = 2 */ if (source_id >= 2) return -EINVAL; ogain = emu->i2c_capture_volume[source_id][0]; /* Left */ ngain = ucontrol->value.integer.value[0]; if (ngain > 0xff) return 0; if (ogain != ngain) { if (emu->i2c_capture_source == source_id) snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff) ); emu->i2c_capture_volume[source_id][0] = ngain; change = 1; } ogain = emu->i2c_capture_volume[source_id][1]; /* Right */ ngain = ucontrol->value.integer.value[1]; if (ngain > 0xff) return 0; if (ogain != ngain) { if (emu->i2c_capture_source == source_id) snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff)); emu->i2c_capture_volume[source_id][1] = ngain; change = 1; } return change; } #define I2C_VOLUME(xname,chid) \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_audigy_i2c_volume_info, \ .get = snd_audigy_i2c_volume_get, \ .put = snd_audigy_i2c_volume_put, \ .tlv = { .p = snd_audigy_db_scale2 }, \ .private_value = chid \ } static struct snd_kcontrol_new snd_audigy_i2c_volume_ctls[] __devinitdata = { I2C_VOLUME("Mic Capture Volume", 0), I2C_VOLUME("Line Capture Volume", 0) }; #if 0 static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static char *texts[] = {"44100", "48000", "96000"}; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = 3; if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0; } static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int tmp; unsigned long flags; spin_lock_irqsave(&emu->reg_lock, flags); tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0); switch (tmp & A_SPDIF_RATE_MASK) { case A_SPDIF_44100: ucontrol->value.enumerated.item[0] = 0; break; case A_SPDIF_48000: ucontrol->value.enumerated.item[0] = 1; break; case A_SPDIF_96000: ucontrol->value.enumerated.item[0] = 2; break; default: ucontrol->value.enumerated.item[0] = 1; } spin_unlock_irqrestore(&emu->reg_lock, flags); return 0; } static int snd_audigy_spdif_output_rate_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); int change; unsigned int reg, val, tmp; unsigned long flags; switch(ucontrol->value.enumerated.item[0]) { case 0: val = A_SPDIF_44100; break; case 1: val = A_SPDIF_48000; break; case 2: val = A_SPDIF_96000; break; default: val = A_SPDIF_48000; break; } spin_lock_irqsave(&emu->reg_lock, flags); reg = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0); tmp = reg & ~A_SPDIF_RATE_MASK; tmp |= val; if ((change = (tmp != reg))) snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp); spin_unlock_irqrestore(&emu->reg_lock, flags); return change; } static struct snd_kcontrol_new snd_audigy_spdif_output_rate = { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Audigy SPDIF Output Sample Rate", .count = 1, .info = snd_audigy_spdif_output_rate_info, .get = snd_audigy_spdif_output_rate_get, .put = snd_audigy_spdif_output_rate_put }; #endif static int snd_emu10k1_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); int change; unsigned int val; unsigned long flags; /* Limit: emu->spdif_bits */ if (idx >= 3) return -EINVAL; val = (ucontrol->value.iec958.status[0] << 0) | (ucontrol->value.iec958.status[1] << 8) | (ucontrol->value.iec958.status[2] << 16) | (ucontrol->value.iec958.status[3] << 24); spin_lock_irqsave(&emu->reg_lock, flags); change = val != emu->spdif_bits[idx]; if (change) { snd_emu10k1_ptr_write(emu, SPCS0 + idx, 0, val); emu->spdif_bits[idx] = val; } spin_unlock_irqrestore(&emu->reg_lock, flags); return change; } static struct snd_kcontrol_new snd_emu10k1_spdif_mask_control = { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), .count = 3, .info = snd_emu10k1_spdif_info, .get = snd_emu10k1_spdif_get_mask }; static struct snd_kcontrol_new snd_emu10k1_spdif_control = { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), .count = 3, .info = snd_emu10k1_spdif_info, .get = snd_emu10k1_spdif_get, .put = snd_emu10k1_spdif_put }; static void update_emu10k1_fxrt(struct snd_emu10k1 *emu, int voice, unsigned char *route) { if (emu->audigy) { snd_emu10k1_ptr_write(emu, A_FXRT1, voice, snd_emu10k1_compose_audigy_fxrt1(route)); snd_emu10k1_ptr_write(emu, A_FXRT2, voice, snd_emu10k1_compose_audigy_fxrt2(route)); } else { snd_emu10k1_ptr_write(emu, FXRT, voice, snd_emu10k1_compose_send_routing(route)); } } static void update_emu10k1_send_volume(struct snd_emu10k1 *emu, int voice, unsigned char *volume) { snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_A, voice, volume[0]); snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_B, voice, volume[1]); snd_emu10k1_ptr_write(emu, PSST_FXSENDAMOUNT_C, voice, volume[2]); snd_emu10k1_ptr_write(emu, DSL_FXSENDAMOUNT_D, voice, volume[3]); if (emu->audigy) { unsigned int val = ((unsigned int)volume[4] << 24) | ((unsigned int)volume[5] << 16) | ((unsigned int)volume[6] << 8) | (unsigned int)volume[7]; snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice, val); } } /* PCM stream controls */ static int snd_emu10k1_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = emu->audigy ? 3*8 : 3*4; uinfo->value.integer.min = 0; uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f; return 0; } static int snd_emu10k1_send_routing_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { unsigned long flags; struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; int voice, idx; int num_efx = emu->audigy ? 8 : 4; int mask = emu->audigy ? 0x3f : 0x0f; spin_lock_irqsave(&emu->reg_lock, flags); for (voice = 0; voice < 3; voice++) for (idx = 0; idx < num_efx; idx++) ucontrol->value.integer.value[(voice * num_efx) + idx] = mix->send_routing[voice][idx] & mask; spin_unlock_irqrestore(&emu->reg_lock, flags); return 0; } static int snd_emu10k1_send_routing_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { unsigned long flags; struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; int change = 0, voice, idx, val; int num_efx = emu->audigy ? 8 : 4; int mask = emu->audigy ? 0x3f : 0x0f; spin_lock_irqsave(&emu->reg_lock, flags); for (voice = 0; voice < 3; voice++) for (idx = 0; idx < num_efx; idx++) { val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask; if (mix->send_routing[voice][idx] != val) { mix->send_routing[voice][idx] = val; change = 1; } } if (change && mix->epcm) { if (mix->epcm->voices[0] && mix->epcm->voices[1]) { update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number, &mix->send_routing[1][0]); update_emu10k1_fxrt(emu, mix->epcm->voices[1]->number, &mix->send_routing[2][0]); } else if (mix->epcm->voices[0]) { update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number, &mix->send_routing[0][0]); } } spin_unlock_irqrestore(&emu->reg_lock, flags); return change; } static struct snd_kcontrol_new snd_emu10k1_send_routing_control = { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "EMU10K1 PCM Send Routing", .count = 32, .info = snd_emu10k1_send_routing_info, .get = snd_emu10k1_send_routing_get, .put = snd_emu10k1_send_routing_put }; static int snd_emu10k1_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = emu->audigy ? 3*8 : 3*4; uinfo->value.integer.min = 0; uinfo->value.integer.max = 255; return 0; } static int snd_emu10k1_send_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { unsigned long flags; struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; int idx; int num_efx = emu->audigy ? 8 : 4; spin_lock_irqsave(&emu->reg_lock, flags); for (idx = 0; idx < 3*num_efx; idx++) ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx]; spin_unlock_irqrestore(&emu->reg_lock, flags); return 0; } static int snd_emu10k1_send_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { unsigned long flags; struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; int change = 0, idx, val; int num_efx = emu->audigy ? 8 : 4; spin_lock_irqsave(&emu->reg_lock, flags); for (idx = 0; idx < 3*num_efx; idx++) { val = ucontrol->value.integer.value[idx] & 255; if (mix->send_volume[idx/num_efx][idx%num_efx] != val) { mix->send_volume[idx/num_efx][idx%num_efx] = val; change = 1; } } if (change && mix->epcm) { if (mix->epcm->voices[0] && mix->epcm->voices[1]) { update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number, &mix->send_volume[1][0]); update_emu10k1_send_volume(emu, mix->epcm->voices[1]->number, &mix->send_volume[2][0]); } else if (mix->epcm->voices[0]) { update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number, &mix->send_volume[0][0]); } } spin_unlock_irqrestore(&emu->reg_lock, flags); return change; } static struct snd_kcontrol_new snd_emu10k1_send_volume_control = { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "EMU10K1 PCM Send Volume", .count = 32, .info = snd_emu10k1_send_volume_info, .get = snd_emu10k1_send_volume_get, .put = snd_emu10k1_send_volume_put }; static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 3; uinfo->value.integer.min = 0; uinfo->value.integer.max = 0xffff; return 0; } static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; unsigned long flags; int idx; spin_lock_irqsave(&emu->reg_lock, flags); for (idx = 0; idx < 3; idx++) ucontrol->value.integer.value[idx] = mix->attn[idx]; spin_unlock_irqrestore(&emu->reg_lock, flags); return 0; } static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { unsigned long flags; struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; int change = 0, idx, val; spin_lock_irqsave(&emu->reg_lock, flags); for (idx = 0; idx < 3; idx++) { val = ucontrol->value.integer.value[idx] & 0xffff; if (mix->attn[idx] != val) { mix->attn[idx] = val; change = 1; } } if (change && mix->epcm) { if (mix->epcm->voices[0] && mix->epcm->voices[1]) { snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]); snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[1]->number, mix->attn[2]); } else if (mix->epcm->voices[0]) { snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]); } } spin_unlock_irqrestore(&emu->reg_lock, flags); return change; } static struct snd_kcontrol_new snd_emu10k1_attn_control = { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "EMU10K1 PCM Volume", .count = 32, .info = snd_emu10k1_attn_info, .get = snd_emu10k1_attn_get, .put = snd_emu10k1_attn_put }; /* Mutichannel PCM stream controls */ static int snd_emu10k1_efx_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = emu->audigy ? 8 : 4; uinfo->value.integer.min = 0; uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f; return 0; } static int snd_emu10k1_efx_send_routing_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { unsigned long flags; struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; int idx; int num_efx = emu->audigy ? 8 : 4; int mask = emu->audigy ? 0x3f : 0x0f; spin_lock_irqsave(&emu->reg_lock, flags); for (idx = 0; idx < num_efx; idx++) ucontrol->value.integer.value[idx] = mix->send_routing[0][idx] & mask; spin_unlock_irqrestore(&emu->reg_lock, flags); return 0; } static int snd_emu10k1_efx_send_routing_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { unsigned long flags; struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch]; int change = 0, idx, val; int num_efx = emu->audigy ? 8 : 4; int mask = emu->audigy ? 0x3f : 0x0f; spin_lock_irqsave(&emu->reg_lock, flags); for (idx = 0; idx < num_efx; idx++) { val = ucontrol->value.integer.value[idx] & mask; if (mix->send_routing[0][idx] != val) { mix->send_routing[0][idx] = val; change = 1; } } if (change && mix->epcm) { if (mix->epcm->voices[ch]) { update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number, &mix->send_routing[0][0]); } } spin_unlock_irqrestore(&emu->reg_lock, flags); return change; } static struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control = { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "Multichannel PCM Send Routing", .count = 16, .info = snd_emu10k1_efx_send_routing_info, .get = snd_emu10k1_efx_send_routing_get, .put = snd_emu10k1_efx_send_routing_put }; static int snd_emu10k1_efx_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = emu->audigy ? 8 : 4; uinfo->value.integer.min = 0; uinfo->value.integer.max = 255; return 0; } static int snd_emu10k1_efx_send_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { unsigned long flags; struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; int idx; int num_efx = emu->audigy ? 8 : 4; spin_lock_irqsave(&emu->reg_lock, flags); for (idx = 0; idx < num_efx; idx++) ucontrol->value.integer.value[idx] = mix->send_volume[0][idx]; spin_unlock_irqrestore(&emu->reg_lock, flags); return 0; } static int snd_emu10k1_efx_send_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { unsigned long flags; struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch]; int change = 0, idx, val; int num_efx = emu->audigy ? 8 : 4; spin_lock_irqsave(&emu->reg_lock, flags); for (idx = 0; idx < num_efx; idx++) { val = ucontrol->value.integer.value[idx] & 255; if (mix->send_volume[0][idx] != val) { mix->send_volume[0][idx] = val; change = 1; } } if (change && mix->epcm) { if (mix->epcm->voices[ch]) { update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number, &mix->send_volume[0][0]); } } spin_unlock_irqrestore(&emu->reg_lock, flags); return change; } static struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control = { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "Multichannel PCM Send Volume", .count = 16, .info = snd_emu10k1_efx_send_volume_info, .get = snd_emu10k1_efx_send_volume_get, .put = snd_emu10k1_efx_send_volume_put }; static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 0xffff; return 0; } static int snd_emu10k1_efx_attn_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; unsigned long flags; spin_lock_irqsave(&emu->reg_lock, flags); ucontrol->value.integer.value[0] = mix->attn[0]; spin_unlock_irqrestore(&emu->reg_lock, flags); return 0; } static int snd_emu10k1_efx_attn_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { unsigned long flags; struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch]; int change = 0, val; spin_lock_irqsave(&emu->reg_lock, flags); val = ucontrol->value.integer.value[0] & 0xffff; if (mix->attn[0] != val) { mix->attn[0] = val; change = 1; } if (change && mix->epcm) { if (mix->epcm->voices[ch]) { snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]); } } spin_unlock_irqrestore(&emu->reg_lock, flags); return change; } static struct snd_kcontrol_new snd_emu10k1_efx_attn_control = { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "Multichannel PCM Volume", .count = 16, .info = snd_emu10k1_efx_attn_info, .get = snd_emu10k1_efx_attn_get, .put = snd_emu10k1_efx_attn_put }; #define snd_emu10k1_shared_spdif_info snd_ctl_boolean_mono_info static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); if (emu->audigy) ucontrol->value.integer.value[0] = inl(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0; else ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0; if (emu->card_capabilities->invert_shared_spdif) ucontrol->value.integer.value[0] = !ucontrol->value.integer.value[0]; return 0; } static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { unsigned long flags; struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int reg, val, sw; int change = 0; sw = ucontrol->value.integer.value[0]; if (emu->card_capabilities->invert_shared_spdif) sw = !sw; spin_lock_irqsave(&emu->reg_lock, flags); if ( emu->card_capabilities->i2c_adc) { /* Do nothing for Audigy 2 ZS Notebook */ } else if (emu->audigy) { reg = inl(emu->port + A_IOCFG); val = sw ? A_IOCFG_GPOUT0 : 0; change = (reg & A_IOCFG_GPOUT0) != val; if (change) { reg &= ~A_IOCFG_GPOUT0; reg |= val; outl(reg | val, emu->port + A_IOCFG); } } reg = inl(emu->port + HCFG); val = sw ? HCFG_GPOUT0 : 0; change |= (reg & HCFG_GPOUT0) != val; if (change) { reg &= ~HCFG_GPOUT0; reg |= val; outl(reg | val, emu->port + HCFG); } spin_unlock_irqrestore(&emu->reg_lock, flags); return change; } static struct snd_kcontrol_new snd_emu10k1_shared_spdif __devinitdata = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "SB Live Analog/Digital Output Jack", .info = snd_emu10k1_shared_spdif_info, .get = snd_emu10k1_shared_spdif_get, .put = snd_emu10k1_shared_spdif_put }; static struct snd_kcontrol_new snd_audigy_shared_spdif __devinitdata = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Audigy Analog/Digital Output Jack", .info = snd_emu10k1_shared_spdif_info, .get = snd_emu10k1_shared_spdif_get, .put = snd_emu10k1_shared_spdif_put }; /* workaround for too low volume on Audigy due to 16bit/24bit conversion */ #define snd_audigy_capture_boost_info snd_ctl_boolean_mono_info static int snd_audigy_capture_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int val; /* FIXME: better to use a cached version */ val = snd_ac97_read(emu->ac97, AC97_REC_GAIN); ucontrol->value.integer.value[0] = !!val; return 0; } static int snd_audigy_capture_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); unsigned int val; if (ucontrol->value.integer.value[0]) val = 0x0f0f; else val = 0; return snd_ac97_update(emu->ac97, AC97_REC_GAIN, val); } static struct snd_kcontrol_new snd_audigy_capture_boost __devinitdata = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Analog Capture Boost", .info = snd_audigy_capture_boost_info, .get = snd_audigy_capture_boost_get, .put = snd_audigy_capture_boost_put }; /* */ static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97) { struct snd_emu10k1 *emu = ac97->private_data; emu->ac97 = NULL; } /* */ static int remove_ctl(struct snd_card *card, const char *name) { struct snd_ctl_elem_id id; memset(&id, 0, sizeof(id)); strcpy(id.name, name); id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; return snd_ctl_remove_id(card, &id); } static struct snd_kcontrol *ctl_find(struct snd_card *card, const char *name) { struct snd_ctl_elem_id sid; memset(&sid, 0, sizeof(sid)); strcpy(sid.name, name); sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; return snd_ctl_find_id(card, &sid); } static int rename_ctl(struct snd_card *card, const char *src, const char *dst) { struct snd_kcontrol *kctl = ctl_find(card, src); if (kctl) { strcpy(kctl->id.name, dst); return 0; } return -ENOENT; } int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu, int pcm_device, int multi_device) { int err, pcm; struct snd_kcontrol *kctl; struct snd_card *card = emu->card; char **c; static char *emu10k1_remove_ctls[] = { /* no AC97 mono, surround, center/lfe */ "Master Mono Playback Switch", "Master Mono Playback Volume", "PCM Out Path & Mute", "Mono Output Select", "Front Playback Switch", "Front Playback Volume", "Surround Playback Switch", "Surround Playback Volume", "Center Playback Switch", "Center Playback Volume", "LFE Playback Switch", "LFE Playback Volume", NULL }; static char *emu10k1_rename_ctls[] = { "Surround Digital Playback Volume", "Surround Playback Volume", "Center Digital Playback Volume", "Center Playback Volume", "LFE Digital Playback Volume", "LFE Playback Volume", NULL }; static char *audigy_remove_ctls[] = { /* Master/PCM controls on ac97 of Audigy has no effect */ /* On the Audigy2 the AC97 playback is piped into * the Philips ADC for 24bit capture */ "PCM Playback Switch", "PCM Playback Volume", "Master Mono Playback Switch", "Master Mono Playback Volume", "Master Playback Switch", "Master Playback Volume", "PCM Out Path & Mute", "Mono Output Select", /* remove unused AC97 capture controls */ "Capture Source", "Capture Switch", "Capture Volume", "Mic Select", "Video Playback Switch", "Video Playback Volume", "Mic Playback Switch", "Mic Playback Volume", NULL }; static char *audigy_rename_ctls[] = { /* use conventional names */ "Wave Playback Volume", "PCM Playback Volume", /* "Wave Capture Volume", "PCM Capture Volume", */ "Wave Master Playback Volume", "Master Playback Volume", "AMic Playback Volume", "Mic Playback Volume", NULL }; static char *audigy_rename_ctls_i2c_adc[] = { //"Analog Mix Capture Volume","OLD Analog Mix Capture Volume", "Line Capture Volume", "Analog Mix Capture Volume", "Wave Playback Volume", "OLD PCM Playback Volume", "Wave Master Playback Volume", "Master Playback Volume", "AMic Playback Volume", "Old Mic Playback Volume", "CD Capture Volume", "IEC958 Optical Capture Volume", NULL }; static char *audigy_remove_ctls_i2c_adc[] = { /* On the Audigy2 ZS Notebook * Capture via WM8775 */ "Mic Capture Volume", "Analog Mix Capture Volume", "Aux Capture Volume", "IEC958 Optical Capture Volume", NULL }; static char *audigy_remove_ctls_1361t_adc[] = { /* On the Audigy2 the AC97 playback is piped into * the Philips ADC for 24bit capture */ "PCM Playback Switch", "PCM Playback Volume", "Master Mono Playback Switch", "Master Mono Playback Volume", "Capture Source", "Capture Switch", "Capture Volume", "Mic Capture Volume", "Headphone Playback Switch", "Headphone Playback Volume", "3D Control - Center", "3D Control - Depth", "3D Control - Switch", "Line2 Playback Volume", "Line2 Capture Volume", NULL }; static char *audigy_rename_ctls_1361t_adc[] = { "Master Playback Switch", "Master Capture Switch", "Master Playback Volume", "Master Capture Volume", "Wave Master Playback Volume", "Master Playback Volume", "PC Speaker Playback Switch", "PC Speaker Capture Switch", "PC Speaker Playback Volume", "PC Speaker Capture Volume", "Phone Playback Switch", "Phone Capture Switch", "Phone Playback Volume", "Phone Capture Volume", "Mic Playback Switch", "Mic Capture Switch", "Mic Playback Volume", "Mic Capture Volume", "Line Playback Switch", "Line Capture Switch", "Line Playback Volume", "Line Capture Volume", "CD Playback Switch", "CD Capture Switch", "CD Playback Volume", "CD Capture Volume", "Aux Playback Switch", "Aux Capture Switch", "Aux Playback Volume", "Aux Capture Volume", "Video Playback Switch", "Video Capture Switch", "Video Playback Volume", "Video Capture Volume", NULL }; if (emu->card_capabilities->ac97_chip) { struct snd_ac97_bus *pbus; struct snd_ac97_template ac97; static struct snd_ac97_bus_ops ops = { .write = snd_emu10k1_ac97_write, .read = snd_emu10k1_ac97_read, }; if ((err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus)) < 0) return err; pbus->no_vra = 1; /* we don't need VRA */ memset(&ac97, 0, sizeof(ac97)); ac97.private_data = emu; ac97.private_free = snd_emu10k1_mixer_free_ac97; ac97.scaps = AC97_SCAP_NO_SPDIF; if ((err = snd_ac97_mixer(pbus, &ac97, &emu->ac97)) < 0) { if (emu->card_capabilities->ac97_chip == 1) return err; snd_printd(KERN_INFO "emu10k1: AC97 is optional on this board\n"); snd_printd(KERN_INFO" Proceeding without ac97 mixers...\n"); snd_device_free(emu->card, pbus); goto no_ac97; /* FIXME: get rid of ugly gotos.. */ } if (emu->audigy) { /* set master volume to 0 dB */ snd_ac97_write_cache(emu->ac97, AC97_MASTER, 0x0000); /* set capture source to mic */ snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000); if (emu->card_capabilities->adc_1361t) c = audigy_remove_ctls_1361t_adc; else c = audigy_remove_ctls; } else { /* * Credits for cards based on STAC9758: * James Courtier-Dutton <James@superbug.demon.co.uk> * Voluspa <voluspa@comhem.se> */ if (emu->ac97->id == AC97_ID_STAC9758) { emu->rear_ac97 = 1; snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT); snd_ac97_write_cache(emu->ac97, AC97_HEADPHONE, 0x0202); } /* remove unused AC97 controls */ snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202); snd_ac97_write_cache(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202); c = emu10k1_remove_ctls; } for (; *c; c++) remove_ctl(card, *c); } else if (emu->card_capabilities->i2c_adc) { c = audigy_remove_ctls_i2c_adc; for (; *c; c++) remove_ctl(card, *c); } else { no_ac97: if (emu->card_capabilities->ecard) strcpy(emu->card->mixername, "EMU APS"); else if (emu->audigy) strcpy(emu->card->mixername, "SB Audigy"); else strcpy(emu->card->mixername, "Emu10k1"); } if (emu->audigy) if (emu->card_capabilities->adc_1361t) c = audigy_rename_ctls_1361t_adc; else if (emu->card_capabilities->i2c_adc) c = audigy_rename_ctls_i2c_adc; else c = audigy_rename_ctls; else c = emu10k1_rename_ctls; for (; *c; c += 2) rename_ctl(card, c[0], c[1]); if (emu->card_capabilities->subsystem == 0x20071102) { /* Audigy 4 Pro */ rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume"); rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume"); rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume"); rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume"); remove_ctl(card, "Headphone Playback Switch"); remove_ctl(card, "Headphone Playback Volume"); remove_ctl(card, "3D Control - Center"); remove_ctl(card, "3D Control - Depth"); remove_ctl(card, "3D Control - Switch"); } if ((kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu)) == NULL) return -ENOMEM; kctl->id.device = pcm_device; if ((err = snd_ctl_add(card, kctl))) return err; if ((kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu)) == NULL) return -ENOMEM; kctl->id.device = pcm_device; if ((err = snd_ctl_add(card, kctl))) return err; if ((kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu)) == NULL) return -ENOMEM; kctl->id.device = pcm_device; if ((err = snd_ctl_add(card, kctl))) return err; if ((kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu)) == NULL) return -ENOMEM; kctl->id.device = multi_device; if ((err = snd_ctl_add(card, kctl))) return err; if ((kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu)) == NULL) return -ENOMEM; kctl->id.device = multi_device; if ((err = snd_ctl_add(card, kctl))) return err; if ((kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu)) == NULL) return -ENOMEM; kctl->id.device = multi_device; if ((err = snd_ctl_add(card, kctl))) return err; /* initialize the routing and volume table for each pcm playback stream */ for (pcm = 0; pcm < 32; pcm++) { struct snd_emu10k1_pcm_mixer *mix; int v; mix = &emu->pcm_mixer[pcm]; mix->epcm = NULL; for (v = 0; v < 4; v++) mix->send_routing[0][v] = mix->send_routing[1][v] = mix->send_routing[2][v] = v; memset(&mix->send_volume, 0, sizeof(mix->send_volume)); mix->send_volume[0][0] = mix->send_volume[0][1] = mix->send_volume[1][0] = mix->send_volume[2][1] = 255; mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff; } /* initialize the routing and volume table for the multichannel playback stream */ for (pcm = 0; pcm < NUM_EFX_PLAYBACK; pcm++) { struct snd_emu10k1_pcm_mixer *mix; int v; mix = &emu->efx_pcm_mixer[pcm]; mix->epcm = NULL; mix->send_routing[0][0] = pcm; mix->send_routing[0][1] = (pcm == 0) ? 1 : 0; for (v = 0; v < 2; v++) mix->send_routing[0][2+v] = 13+v; if (emu->audigy) for (v = 0; v < 4; v++) mix->send_routing[0][4+v] = 60+v; memset(&mix->send_volume, 0, sizeof(mix->send_volume)); mix->send_volume[0][0] = 255; mix->attn[0] = 0xffff; } if (! emu->card_capabilities->ecard) { /* FIXME: APS has these controls? */ /* sb live! and audigy */ if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu)) == NULL) return -ENOMEM; if (!emu->audigy) kctl->id.device = emu->pcm_efx->device; if ((err = snd_ctl_add(card, kctl))) return err; if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu)) == NULL) return -ENOMEM; if (!emu->audigy) kctl->id.device = emu->pcm_efx->device; if ((err = snd_ctl_add(card, kctl))) return err; } if (emu->card_capabilities->emu_model) { ; /* Disable the snd_audigy_spdif_shared_spdif */ } else if (emu->audigy) { if ((kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu)) == NULL) return -ENOMEM; if ((err = snd_ctl_add(card, kctl))) return err; #if 0 if ((kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu)) == NULL) return -ENOMEM; if ((err = snd_ctl_add(card, kctl))) return err; #endif } else if (! emu->card_capabilities->ecard) { /* sb live! */ if ((kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu)) == NULL) return -ENOMEM; if ((err = snd_ctl_add(card, kctl))) return err; } if (emu->card_capabilities->ca0151_chip) { /* P16V */ if ((err = snd_p16v_mixer(emu))) return err; } if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616) { /* 1616(m) cardbus */ int i; for (i = 0; i < ARRAY_SIZE(snd_emu1616_output_enum_ctls); i++) { err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1616_output_enum_ctls[i], emu)); if (err < 0) return err; } for (i = 0; i < ARRAY_SIZE(snd_emu1010_input_enum_ctls); i++) { err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_input_enum_ctls[i], emu)); if (err < 0) return err; } for (i = 0; i < ARRAY_SIZE(snd_emu1010_adc_pads) - 2; i++) { err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_adc_pads[i], emu)); if (err < 0) return err; } for (i = 0; i < ARRAY_SIZE(snd_emu1010_dac_pads) - 2; i++) { err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_dac_pads[i], emu)); if (err < 0) return err; } err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_internal_clock, emu)); if (err < 0) return err; } else if (emu->card_capabilities->emu_model) { /* all other e-mu cards for now */ int i; for (i = 0; i < ARRAY_SIZE(snd_emu1010_output_enum_ctls); i++) { err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_output_enum_ctls[i], emu)); if (err < 0) return err; } for (i = 0; i < ARRAY_SIZE(snd_emu1010_input_enum_ctls); i++) { err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_input_enum_ctls[i], emu)); if (err < 0) return err; } for (i = 0; i < ARRAY_SIZE(snd_emu1010_adc_pads); i++) { err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_adc_pads[i], emu)); if (err < 0) return err; } for (i = 0; i < ARRAY_SIZE(snd_emu1010_dac_pads); i++) { err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_dac_pads[i], emu)); if (err < 0) return err; } err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_internal_clock, emu)); if (err < 0) return err; } if ( emu->card_capabilities->i2c_adc) { int i; err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_i2c_capture_source, emu)); if (err < 0) return err; for (i = 0; i < ARRAY_SIZE(snd_audigy_i2c_volume_ctls); i++) { err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_i2c_volume_ctls[i], emu)); if (err < 0) return err; } } if (emu->card_capabilities->ac97_chip && emu->audigy) { err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_capture_boost, emu)); if (err < 0) return err; } return 0; }
gpl-2.0
sencis/kernel_huawei_u8500
drivers/mtd/tests/mtd_speedtest.c
703
10857
/* * Copyright (C) 2007 Nokia 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. * * 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Test read and write speed of a MTD device. * * Author: Adrian Hunter <ext-adrian.hunter@nokia.com> */ #include <linux/init.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/err.h> #include <linux/mtd/mtd.h> #include <linux/sched.h> #define PRINT_PREF KERN_INFO "mtd_speedtest: " static int dev; module_param(dev, int, S_IRUGO); MODULE_PARM_DESC(dev, "MTD device number to use"); static struct mtd_info *mtd; static unsigned char *iobuf; static unsigned char *bbt; static int pgsize; static int ebcnt; static int pgcnt; static int goodebcnt; static struct timeval start, finish; static unsigned long next = 1; static inline unsigned int simple_rand(void) { next = next * 1103515245 + 12345; return (unsigned int)((next / 65536) % 32768); } static inline void simple_srand(unsigned long seed) { next = seed; } static void set_random_data(unsigned char *buf, size_t len) { size_t i; for (i = 0; i < len; ++i) buf[i] = simple_rand(); } static int erase_eraseblock(int ebnum) { int err; struct erase_info ei; loff_t addr = ebnum * mtd->erasesize; memset(&ei, 0, sizeof(struct erase_info)); ei.mtd = mtd; ei.addr = addr; ei.len = mtd->erasesize; err = mtd->erase(mtd, &ei); if (err) { printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); return err; } if (ei.state == MTD_ERASE_FAILED) { printk(PRINT_PREF "some erase error occurred at EB %d\n", ebnum); return -EIO; } return 0; } static int erase_whole_device(void) { int err; unsigned int i; for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = erase_eraseblock(i); if (err) return err; cond_resched(); } return 0; } static int write_eraseblock(int ebnum) { size_t written = 0; int err = 0; loff_t addr = ebnum * mtd->erasesize; err = mtd->write(mtd, addr, mtd->erasesize, &written, iobuf); if (err || written != mtd->erasesize) { printk(PRINT_PREF "error: write failed at %#llx\n", addr); if (!err) err = -EINVAL; } return err; } static int write_eraseblock_by_page(int ebnum) { size_t written = 0; int i, err = 0; loff_t addr = ebnum * mtd->erasesize; void *buf = iobuf; for (i = 0; i < pgcnt; i++) { err = mtd->write(mtd, addr, pgsize, &written, buf); if (err || written != pgsize) { printk(PRINT_PREF "error: write failed at %#llx\n", addr); if (!err) err = -EINVAL; break; } addr += pgsize; buf += pgsize; } return err; } static int write_eraseblock_by_2pages(int ebnum) { size_t written = 0, sz = pgsize * 2; int i, n = pgcnt / 2, err = 0; loff_t addr = ebnum * mtd->erasesize; void *buf = iobuf; for (i = 0; i < n; i++) { err = mtd->write(mtd, addr, sz, &written, buf); if (err || written != sz) { printk(PRINT_PREF "error: write failed at %#llx\n", addr); if (!err) err = -EINVAL; return err; } addr += sz; buf += sz; } if (pgcnt % 2) { err = mtd->write(mtd, addr, pgsize, &written, buf); if (err || written != pgsize) { printk(PRINT_PREF "error: write failed at %#llx\n", addr); if (!err) err = -EINVAL; } } return err; } static int read_eraseblock(int ebnum) { size_t read = 0; int err = 0; loff_t addr = ebnum * mtd->erasesize; err = mtd->read(mtd, addr, mtd->erasesize, &read, iobuf); /* Ignore corrected ECC errors */ if (err == -EUCLEAN) err = 0; if (err || read != mtd->erasesize) { printk(PRINT_PREF "error: read failed at %#llx\n", addr); if (!err) err = -EINVAL; } return err; } static int read_eraseblock_by_page(int ebnum) { size_t read = 0; int i, err = 0; loff_t addr = ebnum * mtd->erasesize; void *buf = iobuf; for (i = 0; i < pgcnt; i++) { err = mtd->read(mtd, addr, pgsize, &read, buf); /* Ignore corrected ECC errors */ if (err == -EUCLEAN) err = 0; if (err || read != pgsize) { printk(PRINT_PREF "error: read failed at %#llx\n", addr); if (!err) err = -EINVAL; break; } addr += pgsize; buf += pgsize; } return err; } static int read_eraseblock_by_2pages(int ebnum) { size_t read = 0, sz = pgsize * 2; int i, n = pgcnt / 2, err = 0; loff_t addr = ebnum * mtd->erasesize; void *buf = iobuf; for (i = 0; i < n; i++) { err = mtd->read(mtd, addr, sz, &read, buf); /* Ignore corrected ECC errors */ if (err == -EUCLEAN) err = 0; if (err || read != sz) { printk(PRINT_PREF "error: read failed at %#llx\n", addr); if (!err) err = -EINVAL; return err; } addr += sz; buf += sz; } if (pgcnt % 2) { err = mtd->read(mtd, addr, pgsize, &read, buf); /* Ignore corrected ECC errors */ if (err == -EUCLEAN) err = 0; if (err || read != pgsize) { printk(PRINT_PREF "error: read failed at %#llx\n", addr); if (!err) err = -EINVAL; } } return err; } static int is_block_bad(int ebnum) { loff_t addr = ebnum * mtd->erasesize; int ret; ret = mtd->block_isbad(mtd, addr); if (ret) printk(PRINT_PREF "block %d is bad\n", ebnum); return ret; } static inline void start_timing(void) { do_gettimeofday(&start); } static inline void stop_timing(void) { do_gettimeofday(&finish); } static long calc_speed(void) { long ms, k, speed; ms = (finish.tv_sec - start.tv_sec) * 1000 + (finish.tv_usec - start.tv_usec) / 1000; k = goodebcnt * mtd->erasesize / 1024; speed = (k * 1000) / ms; return speed; } static int scan_for_bad_eraseblocks(void) { int i, bad = 0; bbt = kmalloc(ebcnt, GFP_KERNEL); if (!bbt) { printk(PRINT_PREF "error: cannot allocate memory\n"); return -ENOMEM; } memset(bbt, 0 , ebcnt); printk(PRINT_PREF "scanning for bad eraseblocks\n"); for (i = 0; i < ebcnt; ++i) { bbt[i] = is_block_bad(i) ? 1 : 0; if (bbt[i]) bad += 1; cond_resched(); } printk(PRINT_PREF "scanned %d eraseblocks, %d are bad\n", i, bad); goodebcnt = ebcnt - bad; return 0; } static int __init mtd_speedtest_init(void) { int err, i; long speed; uint64_t tmp; printk(KERN_INFO "\n"); printk(KERN_INFO "=================================================\n"); printk(PRINT_PREF "MTD device: %d\n", dev); mtd = get_mtd_device(NULL, dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); printk(PRINT_PREF "error: cannot get MTD device\n"); return err; } if (mtd->writesize == 1) { printk(PRINT_PREF "not NAND flash, assume page size is 512 " "bytes.\n"); pgsize = 512; } else pgsize = mtd->writesize; tmp = mtd->size; do_div(tmp, mtd->erasesize); ebcnt = tmp; pgcnt = mtd->erasesize / mtd->writesize; printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " "page size %u, count of eraseblocks %u, pages per " "eraseblock %u, OOB size %u\n", (unsigned long long)mtd->size, mtd->erasesize, pgsize, ebcnt, pgcnt, mtd->oobsize); err = -ENOMEM; iobuf = kmalloc(mtd->erasesize, GFP_KERNEL); if (!iobuf) { printk(PRINT_PREF "error: cannot allocate memory\n"); goto out; } simple_srand(1); set_random_data(iobuf, mtd->erasesize); err = scan_for_bad_eraseblocks(); if (err) goto out; err = erase_whole_device(); if (err) goto out; /* Write all eraseblocks, 1 eraseblock at a time */ printk(PRINT_PREF "testing eraseblock write speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = write_eraseblock(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); printk(PRINT_PREF "eraseblock write speed is %ld KiB/s\n", speed); /* Read all eraseblocks, 1 eraseblock at a time */ printk(PRINT_PREF "testing eraseblock read speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = read_eraseblock(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); printk(PRINT_PREF "eraseblock read speed is %ld KiB/s\n", speed); err = erase_whole_device(); if (err) goto out; /* Write all eraseblocks, 1 page at a time */ printk(PRINT_PREF "testing page write speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = write_eraseblock_by_page(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); printk(PRINT_PREF "page write speed is %ld KiB/s\n", speed); /* Read all eraseblocks, 1 page at a time */ printk(PRINT_PREF "testing page read speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = read_eraseblock_by_page(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); printk(PRINT_PREF "page read speed is %ld KiB/s\n", speed); err = erase_whole_device(); if (err) goto out; /* Write all eraseblocks, 2 pages at a time */ printk(PRINT_PREF "testing 2 page write speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = write_eraseblock_by_2pages(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); printk(PRINT_PREF "2 page write speed is %ld KiB/s\n", speed); /* Read all eraseblocks, 2 pages at a time */ printk(PRINT_PREF "testing 2 page read speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = read_eraseblock_by_2pages(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); printk(PRINT_PREF "2 page read speed is %ld KiB/s\n", speed); /* Erase all eraseblocks */ printk(PRINT_PREF "Testing erase speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = erase_eraseblock(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); printk(PRINT_PREF "erase speed is %ld KiB/s\n", speed); printk(PRINT_PREF "finished\n"); out: kfree(iobuf); kfree(bbt); put_mtd_device(mtd); if (err) printk(PRINT_PREF "error %d occurred\n", err); printk(KERN_INFO "=================================================\n"); return err; } module_init(mtd_speedtest_init); static void __exit mtd_speedtest_exit(void) { return; } module_exit(mtd_speedtest_exit); MODULE_DESCRIPTION("Speed test module"); MODULE_AUTHOR("Adrian Hunter"); MODULE_LICENSE("GPL");
gpl-2.0
EmbeddedAndroid/linaro-android-3.1
drivers/gpu/drm/via/via_drv.c
2495
3009
/* * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved. * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved. * * 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, sub license, * 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 NON-INFRINGEMENT. IN NO EVENT SHALL * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS 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 "drmP.h" #include "via_drm.h" #include "via_drv.h" #include "drm_pciids.h" static struct pci_device_id pciidlist[] = { viadrv_PCI_IDS }; static struct drm_driver driver = { .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED, .load = via_driver_load, .unload = via_driver_unload, .context_dtor = via_final_context, .get_vblank_counter = via_get_vblank_counter, .enable_vblank = via_enable_vblank, .disable_vblank = via_disable_vblank, .irq_preinstall = via_driver_irq_preinstall, .irq_postinstall = via_driver_irq_postinstall, .irq_uninstall = via_driver_irq_uninstall, .irq_handler = via_driver_irq_handler, .dma_quiescent = via_driver_dma_quiescent, .reclaim_buffers = drm_core_reclaim_buffers, .reclaim_buffers_locked = NULL, .reclaim_buffers_idlelocked = via_reclaim_buffers_locked, .lastclose = via_lastclose, .ioctls = via_ioctls, .fops = { .owner = THIS_MODULE, .open = drm_open, .release = drm_release, .unlocked_ioctl = drm_ioctl, .mmap = drm_mmap, .poll = drm_poll, .fasync = drm_fasync, .llseek = noop_llseek, }, .name = DRIVER_NAME, .desc = DRIVER_DESC, .date = DRIVER_DATE, .major = DRIVER_MAJOR, .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, }; static struct pci_driver via_pci_driver = { .name = DRIVER_NAME, .id_table = pciidlist, }; static int __init via_init(void) { driver.num_ioctls = via_max_ioctl; via_init_command_verifier(); return drm_pci_init(&driver, &via_pci_driver); } static void __exit via_exit(void) { drm_pci_exit(&driver, &via_pci_driver); } module_init(via_init); module_exit(via_exit); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL and additional rights");
gpl-2.0
tchaari/android_kernel_samsung_crespo_jay
drivers/gpu/drm/via/via_drv.c
2495
3009
/* * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved. * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved. * * 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, sub license, * 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 NON-INFRINGEMENT. IN NO EVENT SHALL * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS 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 "drmP.h" #include "via_drm.h" #include "via_drv.h" #include "drm_pciids.h" static struct pci_device_id pciidlist[] = { viadrv_PCI_IDS }; static struct drm_driver driver = { .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED, .load = via_driver_load, .unload = via_driver_unload, .context_dtor = via_final_context, .get_vblank_counter = via_get_vblank_counter, .enable_vblank = via_enable_vblank, .disable_vblank = via_disable_vblank, .irq_preinstall = via_driver_irq_preinstall, .irq_postinstall = via_driver_irq_postinstall, .irq_uninstall = via_driver_irq_uninstall, .irq_handler = via_driver_irq_handler, .dma_quiescent = via_driver_dma_quiescent, .reclaim_buffers = drm_core_reclaim_buffers, .reclaim_buffers_locked = NULL, .reclaim_buffers_idlelocked = via_reclaim_buffers_locked, .lastclose = via_lastclose, .ioctls = via_ioctls, .fops = { .owner = THIS_MODULE, .open = drm_open, .release = drm_release, .unlocked_ioctl = drm_ioctl, .mmap = drm_mmap, .poll = drm_poll, .fasync = drm_fasync, .llseek = noop_llseek, }, .name = DRIVER_NAME, .desc = DRIVER_DESC, .date = DRIVER_DATE, .major = DRIVER_MAJOR, .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, }; static struct pci_driver via_pci_driver = { .name = DRIVER_NAME, .id_table = pciidlist, }; static int __init via_init(void) { driver.num_ioctls = via_max_ioctl; via_init_command_verifier(); return drm_pci_init(&driver, &via_pci_driver); } static void __exit via_exit(void) { drm_pci_exit(&driver, &via_pci_driver); } module_init(via_init); module_exit(via_exit); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL and additional rights");
gpl-2.0
PyYoshi/android_kernel_kyocera_isw12k
fs/ext4/ext4_jbd2.c
2751
3994
/* * Interface between ext4 and JBD */ #include "ext4_jbd2.h" #include <trace/events/ext4.h> int __ext4_journal_get_write_access(const char *where, unsigned int line, handle_t *handle, struct buffer_head *bh) { int err = 0; if (ext4_handle_valid(handle)) { err = jbd2_journal_get_write_access(handle, bh); if (err) ext4_journal_abort_handle(where, line, __func__, bh, handle, err); } return err; } /* * The ext4 forget function must perform a revoke if we are freeing data * which has been journaled. Metadata (eg. indirect blocks) must be * revoked in all cases. * * "bh" may be NULL: a metadata block may have been freed from memory * but there may still be a record of it in the journal, and that record * still needs to be revoked. * * If the handle isn't valid we're not journaling, but we still need to * call into ext4_journal_revoke() to put the buffer head. */ int __ext4_forget(const char *where, unsigned int line, handle_t *handle, int is_metadata, struct inode *inode, struct buffer_head *bh, ext4_fsblk_t blocknr) { int err; might_sleep(); trace_ext4_forget(inode, is_metadata, blocknr); BUFFER_TRACE(bh, "enter"); jbd_debug(4, "forgetting bh %p: is_metadata = %d, mode %o, " "data mode %x\n", bh, is_metadata, inode->i_mode, test_opt(inode->i_sb, DATA_FLAGS)); /* In the no journal case, we can just do a bforget and return */ if (!ext4_handle_valid(handle)) { bforget(bh); return 0; } /* Never use the revoke function if we are doing full data * journaling: there is no need to, and a V1 superblock won't * support it. Otherwise, only skip the revoke on un-journaled * data blocks. */ if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA || (!is_metadata && !ext4_should_journal_data(inode))) { if (bh) { BUFFER_TRACE(bh, "call jbd2_journal_forget"); err = jbd2_journal_forget(handle, bh); if (err) ext4_journal_abort_handle(where, line, __func__, bh, handle, err); return err; } return 0; } /* * data!=journal && (is_metadata || should_journal_data(inode)) */ BUFFER_TRACE(bh, "call jbd2_journal_revoke"); err = jbd2_journal_revoke(handle, blocknr, bh); if (err) { ext4_journal_abort_handle(where, line, __func__, bh, handle, err); __ext4_abort(inode->i_sb, where, line, "error %d when attempting revoke", err); } BUFFER_TRACE(bh, "exit"); return err; } int __ext4_journal_get_create_access(const char *where, unsigned int line, handle_t *handle, struct buffer_head *bh) { int err = 0; if (ext4_handle_valid(handle)) { err = jbd2_journal_get_create_access(handle, bh); if (err) ext4_journal_abort_handle(where, line, __func__, bh, handle, err); } return err; } int __ext4_handle_dirty_metadata(const char *where, unsigned int line, handle_t *handle, struct inode *inode, struct buffer_head *bh) { int err = 0; if (ext4_handle_valid(handle)) { err = jbd2_journal_dirty_metadata(handle, bh); if (err) ext4_journal_abort_handle(where, line, __func__, bh, handle, err); } else { if (inode) mark_buffer_dirty_inode(bh, inode); else mark_buffer_dirty(bh); if (inode && inode_needs_sync(inode)) { sync_dirty_buffer(bh); if (buffer_req(bh) && !buffer_uptodate(bh)) { struct ext4_super_block *es; es = EXT4_SB(inode->i_sb)->s_es; es->s_last_error_block = cpu_to_le64(bh->b_blocknr); ext4_error_inode(inode, where, line, bh->b_blocknr, "IO error syncing itable block"); err = -EIO; } } } return err; } int __ext4_handle_dirty_super(const char *where, unsigned int line, handle_t *handle, struct super_block *sb) { struct buffer_head *bh = EXT4_SB(sb)->s_sbh; int err = 0; if (ext4_handle_valid(handle)) { err = jbd2_journal_dirty_metadata(handle, bh); if (err) ext4_journal_abort_handle(where, line, __func__, bh, handle, err); } else sb->s_dirt = 1; return err; }
gpl-2.0
lce67/android_kernel_htc_inc
arch/x86/kernel/cpu/cpufreq/powernow-k6.c
4287
6705
/* * This file was based upon code in Powertweak Linux (http://powertweak.sf.net) * (C) 2000-2003 Dave Jones, Arjan van de Ven, Janne Pänkälä, * Dominik Brodowski. * * Licensed under the terms of the GNU GPL License version 2. * * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/cpufreq.h> #include <linux/ioport.h> #include <linux/timex.h> #include <linux/io.h> #include <asm/msr.h> #define POWERNOW_IOPORT 0xfff0 /* it doesn't matter where, as long as it is unused */ #define PFX "powernow-k6: " static unsigned int busfreq; /* FSB, in 10 kHz */ static unsigned int max_multiplier; /* Clock ratio multiplied by 10 - see table 27 in AMD#23446 */ static struct cpufreq_frequency_table clock_ratio[] = { {45, /* 000 -> 4.5x */ 0}, {50, /* 001 -> 5.0x */ 0}, {40, /* 010 -> 4.0x */ 0}, {55, /* 011 -> 5.5x */ 0}, {20, /* 100 -> 2.0x */ 0}, {30, /* 101 -> 3.0x */ 0}, {60, /* 110 -> 6.0x */ 0}, {35, /* 111 -> 3.5x */ 0}, {0, CPUFREQ_TABLE_END} }; /** * powernow_k6_get_cpu_multiplier - returns the current FSB multiplier * * Returns the current setting of the frequency multiplier. Core clock * speed is frequency of the Front-Side Bus multiplied with this value. */ static int powernow_k6_get_cpu_multiplier(void) { u64 invalue = 0; u32 msrval; msrval = POWERNOW_IOPORT + 0x1; wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */ invalue = inl(POWERNOW_IOPORT + 0x8); msrval = POWERNOW_IOPORT + 0x0; wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */ return clock_ratio[(invalue >> 5)&7].index; } /** * powernow_k6_set_state - set the PowerNow! multiplier * @best_i: clock_ratio[best_i] is the target multiplier * * Tries to change the PowerNow! multiplier */ static void powernow_k6_set_state(unsigned int best_i) { unsigned long outvalue = 0, invalue = 0; unsigned long msrval; struct cpufreq_freqs freqs; if (clock_ratio[best_i].index > max_multiplier) { printk(KERN_ERR PFX "invalid target frequency\n"); return; } freqs.old = busfreq * powernow_k6_get_cpu_multiplier(); freqs.new = busfreq * clock_ratio[best_i].index; freqs.cpu = 0; /* powernow-k6.c is UP only driver */ cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); /* we now need to transform best_i to the BVC format, see AMD#23446 */ outvalue = (1<<12) | (1<<10) | (1<<9) | (best_i<<5); msrval = POWERNOW_IOPORT + 0x1; wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */ invalue = inl(POWERNOW_IOPORT + 0x8); invalue = invalue & 0xf; outvalue = outvalue | invalue; outl(outvalue , (POWERNOW_IOPORT + 0x8)); msrval = POWERNOW_IOPORT + 0x0; wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */ cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); return; } /** * powernow_k6_verify - verifies a new CPUfreq policy * @policy: new policy * * Policy must be within lowest and highest possible CPU Frequency, * and at least one possible state must be within min and max. */ static int powernow_k6_verify(struct cpufreq_policy *policy) { return cpufreq_frequency_table_verify(policy, &clock_ratio[0]); } /** * powernow_k6_setpolicy - sets a new CPUFreq policy * @policy: new policy * @target_freq: the target frequency * @relation: how that frequency relates to achieved frequency * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) * * sets a new CPUFreq policy */ static int powernow_k6_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation) { unsigned int newstate = 0; if (cpufreq_frequency_table_target(policy, &clock_ratio[0], target_freq, relation, &newstate)) return -EINVAL; powernow_k6_set_state(newstate); return 0; } static int powernow_k6_cpu_init(struct cpufreq_policy *policy) { unsigned int i, f; int result; if (policy->cpu != 0) return -ENODEV; /* get frequencies */ max_multiplier = powernow_k6_get_cpu_multiplier(); busfreq = cpu_khz / max_multiplier; /* table init */ for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { f = clock_ratio[i].index; if (f > max_multiplier) clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID; else clock_ratio[i].frequency = busfreq * f; } /* cpuinfo and default policy values */ policy->cpuinfo.transition_latency = 200000; policy->cur = busfreq * max_multiplier; result = cpufreq_frequency_table_cpuinfo(policy, clock_ratio); if (result) return result; cpufreq_frequency_table_get_attr(clock_ratio, policy->cpu); return 0; } static int powernow_k6_cpu_exit(struct cpufreq_policy *policy) { unsigned int i; for (i = 0; i < 8; i++) { if (i == max_multiplier) powernow_k6_set_state(i); } cpufreq_frequency_table_put_attr(policy->cpu); return 0; } static unsigned int powernow_k6_get(unsigned int cpu) { unsigned int ret; ret = (busfreq * powernow_k6_get_cpu_multiplier()); return ret; } static struct freq_attr *powernow_k6_attr[] = { &cpufreq_freq_attr_scaling_available_freqs, NULL, }; static struct cpufreq_driver powernow_k6_driver = { .verify = powernow_k6_verify, .target = powernow_k6_target, .init = powernow_k6_cpu_init, .exit = powernow_k6_cpu_exit, .get = powernow_k6_get, .name = "powernow-k6", .owner = THIS_MODULE, .attr = powernow_k6_attr, }; /** * powernow_k6_init - initializes the k6 PowerNow! CPUFreq driver * * Initializes the K6 PowerNow! support. Returns -ENODEV on unsupported * devices, -EINVAL or -ENOMEM on problems during initiatization, and zero * on success. */ static int __init powernow_k6_init(void) { struct cpuinfo_x86 *c = &cpu_data(0); if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 5) || ((c->x86_model != 12) && (c->x86_model != 13))) return -ENODEV; if (!request_region(POWERNOW_IOPORT, 16, "PowerNow!")) { printk(KERN_INFO PFX "PowerNow IOPORT region already used.\n"); return -EIO; } if (cpufreq_register_driver(&powernow_k6_driver)) { release_region(POWERNOW_IOPORT, 16); return -EINVAL; } return 0; } /** * powernow_k6_exit - unregisters AMD K6-2+/3+ PowerNow! support * * Unregisters AMD K6-2+ / K6-3+ PowerNow! support. */ static void __exit powernow_k6_exit(void) { cpufreq_unregister_driver(&powernow_k6_driver); release_region(POWERNOW_IOPORT, 16); } MODULE_AUTHOR("Arjan van de Ven, Dave Jones <davej@redhat.com>, " "Dominik Brodowski <linux@brodo.de>"); MODULE_DESCRIPTION("PowerNow! driver for AMD K6-2+ / K6-3+ processors."); MODULE_LICENSE("GPL"); module_init(powernow_k6_init); module_exit(powernow_k6_exit);
gpl-2.0
Outernet-Project/outernetrx-linux
arch/mips/pci/ops-gt64xxx_pci0.c
4543
4172
/* * Copyright (C) 1999, 2000, 2004 MIPS Technologies, Inc. * All rights reserved. * Authors: Carsten Langgaard <carstenl@mips.com> * Maciej W. Rozycki <macro@mips.com> * * This program is free software; you can distribute 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 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 <linux/types.h> #include <linux/pci.h> #include <linux/kernel.h> #include <asm/gt64120.h> #define PCI_ACCESS_READ 0 #define PCI_ACCESS_WRITE 1 /* * PCI configuration cycle AD bus definition */ /* Type 0 */ #define PCI_CFG_TYPE0_REG_SHF 0 #define PCI_CFG_TYPE0_FUNC_SHF 8 /* Type 1 */ #define PCI_CFG_TYPE1_REG_SHF 0 #define PCI_CFG_TYPE1_FUNC_SHF 8 #define PCI_CFG_TYPE1_DEV_SHF 11 #define PCI_CFG_TYPE1_BUS_SHF 16 static int gt64xxx_pci0_pcibios_config_access(unsigned char access_type, struct pci_bus *bus, unsigned int devfn, int where, u32 * data) { unsigned char busnum = bus->number; u32 intr; if ((busnum == 0) && (devfn >= PCI_DEVFN(31, 0))) return -1; /* Because of a bug in the galileo (for slot 31). */ /* Clear cause register bits */ GT_WRITE(GT_INTRCAUSE_OFS, ~(GT_INTRCAUSE_MASABORT0_BIT | GT_INTRCAUSE_TARABORT0_BIT)); /* Setup address */ GT_WRITE(GT_PCI0_CFGADDR_OFS, (busnum << GT_PCI0_CFGADDR_BUSNUM_SHF) | (devfn << GT_PCI0_CFGADDR_FUNCTNUM_SHF) | ((where / 4) << GT_PCI0_CFGADDR_REGNUM_SHF) | GT_PCI0_CFGADDR_CONFIGEN_BIT); if (access_type == PCI_ACCESS_WRITE) { if (busnum == 0 && PCI_SLOT(devfn) == 0) { /* * The Galileo system controller is acting * differently than other devices. */ GT_WRITE(GT_PCI0_CFGDATA_OFS, *data); } else __GT_WRITE(GT_PCI0_CFGDATA_OFS, *data); } else { if (busnum == 0 && PCI_SLOT(devfn) == 0) { /* * The Galileo system controller is acting * differently than other devices. */ *data = GT_READ(GT_PCI0_CFGDATA_OFS); } else *data = __GT_READ(GT_PCI0_CFGDATA_OFS); } /* Check for master or target abort */ intr = GT_READ(GT_INTRCAUSE_OFS); if (intr & (GT_INTRCAUSE_MASABORT0_BIT | GT_INTRCAUSE_TARABORT0_BIT)) { /* Error occurred */ /* Clear bits */ GT_WRITE(GT_INTRCAUSE_OFS, ~(GT_INTRCAUSE_MASABORT0_BIT | GT_INTRCAUSE_TARABORT0_BIT)); return -1; } return 0; } /* * We can't address 8 and 16 bit words directly. Instead we have to * read/write a 32bit word and mask/modify the data we actually want. */ static int gt64xxx_pci0_pcibios_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 * val) { u32 data = 0; if (gt64xxx_pci0_pcibios_config_access(PCI_ACCESS_READ, bus, devfn, where, &data)) return PCIBIOS_DEVICE_NOT_FOUND; if (size == 1) *val = (data >> ((where & 3) << 3)) & 0xff; else if (size == 2) *val = (data >> ((where & 3) << 3)) & 0xffff; else *val = data; return PCIBIOS_SUCCESSFUL; } static int gt64xxx_pci0_pcibios_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val) { u32 data = 0; if (size == 4) data = val; else { if (gt64xxx_pci0_pcibios_config_access(PCI_ACCESS_READ, bus, devfn, where, &data)) return PCIBIOS_DEVICE_NOT_FOUND; if (size == 1) data = (data & ~(0xff << ((where & 3) << 3))) | (val << ((where & 3) << 3)); else if (size == 2) data = (data & ~(0xffff << ((where & 3) << 3))) | (val << ((where & 3) << 3)); } if (gt64xxx_pci0_pcibios_config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data)) return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_SUCCESSFUL; } struct pci_ops gt64xxx_pci0_ops = { .read = gt64xxx_pci0_pcibios_read, .write = gt64xxx_pci0_pcibios_write };
gpl-2.0
ganjafuzz/PureKernel-v2-CAF
tools/perf/util/evsel.c
4799
14536
/* * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> * * Parts came from builtin-{top,stat,record}.c, see those files for further * copyright notes. * * Released under the GPL v2. (and only v2, not any later version) */ #include <byteswap.h> #include "asm/bug.h" #include "evsel.h" #include "evlist.h" #include "util.h" #include "cpumap.h" #include "thread_map.h" #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0)) int __perf_evsel__sample_size(u64 sample_type) { u64 mask = sample_type & PERF_SAMPLE_MASK; int size = 0; int i; for (i = 0; i < 64; i++) { if (mask & (1ULL << i)) size++; } size *= sizeof(u64); return size; } void hists__init(struct hists *hists) { memset(hists, 0, sizeof(*hists)); hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT; hists->entries_in = &hists->entries_in_array[0]; hists->entries_collapsed = RB_ROOT; hists->entries = RB_ROOT; pthread_mutex_init(&hists->lock, NULL); } void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr, int idx) { evsel->idx = idx; evsel->attr = *attr; INIT_LIST_HEAD(&evsel->node); hists__init(&evsel->hists); } struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx) { struct perf_evsel *evsel = zalloc(sizeof(*evsel)); if (evsel != NULL) perf_evsel__init(evsel, attr, idx); return evsel; } void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, struct perf_evsel *first) { struct perf_event_attr *attr = &evsel->attr; int track = !evsel->idx; /* only the first counter needs these */ attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1; attr->inherit = !opts->no_inherit; attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING | PERF_FORMAT_ID; attr->sample_type |= PERF_SAMPLE_IP | PERF_SAMPLE_TID; /* * We default some events to a 1 default interval. But keep * it a weak assumption overridable by the user. */ if (!attr->sample_period || (opts->user_freq != UINT_MAX && opts->user_interval != ULLONG_MAX)) { if (opts->freq) { attr->sample_type |= PERF_SAMPLE_PERIOD; attr->freq = 1; attr->sample_freq = opts->freq; } else { attr->sample_period = opts->default_interval; } } if (opts->no_samples) attr->sample_freq = 0; if (opts->inherit_stat) attr->inherit_stat = 1; if (opts->sample_address) { attr->sample_type |= PERF_SAMPLE_ADDR; attr->mmap_data = track; } if (opts->call_graph) attr->sample_type |= PERF_SAMPLE_CALLCHAIN; if (opts->system_wide) attr->sample_type |= PERF_SAMPLE_CPU; if (opts->period) attr->sample_type |= PERF_SAMPLE_PERIOD; if (!opts->sample_id_all_missing && (opts->sample_time || opts->system_wide || !opts->no_inherit || opts->cpu_list)) attr->sample_type |= PERF_SAMPLE_TIME; if (opts->raw_samples) { attr->sample_type |= PERF_SAMPLE_TIME; attr->sample_type |= PERF_SAMPLE_RAW; attr->sample_type |= PERF_SAMPLE_CPU; } if (opts->no_delay) { attr->watermark = 0; attr->wakeup_events = 1; } if (opts->branch_stack) { attr->sample_type |= PERF_SAMPLE_BRANCH_STACK; attr->branch_sample_type = opts->branch_stack; } attr->mmap = track; attr->comm = track; if (!opts->target_pid && !opts->target_tid && !opts->system_wide && (!opts->group || evsel == first)) { attr->disabled = 1; attr->enable_on_exec = 1; } } int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads) { int cpu, thread; evsel->fd = xyarray__new(ncpus, nthreads, sizeof(int)); if (evsel->fd) { for (cpu = 0; cpu < ncpus; cpu++) { for (thread = 0; thread < nthreads; thread++) { FD(evsel, cpu, thread) = -1; } } } return evsel->fd != NULL ? 0 : -ENOMEM; } int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads) { evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id)); if (evsel->sample_id == NULL) return -ENOMEM; evsel->id = zalloc(ncpus * nthreads * sizeof(u64)); if (evsel->id == NULL) { xyarray__delete(evsel->sample_id); evsel->sample_id = NULL; return -ENOMEM; } return 0; } int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus) { evsel->counts = zalloc((sizeof(*evsel->counts) + (ncpus * sizeof(struct perf_counts_values)))); return evsel->counts != NULL ? 0 : -ENOMEM; } void perf_evsel__free_fd(struct perf_evsel *evsel) { xyarray__delete(evsel->fd); evsel->fd = NULL; } void perf_evsel__free_id(struct perf_evsel *evsel) { xyarray__delete(evsel->sample_id); evsel->sample_id = NULL; free(evsel->id); evsel->id = NULL; } void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads) { int cpu, thread; for (cpu = 0; cpu < ncpus; cpu++) for (thread = 0; thread < nthreads; ++thread) { close(FD(evsel, cpu, thread)); FD(evsel, cpu, thread) = -1; } } void perf_evsel__exit(struct perf_evsel *evsel) { assert(list_empty(&evsel->node)); xyarray__delete(evsel->fd); xyarray__delete(evsel->sample_id); free(evsel->id); } void perf_evsel__delete(struct perf_evsel *evsel) { perf_evsel__exit(evsel); close_cgroup(evsel->cgrp); free(evsel->name); free(evsel); } int __perf_evsel__read_on_cpu(struct perf_evsel *evsel, int cpu, int thread, bool scale) { struct perf_counts_values count; size_t nv = scale ? 3 : 1; if (FD(evsel, cpu, thread) < 0) return -EINVAL; if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1) < 0) return -ENOMEM; if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0) return -errno; if (scale) { if (count.run == 0) count.val = 0; else if (count.run < count.ena) count.val = (u64)((double)count.val * count.ena / count.run + 0.5); } else count.ena = count.run = 0; evsel->counts->cpu[cpu] = count; return 0; } int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads, bool scale) { size_t nv = scale ? 3 : 1; int cpu, thread; struct perf_counts_values *aggr = &evsel->counts->aggr, count; aggr->val = aggr->ena = aggr->run = 0; for (cpu = 0; cpu < ncpus; cpu++) { for (thread = 0; thread < nthreads; thread++) { if (FD(evsel, cpu, thread) < 0) continue; if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0) return -errno; aggr->val += count.val; if (scale) { aggr->ena += count.ena; aggr->run += count.run; } } } evsel->counts->scaled = 0; if (scale) { if (aggr->run == 0) { evsel->counts->scaled = -1; aggr->val = 0; return 0; } if (aggr->run < aggr->ena) { evsel->counts->scaled = 1; aggr->val = (u64)((double)aggr->val * aggr->ena / aggr->run + 0.5); } } else aggr->ena = aggr->run = 0; return 0; } static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, struct thread_map *threads, bool group, struct xyarray *group_fds) { int cpu, thread; unsigned long flags = 0; int pid = -1, err; if (evsel->fd == NULL && perf_evsel__alloc_fd(evsel, cpus->nr, threads->nr) < 0) return -ENOMEM; if (evsel->cgrp) { flags = PERF_FLAG_PID_CGROUP; pid = evsel->cgrp->fd; } for (cpu = 0; cpu < cpus->nr; cpu++) { int group_fd = group_fds ? GROUP_FD(group_fds, cpu) : -1; for (thread = 0; thread < threads->nr; thread++) { if (!evsel->cgrp) pid = threads->map[thread]; FD(evsel, cpu, thread) = sys_perf_event_open(&evsel->attr, pid, cpus->map[cpu], group_fd, flags); if (FD(evsel, cpu, thread) < 0) { err = -errno; goto out_close; } if (group && group_fd == -1) group_fd = FD(evsel, cpu, thread); } } return 0; out_close: do { while (--thread >= 0) { close(FD(evsel, cpu, thread)); FD(evsel, cpu, thread) = -1; } thread = threads->nr; } while (--cpu >= 0); return err; } void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads) { if (evsel->fd == NULL) return; perf_evsel__close_fd(evsel, ncpus, nthreads); perf_evsel__free_fd(evsel); evsel->fd = NULL; } static struct { struct cpu_map map; int cpus[1]; } empty_cpu_map = { .map.nr = 1, .cpus = { -1, }, }; static struct { struct thread_map map; int threads[1]; } empty_thread_map = { .map.nr = 1, .threads = { -1, }, }; int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, struct thread_map *threads, bool group, struct xyarray *group_fd) { if (cpus == NULL) { /* Work around old compiler warnings about strict aliasing */ cpus = &empty_cpu_map.map; } if (threads == NULL) threads = &empty_thread_map.map; return __perf_evsel__open(evsel, cpus, threads, group, group_fd); } int perf_evsel__open_per_cpu(struct perf_evsel *evsel, struct cpu_map *cpus, bool group, struct xyarray *group_fd) { return __perf_evsel__open(evsel, cpus, &empty_thread_map.map, group, group_fd); } int perf_evsel__open_per_thread(struct perf_evsel *evsel, struct thread_map *threads, bool group, struct xyarray *group_fd) { return __perf_evsel__open(evsel, &empty_cpu_map.map, threads, group, group_fd); } static int perf_event__parse_id_sample(const union perf_event *event, u64 type, struct perf_sample *sample) { const u64 *array = event->sample.array; array += ((event->header.size - sizeof(event->header)) / sizeof(u64)) - 1; if (type & PERF_SAMPLE_CPU) { u32 *p = (u32 *)array; sample->cpu = *p; array--; } if (type & PERF_SAMPLE_STREAM_ID) { sample->stream_id = *array; array--; } if (type & PERF_SAMPLE_ID) { sample->id = *array; array--; } if (type & PERF_SAMPLE_TIME) { sample->time = *array; array--; } if (type & PERF_SAMPLE_TID) { u32 *p = (u32 *)array; sample->pid = p[0]; sample->tid = p[1]; } return 0; } static bool sample_overlap(const union perf_event *event, const void *offset, u64 size) { const void *base = event; if (offset + size > base + event->header.size) return true; return false; } int perf_event__parse_sample(const union perf_event *event, u64 type, int sample_size, bool sample_id_all, struct perf_sample *data, bool swapped) { const u64 *array; /* * used for cross-endian analysis. See git commit 65014ab3 * for why this goofiness is needed. */ union { u64 val64; u32 val32[2]; } u; memset(data, 0, sizeof(*data)); data->cpu = data->pid = data->tid = -1; data->stream_id = data->id = data->time = -1ULL; data->period = 1; if (event->header.type != PERF_RECORD_SAMPLE) { if (!sample_id_all) return 0; return perf_event__parse_id_sample(event, type, data); } array = event->sample.array; if (sample_size + sizeof(event->header) > event->header.size) return -EFAULT; if (type & PERF_SAMPLE_IP) { data->ip = event->ip.ip; array++; } if (type & PERF_SAMPLE_TID) { u.val64 = *array; if (swapped) { /* undo swap of u64, then swap on individual u32s */ u.val64 = bswap_64(u.val64); u.val32[0] = bswap_32(u.val32[0]); u.val32[1] = bswap_32(u.val32[1]); } data->pid = u.val32[0]; data->tid = u.val32[1]; array++; } if (type & PERF_SAMPLE_TIME) { data->time = *array; array++; } data->addr = 0; if (type & PERF_SAMPLE_ADDR) { data->addr = *array; array++; } data->id = -1ULL; if (type & PERF_SAMPLE_ID) { data->id = *array; array++; } if (type & PERF_SAMPLE_STREAM_ID) { data->stream_id = *array; array++; } if (type & PERF_SAMPLE_CPU) { u.val64 = *array; if (swapped) { /* undo swap of u64, then swap on individual u32s */ u.val64 = bswap_64(u.val64); u.val32[0] = bswap_32(u.val32[0]); } data->cpu = u.val32[0]; array++; } if (type & PERF_SAMPLE_PERIOD) { data->period = *array; array++; } if (type & PERF_SAMPLE_READ) { fprintf(stderr, "PERF_SAMPLE_READ is unsupported for now\n"); return -1; } if (type & PERF_SAMPLE_CALLCHAIN) { if (sample_overlap(event, array, sizeof(data->callchain->nr))) return -EFAULT; data->callchain = (struct ip_callchain *)array; if (sample_overlap(event, array, data->callchain->nr)) return -EFAULT; array += 1 + data->callchain->nr; } if (type & PERF_SAMPLE_RAW) { const u64 *pdata; u.val64 = *array; if (WARN_ONCE(swapped, "Endianness of raw data not corrected!\n")) { /* undo swap of u64, then swap on individual u32s */ u.val64 = bswap_64(u.val64); u.val32[0] = bswap_32(u.val32[0]); u.val32[1] = bswap_32(u.val32[1]); } if (sample_overlap(event, array, sizeof(u32))) return -EFAULT; data->raw_size = u.val32[0]; pdata = (void *) array + sizeof(u32); if (sample_overlap(event, pdata, data->raw_size)) return -EFAULT; data->raw_data = (void *) pdata; array = (void *)array + data->raw_size + sizeof(u32); } if (type & PERF_SAMPLE_BRANCH_STACK) { u64 sz; data->branch_stack = (struct branch_stack *)array; array++; /* nr */ sz = data->branch_stack->nr * sizeof(struct branch_entry); sz /= sizeof(u64); array += sz; } return 0; } int perf_event__synthesize_sample(union perf_event *event, u64 type, const struct perf_sample *sample, bool swapped) { u64 *array; /* * used for cross-endian analysis. See git commit 65014ab3 * for why this goofiness is needed. */ union { u64 val64; u32 val32[2]; } u; array = event->sample.array; if (type & PERF_SAMPLE_IP) { event->ip.ip = sample->ip; array++; } if (type & PERF_SAMPLE_TID) { u.val32[0] = sample->pid; u.val32[1] = sample->tid; if (swapped) { /* * Inverse of what is done in perf_event__parse_sample */ u.val32[0] = bswap_32(u.val32[0]); u.val32[1] = bswap_32(u.val32[1]); u.val64 = bswap_64(u.val64); } *array = u.val64; array++; } if (type & PERF_SAMPLE_TIME) { *array = sample->time; array++; } if (type & PERF_SAMPLE_ADDR) { *array = sample->addr; array++; } if (type & PERF_SAMPLE_ID) { *array = sample->id; array++; } if (type & PERF_SAMPLE_STREAM_ID) { *array = sample->stream_id; array++; } if (type & PERF_SAMPLE_CPU) { u.val32[0] = sample->cpu; if (swapped) { /* * Inverse of what is done in perf_event__parse_sample */ u.val32[0] = bswap_32(u.val32[0]); u.val64 = bswap_64(u.val64); } *array = u.val64; array++; } if (type & PERF_SAMPLE_PERIOD) { *array = sample->period; array++; } return 0; }
gpl-2.0
EloYGomeZ/caf-j1-exp
drivers/macintosh/windfarm_pm91.c
4799
18629
/* * Windfarm PowerMac thermal control. SMU based 1 CPU desktop control loops * * (c) Copyright 2005 Benjamin Herrenschmidt, IBM Corp. * <benh@kernel.crashing.org> * * Released under the term of the GNU GPL v2. * * The algorithm used is the PID control algorithm, used the same * way the published Darwin code does, using the same values that * are present in the Darwin 8.2 snapshot property lists (note however * that none of the code has been re-used, it's a complete re-implementation * * The various control loops found in Darwin config file are: * * PowerMac9,1 * =========== * * Has 3 control loops: CPU fans is similar to PowerMac8,1 (though it doesn't * try to play with other control loops fans). Drive bay is rather basic PID * with one sensor and one fan. Slots area is a bit different as the Darwin * driver is supposed to be capable of working in a special "AGP" mode which * involves the presence of an AGP sensor and an AGP fan (possibly on the * AGP card itself). I can't deal with that special mode as I don't have * access to those additional sensor/fans for now (though ultimately, it would * be possible to add sensor objects for them) so I'm only implementing the * basic PCI slot control loop */ #include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/delay.h> #include <linux/slab.h> #include <linux/init.h> #include <linux/spinlock.h> #include <linux/wait.h> #include <linux/kmod.h> #include <linux/device.h> #include <linux/platform_device.h> #include <asm/prom.h> #include <asm/machdep.h> #include <asm/io.h> #include <asm/sections.h> #include <asm/smu.h> #include "windfarm.h" #include "windfarm_pid.h" #define VERSION "0.4" #undef DEBUG #ifdef DEBUG #define DBG(args...) printk(args) #else #define DBG(args...) do { } while(0) #endif /* define this to force CPU overtemp to 74 degree, useful for testing * the overtemp code */ #undef HACKED_OVERTEMP /* Controls & sensors */ static struct wf_sensor *sensor_cpu_power; static struct wf_sensor *sensor_cpu_temp; static struct wf_sensor *sensor_hd_temp; static struct wf_sensor *sensor_slots_power; static struct wf_control *fan_cpu_main; static struct wf_control *fan_cpu_second; static struct wf_control *fan_cpu_third; static struct wf_control *fan_hd; static struct wf_control *fan_slots; static struct wf_control *cpufreq_clamp; /* Set to kick the control loop into life */ static int wf_smu_all_controls_ok, wf_smu_all_sensors_ok, wf_smu_started; /* Failure handling.. could be nicer */ #define FAILURE_FAN 0x01 #define FAILURE_SENSOR 0x02 #define FAILURE_OVERTEMP 0x04 static unsigned int wf_smu_failure_state; static int wf_smu_readjust, wf_smu_skipping; /* * ****** CPU Fans Control Loop ****** * */ #define WF_SMU_CPU_FANS_INTERVAL 1 #define WF_SMU_CPU_FANS_MAX_HISTORY 16 /* State data used by the cpu fans control loop */ struct wf_smu_cpu_fans_state { int ticks; s32 cpu_setpoint; struct wf_cpu_pid_state pid; }; static struct wf_smu_cpu_fans_state *wf_smu_cpu_fans; /* * ****** Drive Fan Control Loop ****** * */ struct wf_smu_drive_fans_state { int ticks; s32 setpoint; struct wf_pid_state pid; }; static struct wf_smu_drive_fans_state *wf_smu_drive_fans; /* * ****** Slots Fan Control Loop ****** * */ struct wf_smu_slots_fans_state { int ticks; s32 setpoint; struct wf_pid_state pid; }; static struct wf_smu_slots_fans_state *wf_smu_slots_fans; /* * ***** Implementation ***** * */ static void wf_smu_create_cpu_fans(void) { struct wf_cpu_pid_param pid_param; const struct smu_sdbp_header *hdr; struct smu_sdbp_cpupiddata *piddata; struct smu_sdbp_fvt *fvt; s32 tmax, tdelta, maxpow, powadj; /* First, locate the PID params in SMU SBD */ hdr = smu_get_sdb_partition(SMU_SDB_CPUPIDDATA_ID, NULL); if (hdr == 0) { printk(KERN_WARNING "windfarm: CPU PID fan config not found " "max fan speed\n"); goto fail; } piddata = (struct smu_sdbp_cpupiddata *)&hdr[1]; /* Get the FVT params for operating point 0 (the only supported one * for now) in order to get tmax */ hdr = smu_get_sdb_partition(SMU_SDB_FVT_ID, NULL); if (hdr) { fvt = (struct smu_sdbp_fvt *)&hdr[1]; tmax = ((s32)fvt->maxtemp) << 16; } else tmax = 0x5e0000; /* 94 degree default */ /* Alloc & initialize state */ wf_smu_cpu_fans = kmalloc(sizeof(struct wf_smu_cpu_fans_state), GFP_KERNEL); if (wf_smu_cpu_fans == NULL) goto fail; wf_smu_cpu_fans->ticks = 1; /* Fill PID params */ pid_param.interval = WF_SMU_CPU_FANS_INTERVAL; pid_param.history_len = piddata->history_len; if (pid_param.history_len > WF_CPU_PID_MAX_HISTORY) { printk(KERN_WARNING "windfarm: History size overflow on " "CPU control loop (%d)\n", piddata->history_len); pid_param.history_len = WF_CPU_PID_MAX_HISTORY; } pid_param.gd = piddata->gd; pid_param.gp = piddata->gp; pid_param.gr = piddata->gr / pid_param.history_len; tdelta = ((s32)piddata->target_temp_delta) << 16; maxpow = ((s32)piddata->max_power) << 16; powadj = ((s32)piddata->power_adj) << 16; pid_param.tmax = tmax; pid_param.ttarget = tmax - tdelta; pid_param.pmaxadj = maxpow - powadj; pid_param.min = fan_cpu_main->ops->get_min(fan_cpu_main); pid_param.max = fan_cpu_main->ops->get_max(fan_cpu_main); wf_cpu_pid_init(&wf_smu_cpu_fans->pid, &pid_param); DBG("wf: CPU Fan control initialized.\n"); DBG(" ttarged=%d.%03d, tmax=%d.%03d, min=%d RPM, max=%d RPM\n", FIX32TOPRINT(pid_param.ttarget), FIX32TOPRINT(pid_param.tmax), pid_param.min, pid_param.max); return; fail: printk(KERN_WARNING "windfarm: CPU fan config not found\n" "for this machine model, max fan speed\n"); if (cpufreq_clamp) wf_control_set_max(cpufreq_clamp); if (fan_cpu_main) wf_control_set_max(fan_cpu_main); } static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st) { s32 new_setpoint, temp, power; int rc; if (--st->ticks != 0) { if (wf_smu_readjust) goto readjust; return; } st->ticks = WF_SMU_CPU_FANS_INTERVAL; rc = sensor_cpu_temp->ops->get_value(sensor_cpu_temp, &temp); if (rc) { printk(KERN_WARNING "windfarm: CPU temp sensor error %d\n", rc); wf_smu_failure_state |= FAILURE_SENSOR; return; } rc = sensor_cpu_power->ops->get_value(sensor_cpu_power, &power); if (rc) { printk(KERN_WARNING "windfarm: CPU power sensor error %d\n", rc); wf_smu_failure_state |= FAILURE_SENSOR; return; } DBG("wf_smu: CPU Fans tick ! CPU temp: %d.%03d, power: %d.%03d\n", FIX32TOPRINT(temp), FIX32TOPRINT(power)); #ifdef HACKED_OVERTEMP if (temp > 0x4a0000) wf_smu_failure_state |= FAILURE_OVERTEMP; #else if (temp > st->pid.param.tmax) wf_smu_failure_state |= FAILURE_OVERTEMP; #endif new_setpoint = wf_cpu_pid_run(&st->pid, power, temp); DBG("wf_smu: new_setpoint: %d RPM\n", (int)new_setpoint); if (st->cpu_setpoint == new_setpoint) return; st->cpu_setpoint = new_setpoint; readjust: if (fan_cpu_main && wf_smu_failure_state == 0) { rc = fan_cpu_main->ops->set_value(fan_cpu_main, st->cpu_setpoint); if (rc) { printk(KERN_WARNING "windfarm: CPU main fan" " error %d\n", rc); wf_smu_failure_state |= FAILURE_FAN; } } if (fan_cpu_second && wf_smu_failure_state == 0) { rc = fan_cpu_second->ops->set_value(fan_cpu_second, st->cpu_setpoint); if (rc) { printk(KERN_WARNING "windfarm: CPU second fan" " error %d\n", rc); wf_smu_failure_state |= FAILURE_FAN; } } if (fan_cpu_third && wf_smu_failure_state == 0) { rc = fan_cpu_main->ops->set_value(fan_cpu_third, st->cpu_setpoint); if (rc) { printk(KERN_WARNING "windfarm: CPU third fan" " error %d\n", rc); wf_smu_failure_state |= FAILURE_FAN; } } } static void wf_smu_create_drive_fans(void) { struct wf_pid_param param = { .interval = 5, .history_len = 2, .gd = 0x01e00000, .gp = 0x00500000, .gr = 0x00000000, .itarget = 0x00200000, }; /* Alloc & initialize state */ wf_smu_drive_fans = kmalloc(sizeof(struct wf_smu_drive_fans_state), GFP_KERNEL); if (wf_smu_drive_fans == NULL) { printk(KERN_WARNING "windfarm: Memory allocation error" " max fan speed\n"); goto fail; } wf_smu_drive_fans->ticks = 1; /* Fill PID params */ param.additive = (fan_hd->type == WF_CONTROL_RPM_FAN); param.min = fan_hd->ops->get_min(fan_hd); param.max = fan_hd->ops->get_max(fan_hd); wf_pid_init(&wf_smu_drive_fans->pid, &param); DBG("wf: Drive Fan control initialized.\n"); DBG(" itarged=%d.%03d, min=%d RPM, max=%d RPM\n", FIX32TOPRINT(param.itarget), param.min, param.max); return; fail: if (fan_hd) wf_control_set_max(fan_hd); } static void wf_smu_drive_fans_tick(struct wf_smu_drive_fans_state *st) { s32 new_setpoint, temp; int rc; if (--st->ticks != 0) { if (wf_smu_readjust) goto readjust; return; } st->ticks = st->pid.param.interval; rc = sensor_hd_temp->ops->get_value(sensor_hd_temp, &temp); if (rc) { printk(KERN_WARNING "windfarm: HD temp sensor error %d\n", rc); wf_smu_failure_state |= FAILURE_SENSOR; return; } DBG("wf_smu: Drive Fans tick ! HD temp: %d.%03d\n", FIX32TOPRINT(temp)); if (temp > (st->pid.param.itarget + 0x50000)) wf_smu_failure_state |= FAILURE_OVERTEMP; new_setpoint = wf_pid_run(&st->pid, temp); DBG("wf_smu: new_setpoint: %d\n", (int)new_setpoint); if (st->setpoint == new_setpoint) return; st->setpoint = new_setpoint; readjust: if (fan_hd && wf_smu_failure_state == 0) { rc = fan_hd->ops->set_value(fan_hd, st->setpoint); if (rc) { printk(KERN_WARNING "windfarm: HD fan error %d\n", rc); wf_smu_failure_state |= FAILURE_FAN; } } } static void wf_smu_create_slots_fans(void) { struct wf_pid_param param = { .interval = 1, .history_len = 8, .gd = 0x00000000, .gp = 0x00000000, .gr = 0x00020000, .itarget = 0x00000000 }; /* Alloc & initialize state */ wf_smu_slots_fans = kmalloc(sizeof(struct wf_smu_slots_fans_state), GFP_KERNEL); if (wf_smu_slots_fans == NULL) { printk(KERN_WARNING "windfarm: Memory allocation error" " max fan speed\n"); goto fail; } wf_smu_slots_fans->ticks = 1; /* Fill PID params */ param.additive = (fan_slots->type == WF_CONTROL_RPM_FAN); param.min = fan_slots->ops->get_min(fan_slots); param.max = fan_slots->ops->get_max(fan_slots); wf_pid_init(&wf_smu_slots_fans->pid, &param); DBG("wf: Slots Fan control initialized.\n"); DBG(" itarged=%d.%03d, min=%d RPM, max=%d RPM\n", FIX32TOPRINT(param.itarget), param.min, param.max); return; fail: if (fan_slots) wf_control_set_max(fan_slots); } static void wf_smu_slots_fans_tick(struct wf_smu_slots_fans_state *st) { s32 new_setpoint, power; int rc; if (--st->ticks != 0) { if (wf_smu_readjust) goto readjust; return; } st->ticks = st->pid.param.interval; rc = sensor_slots_power->ops->get_value(sensor_slots_power, &power); if (rc) { printk(KERN_WARNING "windfarm: Slots power sensor error %d\n", rc); wf_smu_failure_state |= FAILURE_SENSOR; return; } DBG("wf_smu: Slots Fans tick ! Slots power: %d.%03d\n", FIX32TOPRINT(power)); #if 0 /* Check what makes a good overtemp condition */ if (power > (st->pid.param.itarget + 0x50000)) wf_smu_failure_state |= FAILURE_OVERTEMP; #endif new_setpoint = wf_pid_run(&st->pid, power); DBG("wf_smu: new_setpoint: %d\n", (int)new_setpoint); if (st->setpoint == new_setpoint) return; st->setpoint = new_setpoint; readjust: if (fan_slots && wf_smu_failure_state == 0) { rc = fan_slots->ops->set_value(fan_slots, st->setpoint); if (rc) { printk(KERN_WARNING "windfarm: Slots fan error %d\n", rc); wf_smu_failure_state |= FAILURE_FAN; } } } /* * ****** Setup / Init / Misc ... ****** * */ static void wf_smu_tick(void) { unsigned int last_failure = wf_smu_failure_state; unsigned int new_failure; if (!wf_smu_started) { DBG("wf: creating control loops !\n"); wf_smu_create_drive_fans(); wf_smu_create_slots_fans(); wf_smu_create_cpu_fans(); wf_smu_started = 1; } /* Skipping ticks */ if (wf_smu_skipping && --wf_smu_skipping) return; wf_smu_failure_state = 0; if (wf_smu_drive_fans) wf_smu_drive_fans_tick(wf_smu_drive_fans); if (wf_smu_slots_fans) wf_smu_slots_fans_tick(wf_smu_slots_fans); if (wf_smu_cpu_fans) wf_smu_cpu_fans_tick(wf_smu_cpu_fans); wf_smu_readjust = 0; new_failure = wf_smu_failure_state & ~last_failure; /* If entering failure mode, clamp cpufreq and ramp all * fans to full speed. */ if (wf_smu_failure_state && !last_failure) { if (cpufreq_clamp) wf_control_set_max(cpufreq_clamp); if (fan_cpu_main) wf_control_set_max(fan_cpu_main); if (fan_cpu_second) wf_control_set_max(fan_cpu_second); if (fan_cpu_third) wf_control_set_max(fan_cpu_third); if (fan_hd) wf_control_set_max(fan_hd); if (fan_slots) wf_control_set_max(fan_slots); } /* If leaving failure mode, unclamp cpufreq and readjust * all fans on next iteration */ if (!wf_smu_failure_state && last_failure) { if (cpufreq_clamp) wf_control_set_min(cpufreq_clamp); wf_smu_readjust = 1; } /* Overtemp condition detected, notify and start skipping a couple * ticks to let the temperature go down */ if (new_failure & FAILURE_OVERTEMP) { wf_set_overtemp(); wf_smu_skipping = 2; } /* We only clear the overtemp condition if overtemp is cleared * _and_ no other failure is present. Since a sensor error will * clear the overtemp condition (can't measure temperature) at * the control loop levels, but we don't want to keep it clear * here in this case */ if (new_failure == 0 && last_failure & FAILURE_OVERTEMP) wf_clear_overtemp(); } static void wf_smu_new_control(struct wf_control *ct) { if (wf_smu_all_controls_ok) return; if (fan_cpu_main == NULL && !strcmp(ct->name, "cpu-rear-fan-0")) { if (wf_get_control(ct) == 0) fan_cpu_main = ct; } if (fan_cpu_second == NULL && !strcmp(ct->name, "cpu-rear-fan-1")) { if (wf_get_control(ct) == 0) fan_cpu_second = ct; } if (fan_cpu_third == NULL && !strcmp(ct->name, "cpu-front-fan-0")) { if (wf_get_control(ct) == 0) fan_cpu_third = ct; } if (cpufreq_clamp == NULL && !strcmp(ct->name, "cpufreq-clamp")) { if (wf_get_control(ct) == 0) cpufreq_clamp = ct; } if (fan_hd == NULL && !strcmp(ct->name, "drive-bay-fan")) { if (wf_get_control(ct) == 0) fan_hd = ct; } if (fan_slots == NULL && !strcmp(ct->name, "slots-fan")) { if (wf_get_control(ct) == 0) fan_slots = ct; } if (fan_cpu_main && (fan_cpu_second || fan_cpu_third) && fan_hd && fan_slots && cpufreq_clamp) wf_smu_all_controls_ok = 1; } static void wf_smu_new_sensor(struct wf_sensor *sr) { if (wf_smu_all_sensors_ok) return; if (sensor_cpu_power == NULL && !strcmp(sr->name, "cpu-power")) { if (wf_get_sensor(sr) == 0) sensor_cpu_power = sr; } if (sensor_cpu_temp == NULL && !strcmp(sr->name, "cpu-temp")) { if (wf_get_sensor(sr) == 0) sensor_cpu_temp = sr; } if (sensor_hd_temp == NULL && !strcmp(sr->name, "hd-temp")) { if (wf_get_sensor(sr) == 0) sensor_hd_temp = sr; } if (sensor_slots_power == NULL && !strcmp(sr->name, "slots-power")) { if (wf_get_sensor(sr) == 0) sensor_slots_power = sr; } if (sensor_cpu_power && sensor_cpu_temp && sensor_hd_temp && sensor_slots_power) wf_smu_all_sensors_ok = 1; } static int wf_smu_notify(struct notifier_block *self, unsigned long event, void *data) { switch(event) { case WF_EVENT_NEW_CONTROL: DBG("wf: new control %s detected\n", ((struct wf_control *)data)->name); wf_smu_new_control(data); wf_smu_readjust = 1; break; case WF_EVENT_NEW_SENSOR: DBG("wf: new sensor %s detected\n", ((struct wf_sensor *)data)->name); wf_smu_new_sensor(data); break; case WF_EVENT_TICK: if (wf_smu_all_controls_ok && wf_smu_all_sensors_ok) wf_smu_tick(); } return 0; } static struct notifier_block wf_smu_events = { .notifier_call = wf_smu_notify, }; static int wf_init_pm(void) { printk(KERN_INFO "windfarm: Initializing for Desktop G5 model\n"); return 0; } static int wf_smu_probe(struct platform_device *ddev) { wf_register_client(&wf_smu_events); return 0; } static int __devexit wf_smu_remove(struct platform_device *ddev) { wf_unregister_client(&wf_smu_events); /* XXX We don't have yet a guarantee that our callback isn't * in progress when returning from wf_unregister_client, so * we add an arbitrary delay. I'll have to fix that in the core */ msleep(1000); /* Release all sensors */ /* One more crappy race: I don't think we have any guarantee here * that the attribute callback won't race with the sensor beeing * disposed of, and I'm not 100% certain what best way to deal * with that except by adding locks all over... I'll do that * eventually but heh, who ever rmmod this module anyway ? */ if (sensor_cpu_power) wf_put_sensor(sensor_cpu_power); if (sensor_cpu_temp) wf_put_sensor(sensor_cpu_temp); if (sensor_hd_temp) wf_put_sensor(sensor_hd_temp); if (sensor_slots_power) wf_put_sensor(sensor_slots_power); /* Release all controls */ if (fan_cpu_main) wf_put_control(fan_cpu_main); if (fan_cpu_second) wf_put_control(fan_cpu_second); if (fan_cpu_third) wf_put_control(fan_cpu_third); if (fan_hd) wf_put_control(fan_hd); if (fan_slots) wf_put_control(fan_slots); if (cpufreq_clamp) wf_put_control(cpufreq_clamp); /* Destroy control loops state structures */ kfree(wf_smu_slots_fans); kfree(wf_smu_drive_fans); kfree(wf_smu_cpu_fans); return 0; } static struct platform_driver wf_smu_driver = { .probe = wf_smu_probe, .remove = __devexit_p(wf_smu_remove), .driver = { .name = "windfarm", .owner = THIS_MODULE, }, }; static int __init wf_smu_init(void) { int rc = -ENODEV; if (of_machine_is_compatible("PowerMac9,1")) rc = wf_init_pm(); if (rc == 0) { #ifdef MODULE request_module("windfarm_smu_controls"); request_module("windfarm_smu_sensors"); request_module("windfarm_lm75_sensor"); request_module("windfarm_cpufreq_clamp"); #endif /* MODULE */ platform_driver_register(&wf_smu_driver); } return rc; } static void __exit wf_smu_exit(void) { platform_driver_unregister(&wf_smu_driver); } module_init(wf_smu_init); module_exit(wf_smu_exit); MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>"); MODULE_DESCRIPTION("Thermal control logic for PowerMac9,1"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:windfarm");
gpl-2.0
SebastianFM/SebastianFM-kernel
drivers/regulator/wm831x-ldo.c
4799
21422
/* * wm831x-ldo.c -- LDO driver for the WM831x series * * Copyright 2009 Wolfson Microelectronics PLC. * * Author: Mark Brown <broonie@opensource.wolfsonmicro.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/module.h> #include <linux/moduleparam.h> #include <linux/init.h> #include <linux/bitops.h> #include <linux/err.h> #include <linux/i2c.h> #include <linux/platform_device.h> #include <linux/regulator/driver.h> #include <linux/slab.h> #include <linux/mfd/wm831x/core.h> #include <linux/mfd/wm831x/regulator.h> #include <linux/mfd/wm831x/pdata.h> #define WM831X_LDO_MAX_NAME 6 #define WM831X_LDO_CONTROL 0 #define WM831X_LDO_ON_CONTROL 1 #define WM831X_LDO_SLEEP_CONTROL 2 #define WM831X_ALIVE_LDO_ON_CONTROL 0 #define WM831X_ALIVE_LDO_SLEEP_CONTROL 1 struct wm831x_ldo { char name[WM831X_LDO_MAX_NAME]; struct regulator_desc desc; int base; struct wm831x *wm831x; struct regulator_dev *regulator; }; /* * Shared */ static int wm831x_ldo_is_enabled(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int mask = 1 << rdev_get_id(rdev); int reg; reg = wm831x_reg_read(wm831x, WM831X_LDO_ENABLE); if (reg < 0) return reg; if (reg & mask) return 1; else return 0; } static int wm831x_ldo_enable(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int mask = 1 << rdev_get_id(rdev); return wm831x_set_bits(wm831x, WM831X_LDO_ENABLE, mask, mask); } static int wm831x_ldo_disable(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int mask = 1 << rdev_get_id(rdev); return wm831x_set_bits(wm831x, WM831X_LDO_ENABLE, mask, 0); } static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data) { struct wm831x_ldo *ldo = data; regulator_notifier_call_chain(ldo->regulator, REGULATOR_EVENT_UNDER_VOLTAGE, NULL); return IRQ_HANDLED; } /* * General purpose LDOs */ #define WM831X_GP_LDO_SELECTOR_LOW 0xe #define WM831X_GP_LDO_MAX_SELECTOR 0x1f static int wm831x_gp_ldo_list_voltage(struct regulator_dev *rdev, unsigned int selector) { /* 0.9-1.6V in 50mV steps */ if (selector <= WM831X_GP_LDO_SELECTOR_LOW) return 900000 + (selector * 50000); /* 1.7-3.3V in 50mV steps */ if (selector <= WM831X_GP_LDO_MAX_SELECTOR) return 1600000 + ((selector - WM831X_GP_LDO_SELECTOR_LOW) * 100000); return -EINVAL; } static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg, int min_uV, int max_uV, unsigned *selector) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int vsel, ret; if (min_uV < 900000) vsel = 0; else if (min_uV < 1700000) vsel = ((min_uV - 900000) / 50000); else vsel = ((min_uV - 1700000) / 100000) + WM831X_GP_LDO_SELECTOR_LOW + 1; ret = wm831x_gp_ldo_list_voltage(rdev, vsel); if (ret < 0) return ret; if (ret < min_uV || ret > max_uV) return -EINVAL; *selector = vsel; return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, vsel); } static int wm831x_gp_ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, unsigned *selector) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); int reg = ldo->base + WM831X_LDO_ON_CONTROL; return wm831x_gp_ldo_set_voltage_int(rdev, reg, min_uV, max_uV, selector); } static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; unsigned int selector; return wm831x_gp_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); } static int wm831x_gp_ldo_get_voltage_sel(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int reg = ldo->base + WM831X_LDO_ON_CONTROL; int ret; ret = wm831x_reg_read(wm831x, reg); if (ret < 0) return ret; ret &= WM831X_LDO1_ON_VSEL_MASK; return ret; } static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int ctrl_reg = ldo->base + WM831X_LDO_CONTROL; int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; int ret; ret = wm831x_reg_read(wm831x, on_reg); if (ret < 0) return ret; if (!(ret & WM831X_LDO1_ON_MODE)) return REGULATOR_MODE_NORMAL; ret = wm831x_reg_read(wm831x, ctrl_reg); if (ret < 0) return ret; if (ret & WM831X_LDO1_LP_MODE) return REGULATOR_MODE_STANDBY; else return REGULATOR_MODE_IDLE; } static int wm831x_gp_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int ctrl_reg = ldo->base + WM831X_LDO_CONTROL; int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; int ret; switch (mode) { case REGULATOR_MODE_NORMAL: ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO1_ON_MODE, 0); if (ret < 0) return ret; break; case REGULATOR_MODE_IDLE: ret = wm831x_set_bits(wm831x, ctrl_reg, WM831X_LDO1_LP_MODE, 0); if (ret < 0) return ret; ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO1_ON_MODE, WM831X_LDO1_ON_MODE); if (ret < 0) return ret; break; case REGULATOR_MODE_STANDBY: ret = wm831x_set_bits(wm831x, ctrl_reg, WM831X_LDO1_LP_MODE, WM831X_LDO1_LP_MODE); if (ret < 0) return ret; ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO1_ON_MODE, WM831X_LDO1_ON_MODE); if (ret < 0) return ret; break; default: return -EINVAL; } return 0; } static int wm831x_gp_ldo_get_status(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int mask = 1 << rdev_get_id(rdev); int ret; /* Is the regulator on? */ ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS); if (ret < 0) return ret; if (!(ret & mask)) return REGULATOR_STATUS_OFF; /* Is it reporting under voltage? */ ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS); if (ret & mask) return REGULATOR_STATUS_ERROR; ret = wm831x_gp_ldo_get_mode(rdev); if (ret < 0) return ret; else return regulator_mode_to_status(ret); } static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev, int input_uV, int output_uV, int load_uA) { if (load_uA < 20000) return REGULATOR_MODE_STANDBY; if (load_uA < 50000) return REGULATOR_MODE_IDLE; return REGULATOR_MODE_NORMAL; } static struct regulator_ops wm831x_gp_ldo_ops = { .list_voltage = wm831x_gp_ldo_list_voltage, .get_voltage_sel = wm831x_gp_ldo_get_voltage_sel, .set_voltage = wm831x_gp_ldo_set_voltage, .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, .get_mode = wm831x_gp_ldo_get_mode, .set_mode = wm831x_gp_ldo_set_mode, .get_status = wm831x_gp_ldo_get_status, .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode, .is_enabled = wm831x_ldo_is_enabled, .enable = wm831x_ldo_enable, .disable = wm831x_ldo_disable, }; static __devinit int wm831x_gp_ldo_probe(struct platform_device *pdev) { struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); struct wm831x_pdata *pdata = wm831x->dev->platform_data; int id; struct wm831x_ldo *ldo; struct resource *res; int ret, irq; if (pdata && pdata->wm831x_num) id = (pdata->wm831x_num * 10) + 1; else id = 0; id = pdev->id - id; dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); if (pdata == NULL || pdata->ldo[id] == NULL) return -ENODEV; ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); if (ldo == NULL) { dev_err(&pdev->dev, "Unable to allocate private data\n"); return -ENOMEM; } ldo->wm831x = wm831x; res = platform_get_resource(pdev, IORESOURCE_IO, 0); if (res == NULL) { dev_err(&pdev->dev, "No I/O resource\n"); ret = -EINVAL; goto err; } ldo->base = res->start; snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); ldo->desc.name = ldo->name; ldo->desc.id = id; ldo->desc.type = REGULATOR_VOLTAGE; ldo->desc.n_voltages = WM831X_GP_LDO_MAX_SELECTOR + 1; ldo->desc.ops = &wm831x_gp_ldo_ops; ldo->desc.owner = THIS_MODULE; ldo->regulator = regulator_register(&ldo->desc, &pdev->dev, pdata->ldo[id], ldo, NULL); if (IS_ERR(ldo->regulator)) { ret = PTR_ERR(ldo->regulator); dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", id + 1, ret); goto err; } irq = platform_get_irq_byname(pdev, "UV"); ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, IRQF_TRIGGER_RISING, ldo->name, ldo); if (ret != 0) { dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", irq, ret); goto err_regulator; } platform_set_drvdata(pdev, ldo); return 0; err_regulator: regulator_unregister(ldo->regulator); err: return ret; } static __devexit int wm831x_gp_ldo_remove(struct platform_device *pdev) { struct wm831x_ldo *ldo = platform_get_drvdata(pdev); platform_set_drvdata(pdev, NULL); free_irq(platform_get_irq_byname(pdev, "UV"), ldo); regulator_unregister(ldo->regulator); return 0; } static struct platform_driver wm831x_gp_ldo_driver = { .probe = wm831x_gp_ldo_probe, .remove = __devexit_p(wm831x_gp_ldo_remove), .driver = { .name = "wm831x-ldo", .owner = THIS_MODULE, }, }; /* * Analogue LDOs */ #define WM831X_ALDO_SELECTOR_LOW 0xc #define WM831X_ALDO_MAX_SELECTOR 0x1f static int wm831x_aldo_list_voltage(struct regulator_dev *rdev, unsigned int selector) { /* 1-1.6V in 50mV steps */ if (selector <= WM831X_ALDO_SELECTOR_LOW) return 1000000 + (selector * 50000); /* 1.7-3.5V in 50mV steps */ if (selector <= WM831X_ALDO_MAX_SELECTOR) return 1600000 + ((selector - WM831X_ALDO_SELECTOR_LOW) * 100000); return -EINVAL; } static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg, int min_uV, int max_uV, unsigned *selector) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int vsel, ret; if (min_uV < 1000000) vsel = 0; else if (min_uV < 1700000) vsel = ((min_uV - 1000000) / 50000); else vsel = ((min_uV - 1700000) / 100000) + WM831X_ALDO_SELECTOR_LOW + 1; ret = wm831x_aldo_list_voltage(rdev, vsel); if (ret < 0) return ret; if (ret < min_uV || ret > max_uV) return -EINVAL; *selector = vsel; return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, vsel); } static int wm831x_aldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, unsigned *selector) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); int reg = ldo->base + WM831X_LDO_ON_CONTROL; return wm831x_aldo_set_voltage_int(rdev, reg, min_uV, max_uV, selector); } static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; unsigned int selector; return wm831x_aldo_set_voltage_int(rdev, reg, uV, uV, &selector); } static int wm831x_aldo_get_voltage_sel(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int reg = ldo->base + WM831X_LDO_ON_CONTROL; int ret; ret = wm831x_reg_read(wm831x, reg); if (ret < 0) return ret; ret &= WM831X_LDO7_ON_VSEL_MASK; return ret; } static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; int ret; ret = wm831x_reg_read(wm831x, on_reg); if (ret < 0) return 0; if (ret & WM831X_LDO7_ON_MODE) return REGULATOR_MODE_IDLE; else return REGULATOR_MODE_NORMAL; } static int wm831x_aldo_set_mode(struct regulator_dev *rdev, unsigned int mode) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; int ret; switch (mode) { case REGULATOR_MODE_NORMAL: ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 0); if (ret < 0) return ret; break; case REGULATOR_MODE_IDLE: ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, WM831X_LDO7_ON_MODE); if (ret < 0) return ret; break; default: return -EINVAL; } return 0; } static int wm831x_aldo_get_status(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int mask = 1 << rdev_get_id(rdev); int ret; /* Is the regulator on? */ ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS); if (ret < 0) return ret; if (!(ret & mask)) return REGULATOR_STATUS_OFF; /* Is it reporting under voltage? */ ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS); if (ret & mask) return REGULATOR_STATUS_ERROR; ret = wm831x_aldo_get_mode(rdev); if (ret < 0) return ret; else return regulator_mode_to_status(ret); } static struct regulator_ops wm831x_aldo_ops = { .list_voltage = wm831x_aldo_list_voltage, .get_voltage_sel = wm831x_aldo_get_voltage_sel, .set_voltage = wm831x_aldo_set_voltage, .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, .get_mode = wm831x_aldo_get_mode, .set_mode = wm831x_aldo_set_mode, .get_status = wm831x_aldo_get_status, .is_enabled = wm831x_ldo_is_enabled, .enable = wm831x_ldo_enable, .disable = wm831x_ldo_disable, }; static __devinit int wm831x_aldo_probe(struct platform_device *pdev) { struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); struct wm831x_pdata *pdata = wm831x->dev->platform_data; int id; struct wm831x_ldo *ldo; struct resource *res; int ret, irq; if (pdata && pdata->wm831x_num) id = (pdata->wm831x_num * 10) + 1; else id = 0; id = pdev->id - id; dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); if (pdata == NULL || pdata->ldo[id] == NULL) return -ENODEV; ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); if (ldo == NULL) { dev_err(&pdev->dev, "Unable to allocate private data\n"); return -ENOMEM; } ldo->wm831x = wm831x; res = platform_get_resource(pdev, IORESOURCE_IO, 0); if (res == NULL) { dev_err(&pdev->dev, "No I/O resource\n"); ret = -EINVAL; goto err; } ldo->base = res->start; snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); ldo->desc.name = ldo->name; ldo->desc.id = id; ldo->desc.type = REGULATOR_VOLTAGE; ldo->desc.n_voltages = WM831X_ALDO_MAX_SELECTOR + 1; ldo->desc.ops = &wm831x_aldo_ops; ldo->desc.owner = THIS_MODULE; ldo->regulator = regulator_register(&ldo->desc, &pdev->dev, pdata->ldo[id], ldo, NULL); if (IS_ERR(ldo->regulator)) { ret = PTR_ERR(ldo->regulator); dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", id + 1, ret); goto err; } irq = platform_get_irq_byname(pdev, "UV"); ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, IRQF_TRIGGER_RISING, ldo->name, ldo); if (ret != 0) { dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", irq, ret); goto err_regulator; } platform_set_drvdata(pdev, ldo); return 0; err_regulator: regulator_unregister(ldo->regulator); err: return ret; } static __devexit int wm831x_aldo_remove(struct platform_device *pdev) { struct wm831x_ldo *ldo = platform_get_drvdata(pdev); free_irq(platform_get_irq_byname(pdev, "UV"), ldo); regulator_unregister(ldo->regulator); return 0; } static struct platform_driver wm831x_aldo_driver = { .probe = wm831x_aldo_probe, .remove = __devexit_p(wm831x_aldo_remove), .driver = { .name = "wm831x-aldo", .owner = THIS_MODULE, }, }; /* * Alive LDO */ #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf static int wm831x_alive_ldo_list_voltage(struct regulator_dev *rdev, unsigned int selector) { /* 0.8-1.55V in 50mV steps */ if (selector <= WM831X_ALIVE_LDO_MAX_SELECTOR) return 800000 + (selector * 50000); return -EINVAL; } static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev, int reg, int min_uV, int max_uV, unsigned *selector) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int vsel, ret; vsel = (min_uV - 800000) / 50000; ret = wm831x_alive_ldo_list_voltage(rdev, vsel); if (ret < 0) return ret; if (ret < min_uV || ret > max_uV) return -EINVAL; *selector = vsel; return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, vsel); } static int wm831x_alive_ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, unsigned *selector) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); int reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; return wm831x_alive_ldo_set_voltage_int(rdev, reg, min_uV, max_uV, selector); } static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); int reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; unsigned selector; return wm831x_alive_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); } static int wm831x_alive_ldo_get_voltage_sel(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; int ret; ret = wm831x_reg_read(wm831x, reg); if (ret < 0) return ret; ret &= WM831X_LDO11_ON_VSEL_MASK; return ret; } static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) { struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); struct wm831x *wm831x = ldo->wm831x; int mask = 1 << rdev_get_id(rdev); int ret; /* Is the regulator on? */ ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS); if (ret < 0) return ret; if (ret & mask) return REGULATOR_STATUS_ON; else return REGULATOR_STATUS_OFF; } static struct regulator_ops wm831x_alive_ldo_ops = { .list_voltage = wm831x_alive_ldo_list_voltage, .get_voltage_sel = wm831x_alive_ldo_get_voltage_sel, .set_voltage = wm831x_alive_ldo_set_voltage, .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, .get_status = wm831x_alive_ldo_get_status, .is_enabled = wm831x_ldo_is_enabled, .enable = wm831x_ldo_enable, .disable = wm831x_ldo_disable, }; static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev) { struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); struct wm831x_pdata *pdata = wm831x->dev->platform_data; int id; struct wm831x_ldo *ldo; struct resource *res; int ret; if (pdata && pdata->wm831x_num) id = (pdata->wm831x_num * 10) + 1; else id = 0; id = pdev->id - id; dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); if (pdata == NULL || pdata->ldo[id] == NULL) return -ENODEV; ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); if (ldo == NULL) { dev_err(&pdev->dev, "Unable to allocate private data\n"); return -ENOMEM; } ldo->wm831x = wm831x; res = platform_get_resource(pdev, IORESOURCE_IO, 0); if (res == NULL) { dev_err(&pdev->dev, "No I/O resource\n"); ret = -EINVAL; goto err; } ldo->base = res->start; snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); ldo->desc.name = ldo->name; ldo->desc.id = id; ldo->desc.type = REGULATOR_VOLTAGE; ldo->desc.n_voltages = WM831X_ALIVE_LDO_MAX_SELECTOR + 1; ldo->desc.ops = &wm831x_alive_ldo_ops; ldo->desc.owner = THIS_MODULE; ldo->regulator = regulator_register(&ldo->desc, &pdev->dev, pdata->ldo[id], ldo, NULL); if (IS_ERR(ldo->regulator)) { ret = PTR_ERR(ldo->regulator); dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", id + 1, ret); goto err; } platform_set_drvdata(pdev, ldo); return 0; err: return ret; } static __devexit int wm831x_alive_ldo_remove(struct platform_device *pdev) { struct wm831x_ldo *ldo = platform_get_drvdata(pdev); regulator_unregister(ldo->regulator); return 0; } static struct platform_driver wm831x_alive_ldo_driver = { .probe = wm831x_alive_ldo_probe, .remove = __devexit_p(wm831x_alive_ldo_remove), .driver = { .name = "wm831x-alive-ldo", .owner = THIS_MODULE, }, }; static int __init wm831x_ldo_init(void) { int ret; ret = platform_driver_register(&wm831x_gp_ldo_driver); if (ret != 0) pr_err("Failed to register WM831x GP LDO driver: %d\n", ret); ret = platform_driver_register(&wm831x_aldo_driver); if (ret != 0) pr_err("Failed to register WM831x ALDO driver: %d\n", ret); ret = platform_driver_register(&wm831x_alive_ldo_driver); if (ret != 0) pr_err("Failed to register WM831x alive LDO driver: %d\n", ret); return 0; } subsys_initcall(wm831x_ldo_init); static void __exit wm831x_ldo_exit(void) { platform_driver_unregister(&wm831x_alive_ldo_driver); platform_driver_unregister(&wm831x_aldo_driver); platform_driver_unregister(&wm831x_gp_ldo_driver); } module_exit(wm831x_ldo_exit); /* Module information */ MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); MODULE_DESCRIPTION("WM831x LDO driver"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:wm831x-ldo"); MODULE_ALIAS("platform:wm831x-aldo"); MODULE_ALIAS("platform:wm831x-aliveldo");
gpl-2.0
AmperificSuperKANG/lge_kernel_loki
arch/powerpc/sysdev/mv64x60_pic.c
8127
8293
/* * Interrupt handling for Marvell mv64360/mv64460 host bridges (Discovery) * * Author: Dale Farnsworth <dale@farnsworth.org> * * 2007 (c) MontaVista, Software, 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/stddef.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/irq.h> #include <linux/interrupt.h> #include <linux/spinlock.h> #include <asm/byteorder.h> #include <asm/io.h> #include <asm/prom.h> #include <asm/irq.h> #include "mv64x60.h" /* Interrupt Controller Interface Registers */ #define MV64X60_IC_MAIN_CAUSE_LO 0x0004 #define MV64X60_IC_MAIN_CAUSE_HI 0x000c #define MV64X60_IC_CPU0_INTR_MASK_LO 0x0014 #define MV64X60_IC_CPU0_INTR_MASK_HI 0x001c #define MV64X60_IC_CPU0_SELECT_CAUSE 0x0024 #define MV64X60_HIGH_GPP_GROUPS 0x0f000000 #define MV64X60_SELECT_CAUSE_HIGH 0x40000000 /* General Purpose Pins Controller Interface Registers */ #define MV64x60_GPP_INTR_CAUSE 0x0008 #define MV64x60_GPP_INTR_MASK 0x000c #define MV64x60_LEVEL1_LOW 0 #define MV64x60_LEVEL1_HIGH 1 #define MV64x60_LEVEL1_GPP 2 #define MV64x60_LEVEL1_MASK 0x00000060 #define MV64x60_LEVEL1_OFFSET 5 #define MV64x60_LEVEL2_MASK 0x0000001f #define MV64x60_NUM_IRQS 96 static DEFINE_SPINLOCK(mv64x60_lock); static void __iomem *mv64x60_irq_reg_base; static void __iomem *mv64x60_gpp_reg_base; /* * Interrupt Controller Handling * * The interrupt controller handles three groups of interrupts: * main low: IRQ0-IRQ31 * main high: IRQ32-IRQ63 * gpp: IRQ64-IRQ95 * * This code handles interrupts in two levels. Level 1 selects the * interrupt group, and level 2 selects an IRQ within that group. * Each group has its own irq_chip structure. */ static u32 mv64x60_cached_low_mask; static u32 mv64x60_cached_high_mask = MV64X60_HIGH_GPP_GROUPS; static u32 mv64x60_cached_gpp_mask; static struct irq_domain *mv64x60_irq_host; /* * mv64x60_chip_low functions */ static void mv64x60_mask_low(struct irq_data *d) { int level2 = irqd_to_hwirq(d) & MV64x60_LEVEL2_MASK; unsigned long flags; spin_lock_irqsave(&mv64x60_lock, flags); mv64x60_cached_low_mask &= ~(1 << level2); out_le32(mv64x60_irq_reg_base + MV64X60_IC_CPU0_INTR_MASK_LO, mv64x60_cached_low_mask); spin_unlock_irqrestore(&mv64x60_lock, flags); (void)in_le32(mv64x60_irq_reg_base + MV64X60_IC_CPU0_INTR_MASK_LO); } static void mv64x60_unmask_low(struct irq_data *d) { int level2 = irqd_to_hwirq(d) & MV64x60_LEVEL2_MASK; unsigned long flags; spin_lock_irqsave(&mv64x60_lock, flags); mv64x60_cached_low_mask |= 1 << level2; out_le32(mv64x60_irq_reg_base + MV64X60_IC_CPU0_INTR_MASK_LO, mv64x60_cached_low_mask); spin_unlock_irqrestore(&mv64x60_lock, flags); (void)in_le32(mv64x60_irq_reg_base + MV64X60_IC_CPU0_INTR_MASK_LO); } static struct irq_chip mv64x60_chip_low = { .name = "mv64x60_low", .irq_mask = mv64x60_mask_low, .irq_mask_ack = mv64x60_mask_low, .irq_unmask = mv64x60_unmask_low, }; /* * mv64x60_chip_high functions */ static void mv64x60_mask_high(struct irq_data *d) { int level2 = irqd_to_hwirq(d) & MV64x60_LEVEL2_MASK; unsigned long flags; spin_lock_irqsave(&mv64x60_lock, flags); mv64x60_cached_high_mask &= ~(1 << level2); out_le32(mv64x60_irq_reg_base + MV64X60_IC_CPU0_INTR_MASK_HI, mv64x60_cached_high_mask); spin_unlock_irqrestore(&mv64x60_lock, flags); (void)in_le32(mv64x60_irq_reg_base + MV64X60_IC_CPU0_INTR_MASK_HI); } static void mv64x60_unmask_high(struct irq_data *d) { int level2 = irqd_to_hwirq(d) & MV64x60_LEVEL2_MASK; unsigned long flags; spin_lock_irqsave(&mv64x60_lock, flags); mv64x60_cached_high_mask |= 1 << level2; out_le32(mv64x60_irq_reg_base + MV64X60_IC_CPU0_INTR_MASK_HI, mv64x60_cached_high_mask); spin_unlock_irqrestore(&mv64x60_lock, flags); (void)in_le32(mv64x60_irq_reg_base + MV64X60_IC_CPU0_INTR_MASK_HI); } static struct irq_chip mv64x60_chip_high = { .name = "mv64x60_high", .irq_mask = mv64x60_mask_high, .irq_mask_ack = mv64x60_mask_high, .irq_unmask = mv64x60_unmask_high, }; /* * mv64x60_chip_gpp functions */ static void mv64x60_mask_gpp(struct irq_data *d) { int level2 = irqd_to_hwirq(d) & MV64x60_LEVEL2_MASK; unsigned long flags; spin_lock_irqsave(&mv64x60_lock, flags); mv64x60_cached_gpp_mask &= ~(1 << level2); out_le32(mv64x60_gpp_reg_base + MV64x60_GPP_INTR_MASK, mv64x60_cached_gpp_mask); spin_unlock_irqrestore(&mv64x60_lock, flags); (void)in_le32(mv64x60_gpp_reg_base + MV64x60_GPP_INTR_MASK); } static void mv64x60_mask_ack_gpp(struct irq_data *d) { int level2 = irqd_to_hwirq(d) & MV64x60_LEVEL2_MASK; unsigned long flags; spin_lock_irqsave(&mv64x60_lock, flags); mv64x60_cached_gpp_mask &= ~(1 << level2); out_le32(mv64x60_gpp_reg_base + MV64x60_GPP_INTR_MASK, mv64x60_cached_gpp_mask); out_le32(mv64x60_gpp_reg_base + MV64x60_GPP_INTR_CAUSE, ~(1 << level2)); spin_unlock_irqrestore(&mv64x60_lock, flags); (void)in_le32(mv64x60_gpp_reg_base + MV64x60_GPP_INTR_CAUSE); } static void mv64x60_unmask_gpp(struct irq_data *d) { int level2 = irqd_to_hwirq(d) & MV64x60_LEVEL2_MASK; unsigned long flags; spin_lock_irqsave(&mv64x60_lock, flags); mv64x60_cached_gpp_mask |= 1 << level2; out_le32(mv64x60_gpp_reg_base + MV64x60_GPP_INTR_MASK, mv64x60_cached_gpp_mask); spin_unlock_irqrestore(&mv64x60_lock, flags); (void)in_le32(mv64x60_gpp_reg_base + MV64x60_GPP_INTR_MASK); } static struct irq_chip mv64x60_chip_gpp = { .name = "mv64x60_gpp", .irq_mask = mv64x60_mask_gpp, .irq_mask_ack = mv64x60_mask_ack_gpp, .irq_unmask = mv64x60_unmask_gpp, }; /* * mv64x60_host_ops functions */ static struct irq_chip *mv64x60_chips[] = { [MV64x60_LEVEL1_LOW] = &mv64x60_chip_low, [MV64x60_LEVEL1_HIGH] = &mv64x60_chip_high, [MV64x60_LEVEL1_GPP] = &mv64x60_chip_gpp, }; static int mv64x60_host_map(struct irq_domain *h, unsigned int virq, irq_hw_number_t hwirq) { int level1; irq_set_status_flags(virq, IRQ_LEVEL); level1 = (hwirq & MV64x60_LEVEL1_MASK) >> MV64x60_LEVEL1_OFFSET; BUG_ON(level1 > MV64x60_LEVEL1_GPP); irq_set_chip_and_handler(virq, mv64x60_chips[level1], handle_level_irq); return 0; } static struct irq_domain_ops mv64x60_host_ops = { .map = mv64x60_host_map, }; /* * Global functions */ void __init mv64x60_init_irq(void) { struct device_node *np; phys_addr_t paddr; unsigned int size; const unsigned int *reg; unsigned long flags; np = of_find_compatible_node(NULL, NULL, "marvell,mv64360-gpp"); reg = of_get_property(np, "reg", &size); paddr = of_translate_address(np, reg); mv64x60_gpp_reg_base = ioremap(paddr, reg[1]); of_node_put(np); np = of_find_compatible_node(NULL, NULL, "marvell,mv64360-pic"); reg = of_get_property(np, "reg", &size); paddr = of_translate_address(np, reg); mv64x60_irq_reg_base = ioremap(paddr, reg[1]); mv64x60_irq_host = irq_domain_add_linear(np, MV64x60_NUM_IRQS, &mv64x60_host_ops, NULL); spin_lock_irqsave(&mv64x60_lock, flags); out_le32(mv64x60_gpp_reg_base + MV64x60_GPP_INTR_MASK, mv64x60_cached_gpp_mask); out_le32(mv64x60_irq_reg_base + MV64X60_IC_CPU0_INTR_MASK_LO, mv64x60_cached_low_mask); out_le32(mv64x60_irq_reg_base + MV64X60_IC_CPU0_INTR_MASK_HI, mv64x60_cached_high_mask); out_le32(mv64x60_gpp_reg_base + MV64x60_GPP_INTR_CAUSE, 0); out_le32(mv64x60_irq_reg_base + MV64X60_IC_MAIN_CAUSE_LO, 0); out_le32(mv64x60_irq_reg_base + MV64X60_IC_MAIN_CAUSE_HI, 0); spin_unlock_irqrestore(&mv64x60_lock, flags); } unsigned int mv64x60_get_irq(void) { u32 cause; int level1; irq_hw_number_t hwirq; int virq = NO_IRQ; cause = in_le32(mv64x60_irq_reg_base + MV64X60_IC_CPU0_SELECT_CAUSE); if (cause & MV64X60_SELECT_CAUSE_HIGH) { cause &= mv64x60_cached_high_mask; level1 = MV64x60_LEVEL1_HIGH; if (cause & MV64X60_HIGH_GPP_GROUPS) { cause = in_le32(mv64x60_gpp_reg_base + MV64x60_GPP_INTR_CAUSE); cause &= mv64x60_cached_gpp_mask; level1 = MV64x60_LEVEL1_GPP; } } else { cause &= mv64x60_cached_low_mask; level1 = MV64x60_LEVEL1_LOW; } if (cause) { hwirq = (level1 << MV64x60_LEVEL1_OFFSET) | __ilog2(cause); virq = irq_linear_revmap(mv64x60_irq_host, hwirq); } return virq; }
gpl-2.0
lenovo-a3-dev/kernel_lenovo_a3
drivers/video/sis/init301.c
11199
342437
/* $XFree86$ */ /* $XdotOrg$ */ /* * Mode initializing code (CRT2 section) * for SiS 300/305/540/630/730, * SiS 315/550/[M]650/651/[M]661[FGM]X/[M]74x[GX]/330/[M]76x[GX], * XGI V3XT/V5/V8, Z7 * (Universal module for Linux kernel framebuffer and X.org/XFree86 4.x) * * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria * * If distributed as part of the Linux kernel, the following license terms * apply: * * * 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 named License, * * or 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 * * Otherwise, the following license terms apply: * * * 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. * * 2) 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. * * 3) The name of the author may not be used to endorse or promote products * * derived from this software without specific prior written permission. * * * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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. * * Author: Thomas Winischhofer <thomas@winischhofer.net> * * Formerly based on non-functional code-fragements for 300 series by SiS, Inc. * Used by permission. * */ #if 1 #define SET_EMI /* 302LV/ELV: Set EMI values */ #endif #if 1 #define SET_PWD /* 301/302LV: Set PWD */ #endif #define COMPAL_HACK /* Needed for Compal 1400x1050 (EMI) */ #define COMPAQ_HACK /* Needed for Inventec/Compaq 1280x1024 (EMI) */ #define ASUS_HACK /* Needed for Asus A2H 1024x768 (EMI) */ #include "init301.h" #ifdef CONFIG_FB_SIS_300 #include "oem300.h" #endif #ifdef CONFIG_FB_SIS_315 #include "oem310.h" #endif #define SiS_I2CDELAY 1000 #define SiS_I2CDELAYSHORT 150 static unsigned short SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr); static void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val); /*********************************************/ /* HELPER: Lock/Unlock CRT2 */ /*********************************************/ void SiS_UnLockCRT2(struct SiS_Private *SiS_Pr) { if(SiS_Pr->ChipType == XGI_20) return; else if(SiS_Pr->ChipType >= SIS_315H) SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01); else SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01); } static void SiS_LockCRT2(struct SiS_Private *SiS_Pr) { if(SiS_Pr->ChipType == XGI_20) return; else if(SiS_Pr->ChipType >= SIS_315H) SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE); else SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE); } /*********************************************/ /* HELPER: Write SR11 */ /*********************************************/ static void SiS_SetRegSR11ANDOR(struct SiS_Private *SiS_Pr, unsigned short DataAND, unsigned short DataOR) { if(SiS_Pr->ChipType >= SIS_661) { DataAND &= 0x0f; DataOR &= 0x0f; } SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,DataAND,DataOR); } /*********************************************/ /* HELPER: Get Pointer to LCD structure */ /*********************************************/ #ifdef CONFIG_FB_SIS_315 static unsigned char * GetLCDStructPtr661(struct SiS_Private *SiS_Pr) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned char *myptr = NULL; unsigned short romindex = 0, reg = 0, idx = 0; /* Use the BIOS tables only for LVDS panels; TMDS is unreliable * due to the variaty of panels the BIOS doesn't know about. * Exception: If the BIOS has better knowledge (such as in case * of machines with a 301C and a panel that does not support DDC) * use the BIOS data as well. */ if((SiS_Pr->SiS_ROMNew) && ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) { if(SiS_Pr->ChipType < SIS_661) reg = 0x3c; else reg = 0x7d; idx = (SiS_GetReg(SiS_Pr->SiS_P3d4,reg) & 0x1f) * 26; if(idx < (8*26)) { myptr = (unsigned char *)&SiS_LCDStruct661[idx]; } romindex = SISGETROMW(0x100); if(romindex) { romindex += idx; myptr = &ROMAddr[romindex]; } } return myptr; } static unsigned short GetLCDStructPtr661_2(struct SiS_Private *SiS_Pr) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short romptr = 0; /* Use the BIOS tables only for LVDS panels; TMDS is unreliable * due to the variaty of panels the BIOS doesn't know about. * Exception: If the BIOS has better knowledge (such as in case * of machines with a 301C and a panel that does not support DDC) * use the BIOS data as well. */ if((SiS_Pr->SiS_ROMNew) && ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) { romptr = SISGETROMW(0x102); romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize); } return romptr; } #endif /*********************************************/ /* Adjust Rate for CRT2 */ /*********************************************/ static bool SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RRTI, unsigned short *i) { unsigned short checkmask=0, modeid, infoflag; modeid = SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID; if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { checkmask |= SupportRAMDAC2; if(SiS_Pr->ChipType >= SIS_315H) { checkmask |= SupportRAMDAC2_135; if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { checkmask |= SupportRAMDAC2_162; if(SiS_Pr->SiS_VBType & VB_SISRAMDAC202) { checkmask |= SupportRAMDAC2_202; } } } } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { checkmask |= SupportLCD; if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_VBType & VB_SISVB) { if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) { if(modeid == 0x2e) checkmask |= Support64048060Hz; } } } } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { checkmask |= SupportHiVision; } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) { checkmask |= SupportTV; if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { checkmask |= SupportTV1024; if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) { checkmask |= SupportYPbPr750p; } } } } } else { /* LVDS */ if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { checkmask |= SupportCHTV; } } if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { checkmask |= SupportLCD; } } /* Look backwards in table for matching CRT2 mode */ for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) { infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag; if(infoflag & checkmask) return true; if((*i) == 0) break; } /* Look through the whole mode-section of the table from the beginning * for a matching CRT2 mode if no mode was found yet. */ for((*i) = 0; ; (*i)++) { if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break; infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag; if(infoflag & checkmask) return true; } return false; } /*********************************************/ /* Get rate index */ /*********************************************/ unsigned short SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned short RRTI,i,backup_i; unsigned short modeflag,index,temp,backupindex; static const unsigned short LCDRefreshIndex[] = { 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }; /* Do NOT check for UseCustomMode here, will skrew up FIFO */ if(ModeNo == 0xfe) return 0; if(ModeNo <= 0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; } else { modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; } if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { if(modeflag & HalfDCLK) return 0; } } if(ModeNo < 0x14) return 0xFFFF; index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F; backupindex = index; if(index > 0) index--; if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) { if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { if(SiS_Pr->SiS_VBType & VB_NoLCD) index = 0; else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index = backupindex = 0; } if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) { temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)]; if(index > temp) index = temp; } } } else { if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0; if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) index = 0; } } } RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex; ModeNo = SiS_Pr->SiS_RefIndex[RRTI].ModeID; if(SiS_Pr->ChipType >= SIS_315H) { if(!(SiS_Pr->SiS_VBInfo & DriverMode)) { if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) || (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) { if(backupindex <= 1) RRTI++; } } } i = 0; do { if(SiS_Pr->SiS_RefIndex[RRTI + i].ModeID != ModeNo) break; temp = SiS_Pr->SiS_RefIndex[RRTI + i].Ext_InfoFlag; temp &= ModeTypeMask; if(temp < SiS_Pr->SiS_ModeType) break; i++; index--; } while(index != 0xFFFF); if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { temp = SiS_Pr->SiS_RefIndex[RRTI + i - 1].Ext_InfoFlag; if(temp & InterlaceMode) i++; } } i--; if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) { backup_i = i; if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RRTI, &i))) { i = backup_i; } } return (RRTI + i); } /*********************************************/ /* STORE CRT2 INFO in CR34 */ /*********************************************/ static void SiS_SaveCRT2Info(struct SiS_Private *SiS_Pr, unsigned short ModeNo) { unsigned short temp1, temp2; /* Store CRT1 ModeNo in CR34 */ SiS_SetReg(SiS_Pr->SiS_P3d4,0x34,ModeNo); temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8; temp2 = ~(SetInSlaveMode >> 8); SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1); } /*********************************************/ /* HELPER: GET SOME DATA FROM BIOS ROM */ /*********************************************/ #ifdef CONFIG_FB_SIS_300 static bool SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short temp,temp1; if(SiS_Pr->SiS_UseROM) { if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f); temp1 = SISGETROMW(0x23b); if(temp1 & temp) return true; } } return false; } static bool SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short temp,temp1; if(SiS_Pr->SiS_UseROM) { if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f); temp1 = SISGETROMW(0x23d); if(temp1 & temp) return true; } } return false; } #endif /*********************************************/ /* HELPER: DELAY FUNCTIONS */ /*********************************************/ void SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime) { while (delaytime-- > 0) SiS_GetReg(SiS_Pr->SiS_P3c4, 0x05); } #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) static void SiS_GenericDelay(struct SiS_Private *SiS_Pr, unsigned short delay) { SiS_DDC2Delay(SiS_Pr, delay * 36); } #endif #ifdef CONFIG_FB_SIS_315 static void SiS_LongDelay(struct SiS_Private *SiS_Pr, unsigned short delay) { while(delay--) { SiS_GenericDelay(SiS_Pr, 6623); } } #endif #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) static void SiS_ShortDelay(struct SiS_Private *SiS_Pr, unsigned short delay) { while(delay--) { SiS_GenericDelay(SiS_Pr, 66); } } #endif static void SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime) { #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short PanelID, DelayIndex, Delay=0; #endif if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36); if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_VBType & VB_SIS301) PanelID &= 0xf7; if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12; } DelayIndex = PanelID >> 4; if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) { Delay = 3; } else { if(DelayTime >= 2) DelayTime -= 2; if(!(DelayTime & 0x01)) { Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0]; } else { Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1]; } if(SiS_Pr->SiS_UseROM) { if(ROMAddr[0x220] & 0x40) { if(!(DelayTime & 0x01)) Delay = (unsigned short)ROMAddr[0x225]; else Delay = (unsigned short)ROMAddr[0x226]; } } } SiS_ShortDelay(SiS_Pr, Delay); #endif /* CONFIG_FB_SIS_300 */ } else { #ifdef CONFIG_FB_SIS_315 if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->ChipType <= SIS_315PRO) || (SiS_Pr->ChipType == SIS_330) || (SiS_Pr->SiS_ROMNew)) { if(!(DelayTime & 0x01)) { SiS_DDC2Delay(SiS_Pr, 0x1000); } else { SiS_DDC2Delay(SiS_Pr, 0x4000); } } else if((SiS_Pr->SiS_IF_DEF_LVDS == 1) /* || (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) || (SiS_Pr->SiS_CustomT == CUT_CLEVO1400) */ ) { /* 315 series, LVDS; Special */ if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36); if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) { if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1b) & 0x10)) PanelID = 0x12; } if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) { DelayIndex = PanelID & 0x0f; } else { DelayIndex = PanelID >> 4; } if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) { Delay = 3; } else { if(DelayTime >= 2) DelayTime -= 2; if(!(DelayTime & 0x01)) { Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0]; } else { Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1]; } if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) { if(ROMAddr[0x13c] & 0x40) { if(!(DelayTime & 0x01)) { Delay = (unsigned short)ROMAddr[0x17e]; } else { Delay = (unsigned short)ROMAddr[0x17f]; } } } } SiS_ShortDelay(SiS_Pr, Delay); } } else if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 315 series, all bridges */ DelayIndex = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4; if(!(DelayTime & 0x01)) { Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0]; } else { Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1]; } Delay <<= 8; SiS_DDC2Delay(SiS_Pr, Delay); } #endif /* CONFIG_FB_SIS_315 */ } } #ifdef CONFIG_FB_SIS_315 static void SiS_PanelDelayLoop(struct SiS_Private *SiS_Pr, unsigned short DelayTime, unsigned short DelayLoop) { int i; for(i = 0; i < DelayLoop; i++) { SiS_PanelDelay(SiS_Pr, DelayTime); } } #endif /*********************************************/ /* HELPER: WAIT-FOR-RETRACE FUNCTIONS */ /*********************************************/ void SiS_WaitRetrace1(struct SiS_Private *SiS_Pr) { unsigned short watchdog; if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return; if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return; watchdog = 65535; while((SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08) && --watchdog); watchdog = 65535; while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog); } #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) static void SiS_WaitRetrace2(struct SiS_Private *SiS_Pr, unsigned short reg) { unsigned short watchdog; watchdog = 65535; while((SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02) && --watchdog); watchdog = 65535; while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog); } #endif static void SiS_WaitVBRetrace(struct SiS_Private *SiS_Pr) { if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return; } if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) { SiS_WaitRetrace1(SiS_Pr); } else { SiS_WaitRetrace2(SiS_Pr, 0x25); } #endif } else { #ifdef CONFIG_FB_SIS_315 if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) { SiS_WaitRetrace1(SiS_Pr); } else { SiS_WaitRetrace2(SiS_Pr, 0x30); } #endif } } static void SiS_VBWait(struct SiS_Private *SiS_Pr) { unsigned short tempal,temp,i,j; temp = 0; for(i = 0; i < 3; i++) { for(j = 0; j < 100; j++) { tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da); if(temp & 0x01) { if((tempal & 0x08)) continue; else break; } else { if(!(tempal & 0x08)) continue; else break; } } temp ^= 0x01; } } static void SiS_VBLongWait(struct SiS_Private *SiS_Pr) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { SiS_VBWait(SiS_Pr); } else { SiS_WaitRetrace1(SiS_Pr); } } /*********************************************/ /* HELPER: MISC */ /*********************************************/ #ifdef CONFIG_FB_SIS_300 static bool SiS_Is301B(struct SiS_Private *SiS_Pr) { if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return true; return false; } #endif static bool SiS_CRT2IsLCD(struct SiS_Private *SiS_Pr) { if(SiS_Pr->ChipType == SIS_730) { if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x20) return true; } if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0x20) return true; return false; } bool SiS_IsDualEdge(struct SiS_Private *SiS_Pr) { #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->ChipType >= SIS_315H) { if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) { if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return true; } } #endif return false; } bool SiS_IsVAMode(struct SiS_Private *SiS_Pr) { #ifdef CONFIG_FB_SIS_315 unsigned short flag; if(SiS_Pr->ChipType >= SIS_315H) { flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); if((flag & EnableDualEdge) && (flag & SetToLCDA)) return true; } #endif return false; } #ifdef CONFIG_FB_SIS_315 static bool SiS_IsVAorLCD(struct SiS_Private *SiS_Pr) { if(SiS_IsVAMode(SiS_Pr)) return true; if(SiS_CRT2IsLCD(SiS_Pr)) return true; return false; } #endif static bool SiS_IsDualLink(struct SiS_Private *SiS_Pr) { #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->ChipType >= SIS_315H) { if((SiS_CRT2IsLCD(SiS_Pr)) || (SiS_IsVAMode(SiS_Pr))) { if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return true; } } #endif return false; } #ifdef CONFIG_FB_SIS_315 static bool SiS_TVEnabled(struct SiS_Private *SiS_Pr) { if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return true; if(SiS_Pr->SiS_VBType & VB_SISYPBPR) { if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return true; } return false; } #endif #ifdef CONFIG_FB_SIS_315 static bool SiS_LCDAEnabled(struct SiS_Private *SiS_Pr) { if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return true; return false; } #endif #ifdef CONFIG_FB_SIS_315 static bool SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr) { if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) { if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return true; } return false; } #endif #ifdef CONFIG_FB_SIS_315 static bool SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr) { unsigned short flag; if(SiS_Pr->ChipType == SIS_650) { flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0; /* Check for revision != A0 only */ if((flag == 0xe0) || (flag == 0xc0) || (flag == 0xb0) || (flag == 0x90)) return false; } else if(SiS_Pr->ChipType >= SIS_661) return false; return true; } #endif #ifdef CONFIG_FB_SIS_315 static bool SiS_IsYPbPr(struct SiS_Private *SiS_Pr) { if(SiS_Pr->ChipType >= SIS_315H) { /* YPrPb = 0x08 */ if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHYPbPr) return true; } return false; } #endif #ifdef CONFIG_FB_SIS_315 static bool SiS_IsChScart(struct SiS_Private *SiS_Pr) { if(SiS_Pr->ChipType >= SIS_315H) { /* Scart = 0x04 */ if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHScart) return true; } return false; } #endif #ifdef CONFIG_FB_SIS_315 static bool SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr) { unsigned short flag; if(SiS_Pr->ChipType >= SIS_315H) { flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); if(flag & SetCRT2ToTV) return true; flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); if(flag & EnableCHYPbPr) return true; /* = YPrPb = 0x08 */ if(flag & EnableCHScart) return true; /* = Scart = 0x04 - TW */ } else { flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); if(flag & SetCRT2ToTV) return true; } return false; } #endif #ifdef CONFIG_FB_SIS_315 static bool SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr) { unsigned short flag; if(SiS_Pr->ChipType >= SIS_315H) { flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); if(flag & SetCRT2ToLCD) return true; flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); if(flag & SetToLCDA) return true; } else { flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); if(flag & SetCRT2ToLCD) return true; } return false; } #endif static bool SiS_HaveBridge(struct SiS_Private *SiS_Pr) { unsigned short flag; if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { return true; } else if(SiS_Pr->SiS_VBType & VB_SISVB) { flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00); if((flag == 1) || (flag == 2)) return true; } return false; } static bool SiS_BridgeIsEnabled(struct SiS_Private *SiS_Pr) { unsigned short flag; if(SiS_HaveBridge(SiS_Pr)) { flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00); if(SiS_Pr->ChipType < SIS_315H) { flag &= 0xa0; if((flag == 0x80) || (flag == 0x20)) return true; } else { flag &= 0x50; if((flag == 0x40) || (flag == 0x10)) return true; } } return false; } static bool SiS_BridgeInSlavemode(struct SiS_Private *SiS_Pr) { unsigned short flag1; flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31); if(flag1 & (SetInSlaveMode >> 8)) return true; return false; } /*********************************************/ /* GET VIDEO BRIDGE CONFIG INFO */ /*********************************************/ /* Setup general purpose IO for Chrontel communication */ #ifdef CONFIG_FB_SIS_300 void SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo) { unsigned int acpibase; unsigned short temp; if(!(SiS_Pr->SiS_ChSW)) return; acpibase = sisfb_read_lpc_pci_dword(SiS_Pr, 0x74); acpibase &= 0xFFFF; if(!acpibase) return; temp = SiS_GetRegShort((acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */ temp &= 0xFEFF; SiS_SetRegShort((acpibase + 0x3c), temp); temp = SiS_GetRegShort((acpibase + 0x3c)); temp = SiS_GetRegShort((acpibase + 0x3a)); /* ACPI register 0x3a: GP Pin Level (low/high) */ temp &= 0xFEFF; if(!(myvbinfo & SetCRT2ToTV)) temp |= 0x0100; SiS_SetRegShort((acpibase + 0x3a), temp); temp = SiS_GetRegShort((acpibase + 0x3a)); } #endif void SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, int checkcrt2mode) { unsigned short tempax, tempbx, temp; unsigned short modeflag, resinfo = 0; SiS_Pr->SiS_SetFlag = 0; modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex); SiS_Pr->SiS_ModeType = modeflag & ModeTypeMask; if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) { resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; } tempbx = 0; if(SiS_HaveBridge(SiS_Pr)) { temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); tempbx |= temp; tempax = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) << 8; tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV); tempbx |= tempax; #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_VBType & VB_SISLCDA) { if(ModeNo == 0x03) { /* Mode 0x03 is never in driver mode */ SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf); } if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) { /* Reset LCDA setting if not driver mode */ SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc); } if(IS_SIS650) { if(SiS_Pr->SiS_UseLCDA) { if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) { if((ModeNo <= 0x13) || (!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) { SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA)); } } } } temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); if((temp & (EnableDualEdge | SetToLCDA)) == (EnableDualEdge | SetToLCDA)) { tempbx |= SetCRT2ToLCDA; } } if(SiS_Pr->ChipType >= SIS_661) { /* New CR layout */ tempbx &= ~(SetCRT2ToYPbPr525750 | SetCRT2ToHiVision); if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0x04) { temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0; if(temp == 0x60) tempbx |= SetCRT2ToHiVision; else if(SiS_Pr->SiS_VBType & VB_SISYPBPR) { tempbx |= SetCRT2ToYPbPr525750; } } } if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); if(temp & SetToLCDA) { tempbx |= SetCRT2ToLCDA; } if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(temp & EnableCHYPbPr) { tempbx |= SetCRT2ToCHYPbPr; } } } } #endif /* CONFIG_FB_SIS_315 */ if(!(SiS_Pr->SiS_VBType & VB_SISVGA2)) { tempbx &= ~(SetCRT2ToRAMDAC); } if(SiS_Pr->SiS_VBType & VB_SISVB) { temp = SetCRT2ToSVIDEO | SetCRT2ToAVIDEO | SetCRT2ToSCART | SetCRT2ToLCDA | SetCRT2ToLCD | SetCRT2ToRAMDAC | SetCRT2ToHiVision | SetCRT2ToYPbPr525750; } else { if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { temp = SetCRT2ToAVIDEO | SetCRT2ToSVIDEO | SetCRT2ToSCART | SetCRT2ToLCDA | SetCRT2ToLCD | SetCRT2ToCHYPbPr; } else { temp = SetCRT2ToLCDA | SetCRT2ToLCD; } } else { if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { temp = SetCRT2ToTV | SetCRT2ToLCD; } else { temp = SetCRT2ToLCD; } } } if(!(tempbx & temp)) { tempax = DisableCRT2Display; tempbx = 0; } if(SiS_Pr->SiS_VBType & VB_SISVB) { unsigned short clearmask = ( DriverMode | DisableCRT2Display | LoadDACFlag | SetNotSimuMode | SetInSlaveMode | SetPALTV | SwitchCRT2 | SetSimuScanMode ); if(tempbx & SetCRT2ToLCDA) tempbx &= (clearmask | SetCRT2ToLCDA); if(tempbx & SetCRT2ToRAMDAC) tempbx &= (clearmask | SetCRT2ToRAMDAC); if(tempbx & SetCRT2ToLCD) tempbx &= (clearmask | SetCRT2ToLCD); if(tempbx & SetCRT2ToSCART) tempbx &= (clearmask | SetCRT2ToSCART); if(tempbx & SetCRT2ToHiVision) tempbx &= (clearmask | SetCRT2ToHiVision); if(tempbx & SetCRT2ToYPbPr525750) tempbx &= (clearmask | SetCRT2ToYPbPr525750); } else { if(SiS_Pr->ChipType >= SIS_315H) { if(tempbx & SetCRT2ToLCDA) { tempbx &= (0xFF00|SwitchCRT2|SetSimuScanMode); } } if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(tempbx & SetCRT2ToTV) { tempbx &= (0xFF00|SetCRT2ToTV|SwitchCRT2|SetSimuScanMode); } } if(tempbx & SetCRT2ToLCD) { tempbx &= (0xFF00|SetCRT2ToLCD|SwitchCRT2|SetSimuScanMode); } if(SiS_Pr->ChipType >= SIS_315H) { if(tempbx & SetCRT2ToLCDA) { tempbx |= SetCRT2ToLCD; } } } if(tempax & DisableCRT2Display) { if(!(tempbx & (SwitchCRT2 | SetSimuScanMode))) { tempbx = SetSimuScanMode | DisableCRT2Display; } } if(!(tempbx & DriverMode)) tempbx |= SetSimuScanMode; /* LVDS/CHRONTEL (LCD/TV) and 301BDH (LCD) can only be slave in 8bpp modes */ if(SiS_Pr->SiS_ModeType <= ModeVGA) { if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) || ((SiS_Pr->SiS_VBType & VB_NoLCD) && (tempbx & SetCRT2ToLCD)) ) { modeflag &= (~CRT2Mode); } } if(!(tempbx & SetSimuScanMode)) { if(tempbx & SwitchCRT2) { if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) { if(resinfo != SIS_RI_1600x1200) { tempbx |= SetSimuScanMode; } } } else { if(SiS_BridgeIsEnabled(SiS_Pr)) { if(!(tempbx & DriverMode)) { if(SiS_BridgeInSlavemode(SiS_Pr)) { tempbx |= SetSimuScanMode; } } } } } if(!(tempbx & DisableCRT2Display)) { if(tempbx & DriverMode) { if(tempbx & SetSimuScanMode) { if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) { if(resinfo != SIS_RI_1600x1200) { tempbx |= SetInSlaveMode; } } } } else { tempbx |= SetInSlaveMode; } } } SiS_Pr->SiS_VBInfo = tempbx; #ifdef CONFIG_FB_SIS_300 if(SiS_Pr->ChipType == SIS_630) { SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo); } #endif #if 0 printk(KERN_DEBUG "sisfb: (init301: VBInfo= 0x%04x, SetFlag=0x%04x)\n", SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag); #endif } /*********************************************/ /* DETERMINE YPbPr MODE */ /*********************************************/ void SiS_SetYPbPr(struct SiS_Private *SiS_Pr) { unsigned char temp; /* Note: This variable is only used on 30xLV systems. * CR38 has a different meaning on LVDS/CH7019 systems. * On 661 and later, these bits moved to CR35. * * On 301, 301B, only HiVision 1080i is supported. * On 30xLV, 301C, only YPbPr 1080i is supported. */ SiS_Pr->SiS_YPbPr = 0; if(SiS_Pr->ChipType >= SIS_661) return; if(SiS_Pr->SiS_VBType) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { SiS_Pr->SiS_YPbPr = YPbPrHiVision; } } if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_VBType & VB_SISYPBPR) { temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); if(temp & 0x08) { switch((temp >> 4)) { case 0x00: SiS_Pr->SiS_YPbPr = YPbPr525i; break; case 0x01: SiS_Pr->SiS_YPbPr = YPbPr525p; break; case 0x02: SiS_Pr->SiS_YPbPr = YPbPr750p; break; case 0x03: SiS_Pr->SiS_YPbPr = YPbPrHiVision; break; } } } } } /*********************************************/ /* DETERMINE TVMode flag */ /*********************************************/ void SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short temp, temp1, resinfo = 0, romindex = 0; unsigned char OutputSelect = *SiS_Pr->pSiS_OutputSelect; SiS_Pr->SiS_TVMode = 0; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return; if(SiS_Pr->UseCustomMode) return; if(ModeNo > 0x13) { resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; } if(SiS_Pr->ChipType < SIS_661) { if(SiS_Pr->SiS_VBInfo & SetPALTV) SiS_Pr->SiS_TVMode |= TVSetPAL; if(SiS_Pr->SiS_VBType & VB_SISVB) { temp = 0; if((SiS_Pr->ChipType == SIS_630) || (SiS_Pr->ChipType == SIS_730)) { temp = 0x35; romindex = 0xfe; } else if(SiS_Pr->ChipType >= SIS_315H) { temp = 0x38; if(SiS_Pr->ChipType < XGI_20) { romindex = 0xf3; if(SiS_Pr->ChipType >= SIS_330) romindex = 0x11b; } } if(temp) { if(romindex && SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) { OutputSelect = ROMAddr[romindex]; if(!(OutputSelect & EnablePALMN)) { SiS_SetRegAND(SiS_Pr->SiS_P3d4,temp,0x3F); } } temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,temp); if(SiS_Pr->SiS_TVMode & TVSetPAL) { if(temp1 & EnablePALM) { /* 0x40 */ SiS_Pr->SiS_TVMode |= TVSetPALM; SiS_Pr->SiS_TVMode &= ~TVSetPAL; } else if(temp1 & EnablePALN) { /* 0x80 */ SiS_Pr->SiS_TVMode |= TVSetPALN; } } else { if(temp1 & EnableNTSCJ) { /* 0x40 */ SiS_Pr->SiS_TVMode |= TVSetNTSCJ; } } } /* Translate HiVision/YPbPr to our new flags */ if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { if(SiS_Pr->SiS_YPbPr == YPbPr750p) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p; else if(SiS_Pr->SiS_YPbPr == YPbPr525p) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p; else if(SiS_Pr->SiS_YPbPr == YPbPrHiVision) SiS_Pr->SiS_TVMode |= TVSetHiVision; else SiS_Pr->SiS_TVMode |= TVSetYPbPr525i; if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p | TVSetYPbPr525i)) { SiS_Pr->SiS_VBInfo &= ~SetCRT2ToHiVision; SiS_Pr->SiS_VBInfo |= SetCRT2ToYPbPr525750; } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) { SiS_Pr->SiS_TVMode |= TVSetPAL; } } } else if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(SiS_Pr->SiS_CHOverScan) { if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35); if((temp & TVOverScan) || (SiS_Pr->SiS_CHOverScan == 1)) { SiS_Pr->SiS_TVMode |= TVSetCHOverScan; } } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79); if((temp & 0x80) || (SiS_Pr->SiS_CHOverScan == 1)) { SiS_Pr->SiS_TVMode |= TVSetCHOverScan; } } if(SiS_Pr->SiS_CHSOverScan) { SiS_Pr->SiS_TVMode |= TVSetCHOverScan; } } if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); if(SiS_Pr->SiS_TVMode & TVSetPAL) { if(temp & EnablePALM) SiS_Pr->SiS_TVMode |= TVSetPALM; else if(temp & EnablePALN) SiS_Pr->SiS_TVMode |= TVSetPALN; } else { if(temp & EnableNTSCJ) { SiS_Pr->SiS_TVMode |= TVSetNTSCJ; } } } } } else { /* 661 and later */ temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35); if(temp1 & 0x01) { SiS_Pr->SiS_TVMode |= TVSetPAL; if(temp1 & 0x08) { SiS_Pr->SiS_TVMode |= TVSetPALN; } else if(temp1 & 0x04) { if(SiS_Pr->SiS_VBType & VB_SISVB) { SiS_Pr->SiS_TVMode &= ~TVSetPAL; } SiS_Pr->SiS_TVMode |= TVSetPALM; } } else { if(temp1 & 0x02) { SiS_Pr->SiS_TVMode |= TVSetNTSCJ; } } if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { if(SiS_Pr->SiS_CHOverScan) { if((temp1 & 0x10) || (SiS_Pr->SiS_CHOverScan == 1)) { SiS_Pr->SiS_TVMode |= TVSetCHOverScan; } } } if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { temp1 &= 0xe0; if(temp1 == 0x00) SiS_Pr->SiS_TVMode |= TVSetYPbPr525i; else if(temp1 == 0x20) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p; else if(temp1 == 0x40) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p; } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { SiS_Pr->SiS_TVMode |= (TVSetHiVision | TVSetPAL); } if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750 | SetCRT2ToHiVision)) { if(resinfo == SIS_RI_800x480 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x720) { SiS_Pr->SiS_TVMode |= TVAspect169; } else { temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39); if(temp1 & 0x02) { if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetHiVision)) { SiS_Pr->SiS_TVMode |= TVAspect169; } else { SiS_Pr->SiS_TVMode |= TVAspect43LB; } } else { SiS_Pr->SiS_TVMode |= TVAspect43; } } } } } if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) SiS_Pr->SiS_TVMode |= TVSetPAL; if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { SiS_Pr->SiS_TVMode |= TVSetPAL; SiS_Pr->SiS_TVMode &= ~(TVSetPALM | TVSetPALN | TVSetNTSCJ); } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525i | TVSetYPbPr525p | TVSetYPbPr750p)) { SiS_Pr->SiS_TVMode &= ~(TVSetPAL | TVSetNTSCJ | TVSetPALM | TVSetPALN); } } if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) { SiS_Pr->SiS_TVMode |= TVSetTVSimuMode; } } if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { if(resinfo == SIS_RI_1024x768) { if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) { SiS_Pr->SiS_TVMode |= TVSet525p1024; } else if(!(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p))) { SiS_Pr->SiS_TVMode |= TVSetNTSC1024; } } } SiS_Pr->SiS_TVMode |= TVRPLLDIV2XO; if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) && (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO; } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) { SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO; } else if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) { if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) { SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO; } } } SiS_Pr->SiS_VBInfo &= ~SetPALTV; } /*********************************************/ /* GET LCD INFO */ /*********************************************/ static unsigned short SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr) { unsigned short temp = SiS_Pr->SiS_LCDResInfo; /* Translate my LCDResInfo to BIOS value */ switch(temp) { case Panel_1280x768_2: temp = Panel_1280x768; break; case Panel_1280x800_2: temp = Panel_1280x800; break; case Panel_1280x854: temp = Panel661_1280x854; break; } return temp; } static void SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr) { #ifdef CONFIG_FB_SIS_315 unsigned char *ROMAddr; unsigned short temp; if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) { if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) { SiS_Pr->SiS_NeedRomModeData = true; SiS_Pr->PanelHT = temp; } if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) { SiS_Pr->SiS_NeedRomModeData = true; SiS_Pr->PanelVT = temp; } SiS_Pr->PanelHRS = SISGETROMW(10); SiS_Pr->PanelHRE = SISGETROMW(12); SiS_Pr->PanelVRS = SISGETROMW(14); SiS_Pr->PanelVRE = SISGETROMW(16); SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315; SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].CLOCK = SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].CLOCK = (unsigned short)((unsigned char)ROMAddr[18]); SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2B = SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_A = ROMAddr[19]; SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C = SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20]; } #endif } static void SiS_CheckScaling(struct SiS_Private *SiS_Pr, unsigned short resinfo, const unsigned char *nonscalingmodes) { int i = 0; while(nonscalingmodes[i] != 0xff) { if(nonscalingmodes[i++] == resinfo) { if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) || (SiS_Pr->UsePanelScaler == -1)) { SiS_Pr->SiS_LCDInfo |= DontExpandLCD; } break; } } } void SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0; bool panelcanscale = false; #ifdef CONFIG_FB_SIS_300 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; static const unsigned char SiS300SeriesLCDRes[] = { 0, 1, 2, 3, 7, 4, 5, 8, 0, 0, 10, 0, 0, 0, 0, 15 }; #endif #ifdef CONFIG_FB_SIS_315 unsigned char *myptr = NULL; #endif SiS_Pr->SiS_LCDResInfo = 0; SiS_Pr->SiS_LCDTypeInfo = 0; SiS_Pr->SiS_LCDInfo = 0; SiS_Pr->PanelHRS = 999; /* HSync start */ SiS_Pr->PanelHRE = 999; /* HSync end */ SiS_Pr->PanelVRS = 999; /* VSync start */ SiS_Pr->PanelVRE = 999; /* VSync end */ SiS_Pr->SiS_NeedRomModeData = false; /* Alternative 1600x1200@60 timing for 1600x1200 LCDA */ SiS_Pr->Alternate1600x1200 = false; if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return; modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex); if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) { resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; modexres = SiS_Pr->SiS_ModeResInfo[resinfo].HTotal; modeyres = SiS_Pr->SiS_ModeResInfo[resinfo].VTotal; } temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36); /* For broken BIOSes: Assume 1024x768 */ if(temp == 0) temp = 0x02; if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) { SiS_Pr->SiS_LCDTypeInfo = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x7c) >> 2; } else if((SiS_Pr->ChipType < SIS_315H) || (SiS_Pr->ChipType >= SIS_661)) { SiS_Pr->SiS_LCDTypeInfo = temp >> 4; } else { SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1; } temp &= 0x0f; #ifdef CONFIG_FB_SIS_300 if(SiS_Pr->ChipType < SIS_315H) { /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */ if(SiS_Pr->SiS_VBType & VB_SIS301) { if(temp < 0x0f) temp &= 0x07; } /* Translate 300 series LCDRes to 315 series for unified usage */ temp = SiS300SeriesLCDRes[temp]; } #endif /* Translate to our internal types */ #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->ChipType == SIS_550) { if (temp == Panel310_1152x768) temp = Panel_320x240_2; /* Verified working */ else if(temp == Panel310_320x240_2) temp = Panel_320x240_2; else if(temp == Panel310_320x240_3) temp = Panel_320x240_3; } else if(SiS_Pr->ChipType >= SIS_661) { if(temp == Panel661_1280x854) temp = Panel_1280x854; } #endif if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* SiS LVDS */ if(temp == Panel310_1280x768) { temp = Panel_1280x768_2; } if(SiS_Pr->SiS_ROMNew) { if(temp == Panel661_1280x800) { temp = Panel_1280x800_2; } } } SiS_Pr->SiS_LCDResInfo = temp; #ifdef CONFIG_FB_SIS_300 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) { SiS_Pr->SiS_LCDResInfo = Panel_Barco1366; } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) { SiS_Pr->SiS_LCDResInfo = Panel_848x480; } else if(SiS_Pr->SiS_CustomT == CUT_PANEL856) { SiS_Pr->SiS_LCDResInfo = Panel_856x480; } } #endif if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301) SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMin301; } else { if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMinLVDS) SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMinLVDS; } temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); SiS_Pr->SiS_LCDInfo = temp & ~0x000e; /* Need temp below! */ /* These must/can't scale no matter what */ switch(SiS_Pr->SiS_LCDResInfo) { case Panel_320x240_1: case Panel_320x240_2: case Panel_320x240_3: case Panel_1280x960: SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD; break; case Panel_640x480: SiS_Pr->SiS_LCDInfo |= DontExpandLCD; } panelcanscale = (bool)(SiS_Pr->SiS_LCDInfo & DontExpandLCD); if(!SiS_Pr->UsePanelScaler) SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD; else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD; /* Dual link, Pass 1:1 BIOS default, etc. */ #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->ChipType >= SIS_661) { if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11; } if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) { if(SiS_Pr->SiS_ROMNew) { if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink; } else if((myptr = GetLCDStructPtr661(SiS_Pr))) { if(myptr[2] & 0x01) SiS_Pr->SiS_LCDInfo |= LCDDualLink; } } } else if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) SiS_Pr->SiS_LCDInfo |= LCDPass11; } if((SiS_Pr->SiS_ROMNew) && (!(SiS_Pr->PanelSelfDetected))) { SiS_Pr->SiS_LCDInfo &= ~(LCDRGB18Bit); temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35); if(temp & 0x01) SiS_Pr->SiS_LCDInfo |= LCDRGB18Bit; if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) { if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink; } } else if(!(SiS_Pr->SiS_ROMNew)) { if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) { if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) && (SiS_Pr->SiS_LCDResInfo == Panel_1024x768)) { SiS_Pr->SiS_LCDInfo |= LCDDualLink; } if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) || (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) || (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) || (SiS_Pr->SiS_LCDResInfo == Panel_1680x1050)) { SiS_Pr->SiS_LCDInfo |= LCDDualLink; } } } } #endif /* Pass 1:1 */ if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) { /* Always center screen on LVDS (if scaling is disabled) */ SiS_Pr->SiS_LCDInfo &= ~LCDPass11; } else if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* Always center screen on SiS LVDS (if scaling is disabled) */ SiS_Pr->SiS_LCDInfo &= ~LCDPass11; } else { /* By default, pass 1:1 on SiS TMDS (if scaling is supported) */ if(panelcanscale) SiS_Pr->SiS_LCDInfo |= LCDPass11; if(SiS_Pr->CenterScreen == 1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11; } } SiS_Pr->PanelVCLKIdx300 = VCLK65_300; SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315; switch(SiS_Pr->SiS_LCDResInfo) { case Panel_320x240_1: case Panel_320x240_2: case Panel_320x240_3: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480; SiS_Pr->PanelVRS = 24; SiS_Pr->PanelVRE = 3; SiS_Pr->PanelVCLKIdx300 = VCLK28; SiS_Pr->PanelVCLKIdx315 = VCLK28; break; case Panel_640x480: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480; SiS_Pr->PanelVRE = 3; SiS_Pr->PanelVCLKIdx300 = VCLK28; SiS_Pr->PanelVCLKIdx315 = VCLK28; break; case Panel_800x600: SiS_Pr->PanelXRes = 800; SiS_Pr->PanelYRes = 600; SiS_Pr->PanelHT = 1056; SiS_Pr->PanelVT = 628; SiS_Pr->PanelHRS = 40; SiS_Pr->PanelHRE = 128; SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 4; SiS_Pr->PanelVCLKIdx300 = VCLK40; SiS_Pr->PanelVCLKIdx315 = VCLK40; break; case Panel_1024x600: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 600; SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 800; SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136; SiS_Pr->PanelVRS = 2 /* 88 */ ; SiS_Pr->PanelVRE = 6; SiS_Pr->PanelVCLKIdx300 = VCLK65_300; SiS_Pr->PanelVCLKIdx315 = VCLK65_315; break; case Panel_1024x768: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768; SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806; SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136; SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6; if(SiS_Pr->ChipType < SIS_315H) { SiS_Pr->PanelHRS = 23; SiS_Pr->PanelVRE = 5; } SiS_Pr->PanelVCLKIdx300 = VCLK65_300; SiS_Pr->PanelVCLKIdx315 = VCLK65_315; SiS_GetLCDInfoBIOS(SiS_Pr); break; case Panel_1152x768: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 768; SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806; SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136; SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6; if(SiS_Pr->ChipType < SIS_315H) { SiS_Pr->PanelHRS = 23; SiS_Pr->PanelVRE = 5; } SiS_Pr->PanelVCLKIdx300 = VCLK65_300; SiS_Pr->PanelVCLKIdx315 = VCLK65_315; break; case Panel_1152x864: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 864; break; case Panel_1280x720: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 720; SiS_Pr->PanelHT = 1650; SiS_Pr->PanelVT = 750; SiS_Pr->PanelHRS = 110; SiS_Pr->PanelHRE = 40; SiS_Pr->PanelVRS = 5; SiS_Pr->PanelVRE = 5; SiS_Pr->PanelVCLKIdx315 = VCLK_1280x720; /* Data above for TMDS (projector); get from BIOS for LVDS */ SiS_GetLCDInfoBIOS(SiS_Pr); break; case Panel_1280x768: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768; if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 806; SiS_Pr->PanelVCLKIdx300 = VCLK81_300; /* ? */ SiS_Pr->PanelVCLKIdx315 = VCLK81_315; /* ? */ } else { SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 802; SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRS = 112; SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6; SiS_Pr->PanelVCLKIdx300 = VCLK81_300; SiS_Pr->PanelVCLKIdx315 = VCLK81_315; } break; case Panel_1280x768_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768; SiS_Pr->PanelHT = 1660; SiS_Pr->PanelVT = 806; SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112; SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6; SiS_Pr->PanelVCLKIdx315 = VCLK_1280x768_2; SiS_GetLCDInfoBIOS(SiS_Pr); break; case Panel_1280x800: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800; SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 816; SiS_Pr->PanelHRS = 21; SiS_Pr->PanelHRE = 24; SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3; SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315; SiS_GetLCDInfoBIOS(SiS_Pr); break; case Panel_1280x800_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800; SiS_Pr->PanelHT = 1552; SiS_Pr->PanelVT = 812; SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112; SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3; SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315_2; SiS_GetLCDInfoBIOS(SiS_Pr); break; case Panel_1280x854: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 854; SiS_Pr->PanelHT = 1664; SiS_Pr->PanelVT = 861; SiS_Pr->PanelHRS = 16; SiS_Pr->PanelHRE = 112; SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3; SiS_Pr->PanelVCLKIdx315 = VCLK_1280x854; SiS_GetLCDInfoBIOS(SiS_Pr); break; case Panel_1280x960: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 960; SiS_Pr->PanelHT = 1800; SiS_Pr->PanelVT = 1000; SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300; SiS_Pr->PanelVCLKIdx315 = VCLK108_3_315; if(resinfo == SIS_RI_1280x1024) { SiS_Pr->PanelVCLKIdx300 = VCLK100_300; SiS_Pr->PanelVCLKIdx315 = VCLK100_315; } break; case Panel_1280x1024: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024; SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066; SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112; SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3; SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300; SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315; SiS_GetLCDInfoBIOS(SiS_Pr); break; case Panel_1400x1050: SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050; SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066; SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112; SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3; SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315; SiS_GetLCDInfoBIOS(SiS_Pr); break; case Panel_1600x1200: SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200; SiS_Pr->PanelHT = 2160; SiS_Pr->PanelVT = 1250; SiS_Pr->PanelHRS = 64; SiS_Pr->PanelHRE = 192; SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3; SiS_Pr->PanelVCLKIdx315 = VCLK162_315; if(SiS_Pr->SiS_VBType & VB_SISTMDSLCDA) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { SiS_Pr->PanelHT = 1760; SiS_Pr->PanelVT = 1235; SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 32; SiS_Pr->PanelVRS = 2; SiS_Pr->PanelVRE = 4; SiS_Pr->PanelVCLKIdx315 = VCLK130_315; SiS_Pr->Alternate1600x1200 = true; } } else if(SiS_Pr->SiS_IF_DEF_LVDS) { SiS_Pr->PanelHT = 2048; SiS_Pr->PanelVT = 1320; SiS_Pr->PanelHRS = SiS_Pr->PanelHRE = 999; SiS_Pr->PanelVRS = SiS_Pr->PanelVRE = 999; } SiS_GetLCDInfoBIOS(SiS_Pr); break; case Panel_1680x1050: SiS_Pr->PanelXRes = 1680; SiS_Pr->PanelYRes = 1050; SiS_Pr->PanelHT = 1900; SiS_Pr->PanelVT = 1066; SiS_Pr->PanelHRS = 26; SiS_Pr->PanelHRE = 76; SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6; SiS_Pr->PanelVCLKIdx315 = VCLK121_315; SiS_GetLCDInfoBIOS(SiS_Pr); break; case Panel_Barco1366: SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024; SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066; break; case Panel_848x480: SiS_Pr->PanelXRes = 848; SiS_Pr->PanelYRes = 480; SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525; break; case Panel_856x480: SiS_Pr->PanelXRes = 856; SiS_Pr->PanelYRes = 480; SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525; break; case Panel_Custom: SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX; SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY; SiS_Pr->PanelHT = SiS_Pr->CHTotal; SiS_Pr->PanelVT = SiS_Pr->CVTotal; if(SiS_Pr->CP_PreferredIndex != -1) { SiS_Pr->PanelXRes = SiS_Pr->CP_HDisplay[SiS_Pr->CP_PreferredIndex]; SiS_Pr->PanelYRes = SiS_Pr->CP_VDisplay[SiS_Pr->CP_PreferredIndex]; SiS_Pr->PanelHT = SiS_Pr->CP_HTotal[SiS_Pr->CP_PreferredIndex]; SiS_Pr->PanelVT = SiS_Pr->CP_VTotal[SiS_Pr->CP_PreferredIndex]; SiS_Pr->PanelHRS = SiS_Pr->CP_HSyncStart[SiS_Pr->CP_PreferredIndex]; SiS_Pr->PanelHRE = SiS_Pr->CP_HSyncEnd[SiS_Pr->CP_PreferredIndex]; SiS_Pr->PanelVRS = SiS_Pr->CP_VSyncStart[SiS_Pr->CP_PreferredIndex]; SiS_Pr->PanelVRE = SiS_Pr->CP_VSyncEnd[SiS_Pr->CP_PreferredIndex]; SiS_Pr->PanelHRS -= SiS_Pr->PanelXRes; SiS_Pr->PanelHRE -= SiS_Pr->PanelHRS; SiS_Pr->PanelVRS -= SiS_Pr->PanelYRes; SiS_Pr->PanelVRE -= SiS_Pr->PanelVRS; if(SiS_Pr->CP_PrefClock) { int idx; SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315; SiS_Pr->PanelVCLKIdx300 = VCLK_CUSTOM_300; if(SiS_Pr->ChipType < SIS_315H) idx = VCLK_CUSTOM_300; else idx = VCLK_CUSTOM_315; SiS_Pr->SiS_VCLKData[idx].CLOCK = SiS_Pr->SiS_VBVCLKData[idx].CLOCK = SiS_Pr->CP_PrefClock; SiS_Pr->SiS_VCLKData[idx].SR2B = SiS_Pr->SiS_VBVCLKData[idx].Part4_A = SiS_Pr->CP_PrefSR2B; SiS_Pr->SiS_VCLKData[idx].SR2C = SiS_Pr->SiS_VBVCLKData[idx].Part4_B = SiS_Pr->CP_PrefSR2C; } } break; default: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768; SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806; break; } /* Special cases */ if( (SiS_Pr->SiS_IF_DEF_FSTN) || (SiS_Pr->SiS_IF_DEF_DSTN) || (SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024) || (SiS_Pr->SiS_CustomT == CUT_PANEL848) || (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) { SiS_Pr->PanelHRS = 999; SiS_Pr->PanelHRE = 999; } if( (SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024) || (SiS_Pr->SiS_CustomT == CUT_PANEL848) || (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) { SiS_Pr->PanelVRS = 999; SiS_Pr->PanelVRE = 999; } /* DontExpand overrule */ if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) { if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (modeflag & NoSupportLCDScale)) { /* No scaling for this mode on any panel (LCD=CRT2)*/ SiS_Pr->SiS_LCDInfo |= DontExpandLCD; } switch(SiS_Pr->SiS_LCDResInfo) { case Panel_Custom: case Panel_1152x864: case Panel_1280x768: /* TMDS only */ SiS_Pr->SiS_LCDInfo |= DontExpandLCD; break; case Panel_800x600: { static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, 0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); break; } case Panel_1024x768: { static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); break; } case Panel_1280x720: { static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, 0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); if(SiS_Pr->PanelHT == 1650) { SiS_Pr->SiS_LCDInfo |= DontExpandLCD; } break; } case Panel_1280x768_2: { /* LVDS only */ static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, SIS_RI_1152x768,0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); switch(resinfo) { case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) { SiS_Pr->SiS_LCDInfo |= DontExpandLCD; } break; } break; } case Panel_1280x800: { /* SiS TMDS special (Averatec 6200 series) */ static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, SIS_RI_1152x768,SIS_RI_1280x720,SIS_RI_1280x768,0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); break; } case Panel_1280x800_2: { /* SiS LVDS */ static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, SIS_RI_1152x768,0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); switch(resinfo) { case SIS_RI_1280x720: case SIS_RI_1280x768: if(SiS_Pr->UsePanelScaler == -1) { SiS_Pr->SiS_LCDInfo |= DontExpandLCD; } break; } break; } case Panel_1280x854: { /* SiS LVDS */ static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, SIS_RI_1152x768,0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); switch(resinfo) { case SIS_RI_1280x720: case SIS_RI_1280x768: case SIS_RI_1280x800: if(SiS_Pr->UsePanelScaler == -1) { SiS_Pr->SiS_LCDInfo |= DontExpandLCD; } break; } break; } case Panel_1280x960: { static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800, SIS_RI_1280x854,0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); break; } case Panel_1280x1024: { static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800, SIS_RI_1280x854,SIS_RI_1280x960,0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); break; } case Panel_1400x1050: { static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x768,SIS_RI_1280x800,SIS_RI_1280x854, SIS_RI_1280x960,0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); switch(resinfo) { case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) { SiS_Pr->SiS_LCDInfo |= DontExpandLCD; } break; case SIS_RI_1280x1024: SiS_Pr->SiS_LCDInfo |= DontExpandLCD; break; } break; } case Panel_1600x1200: { static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800, SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); break; } case Panel_1680x1050: { static const unsigned char nonscalingmodes[] = { SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480, SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600, SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768, SIS_RI_1360x1024,0xff }; SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes); break; } } } #ifdef CONFIG_FB_SIS_300 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) { SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */ } } if(SiS_Pr->ChipType < SIS_315H) { if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { if(SiS_Pr->SiS_UseROM) { if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { if(!(ROMAddr[0x235] & 0x02)) { SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD); } } } } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { if((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10))) { SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD); } } } #endif /* Special cases */ if(modexres == SiS_Pr->PanelXRes && modeyres == SiS_Pr->PanelYRes) { SiS_Pr->SiS_LCDInfo &= ~LCDPass11; } if(SiS_Pr->SiS_IF_DEF_TRUMPION) { SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11); } switch(SiS_Pr->SiS_LCDResInfo) { case Panel_640x480: SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11); break; case Panel_1280x800: /* Don't pass 1:1 by default (TMDS special) */ if(SiS_Pr->CenterScreen == -1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11; break; case Panel_1280x960: SiS_Pr->SiS_LCDInfo &= ~LCDPass11; break; case Panel_Custom: if((!SiS_Pr->CP_PrefClock) || (modexres > SiS_Pr->PanelXRes) || (modeyres > SiS_Pr->PanelYRes)) { SiS_Pr->SiS_LCDInfo |= LCDPass11; } break; } if((SiS_Pr->UseCustomMode) || (SiS_Pr->SiS_CustomT == CUT_UNKNOWNLCD)) { SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11); } /* (In)validate LCDPass11 flag */ if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { SiS_Pr->SiS_LCDInfo &= ~LCDPass11; } /* LVDS DDA */ if(!((SiS_Pr->ChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & SetDOSMode))) { if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) { if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) { if(ModeNo == 0x12) { if(SiS_Pr->SiS_LCDInfo & LCDPass11) { SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; } } else if(ModeNo > 0x13) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) { if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) { SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; } } } } } } if(modeflag & HalfDCLK) { if(SiS_Pr->SiS_IF_DEF_TRUMPION == 1) { SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; } else if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) { SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; } else if(ModeNo > 0x13) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; } else if(SiS_Pr->SiS_LCDResInfo == Panel_800x600) { if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA; } } } } /* VESA timing */ if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) { SiS_Pr->SiS_SetFlag |= LCDVESATiming; } } else { SiS_Pr->SiS_SetFlag |= LCDVESATiming; } #if 0 printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n", SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo); #endif } /*********************************************/ /* GET VCLK */ /*********************************************/ unsigned short SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short CRT2Index, VCLKIndex = 0, VCLKIndexGEN = 0, VCLKIndexGENCRT = 0; unsigned short modeflag, resinfo, tempbx; const unsigned char *CHTVVCLKPtr = NULL; if(ModeNo <= 0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; VCLKIndexGEN = (SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)) >> 2) & 0x03; VCLKIndexGENCRT = VCLKIndexGEN; } else { modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; VCLKIndexGEN = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; VCLKIndexGENCRT = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, (SiS_Pr->SiS_SetFlag & ProgrammingCRT2) ? SiS_Pr->SiS_UseWideCRT2 : SiS_Pr->SiS_UseWide); } if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 30x/B/LV */ if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) { CRT2Index >>= 6; if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /* LCD */ if(SiS_Pr->ChipType < SIS_315H) { VCLKIndex = SiS_Pr->PanelVCLKIdx300; if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) { VCLKIndex = VCLKIndexGEN; } } else { VCLKIndex = SiS_Pr->PanelVCLKIdx315; if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) { switch(resinfo) { /* Correct those whose IndexGEN doesn't match VBVCLK array */ case SIS_RI_720x480: VCLKIndex = VCLK_720x480; break; case SIS_RI_720x576: VCLKIndex = VCLK_720x576; break; case SIS_RI_768x576: VCLKIndex = VCLK_768x576; break; case SIS_RI_848x480: VCLKIndex = VCLK_848x480; break; case SIS_RI_856x480: VCLKIndex = VCLK_856x480; break; case SIS_RI_800x480: VCLKIndex = VCLK_800x480; break; case SIS_RI_1024x576: VCLKIndex = VCLK_1024x576; break; case SIS_RI_1152x864: VCLKIndex = VCLK_1152x864; break; case SIS_RI_1280x720: VCLKIndex = VCLK_1280x720; break; case SIS_RI_1360x768: VCLKIndex = VCLK_1360x768; break; default: VCLKIndex = VCLKIndexGEN; } if(ModeNo <= 0x13) { if(SiS_Pr->ChipType <= SIS_315PRO) { if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42; } else { if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x00; } } if(SiS_Pr->ChipType <= SIS_315PRO) { if(VCLKIndex == 0) VCLKIndex = 0x41; if(VCLKIndex == 1) VCLKIndex = 0x43; if(VCLKIndex == 4) VCLKIndex = 0x44; } } } } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TV */ if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2; else VCLKIndex = HiTVVCLK; if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) VCLKIndex = HiTVSimuVCLK; } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) VCLKIndex = YPbPr750pVCLK; else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) VCLKIndex = TVVCLKDIV2; else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = TVVCLKDIV2; else VCLKIndex = TVVCLK; if(SiS_Pr->ChipType < SIS_315H) VCLKIndex += TVCLKBASE_300; else VCLKIndex += TVCLKBASE_315; } else { /* VGA2 */ VCLKIndex = VCLKIndexGENCRT; if(SiS_Pr->ChipType < SIS_315H) { if(ModeNo > 0x13) { if( (SiS_Pr->ChipType == SIS_630) && (SiS_Pr->ChipRevision >= 0x30)) { if(VCLKIndex == 0x14) VCLKIndex = 0x34; } /* Better VGA2 clock for 1280x1024@75 */ if(VCLKIndex == 0x17) VCLKIndex = 0x45; } } } } else { /* If not programming CRT2 */ VCLKIndex = VCLKIndexGENCRT; if(SiS_Pr->ChipType < SIS_315H) { if(ModeNo > 0x13) { if( (SiS_Pr->ChipType != SIS_630) && (SiS_Pr->ChipType != SIS_300) ) { if(VCLKIndex == 0x1b) VCLKIndex = 0x48; } } } } } else { /* LVDS */ VCLKIndex = CRT2Index; if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) { if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) { VCLKIndex &= 0x1f; tempbx = 0; if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1; if(SiS_Pr->SiS_TVMode & TVSetPAL) { tempbx += 2; if(SiS_Pr->SiS_ModeType > ModeVGA) { if(SiS_Pr->SiS_CHSOverScan) tempbx = 8; } if(SiS_Pr->SiS_TVMode & TVSetPALM) { tempbx = 4; if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1; } else if(SiS_Pr->SiS_TVMode & TVSetPALN) { tempbx = 6; if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1; } } switch(tempbx) { case 0: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUNTSC; break; case 1: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKONTSC; break; case 2: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPAL; break; case 3: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break; case 4: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALM; break; case 5: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALM; break; case 6: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALN; break; case 7: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALN; break; case 8: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKSOPAL; break; default: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break; } VCLKIndex = CHTVVCLKPtr[VCLKIndex]; } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { if(SiS_Pr->ChipType < SIS_315H) { VCLKIndex = SiS_Pr->PanelVCLKIdx300; } else { VCLKIndex = SiS_Pr->PanelVCLKIdx315; } #ifdef CONFIG_FB_SIS_300 /* Special Timing: Barco iQ Pro R series */ if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44; /* Special Timing: 848x480 and 856x480 parallel lvds panels */ if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) { if(SiS_Pr->ChipType < SIS_315H) { VCLKIndex = VCLK34_300; /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */ } else { VCLKIndex = VCLK34_315; /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */ } } #endif } else { VCLKIndex = VCLKIndexGENCRT; if(SiS_Pr->ChipType < SIS_315H) { if(ModeNo > 0x13) { if( (SiS_Pr->ChipType == SIS_630) && (SiS_Pr->ChipRevision >= 0x30) ) { if(VCLKIndex == 0x14) VCLKIndex = 0x2e; } } } } } else { /* if not programming CRT2 */ VCLKIndex = VCLKIndexGENCRT; if(SiS_Pr->ChipType < SIS_315H) { if(ModeNo > 0x13) { if( (SiS_Pr->ChipType != SIS_630) && (SiS_Pr->ChipType != SIS_300) ) { if(VCLKIndex == 0x1b) VCLKIndex = 0x48; } #if 0 if(SiS_Pr->ChipType == SIS_730) { if(VCLKIndex == 0x0b) VCLKIndex = 0x40; /* 1024x768-70 */ if(VCLKIndex == 0x0d) VCLKIndex = 0x41; /* 1024x768-75 */ } #endif } } } } return VCLKIndex; } /*********************************************/ /* SET CRT2 MODE TYPE REGISTERS */ /*********************************************/ static void SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned short i, j, modeflag, tempah=0; short tempcl; #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) unsigned short tempbl; #endif #ifdef CONFIG_FB_SIS_315 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short tempah2, tempbl2; #endif modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex); if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xAF,0x40); SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2E,0xF7); } else { for(i=0,j=4; i<3; i++,j++) SiS_SetReg(SiS_Pr->SiS_Part1Port,j,0); if(SiS_Pr->ChipType >= SIS_315H) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0x7F); } tempcl = SiS_Pr->SiS_ModeType; if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 /* ---- 300 series ---- */ /* For 301BDH: (with LCD via LVDS) */ if(SiS_Pr->SiS_VBType & VB_NoLCD) { tempbl = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32); tempbl &= 0xef; tempbl |= 0x02; if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) || (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { tempbl |= 0x10; tempbl &= 0xfd; } SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,tempbl); } if(ModeNo > 0x13) { tempcl -= ModeVGA; if(tempcl >= 0) { tempah = ((0x10 >> tempcl) | 0x80); } } else tempah = 0x80; if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0; #endif /* CONFIG_FB_SIS_300 */ } else { #ifdef CONFIG_FB_SIS_315 /* ------- 315/330 series ------ */ if(ModeNo > 0x13) { tempcl -= ModeVGA; if(tempcl >= 0) { tempah = (0x08 >> tempcl); if (tempah == 0) tempah = 1; tempah |= 0x40; } } else tempah = 0x40; if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50; #endif /* CONFIG_FB_SIS_315 */ } if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0; if(SiS_Pr->ChipType < SIS_315H) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah); } else { #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah); } else if(SiS_Pr->SiS_VBType & VB_SISVB) { if(IS_SIS740) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah); } else { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah); } } #endif } if(SiS_Pr->SiS_VBType & VB_SISVB) { tempah = 0x01; if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { tempah |= 0x02; } if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { tempah ^= 0x05; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { tempah ^= 0x01; } } if(SiS_Pr->ChipType < SIS_315H) { if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0; tempah = (tempah << 5) & 0xFF; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah); tempah = (tempah >> 5) & 0xFF; } else { if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x08; else if(!(SiS_IsDualEdge(SiS_Pr))) tempah |= 0x08; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2E,0xF0,tempah); tempah &= ~0x08; } if((SiS_Pr->SiS_ModeType == ModeVGA) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) { tempah |= 0x10; } tempah |= 0x80; if(SiS_Pr->SiS_VBType & VB_SIS301) { if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah &= ~0x80; } if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p))) { if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { tempah |= 0x20; } } } SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah); tempah = 0x80; if(SiS_Pr->SiS_VBType & VB_SIS301) { if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah = 0; } if(SiS_IsDualLink(SiS_Pr)) tempah |= 0x40; if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) { tempah |= 0x40; } } SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0C,tempah); } else { /* LVDS */ if(SiS_Pr->ChipType >= SIS_315H) { #ifdef CONFIG_FB_SIS_315 /* LVDS can only be slave in 8bpp modes */ tempah = 0x80; if((modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA)) { if(SiS_Pr->SiS_VBInfo & DriverMode) { tempah |= 0x02; } } if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) tempah |= 0x02; if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah ^= 0x01; if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 1; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah); #endif } else { #ifdef CONFIG_FB_SIS_300 tempah = 0; if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) { tempah |= 0x02; } tempah <<= 5; if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah); #endif } } } /* LCDA */ if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->ChipType >= SIS_315H) { #ifdef CONFIG_FB_SIS_315 /* unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); */ /* The following is nearly unpreditable and varies from machine * to machine. Especially the 301DH seems to be a real trouble * maker. Some BIOSes simply set the registers (like in the * NoLCD-if-statements here), some set them according to the * LCDA stuff. It is very likely that some machines are not * treated correctly in the following, very case-orientated * code. What do I do then...? */ /* 740 variants match for 30xB, 301B-DH, 30xLV */ if(!(IS_SIS740)) { tempah = 0x04; /* For all bridges */ tempbl = 0xfb; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { tempah = 0x00; if(SiS_IsDualEdge(SiS_Pr)) { tempbl = 0xff; } } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah); } /* The following two are responsible for eventually wrong colors * in TV output. The DH (VB_NoLCD) conditions are unknown; the * b0 was found in some 651 machine (Pim; P4_23=0xe5); the b1 version * in a 650 box (Jake). What is the criteria? * Addendum: Another combination 651+301B-DH(b1) (Rapo) needs same * treatment like the 651+301B-DH(b0) case. Seems more to be the * chipset than the bridge revision. */ if((IS_SIS740) || (SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) { tempah = 0x30; tempbl = 0xc0; if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) || ((SiS_Pr->SiS_ROMNew) && (!(ROMAddr[0x5b] & 0x04)))) { tempah = 0x00; tempbl = 0x00; } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,0xcf,tempah); SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0x3f,tempbl); } else if(SiS_Pr->SiS_VBType & VB_SIS301) { /* Fixes "TV-blue-bug" on 315+301 */ SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2c,0xcf); /* For 301 */ SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f); } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xLV */ SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0); } else if(SiS_Pr->SiS_VBType & VB_NoLCD) { /* For 301B-DH */ tempah = 0x30; tempah2 = 0xc0; tempbl = 0xcf; tempbl2 = 0x3f; if(SiS_Pr->SiS_TVBlue == 0) { tempah = tempah2 = 0x00; } else if(SiS_Pr->SiS_TVBlue == -1) { /* Set on 651/M650, clear on 315/650 */ if(!(IS_SIS65x)) /* (bridgerev != 0xb0) */ { tempah = tempah2 = 0x00; } } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah); SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2); } else { tempah = 0x30; tempah2 = 0xc0; /* For 30xB, 301C */ tempbl = 0xcf; tempbl2 = 0x3f; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { tempah = tempah2 = 0x00; if(SiS_IsDualEdge(SiS_Pr)) { tempbl = tempbl2 = 0xff; } } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah); SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2); } if(IS_SIS740) { tempah = 0x80; if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x00; SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,0x7f,tempah); } else { tempah = 0x00; tempbl = 0x7f; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { tempbl = 0xff; if(!(SiS_IsDualEdge(SiS_Pr))) tempah = 0x80; } SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah); } #endif /* CONFIG_FB_SIS_315 */ } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { #ifdef CONFIG_FB_SIS_300 SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f); if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) || ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F); } else { SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x23,0x80); } #endif } if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x0D,0x80); if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) { SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3A,0xC0); } } } else { /* LVDS */ #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { tempah = 0x04; tempbl = 0xfb; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { tempah = 0x00; if(SiS_IsDualEdge(SiS_Pr)) tempbl = 0xff; } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah); if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb); } SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); } else if(SiS_Pr->ChipType == SIS_550) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); } } #endif } } /*********************************************/ /* GET RESOLUTION DATA */ /*********************************************/ unsigned short SiS_GetResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { if(ModeNo <= 0x13) return ((unsigned short)SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo); else return ((unsigned short)SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO); } static void SiS_GetCRT2ResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned short xres, yres, modeflag=0, resindex; if(SiS_Pr->UseCustomMode) { xres = SiS_Pr->CHDisplay; if(SiS_Pr->CModeFlag & HalfDCLK) xres <<= 1; SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres; /* DoubleScanMode-check done in CheckCalcCustomMode()! */ SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = SiS_Pr->CVDisplay; return; } resindex = SiS_GetResInfo(SiS_Pr,ModeNo,ModeIdIndex); if(ModeNo <= 0x13) { xres = SiS_Pr->SiS_StResInfo[resindex].HTotal; yres = SiS_Pr->SiS_StResInfo[resindex].VTotal; } else { xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal; yres = SiS_Pr->SiS_ModeResInfo[resindex].VTotal; modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; } if(!SiS_Pr->SiS_IF_DEF_DSTN && !SiS_Pr->SiS_IF_DEF_FSTN) { if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) { if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & SetDOSMode)) { if(yres == 350) yres = 400; } if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x3a) & 0x01) { if(ModeNo == 0x12) yres = 400; } } if(modeflag & HalfDCLK) xres <<= 1; if(modeflag & DoubleScanMode) yres <<= 1; } if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { switch(SiS_Pr->SiS_LCDResInfo) { case Panel_1024x768: if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { if(yres == 350) yres = 357; if(yres == 400) yres = 420; if(yres == 480) yres = 525; } } break; case Panel_1280x1024: if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { /* BIOS bug - does this regardless of scaling */ if(yres == 400) yres = 405; } if(yres == 350) yres = 360; if(SiS_Pr->SiS_SetFlag & LCDVESATiming) { if(yres == 360) yres = 375; } break; case Panel_1600x1200: if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { if(yres == 1024) yres = 1056; } break; } } } else { if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) { if(xres == 720) xres = 640; } } else if(xres == 720) xres = 640; if(SiS_Pr->SiS_SetFlag & SetDOSMode) { yres = 400; if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480; } else { if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480; } if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) yres = 480; } } SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres; SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres; } /*********************************************/ /* GET CRT2 TIMING DATA */ /*********************************************/ static void SiS_GetCRT2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex, unsigned short *CRT2Index, unsigned short *ResIndex) { unsigned short tempbx=0, tempal=0, resinfo=0; if(ModeNo <= 0x13) { tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; } else { tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; } if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* LCD */ tempbx = SiS_Pr->SiS_LCDResInfo; if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 32; /* patch index */ if(SiS_Pr->SiS_LCDResInfo == Panel_1680x1050) { if (resinfo == SIS_RI_1280x800) tempal = 9; else if(resinfo == SIS_RI_1400x1050) tempal = 11; } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x800) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x800_2) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x854)) { if (resinfo == SIS_RI_1280x768) tempal = 9; } if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { /* Pass 1:1 only (center-screen handled outside) */ /* This is never called for the panel's native resolution */ /* since Pass1:1 will not be set in this case */ tempbx = 100; if(ModeNo >= 0x13) { tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS; } } #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) { if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) { if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { tempbx = 200; if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++; } } } #endif } else { /* TV */ if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { /* if(SiS_Pr->SiS_VGAVDE > 480) SiS_Pr->SiS_TVMode &= (~TVSetTVSimuMode); */ tempbx = 2; if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { tempbx = 13; if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) tempbx = 14; } } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempbx = 7; else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempbx = 6; else tempbx = 5; if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5; } else { if(SiS_Pr->SiS_TVMode & TVSetPAL) tempbx = 3; else tempbx = 4; if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5; } } tempal &= 0x3F; if(ModeNo > 0x13) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) { switch(resinfo) { case SIS_RI_720x480: tempal = 6; if(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetPALN)) tempal = 9; break; case SIS_RI_720x576: case SIS_RI_768x576: case SIS_RI_1024x576: /* Not in NTSC or YPBPR mode (except 1080i)! */ tempal = 6; if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 8; } break; case SIS_RI_800x480: tempal = 4; break; case SIS_RI_512x384: case SIS_RI_1024x768: tempal = 7; if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempal = 8; } break; case SIS_RI_1280x720: if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 9; } break; } } } *CRT2Index = tempbx; *ResIndex = tempal; } else { /* LVDS, 301B-DH (if running on LCD) */ tempbx = 0; if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { tempbx = 90; if(SiS_Pr->SiS_TVMode & TVSetPAL) { tempbx = 92; if(SiS_Pr->SiS_ModeType > ModeVGA) { if(SiS_Pr->SiS_CHSOverScan) tempbx = 99; } if(SiS_Pr->SiS_TVMode & TVSetPALM) tempbx = 94; else if(SiS_Pr->SiS_TVMode & TVSetPALN) tempbx = 96; } if(tempbx != 99) { if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx++; } } else { switch(SiS_Pr->SiS_LCDResInfo) { case Panel_640x480: tempbx = 12; break; case Panel_320x240_1: tempbx = 10; break; case Panel_320x240_2: case Panel_320x240_3: tempbx = 14; break; case Panel_800x600: tempbx = 16; break; case Panel_1024x600: tempbx = 18; break; case Panel_1152x768: case Panel_1024x768: tempbx = 20; break; case Panel_1280x768: tempbx = 22; break; case Panel_1280x1024: tempbx = 24; break; case Panel_1400x1050: tempbx = 26; break; case Panel_1600x1200: tempbx = 28; break; #ifdef CONFIG_FB_SIS_300 case Panel_Barco1366: tempbx = 80; break; #endif } switch(SiS_Pr->SiS_LCDResInfo) { case Panel_320x240_1: case Panel_320x240_2: case Panel_320x240_3: case Panel_640x480: break; default: if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++; } if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 30; #ifdef CONFIG_FB_SIS_300 if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) { tempbx = 82; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++; } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) { tempbx = 84; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++; } #endif } (*CRT2Index) = tempbx; (*ResIndex) = tempal & 0x1F; } } static void SiS_GetRAMDAC2DATA(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short tempax=0, tempbx=0, index, dotclock; unsigned short temp1=0, modeflag=0, tempcx=0; SiS_Pr->SiS_RVBHCMAX = 1; SiS_Pr->SiS_RVBHCFACT = 1; if(ModeNo <= 0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; index = SiS_GetModePtr(SiS_Pr,ModeNo,ModeIdIndex); tempax = SiS_Pr->SiS_StandTable[index].CRTC[0]; tempbx = SiS_Pr->SiS_StandTable[index].CRTC[6]; temp1 = SiS_Pr->SiS_StandTable[index].CRTC[7]; dotclock = (modeflag & Charx8Dot) ? 8 : 9; } else { modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2); tempax = SiS_Pr->SiS_CRT1Table[index].CR[0]; tempax |= (SiS_Pr->SiS_CRT1Table[index].CR[14] << 8); tempax &= 0x03FF; tempbx = SiS_Pr->SiS_CRT1Table[index].CR[6]; tempcx = SiS_Pr->SiS_CRT1Table[index].CR[13] << 8; tempcx &= 0x0100; tempcx <<= 2; tempbx |= tempcx; temp1 = SiS_Pr->SiS_CRT1Table[index].CR[7]; dotclock = 8; } if(temp1 & 0x01) tempbx |= 0x0100; if(temp1 & 0x20) tempbx |= 0x0200; tempax += 5; tempax *= dotclock; if(modeflag & HalfDCLK) tempax <<= 1; tempbx++; SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax; SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = tempbx; } static void SiS_CalcPanelLinkTiming(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short ResIndex; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { if(SiS_Pr->SiS_LCDInfo & LCDPass11) { if(SiS_Pr->UseCustomMode) { ResIndex = SiS_Pr->CHTotal; if(SiS_Pr->CModeFlag & HalfDCLK) ResIndex <<= 1; SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = ResIndex; SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal; } else { if(ModeNo < 0x13) { ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; } else { ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS; } if(ResIndex == 0x09) { if(SiS_Pr->Alternate1600x1200) ResIndex = 0x20; /* 1600x1200 LCDA */ else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) ResIndex = 0x21; /* 1600x1200 LVDS */ } SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAHT; SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAVT; SiS_Pr->SiS_HT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDHT; SiS_Pr->SiS_VT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDVT; } } else { SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->PanelHT; SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->PanelVT; } } else { /* This handles custom modes and custom panels */ SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes; SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes; SiS_Pr->SiS_HT = SiS_Pr->PanelHT; SiS_Pr->SiS_VT = SiS_Pr->PanelVT; SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT - (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE); SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT - (SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE); } } static void SiS_GetCRT2DataLVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short CRT2Index, ResIndex, backup; const struct SiS_LVDSData *LVDSData = NULL; SiS_GetCRT2ResInfo(SiS_Pr, ModeNo, ModeIdIndex); if(SiS_Pr->SiS_VBType & VB_SISVB) { SiS_Pr->SiS_RVBHCMAX = 1; SiS_Pr->SiS_RVBHCFACT = 1; SiS_Pr->SiS_NewFlickerMode = 0; SiS_Pr->SiS_RVBHRS = 50; SiS_Pr->SiS_RY1COE = 0; SiS_Pr->SiS_RY2COE = 0; SiS_Pr->SiS_RY3COE = 0; SiS_Pr->SiS_RY4COE = 0; SiS_Pr->SiS_RVBHRS2 = 0; } if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { #ifdef CONFIG_FB_SIS_315 SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex); #endif } else { /* 301BDH needs LVDS Data */ backup = SiS_Pr->SiS_IF_DEF_LVDS; if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { SiS_Pr->SiS_IF_DEF_LVDS = 1; } SiS_GetCRT2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, &CRT2Index, &ResIndex); SiS_Pr->SiS_IF_DEF_LVDS = backup; switch(CRT2Index) { case 10: LVDSData = SiS_Pr->SiS_LVDS320x240Data_1; break; case 14: LVDSData = SiS_Pr->SiS_LVDS320x240Data_2; break; case 12: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1; break; case 16: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break; case 18: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break; case 20: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break; #ifdef CONFIG_FB_SIS_300 case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break; case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break; case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break; case 84: LVDSData = SiS_Pr->SiS_LVDS848x480Data_1; break; case 85: LVDSData = SiS_Pr->SiS_LVDS848x480Data_2; break; #endif case 90: LVDSData = SiS_Pr->SiS_CHTVUNTSCData; break; case 91: LVDSData = SiS_Pr->SiS_CHTVONTSCData; break; case 92: LVDSData = SiS_Pr->SiS_CHTVUPALData; break; case 93: LVDSData = SiS_Pr->SiS_CHTVOPALData; break; case 94: LVDSData = SiS_Pr->SiS_CHTVUPALMData; break; case 95: LVDSData = SiS_Pr->SiS_CHTVOPALMData; break; case 96: LVDSData = SiS_Pr->SiS_CHTVUPALNData; break; case 97: LVDSData = SiS_Pr->SiS_CHTVOPALNData; break; case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData; break; } if(LVDSData) { SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT; SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT; SiS_Pr->SiS_HT = (LVDSData+ResIndex)->LCDHT; SiS_Pr->SiS_VT = (LVDSData+ResIndex)->LCDVT; } else { SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } if( (!(SiS_Pr->SiS_VBType & VB_SISVB)) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) ) { if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (SiS_Pr->SiS_SetFlag & SetDOSMode) ) { SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes; SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes; #ifdef CONFIG_FB_SIS_300 if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) { if(ResIndex < 0x08) { SiS_Pr->SiS_HDE = 1280; SiS_Pr->SiS_VDE = 1024; } } #endif } } } } static void SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned char *ROMAddr = NULL; unsigned short tempax, tempbx, modeflag, romptr=0; unsigned short resinfo, CRT2Index, ResIndex; const struct SiS_LCDData *LCDPtr = NULL; const struct SiS_TVData *TVPtr = NULL; #ifdef CONFIG_FB_SIS_315 short resinfo661; #endif if(ModeNo <= 0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; } else if(SiS_Pr->UseCustomMode) { modeflag = SiS_Pr->CModeFlag; resinfo = 0; } else { modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; #ifdef CONFIG_FB_SIS_315 resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661; if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_SetFlag & LCDVESATiming) && (resinfo661 >= 0) && (SiS_Pr->SiS_NeedRomModeData) ) { if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) { if((romptr = (SISGETROMW(21)))) { romptr += (resinfo661 * 10); ROMAddr = SiS_Pr->VirtualRomBase; } } } #endif } SiS_Pr->SiS_NewFlickerMode = 0; SiS_Pr->SiS_RVBHRS = 50; SiS_Pr->SiS_RY1COE = 0; SiS_Pr->SiS_RY2COE = 0; SiS_Pr->SiS_RY3COE = 0; SiS_Pr->SiS_RY4COE = 0; SiS_Pr->SiS_RVBHRS2 = 0; SiS_GetCRT2ResInfo(SiS_Pr,ModeNo,ModeIdIndex); if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { if(SiS_Pr->UseCustomMode) { SiS_Pr->SiS_RVBHCMAX = 1; SiS_Pr->SiS_RVBHCFACT = 1; SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE; SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE; tempax = SiS_Pr->CHTotal; if(modeflag & HalfDCLK) tempax <<= 1; SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax; SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal; } else { SiS_GetRAMDAC2DATA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex, &CRT2Index,&ResIndex); switch(CRT2Index) { case 2: TVPtr = SiS_Pr->SiS_ExtHiTVData; break; case 3: TVPtr = SiS_Pr->SiS_ExtPALData; break; case 4: TVPtr = SiS_Pr->SiS_ExtNTSCData; break; case 5: TVPtr = SiS_Pr->SiS_Ext525iData; break; case 6: TVPtr = SiS_Pr->SiS_Ext525pData; break; case 7: TVPtr = SiS_Pr->SiS_Ext750pData; break; case 8: TVPtr = SiS_Pr->SiS_StPALData; break; case 9: TVPtr = SiS_Pr->SiS_StNTSCData; break; case 10: TVPtr = SiS_Pr->SiS_St525iData; break; case 11: TVPtr = SiS_Pr->SiS_St525pData; break; case 12: TVPtr = SiS_Pr->SiS_St750pData; break; case 13: TVPtr = SiS_Pr->SiS_St1HiTVData; break; case 14: TVPtr = SiS_Pr->SiS_St2HiTVData; break; default: TVPtr = SiS_Pr->SiS_StPALData; break; } SiS_Pr->SiS_RVBHCMAX = (TVPtr+ResIndex)->RVBHCMAX; SiS_Pr->SiS_RVBHCFACT = (TVPtr+ResIndex)->RVBHCFACT; SiS_Pr->SiS_VGAHT = (TVPtr+ResIndex)->VGAHT; SiS_Pr->SiS_VGAVT = (TVPtr+ResIndex)->VGAVT; SiS_Pr->SiS_HDE = (TVPtr+ResIndex)->TVHDE; SiS_Pr->SiS_VDE = (TVPtr+ResIndex)->TVVDE; SiS_Pr->SiS_RVBHRS2 = (TVPtr+ResIndex)->RVBHRS2 & 0x0fff; if(modeflag & HalfDCLK) { SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->HALFRVBHRS; if(SiS_Pr->SiS_RVBHRS2) { SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3; tempax = ((TVPtr+ResIndex)->RVBHRS2 >> 12) & 0x07; if((TVPtr+ResIndex)->RVBHRS2 & 0x8000) SiS_Pr->SiS_RVBHRS2 -= tempax; else SiS_Pr->SiS_RVBHRS2 += tempax; } } else { SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->RVBHRS; } SiS_Pr->SiS_NewFlickerMode = ((TVPtr+ResIndex)->FlickerMode) << 7; if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { if((resinfo == SIS_RI_960x600) || (resinfo == SIS_RI_1024x768) || (resinfo == SIS_RI_1280x1024) || (resinfo == SIS_RI_1280x720)) { SiS_Pr->SiS_NewFlickerMode = 0x40; } if(SiS_Pr->SiS_VGAVDE == 350) SiS_Pr->SiS_TVMode |= TVSetTVSimuMode; SiS_Pr->SiS_HT = ExtHiTVHT; SiS_Pr->SiS_VT = ExtHiTVVT; if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) { SiS_Pr->SiS_HT = StHiTVHT; SiS_Pr->SiS_VT = StHiTVVT; } } } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) { SiS_Pr->SiS_HT = 1650; SiS_Pr->SiS_VT = 750; } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) { SiS_Pr->SiS_HT = NTSCHT; if(SiS_Pr->SiS_TVMode & TVSet525p1024) SiS_Pr->SiS_HT = NTSC2HT; SiS_Pr->SiS_VT = NTSCVT; } else { SiS_Pr->SiS_HT = NTSCHT; if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT; SiS_Pr->SiS_VT = NTSCVT; } } else { SiS_Pr->SiS_RY1COE = (TVPtr+ResIndex)->RY1COE; SiS_Pr->SiS_RY2COE = (TVPtr+ResIndex)->RY2COE; SiS_Pr->SiS_RY3COE = (TVPtr+ResIndex)->RY3COE; SiS_Pr->SiS_RY4COE = (TVPtr+ResIndex)->RY4COE; if(modeflag & HalfDCLK) { SiS_Pr->SiS_RY1COE = 0x00; SiS_Pr->SiS_RY2COE = 0xf4; SiS_Pr->SiS_RY3COE = 0x10; SiS_Pr->SiS_RY4COE = 0x38; } if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { SiS_Pr->SiS_HT = NTSCHT; if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT; SiS_Pr->SiS_VT = NTSCVT; } else { SiS_Pr->SiS_HT = PALHT; SiS_Pr->SiS_VT = PALVT; } } } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { SiS_Pr->SiS_RVBHCMAX = 1; SiS_Pr->SiS_RVBHCFACT = 1; if(SiS_Pr->UseCustomMode) { SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE; SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE; tempax = SiS_Pr->CHTotal; if(modeflag & HalfDCLK) tempax <<= 1; SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax; SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal; } else { bool gotit = false; if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) { SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT; SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT; SiS_Pr->SiS_HT = SiS_Pr->PanelHT; SiS_Pr->SiS_VT = SiS_Pr->PanelVT; gotit = true; } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) { #ifdef CONFIG_FB_SIS_315 SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr]; SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1]; SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8); SiS_Pr->SiS_VGAVT = (ROMAddr[romptr+4] << 4) | ((ROMAddr[romptr+3] & 0xf0) >> 4); SiS_Pr->SiS_HT = ROMAddr[romptr+5] | ((ROMAddr[romptr+6] & 0x0f) << 8); SiS_Pr->SiS_VT = (ROMAddr[romptr+7] << 4) | ((ROMAddr[romptr+6] & 0xf0) >> 4); SiS_Pr->SiS_RVBHRS2 = ROMAddr[romptr+8] | ((ROMAddr[romptr+9] & 0x0f) << 8); if((SiS_Pr->SiS_RVBHRS2) && (modeflag & HalfDCLK)) { SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3; tempax = (ROMAddr[romptr+9] >> 4) & 0x07; if(ROMAddr[romptr+9] & 0x80) SiS_Pr->SiS_RVBHRS2 -= tempax; else SiS_Pr->SiS_RVBHRS2 += tempax; } if(SiS_Pr->SiS_VGAHT) gotit = true; else { SiS_Pr->SiS_LCDInfo |= DontExpandLCD; SiS_Pr->SiS_LCDInfo &= ~LCDPass11; SiS_Pr->SiS_RVBHCMAX = 1; SiS_Pr->SiS_RVBHCFACT = 1; SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT; SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT; SiS_Pr->SiS_HT = SiS_Pr->PanelHT; SiS_Pr->SiS_VT = SiS_Pr->PanelVT; SiS_Pr->SiS_RVBHRS2 = 0; gotit = true; } #endif } if(!gotit) { SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex, &CRT2Index,&ResIndex); switch(CRT2Index) { case Panel_1024x768 : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break; case Panel_1024x768 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data; break; case Panel_1280x720 : case Panel_1280x720 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x720Data; break; case Panel_1280x768_2 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x768_2Data; break; case Panel_1280x768_2+ 32: LCDPtr = SiS_Pr->SiS_StLCD1280x768_2Data; break; case Panel_1280x800 : case Panel_1280x800 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x800Data; break; case Panel_1280x800_2 : case Panel_1280x800_2+ 32: LCDPtr = SiS_Pr->SiS_LCD1280x800_2Data; break; case Panel_1280x854 : case Panel_1280x854 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x854Data; break; case Panel_1280x960 : case Panel_1280x960 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x960Data; break; case Panel_1280x1024 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data; break; case Panel_1280x1024 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break; case Panel_1400x1050 : LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data; break; case Panel_1400x1050 + 32: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data; break; case Panel_1600x1200 : LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data; break; case Panel_1600x1200 + 32: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data; break; case Panel_1680x1050 : case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break; case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break; #ifdef CONFIG_FB_SIS_315 case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break; case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break; #endif default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break; } SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX; SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT; SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT; SiS_Pr->SiS_VGAVT = (LCDPtr+ResIndex)->VGAVT; SiS_Pr->SiS_HT = (LCDPtr+ResIndex)->LCDHT; SiS_Pr->SiS_VT = (LCDPtr+ResIndex)->LCDVT; } tempax = SiS_Pr->PanelXRes; tempbx = SiS_Pr->PanelYRes; switch(SiS_Pr->SiS_LCDResInfo) { case Panel_1024x768: if(SiS_Pr->SiS_SetFlag & LCDVESATiming) { if(SiS_Pr->ChipType < SIS_315H) { if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560; else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640; } } else { if (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527; else if(SiS_Pr->SiS_VGAVDE == 420) tempbx = 620; else if(SiS_Pr->SiS_VGAVDE == 525) tempbx = 775; else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775; else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560; else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640; } break; case Panel_1280x960: if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 700; else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 800; else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960; break; case Panel_1280x1024: if (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768; else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800; else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864; break; case Panel_1600x1200: if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 875; else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 1000; } break; } if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { tempax = SiS_Pr->SiS_VGAHDE; tempbx = SiS_Pr->SiS_VGAVDE; } SiS_Pr->SiS_HDE = tempax; SiS_Pr->SiS_VDE = tempbx; } } } static void SiS_GetCRT2Data(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } else { if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { /* Need LVDS Data for LCD on 301B-DH */ SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } else { SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } } } else { SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } } /*********************************************/ /* GET LVDS DES (SKEW) DATA */ /*********************************************/ static const struct SiS_LVDSDes * SiS_GetLVDSDesPtr(struct SiS_Private *SiS_Pr) { const struct SiS_LVDSDes *PanelDesPtr = NULL; #ifdef CONFIG_FB_SIS_300 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { if(SiS_Pr->ChipType < SIS_315H) { if(SiS_Pr->SiS_LCDTypeInfo == 4) { if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) { PanelDesPtr = SiS_Pr->SiS_PanelType04_1a; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { PanelDesPtr = SiS_Pr->SiS_PanelType04_2a; } } else if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) { PanelDesPtr = SiS_Pr->SiS_PanelType04_1b; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { PanelDesPtr = SiS_Pr->SiS_PanelType04_2b; } } } } } #endif return PanelDesPtr; } static void SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short modeflag, ResIndex; const struct SiS_LVDSDes *PanelDesPtr = NULL; SiS_Pr->SiS_LCDHDES = 0; SiS_Pr->SiS_LCDVDES = 0; /* Some special cases */ if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* Trumpion */ if(SiS_Pr->SiS_IF_DEF_TRUMPION) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) { SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; } } return; } /* 640x480 on LVDS */ if(SiS_Pr->ChipType < SIS_315H) { if(SiS_Pr->SiS_LCDResInfo == Panel_640x480 && SiS_Pr->SiS_LCDTypeInfo == 3) { SiS_Pr->SiS_LCDHDES = 8; if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512; else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436; else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440; return; } } } /* LCD */ if( (SiS_Pr->UseCustomMode) || (SiS_Pr->SiS_LCDResInfo == Panel_Custom) || (SiS_Pr->SiS_CustomT == CUT_PANEL848) || (SiS_Pr->SiS_CustomT == CUT_PANEL856) || (SiS_Pr->SiS_LCDInfo & LCDPass11) ) { return; } if(ModeNo <= 0x13) ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; else ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { /* non-pass 1:1 only, see above */ if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) { SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2); } if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) { SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2); } } if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) { switch(SiS_Pr->SiS_CustomT) { case CUT_UNIWILL1024: case CUT_UNIWILL10242: case CUT_CLEVO1400: if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; } break; } switch(SiS_Pr->SiS_LCDResInfo) { case Panel_1280x1024: if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) { SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; } break; case Panel_1280x800: /* Verified for Averatec 6240 */ case Panel_1280x800_2: /* Verified for Asus A4L */ case Panel_1280x854: /* Not verified yet FIXME */ SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; break; } } #endif } else { if((SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) { if(ResIndex <= 3) SiS_Pr->SiS_LCDHDES = 256; } } else if((PanelDesPtr = SiS_GetLVDSDesPtr(SiS_Pr))) { SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES; SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES; } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) { SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2); } if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) { SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2); } else { if(SiS_Pr->ChipType < SIS_315H) { SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; } else { switch(SiS_Pr->SiS_LCDResInfo) { case Panel_800x600: case Panel_1024x768: case Panel_1280x1024: SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT; break; case Panel_1400x1050: SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; break; } } } } else { if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 switch(SiS_Pr->SiS_LCDResInfo) { case Panel_800x600: if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) { SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; } else { SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT + 3; SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT; if(SiS_Pr->SiS_VGAVDE == 400) SiS_Pr->SiS_LCDVDES -= 2; else SiS_Pr->SiS_LCDVDES -= 4; } break; case Panel_1024x768: if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) { SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; } else { SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1; if(SiS_Pr->SiS_VGAVDE <= 400) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 8; if(SiS_Pr->SiS_VGAVDE <= 350) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 12; } break; case Panel_1024x600: default: if( (SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) && (SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) ) { SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; } else { SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1; } break; } switch(SiS_Pr->SiS_LCDTypeInfo) { case 1: SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0; break; case 3: /* 640x480 only? */ SiS_Pr->SiS_LCDHDES = 8; if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512; else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436; else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440; break; } #endif } else { #ifdef CONFIG_FB_SIS_315 switch(SiS_Pr->SiS_LCDResInfo) { case Panel_1024x768: case Panel_1280x1024: if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) { SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1; } break; case Panel_320x240_1: case Panel_320x240_2: case Panel_320x240_3: SiS_Pr->SiS_LCDVDES = 524; break; } #endif } } if((ModeNo <= 0x13) && (SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 632; } else if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) { if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) { if(SiS_Pr->SiS_LCDResInfo >= Panel_1024x768) { if(SiS_Pr->ChipType < SIS_315H) { if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320; } else { #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480; if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804; if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704; if(!(modeflag & HalfDCLK)) { SiS_Pr->SiS_LCDHDES = 320; if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 632; if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 542; } #endif } } } } } } } /*********************************************/ /* DISABLE VIDEO BRIDGE */ /*********************************************/ #ifdef CONFIG_FB_SIS_315 static int SiS_HandlePWD(struct SiS_Private *SiS_Pr) { int ret = 0; #ifdef SET_PWD unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr); unsigned char drivermode = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40; unsigned short temp; if( (SiS_Pr->SiS_VBType & VB_SISPWD) && (romptr) && (SiS_Pr->SiS_PWDOffset) ) { SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2b,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 0]); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2c,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 1]); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2d,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 2]); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2e,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 3]); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2f,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 4]); temp = 0x00; if((ROMAddr[romptr + 2] & (0x06 << 1)) && !drivermode) { temp = 0x80; ret = 1; } SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x27,0x7f,temp); } #endif return ret; } #endif /* NEVER use any variables (VBInfo), this will be called * from outside the context of modeswitch! * MUST call getVBType before calling this */ void SiS_DisableBridge(struct SiS_Private *SiS_Pr) { #ifdef CONFIG_FB_SIS_315 unsigned short tempah, pushax=0, modenum; #endif unsigned short temp=0; if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ===== For 30xB/C/LV ===== */ if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 /* 300 series */ if(!(SiS_CR36BIOSWord23b(SiS_Pr))) { if(SiS_Pr->SiS_VBType & VB_SISLVDS) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE); } else { SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08); } SiS_PanelDelay(SiS_Pr, 3); } if(SiS_Is301B(SiS_Pr)) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f); SiS_ShortDelay(SiS_Pr,1); } SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); SiS_DisplayOff(SiS_Pr); SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); SiS_UnLockCRT2(SiS_Pr); if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); } if( (!(SiS_CRT2IsLCD(SiS_Pr))) || (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) { SiS_PanelDelay(SiS_Pr, 2); if(SiS_Pr->SiS_VBType & VB_SISLVDS) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD); } else { SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04); } } #endif /* CONFIG_FB_SIS_300 */ } else { #ifdef CONFIG_FB_SIS_315 /* 315 series */ int didpwd = 0; bool custom1 = (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) || (SiS_Pr->SiS_CustomT == CUT_CLEVO1400); modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f; if(SiS_Pr->SiS_VBType & VB_SISLVDS) { #ifdef SET_EMI if(SiS_Pr->SiS_VBType & VB_SISEMI) { if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c); } } #endif didpwd = SiS_HandlePWD(SiS_Pr); if( (modenum <= 0x13) || (SiS_IsVAMode(SiS_Pr)) || (!(SiS_IsDualEdge(SiS_Pr))) ) { if(!didpwd) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfe); if(custom1) SiS_PanelDelay(SiS_Pr, 3); } else { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfc); } } if(!custom1) { SiS_DDC2Delay(SiS_Pr,0xff00); SiS_DDC2Delay(SiS_Pr,0xe000); SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00); pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06); if(IS_SIS740) { SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3); } SiS_PanelDelay(SiS_Pr, 3); } } if(!(SiS_IsNotM650orLater(SiS_Pr))) { /* if(SiS_Pr->ChipType < SIS_340) {*/ tempah = 0xef; if(SiS_IsVAMode(SiS_Pr)) tempah = 0xf7; SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah); /*}*/ } if(SiS_Pr->SiS_VBType & VB_SISLVDS) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,~0x10); } tempah = 0x3f; if(SiS_IsDualEdge(SiS_Pr)) { tempah = 0x7f; if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0xbf; } SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah); if((SiS_IsVAMode(SiS_Pr)) || ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) { SiS_DisplayOff(SiS_Pr); if(SiS_Pr->SiS_VBType & VB_SISLVDS) { SiS_PanelDelay(SiS_Pr, 2); } SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF); } if((!(SiS_IsVAMode(SiS_Pr))) || ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) { if(!(SiS_IsDualEdge(SiS_Pr))) { SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf); SiS_DisplayOff(SiS_Pr); } SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); if(SiS_Pr->SiS_VBType & VB_SISLVDS) { SiS_PanelDelay(SiS_Pr, 2); } SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10); SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp); } if(SiS_IsNotM650orLater(SiS_Pr)) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f); } if(SiS_Pr->SiS_VBType & VB_SISLVDS) { if( (!(SiS_IsVAMode(SiS_Pr))) && (!(SiS_CRT2IsLCD(SiS_Pr))) && (!(SiS_IsDualEdge(SiS_Pr))) ) { if(custom1) SiS_PanelDelay(SiS_Pr, 2); if(!didpwd) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD); } if(custom1) SiS_PanelDelay(SiS_Pr, 4); } if(!custom1) { SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax); if(SiS_Pr->SiS_VBType & VB_SISEMI) { if(SiS_IsVAorLCD(SiS_Pr)) { SiS_PanelDelayLoop(SiS_Pr, 3, 20); } } } } #endif /* CONFIG_FB_SIS_315 */ } } else { /* ============ For 301 ================ */ if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 if(!(SiS_CR36BIOSWord23b(SiS_Pr))) { SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08); SiS_PanelDelay(SiS_Pr, 3); } #endif } SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); /* disable VB */ SiS_DisplayOff(SiS_Pr); if(SiS_Pr->ChipType >= SIS_315H) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); } SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); /* disable lock mode */ if(SiS_Pr->ChipType >= SIS_315H) { temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10); SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp); } else { #ifdef CONFIG_FB_SIS_300 SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */ if( (!(SiS_CRT2IsLCD(SiS_Pr))) || (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) { SiS_PanelDelay(SiS_Pr, 2); SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04); } #endif } } } else { /* ============ For LVDS =============*/ if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 /* 300 series */ if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { SiS_SetCH700x(SiS_Pr,0x0E,0x09); } if(SiS_Pr->ChipType == SIS_730) { if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) { SiS_WaitVBRetrace(SiS_Pr); } if(!(SiS_CR36BIOSWord23b(SiS_Pr))) { SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08); SiS_PanelDelay(SiS_Pr, 3); } } else { if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) { if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) { if(!(SiS_CR36BIOSWord23b(SiS_Pr))) { SiS_WaitVBRetrace(SiS_Pr); if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x1c)) { SiS_DisplayOff(SiS_Pr); } SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08); SiS_PanelDelay(SiS_Pr, 3); } } } } SiS_DisplayOff(SiS_Pr); SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); SiS_UnLockCRT2(SiS_Pr); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); if( (!(SiS_CRT2IsLCD(SiS_Pr))) || (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) { SiS_PanelDelay(SiS_Pr, 2); SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04); } #endif /* CONFIG_FB_SIS_300 */ } else { #ifdef CONFIG_FB_SIS_315 /* 315 series */ if(!(SiS_IsNotM650orLater(SiS_Pr))) { /*if(SiS_Pr->ChipType < SIS_340) { */ /* XGI needs this */ SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,~0x18); /* } */ } if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(SiS_Pr->ChipType == SIS_740) { temp = SiS_GetCH701x(SiS_Pr,0x61); if(temp < 1) { SiS_SetCH701x(SiS_Pr,0x76,0xac); SiS_SetCH701x(SiS_Pr,0x66,0x00); } if( (!(SiS_IsDualEdge(SiS_Pr))) || (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) { SiS_SetCH701x(SiS_Pr,0x49,0x3e); } } if( (!(SiS_IsDualEdge(SiS_Pr))) || (SiS_IsVAMode(SiS_Pr)) ) { SiS_Chrontel701xBLOff(SiS_Pr); SiS_Chrontel701xOff(SiS_Pr); } if(SiS_Pr->ChipType != SIS_740) { if( (!(SiS_IsDualEdge(SiS_Pr))) || (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) { SiS_SetCH701x(SiS_Pr,0x49,0x01); } } } if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08); SiS_PanelDelay(SiS_Pr, 3); } if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) || (!(SiS_IsDualEdge(SiS_Pr))) || (!(SiS_IsTVOrYPbPrOrScart(SiS_Pr))) ) { SiS_DisplayOff(SiS_Pr); } if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) || (!(SiS_IsDualEdge(SiS_Pr))) || (!(SiS_IsVAMode(SiS_Pr))) ) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80); } if(SiS_Pr->ChipType == SIS_740) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f); } SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) || (!(SiS_IsDualEdge(SiS_Pr))) || (!(SiS_IsVAMode(SiS_Pr))) ) { SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); } if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { if(SiS_CRT2IsLCD(SiS_Pr)) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf); if(SiS_Pr->ChipType == SIS_550) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xbf); SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xef); } } } else { if(SiS_Pr->ChipType == SIS_740) { if(SiS_IsLCDOrLCDA(SiS_Pr)) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf); } } else if(SiS_IsVAMode(SiS_Pr)) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf); } } if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(SiS_IsDualEdge(SiS_Pr)) { /* SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xff); */ } else { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb); } } SiS_UnLockCRT2(SiS_Pr); if(SiS_Pr->ChipType == SIS_550) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); /* DirectDVD PAL?*/ SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); /* VB clock / 4 ? */ } else if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) || (!(SiS_IsDualEdge(SiS_Pr))) || (!(SiS_IsVAMode(SiS_Pr))) ) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7); } if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { if(SiS_CRT2IsLCD(SiS_Pr)) { if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) { SiS_PanelDelay(SiS_Pr, 2); SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04); } } } #endif /* CONFIG_FB_SIS_315 */ } /* 315 series */ } /* LVDS */ } /*********************************************/ /* ENABLE VIDEO BRIDGE */ /*********************************************/ /* NEVER use any variables (VBInfo), this will be called * from outside the context of a mode switch! * MUST call getVBType before calling this */ static void SiS_EnableBridge(struct SiS_Private *SiS_Pr) { unsigned short temp=0, tempah; #ifdef CONFIG_FB_SIS_315 unsigned short temp1, pushax=0; bool delaylong = false; #endif if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ====== For 301B et al ====== */ if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 /* 300 series */ if(SiS_CRT2IsLCD(SiS_Pr)) { if(SiS_Pr->SiS_VBType & VB_SISLVDS) { SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02); } else if(SiS_Pr->SiS_VBType & VB_NoLCD) { SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00); } if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_NoLCD)) { if(!(SiS_CR36BIOSWord23d(SiS_Pr))) { SiS_PanelDelay(SiS_Pr, 0); } } } if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_CRT2IsLCD(SiS_Pr))) { SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* Enable CRT2 */ SiS_DisplayOn(SiS_Pr); SiS_UnLockCRT2(SiS_Pr); SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF); if(SiS_BridgeInSlavemode(SiS_Pr)) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F); } else { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40); } if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) { if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) { if(!(SiS_CR36BIOSWord23b(SiS_Pr))) { SiS_PanelDelay(SiS_Pr, 1); } SiS_WaitVBRetrace(SiS_Pr); SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00); } } } else { temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */ if(SiS_BridgeInSlavemode(SiS_Pr)) { tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20; } SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp); SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */ SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0); SiS_DisplayOn(SiS_Pr); if(SiS_Pr->SiS_VBType & VB_SISLVDS) { if(SiS_CRT2IsLCD(SiS_Pr)) { if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) { if(!(SiS_CR36BIOSWord23b(SiS_Pr))) { SiS_PanelDelay(SiS_Pr, 1); } SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01); } } } } #endif /* CONFIG_FB_SIS_300 */ } else { #ifdef CONFIG_FB_SIS_315 /* 315 series */ #ifdef SET_EMI unsigned char r30=0, r31=0, r32=0, r33=0, cr36=0; int didpwd = 0; /* unsigned short emidelay=0; */ #endif if(SiS_Pr->SiS_VBType & VB_SISLVDS) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef); #ifdef SET_EMI if(SiS_Pr->SiS_VBType & VB_SISEMI) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c); } #endif } if(!(SiS_IsNotM650orLater(SiS_Pr))) { /*if(SiS_Pr->ChipType < SIS_340) { */ tempah = 0x10; if(SiS_LCDAEnabled(SiS_Pr)) { if(SiS_TVEnabled(SiS_Pr)) tempah = 0x18; else tempah = 0x08; } SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah); /*}*/ } if(SiS_Pr->SiS_VBType & VB_SISLVDS) { SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00); SiS_DisplayOff(SiS_Pr); pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06); if(IS_SIS740) { SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3); } didpwd = SiS_HandlePWD(SiS_Pr); if(SiS_IsVAorLCD(SiS_Pr)) { if(!didpwd) { if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) { SiS_PanelDelayLoop(SiS_Pr, 3, 2); SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02); SiS_PanelDelayLoop(SiS_Pr, 3, 2); if(SiS_Pr->SiS_VBType & VB_SISEMI) { SiS_GenericDelay(SiS_Pr, 17664); } } } else { SiS_PanelDelayLoop(SiS_Pr, 3, 2); if(SiS_Pr->SiS_VBType & VB_SISEMI) { SiS_GenericDelay(SiS_Pr, 17664); } } } if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) { SiS_PanelDelayLoop(SiS_Pr, 3, 10); delaylong = true; } } if(!(SiS_IsVAMode(SiS_Pr))) { temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; if(SiS_BridgeInSlavemode(SiS_Pr)) { tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); if(!(tempah & SetCRT2ToRAMDAC)) { if(!(SiS_LCDAEnabled(SiS_Pr))) temp |= 0x20; } } SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp); SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */ SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80); if(SiS_Pr->SiS_VBType & VB_SISLVDS) { SiS_PanelDelay(SiS_Pr, 2); } } else { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x20); } SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80); if(SiS_Pr->SiS_VBType & VB_SISPOWER) { if( (SiS_LCDAEnabled(SiS_Pr)) || (SiS_CRT2IsLCD(SiS_Pr)) ) { /* Enable "LVDS PLL power on" (even on 301C) */ SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f); /* Enable "LVDS Driver Power on" (even on 301C) */ SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x7f); } } tempah = 0xc0; if(SiS_IsDualEdge(SiS_Pr)) { tempah = 0x80; if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0x40; } SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah); if(SiS_Pr->SiS_VBType & VB_SISLVDS) { SiS_PanelDelay(SiS_Pr, 2); SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80); if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) { #ifdef SET_EMI if(SiS_Pr->SiS_VBType & VB_SISEMI) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c); SiS_GenericDelay(SiS_Pr, 2048); } #endif SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c); if(SiS_Pr->SiS_VBType & VB_SISEMI) { #ifdef SET_EMI cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36); if(SiS_Pr->SiS_ROMNew) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr); if(romptr) { SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */ SiS_Pr->EMI_30 = 0; SiS_Pr->EMI_31 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 0]; SiS_Pr->EMI_32 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 1]; SiS_Pr->EMI_33 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 2]; if(ROMAddr[romptr + 1] & 0x10) SiS_Pr->EMI_30 = 0x40; /* emidelay = SISGETROMW((romptr + 0x22)); */ SiS_Pr->HaveEMI = SiS_Pr->HaveEMILCD = SiS_Pr->OverruleEMI = true; } } /* (P4_30|0x40) */ /* Compal 1400x1050: 0x05, 0x60, 0x00 YES (1.10.7w; CR36=69) */ /* Compal 1400x1050: 0x0d, 0x70, 0x40 YES (1.10.7x; CR36=69) */ /* Acer 1280x1024: 0x12, 0xd0, 0x6b NO (1.10.9k; CR36=73) */ /* Compaq 1280x1024: 0x0d, 0x70, 0x6b YES (1.12.04b; CR36=03) */ /* Clevo 1024x768: 0x05, 0x60, 0x33 NO (1.10.8e; CR36=12, DL!) */ /* Clevo 1024x768: 0x0d, 0x70, 0x40 (if type == 3) YES (1.10.8y; CR36=?2) */ /* Clevo 1024x768: 0x05, 0x60, 0x33 (if type != 3) YES (1.10.8y; CR36=?2) */ /* Asus 1024x768: ? ? (1.10.8o; CR36=?2) */ /* Asus 1024x768: 0x08, 0x10, 0x3c (problematic) YES (1.10.8q; CR36=22) */ if(SiS_Pr->HaveEMI) { r30 = SiS_Pr->EMI_30; r31 = SiS_Pr->EMI_31; r32 = SiS_Pr->EMI_32; r33 = SiS_Pr->EMI_33; } else { r30 = 0; } /* EMI_30 is read at driver start; however, the BIOS sets this * (if it is used) only if the LCD is in use. In case we caught * the machine while on TV output, this bit is not set and we * don't know if it should be set - hence our detection is wrong. * Work-around this here: */ if((!SiS_Pr->HaveEMI) || (!SiS_Pr->HaveEMILCD)) { switch((cr36 & 0x0f)) { case 2: r30 |= 0x40; if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) r30 &= ~0x40; if(!SiS_Pr->HaveEMI) { r31 = 0x05; r32 = 0x60; r33 = 0x33; if((cr36 & 0xf0) == 0x30) { r31 = 0x0d; r32 = 0x70; r33 = 0x40; } } break; case 3: /* 1280x1024 */ if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) r30 |= 0x40; if(!SiS_Pr->HaveEMI) { r31 = 0x12; r32 = 0xd0; r33 = 0x6b; if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) { r31 = 0x0d; r32 = 0x70; r33 = 0x6b; } } break; case 9: /* 1400x1050 */ r30 |= 0x40; if(!SiS_Pr->HaveEMI) { r31 = 0x05; r32 = 0x60; r33 = 0x00; if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) { r31 = 0x0d; r32 = 0x70; r33 = 0x40; /* BIOS values */ } } break; case 11: /* 1600x1200 - unknown */ r30 |= 0x40; if(!SiS_Pr->HaveEMI) { r31 = 0x05; r32 = 0x60; r33 = 0x00; } } } /* BIOS values don't work so well sometimes */ if(!SiS_Pr->OverruleEMI) { #ifdef COMPAL_HACK if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) { if((cr36 & 0x0f) == 0x09) { r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00; } } #endif #ifdef COMPAQ_HACK if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) { if((cr36 & 0x0f) == 0x03) { r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b; } } #endif #ifdef ASUS_HACK if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) { if((cr36 & 0x0f) == 0x02) { /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 2 */ /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 3 */ /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 4 */ /* r30 = 0x20; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 5 */ } } #endif } if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) { SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */ SiS_GenericDelay(SiS_Pr, 2048); } SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x33,r33); #endif /* SET_EMI */ SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10); #ifdef SET_EMI if( (SiS_LCDAEnabled(SiS_Pr)) || (SiS_CRT2IsLCD(SiS_Pr)) ) { if(r30 & 0x40) { /*SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x2a,0x80);*/ SiS_PanelDelayLoop(SiS_Pr, 3, 5); if(delaylong) { SiS_PanelDelayLoop(SiS_Pr, 3, 5); delaylong = false; } SiS_WaitVBRetrace(SiS_Pr); SiS_WaitVBRetrace(SiS_Pr); if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) { SiS_GenericDelay(SiS_Pr, 1280); } SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40); /* Enable */ /*SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);*/ } } #endif } } if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) { if(SiS_IsVAorLCD(SiS_Pr)) { SiS_PanelDelayLoop(SiS_Pr, 3, 10); if(delaylong) { SiS_PanelDelayLoop(SiS_Pr, 3, 10); } SiS_WaitVBRetrace(SiS_Pr); if(SiS_Pr->SiS_VBType & VB_SISEMI) { SiS_GenericDelay(SiS_Pr, 2048); SiS_WaitVBRetrace(SiS_Pr); } if(!didpwd) { SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01); } else { SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x03); } } } SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax); SiS_DisplayOn(SiS_Pr); SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xff); } if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); } #endif /* CONFIG_FB_SIS_315 */ } } else { /* ============ For 301 ================ */ if(SiS_Pr->ChipType < SIS_315H) { if(SiS_CRT2IsLCD(SiS_Pr)) { SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00); SiS_PanelDelay(SiS_Pr, 0); } } temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */ if(SiS_BridgeInSlavemode(SiS_Pr)) { tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20; } SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp); SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */ if(SiS_Pr->ChipType >= SIS_315H) { temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E); if(!(temp & 0x80)) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); /* BVBDOENABLE=1 */ } } SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */ SiS_VBLongWait(SiS_Pr); SiS_DisplayOn(SiS_Pr); if(SiS_Pr->ChipType >= SIS_315H) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); } SiS_VBLongWait(SiS_Pr); if(SiS_Pr->ChipType < SIS_315H) { if(SiS_CRT2IsLCD(SiS_Pr)) { SiS_PanelDelay(SiS_Pr, 1); SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00); } } } } else { /* =================== For LVDS ================== */ if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 /* 300 series */ if(SiS_CRT2IsLCD(SiS_Pr)) { if(SiS_Pr->ChipType == SIS_730) { SiS_PanelDelay(SiS_Pr, 1); SiS_PanelDelay(SiS_Pr, 1); SiS_PanelDelay(SiS_Pr, 1); } SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00); if(!(SiS_CR36BIOSWord23d(SiS_Pr))) { SiS_PanelDelay(SiS_Pr, 0); } } SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); SiS_DisplayOn(SiS_Pr); SiS_UnLockCRT2(SiS_Pr); SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF); if(SiS_BridgeInSlavemode(SiS_Pr)) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F); } else { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40); } if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { if(!(SiS_CRT2IsLCD(SiS_Pr))) { SiS_WaitVBRetrace(SiS_Pr); SiS_SetCH700x(SiS_Pr,0x0E,0x0B); } } if(SiS_CRT2IsLCD(SiS_Pr)) { if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) { if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) { if(!(SiS_CR36BIOSWord23b(SiS_Pr))) { SiS_PanelDelay(SiS_Pr, 1); SiS_PanelDelay(SiS_Pr, 1); } SiS_WaitVBRetrace(SiS_Pr); SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00); } } } #endif /* CONFIG_FB_SIS_300 */ } else { #ifdef CONFIG_FB_SIS_315 /* 315 series */ if(!(SiS_IsNotM650orLater(SiS_Pr))) { /*if(SiS_Pr->ChipType < SIS_340) {*/ /* XGI needs this */ SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x18); /*}*/ } if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { if(SiS_CRT2IsLCD(SiS_Pr)) { SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00); SiS_PanelDelay(SiS_Pr, 0); } } SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); SiS_UnLockCRT2(SiS_Pr); SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7); if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { temp = SiS_GetCH701x(SiS_Pr,0x66); temp &= 0x20; SiS_Chrontel701xBLOff(SiS_Pr); } if(SiS_Pr->ChipType != SIS_550) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f); } if(SiS_Pr->ChipType == SIS_740) { if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { if(SiS_IsLCDOrLCDA(SiS_Pr)) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20); } } } temp1 = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E); if(!(temp1 & 0x80)) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); } if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { if(temp) { SiS_Chrontel701xBLOn(SiS_Pr); } } if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { if(SiS_CRT2IsLCD(SiS_Pr)) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20); if(SiS_Pr->ChipType == SIS_550) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x40); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x10); } } } else if(SiS_IsVAMode(SiS_Pr)) { if(SiS_Pr->ChipType != SIS_740) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20); } } if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f); } if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { if(SiS_IsTVOrYPbPrOrScart(SiS_Pr)) { SiS_Chrontel701xOn(SiS_Pr); } if( (SiS_IsVAMode(SiS_Pr)) || (SiS_IsLCDOrLCDA(SiS_Pr)) ) { SiS_ChrontelDoSomething1(SiS_Pr); } } if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) { if( (SiS_IsVAMode(SiS_Pr)) || (SiS_IsLCDOrLCDA(SiS_Pr)) ) { SiS_Chrontel701xBLOn(SiS_Pr); SiS_ChrontelInitTVVSync(SiS_Pr); } } } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) { if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) { if(SiS_CRT2IsLCD(SiS_Pr)) { SiS_PanelDelay(SiS_Pr, 1); SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00); } } } #endif /* CONFIG_FB_SIS_315 */ } /* 310 series */ } /* LVDS */ } /*********************************************/ /* SET PART 1 REGISTER GROUP */ /*********************************************/ /* Set CRT2 OFFSET / PITCH */ static void SiS_SetCRT2Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RRTI) { unsigned short offset; unsigned char temp; if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return; offset = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,RRTI); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(offset & 0xFF)); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,(offset >> 8)); temp = (unsigned char)(((offset >> 3) & 0xFF) + 1); if(offset & 0x07) temp++; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,temp); } /* Set CRT2 sync and PanelLink mode */ static void SiS_SetCRT2Sync(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RefreshRateTableIndex) { unsigned short tempah=0, tempbl, infoflag; tempbl = 0xC0; if(SiS_Pr->UseCustomMode) { infoflag = SiS_Pr->CInfoFlag; } else { infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag; } if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* LVDS */ if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { tempah = 0; } else if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDInfo & LCDSync)) { tempah = SiS_Pr->SiS_LCDInfo; } else tempah = infoflag >> 8; tempah &= 0xC0; tempah |= 0x20; if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) { tempah |= 0xf0; } if( (SiS_Pr->SiS_IF_DEF_FSTN) || (SiS_Pr->SiS_IF_DEF_DSTN) || (SiS_Pr->SiS_IF_DEF_TRUMPION) || (SiS_Pr->SiS_CustomT == CUT_PANEL848) || (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) { tempah |= 0x30; } if( (SiS_Pr->SiS_IF_DEF_FSTN) || (SiS_Pr->SiS_IF_DEF_DSTN) ) { tempah &= ~0xc0; } } if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { if(SiS_Pr->ChipType >= SIS_315H) { tempah >>= 3; tempah &= 0x18; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xE7,tempah); /* Don't care about 12/18/24 bit mode - TV is via VGA, not PL */ } else { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,0xe0); } } else { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); } } else if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 /* ---- 300 series --- */ if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* 630 - 301B(-DH) */ tempah = infoflag >> 8; tempbl = 0; if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { if(SiS_Pr->SiS_LCDInfo & LCDSync) { tempah = SiS_Pr->SiS_LCDInfo; tempbl = (tempah >> 6) & 0x03; } } tempah &= 0xC0; tempah |= 0x20; if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; tempah |= 0xc0; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) { SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl); } } else { /* 630 - 301 */ tempah = ((infoflag >> 8) & 0xc0) | 0x20; if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); } #endif /* CONFIG_FB_SIS_300 */ } else { #ifdef CONFIG_FB_SIS_315 /* ------- 315 series ------ */ if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* 315 - LVDS */ tempbl = 0; if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) && (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) { tempah = infoflag >> 8; if(SiS_Pr->SiS_LCDInfo & LCDSync) { tempbl = ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6); } } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400) && (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)) { tempah = infoflag >> 8; tempbl = 0x03; } else { tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); tempbl = (tempah >> 6) & 0x03; tempbl |= 0x08; if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempbl |= 0x04; } tempah &= 0xC0; tempah |= 0x20; if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) tempah |= 0xc0; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl); } } } else { /* 315 - TMDS */ tempah = tempbl = infoflag >> 8; if(!SiS_Pr->UseCustomMode) { tempbl = 0; if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { if(ModeNo <= 0x13) { tempah = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)); } } if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { if(SiS_Pr->SiS_LCDInfo & LCDSync) { tempah = SiS_Pr->SiS_LCDInfo; tempbl = (tempah >> 6) & 0x03; } } } } tempah &= 0xC0; tempah |= 0x20; if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10; if(SiS_Pr->SiS_VBType & VB_NoLCD) { /* Imitate BIOS bug */ if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah |= 0xc0; } if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) { tempah >>= 3; tempah &= 0x18; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xe7,tempah); } else { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah); if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl); } } } } #endif /* CONFIG_FB_SIS_315 */ } } } /* Set CRT2 FIFO on 300/540/630/730 */ #ifdef CONFIG_FB_SIS_300 static void SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short temp, index, modeidindex, refreshratetableindex; unsigned short VCLK = 0, MCLK, colorth = 0, data2 = 0; unsigned short tempbx, tempcl, CRT1ModeNo, CRT2ModeNo, SelectRate_backup; unsigned int data, pci50, pciA0; static const unsigned char colortharray[] = { 1, 1, 2, 2, 3, 4 }; SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate; if(!SiS_Pr->CRT1UsesCustomMode) { CRT1ModeNo = SiS_Pr->SiS_CRT1Mode; /* get CRT1 ModeNo */ SiS_SearchModeID(SiS_Pr, &CRT1ModeNo, &modeidindex); SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2); SiS_Pr->SiS_SelectCRT2Rate = 0; refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT1ModeNo, modeidindex); if(CRT1ModeNo >= 0x13) { /* Get VCLK */ index = SiS_GetRefCRTVCLK(SiS_Pr, refreshratetableindex, SiS_Pr->SiS_UseWide); VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; /* Get colordepth */ colorth = SiS_GetColorDepth(SiS_Pr,CRT1ModeNo,modeidindex) >> 1; if(!colorth) colorth++; } } else { CRT1ModeNo = 0xfe; /* Get VCLK */ VCLK = SiS_Pr->CSRClock_CRT1; /* Get color depth */ colorth = colortharray[((SiS_Pr->CModeFlag_CRT1 & ModeTypeMask) - 2)]; } if(CRT1ModeNo >= 0x13) { /* Get MCLK */ if(SiS_Pr->ChipType == SIS_300) { index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A); } else { index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A); } index &= 0x07; MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK; temp = ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 6) & 0x03) << 1; if(!temp) temp++; temp <<= 2; data2 = temp - ((colorth * VCLK) / MCLK); temp = (28 * 16) % data2; data2 = (28 * 16) / data2; if(temp) data2++; if(SiS_Pr->ChipType == SIS_300) { SiS_GetFIFOThresholdIndex300(SiS_Pr, &tempbx, &tempcl); data = SiS_GetFIFOThresholdB300(tempbx, tempcl); } else { pci50 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50); pciA0 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xa0); if(SiS_Pr->ChipType == SIS_730) { index = (unsigned short)(((pciA0 >> 28) & 0x0f) * 3); index += (unsigned short)(((pci50 >> 9)) & 0x03); /* BIOS BUG (2.04.5d, 2.04.6a use ah here, which is unset!) */ index = 0; /* -- do it like the BIOS anyway... */ } else { pci50 >>= 24; pciA0 >>= 24; index = (pci50 >> 1) & 0x07; if(pci50 & 0x01) index += 6; if(!(pciA0 & 0x01)) index += 24; if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12; } data = SiS_GetLatencyFactor630(SiS_Pr, index) + 15; if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80)) data += 5; } data += data2; /* CRT1 Request Period */ SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup; if(!SiS_Pr->UseCustomMode) { CRT2ModeNo = ModeNo; SiS_SearchModeID(SiS_Pr, &CRT2ModeNo, &modeidindex); refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT2ModeNo, modeidindex); /* Get VCLK */ index = SiS_GetVCLK2Ptr(SiS_Pr, CRT2ModeNo, modeidindex, refreshratetableindex); VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) { if(SiS_Pr->SiS_UseROM) { if(ROMAddr[0x220] & 0x01) { VCLK = ROMAddr[0x229] | (ROMAddr[0x22a] << 8); } } } } else { /* Get VCLK */ CRT2ModeNo = 0xfe; VCLK = SiS_Pr->CSRClock; } /* Get colordepth */ colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex) >> 1; if(!colorth) colorth++; data = data * VCLK * colorth; temp = data % (MCLK << 4); data = data / (MCLK << 4); if(temp) data++; if(data < 6) data = 6; else if(data > 0x14) data = 0x14; if(SiS_Pr->ChipType == SIS_300) { temp = 0x16; if((data <= 0x0f) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) temp = 0x13; } else { temp = 0x16; if(( (SiS_Pr->ChipType == SIS_630) || (SiS_Pr->ChipType == SIS_730) ) && (SiS_Pr->ChipRevision >= 0x30)) temp = 0x1b; } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0xe0,temp); if((SiS_Pr->ChipType == SIS_630) && (SiS_Pr->ChipRevision >= 0x30)) { if(data > 0x13) data = 0x13; } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,0xe0,data); } else { /* If mode <= 0x13, we just restore everything */ SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup; } } #endif /* Set CRT2 FIFO on 315/330 series */ #ifdef CONFIG_FB_SIS_315 static void SiS_SetCRT2FIFO_310(struct SiS_Private *SiS_Pr) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3B); if( (SiS_Pr->ChipType == SIS_760) && (SiS_Pr->SiS_SysFlags & SF_760LFB) && (SiS_Pr->SiS_ModeType == Mode32Bpp) && (SiS_Pr->SiS_VGAHDE >= 1280) && (SiS_Pr->SiS_VGAVDE >= 1024) ) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x03); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3b); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x01); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,0x6e); } else { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,~0x3f,0x04); } } #endif static unsigned short SiS_GetVGAHT2(struct SiS_Private *SiS_Pr) { unsigned int tempax,tempbx; tempbx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX; tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT; tempax = (tempax * SiS_Pr->SiS_HT) / tempbx; return (unsigned short)tempax; } /* Set Part 1 / SiS bridge slave mode */ static void SiS_SetGroup1_301(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short temp, modeflag, i, j, xres=0, VGAVDE; static const unsigned short CRTranslation[] = { /* CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7 */ 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, /* CR8 CR9 SR0A SR0B SR0C SR0D SR0E CR0F */ 0x00, 0x0b, 0x17, 0x18, 0x19, 0x00, 0x1a, 0x00, /* CR10 CR11 CR12 CR13 CR14 CR15 CR16 CR17 */ 0x0c, 0x0d, 0x0e, 0x00, 0x0f, 0x10, 0x11, 0x00 }; if(ModeNo <= 0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; } else if(SiS_Pr->UseCustomMode) { modeflag = SiS_Pr->CModeFlag; xres = SiS_Pr->CHDisplay; } else { modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes; } /* The following is only done if bridge is in slave mode: */ if(SiS_Pr->ChipType >= SIS_315H) { if(xres >= 1600) { /* BIOS: == 1600 */ SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x31,0x04); } } SiS_Pr->CHTotal = 8224; /* Max HT, 0x2020, results in 0x3ff in registers */ SiS_Pr->CHDisplay = SiS_Pr->SiS_VGAHDE; if(modeflag & HalfDCLK) SiS_Pr->CHDisplay >>= 1; SiS_Pr->CHBlankStart = SiS_Pr->CHDisplay; if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { SiS_Pr->CHBlankStart += 16; } SiS_Pr->CHBlankEnd = 32; if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { if(xres == 1600) SiS_Pr->CHBlankEnd += 80; } temp = SiS_Pr->SiS_VGAHT - 96; if(!(modeflag & HalfDCLK)) temp -= 32; if(SiS_Pr->SiS_LCDInfo & LCDPass11) { temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x04); temp |= ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2); temp -= 3; temp <<= 3; } else { if(SiS_Pr->SiS_RVBHRS2) temp = SiS_Pr->SiS_RVBHRS2; } SiS_Pr->CHSyncStart = temp; SiS_Pr->CHSyncEnd = 0xffe8; /* results in 0x2000 in registers */ SiS_Pr->CVTotal = 2049; /* Max VT, 0x0801, results in 0x7ff in registers */ VGAVDE = SiS_Pr->SiS_VGAVDE; if (VGAVDE == 357) VGAVDE = 350; else if(VGAVDE == 360) VGAVDE = 350; else if(VGAVDE == 375) VGAVDE = 350; else if(VGAVDE == 405) VGAVDE = 400; else if(VGAVDE == 420) VGAVDE = 400; else if(VGAVDE == 525) VGAVDE = 480; else if(VGAVDE == 1056) VGAVDE = 1024; SiS_Pr->CVDisplay = VGAVDE; SiS_Pr->CVBlankStart = SiS_Pr->CVDisplay; SiS_Pr->CVBlankEnd = 1; if(ModeNo == 0x3c) SiS_Pr->CVBlankEnd = 226; temp = (SiS_Pr->SiS_VGAVT - VGAVDE) >> 1; SiS_Pr->CVSyncStart = VGAVDE + temp; temp >>= 3; SiS_Pr->CVSyncEnd = SiS_Pr->CVSyncStart + temp; SiS_CalcCRRegisters(SiS_Pr, 0); SiS_Pr->CCRT1CRTC[16] &= ~0xE0; for(i = 0; i <= 7; i++) { SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[i]); } for(i = 0x10, j = 8; i <= 0x12; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]); } for(i = 0x15, j = 11; i <= 0x16; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]); } for(i = 0x0a, j = 13; i <= 0x0c; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]); } temp = SiS_Pr->CCRT1CRTC[16] & 0xE0; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x0E],0x1F,temp); temp = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5; if(modeflag & DoubleScanMode) temp |= 0x80; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x09],0x5F,temp); temp = 0; temp |= (SiS_GetReg(SiS_Pr->SiS_P3c4,0x01) & 0x01); if(modeflag & HalfDCLK) temp |= 0x08; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* SR01: HalfDCLK[3], 8/9 div dotclock[0] */ SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,0x00); /* CR14: (text mode: underline location) */ SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,0x00); /* CR17: n/a */ temp = 0; if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) { temp = (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) << 7; } SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* SR0E, dither[7] */ temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); /* ? */ } /* Setup panel link * This is used for LVDS, LCDA and Chrontel TV output * 300/LVDS+TV, 300/301B-DH, 315/LVDS+TV, 315/LCDA */ static void SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short modeflag, resinfo = 0; unsigned short push2, tempax, tempbx, tempcx, temp; unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0; bool islvds = false, issis = false, chkdclkfirst = false; #ifdef CONFIG_FB_SIS_300 unsigned short crt2crtc = 0; #endif #ifdef CONFIG_FB_SIS_315 unsigned short pushcx; #endif if(ModeNo <= 0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; #ifdef CONFIG_FB_SIS_300 crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; #endif } else if(SiS_Pr->UseCustomMode) { modeflag = SiS_Pr->CModeFlag; } else { modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; #ifdef CONFIG_FB_SIS_300 crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; #endif } /* is lvds if really LVDS, or 301B-DH with external LVDS transmitter */ if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) { islvds = true; } /* is really sis if sis bridge, but not 301B-DH */ if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) { issis = true; } if((SiS_Pr->ChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) { if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) { chkdclkfirst = true; } } #ifdef CONFIG_FB_SIS_315 if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { if(IS_SIS330) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10); } else if(IS_SIS740) { if(islvds) { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x03); } else if(SiS_Pr->SiS_VBType & VB_SISVB) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10); } } else { if(islvds) { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04); SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00); } else if(SiS_Pr->SiS_VBType & VB_SISVB) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f); if(SiS_Pr->SiS_VBType & VB_SIS30xC) { if((SiS_Pr->SiS_LCDResInfo == Panel_1024x768) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x20); } } } } } #endif /* Horizontal */ tempax = SiS_Pr->SiS_LCDHDES; if(islvds) { if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(!SiS_Pr->SiS_IF_DEF_FSTN && !SiS_Pr->SiS_IF_DEF_DSTN) { if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) { tempax -= 8; } } } } temp = (tempax & 0x0007); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* BPLHDESKEW[2:0] */ temp = (tempax >> 3) & 0x00FF; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* BPLHDESKEW[10:3] */ tempbx = SiS_Pr->SiS_HDE; if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { tempbx = SiS_Pr->PanelXRes; } if((SiS_Pr->SiS_LCDResInfo == Panel_320x240_1) || (SiS_Pr->SiS_LCDResInfo == Panel_320x240_2) || (SiS_Pr->SiS_LCDResInfo == Panel_320x240_3)) { tempbx >>= 1; } } tempax += tempbx; if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT; temp = tempax; if(temp & 0x07) temp += 8; temp >>= 3; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp); /* BPLHDEE */ tempcx = (SiS_Pr->SiS_HT - tempbx) >> 2; if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { if(SiS_Pr->PanelHRS != 999) tempcx = SiS_Pr->PanelHRS; } } tempcx += tempax; if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT; temp = (tempcx >> 3) & 0x00FF; if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(SiS_Pr->SiS_IF_DEF_TRUMPION) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { switch(ModeNo) { case 0x04: case 0x05: case 0x0d: temp = 0x56; break; case 0x10: temp = 0x60; break; case 0x13: temp = 0x5f; break; case 0x40: case 0x41: case 0x4f: case 0x43: case 0x44: case 0x62: case 0x56: case 0x53: case 0x5d: case 0x5e: temp = 0x54; break; } } } } SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp); /* BPLHRS */ if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { temp += 2; if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { temp += 8; if(SiS_Pr->PanelHRE != 999) { temp = tempcx + SiS_Pr->PanelHRE; if(temp >= SiS_Pr->SiS_HT) temp -= SiS_Pr->SiS_HT; temp >>= 3; } } } else { temp += 10; } temp &= 0x1F; temp |= ((tempcx & 0x07) << 5); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp); /* BPLHRE */ /* Vertical */ tempax = SiS_Pr->SiS_VGAVDE; if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { tempax = SiS_Pr->PanelYRes; } } tempbx = SiS_Pr->SiS_LCDVDES + tempax; if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT; push2 = tempbx; tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE; if(SiS_Pr->ChipType < SIS_315H) { if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->PanelYRes; } } } if(islvds) tempcx >>= 1; else tempcx >>= 2; if( (SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) && (SiS_Pr->PanelVRS != 999) ) { tempcx = SiS_Pr->PanelVRS; tempbx += tempcx; if(issis) tempbx++; } else { tempbx += tempcx; if(SiS_Pr->ChipType < SIS_315H) tempbx++; else if(issis) tempbx++; } if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT; temp = tempbx & 0x00FF; if(SiS_Pr->SiS_IF_DEF_TRUMPION) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if(ModeNo == 0x10) temp = 0xa9; } } SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp); /* BPLVRS */ tempcx >>= 3; tempcx++; if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { if(SiS_Pr->PanelVRE != 999) tempcx = SiS_Pr->PanelVRE; } } tempcx += tempbx; temp = tempcx & 0x000F; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp); /* BPLVRE */ temp = ((tempbx >> 8) & 0x07) << 3; if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) { if(SiS_Pr->SiS_HDE != 640) { if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40; } } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40; if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40; tempbx = 0x87; if((SiS_Pr->ChipType >= SIS_315H) || (SiS_Pr->ChipRevision >= 0x30)) { tempbx = 0x07; if((SiS_Pr->SiS_IF_DEF_CH70xx == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x03) temp |= 0x80; } /* Chrontel 701x operates in 24bit mode (8-8-8, 2x12bit multiplexed) via VGA2 */ if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10) temp |= 0x80; } else { if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) temp |= 0x80; } } } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,tempbx,temp); tempbx = push2; /* BPLVDEE */ tempcx = SiS_Pr->SiS_LCDVDES; /* BPLVDES */ if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { switch(SiS_Pr->SiS_LCDResInfo) { case Panel_640x480: tempbx = SiS_Pr->SiS_VGAVDE - 1; tempcx = SiS_Pr->SiS_VGAVDE; break; case Panel_800x600: if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { if(resinfo == SIS_RI_800x600) tempcx++; } break; case Panel_1024x600: if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { if(resinfo == SIS_RI_1024x600) tempcx++; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { if(resinfo == SIS_RI_800x600) tempcx++; } } break; case Panel_1024x768: if(SiS_Pr->ChipType < SIS_315H) { if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { if(resinfo == SIS_RI_1024x768) tempcx++; } } break; } } temp = ((tempbx >> 8) & 0x07) << 3; temp |= ((tempcx >> 8) & 0x07); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,tempbx); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,tempcx); /* Vertical scaling */ if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 /* 300 series */ tempeax = SiS_Pr->SiS_VGAVDE << 6; temp = (tempeax % (unsigned int)SiS_Pr->SiS_VDE); tempeax = tempeax / (unsigned int)SiS_Pr->SiS_VDE; if(temp) tempeax++; if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempeax = 0x3F; temp = (unsigned short)(tempeax & 0x00FF); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */ tempvcfact = temp; #endif /* CONFIG_FB_SIS_300 */ } else { #ifdef CONFIG_FB_SIS_315 /* 315 series */ tempeax = SiS_Pr->SiS_VGAVDE << 18; tempebx = SiS_Pr->SiS_VDE; temp = (tempeax % tempebx); tempeax = tempeax / tempebx; if(temp) tempeax++; tempvcfact = tempeax; temp = (unsigned short)(tempeax & 0x00FF); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp); temp = (unsigned short)((tempeax & 0x00FF00) >> 8); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp); temp = (unsigned short)((tempeax & 0x00030000) >> 16); if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp); if(SiS_Pr->SiS_VBType & VB_SISPART4SCALER) { temp = (unsigned short)(tempeax & 0x00FF); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp); temp = (unsigned short)((tempeax & 0x00FF00) >> 8); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp); temp = (unsigned short)(((tempeax & 0x00030000) >> 16) << 6); SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp); temp = 0; if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08; SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x30,0xf3,temp); } #endif } /* Horizontal scaling */ tempeax = SiS_Pr->SiS_VGAHDE; /* 1f = ( (VGAHDE * 65536) / ( (VGAHDE * 65536) / HDE ) ) - 1*/ if(chkdclkfirst) { if(modeflag & HalfDCLK) tempeax >>= 1; } tempebx = tempeax << 16; if(SiS_Pr->SiS_HDE == tempeax) { tempecx = 0xFFFF; } else { tempecx = tempebx / SiS_Pr->SiS_HDE; if(SiS_Pr->ChipType >= SIS_315H) { if(tempebx % SiS_Pr->SiS_HDE) tempecx++; } } if(SiS_Pr->ChipType >= SIS_315H) { tempeax = (tempebx / tempecx) - 1; } else { tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1; } tempecx = (tempecx << 16) | (tempeax & 0xFFFF); temp = (unsigned short)(tempecx & 0x00FF); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp); if(SiS_Pr->ChipType >= SIS_315H) { tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact; tempbx = (unsigned short)(tempeax & 0xFFFF); } else { tempeax = SiS_Pr->SiS_VGAVDE << 6; tempbx = tempvcfact & 0x3f; if(tempbx == 0) tempbx = 64; tempeax /= tempbx; tempbx = (unsigned short)(tempeax & 0xFFFF); } if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tempbx--; if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) { if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) tempbx = 1; else if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) tempbx = 1; } temp = ((tempbx >> 8) & 0x07) << 3; temp = temp | ((tempecx >> 8) & 0x07); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,tempbx); tempecx >>= 16; /* BPLHCFACT */ if(!chkdclkfirst) { if(modeflag & HalfDCLK) tempecx >>= 1; } temp = (unsigned short)((tempecx & 0xFF00) >> 8); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp); temp = (unsigned short)(tempecx & 0x00FF); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp); #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SISLVDS)) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20); } } else { if(islvds) { if(SiS_Pr->ChipType == SIS_740) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03); } else { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x23); } } } } #endif #ifdef CONFIG_FB_SIS_300 if(SiS_Pr->SiS_IF_DEF_TRUMPION) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned char *trumpdata; int i, j = crt2crtc; unsigned char TrumpMode13[4] = { 0x01, 0x10, 0x2c, 0x00 }; unsigned char TrumpMode10_1[4] = { 0x01, 0x10, 0x27, 0x00 }; unsigned char TrumpMode10_2[4] = { 0x01, 0x16, 0x10, 0x00 }; if(SiS_Pr->SiS_UseROM) { trumpdata = &ROMAddr[0x8001 + (j * 80)]; } else { if(SiS_Pr->SiS_LCDTypeInfo == 0x0e) j += 7; trumpdata = &SiS300_TrumpionData[j][0]; } SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xbf); for(i=0; i<5; i++) { SiS_SetTrumpionBlock(SiS_Pr, trumpdata); } if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if(ModeNo == 0x13) { for(i=0; i<4; i++) { SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode13[0]); } } else if(ModeNo == 0x10) { for(i=0; i<4; i++) { SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_1[0]); SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_2[0]); } } } SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); } #endif #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x25,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x26,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x27,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x28,0x87); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x29,0x5A); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2A,0x4B); SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x07,0x03); tempax = SiS_Pr->SiS_HDE; /* Blps = lcdhdee(lcdhdes+HDE) + 64 */ if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 || SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 || SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1; tempax += 64; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,tempax & 0xff); temp = (tempax >> 8) << 3; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,~0x078,temp); tempax += 32; /* Blpe = lBlps+32 */ SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,tempax & 0xff); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3A,0x00); /* Bflml = 0 */ SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x007); tempax = SiS_Pr->SiS_VDE; if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 || SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 || SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1; tempax >>= 1; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3B,tempax & 0xff); temp = (tempax >> 8) << 3; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp); tempeax = SiS_Pr->SiS_HDE; if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 || SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 || SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempeax >>= 1; tempeax <<= 2; /* BDxFIFOSTOP = (HDE*4)/128 */ temp = tempeax & 0x7f; tempeax >>= 7; if(temp) tempeax++; temp = tempeax & 0x3f; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,temp); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3F,0x00); /* BDxWadrst0 */ SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3E,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3D,0x10); SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x040); tempax = SiS_Pr->SiS_HDE; if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 || SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 || SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1; tempax >>= 4; /* BDxWadroff = HDE*4/8/8 */ pushcx = tempax; temp = tempax & 0x00FF; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,temp); temp = ((tempax & 0xFF00) >> 8) << 3; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port, 0x44, 0x07, temp); tempax = SiS_Pr->SiS_VDE; /* BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */ if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 || SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 || SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1; tempeax = tempax * pushcx; temp = tempeax & 0xFF; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,temp); temp = (tempeax & 0xFF00) >> 8; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,temp); temp = ((tempeax & 0xFF0000) >> 16) | 0x10; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,temp); temp = ((tempeax & 0x01000000) >> 24) << 7; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port, 0x3C, 0x7F, temp); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x03); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0x50); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x04,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x01); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0x38); if(SiS_Pr->SiS_IF_DEF_FSTN) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2b,0x02); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2c,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,0x0c); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,0x80); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,0xA0); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3a,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3b,0xf0); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3c,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3d,0x10); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3e,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3f,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,0x10); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,0x25); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,0x80); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,0x14); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x44,0x03); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,0x0a); } } #endif /* CONFIG_FB_SIS_315 */ } /* Set Part 1 */ static void SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; #endif unsigned short temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0; unsigned short pushbx=0, CRT1Index=0, modeflag, resinfo=0; #ifdef CONFIG_FB_SIS_315 unsigned short tempbl=0; #endif if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); return; } if(ModeNo <= 0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; } else if(SiS_Pr->UseCustomMode) { modeflag = SiS_Pr->CModeFlag; } else { CRT1Index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2); resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; } SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); if( ! ((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) { if(SiS_Pr->ChipType < SIS_315H ) { #ifdef CONFIG_FB_SIS_300 SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo); #endif } else { #ifdef CONFIG_FB_SIS_315 SiS_SetCRT2FIFO_310(SiS_Pr); #endif } /* 1. Horizontal setup */ if(SiS_Pr->ChipType < SIS_315H ) { #ifdef CONFIG_FB_SIS_300 /* ------------- 300 series --------------*/ temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */ SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */ temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp); /* CRT2 Horizontal Total Overflow [7:4] */ temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF; /* BTVGA2HDEE 0x0A,0x0C */ SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* CRT2 Horizontal Display Enable End */ pushbx = SiS_Pr->SiS_VGAHDE + 12; /* bx BTVGA2HRS 0x0B,0x0C */ tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2; tempbx = pushbx + tempcx; tempcx <<= 1; tempcx += tempbx; bridgeadd = 12; #endif /* CONFIG_FB_SIS_300 */ } else { #ifdef CONFIG_FB_SIS_315 /* ------------------- 315/330 series --------------- */ tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HT 0x08,0x09 */ if(modeflag & HalfDCLK) { if(SiS_Pr->SiS_VBType & VB_SISVB) { tempcx >>= 1; } else { tempax = SiS_Pr->SiS_VGAHDE >> 1; tempcx = SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE + tempax; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { tempcx = SiS_Pr->SiS_HT - tempax; } } } tempcx--; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,tempcx); /* CRT2 Horizontal Total */ temp = (tempcx >> 4) & 0xF0; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0F,temp); /* CRT2 Horizontal Total Overflow [7:4] */ tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HDEE 0x0A,0x0C */ tempbx = SiS_Pr->SiS_VGAHDE; tempcx -= tempbx; tempcx >>= 2; if(modeflag & HalfDCLK) { tempbx >>= 1; tempcx >>= 1; } tempbx += 16; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,tempbx); /* CRT2 Horizontal Display Enable End */ pushbx = tempbx; tempcx >>= 1; tempbx += tempcx; tempcx += tempbx; bridgeadd = 16; if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->ChipType >= SIS_661) { if((SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) { if(resinfo == SIS_RI_1280x1024) { tempcx = (tempcx & 0xff00) | 0x30; } else if(resinfo == SIS_RI_1600x1200) { tempcx = (tempcx & 0xff00) | 0xff; } } } } #endif /* CONFIG_FB_SIS_315 */ } /* 315/330 series */ if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->UseCustomMode) { tempbx = SiS_Pr->CHSyncStart + bridgeadd; tempcx = SiS_Pr->CHSyncEnd + bridgeadd; tempax = SiS_Pr->SiS_VGAHT; if(modeflag & HalfDCLK) tempax >>= 1; tempax--; if(tempcx > tempax) tempcx = tempax; } if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { unsigned char cr4, cr14, cr5, cr15; if(SiS_Pr->UseCustomMode) { cr4 = SiS_Pr->CCRT1CRTC[4]; cr14 = SiS_Pr->CCRT1CRTC[14]; cr5 = SiS_Pr->CCRT1CRTC[5]; cr15 = SiS_Pr->CCRT1CRTC[15]; } else { cr4 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4]; cr14 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14]; cr5 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5]; cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15]; } tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3; /* (VGAHRS-3)*8 */ tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3; /* (VGAHRE-3)*8 */ tempcx &= 0x00FF; tempcx |= (tempbx & 0xFF00); tempbx += bridgeadd; tempcx += bridgeadd; tempax = SiS_Pr->SiS_VGAHT; if(modeflag & HalfDCLK) tempax >>= 1; tempax--; if(tempcx > tempax) tempcx = tempax; } if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) { tempbx = 1040; tempcx = 1044; /* HWCursor bug! */ } } SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,tempbx); /* CRT2 Horizontal Retrace Start */ SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,tempcx); /* CRT2 Horizontal Retrace End */ temp = ((tempbx >> 8) & 0x0F) | ((pushbx >> 4) & 0xF0); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp); /* Overflow */ /* 2. Vertical setup */ tempcx = SiS_Pr->SiS_VGAVT - 1; temp = tempcx & 0x00FF; if(SiS_Pr->ChipType < SIS_661) { if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { if(SiS_Pr->ChipType < SIS_315H) { if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) { temp--; } } } else { temp--; } } else if(SiS_Pr->ChipType >= SIS_315H) { temp--; } } SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp); /* CRT2 Vertical Total */ tempbx = SiS_Pr->SiS_VGAVDE - 1; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,tempbx); /* CRT2 Vertical Display Enable End */ temp = ((tempbx >> 5) & 0x38) | ((tempcx >> 8) & 0x07); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp); /* Overflow */ if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) { tempbx++; tempax = tempbx; tempcx++; tempcx -= tempax; tempcx >>= 2; tempbx += tempcx; if(tempcx < 4) tempcx = 4; tempcx >>= 2; tempcx += tempbx; tempcx++; } else { tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1; /* BTVGA2VRS 0x10,0x11 */ tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1; /* BTVGA2VRE 0x11 */ } if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->UseCustomMode) { tempbx = SiS_Pr->CVSyncStart; tempcx = SiS_Pr->CVSyncEnd; } if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { unsigned char cr8, cr7, cr13; if(SiS_Pr->UseCustomMode) { cr8 = SiS_Pr->CCRT1CRTC[8]; cr7 = SiS_Pr->CCRT1CRTC[7]; cr13 = SiS_Pr->CCRT1CRTC[13]; tempcx = SiS_Pr->CCRT1CRTC[9]; } else { cr8 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[8]; cr7 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7]; cr13 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13]; tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9]; } tempbx = cr8; if(cr7 & 0x04) tempbx |= 0x0100; if(cr7 & 0x80) tempbx |= 0x0200; if(cr13 & 0x08) tempbx |= 0x0400; } } SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,tempbx); /* CRT2 Vertical Retrace Start */ temp = ((tempbx >> 4) & 0x70) | (tempcx & 0x0F); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,temp); /* CRT2 Vert. Retrace End; Overflow */ /* 3. Panel delay compensation */ if(SiS_Pr->ChipType < SIS_315H) { #ifdef CONFIG_FB_SIS_300 /* ---------- 300 series -------------- */ if(SiS_Pr->SiS_VBType & VB_SISVB) { temp = 0x20; if(SiS_Pr->ChipType == SIS_300) { temp = 0x10; if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) temp = 0x2c; if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20; } if(SiS_Pr->SiS_VBType & VB_SIS301) { if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20; } if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960) temp = 0x24; if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) temp = 0x2c; if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08; if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) temp = 0x2c; else temp = 0x20; } if(SiS_Pr->SiS_UseROM) { if(ROMAddr[0x220] & 0x80) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) temp = ROMAddr[0x221]; else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp = ROMAddr[0x222]; else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = ROMAddr[0x223]; else temp = ROMAddr[0x224]; } } if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC; } } else { temp = 0x20; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) temp = 0x04; } if(SiS_Pr->SiS_UseROM) { if(ROMAddr[0x220] & 0x80) { temp = ROMAddr[0x220]; } } if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC; } } temp &= 0x3c; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */ #endif /* CONFIG_FB_SIS_300 */ } else { #ifdef CONFIG_FB_SIS_315 /* --------------- 315/330 series ---------------*/ if(SiS_Pr->ChipType < SIS_661) { if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { if(SiS_Pr->ChipType == SIS_740) temp = 0x03; else temp = 0x00; if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a; tempbl = 0xF0; if(SiS_Pr->ChipType == SIS_650) { if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F; } } if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) { temp = 0x08; tempbl = 0; if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) { if(ROMAddr[0x13c] & 0x80) tempbl = 0xf0; } } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,tempbl,temp); /* Panel Link Delay Compensation */ } } /* < 661 */ tempax = 0; if(modeflag & DoubleScanMode) tempax |= 0x80; if(modeflag & HalfDCLK) tempax |= 0x40; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax); #endif /* CONFIG_FB_SIS_315 */ } } /* Slavemode */ if(SiS_Pr->SiS_VBType & VB_SISVB) { if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { /* For 301BDH with LCD, we set up the Panel Link */ SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } } else { if(SiS_Pr->ChipType < SIS_315H) { SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } else { if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex); } } else { SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex); } } } } /*********************************************/ /* SET PART 2 REGISTER GROUP */ /*********************************************/ #ifdef CONFIG_FB_SIS_315 static unsigned char * SiS_GetGroup2CLVXPtr(struct SiS_Private *SiS_Pr, int tabletype) { const unsigned char *tableptr = NULL; unsigned short a, b, p = 0; a = SiS_Pr->SiS_VGAHDE; b = SiS_Pr->SiS_HDE; if(tabletype) { a = SiS_Pr->SiS_VGAVDE; b = SiS_Pr->SiS_VDE; } if(a < b) { tableptr = SiS_Part2CLVX_1; } else if(a == b) { tableptr = SiS_Part2CLVX_2; } else { if(SiS_Pr->SiS_TVMode & TVSetPAL) { tableptr = SiS_Part2CLVX_4; } else { tableptr = SiS_Part2CLVX_3; } if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) tableptr = SiS_Part2CLVX_3; else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tableptr = SiS_Part2CLVX_3; else tableptr = SiS_Part2CLVX_5; } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { tableptr = SiS_Part2CLVX_6; } do { if((tableptr[p] | tableptr[p+1] << 8) == a) break; p += 0x42; } while((tableptr[p] | tableptr[p+1] << 8) != 0xffff); if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42; } p += 2; return ((unsigned char *)&tableptr[p]); } static void SiS_SetGroup2_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned char *tableptr; unsigned char temp; int i, j; if(!(SiS_Pr->SiS_VBType & VB_SISTAP4SCALER)) return; tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 0); for(i = 0x80, j = 0; i <= 0xbf; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]); } if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 1); for(i = 0xc0, j = 0; i <= 0xff; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]); } } temp = 0x10; if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp |= 0x04; SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xeb,temp); } static bool SiS_GetCRT2Part2Ptr(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex,unsigned short *CRT2Index, unsigned short *ResIndex) { if(SiS_Pr->ChipType < SIS_315H) return false; if(ModeNo <= 0x13) (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; else (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; (*ResIndex) &= 0x3f; (*CRT2Index) = 0; if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { (*CRT2Index) = 200; } } if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if(SiS_Pr->SiS_SetFlag & LCDVESATiming) (*CRT2Index) = 206; } } return (((*CRT2Index) != 0)); } #endif #ifdef CONFIG_FB_SIS_300 static void SiS_Group2LCDSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short crt2crtc) { unsigned short tempcx; static const unsigned char atable[] = { 0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02, 0xab,0x87,0xab,0x9e,0xe7,0x02,0x02 }; if(!SiS_Pr->UseCustomMode) { if( ( ( (SiS_Pr->ChipType == SIS_630) || (SiS_Pr->ChipType == SIS_730) ) && (SiS_Pr->ChipRevision > 2) ) && (SiS_Pr->SiS_LCDResInfo == Panel_1024x768) && (!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) && (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) { if(ModeNo == 0x13) { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6); } else if((crt2crtc & 0x3F) == 4) { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2); } } if(SiS_Pr->ChipType < SIS_315H) { if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) { crt2crtc &= 0x1f; tempcx = 0; if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) { if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { tempcx += 7; } } tempcx += crt2crtc; if(crt2crtc >= 4) { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff); } if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) { if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { if(crt2crtc == 4) { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28); } } } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]); } } } } /* For ECS A907. Highly preliminary. */ static void SiS_Set300Part2Regs(struct SiS_Private *SiS_Pr, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex, unsigned short ModeNo) { const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL; unsigned short crt2crtc, resindex; int i, j; if(SiS_Pr->ChipType != SIS_300) return; if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return; if(SiS_Pr->UseCustomMode) return; if(ModeNo <= 0x13) { crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; } else { crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; } resindex = crt2crtc & 0x3F; if(SiS_Pr->SiS_SetFlag & LCDVESATiming) CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; else CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_2; /* The BIOS code (1.16.51,56) is obviously a fragment! */ if(ModeNo > 0x13) { CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; resindex = 4; } SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]); for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) { SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); } for(j = 0x1c; j <= 0x1d; i++, j++ ) { SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); } for(j = 0x1f; j <= 0x21; i++, j++ ) { SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]); } #endif static void SiS_SetTVSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo) { if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) return; if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) return; if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) { const unsigned char specialtv[] = { 0xa7,0x07,0xf2,0x6e,0x17,0x8b,0x73,0x53, 0x13,0x40,0x34,0xf4,0x63,0xbb,0xcc,0x7a, 0x58,0xe4,0x73,0xda,0x13 }; int i, j; for(i = 0x1c, j = 0; i <= 0x30; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,specialtv[j]); } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,0x72); if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750)) { if(SiS_Pr->SiS_TVMode & TVSetPALM) { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1b); } else { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14); /* 15 */ SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1a); /* 1b */ } } } } else { if((ModeNo == 0x38) || (ModeNo == 0x4a) || (ModeNo == 0x64) || (ModeNo == 0x52) || (ModeNo == 0x58) || (ModeNo == 0x5c)) { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b); /* 21 */ SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54); /* 5a */ } else { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1a); /* 21 */ SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x53); /* 5a */ } } } static void SiS_SetGroup2_Tail(struct SiS_Private *SiS_Pr, unsigned short ModeNo) { unsigned short temp; if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) { if(SiS_Pr->SiS_VGAVDE == 525) { temp = 0xc3; if(SiS_Pr->SiS_ModeType <= ModeVGA) { temp++; if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp += 2; } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3); } else if(SiS_Pr->SiS_VGAVDE == 420) { temp = 0x4d; if(SiS_Pr->SiS_ModeType <= ModeVGA) { temp++; if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp++; } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp); } } if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) { if(SiS_Pr->SiS_VBType & VB_SIS30xB) { SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x1a,0x03); /* Not always for LV, see SetGrp2 */ } temp = 1; if(ModeNo <= 0x13) temp = 3; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0b,temp); } #if 0 /* 651+301C, for 1280x768 - do I really need that? */ if((SiS_Pr->SiS_PanelXRes == 1280) && (SiS_Pr->SiS_PanelYRes == 768)) { if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) { if(((SiS_Pr->SiS_HDE == 640) && (SiS_Pr->SiS_VDE == 480)) || ((SiS_Pr->SiS_HDE == 320) && (SiS_Pr->SiS_VDE == 240))) { SiS_SetReg(SiS_Part2Port,0x01,0x2b); SiS_SetReg(SiS_Part2Port,0x02,0x13); SiS_SetReg(SiS_Part2Port,0x04,0xe5); SiS_SetReg(SiS_Part2Port,0x05,0x08); SiS_SetReg(SiS_Part2Port,0x06,0xe2); SiS_SetReg(SiS_Part2Port,0x1c,0x21); SiS_SetReg(SiS_Part2Port,0x1d,0x45); SiS_SetReg(SiS_Part2Port,0x1f,0x0b); SiS_SetReg(SiS_Part2Port,0x20,0x00); SiS_SetReg(SiS_Part2Port,0x21,0xa9); SiS_SetReg(SiS_Part2Port,0x23,0x0b); SiS_SetReg(SiS_Part2Port,0x25,0x04); } } } #endif } } static void SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short i, j, tempax, tempbx, tempcx, tempch, tempcl, temp; unsigned short push2, modeflag, crt2crtc, bridgeoffset; unsigned int longtemp, PhaseIndex; bool newtvphase; const unsigned char *TimingPoint; #ifdef CONFIG_FB_SIS_315 unsigned short resindex, CRT2Index; const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL; if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return; #endif if(ModeNo <= 0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; } else if(SiS_Pr->UseCustomMode) { modeflag = SiS_Pr->CModeFlag; crt2crtc = 0; } else { modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; } temp = 0; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO)) temp |= 0x08; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO)) temp |= 0x04; if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) temp |= 0x02; if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp |= 0x01; if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) temp |= 0x10; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x00,temp); PhaseIndex = 0x01; /* SiS_PALPhase */ TimingPoint = SiS_Pr->SiS_PALTiming; newtvphase = false; if( (SiS_Pr->SiS_VBType & VB_SIS30xBLV) && ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) { newtvphase = true; } if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { TimingPoint = SiS_Pr->SiS_HiTVExtTiming; if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { TimingPoint = SiS_Pr->SiS_HiTVSt2Timing; if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) { TimingPoint = SiS_Pr->SiS_HiTVSt1Timing; } } } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { i = 0; if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) i = 2; else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) i = 1; TimingPoint = &SiS_YPbPrTable[i][0]; PhaseIndex = 0x00; /* SiS_NTSCPhase */ } else if(SiS_Pr->SiS_TVMode & TVSetPAL) { if(newtvphase) PhaseIndex = 0x09; /* SiS_PALPhase2 */ } else { TimingPoint = SiS_Pr->SiS_NTSCTiming; PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetNTSCJ) ? 0x01 : 0x00; /* SiS_PALPhase : SiS_NTSCPhase */ if(newtvphase) PhaseIndex += 8; /* SiS_PALPhase2 : SiS_NTSCPhase2 */ } if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) { PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetPALM) ? 0x02 : 0x03; /* SiS_PALMPhase : SiS_PALNPhase */ if(newtvphase) PhaseIndex += 8; /* SiS_PALMPhase2 : SiS_PALNPhase2 */ } if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) { if(SiS_Pr->SiS_TVMode & TVSetPALM) { PhaseIndex = 0x05; /* SiS_SpecialPhaseM */ } else if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) { PhaseIndex = 0x11; /* SiS_SpecialPhaseJ */ } else { PhaseIndex = 0x10; /* SiS_SpecialPhase */ } } for(i = 0x31, j = 0; i <= 0x34; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[(PhaseIndex * 4) + j]); } for(i = 0x01, j = 0; i <= 0x2D; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]); } for(i = 0x39; i <= 0x45; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]); } if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { if(SiS_Pr->SiS_ModeType != ModeText) { SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F); } } SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x0A,SiS_Pr->SiS_NewFlickerMode); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x35,SiS_Pr->SiS_RY1COE); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x36,SiS_Pr->SiS_RY2COE); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE); if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempax = 950; else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempax = 680; else if(SiS_Pr->SiS_TVMode & TVSetPAL) tempax = 520; else tempax = 440; /* NTSC, YPbPr 525 */ if( ((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) && (SiS_Pr->SiS_VDE <= tempax)) || ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) && ((SiS_Pr->SiS_VGAHDE == 1024) || (SiS_Pr->SiS_VDE <= tempax)) ) ) { tempax -= SiS_Pr->SiS_VDE; tempax >>= 1; if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) { tempax >>= 1; } tempax &= 0x00ff; temp = tempax + (unsigned short)TimingPoint[0]; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp); temp = tempax + (unsigned short)TimingPoint[1]; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp); if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) { if(SiS_Pr->SiS_TVMode & TVSetPAL) { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54); } else { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x17); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1d); } } } tempcx = SiS_Pr->SiS_HT; if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1; tempcx--; if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) tempcx--; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,tempcx); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,((tempcx >> 8) & 0x0f)); tempcx = SiS_Pr->SiS_HT >> 1; if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1; tempcx += 7; if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4; SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,((tempcx << 4) & 0xf0)); tempbx = TimingPoint[j] | (TimingPoint[j+1] << 8); tempbx += tempcx; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x24,tempbx); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,((tempbx >> 4) & 0xf0)); tempbx += 8; if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { tempbx -= 4; tempcx = tempbx; } SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,((tempbx << 4) & 0xf0)); j += 2; tempcx += (TimingPoint[j] | (TimingPoint[j+1] << 8)); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x27,tempcx); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,((tempcx >> 4) & 0xf0)); tempcx += 8; if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4; SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,((tempcx << 4) & 0xf0)); tempcx = SiS_Pr->SiS_HT >> 1; if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1; j += 2; tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8)); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,((tempcx << 4) & 0xf0)); tempcx -= 11; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { tempcx = SiS_GetVGAHT2(SiS_Pr) - 1; } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2E,tempcx); tempbx = SiS_Pr->SiS_VDE; if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { if(SiS_Pr->SiS_VGAVDE == 360) tempbx = 746; if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 746; if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 853; } else if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) { tempbx >>= 1; if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) { if((ModeNo <= 0x13) && (crt2crtc == 1)) tempbx++; } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { if(SiS_Pr->SiS_ModeType <= ModeVGA) { if(crt2crtc == 4) tempbx++; } } } if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { if((ModeNo == 0x2f) || (ModeNo == 0x5d) || (ModeNo == 0x5e)) tempbx++; } if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { if(ModeNo == 0x03) tempbx++; /* From 1.10.7w - doesn't make sense */ } } } tempbx -= 2; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2F,tempbx); temp = (tempcx >> 8) & 0x0F; temp |= ((tempbx >> 2) & 0xC0); if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) { temp |= 0x10; if(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO) temp |= 0x20; } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,temp); if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) { SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xdf,((tempbx & 0x0400) >> 5)); } if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { tempbx = SiS_Pr->SiS_VDE; if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) && (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) ) { tempbx >>= 1; } tempbx -= 3; temp = ((tempbx >> 3) & 0x60) | 0x18; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x46,temp); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,tempbx); if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) { SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xbf,((tempbx & 0x0400) >> 4)); } } tempbx = 0; if(!(modeflag & HalfDCLK)) { if(SiS_Pr->SiS_VGAHDE >= SiS_Pr->SiS_HDE) { tempax = 0; tempbx |= 0x20; } } tempch = tempcl = 0x01; if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { if(SiS_Pr->SiS_VGAHDE >= 960) { if((!(modeflag & HalfDCLK)) || (SiS_Pr->ChipType < SIS_315H)) { tempcl = 0x20; if(SiS_Pr->SiS_VGAHDE >= 1280) { tempch = 20; tempbx &= ~0x20; } else if(SiS_Pr->SiS_VGAHDE >= 1024) { tempch = 25; } else { tempch = 25; /* OK */ } } } } if(!(tempbx & 0x20)) { if(modeflag & HalfDCLK) tempcl <<= 1; longtemp = ((SiS_Pr->SiS_VGAHDE * tempch) / tempcl) << 13; if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) longtemp <<= 3; tempax = longtemp / SiS_Pr->SiS_HDE; if(longtemp % SiS_Pr->SiS_HDE) tempax++; tempbx |= ((tempax >> 8) & 0x1F); tempcx = tempax >> 13; } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x44,tempax); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,tempbx); if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { tempcx &= 0x07; if(tempbx & 0x20) tempcx = 0; SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xF8,tempcx); if(SiS_Pr->SiS_TVMode & TVSetPAL) { tempbx = 0x0382; tempcx = 0x007e; } else { tempbx = 0x0369; tempcx = 0x0061; } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4B,tempbx); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4C,tempcx); temp = (tempcx & 0x0300) >> 6; temp |= ((tempbx >> 8) & 0x03); if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { temp |= 0x10; if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp |= 0x20; else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp |= 0x40; } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4D,temp); temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,(temp - 3)); SiS_SetTVSpecial(SiS_Pr, ModeNo); if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) { temp = 0; if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8; SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xf7,temp); } } if(SiS_Pr->SiS_TVMode & TVSetPALM) { if(!(SiS_Pr->SiS_TVMode & TVSetNTSC1024)) { temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,(temp - 1)); } SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xEF); } if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,0x00); } } if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) return; /* From here: Part2 LCD setup */ tempbx = SiS_Pr->SiS_HDE; if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1; tempbx--; /* RHACTE = HDE - 1 */ SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,tempbx); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,((tempbx >> 4) & 0xf0)); temp = 0x01; if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) { if(SiS_Pr->SiS_ModeType == ModeEGA) { if(SiS_Pr->SiS_VGAHDE >= 1024) { temp = 0x02; if(SiS_Pr->SiS_SetFlag & LCDVESATiming) { temp = 0x01; } } } } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,temp); tempbx = SiS_Pr->SiS_VDE - 1; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x03,tempbx); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,((tempbx >> 8) & 0x07)); tempcx = SiS_Pr->SiS_VT - 1; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x19,tempcx); temp = (tempcx >> 3) & 0xE0; if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) { /* Enable dithering; only do this for 32bpp mode */ if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) { temp |= 0x10; } } SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1A,0x0f,temp); SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x09,0xF0); SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x0A,0xF0); SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB); SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF); #ifdef CONFIG_FB_SIS_315 if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, &CRT2Index, &resindex)) { switch(CRT2Index) { case 206: CRT2Part2Ptr = SiS310_CRT2Part2_Asus1024x768_3; break; default: case 200: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; break; } SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]); for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) { SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); } for(j = 0x1c; j <= 0x1d; i++, j++ ) { SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); } for(j = 0x1f; j <= 0x21; i++, j++ ) { SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]); } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]); SiS_SetGroup2_Tail(SiS_Pr, ModeNo); } else { #endif /* Checked for 1024x768, 1280x1024, 1400x1050, 1600x1200 */ /* Clevo dual-link 1024x768 */ /* Compaq 1280x1024 has HT 1696 sometimes (calculation OK, if given HT is correct) */ /* Acer: OK, but uses different setting for VESA timing at 640/800/1024 and 640x400 */ if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { if((SiS_Pr->SiS_LCDInfo & LCDPass11) || (SiS_Pr->PanelYRes == SiS_Pr->SiS_VDE)) { tempbx = SiS_Pr->SiS_VDE - 1; tempcx = SiS_Pr->SiS_VT - 1; } else { tempbx = SiS_Pr->SiS_VDE + ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2); tempcx = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2); } } else { tempbx = SiS_Pr->PanelYRes; tempcx = SiS_Pr->SiS_VT; tempax = 1; if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) { tempax = SiS_Pr->PanelYRes; /* if(SiS_Pr->SiS_VGAVDE == 525) tempax += 0x3c; */ /* 651+301C */ if(SiS_Pr->PanelYRes < SiS_Pr->SiS_VDE) { tempax = tempcx = 0; } else { tempax -= SiS_Pr->SiS_VDE; } tempax >>= 1; } tempcx -= tempax; /* lcdvdes */ tempbx -= tempax; /* lcdvdee */ } /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */ SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */ SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */ temp = (tempbx >> 5) & 0x38; temp |= ((tempcx >> 8) & 0x07); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp); tempax = SiS_Pr->SiS_VDE; if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) { tempax = SiS_Pr->PanelYRes; } tempcx = (SiS_Pr->SiS_VT - tempax) >> 4; if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) { if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) { tempcx = (SiS_Pr->SiS_VT - tempax) / 10; } } tempbx = ((SiS_Pr->SiS_VT + SiS_Pr->SiS_VDE) >> 1) - 1; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) { if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { /* ? */ tempax = SiS_Pr->SiS_VT - SiS_Pr->PanelYRes; if(tempax % 4) { tempax >>= 2; tempax++; } else { tempax >>= 2; } tempbx -= (tempax - 1); } else { tempbx -= 10; if(tempbx <= SiS_Pr->SiS_VDE) tempbx = SiS_Pr->SiS_VDE + 1; } } } if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { tempbx++; if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (crt2crtc == 6)) { if(SiS_Pr->SiS_SetFlag & LCDVESATiming) { tempbx = 770; tempcx = 3; } } } /* non-expanding: lcdvrs = ((VT + VDE) / 2) - 10 */ if(SiS_Pr->UseCustomMode) { tempbx = SiS_Pr->CVSyncStart; } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */ temp = (tempbx >> 4) & 0xF0; tempbx += (tempcx + 1); temp |= (tempbx & 0x0F); if(SiS_Pr->UseCustomMode) { temp &= 0xf0; temp |= (SiS_Pr->CVSyncEnd & 0x0f); } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp); #ifdef CONFIG_FB_SIS_300 SiS_Group2LCDSpecial(SiS_Pr, ModeNo, crt2crtc); #endif bridgeoffset = 7; if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) bridgeoffset += 2; if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) bridgeoffset += 2; /* OK for Averatec 1280x800 (301C) */ if(SiS_IsDualLink(SiS_Pr)) bridgeoffset++; else if(SiS_Pr->SiS_VBType & VB_SIS302LV) bridgeoffset++; /* OK for Asus A4L 1280x800 */ /* Higher bridgeoffset shifts to the LEFT */ temp = 0; if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) { if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) { temp = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2); if(SiS_IsDualLink(SiS_Pr)) temp >>= 1; } } temp += bridgeoffset; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1F,temp); /* lcdhdes */ SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0F,((temp >> 4) & 0xf0)); tempcx = SiS_Pr->SiS_HT; tempax = tempbx = SiS_Pr->SiS_HDE; if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) { if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) { tempax = SiS_Pr->PanelXRes; tempbx = SiS_Pr->PanelXRes - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2); } } if(SiS_IsDualLink(SiS_Pr)) { tempcx >>= 1; tempbx >>= 1; tempax >>= 1; } tempbx += bridgeoffset; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempbx); /* lcdhdee */ SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,((tempbx >> 8) & 0x0f)); tempcx = (tempcx - tempax) >> 2; tempbx += tempcx; push2 = tempbx; if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) { if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) { if(SiS_Pr->SiS_LCDInfo & LCDPass11) { if(SiS_Pr->SiS_HDE == 1280) tempbx = (tempbx & 0xff00) | 0x47; } } } if(SiS_Pr->UseCustomMode) { tempbx = SiS_Pr->CHSyncStart; if(modeflag & HalfDCLK) tempbx <<= 1; if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1; tempbx += bridgeoffset; } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */ SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0)); tempbx = push2; tempcx <<= 1; if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) { if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) tempcx >>= 2; } tempbx += tempcx; if(SiS_Pr->UseCustomMode) { tempbx = SiS_Pr->CHSyncEnd; if(modeflag & HalfDCLK) tempbx <<= 1; if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1; tempbx += bridgeoffset; } SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */ SiS_SetGroup2_Tail(SiS_Pr, ModeNo); #ifdef CONFIG_FB_SIS_300 SiS_Set300Part2Regs(SiS_Pr, ModeIdIndex, RefreshRateTableIndex, ModeNo); #endif #ifdef CONFIG_FB_SIS_315 } /* CRT2-LCD from table */ #endif } /*********************************************/ /* SET PART 3 REGISTER GROUP */ /*********************************************/ static void SiS_SetGroup3(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned short i; const unsigned char *tempdi; if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return; #ifndef SIS_CP SiS_SetReg(SiS_Pr->SiS_Part3Port,0x00,0x00); #else SIS_CP_INIT301_CP #endif if(SiS_Pr->SiS_TVMode & TVSetPAL) { SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA); SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8); } else { SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xF5); SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xB7); } if(SiS_Pr->SiS_TVMode & TVSetPALM) { SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA); SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8); SiS_SetReg(SiS_Pr->SiS_Part3Port,0x3D,0xA8); } tempdi = NULL; if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { tempdi = SiS_Pr->SiS_HiTVGroup3Data; if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) { tempdi = SiS_Pr->SiS_HiTVGroup3Simu; } } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) { if(!(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) { tempdi = SiS_HiTVGroup3_1; if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempdi = SiS_HiTVGroup3_2; } } if(tempdi) { for(i=0; i<=0x3E; i++) { SiS_SetReg(SiS_Pr->SiS_Part3Port,i,tempdi[i]); } if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) { if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) { SiS_SetReg(SiS_Pr->SiS_Part3Port,0x28,0x3f); } } } #ifdef SIS_CP SIS_CP_INIT301_CP2 #endif } /*********************************************/ /* SET PART 4 REGISTER GROUP */ /*********************************************/ #ifdef CONFIG_FB_SIS_315 #if 0 static void SiS_ShiftXPos(struct SiS_Private *SiS_Pr, int shift) { unsigned short temp, temp1, temp2; temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x1f); temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x20); temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,temp); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0f,((temp >> 4) & 0xf0)); temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x2b) & 0x0f; temp = (unsigned short)((int)(temp) + shift); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2b,0xf0,(temp & 0x0f)); temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43); temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x42); temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,temp); SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x42,0x0f,((temp >> 4) & 0xf0)); } #endif static void SiS_SetGroup4_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned short temp, temp1, resinfo = 0; unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; if(!(SiS_Pr->SiS_VBType & VB_SIS30xCLV)) return; if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) return; if(SiS_Pr->ChipType >= XGI_20) return; if((SiS_Pr->ChipType >= SIS_661) && (SiS_Pr->SiS_ROMNew)) { if(!(ROMAddr[0x61] & 0x04)) return; } if(ModeNo > 0x13) { resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; } SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3a,0x08); temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x3a); if(!(temp & 0x01)) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3a,0xdf); SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xfc); if((SiS_Pr->ChipType < SIS_661) && (!(SiS_Pr->SiS_ROMNew))) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xf8); } SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0xfb); if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp = 0x0000; else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp = 0x0002; else if(SiS_Pr->SiS_TVMode & TVSetHiVision) temp = 0x0400; else temp = 0x0402; if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) { temp1 = 0; if(SiS_Pr->SiS_TVMode & TVAspect43) temp1 = 4; SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0f,0xfb,temp1); if(SiS_Pr->SiS_TVMode & TVAspect43LB) temp |= 0x01; SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0x7c,(temp & 0xff)); SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8)); if(ModeNo > 0x13) { SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x39,0xfd); } } else { temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x3b) & 0x03; if(temp1 == 0x01) temp |= 0x01; if(temp1 == 0x03) temp |= 0x04; /* ? why not 0x10? */ SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xf8,(temp & 0xff)); SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8)); if(ModeNo > 0x13) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3b,0xfd); } } #if 0 if(SiS_Pr->ChipType >= SIS_661) { /* ? */ if(SiS_Pr->SiS_TVMode & TVAspect43) { if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) { if(resinfo == SIS_RI_1024x768) { SiS_ShiftXPos(SiS_Pr, 97); } else { SiS_ShiftXPos(SiS_Pr, 111); } } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) { SiS_ShiftXPos(SiS_Pr, 136); } } } #endif } } #endif static void SiS_SetCRT2VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short vclkindex, temp, reg1, reg2; if(SiS_Pr->UseCustomMode) { reg1 = SiS_Pr->CSR2B; reg2 = SiS_Pr->CSR2C; } else { vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); reg1 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A; reg2 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B; } if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) { SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x57); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,0x46); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1f,0xf6); } else { SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2); } } else { SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x01); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1); } SiS_SetReg(SiS_Pr->SiS_Part4Port,0x12,0x00); temp = 0x08; if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) temp |= 0x20; SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x12,temp); } static void SiS_SetDualLinkEtc(struct SiS_Private *SiS_Pr) { if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) { if((SiS_CRT2IsLCD(SiS_Pr)) || (SiS_IsVAMode(SiS_Pr))) { if(SiS_Pr->SiS_LCDInfo & LCDDualLink) { SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c); } else { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20); } } } } if(SiS_Pr->SiS_VBType & VB_SISEMI) { SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00); #ifdef SET_EMI SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c); #endif SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10); } } static void SiS_SetGroup4(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short tempax, tempcx, tempbx, modeflag, temp, resinfo; unsigned int tempebx, tempeax, templong; if(ModeNo <= 0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; } else if(SiS_Pr->UseCustomMode) { modeflag = SiS_Pr->CModeFlag; resinfo = 0; } else { modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; } if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_VBType & VB_SISLVDS) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e); } } } if(SiS_Pr->SiS_VBType & (VB_SIS30xCLV | VB_SIS302LV)) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x10,0x9f); } } if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { SiS_SetDualLinkEtc(SiS_Pr); return; } } SiS_SetReg(SiS_Pr->SiS_Part4Port,0x13,SiS_Pr->SiS_RVBHCFACT); tempbx = SiS_Pr->SiS_RVBHCMAX; SiS_SetReg(SiS_Pr->SiS_Part4Port,0x14,tempbx); temp = (tempbx >> 1) & 0x80; tempcx = SiS_Pr->SiS_VGAHT - 1; SiS_SetReg(SiS_Pr->SiS_Part4Port,0x16,tempcx); temp |= ((tempcx >> 5) & 0x78); tempcx = SiS_Pr->SiS_VGAVT - 1; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempcx -= 5; SiS_SetReg(SiS_Pr->SiS_Part4Port,0x17,tempcx); temp |= ((tempcx >> 8) & 0x07); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x15,temp); tempbx = SiS_Pr->SiS_VGAHDE; if(modeflag & HalfDCLK) tempbx >>= 1; if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1; if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { temp = 0; if(tempbx > 800) temp = 0x60; } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { temp = 0; if(tempbx > 1024) temp = 0xC0; else if(tempbx >= 960) temp = 0xA0; } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) { temp = 0; if(tempbx >= 1280) temp = 0x40; else if(tempbx >= 1024) temp = 0x20; } else { temp = 0x80; if(tempbx >= 1024) temp = 0xA0; } temp |= SiS_Pr->Init_P4_0E; if(SiS_Pr->SiS_VBType & VB_SIS301) { if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) { temp &= 0xf0; temp |= 0x0A; } } SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp); tempeax = SiS_Pr->SiS_VGAVDE; tempebx = SiS_Pr->SiS_VDE; if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { if(!(temp & 0xE0)) tempebx >>=1; } tempcx = SiS_Pr->SiS_RVBHRS; SiS_SetReg(SiS_Pr->SiS_Part4Port,0x18,tempcx); tempcx >>= 8; tempcx |= 0x40; if(tempeax <= tempebx) { tempcx ^= 0x40; } else { tempeax -= tempebx; } tempeax *= (256 * 1024); templong = tempeax % tempebx; tempeax /= tempebx; if(templong) tempeax++; temp = (unsigned short)(tempeax & 0x000000FF); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1B,temp); temp = (unsigned short)((tempeax & 0x0000FF00) >> 8); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1A,temp); temp = (unsigned short)((tempeax >> 12) & 0x70); /* sic! */ temp |= (tempcx & 0x4F); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x19,temp); if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1C,0x28); /* Calc Linebuffer max address and set/clear decimode */ tempbx = 0; if(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p)) tempbx = 0x08; tempax = SiS_Pr->SiS_VGAHDE; if(modeflag & HalfDCLK) tempax >>= 1; if(SiS_IsDualLink(SiS_Pr)) tempax >>= 1; if(tempax > 800) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { tempax -= 800; } else { tempbx = 0x08; if(tempax == 960) tempax *= 25; /* Correct */ else if(tempax == 1024) tempax *= 25; else tempax *= 20; temp = tempax % 32; tempax /= 32; if(temp) tempax++; tempax++; if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { if(resinfo == SIS_RI_1024x768 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x1024 || resinfo == SIS_RI_1280x720) { /* Otherwise white line or garbage at right edge */ tempax = (tempax & 0xff00) | 0x20; } } } } tempax--; temp = ((tempax >> 4) & 0x30) | tempbx; SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1D,tempax); SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1E,temp); temp = 0x0036; tempbx = 0xD0; if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) { temp = 0x0026; tempbx = 0xC0; /* See En/DisableBridge() */ } if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { if(!(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetHiVision | TVSetYPbPr750p | TVSetYPbPr525p))) { temp |= 0x01; if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) { temp &= ~0x01; } } } } SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,tempbx,temp); tempbx = SiS_Pr->SiS_HT >> 1; if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1; tempbx -= 2; SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,tempbx); temp = (tempbx >> 5) & 0x38; SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp); if(SiS_Pr->SiS_VBType & VB_SISLVDS) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e); /* LCD-too-dark-error-source, see FinalizeLCD() */ } } SiS_SetDualLinkEtc(SiS_Pr); } /* 301B */ SiS_SetCRT2VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } /*********************************************/ /* SET PART 5 REGISTER GROUP */ /*********************************************/ static void SiS_SetGroup5(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return; if(SiS_Pr->SiS_ModeType == ModeVGA) { if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))) { SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex); } } } /*********************************************/ /* MODIFY CRT1 GROUP FOR SLAVE MODE */ /*********************************************/ static bool SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex, unsigned short *ResIndex, unsigned short *DisplayType) { unsigned short modeflag = 0; bool checkhd = true; /* Pass 1:1 not supported here */ if(ModeNo <= 0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; } else { modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; } (*ResIndex) &= 0x3F; if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { (*DisplayType) = 80; if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) { (*DisplayType) = 82; if(SiS_Pr->SiS_ModeType > ModeVGA) { if(SiS_Pr->SiS_CHSOverScan) (*DisplayType) = 84; } } if((*DisplayType) != 84) { if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++; } } else { (*DisplayType = 0); switch(SiS_Pr->SiS_LCDResInfo) { case Panel_320x240_1: (*DisplayType) = 50; checkhd = false; break; case Panel_320x240_2: (*DisplayType) = 14; break; case Panel_320x240_3: (*DisplayType) = 18; break; case Panel_640x480: (*DisplayType) = 10; break; case Panel_1024x600: (*DisplayType) = 26; break; default: return true; } if(checkhd) { if(modeflag & HalfDCLK) (*DisplayType)++; } if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) { if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) (*DisplayType) += 2; } } return true; } static void SiS_ModCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short tempah, i, modeflag, j, ResIndex, DisplayType; const struct SiS_LVDSCRT1Data *LVDSCRT1Ptr=NULL; static const unsigned short CRIdx[] = { 0x00, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x15, 0x16 }; if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024) || (SiS_Pr->SiS_CustomT == CUT_PANEL848) || (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) return; if(SiS_Pr->SiS_IF_DEF_LVDS) { if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return; } } else if(SiS_Pr->SiS_VBType & VB_SISVB) { if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return; } else return; if(SiS_Pr->SiS_LCDInfo & LCDPass11) return; if(SiS_Pr->ChipType < SIS_315H) { if(SiS_Pr->SiS_SetFlag & SetDOSMode) return; } if(!(SiS_GetLVDSCRT1Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, &ResIndex, &DisplayType))) { return; } switch(DisplayType) { case 50: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_1; break; /* xSTN */ case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2; break; /* xSTN */ case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2_H; break; /* xSTN */ case 18: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3; break; /* xSTN */ case 19: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3_H; break; /* xSTN */ case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1; break; case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1_H; break; #if 0 /* Works better with calculated numbers */ case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break; case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break; case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break; case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break; #endif case 80: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break; case 81: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break; case 82: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break; case 83: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break; case 84: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1SOPAL; break; } if(LVDSCRT1Ptr) { SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f); for(i = 0; i <= 10; i++) { tempah = (LVDSCRT1Ptr + ResIndex)->CR[i]; SiS_SetReg(SiS_Pr->SiS_P3d4,CRIdx[i],tempah); } for(i = 0x0A, j = 11; i <= 0x0C; i++, j++) { tempah = (LVDSCRT1Ptr + ResIndex)->CR[j]; SiS_SetReg(SiS_Pr->SiS_P3c4,i,tempah); } tempah = (LVDSCRT1Ptr + ResIndex)->CR[14] & 0xE0; SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1f,tempah); if(ModeNo <= 0x13) modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; else modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; tempah = ((LVDSCRT1Ptr + ResIndex)->CR[14] & 0x01) << 5; if(modeflag & DoubleScanMode) tempah |= 0x80; SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah); } else { SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex); } } /*********************************************/ /* SET CRT2 ECLK */ /*********************************************/ static void SiS_SetCRT2ECLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short clkbase, vclkindex = 0; unsigned char sr2b, sr2c; if(SiS_Pr->SiS_LCDInfo & LCDPass11) { SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2); if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK == 2) { RefreshRateTableIndex--; } vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; } else { vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } sr2b = SiS_Pr->SiS_VCLKData[vclkindex].SR2B; sr2c = SiS_Pr->SiS_VCLKData[vclkindex].SR2C; if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) { if(SiS_Pr->SiS_UseROM) { if(ROMAddr[0x220] & 0x01) { sr2b = ROMAddr[0x227]; sr2c = ROMAddr[0x228]; } } } clkbase = 0x02B; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) { if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { clkbase += 3; } } SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x20); SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b); SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c); SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x10); SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b); SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c); SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x00); SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b); SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c); } /*********************************************/ /* SET UP CHRONTEL CHIPS */ /*********************************************/ static void SiS_SetCHTVReg(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex) { unsigned short TVType, resindex; const struct SiS_CHTVRegData *CHTVRegData = NULL; if(ModeNo <= 0x13) resindex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; else resindex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC; resindex &= 0x3F; TVType = 0; if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1; if(SiS_Pr->SiS_TVMode & TVSetPAL) { TVType += 2; if(SiS_Pr->SiS_ModeType > ModeVGA) { if(SiS_Pr->SiS_CHSOverScan) TVType = 8; } if(SiS_Pr->SiS_TVMode & TVSetPALM) { TVType = 4; if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1; } else if(SiS_Pr->SiS_TVMode & TVSetPALN) { TVType = 6; if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1; } } switch(TVType) { case 0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break; case 1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break; case 2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL; break; case 3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break; case 4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break; case 5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break; case 6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break; case 7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break; case 8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break; default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break; } if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { #ifdef CONFIG_FB_SIS_300 /* Chrontel 7005 - I assume that it does not come with a 315 series chip */ /* We don't support modes >800x600 */ if (resindex > 5) return; if(SiS_Pr->SiS_TVMode & TVSetPAL) { SiS_SetCH700x(SiS_Pr,0x04,0x43); /* 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/ SiS_SetCH700x(SiS_Pr,0x09,0x69); /* Black level for PAL (105)*/ } else { SiS_SetCH700x(SiS_Pr,0x04,0x03); /* upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/ SiS_SetCH700x(SiS_Pr,0x09,0x71); /* Black level for NTSC (113)*/ } SiS_SetCH700x(SiS_Pr,0x00,CHTVRegData[resindex].Reg[0]); /* Mode register */ SiS_SetCH700x(SiS_Pr,0x07,CHTVRegData[resindex].Reg[1]); /* Start active video register */ SiS_SetCH700x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[2]); /* Position overflow register */ SiS_SetCH700x(SiS_Pr,0x0a,CHTVRegData[resindex].Reg[3]); /* Horiz Position register */ SiS_SetCH700x(SiS_Pr,0x0b,CHTVRegData[resindex].Reg[4]); /* Vertical Position register */ /* Set minimum flicker filter for Luma channel (SR1-0=00), minimum text enhancement (S3-2=10), maximum flicker filter for Chroma channel (S5-4=10) =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!) */ SiS_SetCH700x(SiS_Pr,0x01,0x28); /* Set video bandwidth High bandwidth Luma composite video filter(S0=1) low bandwidth Luma S-video filter (S2-1=00) disable peak filter in S-video channel (S3=0) high bandwidth Chroma Filter (S5-4=11) =00110001=0x31 */ SiS_SetCH700x(SiS_Pr,0x03,0xb1); /* old: 3103 */ /* Register 0x3D does not exist in non-macrovision register map (Maybe this is a macrovision register?) */ #ifndef SIS_CP SiS_SetCH70xx(SiS_Pr,0x3d,0x00); #endif /* Register 0x10 only contains 1 writable bit (S0) for sensing, all other bits a read-only. Macrovision? */ SiS_SetCH70xxANDOR(SiS_Pr,0x10,0x00,0x1F); /* Register 0x11 only contains 3 writable bits (S0-S2) for contrast enhancement (set to 010 -> gain 1 Yout = 17/16*(Yin-30) ) */ SiS_SetCH70xxANDOR(SiS_Pr,0x11,0x02,0xF8); /* Clear DSEN */ SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xEF); if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { /* ---- NTSC ---- */ if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) { if(resindex == 0x04) { /* 640x480 overscan: Mode 16 */ SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */ SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on, no need to set FSCI */ } else if(resindex == 0x05) { /* 800x600 overscan: Mode 23 */ SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* 0x18-0x1f: FSCI 469,762,048 */ SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x0C,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x00,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x00,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x00,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x00,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x00,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x01,0xEF); /* Loop filter on for mode 23 */ SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); /* ACIV off, need to set FSCI */ } } else { if(resindex == 0x04) { /* ----- 640x480 underscan; Mode 17 */ SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */ SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); } else if(resindex == 0x05) { /* ----- 800x600 underscan: Mode 24 */ #if 0 SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* (FSCI was 0x1f1c71c7 - this is for mode 22) */ SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x09,0xF0); /* FSCI for mode 24 is 428,554,851 */ SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x08,0xF0); /* 198b3a63 */ SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x0b,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x04,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x01,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x06,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x05,0xF0); SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off for mode 24 */ SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); * ACIV off, need to set FSCI */ #endif /* All alternatives wrong (datasheet wrong?), don't use FSCI */ SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */ SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); } } } else { /* ---- PAL ---- */ /* We don't play around with FSCI in PAL mode */ if(resindex == 0x04) { SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */ SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */ } else { SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */ SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */ } } #endif /* 300 */ } else { /* Chrontel 7019 - assumed that it does not come with a 300 series chip */ #ifdef CONFIG_FB_SIS_315 unsigned short temp; /* We don't support modes >1024x768 */ if (resindex > 6) return; temp = CHTVRegData[resindex].Reg[0]; if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp |= 0x10; SiS_SetCH701x(SiS_Pr,0x00,temp); SiS_SetCH701x(SiS_Pr,0x01,CHTVRegData[resindex].Reg[1]); SiS_SetCH701x(SiS_Pr,0x02,CHTVRegData[resindex].Reg[2]); SiS_SetCH701x(SiS_Pr,0x04,CHTVRegData[resindex].Reg[3]); SiS_SetCH701x(SiS_Pr,0x03,CHTVRegData[resindex].Reg[4]); SiS_SetCH701x(SiS_Pr,0x05,CHTVRegData[resindex].Reg[5]); SiS_SetCH701x(SiS_Pr,0x06,CHTVRegData[resindex].Reg[6]); temp = CHTVRegData[resindex].Reg[7]; if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 0x66; SiS_SetCH701x(SiS_Pr,0x07,temp); SiS_SetCH701x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[8]); SiS_SetCH701x(SiS_Pr,0x15,CHTVRegData[resindex].Reg[9]); SiS_SetCH701x(SiS_Pr,0x1f,CHTVRegData[resindex].Reg[10]); SiS_SetCH701x(SiS_Pr,0x0c,CHTVRegData[resindex].Reg[11]); SiS_SetCH701x(SiS_Pr,0x0d,CHTVRegData[resindex].Reg[12]); SiS_SetCH701x(SiS_Pr,0x0e,CHTVRegData[resindex].Reg[13]); SiS_SetCH701x(SiS_Pr,0x0f,CHTVRegData[resindex].Reg[14]); SiS_SetCH701x(SiS_Pr,0x10,CHTVRegData[resindex].Reg[15]); temp = SiS_GetCH701x(SiS_Pr,0x21) & ~0x02; /* D1 should be set for PAL, PAL-N and NTSC-J, but I won't do that for PAL unless somebody tells me to do so. Since the BIOS uses non-default CIV values and blacklevels, this might be compensated anyway. */ if(SiS_Pr->SiS_TVMode & (TVSetPALN | TVSetNTSCJ)) temp |= 0x02; SiS_SetCH701x(SiS_Pr,0x21,temp); #endif /* 315 */ } #ifdef SIS_CP SIS_CP_INIT301_CP3 #endif } #ifdef CONFIG_FB_SIS_315 /* ----------- 315 series only ---------- */ void SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr) { unsigned short temp; /* Enable Chrontel 7019 LCD panel backlight */ if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { if(SiS_Pr->ChipType == SIS_740) { SiS_SetCH701x(SiS_Pr,0x66,0x65); } else { temp = SiS_GetCH701x(SiS_Pr,0x66); temp |= 0x20; SiS_SetCH701x(SiS_Pr,0x66,temp); } } } void SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr) { unsigned short temp; /* Disable Chrontel 7019 LCD panel backlight */ if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { temp = SiS_GetCH701x(SiS_Pr,0x66); temp &= 0xDF; SiS_SetCH701x(SiS_Pr,0x66,temp); } } static void SiS_ChrontelPowerSequencing(struct SiS_Private *SiS_Pr) { static const unsigned char regtable[] = { 0x67, 0x68, 0x69, 0x6a, 0x6b }; static const unsigned char table1024_740[] = { 0x01, 0x02, 0x01, 0x01, 0x01 }; static const unsigned char table1400_740[] = { 0x01, 0x6e, 0x01, 0x01, 0x01 }; static const unsigned char asus1024_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 }; static const unsigned char asus1400_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 }; static const unsigned char table1024_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 }; static const unsigned char table1400_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 }; const unsigned char *tableptr = NULL; int i; /* Set up Power up/down timing */ if(SiS_Pr->ChipType == SIS_740) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1024_740; else tableptr = table1024_740; } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) || (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) || (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) { if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1400_740; else tableptr = table1400_740; } else return; } else { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { tableptr = table1024_650; } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) || (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) || (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) { tableptr = table1400_650; } else return; } for(i=0; i<5; i++) { SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]); } } static void SiS_SetCH701xForLCD(struct SiS_Private *SiS_Pr) { const unsigned char *tableptr = NULL; unsigned short tempbh; int i; static const unsigned char regtable[] = { 0x1c, 0x5f, 0x64, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x76, 0x78, 0x7d, 0x66 }; static const unsigned char table1024_740[] = { 0x60, 0x02, 0x00, 0x07, 0x40, 0xed, 0xa3, 0xc8, 0xc7, 0xac, 0xe0, 0x02, 0x44 }; static const unsigned char table1280_740[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3, 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44 }; static const unsigned char table1400_740[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3, 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44 }; static const unsigned char table1600_740[] = { 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3, 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a, 0x44 }; static const unsigned char table1024_650[] = { 0x60, 0x02, 0x00, 0x07, 0x40, 0xed, 0xa3, 0xc8, 0xc7, 0xac, 0x60, 0x02 }; static const unsigned char table1280_650[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3, 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02 }; static const unsigned char table1400_650[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xef, 0xad, 0xdb, 0xf6, 0xac, 0x60, 0x02 }; static const unsigned char table1600_650[] = { 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3, 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a }; if(SiS_Pr->ChipType == SIS_740) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_740; else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_740; else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_740; else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_740; else return; } else { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_650; else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_650; else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_650; else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_650; else return; } tempbh = SiS_GetCH701x(SiS_Pr,0x74); if((tempbh == 0xf6) || (tempbh == 0xc7)) { tempbh = SiS_GetCH701x(SiS_Pr,0x73); if(tempbh == 0xc8) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) return; } else if(tempbh == 0xdb) { if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) return; if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) return; } else if(tempbh == 0xde) { if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) return; } } if(SiS_Pr->ChipType == SIS_740) tempbh = 0x0d; else tempbh = 0x0c; for(i = 0; i < tempbh; i++) { SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]); } SiS_ChrontelPowerSequencing(SiS_Pr); tempbh = SiS_GetCH701x(SiS_Pr,0x1e); tempbh |= 0xc0; SiS_SetCH701x(SiS_Pr,0x1e,tempbh); if(SiS_Pr->ChipType == SIS_740) { tempbh = SiS_GetCH701x(SiS_Pr,0x1c); tempbh &= 0xfb; SiS_SetCH701x(SiS_Pr,0x1c,tempbh); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03); tempbh = SiS_GetCH701x(SiS_Pr,0x64); tempbh |= 0x40; SiS_SetCH701x(SiS_Pr,0x64,tempbh); tempbh = SiS_GetCH701x(SiS_Pr,0x03); tempbh &= 0x3f; SiS_SetCH701x(SiS_Pr,0x03,tempbh); } } static void SiS_ChrontelResetVSync(struct SiS_Private *SiS_Pr) { unsigned char temp, temp1; temp1 = SiS_GetCH701x(SiS_Pr,0x49); SiS_SetCH701x(SiS_Pr,0x49,0x3e); temp = SiS_GetCH701x(SiS_Pr,0x47); temp &= 0x7f; /* Use external VSYNC */ SiS_SetCH701x(SiS_Pr,0x47,temp); SiS_LongDelay(SiS_Pr, 3); temp = SiS_GetCH701x(SiS_Pr,0x47); temp |= 0x80; /* Use internal VSYNC */ SiS_SetCH701x(SiS_Pr,0x47,temp); SiS_SetCH701x(SiS_Pr,0x49,temp1); } static void SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr) { unsigned short temp; if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { if(SiS_Pr->ChipType == SIS_740) { temp = SiS_GetCH701x(SiS_Pr,0x1c); temp |= 0x04; /* Invert XCLK phase */ SiS_SetCH701x(SiS_Pr,0x1c,temp); } if(SiS_IsYPbPr(SiS_Pr)) { temp = SiS_GetCH701x(SiS_Pr,0x01); temp &= 0x3f; temp |= 0x80; /* Enable YPrPb (HDTV) */ SiS_SetCH701x(SiS_Pr,0x01,temp); } if(SiS_IsChScart(SiS_Pr)) { temp = SiS_GetCH701x(SiS_Pr,0x01); temp &= 0x3f; temp |= 0xc0; /* Enable SCART + CVBS */ SiS_SetCH701x(SiS_Pr,0x01,temp); } if(SiS_Pr->ChipType == SIS_740) { SiS_ChrontelResetVSync(SiS_Pr); SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */ } else { SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */ temp = SiS_GetCH701x(SiS_Pr,0x49); if(SiS_IsYPbPr(SiS_Pr)) { temp = SiS_GetCH701x(SiS_Pr,0x73); temp |= 0x60; SiS_SetCH701x(SiS_Pr,0x73,temp); } temp = SiS_GetCH701x(SiS_Pr,0x47); temp &= 0x7f; SiS_SetCH701x(SiS_Pr,0x47,temp); SiS_LongDelay(SiS_Pr, 2); temp = SiS_GetCH701x(SiS_Pr,0x47); temp |= 0x80; SiS_SetCH701x(SiS_Pr,0x47,temp); } } } static void SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr) { unsigned short temp; /* Complete power down of LVDS */ if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { if(SiS_Pr->ChipType == SIS_740) { SiS_LongDelay(SiS_Pr, 1); SiS_GenericDelay(SiS_Pr, 5887); SiS_SetCH701x(SiS_Pr,0x76,0xac); SiS_SetCH701x(SiS_Pr,0x66,0x00); } else { SiS_LongDelay(SiS_Pr, 2); temp = SiS_GetCH701x(SiS_Pr,0x76); temp &= 0xfc; SiS_SetCH701x(SiS_Pr,0x76,temp); SiS_SetCH701x(SiS_Pr,0x66,0x00); } } } static void SiS_ChrontelResetDB(struct SiS_Private *SiS_Pr) { unsigned short temp; if(SiS_Pr->ChipType == SIS_740) { temp = SiS_GetCH701x(SiS_Pr,0x4a); /* Version ID */ temp &= 0x01; if(!temp) { if(SiS_WeHaveBacklightCtrl(SiS_Pr)) { temp = SiS_GetCH701x(SiS_Pr,0x49); SiS_SetCH701x(SiS_Pr,0x49,0x3e); } /* Reset Chrontel 7019 datapath */ SiS_SetCH701x(SiS_Pr,0x48,0x10); SiS_LongDelay(SiS_Pr, 1); SiS_SetCH701x(SiS_Pr,0x48,0x18); if(SiS_WeHaveBacklightCtrl(SiS_Pr)) { SiS_ChrontelResetVSync(SiS_Pr); SiS_SetCH701x(SiS_Pr,0x49,temp); } } else { /* Clear/set/clear GPIO */ temp = SiS_GetCH701x(SiS_Pr,0x5c); temp &= 0xef; SiS_SetCH701x(SiS_Pr,0x5c,temp); temp = SiS_GetCH701x(SiS_Pr,0x5c); temp |= 0x10; SiS_SetCH701x(SiS_Pr,0x5c,temp); temp = SiS_GetCH701x(SiS_Pr,0x5c); temp &= 0xef; SiS_SetCH701x(SiS_Pr,0x5c,temp); temp = SiS_GetCH701x(SiS_Pr,0x61); if(!temp) { SiS_SetCH701xForLCD(SiS_Pr); } } } else { /* 650 */ /* Reset Chrontel 7019 datapath */ SiS_SetCH701x(SiS_Pr,0x48,0x10); SiS_LongDelay(SiS_Pr, 1); SiS_SetCH701x(SiS_Pr,0x48,0x18); } } static void SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr) { unsigned short temp; if(SiS_Pr->ChipType == SIS_740) { if(SiS_WeHaveBacklightCtrl(SiS_Pr)) { SiS_ChrontelResetVSync(SiS_Pr); } } else { SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* Power up LVDS block */ temp = SiS_GetCH701x(SiS_Pr,0x49); temp &= 1; if(temp != 1) { /* TV block powered? (0 = yes, 1 = no) */ temp = SiS_GetCH701x(SiS_Pr,0x47); temp &= 0x70; SiS_SetCH701x(SiS_Pr,0x47,temp); /* enable VSYNC */ SiS_LongDelay(SiS_Pr, 3); temp = SiS_GetCH701x(SiS_Pr,0x47); temp |= 0x80; SiS_SetCH701x(SiS_Pr,0x47,temp); /* disable VSYNC */ } } } static void SiS_ChrontelDoSomething3(struct SiS_Private *SiS_Pr, unsigned short ModeNo) { unsigned short temp,temp1; if(SiS_Pr->ChipType == SIS_740) { temp = SiS_GetCH701x(SiS_Pr,0x61); if(temp < 1) { temp++; SiS_SetCH701x(SiS_Pr,0x61,temp); } SiS_SetCH701x(SiS_Pr,0x66,0x45); /* Panel power on */ SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on */ SiS_LongDelay(SiS_Pr, 1); SiS_GenericDelay(SiS_Pr, 5887); } else { /* 650 */ temp1 = 0; temp = SiS_GetCH701x(SiS_Pr,0x61); if(temp < 2) { temp++; SiS_SetCH701x(SiS_Pr,0x61,temp); temp1 = 1; } SiS_SetCH701x(SiS_Pr,0x76,0xac); temp = SiS_GetCH701x(SiS_Pr,0x66); temp |= 0x5f; SiS_SetCH701x(SiS_Pr,0x66,temp); if(ModeNo > 0x13) { if(SiS_WeHaveBacklightCtrl(SiS_Pr)) { SiS_GenericDelay(SiS_Pr, 1023); } else { SiS_GenericDelay(SiS_Pr, 767); } } else { if(!temp1) SiS_GenericDelay(SiS_Pr, 767); } temp = SiS_GetCH701x(SiS_Pr,0x76); temp |= 0x03; SiS_SetCH701x(SiS_Pr,0x76,temp); temp = SiS_GetCH701x(SiS_Pr,0x66); temp &= 0x7f; SiS_SetCH701x(SiS_Pr,0x66,temp); SiS_LongDelay(SiS_Pr, 1); } } static void SiS_ChrontelDoSomething2(struct SiS_Private *SiS_Pr) { unsigned short temp; SiS_LongDelay(SiS_Pr, 1); do { temp = SiS_GetCH701x(SiS_Pr,0x66); temp &= 0x04; /* PLL stable? -> bail out */ if(temp == 0x04) break; if(SiS_Pr->ChipType == SIS_740) { /* Power down LVDS output, PLL normal operation */ SiS_SetCH701x(SiS_Pr,0x76,0xac); } SiS_SetCH701xForLCD(SiS_Pr); temp = SiS_GetCH701x(SiS_Pr,0x76); temp &= 0xfb; /* Reset PLL */ SiS_SetCH701x(SiS_Pr,0x76,temp); SiS_LongDelay(SiS_Pr, 2); temp = SiS_GetCH701x(SiS_Pr,0x76); temp |= 0x04; /* PLL normal operation */ SiS_SetCH701x(SiS_Pr,0x76,temp); if(SiS_Pr->ChipType == SIS_740) { SiS_SetCH701x(SiS_Pr,0x78,0xe0); /* PLL loop filter */ } else { SiS_SetCH701x(SiS_Pr,0x78,0x60); } SiS_LongDelay(SiS_Pr, 2); } while(0); SiS_SetCH701x(SiS_Pr,0x77,0x00); /* MV? */ } static void SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr) { unsigned short temp; temp = SiS_GetCH701x(SiS_Pr,0x03); temp |= 0x80; /* Set datapath 1 to TV */ temp &= 0xbf; /* Set datapath 2 to LVDS */ SiS_SetCH701x(SiS_Pr,0x03,temp); if(SiS_Pr->ChipType == SIS_740) { temp = SiS_GetCH701x(SiS_Pr,0x1c); temp &= 0xfb; /* Normal XCLK phase */ SiS_SetCH701x(SiS_Pr,0x1c,temp); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03); temp = SiS_GetCH701x(SiS_Pr,0x64); temp |= 0x40; /* ? Bit not defined */ SiS_SetCH701x(SiS_Pr,0x64,temp); temp = SiS_GetCH701x(SiS_Pr,0x03); temp &= 0x3f; /* D1 input to both LVDS and TV */ SiS_SetCH701x(SiS_Pr,0x03,temp); if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) { SiS_SetCH701x(SiS_Pr,0x63,0x40); /* LVDS off */ SiS_LongDelay(SiS_Pr, 1); SiS_SetCH701x(SiS_Pr,0x63,0x00); /* LVDS on */ SiS_ChrontelResetDB(SiS_Pr); SiS_ChrontelDoSomething2(SiS_Pr); SiS_ChrontelDoSomething3(SiS_Pr, 0); } else { temp = SiS_GetCH701x(SiS_Pr,0x66); if(temp != 0x45) { SiS_ChrontelResetDB(SiS_Pr); SiS_ChrontelDoSomething2(SiS_Pr); SiS_ChrontelDoSomething3(SiS_Pr, 0); } } } else { /* 650 */ SiS_ChrontelResetDB(SiS_Pr); SiS_ChrontelDoSomething2(SiS_Pr); temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34); SiS_ChrontelDoSomething3(SiS_Pr,temp); SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on, LVDS normal operation */ } } #endif /* 315 series */ /*********************************************/ /* MAIN: SET CRT2 REGISTER GROUP */ /*********************************************/ bool SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo) { #ifdef CONFIG_FB_SIS_300 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; #endif unsigned short ModeIdIndex, RefreshRateTableIndex; SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; if(!SiS_Pr->UseCustomMode) { SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex); } else { ModeIdIndex = 0; } /* Used for shifting CR33 */ SiS_Pr->SiS_SelectCRT2Rate = 4; SiS_UnLockCRT2(SiS_Pr); RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex); SiS_SaveCRT2Info(SiS_Pr,ModeNo); if(SiS_Pr->SiS_SetFlag & LowModeTests) { SiS_DisableBridge(SiS_Pr); if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->ChipType == SIS_730)) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,0x80); } SiS_SetCRT2ModeRegs(SiS_Pr, ModeNo, ModeIdIndex); } if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) { SiS_LockCRT2(SiS_Pr); SiS_DisplayOn(SiS_Pr); return true; } SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); /* Set up Panel Link for LVDS and LCDA */ SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0; if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) || ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) || ((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) { SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } if(SiS_Pr->SiS_SetFlag & LowModeTests) { SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_SetFlag & LowModeTests) { SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); #ifdef CONFIG_FB_SIS_315 SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); #endif SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex); SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); #ifdef CONFIG_FB_SIS_315 SiS_SetGroup4_C_ELV(SiS_Pr, ModeNo, ModeIdIndex); #endif SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex); SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex); /* For 301BDH (Panel link initialization): */ if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10)))) { if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { SiS_ModCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } } SiS_SetCRT2ECLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } } } else { SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex); SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex); SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex); if(SiS_Pr->SiS_SetFlag & LowModeTests) { if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) { #ifdef CONFIG_FB_SIS_315 SiS_SetCH701xForLCD(SiS_Pr); #endif } } if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex); } } } } #ifdef CONFIG_FB_SIS_300 if(SiS_Pr->ChipType < SIS_315H) { if(SiS_Pr->SiS_SetFlag & LowModeTests) { if(SiS_Pr->SiS_UseOEM) { if((SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_UseOEM == -1)) { if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } } else { SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } } if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) { SetOEMLCDData2(SiS_Pr, ModeNo, ModeIdIndex,RefreshRateTableIndex); } SiS_DisplayOn(SiS_Pr); } } } #endif #ifdef CONFIG_FB_SIS_315 if(SiS_Pr->ChipType >= SIS_315H) { if(SiS_Pr->SiS_SetFlag & LowModeTests) { if(SiS_Pr->ChipType < SIS_661) { SiS_FinalizeLCD(SiS_Pr, ModeNo, ModeIdIndex); SiS_OEM310Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } else { SiS_OEM661Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); } SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40); } } #endif if(SiS_Pr->SiS_SetFlag & LowModeTests) { SiS_EnableBridge(SiS_Pr); } SiS_DisplayOn(SiS_Pr); if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* Disable LCD panel when using TV */ SiS_SetRegSR11ANDOR(SiS_Pr,0xFF,0x0C); } else { /* Disable TV when using LCD */ SiS_SetCH70xxANDOR(SiS_Pr,0x0e,0x01,0xf8); } } if(SiS_Pr->SiS_SetFlag & LowModeTests) { SiS_LockCRT2(SiS_Pr); } return true; } /*********************************************/ /* ENABLE/DISABLE LCD BACKLIGHT (SIS) */ /*********************************************/ void SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr) { /* Switch on LCD backlight on SiS30xLV */ SiS_DDC2Delay(SiS_Pr,0xff00); if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) { SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02); SiS_WaitVBRetrace(SiS_Pr); } if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x01)) { SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01); } } void SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr) { /* Switch off LCD backlight on SiS30xLV */ SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE); SiS_DDC2Delay(SiS_Pr,0xff00); } /*********************************************/ /* DDC RELATED FUNCTIONS */ /*********************************************/ static void SiS_SetupDDCN(struct SiS_Private *SiS_Pr) { SiS_Pr->SiS_DDC_NData = ~SiS_Pr->SiS_DDC_Data; SiS_Pr->SiS_DDC_NClk = ~SiS_Pr->SiS_DDC_Clk; if((SiS_Pr->SiS_DDC_Index == 0x11) && (SiS_Pr->SiS_SensibleSR11)) { SiS_Pr->SiS_DDC_NData &= 0x0f; SiS_Pr->SiS_DDC_NClk &= 0x0f; } } #ifdef CONFIG_FB_SIS_300 static unsigned char * SiS_SetTrumpBlockLoop(struct SiS_Private *SiS_Pr, unsigned char *dataptr) { int i, j, num; unsigned short tempah,temp; unsigned char *mydataptr; for(i=0; i<20; i++) { /* Do 20 attempts to write */ mydataptr = dataptr; num = *mydataptr++; if(!num) return mydataptr; if(i) { SiS_SetStop(SiS_Pr); SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 2); } if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */ tempah = SiS_Pr->SiS_DDC_DeviceAddr; temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */ if(temp) continue; /* (ERROR: no ack) */ tempah = *mydataptr++; temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write register number */ if(temp) continue; /* (ERROR: no ack) */ for(j=0; j<num; j++) { tempah = *mydataptr++; temp = SiS_WriteDDC2Data(SiS_Pr,tempah);/* Write DAB (S0=0=write) */ if(temp) break; } if(temp) continue; if(SiS_SetStop(SiS_Pr)) continue; return mydataptr; } return NULL; } static bool SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr) { SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */ SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */ SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */ SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */ SiS_SetupDDCN(SiS_Pr); SiS_SetSwitchDDC2(SiS_Pr); while(*dataptr) { dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr); if(!dataptr) return false; } return true; } #endif /* The Chrontel 700x is connected to the 630/730 via * the 630/730's DDC/I2C port. * * On 630(S)T chipset, the index changed from 0x11 to * 0x0a, possibly for working around the DDC problems */ static bool SiS_SetChReg(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val, unsigned short myor) { unsigned short temp, i; for(i=0; i<20; i++) { /* Do 20 attempts to write */ if(i) { SiS_SetStop(SiS_Pr); SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4); } if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */ temp = SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */ if(temp) continue; /* (ERROR: no ack) */ temp = SiS_WriteDDC2Data(SiS_Pr, (reg | myor)); /* Write RAB (700x: set bit 7, see datasheet) */ if(temp) continue; /* (ERROR: no ack) */ temp = SiS_WriteDDC2Data(SiS_Pr, val); /* Write data */ if(temp) continue; /* (ERROR: no ack) */ if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */ SiS_Pr->SiS_ChrontelInit = 1; return true; } return false; } /* Write to Chrontel 700x */ void SiS_SetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val) { SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */ SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT); if(!(SiS_Pr->SiS_ChrontelInit)) { SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */ SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */ SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */ SiS_SetupDDCN(SiS_Pr); } if( (!(SiS_SetChReg(SiS_Pr, reg, val, 0x80))) && (!(SiS_Pr->SiS_ChrontelInit)) ) { SiS_Pr->SiS_DDC_Index = 0x0a; SiS_Pr->SiS_DDC_Data = 0x80; SiS_Pr->SiS_DDC_Clk = 0x40; SiS_SetupDDCN(SiS_Pr); SiS_SetChReg(SiS_Pr, reg, val, 0x80); } } /* Write to Chrontel 701x */ /* Parameter is [Data (S15-S8) | Register no (S7-S0)] */ void SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val) { SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */ SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */ SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */ SiS_SetupDDCN(SiS_Pr); SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */ SiS_SetChReg(SiS_Pr, reg, val, 0); } static void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val) { if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) SiS_SetCH700x(SiS_Pr, reg, val); else SiS_SetCH701x(SiS_Pr, reg, val); } static unsigned short SiS_GetChReg(struct SiS_Private *SiS_Pr, unsigned short myor) { unsigned short tempah, temp, i; for(i=0; i<20; i++) { /* Do 20 attempts to read */ if(i) { SiS_SetStop(SiS_Pr); SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4); } if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */ temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */ if(temp) continue; /* (ERROR: no ack) */ temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_ReadAddr | myor); /* Write RAB (700x: | 0x80) */ if(temp) continue; /* (ERROR: no ack) */ if (SiS_SetStart(SiS_Pr)) continue; /* Re-start */ temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr | 0x01);/* DAB (S0=1=read) */ if(temp) continue; /* (ERROR: no ack) */ tempah = SiS_ReadDDC2Data(SiS_Pr); /* Read byte */ if(SiS_SetStop(SiS_Pr)) continue; /* Stop condition */ SiS_Pr->SiS_ChrontelInit = 1; return tempah; } return 0xFFFF; } /* Read from Chrontel 700x */ /* Parameter is [Register no (S7-S0)] */ unsigned short SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempbx) { unsigned short result; SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */ SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT); if(!(SiS_Pr->SiS_ChrontelInit)) { SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */ SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */ SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */ SiS_SetupDDCN(SiS_Pr); } SiS_Pr->SiS_DDC_ReadAddr = tempbx; if( ((result = SiS_GetChReg(SiS_Pr,0x80)) == 0xFFFF) && (!SiS_Pr->SiS_ChrontelInit) ) { SiS_Pr->SiS_DDC_Index = 0x0a; SiS_Pr->SiS_DDC_Data = 0x80; SiS_Pr->SiS_DDC_Clk = 0x40; SiS_SetupDDCN(SiS_Pr); result = SiS_GetChReg(SiS_Pr,0x80); } return result; } /* Read from Chrontel 701x */ /* Parameter is [Register no (S7-S0)] */ unsigned short SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempbx) { SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */ SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */ SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */ SiS_SetupDDCN(SiS_Pr); SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */ SiS_Pr->SiS_DDC_ReadAddr = tempbx; return SiS_GetChReg(SiS_Pr,0); } /* Read from Chrontel 70xx */ /* Parameter is [Register no (S7-S0)] */ static unsigned short SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempbx) { if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) return SiS_GetCH700x(SiS_Pr, tempbx); else return SiS_GetCH701x(SiS_Pr, tempbx); } void SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char myor, unsigned short myand) { unsigned short tempbl; tempbl = (SiS_GetCH70xx(SiS_Pr, (reg & 0xFF)) & myand) | myor; SiS_SetCH70xx(SiS_Pr, reg, tempbl); } /* Our own DDC functions */ static unsigned short SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype, bool checkcr32, unsigned int VBFlags2) { unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 }; unsigned char flag, cr32; unsigned short temp = 0, myadaptnum = adaptnum; if(adaptnum != 0) { if(!(VBFlags2 & VB2_SISTMDSBRIDGE)) return 0xFFFF; if((VBFlags2 & VB2_30xBDH) && (adaptnum == 1)) return 0xFFFF; } /* adapternum for SiS bridges: 0 = CRT1, 1 = LCD, 2 = VGA2 */ SiS_Pr->SiS_ChrontelInit = 0; /* force re-detection! */ SiS_Pr->SiS_DDC_SecAddr = 0; SiS_Pr->SiS_DDC_DeviceAddr = ddcdtype[DDCdatatype]; SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_P3c4; SiS_Pr->SiS_DDC_Index = 0x11; flag = 0xff; cr32 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x32); #if 0 if(VBFlags2 & VB2_SISBRIDGE) { if(myadaptnum == 0) { if(!(cr32 & 0x20)) { myadaptnum = 2; if(!(cr32 & 0x10)) { myadaptnum = 1; if(!(cr32 & 0x08)) { myadaptnum = 0; } } } } } #endif if(VGAEngine == SIS_300_VGA) { /* 300 series */ if(myadaptnum != 0) { flag = 0; if(VBFlags2 & VB2_SISBRIDGE) { SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port; SiS_Pr->SiS_DDC_Index = 0x0f; } } if(!(VBFlags2 & VB2_301)) { if((cr32 & 0x80) && (checkcr32)) { if(myadaptnum >= 1) { if(!(cr32 & 0x08)) { myadaptnum = 1; if(!(cr32 & 0x10)) return 0xFFFF; } } } } temp = 4 - (myadaptnum * 2); if(flag) temp = 0; } else { /* 315/330 series */ /* here we simplify: 0 = CRT1, 1 = CRT2 (VGA, LCD) */ if(VBFlags2 & VB2_SISBRIDGE) { if(myadaptnum == 2) { myadaptnum = 1; } } if(myadaptnum == 1) { flag = 0; if(VBFlags2 & VB2_SISBRIDGE) { SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port; SiS_Pr->SiS_DDC_Index = 0x0f; } } if((cr32 & 0x80) && (checkcr32)) { if(myadaptnum >= 1) { if(!(cr32 & 0x08)) { myadaptnum = 1; if(!(cr32 & 0x10)) return 0xFFFF; } } } temp = myadaptnum; if(myadaptnum == 1) { temp = 0; if(VBFlags2 & VB2_LVDS) flag = 0xff; } if(flag) temp = 0; } SiS_Pr->SiS_DDC_Data = 0x02 << temp; SiS_Pr->SiS_DDC_Clk = 0x01 << temp; SiS_SetupDDCN(SiS_Pr); return 0; } static unsigned short SiS_WriteDABDDC(struct SiS_Private *SiS_Pr) { if(SiS_SetStart(SiS_Pr)) return 0xFFFF; if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr)) { return 0xFFFF; } if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_SecAddr)) { return 0xFFFF; } return 0; } static unsigned short SiS_PrepareReadDDC(struct SiS_Private *SiS_Pr) { if(SiS_SetStart(SiS_Pr)) return 0xFFFF; if(SiS_WriteDDC2Data(SiS_Pr, (SiS_Pr->SiS_DDC_DeviceAddr | 0x01))) { return 0xFFFF; } return 0; } static unsigned short SiS_PrepareDDC(struct SiS_Private *SiS_Pr) { if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr); if(SiS_PrepareReadDDC(SiS_Pr)) return (SiS_PrepareReadDDC(SiS_Pr)); return 0; } static void SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno) { SiS_SetSCLKLow(SiS_Pr); if(yesno) { SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NData, SiS_Pr->SiS_DDC_Data); } else { SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NData, 0); } SiS_SetSCLKHigh(SiS_Pr); } static unsigned short SiS_DoProbeDDC(struct SiS_Private *SiS_Pr) { unsigned char mask, value; unsigned short temp, ret=0; bool failed = false; SiS_SetSwitchDDC2(SiS_Pr); if(SiS_PrepareDDC(SiS_Pr)) { SiS_SetStop(SiS_Pr); return 0xFFFF; } mask = 0xf0; value = 0x20; if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) { temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr); SiS_SendACK(SiS_Pr, 0); if(temp == 0) { mask = 0xff; value = 0xff; } else { failed = true; ret = 0xFFFF; } } if(!failed) { temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr); SiS_SendACK(SiS_Pr, 1); temp &= mask; if(temp == value) ret = 0; else { ret = 0xFFFF; if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) { if(temp == 0x30) ret = 0; } } } SiS_SetStop(SiS_Pr); return ret; } static unsigned short SiS_ProbeDDC(struct SiS_Private *SiS_Pr) { unsigned short flag; flag = 0x180; SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x02; SiS_Pr->SiS_DDC_DeviceAddr = 0xa2; if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x08; SiS_Pr->SiS_DDC_DeviceAddr = 0xa6; if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x10; if(!(flag & 0x1a)) flag = 0; return flag; } static unsigned short SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, unsigned char *buffer) { unsigned short flag, length, i; unsigned char chksum,gotcha; if(DDCdatatype > 4) return 0xFFFF; flag = 0; SiS_SetSwitchDDC2(SiS_Pr); if(!(SiS_PrepareDDC(SiS_Pr))) { length = 127; if(DDCdatatype != 1) length = 255; chksum = 0; gotcha = 0; for(i=0; i<length; i++) { buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr); chksum += buffer[i]; gotcha |= buffer[i]; SiS_SendACK(SiS_Pr, 0); } buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr); chksum += buffer[i]; SiS_SendACK(SiS_Pr, 1); if(gotcha) flag = (unsigned short)chksum; else flag = 0xFFFF; } else { flag = 0xFFFF; } SiS_SetStop(SiS_Pr); return flag; } /* Our private DDC functions It complies somewhat with the corresponding VESA function in arguments and return values. Since this is probably called before the mode is changed, we use our pre-detected pSiS-values instead of SiS_Pr as regards chipset and video bridge type. Arguments: adaptnum: 0=CRT1(analog), 1=CRT2/LCD(digital), 2=CRT2/VGA2(analog) CRT2 DDC is only supported on SiS301, 301B, 301C, 302B. LCDA is CRT1, but DDC is read from CRT2 port. DDCdatatype: 0=Probe, 1=EDID, 2=EDID+VDIF, 3=EDID V2 (P&D), 4=EDID V2 (FPDI-2) buffer: ptr to 256 data bytes which will be filled with read data. Returns 0xFFFF if error, otherwise if DDCdatatype > 0: Returns 0 if reading OK (included a correct checksum) if DDCdatatype = 0: Returns supported DDC modes */ unsigned short SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype, unsigned char *buffer, unsigned int VBFlags2) { unsigned char sr1f, cr17=1; unsigned short result; if(adaptnum > 2) return 0xFFFF; if(DDCdatatype > 4) return 0xFFFF; if((!(VBFlags2 & VB2_VIDEOBRIDGE)) && (adaptnum > 0)) return 0xFFFF; if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, false, VBFlags2) == 0xFFFF) return 0xFFFF; sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f); SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1f,0x3f,0x04); if(VGAEngine == SIS_300_VGA) { cr17 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80; if(!cr17) { SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x17,0x80); SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x01); SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03); } } if((sr1f) || (!cr17)) { SiS_WaitRetrace1(SiS_Pr); SiS_WaitRetrace1(SiS_Pr); SiS_WaitRetrace1(SiS_Pr); SiS_WaitRetrace1(SiS_Pr); } if(DDCdatatype == 0) { result = SiS_ProbeDDC(SiS_Pr); } else { result = SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer); if((!result) && (DDCdatatype == 1)) { if((buffer[0] == 0x00) && (buffer[1] == 0xff) && (buffer[2] == 0xff) && (buffer[3] == 0xff) && (buffer[4] == 0xff) && (buffer[5] == 0xff) && (buffer[6] == 0xff) && (buffer[7] == 0x00) && (buffer[0x12] == 1)) { if(!SiS_Pr->DDCPortMixup) { if(adaptnum == 1) { if(!(buffer[0x14] & 0x80)) result = 0xFFFE; } else { if(buffer[0x14] & 0x80) result = 0xFFFE; } } } } } SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,sr1f); if(VGAEngine == SIS_300_VGA) { SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x17,0x7f,cr17); } return result; } /* Generic I2C functions for Chrontel & DDC --------- */ static void SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr) { SiS_SetSCLKHigh(SiS_Pr); SiS_WaitRetrace1(SiS_Pr); SiS_SetSCLKLow(SiS_Pr); SiS_WaitRetrace1(SiS_Pr); } unsigned short SiS_ReadDDC1Bit(struct SiS_Private *SiS_Pr) { SiS_WaitRetrace1(SiS_Pr); return ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x02) >> 1); } /* Set I2C start condition */ /* This is done by a SD high-to-low transition while SC is high */ static unsigned short SiS_SetStart(struct SiS_Private *SiS_Pr) { if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */ SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NData, SiS_Pr->SiS_DDC_Data); /* SD->high */ if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */ SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NData, 0x00); /* SD->low = start condition */ if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->low) */ return 0; } /* Set I2C stop condition */ /* This is done by a SD low-to-high transition while SC is high */ static unsigned short SiS_SetStop(struct SiS_Private *SiS_Pr) { if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */ SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NData, 0x00); /* SD->low */ if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */ SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NData, SiS_Pr->SiS_DDC_Data); /* SD->high = stop condition */ if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->high) */ return 0; } /* Write 8 bits of data */ static unsigned short SiS_WriteDDC2Data(struct SiS_Private *SiS_Pr, unsigned short tempax) { unsigned short i,flag,temp; flag = 0x80; for(i = 0; i < 8; i++) { SiS_SetSCLKLow(SiS_Pr); /* SC->low */ if(tempax & flag) { SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NData, SiS_Pr->SiS_DDC_Data); /* Write bit (1) to SD */ } else { SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NData, 0x00); /* Write bit (0) to SD */ } SiS_SetSCLKHigh(SiS_Pr); /* SC->high */ flag >>= 1; } temp = SiS_CheckACK(SiS_Pr); /* Check acknowledge */ return temp; } static unsigned short SiS_ReadDDC2Data(struct SiS_Private *SiS_Pr) { unsigned short i, temp, getdata; getdata = 0; for(i = 0; i < 8; i++) { getdata <<= 1; SiS_SetSCLKLow(SiS_Pr); SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NData, SiS_Pr->SiS_DDC_Data); SiS_SetSCLKHigh(SiS_Pr); temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); if(temp & SiS_Pr->SiS_DDC_Data) getdata |= 0x01; } return getdata; } static unsigned short SiS_SetSCLKLow(struct SiS_Private *SiS_Pr) { SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NClk, 0x00); /* SetSCLKLow() */ SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT); return 0; } static unsigned short SiS_SetSCLKHigh(struct SiS_Private *SiS_Pr) { unsigned short temp, watchdog=1000; SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NClk, SiS_Pr->SiS_DDC_Clk); /* SetSCLKHigh() */ do { temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog); if (!watchdog) { return 0xFFFF; } SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT); return 0; } /* Check I2C acknowledge */ /* Returns 0 if ack ok, non-0 if ack not ok */ static unsigned short SiS_CheckACK(struct SiS_Private *SiS_Pr) { unsigned short tempah; SiS_SetSCLKLow(SiS_Pr); /* (SC->low) */ SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, SiS_Pr->SiS_DDC_NData, SiS_Pr->SiS_DDC_Data); /* (SD->high) */ SiS_SetSCLKHigh(SiS_Pr); /* SC->high = clock impulse for ack */ tempah = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); /* Read SD */ SiS_SetSCLKLow(SiS_Pr); /* SC->low = end of clock impulse */ if(tempah & SiS_Pr->SiS_DDC_Data) return 1; /* Ack OK if bit = 0 */ return 0; } /* End of I2C functions ----------------------- */ /* =============== SiS 315/330 O.E.M. ================= */ #ifdef CONFIG_FB_SIS_315 static unsigned short GetRAMDACromptr(struct SiS_Private *SiS_Pr) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short romptr; if(SiS_Pr->ChipType < SIS_330) { romptr = SISGETROMW(0x128); if(SiS_Pr->SiS_VBType & VB_SIS30xB) romptr = SISGETROMW(0x12a); } else { romptr = SISGETROMW(0x1a8); if(SiS_Pr->SiS_VBType & VB_SIS30xB) romptr = SISGETROMW(0x1aa); } return romptr; } static unsigned short GetLCDromptr(struct SiS_Private *SiS_Pr) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short romptr; if(SiS_Pr->ChipType < SIS_330) { romptr = SISGETROMW(0x120); if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) romptr = SISGETROMW(0x122); } else { romptr = SISGETROMW(0x1a0); if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) romptr = SISGETROMW(0x1a2); } return romptr; } static unsigned short GetTVromptr(struct SiS_Private *SiS_Pr) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short romptr; if(SiS_Pr->ChipType < SIS_330) { romptr = SISGETROMW(0x114); if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) romptr = SISGETROMW(0x11a); } else { romptr = SISGETROMW(0x194); if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) romptr = SISGETROMW(0x19a); } return romptr; } static unsigned short GetLCDPtrIndexBIOS(struct SiS_Private *SiS_Pr) { unsigned short index; if((IS_SIS650) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) { if(!(SiS_IsNotM650orLater(SiS_Pr))) { if((index = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0)) { index >>= 4; index *= 3; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2; else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++; return index; } } } index = SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F; if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) index -= 5; if(SiS_Pr->SiS_VBType & VB_SIS301C) { /* 1.15.20 and later (not VB specific) */ if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 5; if(SiS_Pr->SiS_LCDResInfo == Panel_1280x768) index -= 5; } else { if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 6; } index--; index *= 3; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2; else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++; return index; } static unsigned short GetLCDPtrIndex(struct SiS_Private *SiS_Pr) { unsigned short index; index = ((SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F) - 1) * 3; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2; else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++; return index; } static unsigned short GetTVPtrIndex(struct SiS_Private *SiS_Pr) { unsigned short index; index = 0; if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1; if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index = 2; if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) index = 0; index <<= 1; if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) { index++; } return index; } static unsigned int GetOEMTVPtr661_2_GEN(struct SiS_Private *SiS_Pr, int addme) { unsigned short index = 0, temp = 0; if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1; if(SiS_Pr->SiS_TVMode & TVSetPALM) index = 2; if(SiS_Pr->SiS_TVMode & TVSetPALN) index = 3; if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 6; if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) { index = 4; if(SiS_Pr->SiS_TVMode & TVSetPALM) index++; if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 7; } if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) { index += addme; temp++; } temp += 0x0100; } return (unsigned int)(index | (temp << 16)); } static unsigned int GetOEMTVPtr661_2_OLD(struct SiS_Private *SiS_Pr) { return (GetOEMTVPtr661_2_GEN(SiS_Pr, 8)); } #if 0 static unsigned int GetOEMTVPtr661_2_NEW(struct SiS_Private *SiS_Pr) { return (GetOEMTVPtr661_2_GEN(SiS_Pr, 6)); } #endif static int GetOEMTVPtr661(struct SiS_Private *SiS_Pr) { int index = 0; if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 2; if(SiS_Pr->SiS_ROMNew) { if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 4; if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 6; if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 8; if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 10; } else { if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 4; if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 6; if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 8; if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 10; } if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) index++; return index; } static void SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short delay=0,index,myindex,temp,romptr=0; bool dochiptest = true; if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x20,0xbf); } else { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x35,0x7f); } /* Find delay (from ROM, internal tables, PCI subsystem) */ if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { /* ------------ VGA */ if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) { romptr = GetRAMDACromptr(SiS_Pr); } if(romptr) delay = ROMAddr[romptr]; else { delay = 0x04; if(SiS_Pr->SiS_VBType & VB_SIS30xB) { if(IS_SIS650) { delay = 0x0a; } else if(IS_SIS740) { delay = 0x00; } else if(SiS_Pr->ChipType < SIS_330) { delay = 0x0c; } else { delay = 0x0c; } } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { delay = 0x00; } } } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD|SetCRT2ToLCDA)) { /* ---------- LCD/LCDA */ bool gotitfrompci = false; /* Could we detect a PDC for LCD or did we get a user-defined? If yes, use it */ if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { if(SiS_Pr->PDC != -1) { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((SiS_Pr->PDC >> 1) & 0x0f)); SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((SiS_Pr->PDC & 0x01) << 7)); return; } } else { if(SiS_Pr->PDCA != -1) { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((SiS_Pr->PDCA << 3) & 0xf0)); SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((SiS_Pr->PDCA & 0x01) << 6)); return; } } /* Custom Panel? */ if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { delay = 0x00; if((SiS_Pr->PanelXRes <= 1280) && (SiS_Pr->PanelYRes <= 1024)) { delay = 0x20; } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,delay); } else { delay = 0x0c; if(SiS_Pr->SiS_VBType & VB_SIS301C) { delay = 0x03; if((SiS_Pr->PanelXRes > 1280) && (SiS_Pr->PanelYRes > 1024)) { delay = 0x00; } } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) { if(IS_SIS740) delay = 0x01; else delay = 0x03; } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,delay); } return; } /* This is a piece of typical SiS crap: They code the OEM LCD * delay into the code, at no defined place in the BIOS. * We now have to start doing a PCI subsystem check here. */ switch(SiS_Pr->SiS_CustomT) { case CUT_COMPAQ1280: case CUT_COMPAQ12802: if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) { gotitfrompci = true; dochiptest = false; delay = 0x03; } break; case CUT_CLEVO1400: case CUT_CLEVO14002: gotitfrompci = true; dochiptest = false; delay = 0x02; break; case CUT_CLEVO1024: case CUT_CLEVO10242: if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { gotitfrompci = true; dochiptest = false; delay = 0x33; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay); delay &= 0x0f; } break; } /* Could we find it through the PCI ID? If no, use ROM or table */ if(!gotitfrompci) { index = GetLCDPtrIndexBIOS(SiS_Pr); myindex = GetLCDPtrIndex(SiS_Pr); if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) { if(SiS_IsNotM650orLater(SiS_Pr)) { if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) { /* Always use the second pointer on 650; some BIOSes */ /* still carry old 301 data at the first location */ /* romptr = SISGETROMW(0x120); */ /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */ romptr = SISGETROMW(0x122); if(!romptr) return; delay = ROMAddr[(romptr + index)]; } else { delay = SiS310_LCDDelayCompensation_650301LV[myindex]; } } else { delay = SiS310_LCDDelayCompensation_651301LV[myindex]; if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) delay = SiS310_LCDDelayCompensation_651302LV[myindex]; } } else if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew)) && (SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) && (SiS_Pr->SiS_LCDResInfo != Panel_1280x768) && (SiS_Pr->SiS_LCDResInfo != Panel_1280x960) && (SiS_Pr->SiS_LCDResInfo != Panel_1600x1200) && ((romptr = GetLCDromptr(SiS_Pr)))) { /* Data for 1280x1024 wrong in 301B BIOS */ /* Data for 1600x1200 wrong in 301C BIOS */ delay = ROMAddr[(romptr + index)]; } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { if(IS_SIS740) delay = 0x03; else delay = 0x00; } else { delay = SiS310_LCDDelayCompensation_301[myindex]; if(SiS_Pr->SiS_VBType & VB_SISLVDS) { if(IS_SIS740) delay = 0x01; else if(SiS_Pr->ChipType <= SIS_315PRO) delay = SiS310_LCDDelayCompensation_3xx301LV[myindex]; else delay = SiS310_LCDDelayCompensation_650301LV[myindex]; } else if(SiS_Pr->SiS_VBType & VB_SIS301C) { if(IS_SIS740) delay = 0x01; /* ? */ else delay = 0x03; if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) delay = 0x00; /* experience */ } else if(SiS_Pr->SiS_VBType & VB_SIS30xB) { if(IS_SIS740) delay = 0x01; else delay = SiS310_LCDDelayCompensation_3xx301B[myindex]; } } } /* got it from PCI */ if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0)); dochiptest = false; } } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */ index = GetTVPtrIndex(SiS_Pr); if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) { if(SiS_IsNotM650orLater(SiS_Pr)) { if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) { /* Always use the second pointer on 650; some BIOSes */ /* still carry old 301 data at the first location */ /* romptr = SISGETROMW(0x114); */ /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */ romptr = SISGETROMW(0x11a); if(!romptr) return; delay = ROMAddr[romptr + index]; } else { delay = SiS310_TVDelayCompensation_301B[index]; } } else { switch(SiS_Pr->SiS_CustomT) { case CUT_COMPAQ1280: case CUT_COMPAQ12802: case CUT_CLEVO1400: case CUT_CLEVO14002: delay = 0x02; dochiptest = false; break; case CUT_CLEVO1024: case CUT_CLEVO10242: delay = 0x03; dochiptest = false; break; default: delay = SiS310_TVDelayCompensation_651301LV[index]; if(SiS_Pr->SiS_VBType & VB_SIS302LV) { delay = SiS310_TVDelayCompensation_651302LV[index]; } } } } else if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) { romptr = GetTVromptr(SiS_Pr); if(!romptr) return; delay = ROMAddr[romptr + index]; } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { delay = SiS310_TVDelayCompensation_LVDS[index]; } else { delay = SiS310_TVDelayCompensation_301[index]; if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { if(IS_SIS740) { delay = SiS310_TVDelayCompensation_740301B[index]; /* LV: use 301 data? BIOS bug? */ } else { delay = SiS310_TVDelayCompensation_301B[index]; if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x02; } } } if(SiS_LCDAEnabled(SiS_Pr)) { delay &= 0x0f; dochiptest = false; } } else return; /* Write delay */ if(SiS_Pr->SiS_VBType & VB_SISVB) { if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS) && dochiptest) { temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0) >> 4; if(temp == 8) { /* 1400x1050 BIOS (COMPAL) */ delay &= 0x0f; delay |= 0xb0; } else if(temp == 6) { delay &= 0x0f; delay |= 0xc0; } else if(temp > 7) { /* 1280x1024 BIOS (which one?) */ delay = 0x35; } SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay); } else { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay); } } else { /* LVDS */ if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay); } else { if(IS_SIS650 && (SiS_Pr->SiS_IF_DEF_CH70xx != 0)) { delay <<= 4; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,delay); } else { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay); } } } } static void SetAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short index,temp,temp1,romptr=0; if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p|TVSetYPbPr525p)) return; if(ModeNo<=0x13) index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex; else index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex; temp = GetTVPtrIndex(SiS_Pr); temp >>= 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */ temp1 = temp; if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) { if(SiS_Pr->ChipType >= SIS_661) { temp1 = GetOEMTVPtr661(SiS_Pr); temp1 >>= 1; romptr = SISGETROMW(0x260); if(SiS_Pr->ChipType >= SIS_760) { romptr = SISGETROMW(0x360); } } else if(SiS_Pr->ChipType >= SIS_330) { romptr = SISGETROMW(0x192); } else { romptr = SISGETROMW(0x112); } } if(romptr) { temp1 <<= 1; temp = ROMAddr[romptr + temp1 + index]; } else { temp = SiS310_TVAntiFlick1[temp][index]; } temp <<= 4; SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8f,temp); /* index 0A D[6:4] */ } static void SetEdgeEnhance(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short index,temp,temp1,romptr=0; temp = temp1 = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */ if(ModeNo <= 0x13) index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex; else index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex; if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) { if(SiS_Pr->ChipType >= SIS_661) { romptr = SISGETROMW(0x26c); if(SiS_Pr->ChipType >= SIS_760) { romptr = SISGETROMW(0x36c); } temp1 = GetOEMTVPtr661(SiS_Pr); temp1 >>= 1; } else if(SiS_Pr->ChipType >= SIS_330) { romptr = SISGETROMW(0x1a4); } else { romptr = SISGETROMW(0x124); } } if(romptr) { temp1 <<= 1; temp = ROMAddr[romptr + temp1 + index]; } else { temp = SiS310_TVEdge1[temp][index]; } temp <<= 5; SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x3A,0x1F,temp); /* index 0A D[7:5] */ } static void SetYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex) { unsigned short index, temp, i, j; if(ModeNo <= 0x13) { index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex; } else { index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex; } temp = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */ if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 1; /* NTSC-J uses PAL */ else if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 3; /* PAL-M */ else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 4; /* PAL-N */ if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp = 1; /* HiVision uses PAL */ if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { for(i=0x35, j=0; i<=0x38; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]); } for(i=0x48; i<=0x4A; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]); } } else { for(i=0x35, j=0; i<=0x38; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter1[temp][index][j]); } } } static void SetPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short index,temp,i,j,resinfo,romptr=0; unsigned int lindex; if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return; /* NTSC-J data not in BIOS, and already set in SetGroup2 */ if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) return; if((SiS_Pr->ChipType >= SIS_661) || SiS_Pr->SiS_ROMNew) { lindex = GetOEMTVPtr661_2_OLD(SiS_Pr) & 0xffff; lindex <<= 2; for(j=0, i=0x31; i<=0x34; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[lindex + j]); } return; } /* PAL-M, PAL-N not in BIOS, and already set in SetGroup2 */ if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) return; if(ModeNo<=0x13) { resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; } else { resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; } temp = GetTVPtrIndex(SiS_Pr); /* 0: NTSC Graphics, 1: NTSC Text, 2: PAL Graphics, * 3: PAL Text, 4: HiTV Graphics 5: HiTV Text */ if(SiS_Pr->SiS_UseROM) { romptr = SISGETROMW(0x116); if(SiS_Pr->ChipType >= SIS_330) { romptr = SISGETROMW(0x196); } if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { romptr = SISGETROMW(0x11c); if(SiS_Pr->ChipType >= SIS_330) { romptr = SISGETROMW(0x19c); } if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode))) { romptr = SISGETROMW(0x116); if(SiS_Pr->ChipType >= SIS_330) { romptr = SISGETROMW(0x196); } } } } if(romptr) { romptr += (temp << 2); for(j=0, i=0x31; i<=0x34; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]); } } else { index = temp % 2; temp >>= 1; /* 0:NTSC, 1:PAL, 2:HiTV */ for(j=0, i=0x31; i<=0x34; i++, j++) { if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]); else if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr2[temp][index][j]); else SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]); } } if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision))) { if((!(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetYPbPr525p | TVSetYPbPr750p))) && (ModeNo > 0x13)) { if((resinfo == SIS_RI_640x480) || (resinfo == SIS_RI_800x600)) { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x21); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0xf0); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xf5); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7f); } else if(resinfo == SIS_RI_1024x768) { SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x1e); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0x8b); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xfb); SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7b); } } } } static void SetDelayComp661(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RTI) { unsigned short delay = 0, romptr = 0, index, lcdpdcindex; unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToRAMDAC))) return; /* 1. New ROM: VGA2 and LCD/LCDA-Pass1:1 */ /* (If a custom mode is used, Pass1:1 is always set; hence we do this:) */ if(SiS_Pr->SiS_ROMNew) { if((SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) || ((SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) && (SiS_Pr->SiS_LCDInfo & LCDPass11))) { index = 25; if(SiS_Pr->UseCustomMode) { index = SiS_Pr->CSRClock; } else if(ModeNo > 0x13) { index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RTI); index = SiS_Pr->SiS_VCLKData[index].CLOCK; } if(index < 25) index = 25; index = ((index / 25) - 1) << 1; if((ROMAddr[0x5b] & 0x80) || (SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD))) { index++; } romptr = SISGETROMW(0x104); delay = ROMAddr[romptr + index]; if(SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD)) { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f)); SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7)); } else { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0)); SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6)); } return; } } /* 2. Old ROM: VGA2 and LCD/LCDA-Pass 1:1 */ if(SiS_Pr->UseCustomMode) delay = 0x04; else if(ModeNo <= 0x13) delay = 0x04; else delay = (SiS_Pr->SiS_RefIndex[RTI].Ext_PDC >> 4); delay |= (delay << 8); if(SiS_Pr->ChipType >= XGI_20) { delay = 0x0606; if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { delay = 0x0404; if(SiS_Pr->SiS_XGIROM) { index = GetTVPtrIndex(SiS_Pr); if((romptr = SISGETROMW(0x35e))) { delay = (ROMAddr[romptr + index] & 0x0f) << 1; delay |= (delay << 8); } } if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { if(SiS_Pr->ChipType == XGI_40 && SiS_Pr->ChipRevision == 0x02) { delay -= 0x0404; } } } } else if(SiS_Pr->ChipType >= SIS_340) { delay = 0x0606; if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { delay = 0x0404; } /* TODO (eventually) */ } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* 3. TV */ index = GetOEMTVPtr661(SiS_Pr); if(SiS_Pr->SiS_ROMNew) { romptr = SISGETROMW(0x106); if(SiS_Pr->SiS_VBType & VB_UMC) romptr += 12; delay = ROMAddr[romptr + index]; } else { delay = 0x04; if(index > 3) delay = 0; } } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /* 4. LCD, LCDA (for new ROM only LV and non-Pass 1:1) */ if( (SiS_Pr->SiS_LCDResInfo != Panel_Custom) && ((romptr = GetLCDStructPtr661_2(SiS_Pr))) ) { lcdpdcindex = (SiS_Pr->SiS_VBType & VB_UMC) ? 14 : 12; /* For LVDS (and sometimes TMDS), the BIOS must know about the correct value */ delay = ROMAddr[romptr + lcdpdcindex + 1]; /* LCD */ delay |= (ROMAddr[romptr + lcdpdcindex] << 8); /* LCDA */ } else { /* TMDS: Set our own, since BIOS has no idea */ /* (This is done on >=661 only, since <661 is calling this only for LVDS) */ if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { switch(SiS_Pr->SiS_LCDResInfo) { case Panel_1024x768: delay = 0x0008; break; case Panel_1280x720: delay = 0x0004; break; case Panel_1280x768: case Panel_1280x768_2:delay = 0x0004; break; case Panel_1280x800: case Panel_1280x800_2:delay = 0x0004; break; /* Verified for 1280x800 */ case Panel_1280x854: delay = 0x0004; break; /* FIXME */ case Panel_1280x1024: delay = 0x1e04; break; case Panel_1400x1050: delay = 0x0004; break; case Panel_1600x1200: delay = 0x0400; break; case Panel_1680x1050: delay = 0x0e04; break; default: if((SiS_Pr->PanelXRes <= 1024) && (SiS_Pr->PanelYRes <= 768)) { delay = 0x0008; } else if((SiS_Pr->PanelXRes == 1280) && (SiS_Pr->PanelYRes == 1024)) { delay = 0x1e04; } else if((SiS_Pr->PanelXRes <= 1400) && (SiS_Pr->PanelYRes <= 1050)) { delay = 0x0004; } else if((SiS_Pr->PanelXRes <= 1600) && (SiS_Pr->PanelYRes <= 1200)) { delay = 0x0400; } else delay = 0x0e04; break; } } /* Override by detected or user-set values */ /* (but only if, for some reason, we can't read value from BIOS) */ if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->PDC != -1)) { delay = SiS_Pr->PDC & 0x1f; } if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) && (SiS_Pr->PDCA != -1)) { delay = (SiS_Pr->PDCA & 0x1f) << 8; } } } if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { delay >>= 8; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0)); SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6)); } else { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f)); SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7)); } } static void SetCRT2SyncDither661(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RTI) { unsigned short infoflag; unsigned char temp; if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(ModeNo <= 0x13) { infoflag = SiS_GetRegByte(SiS_Pr->SiS_P3ca+2); } else if(SiS_Pr->UseCustomMode) { infoflag = SiS_Pr->CInfoFlag; } else { infoflag = SiS_Pr->SiS_RefIndex[RTI].Ext_InfoFlag; } if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { infoflag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); /* No longer check D5 */ } infoflag &= 0xc0; if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { temp = (infoflag >> 6) | 0x0c; if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) { temp ^= 0x04; if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x10; } SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xe0,temp); } else { temp = 0x30; if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp = 0x20; temp |= infoflag; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0f,temp); temp = 0; if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) { if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x80; } SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1a,0x7f,temp); } } } static void SetPanelParms661(struct SiS_Private *SiS_Pr) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short romptr, temp1, temp2; if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_SIS30xC)) { SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x24,0x0f); } if(SiS_Pr->SiS_VBType & VB_SISLVDS) { if(SiS_Pr->LVDSHL != -1) { SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL); } } if(SiS_Pr->SiS_ROMNew) { if((romptr = GetLCDStructPtr661_2(SiS_Pr))) { if(SiS_Pr->SiS_VBType & VB_SISLVDS) { temp1 = (ROMAddr[romptr] & 0x03) | 0x0c; temp2 = 0xfc; if(SiS_Pr->LVDSHL != -1) { temp1 &= 0xfc; temp2 = 0xf3; } SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,temp2,temp1); } if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { temp1 = (ROMAddr[romptr + 1] & 0x80) >> 1; SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d,0xbf,temp1); } } } } static void SiS_OEM310Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RRTI) { if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) { SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI); if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI); SetPanelParms661(SiS_Pr); } } else { SetDelayComp(SiS_Pr,ModeNo); } if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) { SetAntiFlicker(SiS_Pr,ModeNo,ModeIdIndex); SetPhaseIncr(SiS_Pr,ModeNo,ModeIdIndex); SetYFilter(SiS_Pr,ModeNo,ModeIdIndex); if(SiS_Pr->SiS_VBType & VB_SIS301) { SetEdgeEnhance(SiS_Pr,ModeNo,ModeIdIndex); } } } static void SiS_OEM661Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RRTI) { if(SiS_Pr->SiS_VBType & VB_SISVB) { SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI); if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI); SetPanelParms661(SiS_Pr); } if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { SetPhaseIncr(SiS_Pr, ModeNo, ModeIdIndex); SetYFilter(SiS_Pr, ModeNo, ModeIdIndex); SetAntiFlicker(SiS_Pr, ModeNo, ModeIdIndex); if(SiS_Pr->SiS_VBType & VB_SIS301) { SetEdgeEnhance(SiS_Pr, ModeNo, ModeIdIndex); } } } } /* FinalizeLCD * This finalizes some CRT2 registers for the very panel used. * If we have a backup if these registers, we use it; otherwise * we set the register according to most BIOSes. However, this * function looks quite different in every BIOS, so you better * pray that we have a backup... */ static void SiS_FinalizeLCD(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned short tempcl,tempch,tempbl,tempbh,tempbx,tempax,temp; unsigned short resinfo,modeflag; if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) return; if(SiS_Pr->SiS_ROMNew) return; if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(SiS_Pr->LVDSHL != -1) { SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL); } } if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return; if(SiS_Pr->UseCustomMode) return; switch(SiS_Pr->SiS_CustomT) { case CUT_COMPAQ1280: case CUT_COMPAQ12802: case CUT_CLEVO1400: case CUT_CLEVO14002: return; } if(ModeNo <= 0x13) { resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo; modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; } else { resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; } if(IS_SIS650) { if(!(SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5f) & 0xf0)) { if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x02); } else { SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03); } } } if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { /* Maybe all panels? */ if(SiS_Pr->LVDSHL == -1) { SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01); } return; } } if(SiS_Pr->SiS_CustomT == CUT_CLEVO10242) { if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if(SiS_Pr->LVDSHL == -1) { /* Maybe all panels? */ SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01); } if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4; if(tempch == 3) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b); } } return; } } } if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if(SiS_Pr->SiS_VBType & VB_SISEMI) { SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00); #ifdef SET_EMI SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c); #endif SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10); } } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) { if(SiS_Pr->LVDSHL == -1) { /* Maybe ACER only? */ SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01); } } tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4; if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1f,0x76); } else if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if(tempch == 0x03) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b); } if(SiS_Pr->Backup && (SiS_Pr->Backup_Mode == ModeNo)) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,SiS_Pr->Backup_14); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,SiS_Pr->Backup_15); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,SiS_Pr->Backup_16); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,SiS_Pr->Backup_17); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,SiS_Pr->Backup_18); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,SiS_Pr->Backup_19); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,SiS_Pr->Backup_1a); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,SiS_Pr->Backup_1b); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,SiS_Pr->Backup_1c); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,SiS_Pr->Backup_1d); } else if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { /* 1.10.8w */ SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x90); if(ModeNo <= 0x13) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x11); if((resinfo == 0) || (resinfo == 2)) return; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x18); if((resinfo == 1) || (resinfo == 3)) return; } SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02); if((ModeNo > 0x13) && (resinfo == SIS_RI_1024x768)) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02); /* 1.10.7u */ #if 0 tempbx = 806; /* 0x326 */ /* other older BIOSes */ tempbx--; temp = tempbx & 0xff; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); temp = (tempbx >> 8) & 0x03; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1d,0xf8,temp); #endif } } else if(ModeNo <= 0x13) { if(ModeNo <= 1) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x70); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xff); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12); } if(!(modeflag & HalfDCLK)) { SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x20); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,0x1a); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,0x28); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,0x00); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x4c); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc); if(ModeNo == 0x12) { switch(tempch) { case 0: SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,0x10); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x48); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12); break; case 2: SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95); SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48); break; case 3: SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95); break; } } } } } } else { tempcl = tempbh = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01); tempcl &= 0x0f; tempbh &= 0x70; tempbh >>= 4; tempbl = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x04); tempbx = (tempbh << 8) | tempbl; if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if((resinfo == SIS_RI_1024x768) || (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD))) { if(SiS_Pr->SiS_SetFlag & LCDVESATiming) { tempbx = 770; } else { if(tempbx > 770) tempbx = 770; if(SiS_Pr->SiS_VGAVDE < 600) { tempax = 768 - SiS_Pr->SiS_VGAVDE; tempax >>= 4; /* 1.10.7w; 1.10.6s: 3; */ if(SiS_Pr->SiS_VGAVDE <= 480) tempax >>= 4; /* 1.10.7w; 1.10.6s: < 480; >>=1; */ tempbx -= tempax; } } } else return; } temp = tempbx & 0xff; SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,temp); temp = ((tempbx & 0xff00) >> 4) | tempcl; SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,temp); } } } #endif /* ================= SiS 300 O.E.M. ================== */ #ifdef CONFIG_FB_SIS_300 static void SetOEMLCDData2(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex, unsigned short RefTabIndex) { unsigned short crt2crtc=0, modeflag, myindex=0; unsigned char temp; int i; if(ModeNo <= 0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; } else { modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; crt2crtc = SiS_Pr->SiS_RefIndex[RefTabIndex].Ext_CRT2CRTC; } crt2crtc &= 0x3f; if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) { SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xdf); } if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) { if(modeflag & HalfDCLK) myindex = 1; if(SiS_Pr->SiS_SetFlag & LowModeTests) { for(i=0; i<7; i++) { if(barco_p1[myindex][crt2crtc][i][0]) { SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port, barco_p1[myindex][crt2crtc][i][0], barco_p1[myindex][crt2crtc][i][2], barco_p1[myindex][crt2crtc][i][1]); } } } temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00); if(temp & 0x80) { temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x18); temp++; SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp); } } } static unsigned short GetOEMLCDPtr(struct SiS_Private *SiS_Pr, int Flag) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short tempbx=0,romptr=0; static const unsigned char customtable300[] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }; static const unsigned char customtable630[] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }; if(SiS_Pr->ChipType == SIS_300) { tempbx = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f; if(SiS_Pr->SiS_VBType & VB_SIS301) tempbx &= 0x07; tempbx -= 2; if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 4; if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 3; } if(SiS_Pr->SiS_UseROM) { if(ROMAddr[0x235] & 0x80) { tempbx = SiS_Pr->SiS_LCDTypeInfo; if(Flag) { romptr = SISGETROMW(0x255); if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo]; else tempbx = customtable300[SiS_Pr->SiS_LCDTypeInfo]; if(tempbx == 0xFF) return 0xFFFF; } tempbx <<= 1; if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++; } } } else { if(Flag) { if(SiS_Pr->SiS_UseROM) { romptr = SISGETROMW(0x255); if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo]; else tempbx = 0xff; } else { tempbx = customtable630[SiS_Pr->SiS_LCDTypeInfo]; } if(tempbx == 0xFF) return 0xFFFF; tempbx <<= 2; if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++; return tempbx; } tempbx = SiS_Pr->SiS_LCDTypeInfo << 2; if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2; if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++; } return tempbx; } static void SetOEMLCDDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short index,temp,romptr=0; if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return; if(SiS_Pr->SiS_UseROM) { if(!(ROMAddr[0x237] & 0x01)) return; if(!(ROMAddr[0x237] & 0x02)) return; romptr = SISGETROMW(0x24b); } /* The Panel Compensation Delay should be set according to tables * here. Unfortunately, various BIOS versions don't care about * a uniform way using eg. ROM byte 0x220, but use different * hard coded delays (0x04, 0x20, 0x18) in SetGroup1(). * Thus we don't set this if the user selected a custom pdc or if * we otherwise detected a valid pdc. */ if(SiS_Pr->PDC != -1) return; temp = GetOEMLCDPtr(SiS_Pr, 0); if(SiS_Pr->UseCustomMode) index = 0; else index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex; if(SiS_Pr->ChipType != SIS_300) { if(romptr) { romptr += (temp * 2); romptr = SISGETROMW(romptr); romptr += index; temp = ROMAddr[romptr]; } else { if(SiS_Pr->SiS_VBType & VB_SISVB) { temp = SiS300_OEMLCDDelay2[temp][index]; } else { temp = SiS300_OEMLCDDelay3[temp][index]; } } } else { if(SiS_Pr->SiS_UseROM && (ROMAddr[0x235] & 0x80)) { if(romptr) { romptr += (temp * 2); romptr = SISGETROMW(romptr); romptr += index; temp = ROMAddr[romptr]; } else { temp = SiS300_OEMLCDDelay5[temp][index]; } } else { if(SiS_Pr->SiS_UseROM) { romptr = ROMAddr[0x249] | (ROMAddr[0x24a] << 8); if(romptr) { romptr += (temp * 2); romptr = SISGETROMW(romptr); romptr += index; temp = ROMAddr[romptr]; } else { temp = SiS300_OEMLCDDelay4[temp][index]; } } else { temp = SiS300_OEMLCDDelay4[temp][index]; } } } temp &= 0x3c; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* index 0A D[6:4] */ } static void SetOEMLCDData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { #if 0 /* Unfinished; Data table missing */ unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short index,temp; if((SiS_Pr->SiS_UseROM) { if(!(ROMAddr[0x237] & 0x01)) return; if(!(ROMAddr[0x237] & 0x04)) return; /* No rom pointer in BIOS header! */ } temp = GetOEMLCDPtr(SiS_Pr, 1); if(temp == 0xFFFF) return; index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDHIndex; for(i=0x14, j=0; i<=0x17; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDHData[temp][index][j]); } SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1a, 0xf8, (SiS300_LCDHData[temp][index][j] & 0x07)); index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDVIndex; SiS_SetReg(SiS_SiS_Part1Port,0x18, SiS300_LCDVData[temp][index][0]); SiS_SetRegANDOR(SiS_SiS_Part1Port,0x19, 0xF0, SiS300_LCDVData[temp][index][1]); SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1A, 0xC7, (SiS300_LCDVData[temp][index][2] & 0x38)); for(i=0x1b, j=3; i<=0x1d; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDVData[temp][index][j]); } #endif } static unsigned short GetOEMTVPtr(struct SiS_Private *SiS_Pr) { unsigned short index; index = 0; if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) index += 4; if(SiS_Pr->SiS_VBType & VB_SISVB) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) index += 2; else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index += 3; else if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1; } else { if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) index += 2; if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1; } return index; } static void SetOEMTVDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short index,temp,romptr=0; if(SiS_Pr->SiS_UseROM) { if(!(ROMAddr[0x238] & 0x01)) return; if(!(ROMAddr[0x238] & 0x02)) return; romptr = SISGETROMW(0x241); } temp = GetOEMTVPtr(SiS_Pr); index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVDelayIndex; if(romptr) { romptr += (temp * 2); romptr = SISGETROMW(romptr); romptr += index; temp = ROMAddr[romptr]; } else { if(SiS_Pr->SiS_VBType & VB_SISVB) { temp = SiS300_OEMTVDelay301[temp][index]; } else { temp = SiS300_OEMTVDelayLVDS[temp][index]; } } temp &= 0x3c; SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); } static void SetOEMAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short index,temp,romptr=0; if(SiS_Pr->SiS_UseROM) { if(!(ROMAddr[0x238] & 0x01)) return; if(!(ROMAddr[0x238] & 0x04)) return; romptr = SISGETROMW(0x243); } temp = GetOEMTVPtr(SiS_Pr); index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVFlickerIndex; if(romptr) { romptr += (temp * 2); romptr = SISGETROMW(romptr); romptr += index; temp = ROMAddr[romptr]; } else { temp = SiS300_OEMTVFlicker[temp][index]; } temp &= 0x70; SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8F,temp); } static void SetOEMPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short index,i,j,temp,romptr=0; if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) return; if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetNTSCJ | TVSetPALM | TVSetPALN)) return; if(SiS_Pr->SiS_UseROM) { if(!(ROMAddr[0x238] & 0x01)) return; if(!(ROMAddr[0x238] & 0x08)) return; romptr = SISGETROMW(0x245); } temp = GetOEMTVPtr(SiS_Pr); index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVPhaseIndex; if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { for(i=0x31, j=0; i<=0x34; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase2[temp][index][j]); } } else { if(romptr) { romptr += (temp * 2); romptr = SISGETROMW(romptr); romptr += (index * 4); for(i=0x31, j=0; i<=0x34; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]); } } else { for(i=0x31, j=0; i<=0x34; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase1[temp][index][j]); } } } } static void SetOEMYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) { unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; unsigned short index,temp,i,j,romptr=0; if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVision | SetCRT2ToYPbPr525750)) return; if(SiS_Pr->SiS_UseROM) { if(!(ROMAddr[0x238] & 0x01)) return; if(!(ROMAddr[0x238] & 0x10)) return; romptr = SISGETROMW(0x247); } temp = GetOEMTVPtr(SiS_Pr); if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8; else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 9; /* NTSCJ uses NTSC filters */ index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVYFilterIndex; if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { for(i=0x35, j=0; i<=0x38; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]); } for(i=0x48; i<=0x4A; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]); } } else { if((romptr) && (!(SiS_Pr->SiS_TVMode & (TVSetPALM|TVSetPALN)))) { romptr += (temp * 2); romptr = SISGETROMW(romptr); romptr += (index * 4); for(i=0x35, j=0; i<=0x38; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]); } } else { for(i=0x35, j=0; i<=0x38; i++, j++) { SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter1[temp][index][j]); } } } } static unsigned short SiS_SearchVBModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo) { unsigned short ModeIdIndex; unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO; if(*ModeNo <= 5) *ModeNo |= 1; for(ModeIdIndex=0; ; ModeIdIndex++) { if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == *ModeNo) break; if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == 0xFF) return 0; } if(*ModeNo != 0x07) { if(*ModeNo > 0x03) return ModeIdIndex; if(VGAINFO & 0x80) return ModeIdIndex; ModeIdIndex++; } if(VGAINFO & 0x10) ModeIdIndex++; /* 400 lines */ /* else 350 lines */ return ModeIdIndex; } static void SiS_OEM300Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefTableIndex) { unsigned short OEMModeIdIndex = 0; if(!SiS_Pr->UseCustomMode) { OEMModeIdIndex = SiS_SearchVBModeID(SiS_Pr,&ModeNo); if(!(OEMModeIdIndex)) return; } if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { SetOEMLCDDelay(SiS_Pr, ModeNo, OEMModeIdIndex); if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { SetOEMLCDData(SiS_Pr, ModeNo, OEMModeIdIndex); } } if(SiS_Pr->UseCustomMode) return; if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { SetOEMTVDelay(SiS_Pr, ModeNo,OEMModeIdIndex); if(SiS_Pr->SiS_VBType & VB_SISVB) { SetOEMAntiFlicker(SiS_Pr, ModeNo, OEMModeIdIndex); SetOEMPhaseIncr(SiS_Pr, ModeNo, OEMModeIdIndex); SetOEMYFilter(SiS_Pr, ModeNo, OEMModeIdIndex); } } } #endif
gpl-2.0
santod/google_kernel_m7_3.4.10-g1a25406
arch/blackfin/mach-bf533/dma.c
12223
1575
/* * simple DMA Implementation for Blackfin * * Copyright 2007-2009 Analog Devices Inc. * * Licensed under the GPL-2 or later. */ #include <linux/module.h> #include <asm/blackfin.h> #include <asm/dma.h> struct dma_register * const dma_io_base_addr[MAX_DMA_CHANNELS] = { (struct dma_register *) DMA0_NEXT_DESC_PTR, (struct dma_register *) DMA1_NEXT_DESC_PTR, (struct dma_register *) DMA2_NEXT_DESC_PTR, (struct dma_register *) DMA3_NEXT_DESC_PTR, (struct dma_register *) DMA4_NEXT_DESC_PTR, (struct dma_register *) DMA5_NEXT_DESC_PTR, (struct dma_register *) DMA6_NEXT_DESC_PTR, (struct dma_register *) DMA7_NEXT_DESC_PTR, (struct dma_register *) MDMA_D0_NEXT_DESC_PTR, (struct dma_register *) MDMA_S0_NEXT_DESC_PTR, (struct dma_register *) MDMA_D1_NEXT_DESC_PTR, (struct dma_register *) MDMA_S1_NEXT_DESC_PTR, }; EXPORT_SYMBOL(dma_io_base_addr); int channel2irq(unsigned int channel) { int ret_irq = -1; switch (channel) { case CH_PPI: ret_irq = IRQ_PPI; break; case CH_SPORT0_RX: ret_irq = IRQ_SPORT0_RX; break; case CH_SPORT0_TX: ret_irq = IRQ_SPORT0_TX; break; case CH_SPORT1_RX: ret_irq = IRQ_SPORT1_RX; break; case CH_SPORT1_TX: ret_irq = IRQ_SPORT1_TX; break; case CH_SPI: ret_irq = IRQ_SPI; break; case CH_UART0_RX: ret_irq = IRQ_UART0_RX; break; case CH_UART0_TX: ret_irq = IRQ_UART0_TX; break; case CH_MEM_STREAM0_SRC: case CH_MEM_STREAM0_DEST: ret_irq = IRQ_MEM_DMA0; break; case CH_MEM_STREAM1_SRC: case CH_MEM_STREAM1_DEST: ret_irq = IRQ_MEM_DMA1; break; } return ret_irq; }
gpl-2.0
imaginegit/melody_kernel
sound/pci/echoaudio/indigo_dsp.c
12479
4043
/**************************************************************************** Copyright Echo Digital Audio Corporation (c) 1998 - 2004 All rights reserved www.echoaudio.com This file is part of Echo Digital Audio's generic driver library. Echo Digital Audio's generic driver 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. 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. ************************************************************************* Translation from C++ and adaptation for use in ALSA-Driver were made by Giuliano Pochini <pochini@shiny.it> ****************************************************************************/ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe, int gain); static int update_vmixer_level(struct echoaudio *chip); static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id) { int err; DE_INIT(("init_hw() - Indigo\n")); if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO)) return -ENODEV; if ((err = init_dsp_comm_page(chip))) { DE_INIT(("init_hw - could not initialize DSP comm page\n")); return err; } chip->device_id = device_id; chip->subdevice_id = subdevice_id; chip->bad_board = TRUE; chip->dsp_code_to_load = FW_INDIGO_DSP; /* Since this card has no ASIC, mark it as loaded so everything works OK */ chip->asic_loaded = TRUE; chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL; if ((err = load_firmware(chip)) < 0) return err; chip->bad_board = FALSE; DE_INIT(("init_hw done\n")); return err; } static int set_mixer_defaults(struct echoaudio *chip) { return init_line_levels(chip); } static u32 detect_input_clocks(const struct echoaudio *chip) { return ECHO_CLOCK_BIT_INTERNAL; } /* The Indigo has no ASIC. Just do nothing */ static int load_asic(struct echoaudio *chip) { return 0; } static int set_sample_rate(struct echoaudio *chip, u32 rate) { u32 control_reg; switch (rate) { case 96000: control_reg = MIA_96000; break; case 88200: control_reg = MIA_88200; break; case 48000: control_reg = MIA_48000; break; case 44100: control_reg = MIA_44100; break; case 32000: control_reg = MIA_32000; break; default: DE_ACT(("set_sample_rate: %d invalid!\n", rate)); return -EINVAL; } /* Set the control register if it has changed */ if (control_reg != le32_to_cpu(chip->comm_page->control_register)) { if (wait_handshake(chip)) return -EIO; chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */ chip->comm_page->control_register = cpu_to_le32(control_reg); chip->sample_rate = rate; clear_handshake(chip); return send_vector(chip, DSP_VC_UPDATE_CLOCKS); } return 0; } /* This function routes the sound from a virtual channel to a real output */ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe, int gain) { int index; if (snd_BUG_ON(pipe >= num_pipes_out(chip) || output >= num_busses_out(chip))) return -EINVAL; if (wait_handshake(chip)) return -EIO; chip->vmixer_gain[output][pipe] = gain; index = output * num_pipes_out(chip) + pipe; chip->comm_page->vmixer[index] = gain; DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain)); return 0; } /* Tell the DSP to read and update virtual mixer levels in comm page. */ static int update_vmixer_level(struct echoaudio *chip) { if (wait_handshake(chip)) return -EIO; clear_handshake(chip); return send_vector(chip, DSP_VC_SET_VMIXER_GAIN); }
gpl-2.0
atilag/android_kernel_samsung_smdk4412
sound/pci/echoaudio/indigo_dsp.c
12479
4043
/**************************************************************************** Copyright Echo Digital Audio Corporation (c) 1998 - 2004 All rights reserved www.echoaudio.com This file is part of Echo Digital Audio's generic driver library. Echo Digital Audio's generic driver 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. 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. ************************************************************************* Translation from C++ and adaptation for use in ALSA-Driver were made by Giuliano Pochini <pochini@shiny.it> ****************************************************************************/ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe, int gain); static int update_vmixer_level(struct echoaudio *chip); static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id) { int err; DE_INIT(("init_hw() - Indigo\n")); if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO)) return -ENODEV; if ((err = init_dsp_comm_page(chip))) { DE_INIT(("init_hw - could not initialize DSP comm page\n")); return err; } chip->device_id = device_id; chip->subdevice_id = subdevice_id; chip->bad_board = TRUE; chip->dsp_code_to_load = FW_INDIGO_DSP; /* Since this card has no ASIC, mark it as loaded so everything works OK */ chip->asic_loaded = TRUE; chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL; if ((err = load_firmware(chip)) < 0) return err; chip->bad_board = FALSE; DE_INIT(("init_hw done\n")); return err; } static int set_mixer_defaults(struct echoaudio *chip) { return init_line_levels(chip); } static u32 detect_input_clocks(const struct echoaudio *chip) { return ECHO_CLOCK_BIT_INTERNAL; } /* The Indigo has no ASIC. Just do nothing */ static int load_asic(struct echoaudio *chip) { return 0; } static int set_sample_rate(struct echoaudio *chip, u32 rate) { u32 control_reg; switch (rate) { case 96000: control_reg = MIA_96000; break; case 88200: control_reg = MIA_88200; break; case 48000: control_reg = MIA_48000; break; case 44100: control_reg = MIA_44100; break; case 32000: control_reg = MIA_32000; break; default: DE_ACT(("set_sample_rate: %d invalid!\n", rate)); return -EINVAL; } /* Set the control register if it has changed */ if (control_reg != le32_to_cpu(chip->comm_page->control_register)) { if (wait_handshake(chip)) return -EIO; chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */ chip->comm_page->control_register = cpu_to_le32(control_reg); chip->sample_rate = rate; clear_handshake(chip); return send_vector(chip, DSP_VC_UPDATE_CLOCKS); } return 0; } /* This function routes the sound from a virtual channel to a real output */ static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe, int gain) { int index; if (snd_BUG_ON(pipe >= num_pipes_out(chip) || output >= num_busses_out(chip))) return -EINVAL; if (wait_handshake(chip)) return -EIO; chip->vmixer_gain[output][pipe] = gain; index = output * num_pipes_out(chip) + pipe; chip->comm_page->vmixer[index] = gain; DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain)); return 0; } /* Tell the DSP to read and update virtual mixer levels in comm page. */ static int update_vmixer_level(struct echoaudio *chip) { if (wait_handshake(chip)) return -EIO; clear_handshake(chip); return send_vector(chip, DSP_VC_SET_VMIXER_GAIN); }
gpl-2.0
2fast4u88/Htc-Design-FastKernel
arch/ia64/kernel/paravirt_patch.c
12735
12728
/****************************************************************************** * linux/arch/ia64/xen/paravirt_patch.c * * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp> * VA Linux Systems Japan K.K. * * 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 <linux/init.h> #include <asm/intrinsics.h> #include <asm/kprobes.h> #include <asm/paravirt.h> #include <asm/paravirt_patch.h> typedef union ia64_inst { struct { unsigned long long qp : 6; unsigned long long : 31; unsigned long long opcode : 4; unsigned long long reserved : 23; } generic; unsigned long long l; } ia64_inst_t; /* * flush_icache_range() can't be used here. * we are here before cpu_init() which initializes * ia64_i_cache_stride_shift. flush_icache_range() uses it. */ void __init_or_module paravirt_flush_i_cache_range(const void *instr, unsigned long size) { extern void paravirt_fc_i(const void *addr); unsigned long i; for (i = 0; i < size; i += sizeof(bundle_t)) paravirt_fc_i(instr + i); } bundle_t* __init_or_module paravirt_get_bundle(unsigned long tag) { return (bundle_t *)(tag & ~3UL); } unsigned long __init_or_module paravirt_get_slot(unsigned long tag) { return tag & 3UL; } unsigned long __init_or_module paravirt_get_num_inst(unsigned long stag, unsigned long etag) { bundle_t *sbundle = paravirt_get_bundle(stag); unsigned long sslot = paravirt_get_slot(stag); bundle_t *ebundle = paravirt_get_bundle(etag); unsigned long eslot = paravirt_get_slot(etag); return (ebundle - sbundle) * 3 + eslot - sslot + 1; } unsigned long __init_or_module paravirt_get_next_tag(unsigned long tag) { unsigned long slot = paravirt_get_slot(tag); switch (slot) { case 0: case 1: return tag + 1; case 2: { bundle_t *bundle = paravirt_get_bundle(tag); return (unsigned long)(bundle + 1); } default: BUG(); } /* NOTREACHED */ } ia64_inst_t __init_or_module paravirt_read_slot0(const bundle_t *bundle) { ia64_inst_t inst; inst.l = bundle->quad0.slot0; return inst; } ia64_inst_t __init_or_module paravirt_read_slot1(const bundle_t *bundle) { ia64_inst_t inst; inst.l = bundle->quad0.slot1_p0 | ((unsigned long long)bundle->quad1.slot1_p1 << 18UL); return inst; } ia64_inst_t __init_or_module paravirt_read_slot2(const bundle_t *bundle) { ia64_inst_t inst; inst.l = bundle->quad1.slot2; return inst; } ia64_inst_t __init_or_module paravirt_read_inst(unsigned long tag) { bundle_t *bundle = paravirt_get_bundle(tag); unsigned long slot = paravirt_get_slot(tag); switch (slot) { case 0: return paravirt_read_slot0(bundle); case 1: return paravirt_read_slot1(bundle); case 2: return paravirt_read_slot2(bundle); default: BUG(); } /* NOTREACHED */ } void __init_or_module paravirt_write_slot0(bundle_t *bundle, ia64_inst_t inst) { bundle->quad0.slot0 = inst.l; } void __init_or_module paravirt_write_slot1(bundle_t *bundle, ia64_inst_t inst) { bundle->quad0.slot1_p0 = inst.l; bundle->quad1.slot1_p1 = inst.l >> 18UL; } void __init_or_module paravirt_write_slot2(bundle_t *bundle, ia64_inst_t inst) { bundle->quad1.slot2 = inst.l; } void __init_or_module paravirt_write_inst(unsigned long tag, ia64_inst_t inst) { bundle_t *bundle = paravirt_get_bundle(tag); unsigned long slot = paravirt_get_slot(tag); switch (slot) { case 0: paravirt_write_slot0(bundle, inst); break; case 1: paravirt_write_slot1(bundle, inst); break; case 2: paravirt_write_slot2(bundle, inst); break; default: BUG(); break; } paravirt_flush_i_cache_range(bundle, sizeof(*bundle)); } /* for debug */ void paravirt_print_bundle(const bundle_t *bundle) { const unsigned long *quad = (const unsigned long *)bundle; ia64_inst_t slot0 = paravirt_read_slot0(bundle); ia64_inst_t slot1 = paravirt_read_slot1(bundle); ia64_inst_t slot2 = paravirt_read_slot2(bundle); printk(KERN_DEBUG "bundle 0x%p 0x%016lx 0x%016lx\n", bundle, quad[0], quad[1]); printk(KERN_DEBUG "bundle template 0x%x\n", bundle->quad0.template); printk(KERN_DEBUG "slot0 0x%lx slot1_p0 0x%lx slot1_p1 0x%lx slot2 0x%lx\n", (unsigned long)bundle->quad0.slot0, (unsigned long)bundle->quad0.slot1_p0, (unsigned long)bundle->quad1.slot1_p1, (unsigned long)bundle->quad1.slot2); printk(KERN_DEBUG "slot0 0x%016llx slot1 0x%016llx slot2 0x%016llx\n", slot0.l, slot1.l, slot2.l); } static int noreplace_paravirt __init_or_module = 0; static int __init setup_noreplace_paravirt(char *str) { noreplace_paravirt = 1; return 1; } __setup("noreplace-paravirt", setup_noreplace_paravirt); #ifdef ASM_SUPPORTED static void __init_or_module fill_nop_bundle(void *sbundle, void *ebundle) { extern const char paravirt_nop_bundle[]; extern const unsigned long paravirt_nop_bundle_size; void *bundle = sbundle; BUG_ON((((unsigned long)sbundle) % sizeof(bundle_t)) != 0); BUG_ON((((unsigned long)ebundle) % sizeof(bundle_t)) != 0); while (bundle < ebundle) { memcpy(bundle, paravirt_nop_bundle, paravirt_nop_bundle_size); bundle += paravirt_nop_bundle_size; } } /* helper function */ unsigned long __init_or_module __paravirt_patch_apply_bundle(void *sbundle, void *ebundle, unsigned long type, const struct paravirt_patch_bundle_elem *elems, unsigned long nelems, const struct paravirt_patch_bundle_elem **found) { unsigned long used = 0; unsigned long i; BUG_ON((((unsigned long)sbundle) % sizeof(bundle_t)) != 0); BUG_ON((((unsigned long)ebundle) % sizeof(bundle_t)) != 0); found = NULL; for (i = 0; i < nelems; i++) { const struct paravirt_patch_bundle_elem *p = &elems[i]; if (p->type == type) { unsigned long need = p->ebundle - p->sbundle; unsigned long room = ebundle - sbundle; if (found != NULL) *found = p; if (room < need) { /* no room to replace. skip it */ printk(KERN_DEBUG "the space is too small to put " "bundles. type %ld need %ld room %ld\n", type, need, room); break; } used = need; memcpy(sbundle, p->sbundle, used); break; } } return used; } void __init_or_module paravirt_patch_apply_bundle(const struct paravirt_patch_site_bundle *start, const struct paravirt_patch_site_bundle *end) { const struct paravirt_patch_site_bundle *p; if (noreplace_paravirt) return; if (pv_init_ops.patch_bundle == NULL) return; for (p = start; p < end; p++) { unsigned long used; used = (*pv_init_ops.patch_bundle)(p->sbundle, p->ebundle, p->type); if (used == 0) continue; fill_nop_bundle(p->sbundle + used, p->ebundle); paravirt_flush_i_cache_range(p->sbundle, p->ebundle - p->sbundle); } ia64_sync_i(); ia64_srlz_i(); } /* * nop.i, nop.m, nop.f instruction are same format. * but nop.b has differennt format. * This doesn't support nop.b for now. */ static void __init_or_module fill_nop_inst(unsigned long stag, unsigned long etag) { extern const bundle_t paravirt_nop_mfi_inst_bundle[]; unsigned long tag; const ia64_inst_t nop_inst = paravirt_read_slot0(paravirt_nop_mfi_inst_bundle); for (tag = stag; tag < etag; tag = paravirt_get_next_tag(tag)) paravirt_write_inst(tag, nop_inst); } void __init_or_module paravirt_patch_apply_inst(const struct paravirt_patch_site_inst *start, const struct paravirt_patch_site_inst *end) { const struct paravirt_patch_site_inst *p; if (noreplace_paravirt) return; if (pv_init_ops.patch_inst == NULL) return; for (p = start; p < end; p++) { unsigned long tag; bundle_t *sbundle; bundle_t *ebundle; tag = (*pv_init_ops.patch_inst)(p->stag, p->etag, p->type); if (tag == p->stag) continue; fill_nop_inst(tag, p->etag); sbundle = paravirt_get_bundle(p->stag); ebundle = paravirt_get_bundle(p->etag) + 1; paravirt_flush_i_cache_range(sbundle, (ebundle - sbundle) * sizeof(bundle_t)); } ia64_sync_i(); ia64_srlz_i(); } #endif /* ASM_SUPPOTED */ /* brl.cond.sptk.many <target64> X3 */ typedef union inst_x3_op { ia64_inst_t inst; struct { unsigned long qp: 6; unsigned long btyp: 3; unsigned long unused: 3; unsigned long p: 1; unsigned long imm20b: 20; unsigned long wh: 2; unsigned long d: 1; unsigned long i: 1; unsigned long opcode: 4; }; unsigned long l; } inst_x3_op_t; typedef union inst_x3_imm { ia64_inst_t inst; struct { unsigned long unused: 2; unsigned long imm39: 39; }; unsigned long l; } inst_x3_imm_t; void __init_or_module paravirt_patch_reloc_brl(unsigned long tag, const void *target) { unsigned long tag_op = paravirt_get_next_tag(tag); unsigned long tag_imm = tag; bundle_t *bundle = paravirt_get_bundle(tag); ia64_inst_t inst_op = paravirt_read_inst(tag_op); ia64_inst_t inst_imm = paravirt_read_inst(tag_imm); inst_x3_op_t inst_x3_op = { .l = inst_op.l }; inst_x3_imm_t inst_x3_imm = { .l = inst_imm.l }; unsigned long imm60 = ((unsigned long)target - (unsigned long)bundle) >> 4; BUG_ON(paravirt_get_slot(tag) != 1); /* MLX */ BUG_ON(((unsigned long)target & (sizeof(bundle_t) - 1)) != 0); /* imm60[59] 1bit */ inst_x3_op.i = (imm60 >> 59) & 1; /* imm60[19:0] 20bit */ inst_x3_op.imm20b = imm60 & ((1UL << 20) - 1); /* imm60[58:20] 39bit */ inst_x3_imm.imm39 = (imm60 >> 20) & ((1UL << 39) - 1); inst_op.l = inst_x3_op.l; inst_imm.l = inst_x3_imm.l; paravirt_write_inst(tag_op, inst_op); paravirt_write_inst(tag_imm, inst_imm); } /* br.cond.sptk.many <target25> B1 */ typedef union inst_b1 { ia64_inst_t inst; struct { unsigned long qp: 6; unsigned long btype: 3; unsigned long unused: 3; unsigned long p: 1; unsigned long imm20b: 20; unsigned long wh: 2; unsigned long d: 1; unsigned long s: 1; unsigned long opcode: 4; }; unsigned long l; } inst_b1_t; void __init paravirt_patch_reloc_br(unsigned long tag, const void *target) { bundle_t *bundle = paravirt_get_bundle(tag); ia64_inst_t inst = paravirt_read_inst(tag); unsigned long target25 = (unsigned long)target - (unsigned long)bundle; inst_b1_t inst_b1; BUG_ON(((unsigned long)target & (sizeof(bundle_t) - 1)) != 0); inst_b1.l = inst.l; if (target25 & (1UL << 63)) inst_b1.s = 1; else inst_b1.s = 0; inst_b1.imm20b = target25 >> 4; inst.l = inst_b1.l; paravirt_write_inst(tag, inst); } void __init __paravirt_patch_apply_branch( unsigned long tag, unsigned long type, const struct paravirt_patch_branch_target *entries, unsigned int nr_entries) { unsigned int i; for (i = 0; i < nr_entries; i++) { if (entries[i].type == type) { paravirt_patch_reloc_br(tag, entries[i].entry); break; } } } static void __init paravirt_patch_apply_branch(const struct paravirt_patch_site_branch *start, const struct paravirt_patch_site_branch *end) { const struct paravirt_patch_site_branch *p; if (noreplace_paravirt) return; if (pv_init_ops.patch_branch == NULL) return; for (p = start; p < end; p++) (*pv_init_ops.patch_branch)(p->tag, p->type); ia64_sync_i(); ia64_srlz_i(); } void __init paravirt_patch_apply(void) { extern const char __start_paravirt_bundles[]; extern const char __stop_paravirt_bundles[]; extern const char __start_paravirt_insts[]; extern const char __stop_paravirt_insts[]; extern const char __start_paravirt_branches[]; extern const char __stop_paravirt_branches[]; paravirt_patch_apply_bundle((const struct paravirt_patch_site_bundle *) __start_paravirt_bundles, (const struct paravirt_patch_site_bundle *) __stop_paravirt_bundles); paravirt_patch_apply_inst((const struct paravirt_patch_site_inst *) __start_paravirt_insts, (const struct paravirt_patch_site_inst *) __stop_paravirt_insts); paravirt_patch_apply_branch((const struct paravirt_patch_site_branch *) __start_paravirt_branches, (const struct paravirt_patch_site_branch *) __stop_paravirt_branches); } /* * Local variables: * mode: C * c-set-style: "linux" * c-basic-offset: 8 * tab-width: 8 * indent-tabs-mode: t * End: */
gpl-2.0
doungni/linux
sound/pci/hda/patch_hdmi.c
192
103723
/* * * patch_hdmi.c - routines for HDMI/DisplayPort codecs * * Copyright(c) 2008-2010 Intel Corporation. All rights reserved. * Copyright (c) 2006 ATI Technologies Inc. * Copyright (c) 2008 NVIDIA Corp. All rights reserved. * Copyright (c) 2008 Wei Ni <wni@nvidia.com> * Copyright (c) 2013 Anssi Hannula <anssi.hannula@iki.fi> * * Authors: * Wu Fengguang <wfg@linux.intel.com> * * Maintained by: * Wu Fengguang <wfg@linux.intel.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 <linux/init.h> #include <linux/delay.h> #include <linux/slab.h> #include <linux/module.h> #include <sound/core.h> #include <sound/jack.h> #include <sound/asoundef.h> #include <sound/tlv.h> #include <sound/hdaudio.h> #include <sound/hda_i915.h> #include "hda_codec.h" #include "hda_local.h" #include "hda_jack.h" static bool static_hdmi_pcm; module_param(static_hdmi_pcm, bool, 0644); MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info"); #define is_haswell(codec) ((codec)->core.vendor_id == 0x80862807) #define is_broadwell(codec) ((codec)->core.vendor_id == 0x80862808) #define is_skylake(codec) ((codec)->core.vendor_id == 0x80862809) #define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \ || is_skylake(codec)) #define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882) #define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883) #define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec)) struct hdmi_spec_per_cvt { hda_nid_t cvt_nid; int assigned; unsigned int channels_min; unsigned int channels_max; u32 rates; u64 formats; unsigned int maxbps; }; /* max. connections to a widget */ #define HDA_MAX_CONNECTIONS 32 struct hdmi_spec_per_pin { hda_nid_t pin_nid; int num_mux_nids; hda_nid_t mux_nids[HDA_MAX_CONNECTIONS]; int mux_idx; hda_nid_t cvt_nid; struct hda_codec *codec; struct hdmi_eld sink_eld; struct mutex lock; struct delayed_work work; struct snd_kcontrol *eld_ctl; int repoll_count; bool setup; /* the stream has been set up by prepare callback */ int channels; /* current number of channels */ bool non_pcm; bool chmap_set; /* channel-map override by ALSA API? */ unsigned char chmap[8]; /* ALSA API channel-map */ #ifdef CONFIG_SND_PROC_FS struct snd_info_entry *proc_entry; #endif }; struct cea_channel_speaker_allocation; /* operations used by generic code that can be overridden by patches */ struct hdmi_ops { int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid, unsigned char *buf, int *eld_size); /* get and set channel assigned to each HDMI ASP (audio sample packet) slot */ int (*pin_get_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid, int asp_slot); int (*pin_set_slot_channel)(struct hda_codec *codec, hda_nid_t pin_nid, int asp_slot, int channel); void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid, int ca, int active_channels, int conn_type); /* enable/disable HBR (HD passthrough) */ int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr); int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid, hda_nid_t pin_nid, u32 stream_tag, int format); /* Helpers for producing the channel map TLVs. These can be overridden * for devices that have non-standard mapping requirements. */ int (*chmap_cea_alloc_validate_get_type)(struct cea_channel_speaker_allocation *cap, int channels); void (*cea_alloc_to_tlv_chmap)(struct cea_channel_speaker_allocation *cap, unsigned int *chmap, int channels); /* check that the user-given chmap is supported */ int (*chmap_validate)(int ca, int channels, unsigned char *chmap); }; struct hdmi_spec { int num_cvts; struct snd_array cvts; /* struct hdmi_spec_per_cvt */ hda_nid_t cvt_nids[4]; /* only for haswell fix */ int num_pins; struct snd_array pins; /* struct hdmi_spec_per_pin */ struct hda_pcm *pcm_rec[16]; unsigned int channels_max; /* max over all cvts */ struct hdmi_eld temp_eld; struct hdmi_ops ops; bool dyn_pin_out; /* * Non-generic VIA/NVIDIA specific */ struct hda_multi_out multiout; struct hda_pcm_stream pcm_playback; /* i915/powerwell (Haswell+/Valleyview+) specific */ struct i915_audio_component_audio_ops i915_audio_ops; }; struct hdmi_audio_infoframe { u8 type; /* 0x84 */ u8 ver; /* 0x01 */ u8 len; /* 0x0a */ u8 checksum; u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */ u8 SS01_SF24; u8 CXT04; u8 CA; u8 LFEPBL01_LSV36_DM_INH7; }; struct dp_audio_infoframe { u8 type; /* 0x84 */ u8 len; /* 0x1b */ u8 ver; /* 0x11 << 2 */ u8 CC02_CT47; /* match with HDMI infoframe from this on */ u8 SS01_SF24; u8 CXT04; u8 CA; u8 LFEPBL01_LSV36_DM_INH7; }; union audio_infoframe { struct hdmi_audio_infoframe hdmi; struct dp_audio_infoframe dp; u8 bytes[0]; }; /* * CEA speaker placement: * * FLH FCH FRH * FLW FL FLC FC FRC FR FRW * * LFE * TC * * RL RLC RC RRC RR * * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC. */ enum cea_speaker_placement { FL = (1 << 0), /* Front Left */ FC = (1 << 1), /* Front Center */ FR = (1 << 2), /* Front Right */ FLC = (1 << 3), /* Front Left Center */ FRC = (1 << 4), /* Front Right Center */ RL = (1 << 5), /* Rear Left */ RC = (1 << 6), /* Rear Center */ RR = (1 << 7), /* Rear Right */ RLC = (1 << 8), /* Rear Left Center */ RRC = (1 << 9), /* Rear Right Center */ LFE = (1 << 10), /* Low Frequency Effect */ FLW = (1 << 11), /* Front Left Wide */ FRW = (1 << 12), /* Front Right Wide */ FLH = (1 << 13), /* Front Left High */ FCH = (1 << 14), /* Front Center High */ FRH = (1 << 15), /* Front Right High */ TC = (1 << 16), /* Top Center */ }; /* * ELD SA bits in the CEA Speaker Allocation data block */ static int eld_speaker_allocation_bits[] = { [0] = FL | FR, [1] = LFE, [2] = FC, [3] = RL | RR, [4] = RC, [5] = FLC | FRC, [6] = RLC | RRC, /* the following are not defined in ELD yet */ [7] = FLW | FRW, [8] = FLH | FRH, [9] = TC, [10] = FCH, }; struct cea_channel_speaker_allocation { int ca_index; int speakers[8]; /* derived values, just for convenience */ int channels; int spk_mask; }; /* * ALSA sequence is: * * surround40 surround41 surround50 surround51 surround71 * ch0 front left = = = = * ch1 front right = = = = * ch2 rear left = = = = * ch3 rear right = = = = * ch4 LFE center center center * ch5 LFE LFE * ch6 side left * ch7 side right * * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR} */ static int hdmi_channel_mapping[0x32][8] = { /* stereo */ [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }, /* 2.1 */ [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }, /* Dolby Surround */ [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 }, /* surround40 */ [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 }, /* 4ch */ [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 }, /* surround41 */ [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 }, /* surround50 */ [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 }, /* surround51 */ [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 }, /* 7.1 */ [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 }, }; /* * This is an ordered list! * * The preceding ones have better chances to be selected by * hdmi_channel_allocation(). */ static struct cea_channel_speaker_allocation channel_allocations[] = { /* channel: 7 6 5 4 3 2 1 0 */ { .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } }, /* 2.1 */ { .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } }, /* Dolby Surround */ { .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } }, /* surround40 */ { .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } }, /* surround41 */ { .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } }, /* surround50 */ { .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } }, /* surround51 */ { .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } }, /* 6.1 */ { .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } }, /* surround71 */ { .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } }, { .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } }, { .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } }, { .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } }, { .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } }, { .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } }, { .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } }, { .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } }, { .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } }, { .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } }, { .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } }, { .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } }, { .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } }, { .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } }, { .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } }, { .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } }, { .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } }, { .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } }, { .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } }, { .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } }, { .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } }, { .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } }, { .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } }, { .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } }, { .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } }, { .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } }, { .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } }, { .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } }, { .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } }, { .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } }, { .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } }, { .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } }, { .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } }, { .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } }, { .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } }, { .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } }, { .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } }, { .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } }, { .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } }, { .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } }, { .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } }, { .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } }, }; /* * HDMI routines */ #define get_pin(spec, idx) \ ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx)) #define get_cvt(spec, idx) \ ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx)) #define get_pcm_rec(spec, idx) ((spec)->pcm_rec[idx]) static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid) { struct hdmi_spec *spec = codec->spec; int pin_idx; for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) if (get_pin(spec, pin_idx)->pin_nid == pin_nid) return pin_idx; codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid); return -EINVAL; } static int hinfo_to_pin_index(struct hda_codec *codec, struct hda_pcm_stream *hinfo) { struct hdmi_spec *spec = codec->spec; int pin_idx; for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) if (get_pcm_rec(spec, pin_idx)->stream == hinfo) return pin_idx; codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo); return -EINVAL; } static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid) { struct hdmi_spec *spec = codec->spec; int cvt_idx; for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid) return cvt_idx; codec_warn(codec, "HDMI: cvt nid %d not registered\n", cvt_nid); return -EINVAL; } static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct hdmi_spec *spec = codec->spec; struct hdmi_spec_per_pin *per_pin; struct hdmi_eld *eld; int pin_idx; uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; pin_idx = kcontrol->private_value; per_pin = get_pin(spec, pin_idx); eld = &per_pin->sink_eld; mutex_lock(&per_pin->lock); uinfo->count = eld->eld_valid ? eld->eld_size : 0; mutex_unlock(&per_pin->lock); return 0; } static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct hdmi_spec *spec = codec->spec; struct hdmi_spec_per_pin *per_pin; struct hdmi_eld *eld; int pin_idx; pin_idx = kcontrol->private_value; per_pin = get_pin(spec, pin_idx); eld = &per_pin->sink_eld; mutex_lock(&per_pin->lock); if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) { mutex_unlock(&per_pin->lock); snd_BUG(); return -EINVAL; } memset(ucontrol->value.bytes.data, 0, ARRAY_SIZE(ucontrol->value.bytes.data)); if (eld->eld_valid) memcpy(ucontrol->value.bytes.data, eld->eld_buffer, eld->eld_size); mutex_unlock(&per_pin->lock); return 0; } static struct snd_kcontrol_new eld_bytes_ctl = { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "ELD", .info = hdmi_eld_ctl_info, .get = hdmi_eld_ctl_get, }; static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx, int device) { struct snd_kcontrol *kctl; struct hdmi_spec *spec = codec->spec; int err; kctl = snd_ctl_new1(&eld_bytes_ctl, codec); if (!kctl) return -ENOMEM; kctl->private_value = pin_idx; kctl->id.device = device; err = snd_hda_ctl_add(codec, get_pin(spec, pin_idx)->pin_nid, kctl); if (err < 0) return err; get_pin(spec, pin_idx)->eld_ctl = kctl; return 0; } #ifdef BE_PARANOID static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, int *packet_index, int *byte_index) { int val; val = snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_INDEX, 0); *packet_index = val >> 5; *byte_index = val & 0x1f; } #endif static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, int packet_index, int byte_index) { int val; val = (packet_index << 5) | (byte_index & 0x1f); snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val); } static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid, unsigned char val) { snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val); } static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid) { struct hdmi_spec *spec = codec->spec; int pin_out; /* Unmute */ if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP) snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); if (spec->dyn_pin_out) /* Disable pin out until stream is active */ pin_out = 0; else /* Enable pin out: some machines with GM965 gets broken output * when the pin is disabled or changed while using with HDMI */ pin_out = PIN_OUT; snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out); } static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid) { return 1 + snd_hda_codec_read(codec, cvt_nid, 0, AC_VERB_GET_CVT_CHAN_COUNT, 0); } static void hdmi_set_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid, int chs) { if (chs != hdmi_get_channel_count(codec, cvt_nid)) snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_CVT_CHAN_COUNT, chs - 1); } /* * ELD proc files */ #ifdef CONFIG_SND_PROC_FS static void print_eld_info(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct hdmi_spec_per_pin *per_pin = entry->private_data; mutex_lock(&per_pin->lock); snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer); mutex_unlock(&per_pin->lock); } static void write_eld_info(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct hdmi_spec_per_pin *per_pin = entry->private_data; mutex_lock(&per_pin->lock); snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer); mutex_unlock(&per_pin->lock); } static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) { char name[32]; struct hda_codec *codec = per_pin->codec; struct snd_info_entry *entry; int err; snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index); err = snd_card_proc_new(codec->card, name, &entry); if (err < 0) return err; snd_info_set_text_ops(entry, per_pin, print_eld_info); entry->c.text.write = write_eld_info; entry->mode |= S_IWUSR; per_pin->proc_entry = entry; return 0; } static void eld_proc_free(struct hdmi_spec_per_pin *per_pin) { if (!per_pin->codec->bus->shutdown) { snd_info_free_entry(per_pin->proc_entry); per_pin->proc_entry = NULL; } } #else static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) { return 0; } static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin) { } #endif /* * Channel mapping routines */ /* * Compute derived values in channel_allocations[]. */ static void init_channel_allocations(void) { int i, j; struct cea_channel_speaker_allocation *p; for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { p = channel_allocations + i; p->channels = 0; p->spk_mask = 0; for (j = 0; j < ARRAY_SIZE(p->speakers); j++) if (p->speakers[j]) { p->channels++; p->spk_mask |= p->speakers[j]; } } } static int get_channel_allocation_order(int ca) { int i; for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { if (channel_allocations[i].ca_index == ca) break; } return i; } /* * The transformation takes two steps: * * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask * spk_mask => (channel_allocations[]) => ai->CA * * TODO: it could select the wrong CA from multiple candidates. */ static int hdmi_channel_allocation(struct hda_codec *codec, struct hdmi_eld *eld, int channels) { int i; int ca = 0; int spk_mask = 0; char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE]; /* * CA defaults to 0 for basic stereo audio */ if (channels <= 2) return 0; /* * expand ELD's speaker allocation mask * * ELD tells the speaker mask in a compact(paired) form, * expand ELD's notions to match the ones used by Audio InfoFrame. */ for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) { if (eld->info.spk_alloc & (1 << i)) spk_mask |= eld_speaker_allocation_bits[i]; } /* search for the first working match in the CA table */ for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { if (channels == channel_allocations[i].channels && (spk_mask & channel_allocations[i].spk_mask) == channel_allocations[i].spk_mask) { ca = channel_allocations[i].ca_index; break; } } if (!ca) { /* if there was no match, select the regular ALSA channel * allocation with the matching number of channels */ for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { if (channels == channel_allocations[i].channels) { ca = channel_allocations[i].ca_index; break; } } } snd_print_channel_allocation(eld->info.spk_alloc, buf, sizeof(buf)); codec_dbg(codec, "HDMI: select CA 0x%x for %d-channel allocation: %s\n", ca, channels, buf); return ca; } static void hdmi_debug_channel_mapping(struct hda_codec *codec, hda_nid_t pin_nid) { #ifdef CONFIG_SND_DEBUG_VERBOSE struct hdmi_spec *spec = codec->spec; int i; int channel; for (i = 0; i < 8; i++) { channel = spec->ops.pin_get_slot_channel(codec, pin_nid, i); codec_dbg(codec, "HDMI: ASP channel %d => slot %d\n", channel, i); } #endif } static void hdmi_std_setup_channel_mapping(struct hda_codec *codec, hda_nid_t pin_nid, bool non_pcm, int ca) { struct hdmi_spec *spec = codec->spec; struct cea_channel_speaker_allocation *ch_alloc; int i; int err; int order; int non_pcm_mapping[8]; order = get_channel_allocation_order(ca); ch_alloc = &channel_allocations[order]; if (hdmi_channel_mapping[ca][1] == 0) { int hdmi_slot = 0; /* fill actual channel mappings in ALSA channel (i) order */ for (i = 0; i < ch_alloc->channels; i++) { while (!ch_alloc->speakers[7 - hdmi_slot] && !WARN_ON(hdmi_slot >= 8)) hdmi_slot++; /* skip zero slots */ hdmi_channel_mapping[ca][i] = (i << 4) | hdmi_slot++; } /* fill the rest of the slots with ALSA channel 0xf */ for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) if (!ch_alloc->speakers[7 - hdmi_slot]) hdmi_channel_mapping[ca][i++] = (0xf << 4) | hdmi_slot; } if (non_pcm) { for (i = 0; i < ch_alloc->channels; i++) non_pcm_mapping[i] = (i << 4) | i; for (; i < 8; i++) non_pcm_mapping[i] = (0xf << 4) | i; } for (i = 0; i < 8; i++) { int slotsetup = non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i]; int hdmi_slot = slotsetup & 0x0f; int channel = (slotsetup & 0xf0) >> 4; err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot, channel); if (err) { codec_dbg(codec, "HDMI: channel mapping failed\n"); break; } } } struct channel_map_table { unsigned char map; /* ALSA API channel map position */ int spk_mask; /* speaker position bit mask */ }; static struct channel_map_table map_tables[] = { { SNDRV_CHMAP_FL, FL }, { SNDRV_CHMAP_FR, FR }, { SNDRV_CHMAP_RL, RL }, { SNDRV_CHMAP_RR, RR }, { SNDRV_CHMAP_LFE, LFE }, { SNDRV_CHMAP_FC, FC }, { SNDRV_CHMAP_RLC, RLC }, { SNDRV_CHMAP_RRC, RRC }, { SNDRV_CHMAP_RC, RC }, { SNDRV_CHMAP_FLC, FLC }, { SNDRV_CHMAP_FRC, FRC }, { SNDRV_CHMAP_TFL, FLH }, { SNDRV_CHMAP_TFR, FRH }, { SNDRV_CHMAP_FLW, FLW }, { SNDRV_CHMAP_FRW, FRW }, { SNDRV_CHMAP_TC, TC }, { SNDRV_CHMAP_TFC, FCH }, {} /* terminator */ }; /* from ALSA API channel position to speaker bit mask */ static int to_spk_mask(unsigned char c) { struct channel_map_table *t = map_tables; for (; t->map; t++) { if (t->map == c) return t->spk_mask; } return 0; } /* from ALSA API channel position to CEA slot */ static int to_cea_slot(int ordered_ca, unsigned char pos) { int mask = to_spk_mask(pos); int i; if (mask) { for (i = 0; i < 8; i++) { if (channel_allocations[ordered_ca].speakers[7 - i] == mask) return i; } } return -1; } /* from speaker bit mask to ALSA API channel position */ static int spk_to_chmap(int spk) { struct channel_map_table *t = map_tables; for (; t->map; t++) { if (t->spk_mask == spk) return t->map; } return 0; } /* from CEA slot to ALSA API channel position */ static int from_cea_slot(int ordered_ca, unsigned char slot) { int mask = channel_allocations[ordered_ca].speakers[7 - slot]; return spk_to_chmap(mask); } /* get the CA index corresponding to the given ALSA API channel map */ static int hdmi_manual_channel_allocation(int chs, unsigned char *map) { int i, spks = 0, spk_mask = 0; for (i = 0; i < chs; i++) { int mask = to_spk_mask(map[i]); if (mask) { spk_mask |= mask; spks++; } } for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { if ((chs == channel_allocations[i].channels || spks == channel_allocations[i].channels) && (spk_mask & channel_allocations[i].spk_mask) == channel_allocations[i].spk_mask) return channel_allocations[i].ca_index; } return -1; } /* set up the channel slots for the given ALSA API channel map */ static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec, hda_nid_t pin_nid, int chs, unsigned char *map, int ca) { struct hdmi_spec *spec = codec->spec; int ordered_ca = get_channel_allocation_order(ca); int alsa_pos, hdmi_slot; int assignments[8] = {[0 ... 7] = 0xf}; for (alsa_pos = 0; alsa_pos < chs; alsa_pos++) { hdmi_slot = to_cea_slot(ordered_ca, map[alsa_pos]); if (hdmi_slot < 0) continue; /* unassigned channel */ assignments[hdmi_slot] = alsa_pos; } for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) { int err; err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot, assignments[hdmi_slot]); if (err) return -EINVAL; } return 0; } /* store ALSA API channel map from the current default map */ static void hdmi_setup_fake_chmap(unsigned char *map, int ca) { int i; int ordered_ca = get_channel_allocation_order(ca); for (i = 0; i < 8; i++) { if (i < channel_allocations[ordered_ca].channels) map[i] = from_cea_slot(ordered_ca, hdmi_channel_mapping[ca][i] & 0x0f); else map[i] = 0; } } static void hdmi_setup_channel_mapping(struct hda_codec *codec, hda_nid_t pin_nid, bool non_pcm, int ca, int channels, unsigned char *map, bool chmap_set) { if (!non_pcm && chmap_set) { hdmi_manual_setup_channel_mapping(codec, pin_nid, channels, map, ca); } else { hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca); hdmi_setup_fake_chmap(map, ca); } hdmi_debug_channel_mapping(codec, pin_nid); } static int hdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid, int asp_slot, int channel) { return snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_CHAN_SLOT, (channel << 4) | asp_slot); } static int hdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid, int asp_slot) { return (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_CHAN_SLOT, asp_slot) & 0xf0) >> 4; } /* * Audio InfoFrame routines */ /* * Enable Audio InfoFrame Transmission */ static void hdmi_start_infoframe_trans(struct hda_codec *codec, hda_nid_t pin_nid) { hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_BEST); } /* * Disable Audio InfoFrame Transmission */ static void hdmi_stop_infoframe_trans(struct hda_codec *codec, hda_nid_t pin_nid) { hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_DISABLE); } static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid) { #ifdef CONFIG_SND_DEBUG_VERBOSE int i; int size; size = snd_hdmi_get_eld_size(codec, pin_nid); codec_dbg(codec, "HDMI: ELD buf size is %d\n", size); for (i = 0; i < 8; i++) { size = snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_SIZE, i); codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size); } #endif } static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid) { #ifdef BE_PARANOID int i, j; int size; int pi, bi; for (i = 0; i < 8; i++) { size = snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_SIZE, i); if (size == 0) continue; hdmi_set_dip_index(codec, pin_nid, i, 0x0); for (j = 1; j < 1000; j++) { hdmi_write_dip_byte(codec, pin_nid, 0x0); hdmi_get_dip_index(codec, pin_nid, &pi, &bi); if (pi != i) codec_dbg(codec, "dip index %d: %d != %d\n", bi, pi, i); if (bi == 0) /* byte index wrapped around */ break; } codec_dbg(codec, "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n", i, size, j); } #endif } static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai) { u8 *bytes = (u8 *)hdmi_ai; u8 sum = 0; int i; hdmi_ai->checksum = 0; for (i = 0; i < sizeof(*hdmi_ai); i++) sum += bytes[i]; hdmi_ai->checksum = -sum; } static void hdmi_fill_audio_infoframe(struct hda_codec *codec, hda_nid_t pin_nid, u8 *dip, int size) { int i; hdmi_debug_dip_size(codec, pin_nid); hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */ hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); for (i = 0; i < size; i++) hdmi_write_dip_byte(codec, pin_nid, dip[i]); } static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid, u8 *dip, int size) { u8 val; int i; if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0) != AC_DIPXMIT_BEST) return false; hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0); for (i = 0; i < size; i++) { val = snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_DATA, 0); if (val != dip[i]) return false; } return true; } static void hdmi_pin_setup_infoframe(struct hda_codec *codec, hda_nid_t pin_nid, int ca, int active_channels, int conn_type) { union audio_infoframe ai; memset(&ai, 0, sizeof(ai)); if (conn_type == 0) { /* HDMI */ struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi; hdmi_ai->type = 0x84; hdmi_ai->ver = 0x01; hdmi_ai->len = 0x0a; hdmi_ai->CC02_CT47 = active_channels - 1; hdmi_ai->CA = ca; hdmi_checksum_audio_infoframe(hdmi_ai); } else if (conn_type == 1) { /* DisplayPort */ struct dp_audio_infoframe *dp_ai = &ai.dp; dp_ai->type = 0x84; dp_ai->len = 0x1b; dp_ai->ver = 0x11 << 2; dp_ai->CC02_CT47 = active_channels - 1; dp_ai->CA = ca; } else { codec_dbg(codec, "HDMI: unknown connection type at pin %d\n", pin_nid); return; } /* * sizeof(ai) is used instead of sizeof(*hdmi_ai) or * sizeof(*dp_ai) to avoid partial match/update problems when * the user switches between HDMI/DP monitors. */ if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes, sizeof(ai))) { codec_dbg(codec, "hdmi_pin_setup_infoframe: pin=%d channels=%d ca=0x%02x\n", pin_nid, active_channels, ca); hdmi_stop_infoframe_trans(codec, pin_nid); hdmi_fill_audio_infoframe(codec, pin_nid, ai.bytes, sizeof(ai)); hdmi_start_infoframe_trans(codec, pin_nid); } } static void hdmi_setup_audio_infoframe(struct hda_codec *codec, struct hdmi_spec_per_pin *per_pin, bool non_pcm) { struct hdmi_spec *spec = codec->spec; hda_nid_t pin_nid = per_pin->pin_nid; int channels = per_pin->channels; int active_channels; struct hdmi_eld *eld; int ca, ordered_ca; if (!channels) return; if (is_haswell_plus(codec)) snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); eld = &per_pin->sink_eld; if (!non_pcm && per_pin->chmap_set) ca = hdmi_manual_channel_allocation(channels, per_pin->chmap); else ca = hdmi_channel_allocation(codec, eld, channels); if (ca < 0) ca = 0; ordered_ca = get_channel_allocation_order(ca); active_channels = channel_allocations[ordered_ca].channels; hdmi_set_channel_count(codec, per_pin->cvt_nid, active_channels); /* * always configure channel mapping, it may have been changed by the * user in the meantime */ hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca, channels, per_pin->chmap, per_pin->chmap_set); spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels, eld->info.conn_type); per_pin->non_pcm = non_pcm; } /* * Unsolicited events */ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll); static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid) { struct hdmi_spec *spec = codec->spec; int pin_idx = pin_nid_to_pin_index(codec, nid); if (pin_idx < 0) return; if (hdmi_present_sense(get_pin(spec, pin_idx), 1)) snd_hda_jack_report_sync(codec); } static void jack_callback(struct hda_codec *codec, struct hda_jack_callback *jack) { check_presence_and_report(codec, jack->tbl->nid); } static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) { int tag = res >> AC_UNSOL_RES_TAG_SHIFT; struct hda_jack_tbl *jack; int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT; jack = snd_hda_jack_tbl_get_from_tag(codec, tag); if (!jack) return; jack->jack_dirty = 1; codec_dbg(codec, "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n", codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA), !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV)); check_presence_and_report(codec, jack->nid); } static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) { int tag = res >> AC_UNSOL_RES_TAG_SHIFT; int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; int cp_state = !!(res & AC_UNSOL_RES_CP_STATE); int cp_ready = !!(res & AC_UNSOL_RES_CP_READY); codec_info(codec, "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n", codec->addr, tag, subtag, cp_state, cp_ready); /* TODO */ if (cp_state) ; if (cp_ready) ; } static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res) { int tag = res >> AC_UNSOL_RES_TAG_SHIFT; int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) { codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag); return; } if (subtag == 0) hdmi_intrinsic_event(codec, res); else hdmi_non_intrinsic_event(codec, res); } static void haswell_verify_D0(struct hda_codec *codec, hda_nid_t cvt_nid, hda_nid_t nid) { int pwr; /* For Haswell, the converter 1/2 may keep in D3 state after bootup, * thus pins could only choose converter 0 for use. Make sure the * converters are in correct power state */ if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0)) snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0); if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) { snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0); msleep(40); pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0); pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT; codec_dbg(codec, "Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr); } } /* * Callbacks */ /* HBR should be Non-PCM, 8 channels */ #define is_hbr_format(format) \ ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7) static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr) { int pinctl, new_pinctl; if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) { pinctl = snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); if (pinctl < 0) return hbr ? -EINVAL : 0; new_pinctl = pinctl & ~AC_PINCTL_EPT; if (hbr) new_pinctl |= AC_PINCTL_EPT_HBR; else new_pinctl |= AC_PINCTL_EPT_NATIVE; codec_dbg(codec, "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n", pin_nid, pinctl == new_pinctl ? "" : "new-", new_pinctl); if (pinctl != new_pinctl) snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, new_pinctl); } else if (hbr) return -EINVAL; return 0; } static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid, hda_nid_t pin_nid, u32 stream_tag, int format) { struct hdmi_spec *spec = codec->spec; int err; if (is_haswell_plus(codec)) haswell_verify_D0(codec, cvt_nid, pin_nid); err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format)); if (err) { codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n"); return err; } snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format); return 0; } static int hdmi_choose_cvt(struct hda_codec *codec, int pin_idx, int *cvt_id, int *mux_id) { struct hdmi_spec *spec = codec->spec; struct hdmi_spec_per_pin *per_pin; struct hdmi_spec_per_cvt *per_cvt = NULL; int cvt_idx, mux_idx = 0; per_pin = get_pin(spec, pin_idx); /* Dynamically assign converter to stream */ for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { per_cvt = get_cvt(spec, cvt_idx); /* Must not already be assigned */ if (per_cvt->assigned) continue; /* Must be in pin's mux's list of converters */ for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++) if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid) break; /* Not in mux list */ if (mux_idx == per_pin->num_mux_nids) continue; break; } /* No free converters */ if (cvt_idx == spec->num_cvts) return -ENODEV; per_pin->mux_idx = mux_idx; if (cvt_id) *cvt_id = cvt_idx; if (mux_id) *mux_id = mux_idx; return 0; } /* Assure the pin select the right convetor */ static void intel_verify_pin_cvt_connect(struct hda_codec *codec, struct hdmi_spec_per_pin *per_pin) { hda_nid_t pin_nid = per_pin->pin_nid; int mux_idx, curr; mux_idx = per_pin->mux_idx; curr = snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_CONNECT_SEL, 0); if (curr != mux_idx) snd_hda_codec_write_cache(codec, pin_nid, 0, AC_VERB_SET_CONNECT_SEL, mux_idx); } /* Intel HDMI workaround to fix audio routing issue: * For some Intel display codecs, pins share the same connection list. * So a conveter can be selected by multiple pins and playback on any of these * pins will generate sound on the external display, because audio flows from * the same converter to the display pipeline. Also muting one pin may make * other pins have no sound output. * So this function assures that an assigned converter for a pin is not selected * by any other pins. */ static void intel_not_share_assigned_cvt(struct hda_codec *codec, hda_nid_t pin_nid, int mux_idx) { struct hdmi_spec *spec = codec->spec; hda_nid_t nid; int cvt_idx, curr; struct hdmi_spec_per_cvt *per_cvt; /* configure all pins, including "no physical connection" ones */ for_each_hda_codec_node(nid, codec) { unsigned int wid_caps = get_wcaps(codec, nid); unsigned int wid_type = get_wcaps_type(wid_caps); if (wid_type != AC_WID_PIN) continue; if (nid == pin_nid) continue; curr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0); if (curr != mux_idx) continue; /* choose an unassigned converter. The conveters in the * connection list are in the same order as in the codec. */ for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { per_cvt = get_cvt(spec, cvt_idx); if (!per_cvt->assigned) { codec_dbg(codec, "choose cvt %d for pin nid %d\n", cvt_idx, nid); snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, cvt_idx); break; } } } } /* * HDA PCM callbacks */ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct hdmi_spec *spec = codec->spec; struct snd_pcm_runtime *runtime = substream->runtime; int pin_idx, cvt_idx, mux_idx = 0; struct hdmi_spec_per_pin *per_pin; struct hdmi_eld *eld; struct hdmi_spec_per_cvt *per_cvt = NULL; int err; /* Validate hinfo */ pin_idx = hinfo_to_pin_index(codec, hinfo); if (snd_BUG_ON(pin_idx < 0)) return -EINVAL; per_pin = get_pin(spec, pin_idx); eld = &per_pin->sink_eld; err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, &mux_idx); if (err < 0) return err; per_cvt = get_cvt(spec, cvt_idx); /* Claim converter */ per_cvt->assigned = 1; per_pin->cvt_nid = per_cvt->cvt_nid; hinfo->nid = per_cvt->cvt_nid; snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0, AC_VERB_SET_CONNECT_SEL, mux_idx); /* configure unused pins to choose other converters */ if (is_haswell_plus(codec) || is_valleyview_plus(codec)) intel_not_share_assigned_cvt(codec, per_pin->pin_nid, mux_idx); snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid); /* Initially set the converter's capabilities */ hinfo->channels_min = per_cvt->channels_min; hinfo->channels_max = per_cvt->channels_max; hinfo->rates = per_cvt->rates; hinfo->formats = per_cvt->formats; hinfo->maxbps = per_cvt->maxbps; /* Restrict capabilities by ELD if this isn't disabled */ if (!static_hdmi_pcm && eld->eld_valid) { snd_hdmi_eld_update_pcm_info(&eld->info, hinfo); if (hinfo->channels_min > hinfo->channels_max || !hinfo->rates || !hinfo->formats) { per_cvt->assigned = 0; hinfo->nid = 0; snd_hda_spdif_ctls_unassign(codec, pin_idx); return -ENODEV; } } /* Store the updated parameters */ runtime->hw.channels_min = hinfo->channels_min; runtime->hw.channels_max = hinfo->channels_max; runtime->hw.formats = hinfo->formats; runtime->hw.rates = hinfo->rates; snd_pcm_hw_constraint_step(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2); return 0; } /* * HDA/HDMI auto parsing */ static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx) { struct hdmi_spec *spec = codec->spec; struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); hda_nid_t pin_nid = per_pin->pin_nid; if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) { codec_warn(codec, "HDMI: pin %d wcaps %#x does not support connection list\n", pin_nid, get_wcaps(codec, pin_nid)); return -EINVAL; } per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid, per_pin->mux_nids, HDA_MAX_CONNECTIONS); return 0; } static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll) { struct hda_jack_tbl *jack; struct hda_codec *codec = per_pin->codec; struct hdmi_spec *spec = codec->spec; struct hdmi_eld *eld = &spec->temp_eld; struct hdmi_eld *pin_eld = &per_pin->sink_eld; hda_nid_t pin_nid = per_pin->pin_nid; /* * Always execute a GetPinSense verb here, even when called from * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited * response's PD bit is not the real PD value, but indicates that * the real PD value changed. An older version of the HD-audio * specification worked this way. Hence, we just ignore the data in * the unsolicited response to avoid custom WARs. */ int present; bool update_eld = false; bool eld_changed = false; bool ret; snd_hda_power_up_pm(codec); present = snd_hda_pin_sense(codec, pin_nid); mutex_lock(&per_pin->lock); pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); if (pin_eld->monitor_present) eld->eld_valid = !!(present & AC_PINSENSE_ELDV); else eld->eld_valid = false; codec_dbg(codec, "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n", codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid); if (eld->eld_valid) { if (spec->ops.pin_get_eld(codec, pin_nid, eld->eld_buffer, &eld->eld_size) < 0) eld->eld_valid = false; else { memset(&eld->info, 0, sizeof(struct parsed_hdmi_eld)); if (snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer, eld->eld_size) < 0) eld->eld_valid = false; } if (eld->eld_valid) { snd_hdmi_show_eld(codec, &eld->info); update_eld = true; } else if (repoll) { schedule_delayed_work(&per_pin->work, msecs_to_jiffies(300)); goto unlock; } } if (pin_eld->eld_valid != eld->eld_valid) eld_changed = true; if (pin_eld->eld_valid && !eld->eld_valid) update_eld = true; if (update_eld) { bool old_eld_valid = pin_eld->eld_valid; pin_eld->eld_valid = eld->eld_valid; if (pin_eld->eld_size != eld->eld_size || memcmp(pin_eld->eld_buffer, eld->eld_buffer, eld->eld_size) != 0) { memcpy(pin_eld->eld_buffer, eld->eld_buffer, eld->eld_size); eld_changed = true; } pin_eld->eld_size = eld->eld_size; pin_eld->info = eld->info; /* * Re-setup pin and infoframe. This is needed e.g. when * - sink is first plugged-in (infoframe is not set up if !monitor_present) * - transcoder can change during stream playback on Haswell * and this can make HW reset converter selection on a pin. */ if (eld->eld_valid && !old_eld_valid && per_pin->setup) { if (is_haswell_plus(codec) || is_valleyview_plus(codec)) { intel_verify_pin_cvt_connect(codec, per_pin); intel_not_share_assigned_cvt(codec, pin_nid, per_pin->mux_idx); } hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); } } if (eld_changed) snd_ctl_notify(codec->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &per_pin->eld_ctl->id); unlock: ret = !repoll || !pin_eld->monitor_present || pin_eld->eld_valid; jack = snd_hda_jack_tbl_get(codec, pin_nid); if (jack) jack->block_report = !ret; mutex_unlock(&per_pin->lock); snd_hda_power_down_pm(codec); return ret; } static void hdmi_repoll_eld(struct work_struct *work) { struct hdmi_spec_per_pin *per_pin = container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work); if (per_pin->repoll_count++ > 6) per_pin->repoll_count = 0; if (hdmi_present_sense(per_pin, per_pin->repoll_count)) snd_hda_jack_report_sync(per_pin->codec); } static void intel_haswell_fixup_connect_list(struct hda_codec *codec, hda_nid_t nid); static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid) { struct hdmi_spec *spec = codec->spec; unsigned int caps, config; int pin_idx; struct hdmi_spec_per_pin *per_pin; int err; caps = snd_hda_query_pin_caps(codec, pin_nid); if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP))) return 0; config = snd_hda_codec_get_pincfg(codec, pin_nid); if (get_defcfg_connect(config) == AC_JACK_PORT_NONE) return 0; if (is_haswell_plus(codec)) intel_haswell_fixup_connect_list(codec, pin_nid); pin_idx = spec->num_pins; per_pin = snd_array_new(&spec->pins); if (!per_pin) return -ENOMEM; per_pin->pin_nid = pin_nid; per_pin->non_pcm = false; err = hdmi_read_pin_conn(codec, pin_idx); if (err < 0) return err; spec->num_pins++; return 0; } static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) { struct hdmi_spec *spec = codec->spec; struct hdmi_spec_per_cvt *per_cvt; unsigned int chans; int err; chans = get_wcaps(codec, cvt_nid); chans = get_wcaps_channels(chans); per_cvt = snd_array_new(&spec->cvts); if (!per_cvt) return -ENOMEM; per_cvt->cvt_nid = cvt_nid; per_cvt->channels_min = 2; if (chans <= 16) { per_cvt->channels_max = chans; if (chans > spec->channels_max) spec->channels_max = chans; } err = snd_hda_query_supported_pcm(codec, cvt_nid, &per_cvt->rates, &per_cvt->formats, &per_cvt->maxbps); if (err < 0) return err; if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids)) spec->cvt_nids[spec->num_cvts] = cvt_nid; spec->num_cvts++; return 0; } static int hdmi_parse_codec(struct hda_codec *codec) { hda_nid_t nid; int i, nodes; nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid); if (!nid || nodes < 0) { codec_warn(codec, "HDMI: failed to get afg sub nodes\n"); return -EINVAL; } for (i = 0; i < nodes; i++, nid++) { unsigned int caps; unsigned int type; caps = get_wcaps(codec, nid); type = get_wcaps_type(caps); if (!(caps & AC_WCAP_DIGITAL)) continue; switch (type) { case AC_WID_AUD_OUT: hdmi_add_cvt(codec, nid); break; case AC_WID_PIN: hdmi_add_pin(codec, nid); break; } } return 0; } /* */ static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) { struct hda_spdif_out *spdif; bool non_pcm; mutex_lock(&codec->spdif_mutex); spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid); non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO); mutex_unlock(&codec->spdif_mutex); return non_pcm; } /* * HDMI callbacks */ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { hda_nid_t cvt_nid = hinfo->nid; struct hdmi_spec *spec = codec->spec; int pin_idx = hinfo_to_pin_index(codec, hinfo); struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); hda_nid_t pin_nid = per_pin->pin_nid; bool non_pcm; int pinctl; if (is_haswell_plus(codec) || is_valleyview_plus(codec)) { /* Verify pin:cvt selections to avoid silent audio after S3. * After S3, the audio driver restores pin:cvt selections * but this can happen before gfx is ready and such selection * is overlooked by HW. Thus multiple pins can share a same * default convertor and mute control will affect each other, * which can cause a resumed audio playback become silent * after S3. */ intel_verify_pin_cvt_connect(codec, per_pin); intel_not_share_assigned_cvt(codec, pin_nid, per_pin->mux_idx); } non_pcm = check_non_pcm_per_cvt(codec, cvt_nid); mutex_lock(&per_pin->lock); per_pin->channels = substream->runtime->channels; per_pin->setup = true; hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); mutex_unlock(&per_pin->lock); if (spec->dyn_pin_out) { pinctl = snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl | PIN_OUT); } return spec->ops.setup_stream(codec, cvt_nid, pin_nid, stream_tag, format); } static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { snd_hda_codec_cleanup_stream(codec, hinfo->nid); return 0; } static int hdmi_pcm_close(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct hdmi_spec *spec = codec->spec; int cvt_idx, pin_idx; struct hdmi_spec_per_cvt *per_cvt; struct hdmi_spec_per_pin *per_pin; int pinctl; if (hinfo->nid) { cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid); if (snd_BUG_ON(cvt_idx < 0)) return -EINVAL; per_cvt = get_cvt(spec, cvt_idx); snd_BUG_ON(!per_cvt->assigned); per_cvt->assigned = 0; hinfo->nid = 0; pin_idx = hinfo_to_pin_index(codec, hinfo); if (snd_BUG_ON(pin_idx < 0)) return -EINVAL; per_pin = get_pin(spec, pin_idx); if (spec->dyn_pin_out) { pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); snd_hda_codec_write(codec, per_pin->pin_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl & ~PIN_OUT); } snd_hda_spdif_ctls_unassign(codec, pin_idx); mutex_lock(&per_pin->lock); per_pin->chmap_set = false; memset(per_pin->chmap, 0, sizeof(per_pin->chmap)); per_pin->setup = false; per_pin->channels = 0; mutex_unlock(&per_pin->lock); } return 0; } static const struct hda_pcm_ops generic_ops = { .open = hdmi_pcm_open, .close = hdmi_pcm_close, .prepare = generic_hdmi_playback_pcm_prepare, .cleanup = generic_hdmi_playback_pcm_cleanup, }; /* * ALSA API channel-map control callbacks */ static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); struct hda_codec *codec = info->private_data; struct hdmi_spec *spec = codec->spec; uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = spec->channels_max; uinfo->value.integer.min = 0; uinfo->value.integer.max = SNDRV_CHMAP_LAST; return 0; } static int hdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap, int channels) { /* If the speaker allocation matches the channel count, it is OK.*/ if (cap->channels != channels) return -1; /* all channels are remappable freely */ return SNDRV_CTL_TLVT_CHMAP_VAR; } static void hdmi_cea_alloc_to_tlv_chmap(struct cea_channel_speaker_allocation *cap, unsigned int *chmap, int channels) { int count = 0; int c; for (c = 7; c >= 0; c--) { int spk = cap->speakers[c]; if (!spk) continue; chmap[count++] = spk_to_chmap(spk); } WARN_ON(count != channels); } static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag, unsigned int size, unsigned int __user *tlv) { struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); struct hda_codec *codec = info->private_data; struct hdmi_spec *spec = codec->spec; unsigned int __user *dst; int chs, count = 0; if (size < 8) return -ENOMEM; if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv)) return -EFAULT; size -= 8; dst = tlv + 2; for (chs = 2; chs <= spec->channels_max; chs++) { int i; struct cea_channel_speaker_allocation *cap; cap = channel_allocations; for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) { int chs_bytes = chs * 4; int type = spec->ops.chmap_cea_alloc_validate_get_type(cap, chs); unsigned int tlv_chmap[8]; if (type < 0) continue; if (size < 8) return -ENOMEM; if (put_user(type, dst) || put_user(chs_bytes, dst + 1)) return -EFAULT; dst += 2; size -= 8; count += 8; if (size < chs_bytes) return -ENOMEM; size -= chs_bytes; count += chs_bytes; spec->ops.cea_alloc_to_tlv_chmap(cap, tlv_chmap, chs); if (copy_to_user(dst, tlv_chmap, chs_bytes)) return -EFAULT; dst += chs; } } if (put_user(count, tlv + 1)) return -EFAULT; return 0; } static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); struct hda_codec *codec = info->private_data; struct hdmi_spec *spec = codec->spec; int pin_idx = kcontrol->private_value; struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); int i; for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++) ucontrol->value.integer.value[i] = per_pin->chmap[i]; return 0; } static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); struct hda_codec *codec = info->private_data; struct hdmi_spec *spec = codec->spec; int pin_idx = kcontrol->private_value; struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); unsigned int ctl_idx; struct snd_pcm_substream *substream; unsigned char chmap[8]; int i, err, ca, prepared = 0; ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); substream = snd_pcm_chmap_substream(info, ctl_idx); if (!substream || !substream->runtime) return 0; /* just for avoiding error from alsactl restore */ switch (substream->runtime->status->state) { case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_SETUP: break; case SNDRV_PCM_STATE_PREPARED: prepared = 1; break; default: return -EBUSY; } memset(chmap, 0, sizeof(chmap)); for (i = 0; i < ARRAY_SIZE(chmap); i++) chmap[i] = ucontrol->value.integer.value[i]; if (!memcmp(chmap, per_pin->chmap, sizeof(chmap))) return 0; ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap); if (ca < 0) return -EINVAL; if (spec->ops.chmap_validate) { err = spec->ops.chmap_validate(ca, ARRAY_SIZE(chmap), chmap); if (err) return err; } mutex_lock(&per_pin->lock); per_pin->chmap_set = true; memcpy(per_pin->chmap, chmap, sizeof(chmap)); if (prepared) hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); mutex_unlock(&per_pin->lock); return 0; } static int generic_hdmi_build_pcms(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; int pin_idx; for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hda_pcm *info; struct hda_pcm_stream *pstr; info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx); if (!info) return -ENOMEM; spec->pcm_rec[pin_idx] = info; info->pcm_type = HDA_PCM_TYPE_HDMI; info->own_chmap = true; pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; pstr->substreams = 1; pstr->ops = generic_ops; /* other pstr fields are set in open */ } return 0; } static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx) { char hdmi_str[32] = "HDMI/DP"; struct hdmi_spec *spec = codec->spec; struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); int pcmdev = get_pcm_rec(spec, pin_idx)->device; if (pcmdev > 0) sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev); if (!is_jack_detectable(codec, per_pin->pin_nid)) strncat(hdmi_str, " Phantom", sizeof(hdmi_str) - strlen(hdmi_str) - 1); return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str); } static int generic_hdmi_build_controls(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; int err; int pin_idx; for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); err = generic_hdmi_build_jack(codec, pin_idx); if (err < 0) return err; err = snd_hda_create_dig_out_ctls(codec, per_pin->pin_nid, per_pin->mux_nids[0], HDA_PCM_TYPE_HDMI); if (err < 0) return err; snd_hda_spdif_ctls_unassign(codec, pin_idx); /* add control for ELD Bytes */ err = hdmi_create_eld_ctl(codec, pin_idx, get_pcm_rec(spec, pin_idx)->device); if (err < 0) return err; hdmi_present_sense(per_pin, 0); } /* add channel maps */ for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hda_pcm *pcm; struct snd_pcm_chmap *chmap; struct snd_kcontrol *kctl; int i; pcm = spec->pcm_rec[pin_idx]; if (!pcm || !pcm->pcm) break; err = snd_pcm_add_chmap_ctls(pcm->pcm, SNDRV_PCM_STREAM_PLAYBACK, NULL, 0, pin_idx, &chmap); if (err < 0) return err; /* override handlers */ chmap->private_data = codec; kctl = chmap->kctl; for (i = 0; i < kctl->count; i++) kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE; kctl->info = hdmi_chmap_ctl_info; kctl->get = hdmi_chmap_ctl_get; kctl->put = hdmi_chmap_ctl_put; kctl->tlv.c = hdmi_chmap_ctl_tlv; } return 0; } static int generic_hdmi_init_per_pins(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; int pin_idx; for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); per_pin->codec = codec; mutex_init(&per_pin->lock); INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld); eld_proc_new(per_pin, pin_idx); } return 0; } static int generic_hdmi_init(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; int pin_idx; for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); hda_nid_t pin_nid = per_pin->pin_nid; hdmi_init_pin(codec, pin_nid); snd_hda_jack_detect_enable_callback(codec, pin_nid, codec->jackpoll_interval > 0 ? jack_callback : NULL); } return 0; } static void hdmi_array_init(struct hdmi_spec *spec, int nums) { snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums); snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums); } static void hdmi_array_free(struct hdmi_spec *spec) { snd_array_free(&spec->pins); snd_array_free(&spec->cvts); } static void generic_hdmi_free(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; int pin_idx; if (is_haswell_plus(codec) || is_valleyview_plus(codec)) snd_hdac_i915_register_notifier(NULL); for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); cancel_delayed_work_sync(&per_pin->work); eld_proc_free(per_pin); } hdmi_array_free(spec); kfree(spec); } #ifdef CONFIG_PM static int generic_hdmi_resume(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; int pin_idx; codec->patch_ops.init(codec); regcache_sync(codec->core.regmap); for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); hdmi_present_sense(per_pin, 1); } return 0; } #endif static const struct hda_codec_ops generic_hdmi_patch_ops = { .init = generic_hdmi_init, .free = generic_hdmi_free, .build_pcms = generic_hdmi_build_pcms, .build_controls = generic_hdmi_build_controls, .unsol_event = hdmi_unsol_event, #ifdef CONFIG_PM .resume = generic_hdmi_resume, #endif }; static const struct hdmi_ops generic_standard_hdmi_ops = { .pin_get_eld = snd_hdmi_get_eld, .pin_get_slot_channel = hdmi_pin_get_slot_channel, .pin_set_slot_channel = hdmi_pin_set_slot_channel, .pin_setup_infoframe = hdmi_pin_setup_infoframe, .pin_hbr_setup = hdmi_pin_hbr_setup, .setup_stream = hdmi_setup_stream, .chmap_cea_alloc_validate_get_type = hdmi_chmap_cea_alloc_validate_get_type, .cea_alloc_to_tlv_chmap = hdmi_cea_alloc_to_tlv_chmap, }; static void intel_haswell_fixup_connect_list(struct hda_codec *codec, hda_nid_t nid) { struct hdmi_spec *spec = codec->spec; hda_nid_t conns[4]; int nconns; nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns)); if (nconns == spec->num_cvts && !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t))) return; /* override pins connection list */ codec_dbg(codec, "hdmi: haswell: override pin connection 0x%x\n", nid); snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids); } #define INTEL_VENDOR_NID 0x08 #define INTEL_GET_VENDOR_VERB 0xf81 #define INTEL_SET_VENDOR_VERB 0x781 #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */ #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */ static void intel_haswell_enable_all_pins(struct hda_codec *codec, bool update_tree) { unsigned int vendor_param; vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0, INTEL_GET_VENDOR_VERB, 0); if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS) return; vendor_param |= INTEL_EN_ALL_PIN_CVTS; vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0, INTEL_SET_VENDOR_VERB, vendor_param); if (vendor_param == -1) return; if (update_tree) snd_hda_codec_update_widgets(codec); } static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec) { unsigned int vendor_param; vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0, INTEL_GET_VENDOR_VERB, 0); if (vendor_param == -1 || vendor_param & INTEL_EN_DP12) return; /* enable DP1.2 mode */ vendor_param |= INTEL_EN_DP12; snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB); snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0, INTEL_SET_VENDOR_VERB, vendor_param); } /* Haswell needs to re-issue the vendor-specific verbs before turning to D0. * Otherwise you may get severe h/w communication errors. */ static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg, unsigned int power_state) { if (power_state == AC_PWRST_D0) { intel_haswell_enable_all_pins(codec, false); intel_haswell_fixup_enable_dp12(codec); } snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state); snd_hda_codec_set_power_to_all(codec, fg, power_state); } static void intel_pin_eld_notify(void *audio_ptr, int port) { struct hda_codec *codec = audio_ptr; int pin_nid = port + 0x04; check_presence_and_report(codec, pin_nid); } static int patch_generic_hdmi(struct hda_codec *codec) { struct hdmi_spec *spec; spec = kzalloc(sizeof(*spec), GFP_KERNEL); if (spec == NULL) return -ENOMEM; spec->ops = generic_standard_hdmi_ops; codec->spec = spec; hdmi_array_init(spec, 4); if (is_haswell_plus(codec)) { intel_haswell_enable_all_pins(codec, true); intel_haswell_fixup_enable_dp12(codec); } /* For Valleyview/Cherryview, only the display codec is in the display * power well and can use link_power ops to request/release the power. * For Haswell/Broadwell, the controller is also in the power well and * can cover the codec power request, and so need not set this flag. * For previous platforms, there is no such power well feature. */ if (is_valleyview_plus(codec) || is_skylake(codec)) codec->core.link_power_control = 1; if (is_haswell_plus(codec) || is_valleyview_plus(codec)) { codec->depop_delay = 0; spec->i915_audio_ops.audio_ptr = codec; spec->i915_audio_ops.pin_eld_notify = intel_pin_eld_notify; snd_hdac_i915_register_notifier(&spec->i915_audio_ops); } if (hdmi_parse_codec(codec) < 0) { codec->spec = NULL; kfree(spec); return -EINVAL; } codec->patch_ops = generic_hdmi_patch_ops; if (is_haswell_plus(codec)) { codec->patch_ops.set_power_state = haswell_set_power_state; codec->dp_mst = true; } /* Enable runtime pm for HDMI audio codec of HSW/BDW/SKL/BYT/BSW */ if (is_haswell_plus(codec) || is_valleyview_plus(codec)) codec->auto_runtime_pm = 1; generic_hdmi_init_per_pins(codec); init_channel_allocations(); return 0; } /* * Shared non-generic implementations */ static int simple_playback_build_pcms(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; struct hda_pcm *info; unsigned int chans; struct hda_pcm_stream *pstr; struct hdmi_spec_per_cvt *per_cvt; per_cvt = get_cvt(spec, 0); chans = get_wcaps(codec, per_cvt->cvt_nid); chans = get_wcaps_channels(chans); info = snd_hda_codec_pcm_new(codec, "HDMI 0"); if (!info) return -ENOMEM; spec->pcm_rec[0] = info; info->pcm_type = HDA_PCM_TYPE_HDMI; pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; *pstr = spec->pcm_playback; pstr->nid = per_cvt->cvt_nid; if (pstr->channels_max <= 2 && chans && chans <= 16) pstr->channels_max = chans; return 0; } /* unsolicited event for jack sensing */ static void simple_hdmi_unsol_event(struct hda_codec *codec, unsigned int res) { snd_hda_jack_set_dirty_all(codec); snd_hda_jack_report_sync(codec); } /* generic_hdmi_build_jack can be used for simple_hdmi, too, * as long as spec->pins[] is set correctly */ #define simple_hdmi_build_jack generic_hdmi_build_jack static int simple_playback_build_controls(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; struct hdmi_spec_per_cvt *per_cvt; int err; per_cvt = get_cvt(spec, 0); err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid, per_cvt->cvt_nid, HDA_PCM_TYPE_HDMI); if (err < 0) return err; return simple_hdmi_build_jack(codec, 0); } static int simple_playback_init(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0); hda_nid_t pin = per_pin->pin_nid; snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); /* some codecs require to unmute the pin */ if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); snd_hda_jack_detect_enable(codec, pin); return 0; } static void simple_playback_free(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; hdmi_array_free(spec); kfree(spec); } /* * Nvidia specific implementations */ #define Nv_VERB_SET_Channel_Allocation 0xF79 #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A #define Nv_VERB_SET_Audio_Protection_On 0xF98 #define Nv_VERB_SET_Audio_Protection_Off 0xF99 #define nvhdmi_master_con_nid_7x 0x04 #define nvhdmi_master_pin_nid_7x 0x05 static const hda_nid_t nvhdmi_con_nids_7x[4] = { /*front, rear, clfe, rear_surr */ 0x6, 0x8, 0xa, 0xc, }; static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = { /* set audio protect on */ { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1}, /* enable digital output on pin widget */ { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, {} /* terminator */ }; static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = { /* set audio protect on */ { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1}, /* enable digital output on pin widget */ { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 }, {} /* terminator */ }; #ifdef LIMITED_RATE_FMT_SUPPORT /* support only the safe format and rate */ #define SUPPORTED_RATES SNDRV_PCM_RATE_48000 #define SUPPORTED_MAXBPS 16 #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE #else /* support all rates and formats */ #define SUPPORTED_RATES \ (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\ SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\ SNDRV_PCM_RATE_192000) #define SUPPORTED_MAXBPS 24 #define SUPPORTED_FORMATS \ (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE) #endif static int nvhdmi_7x_init_2ch(struct hda_codec *codec) { snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch); return 0; } static int nvhdmi_7x_init_8ch(struct hda_codec *codec) { snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch); return 0; } static unsigned int channels_2_6_8[] = { 2, 6, 8 }; static unsigned int channels_2_8[] = { 2, 8 }; static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = { .count = ARRAY_SIZE(channels_2_6_8), .list = channels_2_6_8, .mask = 0, }; static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = { .count = ARRAY_SIZE(channels_2_8), .list = channels_2_8, .mask = 0, }; static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct hdmi_spec *spec = codec->spec; struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL; switch (codec->preset->id) { case 0x10de0002: case 0x10de0003: case 0x10de0005: case 0x10de0006: hw_constraints_channels = &hw_constraints_2_8_channels; break; case 0x10de0007: hw_constraints_channels = &hw_constraints_2_6_8_channels; break; default: break; } if (hw_constraints_channels != NULL) { snd_pcm_hw_constraint_list(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, hw_constraints_channels); } else { snd_pcm_hw_constraint_step(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2); } return snd_hda_multi_out_dig_open(codec, &spec->multiout); } static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct hdmi_spec *spec = codec->spec; return snd_hda_multi_out_dig_close(codec, &spec->multiout); } static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { struct hdmi_spec *spec = codec->spec; return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, format, substream); } static const struct hda_pcm_stream simple_pcm_playback = { .substreams = 1, .channels_min = 2, .channels_max = 2, .ops = { .open = simple_playback_pcm_open, .close = simple_playback_pcm_close, .prepare = simple_playback_pcm_prepare }, }; static const struct hda_codec_ops simple_hdmi_patch_ops = { .build_controls = simple_playback_build_controls, .build_pcms = simple_playback_build_pcms, .init = simple_playback_init, .free = simple_playback_free, .unsol_event = simple_hdmi_unsol_event, }; static int patch_simple_hdmi(struct hda_codec *codec, hda_nid_t cvt_nid, hda_nid_t pin_nid) { struct hdmi_spec *spec; struct hdmi_spec_per_cvt *per_cvt; struct hdmi_spec_per_pin *per_pin; spec = kzalloc(sizeof(*spec), GFP_KERNEL); if (!spec) return -ENOMEM; codec->spec = spec; hdmi_array_init(spec, 1); spec->multiout.num_dacs = 0; /* no analog */ spec->multiout.max_channels = 2; spec->multiout.dig_out_nid = cvt_nid; spec->num_cvts = 1; spec->num_pins = 1; per_pin = snd_array_new(&spec->pins); per_cvt = snd_array_new(&spec->cvts); if (!per_pin || !per_cvt) { simple_playback_free(codec); return -ENOMEM; } per_cvt->cvt_nid = cvt_nid; per_pin->pin_nid = pin_nid; spec->pcm_playback = simple_pcm_playback; codec->patch_ops = simple_hdmi_patch_ops; return 0; } static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec, int channels) { unsigned int chanmask; int chan = channels ? (channels - 1) : 1; switch (channels) { default: case 0: case 2: chanmask = 0x00; break; case 4: chanmask = 0x08; break; case 6: chanmask = 0x0b; break; case 8: chanmask = 0x13; break; } /* Set the audio infoframe channel allocation and checksum fields. The * channel count is computed implicitly by the hardware. */ snd_hda_codec_write(codec, 0x1, 0, Nv_VERB_SET_Channel_Allocation, chanmask); snd_hda_codec_write(codec, 0x1, 0, Nv_VERB_SET_Info_Frame_Checksum, (0x71 - chan - chanmask)); } static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct hdmi_spec *spec = codec->spec; int i; snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); for (i = 0; i < 4; i++) { /* set the stream id */ snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0, AC_VERB_SET_CHANNEL_STREAMID, 0); /* set the stream format */ snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0, AC_VERB_SET_STREAM_FORMAT, 0); } /* The audio hardware sends a channel count of 0x7 (8ch) when all the * streams are disabled. */ nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8); return snd_hda_multi_out_dig_close(codec, &spec->multiout); } static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { int chs; unsigned int dataDCC2, channel_id; int i; struct hdmi_spec *spec = codec->spec; struct hda_spdif_out *spdif; struct hdmi_spec_per_cvt *per_cvt; mutex_lock(&codec->spdif_mutex); per_cvt = get_cvt(spec, 0); spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid); chs = substream->runtime->channels; dataDCC2 = 0x2; /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */ if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0, AC_VERB_SET_DIGI_CONVERT_1, spdif->ctls & ~AC_DIG1_ENABLE & 0xff); /* set the stream id */ snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0, AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0); /* set the stream format */ snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0, AC_VERB_SET_STREAM_FORMAT, format); /* turn on again (if needed) */ /* enable and set the channel status audio/data flag */ if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) { snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0, AC_VERB_SET_DIGI_CONVERT_1, spdif->ctls & 0xff); snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0, AC_VERB_SET_DIGI_CONVERT_2, dataDCC2); } for (i = 0; i < 4; i++) { if (chs == 2) channel_id = 0; else channel_id = i * 2; /* turn off SPDIF once; *otherwise the IEC958 bits won't be updated */ if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0, AC_VERB_SET_DIGI_CONVERT_1, spdif->ctls & ~AC_DIG1_ENABLE & 0xff); /* set the stream id */ snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0, AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | channel_id); /* set the stream format */ snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0, AC_VERB_SET_STREAM_FORMAT, format); /* turn on again (if needed) */ /* enable and set the channel status audio/data flag */ if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) { snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0, AC_VERB_SET_DIGI_CONVERT_1, spdif->ctls & 0xff); snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0, AC_VERB_SET_DIGI_CONVERT_2, dataDCC2); } } nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs); mutex_unlock(&codec->spdif_mutex); return 0; } static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = { .substreams = 1, .channels_min = 2, .channels_max = 8, .nid = nvhdmi_master_con_nid_7x, .rates = SUPPORTED_RATES, .maxbps = SUPPORTED_MAXBPS, .formats = SUPPORTED_FORMATS, .ops = { .open = simple_playback_pcm_open, .close = nvhdmi_8ch_7x_pcm_close, .prepare = nvhdmi_8ch_7x_pcm_prepare }, }; static int patch_nvhdmi_2ch(struct hda_codec *codec) { struct hdmi_spec *spec; int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x, nvhdmi_master_pin_nid_7x); if (err < 0) return err; codec->patch_ops.init = nvhdmi_7x_init_2ch; /* override the PCM rates, etc, as the codec doesn't give full list */ spec = codec->spec; spec->pcm_playback.rates = SUPPORTED_RATES; spec->pcm_playback.maxbps = SUPPORTED_MAXBPS; spec->pcm_playback.formats = SUPPORTED_FORMATS; return 0; } static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; int err = simple_playback_build_pcms(codec); if (!err) { struct hda_pcm *info = get_pcm_rec(spec, 0); info->own_chmap = true; } return err; } static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; struct hda_pcm *info; struct snd_pcm_chmap *chmap; int err; err = simple_playback_build_controls(codec); if (err < 0) return err; /* add channel maps */ info = get_pcm_rec(spec, 0); err = snd_pcm_add_chmap_ctls(info->pcm, SNDRV_PCM_STREAM_PLAYBACK, snd_pcm_alt_chmaps, 8, 0, &chmap); if (err < 0) return err; switch (codec->preset->id) { case 0x10de0002: case 0x10de0003: case 0x10de0005: case 0x10de0006: chmap->channel_mask = (1U << 2) | (1U << 8); break; case 0x10de0007: chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8); } return 0; } static int patch_nvhdmi_8ch_7x(struct hda_codec *codec) { struct hdmi_spec *spec; int err = patch_nvhdmi_2ch(codec); if (err < 0) return err; spec = codec->spec; spec->multiout.max_channels = 8; spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x; codec->patch_ops.init = nvhdmi_7x_init_8ch; codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms; codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls; /* Initialize the audio infoframe channel mask and checksum to something * valid */ nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8); return 0; } /* * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on: * - 0x10de0015 * - 0x10de0040 */ static int nvhdmi_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap, int channels) { if (cap->ca_index == 0x00 && channels == 2) return SNDRV_CTL_TLVT_CHMAP_FIXED; return hdmi_chmap_cea_alloc_validate_get_type(cap, channels); } static int nvhdmi_chmap_validate(int ca, int chs, unsigned char *map) { if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR)) return -EINVAL; return 0; } static int patch_nvhdmi(struct hda_codec *codec) { struct hdmi_spec *spec; int err; err = patch_generic_hdmi(codec); if (err) return err; spec = codec->spec; spec->dyn_pin_out = true; spec->ops.chmap_cea_alloc_validate_get_type = nvhdmi_chmap_cea_alloc_validate_get_type; spec->ops.chmap_validate = nvhdmi_chmap_validate; return 0; } /* * The HDA codec on NVIDIA Tegra contains two scratch registers that are * accessed using vendor-defined verbs. These registers can be used for * interoperability between the HDA and HDMI drivers. */ /* Audio Function Group node */ #define NVIDIA_AFG_NID 0x01 /* * The SCRATCH0 register is used to notify the HDMI codec of changes in audio * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to * be raised in the HDMI codec. The remainder of the bits is arbitrary. This * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an * additional bit (at position 30) to signal the validity of the format. * * | 31 | 30 | 29 16 | 15 0 | * +---------+-------+--------+--------+ * | TRIGGER | VALID | UNUSED | FORMAT | * +-----------------------------------| * * Note that for the trigger bit to take effect it needs to change value * (i.e. it needs to be toggled). */ #define NVIDIA_GET_SCRATCH0 0xfa6 #define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7 #define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8 #define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9 #define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa #define NVIDIA_SCRATCH_TRIGGER (1 << 7) #define NVIDIA_SCRATCH_VALID (1 << 6) #define NVIDIA_GET_SCRATCH1 0xfab #define NVIDIA_SET_SCRATCH1_BYTE0 0xfac #define NVIDIA_SET_SCRATCH1_BYTE1 0xfad #define NVIDIA_SET_SCRATCH1_BYTE2 0xfae #define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf /* * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0, * the format is invalidated so that the HDMI codec can be disabled. */ static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format) { unsigned int value; /* bits [31:30] contain the trigger and valid bits */ value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0, NVIDIA_GET_SCRATCH0, 0); value = (value >> 24) & 0xff; /* bits [15:0] are used to store the HDA format */ snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, NVIDIA_SET_SCRATCH0_BYTE0, (format >> 0) & 0xff); snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, NVIDIA_SET_SCRATCH0_BYTE1, (format >> 8) & 0xff); /* bits [16:24] are unused */ snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, NVIDIA_SET_SCRATCH0_BYTE2, 0); /* * Bit 30 signals that the data is valid and hence that HDMI audio can * be enabled. */ if (format == 0) value &= ~NVIDIA_SCRATCH_VALID; else value |= NVIDIA_SCRATCH_VALID; /* * Whenever the trigger bit is toggled, an interrupt is raised in the * HDMI codec. The HDMI driver will use that as trigger to update its * configuration. */ value ^= NVIDIA_SCRATCH_TRIGGER; snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0, NVIDIA_SET_SCRATCH0_BYTE3, value); } static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream) { int err; err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag, format, substream); if (err < 0) return err; /* notify the HDMI codec of the format change */ tegra_hdmi_set_format(codec, format); return 0; } static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { /* invalidate the format in the HDMI codec */ tegra_hdmi_set_format(codec, 0); return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream); } static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type) { struct hdmi_spec *spec = codec->spec; unsigned int i; for (i = 0; i < spec->num_pins; i++) { struct hda_pcm *pcm = get_pcm_rec(spec, i); if (pcm->pcm_type == type) return pcm; } return NULL; } static int tegra_hdmi_build_pcms(struct hda_codec *codec) { struct hda_pcm_stream *stream; struct hda_pcm *pcm; int err; err = generic_hdmi_build_pcms(codec); if (err < 0) return err; pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI); if (!pcm) return -ENODEV; /* * Override ->prepare() and ->cleanup() operations to notify the HDMI * codec about format changes. */ stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK]; stream->ops.prepare = tegra_hdmi_pcm_prepare; stream->ops.cleanup = tegra_hdmi_pcm_cleanup; return 0; } static int patch_tegra_hdmi(struct hda_codec *codec) { int err; err = patch_generic_hdmi(codec); if (err) return err; codec->patch_ops.build_pcms = tegra_hdmi_build_pcms; return 0; } /* * ATI/AMD-specific implementations */ #define is_amdhdmi_rev3_or_later(codec) \ ((codec)->core.vendor_id == 0x1002aa01 && \ ((codec)->core.revision_id & 0xff00) >= 0x0300) #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec) /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */ #define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771 #define ATI_VERB_SET_DOWNMIX_INFO 0x772 #define ATI_VERB_SET_MULTICHANNEL_01 0x777 #define ATI_VERB_SET_MULTICHANNEL_23 0x778 #define ATI_VERB_SET_MULTICHANNEL_45 0x779 #define ATI_VERB_SET_MULTICHANNEL_67 0x77a #define ATI_VERB_SET_HBR_CONTROL 0x77c #define ATI_VERB_SET_MULTICHANNEL_1 0x785 #define ATI_VERB_SET_MULTICHANNEL_3 0x786 #define ATI_VERB_SET_MULTICHANNEL_5 0x787 #define ATI_VERB_SET_MULTICHANNEL_7 0x788 #define ATI_VERB_SET_MULTICHANNEL_MODE 0x789 #define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71 #define ATI_VERB_GET_DOWNMIX_INFO 0xf72 #define ATI_VERB_GET_MULTICHANNEL_01 0xf77 #define ATI_VERB_GET_MULTICHANNEL_23 0xf78 #define ATI_VERB_GET_MULTICHANNEL_45 0xf79 #define ATI_VERB_GET_MULTICHANNEL_67 0xf7a #define ATI_VERB_GET_HBR_CONTROL 0xf7c #define ATI_VERB_GET_MULTICHANNEL_1 0xf85 #define ATI_VERB_GET_MULTICHANNEL_3 0xf86 #define ATI_VERB_GET_MULTICHANNEL_5 0xf87 #define ATI_VERB_GET_MULTICHANNEL_7 0xf88 #define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89 /* AMD specific HDA cvt verbs */ #define ATI_VERB_SET_RAMP_RATE 0x770 #define ATI_VERB_GET_RAMP_RATE 0xf70 #define ATI_OUT_ENABLE 0x1 #define ATI_MULTICHANNEL_MODE_PAIRED 0 #define ATI_MULTICHANNEL_MODE_SINGLE 1 #define ATI_HBR_CAPABLE 0x01 #define ATI_HBR_ENABLE 0x10 static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid, unsigned char *buf, int *eld_size) { /* call hda_eld.c ATI/AMD-specific function */ return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size, is_amdhdmi_rev3_or_later(codec)); } static void atihdmi_pin_setup_infoframe(struct hda_codec *codec, hda_nid_t pin_nid, int ca, int active_channels, int conn_type) { snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca); } static int atihdmi_paired_swap_fc_lfe(int pos) { /* * ATI/AMD have automatic FC/LFE swap built-in * when in pairwise mapping mode. */ switch (pos) { /* see channel_allocations[].speakers[] */ case 2: return 3; case 3: return 2; default: break; } return pos; } static int atihdmi_paired_chmap_validate(int ca, int chs, unsigned char *map) { struct cea_channel_speaker_allocation *cap; int i, j; /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */ cap = &channel_allocations[get_channel_allocation_order(ca)]; for (i = 0; i < chs; ++i) { int mask = to_spk_mask(map[i]); bool ok = false; bool companion_ok = false; if (!mask) continue; for (j = 0 + i % 2; j < 8; j += 2) { int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j); if (cap->speakers[chan_idx] == mask) { /* channel is in a supported position */ ok = true; if (i % 2 == 0 && i + 1 < chs) { /* even channel, check the odd companion */ int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1); int comp_mask_req = to_spk_mask(map[i+1]); int comp_mask_act = cap->speakers[comp_chan_idx]; if (comp_mask_req == comp_mask_act) companion_ok = true; else return -EINVAL; } break; } } if (!ok) return -EINVAL; if (companion_ok) i++; /* companion channel already checked */ } return 0; } static int atihdmi_pin_set_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid, int hdmi_slot, int stream_channel) { int verb; int ati_channel_setup = 0; if (hdmi_slot > 7) return -EINVAL; if (!has_amd_full_remap_support(codec)) { hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot); /* In case this is an odd slot but without stream channel, do not * disable the slot since the corresponding even slot could have a * channel. In case neither have a channel, the slot pair will be * disabled when this function is called for the even slot. */ if (hdmi_slot % 2 != 0 && stream_channel == 0xf) return 0; hdmi_slot -= hdmi_slot % 2; if (stream_channel != 0xf) stream_channel -= stream_channel % 2; } verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e; /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */ if (stream_channel != 0xf) ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE; return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup); } static int atihdmi_pin_get_slot_channel(struct hda_codec *codec, hda_nid_t pin_nid, int asp_slot) { bool was_odd = false; int ati_asp_slot = asp_slot; int verb; int ati_channel_setup; if (asp_slot > 7) return -EINVAL; if (!has_amd_full_remap_support(codec)) { ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot); if (ati_asp_slot % 2 != 0) { ati_asp_slot -= 1; was_odd = true; } } verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e; ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0); if (!(ati_channel_setup & ATI_OUT_ENABLE)) return 0xf; return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd; } static int atihdmi_paired_chmap_cea_alloc_validate_get_type(struct cea_channel_speaker_allocation *cap, int channels) { int c; /* * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so * we need to take that into account (a single channel may take 2 * channel slots if we need to carry a silent channel next to it). * On Rev3+ AMD codecs this function is not used. */ int chanpairs = 0; /* We only produce even-numbered channel count TLVs */ if ((channels % 2) != 0) return -1; for (c = 0; c < 7; c += 2) { if (cap->speakers[c] || cap->speakers[c+1]) chanpairs++; } if (chanpairs * 2 != channels) return -1; return SNDRV_CTL_TLVT_CHMAP_PAIRED; } static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct cea_channel_speaker_allocation *cap, unsigned int *chmap, int channels) { /* produce paired maps for pre-rev3 ATI/AMD codecs */ int count = 0; int c; for (c = 7; c >= 0; c--) { int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c); int spk = cap->speakers[chan]; if (!spk) { /* add N/A channel if the companion channel is occupied */ if (cap->speakers[chan + (chan % 2 ? -1 : 1)]) chmap[count++] = SNDRV_CHMAP_NA; continue; } chmap[count++] = spk_to_chmap(spk); } WARN_ON(count != channels); } static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr) { int hbr_ctl, hbr_ctl_new; hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0); if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) { if (hbr) hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE; else hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE; codec_dbg(codec, "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n", pin_nid, hbr_ctl == hbr_ctl_new ? "" : "new-", hbr_ctl_new); if (hbr_ctl != hbr_ctl_new) snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_HBR_CONTROL, hbr_ctl_new); } else if (hbr) return -EINVAL; return 0; } static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid, hda_nid_t pin_nid, u32 stream_tag, int format) { if (is_amdhdmi_rev3_or_later(codec)) { int ramp_rate = 180; /* default as per AMD spec */ /* disable ramp-up/down for non-pcm as per AMD spec */ if (format & AC_FMT_TYPE_NON_PCM) ramp_rate = 0; snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate); } return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format); } static int atihdmi_init(struct hda_codec *codec) { struct hdmi_spec *spec = codec->spec; int pin_idx, err; err = generic_hdmi_init(codec); if (err) return err; for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); /* make sure downmix information in infoframe is zero */ snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0); /* enable channel-wise remap mode if supported */ if (has_amd_full_remap_support(codec)) snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_MULTICHANNEL_MODE, ATI_MULTICHANNEL_MODE_SINGLE); } return 0; } static int patch_atihdmi(struct hda_codec *codec) { struct hdmi_spec *spec; struct hdmi_spec_per_cvt *per_cvt; int err, cvt_idx; err = patch_generic_hdmi(codec); if (err) return err; codec->patch_ops.init = atihdmi_init; spec = codec->spec; spec->ops.pin_get_eld = atihdmi_pin_get_eld; spec->ops.pin_get_slot_channel = atihdmi_pin_get_slot_channel; spec->ops.pin_set_slot_channel = atihdmi_pin_set_slot_channel; spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe; spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup; spec->ops.setup_stream = atihdmi_setup_stream; if (!has_amd_full_remap_support(codec)) { /* override to ATI/AMD-specific versions with pairwise mapping */ spec->ops.chmap_cea_alloc_validate_get_type = atihdmi_paired_chmap_cea_alloc_validate_get_type; spec->ops.cea_alloc_to_tlv_chmap = atihdmi_paired_cea_alloc_to_tlv_chmap; spec->ops.chmap_validate = atihdmi_paired_chmap_validate; } /* ATI/AMD converters do not advertise all of their capabilities */ for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { per_cvt = get_cvt(spec, cvt_idx); per_cvt->channels_max = max(per_cvt->channels_max, 8u); per_cvt->rates |= SUPPORTED_RATES; per_cvt->formats |= SUPPORTED_FORMATS; per_cvt->maxbps = max(per_cvt->maxbps, 24u); } spec->channels_max = max(spec->channels_max, 8u); return 0; } /* VIA HDMI Implementation */ #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */ #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */ static int patch_via_hdmi(struct hda_codec *codec) { return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID); } /* * patch entries */ static const struct hda_codec_preset snd_hda_preset_hdmi[] = { { .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi }, { .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi }, { .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi }, { .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_atihdmi }, { .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi }, { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi }, { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi }, { .id = 0x10de0002, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x }, { .id = 0x10de0003, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x }, { .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x }, { .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x }, { .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x }, { .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_nvhdmi }, { .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_nvhdmi }, /* 17 is known to be absent */ { .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0020, .name = "Tegra30 HDMI", .patch = patch_tegra_hdmi }, { .id = 0x10de0022, .name = "Tegra114 HDMI", .patch = patch_tegra_hdmi }, { .id = 0x10de0028, .name = "Tegra124 HDMI", .patch = patch_tegra_hdmi }, { .id = 0x10de0029, .name = "Tegra210 HDMI/DP", .patch = patch_tegra_hdmi }, { .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0051, .name = "GPU 51 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0060, .name = "GPU 60 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch }, { .id = 0x10de0070, .name = "GPU 70 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0071, .name = "GPU 71 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de0072, .name = "GPU 72 HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de007d, .name = "GPU 7d HDMI/DP", .patch = patch_nvhdmi }, { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch }, { .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi }, { .id = 0x11069f81, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi }, { .id = 0x11069f84, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi }, { .id = 0x11069f85, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi }, { .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862806, .name = "PantherPoint HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862807, .name = "Haswell HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862808, .name = "Broadwell HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862809, .name = "Skylake HDMI", .patch = patch_generic_hdmi }, { .id = 0x8086280a, .name = "Broxton HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862880, .name = "CedarTrail HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862882, .name = "Valleyview2 HDMI", .patch = patch_generic_hdmi }, { .id = 0x80862883, .name = "Braswell HDMI", .patch = patch_generic_hdmi }, { .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi }, /* special ID for generic HDMI */ { .id = HDA_CODEC_ID_GENERIC_HDMI, .patch = patch_generic_hdmi }, {} /* terminator */ }; MODULE_ALIAS("snd-hda-codec-id:1002793c"); MODULE_ALIAS("snd-hda-codec-id:10027919"); MODULE_ALIAS("snd-hda-codec-id:1002791a"); MODULE_ALIAS("snd-hda-codec-id:1002aa01"); MODULE_ALIAS("snd-hda-codec-id:10951390"); MODULE_ALIAS("snd-hda-codec-id:10951392"); MODULE_ALIAS("snd-hda-codec-id:10de0002"); MODULE_ALIAS("snd-hda-codec-id:10de0003"); MODULE_ALIAS("snd-hda-codec-id:10de0005"); MODULE_ALIAS("snd-hda-codec-id:10de0006"); MODULE_ALIAS("snd-hda-codec-id:10de0007"); MODULE_ALIAS("snd-hda-codec-id:10de000a"); MODULE_ALIAS("snd-hda-codec-id:10de000b"); MODULE_ALIAS("snd-hda-codec-id:10de000c"); MODULE_ALIAS("snd-hda-codec-id:10de000d"); MODULE_ALIAS("snd-hda-codec-id:10de0010"); MODULE_ALIAS("snd-hda-codec-id:10de0011"); MODULE_ALIAS("snd-hda-codec-id:10de0012"); MODULE_ALIAS("snd-hda-codec-id:10de0013"); MODULE_ALIAS("snd-hda-codec-id:10de0014"); MODULE_ALIAS("snd-hda-codec-id:10de0015"); MODULE_ALIAS("snd-hda-codec-id:10de0016"); MODULE_ALIAS("snd-hda-codec-id:10de0018"); MODULE_ALIAS("snd-hda-codec-id:10de0019"); MODULE_ALIAS("snd-hda-codec-id:10de001a"); MODULE_ALIAS("snd-hda-codec-id:10de001b"); MODULE_ALIAS("snd-hda-codec-id:10de001c"); MODULE_ALIAS("snd-hda-codec-id:10de0028"); MODULE_ALIAS("snd-hda-codec-id:10de0040"); MODULE_ALIAS("snd-hda-codec-id:10de0041"); MODULE_ALIAS("snd-hda-codec-id:10de0042"); MODULE_ALIAS("snd-hda-codec-id:10de0043"); MODULE_ALIAS("snd-hda-codec-id:10de0044"); MODULE_ALIAS("snd-hda-codec-id:10de0051"); MODULE_ALIAS("snd-hda-codec-id:10de0060"); MODULE_ALIAS("snd-hda-codec-id:10de0067"); MODULE_ALIAS("snd-hda-codec-id:10de0070"); MODULE_ALIAS("snd-hda-codec-id:10de0071"); MODULE_ALIAS("snd-hda-codec-id:10de0072"); MODULE_ALIAS("snd-hda-codec-id:10de007d"); MODULE_ALIAS("snd-hda-codec-id:10de8001"); MODULE_ALIAS("snd-hda-codec-id:11069f80"); MODULE_ALIAS("snd-hda-codec-id:11069f81"); MODULE_ALIAS("snd-hda-codec-id:11069f84"); MODULE_ALIAS("snd-hda-codec-id:11069f85"); MODULE_ALIAS("snd-hda-codec-id:17e80047"); MODULE_ALIAS("snd-hda-codec-id:80860054"); MODULE_ALIAS("snd-hda-codec-id:80862801"); MODULE_ALIAS("snd-hda-codec-id:80862802"); MODULE_ALIAS("snd-hda-codec-id:80862803"); MODULE_ALIAS("snd-hda-codec-id:80862804"); MODULE_ALIAS("snd-hda-codec-id:80862805"); MODULE_ALIAS("snd-hda-codec-id:80862806"); MODULE_ALIAS("snd-hda-codec-id:80862807"); MODULE_ALIAS("snd-hda-codec-id:80862808"); MODULE_ALIAS("snd-hda-codec-id:80862809"); MODULE_ALIAS("snd-hda-codec-id:8086280a"); MODULE_ALIAS("snd-hda-codec-id:80862880"); MODULE_ALIAS("snd-hda-codec-id:80862882"); MODULE_ALIAS("snd-hda-codec-id:80862883"); MODULE_ALIAS("snd-hda-codec-id:808629fb"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("HDMI HD-audio codec"); MODULE_ALIAS("snd-hda-codec-intelhdmi"); MODULE_ALIAS("snd-hda-codec-nvhdmi"); MODULE_ALIAS("snd-hda-codec-atihdmi"); static struct hda_codec_driver hdmi_driver = { .preset = snd_hda_preset_hdmi, }; module_hda_codec_driver(hdmi_driver);
gpl-2.0
InnoSum/linux-sunxi
drivers/net/wireless/bcm4330/wl_android.c
192
20828
/* * Linux cfg80211 driver - Android related functions * * Copyright (C) 1999-2011, Broadcom Corporation * * Unless you and Broadcom execute a separate written software license * agreement governing use of this software, this software is licensed to you * under the terms of the GNU General Public License version 2 (the "GPL"), * available at http://www.broadcom.com/licenses/GPLv2.php, with the * following added to such license: * * As a special exception, the copyright holders of this software give you * permission to link this software with independent modules, and to copy and * distribute the resulting executable under terms of your choice, provided that * you also meet, for each linked independent module, the terms and conditions of * the license of that module. An independent module is a module which is not * derived from this software. The special exception does not apply to any * modifications of the software. * * Notwithstanding the above, under no circumstances may you combine this * software in any way with any other Broadcom software provided under a license * other than the GPL, without Broadcom's express prior written consent. * * $Id: wl_android.c,v 1.1.4.1.2.14 2011/02/09 01:40:07 Exp $ */ #include <linux/module.h> #include <linux/netdevice.h> #include <wl_android.h> #include <wldev_common.h> #include <wlioctl.h> #include <bcmutils.h> #include <linux_osl.h> #include <dhd_dbg.h> #include <dngl_stats.h> #include <dhd.h> #include <bcmsdbus.h> #if defined(CONFIG_WIFI_CONTROL_FUNC) #include <linux/platform_device.h> #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) #include <linux/wlan_plat.h> #else #include <linux/wifi_tiwlan.h> #endif #endif /* CONFIG_WIFI_CONTROL_FUNC */ /* * Android private command strings, PLEASE define new private commands here * so they can be updated easily in the future (if needed) */ #define CMD_START "START" #define CMD_STOP "STOP" #define CMD_SCAN_ACTIVE "SCAN-ACTIVE" #define CMD_SCAN_PASSIVE "SCAN-PASSIVE" #define CMD_RSSI "RSSI" #define CMD_LINKSPEED "LINKSPEED" #define CMD_RXFILTER_START "RXFILTER-START" #define CMD_RXFILTER_STOP "RXFILTER-STOP" #define CMD_RXFILTER_ADD "RXFILTER-ADD" #define CMD_RXFILTER_REMOVE "RXFILTER-REMOVE" #define CMD_BTCOEXSCAN_START "BTCOEXSCAN-START" #define CMD_BTCOEXSCAN_STOP "BTCOEXSCAN-STOP" #define CMD_BTCOEXMODE "BTCOEXMODE" #define CMD_SETSUSPENDOPT "SETSUSPENDOPT" #ifdef WLP2P #define CMD_P2P_DEV_ADDR "P2P_DEV_ADDR" #endif #define CMD_SETFWPATH "SETFWPATH" #define CMD_SETBAND "SETBAND" #define CMD_GETBAND "GETBAND" #define CMD_COUNTRY "COUNTRY" #ifdef PNO_SUPPORT #define CMD_PNOSSIDCLR_SET "PNOSSIDCLR" #define CMD_PNOSETUP_SET "PNOSETUP " #define CMD_PNOENABLE_SET "PNOFORCE" #define CMD_PNODEBUG_SET "PNODEBUG" #define PNO_TLV_PREFIX 'S' #define PNO_TLV_VERSION '1' #define PNO_TLV_SUBVERSION '2' #define PNO_TLV_RESERVED '0' #define PNO_TLV_TYPE_SSID_IE 'S' #define PNO_TLV_TYPE_TIME 'T' #define PNO_TLV_FREQ_REPEAT 'R' #define PNO_TLV_FREQ_EXPO_MAX 'M' typedef struct cmd_tlv { char prefix; char version; char subver; char reserved; } cmd_tlv_t; #endif /* PNO_SUPPORT */ typedef struct android_wifi_priv_cmd { char *buf; int used_len; int total_len; } android_wifi_priv_cmd; /** * Extern function declarations (TODO: move them to dhd_linux.h) */ void dhd_customer_gpio_wlan_ctrl(int onoff); uint dhd_dev_reset(struct net_device *dev, uint8 flag); void dhd_dev_init_ioctl(struct net_device *dev); #ifdef WLP2P int wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr); #else int wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr) { return 0; } #endif extern bool ap_fw_loaded; #ifdef CUSTOMER_HW2 extern char iface_name[IFNAMSIZ]; #endif /** * Local (static) functions and variables */ /* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first * time (only) in dhd_open, subsequential wifi on will be handled by * wl_android_wifi_on */ static int g_wifi_on = TRUE; /** * Local (static) function definitions */ static int wl_android_get_link_speed(struct net_device *net, char *command, int total_len) { int link_speed; int bytes_written; int error; error = wldev_get_link_speed(net, &link_speed); if (error) return -1; /* Convert Kbps to Android Mbps */ link_speed = link_speed / 1000; bytes_written = snprintf(command, total_len, "LinkSpeed %d", link_speed); DHD_INFO(("%s: command result is %s\n", __FUNCTION__, command)); return bytes_written; } static int wl_android_get_rssi(struct net_device *net, char *command, int total_len) { wlc_ssid_t ssid = {0}; int rssi; int bytes_written = 0; int error; error = wldev_get_rssi(net, &rssi); if (error) return -1; error = wldev_get_ssid(net, &ssid); if (error) return -1; if ((ssid.SSID_len == 0) || (ssid.SSID_len > DOT11_MAX_SSID_LEN)) { DHD_ERROR(("%s: wldev_get_ssid failed\n", __FUNCTION__)); } else { memcpy(command, ssid.SSID, ssid.SSID_len); bytes_written = ssid.SSID_len; } bytes_written += snprintf(&command[bytes_written], total_len, " rssi %d", rssi); DHD_INFO(("%s: command result is %s (%d)\n", __FUNCTION__, command, bytes_written)); return bytes_written; } static int wl_android_set_suspendopt(struct net_device *dev, char *command, int total_len) { int suspend_flag; int ret_now; int ret = 0; suspend_flag = *(command + strlen(CMD_SETSUSPENDOPT) + 1) - '0'; if (suspend_flag != 0) suspend_flag = 1; ret_now = net_os_set_suspend_disable(dev, suspend_flag); if (ret_now != suspend_flag) { if (!(ret = net_os_set_suspend(dev, ret_now))) DHD_INFO(("%s: Suspend Flag %d -> %d\n", __FUNCTION__, ret_now, suspend_flag)); else DHD_ERROR(("%s: failed %d\n", __FUNCTION__, ret)); } return ret; } static int wl_android_get_band(struct net_device *dev, char *command, int total_len) { uint band; int bytes_written; int error; error = wldev_get_band(dev, &band); if (error) return -1; bytes_written = snprintf(command, total_len, "Band %d", band); return bytes_written; } #ifdef PNO_SUPPORT static int wl_android_set_pno_setup(struct net_device *dev, char *command, int total_len) { wlc_ssid_t ssids_local[MAX_PFN_LIST_COUNT]; int res = -1; int nssid = 0; cmd_tlv_t *cmd_tlv_temp; char *str_ptr; int tlv_size_left; int pno_time = 0; int pno_repeat = 0; int pno_freq_expo_max = 0; DHD_INFO(("%s: command=%s, len=%d\n", __FUNCTION__, command, total_len)); if (total_len < (strlen(CMD_PNOSETUP_SET) + sizeof(cmd_tlv_t))) { DHD_ERROR(("%s argument=%d less min size\n", __FUNCTION__, total_len)); goto exit_proc; } str_ptr = command + strlen(CMD_PNOSETUP_SET); tlv_size_left = total_len - strlen(CMD_PNOSETUP_SET); cmd_tlv_temp = (cmd_tlv_t *)str_ptr; memset(ssids_local, 0, sizeof(ssids_local)); if ((cmd_tlv_temp->prefix == PNO_TLV_PREFIX) && (cmd_tlv_temp->version == PNO_TLV_VERSION) && (cmd_tlv_temp->subver == PNO_TLV_SUBVERSION)) { str_ptr += sizeof(cmd_tlv_t); tlv_size_left -= sizeof(cmd_tlv_t); if ((nssid = wl_iw_parse_ssid_list_tlv(&str_ptr, ssids_local, MAX_PFN_LIST_COUNT, &tlv_size_left)) <= 0) { DHD_ERROR(("SSID is not presented or corrupted ret=%d\n", nssid)); goto exit_proc; } else { if ((str_ptr[0] != PNO_TLV_TYPE_TIME) || (tlv_size_left <= 1)) { DHD_ERROR(("%s scan duration corrupted field size %d\n", __FUNCTION__, tlv_size_left)); goto exit_proc; } str_ptr++; pno_time = simple_strtoul(str_ptr, &str_ptr, 16); DHD_INFO(("%s: pno_time=%d\n", __FUNCTION__, pno_time)); if (str_ptr[0] != 0) { if ((str_ptr[0] != PNO_TLV_FREQ_REPEAT)) { DHD_ERROR(("%s pno repeat : corrupted field\n", __FUNCTION__)); goto exit_proc; } str_ptr++; pno_repeat = simple_strtoul(str_ptr, &str_ptr, 16); DHD_INFO(("%s :got pno_repeat=%d\n", __FUNCTION__, pno_repeat)); if (str_ptr[0] != PNO_TLV_FREQ_EXPO_MAX) { DHD_ERROR(("%s FREQ_EXPO_MAX corrupted field size\n", __FUNCTION__)); goto exit_proc; } str_ptr++; pno_freq_expo_max = simple_strtoul(str_ptr, &str_ptr, 16); DHD_INFO(("%s: pno_freq_expo_max=%d\n", __FUNCTION__, pno_freq_expo_max)); } } } else { DHD_ERROR(("%s get wrong TLV command\n", __FUNCTION__)); goto exit_proc; } res = dhd_dev_pno_set(dev, ssids_local, nssid, pno_time, pno_repeat, pno_freq_expo_max); exit_proc: return res; } #endif /* PNO_SUPPORT */ #ifdef WLP2P static int wl_android_get_p2p_dev_addr(struct net_device *ndev, char *command, int total_len) { int ret; int bytes_written = 0; ret = wl_cfg80211_get_p2p_dev_addr(ndev, (struct ether_addr*)command); if (ret) return 0; bytes_written = sizeof(struct ether_addr); return bytes_written; } #endif /** * Global function definitions (declared in wl_android.h) */ int wl_android_wifi_on(struct net_device *dev) { int ret = 0; printf("%s in\n", __FUNCTION__); if (!dev) { DHD_ERROR(("%s: dev is null\n", __FUNCTION__)); return -EINVAL; } dhd_net_if_lock(dev); if (!g_wifi_on) { dhd_customer_gpio_wlan_ctrl(WLAN_RESET_ON); sdioh_start(NULL, 0); ret = dhd_dev_reset(dev, FALSE); sdioh_start(NULL, 1); dhd_dev_init_ioctl(dev); g_wifi_on = 1; } dhd_net_if_unlock(dev); return ret; } int wl_android_wifi_off(struct net_device *dev) { int ret = 0; printf("%s in\n", __FUNCTION__); if (!dev) { DHD_TRACE(("%s: dev is null\n", __FUNCTION__)); return -EINVAL; } dhd_net_if_lock(dev); if (g_wifi_on) { dhd_dev_reset(dev, 1); sdioh_stop(NULL); /* clean up dtim_skip setting */ net_os_set_dtim_skip(dev, TRUE); dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF); g_wifi_on = 0; } dhd_net_if_unlock(dev); return ret; } static int wl_android_set_fwpath(struct net_device *net, char *command, int total_len) { if ((strlen(command) - strlen(CMD_SETFWPATH)) > MOD_PARAM_PATHLEN) return -1; bcm_strncpy_s(fw_path, sizeof(fw_path), command + strlen(CMD_SETFWPATH) + 1, MOD_PARAM_PATHLEN - 1); if (strstr(fw_path, "apsta") != NULL) { DHD_INFO(("GOT APSTA FIRMWARE\n")); ap_fw_loaded = TRUE; } else { DHD_INFO(("GOT STA FIRMWARE\n")); ap_fw_loaded = FALSE; } return 0; } int wl_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd) { int ret = 0; char *command = NULL; int bytes_written = 0; android_wifi_priv_cmd priv_cmd; net_os_wake_lock(net); if (!ifr->ifr_data) { ret = -EINVAL; goto exit; } if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(android_wifi_priv_cmd))) { ret = -EFAULT; goto exit; } command = kmalloc(priv_cmd.total_len, GFP_KERNEL); if (!command) { DHD_ERROR(("%s: failed to allocate memory\n", __FUNCTION__)); ret = -ENOMEM; goto exit; } if (copy_from_user(command, priv_cmd.buf, priv_cmd.total_len)) { ret = -EFAULT; goto exit; } DHD_INFO(("%s: Android private cmd \"%s\" on %s\n", __FUNCTION__, command, ifr->ifr_name)); if (strnicmp(command, CMD_START, strlen(CMD_START)) == 0) { DHD_INFO(("%s, Received regular START command\n", __FUNCTION__)); bytes_written = wl_android_wifi_on(net); } else if (strnicmp(command, CMD_SETFWPATH, strlen(CMD_SETFWPATH)) == 0) { bytes_written = wl_android_set_fwpath(net, command, priv_cmd.total_len); } if (!g_wifi_on) { DHD_ERROR(("%s: Ignore private cmd \"%s\" - iface %s is down\n", __FUNCTION__, command, ifr->ifr_name)); ret = 0; goto exit; } if (strnicmp(command, CMD_STOP, strlen(CMD_STOP)) == 0) { bytes_written = wl_android_wifi_off(net); } else if (strnicmp(command, CMD_SCAN_ACTIVE, strlen(CMD_SCAN_ACTIVE)) == 0) { /* TBD: SCAN-ACTIVE */ } else if (strnicmp(command, CMD_SCAN_PASSIVE, strlen(CMD_SCAN_PASSIVE)) == 0) { /* TBD: SCAN-PASSIVE */ } else if (strnicmp(command, CMD_RSSI, strlen(CMD_RSSI)) == 0) { bytes_written = wl_android_get_rssi(net, command, priv_cmd.total_len); } else if (strnicmp(command, CMD_LINKSPEED, strlen(CMD_LINKSPEED)) == 0) { bytes_written = wl_android_get_link_speed(net, command, priv_cmd.total_len); } else if (strnicmp(command, CMD_RXFILTER_START, strlen(CMD_RXFILTER_START)) == 0) { bytes_written = net_os_set_packet_filter(net, 1); } else if (strnicmp(command, CMD_RXFILTER_STOP, strlen(CMD_RXFILTER_STOP)) == 0) { bytes_written = net_os_set_packet_filter(net, 0); } else if (strnicmp(command, CMD_RXFILTER_ADD, strlen(CMD_RXFILTER_ADD)) == 0) { int filter_num = *(command + strlen(CMD_RXFILTER_ADD) + 1) - '0'; bytes_written = net_os_rxfilter_add_remove(net, TRUE, filter_num); } else if (strnicmp(command, CMD_RXFILTER_REMOVE, strlen(CMD_RXFILTER_REMOVE)) == 0) { int filter_num = *(command + strlen(CMD_RXFILTER_REMOVE) + 1) - '0'; bytes_written = net_os_rxfilter_add_remove(net, FALSE, filter_num); } else if (strnicmp(command, CMD_BTCOEXSCAN_START, strlen(CMD_BTCOEXSCAN_START)) == 0) { /* TBD: BTCOEXSCAN-START */ } else if (strnicmp(command, CMD_BTCOEXSCAN_STOP, strlen(CMD_BTCOEXSCAN_STOP)) == 0) { /* TBD: BTCOEXSCAN-STOP */ } else if (strnicmp(command, CMD_BTCOEXMODE, strlen(CMD_BTCOEXMODE)) == 0) { /* TBD: BTCOEXMODE */ } else if (strnicmp(command, CMD_SETSUSPENDOPT, strlen(CMD_SETSUSPENDOPT)) == 0) { bytes_written = wl_android_set_suspendopt(net, command, priv_cmd.total_len); } else if (strnicmp(command, CMD_SETBAND, strlen(CMD_SETBAND)) == 0) { uint band = *(command + strlen(CMD_SETBAND) + 1) - '0'; bytes_written = wldev_set_band(net, band); } else if (strnicmp(command, CMD_GETBAND, strlen(CMD_GETBAND)) == 0) { bytes_written = wl_android_get_band(net, command, priv_cmd.total_len); } else if (strnicmp(command, CMD_COUNTRY, strlen(CMD_COUNTRY)) == 0) { char *country_code = command + strlen(CMD_COUNTRY) + 1; bytes_written = wldev_set_country(net, country_code); } #ifdef PNO_SUPPORT else if (strnicmp(command, CMD_PNOSSIDCLR_SET, strlen(CMD_PNOSSIDCLR_SET)) == 0) { bytes_written = dhd_dev_pno_reset(net); } else if (strnicmp(command, CMD_PNOSETUP_SET, strlen(CMD_PNOSETUP_SET)) == 0) { bytes_written = wl_android_set_pno_setup(net, command, priv_cmd.total_len); } else if (strnicmp(command, CMD_PNOENABLE_SET, strlen(CMD_PNOENABLE_SET)) == 0) { uint pfn_enabled = *(command + strlen(CMD_PNOENABLE_SET) + 1) - '0'; bytes_written = dhd_dev_pno_enable(net, pfn_enabled); } #endif #ifdef WLP2P else if (strnicmp(command, CMD_P2P_DEV_ADDR, strlen(CMD_P2P_DEV_ADDR)) == 0) { bytes_written = wl_android_get_p2p_dev_addr(net, command, priv_cmd.total_len); } #endif else { DHD_ERROR(("Unknown PRIVATE command %s - ignored\n", command)); snprintf(command, 3, "OK"); bytes_written = strlen("OK"); } if (bytes_written > 0) { if (bytes_written > priv_cmd.total_len) { DHD_ERROR(("%s: bytes_written = %d\n", __FUNCTION__, bytes_written)); bytes_written = priv_cmd.total_len; } else { bytes_written++; } priv_cmd.used_len = bytes_written; if (copy_to_user(priv_cmd.buf, command, bytes_written)) { DHD_ERROR(("%s: failed to copy data to user buffer\n", __FUNCTION__)); ret = -EFAULT; } } else { ret = bytes_written; } exit: net_os_wake_unlock(net); if (command) { kfree(command); } return ret; } int wl_android_init(void) { int ret = 0; dhd_msg_level = DHD_ERROR_VAL; #ifdef ENABLE_INSMOD_NO_FW_LOAD dhd_download_fw_on_driverload = FALSE; #endif /* ENABLE_INSMOD_NO_FW_LOAD */ #if 0 //#ifdef CUSTOMER_HW2 if (!iface_name[0]) bcm_strncpy_s(iface_name, IFNAMSIZ, "wlan", IFNAMSIZ); #endif /* CUSTOMER_HW2 */ return ret; } int wl_android_exit(void) { int ret = 0; return ret; } int wl_android_post_init(void) { int ret = 0; if (!dhd_download_fw_on_driverload) { /* Call customer gpio to turn off power with WL_REG_ON signal */ dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF); g_wifi_on = 0; } return ret; } /** * Functions for Android WiFi card detection */ #if defined(CONFIG_WIFI_CONTROL_FUNC) static int g_wifidev_registered = 0; static struct semaphore wifi_control_sem; static struct wifi_platform_data *wifi_control_data = NULL; static struct resource *wifi_irqres = NULL; static int wifi_add_dev(void); static void wifi_del_dev(void); int wl_android_wifictrl_func_add(void) { int ret = 0; sema_init(&wifi_control_sem, 0); ret = wifi_add_dev(); if (ret) { DHD_ERROR(("%s: platform_driver_register failed\n", __FUNCTION__)); return ret; } g_wifidev_registered = 1; /* Waiting callback after platform_driver_register is done or exit with error */ if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) { ret = -EINVAL; DHD_ERROR(("%s: platform_driver_register timeout\n", __FUNCTION__)); } return ret; } void wl_android_wifictrl_func_del(void) { if (g_wifidev_registered) { wifi_del_dev(); g_wifidev_registered = 0; } } void* wl_android_prealloc(int section, unsigned long size) { void *alloc_ptr = NULL; if (wifi_control_data && wifi_control_data->mem_prealloc) { alloc_ptr = wifi_control_data->mem_prealloc(section, size); if (alloc_ptr) { DHD_INFO(("success alloc section %d\n", section)); bzero(alloc_ptr, size); return alloc_ptr; } } DHD_ERROR(("can't alloc section %d\n", section)); return 0; } int wifi_get_irq_number(unsigned long *irq_flags_ptr) { if (wifi_irqres) { *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK; return (int)wifi_irqres->start; } #ifdef CUSTOM_OOB_GPIO_NUM return CUSTOM_OOB_GPIO_NUM; #else return -1; #endif } int wifi_set_power(int on, unsigned long msec) { DHD_ERROR(("%s = %d\n", __FUNCTION__, on)); if (wifi_control_data && wifi_control_data->set_power) { wifi_control_data->set_power(on); } if (msec) mdelay(msec); return 0; } #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) int wifi_get_mac_addr(unsigned char *buf) { DHD_ERROR(("%s\n", __FUNCTION__)); if (!buf) return -EINVAL; if (wifi_control_data && wifi_control_data->get_mac_addr) { return wifi_control_data->get_mac_addr(buf); } return -EOPNOTSUPP; } #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) void *wifi_get_country_code(char *ccode) { DHD_TRACE(("%s\n", __FUNCTION__)); if (!ccode) return NULL; if (wifi_control_data && wifi_control_data->get_country_code) { return wifi_control_data->get_country_code(ccode); } return NULL; } #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */ static int wifi_set_carddetect(int on) { DHD_ERROR(("%s = %d\n", __FUNCTION__, on)); if (wifi_control_data && wifi_control_data->set_carddetect) { wifi_control_data->set_carddetect(on); } return 0; } static int wifi_probe(struct platform_device *pdev) { struct wifi_platform_data *wifi_ctrl = (struct wifi_platform_data *)(pdev->dev.platform_data); DHD_ERROR(("## %s\n", __FUNCTION__)); wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcmdhd_wlan_irq"); if (wifi_irqres == NULL) wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcm4329_wlan_irq"); wifi_control_data = wifi_ctrl; wifi_set_power(1, 0); /* Power On */ wifi_set_carddetect(1); /* CardDetect (0->1) */ up(&wifi_control_sem); return 0; } static int wifi_remove(struct platform_device *pdev) { struct wifi_platform_data *wifi_ctrl = (struct wifi_platform_data *)(pdev->dev.platform_data); DHD_ERROR(("## %s\n", __FUNCTION__)); wifi_control_data = wifi_ctrl; wifi_set_power(0, 0); /* Power Off */ wifi_set_carddetect(0); /* CardDetect (1->0) */ up(&wifi_control_sem); DHD_ERROR(("## %s leave\n", __FUNCTION__)); return 0; } static int wifi_suspend(struct platform_device *pdev, pm_message_t state) { DHD_TRACE(("##> %s\n", __FUNCTION__)); #if defined(OOB_INTR_ONLY) bcmsdh_oob_intr_set(0); #endif /* (OOB_INTR_ONLY) */ return 0; } static int wifi_resume(struct platform_device *pdev) { DHD_TRACE(("##> %s\n", __FUNCTION__)); #if defined(OOB_INTR_ONLY) bcmsdh_oob_intr_set(1); #endif /* (OOB_INTR_ONLY) */ return 0; } static struct platform_driver wifi_device = { .probe = wifi_probe, .remove = wifi_remove, .suspend = wifi_suspend, .resume = wifi_resume, .driver = { .name = "bcmdhd_wlan", } }; static struct platform_driver wifi_device_legacy = { .probe = wifi_probe, .remove = wifi_remove, .suspend = wifi_suspend, .resume = wifi_resume, .driver = { .name = "bcm4329_wlan", } }; static int wifi_add_dev(void) { DHD_TRACE(("## Calling platform_driver_register\n")); platform_driver_register(&wifi_device); platform_driver_register(&wifi_device_legacy); return 0; } static void wifi_del_dev(void) { DHD_TRACE(("## Unregister platform_driver_register\n")); platform_driver_unregister(&wifi_device); platform_driver_unregister(&wifi_device_legacy); } #endif /* defined(CONFIG_WIFI_CONTROL_FUNC) */
gpl-2.0
articu/linux
drivers/video/fbdev/sis/sis_main.c
960
187423
/* * SiS 300/540/630[S]/730[S], * SiS 315[E|PRO]/550/[M]65x/[M]66x[F|M|G]X/[M]74x[GX]/330/[M]76x[GX], * XGI V3XT/V5/V8, Z7 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3 * * Copyright (C) 2001-2005 Thomas Winischhofer, Vienna, Austria. * * 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 named License, * or 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 * * Author: Thomas Winischhofer <thomas@winischhofer.net> * * Author of (practically wiped) code base: * SiS (www.sis.com) * Copyright (C) 1999 Silicon Integrated Systems, Inc. * * See http://www.winischhofer.net/ for more information and updates * * Originally based on the VBE 2.0 compliant graphic boards framebuffer driver, * which is (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de> * */ #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kernel.h> #include <linux/spinlock.h> #include <linux/errno.h> #include <linux/string.h> #include <linux/mm.h> #include <linux/screen_info.h> #include <linux/slab.h> #include <linux/fb.h> #include <linux/selection.h> #include <linux/ioport.h> #include <linux/init.h> #include <linux/pci.h> #include <linux/vmalloc.h> #include <linux/capability.h> #include <linux/fs.h> #include <linux/types.h> #include <linux/uaccess.h> #include <asm/io.h> #include "sis.h" #include "sis_main.h" #if !defined(CONFIG_FB_SIS_300) && !defined(CONFIG_FB_SIS_315) #warning Neither CONFIG_FB_SIS_300 nor CONFIG_FB_SIS_315 is set #warning sisfb will not work! #endif static void sisfb_handle_command(struct sis_video_info *ivideo, struct sisfb_cmd *sisfb_command); /* ------------------ Internal helper routines ----------------- */ static void __init sisfb_setdefaultparms(void) { sisfb_off = 0; sisfb_parm_mem = 0; sisfb_accel = -1; sisfb_ypan = -1; sisfb_max = -1; sisfb_userom = -1; sisfb_useoem = -1; sisfb_mode_idx = -1; sisfb_parm_rate = -1; sisfb_crt1off = 0; sisfb_forcecrt1 = -1; sisfb_crt2type = -1; sisfb_crt2flags = 0; sisfb_pdc = 0xff; sisfb_pdca = 0xff; sisfb_scalelcd = -1; sisfb_specialtiming = CUT_NONE; sisfb_lvdshl = -1; sisfb_dstn = 0; sisfb_fstn = 0; sisfb_tvplug = -1; sisfb_tvstd = -1; sisfb_tvxposoffset = 0; sisfb_tvyposoffset = 0; sisfb_nocrt2rate = 0; #if !defined(__i386__) && !defined(__x86_64__) sisfb_resetcard = 0; sisfb_videoram = 0; #endif } /* ------------- Parameter parsing -------------- */ static void sisfb_search_vesamode(unsigned int vesamode, bool quiet) { int i = 0, j = 0; /* We don't know the hardware specs yet and there is no ivideo */ if(vesamode == 0) { if(!quiet) printk(KERN_ERR "sisfb: Invalid mode. Using default.\n"); sisfb_mode_idx = DEFAULT_MODE; return; } vesamode &= 0x1dff; /* Clean VESA mode number from other flags */ while(sisbios_mode[i++].mode_no[0] != 0) { if( (sisbios_mode[i-1].vesa_mode_no_1 == vesamode) || (sisbios_mode[i-1].vesa_mode_no_2 == vesamode) ) { if(sisfb_fstn) { if(sisbios_mode[i-1].mode_no[1] == 0x50 || sisbios_mode[i-1].mode_no[1] == 0x56 || sisbios_mode[i-1].mode_no[1] == 0x53) continue; } else { if(sisbios_mode[i-1].mode_no[1] == 0x5a || sisbios_mode[i-1].mode_no[1] == 0x5b) continue; } sisfb_mode_idx = i - 1; j = 1; break; } } if((!j) && !quiet) printk(KERN_ERR "sisfb: Invalid VESA mode 0x%x'\n", vesamode); } static void sisfb_search_mode(char *name, bool quiet) { unsigned int j = 0, xres = 0, yres = 0, depth = 0, rate = 0; int i = 0; char strbuf[16], strbuf1[20]; char *nameptr = name; /* We don't know the hardware specs yet and there is no ivideo */ if(name == NULL) { if(!quiet) printk(KERN_ERR "sisfb: Internal error, using default mode.\n"); sisfb_mode_idx = DEFAULT_MODE; return; } if(!strncasecmp(name, sisbios_mode[MODE_INDEX_NONE].name, strlen(name))) { if(!quiet) printk(KERN_ERR "sisfb: Mode 'none' not supported anymore. Using default.\n"); sisfb_mode_idx = DEFAULT_MODE; return; } if(strlen(name) <= 19) { strcpy(strbuf1, name); for(i = 0; i < strlen(strbuf1); i++) { if(strbuf1[i] < '0' || strbuf1[i] > '9') strbuf1[i] = ' '; } /* This does some fuzzy mode naming detection */ if(sscanf(strbuf1, "%u %u %u %u", &xres, &yres, &depth, &rate) == 4) { if((rate <= 32) || (depth > 32)) { j = rate; rate = depth; depth = j; } sprintf(strbuf, "%ux%ux%u", xres, yres, depth); nameptr = strbuf; sisfb_parm_rate = rate; } else if(sscanf(strbuf1, "%u %u %u", &xres, &yres, &depth) == 3) { sprintf(strbuf, "%ux%ux%u", xres, yres, depth); nameptr = strbuf; } else { xres = 0; if((sscanf(strbuf1, "%u %u", &xres, &yres) == 2) && (xres != 0)) { sprintf(strbuf, "%ux%ux8", xres, yres); nameptr = strbuf; } else { sisfb_search_vesamode(simple_strtoul(name, NULL, 0), quiet); return; } } } i = 0; j = 0; while(sisbios_mode[i].mode_no[0] != 0) { if(!strncasecmp(nameptr, sisbios_mode[i++].name, strlen(nameptr))) { if(sisfb_fstn) { if(sisbios_mode[i-1].mode_no[1] == 0x50 || sisbios_mode[i-1].mode_no[1] == 0x56 || sisbios_mode[i-1].mode_no[1] == 0x53) continue; } else { if(sisbios_mode[i-1].mode_no[1] == 0x5a || sisbios_mode[i-1].mode_no[1] == 0x5b) continue; } sisfb_mode_idx = i - 1; j = 1; break; } } if((!j) && !quiet) printk(KERN_ERR "sisfb: Invalid mode '%s'\n", nameptr); } #ifndef MODULE static void sisfb_get_vga_mode_from_kernel(void) { #ifdef CONFIG_X86 char mymode[32]; int mydepth = screen_info.lfb_depth; if(screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) return; if( (screen_info.lfb_width >= 320) && (screen_info.lfb_width <= 2048) && (screen_info.lfb_height >= 200) && (screen_info.lfb_height <= 1536) && (mydepth >= 8) && (mydepth <= 32) ) { if(mydepth == 24) mydepth = 32; sprintf(mymode, "%ux%ux%u", screen_info.lfb_width, screen_info.lfb_height, mydepth); printk(KERN_DEBUG "sisfb: Using vga mode %s pre-set by kernel as default\n", mymode); sisfb_search_mode(mymode, true); } #endif return; } #endif static void __init sisfb_search_crt2type(const char *name) { int i = 0; /* We don't know the hardware specs yet and there is no ivideo */ if(name == NULL) return; while(sis_crt2type[i].type_no != -1) { if(!strncasecmp(name, sis_crt2type[i].name, strlen(sis_crt2type[i].name))) { sisfb_crt2type = sis_crt2type[i].type_no; sisfb_tvplug = sis_crt2type[i].tvplug_no; sisfb_crt2flags = sis_crt2type[i].flags; break; } i++; } sisfb_dstn = (sisfb_crt2flags & FL_550_DSTN) ? 1 : 0; sisfb_fstn = (sisfb_crt2flags & FL_550_FSTN) ? 1 : 0; if(sisfb_crt2type < 0) printk(KERN_ERR "sisfb: Invalid CRT2 type: %s\n", name); } static void __init sisfb_search_tvstd(const char *name) { int i = 0; /* We don't know the hardware specs yet and there is no ivideo */ if(name == NULL) return; while(sis_tvtype[i].type_no != -1) { if(!strncasecmp(name, sis_tvtype[i].name, strlen(sis_tvtype[i].name))) { sisfb_tvstd = sis_tvtype[i].type_no; break; } i++; } } static void __init sisfb_search_specialtiming(const char *name) { int i = 0; bool found = false; /* We don't know the hardware specs yet and there is no ivideo */ if(name == NULL) return; if(!strncasecmp(name, "none", 4)) { sisfb_specialtiming = CUT_FORCENONE; printk(KERN_DEBUG "sisfb: Special timing disabled\n"); } else { while(mycustomttable[i].chipID != 0) { if(!strncasecmp(name,mycustomttable[i].optionName, strlen(mycustomttable[i].optionName))) { sisfb_specialtiming = mycustomttable[i].SpecialID; found = true; printk(KERN_INFO "sisfb: Special timing for %s %s forced (\"%s\")\n", mycustomttable[i].vendorName, mycustomttable[i].cardName, mycustomttable[i].optionName); break; } i++; } if(!found) { printk(KERN_WARNING "sisfb: Invalid SpecialTiming parameter, valid are:"); printk(KERN_WARNING "\t\"none\" (to disable special timings)\n"); i = 0; while(mycustomttable[i].chipID != 0) { printk(KERN_WARNING "\t\"%s\" (for %s %s)\n", mycustomttable[i].optionName, mycustomttable[i].vendorName, mycustomttable[i].cardName); i++; } } } } /* ----------- Various detection routines ----------- */ static void sisfb_detect_custom_timing(struct sis_video_info *ivideo) { unsigned char *biosver = NULL; unsigned char *biosdate = NULL; bool footprint; u32 chksum = 0; int i, j; if(ivideo->SiS_Pr.UseROM) { biosver = ivideo->SiS_Pr.VirtualRomBase + 0x06; biosdate = ivideo->SiS_Pr.VirtualRomBase + 0x2c; for(i = 0; i < 32768; i++) chksum += ivideo->SiS_Pr.VirtualRomBase[i]; } i = 0; do { if( (mycustomttable[i].chipID == ivideo->chip) && ((!strlen(mycustomttable[i].biosversion)) || (ivideo->SiS_Pr.UseROM && (!strncmp(mycustomttable[i].biosversion, biosver, strlen(mycustomttable[i].biosversion))))) && ((!strlen(mycustomttable[i].biosdate)) || (ivideo->SiS_Pr.UseROM && (!strncmp(mycustomttable[i].biosdate, biosdate, strlen(mycustomttable[i].biosdate))))) && ((!mycustomttable[i].bioschksum) || (ivideo->SiS_Pr.UseROM && (mycustomttable[i].bioschksum == chksum))) && (mycustomttable[i].pcisubsysvendor == ivideo->subsysvendor) && (mycustomttable[i].pcisubsyscard == ivideo->subsysdevice) ) { footprint = true; for(j = 0; j < 5; j++) { if(mycustomttable[i].biosFootprintAddr[j]) { if(ivideo->SiS_Pr.UseROM) { if(ivideo->SiS_Pr.VirtualRomBase[mycustomttable[i].biosFootprintAddr[j]] != mycustomttable[i].biosFootprintData[j]) { footprint = false; } } else footprint = false; } } if(footprint) { ivideo->SiS_Pr.SiS_CustomT = mycustomttable[i].SpecialID; printk(KERN_DEBUG "sisfb: Identified [%s %s], special timing applies\n", mycustomttable[i].vendorName, mycustomttable[i].cardName); printk(KERN_DEBUG "sisfb: [specialtiming parameter name: %s]\n", mycustomttable[i].optionName); break; } } i++; } while(mycustomttable[i].chipID); } static bool sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer) { int i, j, xres, yres, refresh, index; u32 emodes; if(buffer[0] != 0x00 || buffer[1] != 0xff || buffer[2] != 0xff || buffer[3] != 0xff || buffer[4] != 0xff || buffer[5] != 0xff || buffer[6] != 0xff || buffer[7] != 0x00) { printk(KERN_DEBUG "sisfb: Bad EDID header\n"); return false; } if(buffer[0x12] != 0x01) { printk(KERN_INFO "sisfb: EDID version %d not supported\n", buffer[0x12]); return false; } monitor->feature = buffer[0x18]; if(!(buffer[0x14] & 0x80)) { if(!(buffer[0x14] & 0x08)) { printk(KERN_INFO "sisfb: WARNING: Monitor does not support separate syncs\n"); } } if(buffer[0x13] >= 0x01) { /* EDID V1 rev 1 and 2: Search for monitor descriptor * to extract ranges */ j = 0x36; for(i=0; i<4; i++) { if(buffer[j] == 0x00 && buffer[j + 1] == 0x00 && buffer[j + 2] == 0x00 && buffer[j + 3] == 0xfd && buffer[j + 4] == 0x00) { monitor->hmin = buffer[j + 7]; monitor->hmax = buffer[j + 8]; monitor->vmin = buffer[j + 5]; monitor->vmax = buffer[j + 6]; monitor->dclockmax = buffer[j + 9] * 10 * 1000; monitor->datavalid = true; break; } j += 18; } } if(!monitor->datavalid) { /* Otherwise: Get a range from the list of supported * Estabished Timings. This is not entirely accurate, * because fixed frequency monitors are not supported * that way. */ monitor->hmin = 65535; monitor->hmax = 0; monitor->vmin = 65535; monitor->vmax = 0; monitor->dclockmax = 0; emodes = buffer[0x23] | (buffer[0x24] << 8) | (buffer[0x25] << 16); for(i = 0; i < 13; i++) { if(emodes & sisfb_ddcsmodes[i].mask) { if(monitor->hmin > sisfb_ddcsmodes[i].h) monitor->hmin = sisfb_ddcsmodes[i].h; if(monitor->hmax < sisfb_ddcsmodes[i].h) monitor->hmax = sisfb_ddcsmodes[i].h + 1; if(monitor->vmin > sisfb_ddcsmodes[i].v) monitor->vmin = sisfb_ddcsmodes[i].v; if(monitor->vmax < sisfb_ddcsmodes[i].v) monitor->vmax = sisfb_ddcsmodes[i].v; if(monitor->dclockmax < sisfb_ddcsmodes[i].d) monitor->dclockmax = sisfb_ddcsmodes[i].d; } } index = 0x26; for(i = 0; i < 8; i++) { xres = (buffer[index] + 31) * 8; switch(buffer[index + 1] & 0xc0) { case 0xc0: yres = (xres * 9) / 16; break; case 0x80: yres = (xres * 4) / 5; break; case 0x40: yres = (xres * 3) / 4; break; default: yres = xres; break; } refresh = (buffer[index + 1] & 0x3f) + 60; if((xres >= 640) && (yres >= 480)) { for(j = 0; j < 8; j++) { if((xres == sisfb_ddcfmodes[j].x) && (yres == sisfb_ddcfmodes[j].y) && (refresh == sisfb_ddcfmodes[j].v)) { if(monitor->hmin > sisfb_ddcfmodes[j].h) monitor->hmin = sisfb_ddcfmodes[j].h; if(monitor->hmax < sisfb_ddcfmodes[j].h) monitor->hmax = sisfb_ddcfmodes[j].h + 1; if(monitor->vmin > sisfb_ddcsmodes[j].v) monitor->vmin = sisfb_ddcsmodes[j].v; if(monitor->vmax < sisfb_ddcsmodes[j].v) monitor->vmax = sisfb_ddcsmodes[j].v; if(monitor->dclockmax < sisfb_ddcsmodes[j].d) monitor->dclockmax = sisfb_ddcsmodes[j].d; } } } index += 2; } if((monitor->hmin <= monitor->hmax) && (monitor->vmin <= monitor->vmax)) { monitor->datavalid = true; } } return monitor->datavalid; } static void sisfb_handle_ddc(struct sis_video_info *ivideo, struct sisfb_monitor *monitor, int crtno) { unsigned short temp, i, realcrtno = crtno; unsigned char buffer[256]; monitor->datavalid = false; if(crtno) { if(ivideo->vbflags & CRT2_LCD) realcrtno = 1; else if(ivideo->vbflags & CRT2_VGA) realcrtno = 2; else return; } if((ivideo->sisfb_crt1off) && (!crtno)) return; temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine, realcrtno, 0, &buffer[0], ivideo->vbflags2); if((!temp) || (temp == 0xffff)) { printk(KERN_INFO "sisfb: CRT%d DDC probing failed\n", crtno + 1); return; } else { printk(KERN_INFO "sisfb: CRT%d DDC supported\n", crtno + 1); printk(KERN_INFO "sisfb: CRT%d DDC level: %s%s%s%s\n", crtno + 1, (temp & 0x1a) ? "" : "[none of the supported]", (temp & 0x02) ? "2 " : "", (temp & 0x08) ? "D&P" : "", (temp & 0x10) ? "FPDI-2" : ""); if(temp & 0x02) { i = 3; /* Number of retrys */ do { temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine, realcrtno, 1, &buffer[0], ivideo->vbflags2); } while((temp) && i--); if(!temp) { if(sisfb_interpret_edid(monitor, &buffer[0])) { printk(KERN_INFO "sisfb: Monitor range H %d-%dKHz, V %d-%dHz, Max. dotclock %dMHz\n", monitor->hmin, monitor->hmax, monitor->vmin, monitor->vmax, monitor->dclockmax / 1000); } else { printk(KERN_INFO "sisfb: CRT%d DDC EDID corrupt\n", crtno + 1); } } else { printk(KERN_INFO "sisfb: CRT%d DDC reading failed\n", crtno + 1); } } else { printk(KERN_INFO "sisfb: VESA D&P and FPDI-2 not supported yet\n"); } } } /* -------------- Mode validation --------------- */ static bool sisfb_verify_rate(struct sis_video_info *ivideo, struct sisfb_monitor *monitor, int mode_idx, int rate_idx, int rate) { int htotal, vtotal; unsigned int dclock, hsync; if(!monitor->datavalid) return true; if(mode_idx < 0) return false; /* Skip for 320x200, 320x240, 640x400 */ switch(sisbios_mode[mode_idx].mode_no[ivideo->mni]) { case 0x59: case 0x41: case 0x4f: case 0x50: case 0x56: case 0x53: case 0x2f: case 0x5d: case 0x5e: return true; #ifdef CONFIG_FB_SIS_315 case 0x5a: case 0x5b: if(ivideo->sisvga_engine == SIS_315_VGA) return true; #endif } if(rate < (monitor->vmin - 1)) return false; if(rate > (monitor->vmax + 1)) return false; if(sisfb_gettotalfrommode(&ivideo->SiS_Pr, sisbios_mode[mode_idx].mode_no[ivideo->mni], &htotal, &vtotal, rate_idx)) { dclock = (htotal * vtotal * rate) / 1000; if(dclock > (monitor->dclockmax + 1000)) return false; hsync = dclock / htotal; if(hsync < (monitor->hmin - 1)) return false; if(hsync > (monitor->hmax + 1)) return false; } else { return false; } return true; } static int sisfb_validate_mode(struct sis_video_info *ivideo, int myindex, u32 vbflags) { u16 xres=0, yres, myres; #ifdef CONFIG_FB_SIS_300 if(ivideo->sisvga_engine == SIS_300_VGA) { if(!(sisbios_mode[myindex].chipset & MD_SIS300)) return -1 ; } #endif #ifdef CONFIG_FB_SIS_315 if(ivideo->sisvga_engine == SIS_315_VGA) { if(!(sisbios_mode[myindex].chipset & MD_SIS315)) return -1; } #endif myres = sisbios_mode[myindex].yres; switch(vbflags & VB_DISPTYPE_DISP2) { case CRT2_LCD: xres = ivideo->lcdxres; yres = ivideo->lcdyres; if((ivideo->SiS_Pr.SiS_CustomT != CUT_PANEL848) && (ivideo->SiS_Pr.SiS_CustomT != CUT_PANEL856)) { if(sisbios_mode[myindex].xres > xres) return -1; if(myres > yres) return -1; } if(ivideo->sisfb_fstn) { if(sisbios_mode[myindex].xres == 320) { if(myres == 240) { switch(sisbios_mode[myindex].mode_no[1]) { case 0x50: myindex = MODE_FSTN_8; break; case 0x56: myindex = MODE_FSTN_16; break; case 0x53: return -1; } } } } if(SiS_GetModeID_LCD(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres, sisbios_mode[myindex].yres, 0, ivideo->sisfb_fstn, ivideo->SiS_Pr.SiS_CustomT, xres, yres, ivideo->vbflags2) < 0x14) { return -1; } break; case CRT2_TV: if(SiS_GetModeID_TV(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres, sisbios_mode[myindex].yres, 0, ivideo->vbflags2) < 0x14) { return -1; } break; case CRT2_VGA: if(SiS_GetModeID_VGA2(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres, sisbios_mode[myindex].yres, 0, ivideo->vbflags2) < 0x14) { return -1; } break; } return myindex; } static u8 sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate, int mode_idx) { int i = 0; u16 xres = sisbios_mode[mode_idx].xres; u16 yres = sisbios_mode[mode_idx].yres; ivideo->rate_idx = 0; while((sisfb_vrate[i].idx != 0) && (sisfb_vrate[i].xres <= xres)) { if((sisfb_vrate[i].xres == xres) && (sisfb_vrate[i].yres == yres)) { if(sisfb_vrate[i].refresh == rate) { ivideo->rate_idx = sisfb_vrate[i].idx; break; } else if(sisfb_vrate[i].refresh > rate) { if((sisfb_vrate[i].refresh - rate) <= 3) { DPRINTK("sisfb: Adjusting rate from %d up to %d\n", rate, sisfb_vrate[i].refresh); ivideo->rate_idx = sisfb_vrate[i].idx; ivideo->refresh_rate = sisfb_vrate[i].refresh; } else if((sisfb_vrate[i].idx != 1) && ((rate - sisfb_vrate[i-1].refresh) <= 2)) { DPRINTK("sisfb: Adjusting rate from %d down to %d\n", rate, sisfb_vrate[i-1].refresh); ivideo->rate_idx = sisfb_vrate[i-1].idx; ivideo->refresh_rate = sisfb_vrate[i-1].refresh; } break; } else if((rate - sisfb_vrate[i].refresh) <= 2) { DPRINTK("sisfb: Adjusting rate from %d down to %d\n", rate, sisfb_vrate[i].refresh); ivideo->rate_idx = sisfb_vrate[i].idx; break; } } i++; } if(ivideo->rate_idx > 0) { return ivideo->rate_idx; } else { printk(KERN_INFO "sisfb: Unsupported rate %d for %dx%d\n", rate, xres, yres); return 0; } } static bool sisfb_bridgeisslave(struct sis_video_info *ivideo) { unsigned char P1_00; if(!(ivideo->vbflags2 & VB2_VIDEOBRIDGE)) return false; P1_00 = SiS_GetReg(SISPART1, 0x00); if( ((ivideo->sisvga_engine == SIS_300_VGA) && (P1_00 & 0xa0) == 0x20) || ((ivideo->sisvga_engine == SIS_315_VGA) && (P1_00 & 0x50) == 0x10) ) { return true; } else { return false; } } static bool sisfballowretracecrt1(struct sis_video_info *ivideo) { u8 temp; temp = SiS_GetReg(SISCR, 0x17); if(!(temp & 0x80)) return false; temp = SiS_GetReg(SISSR, 0x1f); if(temp & 0xc0) return false; return true; } static bool sisfbcheckvretracecrt1(struct sis_video_info *ivideo) { if(!sisfballowretracecrt1(ivideo)) return false; if (SiS_GetRegByte(SISINPSTAT) & 0x08) return true; else return false; } static void sisfbwaitretracecrt1(struct sis_video_info *ivideo) { int watchdog; if(!sisfballowretracecrt1(ivideo)) return; watchdog = 65536; while ((!(SiS_GetRegByte(SISINPSTAT) & 0x08)) && --watchdog); watchdog = 65536; while ((SiS_GetRegByte(SISINPSTAT) & 0x08) && --watchdog); } static bool sisfbcheckvretracecrt2(struct sis_video_info *ivideo) { unsigned char temp, reg; switch(ivideo->sisvga_engine) { case SIS_300_VGA: reg = 0x25; break; case SIS_315_VGA: reg = 0x30; break; default: return false; } temp = SiS_GetReg(SISPART1, reg); if(temp & 0x02) return true; else return false; } static bool sisfb_CheckVBRetrace(struct sis_video_info *ivideo) { if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) { if(!sisfb_bridgeisslave(ivideo)) { return sisfbcheckvretracecrt2(ivideo); } } return sisfbcheckvretracecrt1(ivideo); } static u32 sisfb_setupvbblankflags(struct sis_video_info *ivideo, u32 *vcount, u32 *hcount) { u8 idx, reg1, reg2, reg3, reg4; u32 ret = 0; (*vcount) = (*hcount) = 0; if((ivideo->currentvbflags & VB_DISPTYPE_DISP2) && (!(sisfb_bridgeisslave(ivideo)))) { ret |= (FB_VBLANK_HAVE_VSYNC | FB_VBLANK_HAVE_HBLANK | FB_VBLANK_HAVE_VBLANK | FB_VBLANK_HAVE_VCOUNT | FB_VBLANK_HAVE_HCOUNT); switch(ivideo->sisvga_engine) { case SIS_300_VGA: idx = 0x25; break; default: case SIS_315_VGA: idx = 0x30; break; } reg1 = SiS_GetReg(SISPART1, (idx+0)); /* 30 */ reg2 = SiS_GetReg(SISPART1, (idx+1)); /* 31 */ reg3 = SiS_GetReg(SISPART1, (idx+2)); /* 32 */ reg4 = SiS_GetReg(SISPART1, (idx+3)); /* 33 */ if(reg1 & 0x01) ret |= FB_VBLANK_VBLANKING; if(reg1 & 0x02) ret |= FB_VBLANK_VSYNCING; if(reg4 & 0x80) ret |= FB_VBLANK_HBLANKING; (*vcount) = reg3 | ((reg4 & 0x70) << 4); (*hcount) = reg2 | ((reg4 & 0x0f) << 8); } else if(sisfballowretracecrt1(ivideo)) { ret |= (FB_VBLANK_HAVE_VSYNC | FB_VBLANK_HAVE_VBLANK | FB_VBLANK_HAVE_VCOUNT | FB_VBLANK_HAVE_HCOUNT); reg1 = SiS_GetRegByte(SISINPSTAT); if(reg1 & 0x08) ret |= FB_VBLANK_VSYNCING; if(reg1 & 0x01) ret |= FB_VBLANK_VBLANKING; reg1 = SiS_GetReg(SISCR, 0x20); reg1 = SiS_GetReg(SISCR, 0x1b); reg2 = SiS_GetReg(SISCR, 0x1c); reg3 = SiS_GetReg(SISCR, 0x1d); (*vcount) = reg2 | ((reg3 & 0x07) << 8); (*hcount) = (reg1 | ((reg3 & 0x10) << 4)) << 3; } return ret; } static int sisfb_myblank(struct sis_video_info *ivideo, int blank) { u8 sr01, sr11, sr1f, cr63=0, p2_0, p1_13; bool backlight = true; switch(blank) { case FB_BLANK_UNBLANK: /* on */ sr01 = 0x00; sr11 = 0x00; sr1f = 0x00; cr63 = 0x00; p2_0 = 0x20; p1_13 = 0x00; backlight = true; break; case FB_BLANK_NORMAL: /* blank */ sr01 = 0x20; sr11 = 0x00; sr1f = 0x00; cr63 = 0x00; p2_0 = 0x20; p1_13 = 0x00; backlight = true; break; case FB_BLANK_VSYNC_SUSPEND: /* no vsync */ sr01 = 0x20; sr11 = 0x08; sr1f = 0x80; cr63 = 0x40; p2_0 = 0x40; p1_13 = 0x80; backlight = false; break; case FB_BLANK_HSYNC_SUSPEND: /* no hsync */ sr01 = 0x20; sr11 = 0x08; sr1f = 0x40; cr63 = 0x40; p2_0 = 0x80; p1_13 = 0x40; backlight = false; break; case FB_BLANK_POWERDOWN: /* off */ sr01 = 0x20; sr11 = 0x08; sr1f = 0xc0; cr63 = 0x40; p2_0 = 0xc0; p1_13 = 0xc0; backlight = false; break; default: return 1; } if(ivideo->currentvbflags & VB_DISPTYPE_CRT1) { if( (!ivideo->sisfb_thismonitor.datavalid) || ((ivideo->sisfb_thismonitor.datavalid) && (ivideo->sisfb_thismonitor.feature & 0xe0))) { if(ivideo->sisvga_engine == SIS_315_VGA) { SiS_SetRegANDOR(SISCR, ivideo->SiS_Pr.SiS_MyCR63, 0xbf, cr63); } if(!(sisfb_bridgeisslave(ivideo))) { SiS_SetRegANDOR(SISSR, 0x01, ~0x20, sr01); SiS_SetRegANDOR(SISSR, 0x1f, 0x3f, sr1f); } } } if(ivideo->currentvbflags & CRT2_LCD) { if(ivideo->vbflags2 & VB2_SISLVDSBRIDGE) { if(backlight) { SiS_SiS30xBLOn(&ivideo->SiS_Pr); } else { SiS_SiS30xBLOff(&ivideo->SiS_Pr); } } else if(ivideo->sisvga_engine == SIS_315_VGA) { #ifdef CONFIG_FB_SIS_315 if(ivideo->vbflags2 & VB2_CHRONTEL) { if(backlight) { SiS_Chrontel701xBLOn(&ivideo->SiS_Pr); } else { SiS_Chrontel701xBLOff(&ivideo->SiS_Pr); } } #endif } if(((ivideo->sisvga_engine == SIS_300_VGA) && (ivideo->vbflags2 & (VB2_301|VB2_30xBDH|VB2_LVDS))) || ((ivideo->sisvga_engine == SIS_315_VGA) && ((ivideo->vbflags2 & (VB2_LVDS | VB2_CHRONTEL)) == VB2_LVDS))) { SiS_SetRegANDOR(SISSR, 0x11, ~0x0c, sr11); } if(ivideo->sisvga_engine == SIS_300_VGA) { if((ivideo->vbflags2 & VB2_30xB) && (!(ivideo->vbflags2 & VB2_30xBDH))) { SiS_SetRegANDOR(SISPART1, 0x13, 0x3f, p1_13); } } else if(ivideo->sisvga_engine == SIS_315_VGA) { if((ivideo->vbflags2 & VB2_30xB) && (!(ivideo->vbflags2 & VB2_30xBDH))) { SiS_SetRegANDOR(SISPART2, 0x00, 0x1f, p2_0); } } } else if(ivideo->currentvbflags & CRT2_VGA) { if(ivideo->vbflags2 & VB2_30xB) { SiS_SetRegANDOR(SISPART2, 0x00, 0x1f, p2_0); } } return 0; } /* ------------- Callbacks from init.c/init301.c -------------- */ #ifdef CONFIG_FB_SIS_300 unsigned int sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg) { struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo; u32 val = 0; pci_read_config_dword(ivideo->nbridge, reg, &val); return (unsigned int)val; } void sisfb_write_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg, unsigned int val) { struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo; pci_write_config_dword(ivideo->nbridge, reg, (u32)val); } unsigned int sisfb_read_lpc_pci_dword(struct SiS_Private *SiS_Pr, int reg) { struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo; u32 val = 0; if(!ivideo->lpcdev) return 0; pci_read_config_dword(ivideo->lpcdev, reg, &val); return (unsigned int)val; } #endif #ifdef CONFIG_FB_SIS_315 void sisfb_write_nbridge_pci_byte(struct SiS_Private *SiS_Pr, int reg, unsigned char val) { struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo; pci_write_config_byte(ivideo->nbridge, reg, (u8)val); } unsigned int sisfb_read_mio_pci_word(struct SiS_Private *SiS_Pr, int reg) { struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo; u16 val = 0; if(!ivideo->lpcdev) return 0; pci_read_config_word(ivideo->lpcdev, reg, &val); return (unsigned int)val; } #endif /* ----------- FBDev related routines for all series ----------- */ static int sisfb_get_cmap_len(const struct fb_var_screeninfo *var) { return (var->bits_per_pixel == 8) ? 256 : 16; } static void sisfb_set_vparms(struct sis_video_info *ivideo) { switch(ivideo->video_bpp) { case 8: ivideo->DstColor = 0x0000; ivideo->SiS310_AccelDepth = 0x00000000; ivideo->video_cmap_len = 256; break; case 16: ivideo->DstColor = 0x8000; ivideo->SiS310_AccelDepth = 0x00010000; ivideo->video_cmap_len = 16; break; case 32: ivideo->DstColor = 0xC000; ivideo->SiS310_AccelDepth = 0x00020000; ivideo->video_cmap_len = 16; break; default: ivideo->video_cmap_len = 16; printk(KERN_ERR "sisfb: Unsupported depth %d", ivideo->video_bpp); ivideo->accel = 0; } } static int sisfb_calc_maxyres(struct sis_video_info *ivideo, struct fb_var_screeninfo *var) { int maxyres = ivideo->sisfb_mem / (var->xres_virtual * (var->bits_per_pixel >> 3)); if(maxyres > 32767) maxyres = 32767; return maxyres; } static void sisfb_calc_pitch(struct sis_video_info *ivideo, struct fb_var_screeninfo *var) { ivideo->video_linelength = var->xres_virtual * (var->bits_per_pixel >> 3); ivideo->scrnpitchCRT1 = ivideo->video_linelength; if(!(ivideo->currentvbflags & CRT1_LCDA)) { if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) { ivideo->scrnpitchCRT1 <<= 1; } } } static void sisfb_set_pitch(struct sis_video_info *ivideo) { bool isslavemode = false; unsigned short HDisplay1 = ivideo->scrnpitchCRT1 >> 3; unsigned short HDisplay2 = ivideo->video_linelength >> 3; if(sisfb_bridgeisslave(ivideo)) isslavemode = true; /* We need to set pitch for CRT1 if bridge is in slave mode, too */ if((ivideo->currentvbflags & VB_DISPTYPE_DISP1) || (isslavemode)) { SiS_SetReg(SISCR, 0x13, (HDisplay1 & 0xFF)); SiS_SetRegANDOR(SISSR, 0x0E, 0xF0, (HDisplay1 >> 8)); } /* We must not set the pitch for CRT2 if bridge is in slave mode */ if((ivideo->currentvbflags & VB_DISPTYPE_DISP2) && (!isslavemode)) { SiS_SetRegOR(SISPART1, ivideo->CRT2_write_enable, 0x01); SiS_SetReg(SISPART1, 0x07, (HDisplay2 & 0xFF)); SiS_SetRegANDOR(SISPART1, 0x09, 0xF0, (HDisplay2 >> 8)); } } static void sisfb_bpp_to_var(struct sis_video_info *ivideo, struct fb_var_screeninfo *var) { ivideo->video_cmap_len = sisfb_get_cmap_len(var); switch(var->bits_per_pixel) { case 8: var->red.offset = var->green.offset = var->blue.offset = 0; var->red.length = var->green.length = var->blue.length = 8; break; case 16: var->red.offset = 11; var->red.length = 5; var->green.offset = 5; var->green.length = 6; var->blue.offset = 0; var->blue.length = 5; var->transp.offset = 0; var->transp.length = 0; break; case 32: var->red.offset = 16; var->red.length = 8; var->green.offset = 8; var->green.length = 8; var->blue.offset = 0; var->blue.length = 8; var->transp.offset = 24; var->transp.length = 8; break; } } static int sisfb_set_mode(struct sis_video_info *ivideo, int clrscrn) { unsigned short modeno = ivideo->mode_no; /* >=2.6.12's fbcon clears the screen anyway */ modeno |= 0x80; SiS_SetReg(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD); sisfb_pre_setmode(ivideo); if(!SiSSetMode(&ivideo->SiS_Pr, modeno)) { printk(KERN_ERR "sisfb: Setting mode[0x%x] failed\n", ivideo->mode_no); return -EINVAL; } SiS_SetReg(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD); sisfb_post_setmode(ivideo); return 0; } static int sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *info) { struct sis_video_info *ivideo = (struct sis_video_info *)info->par; unsigned int htotal = 0, vtotal = 0; unsigned int drate = 0, hrate = 0; int found_mode = 0, ret; int old_mode; u32 pixclock; htotal = var->left_margin + var->xres + var->right_margin + var->hsync_len; vtotal = var->upper_margin + var->lower_margin + var->vsync_len; pixclock = var->pixclock; if((var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED) { vtotal += var->yres; vtotal <<= 1; } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) { vtotal += var->yres; vtotal <<= 2; } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) { vtotal += var->yres; vtotal <<= 1; } else vtotal += var->yres; if(!(htotal) || !(vtotal)) { DPRINTK("sisfb: Invalid 'var' information\n"); return -EINVAL; } if(pixclock && htotal && vtotal) { drate = 1000000000 / pixclock; hrate = (drate * 1000) / htotal; ivideo->refresh_rate = (unsigned int) (hrate * 2 / vtotal); } else { ivideo->refresh_rate = 60; } old_mode = ivideo->sisfb_mode_idx; ivideo->sisfb_mode_idx = 0; while( (sisbios_mode[ivideo->sisfb_mode_idx].mode_no[0] != 0) && (sisbios_mode[ivideo->sisfb_mode_idx].xres <= var->xres) ) { if( (sisbios_mode[ivideo->sisfb_mode_idx].xres == var->xres) && (sisbios_mode[ivideo->sisfb_mode_idx].yres == var->yres) && (sisbios_mode[ivideo->sisfb_mode_idx].bpp == var->bits_per_pixel)) { ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]; found_mode = 1; break; } ivideo->sisfb_mode_idx++; } if(found_mode) { ivideo->sisfb_mode_idx = sisfb_validate_mode(ivideo, ivideo->sisfb_mode_idx, ivideo->currentvbflags); } else { ivideo->sisfb_mode_idx = -1; } if(ivideo->sisfb_mode_idx < 0) { printk(KERN_ERR "sisfb: Mode %dx%dx%d not supported\n", var->xres, var->yres, var->bits_per_pixel); ivideo->sisfb_mode_idx = old_mode; return -EINVAL; } ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]; if(sisfb_search_refresh_rate(ivideo, ivideo->refresh_rate, ivideo->sisfb_mode_idx) == 0) { ivideo->rate_idx = sisbios_mode[ivideo->sisfb_mode_idx].rate_idx; ivideo->refresh_rate = 60; } if(isactive) { /* If acceleration to be used? Need to know * before pre/post_set_mode() */ ivideo->accel = 0; #if defined(FBINFO_HWACCEL_DISABLED) && defined(FBINFO_HWACCEL_XPAN) #ifdef STUPID_ACCELF_TEXT_SHIT if(var->accel_flags & FB_ACCELF_TEXT) { info->flags &= ~FBINFO_HWACCEL_DISABLED; } else { info->flags |= FBINFO_HWACCEL_DISABLED; } #endif if(!(info->flags & FBINFO_HWACCEL_DISABLED)) ivideo->accel = -1; #else if(var->accel_flags & FB_ACCELF_TEXT) ivideo->accel = -1; #endif if((ret = sisfb_set_mode(ivideo, 1))) { return ret; } ivideo->video_bpp = sisbios_mode[ivideo->sisfb_mode_idx].bpp; ivideo->video_width = sisbios_mode[ivideo->sisfb_mode_idx].xres; ivideo->video_height = sisbios_mode[ivideo->sisfb_mode_idx].yres; sisfb_calc_pitch(ivideo, var); sisfb_set_pitch(ivideo); sisfb_set_vparms(ivideo); ivideo->current_width = ivideo->video_width; ivideo->current_height = ivideo->video_height; ivideo->current_bpp = ivideo->video_bpp; ivideo->current_htotal = htotal; ivideo->current_vtotal = vtotal; ivideo->current_linelength = ivideo->video_linelength; ivideo->current_pixclock = var->pixclock; ivideo->current_refresh_rate = ivideo->refresh_rate; ivideo->sisfb_lastrates[ivideo->mode_no] = ivideo->refresh_rate; } return 0; } static void sisfb_set_base_CRT1(struct sis_video_info *ivideo, unsigned int base) { SiS_SetReg(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD); SiS_SetReg(SISCR, 0x0D, base & 0xFF); SiS_SetReg(SISCR, 0x0C, (base >> 8) & 0xFF); SiS_SetReg(SISSR, 0x0D, (base >> 16) & 0xFF); if(ivideo->sisvga_engine == SIS_315_VGA) { SiS_SetRegANDOR(SISSR, 0x37, 0xFE, (base >> 24) & 0x01); } } static void sisfb_set_base_CRT2(struct sis_video_info *ivideo, unsigned int base) { if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) { SiS_SetRegOR(SISPART1, ivideo->CRT2_write_enable, 0x01); SiS_SetReg(SISPART1, 0x06, (base & 0xFF)); SiS_SetReg(SISPART1, 0x05, ((base >> 8) & 0xFF)); SiS_SetReg(SISPART1, 0x04, ((base >> 16) & 0xFF)); if(ivideo->sisvga_engine == SIS_315_VGA) { SiS_SetRegANDOR(SISPART1, 0x02, 0x7F, ((base >> 24) & 0x01) << 7); } } } static int sisfb_pan_var(struct sis_video_info *ivideo, struct fb_info *info, struct fb_var_screeninfo *var) { ivideo->current_base = var->yoffset * info->var.xres_virtual + var->xoffset; /* calculate base bpp dep. */ switch (info->var.bits_per_pixel) { case 32: break; case 16: ivideo->current_base >>= 1; break; case 8: default: ivideo->current_base >>= 2; break; } ivideo->current_base += (ivideo->video_offset >> 2); sisfb_set_base_CRT1(ivideo, ivideo->current_base); sisfb_set_base_CRT2(ivideo, ivideo->current_base); return 0; } static int sisfb_open(struct fb_info *info, int user) { return 0; } static int sisfb_release(struct fb_info *info, int user) { return 0; } static int sisfb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info) { struct sis_video_info *ivideo = (struct sis_video_info *)info->par; if(regno >= sisfb_get_cmap_len(&info->var)) return 1; switch(info->var.bits_per_pixel) { case 8: SiS_SetRegByte(SISDACA, regno); SiS_SetRegByte(SISDACD, (red >> 10)); SiS_SetRegByte(SISDACD, (green >> 10)); SiS_SetRegByte(SISDACD, (blue >> 10)); if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) { SiS_SetRegByte(SISDAC2A, regno); SiS_SetRegByte(SISDAC2D, (red >> 8)); SiS_SetRegByte(SISDAC2D, (green >> 8)); SiS_SetRegByte(SISDAC2D, (blue >> 8)); } break; case 16: if (regno >= 16) break; ((u32 *)(info->pseudo_palette))[regno] = (red & 0xf800) | ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11); break; case 32: if (regno >= 16) break; red >>= 8; green >>= 8; blue >>= 8; ((u32 *)(info->pseudo_palette))[regno] = (red << 16) | (green << 8) | (blue); break; } return 0; } static int sisfb_set_par(struct fb_info *info) { int err; if((err = sisfb_do_set_var(&info->var, 1, info))) return err; sisfb_get_fix(&info->fix, -1, info); return 0; } static int sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) { struct sis_video_info *ivideo = (struct sis_video_info *)info->par; unsigned int htotal = 0, vtotal = 0, myrateindex = 0; unsigned int drate = 0, hrate = 0, maxyres; int found_mode = 0; int refresh_rate, search_idx, tidx; bool recalc_clock = false; u32 pixclock; htotal = var->left_margin + var->xres + var->right_margin + var->hsync_len; vtotal = var->upper_margin + var->lower_margin + var->vsync_len; pixclock = var->pixclock; if((var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED) { vtotal += var->yres; vtotal <<= 1; } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) { vtotal += var->yres; vtotal <<= 2; } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) { vtotal += var->yres; vtotal <<= 1; } else vtotal += var->yres; if(!(htotal) || !(vtotal)) { SISFAIL("sisfb: no valid timing data"); } search_idx = 0; while( (sisbios_mode[search_idx].mode_no[0] != 0) && (sisbios_mode[search_idx].xres <= var->xres) ) { if( (sisbios_mode[search_idx].xres == var->xres) && (sisbios_mode[search_idx].yres == var->yres) && (sisbios_mode[search_idx].bpp == var->bits_per_pixel)) { if((tidx = sisfb_validate_mode(ivideo, search_idx, ivideo->currentvbflags)) > 0) { found_mode = 1; search_idx = tidx; break; } } search_idx++; } if(!found_mode) { search_idx = 0; while(sisbios_mode[search_idx].mode_no[0] != 0) { if( (var->xres <= sisbios_mode[search_idx].xres) && (var->yres <= sisbios_mode[search_idx].yres) && (var->bits_per_pixel == sisbios_mode[search_idx].bpp) ) { if((tidx = sisfb_validate_mode(ivideo,search_idx, ivideo->currentvbflags)) > 0) { found_mode = 1; search_idx = tidx; break; } } search_idx++; } if(found_mode) { printk(KERN_DEBUG "sisfb: Adapted from %dx%dx%d to %dx%dx%d\n", var->xres, var->yres, var->bits_per_pixel, sisbios_mode[search_idx].xres, sisbios_mode[search_idx].yres, var->bits_per_pixel); var->xres = sisbios_mode[search_idx].xres; var->yres = sisbios_mode[search_idx].yres; } else { printk(KERN_ERR "sisfb: Failed to find supported mode near %dx%dx%d\n", var->xres, var->yres, var->bits_per_pixel); return -EINVAL; } } if( ((ivideo->vbflags2 & VB2_LVDS) || ((ivideo->vbflags2 & VB2_30xBDH) && (ivideo->currentvbflags & CRT2_LCD))) && (var->bits_per_pixel == 8) ) { /* Slave modes on LVDS and 301B-DH */ refresh_rate = 60; recalc_clock = true; } else if( (ivideo->current_htotal == htotal) && (ivideo->current_vtotal == vtotal) && (ivideo->current_pixclock == pixclock) ) { /* x=x & y=y & c=c -> assume depth change */ drate = 1000000000 / pixclock; hrate = (drate * 1000) / htotal; refresh_rate = (unsigned int) (hrate * 2 / vtotal); } else if( ( (ivideo->current_htotal != htotal) || (ivideo->current_vtotal != vtotal) ) && (ivideo->current_pixclock == var->pixclock) ) { /* x!=x | y!=y & c=c -> invalid pixclock */ if(ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]]) { refresh_rate = ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]]; } else if(ivideo->sisfb_parm_rate != -1) { /* Sic, sisfb_parm_rate - want to know originally desired rate here */ refresh_rate = ivideo->sisfb_parm_rate; } else { refresh_rate = 60; } recalc_clock = true; } else if((pixclock) && (htotal) && (vtotal)) { drate = 1000000000 / pixclock; hrate = (drate * 1000) / htotal; refresh_rate = (unsigned int) (hrate * 2 / vtotal); } else if(ivideo->current_refresh_rate) { refresh_rate = ivideo->current_refresh_rate; recalc_clock = true; } else { refresh_rate = 60; recalc_clock = true; } myrateindex = sisfb_search_refresh_rate(ivideo, refresh_rate, search_idx); /* Eventually recalculate timing and clock */ if(recalc_clock) { if(!myrateindex) myrateindex = sisbios_mode[search_idx].rate_idx; var->pixclock = (u32) (1000000000 / sisfb_mode_rate_to_dclock(&ivideo->SiS_Pr, sisbios_mode[search_idx].mode_no[ivideo->mni], myrateindex)); sisfb_mode_rate_to_ddata(&ivideo->SiS_Pr, sisbios_mode[search_idx].mode_no[ivideo->mni], myrateindex, var); if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) { var->pixclock <<= 1; } } if(ivideo->sisfb_thismonitor.datavalid) { if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor, search_idx, myrateindex, refresh_rate)) { printk(KERN_INFO "sisfb: WARNING: Refresh rate exceeds monitor specs!\n"); } } /* Adapt RGB settings */ sisfb_bpp_to_var(ivideo, var); if(var->xres > var->xres_virtual) var->xres_virtual = var->xres; if(ivideo->sisfb_ypan) { maxyres = sisfb_calc_maxyres(ivideo, var); if(ivideo->sisfb_max) { var->yres_virtual = maxyres; } else { if(var->yres_virtual > maxyres) { var->yres_virtual = maxyres; } } if(var->yres_virtual <= var->yres) { var->yres_virtual = var->yres; } } else { if(var->yres != var->yres_virtual) { var->yres_virtual = var->yres; } var->xoffset = 0; var->yoffset = 0; } /* Truncate offsets to maximum if too high */ if(var->xoffset > var->xres_virtual - var->xres) { var->xoffset = var->xres_virtual - var->xres - 1; } if(var->yoffset > var->yres_virtual - var->yres) { var->yoffset = var->yres_virtual - var->yres - 1; } /* Set everything else to 0 */ var->red.msb_right = var->green.msb_right = var->blue.msb_right = var->transp.offset = var->transp.length = var->transp.msb_right = 0; return 0; } static int sisfb_pan_display(struct fb_var_screeninfo *var, struct fb_info* info) { struct sis_video_info *ivideo = (struct sis_video_info *)info->par; int err; if (var->vmode & FB_VMODE_YWRAP) return -EINVAL; if (var->xoffset + info->var.xres > info->var.xres_virtual || var->yoffset + info->var.yres > info->var.yres_virtual) return -EINVAL; err = sisfb_pan_var(ivideo, info, var); if (err < 0) return err; info->var.xoffset = var->xoffset; info->var.yoffset = var->yoffset; return 0; } static int sisfb_blank(int blank, struct fb_info *info) { struct sis_video_info *ivideo = (struct sis_video_info *)info->par; return sisfb_myblank(ivideo, blank); } /* ----------- FBDev related routines for all series ---------- */ static int sisfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) { struct sis_video_info *ivideo = (struct sis_video_info *)info->par; struct sis_memreq sismemreq; struct fb_vblank sisvbblank; u32 gpu32 = 0; #ifndef __user #define __user #endif u32 __user *argp = (u32 __user *)arg; switch(cmd) { case FBIO_ALLOC: if(!capable(CAP_SYS_RAWIO)) return -EPERM; if(copy_from_user(&sismemreq, (void __user *)arg, sizeof(sismemreq))) return -EFAULT; sis_malloc(&sismemreq); if(copy_to_user((void __user *)arg, &sismemreq, sizeof(sismemreq))) { sis_free((u32)sismemreq.offset); return -EFAULT; } break; case FBIO_FREE: if(!capable(CAP_SYS_RAWIO)) return -EPERM; if(get_user(gpu32, argp)) return -EFAULT; sis_free(gpu32); break; case FBIOGET_VBLANK: memset(&sisvbblank, 0, sizeof(struct fb_vblank)); sisvbblank.count = 0; sisvbblank.flags = sisfb_setupvbblankflags(ivideo, &sisvbblank.vcount, &sisvbblank.hcount); if(copy_to_user((void __user *)arg, &sisvbblank, sizeof(sisvbblank))) return -EFAULT; break; case SISFB_GET_INFO_SIZE: return put_user(sizeof(struct sisfb_info), argp); case SISFB_GET_INFO_OLD: if(ivideo->warncount++ < 10) printk(KERN_INFO "sisfb: Deprecated ioctl call received - update your application!\n"); case SISFB_GET_INFO: /* For communication with X driver */ ivideo->sisfb_infoblock.sisfb_id = SISFB_ID; ivideo->sisfb_infoblock.sisfb_version = VER_MAJOR; ivideo->sisfb_infoblock.sisfb_revision = VER_MINOR; ivideo->sisfb_infoblock.sisfb_patchlevel = VER_LEVEL; ivideo->sisfb_infoblock.chip_id = ivideo->chip_id; ivideo->sisfb_infoblock.sisfb_pci_vendor = ivideo->chip_vendor; ivideo->sisfb_infoblock.memory = ivideo->video_size / 1024; ivideo->sisfb_infoblock.heapstart = ivideo->heapstart / 1024; if(ivideo->modechanged) { ivideo->sisfb_infoblock.fbvidmode = ivideo->mode_no; } else { ivideo->sisfb_infoblock.fbvidmode = ivideo->modeprechange; } ivideo->sisfb_infoblock.sisfb_caps = ivideo->caps; ivideo->sisfb_infoblock.sisfb_tqlen = ivideo->cmdQueueSize / 1024; ivideo->sisfb_infoblock.sisfb_pcibus = ivideo->pcibus; ivideo->sisfb_infoblock.sisfb_pcislot = ivideo->pcislot; ivideo->sisfb_infoblock.sisfb_pcifunc = ivideo->pcifunc; ivideo->sisfb_infoblock.sisfb_lcdpdc = ivideo->detectedpdc; ivideo->sisfb_infoblock.sisfb_lcdpdca = ivideo->detectedpdca; ivideo->sisfb_infoblock.sisfb_lcda = ivideo->detectedlcda; ivideo->sisfb_infoblock.sisfb_vbflags = ivideo->vbflags; ivideo->sisfb_infoblock.sisfb_currentvbflags = ivideo->currentvbflags; ivideo->sisfb_infoblock.sisfb_scalelcd = ivideo->SiS_Pr.UsePanelScaler; ivideo->sisfb_infoblock.sisfb_specialtiming = ivideo->SiS_Pr.SiS_CustomT; ivideo->sisfb_infoblock.sisfb_haveemi = ivideo->SiS_Pr.HaveEMI ? 1 : 0; ivideo->sisfb_infoblock.sisfb_haveemilcd = ivideo->SiS_Pr.HaveEMILCD ? 1 : 0; ivideo->sisfb_infoblock.sisfb_emi30 = ivideo->SiS_Pr.EMI_30; ivideo->sisfb_infoblock.sisfb_emi31 = ivideo->SiS_Pr.EMI_31; ivideo->sisfb_infoblock.sisfb_emi32 = ivideo->SiS_Pr.EMI_32; ivideo->sisfb_infoblock.sisfb_emi33 = ivideo->SiS_Pr.EMI_33; ivideo->sisfb_infoblock.sisfb_tvxpos = (u16)(ivideo->tvxpos + 32); ivideo->sisfb_infoblock.sisfb_tvypos = (u16)(ivideo->tvypos + 32); ivideo->sisfb_infoblock.sisfb_heapsize = ivideo->sisfb_heap_size / 1024; ivideo->sisfb_infoblock.sisfb_videooffset = ivideo->video_offset; ivideo->sisfb_infoblock.sisfb_curfstn = ivideo->curFSTN; ivideo->sisfb_infoblock.sisfb_curdstn = ivideo->curDSTN; ivideo->sisfb_infoblock.sisfb_vbflags2 = ivideo->vbflags2; ivideo->sisfb_infoblock.sisfb_can_post = ivideo->sisfb_can_post ? 1 : 0; ivideo->sisfb_infoblock.sisfb_card_posted = ivideo->sisfb_card_posted ? 1 : 0; ivideo->sisfb_infoblock.sisfb_was_boot_device = ivideo->sisfb_was_boot_device ? 1 : 0; if(copy_to_user((void __user *)arg, &ivideo->sisfb_infoblock, sizeof(ivideo->sisfb_infoblock))) return -EFAULT; break; case SISFB_GET_VBRSTATUS_OLD: if(ivideo->warncount++ < 10) printk(KERN_INFO "sisfb: Deprecated ioctl call received - update your application!\n"); case SISFB_GET_VBRSTATUS: if(sisfb_CheckVBRetrace(ivideo)) return put_user((u32)1, argp); else return put_user((u32)0, argp); case SISFB_GET_AUTOMAXIMIZE_OLD: if(ivideo->warncount++ < 10) printk(KERN_INFO "sisfb: Deprecated ioctl call received - update your application!\n"); case SISFB_GET_AUTOMAXIMIZE: if(ivideo->sisfb_max) return put_user((u32)1, argp); else return put_user((u32)0, argp); case SISFB_SET_AUTOMAXIMIZE_OLD: if(ivideo->warncount++ < 10) printk(KERN_INFO "sisfb: Deprecated ioctl call received - update your application!\n"); case SISFB_SET_AUTOMAXIMIZE: if(get_user(gpu32, argp)) return -EFAULT; ivideo->sisfb_max = (gpu32) ? 1 : 0; break; case SISFB_SET_TVPOSOFFSET: if(get_user(gpu32, argp)) return -EFAULT; sisfb_set_TVxposoffset(ivideo, ((int)(gpu32 >> 16)) - 32); sisfb_set_TVyposoffset(ivideo, ((int)(gpu32 & 0xffff)) - 32); break; case SISFB_GET_TVPOSOFFSET: return put_user((u32)(((ivideo->tvxpos+32)<<16)|((ivideo->tvypos+32)&0xffff)), argp); case SISFB_COMMAND: if(copy_from_user(&ivideo->sisfb_command, (void __user *)arg, sizeof(struct sisfb_cmd))) return -EFAULT; sisfb_handle_command(ivideo, &ivideo->sisfb_command); if(copy_to_user((void __user *)arg, &ivideo->sisfb_command, sizeof(struct sisfb_cmd))) return -EFAULT; break; case SISFB_SET_LOCK: if(get_user(gpu32, argp)) return -EFAULT; ivideo->sisfblocked = (gpu32) ? 1 : 0; break; default: #ifdef SIS_NEW_CONFIG_COMPAT return -ENOIOCTLCMD; #else return -EINVAL; #endif } return 0; } static int sisfb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info) { struct sis_video_info *ivideo = (struct sis_video_info *)info->par; memset(fix, 0, sizeof(struct fb_fix_screeninfo)); strlcpy(fix->id, ivideo->myid, sizeof(fix->id)); mutex_lock(&info->mm_lock); fix->smem_start = ivideo->video_base + ivideo->video_offset; fix->smem_len = ivideo->sisfb_mem; mutex_unlock(&info->mm_lock); fix->type = FB_TYPE_PACKED_PIXELS; fix->type_aux = 0; fix->visual = (ivideo->video_bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; fix->xpanstep = 1; fix->ypanstep = (ivideo->sisfb_ypan) ? 1 : 0; fix->ywrapstep = 0; fix->line_length = ivideo->video_linelength; fix->mmio_start = ivideo->mmio_base; fix->mmio_len = ivideo->mmio_size; if(ivideo->sisvga_engine == SIS_300_VGA) { fix->accel = FB_ACCEL_SIS_GLAMOUR; } else if((ivideo->chip == SIS_330) || (ivideo->chip == SIS_760) || (ivideo->chip == SIS_761)) { fix->accel = FB_ACCEL_SIS_XABRE; } else if(ivideo->chip == XGI_20) { fix->accel = FB_ACCEL_XGI_VOLARI_Z; } else if(ivideo->chip >= XGI_40) { fix->accel = FB_ACCEL_XGI_VOLARI_V; } else { fix->accel = FB_ACCEL_SIS_GLAMOUR_2; } return 0; } /* ---------------- fb_ops structures ----------------- */ static struct fb_ops sisfb_ops = { .owner = THIS_MODULE, .fb_open = sisfb_open, .fb_release = sisfb_release, .fb_check_var = sisfb_check_var, .fb_set_par = sisfb_set_par, .fb_setcolreg = sisfb_setcolreg, .fb_pan_display = sisfb_pan_display, .fb_blank = sisfb_blank, .fb_fillrect = fbcon_sis_fillrect, .fb_copyarea = fbcon_sis_copyarea, .fb_imageblit = cfb_imageblit, .fb_sync = fbcon_sis_sync, #ifdef SIS_NEW_CONFIG_COMPAT .fb_compat_ioctl= sisfb_ioctl, #endif .fb_ioctl = sisfb_ioctl }; /* ---------------- Chip generation dependent routines ---------------- */ static struct pci_dev *sisfb_get_northbridge(int basechipid) { struct pci_dev *pdev = NULL; int nbridgenum, nbridgeidx, i; static const unsigned short nbridgeids[] = { PCI_DEVICE_ID_SI_540, /* for SiS 540 VGA */ PCI_DEVICE_ID_SI_630, /* for SiS 630/730 VGA */ PCI_DEVICE_ID_SI_730, PCI_DEVICE_ID_SI_550, /* for SiS 550 VGA */ PCI_DEVICE_ID_SI_650, /* for SiS 650/651/740 VGA */ PCI_DEVICE_ID_SI_651, PCI_DEVICE_ID_SI_740, PCI_DEVICE_ID_SI_661, /* for SiS 661/741/660/760/761 VGA */ PCI_DEVICE_ID_SI_741, PCI_DEVICE_ID_SI_660, PCI_DEVICE_ID_SI_760, PCI_DEVICE_ID_SI_761 }; switch(basechipid) { #ifdef CONFIG_FB_SIS_300 case SIS_540: nbridgeidx = 0; nbridgenum = 1; break; case SIS_630: nbridgeidx = 1; nbridgenum = 2; break; #endif #ifdef CONFIG_FB_SIS_315 case SIS_550: nbridgeidx = 3; nbridgenum = 1; break; case SIS_650: nbridgeidx = 4; nbridgenum = 3; break; case SIS_660: nbridgeidx = 7; nbridgenum = 5; break; #endif default: return NULL; } for(i = 0; i < nbridgenum; i++) { if((pdev = pci_get_device(PCI_VENDOR_ID_SI, nbridgeids[nbridgeidx+i], NULL))) break; } return pdev; } static int sisfb_get_dram_size(struct sis_video_info *ivideo) { #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) u8 reg; #endif ivideo->video_size = 0; ivideo->UMAsize = ivideo->LFBsize = 0; switch(ivideo->chip) { #ifdef CONFIG_FB_SIS_300 case SIS_300: reg = SiS_GetReg(SISSR, 0x14); ivideo->video_size = ((reg & 0x3F) + 1) << 20; break; case SIS_540: case SIS_630: case SIS_730: if(!ivideo->nbridge) return -1; pci_read_config_byte(ivideo->nbridge, 0x63, &reg); ivideo->video_size = 1 << (((reg & 0x70) >> 4) + 21); break; #endif #ifdef CONFIG_FB_SIS_315 case SIS_315H: case SIS_315PRO: case SIS_315: reg = SiS_GetReg(SISSR, 0x14); ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20; switch((reg >> 2) & 0x03) { case 0x01: case 0x03: ivideo->video_size <<= 1; break; case 0x02: ivideo->video_size += (ivideo->video_size/2); } break; case SIS_330: reg = SiS_GetReg(SISSR, 0x14); ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20; if(reg & 0x0c) ivideo->video_size <<= 1; break; case SIS_550: case SIS_650: case SIS_740: reg = SiS_GetReg(SISSR, 0x14); ivideo->video_size = (((reg & 0x3f) + 1) << 2) << 20; break; case SIS_661: case SIS_741: reg = SiS_GetReg(SISCR, 0x79); ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20; break; case SIS_660: case SIS_760: case SIS_761: reg = SiS_GetReg(SISCR, 0x79); reg = (reg & 0xf0) >> 4; if(reg) { ivideo->video_size = (1 << reg) << 20; ivideo->UMAsize = ivideo->video_size; } reg = SiS_GetReg(SISCR, 0x78); reg &= 0x30; if(reg) { if(reg == 0x10) { ivideo->LFBsize = (32 << 20); } else { ivideo->LFBsize = (64 << 20); } ivideo->video_size += ivideo->LFBsize; } break; case SIS_340: case XGI_20: case XGI_40: reg = SiS_GetReg(SISSR, 0x14); ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20; if(ivideo->chip != XGI_20) { reg = (reg & 0x0c) >> 2; if(ivideo->revision_id == 2) { if(reg & 0x01) reg = 0x02; else reg = 0x00; } if(reg == 0x02) ivideo->video_size <<= 1; else if(reg == 0x03) ivideo->video_size <<= 2; } break; #endif default: return -1; } return 0; } /* -------------- video bridge device detection --------------- */ static void sisfb_detect_VB_connect(struct sis_video_info *ivideo) { u8 cr32, temp; /* No CRT2 on XGI Z7 */ if(ivideo->chip == XGI_20) { ivideo->sisfb_crt1off = 0; return; } #ifdef CONFIG_FB_SIS_300 if(ivideo->sisvga_engine == SIS_300_VGA) { temp = SiS_GetReg(SISSR, 0x17); if((temp & 0x0F) && (ivideo->chip != SIS_300)) { /* PAL/NTSC is stored on SR16 on such machines */ if(!(ivideo->vbflags & (TV_PAL | TV_NTSC | TV_PALM | TV_PALN))) { temp = SiS_GetReg(SISSR, 0x16); if(temp & 0x20) ivideo->vbflags |= TV_PAL; else ivideo->vbflags |= TV_NTSC; } } } #endif cr32 = SiS_GetReg(SISCR, 0x32); if(cr32 & SIS_CRT1) { ivideo->sisfb_crt1off = 0; } else { ivideo->sisfb_crt1off = (cr32 & 0xDF) ? 1 : 0; } ivideo->vbflags &= ~(CRT2_TV | CRT2_LCD | CRT2_VGA); if(cr32 & SIS_VB_TV) ivideo->vbflags |= CRT2_TV; if(cr32 & SIS_VB_LCD) ivideo->vbflags |= CRT2_LCD; if(cr32 & SIS_VB_CRT2) ivideo->vbflags |= CRT2_VGA; /* Check given parms for hardware compatibility. * (Cannot do this in the search_xx routines since we don't * know what hardware we are running on then) */ if(ivideo->chip != SIS_550) { ivideo->sisfb_dstn = ivideo->sisfb_fstn = 0; } if(ivideo->sisfb_tvplug != -1) { if( (ivideo->sisvga_engine != SIS_315_VGA) || (!(ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) ) { if(ivideo->sisfb_tvplug & TV_YPBPR) { ivideo->sisfb_tvplug = -1; printk(KERN_ERR "sisfb: YPbPr not supported\n"); } } } if(ivideo->sisfb_tvplug != -1) { if( (ivideo->sisvga_engine != SIS_315_VGA) || (!(ivideo->vbflags2 & VB2_SISHIVISIONBRIDGE)) ) { if(ivideo->sisfb_tvplug & TV_HIVISION) { ivideo->sisfb_tvplug = -1; printk(KERN_ERR "sisfb: HiVision not supported\n"); } } } if(ivideo->sisfb_tvstd != -1) { if( (!(ivideo->vbflags2 & VB2_SISBRIDGE)) && (!((ivideo->sisvga_engine == SIS_315_VGA) && (ivideo->vbflags2 & VB2_CHRONTEL))) ) { if(ivideo->sisfb_tvstd & (TV_PALM | TV_PALN | TV_NTSCJ)) { ivideo->sisfb_tvstd = -1; printk(KERN_ERR "sisfb: PALM/PALN/NTSCJ not supported\n"); } } } /* Detect/set TV plug & type */ if(ivideo->sisfb_tvplug != -1) { ivideo->vbflags |= ivideo->sisfb_tvplug; } else { if(cr32 & SIS_VB_YPBPR) ivideo->vbflags |= (TV_YPBPR|TV_YPBPR525I); /* default: 480i */ else if(cr32 & SIS_VB_HIVISION) ivideo->vbflags |= TV_HIVISION; else if(cr32 & SIS_VB_SCART) ivideo->vbflags |= TV_SCART; else { if(cr32 & SIS_VB_SVIDEO) ivideo->vbflags |= TV_SVIDEO; if(cr32 & SIS_VB_COMPOSITE) ivideo->vbflags |= TV_AVIDEO; } } if(!(ivideo->vbflags & (TV_YPBPR | TV_HIVISION))) { if(ivideo->sisfb_tvstd != -1) { ivideo->vbflags &= ~(TV_NTSC | TV_PAL | TV_PALM | TV_PALN | TV_NTSCJ); ivideo->vbflags |= ivideo->sisfb_tvstd; } if(ivideo->vbflags & TV_SCART) { ivideo->vbflags &= ~(TV_NTSC | TV_PALM | TV_PALN | TV_NTSCJ); ivideo->vbflags |= TV_PAL; } if(!(ivideo->vbflags & (TV_PAL | TV_NTSC | TV_PALM | TV_PALN | TV_NTSCJ))) { if(ivideo->sisvga_engine == SIS_300_VGA) { temp = SiS_GetReg(SISSR, 0x38); if(temp & 0x01) ivideo->vbflags |= TV_PAL; else ivideo->vbflags |= TV_NTSC; } else if((ivideo->chip <= SIS_315PRO) || (ivideo->chip >= SIS_330)) { temp = SiS_GetReg(SISSR, 0x38); if(temp & 0x01) ivideo->vbflags |= TV_PAL; else ivideo->vbflags |= TV_NTSC; } else { temp = SiS_GetReg(SISCR, 0x79); if(temp & 0x20) ivideo->vbflags |= TV_PAL; else ivideo->vbflags |= TV_NTSC; } } } /* Copy forceCRT1 option to CRT1off if option is given */ if(ivideo->sisfb_forcecrt1 != -1) { ivideo->sisfb_crt1off = (ivideo->sisfb_forcecrt1) ? 0 : 1; } } /* ------------------ Sensing routines ------------------ */ static bool sisfb_test_DDC1(struct sis_video_info *ivideo) { unsigned short old; int count = 48; old = SiS_ReadDDC1Bit(&ivideo->SiS_Pr); do { if(old != SiS_ReadDDC1Bit(&ivideo->SiS_Pr)) break; } while(count--); return (count != -1); } static void sisfb_sense_crt1(struct sis_video_info *ivideo) { bool mustwait = false; u8 sr1F, cr17; #ifdef CONFIG_FB_SIS_315 u8 cr63=0; #endif u16 temp = 0xffff; int i; sr1F = SiS_GetReg(SISSR, 0x1F); SiS_SetRegOR(SISSR, 0x1F, 0x04); SiS_SetRegAND(SISSR, 0x1F, 0x3F); if(sr1F & 0xc0) mustwait = true; #ifdef CONFIG_FB_SIS_315 if(ivideo->sisvga_engine == SIS_315_VGA) { cr63 = SiS_GetReg(SISCR, ivideo->SiS_Pr.SiS_MyCR63); cr63 &= 0x40; SiS_SetRegAND(SISCR, ivideo->SiS_Pr.SiS_MyCR63, 0xBF); } #endif cr17 = SiS_GetReg(SISCR, 0x17); cr17 &= 0x80; if(!cr17) { SiS_SetRegOR(SISCR, 0x17, 0x80); mustwait = true; SiS_SetReg(SISSR, 0x00, 0x01); SiS_SetReg(SISSR, 0x00, 0x03); } if(mustwait) { for(i=0; i < 10; i++) sisfbwaitretracecrt1(ivideo); } #ifdef CONFIG_FB_SIS_315 if(ivideo->chip >= SIS_330) { SiS_SetRegAND(SISCR, 0x32, ~0x20); if(ivideo->chip >= SIS_340) { SiS_SetReg(SISCR, 0x57, 0x4a); } else { SiS_SetReg(SISCR, 0x57, 0x5f); } SiS_SetRegOR(SISCR, 0x53, 0x02); while ((SiS_GetRegByte(SISINPSTAT)) & 0x01) break; while (!((SiS_GetRegByte(SISINPSTAT)) & 0x01)) break; if ((SiS_GetRegByte(SISMISCW)) & 0x10) temp = 1; SiS_SetRegAND(SISCR, 0x53, 0xfd); SiS_SetRegAND(SISCR, 0x57, 0x00); } #endif if(temp == 0xffff) { i = 3; do { temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine, 0, 0, NULL, ivideo->vbflags2); } while(((temp == 0) || (temp == 0xffff)) && i--); if((temp == 0) || (temp == 0xffff)) { if(sisfb_test_DDC1(ivideo)) temp = 1; } } if((temp) && (temp != 0xffff)) { SiS_SetRegOR(SISCR, 0x32, 0x20); } #ifdef CONFIG_FB_SIS_315 if(ivideo->sisvga_engine == SIS_315_VGA) { SiS_SetRegANDOR(SISCR, ivideo->SiS_Pr.SiS_MyCR63, 0xBF, cr63); } #endif SiS_SetRegANDOR(SISCR, 0x17, 0x7F, cr17); SiS_SetReg(SISSR, 0x1F, sr1F); } /* Determine and detect attached devices on SiS30x */ static void SiS_SenseLCD(struct sis_video_info *ivideo) { unsigned char buffer[256]; unsigned short temp, realcrtno, i; u8 reg, cr37 = 0, paneltype = 0; u16 xres, yres; ivideo->SiS_Pr.PanelSelfDetected = false; /* LCD detection only for TMDS bridges */ if(!(ivideo->vbflags2 & VB2_SISTMDSBRIDGE)) return; if(ivideo->vbflags2 & VB2_30xBDH) return; /* If LCD already set up by BIOS, skip it */ reg = SiS_GetReg(SISCR, 0x32); if(reg & 0x08) return; realcrtno = 1; if(ivideo->SiS_Pr.DDCPortMixup) realcrtno = 0; /* Check DDC capabilities */ temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine, realcrtno, 0, &buffer[0], ivideo->vbflags2); if((!temp) || (temp == 0xffff) || (!(temp & 0x02))) return; /* Read DDC data */ i = 3; /* Number of retrys */ do { temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine, realcrtno, 1, &buffer[0], ivideo->vbflags2); } while((temp) && i--); if(temp) return; /* No digital device */ if(!(buffer[0x14] & 0x80)) return; /* First detailed timing preferred timing? */ if(!(buffer[0x18] & 0x02)) return; xres = buffer[0x38] | ((buffer[0x3a] & 0xf0) << 4); yres = buffer[0x3b] | ((buffer[0x3d] & 0xf0) << 4); switch(xres) { case 1024: if(yres == 768) paneltype = 0x02; break; case 1280: if(yres == 1024) paneltype = 0x03; break; case 1600: if((yres == 1200) && (ivideo->vbflags2 & VB2_30xC)) paneltype = 0x0b; break; } if(!paneltype) return; if(buffer[0x23]) cr37 |= 0x10; if((buffer[0x47] & 0x18) == 0x18) cr37 |= ((((buffer[0x47] & 0x06) ^ 0x06) << 5) | 0x20); else cr37 |= 0xc0; SiS_SetReg(SISCR, 0x36, paneltype); cr37 &= 0xf1; SiS_SetRegANDOR(SISCR, 0x37, 0x0c, cr37); SiS_SetRegOR(SISCR, 0x32, 0x08); ivideo->SiS_Pr.PanelSelfDetected = true; } static int SISDoSense(struct sis_video_info *ivideo, u16 type, u16 test) { int temp, mytest, result, i, j; for(j = 0; j < 10; j++) { result = 0; for(i = 0; i < 3; i++) { mytest = test; SiS_SetReg(SISPART4, 0x11, (type & 0x00ff)); temp = (type >> 8) | (mytest & 0x00ff); SiS_SetRegANDOR(SISPART4, 0x10, 0xe0, temp); SiS_DDC2Delay(&ivideo->SiS_Pr, 0x1500); mytest >>= 8; mytest &= 0x7f; temp = SiS_GetReg(SISPART4, 0x03); temp ^= 0x0e; temp &= mytest; if(temp == mytest) result++; #if 1 SiS_SetReg(SISPART4, 0x11, 0x00); SiS_SetRegAND(SISPART4, 0x10, 0xe0); SiS_DDC2Delay(&ivideo->SiS_Pr, 0x1000); #endif } if((result == 0) || (result >= 2)) break; } return result; } static void SiS_Sense30x(struct sis_video_info *ivideo) { u8 backupP4_0d,backupP2_00,backupP2_4d,backupSR_1e,biosflag=0; u16 svhs=0, svhs_c=0; u16 cvbs=0, cvbs_c=0; u16 vga2=0, vga2_c=0; int myflag, result; char stdstr[] = "sisfb: Detected"; char tvstr[] = "TV connected to"; if(ivideo->vbflags2 & VB2_301) { svhs = 0x00b9; cvbs = 0x00b3; vga2 = 0x00d1; myflag = SiS_GetReg(SISPART4, 0x01); if(myflag & 0x04) { svhs = 0x00dd; cvbs = 0x00ee; vga2 = 0x00fd; } } else if(ivideo->vbflags2 & (VB2_301B | VB2_302B)) { svhs = 0x016b; cvbs = 0x0174; vga2 = 0x0190; } else if(ivideo->vbflags2 & (VB2_301LV | VB2_302LV)) { svhs = 0x0200; cvbs = 0x0100; } else if(ivideo->vbflags2 & (VB2_301C | VB2_302ELV | VB2_307T | VB2_307LV)) { svhs = 0x016b; cvbs = 0x0110; vga2 = 0x0190; } else return; vga2_c = 0x0e08; svhs_c = 0x0404; cvbs_c = 0x0804; if(ivideo->vbflags & (VB2_301LV|VB2_302LV|VB2_302ELV|VB2_307LV)) { svhs_c = 0x0408; cvbs_c = 0x0808; } biosflag = 2; if(ivideo->haveXGIROM) { biosflag = ivideo->bios_abase[0x58] & 0x03; } else if(ivideo->newrom) { if(ivideo->bios_abase[0x5d] & 0x04) biosflag |= 0x01; } else if(ivideo->sisvga_engine == SIS_300_VGA) { if(ivideo->bios_abase) { biosflag = ivideo->bios_abase[0xfe] & 0x03; } } if(ivideo->chip == SIS_300) { myflag = SiS_GetReg(SISSR, 0x3b); if(!(myflag & 0x01)) vga2 = vga2_c = 0; } if(!(ivideo->vbflags2 & VB2_SISVGA2BRIDGE)) { vga2 = vga2_c = 0; } backupSR_1e = SiS_GetReg(SISSR, 0x1e); SiS_SetRegOR(SISSR, 0x1e, 0x20); backupP4_0d = SiS_GetReg(SISPART4, 0x0d); if(ivideo->vbflags2 & VB2_30xC) { SiS_SetRegANDOR(SISPART4, 0x0d, ~0x07, 0x01); } else { SiS_SetRegOR(SISPART4, 0x0d, 0x04); } SiS_DDC2Delay(&ivideo->SiS_Pr, 0x2000); backupP2_00 = SiS_GetReg(SISPART2, 0x00); SiS_SetReg(SISPART2, 0x00, ((backupP2_00 | 0x1c) & 0xfc)); backupP2_4d = SiS_GetReg(SISPART2, 0x4d); if(ivideo->vbflags2 & VB2_SISYPBPRBRIDGE) { SiS_SetReg(SISPART2, 0x4d, (backupP2_4d & ~0x10)); } if(!(ivideo->vbflags2 & VB2_30xCLV)) { SISDoSense(ivideo, 0, 0); } SiS_SetRegAND(SISCR, 0x32, ~0x14); if(vga2_c || vga2) { if(SISDoSense(ivideo, vga2, vga2_c)) { if(biosflag & 0x01) { printk(KERN_INFO "%s %s SCART output\n", stdstr, tvstr); SiS_SetRegOR(SISCR, 0x32, 0x04); } else { printk(KERN_INFO "%s secondary VGA connection\n", stdstr); SiS_SetRegOR(SISCR, 0x32, 0x10); } } } SiS_SetRegAND(SISCR, 0x32, 0x3f); if(ivideo->vbflags2 & VB2_30xCLV) { SiS_SetRegOR(SISPART4, 0x0d, 0x04); } if((ivideo->sisvga_engine == SIS_315_VGA) && (ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) { SiS_SetReg(SISPART2, 0x4d, (backupP2_4d | 0x10)); SiS_DDC2Delay(&ivideo->SiS_Pr, 0x2000); if((result = SISDoSense(ivideo, svhs, 0x0604))) { if((result = SISDoSense(ivideo, cvbs, 0x0804))) { printk(KERN_INFO "%s %s YPbPr component output\n", stdstr, tvstr); SiS_SetRegOR(SISCR, 0x32, 0x80); } } SiS_SetReg(SISPART2, 0x4d, backupP2_4d); } SiS_SetRegAND(SISCR, 0x32, ~0x03); if(!(ivideo->vbflags & TV_YPBPR)) { if((result = SISDoSense(ivideo, svhs, svhs_c))) { printk(KERN_INFO "%s %s SVIDEO output\n", stdstr, tvstr); SiS_SetRegOR(SISCR, 0x32, 0x02); } if((biosflag & 0x02) || (!result)) { if(SISDoSense(ivideo, cvbs, cvbs_c)) { printk(KERN_INFO "%s %s COMPOSITE output\n", stdstr, tvstr); SiS_SetRegOR(SISCR, 0x32, 0x01); } } } SISDoSense(ivideo, 0, 0); SiS_SetReg(SISPART2, 0x00, backupP2_00); SiS_SetReg(SISPART4, 0x0d, backupP4_0d); SiS_SetReg(SISSR, 0x1e, backupSR_1e); if(ivideo->vbflags2 & VB2_30xCLV) { biosflag = SiS_GetReg(SISPART2, 0x00); if(biosflag & 0x20) { for(myflag = 2; myflag > 0; myflag--) { biosflag ^= 0x20; SiS_SetReg(SISPART2, 0x00, biosflag); } } } SiS_SetReg(SISPART2, 0x00, backupP2_00); } /* Determine and detect attached TV's on Chrontel */ static void SiS_SenseCh(struct sis_video_info *ivideo) { #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) u8 temp1, temp2; char stdstr[] = "sisfb: Chrontel: Detected TV connected to"; #endif #ifdef CONFIG_FB_SIS_300 unsigned char test[3]; int i; #endif if(ivideo->chip < SIS_315H) { #ifdef CONFIG_FB_SIS_300 ivideo->SiS_Pr.SiS_IF_DEF_CH70xx = 1; /* Chrontel 700x */ SiS_SetChrontelGPIO(&ivideo->SiS_Pr, 0x9c); /* Set general purpose IO for Chrontel communication */ SiS_DDC2Delay(&ivideo->SiS_Pr, 1000); temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x25); /* See Chrontel TB31 for explanation */ temp2 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0e); if(((temp2 & 0x07) == 0x01) || (temp2 & 0x04)) { SiS_SetCH700x(&ivideo->SiS_Pr, 0x0e, 0x0b); SiS_DDC2Delay(&ivideo->SiS_Pr, 300); } temp2 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x25); if(temp2 != temp1) temp1 = temp2; if((temp1 >= 0x22) && (temp1 <= 0x50)) { /* Read power status */ temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0e); if((temp1 & 0x03) != 0x03) { /* Power all outputs */ SiS_SetCH700x(&ivideo->SiS_Pr, 0x0e,0x0b); SiS_DDC2Delay(&ivideo->SiS_Pr, 300); } /* Sense connected TV devices */ for(i = 0; i < 3; i++) { SiS_SetCH700x(&ivideo->SiS_Pr, 0x10, 0x01); SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96); SiS_SetCH700x(&ivideo->SiS_Pr, 0x10, 0x00); SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96); temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x10); if(!(temp1 & 0x08)) test[i] = 0x02; else if(!(temp1 & 0x02)) test[i] = 0x01; else test[i] = 0; SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96); } if(test[0] == test[1]) temp1 = test[0]; else if(test[0] == test[2]) temp1 = test[0]; else if(test[1] == test[2]) temp1 = test[1]; else { printk(KERN_INFO "sisfb: TV detection unreliable - test results varied\n"); temp1 = test[2]; } if(temp1 == 0x02) { printk(KERN_INFO "%s SVIDEO output\n", stdstr); ivideo->vbflags |= TV_SVIDEO; SiS_SetRegOR(SISCR, 0x32, 0x02); SiS_SetRegAND(SISCR, 0x32, ~0x05); } else if (temp1 == 0x01) { printk(KERN_INFO "%s CVBS output\n", stdstr); ivideo->vbflags |= TV_AVIDEO; SiS_SetRegOR(SISCR, 0x32, 0x01); SiS_SetRegAND(SISCR, 0x32, ~0x06); } else { SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x0e, 0x01, 0xF8); SiS_SetRegAND(SISCR, 0x32, ~0x07); } } else if(temp1 == 0) { SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x0e, 0x01, 0xF8); SiS_SetRegAND(SISCR, 0x32, ~0x07); } /* Set general purpose IO for Chrontel communication */ SiS_SetChrontelGPIO(&ivideo->SiS_Pr, 0x00); #endif } else { #ifdef CONFIG_FB_SIS_315 ivideo->SiS_Pr.SiS_IF_DEF_CH70xx = 2; /* Chrontel 7019 */ temp1 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x49); SiS_SetCH701x(&ivideo->SiS_Pr, 0x49, 0x20); SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96); temp2 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x20); temp2 |= 0x01; SiS_SetCH701x(&ivideo->SiS_Pr, 0x20, temp2); SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96); temp2 ^= 0x01; SiS_SetCH701x(&ivideo->SiS_Pr, 0x20, temp2); SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96); temp2 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x20); SiS_SetCH701x(&ivideo->SiS_Pr, 0x49, temp1); temp1 = 0; if(temp2 & 0x02) temp1 |= 0x01; if(temp2 & 0x10) temp1 |= 0x01; if(temp2 & 0x04) temp1 |= 0x02; if( (temp1 & 0x01) && (temp1 & 0x02) ) temp1 = 0x04; switch(temp1) { case 0x01: printk(KERN_INFO "%s CVBS output\n", stdstr); ivideo->vbflags |= TV_AVIDEO; SiS_SetRegOR(SISCR, 0x32, 0x01); SiS_SetRegAND(SISCR, 0x32, ~0x06); break; case 0x02: printk(KERN_INFO "%s SVIDEO output\n", stdstr); ivideo->vbflags |= TV_SVIDEO; SiS_SetRegOR(SISCR, 0x32, 0x02); SiS_SetRegAND(SISCR, 0x32, ~0x05); break; case 0x04: printk(KERN_INFO "%s SCART output\n", stdstr); SiS_SetRegOR(SISCR, 0x32, 0x04); SiS_SetRegAND(SISCR, 0x32, ~0x03); break; default: SiS_SetRegAND(SISCR, 0x32, ~0x07); } #endif } } static void sisfb_get_VB_type(struct sis_video_info *ivideo) { char stdstr[] = "sisfb: Detected"; char bridgestr[] = "video bridge"; u8 vb_chipid; u8 reg; /* No CRT2 on XGI Z7 */ if(ivideo->chip == XGI_20) return; vb_chipid = SiS_GetReg(SISPART4, 0x00); switch(vb_chipid) { case 0x01: reg = SiS_GetReg(SISPART4, 0x01); if(reg < 0xb0) { ivideo->vbflags |= VB_301; /* Deprecated */ ivideo->vbflags2 |= VB2_301; printk(KERN_INFO "%s SiS301 %s\n", stdstr, bridgestr); } else if(reg < 0xc0) { ivideo->vbflags |= VB_301B; /* Deprecated */ ivideo->vbflags2 |= VB2_301B; reg = SiS_GetReg(SISPART4, 0x23); if(!(reg & 0x02)) { ivideo->vbflags |= VB_30xBDH; /* Deprecated */ ivideo->vbflags2 |= VB2_30xBDH; printk(KERN_INFO "%s SiS301B-DH %s\n", stdstr, bridgestr); } else { printk(KERN_INFO "%s SiS301B %s\n", stdstr, bridgestr); } } else if(reg < 0xd0) { ivideo->vbflags |= VB_301C; /* Deprecated */ ivideo->vbflags2 |= VB2_301C; printk(KERN_INFO "%s SiS301C %s\n", stdstr, bridgestr); } else if(reg < 0xe0) { ivideo->vbflags |= VB_301LV; /* Deprecated */ ivideo->vbflags2 |= VB2_301LV; printk(KERN_INFO "%s SiS301LV %s\n", stdstr, bridgestr); } else if(reg <= 0xe1) { reg = SiS_GetReg(SISPART4, 0x39); if(reg == 0xff) { ivideo->vbflags |= VB_302LV; /* Deprecated */ ivideo->vbflags2 |= VB2_302LV; printk(KERN_INFO "%s SiS302LV %s\n", stdstr, bridgestr); } else { ivideo->vbflags |= VB_301C; /* Deprecated */ ivideo->vbflags2 |= VB2_301C; printk(KERN_INFO "%s SiS301C(P4) %s\n", stdstr, bridgestr); #if 0 ivideo->vbflags |= VB_302ELV; /* Deprecated */ ivideo->vbflags2 |= VB2_302ELV; printk(KERN_INFO "%s SiS302ELV %s\n", stdstr, bridgestr); #endif } } break; case 0x02: ivideo->vbflags |= VB_302B; /* Deprecated */ ivideo->vbflags2 |= VB2_302B; printk(KERN_INFO "%s SiS302B %s\n", stdstr, bridgestr); break; } if((!(ivideo->vbflags2 & VB2_VIDEOBRIDGE)) && (ivideo->chip != SIS_300)) { reg = SiS_GetReg(SISCR, 0x37); reg &= SIS_EXTERNAL_CHIP_MASK; reg >>= 1; if(ivideo->sisvga_engine == SIS_300_VGA) { #ifdef CONFIG_FB_SIS_300 switch(reg) { case SIS_EXTERNAL_CHIP_LVDS: ivideo->vbflags |= VB_LVDS; /* Deprecated */ ivideo->vbflags2 |= VB2_LVDS; break; case SIS_EXTERNAL_CHIP_TRUMPION: ivideo->vbflags |= (VB_LVDS | VB_TRUMPION); /* Deprecated */ ivideo->vbflags2 |= (VB2_LVDS | VB2_TRUMPION); break; case SIS_EXTERNAL_CHIP_CHRONTEL: ivideo->vbflags |= VB_CHRONTEL; /* Deprecated */ ivideo->vbflags2 |= VB2_CHRONTEL; break; case SIS_EXTERNAL_CHIP_LVDS_CHRONTEL: ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */ ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL); break; } if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 1; #endif } else if(ivideo->chip < SIS_661) { #ifdef CONFIG_FB_SIS_315 switch (reg) { case SIS310_EXTERNAL_CHIP_LVDS: ivideo->vbflags |= VB_LVDS; /* Deprecated */ ivideo->vbflags2 |= VB2_LVDS; break; case SIS310_EXTERNAL_CHIP_LVDS_CHRONTEL: ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */ ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL); break; } if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 2; #endif } else if(ivideo->chip >= SIS_661) { #ifdef CONFIG_FB_SIS_315 reg = SiS_GetReg(SISCR, 0x38); reg >>= 5; switch(reg) { case 0x02: ivideo->vbflags |= VB_LVDS; /* Deprecated */ ivideo->vbflags2 |= VB2_LVDS; break; case 0x03: ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */ ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL); break; case 0x04: ivideo->vbflags |= (VB_LVDS | VB_CONEXANT); /* Deprecated */ ivideo->vbflags2 |= (VB2_LVDS | VB2_CONEXANT); break; } if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 2; #endif } if(ivideo->vbflags2 & VB2_LVDS) { printk(KERN_INFO "%s LVDS transmitter\n", stdstr); } if((ivideo->sisvga_engine == SIS_300_VGA) && (ivideo->vbflags2 & VB2_TRUMPION)) { printk(KERN_INFO "%s Trumpion Zurac LCD scaler\n", stdstr); } if(ivideo->vbflags2 & VB2_CHRONTEL) { printk(KERN_INFO "%s Chrontel TV encoder\n", stdstr); } if((ivideo->chip >= SIS_661) && (ivideo->vbflags2 & VB2_CONEXANT)) { printk(KERN_INFO "%s Conexant external device\n", stdstr); } } if(ivideo->vbflags2 & VB2_SISBRIDGE) { SiS_SenseLCD(ivideo); SiS_Sense30x(ivideo); } else if(ivideo->vbflags2 & VB2_CHRONTEL) { SiS_SenseCh(ivideo); } } /* ---------- Engine initialization routines ------------ */ static void sisfb_engine_init(struct sis_video_info *ivideo) { /* Initialize command queue (we use MMIO only) */ /* BEFORE THIS IS CALLED, THE ENGINES *MUST* BE SYNC'ED */ ivideo->caps &= ~(TURBO_QUEUE_CAP | MMIO_CMD_QUEUE_CAP | VM_CMD_QUEUE_CAP | AGP_CMD_QUEUE_CAP); #ifdef CONFIG_FB_SIS_300 if(ivideo->sisvga_engine == SIS_300_VGA) { u32 tqueue_pos; u8 tq_state; tqueue_pos = (ivideo->video_size - ivideo->cmdQueueSize) / (64 * 1024); tq_state = SiS_GetReg(SISSR, IND_SIS_TURBOQUEUE_SET); tq_state |= 0xf0; tq_state &= 0xfc; tq_state |= (u8)(tqueue_pos >> 8); SiS_SetReg(SISSR, IND_SIS_TURBOQUEUE_SET, tq_state); SiS_SetReg(SISSR, IND_SIS_TURBOQUEUE_ADR, (u8)(tqueue_pos & 0xff)); ivideo->caps |= TURBO_QUEUE_CAP; } #endif #ifdef CONFIG_FB_SIS_315 if(ivideo->sisvga_engine == SIS_315_VGA) { u32 tempq = 0, templ; u8 temp; if(ivideo->chip == XGI_20) { switch(ivideo->cmdQueueSize) { case (64 * 1024): temp = SIS_CMD_QUEUE_SIZE_Z7_64k; break; case (128 * 1024): default: temp = SIS_CMD_QUEUE_SIZE_Z7_128k; } } else { switch(ivideo->cmdQueueSize) { case (4 * 1024 * 1024): temp = SIS_CMD_QUEUE_SIZE_4M; break; case (2 * 1024 * 1024): temp = SIS_CMD_QUEUE_SIZE_2M; break; case (1 * 1024 * 1024): temp = SIS_CMD_QUEUE_SIZE_1M; break; default: case (512 * 1024): temp = SIS_CMD_QUEUE_SIZE_512k; } } SiS_SetReg(SISSR, IND_SIS_CMDQUEUE_THRESHOLD, COMMAND_QUEUE_THRESHOLD); SiS_SetReg(SISSR, IND_SIS_CMDQUEUE_SET, SIS_CMD_QUEUE_RESET); if((ivideo->chip >= XGI_40) && ivideo->modechanged) { /* Must disable dual pipe on XGI_40. Can't do * this in MMIO mode, because it requires * setting/clearing a bit in the MMIO fire trigger * register. */ if(!((templ = MMIO_IN32(ivideo->mmio_vbase, 0x8240)) & (1 << 10))) { MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, 0); SiS_SetReg(SISSR, IND_SIS_CMDQUEUE_SET, (temp | SIS_VRAM_CMDQUEUE_ENABLE)); tempq = MMIO_IN32(ivideo->mmio_vbase, Q_READ_PTR); MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, tempq); tempq = (u32)(ivideo->video_size - ivideo->cmdQueueSize); MMIO_OUT32(ivideo->mmio_vbase, Q_BASE_ADDR, tempq); writel(0x16800000 + 0x8240, ivideo->video_vbase + tempq); writel(templ | (1 << 10), ivideo->video_vbase + tempq + 4); writel(0x168F0000, ivideo->video_vbase + tempq + 8); writel(0x168F0000, ivideo->video_vbase + tempq + 12); MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, (tempq + 16)); sisfb_syncaccel(ivideo); SiS_SetReg(SISSR, IND_SIS_CMDQUEUE_SET, SIS_CMD_QUEUE_RESET); } } tempq = MMIO_IN32(ivideo->mmio_vbase, MMIO_QUEUE_READPORT); MMIO_OUT32(ivideo->mmio_vbase, MMIO_QUEUE_WRITEPORT, tempq); temp |= (SIS_MMIO_CMD_ENABLE | SIS_CMD_AUTO_CORR); SiS_SetReg(SISSR, IND_SIS_CMDQUEUE_SET, temp); tempq = (u32)(ivideo->video_size - ivideo->cmdQueueSize); MMIO_OUT32(ivideo->mmio_vbase, MMIO_QUEUE_PHYBASE, tempq); ivideo->caps |= MMIO_CMD_QUEUE_CAP; } #endif ivideo->engineok = 1; } static void sisfb_detect_lcd_type(struct sis_video_info *ivideo) { u8 reg; int i; reg = SiS_GetReg(SISCR, 0x36); reg &= 0x0f; if(ivideo->sisvga_engine == SIS_300_VGA) { ivideo->CRT2LCDType = sis300paneltype[reg]; } else if(ivideo->chip >= SIS_661) { ivideo->CRT2LCDType = sis661paneltype[reg]; } else { ivideo->CRT2LCDType = sis310paneltype[reg]; if((ivideo->chip == SIS_550) && (sisfb_fstn)) { if((ivideo->CRT2LCDType != LCD_320x240_2) && (ivideo->CRT2LCDType != LCD_320x240_3)) { ivideo->CRT2LCDType = LCD_320x240; } } } if(ivideo->CRT2LCDType == LCD_UNKNOWN) { /* For broken BIOSes: Assume 1024x768, RGB18 */ ivideo->CRT2LCDType = LCD_1024x768; SiS_SetRegANDOR(SISCR, 0x36, 0xf0, 0x02); SiS_SetRegANDOR(SISCR, 0x37, 0xee, 0x01); printk(KERN_DEBUG "sisfb: Invalid panel ID (%02x), assuming 1024x768, RGB18\n", reg); } for(i = 0; i < SIS_LCD_NUMBER; i++) { if(ivideo->CRT2LCDType == sis_lcd_data[i].lcdtype) { ivideo->lcdxres = sis_lcd_data[i].xres; ivideo->lcdyres = sis_lcd_data[i].yres; ivideo->lcddefmodeidx = sis_lcd_data[i].default_mode_idx; break; } } #ifdef CONFIG_FB_SIS_300 if(ivideo->SiS_Pr.SiS_CustomT == CUT_BARCO1366) { ivideo->lcdxres = 1360; ivideo->lcdyres = 1024; ivideo->lcddefmodeidx = DEFAULT_MODE_1360; } else if(ivideo->SiS_Pr.SiS_CustomT == CUT_PANEL848) { ivideo->lcdxres = 848; ivideo->lcdyres = 480; ivideo->lcddefmodeidx = DEFAULT_MODE_848; } else if(ivideo->SiS_Pr.SiS_CustomT == CUT_PANEL856) { ivideo->lcdxres = 856; ivideo->lcdyres = 480; ivideo->lcddefmodeidx = DEFAULT_MODE_856; } #endif printk(KERN_DEBUG "sisfb: Detected %dx%d flat panel\n", ivideo->lcdxres, ivideo->lcdyres); } static void sisfb_save_pdc_emi(struct sis_video_info *ivideo) { #ifdef CONFIG_FB_SIS_300 /* Save the current PanelDelayCompensation if the LCD is currently used */ if(ivideo->sisvga_engine == SIS_300_VGA) { if(ivideo->vbflags2 & (VB2_LVDS | VB2_30xBDH)) { int tmp; tmp = SiS_GetReg(SISCR, 0x30); if(tmp & 0x20) { /* Currently on LCD? If yes, read current pdc */ ivideo->detectedpdc = SiS_GetReg(SISPART1, 0x13); ivideo->detectedpdc &= 0x3c; if(ivideo->SiS_Pr.PDC == -1) { /* Let option override detection */ ivideo->SiS_Pr.PDC = ivideo->detectedpdc; } printk(KERN_INFO "sisfb: Detected LCD PDC 0x%02x\n", ivideo->detectedpdc); } if((ivideo->SiS_Pr.PDC != -1) && (ivideo->SiS_Pr.PDC != ivideo->detectedpdc)) { printk(KERN_INFO "sisfb: Using LCD PDC 0x%02x\n", ivideo->SiS_Pr.PDC); } } } #endif #ifdef CONFIG_FB_SIS_315 if(ivideo->sisvga_engine == SIS_315_VGA) { /* Try to find about LCDA */ if(ivideo->vbflags2 & VB2_SISLCDABRIDGE) { int tmp; tmp = SiS_GetReg(SISPART1, 0x13); if(tmp & 0x04) { ivideo->SiS_Pr.SiS_UseLCDA = true; ivideo->detectedlcda = 0x03; } } /* Save PDC */ if(ivideo->vbflags2 & VB2_SISLVDSBRIDGE) { int tmp; tmp = SiS_GetReg(SISCR, 0x30); if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) { /* Currently on LCD? If yes, read current pdc */ u8 pdc; pdc = SiS_GetReg(SISPART1, 0x2D); ivideo->detectedpdc = (pdc & 0x0f) << 1; ivideo->detectedpdca = (pdc & 0xf0) >> 3; pdc = SiS_GetReg(SISPART1, 0x35); ivideo->detectedpdc |= ((pdc >> 7) & 0x01); pdc = SiS_GetReg(SISPART1, 0x20); ivideo->detectedpdca |= ((pdc >> 6) & 0x01); if(ivideo->newrom) { /* New ROM invalidates other PDC resp. */ if(ivideo->detectedlcda != 0xff) { ivideo->detectedpdc = 0xff; } else { ivideo->detectedpdca = 0xff; } } if(ivideo->SiS_Pr.PDC == -1) { if(ivideo->detectedpdc != 0xff) { ivideo->SiS_Pr.PDC = ivideo->detectedpdc; } } if(ivideo->SiS_Pr.PDCA == -1) { if(ivideo->detectedpdca != 0xff) { ivideo->SiS_Pr.PDCA = ivideo->detectedpdca; } } if(ivideo->detectedpdc != 0xff) { printk(KERN_INFO "sisfb: Detected LCD PDC 0x%02x (for LCD=CRT2)\n", ivideo->detectedpdc); } if(ivideo->detectedpdca != 0xff) { printk(KERN_INFO "sisfb: Detected LCD PDC1 0x%02x (for LCD=CRT1)\n", ivideo->detectedpdca); } } /* Save EMI */ if(ivideo->vbflags2 & VB2_SISEMIBRIDGE) { ivideo->SiS_Pr.EMI_30 = SiS_GetReg(SISPART4, 0x30); ivideo->SiS_Pr.EMI_31 = SiS_GetReg(SISPART4, 0x31); ivideo->SiS_Pr.EMI_32 = SiS_GetReg(SISPART4, 0x32); ivideo->SiS_Pr.EMI_33 = SiS_GetReg(SISPART4, 0x33); ivideo->SiS_Pr.HaveEMI = true; if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) { ivideo->SiS_Pr.HaveEMILCD = true; } } } /* Let user override detected PDCs (all bridges) */ if(ivideo->vbflags2 & VB2_30xBLV) { if((ivideo->SiS_Pr.PDC != -1) && (ivideo->SiS_Pr.PDC != ivideo->detectedpdc)) { printk(KERN_INFO "sisfb: Using LCD PDC 0x%02x (for LCD=CRT2)\n", ivideo->SiS_Pr.PDC); } if((ivideo->SiS_Pr.PDCA != -1) && (ivideo->SiS_Pr.PDCA != ivideo->detectedpdca)) { printk(KERN_INFO "sisfb: Using LCD PDC1 0x%02x (for LCD=CRT1)\n", ivideo->SiS_Pr.PDCA); } } } #endif } /* -------------------- Memory manager routines ---------------------- */ static u32 sisfb_getheapstart(struct sis_video_info *ivideo) { u32 ret = ivideo->sisfb_parm_mem * 1024; u32 maxoffs = ivideo->video_size - ivideo->hwcursor_size - ivideo->cmdQueueSize; u32 def; /* Calculate heap start = end of memory for console * * CCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDHHHHQQQQQQQQQQ * C = console, D = heap, H = HWCursor, Q = cmd-queue * * On 76x in UMA+LFB mode, the layout is as follows: * DDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCHHHHQQQQQQQQQQQ * where the heap is the entire UMA area, eventually * into the LFB area if the given mem parameter is * higher than the size of the UMA memory. * * Basically given by "mem" parameter * * maximum = videosize - cmd_queue - hwcursor * (results in a heap of size 0) * default = SiS 300: depends on videosize * SiS 315/330/340/XGI: 32k below max */ if(ivideo->sisvga_engine == SIS_300_VGA) { if(ivideo->video_size > 0x1000000) { def = 0xc00000; } else if(ivideo->video_size > 0x800000) { def = 0x800000; } else { def = 0x400000; } } else if(ivideo->UMAsize && ivideo->LFBsize) { ret = def = 0; } else { def = maxoffs - 0x8000; } /* Use default for secondary card for now (FIXME) */ if((!ret) || (ret > maxoffs) || (ivideo->cardnumber != 0)) ret = def; return ret; } static u32 sisfb_getheapsize(struct sis_video_info *ivideo) { u32 max = ivideo->video_size - ivideo->hwcursor_size - ivideo->cmdQueueSize; u32 ret = 0; if(ivideo->UMAsize && ivideo->LFBsize) { if( (!ivideo->sisfb_parm_mem) || ((ivideo->sisfb_parm_mem * 1024) > max) || ((max - (ivideo->sisfb_parm_mem * 1024)) < ivideo->UMAsize) ) { ret = ivideo->UMAsize; max -= ivideo->UMAsize; } else { ret = max - (ivideo->sisfb_parm_mem * 1024); max = ivideo->sisfb_parm_mem * 1024; } ivideo->video_offset = ret; ivideo->sisfb_mem = max; } else { ret = max - ivideo->heapstart; ivideo->sisfb_mem = ivideo->heapstart; } return ret; } static int sisfb_heap_init(struct sis_video_info *ivideo) { struct SIS_OH *poh; ivideo->video_offset = 0; if(ivideo->sisfb_parm_mem) { if( (ivideo->sisfb_parm_mem < (2 * 1024 * 1024)) || (ivideo->sisfb_parm_mem > ivideo->video_size) ) { ivideo->sisfb_parm_mem = 0; } } ivideo->heapstart = sisfb_getheapstart(ivideo); ivideo->sisfb_heap_size = sisfb_getheapsize(ivideo); ivideo->sisfb_heap_start = ivideo->video_vbase + ivideo->heapstart; ivideo->sisfb_heap_end = ivideo->sisfb_heap_start + ivideo->sisfb_heap_size; printk(KERN_INFO "sisfb: Memory heap starting at %dK, size %dK\n", (int)(ivideo->heapstart / 1024), (int)(ivideo->sisfb_heap_size / 1024)); ivideo->sisfb_heap.vinfo = ivideo; ivideo->sisfb_heap.poha_chain = NULL; ivideo->sisfb_heap.poh_freelist = NULL; poh = sisfb_poh_new_node(&ivideo->sisfb_heap); if(poh == NULL) return 1; poh->poh_next = &ivideo->sisfb_heap.oh_free; poh->poh_prev = &ivideo->sisfb_heap.oh_free; poh->size = ivideo->sisfb_heap_size; poh->offset = ivideo->heapstart; ivideo->sisfb_heap.oh_free.poh_next = poh; ivideo->sisfb_heap.oh_free.poh_prev = poh; ivideo->sisfb_heap.oh_free.size = 0; ivideo->sisfb_heap.max_freesize = poh->size; ivideo->sisfb_heap.oh_used.poh_next = &ivideo->sisfb_heap.oh_used; ivideo->sisfb_heap.oh_used.poh_prev = &ivideo->sisfb_heap.oh_used; ivideo->sisfb_heap.oh_used.size = SENTINEL; if(ivideo->cardnumber == 0) { /* For the first card, make this heap the "global" one * for old DRM (which could handle only one card) */ sisfb_heap = &ivideo->sisfb_heap; } return 0; } static struct SIS_OH * sisfb_poh_new_node(struct SIS_HEAP *memheap) { struct SIS_OHALLOC *poha; struct SIS_OH *poh; unsigned long cOhs; int i; if(memheap->poh_freelist == NULL) { poha = kmalloc(SIS_OH_ALLOC_SIZE, GFP_KERNEL); if(!poha) return NULL; poha->poha_next = memheap->poha_chain; memheap->poha_chain = poha; cOhs = (SIS_OH_ALLOC_SIZE - sizeof(struct SIS_OHALLOC)) / sizeof(struct SIS_OH) + 1; poh = &poha->aoh[0]; for(i = cOhs - 1; i != 0; i--) { poh->poh_next = poh + 1; poh = poh + 1; } poh->poh_next = NULL; memheap->poh_freelist = &poha->aoh[0]; } poh = memheap->poh_freelist; memheap->poh_freelist = poh->poh_next; return poh; } static struct SIS_OH * sisfb_poh_allocate(struct SIS_HEAP *memheap, u32 size) { struct SIS_OH *pohThis; struct SIS_OH *pohRoot; int bAllocated = 0; if(size > memheap->max_freesize) { DPRINTK("sisfb: Can't allocate %dk video memory\n", (unsigned int) size / 1024); return NULL; } pohThis = memheap->oh_free.poh_next; while(pohThis != &memheap->oh_free) { if(size <= pohThis->size) { bAllocated = 1; break; } pohThis = pohThis->poh_next; } if(!bAllocated) { DPRINTK("sisfb: Can't allocate %dk video memory\n", (unsigned int) size / 1024); return NULL; } if(size == pohThis->size) { pohRoot = pohThis; sisfb_delete_node(pohThis); } else { pohRoot = sisfb_poh_new_node(memheap); if(pohRoot == NULL) return NULL; pohRoot->offset = pohThis->offset; pohRoot->size = size; pohThis->offset += size; pohThis->size -= size; } memheap->max_freesize -= size; pohThis = &memheap->oh_used; sisfb_insert_node(pohThis, pohRoot); return pohRoot; } static void sisfb_delete_node(struct SIS_OH *poh) { poh->poh_prev->poh_next = poh->poh_next; poh->poh_next->poh_prev = poh->poh_prev; } static void sisfb_insert_node(struct SIS_OH *pohList, struct SIS_OH *poh) { struct SIS_OH *pohTemp = pohList->poh_next; pohList->poh_next = poh; pohTemp->poh_prev = poh; poh->poh_prev = pohList; poh->poh_next = pohTemp; } static struct SIS_OH * sisfb_poh_free(struct SIS_HEAP *memheap, u32 base) { struct SIS_OH *pohThis; struct SIS_OH *poh_freed; struct SIS_OH *poh_prev; struct SIS_OH *poh_next; u32 ulUpper; u32 ulLower; int foundNode = 0; poh_freed = memheap->oh_used.poh_next; while(poh_freed != &memheap->oh_used) { if(poh_freed->offset == base) { foundNode = 1; break; } poh_freed = poh_freed->poh_next; } if(!foundNode) return NULL; memheap->max_freesize += poh_freed->size; poh_prev = poh_next = NULL; ulUpper = poh_freed->offset + poh_freed->size; ulLower = poh_freed->offset; pohThis = memheap->oh_free.poh_next; while(pohThis != &memheap->oh_free) { if(pohThis->offset == ulUpper) { poh_next = pohThis; } else if((pohThis->offset + pohThis->size) == ulLower) { poh_prev = pohThis; } pohThis = pohThis->poh_next; } sisfb_delete_node(poh_freed); if(poh_prev && poh_next) { poh_prev->size += (poh_freed->size + poh_next->size); sisfb_delete_node(poh_next); sisfb_free_node(memheap, poh_freed); sisfb_free_node(memheap, poh_next); return poh_prev; } if(poh_prev) { poh_prev->size += poh_freed->size; sisfb_free_node(memheap, poh_freed); return poh_prev; } if(poh_next) { poh_next->size += poh_freed->size; poh_next->offset = poh_freed->offset; sisfb_free_node(memheap, poh_freed); return poh_next; } sisfb_insert_node(&memheap->oh_free, poh_freed); return poh_freed; } static void sisfb_free_node(struct SIS_HEAP *memheap, struct SIS_OH *poh) { if(poh == NULL) return; poh->poh_next = memheap->poh_freelist; memheap->poh_freelist = poh; } static void sis_int_malloc(struct sis_video_info *ivideo, struct sis_memreq *req) { struct SIS_OH *poh = NULL; if((ivideo) && (ivideo->sisfb_id == SISFB_ID) && (!ivideo->havenoheap)) poh = sisfb_poh_allocate(&ivideo->sisfb_heap, (u32)req->size); if(poh == NULL) { req->offset = req->size = 0; DPRINTK("sisfb: Video RAM allocation failed\n"); } else { req->offset = poh->offset; req->size = poh->size; DPRINTK("sisfb: Video RAM allocation succeeded: 0x%lx\n", (poh->offset + ivideo->video_vbase)); } } void sis_malloc(struct sis_memreq *req) { struct sis_video_info *ivideo = sisfb_heap->vinfo; if(&ivideo->sisfb_heap == sisfb_heap) sis_int_malloc(ivideo, req); else req->offset = req->size = 0; } void sis_malloc_new(struct pci_dev *pdev, struct sis_memreq *req) { struct sis_video_info *ivideo = pci_get_drvdata(pdev); sis_int_malloc(ivideo, req); } /* sis_free: u32 because "base" is offset inside video ram, can never be >4GB */ static void sis_int_free(struct sis_video_info *ivideo, u32 base) { struct SIS_OH *poh; if((!ivideo) || (ivideo->sisfb_id != SISFB_ID) || (ivideo->havenoheap)) return; poh = sisfb_poh_free(&ivideo->sisfb_heap, base); if(poh == NULL) { DPRINTK("sisfb: sisfb_poh_free() failed at base 0x%x\n", (unsigned int) base); } } void sis_free(u32 base) { struct sis_video_info *ivideo = sisfb_heap->vinfo; sis_int_free(ivideo, base); } void sis_free_new(struct pci_dev *pdev, u32 base) { struct sis_video_info *ivideo = pci_get_drvdata(pdev); sis_int_free(ivideo, base); } /* --------------------- SetMode routines ------------------------- */ static void sisfb_check_engine_and_sync(struct sis_video_info *ivideo) { u8 cr30, cr31; /* Check if MMIO and engines are enabled, * and sync in case they are. Can't use * ivideo->accel here, as this might have * been changed before this is called. */ cr30 = SiS_GetReg(SISSR, IND_SIS_PCI_ADDRESS_SET); cr31 = SiS_GetReg(SISSR, IND_SIS_MODULE_ENABLE); /* MMIO and 2D/3D engine enabled? */ if((cr30 & SIS_MEM_MAP_IO_ENABLE) && (cr31 & 0x42)) { #ifdef CONFIG_FB_SIS_300 if(ivideo->sisvga_engine == SIS_300_VGA) { /* Don't care about TurboQueue. It's * enough to know that the engines * are enabled */ sisfb_syncaccel(ivideo); } #endif #ifdef CONFIG_FB_SIS_315 if(ivideo->sisvga_engine == SIS_315_VGA) { /* Check that any queue mode is * enabled, and that the queue * is not in the state of "reset" */ cr30 = SiS_GetReg(SISSR, 0x26); if((cr30 & 0xe0) && (!(cr30 & 0x01))) { sisfb_syncaccel(ivideo); } } #endif } } static void sisfb_pre_setmode(struct sis_video_info *ivideo) { u8 cr30 = 0, cr31 = 0, cr33 = 0, cr35 = 0, cr38 = 0; int tvregnum = 0; ivideo->currentvbflags &= (VB_VIDEOBRIDGE | VB_DISPTYPE_DISP2); SiS_SetReg(SISSR, 0x05, 0x86); cr31 = SiS_GetReg(SISCR, 0x31); cr31 &= ~0x60; cr31 |= 0x04; cr33 = ivideo->rate_idx & 0x0F; #ifdef CONFIG_FB_SIS_315 if(ivideo->sisvga_engine == SIS_315_VGA) { if(ivideo->chip >= SIS_661) { cr38 = SiS_GetReg(SISCR, 0x38); cr38 &= ~0x07; /* Clear LCDA/DualEdge and YPbPr bits */ } else { tvregnum = 0x38; cr38 = SiS_GetReg(SISCR, tvregnum); cr38 &= ~0x3b; /* Clear LCDA/DualEdge and YPbPr bits */ } } #endif #ifdef CONFIG_FB_SIS_300 if(ivideo->sisvga_engine == SIS_300_VGA) { tvregnum = 0x35; cr38 = SiS_GetReg(SISCR, tvregnum); } #endif SiS_SetEnableDstn(&ivideo->SiS_Pr, false); SiS_SetEnableFstn(&ivideo->SiS_Pr, false); ivideo->curFSTN = ivideo->curDSTN = 0; switch(ivideo->currentvbflags & VB_DISPTYPE_DISP2) { case CRT2_TV: cr38 &= ~0xc0; /* Clear PAL-M / PAL-N bits */ if((ivideo->vbflags & TV_YPBPR) && (ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) { #ifdef CONFIG_FB_SIS_315 if(ivideo->chip >= SIS_661) { cr38 |= 0x04; if(ivideo->vbflags & TV_YPBPR525P) cr35 |= 0x20; else if(ivideo->vbflags & TV_YPBPR750P) cr35 |= 0x40; else if(ivideo->vbflags & TV_YPBPR1080I) cr35 |= 0x60; cr30 |= SIS_SIMULTANEOUS_VIEW_ENABLE; cr35 &= ~0x01; ivideo->currentvbflags |= (TV_YPBPR | (ivideo->vbflags & TV_YPBPRALL)); } else if(ivideo->sisvga_engine == SIS_315_VGA) { cr30 |= (0x80 | SIS_SIMULTANEOUS_VIEW_ENABLE); cr38 |= 0x08; if(ivideo->vbflags & TV_YPBPR525P) cr38 |= 0x10; else if(ivideo->vbflags & TV_YPBPR750P) cr38 |= 0x20; else if(ivideo->vbflags & TV_YPBPR1080I) cr38 |= 0x30; cr31 &= ~0x01; ivideo->currentvbflags |= (TV_YPBPR | (ivideo->vbflags & TV_YPBPRALL)); } #endif } else if((ivideo->vbflags & TV_HIVISION) && (ivideo->vbflags2 & VB2_SISHIVISIONBRIDGE)) { if(ivideo->chip >= SIS_661) { cr38 |= 0x04; cr35 |= 0x60; } else { cr30 |= 0x80; } cr30 |= SIS_SIMULTANEOUS_VIEW_ENABLE; cr31 |= 0x01; cr35 |= 0x01; ivideo->currentvbflags |= TV_HIVISION; } else if(ivideo->vbflags & TV_SCART) { cr30 = (SIS_VB_OUTPUT_SCART | SIS_SIMULTANEOUS_VIEW_ENABLE); cr31 |= 0x01; cr35 |= 0x01; ivideo->currentvbflags |= TV_SCART; } else { if(ivideo->vbflags & TV_SVIDEO) { cr30 = (SIS_VB_OUTPUT_SVIDEO | SIS_SIMULTANEOUS_VIEW_ENABLE); ivideo->currentvbflags |= TV_SVIDEO; } if(ivideo->vbflags & TV_AVIDEO) { cr30 = (SIS_VB_OUTPUT_COMPOSITE | SIS_SIMULTANEOUS_VIEW_ENABLE); ivideo->currentvbflags |= TV_AVIDEO; } } cr31 |= SIS_DRIVER_MODE; if(ivideo->vbflags & (TV_AVIDEO | TV_SVIDEO)) { if(ivideo->vbflags & TV_PAL) { cr31 |= 0x01; cr35 |= 0x01; ivideo->currentvbflags |= TV_PAL; if(ivideo->vbflags & TV_PALM) { cr38 |= 0x40; cr35 |= 0x04; ivideo->currentvbflags |= TV_PALM; } else if(ivideo->vbflags & TV_PALN) { cr38 |= 0x80; cr35 |= 0x08; ivideo->currentvbflags |= TV_PALN; } } else { cr31 &= ~0x01; cr35 &= ~0x01; ivideo->currentvbflags |= TV_NTSC; if(ivideo->vbflags & TV_NTSCJ) { cr38 |= 0x40; cr35 |= 0x02; ivideo->currentvbflags |= TV_NTSCJ; } } } break; case CRT2_LCD: cr30 = (SIS_VB_OUTPUT_LCD | SIS_SIMULTANEOUS_VIEW_ENABLE); cr31 |= SIS_DRIVER_MODE; SiS_SetEnableDstn(&ivideo->SiS_Pr, ivideo->sisfb_dstn); SiS_SetEnableFstn(&ivideo->SiS_Pr, ivideo->sisfb_fstn); ivideo->curFSTN = ivideo->sisfb_fstn; ivideo->curDSTN = ivideo->sisfb_dstn; break; case CRT2_VGA: cr30 = (SIS_VB_OUTPUT_CRT2 | SIS_SIMULTANEOUS_VIEW_ENABLE); cr31 |= SIS_DRIVER_MODE; if(ivideo->sisfb_nocrt2rate) { cr33 |= (sisbios_mode[ivideo->sisfb_mode_idx].rate_idx << 4); } else { cr33 |= ((ivideo->rate_idx & 0x0F) << 4); } break; default: /* disable CRT2 */ cr30 = 0x00; cr31 |= (SIS_DRIVER_MODE | SIS_VB_OUTPUT_DISABLE); } SiS_SetReg(SISCR, 0x30, cr30); SiS_SetReg(SISCR, 0x33, cr33); if(ivideo->chip >= SIS_661) { #ifdef CONFIG_FB_SIS_315 cr31 &= ~0x01; /* Clear PAL flag (now in CR35) */ SiS_SetRegANDOR(SISCR, 0x35, ~0x10, cr35); /* Leave overscan bit alone */ cr38 &= 0x07; /* Use only LCDA and HiVision/YPbPr bits */ SiS_SetRegANDOR(SISCR, 0x38, 0xf8, cr38); #endif } else if(ivideo->chip != SIS_300) { SiS_SetReg(SISCR, tvregnum, cr38); } SiS_SetReg(SISCR, 0x31, cr31); ivideo->SiS_Pr.SiS_UseOEM = ivideo->sisfb_useoem; sisfb_check_engine_and_sync(ivideo); } /* Fix SR11 for 661 and later */ #ifdef CONFIG_FB_SIS_315 static void sisfb_fixup_SR11(struct sis_video_info *ivideo) { u8 tmpreg; if(ivideo->chip >= SIS_661) { tmpreg = SiS_GetReg(SISSR, 0x11); if(tmpreg & 0x20) { tmpreg = SiS_GetReg(SISSR, 0x3e); tmpreg = (tmpreg + 1) & 0xff; SiS_SetReg(SISSR, 0x3e, tmpreg); tmpreg = SiS_GetReg(SISSR, 0x11); } if(tmpreg & 0xf0) { SiS_SetRegAND(SISSR, 0x11, 0x0f); } } } #endif static void sisfb_set_TVxposoffset(struct sis_video_info *ivideo, int val) { if(val > 32) val = 32; if(val < -32) val = -32; ivideo->tvxpos = val; if(ivideo->sisfblocked) return; if(!ivideo->modechanged) return; if(ivideo->currentvbflags & CRT2_TV) { if(ivideo->vbflags2 & VB2_CHRONTEL) { int x = ivideo->tvx; switch(ivideo->chronteltype) { case 1: x += val; if(x < 0) x = 0; SiS_SetReg(SISSR, 0x05, 0x86); SiS_SetCH700x(&ivideo->SiS_Pr, 0x0a, (x & 0xff)); SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x08, ((x & 0x0100) >> 7), 0xFD); break; case 2: /* Not supported by hardware */ break; } } else if(ivideo->vbflags2 & VB2_SISBRIDGE) { u8 p2_1f,p2_20,p2_2b,p2_42,p2_43; unsigned short temp; p2_1f = ivideo->p2_1f; p2_20 = ivideo->p2_20; p2_2b = ivideo->p2_2b; p2_42 = ivideo->p2_42; p2_43 = ivideo->p2_43; temp = p2_1f | ((p2_20 & 0xf0) << 4); temp += (val * 2); p2_1f = temp & 0xff; p2_20 = (temp & 0xf00) >> 4; p2_2b = ((p2_2b & 0x0f) + (val * 2)) & 0x0f; temp = p2_43 | ((p2_42 & 0xf0) << 4); temp += (val * 2); p2_43 = temp & 0xff; p2_42 = (temp & 0xf00) >> 4; SiS_SetReg(SISPART2, 0x1f, p2_1f); SiS_SetRegANDOR(SISPART2, 0x20, 0x0F, p2_20); SiS_SetRegANDOR(SISPART2, 0x2b, 0xF0, p2_2b); SiS_SetRegANDOR(SISPART2, 0x42, 0x0F, p2_42); SiS_SetReg(SISPART2, 0x43, p2_43); } } } static void sisfb_set_TVyposoffset(struct sis_video_info *ivideo, int val) { if(val > 32) val = 32; if(val < -32) val = -32; ivideo->tvypos = val; if(ivideo->sisfblocked) return; if(!ivideo->modechanged) return; if(ivideo->currentvbflags & CRT2_TV) { if(ivideo->vbflags2 & VB2_CHRONTEL) { int y = ivideo->tvy; switch(ivideo->chronteltype) { case 1: y -= val; if(y < 0) y = 0; SiS_SetReg(SISSR, 0x05, 0x86); SiS_SetCH700x(&ivideo->SiS_Pr, 0x0b, (y & 0xff)); SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x08, ((y & 0x0100) >> 8), 0xFE); break; case 2: /* Not supported by hardware */ break; } } else if(ivideo->vbflags2 & VB2_SISBRIDGE) { char p2_01, p2_02; val /= 2; p2_01 = ivideo->p2_01; p2_02 = ivideo->p2_02; p2_01 += val; p2_02 += val; if(!(ivideo->currentvbflags & (TV_HIVISION | TV_YPBPR))) { while((p2_01 <= 0) || (p2_02 <= 0)) { p2_01 += 2; p2_02 += 2; } } SiS_SetReg(SISPART2, 0x01, p2_01); SiS_SetReg(SISPART2, 0x02, p2_02); } } } static void sisfb_post_setmode(struct sis_video_info *ivideo) { bool crt1isoff = false; bool doit = true; #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) u8 reg; #endif #ifdef CONFIG_FB_SIS_315 u8 reg1; #endif SiS_SetReg(SISSR, 0x05, 0x86); #ifdef CONFIG_FB_SIS_315 sisfb_fixup_SR11(ivideo); #endif /* Now we actually HAVE changed the display mode */ ivideo->modechanged = 1; /* We can't switch off CRT1 if bridge is in slave mode */ if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) { if(sisfb_bridgeisslave(ivideo)) doit = false; } else ivideo->sisfb_crt1off = 0; #ifdef CONFIG_FB_SIS_300 if(ivideo->sisvga_engine == SIS_300_VGA) { if((ivideo->sisfb_crt1off) && (doit)) { crt1isoff = true; reg = 0x00; } else { crt1isoff = false; reg = 0x80; } SiS_SetRegANDOR(SISCR, 0x17, 0x7f, reg); } #endif #ifdef CONFIG_FB_SIS_315 if(ivideo->sisvga_engine == SIS_315_VGA) { if((ivideo->sisfb_crt1off) && (doit)) { crt1isoff = true; reg = 0x40; reg1 = 0xc0; } else { crt1isoff = false; reg = 0x00; reg1 = 0x00; } SiS_SetRegANDOR(SISCR, ivideo->SiS_Pr.SiS_MyCR63, ~0x40, reg); SiS_SetRegANDOR(SISSR, 0x1f, 0x3f, reg1); } #endif if(crt1isoff) { ivideo->currentvbflags &= ~VB_DISPTYPE_CRT1; ivideo->currentvbflags |= VB_SINGLE_MODE; } else { ivideo->currentvbflags |= VB_DISPTYPE_CRT1; if(ivideo->currentvbflags & VB_DISPTYPE_CRT2) { ivideo->currentvbflags |= VB_MIRROR_MODE; } else { ivideo->currentvbflags |= VB_SINGLE_MODE; } } SiS_SetRegAND(SISSR, IND_SIS_RAMDAC_CONTROL, ~0x04); if(ivideo->currentvbflags & CRT2_TV) { if(ivideo->vbflags2 & VB2_SISBRIDGE) { ivideo->p2_1f = SiS_GetReg(SISPART2, 0x1f); ivideo->p2_20 = SiS_GetReg(SISPART2, 0x20); ivideo->p2_2b = SiS_GetReg(SISPART2, 0x2b); ivideo->p2_42 = SiS_GetReg(SISPART2, 0x42); ivideo->p2_43 = SiS_GetReg(SISPART2, 0x43); ivideo->p2_01 = SiS_GetReg(SISPART2, 0x01); ivideo->p2_02 = SiS_GetReg(SISPART2, 0x02); } else if(ivideo->vbflags2 & VB2_CHRONTEL) { if(ivideo->chronteltype == 1) { ivideo->tvx = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0a); ivideo->tvx |= (((SiS_GetCH700x(&ivideo->SiS_Pr, 0x08) & 0x02) >> 1) << 8); ivideo->tvy = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0b); ivideo->tvy |= ((SiS_GetCH700x(&ivideo->SiS_Pr, 0x08) & 0x01) << 8); } } } if(ivideo->tvxpos) { sisfb_set_TVxposoffset(ivideo, ivideo->tvxpos); } if(ivideo->tvypos) { sisfb_set_TVyposoffset(ivideo, ivideo->tvypos); } /* Eventually sync engines */ sisfb_check_engine_and_sync(ivideo); /* (Re-)Initialize chip engines */ if(ivideo->accel) { sisfb_engine_init(ivideo); } else { ivideo->engineok = 0; } } static int sisfb_reset_mode(struct sis_video_info *ivideo) { if(sisfb_set_mode(ivideo, 0)) return 1; sisfb_set_pitch(ivideo); sisfb_set_base_CRT1(ivideo, ivideo->current_base); sisfb_set_base_CRT2(ivideo, ivideo->current_base); return 0; } static void sisfb_handle_command(struct sis_video_info *ivideo, struct sisfb_cmd *sisfb_command) { int mycrt1off; switch(sisfb_command->sisfb_cmd) { case SISFB_CMD_GETVBFLAGS: if(!ivideo->modechanged) { sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_EARLY; } else { sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK; sisfb_command->sisfb_result[1] = ivideo->currentvbflags; sisfb_command->sisfb_result[2] = ivideo->vbflags2; } break; case SISFB_CMD_SWITCHCRT1: /* arg[0]: 0 = off, 1 = on, 99 = query */ if(!ivideo->modechanged) { sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_EARLY; } else if(sisfb_command->sisfb_arg[0] == 99) { /* Query */ sisfb_command->sisfb_result[1] = ivideo->sisfb_crt1off ? 0 : 1; sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK; } else if(ivideo->sisfblocked) { sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_LOCKED; } else if((!(ivideo->currentvbflags & CRT2_ENABLE)) && (sisfb_command->sisfb_arg[0] == 0)) { sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_NOCRT2; } else { sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK; mycrt1off = sisfb_command->sisfb_arg[0] ? 0 : 1; if( ((ivideo->currentvbflags & VB_DISPTYPE_CRT1) && mycrt1off) || ((!(ivideo->currentvbflags & VB_DISPTYPE_CRT1)) && !mycrt1off) ) { ivideo->sisfb_crt1off = mycrt1off; if(sisfb_reset_mode(ivideo)) { sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OTHER; } } sisfb_command->sisfb_result[1] = ivideo->sisfb_crt1off ? 0 : 1; } break; /* more to come */ default: sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_UNKNOWN; printk(KERN_ERR "sisfb: Unknown command 0x%x\n", sisfb_command->sisfb_cmd); } } #ifndef MODULE static int __init sisfb_setup(char *options) { char *this_opt; sisfb_setdefaultparms(); if(!options || !(*options)) return 0; while((this_opt = strsep(&options, ",")) != NULL) { if(!(*this_opt)) continue; if(!strncasecmp(this_opt, "off", 3)) { sisfb_off = 1; } else if(!strncasecmp(this_opt, "forcecrt2type:", 14)) { /* Need to check crt2 type first for fstn/dstn */ sisfb_search_crt2type(this_opt + 14); } else if(!strncasecmp(this_opt, "tvmode:",7)) { sisfb_search_tvstd(this_opt + 7); } else if(!strncasecmp(this_opt, "tvstandard:",11)) { sisfb_search_tvstd(this_opt + 11); } else if(!strncasecmp(this_opt, "mode:", 5)) { sisfb_search_mode(this_opt + 5, false); } else if(!strncasecmp(this_opt, "vesa:", 5)) { sisfb_search_vesamode(simple_strtoul(this_opt + 5, NULL, 0), false); } else if(!strncasecmp(this_opt, "rate:", 5)) { sisfb_parm_rate = simple_strtoul(this_opt + 5, NULL, 0); } else if(!strncasecmp(this_opt, "forcecrt1:", 10)) { sisfb_forcecrt1 = (int)simple_strtoul(this_opt + 10, NULL, 0); } else if(!strncasecmp(this_opt, "mem:",4)) { sisfb_parm_mem = simple_strtoul(this_opt + 4, NULL, 0); } else if(!strncasecmp(this_opt, "pdc:", 4)) { sisfb_pdc = simple_strtoul(this_opt + 4, NULL, 0); } else if(!strncasecmp(this_opt, "pdc1:", 5)) { sisfb_pdca = simple_strtoul(this_opt + 5, NULL, 0); } else if(!strncasecmp(this_opt, "noaccel", 7)) { sisfb_accel = 0; } else if(!strncasecmp(this_opt, "accel", 5)) { sisfb_accel = -1; } else if(!strncasecmp(this_opt, "noypan", 6)) { sisfb_ypan = 0; } else if(!strncasecmp(this_opt, "ypan", 4)) { sisfb_ypan = -1; } else if(!strncasecmp(this_opt, "nomax", 5)) { sisfb_max = 0; } else if(!strncasecmp(this_opt, "max", 3)) { sisfb_max = -1; } else if(!strncasecmp(this_opt, "userom:", 7)) { sisfb_userom = (int)simple_strtoul(this_opt + 7, NULL, 0); } else if(!strncasecmp(this_opt, "useoem:", 7)) { sisfb_useoem = (int)simple_strtoul(this_opt + 7, NULL, 0); } else if(!strncasecmp(this_opt, "nocrt2rate", 10)) { sisfb_nocrt2rate = 1; } else if(!strncasecmp(this_opt, "scalelcd:", 9)) { unsigned long temp = 2; temp = simple_strtoul(this_opt + 9, NULL, 0); if((temp == 0) || (temp == 1)) { sisfb_scalelcd = temp ^ 1; } } else if(!strncasecmp(this_opt, "tvxposoffset:", 13)) { int temp = 0; temp = (int)simple_strtol(this_opt + 13, NULL, 0); if((temp >= -32) && (temp <= 32)) { sisfb_tvxposoffset = temp; } } else if(!strncasecmp(this_opt, "tvyposoffset:", 13)) { int temp = 0; temp = (int)simple_strtol(this_opt + 13, NULL, 0); if((temp >= -32) && (temp <= 32)) { sisfb_tvyposoffset = temp; } } else if(!strncasecmp(this_opt, "specialtiming:", 14)) { sisfb_search_specialtiming(this_opt + 14); } else if(!strncasecmp(this_opt, "lvdshl:", 7)) { int temp = 4; temp = simple_strtoul(this_opt + 7, NULL, 0); if((temp >= 0) && (temp <= 3)) { sisfb_lvdshl = temp; } } else if(this_opt[0] >= '0' && this_opt[0] <= '9') { sisfb_search_mode(this_opt, true); #if !defined(__i386__) && !defined(__x86_64__) } else if(!strncasecmp(this_opt, "resetcard", 9)) { sisfb_resetcard = 1; } else if(!strncasecmp(this_opt, "videoram:", 9)) { sisfb_videoram = simple_strtoul(this_opt + 9, NULL, 0); #endif } else { printk(KERN_INFO "sisfb: Invalid option %s\n", this_opt); } } return 0; } #endif static int sisfb_check_rom(void __iomem *rom_base, struct sis_video_info *ivideo) { void __iomem *rom; int romptr; if((readb(rom_base) != 0x55) || (readb(rom_base + 1) != 0xaa)) return 0; romptr = (readb(rom_base + 0x18) | (readb(rom_base + 0x19) << 8)); if(romptr > (0x10000 - 8)) return 0; rom = rom_base + romptr; if((readb(rom) != 'P') || (readb(rom + 1) != 'C') || (readb(rom + 2) != 'I') || (readb(rom + 3) != 'R')) return 0; if((readb(rom + 4) | (readb(rom + 5) << 8)) != ivideo->chip_vendor) return 0; if((readb(rom + 6) | (readb(rom + 7) << 8)) != ivideo->chip_id) return 0; return 1; } static unsigned char *sisfb_find_rom(struct pci_dev *pdev) { struct sis_video_info *ivideo = pci_get_drvdata(pdev); void __iomem *rom_base; unsigned char *myrombase = NULL; size_t romsize; /* First, try the official pci ROM functions (except * on integrated chipsets which have no ROM). */ if(!ivideo->nbridge) { if((rom_base = pci_map_rom(pdev, &romsize))) { if(sisfb_check_rom(rom_base, ivideo)) { if((myrombase = vmalloc(65536))) { memcpy_fromio(myrombase, rom_base, (romsize > 65536) ? 65536 : romsize); } } pci_unmap_rom(pdev, rom_base); } } if(myrombase) return myrombase; /* Otherwise do it the conventional way. */ #if defined(__i386__) || defined(__x86_64__) { u32 temp; for (temp = 0x000c0000; temp < 0x000f0000; temp += 0x00001000) { rom_base = ioremap(temp, 65536); if (!rom_base) continue; if (!sisfb_check_rom(rom_base, ivideo)) { iounmap(rom_base); continue; } if ((myrombase = vmalloc(65536))) memcpy_fromio(myrombase, rom_base, 65536); iounmap(rom_base); break; } } #endif return myrombase; } static void sisfb_post_map_vram(struct sis_video_info *ivideo, unsigned int *mapsize, unsigned int min) { if (*mapsize < (min << 20)) return; ivideo->video_vbase = ioremap_wc(ivideo->video_base, (*mapsize)); if(!ivideo->video_vbase) { printk(KERN_ERR "sisfb: Unable to map maximum video RAM for size detection\n"); (*mapsize) >>= 1; while((!(ivideo->video_vbase = ioremap_wc(ivideo->video_base, (*mapsize))))) { (*mapsize) >>= 1; if((*mapsize) < (min << 20)) break; } if(ivideo->video_vbase) { printk(KERN_ERR "sisfb: Video RAM size detection limited to %dMB\n", (int)((*mapsize) >> 20)); } } } #ifdef CONFIG_FB_SIS_300 static int sisfb_post_300_buswidth(struct sis_video_info *ivideo) { void __iomem *FBAddress = ivideo->video_vbase; unsigned short temp; unsigned char reg; int i, j; SiS_SetRegAND(SISSR, 0x15, 0xFB); SiS_SetRegOR(SISSR, 0x15, 0x04); SiS_SetReg(SISSR, 0x13, 0x00); SiS_SetReg(SISSR, 0x14, 0xBF); for(i = 0; i < 2; i++) { temp = 0x1234; for(j = 0; j < 4; j++) { writew(temp, FBAddress); if(readw(FBAddress) == temp) break; SiS_SetRegOR(SISSR, 0x3c, 0x01); reg = SiS_GetReg(SISSR, 0x05); reg = SiS_GetReg(SISSR, 0x05); SiS_SetRegAND(SISSR, 0x3c, 0xfe); reg = SiS_GetReg(SISSR, 0x05); reg = SiS_GetReg(SISSR, 0x05); temp++; } } writel(0x01234567L, FBAddress); writel(0x456789ABL, (FBAddress + 4)); writel(0x89ABCDEFL, (FBAddress + 8)); writel(0xCDEF0123L, (FBAddress + 12)); reg = SiS_GetReg(SISSR, 0x3b); if(reg & 0x01) { if(readl((FBAddress + 12)) == 0xCDEF0123L) return 4; /* Channel A 128bit */ } if(readl((FBAddress + 4)) == 0x456789ABL) return 2; /* Channel B 64bit */ return 1; /* 32bit */ } static const unsigned short SiS_DRAMType[17][5] = { {0x0C,0x0A,0x02,0x40,0x39}, {0x0D,0x0A,0x01,0x40,0x48}, {0x0C,0x09,0x02,0x20,0x35}, {0x0D,0x09,0x01,0x20,0x44}, {0x0C,0x08,0x02,0x10,0x31}, {0x0D,0x08,0x01,0x10,0x40}, {0x0C,0x0A,0x01,0x20,0x34}, {0x0C,0x09,0x01,0x08,0x32}, {0x0B,0x08,0x02,0x08,0x21}, {0x0C,0x08,0x01,0x08,0x30}, {0x0A,0x08,0x02,0x04,0x11}, {0x0B,0x0A,0x01,0x10,0x28}, {0x09,0x08,0x02,0x02,0x01}, {0x0B,0x09,0x01,0x08,0x24}, {0x0B,0x08,0x01,0x04,0x20}, {0x0A,0x08,0x01,0x02,0x10}, {0x09,0x08,0x01,0x01,0x00} }; static int sisfb_post_300_rwtest(struct sis_video_info *ivideo, int iteration, int buswidth, int PseudoRankCapacity, int PseudoAdrPinCount, unsigned int mapsize) { void __iomem *FBAddr = ivideo->video_vbase; unsigned short sr14; unsigned int k, RankCapacity, PageCapacity, BankNumHigh, BankNumMid; unsigned int PhysicalAdrOtherPage, PhysicalAdrHigh, PhysicalAdrHalfPage; for(k = 0; k < ARRAY_SIZE(SiS_DRAMType); k++) { RankCapacity = buswidth * SiS_DRAMType[k][3]; if(RankCapacity != PseudoRankCapacity) continue; if((SiS_DRAMType[k][2] + SiS_DRAMType[k][0]) > PseudoAdrPinCount) continue; BankNumHigh = RankCapacity * 16 * iteration - 1; if(iteration == 3) { /* Rank No */ BankNumMid = RankCapacity * 16 - 1; } else { BankNumMid = RankCapacity * 16 * iteration / 2 - 1; } PageCapacity = (1 << SiS_DRAMType[k][1]) * buswidth * 4; PhysicalAdrHigh = BankNumHigh; PhysicalAdrHalfPage = (PageCapacity / 2 + PhysicalAdrHigh) % PageCapacity; PhysicalAdrOtherPage = PageCapacity * SiS_DRAMType[k][2] + PhysicalAdrHigh; SiS_SetRegAND(SISSR, 0x15, 0xFB); /* Test */ SiS_SetRegOR(SISSR, 0x15, 0x04); /* Test */ sr14 = (SiS_DRAMType[k][3] * buswidth) - 1; if(buswidth == 4) sr14 |= 0x80; else if(buswidth == 2) sr14 |= 0x40; SiS_SetReg(SISSR, 0x13, SiS_DRAMType[k][4]); SiS_SetReg(SISSR, 0x14, sr14); BankNumHigh <<= 16; BankNumMid <<= 16; if((BankNumHigh + PhysicalAdrHigh >= mapsize) || (BankNumMid + PhysicalAdrHigh >= mapsize) || (BankNumHigh + PhysicalAdrHalfPage >= mapsize) || (BankNumHigh + PhysicalAdrOtherPage >= mapsize)) continue; /* Write data */ writew(((unsigned short)PhysicalAdrHigh), (FBAddr + BankNumHigh + PhysicalAdrHigh)); writew(((unsigned short)BankNumMid), (FBAddr + BankNumMid + PhysicalAdrHigh)); writew(((unsigned short)PhysicalAdrHalfPage), (FBAddr + BankNumHigh + PhysicalAdrHalfPage)); writew(((unsigned short)PhysicalAdrOtherPage), (FBAddr + BankNumHigh + PhysicalAdrOtherPage)); /* Read data */ if(readw(FBAddr + BankNumHigh + PhysicalAdrHigh) == PhysicalAdrHigh) return 1; } return 0; } static void sisfb_post_300_ramsize(struct pci_dev *pdev, unsigned int mapsize) { struct sis_video_info *ivideo = pci_get_drvdata(pdev); int i, j, buswidth; int PseudoRankCapacity, PseudoAdrPinCount; buswidth = sisfb_post_300_buswidth(ivideo); for(i = 6; i >= 0; i--) { PseudoRankCapacity = 1 << i; for(j = 4; j >= 1; j--) { PseudoAdrPinCount = 15 - j; if((PseudoRankCapacity * j) <= 64) { if(sisfb_post_300_rwtest(ivideo, j, buswidth, PseudoRankCapacity, PseudoAdrPinCount, mapsize)) return; } } } } static void sisfb_post_sis300(struct pci_dev *pdev) { struct sis_video_info *ivideo = pci_get_drvdata(pdev); unsigned char *bios = ivideo->SiS_Pr.VirtualRomBase; u8 reg, v1, v2, v3, v4, v5, v6, v7, v8; u16 index, rindex, memtype = 0; unsigned int mapsize; if(!ivideo->SiS_Pr.UseROM) bios = NULL; SiS_SetReg(SISSR, 0x05, 0x86); if(bios) { if(bios[0x52] & 0x80) { memtype = bios[0x52]; } else { memtype = SiS_GetReg(SISSR, 0x3a); } memtype &= 0x07; } v3 = 0x80; v6 = 0x80; if(ivideo->revision_id <= 0x13) { v1 = 0x44; v2 = 0x42; v4 = 0x44; v5 = 0x42; } else { v1 = 0x68; v2 = 0x43; /* Assume 125Mhz MCLK */ v4 = 0x68; v5 = 0x43; /* Assume 125Mhz ECLK */ if(bios) { index = memtype * 5; rindex = index + 0x54; v1 = bios[rindex++]; v2 = bios[rindex++]; v3 = bios[rindex++]; rindex = index + 0x7c; v4 = bios[rindex++]; v5 = bios[rindex++]; v6 = bios[rindex++]; } } SiS_SetReg(SISSR, 0x28, v1); SiS_SetReg(SISSR, 0x29, v2); SiS_SetReg(SISSR, 0x2a, v3); SiS_SetReg(SISSR, 0x2e, v4); SiS_SetReg(SISSR, 0x2f, v5); SiS_SetReg(SISSR, 0x30, v6); v1 = 0x10; if(bios) v1 = bios[0xa4]; SiS_SetReg(SISSR, 0x07, v1); /* DAC speed */ SiS_SetReg(SISSR, 0x11, 0x0f); /* DDC, power save */ v1 = 0x01; v2 = 0x43; v3 = 0x1e; v4 = 0x2a; v5 = 0x06; v6 = 0x00; v7 = 0x00; v8 = 0x00; if(bios) { memtype += 0xa5; v1 = bios[memtype]; v2 = bios[memtype + 8]; v3 = bios[memtype + 16]; v4 = bios[memtype + 24]; v5 = bios[memtype + 32]; v6 = bios[memtype + 40]; v7 = bios[memtype + 48]; v8 = bios[memtype + 56]; } if(ivideo->revision_id >= 0x80) v3 &= 0xfd; SiS_SetReg(SISSR, 0x15, v1); /* Ram type (assuming 0, BIOS 0xa5 step 8) */ SiS_SetReg(SISSR, 0x16, v2); SiS_SetReg(SISSR, 0x17, v3); SiS_SetReg(SISSR, 0x18, v4); SiS_SetReg(SISSR, 0x19, v5); SiS_SetReg(SISSR, 0x1a, v6); SiS_SetReg(SISSR, 0x1b, v7); SiS_SetReg(SISSR, 0x1c, v8); /* ---- */ SiS_SetRegAND(SISSR, 0x15, 0xfb); SiS_SetRegOR(SISSR, 0x15, 0x04); if(bios) { if(bios[0x53] & 0x02) { SiS_SetRegOR(SISSR, 0x19, 0x20); } } v1 = 0x04; /* DAC pedestal (BIOS 0xe5) */ if(ivideo->revision_id >= 0x80) v1 |= 0x01; SiS_SetReg(SISSR, 0x1f, v1); SiS_SetReg(SISSR, 0x20, 0xa4); /* linear & relocated io & disable a0000 */ v1 = 0xf6; v2 = 0x0d; v3 = 0x00; if(bios) { v1 = bios[0xe8]; v2 = bios[0xe9]; v3 = bios[0xea]; } SiS_SetReg(SISSR, 0x23, v1); SiS_SetReg(SISSR, 0x24, v2); SiS_SetReg(SISSR, 0x25, v3); SiS_SetReg(SISSR, 0x21, 0x84); SiS_SetReg(SISSR, 0x22, 0x00); SiS_SetReg(SISCR, 0x37, 0x00); SiS_SetRegOR(SISPART1, 0x24, 0x01); /* unlock crt2 */ SiS_SetReg(SISPART1, 0x00, 0x00); v1 = 0x40; v2 = 0x11; if(bios) { v1 = bios[0xec]; v2 = bios[0xeb]; } SiS_SetReg(SISPART1, 0x02, v1); if(ivideo->revision_id >= 0x80) v2 &= ~0x01; reg = SiS_GetReg(SISPART4, 0x00); if((reg == 1) || (reg == 2)) { SiS_SetReg(SISCR, 0x37, 0x02); SiS_SetReg(SISPART2, 0x00, 0x1c); v4 = 0x00; v5 = 0x00; v6 = 0x10; if(ivideo->SiS_Pr.UseROM) { v4 = bios[0xf5]; v5 = bios[0xf6]; v6 = bios[0xf7]; } SiS_SetReg(SISPART4, 0x0d, v4); SiS_SetReg(SISPART4, 0x0e, v5); SiS_SetReg(SISPART4, 0x10, v6); SiS_SetReg(SISPART4, 0x0f, 0x3f); reg = SiS_GetReg(SISPART4, 0x01); if(reg >= 0xb0) { reg = SiS_GetReg(SISPART4, 0x23); reg &= 0x20; reg <<= 1; SiS_SetReg(SISPART4, 0x23, reg); } } else { v2 &= ~0x10; } SiS_SetReg(SISSR, 0x32, v2); SiS_SetRegAND(SISPART1, 0x24, 0xfe); /* Lock CRT2 */ reg = SiS_GetReg(SISSR, 0x16); reg &= 0xc3; SiS_SetReg(SISCR, 0x35, reg); SiS_SetReg(SISCR, 0x83, 0x00); #if !defined(__i386__) && !defined(__x86_64__) if(sisfb_videoram) { SiS_SetReg(SISSR, 0x13, 0x28); /* ? */ reg = ((sisfb_videoram >> 10) - 1) | 0x40; SiS_SetReg(SISSR, 0x14, reg); } else { #endif /* Need to map max FB size for finding out about RAM size */ mapsize = ivideo->video_size; sisfb_post_map_vram(ivideo, &mapsize, 4); if(ivideo->video_vbase) { sisfb_post_300_ramsize(pdev, mapsize); iounmap(ivideo->video_vbase); } else { printk(KERN_DEBUG "sisfb: Failed to map memory for size detection, assuming 8MB\n"); SiS_SetReg(SISSR, 0x13, 0x28); /* ? */ SiS_SetReg(SISSR, 0x14, 0x47); /* 8MB, 64bit default */ } #if !defined(__i386__) && !defined(__x86_64__) } #endif if(bios) { v1 = bios[0xe6]; v2 = bios[0xe7]; } else { reg = SiS_GetReg(SISSR, 0x3a); if((reg & 0x30) == 0x30) { v1 = 0x04; /* PCI */ v2 = 0x92; } else { v1 = 0x14; /* AGP */ v2 = 0xb2; } } SiS_SetReg(SISSR, 0x21, v1); SiS_SetReg(SISSR, 0x22, v2); /* Sense CRT1 */ sisfb_sense_crt1(ivideo); /* Set default mode, don't clear screen */ ivideo->SiS_Pr.SiS_UseOEM = false; SiS_SetEnableDstn(&ivideo->SiS_Pr, false); SiS_SetEnableFstn(&ivideo->SiS_Pr, false); ivideo->curFSTN = ivideo->curDSTN = 0; ivideo->SiS_Pr.VideoMemorySize = 8 << 20; SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80); SiS_SetReg(SISSR, 0x05, 0x86); /* Display off */ SiS_SetRegOR(SISSR, 0x01, 0x20); /* Save mode number in CR34 */ SiS_SetReg(SISCR, 0x34, 0x2e); /* Let everyone know what the current mode is */ ivideo->modeprechange = 0x2e; } #endif #ifdef CONFIG_FB_SIS_315 #if 0 static void sisfb_post_sis315330(struct pci_dev *pdev) { /* TODO */ } #endif static inline int sisfb_xgi_is21(struct sis_video_info *ivideo) { return ivideo->chip_real_id == XGI_21; } static void sisfb_post_xgi_delay(struct sis_video_info *ivideo, int delay) { unsigned int i; u8 reg; for(i = 0; i <= (delay * 10 * 36); i++) { reg = SiS_GetReg(SISSR, 0x05); reg++; } } static int sisfb_find_host_bridge(struct sis_video_info *ivideo, struct pci_dev *mypdev, unsigned short pcivendor) { struct pci_dev *pdev = NULL; unsigned short temp; int ret = 0; while((pdev = pci_get_class(PCI_CLASS_BRIDGE_HOST, pdev))) { temp = pdev->vendor; if(temp == pcivendor) { ret = 1; pci_dev_put(pdev); break; } } return ret; } static int sisfb_post_xgi_rwtest(struct sis_video_info *ivideo, int starta, unsigned int enda, unsigned int mapsize) { unsigned int pos; int i; writel(0, ivideo->video_vbase); for(i = starta; i <= enda; i++) { pos = 1 << i; if(pos < mapsize) writel(pos, ivideo->video_vbase + pos); } sisfb_post_xgi_delay(ivideo, 150); if(readl(ivideo->video_vbase) != 0) return 0; for(i = starta; i <= enda; i++) { pos = 1 << i; if(pos < mapsize) { if(readl(ivideo->video_vbase + pos) != pos) return 0; } else return 0; } return 1; } static int sisfb_post_xgi_ramsize(struct sis_video_info *ivideo) { unsigned int buswidth, ranksize, channelab, mapsize; int i, j, k, l, status; u8 reg, sr14; static const u8 dramsr13[12 * 5] = { 0x02, 0x0e, 0x0b, 0x80, 0x5d, 0x02, 0x0e, 0x0a, 0x40, 0x59, 0x02, 0x0d, 0x0b, 0x40, 0x4d, 0x02, 0x0e, 0x09, 0x20, 0x55, 0x02, 0x0d, 0x0a, 0x20, 0x49, 0x02, 0x0c, 0x0b, 0x20, 0x3d, 0x02, 0x0e, 0x08, 0x10, 0x51, 0x02, 0x0d, 0x09, 0x10, 0x45, 0x02, 0x0c, 0x0a, 0x10, 0x39, 0x02, 0x0d, 0x08, 0x08, 0x41, 0x02, 0x0c, 0x09, 0x08, 0x35, 0x02, 0x0c, 0x08, 0x04, 0x31 }; static const u8 dramsr13_4[4 * 5] = { 0x02, 0x0d, 0x09, 0x40, 0x45, 0x02, 0x0c, 0x09, 0x20, 0x35, 0x02, 0x0c, 0x08, 0x10, 0x31, 0x02, 0x0b, 0x08, 0x08, 0x21 }; /* Enable linear mode, disable 0xa0000 address decoding */ /* We disable a0000 address decoding, because * - if running on x86, if the card is disabled, it means * that another card is in the system. We don't want * to interphere with that primary card's textmode. * - if running on non-x86, there usually is no VGA window * at a0000. */ SiS_SetRegOR(SISSR, 0x20, (0x80 | 0x04)); /* Need to map max FB size for finding out about RAM size */ mapsize = ivideo->video_size; sisfb_post_map_vram(ivideo, &mapsize, 32); if(!ivideo->video_vbase) { printk(KERN_ERR "sisfb: Unable to detect RAM size. Setting default.\n"); SiS_SetReg(SISSR, 0x13, 0x35); SiS_SetReg(SISSR, 0x14, 0x41); /* TODO */ return -ENOMEM; } /* Non-interleaving */ SiS_SetReg(SISSR, 0x15, 0x00); /* No tiling */ SiS_SetReg(SISSR, 0x1c, 0x00); if(ivideo->chip == XGI_20) { channelab = 1; reg = SiS_GetReg(SISCR, 0x97); if(!(reg & 0x01)) { /* Single 32/16 */ buswidth = 32; SiS_SetReg(SISSR, 0x13, 0xb1); SiS_SetReg(SISSR, 0x14, 0x52); sisfb_post_xgi_delay(ivideo, 1); sr14 = 0x02; if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize)) goto bail_out; SiS_SetReg(SISSR, 0x13, 0x31); SiS_SetReg(SISSR, 0x14, 0x42); sisfb_post_xgi_delay(ivideo, 1); if(sisfb_post_xgi_rwtest(ivideo, 23, 23, mapsize)) goto bail_out; buswidth = 16; SiS_SetReg(SISSR, 0x13, 0xb1); SiS_SetReg(SISSR, 0x14, 0x41); sisfb_post_xgi_delay(ivideo, 1); sr14 = 0x01; if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize)) goto bail_out; else SiS_SetReg(SISSR, 0x13, 0x31); } else { /* Dual 16/8 */ buswidth = 16; SiS_SetReg(SISSR, 0x13, 0xb1); SiS_SetReg(SISSR, 0x14, 0x41); sisfb_post_xgi_delay(ivideo, 1); sr14 = 0x01; if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize)) goto bail_out; SiS_SetReg(SISSR, 0x13, 0x31); SiS_SetReg(SISSR, 0x14, 0x31); sisfb_post_xgi_delay(ivideo, 1); if(sisfb_post_xgi_rwtest(ivideo, 22, 22, mapsize)) goto bail_out; buswidth = 8; SiS_SetReg(SISSR, 0x13, 0xb1); SiS_SetReg(SISSR, 0x14, 0x30); sisfb_post_xgi_delay(ivideo, 1); sr14 = 0x00; if(sisfb_post_xgi_rwtest(ivideo, 21, 22, mapsize)) goto bail_out; else SiS_SetReg(SISSR, 0x13, 0x31); } } else { /* XGI_40 */ reg = SiS_GetReg(SISCR, 0x97); if(!(reg & 0x10)) { reg = SiS_GetReg(SISSR, 0x39); reg >>= 1; } if(reg & 0x01) { /* DDRII */ buswidth = 32; if(ivideo->revision_id == 2) { channelab = 2; SiS_SetReg(SISSR, 0x13, 0xa1); SiS_SetReg(SISSR, 0x14, 0x44); sr14 = 0x04; sisfb_post_xgi_delay(ivideo, 1); if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize)) goto bail_out; SiS_SetReg(SISSR, 0x13, 0x21); SiS_SetReg(SISSR, 0x14, 0x34); if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize)) goto bail_out; channelab = 1; SiS_SetReg(SISSR, 0x13, 0xa1); SiS_SetReg(SISSR, 0x14, 0x40); sr14 = 0x00; if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize)) goto bail_out; SiS_SetReg(SISSR, 0x13, 0x21); SiS_SetReg(SISSR, 0x14, 0x30); } else { channelab = 3; SiS_SetReg(SISSR, 0x13, 0xa1); SiS_SetReg(SISSR, 0x14, 0x4c); sr14 = 0x0c; sisfb_post_xgi_delay(ivideo, 1); if(sisfb_post_xgi_rwtest(ivideo, 23, 25, mapsize)) goto bail_out; channelab = 2; SiS_SetReg(SISSR, 0x14, 0x48); sisfb_post_xgi_delay(ivideo, 1); sr14 = 0x08; if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize)) goto bail_out; SiS_SetReg(SISSR, 0x13, 0x21); SiS_SetReg(SISSR, 0x14, 0x3c); sr14 = 0x0c; if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize)) { channelab = 3; } else { channelab = 2; SiS_SetReg(SISSR, 0x14, 0x38); sr14 = 0x08; } } sisfb_post_xgi_delay(ivideo, 1); } else { /* DDR */ buswidth = 64; if(ivideo->revision_id == 2) { channelab = 1; SiS_SetReg(SISSR, 0x13, 0xa1); SiS_SetReg(SISSR, 0x14, 0x52); sisfb_post_xgi_delay(ivideo, 1); sr14 = 0x02; if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize)) goto bail_out; SiS_SetReg(SISSR, 0x13, 0x21); SiS_SetReg(SISSR, 0x14, 0x42); } else { channelab = 2; SiS_SetReg(SISSR, 0x13, 0xa1); SiS_SetReg(SISSR, 0x14, 0x5a); sisfb_post_xgi_delay(ivideo, 1); sr14 = 0x0a; if(sisfb_post_xgi_rwtest(ivideo, 24, 25, mapsize)) goto bail_out; SiS_SetReg(SISSR, 0x13, 0x21); SiS_SetReg(SISSR, 0x14, 0x4a); } sisfb_post_xgi_delay(ivideo, 1); } } bail_out: SiS_SetRegANDOR(SISSR, 0x14, 0xf0, sr14); sisfb_post_xgi_delay(ivideo, 1); j = (ivideo->chip == XGI_20) ? 5 : 9; k = (ivideo->chip == XGI_20) ? 12 : 4; status = -EIO; for(i = 0; i < k; i++) { reg = (ivideo->chip == XGI_20) ? dramsr13[(i * 5) + 4] : dramsr13_4[(i * 5) + 4]; SiS_SetRegANDOR(SISSR, 0x13, 0x80, reg); sisfb_post_xgi_delay(ivideo, 50); ranksize = (ivideo->chip == XGI_20) ? dramsr13[(i * 5) + 3] : dramsr13_4[(i * 5) + 3]; reg = SiS_GetReg(SISSR, 0x13); if(reg & 0x80) ranksize <<= 1; if(ivideo->chip == XGI_20) { if(buswidth == 16) ranksize <<= 1; else if(buswidth == 32) ranksize <<= 2; } else { if(buswidth == 64) ranksize <<= 1; } reg = 0; l = channelab; if(l == 3) l = 4; if((ranksize * l) <= 256) { while((ranksize >>= 1)) reg += 0x10; } if(!reg) continue; SiS_SetRegANDOR(SISSR, 0x14, 0x0f, (reg & 0xf0)); sisfb_post_xgi_delay(ivideo, 1); if (sisfb_post_xgi_rwtest(ivideo, j, ((reg >> 4) + channelab - 2 + 20), mapsize)) { status = 0; break; } } iounmap(ivideo->video_vbase); return status; } static void sisfb_post_xgi_setclocks(struct sis_video_info *ivideo, u8 regb) { u8 v1, v2, v3; int index; static const u8 cs90[8 * 3] = { 0x16, 0x01, 0x01, 0x3e, 0x03, 0x01, 0x7c, 0x08, 0x01, 0x79, 0x06, 0x01, 0x29, 0x01, 0x81, 0x5c, 0x23, 0x01, 0x5c, 0x23, 0x01, 0x5c, 0x23, 0x01 }; static const u8 csb8[8 * 3] = { 0x5c, 0x23, 0x01, 0x29, 0x01, 0x01, 0x7c, 0x08, 0x01, 0x79, 0x06, 0x01, 0x29, 0x01, 0x81, 0x5c, 0x23, 0x01, 0x5c, 0x23, 0x01, 0x5c, 0x23, 0x01 }; regb = 0; /* ! */ index = regb * 3; v1 = cs90[index]; v2 = cs90[index + 1]; v3 = cs90[index + 2]; if(ivideo->haveXGIROM) { v1 = ivideo->bios_abase[0x90 + index]; v2 = ivideo->bios_abase[0x90 + index + 1]; v3 = ivideo->bios_abase[0x90 + index + 2]; } SiS_SetReg(SISSR, 0x28, v1); SiS_SetReg(SISSR, 0x29, v2); SiS_SetReg(SISSR, 0x2a, v3); sisfb_post_xgi_delay(ivideo, 0x43); sisfb_post_xgi_delay(ivideo, 0x43); sisfb_post_xgi_delay(ivideo, 0x43); index = regb * 3; v1 = csb8[index]; v2 = csb8[index + 1]; v3 = csb8[index + 2]; if(ivideo->haveXGIROM) { v1 = ivideo->bios_abase[0xb8 + index]; v2 = ivideo->bios_abase[0xb8 + index + 1]; v3 = ivideo->bios_abase[0xb8 + index + 2]; } SiS_SetReg(SISSR, 0x2e, v1); SiS_SetReg(SISSR, 0x2f, v2); SiS_SetReg(SISSR, 0x30, v3); sisfb_post_xgi_delay(ivideo, 0x43); sisfb_post_xgi_delay(ivideo, 0x43); sisfb_post_xgi_delay(ivideo, 0x43); } static void sisfb_post_xgi_ddr2_mrs_default(struct sis_video_info *ivideo, u8 regb) { unsigned char *bios = ivideo->bios_abase; u8 v1; SiS_SetReg(SISSR, 0x28, 0x64); SiS_SetReg(SISSR, 0x29, 0x63); sisfb_post_xgi_delay(ivideo, 15); SiS_SetReg(SISSR, 0x18, 0x00); SiS_SetReg(SISSR, 0x19, 0x20); SiS_SetReg(SISSR, 0x16, 0x00); SiS_SetReg(SISSR, 0x16, 0x80); SiS_SetReg(SISSR, 0x18, 0xc5); SiS_SetReg(SISSR, 0x19, 0x23); SiS_SetReg(SISSR, 0x16, 0x00); SiS_SetReg(SISSR, 0x16, 0x80); sisfb_post_xgi_delay(ivideo, 1); SiS_SetReg(SISCR, 0x97, 0x11); sisfb_post_xgi_setclocks(ivideo, regb); sisfb_post_xgi_delay(ivideo, 0x46); SiS_SetReg(SISSR, 0x18, 0xc5); SiS_SetReg(SISSR, 0x19, 0x23); SiS_SetReg(SISSR, 0x16, 0x00); SiS_SetReg(SISSR, 0x16, 0x80); sisfb_post_xgi_delay(ivideo, 1); SiS_SetReg(SISSR, 0x1b, 0x04); sisfb_post_xgi_delay(ivideo, 1); SiS_SetReg(SISSR, 0x1b, 0x00); sisfb_post_xgi_delay(ivideo, 1); v1 = 0x31; if (ivideo->haveXGIROM) { v1 = bios[0xf0]; } SiS_SetReg(SISSR, 0x18, v1); SiS_SetReg(SISSR, 0x19, 0x06); SiS_SetReg(SISSR, 0x16, 0x04); SiS_SetReg(SISSR, 0x16, 0x84); sisfb_post_xgi_delay(ivideo, 1); } static void sisfb_post_xgi_ddr2_mrs_xg21(struct sis_video_info *ivideo) { sisfb_post_xgi_setclocks(ivideo, 1); SiS_SetReg(SISCR, 0x97, 0x11); sisfb_post_xgi_delay(ivideo, 0x46); SiS_SetReg(SISSR, 0x18, 0x00); /* EMRS2 */ SiS_SetReg(SISSR, 0x19, 0x80); SiS_SetReg(SISSR, 0x16, 0x05); SiS_SetReg(SISSR, 0x16, 0x85); SiS_SetReg(SISSR, 0x18, 0x00); /* EMRS3 */ SiS_SetReg(SISSR, 0x19, 0xc0); SiS_SetReg(SISSR, 0x16, 0x05); SiS_SetReg(SISSR, 0x16, 0x85); SiS_SetReg(SISSR, 0x18, 0x00); /* EMRS1 */ SiS_SetReg(SISSR, 0x19, 0x40); SiS_SetReg(SISSR, 0x16, 0x05); SiS_SetReg(SISSR, 0x16, 0x85); SiS_SetReg(SISSR, 0x18, 0x42); /* MRS1 */ SiS_SetReg(SISSR, 0x19, 0x02); SiS_SetReg(SISSR, 0x16, 0x05); SiS_SetReg(SISSR, 0x16, 0x85); sisfb_post_xgi_delay(ivideo, 1); SiS_SetReg(SISSR, 0x1b, 0x04); sisfb_post_xgi_delay(ivideo, 1); SiS_SetReg(SISSR, 0x1b, 0x00); sisfb_post_xgi_delay(ivideo, 1); SiS_SetReg(SISSR, 0x18, 0x42); /* MRS1 */ SiS_SetReg(SISSR, 0x19, 0x00); SiS_SetReg(SISSR, 0x16, 0x05); SiS_SetReg(SISSR, 0x16, 0x85); sisfb_post_xgi_delay(ivideo, 1); } static void sisfb_post_xgi_ddr2(struct sis_video_info *ivideo, u8 regb) { unsigned char *bios = ivideo->bios_abase; static const u8 cs158[8] = { 0x88, 0xaa, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs160[8] = { 0x44, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs168[8] = { 0x48, 0x78, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00 }; u8 reg; u8 v1; u8 v2; u8 v3; SiS_SetReg(SISCR, 0xb0, 0x80); /* DDR2 dual frequency mode */ SiS_SetReg(SISCR, 0x82, 0x77); SiS_SetReg(SISCR, 0x86, 0x00); reg = SiS_GetReg(SISCR, 0x86); SiS_SetReg(SISCR, 0x86, 0x88); reg = SiS_GetReg(SISCR, 0x86); v1 = cs168[regb]; v2 = cs160[regb]; v3 = cs158[regb]; if (ivideo->haveXGIROM) { v1 = bios[regb + 0x168]; v2 = bios[regb + 0x160]; v3 = bios[regb + 0x158]; } SiS_SetReg(SISCR, 0x86, v1); SiS_SetReg(SISCR, 0x82, 0x77); SiS_SetReg(SISCR, 0x85, 0x00); reg = SiS_GetReg(SISCR, 0x85); SiS_SetReg(SISCR, 0x85, 0x88); reg = SiS_GetReg(SISCR, 0x85); SiS_SetReg(SISCR, 0x85, v2); SiS_SetReg(SISCR, 0x82, v3); SiS_SetReg(SISCR, 0x98, 0x01); SiS_SetReg(SISCR, 0x9a, 0x02); if (sisfb_xgi_is21(ivideo)) sisfb_post_xgi_ddr2_mrs_xg21(ivideo); else sisfb_post_xgi_ddr2_mrs_default(ivideo, regb); } static u8 sisfb_post_xgi_ramtype(struct sis_video_info *ivideo) { unsigned char *bios = ivideo->bios_abase; u8 ramtype; u8 reg; u8 v1; ramtype = 0x00; v1 = 0x10; if (ivideo->haveXGIROM) { ramtype = bios[0x62]; v1 = bios[0x1d2]; } if (!(ramtype & 0x80)) { if (sisfb_xgi_is21(ivideo)) { SiS_SetRegAND(SISCR, 0xb4, 0xfd); /* GPIO control */ SiS_SetRegOR(SISCR, 0x4a, 0x80); /* GPIOH EN */ reg = SiS_GetReg(SISCR, 0x48); SiS_SetRegOR(SISCR, 0xb4, 0x02); ramtype = reg & 0x01; /* GPIOH */ } else if (ivideo->chip == XGI_20) { SiS_SetReg(SISCR, 0x97, v1); reg = SiS_GetReg(SISCR, 0x97); if (reg & 0x10) { ramtype = (reg & 0x01) << 1; } } else { reg = SiS_GetReg(SISSR, 0x39); ramtype = reg & 0x02; if (!(ramtype)) { reg = SiS_GetReg(SISSR, 0x3a); ramtype = (reg >> 1) & 0x01; } } } ramtype &= 0x07; return ramtype; } static int sisfb_post_xgi(struct pci_dev *pdev) { struct sis_video_info *ivideo = pci_get_drvdata(pdev); unsigned char *bios = ivideo->bios_abase; struct pci_dev *mypdev = NULL; const u8 *ptr, *ptr2; u8 v1, v2, v3, v4, v5, reg, ramtype; u32 rega, regb, regd; int i, j, k, index; static const u8 cs78[3] = { 0xf6, 0x0d, 0x00 }; static const u8 cs76[2] = { 0xa3, 0xfb }; static const u8 cs7b[3] = { 0xc0, 0x11, 0x00 }; static const u8 cs158[8] = { 0x88, 0xaa, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs160[8] = { 0x44, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs168[8] = { 0x48, 0x78, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs128[3 * 8] = { 0x90, 0x28, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs148[2 * 8] = { 0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs31a[8 * 4] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs33a[8 * 4] = { 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs45a[8 * 2] = { 0x00, 0x00, 0xa0, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs170[7 * 8] = { 0x54, 0x32, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x43, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x34, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0a, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs1a8[3 * 8] = { 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u8 cs100[2 * 8] = { 0xc4, 0x04, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x04, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 }; /* VGA enable */ reg = SiS_GetRegByte(SISVGAENABLE) | 0x01; SiS_SetRegByte(SISVGAENABLE, reg); /* Misc */ reg = SiS_GetRegByte(SISMISCR) | 0x01; SiS_SetRegByte(SISMISCW, reg); /* Unlock SR */ SiS_SetReg(SISSR, 0x05, 0x86); reg = SiS_GetReg(SISSR, 0x05); if(reg != 0xa1) return 0; /* Clear some regs */ for(i = 0; i < 0x22; i++) { if(0x06 + i == 0x20) continue; SiS_SetReg(SISSR, 0x06 + i, 0x00); } for(i = 0; i < 0x0b; i++) { SiS_SetReg(SISSR, 0x31 + i, 0x00); } for(i = 0; i < 0x10; i++) { SiS_SetReg(SISCR, 0x30 + i, 0x00); } ptr = cs78; if(ivideo->haveXGIROM) { ptr = (const u8 *)&bios[0x78]; } for(i = 0; i < 3; i++) { SiS_SetReg(SISSR, 0x23 + i, ptr[i]); } ptr = cs76; if(ivideo->haveXGIROM) { ptr = (const u8 *)&bios[0x76]; } for(i = 0; i < 2; i++) { SiS_SetReg(SISSR, 0x21 + i, ptr[i]); } v1 = 0x18; v2 = 0x00; if(ivideo->haveXGIROM) { v1 = bios[0x74]; v2 = bios[0x75]; } SiS_SetReg(SISSR, 0x07, v1); SiS_SetReg(SISSR, 0x11, 0x0f); SiS_SetReg(SISSR, 0x1f, v2); /* PCI linear mode, RelIO enabled, A0000 decoding disabled */ SiS_SetReg(SISSR, 0x20, 0x80 | 0x20 | 0x04); SiS_SetReg(SISSR, 0x27, 0x74); ptr = cs7b; if(ivideo->haveXGIROM) { ptr = (const u8 *)&bios[0x7b]; } for(i = 0; i < 3; i++) { SiS_SetReg(SISSR, 0x31 + i, ptr[i]); } if(ivideo->chip == XGI_40) { if(ivideo->revision_id == 2) { SiS_SetRegANDOR(SISSR, 0x3b, 0x3f, 0xc0); } SiS_SetReg(SISCR, 0x7d, 0xfe); SiS_SetReg(SISCR, 0x7e, 0x0f); } if(ivideo->revision_id == 0) { /* 40 *and* 20? */ SiS_SetRegAND(SISCR, 0x58, 0xd7); reg = SiS_GetReg(SISCR, 0xcb); if(reg & 0x20) { SiS_SetRegANDOR(SISCR, 0x58, 0xd7, (reg & 0x10) ? 0x08 : 0x20); /* =0x28 Z7 ? */ } } reg = (ivideo->chip == XGI_40) ? 0x20 : 0x00; SiS_SetRegANDOR(SISCR, 0x38, 0x1f, reg); if(ivideo->chip == XGI_20) { SiS_SetReg(SISSR, 0x36, 0x70); } else { SiS_SetReg(SISVID, 0x00, 0x86); SiS_SetReg(SISVID, 0x32, 0x00); SiS_SetReg(SISVID, 0x30, 0x00); SiS_SetReg(SISVID, 0x32, 0x01); SiS_SetReg(SISVID, 0x30, 0x00); SiS_SetRegAND(SISVID, 0x2f, 0xdf); SiS_SetRegAND(SISCAP, 0x00, 0x3f); SiS_SetReg(SISPART1, 0x2f, 0x01); SiS_SetReg(SISPART1, 0x00, 0x00); SiS_SetReg(SISPART1, 0x02, bios[0x7e]); SiS_SetReg(SISPART1, 0x2e, 0x08); SiS_SetRegAND(SISPART1, 0x35, 0x7f); SiS_SetRegAND(SISPART1, 0x50, 0xfe); reg = SiS_GetReg(SISPART4, 0x00); if(reg == 1 || reg == 2) { SiS_SetReg(SISPART2, 0x00, 0x1c); SiS_SetReg(SISPART4, 0x0d, bios[0x7f]); SiS_SetReg(SISPART4, 0x0e, bios[0x80]); SiS_SetReg(SISPART4, 0x10, bios[0x81]); SiS_SetRegAND(SISPART4, 0x0f, 0x3f); reg = SiS_GetReg(SISPART4, 0x01); if((reg & 0xf0) >= 0xb0) { reg = SiS_GetReg(SISPART4, 0x23); if(reg & 0x20) reg |= 0x40; SiS_SetReg(SISPART4, 0x23, reg); reg = (reg & 0x20) ? 0x02 : 0x00; SiS_SetRegANDOR(SISPART1, 0x1e, 0xfd, reg); } } v1 = bios[0x77]; reg = SiS_GetReg(SISSR, 0x3b); if(reg & 0x02) { reg = SiS_GetReg(SISSR, 0x3a); v2 = (reg & 0x30) >> 3; if(!(v2 & 0x04)) v2 ^= 0x02; reg = SiS_GetReg(SISSR, 0x39); if(reg & 0x80) v2 |= 0x80; v2 |= 0x01; if((mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0730, NULL))) { pci_dev_put(mypdev); if(((v2 & 0x06) == 2) || ((v2 & 0x06) == 4)) v2 &= 0xf9; v2 |= 0x08; v1 &= 0xfe; } else { mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0735, NULL); if(!mypdev) mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0645, NULL); if(!mypdev) mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0650, NULL); if(mypdev) { pci_read_config_dword(mypdev, 0x94, &regd); regd &= 0xfffffeff; pci_write_config_dword(mypdev, 0x94, regd); v1 &= 0xfe; pci_dev_put(mypdev); } else if(sisfb_find_host_bridge(ivideo, pdev, PCI_VENDOR_ID_SI)) { v1 &= 0xfe; } else if(sisfb_find_host_bridge(ivideo, pdev, 0x1106) || sisfb_find_host_bridge(ivideo, pdev, 0x1022) || sisfb_find_host_bridge(ivideo, pdev, 0x700e) || sisfb_find_host_bridge(ivideo, pdev, 0x10de)) { if((v2 & 0x06) == 4) v2 ^= 0x06; v2 |= 0x08; } } SiS_SetRegANDOR(SISCR, 0x5f, 0xf0, v2); } SiS_SetReg(SISSR, 0x22, v1); if(ivideo->revision_id == 2) { v1 = SiS_GetReg(SISSR, 0x3b); v2 = SiS_GetReg(SISSR, 0x3a); regd = bios[0x90 + 3] | (bios[0x90 + 4] << 8); if( (!(v1 & 0x02)) && (v2 & 0x30) && (regd < 0xcf) ) SiS_SetRegANDOR(SISCR, 0x5f, 0xf1, 0x01); if((mypdev = pci_get_device(0x10de, 0x01e0, NULL))) { /* TODO: set CR5f &0xf1 | 0x01 for version 6570 * of nforce 2 ROM */ if(0) SiS_SetRegANDOR(SISCR, 0x5f, 0xf1, 0x01); pci_dev_put(mypdev); } } v1 = 0x30; reg = SiS_GetReg(SISSR, 0x3b); v2 = SiS_GetReg(SISCR, 0x5f); if((!(reg & 0x02)) && (v2 & 0x0e)) v1 |= 0x08; SiS_SetReg(SISSR, 0x27, v1); if(bios[0x64] & 0x01) { SiS_SetRegANDOR(SISCR, 0x5f, 0xf0, bios[0x64]); } v1 = bios[0x4f7]; pci_read_config_dword(pdev, 0x50, &regd); regd = (regd >> 20) & 0x0f; if(regd == 1) { v1 &= 0xfc; SiS_SetRegOR(SISCR, 0x5f, 0x08); } SiS_SetReg(SISCR, 0x48, v1); SiS_SetRegANDOR(SISCR, 0x47, 0x04, bios[0x4f6] & 0xfb); SiS_SetRegANDOR(SISCR, 0x49, 0xf0, bios[0x4f8] & 0x0f); SiS_SetRegANDOR(SISCR, 0x4a, 0x60, bios[0x4f9] & 0x9f); SiS_SetRegANDOR(SISCR, 0x4b, 0x08, bios[0x4fa] & 0xf7); SiS_SetRegANDOR(SISCR, 0x4c, 0x80, bios[0x4fb] & 0x7f); SiS_SetReg(SISCR, 0x70, bios[0x4fc]); SiS_SetRegANDOR(SISCR, 0x71, 0xf0, bios[0x4fd] & 0x0f); SiS_SetReg(SISCR, 0x74, 0xd0); SiS_SetRegANDOR(SISCR, 0x74, 0xcf, bios[0x4fe] & 0x30); SiS_SetRegANDOR(SISCR, 0x75, 0xe0, bios[0x4ff] & 0x1f); SiS_SetRegANDOR(SISCR, 0x76, 0xe0, bios[0x500] & 0x1f); v1 = bios[0x501]; if((mypdev = pci_get_device(0x8086, 0x2530, NULL))) { v1 = 0xf0; pci_dev_put(mypdev); } SiS_SetReg(SISCR, 0x77, v1); } /* RAM type: * * 0 == DDR1, 1 == DDR2, 2..7 == reserved? * * The code seems to written so that regb should equal ramtype, * however, so far it has been hardcoded to 0. Enable other values only * on XGI Z9, as it passes the POST, and add a warning for others. */ ramtype = sisfb_post_xgi_ramtype(ivideo); if (!sisfb_xgi_is21(ivideo) && ramtype) { dev_warn(&pdev->dev, "RAM type something else than expected: %d\n", ramtype); regb = 0; } else { regb = ramtype; } v1 = 0xff; if(ivideo->haveXGIROM) { v1 = bios[0x140 + regb]; } SiS_SetReg(SISCR, 0x6d, v1); ptr = cs128; if(ivideo->haveXGIROM) { ptr = (const u8 *)&bios[0x128]; } for(i = 0, j = 0; i < 3; i++, j += 8) { SiS_SetReg(SISCR, 0x68 + i, ptr[j + regb]); } ptr = cs31a; ptr2 = cs33a; if(ivideo->haveXGIROM) { index = (ivideo->chip == XGI_20) ? 0x31a : 0x3a6; ptr = (const u8 *)&bios[index]; ptr2 = (const u8 *)&bios[index + 0x20]; } for(i = 0; i < 2; i++) { if(i == 0) { regd = le32_to_cpu(((u32 *)ptr)[regb]); rega = 0x6b; } else { regd = le32_to_cpu(((u32 *)ptr2)[regb]); rega = 0x6e; } reg = 0x00; for(j = 0; j < 16; j++) { reg &= 0xf3; if(regd & 0x01) reg |= 0x04; if(regd & 0x02) reg |= 0x08; regd >>= 2; SiS_SetReg(SISCR, rega, reg); reg = SiS_GetReg(SISCR, rega); reg = SiS_GetReg(SISCR, rega); reg += 0x10; } } SiS_SetRegAND(SISCR, 0x6e, 0xfc); ptr = NULL; if(ivideo->haveXGIROM) { index = (ivideo->chip == XGI_20) ? 0x35a : 0x3e6; ptr = (const u8 *)&bios[index]; } for(i = 0; i < 4; i++) { SiS_SetRegANDOR(SISCR, 0x6e, 0xfc, i); reg = 0x00; for(j = 0; j < 2; j++) { regd = 0; if(ptr) { regd = le32_to_cpu(((u32 *)ptr)[regb * 8]); ptr += 4; } /* reg = 0x00; */ for(k = 0; k < 16; k++) { reg &= 0xfc; if(regd & 0x01) reg |= 0x01; if(regd & 0x02) reg |= 0x02; regd >>= 2; SiS_SetReg(SISCR, 0x6f, reg); reg = SiS_GetReg(SISCR, 0x6f); reg = SiS_GetReg(SISCR, 0x6f); reg += 0x08; } } } ptr = cs148; if(ivideo->haveXGIROM) { ptr = (const u8 *)&bios[0x148]; } for(i = 0, j = 0; i < 2; i++, j += 8) { SiS_SetReg(SISCR, 0x80 + i, ptr[j + regb]); } SiS_SetRegAND(SISCR, 0x89, 0x8f); ptr = cs45a; if(ivideo->haveXGIROM) { index = (ivideo->chip == XGI_20) ? 0x45a : 0x4e6; ptr = (const u8 *)&bios[index]; } regd = le16_to_cpu(((const u16 *)ptr)[regb]); reg = 0x80; for(i = 0; i < 5; i++) { reg &= 0xfc; if(regd & 0x01) reg |= 0x01; if(regd & 0x02) reg |= 0x02; regd >>= 2; SiS_SetReg(SISCR, 0x89, reg); reg = SiS_GetReg(SISCR, 0x89); reg = SiS_GetReg(SISCR, 0x89); reg += 0x10; } v1 = 0xb5; v2 = 0x20; v3 = 0xf0; v4 = 0x13; if(ivideo->haveXGIROM) { v1 = bios[0x118 + regb]; v2 = bios[0xf8 + regb]; v3 = bios[0x120 + regb]; v4 = bios[0x1ca]; } SiS_SetReg(SISCR, 0x45, v1 & 0x0f); SiS_SetReg(SISCR, 0x99, (v1 >> 4) & 0x07); SiS_SetRegOR(SISCR, 0x40, v1 & 0x80); SiS_SetReg(SISCR, 0x41, v2); ptr = cs170; if(ivideo->haveXGIROM) { ptr = (const u8 *)&bios[0x170]; } for(i = 0, j = 0; i < 7; i++, j += 8) { SiS_SetReg(SISCR, 0x90 + i, ptr[j + regb]); } SiS_SetReg(SISCR, 0x59, v3); ptr = cs1a8; if(ivideo->haveXGIROM) { ptr = (const u8 *)&bios[0x1a8]; } for(i = 0, j = 0; i < 3; i++, j += 8) { SiS_SetReg(SISCR, 0xc3 + i, ptr[j + regb]); } ptr = cs100; if(ivideo->haveXGIROM) { ptr = (const u8 *)&bios[0x100]; } for(i = 0, j = 0; i < 2; i++, j += 8) { SiS_SetReg(SISCR, 0x8a + i, ptr[j + regb]); } SiS_SetReg(SISCR, 0xcf, v4); SiS_SetReg(SISCR, 0x83, 0x09); SiS_SetReg(SISCR, 0x87, 0x00); if(ivideo->chip == XGI_40) { if( (ivideo->revision_id == 1) || (ivideo->revision_id == 2) ) { SiS_SetReg(SISCR, 0x8c, 0x87); } } if (regb == 1) SiS_SetReg(SISSR, 0x17, 0x80); /* DDR2 */ else SiS_SetReg(SISSR, 0x17, 0x00); /* DDR1 */ SiS_SetReg(SISSR, 0x1a, 0x87); if(ivideo->chip == XGI_20) { SiS_SetReg(SISSR, 0x15, 0x00); SiS_SetReg(SISSR, 0x1c, 0x00); } switch(ramtype) { case 0: sisfb_post_xgi_setclocks(ivideo, regb); if((ivideo->chip == XGI_20) || (ivideo->revision_id == 1) || (ivideo->revision_id == 2)) { v1 = cs158[regb]; v2 = cs160[regb]; v3 = cs168[regb]; if(ivideo->haveXGIROM) { v1 = bios[regb + 0x158]; v2 = bios[regb + 0x160]; v3 = bios[regb + 0x168]; } SiS_SetReg(SISCR, 0x82, v1); SiS_SetReg(SISCR, 0x85, v2); SiS_SetReg(SISCR, 0x86, v3); } else { SiS_SetReg(SISCR, 0x82, 0x88); SiS_SetReg(SISCR, 0x86, 0x00); reg = SiS_GetReg(SISCR, 0x86); SiS_SetReg(SISCR, 0x86, 0x88); reg = SiS_GetReg(SISCR, 0x86); SiS_SetReg(SISCR, 0x86, bios[regb + 0x168]); SiS_SetReg(SISCR, 0x82, 0x77); SiS_SetReg(SISCR, 0x85, 0x00); reg = SiS_GetReg(SISCR, 0x85); SiS_SetReg(SISCR, 0x85, 0x88); reg = SiS_GetReg(SISCR, 0x85); SiS_SetReg(SISCR, 0x85, bios[regb + 0x160]); SiS_SetReg(SISCR, 0x82, bios[regb + 0x158]); } if(ivideo->chip == XGI_40) { SiS_SetReg(SISCR, 0x97, 0x00); } SiS_SetReg(SISCR, 0x98, 0x01); SiS_SetReg(SISCR, 0x9a, 0x02); SiS_SetReg(SISSR, 0x18, 0x01); if((ivideo->chip == XGI_20) || (ivideo->revision_id == 2)) { SiS_SetReg(SISSR, 0x19, 0x40); } else { SiS_SetReg(SISSR, 0x19, 0x20); } SiS_SetReg(SISSR, 0x16, 0x00); SiS_SetReg(SISSR, 0x16, 0x80); if((ivideo->chip == XGI_20) || (bios[0x1cb] != 0x0c)) { sisfb_post_xgi_delay(ivideo, 0x43); sisfb_post_xgi_delay(ivideo, 0x43); sisfb_post_xgi_delay(ivideo, 0x43); SiS_SetReg(SISSR, 0x18, 0x00); if((ivideo->chip == XGI_20) || (ivideo->revision_id == 2)) { SiS_SetReg(SISSR, 0x19, 0x40); } else { SiS_SetReg(SISSR, 0x19, 0x20); } } else if((ivideo->chip == XGI_40) && (bios[0x1cb] == 0x0c)) { /* SiS_SetReg(SISSR, 0x16, 0x0c); */ /* ? */ } SiS_SetReg(SISSR, 0x16, 0x00); SiS_SetReg(SISSR, 0x16, 0x80); sisfb_post_xgi_delay(ivideo, 4); v1 = 0x31; v2 = 0x03; v3 = 0x83; v4 = 0x03; v5 = 0x83; if(ivideo->haveXGIROM) { v1 = bios[0xf0]; index = (ivideo->chip == XGI_20) ? 0x4b2 : 0x53e; v2 = bios[index]; v3 = bios[index + 1]; v4 = bios[index + 2]; v5 = bios[index + 3]; } SiS_SetReg(SISSR, 0x18, v1); SiS_SetReg(SISSR, 0x19, ((ivideo->chip == XGI_20) ? 0x02 : 0x01)); SiS_SetReg(SISSR, 0x16, v2); SiS_SetReg(SISSR, 0x16, v3); sisfb_post_xgi_delay(ivideo, 0x43); SiS_SetReg(SISSR, 0x1b, 0x03); sisfb_post_xgi_delay(ivideo, 0x22); SiS_SetReg(SISSR, 0x18, v1); SiS_SetReg(SISSR, 0x19, 0x00); SiS_SetReg(SISSR, 0x16, v4); SiS_SetReg(SISSR, 0x16, v5); SiS_SetReg(SISSR, 0x1b, 0x00); break; case 1: sisfb_post_xgi_ddr2(ivideo, regb); break; default: sisfb_post_xgi_setclocks(ivideo, regb); if((ivideo->chip == XGI_40) && ((ivideo->revision_id == 1) || (ivideo->revision_id == 2))) { SiS_SetReg(SISCR, 0x82, bios[regb + 0x158]); SiS_SetReg(SISCR, 0x85, bios[regb + 0x160]); SiS_SetReg(SISCR, 0x86, bios[regb + 0x168]); } else { SiS_SetReg(SISCR, 0x82, 0x88); SiS_SetReg(SISCR, 0x86, 0x00); reg = SiS_GetReg(SISCR, 0x86); SiS_SetReg(SISCR, 0x86, 0x88); SiS_SetReg(SISCR, 0x82, 0x77); SiS_SetReg(SISCR, 0x85, 0x00); reg = SiS_GetReg(SISCR, 0x85); SiS_SetReg(SISCR, 0x85, 0x88); reg = SiS_GetReg(SISCR, 0x85); v1 = cs160[regb]; v2 = cs158[regb]; if(ivideo->haveXGIROM) { v1 = bios[regb + 0x160]; v2 = bios[regb + 0x158]; } SiS_SetReg(SISCR, 0x85, v1); SiS_SetReg(SISCR, 0x82, v2); } if(ivideo->chip == XGI_40) { SiS_SetReg(SISCR, 0x97, 0x11); } if((ivideo->chip == XGI_40) && (ivideo->revision_id == 2)) { SiS_SetReg(SISCR, 0x98, 0x01); } else { SiS_SetReg(SISCR, 0x98, 0x03); } SiS_SetReg(SISCR, 0x9a, 0x02); if(ivideo->chip == XGI_40) { SiS_SetReg(SISSR, 0x18, 0x01); } else { SiS_SetReg(SISSR, 0x18, 0x00); } SiS_SetReg(SISSR, 0x19, 0x40); SiS_SetReg(SISSR, 0x16, 0x00); SiS_SetReg(SISSR, 0x16, 0x80); if((ivideo->chip == XGI_40) && (bios[0x1cb] != 0x0c)) { sisfb_post_xgi_delay(ivideo, 0x43); sisfb_post_xgi_delay(ivideo, 0x43); sisfb_post_xgi_delay(ivideo, 0x43); SiS_SetReg(SISSR, 0x18, 0x00); SiS_SetReg(SISSR, 0x19, 0x40); SiS_SetReg(SISSR, 0x16, 0x00); SiS_SetReg(SISSR, 0x16, 0x80); } sisfb_post_xgi_delay(ivideo, 4); v1 = 0x31; if(ivideo->haveXGIROM) { v1 = bios[0xf0]; } SiS_SetReg(SISSR, 0x18, v1); SiS_SetReg(SISSR, 0x19, 0x01); if(ivideo->chip == XGI_40) { SiS_SetReg(SISSR, 0x16, bios[0x53e]); SiS_SetReg(SISSR, 0x16, bios[0x53f]); } else { SiS_SetReg(SISSR, 0x16, 0x05); SiS_SetReg(SISSR, 0x16, 0x85); } sisfb_post_xgi_delay(ivideo, 0x43); if(ivideo->chip == XGI_40) { SiS_SetReg(SISSR, 0x1b, 0x01); } else { SiS_SetReg(SISSR, 0x1b, 0x03); } sisfb_post_xgi_delay(ivideo, 0x22); SiS_SetReg(SISSR, 0x18, v1); SiS_SetReg(SISSR, 0x19, 0x00); if(ivideo->chip == XGI_40) { SiS_SetReg(SISSR, 0x16, bios[0x540]); SiS_SetReg(SISSR, 0x16, bios[0x541]); } else { SiS_SetReg(SISSR, 0x16, 0x05); SiS_SetReg(SISSR, 0x16, 0x85); } SiS_SetReg(SISSR, 0x1b, 0x00); } regb = 0; /* ! */ v1 = 0x03; if(ivideo->haveXGIROM) { v1 = bios[0x110 + regb]; } SiS_SetReg(SISSR, 0x1b, v1); /* RAM size */ v1 = 0x00; v2 = 0x00; if(ivideo->haveXGIROM) { v1 = bios[0x62]; v2 = bios[0x63]; } regb = 0; /* ! */ regd = 1 << regb; if((v1 & 0x40) && (v2 & regd) && ivideo->haveXGIROM) { SiS_SetReg(SISSR, 0x13, bios[regb + 0xe0]); SiS_SetReg(SISSR, 0x14, bios[regb + 0xe0 + 8]); } else { int err; /* Set default mode, don't clear screen */ ivideo->SiS_Pr.SiS_UseOEM = false; SiS_SetEnableDstn(&ivideo->SiS_Pr, false); SiS_SetEnableFstn(&ivideo->SiS_Pr, false); ivideo->curFSTN = ivideo->curDSTN = 0; ivideo->SiS_Pr.VideoMemorySize = 8 << 20; SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80); SiS_SetReg(SISSR, 0x05, 0x86); /* Disable read-cache */ SiS_SetRegAND(SISSR, 0x21, 0xdf); err = sisfb_post_xgi_ramsize(ivideo); /* Enable read-cache */ SiS_SetRegOR(SISSR, 0x21, 0x20); if (err) { dev_err(&pdev->dev, "%s: RAM size detection failed: %d\n", __func__, err); return 0; } } #if 0 printk(KERN_DEBUG "-----------------\n"); for(i = 0; i < 0xff; i++) { reg = SiS_GetReg(SISCR, i); printk(KERN_DEBUG "CR%02x(%x) = 0x%02x\n", i, SISCR, reg); } for(i = 0; i < 0x40; i++) { reg = SiS_GetReg(SISSR, i); printk(KERN_DEBUG "SR%02x(%x) = 0x%02x\n", i, SISSR, reg); } printk(KERN_DEBUG "-----------------\n"); #endif /* Sense CRT1 */ if(ivideo->chip == XGI_20) { SiS_SetRegOR(SISCR, 0x32, 0x20); } else { reg = SiS_GetReg(SISPART4, 0x00); if((reg == 1) || (reg == 2)) { sisfb_sense_crt1(ivideo); } else { SiS_SetRegOR(SISCR, 0x32, 0x20); } } /* Set default mode, don't clear screen */ ivideo->SiS_Pr.SiS_UseOEM = false; SiS_SetEnableDstn(&ivideo->SiS_Pr, false); SiS_SetEnableFstn(&ivideo->SiS_Pr, false); ivideo->curFSTN = ivideo->curDSTN = 0; SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80); SiS_SetReg(SISSR, 0x05, 0x86); /* Display off */ SiS_SetRegOR(SISSR, 0x01, 0x20); /* Save mode number in CR34 */ SiS_SetReg(SISCR, 0x34, 0x2e); /* Let everyone know what the current mode is */ ivideo->modeprechange = 0x2e; if(ivideo->chip == XGI_40) { reg = SiS_GetReg(SISCR, 0xca); v1 = SiS_GetReg(SISCR, 0xcc); if((reg & 0x10) && (!(v1 & 0x04))) { printk(KERN_ERR "sisfb: Please connect power to the card.\n"); return 0; } } return 1; } #endif static int sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct sisfb_chip_info *chipinfo = &sisfb_chip_info[ent->driver_data]; struct sis_video_info *ivideo = NULL; struct fb_info *sis_fb_info = NULL; u16 reg16; u8 reg; int i, ret; if(sisfb_off) return -ENXIO; sis_fb_info = framebuffer_alloc(sizeof(*ivideo), &pdev->dev); if(!sis_fb_info) return -ENOMEM; ivideo = (struct sis_video_info *)sis_fb_info->par; ivideo->memyselfandi = sis_fb_info; ivideo->sisfb_id = SISFB_ID; if(card_list == NULL) { ivideo->cardnumber = 0; } else { struct sis_video_info *countvideo = card_list; ivideo->cardnumber = 1; while((countvideo = countvideo->next) != NULL) ivideo->cardnumber++; } strlcpy(ivideo->myid, chipinfo->chip_name, sizeof(ivideo->myid)); ivideo->warncount = 0; ivideo->chip_id = pdev->device; ivideo->chip_vendor = pdev->vendor; ivideo->revision_id = pdev->revision; ivideo->SiS_Pr.ChipRevision = ivideo->revision_id; pci_read_config_word(pdev, PCI_COMMAND, &reg16); ivideo->sisvga_enabled = reg16 & 0x01; ivideo->pcibus = pdev->bus->number; ivideo->pcislot = PCI_SLOT(pdev->devfn); ivideo->pcifunc = PCI_FUNC(pdev->devfn); ivideo->subsysvendor = pdev->subsystem_vendor; ivideo->subsysdevice = pdev->subsystem_device; #ifndef MODULE if(sisfb_mode_idx == -1) { sisfb_get_vga_mode_from_kernel(); } #endif ivideo->chip = chipinfo->chip; ivideo->chip_real_id = chipinfo->chip; ivideo->sisvga_engine = chipinfo->vgaengine; ivideo->hwcursor_size = chipinfo->hwcursor_size; ivideo->CRT2_write_enable = chipinfo->CRT2_write_enable; ivideo->mni = chipinfo->mni; ivideo->detectedpdc = 0xff; ivideo->detectedpdca = 0xff; ivideo->detectedlcda = 0xff; ivideo->sisfb_thismonitor.datavalid = false; ivideo->current_base = 0; ivideo->engineok = 0; ivideo->sisfb_was_boot_device = 0; if(pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW) { if(ivideo->sisvga_enabled) ivideo->sisfb_was_boot_device = 1; else { printk(KERN_DEBUG "sisfb: PCI device is disabled, " "but marked as boot video device ???\n"); printk(KERN_DEBUG "sisfb: I will not accept this " "as the primary VGA device\n"); } } ivideo->sisfb_parm_mem = sisfb_parm_mem; ivideo->sisfb_accel = sisfb_accel; ivideo->sisfb_ypan = sisfb_ypan; ivideo->sisfb_max = sisfb_max; ivideo->sisfb_userom = sisfb_userom; ivideo->sisfb_useoem = sisfb_useoem; ivideo->sisfb_mode_idx = sisfb_mode_idx; ivideo->sisfb_parm_rate = sisfb_parm_rate; ivideo->sisfb_crt1off = sisfb_crt1off; ivideo->sisfb_forcecrt1 = sisfb_forcecrt1; ivideo->sisfb_crt2type = sisfb_crt2type; ivideo->sisfb_crt2flags = sisfb_crt2flags; /* pdc(a), scalelcd, special timing, lvdshl handled below */ ivideo->sisfb_dstn = sisfb_dstn; ivideo->sisfb_fstn = sisfb_fstn; ivideo->sisfb_tvplug = sisfb_tvplug; ivideo->sisfb_tvstd = sisfb_tvstd; ivideo->tvxpos = sisfb_tvxposoffset; ivideo->tvypos = sisfb_tvyposoffset; ivideo->sisfb_nocrt2rate = sisfb_nocrt2rate; ivideo->refresh_rate = 0; if(ivideo->sisfb_parm_rate != -1) { ivideo->refresh_rate = ivideo->sisfb_parm_rate; } ivideo->SiS_Pr.UsePanelScaler = sisfb_scalelcd; ivideo->SiS_Pr.CenterScreen = -1; ivideo->SiS_Pr.SiS_CustomT = sisfb_specialtiming; ivideo->SiS_Pr.LVDSHL = sisfb_lvdshl; ivideo->SiS_Pr.SiS_Backup70xx = 0xff; ivideo->SiS_Pr.SiS_CHOverScan = -1; ivideo->SiS_Pr.SiS_ChSW = false; ivideo->SiS_Pr.SiS_UseLCDA = false; ivideo->SiS_Pr.HaveEMI = false; ivideo->SiS_Pr.HaveEMILCD = false; ivideo->SiS_Pr.OverruleEMI = false; ivideo->SiS_Pr.SiS_SensibleSR11 = false; ivideo->SiS_Pr.SiS_MyCR63 = 0x63; ivideo->SiS_Pr.PDC = -1; ivideo->SiS_Pr.PDCA = -1; ivideo->SiS_Pr.DDCPortMixup = false; #ifdef CONFIG_FB_SIS_315 if(ivideo->chip >= SIS_330) { ivideo->SiS_Pr.SiS_MyCR63 = 0x53; if(ivideo->chip >= SIS_661) { ivideo->SiS_Pr.SiS_SensibleSR11 = true; } } #endif memcpy(&ivideo->default_var, &my_default_var, sizeof(my_default_var)); pci_set_drvdata(pdev, ivideo); /* Patch special cases */ if((ivideo->nbridge = sisfb_get_northbridge(ivideo->chip))) { switch(ivideo->nbridge->device) { #ifdef CONFIG_FB_SIS_300 case PCI_DEVICE_ID_SI_730: ivideo->chip = SIS_730; strcpy(ivideo->myid, "SiS 730"); break; #endif #ifdef CONFIG_FB_SIS_315 case PCI_DEVICE_ID_SI_651: /* ivideo->chip is ok */ strcpy(ivideo->myid, "SiS 651"); break; case PCI_DEVICE_ID_SI_740: ivideo->chip = SIS_740; strcpy(ivideo->myid, "SiS 740"); break; case PCI_DEVICE_ID_SI_661: ivideo->chip = SIS_661; strcpy(ivideo->myid, "SiS 661"); break; case PCI_DEVICE_ID_SI_741: ivideo->chip = SIS_741; strcpy(ivideo->myid, "SiS 741"); break; case PCI_DEVICE_ID_SI_760: ivideo->chip = SIS_760; strcpy(ivideo->myid, "SiS 760"); break; case PCI_DEVICE_ID_SI_761: ivideo->chip = SIS_761; strcpy(ivideo->myid, "SiS 761"); break; #endif default: break; } } ivideo->SiS_Pr.ChipType = ivideo->chip; ivideo->SiS_Pr.ivideo = (void *)ivideo; #ifdef CONFIG_FB_SIS_315 if((ivideo->SiS_Pr.ChipType == SIS_315PRO) || (ivideo->SiS_Pr.ChipType == SIS_315)) { ivideo->SiS_Pr.ChipType = SIS_315H; } #endif if(!ivideo->sisvga_enabled) { if(pci_enable_device(pdev)) { pci_dev_put(ivideo->nbridge); framebuffer_release(sis_fb_info); return -EIO; } } ivideo->video_base = pci_resource_start(pdev, 0); ivideo->video_size = pci_resource_len(pdev, 0); ivideo->mmio_base = pci_resource_start(pdev, 1); ivideo->mmio_size = pci_resource_len(pdev, 1); ivideo->SiS_Pr.RelIO = pci_resource_start(pdev, 2) + 0x30; ivideo->SiS_Pr.IOAddress = ivideo->vga_base = ivideo->SiS_Pr.RelIO; SiSRegInit(&ivideo->SiS_Pr, ivideo->SiS_Pr.IOAddress); #ifdef CONFIG_FB_SIS_300 /* Find PCI systems for Chrontel/GPIO communication setup */ if(ivideo->chip == SIS_630) { i = 0; do { if(mychswtable[i].subsysVendor == ivideo->subsysvendor && mychswtable[i].subsysCard == ivideo->subsysdevice) { ivideo->SiS_Pr.SiS_ChSW = true; printk(KERN_DEBUG "sisfb: Identified [%s %s] " "requiring Chrontel/GPIO setup\n", mychswtable[i].vendorName, mychswtable[i].cardName); ivideo->lpcdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0008, NULL); break; } i++; } while(mychswtable[i].subsysVendor != 0); } #endif #ifdef CONFIG_FB_SIS_315 if((ivideo->chip == SIS_760) && (ivideo->nbridge)) { ivideo->lpcdev = pci_get_slot(ivideo->nbridge->bus, (2 << 3)); } #endif SiS_SetReg(SISSR, 0x05, 0x86); if( (!ivideo->sisvga_enabled) #if !defined(__i386__) && !defined(__x86_64__) || (sisfb_resetcard) #endif ) { for(i = 0x30; i <= 0x3f; i++) { SiS_SetReg(SISCR, i, 0x00); } } /* Find out about current video mode */ ivideo->modeprechange = 0x03; reg = SiS_GetReg(SISCR, 0x34); if(reg & 0x7f) { ivideo->modeprechange = reg & 0x7f; } else if(ivideo->sisvga_enabled) { #if defined(__i386__) || defined(__x86_64__) unsigned char __iomem *tt = ioremap(0x400, 0x100); if(tt) { ivideo->modeprechange = readb(tt + 0x49); iounmap(tt); } #endif } /* Search and copy ROM image */ ivideo->bios_abase = NULL; ivideo->SiS_Pr.VirtualRomBase = NULL; ivideo->SiS_Pr.UseROM = false; ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = false; if(ivideo->sisfb_userom) { ivideo->SiS_Pr.VirtualRomBase = sisfb_find_rom(pdev); ivideo->bios_abase = ivideo->SiS_Pr.VirtualRomBase; ivideo->SiS_Pr.UseROM = (bool)(ivideo->SiS_Pr.VirtualRomBase); printk(KERN_INFO "sisfb: Video ROM %sfound\n", ivideo->SiS_Pr.UseROM ? "" : "not "); if((ivideo->SiS_Pr.UseROM) && (ivideo->chip >= XGI_20)) { ivideo->SiS_Pr.UseROM = false; ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = true; if( (ivideo->revision_id == 2) && (!(ivideo->bios_abase[0x1d1] & 0x01)) ) { ivideo->SiS_Pr.DDCPortMixup = true; } } } else { printk(KERN_INFO "sisfb: Video ROM usage disabled\n"); } /* Find systems for special custom timing */ if(ivideo->SiS_Pr.SiS_CustomT == CUT_NONE) { sisfb_detect_custom_timing(ivideo); } #ifdef CONFIG_FB_SIS_315 if (ivideo->chip == XGI_20) { /* Check if our Z7 chip is actually Z9 */ SiS_SetRegOR(SISCR, 0x4a, 0x40); /* GPIOG EN */ reg = SiS_GetReg(SISCR, 0x48); if (reg & 0x02) { /* GPIOG */ ivideo->chip_real_id = XGI_21; dev_info(&pdev->dev, "Z9 detected\n"); } } #endif /* POST card in case this has not been done by the BIOS */ if( (!ivideo->sisvga_enabled) #if !defined(__i386__) && !defined(__x86_64__) || (sisfb_resetcard) #endif ) { #ifdef CONFIG_FB_SIS_300 if(ivideo->sisvga_engine == SIS_300_VGA) { if(ivideo->chip == SIS_300) { sisfb_post_sis300(pdev); ivideo->sisfb_can_post = 1; } } #endif #ifdef CONFIG_FB_SIS_315 if(ivideo->sisvga_engine == SIS_315_VGA) { int result = 1; /* if((ivideo->chip == SIS_315H) || (ivideo->chip == SIS_315) || (ivideo->chip == SIS_315PRO) || (ivideo->chip == SIS_330)) { sisfb_post_sis315330(pdev); } else */ if(ivideo->chip == XGI_20) { result = sisfb_post_xgi(pdev); ivideo->sisfb_can_post = 1; } else if((ivideo->chip == XGI_40) && ivideo->haveXGIROM) { result = sisfb_post_xgi(pdev); ivideo->sisfb_can_post = 1; } else { printk(KERN_INFO "sisfb: Card is not " "POSTed and sisfb can't do this either.\n"); } if(!result) { printk(KERN_ERR "sisfb: Failed to POST card\n"); ret = -ENODEV; goto error_3; } } #endif } ivideo->sisfb_card_posted = 1; /* Find out about RAM size */ if(sisfb_get_dram_size(ivideo)) { printk(KERN_INFO "sisfb: Fatal error: Unable to determine VRAM size.\n"); ret = -ENODEV; goto error_3; } /* Enable PCI addressing and MMIO */ if((ivideo->sisfb_mode_idx < 0) || ((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]) != 0xFF)) { /* Enable PCI_LINEAR_ADDRESSING and MMIO_ENABLE */ SiS_SetRegOR(SISSR, IND_SIS_PCI_ADDRESS_SET, (SIS_PCI_ADDR_ENABLE | SIS_MEM_MAP_IO_ENABLE)); /* Enable 2D accelerator engine */ SiS_SetRegOR(SISSR, IND_SIS_MODULE_ENABLE, SIS_ENABLE_2D); } if(sisfb_pdc != 0xff) { if(ivideo->sisvga_engine == SIS_300_VGA) sisfb_pdc &= 0x3c; else sisfb_pdc &= 0x1f; ivideo->SiS_Pr.PDC = sisfb_pdc; } #ifdef CONFIG_FB_SIS_315 if(ivideo->sisvga_engine == SIS_315_VGA) { if(sisfb_pdca != 0xff) ivideo->SiS_Pr.PDCA = sisfb_pdca & 0x1f; } #endif if(!request_mem_region(ivideo->video_base, ivideo->video_size, "sisfb FB")) { printk(KERN_ERR "sisfb: Fatal error: Unable to reserve %dMB framebuffer memory\n", (int)(ivideo->video_size >> 20)); printk(KERN_ERR "sisfb: Is there another framebuffer driver active?\n"); ret = -ENODEV; goto error_3; } if(!request_mem_region(ivideo->mmio_base, ivideo->mmio_size, "sisfb MMIO")) { printk(KERN_ERR "sisfb: Fatal error: Unable to reserve MMIO region\n"); ret = -ENODEV; goto error_2; } ivideo->video_vbase = ioremap_wc(ivideo->video_base, ivideo->video_size); ivideo->SiS_Pr.VideoMemoryAddress = ivideo->video_vbase; if(!ivideo->video_vbase) { printk(KERN_ERR "sisfb: Fatal error: Unable to map framebuffer memory\n"); ret = -ENODEV; goto error_1; } ivideo->mmio_vbase = ioremap(ivideo->mmio_base, ivideo->mmio_size); if(!ivideo->mmio_vbase) { printk(KERN_ERR "sisfb: Fatal error: Unable to map MMIO region\n"); ret = -ENODEV; error_0: iounmap(ivideo->video_vbase); error_1: release_mem_region(ivideo->video_base, ivideo->video_size); error_2: release_mem_region(ivideo->mmio_base, ivideo->mmio_size); error_3: vfree(ivideo->bios_abase); pci_dev_put(ivideo->lpcdev); pci_dev_put(ivideo->nbridge); if(!ivideo->sisvga_enabled) pci_disable_device(pdev); framebuffer_release(sis_fb_info); return ret; } printk(KERN_INFO "sisfb: Video RAM at 0x%lx, mapped to 0x%lx, size %ldk\n", ivideo->video_base, (unsigned long)ivideo->video_vbase, ivideo->video_size / 1024); if(ivideo->video_offset) { printk(KERN_INFO "sisfb: Viewport offset %ldk\n", ivideo->video_offset / 1024); } printk(KERN_INFO "sisfb: MMIO at 0x%lx, mapped to 0x%lx, size %ldk\n", ivideo->mmio_base, (unsigned long)ivideo->mmio_vbase, ivideo->mmio_size / 1024); /* Determine the size of the command queue */ if(ivideo->sisvga_engine == SIS_300_VGA) { ivideo->cmdQueueSize = TURBO_QUEUE_AREA_SIZE; } else { if(ivideo->chip == XGI_20) { ivideo->cmdQueueSize = COMMAND_QUEUE_AREA_SIZE_Z7; } else { ivideo->cmdQueueSize = COMMAND_QUEUE_AREA_SIZE; } } /* Engines are no longer initialized here; this is * now done after the first mode-switch (if the * submitted var has its acceleration flags set). */ /* Calculate the base of the (unused) hw cursor */ ivideo->hwcursor_vbase = ivideo->video_vbase + ivideo->video_size - ivideo->cmdQueueSize - ivideo->hwcursor_size; ivideo->caps |= HW_CURSOR_CAP; /* Initialize offscreen memory manager */ if((ivideo->havenoheap = sisfb_heap_init(ivideo))) { printk(KERN_WARNING "sisfb: Failed to initialize offscreen memory heap\n"); } /* Used for clearing the screen only, therefore respect our mem limit */ ivideo->SiS_Pr.VideoMemoryAddress += ivideo->video_offset; ivideo->SiS_Pr.VideoMemorySize = ivideo->sisfb_mem; ivideo->vbflags = 0; ivideo->lcddefmodeidx = DEFAULT_LCDMODE; ivideo->tvdefmodeidx = DEFAULT_TVMODE; ivideo->defmodeidx = DEFAULT_MODE; ivideo->newrom = 0; if(ivideo->chip < XGI_20) { if(ivideo->bios_abase) { ivideo->newrom = SiSDetermineROMLayout661(&ivideo->SiS_Pr); } } if((ivideo->sisfb_mode_idx < 0) || ((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]) != 0xFF)) { sisfb_sense_crt1(ivideo); sisfb_get_VB_type(ivideo); if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) { sisfb_detect_VB_connect(ivideo); } ivideo->currentvbflags = ivideo->vbflags & (VB_VIDEOBRIDGE | TV_STANDARD); /* Decide on which CRT2 device to use */ if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) { if(ivideo->sisfb_crt2type != -1) { if((ivideo->sisfb_crt2type == CRT2_LCD) && (ivideo->vbflags & CRT2_LCD)) { ivideo->currentvbflags |= CRT2_LCD; } else if(ivideo->sisfb_crt2type != CRT2_LCD) { ivideo->currentvbflags |= ivideo->sisfb_crt2type; } } else { /* Chrontel 700x TV detection often unreliable, therefore * use a different default order on such machines */ if((ivideo->sisvga_engine == SIS_300_VGA) && (ivideo->vbflags2 & VB2_CHRONTEL)) { if(ivideo->vbflags & CRT2_LCD) ivideo->currentvbflags |= CRT2_LCD; else if(ivideo->vbflags & CRT2_TV) ivideo->currentvbflags |= CRT2_TV; else if(ivideo->vbflags & CRT2_VGA) ivideo->currentvbflags |= CRT2_VGA; } else { if(ivideo->vbflags & CRT2_TV) ivideo->currentvbflags |= CRT2_TV; else if(ivideo->vbflags & CRT2_LCD) ivideo->currentvbflags |= CRT2_LCD; else if(ivideo->vbflags & CRT2_VGA) ivideo->currentvbflags |= CRT2_VGA; } } } if(ivideo->vbflags & CRT2_LCD) { sisfb_detect_lcd_type(ivideo); } sisfb_save_pdc_emi(ivideo); if(!ivideo->sisfb_crt1off) { sisfb_handle_ddc(ivideo, &ivideo->sisfb_thismonitor, 0); } else { if((ivideo->vbflags2 & VB2_SISTMDSBRIDGE) && (ivideo->vbflags & (CRT2_VGA | CRT2_LCD))) { sisfb_handle_ddc(ivideo, &ivideo->sisfb_thismonitor, 1); } } if(ivideo->sisfb_mode_idx >= 0) { int bu = ivideo->sisfb_mode_idx; ivideo->sisfb_mode_idx = sisfb_validate_mode(ivideo, ivideo->sisfb_mode_idx, ivideo->currentvbflags); if(bu != ivideo->sisfb_mode_idx) { printk(KERN_ERR "Mode %dx%dx%d failed validation\n", sisbios_mode[bu].xres, sisbios_mode[bu].yres, sisbios_mode[bu].bpp); } } if(ivideo->sisfb_mode_idx < 0) { switch(ivideo->currentvbflags & VB_DISPTYPE_DISP2) { case CRT2_LCD: ivideo->sisfb_mode_idx = ivideo->lcddefmodeidx; break; case CRT2_TV: ivideo->sisfb_mode_idx = ivideo->tvdefmodeidx; break; default: ivideo->sisfb_mode_idx = ivideo->defmodeidx; break; } } ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]; if(ivideo->refresh_rate != 0) { sisfb_search_refresh_rate(ivideo, ivideo->refresh_rate, ivideo->sisfb_mode_idx); } if(ivideo->rate_idx == 0) { ivideo->rate_idx = sisbios_mode[ivideo->sisfb_mode_idx].rate_idx; ivideo->refresh_rate = 60; } if(ivideo->sisfb_thismonitor.datavalid) { if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor, ivideo->sisfb_mode_idx, ivideo->rate_idx, ivideo->refresh_rate)) { printk(KERN_INFO "sisfb: WARNING: Refresh rate " "exceeds monitor specs!\n"); } } ivideo->video_bpp = sisbios_mode[ivideo->sisfb_mode_idx].bpp; ivideo->video_width = sisbios_mode[ivideo->sisfb_mode_idx].xres; ivideo->video_height = sisbios_mode[ivideo->sisfb_mode_idx].yres; sisfb_set_vparms(ivideo); printk(KERN_INFO "sisfb: Default mode is %dx%dx%d (%dHz)\n", ivideo->video_width, ivideo->video_height, ivideo->video_bpp, ivideo->refresh_rate); /* Set up the default var according to chosen default display mode */ ivideo->default_var.xres = ivideo->default_var.xres_virtual = ivideo->video_width; ivideo->default_var.yres = ivideo->default_var.yres_virtual = ivideo->video_height; ivideo->default_var.bits_per_pixel = ivideo->video_bpp; sisfb_bpp_to_var(ivideo, &ivideo->default_var); ivideo->default_var.pixclock = (u32) (1000000000 / sisfb_mode_rate_to_dclock(&ivideo->SiS_Pr, ivideo->mode_no, ivideo->rate_idx)); if(sisfb_mode_rate_to_ddata(&ivideo->SiS_Pr, ivideo->mode_no, ivideo->rate_idx, &ivideo->default_var)) { if((ivideo->default_var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) { ivideo->default_var.pixclock <<= 1; } } if(ivideo->sisfb_ypan) { /* Maximize regardless of sisfb_max at startup */ ivideo->default_var.yres_virtual = sisfb_calc_maxyres(ivideo, &ivideo->default_var); if(ivideo->default_var.yres_virtual < ivideo->default_var.yres) { ivideo->default_var.yres_virtual = ivideo->default_var.yres; } } sisfb_calc_pitch(ivideo, &ivideo->default_var); ivideo->accel = 0; if(ivideo->sisfb_accel) { ivideo->accel = -1; #ifdef STUPID_ACCELF_TEXT_SHIT ivideo->default_var.accel_flags |= FB_ACCELF_TEXT; #endif } sisfb_initaccel(ivideo); #if defined(FBINFO_HWACCEL_DISABLED) && defined(FBINFO_HWACCEL_XPAN) sis_fb_info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN | FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT | ((ivideo->accel) ? 0 : FBINFO_HWACCEL_DISABLED); #else sis_fb_info->flags = FBINFO_FLAG_DEFAULT; #endif sis_fb_info->var = ivideo->default_var; sis_fb_info->fix = ivideo->sisfb_fix; sis_fb_info->screen_base = ivideo->video_vbase + ivideo->video_offset; sis_fb_info->fbops = &sisfb_ops; sis_fb_info->pseudo_palette = ivideo->pseudo_palette; fb_alloc_cmap(&sis_fb_info->cmap, 256 , 0); printk(KERN_DEBUG "sisfb: Initial vbflags 0x%x\n", (int)ivideo->vbflags); ivideo->wc_cookie = arch_phys_wc_add(ivideo->video_base, ivideo->video_size); if(register_framebuffer(sis_fb_info) < 0) { printk(KERN_ERR "sisfb: Fatal error: Failed to register framebuffer\n"); ret = -EINVAL; iounmap(ivideo->mmio_vbase); goto error_0; } ivideo->registered = 1; /* Enlist us */ ivideo->next = card_list; card_list = ivideo; printk(KERN_INFO "sisfb: 2D acceleration is %s, y-panning %s\n", ivideo->sisfb_accel ? "enabled" : "disabled", ivideo->sisfb_ypan ? (ivideo->sisfb_max ? "enabled (auto-max)" : "enabled (no auto-max)") : "disabled"); fb_info(sis_fb_info, "%s frame buffer device version %d.%d.%d\n", ivideo->myid, VER_MAJOR, VER_MINOR, VER_LEVEL); printk(KERN_INFO "sisfb: Copyright (C) 2001-2005 Thomas Winischhofer\n"); } /* if mode = "none" */ return 0; } /*****************************************************/ /* PCI DEVICE HANDLING */ /*****************************************************/ static void sisfb_remove(struct pci_dev *pdev) { struct sis_video_info *ivideo = pci_get_drvdata(pdev); struct fb_info *sis_fb_info = ivideo->memyselfandi; int registered = ivideo->registered; int modechanged = ivideo->modechanged; /* Unmap */ iounmap(ivideo->mmio_vbase); iounmap(ivideo->video_vbase); /* Release mem regions */ release_mem_region(ivideo->video_base, ivideo->video_size); release_mem_region(ivideo->mmio_base, ivideo->mmio_size); vfree(ivideo->bios_abase); pci_dev_put(ivideo->lpcdev); pci_dev_put(ivideo->nbridge); arch_phys_wc_del(ivideo->wc_cookie); /* If device was disabled when starting, disable * it when quitting. */ if(!ivideo->sisvga_enabled) pci_disable_device(pdev); /* Unregister the framebuffer */ if(ivideo->registered) { unregister_framebuffer(sis_fb_info); framebuffer_release(sis_fb_info); } /* OK, our ivideo is gone for good from here. */ /* TODO: Restore the initial mode * This sounds easy but is as good as impossible * on many machines with SiS chip and video bridge * since text modes are always set up differently * from machine to machine. Depends on the type * of integration between chipset and bridge. */ if(registered && modechanged) printk(KERN_INFO "sisfb: Restoring of text mode not supported yet\n"); }; static struct pci_driver sisfb_driver = { .name = "sisfb", .id_table = sisfb_pci_table, .probe = sisfb_probe, .remove = sisfb_remove, }; static int __init sisfb_init(void) { #ifndef MODULE char *options = NULL; if(fb_get_options("sisfb", &options)) return -ENODEV; sisfb_setup(options); #endif return pci_register_driver(&sisfb_driver); } #ifndef MODULE module_init(sisfb_init); #endif /*****************************************************/ /* MODULE */ /*****************************************************/ #ifdef MODULE static char *mode = NULL; static int vesa = -1; static unsigned int rate = 0; static unsigned int crt1off = 1; static unsigned int mem = 0; static char *forcecrt2type = NULL; static int forcecrt1 = -1; static int pdc = -1; static int pdc1 = -1; static int noaccel = -1; static int noypan = -1; static int nomax = -1; static int userom = -1; static int useoem = -1; static char *tvstandard = NULL; static int nocrt2rate = 0; static int scalelcd = -1; static char *specialtiming = NULL; static int lvdshl = -1; static int tvxposoffset = 0, tvyposoffset = 0; #if !defined(__i386__) && !defined(__x86_64__) static int resetcard = 0; static int videoram = 0; #endif static int __init sisfb_init_module(void) { sisfb_setdefaultparms(); if(rate) sisfb_parm_rate = rate; if((scalelcd == 0) || (scalelcd == 1)) sisfb_scalelcd = scalelcd ^ 1; /* Need to check crt2 type first for fstn/dstn */ if(forcecrt2type) sisfb_search_crt2type(forcecrt2type); if(tvstandard) sisfb_search_tvstd(tvstandard); if(mode) sisfb_search_mode(mode, false); else if(vesa != -1) sisfb_search_vesamode(vesa, false); sisfb_crt1off = (crt1off == 0) ? 1 : 0; sisfb_forcecrt1 = forcecrt1; if(forcecrt1 == 1) sisfb_crt1off = 0; else if(forcecrt1 == 0) sisfb_crt1off = 1; if(noaccel == 1) sisfb_accel = 0; else if(noaccel == 0) sisfb_accel = 1; if(noypan == 1) sisfb_ypan = 0; else if(noypan == 0) sisfb_ypan = 1; if(nomax == 1) sisfb_max = 0; else if(nomax == 0) sisfb_max = 1; if(mem) sisfb_parm_mem = mem; if(userom != -1) sisfb_userom = userom; if(useoem != -1) sisfb_useoem = useoem; if(pdc != -1) sisfb_pdc = (pdc & 0x7f); if(pdc1 != -1) sisfb_pdca = (pdc1 & 0x1f); sisfb_nocrt2rate = nocrt2rate; if(specialtiming) sisfb_search_specialtiming(specialtiming); if((lvdshl >= 0) && (lvdshl <= 3)) sisfb_lvdshl = lvdshl; sisfb_tvxposoffset = tvxposoffset; sisfb_tvyposoffset = tvyposoffset; #if !defined(__i386__) && !defined(__x86_64__) sisfb_resetcard = (resetcard) ? 1 : 0; if(videoram) sisfb_videoram = videoram; #endif return sisfb_init(); } static void __exit sisfb_remove_module(void) { pci_unregister_driver(&sisfb_driver); printk(KERN_DEBUG "sisfb: Module unloaded\n"); } module_init(sisfb_init_module); module_exit(sisfb_remove_module); MODULE_DESCRIPTION("SiS 300/540/630/730/315/55x/65x/661/74x/330/76x/34x, XGI V3XT/V5/V8/Z7 framebuffer device driver"); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>, Others"); module_param(mem, int, 0); module_param(noaccel, int, 0); module_param(noypan, int, 0); module_param(nomax, int, 0); module_param(userom, int, 0); module_param(useoem, int, 0); module_param(mode, charp, 0); module_param(vesa, int, 0); module_param(rate, int, 0); module_param(forcecrt1, int, 0); module_param(forcecrt2type, charp, 0); module_param(scalelcd, int, 0); module_param(pdc, int, 0); module_param(pdc1, int, 0); module_param(specialtiming, charp, 0); module_param(lvdshl, int, 0); module_param(tvstandard, charp, 0); module_param(tvxposoffset, int, 0); module_param(tvyposoffset, int, 0); module_param(nocrt2rate, int, 0); #if !defined(__i386__) && !defined(__x86_64__) module_param(resetcard, int, 0); module_param(videoram, int, 0); #endif MODULE_PARM_DESC(mem, "\nDetermines the beginning of the video memory heap in KB. This heap is used\n" "for video RAM management for eg. DRM/DRI. On 300 series, the default depends\n" "on the amount of video RAM available. If 8MB of video RAM or less is available,\n" "the heap starts at 4096KB, if between 8 and 16MB are available at 8192KB,\n" "otherwise at 12288KB. On 315/330/340 series, the heap size is 32KB by default.\n" "The value is to be specified without 'KB'.\n"); MODULE_PARM_DESC(noaccel, "\nIf set to anything other than 0, 2D acceleration will be disabled.\n" "(default: 0)\n"); MODULE_PARM_DESC(noypan, "\nIf set to anything other than 0, y-panning will be disabled and scrolling\n" "will be performed by redrawing the screen. (default: 0)\n"); MODULE_PARM_DESC(nomax, "\nIf y-panning is enabled, sisfb will by default use the entire available video\n" "memory for the virtual screen in order to optimize scrolling performance. If\n" "this is set to anything other than 0, sisfb will not do this and thereby \n" "enable the user to positively specify a virtual Y size of the screen using\n" "fbset. (default: 0)\n"); MODULE_PARM_DESC(mode, "\nSelects the desired default display mode in the format XxYxDepth,\n" "eg. 1024x768x16. Other formats supported include XxY-Depth and\n" "XxY-Depth@Rate. If the parameter is only one (decimal or hexadecimal)\n" "number, it will be interpreted as a VESA mode number. (default: 800x600x8)\n"); MODULE_PARM_DESC(vesa, "\nSelects the desired default display mode by VESA defined mode number, eg.\n" "0x117 (default: 0x0103)\n"); MODULE_PARM_DESC(rate, "\nSelects the desired vertical refresh rate for CRT1 (external VGA) in Hz.\n" "If the mode is specified in the format XxY-Depth@Rate, this parameter\n" "will be ignored (default: 60)\n"); MODULE_PARM_DESC(forcecrt1, "\nNormally, the driver autodetects whether or not CRT1 (external VGA) is \n" "connected. With this option, the detection can be overridden (1=CRT1 ON,\n" "0=CRT1 OFF) (default: [autodetected])\n"); MODULE_PARM_DESC(forcecrt2type, "\nIf this option is omitted, the driver autodetects CRT2 output devices, such as\n" "LCD, TV or secondary VGA. With this option, this autodetection can be\n" "overridden. Possible parameters are LCD, TV, VGA or NONE. NONE disables CRT2.\n" "On systems with a SiS video bridge, parameters SVIDEO, COMPOSITE or SCART can\n" "be used instead of TV to override the TV detection. Furthermore, on systems\n" "with a SiS video bridge, SVIDEO+COMPOSITE, HIVISION, YPBPR480I, YPBPR480P,\n" "YPBPR720P and YPBPR1080I are understood. However, whether or not these work\n" "depends on the very hardware in use. (default: [autodetected])\n"); MODULE_PARM_DESC(scalelcd, "\nSetting this to 1 will force the driver to scale the LCD image to the panel's\n" "native resolution. Setting it to 0 will disable scaling; LVDS panels will\n" "show black bars around the image, TMDS panels will probably do the scaling\n" "themselves. Default: 1 on LVDS panels, 0 on TMDS panels\n"); MODULE_PARM_DESC(pdc, "\nThis is for manually selecting the LCD panel delay compensation. The driver\n" "should detect this correctly in most cases; however, sometimes this is not\n" "possible. If you see 'small waves' on the LCD, try setting this to 4, 32 or 24\n" "on a 300 series chipset; 6 on other chipsets. If the problem persists, try\n" "other values (on 300 series: between 4 and 60 in steps of 4; otherwise: any\n" "value from 0 to 31). (default: autodetected, if LCD is active during start)\n"); #ifdef CONFIG_FB_SIS_315 MODULE_PARM_DESC(pdc1, "\nThis is same as pdc, but for LCD-via CRT1. Hence, this is for the 315/330/340\n" "series only. (default: autodetected if LCD is in LCD-via-CRT1 mode during\n" "startup) - Note: currently, this has no effect because LCD-via-CRT1 is not\n" "implemented yet.\n"); #endif MODULE_PARM_DESC(specialtiming, "\nPlease refer to documentation for more information on this option.\n"); MODULE_PARM_DESC(lvdshl, "\nPlease refer to documentation for more information on this option.\n"); MODULE_PARM_DESC(tvstandard, "\nThis allows overriding the BIOS default for the TV standard. Valid choices are\n" "pal, ntsc, palm and paln. (default: [auto; pal or ntsc only])\n"); MODULE_PARM_DESC(tvxposoffset, "\nRelocate TV output horizontally. Possible parameters: -32 through 32.\n" "Default: 0\n"); MODULE_PARM_DESC(tvyposoffset, "\nRelocate TV output vertically. Possible parameters: -32 through 32.\n" "Default: 0\n"); MODULE_PARM_DESC(nocrt2rate, "\nSetting this to 1 will force the driver to use the default refresh rate for\n" "CRT2 if CRT2 type is VGA. (default: 0, use same rate as CRT1)\n"); #if !defined(__i386__) && !defined(__x86_64__) #ifdef CONFIG_FB_SIS_300 MODULE_PARM_DESC(resetcard, "\nSet this to 1 in order to reset (POST) the card on non-x86 machines where\n" "the BIOS did not POST the card (only supported for SiS 300/305 and XGI cards\n" "currently). Default: 0\n"); MODULE_PARM_DESC(videoram, "\nSet this to the amount of video RAM (in kilobyte) the card has. Required on\n" "some non-x86 architectures where the memory auto detection fails. Only\n" "relevant if resetcard is set, too. SiS300/305 only. Default: [auto-detect]\n"); #endif #endif #endif /* /MODULE */ /* _GPL only for new symbols. */ EXPORT_SYMBOL(sis_malloc); EXPORT_SYMBOL(sis_free); EXPORT_SYMBOL_GPL(sis_malloc_new); EXPORT_SYMBOL_GPL(sis_free_new);
gpl-2.0
decly/linux-2.6.37
arch/powerpc/platforms/40x/ppc40x_simple.c
1472
2317
/* * Generic PowerPC 40x platform support * * Copyright 2008 IBM Corporation * * 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. * * This implements simple platform support for PowerPC 44x chips. This is * mostly used for eval boards or other simple and "generic" 44x boards. If * your board has custom functions or hardware, then you will likely want to * implement your own board.c file to accommodate it. */ #include <asm/machdep.h> #include <asm/pci-bridge.h> #include <asm/ppc4xx.h> #include <asm/prom.h> #include <asm/time.h> #include <asm/udbg.h> #include <asm/uic.h> #include <linux/init.h> #include <linux/of_platform.h> static __initdata struct of_device_id ppc40x_of_bus[] = { { .compatible = "ibm,plb3", }, { .compatible = "ibm,plb4", }, { .compatible = "ibm,opb", }, { .compatible = "ibm,ebc", }, { .compatible = "simple-bus", }, {}, }; static int __init ppc40x_device_probe(void) { of_platform_bus_probe(NULL, ppc40x_of_bus, NULL); return 0; } machine_device_initcall(ppc40x_simple, ppc40x_device_probe); /* This is the list of boards that can be supported by this simple * platform code. This does _not_ mean the boards are compatible, * as they most certainly are not from a device tree perspective. * However, their differences are handled by the device tree and the * drivers and therefore they don't need custom board support files. * * Again, if your board needs to do things differently then create a * board.c file for it rather than adding it to this list. */ static char *board[] __initdata = { "amcc,acadia", "amcc,haleakala", "amcc,kilauea", "amcc,makalu", "est,hotfoot" }; static int __init ppc40x_probe(void) { unsigned long root = of_get_flat_dt_root(); int i = 0; for (i = 0; i < ARRAY_SIZE(board); i++) { if (of_flat_dt_is_compatible(root, board[i])) { ppc_pci_set_flags(PPC_PCI_REASSIGN_ALL_RSRC); return 1; } } return 0; } define_machine(ppc40x_simple) { .name = "PowerPC 40x Platform", .probe = ppc40x_probe, .progress = udbg_progress, .init_IRQ = uic_init_tree, .get_irq = uic_get_irq, .restart = ppc4xx_reset_system, .calibrate_decr = generic_calibrate_decr, };
gpl-2.0
mtshima/Victara-CM-kernel
drivers/mfd/mfd-core.c
1472
5815
/* * drivers/mfd/mfd-core.c * * core MFD support * Copyright (c) 2006 Ian Molton * Copyright (c) 2007,2008 Dmitry Baryshkov * * 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/platform_device.h> #include <linux/acpi.h> #include <linux/mfd/core.h> #include <linux/pm_runtime.h> #include <linux/slab.h> #include <linux/module.h> static struct device_type mfd_dev_type = { .name = "mfd_device", }; int mfd_cell_enable(struct platform_device *pdev) { const struct mfd_cell *cell = mfd_get_cell(pdev); int err = 0; /* only call enable hook if the cell wasn't previously enabled */ if (atomic_inc_return(cell->usage_count) == 1) err = cell->enable(pdev); /* if the enable hook failed, decrement counter to allow retries */ if (err) atomic_dec(cell->usage_count); return err; } EXPORT_SYMBOL(mfd_cell_enable); int mfd_cell_disable(struct platform_device *pdev) { const struct mfd_cell *cell = mfd_get_cell(pdev); int err = 0; /* only disable if no other clients are using it */ if (atomic_dec_return(cell->usage_count) == 0) err = cell->disable(pdev); /* if the disable hook failed, increment to allow retries */ if (err) atomic_inc(cell->usage_count); /* sanity check; did someone call disable too many times? */ WARN_ON(atomic_read(cell->usage_count) < 0); return err; } EXPORT_SYMBOL(mfd_cell_disable); static int mfd_platform_add_cell(struct platform_device *pdev, const struct mfd_cell *cell) { if (!cell) return 0; pdev->mfd_cell = kmemdup(cell, sizeof(*cell), GFP_KERNEL); if (!pdev->mfd_cell) return -ENOMEM; return 0; } static int mfd_add_device(struct device *parent, int id, const struct mfd_cell *cell, struct resource *mem_base, int irq_base) { struct resource *res; struct platform_device *pdev; int ret = -ENOMEM; int r; pdev = platform_device_alloc(cell->name, id + cell->id); if (!pdev) goto fail_alloc; res = kzalloc(sizeof(*res) * cell->num_resources, GFP_KERNEL); if (!res) goto fail_device; pdev->dev.parent = parent; pdev->dev.type = &mfd_dev_type; if (cell->pdata_size) { ret = platform_device_add_data(pdev, cell->platform_data, cell->pdata_size); if (ret) goto fail_res; } ret = mfd_platform_add_cell(pdev, cell); if (ret) goto fail_res; for (r = 0; r < cell->num_resources; r++) { res[r].name = cell->resources[r].name; res[r].flags = cell->resources[r].flags; /* Find out base to use */ if ((cell->resources[r].flags & IORESOURCE_MEM) && mem_base) { res[r].parent = mem_base; res[r].start = mem_base->start + cell->resources[r].start; res[r].end = mem_base->start + cell->resources[r].end; } else if (cell->resources[r].flags & IORESOURCE_IRQ) { res[r].start = irq_base + cell->resources[r].start; res[r].end = irq_base + cell->resources[r].end; } else { res[r].parent = cell->resources[r].parent; res[r].start = cell->resources[r].start; res[r].end = cell->resources[r].end; } if (!cell->ignore_resource_conflicts) { ret = acpi_check_resource_conflict(&res[r]); if (ret) goto fail_res; } } ret = platform_device_add_resources(pdev, res, cell->num_resources); if (ret) goto fail_res; ret = platform_device_add(pdev); if (ret) goto fail_res; if (cell->pm_runtime_no_callbacks) pm_runtime_no_callbacks(&pdev->dev); kfree(res); return 0; fail_res: kfree(res); fail_device: platform_device_put(pdev); fail_alloc: return ret; } int mfd_add_devices(struct device *parent, int id, struct mfd_cell *cells, int n_devs, struct resource *mem_base, int irq_base) { int i; int ret = 0; atomic_t *cnts; /* initialize reference counting for all cells */ cnts = kcalloc(n_devs, sizeof(*cnts), GFP_KERNEL); if (!cnts) return -ENOMEM; for (i = 0; i < n_devs; i++) { atomic_set(&cnts[i], 0); cells[i].usage_count = &cnts[i]; ret = mfd_add_device(parent, id, cells + i, mem_base, irq_base); if (ret) break; } if (ret) mfd_remove_devices(parent); return ret; } EXPORT_SYMBOL(mfd_add_devices); static int mfd_remove_devices_fn(struct device *dev, void *c) { struct platform_device *pdev; const struct mfd_cell *cell; atomic_t **usage_count = c; if (dev->type != &mfd_dev_type) return 0; pdev = to_platform_device(dev); cell = mfd_get_cell(pdev); /* find the base address of usage_count pointers (for freeing) */ if (!*usage_count || (cell->usage_count < *usage_count)) *usage_count = cell->usage_count; platform_device_unregister(pdev); return 0; } void mfd_remove_devices(struct device *parent) { atomic_t *cnts = NULL; device_for_each_child(parent, &cnts, mfd_remove_devices_fn); kfree(cnts); } EXPORT_SYMBOL(mfd_remove_devices); int mfd_clone_cell(const char *cell, const char **clones, size_t n_clones) { struct mfd_cell cell_entry; struct device *dev; struct platform_device *pdev; int i; /* fetch the parent cell's device (should already be registered!) */ dev = bus_find_device_by_name(&platform_bus_type, NULL, cell); if (!dev) { printk(KERN_ERR "failed to find device for cell %s\n", cell); return -ENODEV; } pdev = to_platform_device(dev); memcpy(&cell_entry, mfd_get_cell(pdev), sizeof(cell_entry)); WARN_ON(!cell_entry.enable); for (i = 0; i < n_clones; i++) { cell_entry.name = clones[i]; /* don't give up if a single call fails; just report error */ if (mfd_add_device(pdev->dev.parent, -1, &cell_entry, NULL, 0)) dev_err(dev, "failed to create platform device '%s'\n", clones[i]); } return 0; } EXPORT_SYMBOL(mfd_clone_cell); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov");
gpl-2.0
hgl888/linux
drivers/input/misc/mc13783-pwrbutton.c
1728
7388
/** * Copyright (C) 2011 Philippe Rétornaz * * Based on twl4030-pwrbutton driver by: * Peter De Schrijver <peter.de-schrijver@nokia.com> * Felipe Balbi <felipe.balbi@nokia.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. * * 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, Suite 500, Boston, MA 02110-1335 USA */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/input.h> #include <linux/interrupt.h> #include <linux/platform_device.h> #include <linux/mfd/mc13783.h> #include <linux/sched.h> #include <linux/slab.h> struct mc13783_pwrb { struct input_dev *pwr; struct mc13xxx *mc13783; #define MC13783_PWRB_B1_POL_INVERT (1 << 0) #define MC13783_PWRB_B2_POL_INVERT (1 << 1) #define MC13783_PWRB_B3_POL_INVERT (1 << 2) int flags; unsigned short keymap[3]; }; #define MC13783_REG_INTERRUPT_SENSE_1 5 #define MC13783_IRQSENSE1_ONOFD1S (1 << 3) #define MC13783_IRQSENSE1_ONOFD2S (1 << 4) #define MC13783_IRQSENSE1_ONOFD3S (1 << 5) #define MC13783_REG_POWER_CONTROL_2 15 #define MC13783_POWER_CONTROL_2_ON1BDBNC 4 #define MC13783_POWER_CONTROL_2_ON2BDBNC 6 #define MC13783_POWER_CONTROL_2_ON3BDBNC 8 #define MC13783_POWER_CONTROL_2_ON1BRSTEN (1 << 1) #define MC13783_POWER_CONTROL_2_ON2BRSTEN (1 << 2) #define MC13783_POWER_CONTROL_2_ON3BRSTEN (1 << 3) static irqreturn_t button_irq(int irq, void *_priv) { struct mc13783_pwrb *priv = _priv; int val; mc13xxx_irq_ack(priv->mc13783, irq); mc13xxx_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val); switch (irq) { case MC13783_IRQ_ONOFD1: val = val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0; if (priv->flags & MC13783_PWRB_B1_POL_INVERT) val ^= 1; input_report_key(priv->pwr, priv->keymap[0], val); break; case MC13783_IRQ_ONOFD2: val = val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0; if (priv->flags & MC13783_PWRB_B2_POL_INVERT) val ^= 1; input_report_key(priv->pwr, priv->keymap[1], val); break; case MC13783_IRQ_ONOFD3: val = val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0; if (priv->flags & MC13783_PWRB_B3_POL_INVERT) val ^= 1; input_report_key(priv->pwr, priv->keymap[2], val); break; } input_sync(priv->pwr); return IRQ_HANDLED; } static int mc13783_pwrbutton_probe(struct platform_device *pdev) { const struct mc13xxx_buttons_platform_data *pdata; struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent); struct input_dev *pwr; struct mc13783_pwrb *priv; int err = 0; int reg = 0; pdata = dev_get_platdata(&pdev->dev); if (!pdata) { dev_err(&pdev->dev, "missing platform data\n"); return -ENODEV; } pwr = input_allocate_device(); if (!pwr) { dev_dbg(&pdev->dev, "Can't allocate power button\n"); return -ENOMEM; } priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) { err = -ENOMEM; dev_dbg(&pdev->dev, "Can't allocate power button\n"); goto free_input_dev; } reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC; reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC; reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC; priv->pwr = pwr; priv->mc13783 = mc13783; mc13xxx_lock(mc13783); if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) { priv->keymap[0] = pdata->b1on_key; if (pdata->b1on_key != KEY_RESERVED) __set_bit(pdata->b1on_key, pwr->keybit); if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT) priv->flags |= MC13783_PWRB_B1_POL_INVERT; if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN) reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN; err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD1, button_irq, "b1on", priv); if (err) { dev_dbg(&pdev->dev, "Can't request irq\n"); goto free_priv; } } if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) { priv->keymap[1] = pdata->b2on_key; if (pdata->b2on_key != KEY_RESERVED) __set_bit(pdata->b2on_key, pwr->keybit); if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT) priv->flags |= MC13783_PWRB_B2_POL_INVERT; if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN) reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN; err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD2, button_irq, "b2on", priv); if (err) { dev_dbg(&pdev->dev, "Can't request irq\n"); goto free_irq_b1; } } if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) { priv->keymap[2] = pdata->b3on_key; if (pdata->b3on_key != KEY_RESERVED) __set_bit(pdata->b3on_key, pwr->keybit); if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT) priv->flags |= MC13783_PWRB_B3_POL_INVERT; if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN) reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN; err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD3, button_irq, "b3on", priv); if (err) { dev_dbg(&pdev->dev, "Can't request irq: %d\n", err); goto free_irq_b2; } } mc13xxx_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg); mc13xxx_unlock(mc13783); pwr->name = "mc13783_pwrbutton"; pwr->phys = "mc13783_pwrbutton/input0"; pwr->dev.parent = &pdev->dev; pwr->keycode = priv->keymap; pwr->keycodemax = ARRAY_SIZE(priv->keymap); pwr->keycodesize = sizeof(priv->keymap[0]); __set_bit(EV_KEY, pwr->evbit); err = input_register_device(pwr); if (err) { dev_dbg(&pdev->dev, "Can't register power button: %d\n", err); goto free_irq; } platform_set_drvdata(pdev, priv); return 0; free_irq: mc13xxx_lock(mc13783); if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv); free_irq_b2: if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv); free_irq_b1: if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv); free_priv: mc13xxx_unlock(mc13783); kfree(priv); free_input_dev: input_free_device(pwr); return err; } static int mc13783_pwrbutton_remove(struct platform_device *pdev) { struct mc13783_pwrb *priv = platform_get_drvdata(pdev); const struct mc13xxx_buttons_platform_data *pdata; pdata = dev_get_platdata(&pdev->dev); mc13xxx_lock(priv->mc13783); if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv); if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv); if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv); mc13xxx_unlock(priv->mc13783); input_unregister_device(priv->pwr); kfree(priv); return 0; } static struct platform_driver mc13783_pwrbutton_driver = { .probe = mc13783_pwrbutton_probe, .remove = mc13783_pwrbutton_remove, .driver = { .name = "mc13783-pwrbutton", }, }; module_platform_driver(mc13783_pwrbutton_driver); MODULE_ALIAS("platform:mc13783-pwrbutton"); MODULE_DESCRIPTION("MC13783 Power Button"); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Philippe Retornaz");
gpl-2.0
scanno/android_kernel_motorola_msm8992
drivers/platform/x86/ideapad-laptop.c
2240
22515
/* * ideapad-laptop.c - Lenovo IdeaPad ACPI Extras * * Copyright © 2010 Intel Corporation * Copyright © 2010 David Woodhouse <dwmw2@infradead.org> * * 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. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/types.h> #include <acpi/acpi_bus.h> #include <acpi/acpi_drivers.h> #include <linux/rfkill.h> #include <linux/platform_device.h> #include <linux/input.h> #include <linux/input/sparse-keymap.h> #include <linux/backlight.h> #include <linux/fb.h> #include <linux/debugfs.h> #include <linux/seq_file.h> #include <linux/i8042.h> #define IDEAPAD_RFKILL_DEV_NUM (3) #define CFG_BT_BIT (16) #define CFG_3G_BIT (17) #define CFG_WIFI_BIT (18) #define CFG_CAMERA_BIT (19) enum { VPCCMD_R_VPC1 = 0x10, VPCCMD_R_BL_MAX, VPCCMD_R_BL, VPCCMD_W_BL, VPCCMD_R_WIFI, VPCCMD_W_WIFI, VPCCMD_R_BT, VPCCMD_W_BT, VPCCMD_R_BL_POWER, VPCCMD_R_NOVO, VPCCMD_R_VPC2, VPCCMD_R_TOUCHPAD, VPCCMD_W_TOUCHPAD, VPCCMD_R_CAMERA, VPCCMD_W_CAMERA, VPCCMD_R_3G, VPCCMD_W_3G, VPCCMD_R_ODD, /* 0x21 */ VPCCMD_W_FAN, VPCCMD_R_RF, VPCCMD_W_RF, VPCCMD_R_FAN = 0x2B, VPCCMD_R_SPECIAL_BUTTONS = 0x31, VPCCMD_W_BL_POWER = 0x33, }; struct ideapad_private { struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM]; struct platform_device *platform_device; struct input_dev *inputdev; struct backlight_device *blightdev; struct dentry *debug; unsigned long cfg; }; static acpi_handle ideapad_handle; static struct ideapad_private *ideapad_priv; static bool no_bt_rfkill; module_param(no_bt_rfkill, bool, 0444); MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth."); /* * ACPI Helpers */ #define IDEAPAD_EC_TIMEOUT (100) /* in ms */ static int read_method_int(acpi_handle handle, const char *method, int *val) { acpi_status status; unsigned long long result; status = acpi_evaluate_integer(handle, (char *)method, NULL, &result); if (ACPI_FAILURE(status)) { *val = -1; return -1; } else { *val = result; return 0; } } static int method_vpcr(acpi_handle handle, int cmd, int *ret) { acpi_status status; unsigned long long result; struct acpi_object_list params; union acpi_object in_obj; params.count = 1; params.pointer = &in_obj; in_obj.type = ACPI_TYPE_INTEGER; in_obj.integer.value = cmd; status = acpi_evaluate_integer(handle, "VPCR", &params, &result); if (ACPI_FAILURE(status)) { *ret = -1; return -1; } else { *ret = result; return 0; } } static int method_vpcw(acpi_handle handle, int cmd, int data) { struct acpi_object_list params; union acpi_object in_obj[2]; acpi_status status; params.count = 2; params.pointer = in_obj; in_obj[0].type = ACPI_TYPE_INTEGER; in_obj[0].integer.value = cmd; in_obj[1].type = ACPI_TYPE_INTEGER; in_obj[1].integer.value = data; status = acpi_evaluate_object(handle, "VPCW", &params, NULL); if (status != AE_OK) return -1; return 0; } static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data) { int val; unsigned long int end_jiffies; if (method_vpcw(handle, 1, cmd)) return -1; for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1; time_before(jiffies, end_jiffies);) { schedule(); if (method_vpcr(handle, 1, &val)) return -1; if (val == 0) { if (method_vpcr(handle, 0, &val)) return -1; *data = val; return 0; } } pr_err("timeout in read_ec_cmd\n"); return -1; } static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data) { int val; unsigned long int end_jiffies; if (method_vpcw(handle, 0, data)) return -1; if (method_vpcw(handle, 1, cmd)) return -1; for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1; time_before(jiffies, end_jiffies);) { schedule(); if (method_vpcr(handle, 1, &val)) return -1; if (val == 0) return 0; } pr_err("timeout in write_ec_cmd\n"); return -1; } /* * debugfs */ static int debugfs_status_show(struct seq_file *s, void *data) { unsigned long value; if (!read_ec_data(ideapad_handle, VPCCMD_R_BL_MAX, &value)) seq_printf(s, "Backlight max:\t%lu\n", value); if (!read_ec_data(ideapad_handle, VPCCMD_R_BL, &value)) seq_printf(s, "Backlight now:\t%lu\n", value); if (!read_ec_data(ideapad_handle, VPCCMD_R_BL_POWER, &value)) seq_printf(s, "BL power value:\t%s\n", value ? "On" : "Off"); seq_printf(s, "=====================\n"); if (!read_ec_data(ideapad_handle, VPCCMD_R_RF, &value)) seq_printf(s, "Radio status:\t%s(%lu)\n", value ? "On" : "Off", value); if (!read_ec_data(ideapad_handle, VPCCMD_R_WIFI, &value)) seq_printf(s, "Wifi status:\t%s(%lu)\n", value ? "On" : "Off", value); if (!read_ec_data(ideapad_handle, VPCCMD_R_BT, &value)) seq_printf(s, "BT status:\t%s(%lu)\n", value ? "On" : "Off", value); if (!read_ec_data(ideapad_handle, VPCCMD_R_3G, &value)) seq_printf(s, "3G status:\t%s(%lu)\n", value ? "On" : "Off", value); seq_printf(s, "=====================\n"); if (!read_ec_data(ideapad_handle, VPCCMD_R_TOUCHPAD, &value)) seq_printf(s, "Touchpad status:%s(%lu)\n", value ? "On" : "Off", value); if (!read_ec_data(ideapad_handle, VPCCMD_R_CAMERA, &value)) seq_printf(s, "Camera status:\t%s(%lu)\n", value ? "On" : "Off", value); return 0; } static int debugfs_status_open(struct inode *inode, struct file *file) { return single_open(file, debugfs_status_show, NULL); } static const struct file_operations debugfs_status_fops = { .owner = THIS_MODULE, .open = debugfs_status_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; static int debugfs_cfg_show(struct seq_file *s, void *data) { if (!ideapad_priv) { seq_printf(s, "cfg: N/A\n"); } else { seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ", ideapad_priv->cfg); if (test_bit(CFG_BT_BIT, &ideapad_priv->cfg)) seq_printf(s, "Bluetooth "); if (test_bit(CFG_3G_BIT, &ideapad_priv->cfg)) seq_printf(s, "3G "); if (test_bit(CFG_WIFI_BIT, &ideapad_priv->cfg)) seq_printf(s, "Wireless "); if (test_bit(CFG_CAMERA_BIT, &ideapad_priv->cfg)) seq_printf(s, "Camera "); seq_printf(s, "\nGraphic: "); switch ((ideapad_priv->cfg)&0x700) { case 0x100: seq_printf(s, "Intel"); break; case 0x200: seq_printf(s, "ATI"); break; case 0x300: seq_printf(s, "Nvidia"); break; case 0x400: seq_printf(s, "Intel and ATI"); break; case 0x500: seq_printf(s, "Intel and Nvidia"); break; } seq_printf(s, "\n"); } return 0; } static int debugfs_cfg_open(struct inode *inode, struct file *file) { return single_open(file, debugfs_cfg_show, NULL); } static const struct file_operations debugfs_cfg_fops = { .owner = THIS_MODULE, .open = debugfs_cfg_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; static int ideapad_debugfs_init(struct ideapad_private *priv) { struct dentry *node; priv->debug = debugfs_create_dir("ideapad", NULL); if (priv->debug == NULL) { pr_err("failed to create debugfs directory"); goto errout; } node = debugfs_create_file("cfg", S_IRUGO, priv->debug, NULL, &debugfs_cfg_fops); if (!node) { pr_err("failed to create cfg in debugfs"); goto errout; } node = debugfs_create_file("status", S_IRUGO, priv->debug, NULL, &debugfs_status_fops); if (!node) { pr_err("failed to create status in debugfs"); goto errout; } return 0; errout: return -ENOMEM; } static void ideapad_debugfs_exit(struct ideapad_private *priv) { debugfs_remove_recursive(priv->debug); priv->debug = NULL; } /* * sysfs */ static ssize_t show_ideapad_cam(struct device *dev, struct device_attribute *attr, char *buf) { unsigned long result; if (read_ec_data(ideapad_handle, VPCCMD_R_CAMERA, &result)) return sprintf(buf, "-1\n"); return sprintf(buf, "%lu\n", result); } static ssize_t store_ideapad_cam(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int ret, state; if (!count) return 0; if (sscanf(buf, "%i", &state) != 1) return -EINVAL; ret = write_ec_cmd(ideapad_handle, VPCCMD_W_CAMERA, state); if (ret < 0) return -EIO; return count; } static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam); static ssize_t show_ideapad_fan(struct device *dev, struct device_attribute *attr, char *buf) { unsigned long result; if (read_ec_data(ideapad_handle, VPCCMD_R_FAN, &result)) return sprintf(buf, "-1\n"); return sprintf(buf, "%lu\n", result); } static ssize_t store_ideapad_fan(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int ret, state; if (!count) return 0; if (sscanf(buf, "%i", &state) != 1) return -EINVAL; if (state < 0 || state > 4 || state == 3) return -EINVAL; ret = write_ec_cmd(ideapad_handle, VPCCMD_W_FAN, state); if (ret < 0) return -EIO; return count; } static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan); static struct attribute *ideapad_attributes[] = { &dev_attr_camera_power.attr, &dev_attr_fan_mode.attr, NULL }; static umode_t ideapad_is_visible(struct kobject *kobj, struct attribute *attr, int idx) { struct device *dev = container_of(kobj, struct device, kobj); struct ideapad_private *priv = dev_get_drvdata(dev); bool supported; if (attr == &dev_attr_camera_power.attr) supported = test_bit(CFG_CAMERA_BIT, &(priv->cfg)); else if (attr == &dev_attr_fan_mode.attr) { unsigned long value; supported = !read_ec_data(ideapad_handle, VPCCMD_R_FAN, &value); } else supported = true; return supported ? attr->mode : 0; } static struct attribute_group ideapad_attribute_group = { .is_visible = ideapad_is_visible, .attrs = ideapad_attributes }; /* * Rfkill */ struct ideapad_rfk_data { char *name; int cfgbit; int opcode; int type; }; const struct ideapad_rfk_data ideapad_rfk_data[] = { { "ideapad_wlan", CFG_WIFI_BIT, VPCCMD_W_WIFI, RFKILL_TYPE_WLAN }, { "ideapad_bluetooth", CFG_BT_BIT, VPCCMD_W_BT, RFKILL_TYPE_BLUETOOTH }, { "ideapad_3g", CFG_3G_BIT, VPCCMD_W_3G, RFKILL_TYPE_WWAN }, }; static int ideapad_rfk_set(void *data, bool blocked) { unsigned long opcode = (unsigned long)data; return write_ec_cmd(ideapad_handle, opcode, !blocked); } static struct rfkill_ops ideapad_rfk_ops = { .set_block = ideapad_rfk_set, }; static void ideapad_sync_rfk_state(struct ideapad_private *priv) { unsigned long hw_blocked; int i; if (read_ec_data(ideapad_handle, VPCCMD_R_RF, &hw_blocked)) return; hw_blocked = !hw_blocked; for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) if (priv->rfk[i]) rfkill_set_hw_state(priv->rfk[i], hw_blocked); } static int ideapad_register_rfkill(struct acpi_device *adevice, int dev) { struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); int ret; unsigned long sw_blocked; if (no_bt_rfkill && (ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) { /* Force to enable bluetooth when no_bt_rfkill=1 */ write_ec_cmd(ideapad_handle, ideapad_rfk_data[dev].opcode, 1); return 0; } priv->rfk[dev] = rfkill_alloc(ideapad_rfk_data[dev].name, &adevice->dev, ideapad_rfk_data[dev].type, &ideapad_rfk_ops, (void *)(long)dev); if (!priv->rfk[dev]) return -ENOMEM; if (read_ec_data(ideapad_handle, ideapad_rfk_data[dev].opcode-1, &sw_blocked)) { rfkill_init_sw_state(priv->rfk[dev], 0); } else { sw_blocked = !sw_blocked; rfkill_init_sw_state(priv->rfk[dev], sw_blocked); } ret = rfkill_register(priv->rfk[dev]); if (ret) { rfkill_destroy(priv->rfk[dev]); return ret; } return 0; } static void ideapad_unregister_rfkill(struct acpi_device *adevice, int dev) { struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); if (!priv->rfk[dev]) return; rfkill_unregister(priv->rfk[dev]); rfkill_destroy(priv->rfk[dev]); } /* * Platform device */ static int ideapad_platform_init(struct ideapad_private *priv) { int result; priv->platform_device = platform_device_alloc("ideapad", -1); if (!priv->platform_device) return -ENOMEM; platform_set_drvdata(priv->platform_device, priv); result = platform_device_add(priv->platform_device); if (result) goto fail_platform_device; result = sysfs_create_group(&priv->platform_device->dev.kobj, &ideapad_attribute_group); if (result) goto fail_sysfs; return 0; fail_sysfs: platform_device_del(priv->platform_device); fail_platform_device: platform_device_put(priv->platform_device); return result; } static void ideapad_platform_exit(struct ideapad_private *priv) { sysfs_remove_group(&priv->platform_device->dev.kobj, &ideapad_attribute_group); platform_device_unregister(priv->platform_device); } /* * input device */ static const struct key_entry ideapad_keymap[] = { { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } }, { KE_KEY, 7, { KEY_CAMERA } }, { KE_KEY, 11, { KEY_F16 } }, { KE_KEY, 13, { KEY_WLAN } }, { KE_KEY, 16, { KEY_PROG1 } }, { KE_KEY, 17, { KEY_PROG2 } }, { KE_KEY, 64, { KEY_PROG3 } }, { KE_KEY, 65, { KEY_PROG4 } }, { KE_KEY, 66, { KEY_TOUCHPAD_OFF } }, { KE_KEY, 67, { KEY_TOUCHPAD_ON } }, { KE_END, 0 }, }; static int ideapad_input_init(struct ideapad_private *priv) { struct input_dev *inputdev; int error; inputdev = input_allocate_device(); if (!inputdev) { pr_info("Unable to allocate input device\n"); return -ENOMEM; } inputdev->name = "Ideapad extra buttons"; inputdev->phys = "ideapad/input0"; inputdev->id.bustype = BUS_HOST; inputdev->dev.parent = &priv->platform_device->dev; error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL); if (error) { pr_err("Unable to setup input device keymap\n"); goto err_free_dev; } error = input_register_device(inputdev); if (error) { pr_err("Unable to register input device\n"); goto err_free_keymap; } priv->inputdev = inputdev; return 0; err_free_keymap: sparse_keymap_free(inputdev); err_free_dev: input_free_device(inputdev); return error; } static void ideapad_input_exit(struct ideapad_private *priv) { sparse_keymap_free(priv->inputdev); input_unregister_device(priv->inputdev); priv->inputdev = NULL; } static void ideapad_input_report(struct ideapad_private *priv, unsigned long scancode) { sparse_keymap_report_event(priv->inputdev, scancode, 1, true); } static void ideapad_input_novokey(struct ideapad_private *priv) { unsigned long long_pressed; if (read_ec_data(ideapad_handle, VPCCMD_R_NOVO, &long_pressed)) return; if (long_pressed) ideapad_input_report(priv, 17); else ideapad_input_report(priv, 16); } static void ideapad_check_special_buttons(struct ideapad_private *priv) { unsigned long bit, value; read_ec_data(ideapad_handle, VPCCMD_R_SPECIAL_BUTTONS, &value); for (bit = 0; bit < 16; bit++) { if (test_bit(bit, &value)) { switch (bit) { case 0: /* Z580 */ case 6: /* Z570 */ /* Thermal Management button */ ideapad_input_report(priv, 65); break; case 1: /* OneKey Theater button */ ideapad_input_report(priv, 64); break; default: pr_info("Unknown special button: %lu\n", bit); break; } } } } /* * backlight */ static int ideapad_backlight_get_brightness(struct backlight_device *blightdev) { unsigned long now; if (read_ec_data(ideapad_handle, VPCCMD_R_BL, &now)) return -EIO; return now; } static int ideapad_backlight_update_status(struct backlight_device *blightdev) { if (write_ec_cmd(ideapad_handle, VPCCMD_W_BL, blightdev->props.brightness)) return -EIO; if (write_ec_cmd(ideapad_handle, VPCCMD_W_BL_POWER, blightdev->props.power == FB_BLANK_POWERDOWN ? 0 : 1)) return -EIO; return 0; } static const struct backlight_ops ideapad_backlight_ops = { .get_brightness = ideapad_backlight_get_brightness, .update_status = ideapad_backlight_update_status, }; static int ideapad_backlight_init(struct ideapad_private *priv) { struct backlight_device *blightdev; struct backlight_properties props; unsigned long max, now, power; if (read_ec_data(ideapad_handle, VPCCMD_R_BL_MAX, &max)) return -EIO; if (read_ec_data(ideapad_handle, VPCCMD_R_BL, &now)) return -EIO; if (read_ec_data(ideapad_handle, VPCCMD_R_BL_POWER, &power)) return -EIO; memset(&props, 0, sizeof(struct backlight_properties)); props.max_brightness = max; props.type = BACKLIGHT_PLATFORM; blightdev = backlight_device_register("ideapad", &priv->platform_device->dev, priv, &ideapad_backlight_ops, &props); if (IS_ERR(blightdev)) { pr_err("Could not register backlight device\n"); return PTR_ERR(blightdev); } priv->blightdev = blightdev; blightdev->props.brightness = now; blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; backlight_update_status(blightdev); return 0; } static void ideapad_backlight_exit(struct ideapad_private *priv) { if (priv->blightdev) backlight_device_unregister(priv->blightdev); priv->blightdev = NULL; } static void ideapad_backlight_notify_power(struct ideapad_private *priv) { unsigned long power; struct backlight_device *blightdev = priv->blightdev; if (!blightdev) return; if (read_ec_data(ideapad_handle, VPCCMD_R_BL_POWER, &power)) return; blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; } static void ideapad_backlight_notify_brightness(struct ideapad_private *priv) { unsigned long now; /* if we control brightness via acpi video driver */ if (priv->blightdev == NULL) { read_ec_data(ideapad_handle, VPCCMD_R_BL, &now); return; } backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY); } /* * module init/exit */ static const struct acpi_device_id ideapad_device_ids[] = { { "VPC2004", 0}, { "", 0}, }; MODULE_DEVICE_TABLE(acpi, ideapad_device_ids); static void ideapad_sync_touchpad_state(struct acpi_device *adevice) { struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); unsigned long value; /* Without reading from EC touchpad LED doesn't switch state */ if (!read_ec_data(adevice->handle, VPCCMD_R_TOUCHPAD, &value)) { /* Some IdeaPads don't really turn off touchpad - they only * switch the LED state. We (de)activate KBC AUX port to turn * touchpad off and on. We send KEY_TOUCHPAD_OFF and * KEY_TOUCHPAD_ON to not to get out of sync with LED */ unsigned char param; i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE); ideapad_input_report(priv, value ? 67 : 66); } } static int ideapad_acpi_add(struct acpi_device *adevice) { int ret, i; int cfg; struct ideapad_private *priv; if (read_method_int(adevice->handle, "_CFG", &cfg)) return -ENODEV; priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; dev_set_drvdata(&adevice->dev, priv); ideapad_priv = priv; ideapad_handle = adevice->handle; priv->cfg = cfg; ret = ideapad_platform_init(priv); if (ret) goto platform_failed; ret = ideapad_debugfs_init(priv); if (ret) goto debugfs_failed; ret = ideapad_input_init(priv); if (ret) goto input_failed; for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) { if (test_bit(ideapad_rfk_data[i].cfgbit, &priv->cfg)) ideapad_register_rfkill(adevice, i); else priv->rfk[i] = NULL; } ideapad_sync_rfk_state(priv); ideapad_sync_touchpad_state(adevice); if (!acpi_video_backlight_support()) { ret = ideapad_backlight_init(priv); if (ret && ret != -ENODEV) goto backlight_failed; } return 0; backlight_failed: for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) ideapad_unregister_rfkill(adevice, i); ideapad_input_exit(priv); input_failed: ideapad_debugfs_exit(priv); debugfs_failed: ideapad_platform_exit(priv); platform_failed: kfree(priv); return ret; } static int ideapad_acpi_remove(struct acpi_device *adevice) { struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); int i; ideapad_backlight_exit(priv); for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) ideapad_unregister_rfkill(adevice, i); ideapad_input_exit(priv); ideapad_debugfs_exit(priv); ideapad_platform_exit(priv); dev_set_drvdata(&adevice->dev, NULL); kfree(priv); return 0; } static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event) { struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); acpi_handle handle = adevice->handle; unsigned long vpc1, vpc2, vpc_bit; if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1)) return; if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2)) return; vpc1 = (vpc2 << 8) | vpc1; for (vpc_bit = 0; vpc_bit < 16; vpc_bit++) { if (test_bit(vpc_bit, &vpc1)) { switch (vpc_bit) { case 9: ideapad_sync_rfk_state(priv); break; case 13: case 11: case 7: case 6: ideapad_input_report(priv, vpc_bit); break; case 5: ideapad_sync_touchpad_state(adevice); break; case 4: ideapad_backlight_notify_brightness(priv); break; case 3: ideapad_input_novokey(priv); break; case 2: ideapad_backlight_notify_power(priv); break; case 0: ideapad_check_special_buttons(priv); break; default: pr_info("Unknown event: %lu\n", vpc_bit); } } } } static int ideapad_acpi_resume(struct device *device) { ideapad_sync_rfk_state(ideapad_priv); ideapad_sync_touchpad_state(to_acpi_device(device)); return 0; } static SIMPLE_DEV_PM_OPS(ideapad_pm, NULL, ideapad_acpi_resume); static struct acpi_driver ideapad_acpi_driver = { .name = "ideapad_acpi", .class = "IdeaPad", .ids = ideapad_device_ids, .ops.add = ideapad_acpi_add, .ops.remove = ideapad_acpi_remove, .ops.notify = ideapad_acpi_notify, .drv.pm = &ideapad_pm, .owner = THIS_MODULE, }; module_acpi_driver(ideapad_acpi_driver); MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); MODULE_DESCRIPTION("IdeaPad ACPI Extras"); MODULE_LICENSE("GPL");
gpl-2.0
Pillar1989/intel_edison_linux-3.10.17
drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
2240
5481
/* The industrial I/O periodic RTC trigger driver * * 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 is a heavily rewritten version of the periodic timer system in * earlier version of industrialio. It supplies the same functionality * but via a trigger rather than a specific periodic timer system. */ #include <linux/platform_device.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/rtc.h> #include <linux/iio/iio.h> #include <linux/iio/trigger.h> static LIST_HEAD(iio_prtc_trigger_list); static DEFINE_MUTEX(iio_prtc_trigger_list_lock); struct iio_prtc_trigger_info { struct rtc_device *rtc; int frequency; struct rtc_task task; }; static int iio_trig_periodic_rtc_set_state(struct iio_trigger *trig, bool state) { struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig); if (trig_info->frequency == 0) return -EINVAL; printk(KERN_INFO "trigger frequency is %d\n", trig_info->frequency); return rtc_irq_set_state(trig_info->rtc, &trig_info->task, state); } static ssize_t iio_trig_periodic_read_freq(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_trigger *trig = to_iio_trigger(dev); struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig); return sprintf(buf, "%u\n", trig_info->frequency); } static ssize_t iio_trig_periodic_write_freq(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct iio_trigger *trig = to_iio_trigger(dev); struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig); unsigned long val; int ret; ret = strict_strtoul(buf, 10, &val); if (ret) goto error_ret; ret = rtc_irq_set_freq(trig_info->rtc, &trig_info->task, val); if (ret) goto error_ret; trig_info->frequency = val; return len; error_ret: return ret; } static DEVICE_ATTR(frequency, S_IRUGO | S_IWUSR, iio_trig_periodic_read_freq, iio_trig_periodic_write_freq); static struct attribute *iio_trig_prtc_attrs[] = { &dev_attr_frequency.attr, NULL, }; static const struct attribute_group iio_trig_prtc_attr_group = { .attrs = iio_trig_prtc_attrs, }; static const struct attribute_group *iio_trig_prtc_attr_groups[] = { &iio_trig_prtc_attr_group, NULL }; static void iio_prtc_trigger_poll(void *private_data) { /* Timestamp is not provided currently */ iio_trigger_poll(private_data, 0); } static const struct iio_trigger_ops iio_prtc_trigger_ops = { .owner = THIS_MODULE, .set_trigger_state = &iio_trig_periodic_rtc_set_state, }; static int iio_trig_periodic_rtc_probe(struct platform_device *dev) { char **pdata = dev->dev.platform_data; struct iio_prtc_trigger_info *trig_info; struct iio_trigger *trig, *trig2; int i, ret; for (i = 0;; i++) { if (pdata[i] == NULL) break; trig = iio_trigger_alloc("periodic%s", pdata[i]); if (!trig) { ret = -ENOMEM; goto error_free_completed_registrations; } list_add(&trig->alloc_list, &iio_prtc_trigger_list); trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL); if (!trig_info) { ret = -ENOMEM; goto error_put_trigger_and_remove_from_list; } iio_trigger_set_drvdata(trig, trig_info); trig->ops = &iio_prtc_trigger_ops; /* RTC access */ trig_info->rtc = rtc_class_open(pdata[i]); if (trig_info->rtc == NULL) { ret = -EINVAL; goto error_free_trig_info; } trig_info->task.func = iio_prtc_trigger_poll; trig_info->task.private_data = trig; ret = rtc_irq_register(trig_info->rtc, &trig_info->task); if (ret) goto error_close_rtc; trig->dev.groups = iio_trig_prtc_attr_groups; ret = iio_trigger_register(trig); if (ret) goto error_unregister_rtc_irq; } return 0; error_unregister_rtc_irq: rtc_irq_unregister(trig_info->rtc, &trig_info->task); error_close_rtc: rtc_class_close(trig_info->rtc); error_free_trig_info: kfree(trig_info); error_put_trigger_and_remove_from_list: list_del(&trig->alloc_list); iio_trigger_put(trig); error_free_completed_registrations: list_for_each_entry_safe(trig, trig2, &iio_prtc_trigger_list, alloc_list) { trig_info = iio_trigger_get_drvdata(trig); rtc_irq_unregister(trig_info->rtc, &trig_info->task); rtc_class_close(trig_info->rtc); kfree(trig_info); iio_trigger_unregister(trig); } return ret; } static int iio_trig_periodic_rtc_remove(struct platform_device *dev) { struct iio_trigger *trig, *trig2; struct iio_prtc_trigger_info *trig_info; mutex_lock(&iio_prtc_trigger_list_lock); list_for_each_entry_safe(trig, trig2, &iio_prtc_trigger_list, alloc_list) { trig_info = iio_trigger_get_drvdata(trig); rtc_irq_unregister(trig_info->rtc, &trig_info->task); rtc_class_close(trig_info->rtc); kfree(trig_info); iio_trigger_unregister(trig); } mutex_unlock(&iio_prtc_trigger_list_lock); return 0; } static struct platform_driver iio_trig_periodic_rtc_driver = { .probe = iio_trig_periodic_rtc_probe, .remove = iio_trig_periodic_rtc_remove, .driver = { .name = "iio_prtc_trigger", .owner = THIS_MODULE, }, }; module_platform_driver(iio_trig_periodic_rtc_driver); MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); MODULE_DESCRIPTION("Periodic realtime clock trigger for the iio subsystem"); MODULE_LICENSE("GPL v2");
gpl-2.0
AntaresOne/AntaresCore-Kernel-h815
arch/arm/mach-dove/irq.c
2752
3084
/* * arch/arm/mach-dove/irq.c * * Dove IRQ handling. * * 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/irq.h> #include <linux/gpio.h> #include <linux/io.h> #include <asm/mach/arch.h> #include <plat/irq.h> #include <asm/mach/irq.h> #include <mach/pm.h> #include <mach/bridge-regs.h> #include <plat/orion-gpio.h> #include "common.h" static void pmu_irq_mask(struct irq_data *d) { int pin = irq_to_pmu(d->irq); u32 u; u = readl(PMU_INTERRUPT_MASK); u &= ~(1 << (pin & 31)); writel(u, PMU_INTERRUPT_MASK); } static void pmu_irq_unmask(struct irq_data *d) { int pin = irq_to_pmu(d->irq); u32 u; u = readl(PMU_INTERRUPT_MASK); u |= 1 << (pin & 31); writel(u, PMU_INTERRUPT_MASK); } static void pmu_irq_ack(struct irq_data *d) { int pin = irq_to_pmu(d->irq); u32 u; /* * The PMU mask register is not RW0C: it is RW. This means that * the bits take whatever value is written to them; if you write * a '1', you will set the interrupt. * * Unfortunately this means there is NO race free way to clear * these interrupts. * * So, let's structure the code so that the window is as small as * possible. */ u = ~(1 << (pin & 31)); u &= readl_relaxed(PMU_INTERRUPT_CAUSE); writel_relaxed(u, PMU_INTERRUPT_CAUSE); } static struct irq_chip pmu_irq_chip = { .name = "pmu_irq", .irq_mask = pmu_irq_mask, .irq_unmask = pmu_irq_unmask, .irq_ack = pmu_irq_ack, }; static void pmu_irq_handler(unsigned int irq, struct irq_desc *desc) { unsigned long cause = readl(PMU_INTERRUPT_CAUSE); cause &= readl(PMU_INTERRUPT_MASK); if (cause == 0) { do_bad_IRQ(irq, desc); return; } for (irq = 0; irq < NR_PMU_IRQS; irq++) { if (!(cause & (1 << irq))) continue; irq = pmu_to_irq(irq); generic_handle_irq(irq); } } static int __initdata gpio0_irqs[4] = { IRQ_DOVE_GPIO_0_7, IRQ_DOVE_GPIO_8_15, IRQ_DOVE_GPIO_16_23, IRQ_DOVE_GPIO_24_31, }; static int __initdata gpio1_irqs[4] = { IRQ_DOVE_HIGH_GPIO, 0, 0, 0, }; static int __initdata gpio2_irqs[4] = { 0, 0, 0, 0, }; void __init dove_init_irq(void) { int i; orion_irq_init(0, IRQ_VIRT_BASE + IRQ_MASK_LOW_OFF); orion_irq_init(32, IRQ_VIRT_BASE + IRQ_MASK_HIGH_OFF); /* * Initialize gpiolib for GPIOs 0-71. */ orion_gpio_init(NULL, 0, 32, DOVE_GPIO_LO_VIRT_BASE, 0, IRQ_DOVE_GPIO_START, gpio0_irqs); orion_gpio_init(NULL, 32, 32, DOVE_GPIO_HI_VIRT_BASE, 0, IRQ_DOVE_GPIO_START + 32, gpio1_irqs); orion_gpio_init(NULL, 64, 8, DOVE_GPIO2_VIRT_BASE, 0, IRQ_DOVE_GPIO_START + 64, gpio2_irqs); /* * Mask and clear PMU interrupts */ writel(0, PMU_INTERRUPT_MASK); writel(0, PMU_INTERRUPT_CAUSE); for (i = IRQ_DOVE_PMU_START; i < NR_IRQS; i++) { irq_set_chip_and_handler(i, &pmu_irq_chip, handle_level_irq); irq_set_status_flags(i, IRQ_LEVEL); set_irq_flags(i, IRQF_VALID); } irq_set_chained_handler(IRQ_DOVE_PMU, pmu_irq_handler); }
gpl-2.0
sktjdgns1189/android_kernel_samsung_SHW-M190S-4.2.2
arch/arm/mach-w90x900/cpu.c
3776
5325
/* * linux/arch/arm/mach-w90x900/cpu.c * * Copyright (c) 2009 Nuvoton corporation. * * Wan ZongShun <mcuos.com@gmail.com> * * NUC900 series cpu common 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;version 2 of the License. * */ #include <linux/kernel.h> #include <linux/types.h> #include <linux/interrupt.h> #include <linux/list.h> #include <linux/timer.h> #include <linux/init.h> #include <linux/platform_device.h> #include <linux/io.h> #include <linux/serial_8250.h> #include <linux/delay.h> #include <asm/mach/arch.h> #include <asm/mach/map.h> #include <asm/mach/irq.h> #include <asm/irq.h> #include <mach/hardware.h> #include <mach/regs-serial.h> #include <mach/regs-clock.h> #include <mach/regs-ebi.h> #include "cpu.h" #include "clock.h" /* Initial IO mappings */ static struct map_desc nuc900_iodesc[] __initdata = { IODESC_ENT(IRQ), IODESC_ENT(GCR), IODESC_ENT(UART), IODESC_ENT(TIMER), IODESC_ENT(EBI), IODESC_ENT(GPIO), }; /* Initial clock declarations. */ static DEFINE_CLK(lcd, 0); static DEFINE_CLK(audio, 1); static DEFINE_CLK(fmi, 4); static DEFINE_SUBCLK(ms, 0); static DEFINE_SUBCLK(sd, 1); static DEFINE_CLK(dmac, 5); static DEFINE_CLK(atapi, 6); static DEFINE_CLK(emc, 7); static DEFINE_SUBCLK(rmii, 2); static DEFINE_CLK(usbd, 8); static DEFINE_CLK(usbh, 9); static DEFINE_CLK(g2d, 10);; static DEFINE_CLK(pwm, 18); static DEFINE_CLK(ps2, 24); static DEFINE_CLK(kpi, 25); static DEFINE_CLK(wdt, 26); static DEFINE_CLK(gdma, 27); static DEFINE_CLK(adc, 28); static DEFINE_CLK(usi, 29); static DEFINE_CLK(ext, 0); static DEFINE_CLK(timer0, 19); static DEFINE_CLK(timer1, 20); static DEFINE_CLK(timer2, 21); static DEFINE_CLK(timer3, 22); static DEFINE_CLK(timer4, 23); static struct clk_lookup nuc900_clkregs[] = { DEF_CLKLOOK(&clk_lcd, "nuc900-lcd", NULL), DEF_CLKLOOK(&clk_audio, "nuc900-audio", NULL), DEF_CLKLOOK(&clk_fmi, "nuc900-fmi", NULL), DEF_CLKLOOK(&clk_ms, "nuc900-fmi", "MS"), DEF_CLKLOOK(&clk_sd, "nuc900-fmi", "SD"), DEF_CLKLOOK(&clk_dmac, "nuc900-dmac", NULL), DEF_CLKLOOK(&clk_atapi, "nuc900-atapi", NULL), DEF_CLKLOOK(&clk_emc, "nuc900-emc", NULL), DEF_CLKLOOK(&clk_rmii, "nuc900-emc", "RMII"), DEF_CLKLOOK(&clk_usbd, "nuc900-usbd", NULL), DEF_CLKLOOK(&clk_usbh, "nuc900-usbh", NULL), DEF_CLKLOOK(&clk_g2d, "nuc900-g2d", NULL), DEF_CLKLOOK(&clk_pwm, "nuc900-pwm", NULL), DEF_CLKLOOK(&clk_ps2, "nuc900-ps2", NULL), DEF_CLKLOOK(&clk_kpi, "nuc900-kpi", NULL), DEF_CLKLOOK(&clk_wdt, "nuc900-wdt", NULL), DEF_CLKLOOK(&clk_gdma, "nuc900-gdma", NULL), DEF_CLKLOOK(&clk_adc, "nuc900-ts", NULL), DEF_CLKLOOK(&clk_usi, "nuc900-spi", NULL), DEF_CLKLOOK(&clk_ext, NULL, "ext"), DEF_CLKLOOK(&clk_timer0, NULL, "timer0"), DEF_CLKLOOK(&clk_timer1, NULL, "timer1"), DEF_CLKLOOK(&clk_timer2, NULL, "timer2"), DEF_CLKLOOK(&clk_timer3, NULL, "timer3"), DEF_CLKLOOK(&clk_timer4, NULL, "timer4"), }; /* Initial serial platform data */ struct plat_serial8250_port nuc900_uart_data[] = { NUC900_8250PORT(UART0), {}, }; struct platform_device nuc900_serial_device = { .name = "serial8250", .id = PLAT8250_DEV_PLATFORM, .dev = { .platform_data = nuc900_uart_data, }, }; /*Set NUC900 series cpu frequence*/ static int __init nuc900_set_clkval(unsigned int cpufreq) { unsigned int pllclk, ahbclk, apbclk, val; pllclk = 0; ahbclk = 0; apbclk = 0; switch (cpufreq) { case 66: pllclk = PLL_66MHZ; ahbclk = AHB_CPUCLK_1_1; apbclk = APB_AHB_1_2; break; case 100: pllclk = PLL_100MHZ; ahbclk = AHB_CPUCLK_1_1; apbclk = APB_AHB_1_2; break; case 120: pllclk = PLL_120MHZ; ahbclk = AHB_CPUCLK_1_2; apbclk = APB_AHB_1_2; break; case 166: pllclk = PLL_166MHZ; ahbclk = AHB_CPUCLK_1_2; apbclk = APB_AHB_1_2; break; case 200: pllclk = PLL_200MHZ; ahbclk = AHB_CPUCLK_1_2; apbclk = APB_AHB_1_2; break; } __raw_writel(pllclk, REG_PLLCON0); val = __raw_readl(REG_CLKDIV); val &= ~(0x03 << 24 | 0x03 << 26); val |= (ahbclk << 24 | apbclk << 26); __raw_writel(val, REG_CLKDIV); return 0; } static int __init nuc900_set_cpufreq(char *str) { unsigned long cpufreq, val; if (!*str) return 0; strict_strtoul(str, 0, &cpufreq); nuc900_clock_source(NULL, "ext"); nuc900_set_clkval(cpufreq); mdelay(1); val = __raw_readl(REG_CKSKEW); val &= ~0xff; val |= DEFAULTSKEW; __raw_writel(val, REG_CKSKEW); nuc900_clock_source(NULL, "pll0"); return 1; } __setup("cpufreq=", nuc900_set_cpufreq); /*Init NUC900 evb io*/ void __init nuc900_map_io(struct map_desc *mach_desc, int mach_size) { unsigned long idcode = 0x0; iotable_init(mach_desc, mach_size); iotable_init(nuc900_iodesc, ARRAY_SIZE(nuc900_iodesc)); idcode = __raw_readl(NUC900PDID); if (idcode == NUC910_CPUID) printk(KERN_INFO "CPU type 0x%08lx is NUC910\n", idcode); else if (idcode == NUC920_CPUID) printk(KERN_INFO "CPU type 0x%08lx is NUC920\n", idcode); else if (idcode == NUC950_CPUID) printk(KERN_INFO "CPU type 0x%08lx is NUC950\n", idcode); else if (idcode == NUC960_CPUID) printk(KERN_INFO "CPU type 0x%08lx is NUC960\n", idcode); } /*Init NUC900 clock*/ void __init nuc900_init_clocks(void) { clkdev_add_table(nuc900_clkregs, ARRAY_SIZE(nuc900_clkregs)); }
gpl-2.0
TeamPlaceholder/android_kernel_lge_gee
arch/powerpc/platforms/85xx/mpc85xx_ads.c
4544
5458
/* * MPC85xx setup and early boot code plus other random bits. * * Maintained by Kumar Gala (see MAINTAINERS for contact information) * * Copyright 2005 Freescale Semiconductor 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. */ #include <linux/stddef.h> #include <linux/kernel.h> #include <linux/pci.h> #include <linux/kdev_t.h> #include <linux/delay.h> #include <linux/seq_file.h> #include <linux/of_platform.h> #include <asm/time.h> #include <asm/machdep.h> #include <asm/pci-bridge.h> #include <asm/mpic.h> #include <mm/mmu_decl.h> #include <asm/udbg.h> #include <sysdev/fsl_soc.h> #include <sysdev/fsl_pci.h> #ifdef CONFIG_CPM2 #include <asm/cpm2.h> #include <sysdev/cpm2_pic.h> #endif #include "mpc85xx.h" #ifdef CONFIG_PCI static int mpc85xx_exclude_device(struct pci_controller *hose, u_char bus, u_char devfn) { if (bus == 0 && PCI_SLOT(devfn) == 0) return PCIBIOS_DEVICE_NOT_FOUND; else return PCIBIOS_SUCCESSFUL; } #endif /* CONFIG_PCI */ static void __init mpc85xx_ads_pic_init(void) { struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN, 0, 256, " OpenPIC "); BUG_ON(mpic == NULL); mpic_init(mpic); mpc85xx_cpm2_pic_init(); } /* * Setup the architecture */ #ifdef CONFIG_CPM2 struct cpm_pin { int port, pin, flags; }; static const struct cpm_pin mpc8560_ads_pins[] = { /* SCC1 */ {3, 29, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {3, 30, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY}, {3, 31, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* SCC2 */ {2, 12, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {2, 13, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {3, 26, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {3, 27, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {3, 28, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* FCC2 */ {1, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 20, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 22, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {1, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {1, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {1, 25, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {1, 26, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 27, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 28, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY}, {1, 30, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 31, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {2, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* CLK14 */ {2, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* CLK13 */ /* FCC3 */ {1, 4, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {1, 5, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {1, 6, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {1, 8, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 9, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 10, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 11, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 12, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 13, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 14, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {1, 15, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, {1, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {1, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, {2, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* CLK16 */ {2, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* CLK15 */ {2, 27, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, }; static void __init init_ioports(void) { int i; for (i = 0; i < ARRAY_SIZE(mpc8560_ads_pins); i++) { const struct cpm_pin *pin = &mpc8560_ads_pins[i]; cpm2_set_pin(pin->port, pin->pin, pin->flags); } cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_RX); cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_TX); cpm2_clk_setup(CPM_CLK_SCC2, CPM_BRG2, CPM_CLK_RX); cpm2_clk_setup(CPM_CLK_SCC2, CPM_BRG2, CPM_CLK_TX); cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK13, CPM_CLK_RX); cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK14, CPM_CLK_TX); cpm2_clk_setup(CPM_CLK_FCC3, CPM_CLK15, CPM_CLK_RX); cpm2_clk_setup(CPM_CLK_FCC3, CPM_CLK16, CPM_CLK_TX); } #endif static void __init mpc85xx_ads_setup_arch(void) { #ifdef CONFIG_PCI struct device_node *np; #endif if (ppc_md.progress) ppc_md.progress("mpc85xx_ads_setup_arch()", 0); #ifdef CONFIG_CPM2 cpm2_reset(); init_ioports(); #endif #ifdef CONFIG_PCI for_each_compatible_node(np, "pci", "fsl,mpc8540-pci") fsl_add_bridge(np, 1); ppc_md.pci_exclude_device = mpc85xx_exclude_device; #endif } static void mpc85xx_ads_show_cpuinfo(struct seq_file *m) { uint pvid, svid, phid1; pvid = mfspr(SPRN_PVR); svid = mfspr(SPRN_SVR); seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n"); seq_printf(m, "PVR\t\t: 0x%x\n", pvid); seq_printf(m, "SVR\t\t: 0x%x\n", svid); /* Display cpu Pll setting */ phid1 = mfspr(SPRN_HID1); seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f)); } machine_device_initcall(mpc85xx_ads, mpc85xx_common_publish_devices); /* * Called very early, device-tree isn't unflattened */ static int __init mpc85xx_ads_probe(void) { unsigned long root = of_get_flat_dt_root(); return of_flat_dt_is_compatible(root, "MPC85xxADS"); } define_machine(mpc85xx_ads) { .name = "MPC85xx ADS", .probe = mpc85xx_ads_probe, .setup_arch = mpc85xx_ads_setup_arch, .init_IRQ = mpc85xx_ads_pic_init, .show_cpuinfo = mpc85xx_ads_show_cpuinfo, .get_irq = mpic_get_irq, .restart = fsl_rstcr_restart, .calibrate_decr = generic_calibrate_decr, .progress = udbg_progress, };
gpl-2.0
Alucard24/SGS4-SAMMY-Kernel
drivers/staging/ozwpan/ozevent.c
4800
3148
/* ----------------------------------------------------------------------------- * Copyright (c) 2011 Ozmo Inc * Released under the GNU General Public License Version 2 (GPLv2). * ----------------------------------------------------------------------------- */ #include "ozconfig.h" #ifdef WANT_EVENT_TRACE #include <linux/jiffies.h> #include <linux/uaccess.h> #include "oztrace.h" #include "ozevent.h" /*------------------------------------------------------------------------------ */ unsigned long g_evt_mask = 0xffffffff; /*------------------------------------------------------------------------------ */ #define OZ_MAX_EVTS 2048 /* Must be power of 2 */ DEFINE_SPINLOCK(g_eventlock); static int g_evt_in; static int g_evt_out; static int g_missed_events; static struct oz_event g_events[OZ_MAX_EVTS]; /*------------------------------------------------------------------------------ * Context: process */ void oz_event_init(void) { oz_trace("Event tracing initialized\n"); g_evt_in = g_evt_out = 0; g_missed_events = 0; } /*------------------------------------------------------------------------------ * Context: process */ void oz_event_term(void) { oz_trace("Event tracing terminated\n"); } /*------------------------------------------------------------------------------ * Context: any */ void oz_event_log2(u8 evt, u8 ctx1, u16 ctx2, void *ctx3, unsigned ctx4) { unsigned long irqstate; int ix; spin_lock_irqsave(&g_eventlock, irqstate); ix = (g_evt_in + 1) & (OZ_MAX_EVTS - 1); if (ix != g_evt_out) { struct oz_event *e = &g_events[g_evt_in]; e->jiffies = jiffies; e->evt = evt; e->ctx1 = ctx1; e->ctx2 = ctx2; e->ctx3 = ctx3; e->ctx4 = ctx4; g_evt_in = ix; } else { g_missed_events++; } spin_unlock_irqrestore(&g_eventlock, irqstate); } /*------------------------------------------------------------------------------ * Context: process */ int oz_events_copy(struct oz_evtlist __user *lst) { int first; int ix; struct hdr { int count; int missed; } hdr; ix = g_evt_out; hdr.count = g_evt_in - ix; if (hdr.count < 0) hdr.count += OZ_MAX_EVTS; if (hdr.count > OZ_EVT_LIST_SZ) hdr.count = OZ_EVT_LIST_SZ; hdr.missed = g_missed_events; g_missed_events = 0; if (copy_to_user((void __user *)lst, &hdr, sizeof(hdr))) return -EFAULT; first = OZ_MAX_EVTS - ix; if (first > hdr.count) first = hdr.count; if (first) { int sz = first*sizeof(struct oz_event); void __user *p = (void __user *)lst->evts; if (copy_to_user(p, &g_events[ix], sz)) return -EFAULT; if (hdr.count > first) { p = (void __user *)&lst->evts[first]; sz = (hdr.count-first)*sizeof(struct oz_event); if (copy_to_user(p, g_events, sz)) return -EFAULT; } } ix += hdr.count; if (ix >= OZ_MAX_EVTS) ix -= OZ_MAX_EVTS; g_evt_out = ix; return 0; } /*------------------------------------------------------------------------------ * Context: process */ void oz_events_clear(void) { unsigned long irqstate; spin_lock_irqsave(&g_eventlock, irqstate); g_evt_in = g_evt_out = 0; g_missed_events = 0; spin_unlock_irqrestore(&g_eventlock, irqstate); } #endif /* WANT_EVENT_TRACE */
gpl-2.0
CaptainThrowback/kernel_htc_m8whl_3.30.654.2
drivers/s390/cio/cio.c
4800
27214
/* * drivers/s390/cio/cio.c * S/390 common I/O routines -- low level i/o calls * * Copyright IBM Corp. 1999,2008 * Author(s): Ingo Adlung (adlung@de.ibm.com) * Cornelia Huck (cornelia.huck@de.ibm.com) * Arnd Bergmann (arndb@de.ibm.com) * Martin Schwidefsky (schwidefsky@de.ibm.com) */ #define KMSG_COMPONENT "cio" #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt #include <linux/ftrace.h> #include <linux/module.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/device.h> #include <linux/kernel_stat.h> #include <linux/interrupt.h> #include <asm/cio.h> #include <asm/delay.h> #include <asm/irq.h> #include <asm/irq_regs.h> #include <asm/setup.h> #include <asm/reset.h> #include <asm/ipl.h> #include <asm/chpid.h> #include <asm/airq.h> #include <asm/isc.h> #include <asm/cputime.h> #include <asm/fcx.h> #include <asm/nmi.h> #include <asm/crw.h> #include "cio.h" #include "css.h" #include "chsc.h" #include "ioasm.h" #include "io_sch.h" #include "blacklist.h" #include "cio_debug.h" #include "chp.h" debug_info_t *cio_debug_msg_id; debug_info_t *cio_debug_trace_id; debug_info_t *cio_debug_crw_id; /* * Function: cio_debug_init * Initializes three debug logs for common I/O: * - cio_msg logs generic cio messages * - cio_trace logs the calling of different functions * - cio_crw logs machine check related cio messages */ static int __init cio_debug_init(void) { cio_debug_msg_id = debug_register("cio_msg", 16, 1, 16 * sizeof(long)); if (!cio_debug_msg_id) goto out_unregister; debug_register_view(cio_debug_msg_id, &debug_sprintf_view); debug_set_level(cio_debug_msg_id, 2); cio_debug_trace_id = debug_register("cio_trace", 16, 1, 16); if (!cio_debug_trace_id) goto out_unregister; debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view); debug_set_level(cio_debug_trace_id, 2); cio_debug_crw_id = debug_register("cio_crw", 16, 1, 16 * sizeof(long)); if (!cio_debug_crw_id) goto out_unregister; debug_register_view(cio_debug_crw_id, &debug_sprintf_view); debug_set_level(cio_debug_crw_id, 4); return 0; out_unregister: if (cio_debug_msg_id) debug_unregister(cio_debug_msg_id); if (cio_debug_trace_id) debug_unregister(cio_debug_trace_id); if (cio_debug_crw_id) debug_unregister(cio_debug_crw_id); return -1; } arch_initcall (cio_debug_init); int cio_set_options(struct subchannel *sch, int flags) { struct io_subchannel_private *priv = to_io_private(sch); priv->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0; priv->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0; priv->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0; return 0; } static int cio_start_handle_notoper(struct subchannel *sch, __u8 lpm) { char dbf_text[15]; if (lpm != 0) sch->lpm &= ~lpm; else sch->lpm = 0; CIO_MSG_EVENT(2, "cio_start: 'not oper' status for " "subchannel 0.%x.%04x!\n", sch->schid.ssid, sch->schid.sch_no); if (cio_update_schib(sch)) return -ENODEV; sprintf(dbf_text, "no%s", dev_name(&sch->dev)); CIO_TRACE_EVENT(0, dbf_text); CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib)); return (sch->lpm ? -EACCES : -ENODEV); } int cio_start_key (struct subchannel *sch, /* subchannel structure */ struct ccw1 * cpa, /* logical channel prog addr */ __u8 lpm, /* logical path mask */ __u8 key) /* storage key */ { struct io_subchannel_private *priv = to_io_private(sch); union orb *orb = &priv->orb; int ccode; CIO_TRACE_EVENT(5, "stIO"); CIO_TRACE_EVENT(5, dev_name(&sch->dev)); memset(orb, 0, sizeof(union orb)); /* sch is always under 2G. */ orb->cmd.intparm = (u32)(addr_t)sch; orb->cmd.fmt = 1; orb->cmd.pfch = priv->options.prefetch == 0; orb->cmd.spnd = priv->options.suspend; orb->cmd.ssic = priv->options.suspend && priv->options.inter; orb->cmd.lpm = (lpm != 0) ? lpm : sch->lpm; #ifdef CONFIG_64BIT /* * for 64 bit we always support 64 bit IDAWs with 4k page size only */ orb->cmd.c64 = 1; orb->cmd.i2k = 0; #endif orb->cmd.key = key >> 4; /* issue "Start Subchannel" */ orb->cmd.cpa = (__u32) __pa(cpa); ccode = ssch(sch->schid, orb); /* process condition code */ CIO_HEX_EVENT(5, &ccode, sizeof(ccode)); switch (ccode) { case 0: /* * initialize device status information */ sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND; return 0; case 1: /* status pending */ case 2: /* busy */ return -EBUSY; case 3: /* device/path not operational */ return cio_start_handle_notoper(sch, lpm); default: return ccode; } } int cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm) { return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY); } /* * resume suspended I/O operation */ int cio_resume (struct subchannel *sch) { int ccode; CIO_TRACE_EVENT(4, "resIO"); CIO_TRACE_EVENT(4, dev_name(&sch->dev)); ccode = rsch (sch->schid); CIO_HEX_EVENT(4, &ccode, sizeof(ccode)); switch (ccode) { case 0: sch->schib.scsw.cmd.actl |= SCSW_ACTL_RESUME_PEND; return 0; case 1: return -EBUSY; case 2: return -EINVAL; default: /* * useless to wait for request completion * as device is no longer operational ! */ return -ENODEV; } } /* * halt I/O operation */ int cio_halt(struct subchannel *sch) { int ccode; if (!sch) return -ENODEV; CIO_TRACE_EVENT(2, "haltIO"); CIO_TRACE_EVENT(2, dev_name(&sch->dev)); /* * Issue "Halt subchannel" and process condition code */ ccode = hsch (sch->schid); CIO_HEX_EVENT(2, &ccode, sizeof(ccode)); switch (ccode) { case 0: sch->schib.scsw.cmd.actl |= SCSW_ACTL_HALT_PEND; return 0; case 1: /* status pending */ case 2: /* busy */ return -EBUSY; default: /* device not operational */ return -ENODEV; } } /* * Clear I/O operation */ int cio_clear(struct subchannel *sch) { int ccode; if (!sch) return -ENODEV; CIO_TRACE_EVENT(2, "clearIO"); CIO_TRACE_EVENT(2, dev_name(&sch->dev)); /* * Issue "Clear subchannel" and process condition code */ ccode = csch (sch->schid); CIO_HEX_EVENT(2, &ccode, sizeof(ccode)); switch (ccode) { case 0: sch->schib.scsw.cmd.actl |= SCSW_ACTL_CLEAR_PEND; return 0; default: /* device not operational */ return -ENODEV; } } /* * Function: cio_cancel * Issues a "Cancel Subchannel" on the specified subchannel * Note: We don't need any fancy intparms and flags here * since xsch is executed synchronously. * Only for common I/O internal use as for now. */ int cio_cancel (struct subchannel *sch) { int ccode; if (!sch) return -ENODEV; CIO_TRACE_EVENT(2, "cancelIO"); CIO_TRACE_EVENT(2, dev_name(&sch->dev)); ccode = xsch (sch->schid); CIO_HEX_EVENT(2, &ccode, sizeof(ccode)); switch (ccode) { case 0: /* success */ /* Update information in scsw. */ if (cio_update_schib(sch)) return -ENODEV; return 0; case 1: /* status pending */ return -EBUSY; case 2: /* not applicable */ return -EINVAL; default: /* not oper */ return -ENODEV; } } static void cio_apply_config(struct subchannel *sch, struct schib *schib) { schib->pmcw.intparm = sch->config.intparm; schib->pmcw.mbi = sch->config.mbi; schib->pmcw.isc = sch->config.isc; schib->pmcw.ena = sch->config.ena; schib->pmcw.mme = sch->config.mme; schib->pmcw.mp = sch->config.mp; schib->pmcw.csense = sch->config.csense; schib->pmcw.mbfc = sch->config.mbfc; if (sch->config.mbfc) schib->mba = sch->config.mba; } static int cio_check_config(struct subchannel *sch, struct schib *schib) { return (schib->pmcw.intparm == sch->config.intparm) && (schib->pmcw.mbi == sch->config.mbi) && (schib->pmcw.isc == sch->config.isc) && (schib->pmcw.ena == sch->config.ena) && (schib->pmcw.mme == sch->config.mme) && (schib->pmcw.mp == sch->config.mp) && (schib->pmcw.csense == sch->config.csense) && (schib->pmcw.mbfc == sch->config.mbfc) && (!sch->config.mbfc || (schib->mba == sch->config.mba)); } /* * cio_commit_config - apply configuration to the subchannel */ int cio_commit_config(struct subchannel *sch) { struct schib schib; int ccode, retry, ret = 0; if (stsch_err(sch->schid, &schib) || !css_sch_is_valid(&schib)) return -ENODEV; for (retry = 0; retry < 5; retry++) { /* copy desired changes to local schib */ cio_apply_config(sch, &schib); ccode = msch_err(sch->schid, &schib); if (ccode < 0) /* -EIO if msch gets a program check. */ return ccode; switch (ccode) { case 0: /* successful */ if (stsch_err(sch->schid, &schib) || !css_sch_is_valid(&schib)) return -ENODEV; if (cio_check_config(sch, &schib)) { /* commit changes from local schib */ memcpy(&sch->schib, &schib, sizeof(schib)); return 0; } ret = -EAGAIN; break; case 1: /* status pending */ return -EBUSY; case 2: /* busy */ udelay(100); /* allow for recovery */ ret = -EBUSY; break; case 3: /* not operational */ return -ENODEV; } } return ret; } /** * cio_update_schib - Perform stsch and update schib if subchannel is valid. * @sch: subchannel on which to perform stsch * Return zero on success, -ENODEV otherwise. */ int cio_update_schib(struct subchannel *sch) { struct schib schib; if (stsch_err(sch->schid, &schib) || !css_sch_is_valid(&schib)) return -ENODEV; memcpy(&sch->schib, &schib, sizeof(schib)); return 0; } EXPORT_SYMBOL_GPL(cio_update_schib); /** * cio_enable_subchannel - enable a subchannel. * @sch: subchannel to be enabled * @intparm: interruption parameter to set */ int cio_enable_subchannel(struct subchannel *sch, u32 intparm) { int retry; int ret; CIO_TRACE_EVENT(2, "ensch"); CIO_TRACE_EVENT(2, dev_name(&sch->dev)); if (sch_is_pseudo_sch(sch)) return -EINVAL; if (cio_update_schib(sch)) return -ENODEV; sch->config.ena = 1; sch->config.isc = sch->isc; sch->config.intparm = intparm; for (retry = 0; retry < 3; retry++) { ret = cio_commit_config(sch); if (ret == -EIO) { /* * Got a program check in msch. Try without * the concurrent sense bit the next time. */ sch->config.csense = 0; } else if (ret == -EBUSY) { struct irb irb; if (tsch(sch->schid, &irb) != 0) break; } else break; } CIO_HEX_EVENT(2, &ret, sizeof(ret)); return ret; } EXPORT_SYMBOL_GPL(cio_enable_subchannel); /** * cio_disable_subchannel - disable a subchannel. * @sch: subchannel to disable */ int cio_disable_subchannel(struct subchannel *sch) { int retry; int ret; CIO_TRACE_EVENT(2, "dissch"); CIO_TRACE_EVENT(2, dev_name(&sch->dev)); if (sch_is_pseudo_sch(sch)) return 0; if (cio_update_schib(sch)) return -ENODEV; sch->config.ena = 0; for (retry = 0; retry < 3; retry++) { ret = cio_commit_config(sch); if (ret == -EBUSY) { struct irb irb; if (tsch(sch->schid, &irb) != 0) break; } else break; } CIO_HEX_EVENT(2, &ret, sizeof(ret)); return ret; } EXPORT_SYMBOL_GPL(cio_disable_subchannel); int cio_create_sch_lock(struct subchannel *sch) { sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL); if (!sch->lock) return -ENOMEM; spin_lock_init(sch->lock); return 0; } static int cio_check_devno_blacklisted(struct subchannel *sch) { if (is_blacklisted(sch->schid.ssid, sch->schib.pmcw.dev)) { /* * This device must not be known to Linux. So we simply * say that there is no device and return ENODEV. */ CIO_MSG_EVENT(6, "Blacklisted device detected " "at devno %04X, subchannel set %x\n", sch->schib.pmcw.dev, sch->schid.ssid); return -ENODEV; } return 0; } static int cio_validate_io_subchannel(struct subchannel *sch) { /* Initialization for io subchannels. */ if (!css_sch_is_valid(&sch->schib)) return -ENODEV; /* Devno is valid. */ return cio_check_devno_blacklisted(sch); } static int cio_validate_msg_subchannel(struct subchannel *sch) { /* Initialization for message subchannels. */ if (!css_sch_is_valid(&sch->schib)) return -ENODEV; /* Devno is valid. */ return cio_check_devno_blacklisted(sch); } /** * cio_validate_subchannel - basic validation of subchannel * @sch: subchannel structure to be filled out * @schid: subchannel id * * Find out subchannel type and initialize struct subchannel. * Return codes: * 0 on success * -ENXIO for non-defined subchannels * -ENODEV for invalid subchannels or blacklisted devices * -EIO for subchannels in an invalid subchannel set */ int cio_validate_subchannel(struct subchannel *sch, struct subchannel_id schid) { char dbf_txt[15]; int ccode; int err; sprintf(dbf_txt, "valsch%x", schid.sch_no); CIO_TRACE_EVENT(4, dbf_txt); /* Nuke all fields. */ memset(sch, 0, sizeof(struct subchannel)); sch->schid = schid; if (cio_is_console(schid)) { sch->lock = cio_get_console_lock(); } else { err = cio_create_sch_lock(sch); if (err) goto out; } mutex_init(&sch->reg_mutex); /* * The first subchannel that is not-operational (ccode==3) * indicates that there aren't any more devices available. * If stsch gets an exception, it means the current subchannel set * is not valid. */ ccode = stsch_err (schid, &sch->schib); if (ccode) { err = (ccode == 3) ? -ENXIO : ccode; goto out; } /* Copy subchannel type from path management control word. */ sch->st = sch->schib.pmcw.st; switch (sch->st) { case SUBCHANNEL_TYPE_IO: err = cio_validate_io_subchannel(sch); break; case SUBCHANNEL_TYPE_MSG: err = cio_validate_msg_subchannel(sch); break; default: err = 0; } if (err) goto out; CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n", sch->schid.ssid, sch->schid.sch_no, sch->st); return 0; out: if (!cio_is_console(schid)) kfree(sch->lock); sch->lock = NULL; return err; } /* * do_IRQ() handles all normal I/O device IRQ's (the special * SMP cross-CPU interrupts have their own specific * handlers). * */ void __irq_entry do_IRQ(struct pt_regs *regs) { struct tpi_info *tpi_info; struct subchannel *sch; struct irb *irb; struct pt_regs *old_regs; old_regs = set_irq_regs(regs); irq_enter(); __this_cpu_write(s390_idle.nohz_delay, 1); if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator) /* Serve timer interrupts first. */ clock_comparator_work(); /* * Get interrupt information from lowcore */ tpi_info = (struct tpi_info *)&S390_lowcore.subchannel_id; irb = (struct irb *)&S390_lowcore.irb; do { kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++; if (tpi_info->adapter_IO) { do_adapter_IO(tpi_info->isc); continue; } sch = (struct subchannel *)(unsigned long)tpi_info->intparm; if (!sch) { /* Clear pending interrupt condition. */ kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++; tsch(tpi_info->schid, irb); continue; } spin_lock(sch->lock); /* Store interrupt response block to lowcore. */ if (tsch(tpi_info->schid, irb) == 0) { /* Keep subchannel information word up to date. */ memcpy (&sch->schib.scsw, &irb->scsw, sizeof (irb->scsw)); /* Call interrupt handler if there is one. */ if (sch->driver && sch->driver->irq) sch->driver->irq(sch); else kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++; } else kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++; spin_unlock(sch->lock); /* * Are more interrupts pending? * If so, the tpi instruction will update the lowcore * to hold the info for the next interrupt. * We don't do this for VM because a tpi drops the cpu * out of the sie which costs more cycles than it saves. */ } while (MACHINE_IS_LPAR && tpi(NULL) != 0); irq_exit(); set_irq_regs(old_regs); } #ifdef CONFIG_CCW_CONSOLE static struct subchannel console_subchannel; static struct io_subchannel_private console_priv; static int console_subchannel_in_use; /* * Use cio_tpi to get a pending interrupt and call the interrupt handler. * Return non-zero if an interrupt was processed, zero otherwise. */ static int cio_tpi(void) { struct tpi_info *tpi_info; struct subchannel *sch; struct irb *irb; int irq_context; tpi_info = (struct tpi_info *)&S390_lowcore.subchannel_id; if (tpi(NULL) != 1) return 0; kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++; if (tpi_info->adapter_IO) { do_adapter_IO(tpi_info->isc); return 1; } irb = (struct irb *)&S390_lowcore.irb; /* Store interrupt response block to lowcore. */ if (tsch(tpi_info->schid, irb) != 0) { /* Not status pending or not operational. */ kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++; return 1; } sch = (struct subchannel *)(unsigned long)tpi_info->intparm; if (!sch) { kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++; return 1; } irq_context = in_interrupt(); if (!irq_context) local_bh_disable(); irq_enter(); spin_lock(sch->lock); memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw)); if (sch->driver && sch->driver->irq) sch->driver->irq(sch); else kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++; spin_unlock(sch->lock); irq_exit(); if (!irq_context) _local_bh_enable(); return 1; } void *cio_get_console_priv(void) { return &console_priv; } /* * busy wait for the next interrupt on the console */ void wait_cons_dev(void) __releases(console_subchannel.lock) __acquires(console_subchannel.lock) { unsigned long cr6 __attribute__ ((aligned (8))); unsigned long save_cr6 __attribute__ ((aligned (8))); /* * before entering the spinlock we may already have * processed the interrupt on a different CPU... */ if (!console_subchannel_in_use) return; /* disable all but the console isc */ __ctl_store (save_cr6, 6, 6); cr6 = 1UL << (31 - CONSOLE_ISC); __ctl_load (cr6, 6, 6); do { spin_unlock(console_subchannel.lock); if (!cio_tpi()) cpu_relax(); spin_lock(console_subchannel.lock); } while (console_subchannel.schib.scsw.cmd.actl != 0); /* * restore previous isc value */ __ctl_load (save_cr6, 6, 6); } static int cio_test_for_console(struct subchannel_id schid, void *data) { if (stsch_err(schid, &console_subchannel.schib) != 0) return -ENXIO; if ((console_subchannel.schib.pmcw.st == SUBCHANNEL_TYPE_IO) && console_subchannel.schib.pmcw.dnv && (console_subchannel.schib.pmcw.dev == console_devno)) { console_irq = schid.sch_no; return 1; /* found */ } return 0; } static int cio_get_console_sch_no(void) { struct subchannel_id schid; init_subchannel_id(&schid); if (console_irq != -1) { /* VM provided us with the irq number of the console. */ schid.sch_no = console_irq; if (stsch_err(schid, &console_subchannel.schib) != 0 || (console_subchannel.schib.pmcw.st != SUBCHANNEL_TYPE_IO) || !console_subchannel.schib.pmcw.dnv) return -1; console_devno = console_subchannel.schib.pmcw.dev; } else if (console_devno != -1) { /* At least the console device number is known. */ for_each_subchannel(cio_test_for_console, NULL); if (console_irq == -1) return -1; } else { /* unlike in 2.4, we cannot autoprobe here, since * the channel subsystem is not fully initialized. * With some luck, the HWC console can take over */ return -1; } return console_irq; } struct subchannel * cio_probe_console(void) { int sch_no, ret; struct subchannel_id schid; if (xchg(&console_subchannel_in_use, 1) != 0) return ERR_PTR(-EBUSY); sch_no = cio_get_console_sch_no(); if (sch_no == -1) { console_subchannel_in_use = 0; pr_warning("No CCW console was found\n"); return ERR_PTR(-ENODEV); } memset(&console_subchannel, 0, sizeof(struct subchannel)); init_subchannel_id(&schid); schid.sch_no = sch_no; ret = cio_validate_subchannel(&console_subchannel, schid); if (ret) { console_subchannel_in_use = 0; return ERR_PTR(-ENODEV); } /* * enable console I/O-interrupt subclass */ isc_register(CONSOLE_ISC); console_subchannel.config.isc = CONSOLE_ISC; console_subchannel.config.intparm = (u32)(addr_t)&console_subchannel; ret = cio_commit_config(&console_subchannel); if (ret) { isc_unregister(CONSOLE_ISC); console_subchannel_in_use = 0; return ERR_PTR(ret); } return &console_subchannel; } void cio_release_console(void) { console_subchannel.config.intparm = 0; cio_commit_config(&console_subchannel); isc_unregister(CONSOLE_ISC); console_subchannel_in_use = 0; } /* Bah... hack to catch console special sausages. */ int cio_is_console(struct subchannel_id schid) { if (!console_subchannel_in_use) return 0; return schid_equal(&schid, &console_subchannel.schid); } struct subchannel * cio_get_console_subchannel(void) { if (!console_subchannel_in_use) return NULL; return &console_subchannel; } #endif static int __disable_subchannel_easy(struct subchannel_id schid, struct schib *schib) { int retry, cc; cc = 0; for (retry=0;retry<3;retry++) { schib->pmcw.ena = 0; cc = msch_err(schid, schib); if (cc) return (cc==3?-ENODEV:-EBUSY); if (stsch_err(schid, schib) || !css_sch_is_valid(schib)) return -ENODEV; if (!schib->pmcw.ena) return 0; } return -EBUSY; /* uhm... */ } static int __clear_io_subchannel_easy(struct subchannel_id schid) { int retry; if (csch(schid)) return -ENODEV; for (retry=0;retry<20;retry++) { struct tpi_info ti; if (tpi(&ti)) { tsch(ti.schid, (struct irb *)&S390_lowcore.irb); if (schid_equal(&ti.schid, &schid)) return 0; } udelay_simple(100); } return -EBUSY; } static void __clear_chsc_subchannel_easy(void) { /* It seems we can only wait for a bit here :/ */ udelay_simple(100); } static int pgm_check_occured; static void cio_reset_pgm_check_handler(void) { pgm_check_occured = 1; } static int stsch_reset(struct subchannel_id schid, struct schib *addr) { int rc; pgm_check_occured = 0; s390_base_pgm_handler_fn = cio_reset_pgm_check_handler; rc = stsch_err(schid, addr); s390_base_pgm_handler_fn = NULL; /* The program check handler could have changed pgm_check_occured. */ barrier(); if (pgm_check_occured) return -EIO; else return rc; } static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data) { struct schib schib; if (stsch_reset(schid, &schib)) return -ENXIO; if (!schib.pmcw.ena) return 0; switch(__disable_subchannel_easy(schid, &schib)) { case 0: case -ENODEV: break; default: /* -EBUSY */ switch (schib.pmcw.st) { case SUBCHANNEL_TYPE_IO: if (__clear_io_subchannel_easy(schid)) goto out; /* give up... */ break; case SUBCHANNEL_TYPE_CHSC: __clear_chsc_subchannel_easy(); break; default: /* No default clear strategy */ break; } stsch_err(schid, &schib); __disable_subchannel_easy(schid, &schib); } out: return 0; } static atomic_t chpid_reset_count; static void s390_reset_chpids_mcck_handler(void) { struct crw crw; struct mci *mci; /* Check for pending channel report word. */ mci = (struct mci *)&S390_lowcore.mcck_interruption_code; if (!mci->cp) return; /* Process channel report words. */ while (stcrw(&crw) == 0) { /* Check for responses to RCHP. */ if (crw.slct && crw.rsc == CRW_RSC_CPATH) atomic_dec(&chpid_reset_count); } } #define RCHP_TIMEOUT (30 * USEC_PER_SEC) static void css_reset(void) { int i, ret; unsigned long long timeout; struct chp_id chpid; /* Reset subchannels. */ for_each_subchannel(__shutdown_subchannel_easy, NULL); /* Reset channel paths. */ s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler; /* Enable channel report machine checks. */ __ctl_set_bit(14, 28); /* Temporarily reenable machine checks. */ local_mcck_enable(); chp_id_init(&chpid); for (i = 0; i <= __MAX_CHPID; i++) { chpid.id = i; ret = rchp(chpid); if ((ret == 0) || (ret == 2)) /* * rchp either succeeded, or another rchp is already * in progress. In either case, we'll get a crw. */ atomic_inc(&chpid_reset_count); } /* Wait for machine check for all channel paths. */ timeout = get_clock() + (RCHP_TIMEOUT << 12); while (atomic_read(&chpid_reset_count) != 0) { if (get_clock() > timeout) break; cpu_relax(); } /* Disable machine checks again. */ local_mcck_disable(); /* Disable channel report machine checks. */ __ctl_clear_bit(14, 28); s390_base_mcck_handler_fn = NULL; } static struct reset_call css_reset_call = { .fn = css_reset, }; static int __init init_css_reset_call(void) { atomic_set(&chpid_reset_count, 0); register_reset_call(&css_reset_call); return 0; } arch_initcall(init_css_reset_call); struct sch_match_id { struct subchannel_id schid; struct ccw_dev_id devid; int rc; }; static int __reipl_subchannel_match(struct subchannel_id schid, void *data) { struct schib schib; struct sch_match_id *match_id = data; if (stsch_reset(schid, &schib)) return -ENXIO; if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv && (schib.pmcw.dev == match_id->devid.devno) && (schid.ssid == match_id->devid.ssid)) { match_id->schid = schid; match_id->rc = 0; return 1; } return 0; } static int reipl_find_schid(struct ccw_dev_id *devid, struct subchannel_id *schid) { struct sch_match_id match_id; match_id.devid = *devid; match_id.rc = -ENODEV; for_each_subchannel(__reipl_subchannel_match, &match_id); if (match_id.rc == 0) *schid = match_id.schid; return match_id.rc; } extern void do_reipl_asm(__u32 schid); /* Make sure all subchannels are quiet before we re-ipl an lpar. */ void reipl_ccw_dev(struct ccw_dev_id *devid) { struct subchannel_id schid; s390_reset_system(NULL, NULL); if (reipl_find_schid(devid, &schid) != 0) panic("IPL Device not found\n"); do_reipl_asm(*((__u32*)&schid)); } int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo) { struct subchannel_id schid; struct schib schib; schid = *(struct subchannel_id *)&S390_lowcore.subchannel_id; if (!schid.one) return -ENODEV; if (stsch_err(schid, &schib)) return -ENODEV; if (schib.pmcw.st != SUBCHANNEL_TYPE_IO) return -ENODEV; if (!schib.pmcw.dnv) return -ENODEV; iplinfo->devno = schib.pmcw.dev; iplinfo->is_qdio = schib.pmcw.qf; return 0; } /** * cio_tm_start_key - perform start function * @sch: subchannel on which to perform the start function * @tcw: transport-command word to be started * @lpm: mask of paths to use * @key: storage key to use for storage access * * Start the tcw on the given subchannel. Return zero on success, non-zero * otherwise. */ int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key) { int cc; union orb *orb = &to_io_private(sch)->orb; memset(orb, 0, sizeof(union orb)); orb->tm.intparm = (u32) (addr_t) sch; orb->tm.key = key >> 4; orb->tm.b = 1; orb->tm.lpm = lpm ? lpm : sch->lpm; orb->tm.tcw = (u32) (addr_t) tcw; cc = ssch(sch->schid, orb); switch (cc) { case 0: return 0; case 1: case 2: return -EBUSY; default: return cio_start_handle_notoper(sch, lpm); } } /** * cio_tm_intrg - perform interrogate function * @sch - subchannel on which to perform the interrogate function * * If the specified subchannel is running in transport-mode, perform the * interrogate function. Return zero on success, non-zero otherwie. */ int cio_tm_intrg(struct subchannel *sch) { int cc; if (!to_io_private(sch)->orb.tm.b) return -EINVAL; cc = xsch(sch->schid); switch (cc) { case 0: case 2: return 0; case 1: return -EBUSY; default: return -ENODEV; } }
gpl-2.0
TeamWin/android_kernel_samsung_j2lte
arch/x86/xen/grant-table.c
7360
4010
/****************************************************************************** * grant_table.c * x86 specific part * * Granting foreign access to our memory reservation. * * Copyright (c) 2005-2006, Christopher Clark * Copyright (c) 2004-2005, K A Fraser * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp> * VA Linux Systems Japan. Split out x86 specific part. * * 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/sched.h> #include <linux/mm.h> #include <linux/vmalloc.h> #include <xen/interface/xen.h> #include <xen/page.h> #include <xen/grant_table.h> #include <asm/pgtable.h> static int map_pte_fn(pte_t *pte, struct page *pmd_page, unsigned long addr, void *data) { unsigned long **frames = (unsigned long **)data; set_pte_at(&init_mm, addr, pte, mfn_pte((*frames)[0], PAGE_KERNEL)); (*frames)++; return 0; } /* * This function is used to map shared frames to store grant status. It is * different from map_pte_fn above, the frames type here is uint64_t. */ static int map_pte_fn_status(pte_t *pte, struct page *pmd_page, unsigned long addr, void *data) { uint64_t **frames = (uint64_t **)data; set_pte_at(&init_mm, addr, pte, mfn_pte((*frames)[0], PAGE_KERNEL)); (*frames)++; return 0; } static int unmap_pte_fn(pte_t *pte, struct page *pmd_page, unsigned long addr, void *data) { set_pte_at(&init_mm, addr, pte, __pte(0)); return 0; } int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes, unsigned long max_nr_gframes, void **__shared) { int rc; void *shared = *__shared; if (shared == NULL) { struct vm_struct *area = alloc_vm_area(PAGE_SIZE * max_nr_gframes, NULL); BUG_ON(area == NULL); shared = area->addr; *__shared = shared; } rc = apply_to_page_range(&init_mm, (unsigned long)shared, PAGE_SIZE * nr_gframes, map_pte_fn, &frames); return rc; } int arch_gnttab_map_status(uint64_t *frames, unsigned long nr_gframes, unsigned long max_nr_gframes, grant_status_t **__shared) { int rc; grant_status_t *shared = *__shared; if (shared == NULL) { /* No need to pass in PTE as we are going to do it * in apply_to_page_range anyhow. */ struct vm_struct *area = alloc_vm_area(PAGE_SIZE * max_nr_gframes, NULL); BUG_ON(area == NULL); shared = area->addr; *__shared = shared; } rc = apply_to_page_range(&init_mm, (unsigned long)shared, PAGE_SIZE * nr_gframes, map_pte_fn_status, &frames); return rc; } void arch_gnttab_unmap(void *shared, unsigned long nr_gframes) { apply_to_page_range(&init_mm, (unsigned long)shared, PAGE_SIZE * nr_gframes, unmap_pte_fn, NULL); }
gpl-2.0
sirmordred/samsung-kernel-msm7x30-2
arch/ia64/oprofile/backtrace.c
9408
3836
/** * @file backtrace.c * * @remark Copyright 2004 Silicon Graphics Inc. All Rights Reserved. * @remark Read the file COPYING * * @author Greg Banks <gnb@melbourne.sgi.com> * @author Keith Owens <kaos@melbourne.sgi.com> * Based on work done for the ia64 port of the SGI kernprof patch, which is * Copyright (c) 2003-2004 Silicon Graphics Inc. All Rights Reserved. */ #include <linux/oprofile.h> #include <linux/sched.h> #include <linux/mm.h> #include <asm/ptrace.h> /* * For IA64 we need to perform a complex little dance to get both * the struct pt_regs and a synthetic struct switch_stack in place * to allow the unwind code to work. This dance requires our unwind * using code to be called from a function called from unw_init_running(). * There we only get a single void* data pointer, so use this struct * to hold all the data we need during the unwind. */ typedef struct { unsigned int depth; struct pt_regs *regs; struct unw_frame_info frame; unsigned long *prev_pfs_loc; /* state for WAR for old spinlock ool code */ } ia64_backtrace_t; /* Returns non-zero if the PC is in the Interrupt Vector Table */ static __inline__ int in_ivt_code(unsigned long pc) { extern char ia64_ivt[]; return (pc >= (u_long)ia64_ivt && pc < (u_long)ia64_ivt+32768); } /* * Unwind to next stack frame. */ static __inline__ int next_frame(ia64_backtrace_t *bt) { /* * Avoid unsightly console message from unw_unwind() when attempting * to unwind through the Interrupt Vector Table which has no unwind * information. */ if (in_ivt_code(bt->frame.ip)) return 0; /* * WAR for spinlock contention from leaf functions. ia64_spinlock_contention_pre3_4 * has ar.pfs == r0. Leaf functions do not modify ar.pfs so ar.pfs remains * as 0, stopping the backtrace. Record the previous ar.pfs when the current * IP is in ia64_spinlock_contention_pre3_4 then unwind, if pfs_loc has not changed * after unwind then use pt_regs.ar_pfs which is where the real ar.pfs is for * leaf functions. */ if (bt->prev_pfs_loc && bt->regs && bt->frame.pfs_loc == bt->prev_pfs_loc) bt->frame.pfs_loc = &bt->regs->ar_pfs; bt->prev_pfs_loc = NULL; return unw_unwind(&bt->frame) == 0; } static void do_ia64_backtrace(struct unw_frame_info *info, void *vdata) { ia64_backtrace_t *bt = vdata; struct switch_stack *sw; int count = 0; u_long pc, sp; sw = (struct switch_stack *)(info+1); /* padding from unw_init_running */ sw = (struct switch_stack *)(((unsigned long)sw + 15) & ~15); unw_init_frame_info(&bt->frame, current, sw); /* skip over interrupt frame and oprofile calls */ do { unw_get_sp(&bt->frame, &sp); if (sp >= (u_long)bt->regs) break; if (!next_frame(bt)) return; } while (count++ < 200); /* finally, grab the actual sample */ while (bt->depth-- && next_frame(bt)) { unw_get_ip(&bt->frame, &pc); oprofile_add_trace(pc); if (unw_is_intr_frame(&bt->frame)) { /* * Interrupt received on kernel stack; this can * happen when timer interrupt fires while processing * a softirq from the tail end of a hardware interrupt * which interrupted a system call. Don't laugh, it * happens! Splice the backtrace into two parts to * avoid spurious cycles in the gprof output. */ /* TODO: split rather than drop the 2nd half */ break; } } } void ia64_backtrace(struct pt_regs * const regs, unsigned int depth) { ia64_backtrace_t bt; unsigned long flags; /* * On IA64 there is little hope of getting backtraces from * user space programs -- the problems of getting the unwind * information from arbitrary user programs are extreme. */ if (user_mode(regs)) return; bt.depth = depth; bt.regs = regs; bt.prev_pfs_loc = NULL; local_irq_save(flags); unw_init_running(do_ia64_backtrace, &bt); local_irq_restore(flags); }
gpl-2.0
visi0nary/mt6735-kernel-3.10.61
fs/xfs/xfs_mru_cache.c
10944
18203
/* * Copyright (c) 2006-2007 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_mru_cache.h" /* * The MRU Cache data structure consists of a data store, an array of lists and * a lock to protect its internal state. At initialisation time, the client * supplies an element lifetime in milliseconds and a group count, as well as a * function pointer to call when deleting elements. A data structure for * queueing up work in the form of timed callbacks is also included. * * The group count controls how many lists are created, and thereby how finely * the elements are grouped in time. When reaping occurs, all the elements in * all the lists whose time has expired are deleted. * * To give an example of how this works in practice, consider a client that * initialises an MRU Cache with a lifetime of ten seconds and a group count of * five. Five internal lists will be created, each representing a two second * period in time. When the first element is added, time zero for the data * structure is initialised to the current time. * * All the elements added in the first two seconds are appended to the first * list. Elements added in the third second go into the second list, and so on. * If an element is accessed at any point, it is removed from its list and * inserted at the head of the current most-recently-used list. * * The reaper function will have nothing to do until at least twelve seconds * have elapsed since the first element was added. The reason for this is that * if it were called at t=11s, there could be elements in the first list that * have only been inactive for nine seconds, so it still does nothing. If it is * called anywhere between t=12 and t=14 seconds, it will delete all the * elements that remain in the first list. It's therefore possible for elements * to remain in the data store even after they've been inactive for up to * (t + t/g) seconds, where t is the inactive element lifetime and g is the * number of groups. * * The above example assumes that the reaper function gets called at least once * every (t/g) seconds. If it is called less frequently, unused elements will * accumulate in the reap list until the reaper function is eventually called. * The current implementation uses work queue callbacks to carefully time the * reaper function calls, so this should happen rarely, if at all. * * From a design perspective, the primary reason for the choice of a list array * representing discrete time intervals is that it's only practical to reap * expired elements in groups of some appreciable size. This automatically * introduces a granularity to element lifetimes, so there's no point storing an * individual timeout with each element that specifies a more precise reap time. * The bonus is a saving of sizeof(long) bytes of memory per element stored. * * The elements could have been stored in just one list, but an array of * counters or pointers would need to be maintained to allow them to be divided * up into discrete time groups. More critically, the process of touching or * removing an element would involve walking large portions of the entire list, * which would have a detrimental effect on performance. The additional memory * requirement for the array of list heads is minimal. * * When an element is touched or deleted, it needs to be removed from its * current list. Doubly linked lists are used to make the list maintenance * portion of these operations O(1). Since reaper timing can be imprecise, * inserts and lookups can occur when there are no free lists available. When * this happens, all the elements on the LRU list need to be migrated to the end * of the reap list. To keep the list maintenance portion of these operations * O(1) also, list tails need to be accessible without walking the entire list. * This is the reason why doubly linked list heads are used. */ /* * An MRU Cache is a dynamic data structure that stores its elements in a way * that allows efficient lookups, but also groups them into discrete time * intervals based on insertion time. This allows elements to be efficiently * and automatically reaped after a fixed period of inactivity. * * When a client data pointer is stored in the MRU Cache it needs to be added to * both the data store and to one of the lists. It must also be possible to * access each of these entries via the other, i.e. to: * * a) Walk a list, removing the corresponding data store entry for each item. * b) Look up a data store entry, then access its list entry directly. * * To achieve both of these goals, each entry must contain both a list entry and * a key, in addition to the user's data pointer. Note that it's not a good * idea to have the client embed one of these structures at the top of their own * data structure, because inserting the same item more than once would most * likely result in a loop in one of the lists. That's a sure-fire recipe for * an infinite loop in the code. */ typedef struct xfs_mru_cache_elem { struct list_head list_node; unsigned long key; void *value; } xfs_mru_cache_elem_t; static kmem_zone_t *xfs_mru_elem_zone; static struct workqueue_struct *xfs_mru_reap_wq; /* * When inserting, destroying or reaping, it's first necessary to update the * lists relative to a particular time. In the case of destroying, that time * will be well in the future to ensure that all items are moved to the reap * list. In all other cases though, the time will be the current time. * * This function enters a loop, moving the contents of the LRU list to the reap * list again and again until either a) the lists are all empty, or b) time zero * has been advanced sufficiently to be within the immediate element lifetime. * * Case a) above is detected by counting how many groups are migrated and * stopping when they've all been moved. Case b) is detected by monitoring the * time_zero field, which is updated as each group is migrated. * * The return value is the earliest time that more migration could be needed, or * zero if there's no need to schedule more work because the lists are empty. */ STATIC unsigned long _xfs_mru_cache_migrate( xfs_mru_cache_t *mru, unsigned long now) { unsigned int grp; unsigned int migrated = 0; struct list_head *lru_list; /* Nothing to do if the data store is empty. */ if (!mru->time_zero) return 0; /* While time zero is older than the time spanned by all the lists. */ while (mru->time_zero <= now - mru->grp_count * mru->grp_time) { /* * If the LRU list isn't empty, migrate its elements to the tail * of the reap list. */ lru_list = mru->lists + mru->lru_grp; if (!list_empty(lru_list)) list_splice_init(lru_list, mru->reap_list.prev); /* * Advance the LRU group number, freeing the old LRU list to * become the new MRU list; advance time zero accordingly. */ mru->lru_grp = (mru->lru_grp + 1) % mru->grp_count; mru->time_zero += mru->grp_time; /* * If reaping is so far behind that all the elements on all the * lists have been migrated to the reap list, it's now empty. */ if (++migrated == mru->grp_count) { mru->lru_grp = 0; mru->time_zero = 0; return 0; } } /* Find the first non-empty list from the LRU end. */ for (grp = 0; grp < mru->grp_count; grp++) { /* Check the grp'th list from the LRU end. */ lru_list = mru->lists + ((mru->lru_grp + grp) % mru->grp_count); if (!list_empty(lru_list)) return mru->time_zero + (mru->grp_count + grp) * mru->grp_time; } /* All the lists must be empty. */ mru->lru_grp = 0; mru->time_zero = 0; return 0; } /* * When inserting or doing a lookup, an element needs to be inserted into the * MRU list. The lists must be migrated first to ensure that they're * up-to-date, otherwise the new element could be given a shorter lifetime in * the cache than it should. */ STATIC void _xfs_mru_cache_list_insert( xfs_mru_cache_t *mru, xfs_mru_cache_elem_t *elem) { unsigned int grp = 0; unsigned long now = jiffies; /* * If the data store is empty, initialise time zero, leave grp set to * zero and start the work queue timer if necessary. Otherwise, set grp * to the number of group times that have elapsed since time zero. */ if (!_xfs_mru_cache_migrate(mru, now)) { mru->time_zero = now; if (!mru->queued) { mru->queued = 1; queue_delayed_work(xfs_mru_reap_wq, &mru->work, mru->grp_count * mru->grp_time); } } else { grp = (now - mru->time_zero) / mru->grp_time; grp = (mru->lru_grp + grp) % mru->grp_count; } /* Insert the element at the tail of the corresponding list. */ list_add_tail(&elem->list_node, mru->lists + grp); } /* * When destroying or reaping, all the elements that were migrated to the reap * list need to be deleted. For each element this involves removing it from the * data store, removing it from the reap list, calling the client's free * function and deleting the element from the element zone. * * We get called holding the mru->lock, which we drop and then reacquire. * Sparse need special help with this to tell it we know what we are doing. */ STATIC void _xfs_mru_cache_clear_reap_list( xfs_mru_cache_t *mru) __releases(mru->lock) __acquires(mru->lock) { xfs_mru_cache_elem_t *elem, *next; struct list_head tmp; INIT_LIST_HEAD(&tmp); list_for_each_entry_safe(elem, next, &mru->reap_list, list_node) { /* Remove the element from the data store. */ radix_tree_delete(&mru->store, elem->key); /* * remove to temp list so it can be freed without * needing to hold the lock */ list_move(&elem->list_node, &tmp); } spin_unlock(&mru->lock); list_for_each_entry_safe(elem, next, &tmp, list_node) { /* Remove the element from the reap list. */ list_del_init(&elem->list_node); /* Call the client's free function with the key and value pointer. */ mru->free_func(elem->key, elem->value); /* Free the element structure. */ kmem_zone_free(xfs_mru_elem_zone, elem); } spin_lock(&mru->lock); } /* * We fire the reap timer every group expiry interval so * we always have a reaper ready to run. This makes shutdown * and flushing of the reaper easy to do. Hence we need to * keep when the next reap must occur so we can determine * at each interval whether there is anything we need to do. */ STATIC void _xfs_mru_cache_reap( struct work_struct *work) { xfs_mru_cache_t *mru = container_of(work, xfs_mru_cache_t, work.work); unsigned long now, next; ASSERT(mru && mru->lists); if (!mru || !mru->lists) return; spin_lock(&mru->lock); next = _xfs_mru_cache_migrate(mru, jiffies); _xfs_mru_cache_clear_reap_list(mru); mru->queued = next; if ((mru->queued > 0)) { now = jiffies; if (next <= now) next = 0; else next -= now; queue_delayed_work(xfs_mru_reap_wq, &mru->work, next); } spin_unlock(&mru->lock); } int xfs_mru_cache_init(void) { xfs_mru_elem_zone = kmem_zone_init(sizeof(xfs_mru_cache_elem_t), "xfs_mru_cache_elem"); if (!xfs_mru_elem_zone) goto out; xfs_mru_reap_wq = alloc_workqueue("xfs_mru_cache", WQ_MEM_RECLAIM, 1); if (!xfs_mru_reap_wq) goto out_destroy_mru_elem_zone; return 0; out_destroy_mru_elem_zone: kmem_zone_destroy(xfs_mru_elem_zone); out: return -ENOMEM; } void xfs_mru_cache_uninit(void) { destroy_workqueue(xfs_mru_reap_wq); kmem_zone_destroy(xfs_mru_elem_zone); } /* * To initialise a struct xfs_mru_cache pointer, call xfs_mru_cache_create() * with the address of the pointer, a lifetime value in milliseconds, a group * count and a free function to use when deleting elements. This function * returns 0 if the initialisation was successful. */ int xfs_mru_cache_create( xfs_mru_cache_t **mrup, unsigned int lifetime_ms, unsigned int grp_count, xfs_mru_cache_free_func_t free_func) { xfs_mru_cache_t *mru = NULL; int err = 0, grp; unsigned int grp_time; if (mrup) *mrup = NULL; if (!mrup || !grp_count || !lifetime_ms || !free_func) return EINVAL; if (!(grp_time = msecs_to_jiffies(lifetime_ms) / grp_count)) return EINVAL; if (!(mru = kmem_zalloc(sizeof(*mru), KM_SLEEP))) return ENOMEM; /* An extra list is needed to avoid reaping up to a grp_time early. */ mru->grp_count = grp_count + 1; mru->lists = kmem_zalloc(mru->grp_count * sizeof(*mru->lists), KM_SLEEP); if (!mru->lists) { err = ENOMEM; goto exit; } for (grp = 0; grp < mru->grp_count; grp++) INIT_LIST_HEAD(mru->lists + grp); /* * We use GFP_KERNEL radix tree preload and do inserts under a * spinlock so GFP_ATOMIC is appropriate for the radix tree itself. */ INIT_RADIX_TREE(&mru->store, GFP_ATOMIC); INIT_LIST_HEAD(&mru->reap_list); spin_lock_init(&mru->lock); INIT_DELAYED_WORK(&mru->work, _xfs_mru_cache_reap); mru->grp_time = grp_time; mru->free_func = free_func; *mrup = mru; exit: if (err && mru && mru->lists) kmem_free(mru->lists); if (err && mru) kmem_free(mru); return err; } /* * Call xfs_mru_cache_flush() to flush out all cached entries, calling their * free functions as they're deleted. When this function returns, the caller is * guaranteed that all the free functions for all the elements have finished * executing and the reaper is not running. */ static void xfs_mru_cache_flush( xfs_mru_cache_t *mru) { if (!mru || !mru->lists) return; spin_lock(&mru->lock); if (mru->queued) { spin_unlock(&mru->lock); cancel_delayed_work_sync(&mru->work); spin_lock(&mru->lock); } _xfs_mru_cache_migrate(mru, jiffies + mru->grp_count * mru->grp_time); _xfs_mru_cache_clear_reap_list(mru); spin_unlock(&mru->lock); } void xfs_mru_cache_destroy( xfs_mru_cache_t *mru) { if (!mru || !mru->lists) return; xfs_mru_cache_flush(mru); kmem_free(mru->lists); kmem_free(mru); } /* * To insert an element, call xfs_mru_cache_insert() with the data store, the * element's key and the client data pointer. This function returns 0 on * success or ENOMEM if memory for the data element couldn't be allocated. */ int xfs_mru_cache_insert( xfs_mru_cache_t *mru, unsigned long key, void *value) { xfs_mru_cache_elem_t *elem; ASSERT(mru && mru->lists); if (!mru || !mru->lists) return EINVAL; elem = kmem_zone_zalloc(xfs_mru_elem_zone, KM_SLEEP); if (!elem) return ENOMEM; if (radix_tree_preload(GFP_KERNEL)) { kmem_zone_free(xfs_mru_elem_zone, elem); return ENOMEM; } INIT_LIST_HEAD(&elem->list_node); elem->key = key; elem->value = value; spin_lock(&mru->lock); radix_tree_insert(&mru->store, key, elem); radix_tree_preload_end(); _xfs_mru_cache_list_insert(mru, elem); spin_unlock(&mru->lock); return 0; } /* * To remove an element without calling the free function, call * xfs_mru_cache_remove() with the data store and the element's key. On success * the client data pointer for the removed element is returned, otherwise this * function will return a NULL pointer. */ void * xfs_mru_cache_remove( xfs_mru_cache_t *mru, unsigned long key) { xfs_mru_cache_elem_t *elem; void *value = NULL; ASSERT(mru && mru->lists); if (!mru || !mru->lists) return NULL; spin_lock(&mru->lock); elem = radix_tree_delete(&mru->store, key); if (elem) { value = elem->value; list_del(&elem->list_node); } spin_unlock(&mru->lock); if (elem) kmem_zone_free(xfs_mru_elem_zone, elem); return value; } /* * To remove and element and call the free function, call xfs_mru_cache_delete() * with the data store and the element's key. */ void xfs_mru_cache_delete( xfs_mru_cache_t *mru, unsigned long key) { void *value = xfs_mru_cache_remove(mru, key); if (value) mru->free_func(key, value); } /* * To look up an element using its key, call xfs_mru_cache_lookup() with the * data store and the element's key. If found, the element will be moved to the * head of the MRU list to indicate that it's been touched. * * The internal data structures are protected by a spinlock that is STILL HELD * when this function returns. Call xfs_mru_cache_done() to release it. Note * that it is not safe to call any function that might sleep in the interim. * * The implementation could have used reference counting to avoid this * restriction, but since most clients simply want to get, set or test a member * of the returned data structure, the extra per-element memory isn't warranted. * * If the element isn't found, this function returns NULL and the spinlock is * released. xfs_mru_cache_done() should NOT be called when this occurs. * * Because sparse isn't smart enough to know about conditional lock return * status, we need to help it get it right by annotating the path that does * not release the lock. */ void * xfs_mru_cache_lookup( xfs_mru_cache_t *mru, unsigned long key) { xfs_mru_cache_elem_t *elem; ASSERT(mru && mru->lists); if (!mru || !mru->lists) return NULL; spin_lock(&mru->lock); elem = radix_tree_lookup(&mru->store, key); if (elem) { list_del(&elem->list_node); _xfs_mru_cache_list_insert(mru, elem); __release(mru_lock); /* help sparse not be stupid */ } else spin_unlock(&mru->lock); return elem ? elem->value : NULL; } /* * To release the internal data structure spinlock after having performed an * xfs_mru_cache_lookup() or an xfs_mru_cache_peek(), call xfs_mru_cache_done() * with the data store pointer. */ void xfs_mru_cache_done( xfs_mru_cache_t *mru) __releases(mru->lock) { spin_unlock(&mru->lock); }
gpl-2.0
DJSteve/kernel_dell_streak7
mm/kmemcheck.c
12736
2910
#include <linux/gfp.h> #include <linux/mm_types.h> #include <linux/mm.h> #include <linux/slab.h> #include <linux/kmemcheck.h> void kmemcheck_alloc_shadow(struct page *page, int order, gfp_t flags, int node) { struct page *shadow; int pages; int i; pages = 1 << order; /* * With kmemcheck enabled, we need to allocate a memory area for the * shadow bits as well. */ shadow = alloc_pages_node(node, flags | __GFP_NOTRACK, order); if (!shadow) { if (printk_ratelimit()) printk(KERN_ERR "kmemcheck: failed to allocate " "shadow bitmap\n"); return; } for(i = 0; i < pages; ++i) page[i].shadow = page_address(&shadow[i]); /* * Mark it as non-present for the MMU so that our accesses to * this memory will trigger a page fault and let us analyze * the memory accesses. */ kmemcheck_hide_pages(page, pages); } void kmemcheck_free_shadow(struct page *page, int order) { struct page *shadow; int pages; int i; if (!kmemcheck_page_is_tracked(page)) return; pages = 1 << order; kmemcheck_show_pages(page, pages); shadow = virt_to_page(page[0].shadow); for(i = 0; i < pages; ++i) page[i].shadow = NULL; __free_pages(shadow, order); } void kmemcheck_slab_alloc(struct kmem_cache *s, gfp_t gfpflags, void *object, size_t size) { /* * Has already been memset(), which initializes the shadow for us * as well. */ if (gfpflags & __GFP_ZERO) return; /* No need to initialize the shadow of a non-tracked slab. */ if (s->flags & SLAB_NOTRACK) return; if (!kmemcheck_enabled || gfpflags & __GFP_NOTRACK) { /* * Allow notracked objects to be allocated from * tracked caches. Note however that these objects * will still get page faults on access, they just * won't ever be flagged as uninitialized. If page * faults are not acceptable, the slab cache itself * should be marked NOTRACK. */ kmemcheck_mark_initialized(object, size); } else if (!s->ctor) { /* * New objects should be marked uninitialized before * they're returned to the called. */ kmemcheck_mark_uninitialized(object, size); } } void kmemcheck_slab_free(struct kmem_cache *s, void *object, size_t size) { /* TODO: RCU freeing is unsupported for now; hide false positives. */ if (!s->ctor && !(s->flags & SLAB_DESTROY_BY_RCU)) kmemcheck_mark_freed(object, size); } void kmemcheck_pagealloc_alloc(struct page *page, unsigned int order, gfp_t gfpflags) { int pages; if (gfpflags & (__GFP_HIGHMEM | __GFP_NOTRACK)) return; pages = 1 << order; /* * NOTE: We choose to track GFP_ZERO pages too; in fact, they * can become uninitialized by copying uninitialized memory * into them. */ /* XXX: Can use zone->node for node? */ kmemcheck_alloc_shadow(page, order, gfpflags, -1); if (gfpflags & __GFP_ZERO) kmemcheck_mark_initialized_pages(page, pages); else kmemcheck_mark_uninitialized_pages(page, pages); }
gpl-2.0
Fagulhas/android_kernel_huawei_u8815
crypto/cipher.c
12992
3391
/* * Cryptographic API. * * Cipher operations. * * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> * Copyright (c) 2005 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 <linux/kernel.h> #include <linux/crypto.h> #include <linux/errno.h> #include <linux/slab.h> #include <linux/string.h> #include "internal.h" static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher; unsigned long alignmask = crypto_tfm_alg_alignmask(tfm); int ret; u8 *buffer, *alignbuffer; unsigned long absize; absize = keylen + alignmask; buffer = kmalloc(absize, GFP_ATOMIC); if (!buffer) return -ENOMEM; alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1); memcpy(alignbuffer, key, keylen); ret = cia->cia_setkey(tfm, alignbuffer, keylen); memset(alignbuffer, 0, keylen); kfree(buffer); return ret; } static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher; unsigned long alignmask = crypto_tfm_alg_alignmask(tfm); tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK; if (keylen < cia->cia_min_keysize || keylen > cia->cia_max_keysize) { tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; return -EINVAL; } if ((unsigned long)key & alignmask) return setkey_unaligned(tfm, key, keylen); return cia->cia_setkey(tfm, key, keylen); } static void cipher_crypt_unaligned(void (*fn)(struct crypto_tfm *, u8 *, const u8 *), struct crypto_tfm *tfm, u8 *dst, const u8 *src) { unsigned long alignmask = crypto_tfm_alg_alignmask(tfm); unsigned int size = crypto_tfm_alg_blocksize(tfm); u8 buffer[size + alignmask]; u8 *tmp = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1); memcpy(tmp, src, size); fn(tfm, tmp, tmp); memcpy(dst, tmp, size); } static void cipher_encrypt_unaligned(struct crypto_tfm *tfm, u8 *dst, const u8 *src) { unsigned long alignmask = crypto_tfm_alg_alignmask(tfm); struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher; if (unlikely(((unsigned long)dst | (unsigned long)src) & alignmask)) { cipher_crypt_unaligned(cipher->cia_encrypt, tfm, dst, src); return; } cipher->cia_encrypt(tfm, dst, src); } static void cipher_decrypt_unaligned(struct crypto_tfm *tfm, u8 *dst, const u8 *src) { unsigned long alignmask = crypto_tfm_alg_alignmask(tfm); struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher; if (unlikely(((unsigned long)dst | (unsigned long)src) & alignmask)) { cipher_crypt_unaligned(cipher->cia_decrypt, tfm, dst, src); return; } cipher->cia_decrypt(tfm, dst, src); } int crypto_init_cipher_ops(struct crypto_tfm *tfm) { struct cipher_tfm *ops = &tfm->crt_cipher; struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher; ops->cit_setkey = setkey; ops->cit_encrypt_one = crypto_tfm_alg_alignmask(tfm) ? cipher_encrypt_unaligned : cipher->cia_encrypt; ops->cit_decrypt_one = crypto_tfm_alg_alignmask(tfm) ? cipher_decrypt_unaligned : cipher->cia_decrypt; return 0; } void crypto_exit_cipher_ops(struct crypto_tfm *tfm) { }
gpl-2.0
csimmonds/rowboat-kernel
drivers/watchdog/wdt_pci.c
193
19325
/* * Industrial Computer Source PCI-WDT500/501 driver * * (c) Copyright 1996-1997 Alan Cox <alan@lxorguk.ukuu.org.uk>, * 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; either version * 2 of the License, or (at your option) any later version. * * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide * warranty for any of this software. This material is provided * "AS-IS" and at no charge. * * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk> * * Release 0.10. * * Fixes * Dave Gregorich : Modularisation and minor bugs * Alan Cox : Added the watchdog ioctl() stuff * Alan Cox : Fixed the reboot problem (as noted by * Matt Crocker). * Alan Cox : Added wdt= boot option * Alan Cox : Cleaned up copy/user stuff * Tim Hockin : Added insmod parameters, comment cleanup * Parameterized timeout * JP Nollmann : Added support for PCI wdt501p * Alan Cox : Split ISA and PCI cards into two drivers * Jeff Garzik : PCI cleanups * Tigran Aivazian : Restructured wdtpci_init_one() to handle * failures * Joel Becker : Added WDIOC_GET/SETTIMEOUT * Zwane Mwaikambo : Magic char closing, locking changes, * cleanups * Matt Domsch : nowayout module option */ #include <linux/interrupt.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/types.h> #include <linux/miscdevice.h> #include <linux/watchdog.h> #include <linux/ioport.h> #include <linux/delay.h> #include <linux/notifier.h> #include <linux/reboot.h> #include <linux/init.h> #include <linux/fs.h> #include <linux/pci.h> #include <linux/io.h> #include <linux/uaccess.h> #include <asm/system.h> #define WDT_IS_PCI #include "wd501p.h" #define PFX "wdt_pci: " /* * Until Access I/O gets their application for a PCI vendor ID approved, * I don't think that it's appropriate to move these constants into the * regular pci_ids.h file. -- JPN 2000/01/18 */ #ifndef PCI_VENDOR_ID_ACCESSIO #define PCI_VENDOR_ID_ACCESSIO 0x494f #endif #ifndef PCI_DEVICE_ID_WDG_CSM #define PCI_DEVICE_ID_WDG_CSM 0x22c0 #endif /* We can only use 1 card due to the /dev/watchdog restriction */ static int dev_count; static unsigned long open_lock; static DEFINE_SPINLOCK(wdtpci_lock); static char expect_close; static int io; static int irq; /* Default timeout */ #define WD_TIMO 60 /* Default heartbeat = 60 seconds */ static int heartbeat = WD_TIMO; static int wd_heartbeat; module_param(heartbeat, int, 0); MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WD_TIMO) ")"); static int nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, int, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); #ifdef CONFIG_WDT_501_PCI /* Support for the Fan Tachometer on the PCI-WDT501 */ static int tachometer; module_param(tachometer, int, 0); MODULE_PARM_DESC(tachometer, "PCI-WDT501 Fan Tachometer support (0=disable, default=0)"); #endif /* CONFIG_WDT_501_PCI */ /* * Programming support */ static void wdtpci_ctr_mode(int ctr, int mode) { ctr <<= 6; ctr |= 0x30; ctr |= (mode << 1); outb(ctr, WDT_CR); udelay(8); } static void wdtpci_ctr_load(int ctr, int val) { outb(val & 0xFF, WDT_COUNT0 + ctr); udelay(8); outb(val >> 8, WDT_COUNT0 + ctr); udelay(8); } /** * wdtpci_start: * * Start the watchdog driver. */ static int wdtpci_start(void) { unsigned long flags; spin_lock_irqsave(&wdtpci_lock, flags); /* * "pet" the watchdog, as Access says. * This resets the clock outputs. */ inb(WDT_DC); /* Disable watchdog */ udelay(8); wdtpci_ctr_mode(2, 0); /* Program CTR2 for Mode 0: Pulse on Terminal Count */ outb(0, WDT_DC); /* Enable watchdog */ udelay(8); inb(WDT_DC); /* Disable watchdog */ udelay(8); outb(0, WDT_CLOCK); /* 2.0833MHz clock */ udelay(8); inb(WDT_BUZZER); /* disable */ udelay(8); inb(WDT_OPTONOTRST); /* disable */ udelay(8); inb(WDT_OPTORST); /* disable */ udelay(8); inb(WDT_PROGOUT); /* disable */ udelay(8); wdtpci_ctr_mode(0, 3); /* Program CTR0 for Mode 3: Square Wave Generator */ wdtpci_ctr_mode(1, 2); /* Program CTR1 for Mode 2: Rate Generator */ wdtpci_ctr_mode(2, 1); /* Program CTR2 for Mode 1: Retriggerable One-Shot */ wdtpci_ctr_load(0, 20833); /* count at 100Hz */ wdtpci_ctr_load(1, wd_heartbeat);/* Heartbeat */ /* DO NOT LOAD CTR2 on PCI card! -- JPN */ outb(0, WDT_DC); /* Enable watchdog */ udelay(8); spin_unlock_irqrestore(&wdtpci_lock, flags); return 0; } /** * wdtpci_stop: * * Stop the watchdog driver. */ static int wdtpci_stop(void) { unsigned long flags; /* Turn the card off */ spin_lock_irqsave(&wdtpci_lock, flags); inb(WDT_DC); /* Disable watchdog */ udelay(8); wdtpci_ctr_load(2, 0); /* 0 length reset pulses now */ spin_unlock_irqrestore(&wdtpci_lock, flags); return 0; } /** * wdtpci_ping: * * Reload counter one with the watchdog heartbeat. We don't bother * reloading the cascade counter. */ static int wdtpci_ping(void) { unsigned long flags; spin_lock_irqsave(&wdtpci_lock, flags); /* Write a watchdog value */ inb(WDT_DC); /* Disable watchdog */ udelay(8); wdtpci_ctr_mode(1, 2); /* Re-Program CTR1 for Mode 2: Rate Generator */ wdtpci_ctr_load(1, wd_heartbeat);/* Heartbeat */ outb(0, WDT_DC); /* Enable watchdog */ udelay(8); spin_unlock_irqrestore(&wdtpci_lock, flags); return 0; } /** * wdtpci_set_heartbeat: * @t: the new heartbeat value that needs to be set. * * Set a new heartbeat value for the watchdog device. If the heartbeat * value is incorrect we keep the old value and return -EINVAL. * If successful we return 0. */ static int wdtpci_set_heartbeat(int t) { /* Arbitrary, can't find the card's limits */ if (t < 1 || t > 65535) return -EINVAL; heartbeat = t; wd_heartbeat = t * 100; return 0; } /** * wdtpci_get_status: * @status: the new status. * * Extract the status information from a WDT watchdog device. There are * several board variants so we have to know which bits are valid. Some * bits default to one and some to zero in order to be maximally painful. * * we then map the bits onto the status ioctl flags. */ static int wdtpci_get_status(int *status) { unsigned char new_status; unsigned long flags; spin_lock_irqsave(&wdtpci_lock, flags); new_status = inb(WDT_SR); spin_unlock_irqrestore(&wdtpci_lock, flags); *status = 0; if (new_status & WDC_SR_ISOI0) *status |= WDIOF_EXTERN1; if (new_status & WDC_SR_ISII1) *status |= WDIOF_EXTERN2; #ifdef CONFIG_WDT_501_PCI if (!(new_status & WDC_SR_TGOOD)) *status |= WDIOF_OVERHEAT; if (!(new_status & WDC_SR_PSUOVER)) *status |= WDIOF_POWEROVER; if (!(new_status & WDC_SR_PSUUNDR)) *status |= WDIOF_POWERUNDER; if (tachometer) { if (!(new_status & WDC_SR_FANGOOD)) *status |= WDIOF_FANFAULT; } #endif /* CONFIG_WDT_501_PCI */ return 0; } #ifdef CONFIG_WDT_501_PCI /** * wdtpci_get_temperature: * * Reports the temperature in degrees Fahrenheit. The API is in * farenheit. It was designed by an imperial measurement luddite. */ static int wdtpci_get_temperature(int *temperature) { unsigned short c; unsigned long flags; spin_lock_irqsave(&wdtpci_lock, flags); c = inb(WDT_RT); udelay(8); spin_unlock_irqrestore(&wdtpci_lock, flags); *temperature = (c * 11 / 15) + 7; return 0; } #endif /* CONFIG_WDT_501_PCI */ /** * wdtpci_interrupt: * @irq: Interrupt number * @dev_id: Unused as we don't allow multiple devices. * * Handle an interrupt from the board. These are raised when the status * map changes in what the board considers an interesting way. That means * a failure condition occurring. */ static irqreturn_t wdtpci_interrupt(int irq, void *dev_id) { /* * Read the status register see what is up and * then printk it. */ unsigned char status; spin_lock(&wdtpci_lock); status = inb(WDT_SR); udelay(8); printk(KERN_CRIT PFX "status %d\n", status); #ifdef CONFIG_WDT_501_PCI if (!(status & WDC_SR_TGOOD)) { u8 alarm = inb(WDT_RT); printk(KERN_CRIT PFX "Overheat alarm.(%d)\n", alarm); udelay(8); } if (!(status & WDC_SR_PSUOVER)) printk(KERN_CRIT PFX "PSU over voltage.\n"); if (!(status & WDC_SR_PSUUNDR)) printk(KERN_CRIT PFX "PSU under voltage.\n"); if (tachometer) { if (!(status & WDC_SR_FANGOOD)) printk(KERN_CRIT PFX "Possible fan fault.\n"); } #endif /* CONFIG_WDT_501_PCI */ if (!(status&WDC_SR_WCCR)) { #ifdef SOFTWARE_REBOOT #ifdef ONLY_TESTING printk(KERN_CRIT PFX "Would Reboot.\n"); #else printk(KERN_CRIT PFX "Initiating system reboot.\n"); emergency_restart(NULL); #endif #else printk(KERN_CRIT PFX "Reset in 5ms.\n"); #endif } spin_unlock(&wdtpci_lock); return IRQ_HANDLED; } /** * wdtpci_write: * @file: file handle to the watchdog * @buf: buffer to write (unused as data does not matter here * @count: count of bytes * @ppos: pointer to the position to write. No seeks allowed * * A write to a watchdog device is defined as a keepalive signal. Any * write of data will do, as we we don't define content meaning. */ static ssize_t wdtpci_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { if (count) { if (!nowayout) { size_t i; expect_close = 0; for (i = 0; i != count; i++) { char c; if (get_user(c, buf + i)) return -EFAULT; if (c == 'V') expect_close = 42; } } wdtpci_ping(); } return count; } /** * wdtpci_ioctl: * @file: file handle to the device * @cmd: watchdog command * @arg: argument pointer * * The watchdog API defines a common set of functions for all watchdogs * according to their available features. We only actually usefully support * querying capabilities and current status. */ static long wdtpci_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int new_heartbeat; int status; void __user *argp = (void __user *)arg; int __user *p = argp; static struct watchdog_info ident = { .options = WDIOF_SETTIMEOUT| WDIOF_MAGICCLOSE| WDIOF_KEEPALIVEPING, .firmware_version = 1, .identity = "PCI-WDT500/501", }; /* Add options according to the card we have */ ident.options |= (WDIOF_EXTERN1|WDIOF_EXTERN2); #ifdef CONFIG_WDT_501_PCI ident.options |= (WDIOF_OVERHEAT|WDIOF_POWERUNDER|WDIOF_POWEROVER); if (tachometer) ident.options |= WDIOF_FANFAULT; #endif /* CONFIG_WDT_501_PCI */ switch (cmd) { case WDIOC_GETSUPPORT: return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; case WDIOC_GETSTATUS: wdtpci_get_status(&status); return put_user(status, p); case WDIOC_GETBOOTSTATUS: return put_user(0, p); case WDIOC_KEEPALIVE: wdtpci_ping(); return 0; case WDIOC_SETTIMEOUT: if (get_user(new_heartbeat, p)) return -EFAULT; if (wdtpci_set_heartbeat(new_heartbeat)) return -EINVAL; wdtpci_ping(); /* Fall */ case WDIOC_GETTIMEOUT: return put_user(heartbeat, p); default: return -ENOTTY; } } /** * wdtpci_open: * @inode: inode of device * @file: file handle to device * * The watchdog device has been opened. The watchdog device is single * open and on opening we load the counters. Counter zero is a 100Hz * cascade, into counter 1 which downcounts to reboot. When the counter * triggers counter 2 downcounts the length of the reset pulse which * set set to be as long as possible. */ static int wdtpci_open(struct inode *inode, struct file *file) { if (test_and_set_bit(0, &open_lock)) return -EBUSY; if (nowayout) __module_get(THIS_MODULE); /* * Activate */ wdtpci_start(); return nonseekable_open(inode, file); } /** * wdtpci_release: * @inode: inode to board * @file: file handle to board * * The watchdog has a configurable API. There is a religious dispute * between people who want their watchdog to be able to shut down and * those who want to be sure if the watchdog manager dies the machine * reboots. In the former case we disable the counters, in the latter * case you have to open it again very soon. */ static int wdtpci_release(struct inode *inode, struct file *file) { if (expect_close == 42) { wdtpci_stop(); } else { printk(KERN_CRIT PFX "Unexpected close, not stopping timer!"); wdtpci_ping(); } expect_close = 0; clear_bit(0, &open_lock); return 0; } #ifdef CONFIG_WDT_501_PCI /** * wdtpci_temp_read: * @file: file handle to the watchdog board * @buf: buffer to write 1 byte into * @count: length of buffer * @ptr: offset (no seek allowed) * * Read reports the temperature in degrees Fahrenheit. The API is in * fahrenheit. It was designed by an imperial measurement luddite. */ static ssize_t wdtpci_temp_read(struct file *file, char __user *buf, size_t count, loff_t *ptr) { int temperature; if (wdtpci_get_temperature(&temperature)) return -EFAULT; if (copy_to_user(buf, &temperature, 1)) return -EFAULT; return 1; } /** * wdtpci_temp_open: * @inode: inode of device * @file: file handle to device * * The temperature device has been opened. */ static int wdtpci_temp_open(struct inode *inode, struct file *file) { return nonseekable_open(inode, file); } /** * wdtpci_temp_release: * @inode: inode to board * @file: file handle to board * * The temperature device has been closed. */ static int wdtpci_temp_release(struct inode *inode, struct file *file) { return 0; } #endif /* CONFIG_WDT_501_PCI */ /** * notify_sys: * @this: our notifier block * @code: the event being reported * @unused: unused * * Our notifier is called on system shutdowns. We want to turn the card * off at reboot otherwise the machine will reboot again during memory * test or worse yet during the following fsck. This would suck, in fact * trust me - if it happens it does suck. */ static int wdtpci_notify_sys(struct notifier_block *this, unsigned long code, void *unused) { if (code == SYS_DOWN || code == SYS_HALT) wdtpci_stop(); return NOTIFY_DONE; } /* * Kernel Interfaces */ static const struct file_operations wdtpci_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .write = wdtpci_write, .unlocked_ioctl = wdtpci_ioctl, .open = wdtpci_open, .release = wdtpci_release, }; static struct miscdevice wdtpci_miscdev = { .minor = WATCHDOG_MINOR, .name = "watchdog", .fops = &wdtpci_fops, }; #ifdef CONFIG_WDT_501_PCI static const struct file_operations wdtpci_temp_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .read = wdtpci_temp_read, .open = wdtpci_temp_open, .release = wdtpci_temp_release, }; static struct miscdevice temp_miscdev = { .minor = TEMP_MINOR, .name = "temperature", .fops = &wdtpci_temp_fops, }; #endif /* CONFIG_WDT_501_PCI */ /* * The WDT card needs to learn about soft shutdowns in order to * turn the timebomb registers off. */ static struct notifier_block wdtpci_notifier = { .notifier_call = wdtpci_notify_sys, }; static int __devinit wdtpci_init_one(struct pci_dev *dev, const struct pci_device_id *ent) { int ret = -EIO; dev_count++; if (dev_count > 1) { printk(KERN_ERR PFX "This driver only supports one device\n"); return -ENODEV; } if (pci_enable_device(dev)) { printk(KERN_ERR PFX "Not possible to enable PCI Device\n"); return -ENODEV; } if (pci_resource_start(dev, 2) == 0x0000) { printk(KERN_ERR PFX "No I/O-Address for card detected\n"); ret = -ENODEV; goto out_pci; } irq = dev->irq; io = pci_resource_start(dev, 2); if (request_region(io, 16, "wdt_pci") == NULL) { printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", io); goto out_pci; } if (request_irq(irq, wdtpci_interrupt, IRQF_DISABLED | IRQF_SHARED, "wdt_pci", &wdtpci_miscdev)) { printk(KERN_ERR PFX "IRQ %d is not free\n", irq); goto out_reg; } printk(KERN_INFO "PCI-WDT500/501 (PCI-WDG-CSM) driver 0.10 at 0x%04x (Interrupt %d)\n", io, irq); /* Check that the heartbeat value is within its range; if not reset to the default */ if (wdtpci_set_heartbeat(heartbeat)) { wdtpci_set_heartbeat(WD_TIMO); printk(KERN_INFO PFX "heartbeat value must be 0 < heartbeat < 65536, using %d\n", WD_TIMO); } ret = register_reboot_notifier(&wdtpci_notifier); if (ret) { printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", ret); goto out_irq; } #ifdef CONFIG_WDT_501_PCI ret = misc_register(&temp_miscdev); if (ret) { printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", TEMP_MINOR, ret); goto out_rbt; } #endif /* CONFIG_WDT_501_PCI */ ret = misc_register(&wdtpci_miscdev); if (ret) { printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", WATCHDOG_MINOR, ret); goto out_misc; } printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n", heartbeat, nowayout); #ifdef CONFIG_WDT_501_PCI printk(KERN_INFO "wdt: Fan Tachometer is %s\n", (tachometer ? "Enabled" : "Disabled")); #endif /* CONFIG_WDT_501_PCI */ ret = 0; out: return ret; out_misc: #ifdef CONFIG_WDT_501_PCI misc_deregister(&temp_miscdev); out_rbt: #endif /* CONFIG_WDT_501_PCI */ unregister_reboot_notifier(&wdtpci_notifier); out_irq: free_irq(irq, &wdtpci_miscdev); out_reg: release_region(io, 16); out_pci: pci_disable_device(dev); goto out; } static void __devexit wdtpci_remove_one(struct pci_dev *pdev) { /* here we assume only one device will ever have * been picked up and registered by probe function */ misc_deregister(&wdtpci_miscdev); #ifdef CONFIG_WDT_501_PCI misc_deregister(&temp_miscdev); #endif /* CONFIG_WDT_501_PCI */ unregister_reboot_notifier(&wdtpci_notifier); free_irq(irq, &wdtpci_miscdev); release_region(io, 16); pci_disable_device(pdev); dev_count--; } static struct pci_device_id wdtpci_pci_tbl[] = { { .vendor = PCI_VENDOR_ID_ACCESSIO, .device = PCI_DEVICE_ID_WDG_CSM, .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, }, { 0, }, /* terminate list */ }; MODULE_DEVICE_TABLE(pci, wdtpci_pci_tbl); static struct pci_driver wdtpci_driver = { .name = "wdt_pci", .id_table = wdtpci_pci_tbl, .probe = wdtpci_init_one, .remove = __devexit_p(wdtpci_remove_one), }; /** * wdtpci_cleanup: * * Unload the watchdog. You cannot do this with any file handles open. * If your watchdog is set to continue ticking on close and you unload * it, well it keeps ticking. We won't get the interrupt but the board * will not touch PC memory so all is fine. You just have to load a new * module in xx seconds or reboot. */ static void __exit wdtpci_cleanup(void) { pci_unregister_driver(&wdtpci_driver); } /** * wdtpci_init: * * Set up the WDT watchdog board. All we have to do is grab the * resources we require and bitch if anyone beat us to them. * The open() function will actually kick the board off. */ static int __init wdtpci_init(void) { return pci_register_driver(&wdtpci_driver); } module_init(wdtpci_init); module_exit(wdtpci_cleanup); MODULE_AUTHOR("JP Nollmann, Alan Cox"); MODULE_DESCRIPTION("Driver for the ICS PCI-WDT500/501 watchdog cards"); MODULE_LICENSE("GPL"); MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); MODULE_ALIAS_MISCDEV(TEMP_MINOR);
gpl-2.0
jenswi-linaro/linux
drivers/staging/fsl-mc/bus/mc-bus.c
193
21198
/* * Freescale Management Complex (MC) bus driver * * Copyright (C) 2014 Freescale Semiconductor, Inc. * Author: German Rivera <German.Rivera@freescale.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 "../include/mc-private.h" #include <linux/module.h> #include <linux/of_device.h> #include <linux/of_address.h> #include <linux/ioport.h> #include <linux/slab.h> #include <linux/limits.h> #include "../include/dpmng.h" #include "../include/mc-sys.h" #include "dprc-cmd.h" static struct kmem_cache *mc_dev_cache; static bool fsl_mc_is_root_dprc(struct device *dev); /** * fsl_mc_bus_match - device to driver matching callback * @dev: the MC object device structure to match against * @drv: the device driver to search for matching MC object device id * structures * * Returns 1 on success, 0 otherwise. */ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv) { const struct fsl_mc_device_match_id *id; struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv); bool found = false; bool major_version_mismatch = false; bool minor_version_mismatch = false; if (WARN_ON(!fsl_mc_bus_exists())) goto out; if (!mc_drv->match_id_table) goto out; /* * If the object is not 'plugged' don't match. * Only exception is the root DPRC, which is a special case. */ if ((mc_dev->obj_desc.state & DPRC_OBJ_STATE_PLUGGED) == 0 && !fsl_mc_is_root_dprc(&mc_dev->dev)) goto out; /* * Traverse the match_id table of the given driver, trying to find * a matching for the given MC object device. */ for (id = mc_drv->match_id_table; id->vendor != 0x0; id++) { if (id->vendor == mc_dev->obj_desc.vendor && strcmp(id->obj_type, mc_dev->obj_desc.type) == 0) { if (id->ver_major == mc_dev->obj_desc.ver_major) { found = true; if (id->ver_minor != mc_dev->obj_desc.ver_minor) minor_version_mismatch = true; } else { major_version_mismatch = true; } break; } } if (major_version_mismatch) { dev_warn(dev, "Major version mismatch: driver version %u.%u, MC object version %u.%u\n", id->ver_major, id->ver_minor, mc_dev->obj_desc.ver_major, mc_dev->obj_desc.ver_minor); } else if (minor_version_mismatch) { dev_warn(dev, "Minor version mismatch: driver version %u.%u, MC object version %u.%u\n", id->ver_major, id->ver_minor, mc_dev->obj_desc.ver_major, mc_dev->obj_desc.ver_minor); } out: dev_dbg(dev, "%smatched\n", found ? "" : "not "); return found; } /** * fsl_mc_bus_uevent - callback invoked when a device is added */ static int fsl_mc_bus_uevent(struct device *dev, struct kobj_uevent_env *env) { pr_debug("%s invoked\n", __func__); return 0; } struct bus_type fsl_mc_bus_type = { .name = "fsl-mc", .match = fsl_mc_bus_match, .uevent = fsl_mc_bus_uevent, }; EXPORT_SYMBOL_GPL(fsl_mc_bus_type); static atomic_t root_dprc_count = ATOMIC_INIT(0); static int fsl_mc_driver_probe(struct device *dev) { struct fsl_mc_driver *mc_drv; struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); int error; if (WARN_ON(!dev->driver)) return -EINVAL; mc_drv = to_fsl_mc_driver(dev->driver); if (WARN_ON(!mc_drv->probe)) return -EINVAL; error = mc_drv->probe(mc_dev); if (error < 0) { dev_err(dev, "MC object device probe callback failed: %d\n", error); return error; } return 0; } static int fsl_mc_driver_remove(struct device *dev) { struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); int error; if (WARN_ON(!dev->driver)) return -EINVAL; error = mc_drv->remove(mc_dev); if (error < 0) { dev_err(dev, "MC object device remove callback failed: %d\n", error); return error; } return 0; } static void fsl_mc_driver_shutdown(struct device *dev) { struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver); struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); mc_drv->shutdown(mc_dev); } /** * __fsl_mc_driver_register - registers a child device driver with the * MC bus * * This function is implicitly invoked from the registration function of * fsl_mc device drivers, which is generated by the * module_fsl_mc_driver() macro. */ int __fsl_mc_driver_register(struct fsl_mc_driver *mc_driver, struct module *owner) { int error; mc_driver->driver.owner = owner; mc_driver->driver.bus = &fsl_mc_bus_type; if (mc_driver->probe) mc_driver->driver.probe = fsl_mc_driver_probe; if (mc_driver->remove) mc_driver->driver.remove = fsl_mc_driver_remove; if (mc_driver->shutdown) mc_driver->driver.shutdown = fsl_mc_driver_shutdown; error = driver_register(&mc_driver->driver); if (error < 0) { pr_err("driver_register() failed for %s: %d\n", mc_driver->driver.name, error); return error; } pr_info("MC object device driver %s registered\n", mc_driver->driver.name); return 0; } EXPORT_SYMBOL_GPL(__fsl_mc_driver_register); /** * fsl_mc_driver_unregister - unregisters a device driver from the * MC bus */ void fsl_mc_driver_unregister(struct fsl_mc_driver *mc_driver) { driver_unregister(&mc_driver->driver); } EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister); /** * fsl_mc_bus_exists - check if a root dprc exists */ bool fsl_mc_bus_exists(void) { return atomic_read(&root_dprc_count) > 0; } EXPORT_SYMBOL_GPL(fsl_mc_bus_exists); /** * fsl_mc_get_root_dprc - function to traverse to the root dprc */ static void fsl_mc_get_root_dprc(struct device *dev, struct device **root_dprc_dev) { if (WARN_ON(!dev)) { *root_dprc_dev = NULL; } else if (WARN_ON(dev->bus != &fsl_mc_bus_type)) { *root_dprc_dev = NULL; } else { *root_dprc_dev = dev; while ((*root_dprc_dev)->parent->bus == &fsl_mc_bus_type) *root_dprc_dev = (*root_dprc_dev)->parent; } } /** * fsl_mc_is_root_dprc - function to check if a given device is a root dprc */ static bool fsl_mc_is_root_dprc(struct device *dev) { struct device *root_dprc_dev; fsl_mc_get_root_dprc(dev, &root_dprc_dev); if (!root_dprc_dev) return false; else return dev == root_dprc_dev; } static int get_dprc_icid(struct fsl_mc_io *mc_io, int container_id, u16 *icid) { u16 dprc_handle; struct dprc_attributes attr; int error; error = dprc_open(mc_io, 0, container_id, &dprc_handle); if (error < 0) { pr_err("dprc_open() failed: %d\n", error); return error; } memset(&attr, 0, sizeof(attr)); error = dprc_get_attributes(mc_io, 0, dprc_handle, &attr); if (error < 0) { pr_err("dprc_get_attributes() failed: %d\n", error); goto common_cleanup; } *icid = attr.icid; error = 0; common_cleanup: (void)dprc_close(mc_io, 0, dprc_handle); return error; } static int translate_mc_addr(struct fsl_mc_device *mc_dev, enum dprc_region_type mc_region_type, u64 mc_offset, phys_addr_t *phys_addr) { int i; struct device *root_dprc_dev; struct fsl_mc *mc; fsl_mc_get_root_dprc(&mc_dev->dev, &root_dprc_dev); if (WARN_ON(!root_dprc_dev)) return -EINVAL; mc = dev_get_drvdata(root_dprc_dev->parent); if (mc->num_translation_ranges == 0) { /* * Do identity mapping: */ *phys_addr = mc_offset; return 0; } for (i = 0; i < mc->num_translation_ranges; i++) { struct fsl_mc_addr_translation_range *range = &mc->translation_ranges[i]; if (mc_region_type == range->mc_region_type && mc_offset >= range->start_mc_offset && mc_offset < range->end_mc_offset) { *phys_addr = range->start_phys_addr + (mc_offset - range->start_mc_offset); return 0; } } return -EFAULT; } static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev, struct fsl_mc_device *mc_bus_dev) { int i; int error; struct resource *regions; struct dprc_obj_desc *obj_desc = &mc_dev->obj_desc; struct device *parent_dev = mc_dev->dev.parent; enum dprc_region_type mc_region_type; if (strcmp(obj_desc->type, "dprc") == 0 || strcmp(obj_desc->type, "dpmcp") == 0) { mc_region_type = DPRC_REGION_TYPE_MC_PORTAL; } else if (strcmp(obj_desc->type, "dpio") == 0) { mc_region_type = DPRC_REGION_TYPE_QBMAN_PORTAL; } else { /* * This function should not have been called for this MC object * type, as this object type is not supposed to have MMIO * regions */ WARN_ON(true); return -EINVAL; } regions = kmalloc_array(obj_desc->region_count, sizeof(regions[0]), GFP_KERNEL); if (!regions) return -ENOMEM; for (i = 0; i < obj_desc->region_count; i++) { struct dprc_region_desc region_desc; error = dprc_get_obj_region(mc_bus_dev->mc_io, 0, mc_bus_dev->mc_handle, obj_desc->type, obj_desc->id, i, &region_desc); if (error < 0) { dev_err(parent_dev, "dprc_get_obj_region() failed: %d\n", error); goto error_cleanup_regions; } WARN_ON(region_desc.size == 0); error = translate_mc_addr(mc_dev, mc_region_type, region_desc.base_offset, &regions[i].start); if (error < 0) { dev_err(parent_dev, "Invalid MC offset: %#x (for %s.%d\'s region %d)\n", region_desc.base_offset, obj_desc->type, obj_desc->id, i); goto error_cleanup_regions; } regions[i].end = regions[i].start + region_desc.size - 1; regions[i].name = "fsl-mc object MMIO region"; regions[i].flags = IORESOURCE_IO; } mc_dev->regions = regions; return 0; error_cleanup_regions: kfree(regions); return error; } /** * Add a newly discovered MC object device to be visible in Linux */ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc, struct fsl_mc_io *mc_io, struct device *parent_dev, struct fsl_mc_device **new_mc_dev) { int error; struct fsl_mc_device *mc_dev = NULL; struct fsl_mc_bus *mc_bus = NULL; struct fsl_mc_device *parent_mc_dev; if (parent_dev->bus == &fsl_mc_bus_type) parent_mc_dev = to_fsl_mc_device(parent_dev); else parent_mc_dev = NULL; if (strcmp(obj_desc->type, "dprc") == 0) { /* * Allocate an MC bus device object: */ mc_bus = devm_kzalloc(parent_dev, sizeof(*mc_bus), GFP_KERNEL); if (!mc_bus) return -ENOMEM; mc_dev = &mc_bus->mc_dev; } else { /* * Allocate a regular fsl_mc_device object: */ mc_dev = kmem_cache_zalloc(mc_dev_cache, GFP_KERNEL); if (!mc_dev) return -ENOMEM; } mc_dev->obj_desc = *obj_desc; mc_dev->mc_io = mc_io; device_initialize(&mc_dev->dev); mc_dev->dev.parent = parent_dev; mc_dev->dev.bus = &fsl_mc_bus_type; dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id); if (strcmp(obj_desc->type, "dprc") == 0) { struct fsl_mc_io *mc_io2; mc_dev->flags |= FSL_MC_IS_DPRC; /* * To get the DPRC's ICID, we need to open the DPRC * in get_dprc_icid(). For child DPRCs, we do so using the * parent DPRC's MC portal instead of the child DPRC's MC * portal, in case the child DPRC is already opened with * its own portal (e.g., the DPRC used by AIOP). * * NOTE: There cannot be more than one active open for a * given MC object, using the same MC portal. */ if (parent_mc_dev) { /* * device being added is a child DPRC device */ mc_io2 = parent_mc_dev->mc_io; } else { /* * device being added is the root DPRC device */ if (WARN_ON(!mc_io)) { error = -EINVAL; goto error_cleanup_dev; } mc_io2 = mc_io; atomic_inc(&root_dprc_count); } error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid); if (error < 0) goto error_cleanup_dev; } else { /* * A non-DPRC MC object device has to be a child of another * MC object (specifically a DPRC object) */ mc_dev->icid = parent_mc_dev->icid; mc_dev->dma_mask = FSL_MC_DEFAULT_DMA_MASK; mc_dev->dev.dma_mask = &mc_dev->dma_mask; } /* * Get MMIO regions for the device from the MC: * * NOTE: the root DPRC is a special case as its MMIO region is * obtained from the device tree */ if (parent_mc_dev && obj_desc->region_count != 0) { error = fsl_mc_device_get_mmio_regions(mc_dev, parent_mc_dev); if (error < 0) goto error_cleanup_dev; } /* * The device-specific probe callback will get invoked by device_add() */ error = device_add(&mc_dev->dev); if (error < 0) { dev_err(parent_dev, "device_add() failed for device %s: %d\n", dev_name(&mc_dev->dev), error); goto error_cleanup_dev; } (void)get_device(&mc_dev->dev); dev_dbg(parent_dev, "Added MC object device %s\n", dev_name(&mc_dev->dev)); *new_mc_dev = mc_dev; return 0; error_cleanup_dev: kfree(mc_dev->regions); if (mc_bus) devm_kfree(parent_dev, mc_bus); else kmem_cache_free(mc_dev_cache, mc_dev); return error; } EXPORT_SYMBOL_GPL(fsl_mc_device_add); /** * fsl_mc_device_remove - Remove a MC object device from being visible to * Linux * * @mc_dev: Pointer to a MC object device object */ void fsl_mc_device_remove(struct fsl_mc_device *mc_dev) { struct fsl_mc_bus *mc_bus = NULL; kfree(mc_dev->regions); /* * The device-specific remove callback will get invoked by device_del() */ device_del(&mc_dev->dev); put_device(&mc_dev->dev); if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) { mc_bus = to_fsl_mc_bus(mc_dev); if (mc_dev->mc_io) { fsl_destroy_mc_io(mc_dev->mc_io); mc_dev->mc_io = NULL; } if (fsl_mc_is_root_dprc(&mc_dev->dev)) { if (atomic_read(&root_dprc_count) > 0) atomic_dec(&root_dprc_count); else WARN_ON(1); } } if (mc_bus) devm_kfree(mc_dev->dev.parent, mc_bus); else kmem_cache_free(mc_dev_cache, mc_dev); } EXPORT_SYMBOL_GPL(fsl_mc_device_remove); static int parse_mc_ranges(struct device *dev, int *paddr_cells, int *mc_addr_cells, int *mc_size_cells, const __be32 **ranges_start, u8 *num_ranges) { const __be32 *prop; int range_tuple_cell_count; int ranges_len; int tuple_len; struct device_node *mc_node = dev->of_node; *ranges_start = of_get_property(mc_node, "ranges", &ranges_len); if (!(*ranges_start) || !ranges_len) { dev_warn(dev, "missing or empty ranges property for device tree node '%s'\n", mc_node->name); *num_ranges = 0; return 0; } *paddr_cells = of_n_addr_cells(mc_node); prop = of_get_property(mc_node, "#address-cells", NULL); if (prop) *mc_addr_cells = be32_to_cpup(prop); else *mc_addr_cells = *paddr_cells; prop = of_get_property(mc_node, "#size-cells", NULL); if (prop) *mc_size_cells = be32_to_cpup(prop); else *mc_size_cells = of_n_size_cells(mc_node); range_tuple_cell_count = *paddr_cells + *mc_addr_cells + *mc_size_cells; tuple_len = range_tuple_cell_count * sizeof(__be32); if (ranges_len % tuple_len != 0) { dev_err(dev, "malformed ranges property '%s'\n", mc_node->name); return -EINVAL; } *num_ranges = ranges_len / tuple_len; return 0; } static int get_mc_addr_translation_ranges(struct device *dev, struct fsl_mc_addr_translation_range **ranges, u8 *num_ranges) { int error; int paddr_cells; int mc_addr_cells; int mc_size_cells; int i; const __be32 *ranges_start; const __be32 *cell; error = parse_mc_ranges(dev, &paddr_cells, &mc_addr_cells, &mc_size_cells, &ranges_start, num_ranges); if (error < 0) return error; if (!(*num_ranges)) { /* * Missing or empty ranges property ("ranges;") for the * 'fsl,qoriq-mc' node. In this case, identity mapping * will be used. */ *ranges = NULL; return 0; } *ranges = devm_kcalloc(dev, *num_ranges, sizeof(struct fsl_mc_addr_translation_range), GFP_KERNEL); if (!(*ranges)) return -ENOMEM; cell = ranges_start; for (i = 0; i < *num_ranges; ++i) { struct fsl_mc_addr_translation_range *range = &(*ranges)[i]; range->mc_region_type = of_read_number(cell, 1); range->start_mc_offset = of_read_number(cell + 1, mc_addr_cells - 1); cell += mc_addr_cells; range->start_phys_addr = of_read_number(cell, paddr_cells); cell += paddr_cells; range->end_mc_offset = range->start_mc_offset + of_read_number(cell, mc_size_cells); cell += mc_size_cells; } return 0; } /** * fsl_mc_bus_probe - callback invoked when the root MC bus is being * added */ static int fsl_mc_bus_probe(struct platform_device *pdev) { struct dprc_obj_desc obj_desc; int error; struct fsl_mc *mc; struct fsl_mc_device *mc_bus_dev = NULL; struct fsl_mc_io *mc_io = NULL; int container_id; phys_addr_t mc_portal_phys_addr; u32 mc_portal_size; struct mc_version mc_version; struct resource res; dev_info(&pdev->dev, "Root MC bus device probed"); mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); if (!mc) return -ENOMEM; platform_set_drvdata(pdev, mc); /* * Get physical address of MC portal for the root DPRC: */ error = of_address_to_resource(pdev->dev.of_node, 0, &res); if (error < 0) { dev_err(&pdev->dev, "of_address_to_resource() failed for %s\n", pdev->dev.of_node->full_name); return error; } mc_portal_phys_addr = res.start; mc_portal_size = resource_size(&res); error = fsl_create_mc_io(&pdev->dev, mc_portal_phys_addr, mc_portal_size, NULL, 0, &mc_io); if (error < 0) return error; error = mc_get_version(mc_io, 0, &mc_version); if (error != 0) { dev_err(&pdev->dev, "mc_get_version() failed with error %d\n", error); goto error_cleanup_mc_io; } dev_info(&pdev->dev, "Freescale Management Complex Firmware version: %u.%u.%u\n", mc_version.major, mc_version.minor, mc_version.revision); if (mc_version.major < MC_VER_MAJOR) { dev_err(&pdev->dev, "ERROR: MC firmware version not supported by driver (driver version: %u.%u)\n", MC_VER_MAJOR, MC_VER_MINOR); error = -ENOTSUPP; goto error_cleanup_mc_io; } if (mc_version.major > MC_VER_MAJOR) { dev_warn(&pdev->dev, "WARNING: driver may not support newer MC firmware features (driver version: %u.%u)\n", MC_VER_MAJOR, MC_VER_MINOR); } error = get_mc_addr_translation_ranges(&pdev->dev, &mc->translation_ranges, &mc->num_translation_ranges); if (error < 0) goto error_cleanup_mc_io; error = dpmng_get_container_id(mc_io, 0, &container_id); if (error < 0) { dev_err(&pdev->dev, "dpmng_get_container_id() failed: %d\n", error); goto error_cleanup_mc_io; } obj_desc.vendor = FSL_MC_VENDOR_FREESCALE; strcpy(obj_desc.type, "dprc"); obj_desc.id = container_id; obj_desc.ver_major = DPRC_VER_MAJOR; obj_desc.ver_minor = DPRC_VER_MINOR; obj_desc.irq_count = 1; obj_desc.region_count = 0; error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev); if (error < 0) goto error_cleanup_mc_io; mc->root_mc_bus_dev = mc_bus_dev; return 0; error_cleanup_mc_io: fsl_destroy_mc_io(mc_io); return error; } /** * fsl_mc_bus_remove - callback invoked when the root MC bus is being * removed */ static int fsl_mc_bus_remove(struct platform_device *pdev) { struct fsl_mc *mc = platform_get_drvdata(pdev); if (WARN_ON(!fsl_mc_is_root_dprc(&mc->root_mc_bus_dev->dev))) return -EINVAL; fsl_mc_device_remove(mc->root_mc_bus_dev); dev_info(&pdev->dev, "Root MC bus device removed"); return 0; } static const struct of_device_id fsl_mc_bus_match_table[] = { {.compatible = "fsl,qoriq-mc",}, {}, }; MODULE_DEVICE_TABLE(of, fsl_mc_bus_match_table); static struct platform_driver fsl_mc_bus_driver = { .driver = { .name = "fsl_mc_bus", .owner = THIS_MODULE, .pm = NULL, .of_match_table = fsl_mc_bus_match_table, }, .probe = fsl_mc_bus_probe, .remove = fsl_mc_bus_remove, }; static int __init fsl_mc_bus_driver_init(void) { int error; mc_dev_cache = kmem_cache_create("fsl_mc_device", sizeof(struct fsl_mc_device), 0, 0, NULL); if (!mc_dev_cache) { pr_err("Could not create fsl_mc_device cache\n"); return -ENOMEM; } error = bus_register(&fsl_mc_bus_type); if (error < 0) { pr_err("fsl-mc bus type registration failed: %d\n", error); goto error_cleanup_cache; } pr_info("fsl-mc bus type registered\n"); error = platform_driver_register(&fsl_mc_bus_driver); if (error < 0) { pr_err("platform_driver_register() failed: %d\n", error); goto error_cleanup_bus; } error = dprc_driver_init(); if (error < 0) goto error_cleanup_driver; error = fsl_mc_allocator_driver_init(); if (error < 0) goto error_cleanup_dprc_driver; return 0; error_cleanup_dprc_driver: dprc_driver_exit(); error_cleanup_driver: platform_driver_unregister(&fsl_mc_bus_driver); error_cleanup_bus: bus_unregister(&fsl_mc_bus_type); error_cleanup_cache: kmem_cache_destroy(mc_dev_cache); return error; } postcore_initcall(fsl_mc_bus_driver_init); static void __exit fsl_mc_bus_driver_exit(void) { if (WARN_ON(!mc_dev_cache)) return; fsl_mc_allocator_driver_exit(); dprc_driver_exit(); platform_driver_unregister(&fsl_mc_bus_driver); bus_unregister(&fsl_mc_bus_type); kmem_cache_destroy(mc_dev_cache); pr_info("MC bus unregistered\n"); } module_exit(fsl_mc_bus_driver_exit); MODULE_AUTHOR("Freescale Semiconductor Inc."); MODULE_DESCRIPTION("Freescale Management Complex (MC) bus driver"); MODULE_LICENSE("GPL");
gpl-2.0
fedya/aircam-openwrt
build_dir/toolchain-arm_v5te_gcc-linaro_uClibc-0.9.32_eabi/gcc-linaro-4.5-2011.02-0/gcc/testsuite/gcc.dg/builtins-40.c
193
1251
/* Copyright (C) 2004 Free Software Foundation. Check that fmod, fmodf, fmodl, drem, dremf, dreml, remainder, remainderf and remainderl built-in functions compile. Written by Uros Bizjak, 5th May 2004. */ /* { dg-do compile } */ /* { dg-options "-O2" } */ extern double fmod(double, double); extern float fmodf(float, float); extern long double fmodl(long double, long double); extern double remainder(double, double); extern float remainderf(float, float); extern long double remainderl(long double, long double); extern double drem(double, double); extern float dremf(float, float); extern long double dreml(long double, long double); double test1(double x, double y) { return fmod(x, y); } float test1f(float x, float y) { return fmodf(x, y); } long double test1l(long double x, long double y) { return fmodl(x, y); } double test2(double x, double y) { return remainder(x, y); } float test2f(float x, float y) { return remainderf(x, y); } long double test2l(long double x, long double y) { return remainderl(x, y); } double test3(double x, double y) { return drem(x, y); } float test3f(float x, float y) { return dremf(x, y); } long double test3l(long double x, long double y) { return dreml(x, y); }
gpl-2.0
mayqueenEMBEDDED/mq-kernel
drivers/staging/android/ion/ion_chunk_heap.c
193
5146
/* * drivers/staging/android/ion/ion_chunk_heap.c * * Copyright (C) 2012 Google, Inc. * * 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/dma-mapping.h> #include <linux/err.h> #include <linux/genalloc.h> #include <linux/io.h> #include <linux/mm.h> #include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include "ion.h" #include "ion_priv.h" struct ion_chunk_heap { struct ion_heap heap; struct gen_pool *pool; ion_phys_addr_t base; unsigned long chunk_size; unsigned long size; unsigned long allocated; }; static int ion_chunk_heap_allocate(struct ion_heap *heap, struct ion_buffer *buffer, unsigned long size, unsigned long align, unsigned long flags) { struct ion_chunk_heap *chunk_heap = container_of(heap, struct ion_chunk_heap, heap); struct sg_table *table; struct scatterlist *sg; int ret, i; unsigned long num_chunks; unsigned long allocated_size; if (align > chunk_heap->chunk_size) return -EINVAL; allocated_size = ALIGN(size, chunk_heap->chunk_size); num_chunks = allocated_size / chunk_heap->chunk_size; if (allocated_size > chunk_heap->size - chunk_heap->allocated) return -ENOMEM; table = kmalloc(sizeof(struct sg_table), GFP_KERNEL); if (!table) return -ENOMEM; ret = sg_alloc_table(table, num_chunks, GFP_KERNEL); if (ret) { kfree(table); return ret; } sg = table->sgl; for (i = 0; i < num_chunks; i++) { unsigned long paddr = gen_pool_alloc(chunk_heap->pool, chunk_heap->chunk_size); if (!paddr) goto err; sg_set_page(sg, pfn_to_page(PFN_DOWN(paddr)), chunk_heap->chunk_size, 0); sg = sg_next(sg); } buffer->priv_virt = table; chunk_heap->allocated += allocated_size; return 0; err: sg = table->sgl; for (i -= 1; i >= 0; i--) { gen_pool_free(chunk_heap->pool, page_to_phys(sg_page(sg)), sg->length); sg = sg_next(sg); } sg_free_table(table); kfree(table); return -ENOMEM; } static void ion_chunk_heap_free(struct ion_buffer *buffer) { struct ion_heap *heap = buffer->heap; struct ion_chunk_heap *chunk_heap = container_of(heap, struct ion_chunk_heap, heap); struct sg_table *table = buffer->priv_virt; struct scatterlist *sg; int i; unsigned long allocated_size; allocated_size = ALIGN(buffer->size, chunk_heap->chunk_size); ion_heap_buffer_zero(buffer); if (ion_buffer_cached(buffer)) dma_sync_sg_for_device(NULL, table->sgl, table->nents, DMA_BIDIRECTIONAL); for_each_sg(table->sgl, sg, table->nents, i) { gen_pool_free(chunk_heap->pool, page_to_phys(sg_page(sg)), sg->length); } chunk_heap->allocated -= allocated_size; sg_free_table(table); kfree(table); } static struct sg_table *ion_chunk_heap_map_dma(struct ion_heap *heap, struct ion_buffer *buffer) { return buffer->priv_virt; } static void ion_chunk_heap_unmap_dma(struct ion_heap *heap, struct ion_buffer *buffer) { } static struct ion_heap_ops chunk_heap_ops = { .allocate = ion_chunk_heap_allocate, .free = ion_chunk_heap_free, .map_dma = ion_chunk_heap_map_dma, .unmap_dma = ion_chunk_heap_unmap_dma, .map_user = ion_heap_map_user, .map_kernel = ion_heap_map_kernel, .unmap_kernel = ion_heap_unmap_kernel, }; struct ion_heap *ion_chunk_heap_create(struct ion_platform_heap *heap_data) { struct ion_chunk_heap *chunk_heap; int ret; struct page *page; size_t size; page = pfn_to_page(PFN_DOWN(heap_data->base)); size = heap_data->size; ion_pages_sync_for_device(NULL, page, size, DMA_BIDIRECTIONAL); ret = ion_heap_pages_zero(page, size, pgprot_writecombine(PAGE_KERNEL)); if (ret) return ERR_PTR(ret); chunk_heap = kzalloc(sizeof(struct ion_chunk_heap), GFP_KERNEL); if (!chunk_heap) return ERR_PTR(-ENOMEM); chunk_heap->chunk_size = (unsigned long)heap_data->priv; chunk_heap->pool = gen_pool_create(get_order(chunk_heap->chunk_size) + PAGE_SHIFT, -1); if (!chunk_heap->pool) { ret = -ENOMEM; goto error_gen_pool_create; } chunk_heap->base = heap_data->base; chunk_heap->size = heap_data->size; chunk_heap->allocated = 0; gen_pool_add(chunk_heap->pool, chunk_heap->base, heap_data->size, -1); chunk_heap->heap.ops = &chunk_heap_ops; chunk_heap->heap.type = ION_HEAP_TYPE_CHUNK; chunk_heap->heap.flags = ION_HEAP_FLAG_DEFER_FREE; pr_debug("%s: base %lu size %zu align %ld\n", __func__, chunk_heap->base, heap_data->size, heap_data->align); return &chunk_heap->heap; error_gen_pool_create: kfree(chunk_heap); return ERR_PTR(ret); } void ion_chunk_heap_destroy(struct ion_heap *heap) { struct ion_chunk_heap *chunk_heap = container_of(heap, struct ion_chunk_heap, heap); gen_pool_destroy(chunk_heap->pool); kfree(chunk_heap); chunk_heap = NULL; }
gpl-2.0
skritchz/semc-kernel-qsd8k-ics
drivers/char/misc.c
193
6769
/* * linux/drivers/char/misc.c * * Generic misc open routine by Johan Myreen * * Based on code from Linus * * Teemu Rantanen's Microsoft Busmouse support and Derrick Cole's * changes incorporated into 0.97pl4 * by Peter Cervasio (pete%q106fm.uucp@wupost.wustl.edu) (08SEP92) * See busmouse.c for particulars. * * Made things a lot mode modular - easy to compile in just one or two * of the misc drivers, as they are now completely independent. Linus. * * Support for loadable modules. 8-Sep-95 Philip Blundell <pjb27@cam.ac.uk> * * Fixed a failing symbol register to free the device registration * Alan Cox <alan@lxorguk.ukuu.org.uk> 21-Jan-96 * * Dynamic minors and /proc/mice by Alessandro Rubini. 26-Mar-96 * * Renamed to misc and miscdevice to be more accurate. Alan Cox 26-Mar-96 * * Handling of mouse minor numbers for kerneld: * Idea by Jacques Gelinas <jack@solucorp.qc.ca>, * adapted by Bjorn Ekwall <bj0rn@blox.se> * corrected by Alan Cox <alan@lxorguk.ukuu.org.uk> * * Changes for kmod (from kerneld): * Cyrus Durgin <cider@speakeasy.org> * * Added devfs support. Richard Gooch <rgooch@atnf.csiro.au> 10-Jan-1998 */ #include <linux/module.h> #include <linux/fs.h> #include <linux/errno.h> #include <linux/miscdevice.h> #include <linux/kernel.h> #include <linux/major.h> #include <linux/slab.h> #include <linux/mutex.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/stat.h> #include <linux/init.h> #include <linux/device.h> #include <linux/tty.h> #include <linux/kmod.h> #include <linux/smp_lock.h> /* * Head entry for the doubly linked miscdevice list */ static LIST_HEAD(misc_list); static DEFINE_MUTEX(misc_mtx); /* * Assigned numbers, used for dynamic minors */ #define DYNAMIC_MINORS 64 /* like dynamic majors */ static unsigned char misc_minors[DYNAMIC_MINORS / 8]; extern int pmu_device_init(void); #ifdef CONFIG_PROC_FS static void *misc_seq_start(struct seq_file *seq, loff_t *pos) { mutex_lock(&misc_mtx); return seq_list_start(&misc_list, *pos); } static void *misc_seq_next(struct seq_file *seq, void *v, loff_t *pos) { return seq_list_next(v, &misc_list, pos); } static void misc_seq_stop(struct seq_file *seq, void *v) { mutex_unlock(&misc_mtx); } static int misc_seq_show(struct seq_file *seq, void *v) { const struct miscdevice *p = list_entry(v, struct miscdevice, list); seq_printf(seq, "%3i %s\n", p->minor, p->name ? p->name : ""); return 0; } static struct seq_operations misc_seq_ops = { .start = misc_seq_start, .next = misc_seq_next, .stop = misc_seq_stop, .show = misc_seq_show, }; static int misc_seq_open(struct inode *inode, struct file *file) { return seq_open(file, &misc_seq_ops); } static const struct file_operations misc_proc_fops = { .owner = THIS_MODULE, .open = misc_seq_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release, }; #endif static int misc_open(struct inode * inode, struct file * file) { int minor = iminor(inode); struct miscdevice *c; int err = -ENODEV; const struct file_operations *old_fops, *new_fops = NULL; lock_kernel(); mutex_lock(&misc_mtx); list_for_each_entry(c, &misc_list, list) { if (c->minor == minor) { new_fops = fops_get(c->fops); break; } } if (!new_fops) { mutex_unlock(&misc_mtx); request_module("char-major-%d-%d", MISC_MAJOR, minor); mutex_lock(&misc_mtx); list_for_each_entry(c, &misc_list, list) { if (c->minor == minor) { new_fops = fops_get(c->fops); break; } } if (!new_fops) goto fail; } err = 0; old_fops = file->f_op; file->f_op = new_fops; if (file->f_op->open) { err=file->f_op->open(inode,file); if (err) { fops_put(file->f_op); file->f_op = fops_get(old_fops); } } fops_put(old_fops); fail: mutex_unlock(&misc_mtx); unlock_kernel(); return err; } static struct class *misc_class; static const struct file_operations misc_fops = { .owner = THIS_MODULE, .open = misc_open, }; /** * misc_register - register a miscellaneous device * @misc: device structure * * Register a miscellaneous device with the kernel. If the minor * number is set to %MISC_DYNAMIC_MINOR a minor number is assigned * and placed in the minor field of the structure. For other cases * the minor number requested is used. * * The structure passed is linked into the kernel and may not be * destroyed until it has been unregistered. * * A zero is returned on success and a negative errno code for * failure. */ int misc_register(struct miscdevice * misc) { struct miscdevice *c; dev_t dev; int err = 0; INIT_LIST_HEAD(&misc->list); mutex_lock(&misc_mtx); list_for_each_entry(c, &misc_list, list) { if (c->minor == misc->minor) { mutex_unlock(&misc_mtx); return -EBUSY; } } if (misc->minor == MISC_DYNAMIC_MINOR) { int i = DYNAMIC_MINORS; while (--i >= 0) if ( (misc_minors[i>>3] & (1 << (i&7))) == 0) break; if (i<0) { mutex_unlock(&misc_mtx); return -EBUSY; } misc->minor = i; } if (misc->minor < DYNAMIC_MINORS) misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7); dev = MKDEV(MISC_MAJOR, misc->minor); misc->this_device = device_create(misc_class, misc->parent, dev, NULL, "%s", misc->name); if (IS_ERR(misc->this_device)) { err = PTR_ERR(misc->this_device); goto out; } /* * Add it to the front, so that later devices can "override" * earlier defaults */ list_add(&misc->list, &misc_list); out: mutex_unlock(&misc_mtx); return err; } /** * misc_deregister - unregister a miscellaneous device * @misc: device to unregister * * Unregister a miscellaneous device that was previously * successfully registered with misc_register(). Success * is indicated by a zero return, a negative errno code * indicates an error. */ int misc_deregister(struct miscdevice *misc) { int i = misc->minor; if (list_empty(&misc->list)) return -EINVAL; mutex_lock(&misc_mtx); list_del(&misc->list); device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor)); if (i < DYNAMIC_MINORS && i>0) { misc_minors[i>>3] &= ~(1 << (misc->minor & 7)); } mutex_unlock(&misc_mtx); return 0; } EXPORT_SYMBOL(misc_register); EXPORT_SYMBOL(misc_deregister); static int __init misc_init(void) { int err; #ifdef CONFIG_PROC_FS proc_create("misc", 0, NULL, &misc_proc_fops); #endif misc_class = class_create(THIS_MODULE, "misc"); err = PTR_ERR(misc_class); if (IS_ERR(misc_class)) goto fail_remove; err = -EIO; if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) goto fail_printk; return 0; fail_printk: printk("unable to get major %d for misc devices\n", MISC_MAJOR); class_destroy(misc_class); fail_remove: remove_proc_entry("misc", NULL); return err; } subsys_initcall(misc_init);
gpl-2.0
sudosurootdev/gcc
gcc/testsuite/gcc.target/i386/sse4_1-pextrb.c
193
1877
/* { dg-do run } */ /* { dg-require-effective-target sse4 } */ /* { dg-options "-O2 -msse4.1" } */ #ifndef CHECK_H #define CHECK_H "sse4_1-check.h" #endif #ifndef TEST #define TEST sse4_1_test #endif #include CHECK_H #include <smmintrin.h> #define msk0 0 #define msk1 1 #define msk2 2 #define msk3 3 #define msk4 4 #define msk5 5 #define msk6 6 #define msk7 7 #define msk8 8 #define msk9 9 #define msk10 10 #define msk11 11 #define msk12 12 #define msk13 13 #define msk14 14 #define msk15 15 static void TEST (void) { union { __m128i x; int i[4]; char c[16]; } val1; int res[16], masks[16]; int i; val1.i[0] = 0x04030201; val1.i[1] = 0x08070605; val1.i[2] = 0x0C0B0A09; val1.i[3] = 0x100F0E0D; res[0] = _mm_extract_epi8 (val1.x, msk0); res[1] = _mm_extract_epi8 (val1.x, msk1); res[2] = _mm_extract_epi8 (val1.x, msk2); res[3] = _mm_extract_epi8 (val1.x, msk3); res[4] = _mm_extract_epi8 (val1.x, msk4); res[5] = _mm_extract_epi8 (val1.x, msk5); res[6] = _mm_extract_epi8 (val1.x, msk6); res[7] = _mm_extract_epi8 (val1.x, msk7); res[8] = _mm_extract_epi8 (val1.x, msk8); res[9] = _mm_extract_epi8 (val1.x, msk9); res[10] = _mm_extract_epi8 (val1.x, msk10); res[11] = _mm_extract_epi8 (val1.x, msk11); res[12] = _mm_extract_epi8 (val1.x, msk12); res[13] = _mm_extract_epi8 (val1.x, msk13); res[14] = _mm_extract_epi8 (val1.x, msk14); res[15] = _mm_extract_epi8 (val1.x, msk15); masks[0] = msk0; masks[1] = msk1; masks[2] = msk2; masks[3] = msk3; masks[4] = msk4; masks[5] = msk5; masks[6] = msk6; masks[7] = msk7; masks[8] = msk8; masks[9] = msk9; masks[10] = msk10; masks[11] = msk11; masks[12] = msk12; masks[13] = msk13; masks[14] = msk14; masks[15] = msk15; for (i = 0; i < 16; i++) if (res[i] != val1.c [masks[i]]) abort (); }
gpl-2.0
LeJay/android_kernel_samsung_jactiveltexx
arch/arm/mach-msm/sdio_tty.c
1473
21634
/* Copyright (c) 2011, 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/slab.h> #include <linux/sched.h> #include <linux/wait.h> #include <linux/workqueue.h> #include <linux/platform_device.h> #include <linux/tty.h> #include <linux/tty_flip.h> #include <linux/module.h> #include <linux/debugfs.h> #include <mach/sdio_al.h> #define INPUT_SPEED 4800 #define OUTPUT_SPEED 4800 #define SDIO_TTY_MODULE_NAME "sdio_tty" #define SDIO_TTY_MAX_PACKET_SIZE 4096 #define MAX_SDIO_TTY_DRV 1 #define MAX_SDIO_TTY_DEVS 2 #define MAX_SDIO_TTY_DEV_NAME_SIZE 25 /* Configurations per channel device */ /* CSVT */ #define SDIO_TTY_CSVT_DEV "sdio_tty_csvt_0" #define SDIO_TTY_CSVT_TEST_DEV "sdio_tty_csvt_test_0" #define SDIO_TTY_CH_CSVT "SDIO_CSVT" enum sdio_tty_state { TTY_INITIAL = 0, TTY_REGISTERED = 1, TTY_OPENED = 2, TTY_CLOSED = 3, }; enum sdio_tty_devices { SDIO_CSVT, SDIO_CSVT_TEST_APP, }; static const struct platform_device_id sdio_tty_id_table[] = { { "SDIO_CSVT", SDIO_CSVT }, { "SDIO_CSVT_TEST_APP", SDIO_CSVT_TEST_APP }, { }, }; MODULE_DEVICE_TABLE(platform, sdio_tty_id_table); struct sdio_tty { struct sdio_channel *ch; char *sdio_ch_name; char tty_dev_name[MAX_SDIO_TTY_DEV_NAME_SIZE]; int device_id; struct workqueue_struct *workq; struct work_struct work_read; wait_queue_head_t waitq; struct tty_driver *tty_drv; struct tty_struct *tty_str; int debug_msg_on; char *read_buf; enum sdio_tty_state sdio_tty_state; int is_sdio_open; int tty_open_count; int total_rx; int total_tx; }; static struct sdio_tty *sdio_tty[MAX_SDIO_TTY_DEVS]; #ifdef CONFIG_DEBUG_FS struct dentry *sdio_tty_debug_root; struct dentry *sdio_tty_debug_info; #endif #define DEBUG_MSG(sdio_tty_drv, x...) if (sdio_tty_drv->debug_msg_on) pr_info(x) /* * Enable sdio_tty debug messages * By default the sdio_tty debug messages are turned off */ static int csvt_debug_msg_on; module_param(csvt_debug_msg_on, int, 0); static void sdio_tty_read(struct work_struct *work) { int ret = 0; int read_avail = 0; int left = 0; int total_push = 0; int num_push = 0; struct sdio_tty *sdio_tty_drv = NULL; sdio_tty_drv = container_of(work, struct sdio_tty, work_read); if (!sdio_tty_drv) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL sdio_tty", __func__); return ; } if (sdio_tty_drv->sdio_tty_state != TTY_OPENED) { pr_err(SDIO_TTY_MODULE_NAME ": %s: sdio_tty_state = %d", __func__, sdio_tty_drv->sdio_tty_state); return; } if (!sdio_tty_drv->read_buf) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL read_buf for dev %s", __func__, sdio_tty_drv->tty_dev_name); return; } /* Read the data from the SDIO channel as long as there is available data */ while (1) { if (test_bit(TTY_THROTTLED, &sdio_tty_drv->tty_str->flags)) { DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: TTY_THROTTLED bit is set for " "dev %s, exit", __func__, sdio_tty_drv->tty_dev_name); return; } total_push = 0; read_avail = sdio_read_avail(sdio_tty_drv->ch); DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: read_avail is %d for dev %s", __func__, read_avail, sdio_tty_drv->tty_dev_name); if (read_avail == 0) { DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: read_avail is 0 for dev %s", __func__, sdio_tty_drv->tty_dev_name); return; } if (read_avail > SDIO_TTY_MAX_PACKET_SIZE) { pr_err(SDIO_TTY_MODULE_NAME ": %s: read_avail(%d) is " "bigger than SDIO_TTY_MAX_PACKET_SIZE(%d) " "for dev %s", __func__, read_avail, SDIO_TTY_MAX_PACKET_SIZE, sdio_tty_drv->tty_dev_name); return; } ret = sdio_read(sdio_tty_drv->ch, sdio_tty_drv->read_buf, read_avail); if (ret < 0) { pr_err(SDIO_TTY_MODULE_NAME ": %s: sdio_read error(%d) " "for dev %s", __func__, ret, sdio_tty_drv->tty_dev_name); return; } left = read_avail; do { num_push = tty_insert_flip_string( sdio_tty_drv->tty_str, sdio_tty_drv->read_buf+total_push, left); total_push += num_push; left -= num_push; tty_flip_buffer_push(sdio_tty_drv->tty_str); } while (left != 0); if (total_push != read_avail) { pr_err(SDIO_TTY_MODULE_NAME ": %s: failed, total_push" "(%d) != read_avail(%d) for dev %s\n", __func__, total_push, read_avail, sdio_tty_drv->tty_dev_name); } tty_flip_buffer_push(sdio_tty_drv->tty_str); sdio_tty_drv->total_rx += read_avail; DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: Rx: %d, " "Total Rx = %d bytes for dev %s", __func__, read_avail, sdio_tty_drv->total_rx, sdio_tty_drv->tty_dev_name); } } /** * sdio_tty_write_room * * This is the write_room function of the tty driver. * * @tty: pointer to tty struct. * @return free bytes for write. * */ static int sdio_tty_write_room(struct tty_struct *tty) { int write_avail = 0; struct sdio_tty *sdio_tty_drv = NULL; if (!tty) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL tty", __func__); return -ENODEV; } sdio_tty_drv = tty->driver_data; if (!sdio_tty_drv) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL sdio_tty_drv", __func__); return -ENODEV; } if (sdio_tty_drv->sdio_tty_state != TTY_OPENED) { pr_err(SDIO_TTY_MODULE_NAME ": %s: sdio_tty_state = %d", __func__, sdio_tty_drv->sdio_tty_state); return -EPERM; } write_avail = sdio_write_avail(sdio_tty_drv->ch); DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: write_avail=%d " "for dev %s", __func__, write_avail, sdio_tty_drv->tty_dev_name); return write_avail; } /** * sdio_tty_write_callback * this is the write callback of the tty driver. * * @tty: pointer to tty struct. * @buf: buffer to write from. * @count: number of bytes to write. * @return bytes written or negative value on error. * * if destination buffer has not enough room for the incoming * data, writes the possible amount of bytes . */ static int sdio_tty_write_callback(struct tty_struct *tty, const unsigned char *buf, int count) { int write_avail = 0; int len = count; int ret = 0; struct sdio_tty *sdio_tty_drv = NULL; if (!tty) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL tty", __func__); return -ENODEV; } sdio_tty_drv = tty->driver_data; if (!sdio_tty_drv) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL sdio_tty_drv", __func__); return -ENODEV; } if (sdio_tty_drv->sdio_tty_state != TTY_OPENED) { pr_err(SDIO_TTY_MODULE_NAME ": %s: sdio_tty_state = %d", __func__, sdio_tty_drv->sdio_tty_state); return -EPERM; } DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: Write Callback " "called with %d bytes for dev %s\n", __func__, count, sdio_tty_drv->tty_dev_name); write_avail = sdio_write_avail(sdio_tty_drv->ch); if (write_avail == 0) { DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: " "write_avail is 0 for dev %s\n", __func__, sdio_tty_drv->tty_dev_name); return 0; } if (write_avail > SDIO_TTY_MAX_PACKET_SIZE) { DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: " "write_avail(%d) is bigger than max packet " "size(%d) for dev %s, setting to " "max_packet_size\n", __func__, write_avail, SDIO_TTY_MAX_PACKET_SIZE, sdio_tty_drv->tty_dev_name); write_avail = SDIO_TTY_MAX_PACKET_SIZE; } if (write_avail < count) { DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: " "write_avail(%d) is smaller than required(%d) " "for dev %s, writing only %d bytes\n", __func__, write_avail, count, sdio_tty_drv->tty_dev_name, write_avail); len = write_avail; } ret = sdio_write(sdio_tty_drv->ch, buf, len); if (ret) { pr_err(SDIO_TTY_MODULE_NAME ": %s: sdio_write failed for " "dev %s, ret=%d\n", __func__, sdio_tty_drv->tty_dev_name, ret); return 0; } sdio_tty_drv->total_tx += len; DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: Tx: %d, " "Total Tx = %d for dev %s", __func__, len, sdio_tty_drv->total_tx, sdio_tty_drv->tty_dev_name); return len; } static void sdio_tty_notify(void *priv, unsigned event) { struct sdio_tty *sdio_tty_drv = priv; if (!sdio_tty_drv) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL sdio_tty_drv", __func__); } if (sdio_tty_drv->sdio_tty_state != TTY_OPENED) { pr_err(SDIO_TTY_MODULE_NAME ": %s: sdio_tty_state = %d", __func__, sdio_tty_drv->sdio_tty_state); return; } DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: event %d " "received for dev %s\n", __func__, event, sdio_tty_drv->tty_dev_name); if (event == SDIO_EVENT_DATA_READ_AVAIL) queue_work(sdio_tty_drv->workq, &sdio_tty_drv->work_read); } /** * sdio_tty_open * This is the open callback of the tty driver. it opens * the sdio channel, and creates the workqueue. * * @tty: a pointer to the tty struct. * @file: file descriptor. * @return 0 on success or negative value on error. */ static int sdio_tty_open(struct tty_struct *tty, struct file *file) { int ret = 0; int i = 0; struct sdio_tty *sdio_tty_drv = NULL; if (!tty) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL tty", __func__); return -ENODEV; } for (i = 0; i < MAX_SDIO_TTY_DEVS; i++) { if (sdio_tty[i] == NULL) continue; if (!strncmp(sdio_tty[i]->tty_dev_name, tty->name, MAX_SDIO_TTY_DEV_NAME_SIZE)) { sdio_tty_drv = sdio_tty[i]; break; } } if (!sdio_tty_drv) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL sdio_tty_drv", __func__); return -ENODEV; } sdio_tty_drv->tty_open_count++; if (sdio_tty_drv->sdio_tty_state == TTY_OPENED) { pr_err(SDIO_TTY_MODULE_NAME ": %s: tty dev(%s) is already open", __func__, sdio_tty_drv->tty_dev_name); return -EBUSY; } tty->driver_data = sdio_tty_drv; sdio_tty_drv->tty_str = tty; sdio_tty_drv->tty_str->low_latency = 1; sdio_tty_drv->tty_str->icanon = 0; set_bit(TTY_NO_WRITE_SPLIT, &sdio_tty_drv->tty_str->flags); sdio_tty_drv->read_buf = kzalloc(SDIO_TTY_MAX_PACKET_SIZE, GFP_KERNEL); if (sdio_tty_drv->read_buf == NULL) { pr_err(SDIO_TTY_MODULE_NAME ": %s: failed to allocate read_buf " "for dev %s", __func__, sdio_tty_drv->tty_dev_name); return -ENOMEM; } sdio_tty_drv->workq = create_singlethread_workqueue("sdio_tty_read"); if (!sdio_tty_drv->workq) { pr_err(SDIO_TTY_MODULE_NAME ": %s: failed to create workq " "for dev %s", __func__, sdio_tty_drv->tty_dev_name); return -ENOMEM; } if (!sdio_tty_drv->is_sdio_open) { ret = sdio_open(sdio_tty_drv->sdio_ch_name, &sdio_tty_drv->ch, sdio_tty_drv, sdio_tty_notify); if (ret < 0) { pr_err(SDIO_TTY_MODULE_NAME ": %s: sdio_open err=%d " "for dev %s\n", __func__, ret, sdio_tty_drv->tty_dev_name); destroy_workqueue(sdio_tty_drv->workq); return ret; } pr_info(SDIO_TTY_MODULE_NAME ": %s: SDIO_TTY channel(%s) " "opened\n", __func__, sdio_tty_drv->sdio_ch_name); sdio_tty_drv->is_sdio_open = 1; } else { /* If SDIO channel is already open try to read the data * from the modem */ queue_work(sdio_tty_drv->workq, &sdio_tty_drv->work_read); } sdio_tty_drv->sdio_tty_state = TTY_OPENED; pr_info(SDIO_TTY_MODULE_NAME ": %s: TTY device(%s) opened\n", __func__, sdio_tty_drv->tty_dev_name); return ret; } /** * sdio_tty_close * This is the close callback of the tty driver. it requests * the main thread to exit, and waits for notification of it. * it also de-allocates the buffers, and unregisters the tty * driver and device. * * @tty: a pointer to the tty struct. * @file: file descriptor. * @return None. */ static void sdio_tty_close(struct tty_struct *tty, struct file *file) { struct sdio_tty *sdio_tty_drv = NULL; if (!tty) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL tty", __func__); return; } sdio_tty_drv = tty->driver_data; if (!sdio_tty_drv) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL sdio_tty_drv", __func__); return; } if (sdio_tty_drv->sdio_tty_state != TTY_OPENED) { pr_err(SDIO_TTY_MODULE_NAME ": %s: trying to close a " "TTY device that was not opened\n", __func__); return; } if (--sdio_tty_drv->tty_open_count != 0) return; flush_workqueue(sdio_tty_drv->workq); destroy_workqueue(sdio_tty_drv->workq); kfree(sdio_tty_drv->read_buf); sdio_tty_drv->read_buf = NULL; sdio_tty_drv->sdio_tty_state = TTY_CLOSED; pr_info(SDIO_TTY_MODULE_NAME ": %s: SDIO_TTY device(%s) closed\n", __func__, sdio_tty_drv->tty_dev_name); } static void sdio_tty_unthrottle(struct tty_struct *tty) { struct sdio_tty *sdio_tty_drv = NULL; if (!tty) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL tty", __func__); return; } sdio_tty_drv = tty->driver_data; if (!sdio_tty_drv) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL sdio_tty_drv", __func__); return; } if (sdio_tty_drv->sdio_tty_state != TTY_OPENED) { pr_err(SDIO_TTY_MODULE_NAME ": %s: sdio_tty_state = %d", __func__, sdio_tty_drv->sdio_tty_state); return; } queue_work(sdio_tty_drv->workq, &sdio_tty_drv->work_read); return; } static const struct tty_operations sdio_tty_ops = { .open = sdio_tty_open, .close = sdio_tty_close, .write = sdio_tty_write_callback, .write_room = sdio_tty_write_room, .unthrottle = sdio_tty_unthrottle, }; int sdio_tty_init_tty(char *tty_name, char *sdio_ch_name, enum sdio_tty_devices device_id, int debug_msg_on) { int ret = 0; int i = 0; struct device *tty_dev = NULL; struct sdio_tty *sdio_tty_drv = NULL; sdio_tty_drv = kzalloc(sizeof(struct sdio_tty), GFP_KERNEL); if (sdio_tty_drv == NULL) { pr_err(SDIO_TTY_MODULE_NAME ": %s: failed to allocate sdio_tty " "for dev %s", __func__, tty_name); return -ENOMEM; } for (i = 0; i < MAX_SDIO_TTY_DEVS; i++) { if (sdio_tty[i] == NULL) { sdio_tty[i] = sdio_tty_drv; break; } } if (i == MAX_SDIO_TTY_DEVS) { pr_err(SDIO_TTY_MODULE_NAME ": %s: tty dev(%s) creation failed," " max limit(%d) reached.", __func__, tty_name, MAX_SDIO_TTY_DEVS); kfree(sdio_tty_drv); return -ENODEV; } snprintf(sdio_tty_drv->tty_dev_name, MAX_SDIO_TTY_DEV_NAME_SIZE, "%s%d", tty_name, 0); sdio_tty_drv->sdio_ch_name = sdio_ch_name; sdio_tty_drv->device_id = device_id; pr_info(SDIO_TTY_MODULE_NAME ": %s: dev=%s, id=%d, channel=%s\n", __func__, sdio_tty_drv->tty_dev_name, sdio_tty_drv->device_id, sdio_tty_drv->sdio_ch_name); INIT_WORK(&sdio_tty_drv->work_read, sdio_tty_read); sdio_tty_drv->tty_drv = alloc_tty_driver(MAX_SDIO_TTY_DRV); if (!sdio_tty_drv->tty_drv) { pr_err(SDIO_TTY_MODULE_NAME ": %s - tty_drv is NULL for dev %s", __func__, sdio_tty_drv->tty_dev_name); kfree(sdio_tty_drv); return -ENODEV; } sdio_tty_drv->tty_drv->name = tty_name; sdio_tty_drv->tty_drv->owner = THIS_MODULE; sdio_tty_drv->tty_drv->driver_name = "SDIO_tty"; /* uses dynamically assigned dev_t values */ sdio_tty_drv->tty_drv->type = TTY_DRIVER_TYPE_SERIAL; sdio_tty_drv->tty_drv->subtype = SERIAL_TYPE_NORMAL; sdio_tty_drv->tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_RESET_TERMIOS; /* initializing the tty driver */ sdio_tty_drv->tty_drv->init_termios = tty_std_termios; sdio_tty_drv->tty_drv->init_termios.c_cflag = B4800 | CS8 | CREAD | HUPCL | CLOCAL; sdio_tty_drv->tty_drv->init_termios.c_ispeed = INPUT_SPEED; sdio_tty_drv->tty_drv->init_termios.c_ospeed = OUTPUT_SPEED; tty_set_operations(sdio_tty_drv->tty_drv, &sdio_tty_ops); ret = tty_register_driver(sdio_tty_drv->tty_drv); if (ret) { put_tty_driver(sdio_tty_drv->tty_drv); pr_err(SDIO_TTY_MODULE_NAME ": %s: tty_register_driver() " "failed for dev %s\n", __func__, sdio_tty_drv->tty_dev_name); sdio_tty_drv->tty_drv = NULL; kfree(sdio_tty_drv); return -ENODEV; } tty_dev = tty_register_device(sdio_tty_drv->tty_drv, 0, NULL); if (IS_ERR(tty_dev)) { pr_err(SDIO_TTY_MODULE_NAME ": %s: tty_register_device() " "failed for dev %s\n", __func__, sdio_tty_drv->tty_dev_name); tty_unregister_driver(sdio_tty_drv->tty_drv); put_tty_driver(sdio_tty_drv->tty_drv); kfree(sdio_tty_drv); return -ENODEV; } sdio_tty_drv->sdio_tty_state = TTY_REGISTERED; if (debug_msg_on) { pr_info(SDIO_TTY_MODULE_NAME ": %s: turn on debug msg for %s", __func__, sdio_tty_drv->tty_dev_name); sdio_tty_drv->debug_msg_on = debug_msg_on; } return 0; } int sdio_tty_uninit_tty(void *sdio_tty_handle) { int ret = 0; int i = 0; struct sdio_tty *sdio_tty_drv = sdio_tty_handle; if (!sdio_tty_drv) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL sdio_tty_drv", __func__); return -ENODEV; } if (sdio_tty_drv->sdio_tty_state == TTY_OPENED) { flush_workqueue(sdio_tty_drv->workq); destroy_workqueue(sdio_tty_drv->workq); kfree(sdio_tty_drv->read_buf); sdio_tty_drv->read_buf = NULL; } if (sdio_tty_drv->sdio_tty_state != TTY_INITIAL) { tty_unregister_device(sdio_tty_drv->tty_drv, 0); ret = tty_unregister_driver(sdio_tty_drv->tty_drv); if (ret) { pr_err(SDIO_TTY_MODULE_NAME ": %s: " "tty_unregister_driver() failed for dev %s\n", __func__, sdio_tty_drv->tty_dev_name); } put_tty_driver(sdio_tty_drv->tty_drv); sdio_tty_drv->sdio_tty_state = TTY_INITIAL; sdio_tty_drv->tty_drv = NULL; } for (i = 0; i < MAX_SDIO_TTY_DEVS; i++) { if (sdio_tty[i] == NULL) continue; if (sdio_tty[i]->device_id == sdio_tty_drv->device_id) { sdio_tty[i] = NULL; break; } } DEBUG_MSG(sdio_tty_drv, SDIO_TTY_MODULE_NAME ": %s: Freeing sdio_tty " "structure, dev=%s", __func__, sdio_tty_drv->tty_dev_name); kfree(sdio_tty_drv); return 0; } static int sdio_tty_probe(struct platform_device *pdev) { const struct platform_device_id *id = platform_get_device_id(pdev); enum sdio_tty_devices device_id = id->driver_data; char *device_name = NULL; char *channel_name = NULL; int debug_msg_on = 0; int ret = 0; pr_debug(SDIO_TTY_MODULE_NAME ": %s for %s", __func__, pdev->name); switch (device_id) { case SDIO_CSVT: device_name = SDIO_TTY_CSVT_DEV; channel_name = SDIO_TTY_CH_CSVT; debug_msg_on = csvt_debug_msg_on; break; case SDIO_CSVT_TEST_APP: device_name = SDIO_TTY_CSVT_TEST_DEV; channel_name = SDIO_TTY_CH_CSVT; debug_msg_on = csvt_debug_msg_on; break; default: pr_err(SDIO_TTY_MODULE_NAME ": %s Invalid device:%s, id:%d", __func__, pdev->name, device_id); ret = -ENODEV; break; } if (device_name) { ret = sdio_tty_init_tty(device_name, channel_name, device_id, debug_msg_on); if (ret) { pr_err(SDIO_TTY_MODULE_NAME ": %s: sdio_tty_init_tty " "failed for dev:%s", __func__, device_name); } } return ret; } static int sdio_tty_remove(struct platform_device *pdev) { const struct platform_device_id *id = platform_get_device_id(pdev); enum sdio_tty_devices device_id = id->driver_data; struct sdio_tty *sdio_tty_drv = NULL; int i = 0; int ret = 0; pr_debug(SDIO_TTY_MODULE_NAME ": %s for %s", __func__, pdev->name); for (i = 0; i < MAX_SDIO_TTY_DEVS; i++) { if (sdio_tty[i] == NULL) continue; if (sdio_tty[i]->device_id == device_id) { sdio_tty_drv = sdio_tty[i]; break; } } if (!sdio_tty_drv) { pr_err(SDIO_TTY_MODULE_NAME ": %s: NULL sdio_tty_drv", __func__); return -ENODEV; } ret = sdio_tty_uninit_tty(sdio_tty_drv); if (ret) { pr_err(SDIO_TTY_MODULE_NAME ": %s: sdio_tty_uninit_tty " "failed for %s", __func__, pdev->name); } return ret; } static struct platform_driver sdio_tty_pdrv = { .probe = sdio_tty_probe, .remove = sdio_tty_remove, .id_table = sdio_tty_id_table, .driver = { .name = "SDIO_TTY", .owner = THIS_MODULE, }, }; #ifdef CONFIG_DEBUG_FS void sdio_tty_print_info(void) { int i = 0; for (i = 0; i < MAX_SDIO_TTY_DEVS; i++) { if (sdio_tty[i] == NULL) continue; pr_info(SDIO_TTY_MODULE_NAME ": %s: Total Rx=%d, Tx = %d " "for dev %s", __func__, sdio_tty[i]->total_rx, sdio_tty[i]->total_tx, sdio_tty[i]->tty_dev_name); } } static int tty_debug_info_open(struct inode *inode, struct file *file) { file->private_data = inode->i_private; return 0; } static ssize_t tty_debug_info_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { sdio_tty_print_info(); return count; } const struct file_operations tty_debug_info_ops = { .open = tty_debug_info_open, .write = tty_debug_info_write, }; #endif /* * Module Init. * * Register SDIO TTY driver. * */ static int __init sdio_tty_init(void) { int ret = 0; ret = platform_driver_register(&sdio_tty_pdrv); if (ret) { pr_err(SDIO_TTY_MODULE_NAME ": %s: platform_driver_register " "failed", __func__); } #ifdef CONFIG_DEBUG_FS else { sdio_tty_debug_root = debugfs_create_dir("sdio_tty", NULL); if (sdio_tty_debug_root) { sdio_tty_debug_info = debugfs_create_file( "sdio_tty_debug", S_IRUGO | S_IWUGO, sdio_tty_debug_root, NULL, &tty_debug_info_ops); } } #endif return ret; }; /* * Module Exit. * * Unregister SDIO TTY driver. * */ static void __exit sdio_tty_exit(void) { #ifdef CONFIG_DEBUG_FS debugfs_remove(sdio_tty_debug_info); debugfs_remove(sdio_tty_debug_root); #endif platform_driver_unregister(&sdio_tty_pdrv); } module_init(sdio_tty_init); module_exit(sdio_tty_exit); MODULE_DESCRIPTION("SDIO TTY"); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Maya Erez <merez@codeaurora.org>");
gpl-2.0
dutchanddutch/ti81xx-linux
drivers/hwmon/f71805f.c
1473
49345
/* * f71805f.c - driver for the Fintek F71805F/FG and F71872F/FG Super-I/O * chips integrated hardware monitoring features * Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org> * * The F71805F/FG is a LPC Super-I/O chip made by Fintek. It integrates * complete hardware monitoring features: voltage, fan and temperature * sensors, and manual and automatic fan speed control. * * The F71872F/FG is almost the same, with two more voltages monitored, * and 6 VID inputs. * * The F71806F/FG is essentially the same as the F71872F/FG. It even has * the same chip ID, so the driver can't differentiate between. * * 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 <linux/slab.h> #include <linux/jiffies.h> #include <linux/platform_device.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h> #include <linux/mutex.h> #include <linux/sysfs.h> #include <linux/ioport.h> #include <linux/acpi.h> #include <linux/io.h> static unsigned short force_id; module_param(force_id, ushort, 0); MODULE_PARM_DESC(force_id, "Override the detected device ID"); static struct platform_device *pdev; #define DRVNAME "f71805f" enum kinds { f71805f, f71872f }; /* * Super-I/O constants and functions */ #define F71805F_LD_HWM 0x04 #define SIO_REG_LDSEL 0x07 /* Logical device select */ #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */ #define SIO_REG_DEVREV 0x22 /* Device revision */ #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */ #define SIO_REG_FNSEL1 0x29 /* Multi Function Select 1 (F71872F) */ #define SIO_REG_ENABLE 0x30 /* Logical device enable */ #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ #define SIO_FINTEK_ID 0x1934 #define SIO_F71805F_ID 0x0406 #define SIO_F71872F_ID 0x0341 static inline int superio_inb(int base, int reg) { outb(reg, base); return inb(base + 1); } static int superio_inw(int base, int reg) { int val; outb(reg++, base); val = inb(base + 1) << 8; outb(reg, base); val |= inb(base + 1); return val; } static inline void superio_select(int base, int ld) { outb(SIO_REG_LDSEL, base); outb(ld, base + 1); } static inline void superio_enter(int base) { outb(0x87, base); outb(0x87, base); } static inline void superio_exit(int base) { outb(0xaa, base); } /* * ISA constants */ #define REGION_LENGTH 8 #define ADDR_REG_OFFSET 5 #define DATA_REG_OFFSET 6 /* * Registers */ /* in nr from 0 to 10 (8-bit values) */ #define F71805F_REG_IN(nr) (0x10 + (nr)) #define F71805F_REG_IN_HIGH(nr) ((nr) < 10 ? 0x40 + 2 * (nr) : 0x2E) #define F71805F_REG_IN_LOW(nr) ((nr) < 10 ? 0x41 + 2 * (nr) : 0x2F) /* fan nr from 0 to 2 (12-bit values, two registers) */ #define F71805F_REG_FAN(nr) (0x20 + 2 * (nr)) #define F71805F_REG_FAN_LOW(nr) (0x28 + 2 * (nr)) #define F71805F_REG_FAN_TARGET(nr) (0x69 + 16 * (nr)) #define F71805F_REG_FAN_CTRL(nr) (0x60 + 16 * (nr)) #define F71805F_REG_PWM_FREQ(nr) (0x63 + 16 * (nr)) #define F71805F_REG_PWM_DUTY(nr) (0x6B + 16 * (nr)) /* temp nr from 0 to 2 (8-bit values) */ #define F71805F_REG_TEMP(nr) (0x1B + (nr)) #define F71805F_REG_TEMP_HIGH(nr) (0x54 + 2 * (nr)) #define F71805F_REG_TEMP_HYST(nr) (0x55 + 2 * (nr)) #define F71805F_REG_TEMP_MODE 0x01 /* pwm/fan pwmnr from 0 to 2, auto point apnr from 0 to 2 */ /* map Fintek numbers to our numbers as follows: 9->0, 5->1, 1->2 */ #define F71805F_REG_PWM_AUTO_POINT_TEMP(pwmnr, apnr) \ (0xA0 + 0x10 * (pwmnr) + (2 - (apnr))) #define F71805F_REG_PWM_AUTO_POINT_FAN(pwmnr, apnr) \ (0xA4 + 0x10 * (pwmnr) + \ 2 * (2 - (apnr))) #define F71805F_REG_START 0x00 /* status nr from 0 to 2 */ #define F71805F_REG_STATUS(nr) (0x36 + (nr)) /* individual register bits */ #define FAN_CTRL_DC_MODE 0x10 #define FAN_CTRL_LATCH_FULL 0x08 #define FAN_CTRL_MODE_MASK 0x03 #define FAN_CTRL_MODE_SPEED 0x00 #define FAN_CTRL_MODE_TEMPERATURE 0x01 #define FAN_CTRL_MODE_MANUAL 0x02 /* * Data structures and manipulation thereof */ struct f71805f_auto_point { u8 temp[3]; u16 fan[3]; }; struct f71805f_data { unsigned short addr; const char *name; struct device *hwmon_dev; struct mutex update_lock; char valid; /* !=0 if following fields are valid */ unsigned long last_updated; /* In jiffies */ unsigned long last_limits; /* In jiffies */ /* Register values */ u8 in[11]; u8 in_high[11]; u8 in_low[11]; u16 has_in; u16 fan[3]; u16 fan_low[3]; u16 fan_target[3]; u8 fan_ctrl[3]; u8 pwm[3]; u8 pwm_freq[3]; u8 temp[3]; u8 temp_high[3]; u8 temp_hyst[3]; u8 temp_mode; unsigned long alarms; struct f71805f_auto_point auto_points[3]; }; struct f71805f_sio_data { enum kinds kind; u8 fnsel1; }; static inline long in_from_reg(u8 reg) { return (reg * 8); } /* The 2 least significant bits are not used */ static inline u8 in_to_reg(long val) { if (val <= 0) return 0; if (val >= 2016) return 0xfc; return (((val + 16) / 32) << 2); } /* in0 is downscaled by a factor 2 internally */ static inline long in0_from_reg(u8 reg) { return (reg * 16); } static inline u8 in0_to_reg(long val) { if (val <= 0) return 0; if (val >= 4032) return 0xfc; return (((val + 32) / 64) << 2); } /* The 4 most significant bits are not used */ static inline long fan_from_reg(u16 reg) { reg &= 0xfff; if (!reg || reg == 0xfff) return 0; return (1500000 / reg); } static inline u16 fan_to_reg(long rpm) { /* If the low limit is set below what the chip can measure, store the largest possible 12-bit value in the registers, so that no alarm will ever trigger. */ if (rpm < 367) return 0xfff; return (1500000 / rpm); } static inline unsigned long pwm_freq_from_reg(u8 reg) { unsigned long clock = (reg & 0x80) ? 48000000UL : 1000000UL; reg &= 0x7f; if (reg == 0) reg++; return clock / (reg << 8); } static inline u8 pwm_freq_to_reg(unsigned long val) { if (val >= 187500) /* The highest we can do */ return 0x80; if (val >= 1475) /* Use 48 MHz clock */ return 0x80 | (48000000UL / (val << 8)); if (val < 31) /* The lowest we can do */ return 0x7f; else /* Use 1 MHz clock */ return 1000000UL / (val << 8); } static inline int pwm_mode_from_reg(u8 reg) { return !(reg & FAN_CTRL_DC_MODE); } static inline long temp_from_reg(u8 reg) { return (reg * 1000); } static inline u8 temp_to_reg(long val) { if (val < 0) val = 0; else if (val > 1000 * 0xff) val = 0xff; return ((val + 500) / 1000); } /* * Device I/O access */ /* Must be called with data->update_lock held, except during initialization */ static u8 f71805f_read8(struct f71805f_data *data, u8 reg) { outb(reg, data->addr + ADDR_REG_OFFSET); return inb(data->addr + DATA_REG_OFFSET); } /* Must be called with data->update_lock held, except during initialization */ static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val) { outb(reg, data->addr + ADDR_REG_OFFSET); outb(val, data->addr + DATA_REG_OFFSET); } /* It is important to read the MSB first, because doing so latches the value of the LSB, so we are sure both bytes belong to the same value. Must be called with data->update_lock held, except during initialization */ static u16 f71805f_read16(struct f71805f_data *data, u8 reg) { u16 val; outb(reg, data->addr + ADDR_REG_OFFSET); val = inb(data->addr + DATA_REG_OFFSET) << 8; outb(++reg, data->addr + ADDR_REG_OFFSET); val |= inb(data->addr + DATA_REG_OFFSET); return val; } /* Must be called with data->update_lock held, except during initialization */ static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val) { outb(reg, data->addr + ADDR_REG_OFFSET); outb(val >> 8, data->addr + DATA_REG_OFFSET); outb(++reg, data->addr + ADDR_REG_OFFSET); outb(val & 0xff, data->addr + DATA_REG_OFFSET); } static struct f71805f_data *f71805f_update_device(struct device *dev) { struct f71805f_data *data = dev_get_drvdata(dev); int nr, apnr; mutex_lock(&data->update_lock); /* Limit registers cache is refreshed after 60 seconds */ if (time_after(jiffies, data->last_updated + 60 * HZ) || !data->valid) { for (nr = 0; nr < 11; nr++) { if (!(data->has_in & (1 << nr))) continue; data->in_high[nr] = f71805f_read8(data, F71805F_REG_IN_HIGH(nr)); data->in_low[nr] = f71805f_read8(data, F71805F_REG_IN_LOW(nr)); } for (nr = 0; nr < 3; nr++) { data->fan_low[nr] = f71805f_read16(data, F71805F_REG_FAN_LOW(nr)); data->fan_target[nr] = f71805f_read16(data, F71805F_REG_FAN_TARGET(nr)); data->pwm_freq[nr] = f71805f_read8(data, F71805F_REG_PWM_FREQ(nr)); } for (nr = 0; nr < 3; nr++) { data->temp_high[nr] = f71805f_read8(data, F71805F_REG_TEMP_HIGH(nr)); data->temp_hyst[nr] = f71805f_read8(data, F71805F_REG_TEMP_HYST(nr)); } data->temp_mode = f71805f_read8(data, F71805F_REG_TEMP_MODE); for (nr = 0; nr < 3; nr++) { for (apnr = 0; apnr < 3; apnr++) { data->auto_points[nr].temp[apnr] = f71805f_read8(data, F71805F_REG_PWM_AUTO_POINT_TEMP(nr, apnr)); data->auto_points[nr].fan[apnr] = f71805f_read16(data, F71805F_REG_PWM_AUTO_POINT_FAN(nr, apnr)); } } data->last_limits = jiffies; } /* Measurement registers cache is refreshed after 1 second */ if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { for (nr = 0; nr < 11; nr++) { if (!(data->has_in & (1 << nr))) continue; data->in[nr] = f71805f_read8(data, F71805F_REG_IN(nr)); } for (nr = 0; nr < 3; nr++) { data->fan[nr] = f71805f_read16(data, F71805F_REG_FAN(nr)); data->fan_ctrl[nr] = f71805f_read8(data, F71805F_REG_FAN_CTRL(nr)); data->pwm[nr] = f71805f_read8(data, F71805F_REG_PWM_DUTY(nr)); } for (nr = 0; nr < 3; nr++) { data->temp[nr] = f71805f_read8(data, F71805F_REG_TEMP(nr)); } data->alarms = f71805f_read8(data, F71805F_REG_STATUS(0)) + (f71805f_read8(data, F71805F_REG_STATUS(1)) << 8) + (f71805f_read8(data, F71805F_REG_STATUS(2)) << 16); data->last_updated = jiffies; data->valid = 1; } mutex_unlock(&data->update_lock); return data; } /* * Sysfs interface */ static ssize_t show_in0(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", in0_from_reg(data->in[nr])); } static ssize_t show_in0_max(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", in0_from_reg(data->in_high[nr])); } static ssize_t show_in0_min(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", in0_from_reg(data->in_low[nr])); } static ssize_t set_in0_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->in_high[nr] = in0_to_reg(val); f71805f_write8(data, F71805F_REG_IN_HIGH(nr), data->in_high[nr]); mutex_unlock(&data->update_lock); return count; } static ssize_t set_in0_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->in_low[nr] = in0_to_reg(val); f71805f_write8(data, F71805F_REG_IN_LOW(nr), data->in_low[nr]); mutex_unlock(&data->update_lock); return count; } static ssize_t show_in(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", in_from_reg(data->in[nr])); } static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", in_from_reg(data->in_high[nr])); } static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", in_from_reg(data->in_low[nr])); } static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->in_high[nr] = in_to_reg(val); f71805f_write8(data, F71805F_REG_IN_HIGH(nr), data->in_high[nr]); mutex_unlock(&data->update_lock); return count; } static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->in_low[nr] = in_to_reg(val); f71805f_write8(data, F71805F_REG_IN_LOW(nr), data->in_low[nr]); mutex_unlock(&data->update_lock); return count; } static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", fan_from_reg(data->fan[nr])); } static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", fan_from_reg(data->fan_low[nr])); } static ssize_t show_fan_target(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", fan_from_reg(data->fan_target[nr])); } static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->fan_low[nr] = fan_to_reg(val); f71805f_write16(data, F71805F_REG_FAN_LOW(nr), data->fan_low[nr]); mutex_unlock(&data->update_lock); return count; } static ssize_t set_fan_target(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->fan_target[nr] = fan_to_reg(val); f71805f_write16(data, F71805F_REG_FAN_TARGET(nr), data->fan_target[nr]); mutex_unlock(&data->update_lock); return count; } static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%d\n", (int)data->pwm[nr]); } static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; int mode; switch (data->fan_ctrl[nr] & FAN_CTRL_MODE_MASK) { case FAN_CTRL_MODE_SPEED: mode = 3; break; case FAN_CTRL_MODE_TEMPERATURE: mode = 2; break; default: /* MANUAL */ mode = 1; } return sprintf(buf, "%d\n", mode); } static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%lu\n", pwm_freq_from_reg(data->pwm_freq[nr])); } static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%d\n", pwm_mode_from_reg(data->fan_ctrl[nr])); } static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; unsigned long val = simple_strtoul(buf, NULL, 10); if (val > 255) return -EINVAL; mutex_lock(&data->update_lock); data->pwm[nr] = val; f71805f_write8(data, F71805F_REG_PWM_DUTY(nr), data->pwm[nr]); mutex_unlock(&data->update_lock); return count; } static struct attribute *f71805f_attr_pwm[]; static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; unsigned long val = simple_strtoul(buf, NULL, 10); u8 reg; if (val < 1 || val > 3) return -EINVAL; if (val > 1) { /* Automatic mode, user can't set PWM value */ if (sysfs_chmod_file(&dev->kobj, f71805f_attr_pwm[nr], S_IRUGO)) dev_dbg(dev, "chmod -w pwm%d failed\n", nr + 1); } mutex_lock(&data->update_lock); reg = f71805f_read8(data, F71805F_REG_FAN_CTRL(nr)) & ~FAN_CTRL_MODE_MASK; switch (val) { case 1: reg |= FAN_CTRL_MODE_MANUAL; break; case 2: reg |= FAN_CTRL_MODE_TEMPERATURE; break; case 3: reg |= FAN_CTRL_MODE_SPEED; break; } data->fan_ctrl[nr] = reg; f71805f_write8(data, F71805F_REG_FAN_CTRL(nr), reg); mutex_unlock(&data->update_lock); if (val == 1) { /* Manual mode, user can set PWM value */ if (sysfs_chmod_file(&dev->kobj, f71805f_attr_pwm[nr], S_IRUGO | S_IWUSR)) dev_dbg(dev, "chmod +w pwm%d failed\n", nr + 1); } return count; } static ssize_t set_pwm_freq(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; unsigned long val = simple_strtoul(buf, NULL, 10); mutex_lock(&data->update_lock); data->pwm_freq[nr] = pwm_freq_to_reg(val); f71805f_write8(data, F71805F_REG_PWM_FREQ(nr), data->pwm_freq[nr]); mutex_unlock(&data->update_lock); return count; } static ssize_t show_pwm_auto_point_temp(struct device *dev, struct device_attribute *devattr, char* buf) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); int pwmnr = attr->nr; int apnr = attr->index; return sprintf(buf, "%ld\n", temp_from_reg(data->auto_points[pwmnr].temp[apnr])); } static ssize_t set_pwm_auto_point_temp(struct device *dev, struct device_attribute *devattr, const char* buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); int pwmnr = attr->nr; int apnr = attr->index; unsigned long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->auto_points[pwmnr].temp[apnr] = temp_to_reg(val); f71805f_write8(data, F71805F_REG_PWM_AUTO_POINT_TEMP(pwmnr, apnr), data->auto_points[pwmnr].temp[apnr]); mutex_unlock(&data->update_lock); return count; } static ssize_t show_pwm_auto_point_fan(struct device *dev, struct device_attribute *devattr, char* buf) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); int pwmnr = attr->nr; int apnr = attr->index; return sprintf(buf, "%ld\n", fan_from_reg(data->auto_points[pwmnr].fan[apnr])); } static ssize_t set_pwm_auto_point_fan(struct device *dev, struct device_attribute *devattr, const char* buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); int pwmnr = attr->nr; int apnr = attr->index; unsigned long val = simple_strtoul(buf, NULL, 10); mutex_lock(&data->update_lock); data->auto_points[pwmnr].fan[apnr] = fan_to_reg(val); f71805f_write16(data, F71805F_REG_PWM_AUTO_POINT_FAN(pwmnr, apnr), data->auto_points[pwmnr].fan[apnr]); mutex_unlock(&data->update_lock); return count; } static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", temp_from_reg(data->temp[nr])); } static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", temp_from_reg(data->temp_high[nr])); } static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; return sprintf(buf, "%ld\n", temp_from_reg(data->temp_hyst[nr])); } static ssize_t show_temp_type(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; /* 3 is diode, 4 is thermistor */ return sprintf(buf, "%u\n", (data->temp_mode & (1 << nr)) ? 3 : 4); } static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->temp_high[nr] = temp_to_reg(val); f71805f_write8(data, F71805F_REG_TEMP_HIGH(nr), data->temp_high[nr]); mutex_unlock(&data->update_lock); return count; } static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct f71805f_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int nr = attr->index; long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->temp_hyst[nr] = temp_to_reg(val); f71805f_write8(data, F71805F_REG_TEMP_HYST(nr), data->temp_hyst[nr]); mutex_unlock(&data->update_lock); return count; } static ssize_t show_alarms_in(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); return sprintf(buf, "%lu\n", data->alarms & 0x7ff); } static ssize_t show_alarms_fan(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); return sprintf(buf, "%lu\n", (data->alarms >> 16) & 0x07); } static ssize_t show_alarms_temp(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); return sprintf(buf, "%lu\n", (data->alarms >> 11) & 0x07); } static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = f71805f_update_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); int bitnr = attr->index; return sprintf(buf, "%lu\n", (data->alarms >> bitnr) & 1); } static ssize_t show_name(struct device *dev, struct device_attribute *devattr, char *buf) { struct f71805f_data *data = dev_get_drvdata(dev); return sprintf(buf, "%s\n", data->name); } static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL, 0); static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max, 0); static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min, 0); static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1); static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR, show_in_max, set_in_max, 1); static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR, show_in_min, set_in_min, 1); static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2); static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S_IWUSR, show_in_max, set_in_max, 2); static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S_IWUSR, show_in_min, set_in_min, 2); static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3); static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO | S_IWUSR, show_in_max, set_in_max, 3); static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO | S_IWUSR, show_in_min, set_in_min, 3); static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 4); static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S_IWUSR, show_in_max, set_in_max, 4); static SENSOR_DEVICE_ATTR(in4_min, S_IRUGO | S_IWUSR, show_in_min, set_in_min, 4); static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 5); static SENSOR_DEVICE_ATTR(in5_max, S_IRUGO | S_IWUSR, show_in_max, set_in_max, 5); static SENSOR_DEVICE_ATTR(in5_min, S_IRUGO | S_IWUSR, show_in_min, set_in_min, 5); static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 6); static SENSOR_DEVICE_ATTR(in6_max, S_IRUGO | S_IWUSR, show_in_max, set_in_max, 6); static SENSOR_DEVICE_ATTR(in6_min, S_IRUGO | S_IWUSR, show_in_min, set_in_min, 6); static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 7); static SENSOR_DEVICE_ATTR(in7_max, S_IRUGO | S_IWUSR, show_in_max, set_in_max, 7); static SENSOR_DEVICE_ATTR(in7_min, S_IRUGO | S_IWUSR, show_in_min, set_in_min, 7); static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 8); static SENSOR_DEVICE_ATTR(in8_max, S_IRUGO | S_IWUSR, show_in_max, set_in_max, 8); static SENSOR_DEVICE_ATTR(in8_min, S_IRUGO | S_IWUSR, show_in_min, set_in_min, 8); static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_in0, NULL, 9); static SENSOR_DEVICE_ATTR(in9_max, S_IRUGO | S_IWUSR, show_in0_max, set_in0_max, 9); static SENSOR_DEVICE_ATTR(in9_min, S_IRUGO | S_IWUSR, show_in0_min, set_in0_min, 9); static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_in0, NULL, 10); static SENSOR_DEVICE_ATTR(in10_max, S_IRUGO | S_IWUSR, show_in0_max, set_in0_max, 10); static SENSOR_DEVICE_ATTR(in10_min, S_IRUGO | S_IWUSR, show_in0_min, set_in0_min, 10); static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR, show_fan_min, set_fan_min, 0); static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, show_fan_target, set_fan_target, 0); static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1); static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR, show_fan_min, set_fan_min, 1); static SENSOR_DEVICE_ATTR(fan2_target, S_IRUGO | S_IWUSR, show_fan_target, set_fan_target, 1); static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); static SENSOR_DEVICE_ATTR(fan3_min, S_IRUGO | S_IWUSR, show_fan_min, set_fan_min, 2); static SENSOR_DEVICE_ATTR(fan3_target, S_IRUGO | S_IWUSR, show_fan_target, set_fan_target, 2); static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp_max, set_temp_max, 0); static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp_hyst, set_temp_hyst, 0); static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0); static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR, show_temp_max, set_temp_max, 1); static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp_hyst, set_temp_hyst, 1); static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1); static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR, show_temp_max, set_temp_max, 2); static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_hyst, set_temp_hyst, 2); static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2); /* pwm (value) files are created read-only, write permission is then added or removed dynamically as needed */ static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO, show_pwm, set_pwm, 0); static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable, set_pwm_enable, 0); static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq, set_pwm_freq, 0); static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0); static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO, show_pwm, set_pwm, 1); static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable, set_pwm_enable, 1); static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO | S_IWUSR, show_pwm_freq, set_pwm_freq, 1); static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO, show_pwm_mode, NULL, 1); static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO, show_pwm, set_pwm, 2); static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable, set_pwm_enable, 2); static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO | S_IWUSR, show_pwm_freq, set_pwm_freq, 2); static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2); static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR, show_pwm_auto_point_temp, set_pwm_auto_point_temp, 0, 0); static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_fan, S_IRUGO | S_IWUSR, show_pwm_auto_point_fan, set_pwm_auto_point_fan, 0, 0); static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR, show_pwm_auto_point_temp, set_pwm_auto_point_temp, 0, 1); static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_fan, S_IRUGO | S_IWUSR, show_pwm_auto_point_fan, set_pwm_auto_point_fan, 0, 1); static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR, show_pwm_auto_point_temp, set_pwm_auto_point_temp, 0, 2); static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_fan, S_IRUGO | S_IWUSR, show_pwm_auto_point_fan, set_pwm_auto_point_fan, 0, 2); static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR, show_pwm_auto_point_temp, set_pwm_auto_point_temp, 1, 0); static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_fan, S_IRUGO | S_IWUSR, show_pwm_auto_point_fan, set_pwm_auto_point_fan, 1, 0); static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR, show_pwm_auto_point_temp, set_pwm_auto_point_temp, 1, 1); static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_fan, S_IRUGO | S_IWUSR, show_pwm_auto_point_fan, set_pwm_auto_point_fan, 1, 1); static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR, show_pwm_auto_point_temp, set_pwm_auto_point_temp, 1, 2); static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_fan, S_IRUGO | S_IWUSR, show_pwm_auto_point_fan, set_pwm_auto_point_fan, 1, 2); static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR, show_pwm_auto_point_temp, set_pwm_auto_point_temp, 2, 0); static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_fan, S_IRUGO | S_IWUSR, show_pwm_auto_point_fan, set_pwm_auto_point_fan, 2, 0); static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR, show_pwm_auto_point_temp, set_pwm_auto_point_temp, 2, 1); static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_fan, S_IRUGO | S_IWUSR, show_pwm_auto_point_fan, set_pwm_auto_point_fan, 2, 1); static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR, show_pwm_auto_point_temp, set_pwm_auto_point_temp, 2, 2); static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_fan, S_IRUGO | S_IWUSR, show_pwm_auto_point_fan, set_pwm_auto_point_fan, 2, 2); static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4); static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5); static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6); static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7); static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 8); static SENSOR_DEVICE_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 9); static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 10); static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 11); static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 12); static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13); static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 16); static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 17); static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18); static DEVICE_ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL); static DEVICE_ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL); static DEVICE_ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL); static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); static struct attribute *f71805f_attributes[] = { &sensor_dev_attr_in0_input.dev_attr.attr, &sensor_dev_attr_in0_max.dev_attr.attr, &sensor_dev_attr_in0_min.dev_attr.attr, &sensor_dev_attr_in1_input.dev_attr.attr, &sensor_dev_attr_in1_max.dev_attr.attr, &sensor_dev_attr_in1_min.dev_attr.attr, &sensor_dev_attr_in2_input.dev_attr.attr, &sensor_dev_attr_in2_max.dev_attr.attr, &sensor_dev_attr_in2_min.dev_attr.attr, &sensor_dev_attr_in3_input.dev_attr.attr, &sensor_dev_attr_in3_max.dev_attr.attr, &sensor_dev_attr_in3_min.dev_attr.attr, &sensor_dev_attr_in5_input.dev_attr.attr, &sensor_dev_attr_in5_max.dev_attr.attr, &sensor_dev_attr_in5_min.dev_attr.attr, &sensor_dev_attr_in6_input.dev_attr.attr, &sensor_dev_attr_in6_max.dev_attr.attr, &sensor_dev_attr_in6_min.dev_attr.attr, &sensor_dev_attr_in7_input.dev_attr.attr, &sensor_dev_attr_in7_max.dev_attr.attr, &sensor_dev_attr_in7_min.dev_attr.attr, &sensor_dev_attr_fan1_input.dev_attr.attr, &sensor_dev_attr_fan1_min.dev_attr.attr, &sensor_dev_attr_fan1_alarm.dev_attr.attr, &sensor_dev_attr_fan1_target.dev_attr.attr, &sensor_dev_attr_fan2_input.dev_attr.attr, &sensor_dev_attr_fan2_min.dev_attr.attr, &sensor_dev_attr_fan2_alarm.dev_attr.attr, &sensor_dev_attr_fan2_target.dev_attr.attr, &sensor_dev_attr_fan3_input.dev_attr.attr, &sensor_dev_attr_fan3_min.dev_attr.attr, &sensor_dev_attr_fan3_alarm.dev_attr.attr, &sensor_dev_attr_fan3_target.dev_attr.attr, &sensor_dev_attr_pwm1.dev_attr.attr, &sensor_dev_attr_pwm1_enable.dev_attr.attr, &sensor_dev_attr_pwm1_mode.dev_attr.attr, &sensor_dev_attr_pwm2.dev_attr.attr, &sensor_dev_attr_pwm2_enable.dev_attr.attr, &sensor_dev_attr_pwm2_mode.dev_attr.attr, &sensor_dev_attr_pwm3.dev_attr.attr, &sensor_dev_attr_pwm3_enable.dev_attr.attr, &sensor_dev_attr_pwm3_mode.dev_attr.attr, &sensor_dev_attr_temp1_input.dev_attr.attr, &sensor_dev_attr_temp1_max.dev_attr.attr, &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, &sensor_dev_attr_temp1_type.dev_attr.attr, &sensor_dev_attr_temp2_input.dev_attr.attr, &sensor_dev_attr_temp2_max.dev_attr.attr, &sensor_dev_attr_temp2_max_hyst.dev_attr.attr, &sensor_dev_attr_temp2_type.dev_attr.attr, &sensor_dev_attr_temp3_input.dev_attr.attr, &sensor_dev_attr_temp3_max.dev_attr.attr, &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, &sensor_dev_attr_temp3_type.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point1_fan.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point2_fan.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point3_fan.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point1_fan.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point2_fan.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point3_fan.dev_attr.attr, &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr, &sensor_dev_attr_pwm3_auto_point1_fan.dev_attr.attr, &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr, &sensor_dev_attr_pwm3_auto_point2_fan.dev_attr.attr, &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr, &sensor_dev_attr_pwm3_auto_point3_fan.dev_attr.attr, &sensor_dev_attr_in0_alarm.dev_attr.attr, &sensor_dev_attr_in1_alarm.dev_attr.attr, &sensor_dev_attr_in2_alarm.dev_attr.attr, &sensor_dev_attr_in3_alarm.dev_attr.attr, &sensor_dev_attr_in5_alarm.dev_attr.attr, &sensor_dev_attr_in6_alarm.dev_attr.attr, &sensor_dev_attr_in7_alarm.dev_attr.attr, &dev_attr_alarms_in.attr, &sensor_dev_attr_temp1_alarm.dev_attr.attr, &sensor_dev_attr_temp2_alarm.dev_attr.attr, &sensor_dev_attr_temp3_alarm.dev_attr.attr, &dev_attr_alarms_temp.attr, &dev_attr_alarms_fan.attr, &dev_attr_name.attr, NULL }; static const struct attribute_group f71805f_group = { .attrs = f71805f_attributes, }; static struct attribute *f71805f_attributes_optin[4][5] = { { &sensor_dev_attr_in4_input.dev_attr.attr, &sensor_dev_attr_in4_max.dev_attr.attr, &sensor_dev_attr_in4_min.dev_attr.attr, &sensor_dev_attr_in4_alarm.dev_attr.attr, NULL }, { &sensor_dev_attr_in8_input.dev_attr.attr, &sensor_dev_attr_in8_max.dev_attr.attr, &sensor_dev_attr_in8_min.dev_attr.attr, &sensor_dev_attr_in8_alarm.dev_attr.attr, NULL }, { &sensor_dev_attr_in9_input.dev_attr.attr, &sensor_dev_attr_in9_max.dev_attr.attr, &sensor_dev_attr_in9_min.dev_attr.attr, &sensor_dev_attr_in9_alarm.dev_attr.attr, NULL }, { &sensor_dev_attr_in10_input.dev_attr.attr, &sensor_dev_attr_in10_max.dev_attr.attr, &sensor_dev_attr_in10_min.dev_attr.attr, &sensor_dev_attr_in10_alarm.dev_attr.attr, NULL } }; static const struct attribute_group f71805f_group_optin[4] = { { .attrs = f71805f_attributes_optin[0] }, { .attrs = f71805f_attributes_optin[1] }, { .attrs = f71805f_attributes_optin[2] }, { .attrs = f71805f_attributes_optin[3] }, }; /* We don't include pwm_freq files in the arrays above, because they must be created conditionally (only if pwm_mode is 1 == PWM) */ static struct attribute *f71805f_attributes_pwm_freq[] = { &sensor_dev_attr_pwm1_freq.dev_attr.attr, &sensor_dev_attr_pwm2_freq.dev_attr.attr, &sensor_dev_attr_pwm3_freq.dev_attr.attr, NULL }; static const struct attribute_group f71805f_group_pwm_freq = { .attrs = f71805f_attributes_pwm_freq, }; /* We also need an indexed access to pwmN files to toggle writability */ static struct attribute *f71805f_attr_pwm[] = { &sensor_dev_attr_pwm1.dev_attr.attr, &sensor_dev_attr_pwm2.dev_attr.attr, &sensor_dev_attr_pwm3.dev_attr.attr, }; /* * Device registration and initialization */ static void __devinit f71805f_init_device(struct f71805f_data *data) { u8 reg; int i; reg = f71805f_read8(data, F71805F_REG_START); if ((reg & 0x41) != 0x01) { printk(KERN_DEBUG DRVNAME ": Starting monitoring " "operations\n"); f71805f_write8(data, F71805F_REG_START, (reg | 0x01) & ~0x40); } /* Fan monitoring can be disabled. If it is, we won't be polling the register values, and won't create the related sysfs files. */ for (i = 0; i < 3; i++) { data->fan_ctrl[i] = f71805f_read8(data, F71805F_REG_FAN_CTRL(i)); /* Clear latch full bit, else "speed mode" fan speed control doesn't work */ if (data->fan_ctrl[i] & FAN_CTRL_LATCH_FULL) { data->fan_ctrl[i] &= ~FAN_CTRL_LATCH_FULL; f71805f_write8(data, F71805F_REG_FAN_CTRL(i), data->fan_ctrl[i]); } } } static int __devinit f71805f_probe(struct platform_device *pdev) { struct f71805f_sio_data *sio_data = pdev->dev.platform_data; struct f71805f_data *data; struct resource *res; int i, err; static const char *names[] = { "f71805f", "f71872f", }; if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) { err = -ENOMEM; printk(KERN_ERR DRVNAME ": Out of memory\n"); goto exit; } res = platform_get_resource(pdev, IORESOURCE_IO, 0); if (!request_region(res->start + ADDR_REG_OFFSET, 2, DRVNAME)) { err = -EBUSY; dev_err(&pdev->dev, "Failed to request region 0x%lx-0x%lx\n", (unsigned long)(res->start + ADDR_REG_OFFSET), (unsigned long)(res->start + ADDR_REG_OFFSET + 1)); goto exit_free; } data->addr = res->start; data->name = names[sio_data->kind]; mutex_init(&data->update_lock); platform_set_drvdata(pdev, data); /* Some voltage inputs depend on chip model and configuration */ switch (sio_data->kind) { case f71805f: data->has_in = 0x1ff; break; case f71872f: data->has_in = 0x6ef; if (sio_data->fnsel1 & 0x01) data->has_in |= (1 << 4); /* in4 */ if (sio_data->fnsel1 & 0x02) data->has_in |= (1 << 8); /* in8 */ break; } /* Initialize the F71805F chip */ f71805f_init_device(data); /* Register sysfs interface files */ if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group))) goto exit_release_region; if (data->has_in & (1 << 4)) { /* in4 */ if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group_optin[0]))) goto exit_remove_files; } if (data->has_in & (1 << 8)) { /* in8 */ if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group_optin[1]))) goto exit_remove_files; } if (data->has_in & (1 << 9)) { /* in9 (F71872F/FG only) */ if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group_optin[2]))) goto exit_remove_files; } if (data->has_in & (1 << 10)) { /* in9 (F71872F/FG only) */ if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group_optin[3]))) goto exit_remove_files; } for (i = 0; i < 3; i++) { /* If control mode is PWM, create pwm_freq file */ if (!(data->fan_ctrl[i] & FAN_CTRL_DC_MODE)) { if ((err = sysfs_create_file(&pdev->dev.kobj, f71805f_attributes_pwm_freq[i]))) goto exit_remove_files; } /* If PWM is in manual mode, add write permission */ if (data->fan_ctrl[i] & FAN_CTRL_MODE_MANUAL) { if ((err = sysfs_chmod_file(&pdev->dev.kobj, f71805f_attr_pwm[i], S_IRUGO | S_IWUSR))) { dev_err(&pdev->dev, "chmod +w pwm%d failed\n", i + 1); goto exit_remove_files; } } } data->hwmon_dev = hwmon_device_register(&pdev->dev); if (IS_ERR(data->hwmon_dev)) { err = PTR_ERR(data->hwmon_dev); dev_err(&pdev->dev, "Class registration failed (%d)\n", err); goto exit_remove_files; } return 0; exit_remove_files: sysfs_remove_group(&pdev->dev.kobj, &f71805f_group); for (i = 0; i < 4; i++) sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]); sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); exit_release_region: release_region(res->start + ADDR_REG_OFFSET, 2); exit_free: platform_set_drvdata(pdev, NULL); kfree(data); exit: return err; } static int __devexit f71805f_remove(struct platform_device *pdev) { struct f71805f_data *data = platform_get_drvdata(pdev); struct resource *res; int i; hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&pdev->dev.kobj, &f71805f_group); for (i = 0; i < 4; i++) sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]); sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); platform_set_drvdata(pdev, NULL); kfree(data); res = platform_get_resource(pdev, IORESOURCE_IO, 0); release_region(res->start + ADDR_REG_OFFSET, 2); return 0; } static struct platform_driver f71805f_driver = { .driver = { .owner = THIS_MODULE, .name = DRVNAME, }, .probe = f71805f_probe, .remove = __devexit_p(f71805f_remove), }; static int __init f71805f_device_add(unsigned short address, const struct f71805f_sio_data *sio_data) { struct resource res = { .start = address, .end = address + REGION_LENGTH - 1, .flags = IORESOURCE_IO, }; int err; pdev = platform_device_alloc(DRVNAME, address); if (!pdev) { err = -ENOMEM; printk(KERN_ERR DRVNAME ": Device allocation failed\n"); goto exit; } res.name = pdev->name; err = acpi_check_resource_conflict(&res); if (err) goto exit_device_put; err = platform_device_add_resources(pdev, &res, 1); if (err) { printk(KERN_ERR DRVNAME ": Device resource addition failed " "(%d)\n", err); goto exit_device_put; } err = platform_device_add_data(pdev, sio_data, sizeof(struct f71805f_sio_data)); if (err) { printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); goto exit_device_put; } err = platform_device_add(pdev); if (err) { printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", err); goto exit_device_put; } return 0; exit_device_put: platform_device_put(pdev); exit: return err; } static int __init f71805f_find(int sioaddr, unsigned short *address, struct f71805f_sio_data *sio_data) { int err = -ENODEV; u16 devid; static const char *names[] = { "F71805F/FG", "F71872F/FG or F71806F/FG", }; superio_enter(sioaddr); devid = superio_inw(sioaddr, SIO_REG_MANID); if (devid != SIO_FINTEK_ID) goto exit; devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID); switch (devid) { case SIO_F71805F_ID: sio_data->kind = f71805f; break; case SIO_F71872F_ID: sio_data->kind = f71872f; sio_data->fnsel1 = superio_inb(sioaddr, SIO_REG_FNSEL1); break; default: printk(KERN_INFO DRVNAME ": Unsupported Fintek device, " "skipping\n"); goto exit; } superio_select(sioaddr, F71805F_LD_HWM); if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) { printk(KERN_WARNING DRVNAME ": Device not activated, " "skipping\n"); goto exit; } *address = superio_inw(sioaddr, SIO_REG_ADDR); if (*address == 0) { printk(KERN_WARNING DRVNAME ": Base address not set, " "skipping\n"); goto exit; } *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */ err = 0; printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %u\n", names[sio_data->kind], *address, superio_inb(sioaddr, SIO_REG_DEVREV)); exit: superio_exit(sioaddr); return err; } static int __init f71805f_init(void) { int err; unsigned short address; struct f71805f_sio_data sio_data; if (f71805f_find(0x2e, &address, &sio_data) && f71805f_find(0x4e, &address, &sio_data)) return -ENODEV; err = platform_driver_register(&f71805f_driver); if (err) goto exit; /* Sets global pdev as a side effect */ err = f71805f_device_add(address, &sio_data); if (err) goto exit_driver; return 0; exit_driver: platform_driver_unregister(&f71805f_driver); exit: return err; } static void __exit f71805f_exit(void) { platform_device_unregister(pdev); platform_driver_unregister(&f71805f_driver); } MODULE_AUTHOR("Jean Delvare <khali@linux-fr>"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("F71805F/F71872F hardware monitoring driver"); module_init(f71805f_init); module_exit(f71805f_exit);
gpl-2.0
Zenfone2-Dev/Kernel-for-Asus-Zenfone-2
drivers/video/backlight/kb3886_bl.c
2241
4916
/* * Backlight Driver for the KB3886 Backlight * * Copyright (c) 2007-2008 Claudio Nieder * * Based on corgi_bl.c by Richard Purdie and kb3886 driver by Robert Woerle * * 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/kernel.h> #include <linux/init.h> #include <linux/platform_device.h> #include <linux/mutex.h> #include <linux/fb.h> #include <linux/backlight.h> #include <linux/delay.h> #include <linux/dmi.h> #define KB3886_PARENT 0x64 #define KB3886_IO 0x60 #define KB3886_ADC_DAC_PWM 0xC4 #define KB3886_PWM0_WRITE 0x81 #define KB3886_PWM0_READ 0x41 static DEFINE_MUTEX(bl_mutex); static void kb3886_bl_set_intensity(int intensity) { mutex_lock(&bl_mutex); intensity = intensity&0xff; outb(KB3886_ADC_DAC_PWM, KB3886_PARENT); usleep_range(10000, 11000); outb(KB3886_PWM0_WRITE, KB3886_IO); usleep_range(10000, 11000); outb(intensity, KB3886_IO); mutex_unlock(&bl_mutex); } struct kb3886bl_machinfo { int max_intensity; int default_intensity; int limit_mask; void (*set_bl_intensity)(int intensity); }; static struct kb3886bl_machinfo kb3886_bl_machinfo = { .max_intensity = 0xff, .default_intensity = 0xa0, .limit_mask = 0x7f, .set_bl_intensity = kb3886_bl_set_intensity, }; static struct platform_device kb3886bl_device = { .name = "kb3886-bl", .dev = { .platform_data = &kb3886_bl_machinfo, }, .id = -1, }; static struct platform_device *devices[] __initdata = { &kb3886bl_device, }; /* * Back to driver */ static int kb3886bl_intensity; static struct backlight_device *kb3886_backlight_device; static struct kb3886bl_machinfo *bl_machinfo; static unsigned long kb3886bl_flags; #define KB3886BL_SUSPENDED 0x01 static struct dmi_system_id __initdata kb3886bl_device_table[] = { { .ident = "Sahara Touch-iT", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "SDV"), DMI_MATCH(DMI_PRODUCT_NAME, "iTouch T201"), }, }, { } }; static int kb3886bl_send_intensity(struct backlight_device *bd) { int intensity = bd->props.brightness; if (bd->props.power != FB_BLANK_UNBLANK) intensity = 0; if (bd->props.fb_blank != FB_BLANK_UNBLANK) intensity = 0; if (kb3886bl_flags & KB3886BL_SUSPENDED) intensity = 0; bl_machinfo->set_bl_intensity(intensity); kb3886bl_intensity = intensity; return 0; } #ifdef CONFIG_PM_SLEEP static int kb3886bl_suspend(struct device *dev) { struct backlight_device *bd = dev_get_drvdata(dev); kb3886bl_flags |= KB3886BL_SUSPENDED; backlight_update_status(bd); return 0; } static int kb3886bl_resume(struct device *dev) { struct backlight_device *bd = dev_get_drvdata(dev); kb3886bl_flags &= ~KB3886BL_SUSPENDED; backlight_update_status(bd); return 0; } #endif static SIMPLE_DEV_PM_OPS(kb3886bl_pm_ops, kb3886bl_suspend, kb3886bl_resume); static int kb3886bl_get_intensity(struct backlight_device *bd) { return kb3886bl_intensity; } static const struct backlight_ops kb3886bl_ops = { .get_brightness = kb3886bl_get_intensity, .update_status = kb3886bl_send_intensity, }; static int kb3886bl_probe(struct platform_device *pdev) { struct backlight_properties props; struct kb3886bl_machinfo *machinfo = pdev->dev.platform_data; bl_machinfo = machinfo; if (!machinfo->limit_mask) machinfo->limit_mask = -1; memset(&props, 0, sizeof(struct backlight_properties)); props.type = BACKLIGHT_RAW; props.max_brightness = machinfo->max_intensity; kb3886_backlight_device = backlight_device_register("kb3886-bl", &pdev->dev, NULL, &kb3886bl_ops, &props); if (IS_ERR(kb3886_backlight_device)) return PTR_ERR(kb3886_backlight_device); platform_set_drvdata(pdev, kb3886_backlight_device); kb3886_backlight_device->props.power = FB_BLANK_UNBLANK; kb3886_backlight_device->props.brightness = machinfo->default_intensity; backlight_update_status(kb3886_backlight_device); return 0; } static int kb3886bl_remove(struct platform_device *pdev) { struct backlight_device *bd = platform_get_drvdata(pdev); backlight_device_unregister(bd); return 0; } static struct platform_driver kb3886bl_driver = { .probe = kb3886bl_probe, .remove = kb3886bl_remove, .driver = { .name = "kb3886-bl", .pm = &kb3886bl_pm_ops, }, }; static int __init kb3886_init(void) { if (!dmi_check_system(kb3886bl_device_table)) return -ENODEV; platform_add_devices(devices, ARRAY_SIZE(devices)); return platform_driver_register(&kb3886bl_driver); } static void __exit kb3886_exit(void) { platform_driver_unregister(&kb3886bl_driver); } module_init(kb3886_init); module_exit(kb3886_exit); MODULE_AUTHOR("Claudio Nieder <private@claudio.ch>"); MODULE_DESCRIPTION("Tabletkiosk Sahara Touch-iT Backlight Driver"); MODULE_LICENSE("GPL"); MODULE_ALIAS("dmi:*:svnSDV:pniTouchT201:*");
gpl-2.0
MCP1/android_kernel_motorola_msm8960-common
drivers/gpu/drm/radeon/radeon_legacy_tv.c
2753
27656
#include "drmP.h" #include "drm_crtc_helper.h" #include "radeon.h" /* * Integrated TV out support based on the GATOS code by * Federico Ulivi <fulivi@lycos.com> */ /* * Limits of h/v positions (hPos & vPos) */ #define MAX_H_POSITION 5 /* Range: [-5..5], negative is on the left, 0 is default, positive is on the right */ #define MAX_V_POSITION 5 /* Range: [-5..5], negative is up, 0 is default, positive is down */ /* * Unit for hPos (in TV clock periods) */ #define H_POS_UNIT 10 /* * Indexes in h. code timing table for horizontal line position adjustment */ #define H_TABLE_POS1 6 #define H_TABLE_POS2 8 /* * Limits of hor. size (hSize) */ #define MAX_H_SIZE 5 /* Range: [-5..5], negative is smaller, positive is larger */ /* tv standard constants */ #define NTSC_TV_CLOCK_T 233 #define NTSC_TV_VFTOTAL 1 #define NTSC_TV_LINES_PER_FRAME 525 #define NTSC_TV_ZERO_H_SIZE 479166 #define NTSC_TV_H_SIZE_UNIT 9478 #define PAL_TV_CLOCK_T 188 #define PAL_TV_VFTOTAL 3 #define PAL_TV_LINES_PER_FRAME 625 #define PAL_TV_ZERO_H_SIZE 473200 #define PAL_TV_H_SIZE_UNIT 9360 /* tv pll setting for 27 mhz ref clk */ #define NTSC_TV_PLL_M_27 22 #define NTSC_TV_PLL_N_27 175 #define NTSC_TV_PLL_P_27 5 #define PAL_TV_PLL_M_27 113 #define PAL_TV_PLL_N_27 668 #define PAL_TV_PLL_P_27 3 /* tv pll setting for 14 mhz ref clk */ #define NTSC_TV_PLL_M_14 33 #define NTSC_TV_PLL_N_14 693 #define NTSC_TV_PLL_P_14 7 #define PAL_TV_PLL_M_14 19 #define PAL_TV_PLL_N_14 353 #define PAL_TV_PLL_P_14 5 #define VERT_LEAD_IN_LINES 2 #define FRAC_BITS 0xe #define FRAC_MASK 0x3fff struct radeon_tv_mode_constants { uint16_t hor_resolution; uint16_t ver_resolution; enum radeon_tv_std standard; uint16_t hor_total; uint16_t ver_total; uint16_t hor_start; uint16_t hor_syncstart; uint16_t ver_syncstart; unsigned def_restart; uint16_t crtcPLL_N; uint8_t crtcPLL_M; uint8_t crtcPLL_post_div; unsigned pix_to_tv; }; static const uint16_t hor_timing_NTSC[MAX_H_CODE_TIMING_LEN] = { 0x0007, 0x003f, 0x0263, 0x0a24, 0x2a6b, 0x0a36, 0x126d, /* H_TABLE_POS1 */ 0x1bfe, 0x1a8f, /* H_TABLE_POS2 */ 0x1ec7, 0x3863, 0x1bfe, 0x1bfe, 0x1a2a, 0x1e95, 0x0e31, 0x201b, 0 }; static const uint16_t vert_timing_NTSC[MAX_V_CODE_TIMING_LEN] = { 0x2001, 0x200d, 0x1006, 0x0c06, 0x1006, 0x1818, 0x21e3, 0x1006, 0x0c06, 0x1006, 0x1817, 0x21d4, 0x0002, 0 }; static const uint16_t hor_timing_PAL[MAX_H_CODE_TIMING_LEN] = { 0x0007, 0x0058, 0x027c, 0x0a31, 0x2a77, 0x0a95, 0x124f, /* H_TABLE_POS1 */ 0x1bfe, 0x1b22, /* H_TABLE_POS2 */ 0x1ef9, 0x387c, 0x1bfe, 0x1bfe, 0x1b31, 0x1eb5, 0x0e43, 0x201b, 0 }; static const uint16_t vert_timing_PAL[MAX_V_CODE_TIMING_LEN] = { 0x2001, 0x200c, 0x1005, 0x0c05, 0x1005, 0x1401, 0x1821, 0x2240, 0x1005, 0x0c05, 0x1005, 0x1401, 0x1822, 0x2230, 0x0002, 0 }; /********************************************************************** * * availableModes * * Table of all allowed modes for tv output * **********************************************************************/ static const struct radeon_tv_mode_constants available_tv_modes[] = { { /* NTSC timing for 27 Mhz ref clk */ 800, /* horResolution */ 600, /* verResolution */ TV_STD_NTSC, /* standard */ 990, /* horTotal */ 740, /* verTotal */ 813, /* horStart */ 824, /* horSyncStart */ 632, /* verSyncStart */ 625592, /* defRestart */ 592, /* crtcPLL_N */ 91, /* crtcPLL_M */ 4, /* crtcPLL_postDiv */ 1022, /* pixToTV */ }, { /* PAL timing for 27 Mhz ref clk */ 800, /* horResolution */ 600, /* verResolution */ TV_STD_PAL, /* standard */ 1144, /* horTotal */ 706, /* verTotal */ 812, /* horStart */ 824, /* horSyncStart */ 669, /* verSyncStart */ 696700, /* defRestart */ 1382, /* crtcPLL_N */ 231, /* crtcPLL_M */ 4, /* crtcPLL_postDiv */ 759, /* pixToTV */ }, { /* NTSC timing for 14 Mhz ref clk */ 800, /* horResolution */ 600, /* verResolution */ TV_STD_NTSC, /* standard */ 1018, /* horTotal */ 727, /* verTotal */ 813, /* horStart */ 840, /* horSyncStart */ 633, /* verSyncStart */ 630627, /* defRestart */ 347, /* crtcPLL_N */ 14, /* crtcPLL_M */ 8, /* crtcPLL_postDiv */ 1022, /* pixToTV */ }, { /* PAL timing for 14 Mhz ref clk */ 800, /* horResolution */ 600, /* verResolution */ TV_STD_PAL, /* standard */ 1131, /* horTotal */ 742, /* verTotal */ 813, /* horStart */ 840, /* horSyncStart */ 633, /* verSyncStart */ 708369, /* defRestart */ 211, /* crtcPLL_N */ 9, /* crtcPLL_M */ 8, /* crtcPLL_postDiv */ 759, /* pixToTV */ }, }; #define N_AVAILABLE_MODES ARRAY_SIZE(available_tv_modes) static const struct radeon_tv_mode_constants *radeon_legacy_tv_get_std_mode(struct radeon_encoder *radeon_encoder, uint16_t *pll_ref_freq) { struct drm_device *dev = radeon_encoder->base.dev; struct radeon_device *rdev = dev->dev_private; struct radeon_crtc *radeon_crtc; struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv; const struct radeon_tv_mode_constants *const_ptr; struct radeon_pll *pll; radeon_crtc = to_radeon_crtc(radeon_encoder->base.crtc); if (radeon_crtc->crtc_id == 1) pll = &rdev->clock.p2pll; else pll = &rdev->clock.p1pll; if (pll_ref_freq) *pll_ref_freq = pll->reference_freq; if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J || tv_dac->tv_std == TV_STD_PAL_M) { if (pll->reference_freq == 2700) const_ptr = &available_tv_modes[0]; else const_ptr = &available_tv_modes[2]; } else { if (pll->reference_freq == 2700) const_ptr = &available_tv_modes[1]; else const_ptr = &available_tv_modes[3]; } return const_ptr; } static long YCOEF_value[5] = { 2, 2, 0, 4, 0 }; static long YCOEF_EN_value[5] = { 1, 1, 0, 1, 0 }; static long SLOPE_value[5] = { 1, 2, 2, 4, 8 }; static long SLOPE_limit[5] = { 6, 5, 4, 3, 2 }; static void radeon_wait_pll_lock(struct drm_encoder *encoder, unsigned n_tests, unsigned n_wait_loops, unsigned cnt_threshold) { struct drm_device *dev = encoder->dev; struct radeon_device *rdev = dev->dev_private; uint32_t save_pll_test; unsigned int i, j; WREG32(RADEON_TEST_DEBUG_MUX, (RREG32(RADEON_TEST_DEBUG_MUX) & 0xffff60ff) | 0x100); save_pll_test = RREG32_PLL(RADEON_PLL_TEST_CNTL); WREG32_PLL(RADEON_PLL_TEST_CNTL, save_pll_test & ~RADEON_PLL_MASK_READ_B); WREG8(RADEON_CLOCK_CNTL_INDEX, RADEON_PLL_TEST_CNTL); for (i = 0; i < n_tests; i++) { WREG8(RADEON_CLOCK_CNTL_DATA + 3, 0); for (j = 0; j < n_wait_loops; j++) if (RREG8(RADEON_CLOCK_CNTL_DATA + 3) >= cnt_threshold) break; } WREG32_PLL(RADEON_PLL_TEST_CNTL, save_pll_test); WREG32(RADEON_TEST_DEBUG_MUX, RREG32(RADEON_TEST_DEBUG_MUX) & 0xffffe0ff); } static void radeon_legacy_tv_write_fifo(struct radeon_encoder *radeon_encoder, uint16_t addr, uint32_t value) { struct drm_device *dev = radeon_encoder->base.dev; struct radeon_device *rdev = dev->dev_private; uint32_t tmp; int i = 0; WREG32(RADEON_TV_HOST_WRITE_DATA, value); WREG32(RADEON_TV_HOST_RD_WT_CNTL, addr); WREG32(RADEON_TV_HOST_RD_WT_CNTL, addr | RADEON_HOST_FIFO_WT); do { tmp = RREG32(RADEON_TV_HOST_RD_WT_CNTL); if ((tmp & RADEON_HOST_FIFO_WT_ACK) == 0) break; i++; } while (i < 10000); WREG32(RADEON_TV_HOST_RD_WT_CNTL, 0); } #if 0 /* included for completeness */ static uint32_t radeon_legacy_tv_read_fifo(struct radeon_encoder *radeon_encoder, uint16_t addr) { struct drm_device *dev = radeon_encoder->base.dev; struct radeon_device *rdev = dev->dev_private; uint32_t tmp; int i = 0; WREG32(RADEON_TV_HOST_RD_WT_CNTL, addr); WREG32(RADEON_TV_HOST_RD_WT_CNTL, addr | RADEON_HOST_FIFO_RD); do { tmp = RREG32(RADEON_TV_HOST_RD_WT_CNTL); if ((tmp & RADEON_HOST_FIFO_RD_ACK) == 0) break; i++; } while (i < 10000); WREG32(RADEON_TV_HOST_RD_WT_CNTL, 0); return RREG32(RADEON_TV_HOST_READ_DATA); } #endif static uint16_t radeon_get_htiming_tables_addr(uint32_t tv_uv_adr) { uint16_t h_table; switch ((tv_uv_adr & RADEON_HCODE_TABLE_SEL_MASK) >> RADEON_HCODE_TABLE_SEL_SHIFT) { case 0: h_table = RADEON_TV_MAX_FIFO_ADDR_INTERNAL; break; case 1: h_table = ((tv_uv_adr & RADEON_TABLE1_BOT_ADR_MASK) >> RADEON_TABLE1_BOT_ADR_SHIFT) * 2; break; case 2: h_table = ((tv_uv_adr & RADEON_TABLE3_TOP_ADR_MASK) >> RADEON_TABLE3_TOP_ADR_SHIFT) * 2; break; default: h_table = 0; break; } return h_table; } static uint16_t radeon_get_vtiming_tables_addr(uint32_t tv_uv_adr) { uint16_t v_table; switch ((tv_uv_adr & RADEON_VCODE_TABLE_SEL_MASK) >> RADEON_VCODE_TABLE_SEL_SHIFT) { case 0: v_table = ((tv_uv_adr & RADEON_MAX_UV_ADR_MASK) >> RADEON_MAX_UV_ADR_SHIFT) * 2 + 1; break; case 1: v_table = ((tv_uv_adr & RADEON_TABLE1_BOT_ADR_MASK) >> RADEON_TABLE1_BOT_ADR_SHIFT) * 2 + 1; break; case 2: v_table = ((tv_uv_adr & RADEON_TABLE3_TOP_ADR_MASK) >> RADEON_TABLE3_TOP_ADR_SHIFT) * 2 + 1; break; default: v_table = 0; break; } return v_table; } static void radeon_restore_tv_timing_tables(struct radeon_encoder *radeon_encoder) { struct drm_device *dev = radeon_encoder->base.dev; struct radeon_device *rdev = dev->dev_private; struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv; uint16_t h_table, v_table; uint32_t tmp; int i; WREG32(RADEON_TV_UV_ADR, tv_dac->tv.tv_uv_adr); h_table = radeon_get_htiming_tables_addr(tv_dac->tv.tv_uv_adr); v_table = radeon_get_vtiming_tables_addr(tv_dac->tv.tv_uv_adr); for (i = 0; i < MAX_H_CODE_TIMING_LEN; i += 2, h_table--) { tmp = ((uint32_t)tv_dac->tv.h_code_timing[i] << 14) | ((uint32_t)tv_dac->tv.h_code_timing[i+1]); radeon_legacy_tv_write_fifo(radeon_encoder, h_table, tmp); if (tv_dac->tv.h_code_timing[i] == 0 || tv_dac->tv.h_code_timing[i + 1] == 0) break; } for (i = 0; i < MAX_V_CODE_TIMING_LEN; i += 2, v_table++) { tmp = ((uint32_t)tv_dac->tv.v_code_timing[i+1] << 14) | ((uint32_t)tv_dac->tv.v_code_timing[i]); radeon_legacy_tv_write_fifo(radeon_encoder, v_table, tmp); if (tv_dac->tv.v_code_timing[i] == 0 || tv_dac->tv.v_code_timing[i + 1] == 0) break; } } static void radeon_legacy_write_tv_restarts(struct radeon_encoder *radeon_encoder) { struct drm_device *dev = radeon_encoder->base.dev; struct radeon_device *rdev = dev->dev_private; struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv; WREG32(RADEON_TV_FRESTART, tv_dac->tv.frestart); WREG32(RADEON_TV_HRESTART, tv_dac->tv.hrestart); WREG32(RADEON_TV_VRESTART, tv_dac->tv.vrestart); } static bool radeon_legacy_tv_init_restarts(struct drm_encoder *encoder) { struct drm_device *dev = encoder->dev; struct radeon_device *rdev = dev->dev_private; struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv; struct radeon_crtc *radeon_crtc; int restart; unsigned int h_total, v_total, f_total; int v_offset, h_offset; u16 p1, p2, h_inc; bool h_changed; const struct radeon_tv_mode_constants *const_ptr; struct radeon_pll *pll; radeon_crtc = to_radeon_crtc(radeon_encoder->base.crtc); if (radeon_crtc->crtc_id == 1) pll = &rdev->clock.p2pll; else pll = &rdev->clock.p1pll; const_ptr = radeon_legacy_tv_get_std_mode(radeon_encoder, NULL); if (!const_ptr) return false; h_total = const_ptr->hor_total; v_total = const_ptr->ver_total; if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J || tv_dac->tv_std == TV_STD_PAL_M || tv_dac->tv_std == TV_STD_PAL_60) f_total = NTSC_TV_VFTOTAL + 1; else f_total = PAL_TV_VFTOTAL + 1; /* adjust positions 1&2 in hor. cod timing table */ h_offset = tv_dac->h_pos * H_POS_UNIT; if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J || tv_dac->tv_std == TV_STD_PAL_M) { h_offset -= 50; p1 = hor_timing_NTSC[H_TABLE_POS1]; p2 = hor_timing_NTSC[H_TABLE_POS2]; } else { p1 = hor_timing_PAL[H_TABLE_POS1]; p2 = hor_timing_PAL[H_TABLE_POS2]; } p1 = (u16)((int)p1 + h_offset); p2 = (u16)((int)p2 - h_offset); h_changed = (p1 != tv_dac->tv.h_code_timing[H_TABLE_POS1] || p2 != tv_dac->tv.h_code_timing[H_TABLE_POS2]); tv_dac->tv.h_code_timing[H_TABLE_POS1] = p1; tv_dac->tv.h_code_timing[H_TABLE_POS2] = p2; /* Convert hOffset from n. of TV clock periods to n. of CRTC clock periods (CRTC pixels) */ h_offset = (h_offset * (int)(const_ptr->pix_to_tv)) / 1000; /* adjust restart */ restart = const_ptr->def_restart; /* * convert v_pos TV lines to n. of CRTC pixels */ if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J || tv_dac->tv_std == TV_STD_PAL_M || tv_dac->tv_std == TV_STD_PAL_60) v_offset = ((int)(v_total * h_total) * 2 * tv_dac->v_pos) / (int)(NTSC_TV_LINES_PER_FRAME); else v_offset = ((int)(v_total * h_total) * 2 * tv_dac->v_pos) / (int)(PAL_TV_LINES_PER_FRAME); restart -= v_offset + h_offset; DRM_DEBUG_KMS("compute_restarts: def = %u h = %d v = %d, p1 = %04x, p2 = %04x, restart = %d\n", const_ptr->def_restart, tv_dac->h_pos, tv_dac->v_pos, p1, p2, restart); tv_dac->tv.hrestart = restart % h_total; restart /= h_total; tv_dac->tv.vrestart = restart % v_total; restart /= v_total; tv_dac->tv.frestart = restart % f_total; DRM_DEBUG_KMS("compute_restart: F/H/V=%u,%u,%u\n", (unsigned)tv_dac->tv.frestart, (unsigned)tv_dac->tv.vrestart, (unsigned)tv_dac->tv.hrestart); /* compute h_inc from hsize */ if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J || tv_dac->tv_std == TV_STD_PAL_M) h_inc = (u16)((int)(const_ptr->hor_resolution * 4096 * NTSC_TV_CLOCK_T) / (tv_dac->h_size * (int)(NTSC_TV_H_SIZE_UNIT) + (int)(NTSC_TV_ZERO_H_SIZE))); else h_inc = (u16)((int)(const_ptr->hor_resolution * 4096 * PAL_TV_CLOCK_T) / (tv_dac->h_size * (int)(PAL_TV_H_SIZE_UNIT) + (int)(PAL_TV_ZERO_H_SIZE))); tv_dac->tv.timing_cntl = (tv_dac->tv.timing_cntl & ~RADEON_H_INC_MASK) | ((u32)h_inc << RADEON_H_INC_SHIFT); DRM_DEBUG_KMS("compute_restart: h_size = %d h_inc = %d\n", tv_dac->h_size, h_inc); return h_changed; } void radeon_legacy_tv_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode) { struct drm_device *dev = encoder->dev; struct radeon_device *rdev = dev->dev_private; struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv; const struct radeon_tv_mode_constants *const_ptr; struct radeon_crtc *radeon_crtc; int i; uint16_t pll_ref_freq; uint32_t vert_space, flicker_removal, tmp; uint32_t tv_master_cntl, tv_rgb_cntl, tv_dac_cntl; uint32_t tv_modulator_cntl1, tv_modulator_cntl2; uint32_t tv_vscaler_cntl1, tv_vscaler_cntl2; uint32_t tv_pll_cntl, tv_pll_cntl1, tv_ftotal; uint32_t tv_y_fall_cntl, tv_y_rise_cntl, tv_y_saw_tooth_cntl; uint32_t m, n, p; const uint16_t *hor_timing; const uint16_t *vert_timing; const_ptr = radeon_legacy_tv_get_std_mode(radeon_encoder, &pll_ref_freq); if (!const_ptr) return; radeon_crtc = to_radeon_crtc(encoder->crtc); tv_master_cntl = (RADEON_VIN_ASYNC_RST | RADEON_CRT_FIFO_CE_EN | RADEON_TV_FIFO_CE_EN | RADEON_TV_ON); if (!ASIC_IS_R300(rdev)) tv_master_cntl |= RADEON_TVCLK_ALWAYS_ONb; if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J) tv_master_cntl |= RADEON_RESTART_PHASE_FIX; tv_modulator_cntl1 = (RADEON_SLEW_RATE_LIMIT | RADEON_SYNC_TIP_LEVEL | RADEON_YFLT_EN | RADEON_UVFLT_EN | (6 << RADEON_CY_FILT_BLEND_SHIFT)); if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J) { tv_modulator_cntl1 |= (0x46 << RADEON_SET_UP_LEVEL_SHIFT) | (0x3b << RADEON_BLANK_LEVEL_SHIFT); tv_modulator_cntl2 = (-111 & RADEON_TV_U_BURST_LEVEL_MASK) | ((0 & RADEON_TV_V_BURST_LEVEL_MASK) << RADEON_TV_V_BURST_LEVEL_SHIFT); } else if (tv_dac->tv_std == TV_STD_SCART_PAL) { tv_modulator_cntl1 |= RADEON_ALT_PHASE_EN; tv_modulator_cntl2 = (0 & RADEON_TV_U_BURST_LEVEL_MASK) | ((0 & RADEON_TV_V_BURST_LEVEL_MASK) << RADEON_TV_V_BURST_LEVEL_SHIFT); } else { tv_modulator_cntl1 |= RADEON_ALT_PHASE_EN | (0x3b << RADEON_SET_UP_LEVEL_SHIFT) | (0x3b << RADEON_BLANK_LEVEL_SHIFT); tv_modulator_cntl2 = (-78 & RADEON_TV_U_BURST_LEVEL_MASK) | ((62 & RADEON_TV_V_BURST_LEVEL_MASK) << RADEON_TV_V_BURST_LEVEL_SHIFT); } tv_rgb_cntl = (RADEON_RGB_DITHER_EN | RADEON_TVOUT_SCALE_EN | (0x0b << RADEON_UVRAM_READ_MARGIN_SHIFT) | (0x07 << RADEON_FIFORAM_FFMACRO_READ_MARGIN_SHIFT) | RADEON_RGB_ATTEN_SEL(0x3) | RADEON_RGB_ATTEN_VAL(0xc)); if (radeon_crtc->crtc_id == 1) tv_rgb_cntl |= RADEON_RGB_SRC_SEL_CRTC2; else { if (radeon_crtc->rmx_type != RMX_OFF) tv_rgb_cntl |= RADEON_RGB_SRC_SEL_RMX; else tv_rgb_cntl |= RADEON_RGB_SRC_SEL_CRTC1; } if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J || tv_dac->tv_std == TV_STD_PAL_M || tv_dac->tv_std == TV_STD_PAL_60) vert_space = const_ptr->ver_total * 2 * 10000 / NTSC_TV_LINES_PER_FRAME; else vert_space = const_ptr->ver_total * 2 * 10000 / PAL_TV_LINES_PER_FRAME; tmp = RREG32(RADEON_TV_VSCALER_CNTL1); tmp &= 0xe3ff0000; tmp |= (vert_space * (1 << FRAC_BITS) / 10000); tv_vscaler_cntl1 = tmp; if (pll_ref_freq == 2700) tv_vscaler_cntl1 |= RADEON_RESTART_FIELD; if (const_ptr->hor_resolution == 1024) tv_vscaler_cntl1 |= (4 << RADEON_Y_DEL_W_SIG_SHIFT); else tv_vscaler_cntl1 |= (2 << RADEON_Y_DEL_W_SIG_SHIFT); /* scale up for int divide */ tmp = const_ptr->ver_total * 2 * 1000; if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J || tv_dac->tv_std == TV_STD_PAL_M || tv_dac->tv_std == TV_STD_PAL_60) { tmp /= NTSC_TV_LINES_PER_FRAME; } else { tmp /= PAL_TV_LINES_PER_FRAME; } flicker_removal = (tmp + 500) / 1000; if (flicker_removal < 3) flicker_removal = 3; for (i = 0; i < ARRAY_SIZE(SLOPE_limit); ++i) { if (flicker_removal == SLOPE_limit[i]) break; } tv_y_saw_tooth_cntl = (vert_space * SLOPE_value[i] * (1 << (FRAC_BITS - 1)) + 5001) / 10000 / 8 | ((SLOPE_value[i] * (1 << (FRAC_BITS - 1)) / 8) << 16); tv_y_fall_cntl = (YCOEF_EN_value[i] << 17) | ((YCOEF_value[i] * (1 << 8) / 8) << 24) | RADEON_Y_FALL_PING_PONG | (272 * SLOPE_value[i] / 8) * (1 << (FRAC_BITS - 1)) / 1024; tv_y_rise_cntl = RADEON_Y_RISE_PING_PONG| (flicker_removal * 1024 - 272) * SLOPE_value[i] / 8 * (1 << (FRAC_BITS - 1)) / 1024; tv_vscaler_cntl2 = RREG32(RADEON_TV_VSCALER_CNTL2) & 0x00fffff0; tv_vscaler_cntl2 |= (0x10 << 24) | RADEON_DITHER_MODE | RADEON_Y_OUTPUT_DITHER_EN | RADEON_UV_OUTPUT_DITHER_EN | RADEON_UV_TO_BUF_DITHER_EN; tmp = (tv_vscaler_cntl1 >> RADEON_UV_INC_SHIFT) & RADEON_UV_INC_MASK; tmp = ((16384 * 256 * 10) / tmp + 5) / 10; tmp = (tmp << RADEON_UV_OUTPUT_POST_SCALE_SHIFT) | 0x000b0000; tv_dac->tv.timing_cntl = tmp; if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J || tv_dac->tv_std == TV_STD_PAL_M || tv_dac->tv_std == TV_STD_PAL_60) tv_dac_cntl = tv_dac->ntsc_tvdac_adj; else tv_dac_cntl = tv_dac->pal_tvdac_adj; tv_dac_cntl |= RADEON_TV_DAC_NBLANK | RADEON_TV_DAC_NHOLD; if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J) tv_dac_cntl |= RADEON_TV_DAC_STD_NTSC; else tv_dac_cntl |= RADEON_TV_DAC_STD_PAL; if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J) { if (pll_ref_freq == 2700) { m = NTSC_TV_PLL_M_27; n = NTSC_TV_PLL_N_27; p = NTSC_TV_PLL_P_27; } else { m = NTSC_TV_PLL_M_14; n = NTSC_TV_PLL_N_14; p = NTSC_TV_PLL_P_14; } } else { if (pll_ref_freq == 2700) { m = PAL_TV_PLL_M_27; n = PAL_TV_PLL_N_27; p = PAL_TV_PLL_P_27; } else { m = PAL_TV_PLL_M_14; n = PAL_TV_PLL_N_14; p = PAL_TV_PLL_P_14; } } tv_pll_cntl = (m & RADEON_TV_M0LO_MASK) | (((m >> 8) & RADEON_TV_M0HI_MASK) << RADEON_TV_M0HI_SHIFT) | ((n & RADEON_TV_N0LO_MASK) << RADEON_TV_N0LO_SHIFT) | (((n >> 9) & RADEON_TV_N0HI_MASK) << RADEON_TV_N0HI_SHIFT) | ((p & RADEON_TV_P_MASK) << RADEON_TV_P_SHIFT); tv_pll_cntl1 = (((4 & RADEON_TVPCP_MASK) << RADEON_TVPCP_SHIFT) | ((4 & RADEON_TVPVG_MASK) << RADEON_TVPVG_SHIFT) | ((1 & RADEON_TVPDC_MASK) << RADEON_TVPDC_SHIFT) | RADEON_TVCLK_SRC_SEL_TVPLL | RADEON_TVPLL_TEST_DIS); tv_dac->tv.tv_uv_adr = 0xc8; if (tv_dac->tv_std == TV_STD_NTSC || tv_dac->tv_std == TV_STD_NTSC_J || tv_dac->tv_std == TV_STD_PAL_M || tv_dac->tv_std == TV_STD_PAL_60) { tv_ftotal = NTSC_TV_VFTOTAL; hor_timing = hor_timing_NTSC; vert_timing = vert_timing_NTSC; } else { hor_timing = hor_timing_PAL; vert_timing = vert_timing_PAL; tv_ftotal = PAL_TV_VFTOTAL; } for (i = 0; i < MAX_H_CODE_TIMING_LEN; i++) { if ((tv_dac->tv.h_code_timing[i] = hor_timing[i]) == 0) break; } for (i = 0; i < MAX_V_CODE_TIMING_LEN; i++) { if ((tv_dac->tv.v_code_timing[i] = vert_timing[i]) == 0) break; } radeon_legacy_tv_init_restarts(encoder); /* play with DAC_CNTL */ /* play with GPIOPAD_A */ /* DISP_OUTPUT_CNTL */ /* use reference freq */ /* program the TV registers */ WREG32(RADEON_TV_MASTER_CNTL, (tv_master_cntl | RADEON_TV_ASYNC_RST | RADEON_CRT_ASYNC_RST | RADEON_TV_FIFO_ASYNC_RST)); tmp = RREG32(RADEON_TV_DAC_CNTL); tmp &= ~RADEON_TV_DAC_NBLANK; tmp |= RADEON_TV_DAC_BGSLEEP | RADEON_TV_DAC_RDACPD | RADEON_TV_DAC_GDACPD | RADEON_TV_DAC_BDACPD; WREG32(RADEON_TV_DAC_CNTL, tmp); /* TV PLL */ WREG32_PLL_P(RADEON_TV_PLL_CNTL1, 0, ~RADEON_TVCLK_SRC_SEL_TVPLL); WREG32_PLL(RADEON_TV_PLL_CNTL, tv_pll_cntl); WREG32_PLL_P(RADEON_TV_PLL_CNTL1, RADEON_TVPLL_RESET, ~RADEON_TVPLL_RESET); radeon_wait_pll_lock(encoder, 200, 800, 135); WREG32_PLL_P(RADEON_TV_PLL_CNTL1, 0, ~RADEON_TVPLL_RESET); radeon_wait_pll_lock(encoder, 300, 160, 27); radeon_wait_pll_lock(encoder, 200, 800, 135); WREG32_PLL_P(RADEON_TV_PLL_CNTL1, 0, ~0xf); WREG32_PLL_P(RADEON_TV_PLL_CNTL1, RADEON_TVCLK_SRC_SEL_TVPLL, ~RADEON_TVCLK_SRC_SEL_TVPLL); WREG32_PLL_P(RADEON_TV_PLL_CNTL1, (1 << RADEON_TVPDC_SHIFT), ~RADEON_TVPDC_MASK); WREG32_PLL_P(RADEON_TV_PLL_CNTL1, 0, ~RADEON_TVPLL_SLEEP); /* TV HV */ WREG32(RADEON_TV_RGB_CNTL, tv_rgb_cntl); WREG32(RADEON_TV_HTOTAL, const_ptr->hor_total - 1); WREG32(RADEON_TV_HDISP, const_ptr->hor_resolution - 1); WREG32(RADEON_TV_HSTART, const_ptr->hor_start); WREG32(RADEON_TV_VTOTAL, const_ptr->ver_total - 1); WREG32(RADEON_TV_VDISP, const_ptr->ver_resolution - 1); WREG32(RADEON_TV_FTOTAL, tv_ftotal); WREG32(RADEON_TV_VSCALER_CNTL1, tv_vscaler_cntl1); WREG32(RADEON_TV_VSCALER_CNTL2, tv_vscaler_cntl2); WREG32(RADEON_TV_Y_FALL_CNTL, tv_y_fall_cntl); WREG32(RADEON_TV_Y_RISE_CNTL, tv_y_rise_cntl); WREG32(RADEON_TV_Y_SAW_TOOTH_CNTL, tv_y_saw_tooth_cntl); WREG32(RADEON_TV_MASTER_CNTL, (tv_master_cntl | RADEON_TV_ASYNC_RST | RADEON_CRT_ASYNC_RST)); /* TV restarts */ radeon_legacy_write_tv_restarts(radeon_encoder); /* tv timings */ radeon_restore_tv_timing_tables(radeon_encoder); WREG32(RADEON_TV_MASTER_CNTL, (tv_master_cntl | RADEON_TV_ASYNC_RST)); /* tv std */ WREG32(RADEON_TV_SYNC_CNTL, (RADEON_SYNC_PUB | RADEON_TV_SYNC_IO_DRIVE)); WREG32(RADEON_TV_TIMING_CNTL, tv_dac->tv.timing_cntl); WREG32(RADEON_TV_MODULATOR_CNTL1, tv_modulator_cntl1); WREG32(RADEON_TV_MODULATOR_CNTL2, tv_modulator_cntl2); WREG32(RADEON_TV_PRE_DAC_MUX_CNTL, (RADEON_Y_RED_EN | RADEON_C_GRN_EN | RADEON_CMP_BLU_EN | RADEON_DAC_DITHER_EN)); WREG32(RADEON_TV_CRC_CNTL, 0); WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl); WREG32(RADEON_TV_GAIN_LIMIT_SETTINGS, ((0x17f << RADEON_UV_GAIN_LIMIT_SHIFT) | (0x5ff << RADEON_Y_GAIN_LIMIT_SHIFT))); WREG32(RADEON_TV_LINEAR_GAIN_SETTINGS, ((0x100 << RADEON_UV_GAIN_SHIFT) | (0x100 << RADEON_Y_GAIN_SHIFT))); WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl); } void radeon_legacy_tv_adjust_crtc_reg(struct drm_encoder *encoder, uint32_t *h_total_disp, uint32_t *h_sync_strt_wid, uint32_t *v_total_disp, uint32_t *v_sync_strt_wid) { struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); const struct radeon_tv_mode_constants *const_ptr; uint32_t tmp; const_ptr = radeon_legacy_tv_get_std_mode(radeon_encoder, NULL); if (!const_ptr) return; *h_total_disp = (((const_ptr->hor_resolution / 8) - 1) << RADEON_CRTC_H_DISP_SHIFT) | (((const_ptr->hor_total / 8) - 1) << RADEON_CRTC_H_TOTAL_SHIFT); tmp = *h_sync_strt_wid; tmp &= ~(RADEON_CRTC_H_SYNC_STRT_PIX | RADEON_CRTC_H_SYNC_STRT_CHAR); tmp |= (((const_ptr->hor_syncstart / 8) - 1) << RADEON_CRTC_H_SYNC_STRT_CHAR_SHIFT) | (const_ptr->hor_syncstart & 7); *h_sync_strt_wid = tmp; *v_total_disp = ((const_ptr->ver_resolution - 1) << RADEON_CRTC_V_DISP_SHIFT) | ((const_ptr->ver_total - 1) << RADEON_CRTC_V_TOTAL_SHIFT); tmp = *v_sync_strt_wid; tmp &= ~RADEON_CRTC_V_SYNC_STRT; tmp |= ((const_ptr->ver_syncstart - 1) << RADEON_CRTC_V_SYNC_STRT_SHIFT); *v_sync_strt_wid = tmp; } static inline int get_post_div(int value) { int post_div; switch (value) { case 1: post_div = 0; break; case 2: post_div = 1; break; case 3: post_div = 4; break; case 4: post_div = 2; break; case 6: post_div = 6; break; case 8: post_div = 3; break; case 12: post_div = 7; break; case 16: default: post_div = 5; break; } return post_div; } void radeon_legacy_tv_adjust_pll1(struct drm_encoder *encoder, uint32_t *htotal_cntl, uint32_t *ppll_ref_div, uint32_t *ppll_div_3, uint32_t *pixclks_cntl) { struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); const struct radeon_tv_mode_constants *const_ptr; const_ptr = radeon_legacy_tv_get_std_mode(radeon_encoder, NULL); if (!const_ptr) return; *htotal_cntl = (const_ptr->hor_total & 0x7) | RADEON_HTOT_CNTL_VGA_EN; *ppll_ref_div = const_ptr->crtcPLL_M; *ppll_div_3 = (const_ptr->crtcPLL_N & 0x7ff) | (get_post_div(const_ptr->crtcPLL_post_div) << 16); *pixclks_cntl &= ~(RADEON_PIX2CLK_SRC_SEL_MASK | RADEON_PIXCLK_TV_SRC_SEL); *pixclks_cntl |= RADEON_PIX2CLK_SRC_SEL_P2PLLCLK; } void radeon_legacy_tv_adjust_pll2(struct drm_encoder *encoder, uint32_t *htotal2_cntl, uint32_t *p2pll_ref_div, uint32_t *p2pll_div_0, uint32_t *pixclks_cntl) { struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); const struct radeon_tv_mode_constants *const_ptr; const_ptr = radeon_legacy_tv_get_std_mode(radeon_encoder, NULL); if (!const_ptr) return; *htotal2_cntl = (const_ptr->hor_total & 0x7); *p2pll_ref_div = const_ptr->crtcPLL_M; *p2pll_div_0 = (const_ptr->crtcPLL_N & 0x7ff) | (get_post_div(const_ptr->crtcPLL_post_div) << 16); *pixclks_cntl &= ~RADEON_PIX2CLK_SRC_SEL_MASK; *pixclks_cntl |= RADEON_PIX2CLK_SRC_SEL_P2PLLCLK | RADEON_PIXCLK_TV_SRC_SEL; }
gpl-2.0
javelinanddart/shamu
arch/sh/drivers/pci/pcie-sh7786.c
4289
14275
/* * Low-Level PCI Express Support for the SH7786 * * Copyright (C) 2009 - 2011 Paul Mundt * * 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. */ #define pr_fmt(fmt) "PCI: " fmt #include <linux/pci.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/io.h> #include <linux/async.h> #include <linux/delay.h> #include <linux/slab.h> #include <linux/clk.h> #include <linux/sh_clk.h> #include <linux/sh_intc.h> #include "pcie-sh7786.h" #include <asm/sizes.h> struct sh7786_pcie_port { struct pci_channel *hose; struct clk *fclk, phy_clk; unsigned int index; int endpoint; int link; }; static struct sh7786_pcie_port *sh7786_pcie_ports; static unsigned int nr_ports; static struct sh7786_pcie_hwops { int (*core_init)(void); async_func_t port_init_hw; } *sh7786_pcie_hwops; static struct resource sh7786_pci0_resources[] = { { .name = "PCIe0 IO", .start = 0xfd000000, .end = 0xfd000000 + SZ_8M - 1, .flags = IORESOURCE_IO, }, { .name = "PCIe0 MEM 0", .start = 0xc0000000, .end = 0xc0000000 + SZ_512M - 1, .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT, }, { .name = "PCIe0 MEM 1", .start = 0x10000000, .end = 0x10000000 + SZ_64M - 1, .flags = IORESOURCE_MEM, }, { .name = "PCIe0 MEM 2", .start = 0xfe100000, .end = 0xfe100000 + SZ_1M - 1, .flags = IORESOURCE_MEM, }, }; static struct resource sh7786_pci1_resources[] = { { .name = "PCIe1 IO", .start = 0xfd800000, .end = 0xfd800000 + SZ_8M - 1, .flags = IORESOURCE_IO, }, { .name = "PCIe1 MEM 0", .start = 0xa0000000, .end = 0xa0000000 + SZ_512M - 1, .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT, }, { .name = "PCIe1 MEM 1", .start = 0x30000000, .end = 0x30000000 + SZ_256M - 1, .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT, }, { .name = "PCIe1 MEM 2", .start = 0xfe300000, .end = 0xfe300000 + SZ_1M - 1, .flags = IORESOURCE_MEM, }, }; static struct resource sh7786_pci2_resources[] = { { .name = "PCIe2 IO", .start = 0xfc800000, .end = 0xfc800000 + SZ_4M - 1, .flags = IORESOURCE_IO, }, { .name = "PCIe2 MEM 0", .start = 0x80000000, .end = 0x80000000 + SZ_512M - 1, .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT, }, { .name = "PCIe2 MEM 1", .start = 0x20000000, .end = 0x20000000 + SZ_256M - 1, .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT, }, { .name = "PCIe2 MEM 2", .start = 0xfcd00000, .end = 0xfcd00000 + SZ_1M - 1, .flags = IORESOURCE_MEM, }, }; extern struct pci_ops sh7786_pci_ops; #define DEFINE_CONTROLLER(start, idx) \ { \ .pci_ops = &sh7786_pci_ops, \ .resources = sh7786_pci##idx##_resources, \ .nr_resources = ARRAY_SIZE(sh7786_pci##idx##_resources), \ .reg_base = start, \ .mem_offset = 0, \ .io_offset = 0, \ } static struct pci_channel sh7786_pci_channels[] = { DEFINE_CONTROLLER(0xfe000000, 0), DEFINE_CONTROLLER(0xfe200000, 1), DEFINE_CONTROLLER(0xfcc00000, 2), }; static struct clk fixed_pciexclkp = { .rate = 100000000, /* 100 MHz reference clock */ }; static void sh7786_pci_fixup(struct pci_dev *dev) { /* * Prevent enumeration of root complex resources. */ if (pci_is_root_bus(dev->bus) && dev->devfn == 0) { int i; for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { dev->resource[i].start = 0; dev->resource[i].end = 0; dev->resource[i].flags = 0; } } } DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_RENESAS, PCI_DEVICE_ID_RENESAS_SH7786, sh7786_pci_fixup); static int __init phy_wait_for_ack(struct pci_channel *chan) { unsigned int timeout = 100; while (timeout--) { if (pci_read_reg(chan, SH4A_PCIEPHYADRR) & (1 << BITS_ACK)) return 0; udelay(100); } return -ETIMEDOUT; } static int __init pci_wait_for_irq(struct pci_channel *chan, unsigned int mask) { unsigned int timeout = 100; while (timeout--) { if ((pci_read_reg(chan, SH4A_PCIEINTR) & mask) == mask) return 0; udelay(100); } return -ETIMEDOUT; } static void __init phy_write_reg(struct pci_channel *chan, unsigned int addr, unsigned int lane, unsigned int data) { unsigned long phyaddr; phyaddr = (1 << BITS_CMD) + ((lane & 0xf) << BITS_LANE) + ((addr & 0xff) << BITS_ADR); /* Set write data */ pci_write_reg(chan, data, SH4A_PCIEPHYDOUTR); pci_write_reg(chan, phyaddr, SH4A_PCIEPHYADRR); phy_wait_for_ack(chan); /* Clear command */ pci_write_reg(chan, 0, SH4A_PCIEPHYDOUTR); pci_write_reg(chan, 0, SH4A_PCIEPHYADRR); phy_wait_for_ack(chan); } static int __init pcie_clk_init(struct sh7786_pcie_port *port) { struct pci_channel *chan = port->hose; struct clk *clk; char fclk_name[16]; int ret; /* * First register the fixed clock */ ret = clk_register(&fixed_pciexclkp); if (unlikely(ret != 0)) return ret; /* * Grab the port's function clock, which the PHY clock depends * on. clock lookups don't help us much at this point, since no * dev_id is available this early. Lame. */ snprintf(fclk_name, sizeof(fclk_name), "pcie%d_fck", port->index); port->fclk = clk_get(NULL, fclk_name); if (IS_ERR(port->fclk)) { ret = PTR_ERR(port->fclk); goto err_fclk; } clk_enable(port->fclk); /* * And now, set up the PHY clock */ clk = &port->phy_clk; memset(clk, 0, sizeof(struct clk)); clk->parent = &fixed_pciexclkp; clk->enable_reg = (void __iomem *)(chan->reg_base + SH4A_PCIEPHYCTLR); clk->enable_bit = BITS_CKE; ret = sh_clk_mstp_register(clk, 1); if (unlikely(ret < 0)) goto err_phy; return 0; err_phy: clk_disable(port->fclk); clk_put(port->fclk); err_fclk: clk_unregister(&fixed_pciexclkp); return ret; } static int __init phy_init(struct sh7786_pcie_port *port) { struct pci_channel *chan = port->hose; unsigned int timeout = 100; clk_enable(&port->phy_clk); /* Initialize the phy */ phy_write_reg(chan, 0x60, 0xf, 0x004b008b); phy_write_reg(chan, 0x61, 0xf, 0x00007b41); phy_write_reg(chan, 0x64, 0xf, 0x00ff4f00); phy_write_reg(chan, 0x65, 0xf, 0x09070907); phy_write_reg(chan, 0x66, 0xf, 0x00000010); phy_write_reg(chan, 0x74, 0xf, 0x0007001c); phy_write_reg(chan, 0x79, 0xf, 0x01fc000d); phy_write_reg(chan, 0xb0, 0xf, 0x00000610); /* Deassert Standby */ phy_write_reg(chan, 0x67, 0x1, 0x00000400); /* Disable clock */ clk_disable(&port->phy_clk); while (timeout--) { if (pci_read_reg(chan, SH4A_PCIEPHYSR)) return 0; udelay(100); } return -ETIMEDOUT; } static void __init pcie_reset(struct sh7786_pcie_port *port) { struct pci_channel *chan = port->hose; pci_write_reg(chan, 1, SH4A_PCIESRSTR); pci_write_reg(chan, 0, SH4A_PCIETCTLR); pci_write_reg(chan, 0, SH4A_PCIESRSTR); pci_write_reg(chan, 0, SH4A_PCIETXVC0SR); } static int __init pcie_init(struct sh7786_pcie_port *port) { struct pci_channel *chan = port->hose; unsigned int data; phys_addr_t memphys; size_t memsize; int ret, i, win; /* Begin initialization */ pcie_reset(port); /* * Initial header for port config space is type 1, set the device * class to match. Hardware takes care of propagating the IDSETR * settings, so there is no need to bother with a quirk. */ pci_write_reg(chan, PCI_CLASS_BRIDGE_PCI << 16, SH4A_PCIEIDSETR1); /* Initialize default capabilities. */ data = pci_read_reg(chan, SH4A_PCIEEXPCAP0); data &= ~(PCI_EXP_FLAGS_TYPE << 16); if (port->endpoint) data |= PCI_EXP_TYPE_ENDPOINT << 20; else data |= PCI_EXP_TYPE_ROOT_PORT << 20; data |= PCI_CAP_ID_EXP; pci_write_reg(chan, data, SH4A_PCIEEXPCAP0); /* Enable data link layer active state reporting */ pci_write_reg(chan, PCI_EXP_LNKCAP_DLLLARC, SH4A_PCIEEXPCAP3); /* Enable extended sync and ASPM L0s support */ data = pci_read_reg(chan, SH4A_PCIEEXPCAP4); data &= ~PCI_EXP_LNKCTL_ASPMC; data |= PCI_EXP_LNKCTL_ES | 1; pci_write_reg(chan, data, SH4A_PCIEEXPCAP4); /* Write out the physical slot number */ data = pci_read_reg(chan, SH4A_PCIEEXPCAP5); data &= ~PCI_EXP_SLTCAP_PSN; data |= (port->index + 1) << 19; pci_write_reg(chan, data, SH4A_PCIEEXPCAP5); /* Set the completion timer timeout to the maximum 32ms. */ data = pci_read_reg(chan, SH4A_PCIETLCTLR); data &= ~0x3f00; data |= 0x32 << 8; pci_write_reg(chan, data, SH4A_PCIETLCTLR); /* * Set fast training sequences to the maximum 255, * and enable MAC data scrambling. */ data = pci_read_reg(chan, SH4A_PCIEMACCTLR); data &= ~PCIEMACCTLR_SCR_DIS; data |= (0xff << 16); pci_write_reg(chan, data, SH4A_PCIEMACCTLR); memphys = __pa(memory_start); memsize = roundup_pow_of_two(memory_end - memory_start); /* * If there's more than 512MB of memory, we need to roll over to * LAR1/LAMR1. */ if (memsize > SZ_512M) { pci_write_reg(chan, memphys + SZ_512M, SH4A_PCIELAR1); pci_write_reg(chan, ((memsize - SZ_512M) - SZ_256) | 1, SH4A_PCIELAMR1); memsize = SZ_512M; } else { /* * Otherwise just zero it out and disable it. */ pci_write_reg(chan, 0, SH4A_PCIELAR1); pci_write_reg(chan, 0, SH4A_PCIELAMR1); } /* * LAR0/LAMR0 covers up to the first 512MB, which is enough to * cover all of lowmem on most platforms. */ pci_write_reg(chan, memphys, SH4A_PCIELAR0); pci_write_reg(chan, (memsize - SZ_256) | 1, SH4A_PCIELAMR0); /* Finish initialization */ data = pci_read_reg(chan, SH4A_PCIETCTLR); data |= 0x1; pci_write_reg(chan, data, SH4A_PCIETCTLR); /* Let things settle down a bit.. */ mdelay(100); /* Enable DL_Active Interrupt generation */ data = pci_read_reg(chan, SH4A_PCIEDLINTENR); data |= PCIEDLINTENR_DLL_ACT_ENABLE; pci_write_reg(chan, data, SH4A_PCIEDLINTENR); /* Disable MAC data scrambling. */ data = pci_read_reg(chan, SH4A_PCIEMACCTLR); data |= PCIEMACCTLR_SCR_DIS | (0xff << 16); pci_write_reg(chan, data, SH4A_PCIEMACCTLR); /* * This will timeout if we don't have a link, but we permit the * port to register anyways in order to support hotplug on future * hardware. */ ret = pci_wait_for_irq(chan, MASK_INT_TX_CTRL); data = pci_read_reg(chan, SH4A_PCIEPCICONF1); data &= ~(PCI_STATUS_DEVSEL_MASK << 16); data |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | (PCI_STATUS_CAP_LIST | PCI_STATUS_DEVSEL_FAST) << 16; pci_write_reg(chan, data, SH4A_PCIEPCICONF1); pci_write_reg(chan, 0x80888000, SH4A_PCIETXVC0DCTLR); pci_write_reg(chan, 0x00222000, SH4A_PCIERXVC0DCTLR); wmb(); if (ret == 0) { data = pci_read_reg(chan, SH4A_PCIEMACSR); printk(KERN_NOTICE "PCI: PCIe#%d x%d link detected\n", port->index, (data >> 20) & 0x3f); } else printk(KERN_NOTICE "PCI: PCIe#%d link down\n", port->index); for (i = win = 0; i < chan->nr_resources; i++) { struct resource *res = chan->resources + i; resource_size_t size; u32 mask; /* * We can't use the 32-bit mode windows in legacy 29-bit * mode, so just skip them entirely. */ if ((res->flags & IORESOURCE_MEM_32BIT) && __in_29bit_mode()) continue; pci_write_reg(chan, 0x00000000, SH4A_PCIEPTCTLR(win)); /* * The PAMR mask is calculated in units of 256kB, which * keeps things pretty simple. */ size = resource_size(res); mask = (roundup_pow_of_two(size) / SZ_256K) - 1; pci_write_reg(chan, mask << 18, SH4A_PCIEPAMR(win)); pci_write_reg(chan, upper_32_bits(res->start), SH4A_PCIEPARH(win)); pci_write_reg(chan, lower_32_bits(res->start), SH4A_PCIEPARL(win)); mask = MASK_PARE; if (res->flags & IORESOURCE_IO) mask |= MASK_SPC; pci_write_reg(chan, mask, SH4A_PCIEPTCTLR(win)); win++; } return 0; } int __init pcibios_map_platform_irq(const struct pci_dev *pdev, u8 slot, u8 pin) { return evt2irq(0xae0); } static int __init sh7786_pcie_core_init(void) { /* Return the number of ports */ return test_mode_pin(MODE_PIN12) ? 3 : 2; } static void __init sh7786_pcie_init_hw(void *data, async_cookie_t cookie) { struct sh7786_pcie_port *port = data; int ret; /* * Check if we are configured in endpoint or root complex mode, * this is a fixed pin setting that applies to all PCIe ports. */ port->endpoint = test_mode_pin(MODE_PIN11); /* * Setup clocks, needed both for PHY and PCIe registers. */ ret = pcie_clk_init(port); if (unlikely(ret < 0)) { pr_err("clock initialization failed for port#%d\n", port->index); return; } ret = phy_init(port); if (unlikely(ret < 0)) { pr_err("phy initialization failed for port#%d\n", port->index); return; } ret = pcie_init(port); if (unlikely(ret < 0)) { pr_err("core initialization failed for port#%d\n", port->index); return; } /* In the interest of preserving device ordering, synchronize */ async_synchronize_cookie(cookie); register_pci_controller(port->hose); } static struct sh7786_pcie_hwops sh7786_65nm_pcie_hwops __initdata = { .core_init = sh7786_pcie_core_init, .port_init_hw = sh7786_pcie_init_hw, }; static int __init sh7786_pcie_init(void) { struct clk *platclk; int i; printk(KERN_NOTICE "PCI: Starting initialization.\n"); sh7786_pcie_hwops = &sh7786_65nm_pcie_hwops; nr_ports = sh7786_pcie_hwops->core_init(); BUG_ON(nr_ports > ARRAY_SIZE(sh7786_pci_channels)); if (unlikely(nr_ports == 0)) return -ENODEV; sh7786_pcie_ports = kzalloc(nr_ports * sizeof(struct sh7786_pcie_port), GFP_KERNEL); if (unlikely(!sh7786_pcie_ports)) return -ENOMEM; /* * Fetch any optional platform clock associated with this block. * * This is a rather nasty hack for boards with spec-mocking FPGAs * that have a secondary set of clocks outside of the on-chip * ones that need to be accounted for before there is any chance * of touching the existing MSTP bits or CPG clocks. */ platclk = clk_get(NULL, "pcie_plat_clk"); if (IS_ERR(platclk)) { /* Sane hardware should probably get a WARN_ON.. */ platclk = NULL; } clk_enable(platclk); printk(KERN_NOTICE "PCI: probing %d ports.\n", nr_ports); for (i = 0; i < nr_ports; i++) { struct sh7786_pcie_port *port = sh7786_pcie_ports + i; port->index = i; port->hose = sh7786_pci_channels + i; port->hose->io_map_base = port->hose->resources[0].start; async_schedule(sh7786_pcie_hwops->port_init_hw, port); } async_synchronize_full(); return 0; } arch_initcall(sh7786_pcie_init);
gpl-2.0
martyborya/N3-CM-Unified
drivers/isdn/hardware/mISDN/w6692.c
4801
36929
/* * w6692.c mISDN driver for Winbond w6692 based cards * * Author Karsten Keil <kkeil@suse.de> * based on the w6692 I4L driver from Petr Novak <petr.novak@i.cz> * * Copyright 2009 by Karsten Keil <keil@isdn4linux.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. * * 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/interrupt.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/delay.h> #include <linux/mISDNhw.h> #include <linux/slab.h> #include "w6692.h" #define W6692_REV "2.0" #define DBUSY_TIMER_VALUE 80 enum { W6692_ASUS, W6692_WINBOND, W6692_USR }; /* private data in the PCI devices list */ struct w6692map { u_int subtype; char *name; }; static const struct w6692map w6692_map[] = { {W6692_ASUS, "Dynalink/AsusCom IS64PH"}, {W6692_WINBOND, "Winbond W6692"}, {W6692_USR, "USR W6692"} }; #ifndef PCI_VENDOR_ID_USR #define PCI_VENDOR_ID_USR 0x16ec #define PCI_DEVICE_ID_USR_6692 0x3409 #endif struct w6692_ch { struct bchannel bch; u32 addr; struct timer_list timer; u8 b_mode; }; struct w6692_hw { struct list_head list; struct pci_dev *pdev; char name[MISDN_MAX_IDLEN]; u32 irq; u32 irqcnt; u32 addr; u32 fmask; /* feature mask - bit set per card nr */ int subtype; spinlock_t lock; /* hw lock */ u8 imask; u8 pctl; u8 xaddr; u8 xdata; u8 state; struct w6692_ch bc[2]; struct dchannel dch; char log[64]; }; static LIST_HEAD(Cards); static DEFINE_RWLOCK(card_lock); /* protect Cards */ static int w6692_cnt; static int debug; static u32 led; static u32 pots; static void _set_debug(struct w6692_hw *card) { card->dch.debug = debug; card->bc[0].bch.debug = debug; card->bc[1].bch.debug = debug; } static int set_debug(const char *val, struct kernel_param *kp) { int ret; struct w6692_hw *card; ret = param_set_uint(val, kp); if (!ret) { read_lock(&card_lock); list_for_each_entry(card, &Cards, list) _set_debug(card); read_unlock(&card_lock); } return ret; } MODULE_AUTHOR("Karsten Keil"); MODULE_LICENSE("GPL v2"); MODULE_VERSION(W6692_REV); module_param_call(debug, set_debug, param_get_uint, &debug, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(debug, "W6692 debug mask"); module_param(led, uint, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(led, "W6692 LED support bitmask (one bit per card)"); module_param(pots, uint, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(pots, "W6692 POTS support bitmask (one bit per card)"); static inline u8 ReadW6692(struct w6692_hw *card, u8 offset) { return inb(card->addr + offset); } static inline void WriteW6692(struct w6692_hw *card, u8 offset, u8 value) { outb(value, card->addr + offset); } static inline u8 ReadW6692B(struct w6692_ch *bc, u8 offset) { return inb(bc->addr + offset); } static inline void WriteW6692B(struct w6692_ch *bc, u8 offset, u8 value) { outb(value, bc->addr + offset); } static void enable_hwirq(struct w6692_hw *card) { WriteW6692(card, W_IMASK, card->imask); } static void disable_hwirq(struct w6692_hw *card) { WriteW6692(card, W_IMASK, 0xff); } static const char *W6692Ver[] = {"V00", "V01", "V10", "V11"}; static void W6692Version(struct w6692_hw *card) { int val; val = ReadW6692(card, W_D_RBCH); pr_notice("%s: Winbond W6692 version: %s\n", card->name, W6692Ver[(val >> 6) & 3]); } static void w6692_led_handler(struct w6692_hw *card, int on) { if ((!(card->fmask & led)) || card->subtype == W6692_USR) return; if (on) { card->xdata &= 0xfb; /* LED ON */ WriteW6692(card, W_XDATA, card->xdata); } else { card->xdata |= 0x04; /* LED OFF */ WriteW6692(card, W_XDATA, card->xdata); } } static void ph_command(struct w6692_hw *card, u8 cmd) { pr_debug("%s: ph_command %x\n", card->name, cmd); WriteW6692(card, W_CIX, cmd); } static void W6692_new_ph(struct w6692_hw *card) { if (card->state == W_L1CMD_RST) ph_command(card, W_L1CMD_DRC); schedule_event(&card->dch, FLG_PHCHANGE); } static void W6692_ph_bh(struct dchannel *dch) { struct w6692_hw *card = dch->hw; switch (card->state) { case W_L1CMD_RST: dch->state = 0; l1_event(dch->l1, HW_RESET_IND); break; case W_L1IND_CD: dch->state = 3; l1_event(dch->l1, HW_DEACT_CNF); break; case W_L1IND_DRD: dch->state = 3; l1_event(dch->l1, HW_DEACT_IND); break; case W_L1IND_CE: dch->state = 4; l1_event(dch->l1, HW_POWERUP_IND); break; case W_L1IND_LD: if (dch->state <= 5) { dch->state = 5; l1_event(dch->l1, ANYSIGNAL); } else { dch->state = 8; l1_event(dch->l1, LOSTFRAMING); } break; case W_L1IND_ARD: dch->state = 6; l1_event(dch->l1, INFO2); break; case W_L1IND_AI8: dch->state = 7; l1_event(dch->l1, INFO4_P8); break; case W_L1IND_AI10: dch->state = 7; l1_event(dch->l1, INFO4_P10); break; default: pr_debug("%s: TE unknown state %02x dch state %02x\n", card->name, card->state, dch->state); break; } pr_debug("%s: TE newstate %02x\n", card->name, dch->state); } static void W6692_empty_Dfifo(struct w6692_hw *card, int count) { struct dchannel *dch = &card->dch; u8 *ptr; pr_debug("%s: empty_Dfifo %d\n", card->name, count); if (!dch->rx_skb) { dch->rx_skb = mI_alloc_skb(card->dch.maxlen, GFP_ATOMIC); if (!dch->rx_skb) { pr_info("%s: D receive out of memory\n", card->name); WriteW6692(card, W_D_CMDR, W_D_CMDR_RACK); return; } } if ((dch->rx_skb->len + count) >= dch->maxlen) { pr_debug("%s: empty_Dfifo overrun %d\n", card->name, dch->rx_skb->len + count); WriteW6692(card, W_D_CMDR, W_D_CMDR_RACK); return; } ptr = skb_put(dch->rx_skb, count); insb(card->addr + W_D_RFIFO, ptr, count); WriteW6692(card, W_D_CMDR, W_D_CMDR_RACK); if (debug & DEBUG_HW_DFIFO) { snprintf(card->log, 63, "D-recv %s %d ", card->name, count); print_hex_dump_bytes(card->log, DUMP_PREFIX_OFFSET, ptr, count); } } static void W6692_fill_Dfifo(struct w6692_hw *card) { struct dchannel *dch = &card->dch; int count; u8 *ptr; u8 cmd = W_D_CMDR_XMS; pr_debug("%s: fill_Dfifo\n", card->name); if (!dch->tx_skb) return; count = dch->tx_skb->len - dch->tx_idx; if (count <= 0) return; if (count > W_D_FIFO_THRESH) count = W_D_FIFO_THRESH; else cmd |= W_D_CMDR_XME; ptr = dch->tx_skb->data + dch->tx_idx; dch->tx_idx += count; outsb(card->addr + W_D_XFIFO, ptr, count); WriteW6692(card, W_D_CMDR, cmd); if (test_and_set_bit(FLG_BUSY_TIMER, &dch->Flags)) { pr_debug("%s: fill_Dfifo dbusytimer running\n", card->name); del_timer(&dch->timer); } init_timer(&dch->timer); dch->timer.expires = jiffies + ((DBUSY_TIMER_VALUE * HZ) / 1000); add_timer(&dch->timer); if (debug & DEBUG_HW_DFIFO) { snprintf(card->log, 63, "D-send %s %d ", card->name, count); print_hex_dump_bytes(card->log, DUMP_PREFIX_OFFSET, ptr, count); } } static void d_retransmit(struct w6692_hw *card) { struct dchannel *dch = &card->dch; if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags)) del_timer(&dch->timer); #ifdef FIXME if (test_and_clear_bit(FLG_L1_BUSY, &dch->Flags)) dchannel_sched_event(dch, D_CLEARBUSY); #endif if (test_bit(FLG_TX_BUSY, &dch->Flags)) { /* Restart frame */ dch->tx_idx = 0; W6692_fill_Dfifo(card); } else if (dch->tx_skb) { /* should not happen */ pr_info("%s: %s without TX_BUSY\n", card->name, __func__); test_and_set_bit(FLG_TX_BUSY, &dch->Flags); dch->tx_idx = 0; W6692_fill_Dfifo(card); } else { pr_info("%s: XDU no TX_BUSY\n", card->name); if (get_next_dframe(dch)) W6692_fill_Dfifo(card); } } static void handle_rxD(struct w6692_hw *card) { u8 stat; int count; stat = ReadW6692(card, W_D_RSTA); if (stat & (W_D_RSTA_RDOV | W_D_RSTA_CRCE | W_D_RSTA_RMB)) { if (stat & W_D_RSTA_RDOV) { pr_debug("%s: D-channel RDOV\n", card->name); #ifdef ERROR_STATISTIC card->dch.err_rx++; #endif } if (stat & W_D_RSTA_CRCE) { pr_debug("%s: D-channel CRC error\n", card->name); #ifdef ERROR_STATISTIC card->dch.err_crc++; #endif } if (stat & W_D_RSTA_RMB) { pr_debug("%s: D-channel ABORT\n", card->name); #ifdef ERROR_STATISTIC card->dch.err_rx++; #endif } if (card->dch.rx_skb) dev_kfree_skb(card->dch.rx_skb); card->dch.rx_skb = NULL; WriteW6692(card, W_D_CMDR, W_D_CMDR_RACK | W_D_CMDR_RRST); } else { count = ReadW6692(card, W_D_RBCL) & (W_D_FIFO_THRESH - 1); if (count == 0) count = W_D_FIFO_THRESH; W6692_empty_Dfifo(card, count); recv_Dchannel(&card->dch); } } static void handle_txD(struct w6692_hw *card) { if (test_and_clear_bit(FLG_BUSY_TIMER, &card->dch.Flags)) del_timer(&card->dch.timer); if (card->dch.tx_skb && card->dch.tx_idx < card->dch.tx_skb->len) { W6692_fill_Dfifo(card); } else { if (card->dch.tx_skb) dev_kfree_skb(card->dch.tx_skb); if (get_next_dframe(&card->dch)) W6692_fill_Dfifo(card); } } static void handle_statusD(struct w6692_hw *card) { struct dchannel *dch = &card->dch; u8 exval, v1, cir; exval = ReadW6692(card, W_D_EXIR); pr_debug("%s: D_EXIR %02x\n", card->name, exval); if (exval & (W_D_EXI_XDUN | W_D_EXI_XCOL)) { /* Transmit underrun/collision */ pr_debug("%s: D-channel underrun/collision\n", card->name); #ifdef ERROR_STATISTIC dch->err_tx++; #endif d_retransmit(card); } if (exval & W_D_EXI_RDOV) { /* RDOV */ pr_debug("%s: D-channel RDOV\n", card->name); WriteW6692(card, W_D_CMDR, W_D_CMDR_RRST); } if (exval & W_D_EXI_TIN2) /* TIN2 - never */ pr_debug("%s: spurious TIN2 interrupt\n", card->name); if (exval & W_D_EXI_MOC) { /* MOC - not supported */ v1 = ReadW6692(card, W_MOSR); pr_debug("%s: spurious MOC interrupt MOSR %02x\n", card->name, v1); } if (exval & W_D_EXI_ISC) { /* ISC - Level1 change */ cir = ReadW6692(card, W_CIR); pr_debug("%s: ISC CIR %02X\n", card->name, cir); if (cir & W_CIR_ICC) { v1 = cir & W_CIR_COD_MASK; pr_debug("%s: ph_state_change %x -> %x\n", card->name, dch->state, v1); card->state = v1; if (card->fmask & led) { switch (v1) { case W_L1IND_AI8: case W_L1IND_AI10: w6692_led_handler(card, 1); break; default: w6692_led_handler(card, 0); break; } } W6692_new_ph(card); } if (cir & W_CIR_SCC) { v1 = ReadW6692(card, W_SQR); pr_debug("%s: SCC SQR %02X\n", card->name, v1); } } if (exval & W_D_EXI_WEXP) pr_debug("%s: spurious WEXP interrupt!\n", card->name); if (exval & W_D_EXI_TEXP) pr_debug("%s: spurious TEXP interrupt!\n", card->name); } static void W6692_empty_Bfifo(struct w6692_ch *wch, int count) { struct w6692_hw *card = wch->bch.hw; u8 *ptr; pr_debug("%s: empty_Bfifo %d\n", card->name, count); if (unlikely(wch->bch.state == ISDN_P_NONE)) { pr_debug("%s: empty_Bfifo ISDN_P_NONE\n", card->name); WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RACK | W_B_CMDR_RACT); if (wch->bch.rx_skb) skb_trim(wch->bch.rx_skb, 0); return; } if (!wch->bch.rx_skb) { wch->bch.rx_skb = mI_alloc_skb(wch->bch.maxlen, GFP_ATOMIC); if (unlikely(!wch->bch.rx_skb)) { pr_info("%s: B receive out of memory\n", card->name); WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RACK | W_B_CMDR_RACT); return; } } if (wch->bch.rx_skb->len + count > wch->bch.maxlen) { pr_debug("%s: empty_Bfifo incoming packet too large\n", card->name); WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RACK | W_B_CMDR_RACT); skb_trim(wch->bch.rx_skb, 0); return; } ptr = skb_put(wch->bch.rx_skb, count); insb(wch->addr + W_B_RFIFO, ptr, count); WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RACK | W_B_CMDR_RACT); if (debug & DEBUG_HW_DFIFO) { snprintf(card->log, 63, "B%1d-recv %s %d ", wch->bch.nr, card->name, count); print_hex_dump_bytes(card->log, DUMP_PREFIX_OFFSET, ptr, count); } } static void W6692_fill_Bfifo(struct w6692_ch *wch) { struct w6692_hw *card = wch->bch.hw; int count; u8 *ptr, cmd = W_B_CMDR_RACT | W_B_CMDR_XMS; pr_debug("%s: fill Bfifo\n", card->name); if (!wch->bch.tx_skb) return; count = wch->bch.tx_skb->len - wch->bch.tx_idx; if (count <= 0) return; ptr = wch->bch.tx_skb->data + wch->bch.tx_idx; if (count > W_B_FIFO_THRESH) count = W_B_FIFO_THRESH; else if (test_bit(FLG_HDLC, &wch->bch.Flags)) cmd |= W_B_CMDR_XME; pr_debug("%s: fill Bfifo%d/%d\n", card->name, count, wch->bch.tx_idx); wch->bch.tx_idx += count; outsb(wch->addr + W_B_XFIFO, ptr, count); WriteW6692B(wch, W_B_CMDR, cmd); if (debug & DEBUG_HW_DFIFO) { snprintf(card->log, 63, "B%1d-send %s %d ", wch->bch.nr, card->name, count); print_hex_dump_bytes(card->log, DUMP_PREFIX_OFFSET, ptr, count); } } #if 0 static int setvolume(struct w6692_ch *wch, int mic, struct sk_buff *skb) { struct w6692_hw *card = wch->bch.hw; u16 *vol = (u16 *)skb->data; u8 val; if ((!(card->fmask & pots)) || !test_bit(FLG_TRANSPARENT, &wch->bch.Flags)) return -ENODEV; if (skb->len < 2) return -EINVAL; if (*vol > 7) return -EINVAL; val = *vol & 7; val = 7 - val; if (mic) { val <<= 3; card->xaddr &= 0xc7; } else { card->xaddr &= 0xf8; } card->xaddr |= val; WriteW6692(card, W_XADDR, card->xaddr); return 0; } static int enable_pots(struct w6692_ch *wch) { struct w6692_hw *card = wch->bch.hw; if ((!(card->fmask & pots)) || !test_bit(FLG_TRANSPARENT, &wch->bch.Flags)) return -ENODEV; wch->b_mode |= W_B_MODE_EPCM | W_B_MODE_BSW0; WriteW6692B(wch, W_B_MODE, wch->b_mode); WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RRST | W_B_CMDR_XRST); card->pctl |= ((wch->bch.nr & 2) ? W_PCTL_PCX : 0); WriteW6692(card, W_PCTL, card->pctl); return 0; } #endif static int disable_pots(struct w6692_ch *wch) { struct w6692_hw *card = wch->bch.hw; if (!(card->fmask & pots)) return -ENODEV; wch->b_mode &= ~(W_B_MODE_EPCM | W_B_MODE_BSW0); WriteW6692B(wch, W_B_MODE, wch->b_mode); WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RRST | W_B_CMDR_RACT | W_B_CMDR_XRST); return 0; } static int w6692_mode(struct w6692_ch *wch, u32 pr) { struct w6692_hw *card; card = wch->bch.hw; pr_debug("%s: B%d protocol %x-->%x\n", card->name, wch->bch.nr, wch->bch.state, pr); switch (pr) { case ISDN_P_NONE: if ((card->fmask & pots) && (wch->b_mode & W_B_MODE_EPCM)) disable_pots(wch); wch->b_mode = 0; mISDN_clear_bchannel(&wch->bch); WriteW6692B(wch, W_B_MODE, wch->b_mode); WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RRST | W_B_CMDR_XRST); test_and_clear_bit(FLG_HDLC, &wch->bch.Flags); test_and_clear_bit(FLG_TRANSPARENT, &wch->bch.Flags); break; case ISDN_P_B_RAW: wch->b_mode = W_B_MODE_MMS; WriteW6692B(wch, W_B_MODE, wch->b_mode); WriteW6692B(wch, W_B_EXIM, 0); WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RRST | W_B_CMDR_RACT | W_B_CMDR_XRST); test_and_set_bit(FLG_TRANSPARENT, &wch->bch.Flags); break; case ISDN_P_B_HDLC: wch->b_mode = W_B_MODE_ITF; WriteW6692B(wch, W_B_MODE, wch->b_mode); WriteW6692B(wch, W_B_ADM1, 0xff); WriteW6692B(wch, W_B_ADM2, 0xff); WriteW6692B(wch, W_B_EXIM, 0); WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RRST | W_B_CMDR_RACT | W_B_CMDR_XRST); test_and_set_bit(FLG_HDLC, &wch->bch.Flags); break; default: pr_info("%s: protocol %x not known\n", card->name, pr); return -ENOPROTOOPT; } wch->bch.state = pr; return 0; } static void send_next(struct w6692_ch *wch) { if (wch->bch.tx_skb && wch->bch.tx_idx < wch->bch.tx_skb->len) W6692_fill_Bfifo(wch); else { if (wch->bch.tx_skb) { /* send confirm, on trans, free on hdlc. */ if (test_bit(FLG_TRANSPARENT, &wch->bch.Flags)) confirm_Bsend(&wch->bch); dev_kfree_skb(wch->bch.tx_skb); } if (get_next_bframe(&wch->bch)) W6692_fill_Bfifo(wch); } } static void W6692B_interrupt(struct w6692_hw *card, int ch) { struct w6692_ch *wch = &card->bc[ch]; int count; u8 stat, star = 0; stat = ReadW6692B(wch, W_B_EXIR); pr_debug("%s: B%d EXIR %02x\n", card->name, wch->bch.nr, stat); if (stat & W_B_EXI_RME) { star = ReadW6692B(wch, W_B_STAR); if (star & (W_B_STAR_RDOV | W_B_STAR_CRCE | W_B_STAR_RMB)) { if ((star & W_B_STAR_RDOV) && test_bit(FLG_ACTIVE, &wch->bch.Flags)) { pr_debug("%s: B%d RDOV proto=%x\n", card->name, wch->bch.nr, wch->bch.state); #ifdef ERROR_STATISTIC wch->bch.err_rdo++; #endif } if (test_bit(FLG_HDLC, &wch->bch.Flags)) { if (star & W_B_STAR_CRCE) { pr_debug("%s: B%d CRC error\n", card->name, wch->bch.nr); #ifdef ERROR_STATISTIC wch->bch.err_crc++; #endif } if (star & W_B_STAR_RMB) { pr_debug("%s: B%d message abort\n", card->name, wch->bch.nr); #ifdef ERROR_STATISTIC wch->bch.err_inv++; #endif } } WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RACK | W_B_CMDR_RRST | W_B_CMDR_RACT); if (wch->bch.rx_skb) skb_trim(wch->bch.rx_skb, 0); } else { count = ReadW6692B(wch, W_B_RBCL) & (W_B_FIFO_THRESH - 1); if (count == 0) count = W_B_FIFO_THRESH; W6692_empty_Bfifo(wch, count); recv_Bchannel(&wch->bch, 0); } } if (stat & W_B_EXI_RMR) { if (!(stat & W_B_EXI_RME)) star = ReadW6692B(wch, W_B_STAR); if (star & W_B_STAR_RDOV) { pr_debug("%s: B%d RDOV proto=%x\n", card->name, wch->bch.nr, wch->bch.state); #ifdef ERROR_STATISTIC wch->bch.err_rdo++; #endif WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RACK | W_B_CMDR_RRST | W_B_CMDR_RACT); } else { W6692_empty_Bfifo(wch, W_B_FIFO_THRESH); if (test_bit(FLG_TRANSPARENT, &wch->bch.Flags) && wch->bch.rx_skb && (wch->bch.rx_skb->len > 0)) recv_Bchannel(&wch->bch, 0); } } if (stat & W_B_EXI_RDOV) { /* only if it is not handled yet */ if (!(star & W_B_STAR_RDOV)) { pr_debug("%s: B%d RDOV IRQ proto=%x\n", card->name, wch->bch.nr, wch->bch.state); #ifdef ERROR_STATISTIC wch->bch.err_rdo++; #endif WriteW6692B(wch, W_B_CMDR, W_B_CMDR_RACK | W_B_CMDR_RRST | W_B_CMDR_RACT); } } if (stat & W_B_EXI_XFR) { if (!(stat & (W_B_EXI_RME | W_B_EXI_RMR))) { star = ReadW6692B(wch, W_B_STAR); pr_debug("%s: B%d star %02x\n", card->name, wch->bch.nr, star); } if (star & W_B_STAR_XDOW) { pr_debug("%s: B%d XDOW proto=%x\n", card->name, wch->bch.nr, wch->bch.state); #ifdef ERROR_STATISTIC wch->bch.err_xdu++; #endif WriteW6692B(wch, W_B_CMDR, W_B_CMDR_XRST | W_B_CMDR_RACT); /* resend */ if (wch->bch.tx_skb) { if (!test_bit(FLG_TRANSPARENT, &wch->bch.Flags)) wch->bch.tx_idx = 0; } } send_next(wch); if (stat & W_B_EXI_XDUN) return; /* handle XDOW only once */ } if (stat & W_B_EXI_XDUN) { pr_debug("%s: B%d XDUN proto=%x\n", card->name, wch->bch.nr, wch->bch.state); #ifdef ERROR_STATISTIC wch->bch.err_xdu++; #endif WriteW6692B(wch, W_B_CMDR, W_B_CMDR_XRST | W_B_CMDR_RACT); /* resend */ if (wch->bch.tx_skb) { if (!test_bit(FLG_TRANSPARENT, &wch->bch.Flags)) wch->bch.tx_idx = 0; } send_next(wch); } } static irqreturn_t w6692_irq(int intno, void *dev_id) { struct w6692_hw *card = dev_id; u8 ista; spin_lock(&card->lock); ista = ReadW6692(card, W_ISTA); if ((ista | card->imask) == card->imask) { /* possible a shared IRQ reqest */ spin_unlock(&card->lock); return IRQ_NONE; } card->irqcnt++; pr_debug("%s: ista %02x\n", card->name, ista); ista &= ~card->imask; if (ista & W_INT_B1_EXI) W6692B_interrupt(card, 0); if (ista & W_INT_B2_EXI) W6692B_interrupt(card, 1); if (ista & W_INT_D_RME) handle_rxD(card); if (ista & W_INT_D_RMR) W6692_empty_Dfifo(card, W_D_FIFO_THRESH); if (ista & W_INT_D_XFR) handle_txD(card); if (ista & W_INT_D_EXI) handle_statusD(card); if (ista & (W_INT_XINT0 | W_INT_XINT1)) /* XINT0/1 - never */ pr_debug("%s: W6692 spurious XINT!\n", card->name); /* End IRQ Handler */ spin_unlock(&card->lock); return IRQ_HANDLED; } static void dbusy_timer_handler(struct dchannel *dch) { struct w6692_hw *card = dch->hw; int rbch, star; u_long flags; if (test_bit(FLG_BUSY_TIMER, &dch->Flags)) { spin_lock_irqsave(&card->lock, flags); rbch = ReadW6692(card, W_D_RBCH); star = ReadW6692(card, W_D_STAR); pr_debug("%s: D-Channel Busy RBCH %02x STAR %02x\n", card->name, rbch, star); if (star & W_D_STAR_XBZ) /* D-Channel Busy */ test_and_set_bit(FLG_L1_BUSY, &dch->Flags); else { /* discard frame; reset transceiver */ test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags); if (dch->tx_idx) dch->tx_idx = 0; else pr_info("%s: W6692 D-Channel Busy no tx_idx\n", card->name); /* Transmitter reset */ WriteW6692(card, W_D_CMDR, W_D_CMDR_XRST); } spin_unlock_irqrestore(&card->lock, flags); } } void initW6692(struct w6692_hw *card) { u8 val; card->dch.timer.function = (void *)dbusy_timer_handler; card->dch.timer.data = (u_long)&card->dch; init_timer(&card->dch.timer); w6692_mode(&card->bc[0], ISDN_P_NONE); w6692_mode(&card->bc[1], ISDN_P_NONE); WriteW6692(card, W_D_CTL, 0x00); disable_hwirq(card); WriteW6692(card, W_D_SAM, 0xff); WriteW6692(card, W_D_TAM, 0xff); WriteW6692(card, W_D_MODE, W_D_MODE_RACT); card->state = W_L1CMD_RST; ph_command(card, W_L1CMD_RST); ph_command(card, W_L1CMD_ECK); /* enable all IRQ but extern */ card->imask = 0x18; WriteW6692(card, W_D_EXIM, 0x00); WriteW6692B(&card->bc[0], W_B_EXIM, 0); WriteW6692B(&card->bc[1], W_B_EXIM, 0); /* Reset D-chan receiver and transmitter */ WriteW6692(card, W_D_CMDR, W_D_CMDR_RRST | W_D_CMDR_XRST); /* Reset B-chan receiver and transmitter */ WriteW6692B(&card->bc[0], W_B_CMDR, W_B_CMDR_RRST | W_B_CMDR_XRST); WriteW6692B(&card->bc[1], W_B_CMDR, W_B_CMDR_RRST | W_B_CMDR_XRST); /* enable peripheral */ if (card->subtype == W6692_USR) { /* seems that USR implemented some power control features * Pin 79 is connected to the oscilator circuit so we * have to handle it here */ card->pctl = 0x80; card->xdata = 0; WriteW6692(card, W_PCTL, card->pctl); WriteW6692(card, W_XDATA, card->xdata); } else { card->pctl = W_PCTL_OE5 | W_PCTL_OE4 | W_PCTL_OE2 | W_PCTL_OE1 | W_PCTL_OE0; card->xaddr = 0x00;/* all sw off */ if (card->fmask & pots) card->xdata |= 0x06; /* POWER UP/ LED OFF / ALAW */ if (card->fmask & led) card->xdata |= 0x04; /* LED OFF */ if ((card->fmask & pots) || (card->fmask & led)) { WriteW6692(card, W_PCTL, card->pctl); WriteW6692(card, W_XADDR, card->xaddr); WriteW6692(card, W_XDATA, card->xdata); val = ReadW6692(card, W_XADDR); if (debug & DEBUG_HW) pr_notice("%s: W_XADDR=%02x\n", card->name, val); } } } static void reset_w6692(struct w6692_hw *card) { WriteW6692(card, W_D_CTL, W_D_CTL_SRST); mdelay(10); WriteW6692(card, W_D_CTL, 0); } static int init_card(struct w6692_hw *card) { int cnt = 3; u_long flags; spin_lock_irqsave(&card->lock, flags); disable_hwirq(card); spin_unlock_irqrestore(&card->lock, flags); if (request_irq(card->irq, w6692_irq, IRQF_SHARED, card->name, card)) { pr_info("%s: couldn't get interrupt %d\n", card->name, card->irq); return -EIO; } while (cnt--) { spin_lock_irqsave(&card->lock, flags); initW6692(card); enable_hwirq(card); spin_unlock_irqrestore(&card->lock, flags); /* Timeout 10ms */ msleep_interruptible(10); if (debug & DEBUG_HW) pr_notice("%s: IRQ %d count %d\n", card->name, card->irq, card->irqcnt); if (!card->irqcnt) { pr_info("%s: IRQ(%d) getting no IRQs during init %d\n", card->name, card->irq, 3 - cnt); reset_w6692(card); } else return 0; } free_irq(card->irq, card); return -EIO; } static int w6692_l2l1B(struct mISDNchannel *ch, struct sk_buff *skb) { struct bchannel *bch = container_of(ch, struct bchannel, ch); struct w6692_ch *bc = container_of(bch, struct w6692_ch, bch); struct w6692_hw *card = bch->hw; int ret = -EINVAL; struct mISDNhead *hh = mISDN_HEAD_P(skb); u32 id; u_long flags; switch (hh->prim) { case PH_DATA_REQ: spin_lock_irqsave(&card->lock, flags); ret = bchannel_senddata(bch, skb); if (ret > 0) { /* direct TX */ id = hh->id; /* skb can be freed */ ret = 0; W6692_fill_Bfifo(bc); spin_unlock_irqrestore(&card->lock, flags); if (!test_bit(FLG_TRANSPARENT, &bch->Flags)) queue_ch_frame(ch, PH_DATA_CNF, id, NULL); } else spin_unlock_irqrestore(&card->lock, flags); return ret; case PH_ACTIVATE_REQ: spin_lock_irqsave(&card->lock, flags); if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags)) ret = w6692_mode(bc, ch->protocol); else ret = 0; spin_unlock_irqrestore(&card->lock, flags); if (!ret) _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0, NULL, GFP_KERNEL); break; case PH_DEACTIVATE_REQ: spin_lock_irqsave(&card->lock, flags); mISDN_clear_bchannel(bch); w6692_mode(bc, ISDN_P_NONE); spin_unlock_irqrestore(&card->lock, flags); _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0, NULL, GFP_KERNEL); ret = 0; break; default: pr_info("%s: %s unknown prim(%x,%x)\n", card->name, __func__, hh->prim, hh->id); ret = -EINVAL; } if (!ret) dev_kfree_skb(skb); return ret; } static int channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq) { int ret = 0; switch (cq->op) { case MISDN_CTRL_GETOP: cq->op = 0; break; /* Nothing implemented yet */ case MISDN_CTRL_FILL_EMPTY: default: pr_info("%s: unknown Op %x\n", __func__, cq->op); ret = -EINVAL; break; } return ret; } static int open_bchannel(struct w6692_hw *card, struct channel_req *rq) { struct bchannel *bch; if (rq->adr.channel == 0 || rq->adr.channel > 2) return -EINVAL; if (rq->protocol == ISDN_P_NONE) return -EINVAL; bch = &card->bc[rq->adr.channel - 1].bch; if (test_and_set_bit(FLG_OPEN, &bch->Flags)) return -EBUSY; /* b-channel can be only open once */ test_and_clear_bit(FLG_FILLEMPTY, &bch->Flags); bch->ch.protocol = rq->protocol; rq->ch = &bch->ch; return 0; } static int channel_ctrl(struct w6692_hw *card, struct mISDN_ctrl_req *cq) { int ret = 0; switch (cq->op) { case MISDN_CTRL_GETOP: cq->op = 0; break; default: pr_info("%s: unknown CTRL OP %x\n", card->name, cq->op); ret = -EINVAL; break; } return ret; } static int w6692_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg) { struct bchannel *bch = container_of(ch, struct bchannel, ch); struct w6692_ch *bc = container_of(bch, struct w6692_ch, bch); struct w6692_hw *card = bch->hw; int ret = -EINVAL; u_long flags; pr_debug("%s: %s cmd:%x %p\n", card->name, __func__, cmd, arg); switch (cmd) { case CLOSE_CHANNEL: test_and_clear_bit(FLG_OPEN, &bch->Flags); if (test_bit(FLG_ACTIVE, &bch->Flags)) { spin_lock_irqsave(&card->lock, flags); mISDN_freebchannel(bch); w6692_mode(bc, ISDN_P_NONE); spin_unlock_irqrestore(&card->lock, flags); } else { skb_queue_purge(&bch->rqueue); bch->rcount = 0; } ch->protocol = ISDN_P_NONE; ch->peer = NULL; module_put(THIS_MODULE); ret = 0; break; case CONTROL_CHANNEL: ret = channel_bctrl(bch, arg); break; default: pr_info("%s: %s unknown prim(%x)\n", card->name, __func__, cmd); } return ret; } static int w6692_l2l1D(struct mISDNchannel *ch, struct sk_buff *skb) { struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D); struct dchannel *dch = container_of(dev, struct dchannel, dev); struct w6692_hw *card = container_of(dch, struct w6692_hw, dch); int ret = -EINVAL; struct mISDNhead *hh = mISDN_HEAD_P(skb); u32 id; u_long flags; switch (hh->prim) { case PH_DATA_REQ: spin_lock_irqsave(&card->lock, flags); ret = dchannel_senddata(dch, skb); if (ret > 0) { /* direct TX */ id = hh->id; /* skb can be freed */ W6692_fill_Dfifo(card); ret = 0; spin_unlock_irqrestore(&card->lock, flags); queue_ch_frame(ch, PH_DATA_CNF, id, NULL); } else spin_unlock_irqrestore(&card->lock, flags); return ret; case PH_ACTIVATE_REQ: ret = l1_event(dch->l1, hh->prim); break; case PH_DEACTIVATE_REQ: test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags); ret = l1_event(dch->l1, hh->prim); break; } if (!ret) dev_kfree_skb(skb); return ret; } static int w6692_l1callback(struct dchannel *dch, u32 cmd) { struct w6692_hw *card = container_of(dch, struct w6692_hw, dch); u_long flags; pr_debug("%s: cmd(%x) state(%02x)\n", card->name, cmd, card->state); switch (cmd) { case INFO3_P8: spin_lock_irqsave(&card->lock, flags); ph_command(card, W_L1CMD_AR8); spin_unlock_irqrestore(&card->lock, flags); break; case INFO3_P10: spin_lock_irqsave(&card->lock, flags); ph_command(card, W_L1CMD_AR10); spin_unlock_irqrestore(&card->lock, flags); break; case HW_RESET_REQ: spin_lock_irqsave(&card->lock, flags); if (card->state != W_L1IND_DRD) ph_command(card, W_L1CMD_RST); ph_command(card, W_L1CMD_ECK); spin_unlock_irqrestore(&card->lock, flags); break; case HW_DEACT_REQ: skb_queue_purge(&dch->squeue); if (dch->tx_skb) { dev_kfree_skb(dch->tx_skb); dch->tx_skb = NULL; } dch->tx_idx = 0; if (dch->rx_skb) { dev_kfree_skb(dch->rx_skb); dch->rx_skb = NULL; } test_and_clear_bit(FLG_TX_BUSY, &dch->Flags); if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags)) del_timer(&dch->timer); break; case HW_POWERUP_REQ: spin_lock_irqsave(&card->lock, flags); ph_command(card, W_L1CMD_ECK); spin_unlock_irqrestore(&card->lock, flags); break; case PH_ACTIVATE_IND: test_and_set_bit(FLG_ACTIVE, &dch->Flags); _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL, GFP_ATOMIC); break; case PH_DEACTIVATE_IND: test_and_clear_bit(FLG_ACTIVE, &dch->Flags); _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL, GFP_ATOMIC); break; default: pr_debug("%s: %s unknown command %x\n", card->name, __func__, cmd); return -1; } return 0; } static int open_dchannel(struct w6692_hw *card, struct channel_req *rq) { pr_debug("%s: %s dev(%d) open from %p\n", card->name, __func__, card->dch.dev.id, __builtin_return_address(1)); if (rq->protocol != ISDN_P_TE_S0) return -EINVAL; if (rq->adr.channel == 1) /* E-Channel not supported */ return -EINVAL; rq->ch = &card->dch.dev.D; rq->ch->protocol = rq->protocol; if (card->dch.state == 7) _queue_data(rq->ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0, NULL, GFP_KERNEL); return 0; } static int w6692_dctrl(struct mISDNchannel *ch, u32 cmd, void *arg) { struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D); struct dchannel *dch = container_of(dev, struct dchannel, dev); struct w6692_hw *card = container_of(dch, struct w6692_hw, dch); struct channel_req *rq; int err = 0; pr_debug("%s: DCTRL: %x %p\n", card->name, cmd, arg); switch (cmd) { case OPEN_CHANNEL: rq = arg; if (rq->protocol == ISDN_P_TE_S0) err = open_dchannel(card, rq); else err = open_bchannel(card, rq); if (err) break; if (!try_module_get(THIS_MODULE)) pr_info("%s: cannot get module\n", card->name); break; case CLOSE_CHANNEL: pr_debug("%s: dev(%d) close from %p\n", card->name, dch->dev.id, __builtin_return_address(0)); module_put(THIS_MODULE); break; case CONTROL_CHANNEL: err = channel_ctrl(card, arg); break; default: pr_debug("%s: unknown DCTRL command %x\n", card->name, cmd); return -EINVAL; } return err; } static int setup_w6692(struct w6692_hw *card) { u32 val; if (!request_region(card->addr, 256, card->name)) { pr_info("%s: config port %x-%x already in use\n", card->name, card->addr, card->addr + 255); return -EIO; } W6692Version(card); card->bc[0].addr = card->addr; card->bc[1].addr = card->addr + 0x40; val = ReadW6692(card, W_ISTA); if (debug & DEBUG_HW) pr_notice("%s ISTA=%02x\n", card->name, val); val = ReadW6692(card, W_IMASK); if (debug & DEBUG_HW) pr_notice("%s IMASK=%02x\n", card->name, val); val = ReadW6692(card, W_D_EXIR); if (debug & DEBUG_HW) pr_notice("%s D_EXIR=%02x\n", card->name, val); val = ReadW6692(card, W_D_EXIM); if (debug & DEBUG_HW) pr_notice("%s D_EXIM=%02x\n", card->name, val); val = ReadW6692(card, W_D_RSTA); if (debug & DEBUG_HW) pr_notice("%s D_RSTA=%02x\n", card->name, val); return 0; } static void release_card(struct w6692_hw *card) { u_long flags; spin_lock_irqsave(&card->lock, flags); disable_hwirq(card); w6692_mode(&card->bc[0], ISDN_P_NONE); w6692_mode(&card->bc[1], ISDN_P_NONE); if ((card->fmask & led) || card->subtype == W6692_USR) { card->xdata |= 0x04; /* LED OFF */ WriteW6692(card, W_XDATA, card->xdata); } spin_unlock_irqrestore(&card->lock, flags); free_irq(card->irq, card); l1_event(card->dch.l1, CLOSE_CHANNEL); mISDN_unregister_device(&card->dch.dev); release_region(card->addr, 256); mISDN_freebchannel(&card->bc[1].bch); mISDN_freebchannel(&card->bc[0].bch); mISDN_freedchannel(&card->dch); write_lock_irqsave(&card_lock, flags); list_del(&card->list); write_unlock_irqrestore(&card_lock, flags); pci_disable_device(card->pdev); pci_set_drvdata(card->pdev, NULL); kfree(card); } static int setup_instance(struct w6692_hw *card) { int i, err; u_long flags; snprintf(card->name, MISDN_MAX_IDLEN - 1, "w6692.%d", w6692_cnt + 1); write_lock_irqsave(&card_lock, flags); list_add_tail(&card->list, &Cards); write_unlock_irqrestore(&card_lock, flags); card->fmask = (1 << w6692_cnt); _set_debug(card); spin_lock_init(&card->lock); mISDN_initdchannel(&card->dch, MAX_DFRAME_LEN_L1, W6692_ph_bh); card->dch.dev.Dprotocols = (1 << ISDN_P_TE_S0); card->dch.dev.D.send = w6692_l2l1D; card->dch.dev.D.ctrl = w6692_dctrl; card->dch.dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) | (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK)); card->dch.hw = card; card->dch.dev.nrbchan = 2; for (i = 0; i < 2; i++) { mISDN_initbchannel(&card->bc[i].bch, MAX_DATA_MEM); card->bc[i].bch.hw = card; card->bc[i].bch.nr = i + 1; card->bc[i].bch.ch.nr = i + 1; card->bc[i].bch.ch.send = w6692_l2l1B; card->bc[i].bch.ch.ctrl = w6692_bctrl; set_channelmap(i + 1, card->dch.dev.channelmap); list_add(&card->bc[i].bch.ch.list, &card->dch.dev.bchannels); } err = setup_w6692(card); if (err) goto error_setup; err = mISDN_register_device(&card->dch.dev, &card->pdev->dev, card->name); if (err) goto error_reg; err = init_card(card); if (err) goto error_init; err = create_l1(&card->dch, w6692_l1callback); if (!err) { w6692_cnt++; pr_notice("W6692 %d cards installed\n", w6692_cnt); return 0; } free_irq(card->irq, card); error_init: mISDN_unregister_device(&card->dch.dev); error_reg: release_region(card->addr, 256); error_setup: mISDN_freebchannel(&card->bc[1].bch); mISDN_freebchannel(&card->bc[0].bch); mISDN_freedchannel(&card->dch); write_lock_irqsave(&card_lock, flags); list_del(&card->list); write_unlock_irqrestore(&card_lock, flags); kfree(card); return err; } static int __devinit w6692_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { int err = -ENOMEM; struct w6692_hw *card; struct w6692map *m = (struct w6692map *)ent->driver_data; card = kzalloc(sizeof(struct w6692_hw), GFP_KERNEL); if (!card) { pr_info("No kmem for w6692 card\n"); return err; } card->pdev = pdev; card->subtype = m->subtype; err = pci_enable_device(pdev); if (err) { kfree(card); return err; } printk(KERN_INFO "mISDN_w6692: found adapter %s at %s\n", m->name, pci_name(pdev)); card->addr = pci_resource_start(pdev, 1); card->irq = pdev->irq; pci_set_drvdata(pdev, card); err = setup_instance(card); if (err) pci_set_drvdata(pdev, NULL); return err; } static void __devexit w6692_remove_pci(struct pci_dev *pdev) { struct w6692_hw *card = pci_get_drvdata(pdev); if (card) release_card(card); else if (debug) pr_notice("%s: drvdata already removed\n", __func__); } static struct pci_device_id w6692_ids[] = { { PCI_VENDOR_ID_DYNALINK, PCI_DEVICE_ID_DYNALINK_IS64PH, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (ulong)&w6692_map[0]}, { PCI_VENDOR_ID_WINBOND2, PCI_DEVICE_ID_WINBOND2_6692, PCI_VENDOR_ID_USR, PCI_DEVICE_ID_USR_6692, 0, 0, (ulong)&w6692_map[2]}, { PCI_VENDOR_ID_WINBOND2, PCI_DEVICE_ID_WINBOND2_6692, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (ulong)&w6692_map[1]}, { } }; MODULE_DEVICE_TABLE(pci, w6692_ids); static struct pci_driver w6692_driver = { .name = "w6692", .probe = w6692_probe, .remove = __devexit_p(w6692_remove_pci), .id_table = w6692_ids, }; static int __init w6692_init(void) { int err; pr_notice("Winbond W6692 PCI driver Rev. %s\n", W6692_REV); err = pci_register_driver(&w6692_driver); return err; } static void __exit w6692_cleanup(void) { pci_unregister_driver(&w6692_driver); } module_init(w6692_init); module_exit(w6692_cleanup);
gpl-2.0
MikeC84/mac_kernel_lge_hammerhead
drivers/net/wireless/mwifiex/txrx.c
4801
4732
/* * Marvell Wireless LAN device driver: generic TX/RX data handling * * Copyright (C) 2011, Marvell International Ltd. * * This software file (the "File") is distributed by Marvell International * Ltd. under the terms of the GNU General Public License Version 2, June 1991 * (the "License"). You may use, redistribute and/or modify this File in * accordance with the terms and conditions of the License, a copy of which * is available by writing to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. * * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE * ARE EXPRESSLY DISCLAIMED. The License provides additional details about * this warranty disclaimer. */ #include "decl.h" #include "ioctl.h" #include "util.h" #include "fw.h" #include "main.h" #include "wmm.h" /* * This function processes the received buffer. * * Main responsibility of this function is to parse the RxPD to * identify the correct interface this packet is headed for and * forwarding it to the associated handling function, where the * packet will be further processed and sent to kernel/upper layer * if required. */ int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter, struct sk_buff *skb) { struct mwifiex_private *priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); struct rxpd *local_rx_pd; struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb); local_rx_pd = (struct rxpd *) (skb->data); /* Get the BSS number from rxpd, get corresponding priv */ priv = mwifiex_get_priv_by_id(adapter, local_rx_pd->bss_num & BSS_NUM_MASK, local_rx_pd->bss_type); if (!priv) priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); rx_info->bss_num = priv->bss_num; rx_info->bss_type = priv->bss_type; return mwifiex_process_sta_rx_packet(adapter, skb); } EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet); /* * This function sends a packet to device. * * It processes the packet to add the TxPD, checks condition and * sends the processed packet to firmware for transmission. * * On successful completion, the function calls the completion callback * and logs the time. */ int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb, struct mwifiex_tx_param *tx_param) { int ret = -1; struct mwifiex_adapter *adapter = priv->adapter; u8 *head_ptr; struct txpd *local_tx_pd = NULL; head_ptr = mwifiex_process_sta_txpd(priv, skb); if (head_ptr) { if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) local_tx_pd = (struct txpd *) (head_ptr + INTF_HEADER_LEN); ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA, skb, tx_param); } switch (ret) { case -EBUSY: if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) { priv->adapter->tx_lock_flag = false; if (local_tx_pd) local_tx_pd->flags = 0; } dev_dbg(adapter->dev, "data: -EBUSY is returned\n"); break; case -1: adapter->data_sent = false; dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n", ret); adapter->dbg.num_tx_host_to_card_failure++; mwifiex_write_data_complete(adapter, skb, ret); break; case -EINPROGRESS: adapter->data_sent = false; break; case 0: mwifiex_write_data_complete(adapter, skb, ret); break; default: break; } return ret; } /* * Packet send completion callback handler. * * It either frees the buffer directly or forwards it to another * completion callback which checks conditions, updates statistics, * wakes up stalled traffic queue if required, and then frees the buffer. */ int mwifiex_write_data_complete(struct mwifiex_adapter *adapter, struct sk_buff *skb, int status) { struct mwifiex_private *priv, *tpriv; struct mwifiex_txinfo *tx_info; int i; if (!skb) return 0; tx_info = MWIFIEX_SKB_TXCB(skb); priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num, tx_info->bss_type); if (!priv) goto done; mwifiex_set_trans_start(priv->netdev); if (!status) { priv->stats.tx_packets++; priv->stats.tx_bytes += skb->len; } else { priv->stats.tx_errors++; } if (atomic_dec_return(&adapter->tx_pending) >= LOW_TX_PENDING) goto done; for (i = 0; i < adapter->priv_num; i++) { tpriv = adapter->priv[i]; if ((GET_BSS_ROLE(tpriv) == MWIFIEX_BSS_ROLE_STA) && (tpriv->media_connected)) { if (netif_queue_stopped(tpriv->netdev)) mwifiex_wake_up_net_dev_queue(tpriv->netdev, adapter); } } done: dev_kfree_skb_any(skb); return 0; }
gpl-2.0
boa19861105/android_LP5.0.2_kernel_htc_dlxub1
drivers/net/ethernet/amd/atarilance.c
4801
34147
/* atarilance.c: Ethernet driver for VME Lance cards on the Atari */ /* Written 1995/96 by Roman Hodek (Roman.Hodek@informatik.uni-erlangen.de) This software may be used and distributed according to the terms of the GNU General Public License, incorporated herein by reference. This drivers was written with the following sources of reference: - The driver for the Riebl Lance card by the TU Vienna. - The modified TUW driver for PAM's VME cards - The PC-Linux driver for Lance cards (but this is for bus master cards, not the shared memory ones) - The Amiga Ariadne driver v1.0: (in 1.2.13pl4/0.9.13) Initial version v1.1: (in 1.2.13pl5) more comments deleted some debugging stuff optimized register access (keep AREG pointing to CSR0) following AMD, CSR0_STRT should be set only after IDON is detected use memcpy() for data transfers, that also employs long word moves better probe procedure for 24-bit systems non-VME-RieblCards need extra delays in memcpy must also do write test, since 0xfxe00000 may hit ROM use 8/32 tx/rx buffers, which should give better NFS performance; this is made possible by shifting the last packet buffer after the RieblCard reserved area v1.2: (in 1.2.13pl8) again fixed probing for the Falcon; 0xfe01000 hits phys. 0x00010000 and thus RAM, in case of no Lance found all memory contents have to be restored! Now possible to compile as module. v1.3: 03/30/96 Jes Sorensen, Roman (in 1.3) Several little 1.3 adaptions When the lance is stopped it jumps back into little-endian mode. It is therefore necessary to put it back where it belongs, in big endian mode, in order to make things work. This might be the reason why multicast-mode didn't work before, but I'm not able to test it as I only got an Amiga (we had similar problems with the A2065 driver). */ static char version[] = "atarilance.c: v1.3 04/04/96 " "Roman.Hodek@informatik.uni-erlangen.de\n"; #include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/module.h> #include <linux/stddef.h> #include <linux/kernel.h> #include <linux/string.h> #include <linux/errno.h> #include <linux/skbuff.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/bitops.h> #include <asm/setup.h> #include <asm/irq.h> #include <asm/atarihw.h> #include <asm/atariints.h> #include <asm/io.h> /* Debug level: * 0 = silent, print only serious errors * 1 = normal, print error messages * 2 = debug, print debug infos * 3 = debug, print even more debug infos (packet data) */ #define LANCE_DEBUG 1 #ifdef LANCE_DEBUG static int lance_debug = LANCE_DEBUG; #else static int lance_debug = 1; #endif module_param(lance_debug, int, 0); MODULE_PARM_DESC(lance_debug, "atarilance debug level (0-3)"); MODULE_LICENSE("GPL"); /* Print debug messages on probing? */ #undef LANCE_DEBUG_PROBE #define DPRINTK(n,a) \ do { \ if (lance_debug >= n) \ printk a; \ } while( 0 ) #ifdef LANCE_DEBUG_PROBE # define PROBE_PRINT(a) printk a #else # define PROBE_PRINT(a) #endif /* These define the number of Rx and Tx buffers as log2. (Only powers * of two are valid) * Much more rx buffers (32) are reserved than tx buffers (8), since receiving * is more time critical then sending and packets may have to remain in the * board's memory when main memory is low. */ #define TX_LOG_RING_SIZE 3 #define RX_LOG_RING_SIZE 5 /* These are the derived values */ #define TX_RING_SIZE (1 << TX_LOG_RING_SIZE) #define TX_RING_LEN_BITS (TX_LOG_RING_SIZE << 5) #define TX_RING_MOD_MASK (TX_RING_SIZE - 1) #define RX_RING_SIZE (1 << RX_LOG_RING_SIZE) #define RX_RING_LEN_BITS (RX_LOG_RING_SIZE << 5) #define RX_RING_MOD_MASK (RX_RING_SIZE - 1) #define TX_TIMEOUT (HZ/5) /* The LANCE Rx and Tx ring descriptors. */ struct lance_rx_head { unsigned short base; /* Low word of base addr */ volatile unsigned char flag; unsigned char base_hi; /* High word of base addr (unused) */ short buf_length; /* This length is 2s complement! */ volatile short msg_length; /* This length is "normal". */ }; struct lance_tx_head { unsigned short base; /* Low word of base addr */ volatile unsigned char flag; unsigned char base_hi; /* High word of base addr (unused) */ short length; /* Length is 2s complement! */ volatile short misc; }; struct ringdesc { unsigned short adr_lo; /* Low 16 bits of address */ unsigned char len; /* Length bits */ unsigned char adr_hi; /* High 8 bits of address (unused) */ }; /* The LANCE initialization block, described in databook. */ struct lance_init_block { unsigned short mode; /* Pre-set mode */ unsigned char hwaddr[6]; /* Physical ethernet address */ unsigned filter[2]; /* Multicast filter (unused). */ /* Receive and transmit ring base, along with length bits. */ struct ringdesc rx_ring; struct ringdesc tx_ring; }; /* The whole layout of the Lance shared memory */ struct lance_memory { struct lance_init_block init; struct lance_tx_head tx_head[TX_RING_SIZE]; struct lance_rx_head rx_head[RX_RING_SIZE]; char packet_area[0]; /* packet data follow after the * init block and the ring * descriptors and are located * at runtime */ }; /* RieblCard specifics: * The original TOS driver for these cards reserves the area from offset * 0xee70 to 0xeebb for storing configuration data. Of interest to us is the * Ethernet address there, and the magic for verifying the data's validity. * The reserved area isn't touch by packet buffers. Furthermore, offset 0xfffe * is reserved for the interrupt vector number. */ #define RIEBL_RSVD_START 0xee70 #define RIEBL_RSVD_END 0xeec0 #define RIEBL_MAGIC 0x09051990 #define RIEBL_MAGIC_ADDR ((unsigned long *)(((char *)MEM) + 0xee8a)) #define RIEBL_HWADDR_ADDR ((unsigned char *)(((char *)MEM) + 0xee8e)) #define RIEBL_IVEC_ADDR ((unsigned short *)(((char *)MEM) + 0xfffe)) /* This is a default address for the old RieblCards without a battery * that have no ethernet address at boot time. 00:00:36:04 is the * prefix for Riebl cards, the 00:00 at the end is arbitrary. */ static unsigned char OldRieblDefHwaddr[6] = { 0x00, 0x00, 0x36, 0x04, 0x00, 0x00 }; /* I/O registers of the Lance chip */ struct lance_ioreg { /* base+0x0 */ volatile unsigned short data; /* base+0x2 */ volatile unsigned short addr; unsigned char _dummy1[3]; /* base+0x7 */ volatile unsigned char ivec; unsigned char _dummy2[5]; /* base+0xd */ volatile unsigned char eeprom; unsigned char _dummy3; /* base+0xf */ volatile unsigned char mem; }; /* Types of boards this driver supports */ enum lance_type { OLD_RIEBL, /* old Riebl card without battery */ NEW_RIEBL, /* new Riebl card with battery */ PAM_CARD /* PAM card with EEPROM */ }; static char *lance_names[] = { "Riebl-Card (without battery)", "Riebl-Card (with battery)", "PAM intern card" }; /* The driver's private device structure */ struct lance_private { enum lance_type cardtype; struct lance_ioreg *iobase; struct lance_memory *mem; int cur_rx, cur_tx; /* The next free ring entry */ int dirty_tx; /* Ring entries to be freed. */ /* copy function */ void *(*memcpy_f)( void *, const void *, size_t ); /* This must be long for set_bit() */ long tx_full; spinlock_t devlock; }; /* I/O register access macros */ #define MEM lp->mem #define DREG IO->data #define AREG IO->addr #define REGA(a) (*( AREG = (a), &DREG )) /* Definitions for packet buffer access: */ #define PKT_BUF_SZ 1544 /* Get the address of a packet buffer corresponding to a given buffer head */ #define PKTBUF_ADDR(head) (((unsigned char *)(MEM)) + (head)->base) /* Possible memory/IO addresses for probing */ static struct lance_addr { unsigned long memaddr; unsigned long ioaddr; int slow_flag; } lance_addr_list[] = { { 0xfe010000, 0xfe00fff0, 0 }, /* RieblCard VME in TT */ { 0xffc10000, 0xffc0fff0, 0 }, /* RieblCard VME in MegaSTE (highest byte stripped) */ { 0xffe00000, 0xffff7000, 1 }, /* RieblCard in ST (highest byte stripped) */ { 0xffd00000, 0xffff7000, 1 }, /* RieblCard in ST with hw modif. to avoid conflict with ROM (highest byte stripped) */ { 0xffcf0000, 0xffcffff0, 0 }, /* PAMCard VME in TT and MSTE (highest byte stripped) */ { 0xfecf0000, 0xfecffff0, 0 }, /* Rhotron's PAMCard VME in TT and MSTE (highest byte stripped) */ }; #define N_LANCE_ADDR ARRAY_SIZE(lance_addr_list) /* Definitions for the Lance */ /* tx_head flags */ #define TMD1_ENP 0x01 /* end of packet */ #define TMD1_STP 0x02 /* start of packet */ #define TMD1_DEF 0x04 /* deferred */ #define TMD1_ONE 0x08 /* one retry needed */ #define TMD1_MORE 0x10 /* more than one retry needed */ #define TMD1_ERR 0x40 /* error summary */ #define TMD1_OWN 0x80 /* ownership (set: chip owns) */ #define TMD1_OWN_CHIP TMD1_OWN #define TMD1_OWN_HOST 0 /* tx_head misc field */ #define TMD3_TDR 0x03FF /* Time Domain Reflectometry counter */ #define TMD3_RTRY 0x0400 /* failed after 16 retries */ #define TMD3_LCAR 0x0800 /* carrier lost */ #define TMD3_LCOL 0x1000 /* late collision */ #define TMD3_UFLO 0x4000 /* underflow (late memory) */ #define TMD3_BUFF 0x8000 /* buffering error (no ENP) */ /* rx_head flags */ #define RMD1_ENP 0x01 /* end of packet */ #define RMD1_STP 0x02 /* start of packet */ #define RMD1_BUFF 0x04 /* buffer error */ #define RMD1_CRC 0x08 /* CRC error */ #define RMD1_OFLO 0x10 /* overflow */ #define RMD1_FRAM 0x20 /* framing error */ #define RMD1_ERR 0x40 /* error summary */ #define RMD1_OWN 0x80 /* ownership (set: ship owns) */ #define RMD1_OWN_CHIP RMD1_OWN #define RMD1_OWN_HOST 0 /* register names */ #define CSR0 0 /* mode/status */ #define CSR1 1 /* init block addr (low) */ #define CSR2 2 /* init block addr (high) */ #define CSR3 3 /* misc */ #define CSR8 8 /* address filter */ #define CSR15 15 /* promiscuous mode */ /* CSR0 */ /* (R=readable, W=writeable, S=set on write, C=clear on write) */ #define CSR0_INIT 0x0001 /* initialize (RS) */ #define CSR0_STRT 0x0002 /* start (RS) */ #define CSR0_STOP 0x0004 /* stop (RS) */ #define CSR0_TDMD 0x0008 /* transmit demand (RS) */ #define CSR0_TXON 0x0010 /* transmitter on (R) */ #define CSR0_RXON 0x0020 /* receiver on (R) */ #define CSR0_INEA 0x0040 /* interrupt enable (RW) */ #define CSR0_INTR 0x0080 /* interrupt active (R) */ #define CSR0_IDON 0x0100 /* initialization done (RC) */ #define CSR0_TINT 0x0200 /* transmitter interrupt (RC) */ #define CSR0_RINT 0x0400 /* receiver interrupt (RC) */ #define CSR0_MERR 0x0800 /* memory error (RC) */ #define CSR0_MISS 0x1000 /* missed frame (RC) */ #define CSR0_CERR 0x2000 /* carrier error (no heartbeat :-) (RC) */ #define CSR0_BABL 0x4000 /* babble: tx-ed too many bits (RC) */ #define CSR0_ERR 0x8000 /* error (RC) */ /* CSR3 */ #define CSR3_BCON 0x0001 /* byte control */ #define CSR3_ACON 0x0002 /* ALE control */ #define CSR3_BSWP 0x0004 /* byte swap (1=big endian) */ /***************************** Prototypes *****************************/ static unsigned long lance_probe1( struct net_device *dev, struct lance_addr *init_rec ); static int lance_open( struct net_device *dev ); static void lance_init_ring( struct net_device *dev ); static int lance_start_xmit( struct sk_buff *skb, struct net_device *dev ); static irqreturn_t lance_interrupt( int irq, void *dev_id ); static int lance_rx( struct net_device *dev ); static int lance_close( struct net_device *dev ); static void set_multicast_list( struct net_device *dev ); static int lance_set_mac_address( struct net_device *dev, void *addr ); static void lance_tx_timeout (struct net_device *dev); /************************* End of Prototypes **************************/ static void *slow_memcpy( void *dst, const void *src, size_t len ) { char *cto = dst; const char *cfrom = src; while( len-- ) { *cto++ = *cfrom++; MFPDELAY(); } return dst; } struct net_device * __init atarilance_probe(int unit) { int i; static int found; struct net_device *dev; int err = -ENODEV; if (!MACH_IS_ATARI || found) /* Assume there's only one board possible... That seems true, since * the Riebl/PAM board's address cannot be changed. */ return ERR_PTR(-ENODEV); dev = alloc_etherdev(sizeof(struct lance_private)); if (!dev) return ERR_PTR(-ENOMEM); if (unit >= 0) { sprintf(dev->name, "eth%d", unit); netdev_boot_setup_check(dev); } for( i = 0; i < N_LANCE_ADDR; ++i ) { if (lance_probe1( dev, &lance_addr_list[i] )) { found = 1; err = register_netdev(dev); if (!err) return dev; free_irq(dev->irq, dev); break; } } free_netdev(dev); return ERR_PTR(err); } /* Derived from hwreg_present() in atari/config.c: */ static noinline int __init addr_accessible(volatile void *regp, int wordflag, int writeflag) { int ret; unsigned long flags; long *vbr, save_berr; local_irq_save(flags); __asm__ __volatile__ ( "movec %/vbr,%0" : "=r" (vbr) : ); save_berr = vbr[2]; __asm__ __volatile__ ( "movel %/sp,%/d1\n\t" "movel #Lberr,%2@\n\t" "moveq #0,%0\n\t" "tstl %3\n\t" "bne 1f\n\t" "moveb %1@,%/d0\n\t" "nop \n\t" "bra 2f\n" "1: movew %1@,%/d0\n\t" "nop \n" "2: tstl %4\n\t" "beq 2f\n\t" "tstl %3\n\t" "bne 1f\n\t" "clrb %1@\n\t" "nop \n\t" "moveb %/d0,%1@\n\t" "nop \n\t" "bra 2f\n" "1: clrw %1@\n\t" "nop \n\t" "movew %/d0,%1@\n\t" "nop \n" "2: moveq #1,%0\n" "Lberr: movel %/d1,%/sp" : "=&d" (ret) : "a" (regp), "a" (&vbr[2]), "rm" (wordflag), "rm" (writeflag) : "d0", "d1", "memory" ); vbr[2] = save_berr; local_irq_restore(flags); return ret; } static const struct net_device_ops lance_netdev_ops = { .ndo_open = lance_open, .ndo_stop = lance_close, .ndo_start_xmit = lance_start_xmit, .ndo_set_rx_mode = set_multicast_list, .ndo_set_mac_address = lance_set_mac_address, .ndo_tx_timeout = lance_tx_timeout, .ndo_validate_addr = eth_validate_addr, .ndo_change_mtu = eth_change_mtu, }; static unsigned long __init lance_probe1( struct net_device *dev, struct lance_addr *init_rec ) { volatile unsigned short *memaddr = (volatile unsigned short *)init_rec->memaddr; volatile unsigned short *ioaddr = (volatile unsigned short *)init_rec->ioaddr; struct lance_private *lp; struct lance_ioreg *IO; int i; static int did_version; unsigned short save1, save2; PROBE_PRINT(( "Probing for Lance card at mem %#lx io %#lx\n", (long)memaddr, (long)ioaddr )); /* Test whether memory readable and writable */ PROBE_PRINT(( "lance_probe1: testing memory to be accessible\n" )); if (!addr_accessible( memaddr, 1, 1 )) goto probe_fail; /* Written values should come back... */ PROBE_PRINT(( "lance_probe1: testing memory to be writable (1)\n" )); save1 = *memaddr; *memaddr = 0x0001; if (*memaddr != 0x0001) goto probe_fail; PROBE_PRINT(( "lance_probe1: testing memory to be writable (2)\n" )); *memaddr = 0x0000; if (*memaddr != 0x0000) goto probe_fail; *memaddr = save1; /* First port should be readable and writable */ PROBE_PRINT(( "lance_probe1: testing ioport to be accessible\n" )); if (!addr_accessible( ioaddr, 1, 1 )) goto probe_fail; /* and written values should be readable */ PROBE_PRINT(( "lance_probe1: testing ioport to be writeable\n" )); save2 = ioaddr[1]; ioaddr[1] = 0x0001; if (ioaddr[1] != 0x0001) goto probe_fail; /* The CSR0_INIT bit should not be readable */ PROBE_PRINT(( "lance_probe1: testing CSR0 register function (1)\n" )); save1 = ioaddr[0]; ioaddr[1] = CSR0; ioaddr[0] = CSR0_INIT | CSR0_STOP; if (ioaddr[0] != CSR0_STOP) { ioaddr[0] = save1; ioaddr[1] = save2; goto probe_fail; } PROBE_PRINT(( "lance_probe1: testing CSR0 register function (2)\n" )); ioaddr[0] = CSR0_STOP; if (ioaddr[0] != CSR0_STOP) { ioaddr[0] = save1; ioaddr[1] = save2; goto probe_fail; } /* Now ok... */ PROBE_PRINT(( "lance_probe1: Lance card detected\n" )); goto probe_ok; probe_fail: return 0; probe_ok: lp = netdev_priv(dev); MEM = (struct lance_memory *)memaddr; IO = lp->iobase = (struct lance_ioreg *)ioaddr; dev->base_addr = (unsigned long)ioaddr; /* informational only */ lp->memcpy_f = init_rec->slow_flag ? slow_memcpy : memcpy; REGA( CSR0 ) = CSR0_STOP; /* Now test for type: If the eeprom I/O port is readable, it is a * PAM card */ if (addr_accessible( &(IO->eeprom), 0, 0 )) { /* Switch back to Ram */ i = IO->mem; lp->cardtype = PAM_CARD; } else if (*RIEBL_MAGIC_ADDR == RIEBL_MAGIC) { lp->cardtype = NEW_RIEBL; } else lp->cardtype = OLD_RIEBL; if (lp->cardtype == PAM_CARD || memaddr == (unsigned short *)0xffe00000) { /* PAMs card and Riebl on ST use level 5 autovector */ if (request_irq(IRQ_AUTO_5, lance_interrupt, IRQ_TYPE_PRIO, "PAM,Riebl-ST Ethernet", dev)) { printk( "Lance: request for irq %d failed\n", IRQ_AUTO_5 ); return 0; } dev->irq = (unsigned short)IRQ_AUTO_5; } else { /* For VME-RieblCards, request a free VME int; * (This must be unsigned long, since dev->irq is short and the * IRQ_MACHSPEC bit would be cut off...) */ unsigned long irq = atari_register_vme_int(); if (!irq) { printk( "Lance: request for VME interrupt failed\n" ); return 0; } if (request_irq(irq, lance_interrupt, IRQ_TYPE_PRIO, "Riebl-VME Ethernet", dev)) { printk( "Lance: request for irq %ld failed\n", irq ); return 0; } dev->irq = irq; } printk("%s: %s at io %#lx, mem %#lx, irq %d%s, hwaddr ", dev->name, lance_names[lp->cardtype], (unsigned long)ioaddr, (unsigned long)memaddr, dev->irq, init_rec->slow_flag ? " (slow memcpy)" : "" ); /* Get the ethernet address */ switch( lp->cardtype ) { case OLD_RIEBL: /* No ethernet address! (Set some default address) */ memcpy( dev->dev_addr, OldRieblDefHwaddr, 6 ); break; case NEW_RIEBL: lp->memcpy_f( dev->dev_addr, RIEBL_HWADDR_ADDR, 6 ); break; case PAM_CARD: i = IO->eeprom; for( i = 0; i < 6; ++i ) dev->dev_addr[i] = ((((unsigned short *)MEM)[i*2] & 0x0f) << 4) | ((((unsigned short *)MEM)[i*2+1] & 0x0f)); i = IO->mem; break; } printk("%pM\n", dev->dev_addr); if (lp->cardtype == OLD_RIEBL) { printk( "%s: Warning: This is a default ethernet address!\n", dev->name ); printk( " Use \"ifconfig hw ether ...\" to set the address.\n" ); } spin_lock_init(&lp->devlock); MEM->init.mode = 0x0000; /* Disable Rx and Tx. */ for( i = 0; i < 6; i++ ) MEM->init.hwaddr[i] = dev->dev_addr[i^1]; /* <- 16 bit swap! */ MEM->init.filter[0] = 0x00000000; MEM->init.filter[1] = 0x00000000; MEM->init.rx_ring.adr_lo = offsetof( struct lance_memory, rx_head ); MEM->init.rx_ring.adr_hi = 0; MEM->init.rx_ring.len = RX_RING_LEN_BITS; MEM->init.tx_ring.adr_lo = offsetof( struct lance_memory, tx_head ); MEM->init.tx_ring.adr_hi = 0; MEM->init.tx_ring.len = TX_RING_LEN_BITS; if (lp->cardtype == PAM_CARD) IO->ivec = IRQ_SOURCE_TO_VECTOR(dev->irq); else *RIEBL_IVEC_ADDR = IRQ_SOURCE_TO_VECTOR(dev->irq); if (did_version++ == 0) DPRINTK( 1, ( version )); dev->netdev_ops = &lance_netdev_ops; /* XXX MSch */ dev->watchdog_timeo = TX_TIMEOUT; return 1; } static int lance_open( struct net_device *dev ) { struct lance_private *lp = netdev_priv(dev); struct lance_ioreg *IO = lp->iobase; int i; DPRINTK( 2, ( "%s: lance_open()\n", dev->name )); lance_init_ring(dev); /* Re-initialize the LANCE, and start it when done. */ REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0); REGA( CSR2 ) = 0; REGA( CSR1 ) = 0; REGA( CSR0 ) = CSR0_INIT; /* From now on, AREG is kept to point to CSR0 */ i = 1000000; while (--i > 0) if (DREG & CSR0_IDON) break; if (i <= 0 || (DREG & CSR0_ERR)) { DPRINTK( 2, ( "lance_open(): opening %s failed, i=%d, csr0=%04x\n", dev->name, i, DREG )); DREG = CSR0_STOP; return -EIO; } DREG = CSR0_IDON; DREG = CSR0_STRT; DREG = CSR0_INEA; netif_start_queue (dev); DPRINTK( 2, ( "%s: LANCE is open, csr0 %04x\n", dev->name, DREG )); return 0; } /* Initialize the LANCE Rx and Tx rings. */ static void lance_init_ring( struct net_device *dev ) { struct lance_private *lp = netdev_priv(dev); int i; unsigned offset; lp->tx_full = 0; lp->cur_rx = lp->cur_tx = 0; lp->dirty_tx = 0; offset = offsetof( struct lance_memory, packet_area ); /* If the packet buffer at offset 'o' would conflict with the reserved area * of RieblCards, advance it */ #define CHECK_OFFSET(o) \ do { \ if (lp->cardtype == OLD_RIEBL || lp->cardtype == NEW_RIEBL) { \ if (((o) < RIEBL_RSVD_START) ? (o)+PKT_BUF_SZ > RIEBL_RSVD_START \ : (o) < RIEBL_RSVD_END) \ (o) = RIEBL_RSVD_END; \ } \ } while(0) for( i = 0; i < TX_RING_SIZE; i++ ) { CHECK_OFFSET(offset); MEM->tx_head[i].base = offset; MEM->tx_head[i].flag = TMD1_OWN_HOST; MEM->tx_head[i].base_hi = 0; MEM->tx_head[i].length = 0; MEM->tx_head[i].misc = 0; offset += PKT_BUF_SZ; } for( i = 0; i < RX_RING_SIZE; i++ ) { CHECK_OFFSET(offset); MEM->rx_head[i].base = offset; MEM->rx_head[i].flag = TMD1_OWN_CHIP; MEM->rx_head[i].base_hi = 0; MEM->rx_head[i].buf_length = -PKT_BUF_SZ; MEM->rx_head[i].msg_length = 0; offset += PKT_BUF_SZ; } } /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */ static void lance_tx_timeout (struct net_device *dev) { struct lance_private *lp = netdev_priv(dev); struct lance_ioreg *IO = lp->iobase; AREG = CSR0; DPRINTK( 1, ( "%s: transmit timed out, status %04x, resetting.\n", dev->name, DREG )); DREG = CSR0_STOP; /* * Always set BSWP after a STOP as STOP puts it back into * little endian mode. */ REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0); dev->stats.tx_errors++; #ifndef final_version { int i; DPRINTK( 2, ( "Ring data: dirty_tx %d cur_tx %d%s cur_rx %d\n", lp->dirty_tx, lp->cur_tx, lp->tx_full ? " (full)" : "", lp->cur_rx )); for( i = 0 ; i < RX_RING_SIZE; i++ ) DPRINTK( 2, ( "rx #%d: base=%04x blen=%04x mlen=%04x\n", i, MEM->rx_head[i].base, -MEM->rx_head[i].buf_length, MEM->rx_head[i].msg_length )); for( i = 0 ; i < TX_RING_SIZE; i++ ) DPRINTK( 2, ( "tx #%d: base=%04x len=%04x misc=%04x\n", i, MEM->tx_head[i].base, -MEM->tx_head[i].length, MEM->tx_head[i].misc )); } #endif /* XXX MSch: maybe purge/reinit ring here */ /* lance_restart, essentially */ lance_init_ring(dev); REGA( CSR0 ) = CSR0_INEA | CSR0_INIT | CSR0_STRT; dev->trans_start = jiffies; /* prevent tx timeout */ netif_wake_queue(dev); } /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */ static int lance_start_xmit( struct sk_buff *skb, struct net_device *dev ) { struct lance_private *lp = netdev_priv(dev); struct lance_ioreg *IO = lp->iobase; int entry, len; struct lance_tx_head *head; unsigned long flags; DPRINTK( 2, ( "%s: lance_start_xmit() called, csr0 %4.4x.\n", dev->name, DREG )); /* The old LANCE chips doesn't automatically pad buffers to min. size. */ len = skb->len; if (len < ETH_ZLEN) len = ETH_ZLEN; /* PAM-Card has a bug: Can only send packets with even number of bytes! */ else if (lp->cardtype == PAM_CARD && (len & 1)) ++len; if (len > skb->len) { if (skb_padto(skb, len)) return NETDEV_TX_OK; } netif_stop_queue (dev); /* Fill in a Tx ring entry */ if (lance_debug >= 3) { printk( "%s: TX pkt type 0x%04x from %pM to %pM" " data at 0x%08x len %d\n", dev->name, ((u_short *)skb->data)[6], &skb->data[6], skb->data, (int)skb->data, (int)skb->len ); } /* We're not prepared for the int until the last flags are set/reset. And * the int may happen already after setting the OWN_CHIP... */ spin_lock_irqsave (&lp->devlock, flags); /* Mask to ring buffer boundary. */ entry = lp->cur_tx & TX_RING_MOD_MASK; head = &(MEM->tx_head[entry]); /* Caution: the write order is important here, set the "ownership" bits * last. */ head->length = -len; head->misc = 0; lp->memcpy_f( PKTBUF_ADDR(head), (void *)skb->data, skb->len ); head->flag = TMD1_OWN_CHIP | TMD1_ENP | TMD1_STP; dev->stats.tx_bytes += skb->len; dev_kfree_skb( skb ); lp->cur_tx++; while( lp->cur_tx >= TX_RING_SIZE && lp->dirty_tx >= TX_RING_SIZE ) { lp->cur_tx -= TX_RING_SIZE; lp->dirty_tx -= TX_RING_SIZE; } /* Trigger an immediate send poll. */ DREG = CSR0_INEA | CSR0_TDMD; if ((MEM->tx_head[(entry+1) & TX_RING_MOD_MASK].flag & TMD1_OWN) == TMD1_OWN_HOST) netif_start_queue (dev); else lp->tx_full = 1; spin_unlock_irqrestore (&lp->devlock, flags); return NETDEV_TX_OK; } /* The LANCE interrupt handler. */ static irqreturn_t lance_interrupt( int irq, void *dev_id ) { struct net_device *dev = dev_id; struct lance_private *lp; struct lance_ioreg *IO; int csr0, boguscnt = 10; int handled = 0; if (dev == NULL) { DPRINTK( 1, ( "lance_interrupt(): interrupt for unknown device.\n" )); return IRQ_NONE; } lp = netdev_priv(dev); IO = lp->iobase; spin_lock (&lp->devlock); AREG = CSR0; while( ((csr0 = DREG) & (CSR0_ERR | CSR0_TINT | CSR0_RINT)) && --boguscnt >= 0) { handled = 1; /* Acknowledge all of the current interrupt sources ASAP. */ DREG = csr0 & ~(CSR0_INIT | CSR0_STRT | CSR0_STOP | CSR0_TDMD | CSR0_INEA); DPRINTK( 2, ( "%s: interrupt csr0=%04x new csr=%04x.\n", dev->name, csr0, DREG )); if (csr0 & CSR0_RINT) /* Rx interrupt */ lance_rx( dev ); if (csr0 & CSR0_TINT) { /* Tx-done interrupt */ int dirty_tx = lp->dirty_tx; while( dirty_tx < lp->cur_tx) { int entry = dirty_tx & TX_RING_MOD_MASK; int status = MEM->tx_head[entry].flag; if (status & TMD1_OWN_CHIP) break; /* It still hasn't been Txed */ MEM->tx_head[entry].flag = 0; if (status & TMD1_ERR) { /* There was an major error, log it. */ int err_status = MEM->tx_head[entry].misc; dev->stats.tx_errors++; if (err_status & TMD3_RTRY) dev->stats.tx_aborted_errors++; if (err_status & TMD3_LCAR) dev->stats.tx_carrier_errors++; if (err_status & TMD3_LCOL) dev->stats.tx_window_errors++; if (err_status & TMD3_UFLO) { /* Ackk! On FIFO errors the Tx unit is turned off! */ dev->stats.tx_fifo_errors++; /* Remove this verbosity later! */ DPRINTK( 1, ( "%s: Tx FIFO error! Status %04x\n", dev->name, csr0 )); /* Restart the chip. */ DREG = CSR0_STRT; } } else { if (status & (TMD1_MORE | TMD1_ONE | TMD1_DEF)) dev->stats.collisions++; dev->stats.tx_packets++; } /* XXX MSch: free skb?? */ dirty_tx++; } #ifndef final_version if (lp->cur_tx - dirty_tx >= TX_RING_SIZE) { DPRINTK( 0, ( "out-of-sync dirty pointer," " %d vs. %d, full=%ld.\n", dirty_tx, lp->cur_tx, lp->tx_full )); dirty_tx += TX_RING_SIZE; } #endif if (lp->tx_full && (netif_queue_stopped(dev)) && dirty_tx > lp->cur_tx - TX_RING_SIZE + 2) { /* The ring is no longer full, clear tbusy. */ lp->tx_full = 0; netif_wake_queue (dev); } lp->dirty_tx = dirty_tx; } /* Log misc errors. */ if (csr0 & CSR0_BABL) dev->stats.tx_errors++; /* Tx babble. */ if (csr0 & CSR0_MISS) dev->stats.rx_errors++; /* Missed a Rx frame. */ if (csr0 & CSR0_MERR) { DPRINTK( 1, ( "%s: Bus master arbitration failure (?!?), " "status %04x.\n", dev->name, csr0 )); /* Restart the chip. */ DREG = CSR0_STRT; } } /* Clear any other interrupt, and set interrupt enable. */ DREG = CSR0_BABL | CSR0_CERR | CSR0_MISS | CSR0_MERR | CSR0_IDON | CSR0_INEA; DPRINTK( 2, ( "%s: exiting interrupt, csr0=%#04x.\n", dev->name, DREG )); spin_unlock (&lp->devlock); return IRQ_RETVAL(handled); } static int lance_rx( struct net_device *dev ) { struct lance_private *lp = netdev_priv(dev); int entry = lp->cur_rx & RX_RING_MOD_MASK; int i; DPRINTK( 2, ( "%s: rx int, flag=%04x\n", dev->name, MEM->rx_head[entry].flag )); /* If we own the next entry, it's a new packet. Send it up. */ while( (MEM->rx_head[entry].flag & RMD1_OWN) == RMD1_OWN_HOST ) { struct lance_rx_head *head = &(MEM->rx_head[entry]); int status = head->flag; if (status != (RMD1_ENP|RMD1_STP)) { /* There was an error. */ /* There is a tricky error noted by John Murphy, <murf@perftech.com> to Russ Nelson: Even with full-sized buffers it's possible for a jabber packet to use two buffers, with only the last correctly noting the error. */ if (status & RMD1_ENP) /* Only count a general error at the */ dev->stats.rx_errors++; /* end of a packet.*/ if (status & RMD1_FRAM) dev->stats.rx_frame_errors++; if (status & RMD1_OFLO) dev->stats.rx_over_errors++; if (status & RMD1_CRC) dev->stats.rx_crc_errors++; if (status & RMD1_BUFF) dev->stats.rx_fifo_errors++; head->flag &= (RMD1_ENP|RMD1_STP); } else { /* Malloc up new buffer, compatible with net-3. */ short pkt_len = head->msg_length & 0xfff; struct sk_buff *skb; if (pkt_len < 60) { printk( "%s: Runt packet!\n", dev->name ); dev->stats.rx_errors++; } else { skb = netdev_alloc_skb(dev, pkt_len + 2); if (skb == NULL) { DPRINTK( 1, ( "%s: Memory squeeze, deferring packet.\n", dev->name )); for( i = 0; i < RX_RING_SIZE; i++ ) if (MEM->rx_head[(entry+i) & RX_RING_MOD_MASK].flag & RMD1_OWN_CHIP) break; if (i > RX_RING_SIZE - 2) { dev->stats.rx_dropped++; head->flag |= RMD1_OWN_CHIP; lp->cur_rx++; } break; } if (lance_debug >= 3) { u_char *data = PKTBUF_ADDR(head); printk(KERN_DEBUG "%s: RX pkt type 0x%04x from %pM to %pM " "data %02x %02x %02x %02x %02x %02x %02x %02x " "len %d\n", dev->name, ((u_short *)data)[6], &data[6], data, data[15], data[16], data[17], data[18], data[19], data[20], data[21], data[22], pkt_len); } skb_reserve( skb, 2 ); /* 16 byte align */ skb_put( skb, pkt_len ); /* Make room */ lp->memcpy_f( skb->data, PKTBUF_ADDR(head), pkt_len ); skb->protocol = eth_type_trans( skb, dev ); netif_rx( skb ); dev->stats.rx_packets++; dev->stats.rx_bytes += pkt_len; } } head->flag |= RMD1_OWN_CHIP; entry = (++lp->cur_rx) & RX_RING_MOD_MASK; } lp->cur_rx &= RX_RING_MOD_MASK; /* From lance.c (Donald Becker): */ /* We should check that at least two ring entries are free. If not, we should free one and mark stats->rx_dropped++. */ return 0; } static int lance_close( struct net_device *dev ) { struct lance_private *lp = netdev_priv(dev); struct lance_ioreg *IO = lp->iobase; netif_stop_queue (dev); AREG = CSR0; DPRINTK( 2, ( "%s: Shutting down ethercard, status was %2.2x.\n", dev->name, DREG )); /* We stop the LANCE here -- it occasionally polls memory if we don't. */ DREG = CSR0_STOP; return 0; } /* Set or clear the multicast filter for this adaptor. num_addrs == -1 Promiscuous mode, receive all packets num_addrs == 0 Normal mode, clear multicast list num_addrs > 0 Multicast mode, receive normal and MC packets, and do best-effort filtering. */ static void set_multicast_list( struct net_device *dev ) { struct lance_private *lp = netdev_priv(dev); struct lance_ioreg *IO = lp->iobase; if (netif_running(dev)) /* Only possible if board is already started */ return; /* We take the simple way out and always enable promiscuous mode. */ DREG = CSR0_STOP; /* Temporarily stop the lance. */ if (dev->flags & IFF_PROMISC) { /* Log any net taps. */ DPRINTK( 2, ( "%s: Promiscuous mode enabled.\n", dev->name )); REGA( CSR15 ) = 0x8000; /* Set promiscuous mode */ } else { short multicast_table[4]; int num_addrs = netdev_mc_count(dev); int i; /* We don't use the multicast table, but rely on upper-layer * filtering. */ memset( multicast_table, (num_addrs == 0) ? 0 : -1, sizeof(multicast_table) ); for( i = 0; i < 4; i++ ) REGA( CSR8+i ) = multicast_table[i]; REGA( CSR15 ) = 0; /* Unset promiscuous mode */ } /* * Always set BSWP after a STOP as STOP puts it back into * little endian mode. */ REGA( CSR3 ) = CSR3_BSWP | (lp->cardtype == PAM_CARD ? CSR3_ACON : 0); /* Resume normal operation and reset AREG to CSR0 */ REGA( CSR0 ) = CSR0_IDON | CSR0_INEA | CSR0_STRT; } /* This is needed for old RieblCards and possible for new RieblCards */ static int lance_set_mac_address( struct net_device *dev, void *addr ) { struct lance_private *lp = netdev_priv(dev); struct sockaddr *saddr = addr; int i; if (lp->cardtype != OLD_RIEBL && lp->cardtype != NEW_RIEBL) return -EOPNOTSUPP; if (netif_running(dev)) { /* Only possible while card isn't started */ DPRINTK( 1, ( "%s: hwaddr can be set only while card isn't open.\n", dev->name )); return -EIO; } memcpy( dev->dev_addr, saddr->sa_data, dev->addr_len ); for( i = 0; i < 6; i++ ) MEM->init.hwaddr[i] = dev->dev_addr[i^1]; /* <- 16 bit swap! */ lp->memcpy_f( RIEBL_HWADDR_ADDR, dev->dev_addr, 6 ); /* set also the magic for future sessions */ *RIEBL_MAGIC_ADDR = RIEBL_MAGIC; return 0; } #ifdef MODULE static struct net_device *atarilance_dev; static int __init atarilance_module_init(void) { atarilance_dev = atarilance_probe(-1); if (IS_ERR(atarilance_dev)) return PTR_ERR(atarilance_dev); return 0; } static void __exit atarilance_module_exit(void) { unregister_netdev(atarilance_dev); free_irq(atarilance_dev->irq, atarilance_dev); free_netdev(atarilance_dev); } module_init(atarilance_module_init); module_exit(atarilance_module_exit); #endif /* MODULE */ /* * Local variables: * c-indent-level: 4 * tab-width: 4 * End: */
gpl-2.0
hch-im/nexus4_kernel
lib/raid6/algos.c
5057
3744
/* -*- linux-c -*- ------------------------------------------------------- * * * Copyright 2002 H. Peter Anvin - 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, Inc., 53 Temple Place Ste 330, * Boston MA 02111-1307, USA; either version 2 of the License, or * (at your option) any later version; incorporated herein by reference. * * ----------------------------------------------------------------------- */ /* * raid6/algos.c * * Algorithm list and algorithm selection for RAID-6 */ #include <linux/raid/pq.h> #include <linux/module.h> #ifndef __KERNEL__ #include <sys/mman.h> #include <stdio.h> #else #include <linux/gfp.h> #if !RAID6_USE_EMPTY_ZERO_PAGE /* In .bss so it's zeroed */ const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256))); EXPORT_SYMBOL(raid6_empty_zero_page); #endif #endif struct raid6_calls raid6_call; EXPORT_SYMBOL_GPL(raid6_call); const struct raid6_calls * const raid6_algos[] = { &raid6_intx1, &raid6_intx2, &raid6_intx4, &raid6_intx8, #if defined(__ia64__) &raid6_intx16, &raid6_intx32, #endif #if defined(__i386__) && !defined(__arch_um__) &raid6_mmxx1, &raid6_mmxx2, &raid6_sse1x1, &raid6_sse1x2, &raid6_sse2x1, &raid6_sse2x2, #endif #if defined(__x86_64__) && !defined(__arch_um__) &raid6_sse2x1, &raid6_sse2x2, &raid6_sse2x4, #endif #ifdef CONFIG_ALTIVEC &raid6_altivec1, &raid6_altivec2, &raid6_altivec4, &raid6_altivec8, #endif NULL }; #ifdef __KERNEL__ #define RAID6_TIME_JIFFIES_LG2 4 #else /* Need more time to be stable in userspace */ #define RAID6_TIME_JIFFIES_LG2 9 #define time_before(x, y) ((x) < (y)) #endif /* Try to pick the best algorithm */ /* This code uses the gfmul table as convenient data set to abuse */ int __init raid6_select_algo(void) { const struct raid6_calls * const * algo; const struct raid6_calls * best; char *syndromes; void *dptrs[(65536/PAGE_SIZE)+2]; int i, disks; unsigned long perf, bestperf; int bestprefer; unsigned long j0, j1; disks = (65536/PAGE_SIZE)+2; for ( i = 0 ; i < disks-2 ; i++ ) { dptrs[i] = ((char *)raid6_gfmul) + PAGE_SIZE*i; } /* Normal code - use a 2-page allocation to avoid D$ conflict */ syndromes = (void *) __get_free_pages(GFP_KERNEL, 1); if ( !syndromes ) { printk("raid6: Yikes! No memory available.\n"); return -ENOMEM; } dptrs[disks-2] = syndromes; dptrs[disks-1] = syndromes + PAGE_SIZE; bestperf = 0; bestprefer = 0; best = NULL; for ( algo = raid6_algos ; *algo ; algo++ ) { if ( !(*algo)->valid || (*algo)->valid() ) { perf = 0; preempt_disable(); j0 = jiffies; while ( (j1 = jiffies) == j0 ) cpu_relax(); while (time_before(jiffies, j1 + (1<<RAID6_TIME_JIFFIES_LG2))) { (*algo)->gen_syndrome(disks, PAGE_SIZE, dptrs); perf++; } preempt_enable(); if ( (*algo)->prefer > bestprefer || ((*algo)->prefer == bestprefer && perf > bestperf) ) { best = *algo; bestprefer = best->prefer; bestperf = perf; } printk("raid6: %-8s %5ld MB/s\n", (*algo)->name, (perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2)); } } if (best) { printk("raid6: using algorithm %s (%ld MB/s)\n", best->name, (bestperf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2)); raid6_call = *best; } else printk("raid6: Yikes! No algorithm found!\n"); free_pages((unsigned long)syndromes, 1); return best ? 0 : -EINVAL; } static void raid6_exit(void) { do { } while (0); } subsys_initcall(raid6_select_algo); module_exit(raid6_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("RAID6 Q-syndrome calculations");
gpl-2.0
blumak2000/blumak_kernel_s4_Lollipop
lib/raid6/algos.c
5057
3744
/* -*- linux-c -*- ------------------------------------------------------- * * * Copyright 2002 H. Peter Anvin - 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, Inc., 53 Temple Place Ste 330, * Boston MA 02111-1307, USA; either version 2 of the License, or * (at your option) any later version; incorporated herein by reference. * * ----------------------------------------------------------------------- */ /* * raid6/algos.c * * Algorithm list and algorithm selection for RAID-6 */ #include <linux/raid/pq.h> #include <linux/module.h> #ifndef __KERNEL__ #include <sys/mman.h> #include <stdio.h> #else #include <linux/gfp.h> #if !RAID6_USE_EMPTY_ZERO_PAGE /* In .bss so it's zeroed */ const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256))); EXPORT_SYMBOL(raid6_empty_zero_page); #endif #endif struct raid6_calls raid6_call; EXPORT_SYMBOL_GPL(raid6_call); const struct raid6_calls * const raid6_algos[] = { &raid6_intx1, &raid6_intx2, &raid6_intx4, &raid6_intx8, #if defined(__ia64__) &raid6_intx16, &raid6_intx32, #endif #if defined(__i386__) && !defined(__arch_um__) &raid6_mmxx1, &raid6_mmxx2, &raid6_sse1x1, &raid6_sse1x2, &raid6_sse2x1, &raid6_sse2x2, #endif #if defined(__x86_64__) && !defined(__arch_um__) &raid6_sse2x1, &raid6_sse2x2, &raid6_sse2x4, #endif #ifdef CONFIG_ALTIVEC &raid6_altivec1, &raid6_altivec2, &raid6_altivec4, &raid6_altivec8, #endif NULL }; #ifdef __KERNEL__ #define RAID6_TIME_JIFFIES_LG2 4 #else /* Need more time to be stable in userspace */ #define RAID6_TIME_JIFFIES_LG2 9 #define time_before(x, y) ((x) < (y)) #endif /* Try to pick the best algorithm */ /* This code uses the gfmul table as convenient data set to abuse */ int __init raid6_select_algo(void) { const struct raid6_calls * const * algo; const struct raid6_calls * best; char *syndromes; void *dptrs[(65536/PAGE_SIZE)+2]; int i, disks; unsigned long perf, bestperf; int bestprefer; unsigned long j0, j1; disks = (65536/PAGE_SIZE)+2; for ( i = 0 ; i < disks-2 ; i++ ) { dptrs[i] = ((char *)raid6_gfmul) + PAGE_SIZE*i; } /* Normal code - use a 2-page allocation to avoid D$ conflict */ syndromes = (void *) __get_free_pages(GFP_KERNEL, 1); if ( !syndromes ) { printk("raid6: Yikes! No memory available.\n"); return -ENOMEM; } dptrs[disks-2] = syndromes; dptrs[disks-1] = syndromes + PAGE_SIZE; bestperf = 0; bestprefer = 0; best = NULL; for ( algo = raid6_algos ; *algo ; algo++ ) { if ( !(*algo)->valid || (*algo)->valid() ) { perf = 0; preempt_disable(); j0 = jiffies; while ( (j1 = jiffies) == j0 ) cpu_relax(); while (time_before(jiffies, j1 + (1<<RAID6_TIME_JIFFIES_LG2))) { (*algo)->gen_syndrome(disks, PAGE_SIZE, dptrs); perf++; } preempt_enable(); if ( (*algo)->prefer > bestprefer || ((*algo)->prefer == bestprefer && perf > bestperf) ) { best = *algo; bestprefer = best->prefer; bestperf = perf; } printk("raid6: %-8s %5ld MB/s\n", (*algo)->name, (perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2)); } } if (best) { printk("raid6: using algorithm %s (%ld MB/s)\n", best->name, (bestperf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2)); raid6_call = *best; } else printk("raid6: Yikes! No algorithm found!\n"); free_pages((unsigned long)syndromes, 1); return best ? 0 : -EINVAL; } static void raid6_exit(void) { do { } while (0); } subsys_initcall(raid6_select_algo); module_exit(raid6_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("RAID6 Q-syndrome calculations");
gpl-2.0
omegamoon/rockchip-rk3188-generic
fs/fscache/stats.c
7361
9842
/* FS-Cache statistics * * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.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. */ #define FSCACHE_DEBUG_LEVEL THREAD #include <linux/module.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> #include "internal.h" /* * operation counters */ atomic_t fscache_n_op_pend; atomic_t fscache_n_op_run; atomic_t fscache_n_op_enqueue; atomic_t fscache_n_op_requeue; atomic_t fscache_n_op_deferred_release; atomic_t fscache_n_op_release; atomic_t fscache_n_op_gc; atomic_t fscache_n_op_cancelled; atomic_t fscache_n_op_rejected; atomic_t fscache_n_attr_changed; atomic_t fscache_n_attr_changed_ok; atomic_t fscache_n_attr_changed_nobufs; atomic_t fscache_n_attr_changed_nomem; atomic_t fscache_n_attr_changed_calls; atomic_t fscache_n_allocs; atomic_t fscache_n_allocs_ok; atomic_t fscache_n_allocs_wait; atomic_t fscache_n_allocs_nobufs; atomic_t fscache_n_allocs_intr; atomic_t fscache_n_allocs_object_dead; atomic_t fscache_n_alloc_ops; atomic_t fscache_n_alloc_op_waits; atomic_t fscache_n_retrievals; atomic_t fscache_n_retrievals_ok; atomic_t fscache_n_retrievals_wait; atomic_t fscache_n_retrievals_nodata; atomic_t fscache_n_retrievals_nobufs; atomic_t fscache_n_retrievals_intr; atomic_t fscache_n_retrievals_nomem; atomic_t fscache_n_retrievals_object_dead; atomic_t fscache_n_retrieval_ops; atomic_t fscache_n_retrieval_op_waits; atomic_t fscache_n_stores; atomic_t fscache_n_stores_ok; atomic_t fscache_n_stores_again; atomic_t fscache_n_stores_nobufs; atomic_t fscache_n_stores_oom; atomic_t fscache_n_store_ops; atomic_t fscache_n_store_calls; atomic_t fscache_n_store_pages; atomic_t fscache_n_store_radix_deletes; atomic_t fscache_n_store_pages_over_limit; atomic_t fscache_n_store_vmscan_not_storing; atomic_t fscache_n_store_vmscan_gone; atomic_t fscache_n_store_vmscan_busy; atomic_t fscache_n_store_vmscan_cancelled; atomic_t fscache_n_marks; atomic_t fscache_n_uncaches; atomic_t fscache_n_acquires; atomic_t fscache_n_acquires_null; atomic_t fscache_n_acquires_no_cache; atomic_t fscache_n_acquires_ok; atomic_t fscache_n_acquires_nobufs; atomic_t fscache_n_acquires_oom; atomic_t fscache_n_updates; atomic_t fscache_n_updates_null; atomic_t fscache_n_updates_run; atomic_t fscache_n_relinquishes; atomic_t fscache_n_relinquishes_null; atomic_t fscache_n_relinquishes_waitcrt; atomic_t fscache_n_relinquishes_retire; atomic_t fscache_n_cookie_index; atomic_t fscache_n_cookie_data; atomic_t fscache_n_cookie_special; atomic_t fscache_n_object_alloc; atomic_t fscache_n_object_no_alloc; atomic_t fscache_n_object_lookups; atomic_t fscache_n_object_lookups_negative; atomic_t fscache_n_object_lookups_positive; atomic_t fscache_n_object_lookups_timed_out; atomic_t fscache_n_object_created; atomic_t fscache_n_object_avail; atomic_t fscache_n_object_dead; atomic_t fscache_n_checkaux_none; atomic_t fscache_n_checkaux_okay; atomic_t fscache_n_checkaux_update; atomic_t fscache_n_checkaux_obsolete; atomic_t fscache_n_cop_alloc_object; atomic_t fscache_n_cop_lookup_object; atomic_t fscache_n_cop_lookup_complete; atomic_t fscache_n_cop_grab_object; atomic_t fscache_n_cop_update_object; atomic_t fscache_n_cop_drop_object; atomic_t fscache_n_cop_put_object; atomic_t fscache_n_cop_sync_cache; atomic_t fscache_n_cop_attr_changed; atomic_t fscache_n_cop_read_or_alloc_page; atomic_t fscache_n_cop_read_or_alloc_pages; atomic_t fscache_n_cop_allocate_page; atomic_t fscache_n_cop_allocate_pages; atomic_t fscache_n_cop_write_page; atomic_t fscache_n_cop_uncache_page; atomic_t fscache_n_cop_dissociate_pages; /* * display the general statistics */ static int fscache_stats_show(struct seq_file *m, void *v) { seq_puts(m, "FS-Cache statistics\n"); seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n", atomic_read(&fscache_n_cookie_index), atomic_read(&fscache_n_cookie_data), atomic_read(&fscache_n_cookie_special)); seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n", atomic_read(&fscache_n_object_alloc), atomic_read(&fscache_n_object_no_alloc), atomic_read(&fscache_n_object_avail), atomic_read(&fscache_n_object_dead)); seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n", atomic_read(&fscache_n_checkaux_none), atomic_read(&fscache_n_checkaux_okay), atomic_read(&fscache_n_checkaux_update), atomic_read(&fscache_n_checkaux_obsolete)); seq_printf(m, "Pages : mrk=%u unc=%u\n", atomic_read(&fscache_n_marks), atomic_read(&fscache_n_uncaches)); seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u" " oom=%u\n", atomic_read(&fscache_n_acquires), atomic_read(&fscache_n_acquires_null), atomic_read(&fscache_n_acquires_no_cache), atomic_read(&fscache_n_acquires_ok), atomic_read(&fscache_n_acquires_nobufs), atomic_read(&fscache_n_acquires_oom)); seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n", atomic_read(&fscache_n_object_lookups), atomic_read(&fscache_n_object_lookups_negative), atomic_read(&fscache_n_object_lookups_positive), atomic_read(&fscache_n_object_created), atomic_read(&fscache_n_object_lookups_timed_out)); seq_printf(m, "Updates: n=%u nul=%u run=%u\n", atomic_read(&fscache_n_updates), atomic_read(&fscache_n_updates_null), atomic_read(&fscache_n_updates_run)); seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n", atomic_read(&fscache_n_relinquishes), atomic_read(&fscache_n_relinquishes_null), atomic_read(&fscache_n_relinquishes_waitcrt), atomic_read(&fscache_n_relinquishes_retire)); seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n", atomic_read(&fscache_n_attr_changed), atomic_read(&fscache_n_attr_changed_ok), atomic_read(&fscache_n_attr_changed_nobufs), atomic_read(&fscache_n_attr_changed_nomem), atomic_read(&fscache_n_attr_changed_calls)); seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n", atomic_read(&fscache_n_allocs), atomic_read(&fscache_n_allocs_ok), atomic_read(&fscache_n_allocs_wait), atomic_read(&fscache_n_allocs_nobufs), atomic_read(&fscache_n_allocs_intr)); seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n", atomic_read(&fscache_n_alloc_ops), atomic_read(&fscache_n_alloc_op_waits), atomic_read(&fscache_n_allocs_object_dead)); seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u" " int=%u oom=%u\n", atomic_read(&fscache_n_retrievals), atomic_read(&fscache_n_retrievals_ok), atomic_read(&fscache_n_retrievals_wait), atomic_read(&fscache_n_retrievals_nodata), atomic_read(&fscache_n_retrievals_nobufs), atomic_read(&fscache_n_retrievals_intr), atomic_read(&fscache_n_retrievals_nomem)); seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n", atomic_read(&fscache_n_retrieval_ops), atomic_read(&fscache_n_retrieval_op_waits), atomic_read(&fscache_n_retrievals_object_dead)); seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n", atomic_read(&fscache_n_stores), atomic_read(&fscache_n_stores_ok), atomic_read(&fscache_n_stores_again), atomic_read(&fscache_n_stores_nobufs), atomic_read(&fscache_n_stores_oom)); seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n", atomic_read(&fscache_n_store_ops), atomic_read(&fscache_n_store_calls), atomic_read(&fscache_n_store_pages), atomic_read(&fscache_n_store_radix_deletes), atomic_read(&fscache_n_store_pages_over_limit)); seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n", atomic_read(&fscache_n_store_vmscan_not_storing), atomic_read(&fscache_n_store_vmscan_gone), atomic_read(&fscache_n_store_vmscan_busy), atomic_read(&fscache_n_store_vmscan_cancelled)); seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n", atomic_read(&fscache_n_op_pend), atomic_read(&fscache_n_op_run), atomic_read(&fscache_n_op_enqueue), atomic_read(&fscache_n_op_cancelled), atomic_read(&fscache_n_op_rejected)); seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n", atomic_read(&fscache_n_op_deferred_release), atomic_read(&fscache_n_op_release), atomic_read(&fscache_n_op_gc)); seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n", atomic_read(&fscache_n_cop_alloc_object), atomic_read(&fscache_n_cop_lookup_object), atomic_read(&fscache_n_cop_lookup_complete), atomic_read(&fscache_n_cop_grab_object)); seq_printf(m, "CacheOp: upo=%d dro=%d pto=%d atc=%d syn=%d\n", atomic_read(&fscache_n_cop_update_object), atomic_read(&fscache_n_cop_drop_object), atomic_read(&fscache_n_cop_put_object), atomic_read(&fscache_n_cop_attr_changed), atomic_read(&fscache_n_cop_sync_cache)); seq_printf(m, "CacheOp: rap=%d ras=%d alp=%d als=%d wrp=%d ucp=%d dsp=%d\n", atomic_read(&fscache_n_cop_read_or_alloc_page), atomic_read(&fscache_n_cop_read_or_alloc_pages), atomic_read(&fscache_n_cop_allocate_page), atomic_read(&fscache_n_cop_allocate_pages), atomic_read(&fscache_n_cop_write_page), atomic_read(&fscache_n_cop_uncache_page), atomic_read(&fscache_n_cop_dissociate_pages)); return 0; } /* * open "/proc/fs/fscache/stats" allowing provision of a statistical summary */ static int fscache_stats_open(struct inode *inode, struct file *file) { return single_open(file, fscache_stats_show, NULL); } const struct file_operations fscache_stats_fops = { .owner = THIS_MODULE, .open = fscache_stats_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release, };
gpl-2.0
javelinanddart/android_kernel_3.10_ville
arch/cris/arch-v10/kernel/setup.c
7873
2998
/* * * linux/arch/cris/arch-v10/kernel/setup.c * * Copyright (C) 1995 Linus Torvalds * Copyright (c) 2001-2002 Axis Communications AB */ /* * This file handles the architecture-dependent parts of initialization */ #include <linux/seq_file.h> #include <linux/proc_fs.h> #include <linux/delay.h> #include <linux/param.h> #include <arch/system.h> #ifdef CONFIG_PROC_FS #define HAS_FPU 0x0001 #define HAS_MMU 0x0002 #define HAS_ETHERNET100 0x0004 #define HAS_TOKENRING 0x0008 #define HAS_SCSI 0x0010 #define HAS_ATA 0x0020 #define HAS_USB 0x0040 #define HAS_IRQ_BUG 0x0080 #define HAS_MMU_BUG 0x0100 static struct cpu_info { char *model; unsigned short cache; unsigned short flags; } cpu_info[] = { /* The first four models will never ever run this code and are only here for display. */ { "ETRAX 1", 0, 0 }, { "ETRAX 2", 0, 0 }, { "ETRAX 3", 0, HAS_TOKENRING }, { "ETRAX 4", 0, HAS_TOKENRING | HAS_SCSI }, { "Unknown", 0, 0 }, { "Unknown", 0, 0 }, { "Unknown", 0, 0 }, { "Simulator", 8, HAS_ETHERNET100 | HAS_SCSI | HAS_ATA }, { "ETRAX 100", 8, HAS_ETHERNET100 | HAS_SCSI | HAS_ATA | HAS_IRQ_BUG }, { "ETRAX 100", 8, HAS_ETHERNET100 | HAS_SCSI | HAS_ATA }, { "ETRAX 100LX", 8, HAS_ETHERNET100 | HAS_SCSI | HAS_ATA | HAS_USB | HAS_MMU | HAS_MMU_BUG }, { "ETRAX 100LX v2", 8, HAS_ETHERNET100 | HAS_SCSI | HAS_ATA | HAS_USB | HAS_MMU }, { "Unknown", 0, 0 } /* This entry MUST be the last */ }; int show_cpuinfo(struct seq_file *m, void *v) { unsigned long revision; struct cpu_info *info; /* read the version register in the CPU and print some stuff */ revision = rdvr(); if (revision >= ARRAY_SIZE(cpu_info)) info = &cpu_info[ARRAY_SIZE(cpu_info) - 1]; else info = &cpu_info[revision]; return seq_printf(m, "processor\t: 0\n" "cpu\t\t: CRIS\n" "cpu revision\t: %lu\n" "cpu model\t: %s\n" "cache size\t: %d kB\n" "fpu\t\t: %s\n" "mmu\t\t: %s\n" "mmu DMA bug\t: %s\n" "ethernet\t: %s Mbps\n" "token ring\t: %s\n" "scsi\t\t: %s\n" "ata\t\t: %s\n" "usb\t\t: %s\n" "bogomips\t: %lu.%02lu\n", revision, info->model, info->cache, info->flags & HAS_FPU ? "yes" : "no", info->flags & HAS_MMU ? "yes" : "no", info->flags & HAS_MMU_BUG ? "yes" : "no", info->flags & HAS_ETHERNET100 ? "10/100" : "10", info->flags & HAS_TOKENRING ? "4/16 Mbps" : "no", info->flags & HAS_SCSI ? "yes" : "no", info->flags & HAS_ATA ? "yes" : "no", info->flags & HAS_USB ? "yes" : "no", (loops_per_jiffy * HZ + 500) / 500000, ((loops_per_jiffy * HZ + 500) / 5000) % 100); } #endif /* CONFIG_PROC_FS */ void show_etrax_copyright(void) { printk(KERN_INFO "Linux/CRIS port on ETRAX 100LX (c) 2001 Axis Communications AB\n"); }
gpl-2.0
AdiPat/android_kernel_htc_pico
drivers/input/touchscreen/dynapro.c
9153
4883
/* * Dynapro serial touchscreen driver * * Copyright (c) 2009 Tias Guns * Based on the inexio driver (c) Vojtech Pavlik and Dan Streetman and * Richard Lemon * */ /* * 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. */ /* * 2009/09/19 Tias Guns <tias@ulyssis.org> * Copied inexio.c and edited for Dynapro protocol (from retired Xorg module) */ #include <linux/errno.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/input.h> #include <linux/serio.h> #include <linux/init.h> #define DRIVER_DESC "Dynapro serial touchscreen driver" MODULE_AUTHOR("Tias Guns <tias@ulyssis.org>"); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); /* * Definitions & global arrays. */ #define DYNAPRO_FORMAT_TOUCH_BIT 0x40 #define DYNAPRO_FORMAT_LENGTH 3 #define DYNAPRO_RESPONSE_BEGIN_BYTE 0x80 #define DYNAPRO_MIN_XC 0 #define DYNAPRO_MAX_XC 0x3ff #define DYNAPRO_MIN_YC 0 #define DYNAPRO_MAX_YC 0x3ff #define DYNAPRO_GET_XC(data) (data[1] | ((data[0] & 0x38) << 4)) #define DYNAPRO_GET_YC(data) (data[2] | ((data[0] & 0x07) << 7)) #define DYNAPRO_GET_TOUCHED(data) (DYNAPRO_FORMAT_TOUCH_BIT & data[0]) /* * Per-touchscreen data. */ struct dynapro { struct input_dev *dev; struct serio *serio; int idx; unsigned char data[DYNAPRO_FORMAT_LENGTH]; char phys[32]; }; static void dynapro_process_data(struct dynapro *pdynapro) { struct input_dev *dev = pdynapro->dev; if (DYNAPRO_FORMAT_LENGTH == ++pdynapro->idx) { input_report_abs(dev, ABS_X, DYNAPRO_GET_XC(pdynapro->data)); input_report_abs(dev, ABS_Y, DYNAPRO_GET_YC(pdynapro->data)); input_report_key(dev, BTN_TOUCH, DYNAPRO_GET_TOUCHED(pdynapro->data)); input_sync(dev); pdynapro->idx = 0; } } static irqreturn_t dynapro_interrupt(struct serio *serio, unsigned char data, unsigned int flags) { struct dynapro *pdynapro = serio_get_drvdata(serio); pdynapro->data[pdynapro->idx] = data; if (DYNAPRO_RESPONSE_BEGIN_BYTE & pdynapro->data[0]) dynapro_process_data(pdynapro); else dev_dbg(&serio->dev, "unknown/unsynchronized data: %x\n", pdynapro->data[0]); return IRQ_HANDLED; } static void dynapro_disconnect(struct serio *serio) { struct dynapro *pdynapro = serio_get_drvdata(serio); input_get_device(pdynapro->dev); input_unregister_device(pdynapro->dev); serio_close(serio); serio_set_drvdata(serio, NULL); input_put_device(pdynapro->dev); kfree(pdynapro); } /* * dynapro_connect() is the routine that is called when someone adds a * new serio device that supports dynapro protocol and registers it as * an input device. This is usually accomplished using inputattach. */ static int dynapro_connect(struct serio *serio, struct serio_driver *drv) { struct dynapro *pdynapro; struct input_dev *input_dev; int err; pdynapro = kzalloc(sizeof(struct dynapro), GFP_KERNEL); input_dev = input_allocate_device(); if (!pdynapro || !input_dev) { err = -ENOMEM; goto fail1; } pdynapro->serio = serio; pdynapro->dev = input_dev; snprintf(pdynapro->phys, sizeof(pdynapro->phys), "%s/input0", serio->phys); input_dev->name = "Dynapro Serial TouchScreen"; input_dev->phys = pdynapro->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_DYNAPRO; input_dev->id.product = 0; input_dev->id.version = 0x0001; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); input_set_abs_params(pdynapro->dev, ABS_X, DYNAPRO_MIN_XC, DYNAPRO_MAX_XC, 0, 0); input_set_abs_params(pdynapro->dev, ABS_Y, DYNAPRO_MIN_YC, DYNAPRO_MAX_YC, 0, 0); serio_set_drvdata(serio, pdynapro); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(pdynapro->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(pdynapro); return err; } /* * The serio driver structure. */ static struct serio_device_id dynapro_serio_ids[] = { { .type = SERIO_RS232, .proto = SERIO_DYNAPRO, .id = SERIO_ANY, .extra = SERIO_ANY, }, { 0 } }; MODULE_DEVICE_TABLE(serio, dynapro_serio_ids); static struct serio_driver dynapro_drv = { .driver = { .name = "dynapro", }, .description = DRIVER_DESC, .id_table = dynapro_serio_ids, .interrupt = dynapro_interrupt, .connect = dynapro_connect, .disconnect = dynapro_disconnect, }; /* * The functions for inserting/removing us as a module. */ static int __init dynapro_init(void) { return serio_register_driver(&dynapro_drv); } static void __exit dynapro_exit(void) { serio_unregister_driver(&dynapro_drv); } module_init(dynapro_init); module_exit(dynapro_exit);
gpl-2.0
alouche/redhat-2.6.32-xen-dom0-kernel
drivers/input/touchscreen/fujitsu_ts.c
9921
4297
/* * Fujitsu serial touchscreen driver * * Copyright (c) Dmitry Torokhov <dtor@mail.ru> */ /* * 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/errno.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/input.h> #include <linux/serio.h> #include <linux/init.h> #define DRIVER_DESC "Fujitsu serial touchscreen driver" MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>"); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); #define FUJITSU_LENGTH 5 /* * Per-touchscreen data. */ struct fujitsu { struct input_dev *dev; struct serio *serio; int idx; unsigned char data[FUJITSU_LENGTH]; char phys[32]; }; /* * Decode serial data (5 bytes per packet) * First byte * 1 C 0 0 R S S S * Where C is 1 while in calibration mode (which we don't use) * R is 1 when no coordinate corection was done. * S are button state */ static irqreturn_t fujitsu_interrupt(struct serio *serio, unsigned char data, unsigned int flags) { struct fujitsu *fujitsu = serio_get_drvdata(serio); struct input_dev *dev = fujitsu->dev; if (fujitsu->idx == 0) { /* resync skip until start of frame */ if ((data & 0xf0) != 0x80) return IRQ_HANDLED; } else { /* resync skip garbage */ if (data & 0x80) { fujitsu->idx = 0; return IRQ_HANDLED; } } fujitsu->data[fujitsu->idx++] = data; if (fujitsu->idx == FUJITSU_LENGTH) { input_report_abs(dev, ABS_X, (fujitsu->data[2] << 7) | fujitsu->data[1]); input_report_abs(dev, ABS_Y, (fujitsu->data[4] << 7) | fujitsu->data[3]); input_report_key(dev, BTN_TOUCH, (fujitsu->data[0] & 0x03) != 2); input_sync(dev); fujitsu->idx = 0; } return IRQ_HANDLED; } /* * fujitsu_disconnect() is the opposite of fujitsu_connect() */ static void fujitsu_disconnect(struct serio *serio) { struct fujitsu *fujitsu = serio_get_drvdata(serio); input_get_device(fujitsu->dev); input_unregister_device(fujitsu->dev); serio_close(serio); serio_set_drvdata(serio, NULL); input_put_device(fujitsu->dev); kfree(fujitsu); } /* * fujitsu_connect() is the routine that is called when someone adds a * new serio device that supports the Fujitsu protocol and registers it * as input device. */ static int fujitsu_connect(struct serio *serio, struct serio_driver *drv) { struct fujitsu *fujitsu; struct input_dev *input_dev; int err; fujitsu = kzalloc(sizeof(struct fujitsu), GFP_KERNEL); input_dev = input_allocate_device(); if (!fujitsu || !input_dev) { err = -ENOMEM; goto fail1; } fujitsu->serio = serio; fujitsu->dev = input_dev; snprintf(fujitsu->phys, sizeof(fujitsu->phys), "%s/input0", serio->phys); input_dev->name = "Fujitsu Serial Touchscreen"; input_dev->phys = fujitsu->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_FUJITSU; input_dev->id.product = 0; input_dev->id.version = 0x0100; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); input_set_abs_params(input_dev, ABS_X, 0, 4096, 0, 0); input_set_abs_params(input_dev, ABS_Y, 0, 4096, 0, 0); serio_set_drvdata(serio, fujitsu); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(fujitsu->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(fujitsu); return err; } /* * The serio driver structure. */ static struct serio_device_id fujitsu_serio_ids[] = { { .type = SERIO_RS232, .proto = SERIO_FUJITSU, .id = SERIO_ANY, .extra = SERIO_ANY, }, { 0 } }; MODULE_DEVICE_TABLE(serio, fujitsu_serio_ids); static struct serio_driver fujitsu_drv = { .driver = { .name = "fujitsu_ts", }, .description = DRIVER_DESC, .id_table = fujitsu_serio_ids, .interrupt = fujitsu_interrupt, .connect = fujitsu_connect, .disconnect = fujitsu_disconnect, }; static int __init fujitsu_init(void) { return serio_register_driver(&fujitsu_drv); } static void __exit fujitsu_exit(void) { serio_unregister_driver(&fujitsu_drv); } module_init(fujitsu_init); module_exit(fujitsu_exit);
gpl-2.0
CyanideL/android_kernel_htc_msm8974
drivers/input/touchscreen/touchwin.c
9921
4399
/* * Touchwindow serial touchscreen driver * * Copyright (c) 2006 Rick Koch <n1gp@hotmail.com> * * Based on MicroTouch driver (drivers/input/touchscreen/mtouch.c) * Copyright (c) 2004 Vojtech Pavlik * and Dan Streetman <ddstreet@ieee.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. */ /* * 2005/02/19 Rick Koch: * The Touchwindow I used is made by Edmark Corp. and * constantly outputs a stream of 0's unless it is touched. * It then outputs 3 bytes: X, Y, and a copy of Y. */ #include <linux/errno.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/input.h> #include <linux/serio.h> #include <linux/init.h> #define DRIVER_DESC "Touchwindow serial touchscreen driver" MODULE_AUTHOR("Rick Koch <n1gp@hotmail.com>"); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); /* * Definitions & global arrays. */ #define TW_LENGTH 3 #define TW_MIN_XC 0 #define TW_MAX_XC 0xff #define TW_MIN_YC 0 #define TW_MAX_YC 0xff /* * Per-touchscreen data. */ struct tw { struct input_dev *dev; struct serio *serio; int idx; int touched; unsigned char data[TW_LENGTH]; char phys[32]; }; static irqreturn_t tw_interrupt(struct serio *serio, unsigned char data, unsigned int flags) { struct tw *tw = serio_get_drvdata(serio); struct input_dev *dev = tw->dev; if (data) { /* touch */ tw->touched = 1; tw->data[tw->idx++] = data; /* verify length and that the two Y's are the same */ if (tw->idx == TW_LENGTH && tw->data[1] == tw->data[2]) { input_report_abs(dev, ABS_X, tw->data[0]); input_report_abs(dev, ABS_Y, tw->data[1]); input_report_key(dev, BTN_TOUCH, 1); input_sync(dev); tw->idx = 0; } } else if (tw->touched) { /* untouch */ input_report_key(dev, BTN_TOUCH, 0); input_sync(dev); tw->idx = 0; tw->touched = 0; } return IRQ_HANDLED; } /* * tw_disconnect() is the opposite of tw_connect() */ static void tw_disconnect(struct serio *serio) { struct tw *tw = serio_get_drvdata(serio); input_get_device(tw->dev); input_unregister_device(tw->dev); serio_close(serio); serio_set_drvdata(serio, NULL); input_put_device(tw->dev); kfree(tw); } /* * tw_connect() is the routine that is called when someone adds a * new serio device that supports the Touchwin protocol and registers it as * an input device. */ static int tw_connect(struct serio *serio, struct serio_driver *drv) { struct tw *tw; struct input_dev *input_dev; int err; tw = kzalloc(sizeof(struct tw), GFP_KERNEL); input_dev = input_allocate_device(); if (!tw || !input_dev) { err = -ENOMEM; goto fail1; } tw->serio = serio; tw->dev = input_dev; snprintf(tw->phys, sizeof(tw->phys), "%s/input0", serio->phys); input_dev->name = "Touchwindow Serial TouchScreen"; input_dev->phys = tw->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_TOUCHWIN; input_dev->id.product = 0; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); input_set_abs_params(tw->dev, ABS_X, TW_MIN_XC, TW_MAX_XC, 0, 0); input_set_abs_params(tw->dev, ABS_Y, TW_MIN_YC, TW_MAX_YC, 0, 0); serio_set_drvdata(serio, tw); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(tw->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(tw); return err; } /* * The serio driver structure. */ static struct serio_device_id tw_serio_ids[] = { { .type = SERIO_RS232, .proto = SERIO_TOUCHWIN, .id = SERIO_ANY, .extra = SERIO_ANY, }, { 0 } }; MODULE_DEVICE_TABLE(serio, tw_serio_ids); static struct serio_driver tw_drv = { .driver = { .name = "touchwin", }, .description = DRIVER_DESC, .id_table = tw_serio_ids, .interrupt = tw_interrupt, .connect = tw_connect, .disconnect = tw_disconnect, }; /* * The functions for inserting/removing us as a module. */ static int __init tw_init(void) { return serio_register_driver(&tw_drv); } static void __exit tw_exit(void) { serio_unregister_driver(&tw_drv); } module_init(tw_init); module_exit(tw_exit);
gpl-2.0
EPDCenter/android_kernel_odys_genio
drivers/video/console/font_8x16.c
14785
95976
/**********************************************/ /* */ /* Font file generated by cpi2fnt */ /* */ /**********************************************/ #include <linux/font.h> #include <linux/module.h> #define FONTDATAMAX 4096 static const unsigned char fontdata_8x16[FONTDATAMAX] = { /* 0 0x00 '^@' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 1 0x01 '^A' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x81, /* 10000001 */ 0xa5, /* 10100101 */ 0x81, /* 10000001 */ 0x81, /* 10000001 */ 0xbd, /* 10111101 */ 0x99, /* 10011001 */ 0x81, /* 10000001 */ 0x81, /* 10000001 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 2 0x02 '^B' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0xff, /* 11111111 */ 0xdb, /* 11011011 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xc3, /* 11000011 */ 0xe7, /* 11100111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 3 0x03 '^C' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x6c, /* 01101100 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0x7c, /* 01111100 */ 0x38, /* 00111000 */ 0x10, /* 00010000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 4 0x04 '^D' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x7c, /* 01111100 */ 0xfe, /* 11111110 */ 0x7c, /* 01111100 */ 0x38, /* 00111000 */ 0x10, /* 00010000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 5 0x05 '^E' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0xe7, /* 11100111 */ 0xe7, /* 11100111 */ 0xe7, /* 11100111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 6 0x06 '^F' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x7e, /* 01111110 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 7 0x07 '^G' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 8 0x08 '^H' */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xe7, /* 11100111 */ 0xc3, /* 11000011 */ 0xc3, /* 11000011 */ 0xe7, /* 11100111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ /* 9 0x09 '^I' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x42, /* 01000010 */ 0x42, /* 01000010 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 10 0x0a '^J' */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xc3, /* 11000011 */ 0x99, /* 10011001 */ 0xbd, /* 10111101 */ 0xbd, /* 10111101 */ 0x99, /* 10011001 */ 0xc3, /* 11000011 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ /* 11 0x0b '^K' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1e, /* 00011110 */ 0x0e, /* 00001110 */ 0x1a, /* 00011010 */ 0x32, /* 00110010 */ 0x78, /* 01111000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 12 0x0c '^L' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 13 0x0d '^M' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3f, /* 00111111 */ 0x33, /* 00110011 */ 0x3f, /* 00111111 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x70, /* 01110000 */ 0xf0, /* 11110000 */ 0xe0, /* 11100000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 14 0x0e '^N' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7f, /* 01111111 */ 0x63, /* 01100011 */ 0x7f, /* 01111111 */ 0x63, /* 01100011 */ 0x63, /* 01100011 */ 0x63, /* 01100011 */ 0x63, /* 01100011 */ 0x67, /* 01100111 */ 0xe7, /* 11100111 */ 0xe6, /* 11100110 */ 0xc0, /* 11000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 15 0x0f '^O' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xdb, /* 11011011 */ 0x3c, /* 00111100 */ 0xe7, /* 11100111 */ 0x3c, /* 00111100 */ 0xdb, /* 11011011 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 16 0x10 '^P' */ 0x00, /* 00000000 */ 0x80, /* 10000000 */ 0xc0, /* 11000000 */ 0xe0, /* 11100000 */ 0xf0, /* 11110000 */ 0xf8, /* 11111000 */ 0xfe, /* 11111110 */ 0xf8, /* 11111000 */ 0xf0, /* 11110000 */ 0xe0, /* 11100000 */ 0xc0, /* 11000000 */ 0x80, /* 10000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 17 0x11 '^Q' */ 0x00, /* 00000000 */ 0x02, /* 00000010 */ 0x06, /* 00000110 */ 0x0e, /* 00001110 */ 0x1e, /* 00011110 */ 0x3e, /* 00111110 */ 0xfe, /* 11111110 */ 0x3e, /* 00111110 */ 0x1e, /* 00011110 */ 0x0e, /* 00001110 */ 0x06, /* 00000110 */ 0x02, /* 00000010 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 18 0x12 '^R' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 19 0x13 '^S' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 20 0x14 '^T' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7f, /* 01111111 */ 0xdb, /* 11011011 */ 0xdb, /* 11011011 */ 0xdb, /* 11011011 */ 0x7b, /* 01111011 */ 0x1b, /* 00011011 */ 0x1b, /* 00011011 */ 0x1b, /* 00011011 */ 0x1b, /* 00011011 */ 0x1b, /* 00011011 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 21 0x15 '^U' */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0x60, /* 01100000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x0c, /* 00001100 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 22 0x16 '^V' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 23 0x17 '^W' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 24 0x18 '^X' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 25 0x19 '^Y' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 26 0x1a '^Z' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0xfe, /* 11111110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 27 0x1b '^[' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xfe, /* 11111110 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 28 0x1c '^\' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 29 0x1d '^]' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x28, /* 00101000 */ 0x6c, /* 01101100 */ 0xfe, /* 11111110 */ 0x6c, /* 01101100 */ 0x28, /* 00101000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 30 0x1e '^^' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x38, /* 00111000 */ 0x7c, /* 01111100 */ 0x7c, /* 01111100 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 31 0x1f '^_' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0x7c, /* 01111100 */ 0x7c, /* 01111100 */ 0x38, /* 00111000 */ 0x38, /* 00111000 */ 0x10, /* 00010000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 32 0x20 ' ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 33 0x21 '!' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 34 0x22 '"' */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x24, /* 00100100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 35 0x23 '#' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0xfe, /* 11111110 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0xfe, /* 11111110 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 36 0x24 '$' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc2, /* 11000010 */ 0xc0, /* 11000000 */ 0x7c, /* 01111100 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x86, /* 10000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 37 0x25 '%' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc2, /* 11000010 */ 0xc6, /* 11000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc6, /* 11000110 */ 0x86, /* 10000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 38 0x26 '&' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 39 0x27 ''' */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 40 0x28 '(' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 41 0x29 ')' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 42 0x2a '*' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0xff, /* 11111111 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 43 0x2b '+' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 44 0x2c ',' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 45 0x2d '-' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 46 0x2e '.' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 47 0x2f '/' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x02, /* 00000010 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0x80, /* 10000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 48 0x30 '0' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 49 0x31 '1' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x38, /* 00111000 */ 0x78, /* 01111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 50 0x32 '2' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 51 0x33 '3' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x3c, /* 00111100 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 52 0x34 '4' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x0c, /* 00001100 */ 0x1c, /* 00011100 */ 0x3c, /* 00111100 */ 0x6c, /* 01101100 */ 0xcc, /* 11001100 */ 0xfe, /* 11111110 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x1e, /* 00011110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 53 0x35 '5' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xfc, /* 11111100 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 54 0x36 '6' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xfc, /* 11111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 55 0x37 '7' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 56 0x38 '8' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 57 0x39 '9' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7e, /* 01111110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 58 0x3a ':' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 59 0x3b ';' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 60 0x3c '<' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x06, /* 00000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 61 0x3d '=' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 62 0x3e '>' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 63 0x3f '?' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 64 0x40 '@' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xde, /* 11011110 */ 0xde, /* 11011110 */ 0xde, /* 11011110 */ 0xdc, /* 11011100 */ 0xc0, /* 11000000 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 65 0x41 'A' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 66 0x42 'B' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfc, /* 11111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0xfc, /* 11111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 67 0x43 'C' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0xc2, /* 11000010 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc2, /* 11000010 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 68 0x44 'D' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xf8, /* 11111000 */ 0x6c, /* 01101100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x6c, /* 01101100 */ 0xf8, /* 11111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 69 0x45 'E' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x66, /* 01100110 */ 0x62, /* 01100010 */ 0x68, /* 01101000 */ 0x78, /* 01111000 */ 0x68, /* 01101000 */ 0x60, /* 01100000 */ 0x62, /* 01100010 */ 0x66, /* 01100110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 70 0x46 'F' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x66, /* 01100110 */ 0x62, /* 01100010 */ 0x68, /* 01101000 */ 0x78, /* 01111000 */ 0x68, /* 01101000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xf0, /* 11110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 71 0x47 'G' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0xc2, /* 11000010 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xde, /* 11011110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x66, /* 01100110 */ 0x3a, /* 00111010 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 72 0x48 'H' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 73 0x49 'I' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 74 0x4a 'J' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1e, /* 00011110 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 75 0x4b 'K' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xe6, /* 11100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x6c, /* 01101100 */ 0x78, /* 01111000 */ 0x78, /* 01111000 */ 0x6c, /* 01101100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0xe6, /* 11100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 76 0x4c 'L' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xf0, /* 11110000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x62, /* 01100010 */ 0x66, /* 01100110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 77 0x4d 'M' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xee, /* 11101110 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0xd6, /* 11010110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 78 0x4e 'N' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xe6, /* 11100110 */ 0xf6, /* 11110110 */ 0xfe, /* 11111110 */ 0xde, /* 11011110 */ 0xce, /* 11001110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 79 0x4f 'O' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 80 0x50 'P' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfc, /* 11111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xf0, /* 11110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 81 0x51 'Q' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xd6, /* 11010110 */ 0xde, /* 11011110 */ 0x7c, /* 01111100 */ 0x0c, /* 00001100 */ 0x0e, /* 00001110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 82 0x52 'R' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfc, /* 11111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x6c, /* 01101100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0xe6, /* 11100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 83 0x53 'S' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x60, /* 01100000 */ 0x38, /* 00111000 */ 0x0c, /* 00001100 */ 0x06, /* 00000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 84 0x54 'T' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x5a, /* 01011010 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 85 0x55 'U' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 86 0x56 'V' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x10, /* 00010000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 87 0x57 'W' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xfe, /* 11111110 */ 0xee, /* 11101110 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 88 0x58 'X' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x7c, /* 01111100 */ 0x38, /* 00111000 */ 0x38, /* 00111000 */ 0x7c, /* 01111100 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 89 0x59 'Y' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 90 0x5a 'Z' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0x86, /* 10000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc2, /* 11000010 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 91 0x5b '[' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 92 0x5c '\' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x80, /* 10000000 */ 0xc0, /* 11000000 */ 0xe0, /* 11100000 */ 0x70, /* 01110000 */ 0x38, /* 00111000 */ 0x1c, /* 00011100 */ 0x0e, /* 00001110 */ 0x06, /* 00000110 */ 0x02, /* 00000010 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 93 0x5d ']' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 94 0x5e '^' */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 95 0x5f '_' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 96 0x60 '`' */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 97 0x61 'a' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 98 0x62 'b' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xe0, /* 11100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x78, /* 01111000 */ 0x6c, /* 01101100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 99 0x63 'c' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 100 0x64 'd' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1c, /* 00011100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x3c, /* 00111100 */ 0x6c, /* 01101100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 101 0x65 'e' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 102 0x66 'f' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1c, /* 00011100 */ 0x36, /* 00110110 */ 0x32, /* 00110010 */ 0x30, /* 00110000 */ 0x78, /* 01111000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 103 0x67 'g' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x7c, /* 01111100 */ 0x0c, /* 00001100 */ 0xcc, /* 11001100 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ /* 104 0x68 'h' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xe0, /* 11100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x6c, /* 01101100 */ 0x76, /* 01110110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0xe6, /* 11100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 105 0x69 'i' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 106 0x6a 'j' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x00, /* 00000000 */ 0x0e, /* 00001110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ /* 107 0x6b 'k' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xe0, /* 11100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x66, /* 01100110 */ 0x6c, /* 01101100 */ 0x78, /* 01111000 */ 0x78, /* 01111000 */ 0x6c, /* 01101100 */ 0x66, /* 01100110 */ 0xe6, /* 11100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 108 0x6c 'l' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 109 0x6d 'm' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xec, /* 11101100 */ 0xfe, /* 11111110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 110 0x6e 'n' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xdc, /* 11011100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 111 0x6f 'o' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 112 0x70 'p' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xdc, /* 11011100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xf0, /* 11110000 */ 0x00, /* 00000000 */ /* 113 0x71 'q' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x7c, /* 01111100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x1e, /* 00011110 */ 0x00, /* 00000000 */ /* 114 0x72 'r' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xdc, /* 11011100 */ 0x76, /* 01110110 */ 0x66, /* 01100110 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xf0, /* 11110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 115 0x73 's' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0x60, /* 01100000 */ 0x38, /* 00111000 */ 0x0c, /* 00001100 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 116 0x74 't' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0xfc, /* 11111100 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x36, /* 00110110 */ 0x1c, /* 00011100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 117 0x75 'u' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 118 0x76 'v' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 119 0x77 'w' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xfe, /* 11111110 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 120 0x78 'x' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x38, /* 00111000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 121 0x79 'y' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7e, /* 01111110 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0xf8, /* 11111000 */ 0x00, /* 00000000 */ /* 122 0x7a 'z' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xcc, /* 11001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 123 0x7b '{' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x0e, /* 00001110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x70, /* 01110000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x0e, /* 00001110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 124 0x7c '|' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 125 0x7d '}' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x70, /* 01110000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x0e, /* 00001110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 126 0x7e '~' */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 127 0x7f '' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 128 0x80 '€' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0xc2, /* 11000010 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc2, /* 11000010 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 129 0x81 '' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 130 0x82 '‚' */ 0x00, /* 00000000 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 131 0x83 'ƒ' */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 132 0x84 '„' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 133 0x85 '…' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 134 0x86 '†' */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 135 0x87 '‡' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x18, /* 00011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 136 0x88 'ˆ' */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 137 0x89 '‰' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 138 0x8a 'Š' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 139 0x8b '‹' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 140 0x8c 'Œ' */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 141 0x8d '' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 142 0x8e 'Ž' */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 143 0x8f '' */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 144 0x90 '' */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x66, /* 01100110 */ 0x62, /* 01100010 */ 0x68, /* 01101000 */ 0x78, /* 01111000 */ 0x68, /* 01101000 */ 0x62, /* 01100010 */ 0x66, /* 01100110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 145 0x91 '‘' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xec, /* 11101100 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x7e, /* 01111110 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0x6e, /* 01101110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 146 0x92 '’' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3e, /* 00111110 */ 0x6c, /* 01101100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xfe, /* 11111110 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xce, /* 11001110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 147 0x93 '“' */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 148 0x94 '”' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 149 0x95 '•' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 150 0x96 '–' */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x78, /* 01111000 */ 0xcc, /* 11001100 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 151 0x97 '—' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 152 0x98 '˜' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7e, /* 01111110 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ /* 153 0x99 '™' */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 154 0x9a 'š' */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 155 0x9b '›' */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 156 0x9c 'œ' */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x64, /* 01100100 */ 0x60, /* 01100000 */ 0xf0, /* 11110000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xe6, /* 11100110 */ 0xfc, /* 11111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 157 0x9d '' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 158 0x9e 'ž' */ 0x00, /* 00000000 */ 0xf8, /* 11111000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xf8, /* 11111000 */ 0xc4, /* 11000100 */ 0xcc, /* 11001100 */ 0xde, /* 11011110 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 159 0x9f 'Ÿ' */ 0x00, /* 00000000 */ 0x0e, /* 00001110 */ 0x1b, /* 00011011 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xd8, /* 11011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 160 0xa0 ' ' */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 161 0xa1 '¡' */ 0x00, /* 00000000 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 162 0xa2 '¢' */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 163 0xa3 '£' */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 164 0xa4 '¤' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x00, /* 00000000 */ 0xdc, /* 11011100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 165 0xa5 '¥' */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xe6, /* 11100110 */ 0xf6, /* 11110110 */ 0xfe, /* 11111110 */ 0xde, /* 11011110 */ 0xce, /* 11001110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 166 0xa6 '¦' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x3e, /* 00111110 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 167 0xa7 '§' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 168 0xa8 '¨' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 169 0xa9 '©' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 170 0xaa 'ª' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 171 0xab '«' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0xe0, /* 11100000 */ 0x62, /* 01100010 */ 0x66, /* 01100110 */ 0x6c, /* 01101100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xdc, /* 11011100 */ 0x86, /* 10000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x3e, /* 00111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 172 0xac '¬' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0xe0, /* 11100000 */ 0x62, /* 01100010 */ 0x66, /* 01100110 */ 0x6c, /* 01101100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x66, /* 01100110 */ 0xce, /* 11001110 */ 0x9a, /* 10011010 */ 0x3f, /* 00111111 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 173 0xad '­' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 174 0xae '®' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x36, /* 00110110 */ 0x6c, /* 01101100 */ 0xd8, /* 11011000 */ 0x6c, /* 01101100 */ 0x36, /* 00110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 175 0xaf '¯' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xd8, /* 11011000 */ 0x6c, /* 01101100 */ 0x36, /* 00110110 */ 0x6c, /* 01101100 */ 0xd8, /* 11011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 176 0xb0 '°' */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ /* 177 0xb1 '±' */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ /* 178 0xb2 '²' */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ /* 179 0xb3 '³' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 180 0xb4 '´' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 181 0xb5 'µ' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 182 0xb6 '¶' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xf6, /* 11110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 183 0xb7 '·' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 184 0xb8 '¸' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 185 0xb9 '¹' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xf6, /* 11110110 */ 0x06, /* 00000110 */ 0xf6, /* 11110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 186 0xba 'º' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 187 0xbb '»' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x06, /* 00000110 */ 0xf6, /* 11110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 188 0xbc '¼' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xf6, /* 11110110 */ 0x06, /* 00000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 189 0xbd '½' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 190 0xbe '¾' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 191 0xbf '¿' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 192 0xc0 'À' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 193 0xc1 'Á' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 194 0xc2 'Â' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 195 0xc3 'Ã' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 196 0xc4 'Ä' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 197 0xc5 'Å' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xff, /* 11111111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 198 0xc6 'Æ' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 199 0xc7 'Ç' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x37, /* 00110111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 200 0xc8 'È' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x37, /* 00110111 */ 0x30, /* 00110000 */ 0x3f, /* 00111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 201 0xc9 'É' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3f, /* 00111111 */ 0x30, /* 00110000 */ 0x37, /* 00110111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 202 0xca 'Ê' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xf7, /* 11110111 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 203 0xcb 'Ë' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0xf7, /* 11110111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 204 0xcc 'Ì' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x37, /* 00110111 */ 0x30, /* 00110000 */ 0x37, /* 00110111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 205 0xcd 'Í' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 206 0xce 'Î' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xf7, /* 11110111 */ 0x00, /* 00000000 */ 0xf7, /* 11110111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 207 0xcf 'Ï' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 208 0xd0 'Ð' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 209 0xd1 'Ñ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 210 0xd2 'Ò' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 211 0xd3 'Ó' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x3f, /* 00111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 212 0xd4 'Ô' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 213 0xd5 'Õ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 214 0xd6 'Ö' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3f, /* 00111111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 215 0xd7 '×' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xff, /* 11111111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 216 0xd8 'Ø' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xff, /* 11111111 */ 0x18, /* 00011000 */ 0xff, /* 11111111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 217 0xd9 'Ù' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 218 0xda 'Ú' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 219 0xdb 'Û' */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ /* 220 0xdc 'Ü' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ /* 221 0xdd 'Ý' */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ /* 222 0xde 'Þ' */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ /* 223 0xdf 'ß' */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 224 0xe0 'à' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xdc, /* 11011100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 225 0xe1 'á' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xd8, /* 11011000 */ 0xcc, /* 11001100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xcc, /* 11001100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 226 0xe2 'â' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 227 0xe3 'ã' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 228 0xe4 'ä' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 229 0xe5 'å' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 230 0xe6 'æ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0x00, /* 00000000 */ /* 231 0xe7 'ç' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 232 0xe8 'è' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 233 0xe9 'é' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 234 0xea 'ê' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0xee, /* 11101110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 235 0xeb 'ë' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1e, /* 00011110 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x3e, /* 00111110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 236 0xec 'ì' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0xdb, /* 11011011 */ 0xdb, /* 11011011 */ 0xdb, /* 11011011 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 237 0xed 'í' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x03, /* 00000011 */ 0x06, /* 00000110 */ 0x7e, /* 01111110 */ 0xdb, /* 11011011 */ 0xdb, /* 11011011 */ 0xf3, /* 11110011 */ 0x7e, /* 01111110 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 238 0xee 'î' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1c, /* 00011100 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x7c, /* 01111100 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x1c, /* 00011100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 239 0xef 'ï' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 240 0xf0 'ð' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 241 0xf1 'ñ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 242 0xf2 'ò' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 243 0xf3 'ó' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 244 0xf4 'ô' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x0e, /* 00001110 */ 0x1b, /* 00011011 */ 0x1b, /* 00011011 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 245 0xf5 'õ' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 246 0xf6 'ö' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 247 0xf7 '÷' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 248 0xf8 'ø' */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 249 0xf9 'ù' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 250 0xfa 'ú' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 251 0xfb 'û' */ 0x00, /* 00000000 */ 0x0f, /* 00001111 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0xec, /* 11101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x3c, /* 00111100 */ 0x1c, /* 00011100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 252 0xfc 'ü' */ 0x00, /* 00000000 */ 0x6c, /* 01101100 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 253 0xfd 'ý' */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x32, /* 00110010 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 254 0xfe 'þ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 255 0xff 'ÿ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ }; const struct font_desc font_vga_8x16 = { .idx = VGA8x16_IDX, .name = "VGA8x16", .width = 8, .height = 16, .data = fontdata_8x16, .pref = 0, }; EXPORT_SYMBOL(font_vga_8x16);
gpl-2.0
alexey6600/kernel_sony_tetra_2
drivers/video/console/font_8x16.c
14785
95976
/**********************************************/ /* */ /* Font file generated by cpi2fnt */ /* */ /**********************************************/ #include <linux/font.h> #include <linux/module.h> #define FONTDATAMAX 4096 static const unsigned char fontdata_8x16[FONTDATAMAX] = { /* 0 0x00 '^@' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 1 0x01 '^A' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x81, /* 10000001 */ 0xa5, /* 10100101 */ 0x81, /* 10000001 */ 0x81, /* 10000001 */ 0xbd, /* 10111101 */ 0x99, /* 10011001 */ 0x81, /* 10000001 */ 0x81, /* 10000001 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 2 0x02 '^B' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0xff, /* 11111111 */ 0xdb, /* 11011011 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xc3, /* 11000011 */ 0xe7, /* 11100111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 3 0x03 '^C' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x6c, /* 01101100 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0x7c, /* 01111100 */ 0x38, /* 00111000 */ 0x10, /* 00010000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 4 0x04 '^D' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x7c, /* 01111100 */ 0xfe, /* 11111110 */ 0x7c, /* 01111100 */ 0x38, /* 00111000 */ 0x10, /* 00010000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 5 0x05 '^E' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0xe7, /* 11100111 */ 0xe7, /* 11100111 */ 0xe7, /* 11100111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 6 0x06 '^F' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x7e, /* 01111110 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 7 0x07 '^G' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 8 0x08 '^H' */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xe7, /* 11100111 */ 0xc3, /* 11000011 */ 0xc3, /* 11000011 */ 0xe7, /* 11100111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ /* 9 0x09 '^I' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x42, /* 01000010 */ 0x42, /* 01000010 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 10 0x0a '^J' */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xc3, /* 11000011 */ 0x99, /* 10011001 */ 0xbd, /* 10111101 */ 0xbd, /* 10111101 */ 0x99, /* 10011001 */ 0xc3, /* 11000011 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ /* 11 0x0b '^K' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1e, /* 00011110 */ 0x0e, /* 00001110 */ 0x1a, /* 00011010 */ 0x32, /* 00110010 */ 0x78, /* 01111000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 12 0x0c '^L' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 13 0x0d '^M' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3f, /* 00111111 */ 0x33, /* 00110011 */ 0x3f, /* 00111111 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x70, /* 01110000 */ 0xf0, /* 11110000 */ 0xe0, /* 11100000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 14 0x0e '^N' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7f, /* 01111111 */ 0x63, /* 01100011 */ 0x7f, /* 01111111 */ 0x63, /* 01100011 */ 0x63, /* 01100011 */ 0x63, /* 01100011 */ 0x63, /* 01100011 */ 0x67, /* 01100111 */ 0xe7, /* 11100111 */ 0xe6, /* 11100110 */ 0xc0, /* 11000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 15 0x0f '^O' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xdb, /* 11011011 */ 0x3c, /* 00111100 */ 0xe7, /* 11100111 */ 0x3c, /* 00111100 */ 0xdb, /* 11011011 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 16 0x10 '^P' */ 0x00, /* 00000000 */ 0x80, /* 10000000 */ 0xc0, /* 11000000 */ 0xe0, /* 11100000 */ 0xf0, /* 11110000 */ 0xf8, /* 11111000 */ 0xfe, /* 11111110 */ 0xf8, /* 11111000 */ 0xf0, /* 11110000 */ 0xe0, /* 11100000 */ 0xc0, /* 11000000 */ 0x80, /* 10000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 17 0x11 '^Q' */ 0x00, /* 00000000 */ 0x02, /* 00000010 */ 0x06, /* 00000110 */ 0x0e, /* 00001110 */ 0x1e, /* 00011110 */ 0x3e, /* 00111110 */ 0xfe, /* 11111110 */ 0x3e, /* 00111110 */ 0x1e, /* 00011110 */ 0x0e, /* 00001110 */ 0x06, /* 00000110 */ 0x02, /* 00000010 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 18 0x12 '^R' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 19 0x13 '^S' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 20 0x14 '^T' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7f, /* 01111111 */ 0xdb, /* 11011011 */ 0xdb, /* 11011011 */ 0xdb, /* 11011011 */ 0x7b, /* 01111011 */ 0x1b, /* 00011011 */ 0x1b, /* 00011011 */ 0x1b, /* 00011011 */ 0x1b, /* 00011011 */ 0x1b, /* 00011011 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 21 0x15 '^U' */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0x60, /* 01100000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x0c, /* 00001100 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 22 0x16 '^V' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 23 0x17 '^W' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 24 0x18 '^X' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 25 0x19 '^Y' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 26 0x1a '^Z' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0xfe, /* 11111110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 27 0x1b '^[' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xfe, /* 11111110 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 28 0x1c '^\' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 29 0x1d '^]' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x28, /* 00101000 */ 0x6c, /* 01101100 */ 0xfe, /* 11111110 */ 0x6c, /* 01101100 */ 0x28, /* 00101000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 30 0x1e '^^' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x38, /* 00111000 */ 0x7c, /* 01111100 */ 0x7c, /* 01111100 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 31 0x1f '^_' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0x7c, /* 01111100 */ 0x7c, /* 01111100 */ 0x38, /* 00111000 */ 0x38, /* 00111000 */ 0x10, /* 00010000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 32 0x20 ' ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 33 0x21 '!' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 34 0x22 '"' */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x24, /* 00100100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 35 0x23 '#' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0xfe, /* 11111110 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0xfe, /* 11111110 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 36 0x24 '$' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc2, /* 11000010 */ 0xc0, /* 11000000 */ 0x7c, /* 01111100 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x86, /* 10000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 37 0x25 '%' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc2, /* 11000010 */ 0xc6, /* 11000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc6, /* 11000110 */ 0x86, /* 10000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 38 0x26 '&' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 39 0x27 ''' */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 40 0x28 '(' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 41 0x29 ')' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 42 0x2a '*' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0xff, /* 11111111 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 43 0x2b '+' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 44 0x2c ',' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 45 0x2d '-' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 46 0x2e '.' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 47 0x2f '/' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x02, /* 00000010 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0x80, /* 10000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 48 0x30 '0' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 49 0x31 '1' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x38, /* 00111000 */ 0x78, /* 01111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 50 0x32 '2' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 51 0x33 '3' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x3c, /* 00111100 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 52 0x34 '4' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x0c, /* 00001100 */ 0x1c, /* 00011100 */ 0x3c, /* 00111100 */ 0x6c, /* 01101100 */ 0xcc, /* 11001100 */ 0xfe, /* 11111110 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x1e, /* 00011110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 53 0x35 '5' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xfc, /* 11111100 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 54 0x36 '6' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xfc, /* 11111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 55 0x37 '7' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 56 0x38 '8' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 57 0x39 '9' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7e, /* 01111110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 58 0x3a ':' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 59 0x3b ';' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 60 0x3c '<' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x06, /* 00000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 61 0x3d '=' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 62 0x3e '>' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 63 0x3f '?' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 64 0x40 '@' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xde, /* 11011110 */ 0xde, /* 11011110 */ 0xde, /* 11011110 */ 0xdc, /* 11011100 */ 0xc0, /* 11000000 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 65 0x41 'A' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 66 0x42 'B' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfc, /* 11111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0xfc, /* 11111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 67 0x43 'C' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0xc2, /* 11000010 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc2, /* 11000010 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 68 0x44 'D' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xf8, /* 11111000 */ 0x6c, /* 01101100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x6c, /* 01101100 */ 0xf8, /* 11111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 69 0x45 'E' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x66, /* 01100110 */ 0x62, /* 01100010 */ 0x68, /* 01101000 */ 0x78, /* 01111000 */ 0x68, /* 01101000 */ 0x60, /* 01100000 */ 0x62, /* 01100010 */ 0x66, /* 01100110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 70 0x46 'F' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x66, /* 01100110 */ 0x62, /* 01100010 */ 0x68, /* 01101000 */ 0x78, /* 01111000 */ 0x68, /* 01101000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xf0, /* 11110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 71 0x47 'G' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0xc2, /* 11000010 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xde, /* 11011110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x66, /* 01100110 */ 0x3a, /* 00111010 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 72 0x48 'H' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 73 0x49 'I' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 74 0x4a 'J' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1e, /* 00011110 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 75 0x4b 'K' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xe6, /* 11100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x6c, /* 01101100 */ 0x78, /* 01111000 */ 0x78, /* 01111000 */ 0x6c, /* 01101100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0xe6, /* 11100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 76 0x4c 'L' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xf0, /* 11110000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x62, /* 01100010 */ 0x66, /* 01100110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 77 0x4d 'M' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xee, /* 11101110 */ 0xfe, /* 11111110 */ 0xfe, /* 11111110 */ 0xd6, /* 11010110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 78 0x4e 'N' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xe6, /* 11100110 */ 0xf6, /* 11110110 */ 0xfe, /* 11111110 */ 0xde, /* 11011110 */ 0xce, /* 11001110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 79 0x4f 'O' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 80 0x50 'P' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfc, /* 11111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xf0, /* 11110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 81 0x51 'Q' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xd6, /* 11010110 */ 0xde, /* 11011110 */ 0x7c, /* 01111100 */ 0x0c, /* 00001100 */ 0x0e, /* 00001110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 82 0x52 'R' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfc, /* 11111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x6c, /* 01101100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0xe6, /* 11100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 83 0x53 'S' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x60, /* 01100000 */ 0x38, /* 00111000 */ 0x0c, /* 00001100 */ 0x06, /* 00000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 84 0x54 'T' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x5a, /* 01011010 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 85 0x55 'U' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 86 0x56 'V' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x10, /* 00010000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 87 0x57 'W' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xfe, /* 11111110 */ 0xee, /* 11101110 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 88 0x58 'X' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x7c, /* 01111100 */ 0x38, /* 00111000 */ 0x38, /* 00111000 */ 0x7c, /* 01111100 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 89 0x59 'Y' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 90 0x5a 'Z' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0x86, /* 10000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc2, /* 11000010 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 91 0x5b '[' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 92 0x5c '\' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x80, /* 10000000 */ 0xc0, /* 11000000 */ 0xe0, /* 11100000 */ 0x70, /* 01110000 */ 0x38, /* 00111000 */ 0x1c, /* 00011100 */ 0x0e, /* 00001110 */ 0x06, /* 00000110 */ 0x02, /* 00000010 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 93 0x5d ']' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 94 0x5e '^' */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 95 0x5f '_' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 96 0x60 '`' */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 97 0x61 'a' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 98 0x62 'b' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xe0, /* 11100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x78, /* 01111000 */ 0x6c, /* 01101100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 99 0x63 'c' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 100 0x64 'd' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1c, /* 00011100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x3c, /* 00111100 */ 0x6c, /* 01101100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 101 0x65 'e' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 102 0x66 'f' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1c, /* 00011100 */ 0x36, /* 00110110 */ 0x32, /* 00110010 */ 0x30, /* 00110000 */ 0x78, /* 01111000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 103 0x67 'g' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x7c, /* 01111100 */ 0x0c, /* 00001100 */ 0xcc, /* 11001100 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ /* 104 0x68 'h' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xe0, /* 11100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x6c, /* 01101100 */ 0x76, /* 01110110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0xe6, /* 11100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 105 0x69 'i' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 106 0x6a 'j' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x00, /* 00000000 */ 0x0e, /* 00001110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ /* 107 0x6b 'k' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xe0, /* 11100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x66, /* 01100110 */ 0x6c, /* 01101100 */ 0x78, /* 01111000 */ 0x78, /* 01111000 */ 0x6c, /* 01101100 */ 0x66, /* 01100110 */ 0xe6, /* 11100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 108 0x6c 'l' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 109 0x6d 'm' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xec, /* 11101100 */ 0xfe, /* 11111110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 110 0x6e 'n' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xdc, /* 11011100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 111 0x6f 'o' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 112 0x70 'p' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xdc, /* 11011100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xf0, /* 11110000 */ 0x00, /* 00000000 */ /* 113 0x71 'q' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x7c, /* 01111100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x1e, /* 00011110 */ 0x00, /* 00000000 */ /* 114 0x72 'r' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xdc, /* 11011100 */ 0x76, /* 01110110 */ 0x66, /* 01100110 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xf0, /* 11110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 115 0x73 's' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0x60, /* 01100000 */ 0x38, /* 00111000 */ 0x0c, /* 00001100 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 116 0x74 't' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0xfc, /* 11111100 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x36, /* 00110110 */ 0x1c, /* 00011100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 117 0x75 'u' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 118 0x76 'v' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 119 0x77 'w' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xd6, /* 11010110 */ 0xfe, /* 11111110 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 120 0x78 'x' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x38, /* 00111000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 121 0x79 'y' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7e, /* 01111110 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0xf8, /* 11111000 */ 0x00, /* 00000000 */ /* 122 0x7a 'z' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xcc, /* 11001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 123 0x7b '{' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x0e, /* 00001110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x70, /* 01110000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x0e, /* 00001110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 124 0x7c '|' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 125 0x7d '}' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x70, /* 01110000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x0e, /* 00001110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 126 0x7e '~' */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 127 0x7f '' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 128 0x80 '€' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0xc2, /* 11000010 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc2, /* 11000010 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 129 0x81 '' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 130 0x82 '‚' */ 0x00, /* 00000000 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 131 0x83 'ƒ' */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 132 0x84 '„' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 133 0x85 '…' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 134 0x86 '†' */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 135 0x87 '‡' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x18, /* 00011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 136 0x88 'ˆ' */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 137 0x89 '‰' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 138 0x8a 'Š' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 139 0x8b '‹' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 140 0x8c 'Œ' */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 141 0x8d '' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 142 0x8e 'Ž' */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 143 0x8f '' */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 144 0x90 '' */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x66, /* 01100110 */ 0x62, /* 01100010 */ 0x68, /* 01101000 */ 0x78, /* 01111000 */ 0x68, /* 01101000 */ 0x62, /* 01100010 */ 0x66, /* 01100110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 145 0x91 '‘' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xec, /* 11101100 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x7e, /* 01111110 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0x6e, /* 01101110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 146 0x92 '’' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3e, /* 00111110 */ 0x6c, /* 01101100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xfe, /* 11111110 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xce, /* 11001110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 147 0x93 '“' */ 0x00, /* 00000000 */ 0x10, /* 00010000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 148 0x94 '”' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 149 0x95 '•' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 150 0x96 '–' */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x78, /* 01111000 */ 0xcc, /* 11001100 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 151 0x97 '—' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 152 0x98 '˜' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7e, /* 01111110 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x78, /* 01111000 */ 0x00, /* 00000000 */ /* 153 0x99 '™' */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 154 0x9a 'š' */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 155 0x9b '›' */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 156 0x9c 'œ' */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x64, /* 01100100 */ 0x60, /* 01100000 */ 0xf0, /* 11110000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xe6, /* 11100110 */ 0xfc, /* 11111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 157 0x9d '' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 158 0x9e 'ž' */ 0x00, /* 00000000 */ 0xf8, /* 11111000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xf8, /* 11111000 */ 0xc4, /* 11000100 */ 0xcc, /* 11001100 */ 0xde, /* 11011110 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 159 0x9f 'Ÿ' */ 0x00, /* 00000000 */ 0x0e, /* 00001110 */ 0x1b, /* 00011011 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xd8, /* 11011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 160 0xa0 ' ' */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0x0c, /* 00001100 */ 0x7c, /* 01111100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 161 0xa1 '¡' */ 0x00, /* 00000000 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 162 0xa2 '¢' */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 163 0xa3 '£' */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x00, /* 00000000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 164 0xa4 '¤' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x00, /* 00000000 */ 0xdc, /* 11011100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 165 0xa5 '¥' */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x00, /* 00000000 */ 0xc6, /* 11000110 */ 0xe6, /* 11100110 */ 0xf6, /* 11110110 */ 0xfe, /* 11111110 */ 0xde, /* 11011110 */ 0xce, /* 11001110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 166 0xa6 '¦' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x3e, /* 00111110 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 167 0xa7 '§' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 168 0xa8 '¨' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x7c, /* 01111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 169 0xa9 '©' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 170 0xaa 'ª' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 171 0xab '«' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0xe0, /* 11100000 */ 0x62, /* 01100010 */ 0x66, /* 01100110 */ 0x6c, /* 01101100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xdc, /* 11011100 */ 0x86, /* 10000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x3e, /* 00111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 172 0xac '¬' */ 0x00, /* 00000000 */ 0x60, /* 01100000 */ 0xe0, /* 11100000 */ 0x62, /* 01100010 */ 0x66, /* 01100110 */ 0x6c, /* 01101100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x66, /* 01100110 */ 0xce, /* 11001110 */ 0x9a, /* 10011010 */ 0x3f, /* 00111111 */ 0x06, /* 00000110 */ 0x06, /* 00000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 173 0xad '­' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 174 0xae '®' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x36, /* 00110110 */ 0x6c, /* 01101100 */ 0xd8, /* 11011000 */ 0x6c, /* 01101100 */ 0x36, /* 00110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 175 0xaf '¯' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xd8, /* 11011000 */ 0x6c, /* 01101100 */ 0x36, /* 00110110 */ 0x6c, /* 01101100 */ 0xd8, /* 11011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 176 0xb0 '°' */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ 0x11, /* 00010001 */ 0x44, /* 01000100 */ /* 177 0xb1 '±' */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ 0x55, /* 01010101 */ 0xaa, /* 10101010 */ /* 178 0xb2 '²' */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ 0xdd, /* 11011101 */ 0x77, /* 01110111 */ /* 179 0xb3 '³' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 180 0xb4 '´' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 181 0xb5 'µ' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 182 0xb6 '¶' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xf6, /* 11110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 183 0xb7 '·' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 184 0xb8 '¸' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 185 0xb9 '¹' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xf6, /* 11110110 */ 0x06, /* 00000110 */ 0xf6, /* 11110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 186 0xba 'º' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 187 0xbb '»' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x06, /* 00000110 */ 0xf6, /* 11110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 188 0xbc '¼' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xf6, /* 11110110 */ 0x06, /* 00000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 189 0xbd '½' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 190 0xbe '¾' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 191 0xbf '¿' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xf8, /* 11111000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 192 0xc0 'À' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 193 0xc1 'Á' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 194 0xc2 'Â' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 195 0xc3 'Ã' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 196 0xc4 'Ä' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 197 0xc5 'Å' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xff, /* 11111111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 198 0xc6 'Æ' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 199 0xc7 'Ç' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x37, /* 00110111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 200 0xc8 'È' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x37, /* 00110111 */ 0x30, /* 00110000 */ 0x3f, /* 00111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 201 0xc9 'É' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3f, /* 00111111 */ 0x30, /* 00110000 */ 0x37, /* 00110111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 202 0xca 'Ê' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xf7, /* 11110111 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 203 0xcb 'Ë' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0xf7, /* 11110111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 204 0xcc 'Ì' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x37, /* 00110111 */ 0x30, /* 00110000 */ 0x37, /* 00110111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 205 0xcd 'Í' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 206 0xce 'Î' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xf7, /* 11110111 */ 0x00, /* 00000000 */ 0xf7, /* 11110111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 207 0xcf 'Ï' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 208 0xd0 'Ð' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 209 0xd1 'Ñ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 210 0xd2 'Ò' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 211 0xd3 'Ó' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x3f, /* 00111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 212 0xd4 'Ô' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 213 0xd5 'Õ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 214 0xd6 'Ö' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x3f, /* 00111111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 215 0xd7 '×' */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0xff, /* 11111111 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ /* 216 0xd8 'Ø' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xff, /* 11111111 */ 0x18, /* 00011000 */ 0xff, /* 11111111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 217 0xd9 'Ù' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xf8, /* 11111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 218 0xda 'Ú' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1f, /* 00011111 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 219 0xdb 'Û' */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ /* 220 0xdc 'Ü' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ /* 221 0xdd 'Ý' */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ 0xf0, /* 11110000 */ /* 222 0xde 'Þ' */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ 0x0f, /* 00001111 */ /* 223 0xdf 'ß' */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0xff, /* 11111111 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 224 0xe0 'à' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xdc, /* 11011100 */ 0x76, /* 01110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 225 0xe1 'á' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x78, /* 01111000 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xcc, /* 11001100 */ 0xd8, /* 11011000 */ 0xcc, /* 11001100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xcc, /* 11001100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 226 0xe2 'â' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0xc0, /* 11000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 227 0xe3 'ã' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 228 0xe4 'ä' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 229 0xe5 'å' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 230 0xe6 'æ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x7c, /* 01111100 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0x00, /* 00000000 */ /* 231 0xe7 'ç' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 232 0xe8 'è' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 233 0xe9 'é' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xfe, /* 11111110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 234 0xea 'ê' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0xee, /* 11101110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 235 0xeb 'ë' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1e, /* 00011110 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x3e, /* 00111110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x66, /* 01100110 */ 0x3c, /* 00111100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 236 0xec 'ì' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0xdb, /* 11011011 */ 0xdb, /* 11011011 */ 0xdb, /* 11011011 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 237 0xed 'í' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x03, /* 00000011 */ 0x06, /* 00000110 */ 0x7e, /* 01111110 */ 0xdb, /* 11011011 */ 0xdb, /* 11011011 */ 0xf3, /* 11110011 */ 0x7e, /* 01111110 */ 0x60, /* 01100000 */ 0xc0, /* 11000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 238 0xee 'î' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x1c, /* 00011100 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x7c, /* 01111100 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x1c, /* 00011100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 239 0xef 'ï' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7c, /* 01111100 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0xc6, /* 11000110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 240 0xf0 'ð' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0xfe, /* 11111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 241 0xf1 'ñ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x7e, /* 01111110 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 242 0xf2 'ò' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x06, /* 00000110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 243 0xf3 'ó' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x30, /* 00110000 */ 0x60, /* 01100000 */ 0x30, /* 00110000 */ 0x18, /* 00011000 */ 0x0c, /* 00001100 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 244 0xf4 'ô' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x0e, /* 00001110 */ 0x1b, /* 00011011 */ 0x1b, /* 00011011 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ /* 245 0xf5 'õ' */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0xd8, /* 11011000 */ 0x70, /* 01110000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 246 0xf6 'ö' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 247 0xf7 '÷' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x00, /* 00000000 */ 0x76, /* 01110110 */ 0xdc, /* 11011100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 248 0xf8 'ø' */ 0x00, /* 00000000 */ 0x38, /* 00111000 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x38, /* 00111000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 249 0xf9 'ù' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 250 0xfa 'ú' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 251 0xfb 'û' */ 0x00, /* 00000000 */ 0x0f, /* 00001111 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0x0c, /* 00001100 */ 0xec, /* 11101100 */ 0x6c, /* 01101100 */ 0x6c, /* 01101100 */ 0x3c, /* 00111100 */ 0x1c, /* 00011100 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 252 0xfc 'ü' */ 0x00, /* 00000000 */ 0x6c, /* 01101100 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x36, /* 00110110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 253 0xfd 'ý' */ 0x00, /* 00000000 */ 0x3c, /* 00111100 */ 0x66, /* 01100110 */ 0x0c, /* 00001100 */ 0x18, /* 00011000 */ 0x32, /* 00110010 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 254 0xfe 'þ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x7e, /* 01111110 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* 255 0xff 'ÿ' */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ }; const struct font_desc font_vga_8x16 = { .idx = VGA8x16_IDX, .name = "VGA8x16", .width = 8, .height = 16, .data = fontdata_8x16, .pref = 0, }; EXPORT_SYMBOL(font_vga_8x16);
gpl-2.0
krichter722/gcc
gcc/testsuite/gcc.dg/tree-ssa/pr34244.c
194
1169
/* PR tree-optimization/34244 */ /* { dg-do run } */ /* { dg-options "-O2 " } */ int __attribute__((noinline)) GetParent(void) { static int count = 0; count++; switch (count) { case 1: case 3: case 4: return 1; default: return 0; } } int __attribute__((noinline)) FindCommonAncestor(int aNode1, int aNode2) { if (aNode1 && aNode2) { int offset = 0; int anc1 = aNode1; for (;;) { ++offset; int parent = GetParent(); if (!parent) break; anc1 = parent; } int anc2 = aNode2; for (;;) { --offset; int parent = GetParent(); if (!parent) break; anc2 = parent; } if (anc1 == anc2) { anc1 = aNode1; anc2 = aNode2; while (offset > 0) { anc1 = GetParent(); --offset; } while (offset < 0) { anc2 = GetParent(); ++offset; } while (anc1 != anc2) { anc1 = GetParent(); anc2 = GetParent(); } return anc1; } } return 0; } extern void abort (void); int main() { if (FindCommonAncestor (1, 1) != 0) abort (); return 0; }
gpl-2.0