aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/acpi/namespace/nsnames.c8
-rw-r--r--drivers/acpi/pci_link.c31
-rw-r--r--drivers/acpi/pci_slot.c5
-rw-r--r--drivers/acpi/processor_idle.c6
-rw-r--r--drivers/acpi/processor_throttling.c17
-rw-r--r--drivers/acpi/sleep/main.c42
-rw-r--r--drivers/acpi/system.c1
-rw-r--r--drivers/acpi/tables/tbfadt.c17
-rw-r--r--drivers/acpi/thermal.c43
-rw-r--r--drivers/acpi/utilities/utalloc.c4
-rw-r--r--drivers/acpi/video.c14
-rw-r--r--drivers/ata/ahci.c2
-rw-r--r--drivers/atm/fore200e.c15
-rw-r--r--drivers/auxdisplay/cfag12864b.c13
-rw-r--r--drivers/base/core.c6
-rw-r--r--drivers/base/cpu.c4
-rw-r--r--drivers/base/firmware_class.c12
-rw-r--r--drivers/base/isa.c4
-rw-r--r--drivers/base/memory.c22
-rw-r--r--drivers/base/sys.c12
-rw-r--r--drivers/block/aoe/aoechr.c9
-rw-r--r--drivers/block/virtio_blk.c10
-rw-r--r--drivers/char/Kconfig26
-rw-r--r--drivers/char/Makefile7
-rw-r--r--drivers/char/ds1302.c17
-rw-r--r--drivers/char/dsp56k.c22
-rw-r--r--drivers/char/efirtc.c35
-rw-r--r--drivers/char/hpet.c2
-rw-r--r--drivers/char/hvc_console.c85
-rw-r--r--drivers/char/hvc_console.h35
-rw-r--r--drivers/char/hvc_irq.c44
-rw-r--r--drivers/char/hvc_iseries.c2
-rw-r--r--drivers/char/hvc_vio.c2
-rw-r--r--drivers/char/hvc_xen.c2
-rw-r--r--drivers/char/ip2/ip2main.c13
-rw-r--r--drivers/char/lcd.c516
-rw-r--r--drivers/char/lcd.h154
-rw-r--r--drivers/char/mem.c5
-rw-r--r--drivers/char/mspec.c23
-rw-r--r--drivers/char/mwave/mwavedd.c39
-rw-r--r--drivers/char/mwave/mwavedd.h2
-rw-r--r--drivers/char/mwave/tp3780i.c2
-rw-r--r--drivers/char/mxser.c337
-rw-r--r--drivers/char/nwflash.c31
-rw-r--r--drivers/char/ppdev.c18
-rw-r--r--drivers/char/random.c1
-rw-r--r--drivers/char/rio/rio_linux.c8
-rw-r--r--drivers/char/rtc.c24
-rw-r--r--drivers/char/stallion.c1
-rw-r--r--drivers/char/sx.c73
-rw-r--r--drivers/char/tpm/tpm.c128
-rw-r--r--drivers/char/tpm/tpm_bios.c4
-rw-r--r--drivers/char/tpm/tpm_tis.c1
-rw-r--r--drivers/char/tty_io.c14
-rw-r--r--drivers/char/virtio_console.c40
-rw-r--r--drivers/char/vt.c8
-rw-r--r--drivers/char/xilinx_hwicap/xilinx_hwicap.c1
-rw-r--r--drivers/cpufreq/cpufreq.c14
-rw-r--r--drivers/cpufreq/cpufreq_conservative.c2
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c4
-rw-r--r--drivers/cpufreq/cpufreq_userspace.c79
-rw-r--r--drivers/edac/Kconfig7
-rw-r--r--drivers/edac/Makefile1
-rw-r--r--drivers/edac/e752x_edac.c59
-rw-r--r--drivers/edac/edac_mc_sysfs.c158
-rw-r--r--drivers/edac/edac_pci_sysfs.c30
-rw-r--r--drivers/edac/i5100_edac.c981
-rw-r--r--drivers/edac/mpc85xx_edac.c67
-rw-r--r--drivers/edac/mv64x60_edac.c37
-rw-r--r--drivers/firewire/fw-iso.c2
-rw-r--r--drivers/firewire/fw-ohci.c2
-rw-r--r--drivers/firewire/fw-sbp2.c8
-rw-r--r--drivers/firmware/dcdbas.c16
-rw-r--r--drivers/firmware/dell_rbu.c28
-rw-r--r--drivers/firmware/memmap.c6
-rw-r--r--drivers/gpio/Kconfig85
-rw-r--r--drivers/gpio/Makefile4
-rw-r--r--drivers/gpio/bt8xxgpio.c348
-rw-r--r--drivers/gpio/gpiolib.c536
-rw-r--r--drivers/gpio/max732x.c385
-rw-r--r--drivers/gpio/mcp23s08.c134
-rw-r--r--drivers/gpio/pca953x.c1
-rw-r--r--drivers/gpio/pcf857x.c1
-rw-r--r--drivers/gpu/drm/drm_drv.c2
-rw-r--r--drivers/i2c/chips/Kconfig2
-rw-r--r--drivers/i2c/chips/tps65010.c2
-rw-r--r--drivers/ide/Kconfig2
-rw-r--r--drivers/ide/Makefile9
-rw-r--r--drivers/ide/arm/icside.c6
-rw-r--r--drivers/ide/arm/palm_bk3710.c9
-rw-r--r--drivers/ide/arm/rapide.c6
-rw-r--r--drivers/ide/ide-cd.c39
-rw-r--r--drivers/ide/ide-disk.c12
-rw-r--r--drivers/ide/ide-dma.c2
-rw-r--r--drivers/ide/ide-floppy.c12
-rw-r--r--drivers/ide/ide-generic.c36
-rw-r--r--drivers/ide/ide-iops.c6
-rw-r--r--drivers/ide/ide-probe.c71
-rw-r--r--drivers/ide/ide-proc.c4
-rw-r--r--drivers/ide/ide-tape.c32
-rw-r--r--drivers/ide/ide-taskfile.c12
-rw-r--r--drivers/ide/ide.c47
-rw-r--r--drivers/ide/legacy/gayle.c8
-rw-r--r--drivers/ide/legacy/ht6560b.c24
-rw-r--r--drivers/ide/pci/aec62xx.c76
-rw-r--r--drivers/ide/pci/alim15x3.c18
-rw-r--r--drivers/ide/pci/amd74xx.c155
-rw-r--r--drivers/ide/pci/atiixp.c20
-rw-r--r--drivers/ide/pci/cmd64x.c50
-rw-r--r--drivers/ide/pci/cs5520.c24
-rw-r--r--drivers/ide/pci/cs5530.c20
-rw-r--r--drivers/ide/pci/cs5535.c13
-rw-r--r--drivers/ide/pci/cy82c693.c35
-rw-r--r--drivers/ide/pci/generic.c78
-rw-r--r--drivers/ide/pci/hpt34x.c21
-rw-r--r--drivers/ide/pci/hpt366.c183
-rw-r--r--drivers/ide/pci/it8213.c35
-rw-r--r--drivers/ide/pci/it821x.c74
-rw-r--r--drivers/ide/pci/jmicron.c13
-rw-r--r--drivers/ide/pci/ns87415.c13
-rw-r--r--drivers/ide/pci/opti621.c13
-rw-r--r--drivers/ide/pci/pdc202xx_new.c78
-rw-r--r--drivers/ide/pci/pdc202xx_old.c49
-rw-r--r--drivers/ide/pci/piix.c118
-rw-r--r--drivers/ide/pci/rz1000.c13
-rw-r--r--drivers/ide/pci/sc1200.c50
-rw-r--r--drivers/ide/pci/serverworks.c40
-rw-r--r--drivers/ide/pci/siimage.c161
-rw-r--r--drivers/ide/pci/sis5513.c39
-rw-r--r--drivers/ide/pci/sl82c105.c17
-rw-r--r--drivers/ide/pci/slc90e66.c13
-rw-r--r--drivers/ide/pci/tc86c001.c57
-rw-r--r--drivers/ide/pci/triflex.c13
-rw-r--r--drivers/ide/pci/trm290.c17
-rw-r--r--drivers/ide/pci/via82cxxx.c139
-rw-r--r--drivers/ide/setup-pci.c240
-rw-r--r--drivers/ieee1394/iso.c1
-rw-r--r--drivers/infiniband/core/cma.c99
-rw-r--r--drivers/infiniband/core/iwcm.c3
-rw-r--r--drivers/infiniband/core/sa_query.c3
-rw-r--r--drivers/infiniband/hw/ehca/ehca_classes.h1
-rw-r--r--drivers/infiniband/hw/ehca/ehca_hca.c4
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.c8
-rw-r--r--drivers/infiniband/hw/ehca/ehca_qp.c2
-rw-r--r--drivers/infiniband/hw/ehca/ipz_pt_fn.c1
-rw-r--r--drivers/infiniband/hw/ipath/ipath_sdma.c2
-rw-r--r--drivers/infiniband/hw/ipath/ipath_user_sdma.c6
-rw-r--r--drivers/infiniband/hw/mlx4/cq.c12
-rw-r--r--drivers/infiniband/hw/mlx4/main.c11
-rw-r--r--drivers/infiniband/hw/mlx4/mlx4_ib.h15
-rw-r--r--drivers/infiniband/hw/mlx4/mr.c70
-rw-r--r--drivers/infiniband/hw/mlx4/qp.c74
-rw-r--r--drivers/infiniband/hw/mthca/mthca_dev.h1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_eq.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mr.c26
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c2
-rw-r--r--drivers/infiniband/ulp/iser/iser_verbs.c1
-rw-r--r--drivers/input/keyboard/hil_kbd.c1
-rw-r--r--drivers/input/keyboard/tosakbd.c2
-rw-r--r--drivers/input/misc/hp_sdc_rtc.c1
-rw-r--r--drivers/input/serio/hp_sdc.c2
-rw-r--r--drivers/isdn/Kconfig4
-rw-r--r--drivers/isdn/Makefile1
-rw-r--r--drivers/isdn/gigaset/asyncdata.c3
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c12
-rw-r--r--drivers/isdn/gigaset/common.c2
-rw-r--r--drivers/isdn/gigaset/gigaset.h3
-rw-r--r--drivers/isdn/gigaset/i4l.c56
-rw-r--r--drivers/isdn/gigaset/interface.c25
-rw-r--r--drivers/isdn/gigaset/usb-gigaset.c7
-rw-r--r--drivers/isdn/hardware/Makefile1
-rw-r--r--drivers/isdn/hardware/mISDN/Kconfig25
-rw-r--r--drivers/isdn/hardware/mISDN/Makefile7
-rw-r--r--drivers/isdn/hardware/mISDN/hfc_multi.h1204
-rw-r--r--drivers/isdn/hardware/mISDN/hfc_pci.h228
-rw-r--r--drivers/isdn/hardware/mISDN/hfcmulti.c5320
-rw-r--r--drivers/isdn/hardware/mISDN/hfcpci.c2256
-rw-r--r--drivers/isdn/hisax/hisax_fcpcipnp.c2
-rw-r--r--drivers/isdn/hisax/st5481.h4
-rw-r--r--drivers/isdn/hisax/st5481_b.c4
-rw-r--r--drivers/isdn/hisax/st5481_d.c6
-rw-r--r--drivers/isdn/hisax/st5481_usb.c18
-rw-r--r--drivers/isdn/mISDN/Kconfig44
-rw-r--r--drivers/isdn/mISDN/Makefile13
-rw-r--r--drivers/isdn/mISDN/core.c244
-rw-r--r--drivers/isdn/mISDN/core.h77
-rw-r--r--drivers/isdn/mISDN/dsp.h263
-rw-r--r--drivers/isdn/mISDN/dsp_audio.c434
-rw-r--r--drivers/isdn/mISDN/dsp_biquad.h65
-rw-r--r--drivers/isdn/mISDN/dsp_blowfish.c672
-rw-r--r--drivers/isdn/mISDN/dsp_cmx.c1886
-rw-r--r--drivers/isdn/mISDN/dsp_core.c1191
-rw-r--r--drivers/isdn/mISDN/dsp_dtmf.c303
-rw-r--r--drivers/isdn/mISDN/dsp_ecdis.h110
-rw-r--r--drivers/isdn/mISDN/dsp_hwec.c138
-rw-r--r--drivers/isdn/mISDN/dsp_hwec.h10
-rw-r--r--drivers/isdn/mISDN/dsp_pipeline.c348
-rw-r--r--drivers/isdn/mISDN/dsp_tones.c551
-rw-r--r--drivers/isdn/mISDN/fsm.c183
-rw-r--r--drivers/isdn/mISDN/fsm.h67
-rw-r--r--drivers/isdn/mISDN/hwchannel.c365
-rw-r--r--drivers/isdn/mISDN/l1oip.h91
-rw-r--r--drivers/isdn/mISDN/l1oip_codec.c374
-rw-r--r--drivers/isdn/mISDN/l1oip_core.c1518
-rw-r--r--drivers/isdn/mISDN/layer1.c403
-rw-r--r--drivers/isdn/mISDN/layer1.h26
-rw-r--r--drivers/isdn/mISDN/layer2.c2216
-rw-r--r--drivers/isdn/mISDN/layer2.h140
-rw-r--r--drivers/isdn/mISDN/socket.c781
-rw-r--r--drivers/isdn/mISDN/stack.c674
-rw-r--r--drivers/isdn/mISDN/tei.c1340
-rw-r--r--drivers/isdn/mISDN/timerdev.c301
-rw-r--r--drivers/leds/Kconfig16
-rw-r--r--drivers/leds/Makefile2
-rw-r--r--drivers/leds/led-triggers.c3
-rw-r--r--drivers/leds/leds-atmel-pwm.c2
-rw-r--r--drivers/leds/leds-h1940.c9
-rw-r--r--drivers/leds/leds-pca9532.c337
-rw-r--r--drivers/leds/leds-pca955x.c384
-rw-r--r--drivers/lguest/lguest_device.c14
-rw-r--r--drivers/media/dvb/pluto2/pluto2.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-dvb.c1
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ioread.c1
-rw-r--r--drivers/media/video/uvc/uvc_queue.c1
-rw-r--r--drivers/media/video/videobuf-core.c1
-rw-r--r--drivers/memstick/core/memstick.c36
-rw-r--r--drivers/memstick/core/mspro_block.c365
-rw-r--r--drivers/memstick/host/jmb38x_ms.c102
-rw-r--r--drivers/memstick/host/tifm_ms.c66
-rw-r--r--drivers/message/fusion/lsi/mpi_history.txt6
-rw-r--r--drivers/message/i2o/device.c54
-rw-r--r--drivers/mfd/Kconfig21
-rw-r--r--drivers/mfd/Makefile4
-rw-r--r--drivers/mfd/asic3.c8
-rw-r--r--drivers/mfd/htc-egpio.c2
-rw-r--r--drivers/mfd/htc-pasic3.c2
-rw-r--r--drivers/mfd/mcp-sa11x0.c2
-rw-r--r--drivers/mfd/mfd-core.c114
-rw-r--r--drivers/mfd/sm501.c439
-rw-r--r--drivers/mfd/tc6393xb.c600
-rw-r--r--drivers/misc/Kconfig19
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/atmel_pwm.c3
-rw-r--r--drivers/misc/hp-wmi.c494
-rw-r--r--drivers/misc/phantom.c2
-rw-r--r--drivers/misc/sgi-xp/xpc_main.c3
-rw-r--r--drivers/misc/thinkpad_acpi.c475
-rw-r--r--drivers/mmc/host/sdhci.c4
-rw-r--r--drivers/mmc/host/sdhci.h2
-rw-r--r--drivers/mtd/maps/uclinux.c1
-rw-r--r--drivers/mtd/nand/cmx270_nand.c79
-rw-r--r--drivers/mtd/ubi/build.c99
-rw-r--r--drivers/mtd/ubi/cdev.c234
-rw-r--r--drivers/mtd/ubi/debug.c158
-rw-r--r--drivers/mtd/ubi/debug.h74
-rw-r--r--drivers/mtd/ubi/eba.c77
-rw-r--r--drivers/mtd/ubi/gluebi.c16
-rw-r--r--drivers/mtd/ubi/io.c48
-rw-r--r--drivers/mtd/ubi/kapi.c50
-rw-r--r--drivers/mtd/ubi/misc.c2
-rw-r--r--drivers/mtd/ubi/scan.c136
-rw-r--r--drivers/mtd/ubi/scan.h21
-rw-r--r--drivers/mtd/ubi/ubi-media.h38
-rw-r--r--drivers/mtd/ubi/ubi.h75
-rw-r--r--drivers/mtd/ubi/upd.c32
-rw-r--r--drivers/mtd/ubi/vmt.c148
-rw-r--r--drivers/mtd/ubi/vtbl.c127
-rw-r--r--drivers/mtd/ubi/wl.c208
-rw-r--r--drivers/net/arm/ep93xx_eth.c4
-rw-r--r--drivers/net/bnx2x_main.c14
-rw-r--r--drivers/net/cassini.c12
-rw-r--r--drivers/net/cxgb3/sge.c2
-rw-r--r--drivers/net/e100.c2
-rw-r--r--drivers/net/e1000e/ethtool.c4
-rw-r--r--drivers/net/e1000e/netdev.c13
-rw-r--r--drivers/net/fec.c54
-rw-r--r--drivers/net/ibmveth.c219
-rw-r--r--drivers/net/ibmveth.h5
-rw-r--r--drivers/net/iseries_veth.c4
-rw-r--r--drivers/net/mlx4/cmd.c3
-rw-r--r--drivers/net/mlx4/eq.c3
-rw-r--r--drivers/net/mlx4/fw.c18
-rw-r--r--drivers/net/mlx4/fw.h2
-rw-r--r--drivers/net/mlx4/main.c2
-rw-r--r--drivers/net/mlx4/mlx4.h1
-rw-r--r--drivers/net/mlx4/mr.c49
-rw-r--r--drivers/net/mlx4/pd.c7
-rw-r--r--drivers/net/pasemi_mac.c6
-rw-r--r--drivers/net/ppp_generic.c6
-rw-r--r--drivers/net/qla3xxx.c12
-rw-r--r--drivers/net/s2io.c48
-rw-r--r--drivers/net/sfc/rx.c4
-rw-r--r--drivers/net/sfc/tx.c7
-rw-r--r--drivers/net/sky2.c5
-rw-r--r--drivers/net/smc91x.c94
-rw-r--r--drivers/net/smc91x.h76
-rw-r--r--drivers/net/spider_net.c4
-rw-r--r--drivers/net/tc35815.c4
-rw-r--r--drivers/net/virtio_net.c114
-rw-r--r--drivers/net/wireless/ath5k/base.c4
-rw-r--r--drivers/of/Kconfig2
-rw-r--r--drivers/of/of_i2c.c2
-rw-r--r--drivers/parport/ieee1284.c2
-rw-r--r--drivers/parport/parport_ax88796.c2
-rw-r--r--drivers/parport/parport_cs.c2
-rw-r--r--drivers/parport/parport_pc.c2
-rw-r--r--drivers/parport/procfs.c3
-rw-r--r--drivers/pci/dmar.c4
-rw-r--r--drivers/pci/pci.c34
-rw-r--r--drivers/pci/proc.c18
-rw-r--r--drivers/pcmcia/Kconfig3
-rw-r--r--drivers/pcmcia/Makefile1
-rw-r--r--drivers/pcmcia/electra_cf.c1
-rw-r--r--drivers/pcmcia/pxa2xx_cm_x270.c93
-rw-r--r--drivers/pcmcia/pxa2xx_palmtx.c118
-rw-r--r--drivers/pnp/base.h1
-rw-r--r--drivers/pnp/card.c6
-rw-r--r--drivers/pnp/quirks.c13
-rw-r--r--drivers/power/Kconfig6
-rw-r--r--drivers/power/Makefile1
-rw-r--r--drivers/power/ds2760_battery.c2
-rw-r--r--drivers/power/palmtx_battery.c198
-rw-r--r--drivers/power/pda_power.c2
-rw-r--r--drivers/rtc/Kconfig19
-rw-r--r--drivers/rtc/Makefile2
-rw-r--r--drivers/rtc/rtc-at91rm9200.c16
-rw-r--r--drivers/rtc/rtc-cmos.c294
-rw-r--r--drivers/rtc/rtc-dev.c58
-rw-r--r--drivers/rtc/rtc-ds1305.c847
-rw-r--r--drivers/rtc/rtc-m41t80.c20
-rw-r--r--drivers/rtc/rtc-m41t94.c173
-rw-r--r--drivers/rtc/rtc-omap.c21
-rw-r--r--drivers/rtc/rtc-pcf8583.c129
-rw-r--r--drivers/rtc/rtc-s3c.c89
-rw-r--r--drivers/rtc/rtc-vr41xx.c65
-rw-r--r--drivers/s390/kvm/kvm_virtio.c34
-rw-r--r--drivers/s390/net/qeth_core_main.c14
-rw-r--r--drivers/s390/net/qeth_l2_main.c26
-rw-r--r--drivers/s390/net/qeth_l3_main.c30
-rw-r--r--drivers/scsi/ibmvscsi/ibmvfc.c19
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c49
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.h2
-rw-r--r--drivers/scsi/ibmvscsi/ibmvstgt.c2
-rw-r--r--drivers/scsi/ibmvscsi/rpa_vscsi.c2
-rw-r--r--drivers/scsi/ide-scsi.c33
-rw-r--r--drivers/scsi/sun_esp.c1
-rw-r--r--drivers/serial/8250.c17
-rw-r--r--drivers/serial/8250_gsc.c2
-rw-r--r--drivers/serial/8250_pci.c17
-rw-r--r--drivers/serial/Kconfig16
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_core.c21
-rw-r--r--drivers/serial/dz.c24
-rw-r--r--drivers/serial/zs.c21
-rw-r--r--drivers/spi/Kconfig45
-rw-r--r--drivers/spi/atmel_spi.c4
-rw-r--r--drivers/spi/au1550_spi.c213
-rw-r--r--drivers/spi/omap2_mcspi.c4
-rw-r--r--drivers/spi/pxa2xx_spi.c4
-rw-r--r--drivers/spi/spi.c4
-rw-r--r--drivers/spi/spi_imx.c6
-rw-r--r--drivers/spi/spi_mpc83xx.c29
-rw-r--r--drivers/spi/spidev.c19
-rw-r--r--drivers/spi/xilinx_spi.c5
-rw-r--r--drivers/telephony/ixj.c17
-rw-r--r--drivers/usb/gadget/at91_udc.h2
-rw-r--r--drivers/usb/gadget/cdc2.c2
-rw-r--r--drivers/usb/gadget/ether.c2
-rw-r--r--drivers/usb/gadget/file_storage.c14
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.c2
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.h2
-rw-r--r--drivers/usb/gadget/gmidi.c2
-rw-r--r--drivers/usb/gadget/goku_udc.c2
-rw-r--r--drivers/usb/gadget/goku_udc.h2
-rw-r--r--drivers/usb/gadget/inode.c2
-rw-r--r--drivers/usb/gadget/net2280.c2
-rw-r--r--drivers/usb/gadget/net2280.h2
-rw-r--r--drivers/usb/gadget/omap_udc.c6
-rw-r--r--drivers/usb/gadget/omap_udc.h2
-rw-r--r--drivers/usb/gadget/printer.c2
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c12
-rw-r--r--drivers/usb/gadget/pxa25x_udc.h2
-rw-r--r--drivers/usb/gadget/u_ether.c3
-rw-r--r--drivers/usb/host/isp116x-hcd.c2
-rw-r--r--drivers/usb/host/isp116x.h2
-rw-r--r--drivers/usb/host/sl811-hcd.c2
-rw-r--r--drivers/usb/host/sl811.h2
-rw-r--r--drivers/usb/misc/usbtest.c4
-rw-r--r--drivers/usb/mon/mon_text.c4
-rw-r--r--drivers/video/Kconfig53
-rw-r--r--drivers/video/Makefile5
-rw-r--r--drivers/video/acornfb.c1
-rw-r--r--drivers/video/amifb.c24
-rw-r--r--drivers/video/atafb.c7
-rw-r--r--drivers/video/atmel_lcdfb.c92
-rw-r--r--drivers/video/aty/aty128fb.c6
-rw-r--r--drivers/video/aty/atyfb_base.c100
-rw-r--r--drivers/video/aty/radeon_base.c20
-rw-r--r--drivers/video/backlight/Kconfig45
-rw-r--r--drivers/video/backlight/Makefile8
-rw-r--r--drivers/video/backlight/atmel-pwm-bl.c244
-rw-r--r--drivers/video/backlight/backlight.c1
-rw-r--r--drivers/video/backlight/ili9320.c330
-rw-r--r--drivers/video/backlight/ili9320.h80
-rw-r--r--drivers/video/backlight/lcd.c2
-rw-r--r--drivers/video/backlight/mbp_nvidia_bl.c116
-rw-r--r--drivers/video/backlight/platform_lcd.c172
-rw-r--r--drivers/video/backlight/vgg2432a4.c284
-rw-r--r--drivers/video/bf54x-lq043fb.c2
-rw-r--r--drivers/video/bfin-t350mcqb-fb.c2
-rw-r--r--drivers/video/carminefb.c790
-rw-r--r--drivers/video/carminefb.h64
-rw-r--r--drivers/video/carminefb_regs.h159
-rw-r--r--drivers/video/cobalt_lcdfb.c371
-rw-r--r--drivers/video/console/fbcon.c5
-rw-r--r--drivers/video/console/fbcon.h8
-rw-r--r--drivers/video/console/mdacon.c4
-rw-r--r--drivers/video/console/sticon.c2
-rw-r--r--drivers/video/console/sticore.c33
-rw-r--r--drivers/video/fbmem.c9
-rw-r--r--drivers/video/fbmon.c2
-rw-r--r--drivers/video/fsl-diu-fb.c60
-rw-r--r--drivers/video/geode/lxfb.h2
-rw-r--r--drivers/video/geode/lxfb_ops.c28
-rw-r--r--drivers/video/hgafb.c36
-rw-r--r--drivers/video/imxfb.c1
-rw-r--r--drivers/video/macfb.c2
-rw-r--r--drivers/video/neofb.c215
-rw-r--r--drivers/video/omap/dispc.c1
-rw-r--r--drivers/video/omap/omapfb_main.c1
-rw-r--r--drivers/video/pxafb.c72
-rw-r--r--drivers/video/pxafb.h2
-rw-r--r--drivers/video/sa1100fb.c8
-rw-r--r--drivers/video/sa1100fb.h2
-rw-r--r--drivers/video/sh7760fb.c658
-rw-r--r--drivers/video/sh_mobile_lcdcfb.c725
-rw-r--r--drivers/video/sis/init.h1
-rw-r--r--drivers/video/sis/init301.h1
-rw-r--r--drivers/video/sis/initextlfb.c1
-rw-r--r--drivers/video/sis/osdef.h1
-rw-r--r--drivers/video/sis/sis.h22
-rw-r--r--drivers/video/sis/sis_accel.c1
-rw-r--r--drivers/video/sis/sis_main.c44
-rw-r--r--drivers/video/sis/sis_main.h4
-rw-r--r--drivers/video/sis/vgatypes.h4
-rw-r--r--drivers/video/skeletonfb.c37
-rw-r--r--drivers/video/sm501fb.c329
-rw-r--r--drivers/video/sticore.h2
-rw-r--r--drivers/video/stifb.c6
-rw-r--r--drivers/video/tdfxfb.c8
-rw-r--r--drivers/video/tridentfb.c1350
-rw-r--r--drivers/video/uvesafb.c4
-rw-r--r--drivers/video/vfb.c14
-rw-r--r--drivers/video/vga16fb.c122
-rw-r--r--drivers/virtio/virtio.c26
-rw-r--r--drivers/virtio/virtio_pci.c13
-rw-r--r--drivers/virtio/virtio_ring.c23
-rw-r--r--drivers/watchdog/Kconfig2
-rw-r--r--drivers/watchdog/Makefile2
-rw-r--r--drivers/zorro/zorro-sysfs.c1
460 files changed, 41643 insertions, 5869 deletions
diff --git a/drivers/Makefile b/drivers/Makefile
index 808e0ae66aa8..54ec5e718c0e 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -5,7 +5,7 @@
5# Rewritten to use lists instead of if-statements. 5# Rewritten to use lists instead of if-statements.
6# 6#
7 7
8obj-$(CONFIG_HAVE_GPIO_LIB) += gpio/ 8obj-y += gpio/
9obj-$(CONFIG_PCI) += pci/ 9obj-$(CONFIG_PCI) += pci/
10obj-$(CONFIG_PARISC) += parisc/ 10obj-$(CONFIG_PARISC) += parisc/
11obj-$(CONFIG_RAPIDIO) += rapidio/ 11obj-$(CONFIG_RAPIDIO) += rapidio/
diff --git a/drivers/acpi/namespace/nsnames.c b/drivers/acpi/namespace/nsnames.c
index cffef1bcbdbc..549db42f16cf 100644
--- a/drivers/acpi/namespace/nsnames.c
+++ b/drivers/acpi/namespace/nsnames.c
@@ -137,6 +137,10 @@ char *acpi_ns_get_external_pathname(struct acpi_namespace_node *node)
137 /* Calculate required buffer size based on depth below root */ 137 /* Calculate required buffer size based on depth below root */
138 138
139 size = acpi_ns_get_pathname_length(node); 139 size = acpi_ns_get_pathname_length(node);
140 if (!size) {
141 ACPI_ERROR((AE_INFO, "Invalid node failure"));
142 return_PTR(NULL);
143 }
140 144
141 /* Allocate a buffer to be returned to caller */ 145 /* Allocate a buffer to be returned to caller */
142 146
@@ -229,6 +233,10 @@ acpi_ns_handle_to_pathname(acpi_handle target_handle,
229 /* Determine size required for the caller buffer */ 233 /* Determine size required for the caller buffer */
230 234
231 required_size = acpi_ns_get_pathname_length(node); 235 required_size = acpi_ns_get_pathname_length(node);
236 if (!required_size) {
237 ACPI_ERROR((AE_INFO, "Invalid node failure"));
238 return_ACPI_STATUS(AE_ERROR);
239 }
232 240
233 /* Validate/Allocate/Clear caller buffer */ 241 /* Validate/Allocate/Clear caller buffer */
234 242
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 233c40c51684..89f3b2abfdc7 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -113,20 +113,23 @@ acpi_pci_link_check_possible(struct acpi_resource *resource, void *context)
113 113
114 switch (resource->type) { 114 switch (resource->type) {
115 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 115 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
116 case ACPI_RESOURCE_TYPE_END_TAG:
116 return AE_OK; 117 return AE_OK;
117 case ACPI_RESOURCE_TYPE_IRQ: 118 case ACPI_RESOURCE_TYPE_IRQ:
118 { 119 {
119 struct acpi_resource_irq *p = &resource->data.irq; 120 struct acpi_resource_irq *p = &resource->data.irq;
120 if (!p || !p->interrupt_count) { 121 if (!p || !p->interrupt_count) {
121 printk(KERN_WARNING PREFIX "Blank IRQ resource\n"); 122 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
123 "Blank _PRS IRQ resource\n"));
122 return AE_OK; 124 return AE_OK;
123 } 125 }
124 for (i = 0; 126 for (i = 0;
125 (i < p->interrupt_count 127 (i < p->interrupt_count
126 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { 128 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
127 if (!p->interrupts[i]) { 129 if (!p->interrupts[i]) {
128 printk(KERN_WARNING PREFIX "Invalid IRQ %d\n", 130 printk(KERN_WARNING PREFIX
129 p->interrupts[i]); 131 "Invalid _PRS IRQ %d\n",
132 p->interrupts[i]);
130 continue; 133 continue;
131 } 134 }
132 link->irq.possible[i] = p->interrupts[i]; 135 link->irq.possible[i] = p->interrupts[i];
@@ -143,15 +146,16 @@ acpi_pci_link_check_possible(struct acpi_resource *resource, void *context)
143 &resource->data.extended_irq; 146 &resource->data.extended_irq;
144 if (!p || !p->interrupt_count) { 147 if (!p || !p->interrupt_count) {
145 printk(KERN_WARNING PREFIX 148 printk(KERN_WARNING PREFIX
146 "Blank EXT IRQ resource\n"); 149 "Blank _PRS EXT IRQ resource\n");
147 return AE_OK; 150 return AE_OK;
148 } 151 }
149 for (i = 0; 152 for (i = 0;
150 (i < p->interrupt_count 153 (i < p->interrupt_count
151 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { 154 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
152 if (!p->interrupts[i]) { 155 if (!p->interrupts[i]) {
153 printk(KERN_WARNING PREFIX "Invalid IRQ %d\n", 156 printk(KERN_WARNING PREFIX
154 p->interrupts[i]); 157 "Invalid _PRS IRQ %d\n",
158 p->interrupts[i]);
155 continue; 159 continue;
156 } 160 }
157 link->irq.possible[i] = p->interrupts[i]; 161 link->irq.possible[i] = p->interrupts[i];
@@ -163,7 +167,8 @@ acpi_pci_link_check_possible(struct acpi_resource *resource, void *context)
163 break; 167 break;
164 } 168 }
165 default: 169 default:
166 printk(KERN_ERR PREFIX "Resource is not an IRQ entry\n"); 170 printk(KERN_ERR PREFIX "_PRS resource type 0x%x isn't an IRQ\n",
171 resource->type);
167 return AE_OK; 172 return AE_OK;
168 } 173 }
169 174
@@ -199,6 +204,9 @@ acpi_pci_link_check_current(struct acpi_resource *resource, void *context)
199 204
200 205
201 switch (resource->type) { 206 switch (resource->type) {
207 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
208 case ACPI_RESOURCE_TYPE_END_TAG:
209 return AE_OK;
202 case ACPI_RESOURCE_TYPE_IRQ: 210 case ACPI_RESOURCE_TYPE_IRQ:
203 { 211 {
204 struct acpi_resource_irq *p = &resource->data.irq; 212 struct acpi_resource_irq *p = &resource->data.irq;
@@ -208,7 +216,7 @@ acpi_pci_link_check_current(struct acpi_resource *resource, void *context)
208 * particularly those those w/ _STA disabled 216 * particularly those those w/ _STA disabled
209 */ 217 */
210 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 218 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
211 "Blank IRQ resource\n")); 219 "Blank _CRS IRQ resource\n"));
212 return AE_OK; 220 return AE_OK;
213 } 221 }
214 *irq = p->interrupts[0]; 222 *irq = p->interrupts[0];
@@ -224,7 +232,7 @@ acpi_pci_link_check_current(struct acpi_resource *resource, void *context)
224 * return at least 1 IRQ 232 * return at least 1 IRQ
225 */ 233 */
226 printk(KERN_WARNING PREFIX 234 printk(KERN_WARNING PREFIX
227 "Blank EXT IRQ resource\n"); 235 "Blank _CRS EXT IRQ resource\n");
228 return AE_OK; 236 return AE_OK;
229 } 237 }
230 *irq = p->interrupts[0]; 238 *irq = p->interrupts[0];
@@ -232,10 +240,11 @@ acpi_pci_link_check_current(struct acpi_resource *resource, void *context)
232 } 240 }
233 break; 241 break;
234 default: 242 default:
235 printk(KERN_ERR PREFIX "Resource %d isn't an IRQ\n", resource->type); 243 printk(KERN_ERR PREFIX "_CRS resource type 0x%x isn't an IRQ\n",
236 case ACPI_RESOURCE_TYPE_END_TAG: 244 resource->type);
237 return AE_OK; 245 return AE_OK;
238 } 246 }
247
239 return AE_CTRL_TERMINATE; 248 return AE_CTRL_TERMINATE;
240} 249}
241 250
diff --git a/drivers/acpi/pci_slot.c b/drivers/acpi/pci_slot.c
index b9ab030a52d5..dd376f7ad090 100644
--- a/drivers/acpi/pci_slot.c
+++ b/drivers/acpi/pci_slot.c
@@ -6,8 +6,8 @@
6 * Thanks to Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> for code 6 * Thanks to Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> for code
7 * review and fixes. 7 * review and fixes.
8 * 8 *
9 * Copyright (C) 2007 Alex Chiang <achiang@hp.com> 9 * Copyright (C) 2007-2008 Hewlett-Packard Development Company, L.P.
10 * Copyright (C) 2007 Hewlett-Packard Development Company, L.P. 10 * Alex Chiang <achiang@hp.com>
11 * 11 *
12 * This program is free software; you can redistribute it and/or modify it 12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms and conditions of the GNU General Public License, 13 * under the terms and conditions of the GNU General Public License,
@@ -158,6 +158,7 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
158 if (IS_ERR(pci_slot)) { 158 if (IS_ERR(pci_slot)) {
159 err("pci_create_slot returned %ld\n", PTR_ERR(pci_slot)); 159 err("pci_create_slot returned %ld\n", PTR_ERR(pci_slot));
160 kfree(slot); 160 kfree(slot);
161 return AE_OK;
161 } 162 }
162 163
163 slot->root_handle = parent_context->root_handle; 164 slot->root_handle = parent_context->root_handle;
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index d592dbb1d12a..b7f2963693a7 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -272,6 +272,8 @@ static atomic_t c3_cpu_count;
272/* Common C-state entry for C2, C3, .. */ 272/* Common C-state entry for C2, C3, .. */
273static void acpi_cstate_enter(struct acpi_processor_cx *cstate) 273static void acpi_cstate_enter(struct acpi_processor_cx *cstate)
274{ 274{
275 /* Don't trace irqs off for idle */
276 stop_critical_timings();
275 if (cstate->entry_method == ACPI_CSTATE_FFH) { 277 if (cstate->entry_method == ACPI_CSTATE_FFH) {
276 /* Call into architectural FFH based C-state */ 278 /* Call into architectural FFH based C-state */
277 acpi_processor_ffh_cstate_enter(cstate); 279 acpi_processor_ffh_cstate_enter(cstate);
@@ -284,6 +286,7 @@ static void acpi_cstate_enter(struct acpi_processor_cx *cstate)
284 gets asserted in time to freeze execution properly. */ 286 gets asserted in time to freeze execution properly. */
285 unused = inl(acpi_gbl_FADT.xpm_timer_block.address); 287 unused = inl(acpi_gbl_FADT.xpm_timer_block.address);
286 } 288 }
289 start_critical_timings();
287} 290}
288#endif /* !CONFIG_CPU_IDLE */ 291#endif /* !CONFIG_CPU_IDLE */
289 292
@@ -1418,6 +1421,8 @@ static inline void acpi_idle_update_bm_rld(struct acpi_processor *pr,
1418 */ 1421 */
1419static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx) 1422static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
1420{ 1423{
1424 /* Don't trace irqs off for idle */
1425 stop_critical_timings();
1421 if (cx->entry_method == ACPI_CSTATE_FFH) { 1426 if (cx->entry_method == ACPI_CSTATE_FFH) {
1422 /* Call into architectural FFH based C-state */ 1427 /* Call into architectural FFH based C-state */
1423 acpi_processor_ffh_cstate_enter(cx); 1428 acpi_processor_ffh_cstate_enter(cx);
@@ -1432,6 +1437,7 @@ static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
1432 gets asserted in time to freeze execution properly. */ 1437 gets asserted in time to freeze execution properly. */
1433 unused = inl(acpi_gbl_FADT.xpm_timer_block.address); 1438 unused = inl(acpi_gbl_FADT.xpm_timer_block.address);
1434 } 1439 }
1440 start_critical_timings();
1435} 1441}
1436 1442
1437/** 1443/**
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index 0622ace05220..a2c3f9cfa549 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -827,6 +827,7 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
827static int acpi_processor_get_throttling(struct acpi_processor *pr) 827static int acpi_processor_get_throttling(struct acpi_processor *pr)
828{ 828{
829 cpumask_t saved_mask; 829 cpumask_t saved_mask;
830 cpumask_of_cpu_ptr_declare(new_mask);
830 int ret; 831 int ret;
831 832
832 if (!pr) 833 if (!pr)
@@ -838,7 +839,8 @@ static int acpi_processor_get_throttling(struct acpi_processor *pr)
838 * Migrate task to the cpu pointed by pr. 839 * Migrate task to the cpu pointed by pr.
839 */ 840 */
840 saved_mask = current->cpus_allowed; 841 saved_mask = current->cpus_allowed;
841 set_cpus_allowed_ptr(current, &cpumask_of_cpu(pr->id)); 842 cpumask_of_cpu_ptr_next(new_mask, pr->id);
843 set_cpus_allowed_ptr(current, new_mask);
842 ret = pr->throttling.acpi_processor_get_throttling(pr); 844 ret = pr->throttling.acpi_processor_get_throttling(pr);
843 /* restore the previous state */ 845 /* restore the previous state */
844 set_cpus_allowed_ptr(current, &saved_mask); 846 set_cpus_allowed_ptr(current, &saved_mask);
@@ -987,6 +989,7 @@ static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
987int acpi_processor_set_throttling(struct acpi_processor *pr, int state) 989int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
988{ 990{
989 cpumask_t saved_mask; 991 cpumask_t saved_mask;
992 cpumask_of_cpu_ptr_declare(new_mask);
990 int ret = 0; 993 int ret = 0;
991 unsigned int i; 994 unsigned int i;
992 struct acpi_processor *match_pr; 995 struct acpi_processor *match_pr;
@@ -1013,7 +1016,7 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
1013 * affected cpu in order to get one proper T-state. 1016 * affected cpu in order to get one proper T-state.
1014 * The notifier event is THROTTLING_PRECHANGE. 1017 * The notifier event is THROTTLING_PRECHANGE.
1015 */ 1018 */
1016 for_each_cpu_mask(i, online_throttling_cpus) { 1019 for_each_cpu_mask_nr(i, online_throttling_cpus) {
1017 t_state.cpu = i; 1020 t_state.cpu = i;
1018 acpi_processor_throttling_notifier(THROTTLING_PRECHANGE, 1021 acpi_processor_throttling_notifier(THROTTLING_PRECHANGE,
1019 &t_state); 1022 &t_state);
@@ -1025,7 +1028,8 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
1025 * it can be called only for the cpu pointed by pr. 1028 * it can be called only for the cpu pointed by pr.
1026 */ 1029 */
1027 if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) { 1030 if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) {
1028 set_cpus_allowed_ptr(current, &cpumask_of_cpu(pr->id)); 1031 cpumask_of_cpu_ptr_next(new_mask, pr->id);
1032 set_cpus_allowed_ptr(current, new_mask);
1029 ret = p_throttling->acpi_processor_set_throttling(pr, 1033 ret = p_throttling->acpi_processor_set_throttling(pr,
1030 t_state.target_state); 1034 t_state.target_state);
1031 } else { 1035 } else {
@@ -1034,7 +1038,7 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
1034 * it is necessary to set T-state for every affected 1038 * it is necessary to set T-state for every affected
1035 * cpus. 1039 * cpus.
1036 */ 1040 */
1037 for_each_cpu_mask(i, online_throttling_cpus) { 1041 for_each_cpu_mask_nr(i, online_throttling_cpus) {
1038 match_pr = per_cpu(processors, i); 1042 match_pr = per_cpu(processors, i);
1039 /* 1043 /*
1040 * If the pointer is invalid, we will report the 1044 * If the pointer is invalid, we will report the
@@ -1056,7 +1060,8 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
1056 continue; 1060 continue;
1057 } 1061 }
1058 t_state.cpu = i; 1062 t_state.cpu = i;
1059 set_cpus_allowed_ptr(current, &cpumask_of_cpu(i)); 1063 cpumask_of_cpu_ptr_next(new_mask, i);
1064 set_cpus_allowed_ptr(current, new_mask);
1060 ret = match_pr->throttling. 1065 ret = match_pr->throttling.
1061 acpi_processor_set_throttling( 1066 acpi_processor_set_throttling(
1062 match_pr, t_state.target_state); 1067 match_pr, t_state.target_state);
@@ -1068,7 +1073,7 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
1068 * affected cpu to update the T-states. 1073 * affected cpu to update the T-states.
1069 * The notifier event is THROTTLING_POSTCHANGE 1074 * The notifier event is THROTTLING_POSTCHANGE
1070 */ 1075 */
1071 for_each_cpu_mask(i, online_throttling_cpus) { 1076 for_each_cpu_mask_nr(i, online_throttling_cpus) {
1072 t_state.cpu = i; 1077 t_state.cpu = i;
1073 acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE, 1078 acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE,
1074 &t_state); 1079 &t_state);
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index 0489a7d1d42c..d13194a031bf 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -280,9 +280,36 @@ static struct platform_suspend_ops acpi_suspend_ops_old = {
280 .end = acpi_pm_end, 280 .end = acpi_pm_end,
281 .recover = acpi_pm_finish, 281 .recover = acpi_pm_finish,
282}; 282};
283
284static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
285{
286 old_suspend_ordering = true;
287 return 0;
288}
289
290static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
291 {
292 .callback = init_old_suspend_ordering,
293 .ident = "Abit KN9 (nForce4 variant)",
294 .matches = {
295 DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
296 DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
297 },
298 },
299 {},
300};
283#endif /* CONFIG_SUSPEND */ 301#endif /* CONFIG_SUSPEND */
284 302
285#ifdef CONFIG_HIBERNATION 303#ifdef CONFIG_HIBERNATION
304static unsigned long s4_hardware_signature;
305static struct acpi_table_facs *facs;
306static bool nosigcheck;
307
308void __init acpi_no_s4_hw_signature(void)
309{
310 nosigcheck = true;
311}
312
286static int acpi_hibernation_begin(void) 313static int acpi_hibernation_begin(void)
287{ 314{
288 acpi_target_sleep_state = ACPI_STATE_S4; 315 acpi_target_sleep_state = ACPI_STATE_S4;
@@ -316,6 +343,12 @@ static void acpi_hibernation_leave(void)
316 acpi_enable(); 343 acpi_enable();
317 /* Reprogram control registers and execute _BFS */ 344 /* Reprogram control registers and execute _BFS */
318 acpi_leave_sleep_state_prep(ACPI_STATE_S4); 345 acpi_leave_sleep_state_prep(ACPI_STATE_S4);
346 /* Check the hardware signature */
347 if (facs && s4_hardware_signature != facs->hardware_signature) {
348 printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
349 "cannot resume!\n");
350 panic("ACPI S4 hardware signature mismatch");
351 }
319} 352}
320 353
321static void acpi_pm_enable_gpes(void) 354static void acpi_pm_enable_gpes(void)
@@ -516,6 +549,8 @@ int __init acpi_sleep_init(void)
516 u8 type_a, type_b; 549 u8 type_a, type_b;
517#ifdef CONFIG_SUSPEND 550#ifdef CONFIG_SUSPEND
518 int i = 0; 551 int i = 0;
552
553 dmi_check_system(acpisleep_dmi_table);
519#endif 554#endif
520 555
521 if (acpi_disabled) 556 if (acpi_disabled)
@@ -544,6 +579,13 @@ int __init acpi_sleep_init(void)
544 &acpi_hibernation_ops_old : &acpi_hibernation_ops); 579 &acpi_hibernation_ops_old : &acpi_hibernation_ops);
545 sleep_states[ACPI_STATE_S4] = 1; 580 sleep_states[ACPI_STATE_S4] = 1;
546 printk(" S4"); 581 printk(" S4");
582 if (!nosigcheck) {
583 acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
584 (struct acpi_table_header **)&facs);
585 if (facs)
586 s4_hardware_signature =
587 facs->hardware_signature;
588 }
547 } 589 }
548#endif 590#endif
549 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); 591 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index d8e3f153b295..91dec448b3ed 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -26,6 +26,7 @@
26#include <linux/proc_fs.h> 26#include <linux/proc_fs.h>
27#include <linux/seq_file.h> 27#include <linux/seq_file.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/string.h>
29#include <asm/uaccess.h> 30#include <asm/uaccess.h>
30 31
31#include <acpi/acpi_drivers.h> 32#include <acpi/acpi_drivers.h>
diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c
index ccb5b64bbef3..a4a41ba2484b 100644
--- a/drivers/acpi/tables/tbfadt.c
+++ b/drivers/acpi/tables/tbfadt.c
@@ -124,7 +124,7 @@ static struct acpi_fadt_info fadt_info_table[] = {
124 124
125static void inline 125static void inline
126acpi_tb_init_generic_address(struct acpi_generic_address *generic_address, 126acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
127 u8 byte_width, u64 address) 127 u8 bit_width, u64 address)
128{ 128{
129 129
130 /* 130 /*
@@ -136,7 +136,7 @@ acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
136 /* All other fields are byte-wide */ 136 /* All other fields are byte-wide */
137 137
138 generic_address->space_id = ACPI_ADR_SPACE_SYSTEM_IO; 138 generic_address->space_id = ACPI_ADR_SPACE_SYSTEM_IO;
139 generic_address->bit_width = byte_width << 3; 139 generic_address->bit_width = bit_width;
140 generic_address->bit_offset = 0; 140 generic_address->bit_offset = 0;
141 generic_address->access_width = 0; 141 generic_address->access_width = 0;
142} 142}
@@ -343,11 +343,9 @@ static void acpi_tb_convert_fadt(void)
343 * 343 *
344 * The PM event blocks are split into two register blocks, first is the 344 * The PM event blocks are split into two register blocks, first is the
345 * PM Status Register block, followed immediately by the PM Enable Register 345 * PM Status Register block, followed immediately by the PM Enable Register
346 * block. Each is of length (xpm1x_event_block.bit_width/2) 346 * block. Each is of length (pm1_event_length/2)
347 */ 347 */
348 WARN_ON(ACPI_MOD_16(acpi_gbl_FADT.xpm1a_event_block.bit_width)); 348 pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length);
349 pm1_register_length = (u8) ACPI_DIV_16(acpi_gbl_FADT
350 .xpm1a_event_block.bit_width);
351 349
352 /* The PM1A register block is required */ 350 /* The PM1A register block is required */
353 351
@@ -362,17 +360,14 @@ static void acpi_tb_convert_fadt(void)
362 /* The PM1B register block is optional, ignore if not present */ 360 /* The PM1B register block is optional, ignore if not present */
363 361
364 if (acpi_gbl_FADT.xpm1b_event_block.address) { 362 if (acpi_gbl_FADT.xpm1b_event_block.address) {
365 WARN_ON(ACPI_MOD_16(acpi_gbl_FADT.xpm1b_event_block.bit_width));
366 pm1_register_length = (u8) ACPI_DIV_16(acpi_gbl_FADT
367 .xpm1b_event_block
368 .bit_width);
369 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable, 363 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
370 pm1_register_length, 364 pm1_register_length,
371 (acpi_gbl_FADT.xpm1b_event_block. 365 (acpi_gbl_FADT.xpm1b_event_block.
372 address + pm1_register_length)); 366 address + pm1_register_length));
373 /* Don't forget to copy space_id of the GAS */ 367 /* Don't forget to copy space_id of the GAS */
374 acpi_gbl_xpm1b_enable.space_id = 368 acpi_gbl_xpm1b_enable.space_id =
375 acpi_gbl_FADT.xpm1b_event_block.space_id; 369 acpi_gbl_FADT.xpm1a_event_block.space_id;
370
376 } 371 }
377} 372}
378 373
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 30a341337933..912703691d36 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -769,6 +769,47 @@ static void acpi_thermal_run(unsigned long data)
769 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data); 769 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
770} 770}
771 771
772static void acpi_thermal_active_off(void *data)
773{
774 int result = 0;
775 struct acpi_thermal *tz = data;
776 int i = 0;
777 int j = 0;
778 struct acpi_thermal_active *active = NULL;
779
780 if (!tz) {
781 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
782 return;
783 }
784
785 result = acpi_thermal_get_temperature(tz);
786 if (result)
787 return;
788
789 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
790 active = &(tz->trips.active[i]);
791 if (!active || !active->flags.valid)
792 break;
793 if (tz->temperature >= active->temperature) {
794 /*
795 * If the thermal temperature is greater than the
796 * active threshod, unnecessary to turn off the
797 * the active cooling device.
798 */
799 continue;
800 }
801 /*
802 * Below Threshold?
803 * ----------------
804 * Turn OFF all cooling devices associated with this
805 * threshold.
806 */
807 for (j = 0; j < active->devices.count; j++)
808 result = acpi_bus_set_power(active->devices.handles[j],
809 ACPI_STATE_D3);
810 }
811}
812
772static void acpi_thermal_check(void *data) 813static void acpi_thermal_check(void *data)
773{ 814{
774 int result = 0; 815 int result = 0;
@@ -1624,6 +1665,8 @@ static int acpi_thermal_add(struct acpi_device *device)
1624 1665
1625 init_timer(&tz->timer); 1666 init_timer(&tz->timer);
1626 1667
1668 acpi_thermal_active_off(tz);
1669
1627 acpi_thermal_check(tz); 1670 acpi_thermal_check(tz);
1628 1671
1629 status = acpi_install_notify_handler(device->handle, 1672 status = acpi_install_notify_handler(device->handle,
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index 3dfb8a442b26..e7bf34a7b1d2 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -242,6 +242,10 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
242{ 242{
243 acpi_status status = AE_OK; 243 acpi_status status = AE_OK;
244 244
245 if (!required_length) {
246 WARN_ON(1);
247 return AE_ERROR;
248 }
245 switch (buffer->length) { 249 switch (buffer->length) {
246 case ACPI_NO_BUFFER: 250 case ACPI_NO_BUFFER:
247 251
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 37b9e16710d6..e8a51a1700f7 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -741,7 +741,7 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
741 741
742 max_level = acpi_video_init_brightness(device); 742 max_level = acpi_video_init_brightness(device);
743 743
744 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){ 744 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
745 int result; 745 int result;
746 static int count = 0; 746 static int count = 0;
747 char *name; 747 char *name;
@@ -753,7 +753,17 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
753 device->backlight = backlight_device_register(name, 753 device->backlight = backlight_device_register(name,
754 NULL, device, &acpi_backlight_ops); 754 NULL, device, &acpi_backlight_ops);
755 device->backlight->props.max_brightness = device->brightness->count-3; 755 device->backlight->props.max_brightness = device->brightness->count-3;
756 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight); 756 /*
757 * If there exists the _BQC object, the _BQC object will be
758 * called to get the current backlight brightness. Otherwise
759 * the brightness will be set to the maximum.
760 */
761 if (device->cap._BQC)
762 device->backlight->props.brightness =
763 acpi_video_get_brightness(device->backlight);
764 else
765 device->backlight->props.brightness =
766 device->backlight->props.max_brightness;
757 backlight_update_status(device->backlight); 767 backlight_update_status(device->backlight);
758 kfree(name); 768 kfree(name);
759 769
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index dc7596f028b6..ef3e5522e1a4 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1273,7 +1273,7 @@ static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
1273 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR]; 1273 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1274 u32 em_ctl; 1274 u32 em_ctl;
1275 u32 message[] = {0, 0}; 1275 u32 message[] = {0, 0};
1276 unsigned int flags; 1276 unsigned long flags;
1277 int pmp; 1277 int pmp;
1278 struct ahci_em_priv *emp; 1278 struct ahci_em_priv *emp;
1279 1279
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index d5c1bbfbe79d..73338d231db9 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -2562,7 +2562,8 @@ fore200e_load_and_start_fw(struct fore200e* fore200e)
2562 const struct firmware *firmware; 2562 const struct firmware *firmware;
2563 struct device *device; 2563 struct device *device;
2564 struct fw_header *fw_header; 2564 struct fw_header *fw_header;
2565 u32 *fw_data, fw_size; 2565 const __le32 *fw_data;
2566 u32 fw_size;
2566 u32 __iomem *load_addr; 2567 u32 __iomem *load_addr;
2567 char buf[48]; 2568 char buf[48];
2568 int err = -ENODEV; 2569 int err = -ENODEV;
@@ -2582,7 +2583,7 @@ fore200e_load_and_start_fw(struct fore200e* fore200e)
2582 return err; 2583 return err;
2583 } 2584 }
2584 2585
2585 fw_data = (u32 *) firmware->data; 2586 fw_data = (__le32 *) firmware->data;
2586 fw_size = firmware->size / sizeof(u32); 2587 fw_size = firmware->size / sizeof(u32);
2587 fw_header = (struct fw_header *) firmware->data; 2588 fw_header = (struct fw_header *) firmware->data;
2588 load_addr = fore200e->virt_base + le32_to_cpu(fw_header->load_offset); 2589 load_addr = fore200e->virt_base + le32_to_cpu(fw_header->load_offset);
@@ -3199,6 +3200,14 @@ static const struct fore200e_bus fore200e_bus[] = {
3199 {} 3200 {}
3200}; 3201};
3201 3202
3202#ifdef MODULE_LICENSE
3203MODULE_LICENSE("GPL"); 3203MODULE_LICENSE("GPL");
3204#ifdef CONFIG_PCI
3205#ifdef __LITTLE_ENDIAN__
3206MODULE_FIRMWARE("pca200e.bin");
3207#else
3208MODULE_FIRMWARE("pca200e_ecd.bin2");
3209#endif
3210#endif /* CONFIG_PCI */
3211#ifdef CONFIG_SBUS
3212MODULE_FIRMWARE("sba200e_ecd.bin2");
3204#endif 3213#endif
diff --git a/drivers/auxdisplay/cfag12864b.c b/drivers/auxdisplay/cfag12864b.c
index 683509f013ab..eacb175f6bd3 100644
--- a/drivers/auxdisplay/cfag12864b.c
+++ b/drivers/auxdisplay/cfag12864b.c
@@ -336,16 +336,9 @@ static int __init cfag12864b_init(void)
336 "ks0108 is not initialized\n"); 336 "ks0108 is not initialized\n");
337 goto none; 337 goto none;
338 } 338 }
339 BUILD_BUG_ON(PAGE_SIZE < CFAG12864B_SIZE);
339 340
340 if (PAGE_SIZE < CFAG12864B_SIZE) { 341 cfag12864b_buffer = (unsigned char *) get_zeroed_page(GFP_KERNEL);
341 printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
342 "page size (%i) < cfag12864b size (%i)\n",
343 (unsigned int)PAGE_SIZE, CFAG12864B_SIZE);
344 ret = -ENOMEM;
345 goto none;
346 }
347
348 cfag12864b_buffer = (unsigned char *) __get_free_page(GFP_KERNEL);
349 if (cfag12864b_buffer == NULL) { 342 if (cfag12864b_buffer == NULL) {
350 printk(KERN_ERR CFAG12864B_NAME ": ERROR: " 343 printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
351 "can't get a free page\n"); 344 "can't get a free page\n");
@@ -367,8 +360,6 @@ static int __init cfag12864b_init(void)
367 if (cfag12864b_workqueue == NULL) 360 if (cfag12864b_workqueue == NULL)
368 goto cachealloced; 361 goto cachealloced;
369 362
370 memset(cfag12864b_buffer, 0, CFAG12864B_SIZE);
371
372 cfag12864b_clear(); 363 cfag12864b_clear();
373 cfag12864b_on(); 364 cfag12864b_on();
374 365
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 7d5c63c81a59..068aa1c9538c 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -116,12 +116,10 @@ static void device_release(struct kobject *kobj)
116 dev->type->release(dev); 116 dev->type->release(dev);
117 else if (dev->class && dev->class->dev_release) 117 else if (dev->class && dev->class->dev_release)
118 dev->class->dev_release(dev); 118 dev->class->dev_release(dev);
119 else { 119 else
120 printk(KERN_ERR "Device '%s' does not have a release() " 120 WARN(1, KERN_ERR "Device '%s' does not have a release() "
121 "function, it is broken and must be fixed.\n", 121 "function, it is broken and must be fixed.\n",
122 dev->bus_id); 122 dev->bus_id);
123 WARN_ON(1);
124 }
125} 123}
126 124
127static struct kobj_type device_ktype = { 125static struct kobj_type device_ktype = {
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 20537d507909..64f5d54f7edc 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -121,14 +121,14 @@ static ssize_t print_cpus_##type(struct sysdev_class *class, char *buf) \
121{ \ 121{ \
122 return print_cpus_map(buf, &cpu_##type##_map); \ 122 return print_cpus_map(buf, &cpu_##type##_map); \
123} \ 123} \
124struct sysdev_class_attribute attr_##type##_map = \ 124static struct sysdev_class_attribute attr_##type##_map = \
125 _SYSDEV_CLASS_ATTR(type, 0444, print_cpus_##type, NULL) 125 _SYSDEV_CLASS_ATTR(type, 0444, print_cpus_##type, NULL)
126 126
127print_cpus_func(online); 127print_cpus_func(online);
128print_cpus_func(possible); 128print_cpus_func(possible);
129print_cpus_func(present); 129print_cpus_func(present);
130 130
131struct sysdev_class_attribute *cpu_state_attr[] = { 131static struct sysdev_class_attribute *cpu_state_attr[] = {
132 &attr_online_map, 132 &attr_online_map,
133 &attr_possible_map, 133 &attr_possible_map,
134 &attr_present_map, 134 &attr_present_map,
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index b0be1d18fee2..c9c92b00fd55 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -184,7 +184,7 @@ firmware_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
184 struct device *dev = to_dev(kobj); 184 struct device *dev = to_dev(kobj);
185 struct firmware_priv *fw_priv = dev_get_drvdata(dev); 185 struct firmware_priv *fw_priv = dev_get_drvdata(dev);
186 struct firmware *fw; 186 struct firmware *fw;
187 ssize_t ret_count = count; 187 ssize_t ret_count;
188 188
189 mutex_lock(&fw_lock); 189 mutex_lock(&fw_lock);
190 fw = fw_priv->fw; 190 fw = fw_priv->fw;
@@ -192,14 +192,8 @@ firmware_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
192 ret_count = -ENODEV; 192 ret_count = -ENODEV;
193 goto out; 193 goto out;
194 } 194 }
195 if (offset > fw->size) { 195 ret_count = memory_read_from_buffer(buffer, count, &offset,
196 ret_count = 0; 196 fw->data, fw->size);
197 goto out;
198 }
199 if (offset + ret_count > fw->size)
200 ret_count = fw->size - offset;
201
202 memcpy(buffer, fw->data + offset, ret_count);
203out: 197out:
204 mutex_unlock(&fw_lock); 198 mutex_unlock(&fw_lock);
205 return ret_count; 199 return ret_count;
diff --git a/drivers/base/isa.c b/drivers/base/isa.c
index d2222397a401..efd577574948 100644
--- a/drivers/base/isa.c
+++ b/drivers/base/isa.c
@@ -7,6 +7,7 @@
7#include <linux/slab.h> 7#include <linux/slab.h>
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/init.h> 9#include <linux/init.h>
10#include <linux/dma-mapping.h>
10#include <linux/isa.h> 11#include <linux/isa.h>
11 12
12static struct device isa_bus = { 13static struct device isa_bus = {
@@ -141,6 +142,9 @@ int isa_register_driver(struct isa_driver *isa_driver, unsigned int ndev)
141 isa_dev->dev.release = isa_dev_release; 142 isa_dev->dev.release = isa_dev_release;
142 isa_dev->id = id; 143 isa_dev->id = id;
143 144
145 isa_dev->dev.coherent_dma_mask = DMA_24BIT_MASK;
146 isa_dev->dev.dma_mask = &isa_dev->dev.coherent_dma_mask;
147
144 error = device_register(&isa_dev->dev); 148 error = device_register(&isa_dev->dev);
145 if (error) { 149 if (error) {
146 put_device(&isa_dev->dev); 150 put_device(&isa_dev->dev);
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 4d4e0e7b6e92..3ad49a00029f 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -101,6 +101,21 @@ static ssize_t show_mem_phys_index(struct sys_device *dev,
101} 101}
102 102
103/* 103/*
104 * Show whether the section of memory is likely to be hot-removable
105 */
106static ssize_t show_mem_removable(struct sys_device *dev, char *buf)
107{
108 unsigned long start_pfn;
109 int ret;
110 struct memory_block *mem =
111 container_of(dev, struct memory_block, sysdev);
112
113 start_pfn = section_nr_to_pfn(mem->phys_index);
114 ret = is_mem_section_removable(start_pfn, PAGES_PER_SECTION);
115 return sprintf(buf, "%d\n", ret);
116}
117
118/*
104 * online, offline, going offline, etc. 119 * online, offline, going offline, etc.
105 */ 120 */
106static ssize_t show_mem_state(struct sys_device *dev, 121static ssize_t show_mem_state(struct sys_device *dev,
@@ -189,9 +204,8 @@ memory_block_action(struct memory_block *mem, unsigned long action)
189 } 204 }
190 break; 205 break;
191 default: 206 default:
192 printk(KERN_WARNING "%s(%p, %ld) unknown action: %ld\n", 207 WARN(1, KERN_WARNING "%s(%p, %ld) unknown action: %ld\n",
193 __func__, mem, action, action); 208 __func__, mem, action, action);
194 WARN_ON(1);
195 ret = -EINVAL; 209 ret = -EINVAL;
196 } 210 }
197 211
@@ -262,6 +276,7 @@ static ssize_t show_phys_device(struct sys_device *dev,
262static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL); 276static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL);
263static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state); 277static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state);
264static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL); 278static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL);
279static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL);
265 280
266#define mem_create_simple_file(mem, attr_name) \ 281#define mem_create_simple_file(mem, attr_name) \
267 sysdev_create_file(&mem->sysdev, &attr_##attr_name) 282 sysdev_create_file(&mem->sysdev, &attr_##attr_name)
@@ -350,6 +365,8 @@ static int add_memory_block(unsigned long node_id, struct mem_section *section,
350 ret = mem_create_simple_file(mem, state); 365 ret = mem_create_simple_file(mem, state);
351 if (!ret) 366 if (!ret)
352 ret = mem_create_simple_file(mem, phys_device); 367 ret = mem_create_simple_file(mem, phys_device);
368 if (!ret)
369 ret = mem_create_simple_file(mem, removable);
353 370
354 return ret; 371 return ret;
355} 372}
@@ -394,6 +411,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
394 mem_remove_simple_file(mem, phys_index); 411 mem_remove_simple_file(mem, phys_index);
395 mem_remove_simple_file(mem, state); 412 mem_remove_simple_file(mem, state);
396 mem_remove_simple_file(mem, phys_device); 413 mem_remove_simple_file(mem, phys_device);
414 mem_remove_simple_file(mem, removable);
397 unregister_memory(mem, section); 415 unregister_memory(mem, section);
398 416
399 return 0; 417 return 0;
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 40fc14f03540..75dd6e22faff 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -168,19 +168,16 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv)
168 int err = 0; 168 int err = 0;
169 169
170 if (!cls) { 170 if (!cls) {
171 printk(KERN_WARNING "sysdev: invalid class passed to " 171 WARN(1, KERN_WARNING "sysdev: invalid class passed to "
172 "sysdev_driver_register!\n"); 172 "sysdev_driver_register!\n");
173 WARN_ON(1);
174 return -EINVAL; 173 return -EINVAL;
175 } 174 }
176 175
177 /* Check whether this driver has already been added to a class. */ 176 /* Check whether this driver has already been added to a class. */
178 if (drv->entry.next && !list_empty(&drv->entry)) { 177 if (drv->entry.next && !list_empty(&drv->entry))
179 printk(KERN_WARNING "sysdev: class %s: driver (%p) has already" 178 WARN(1, KERN_WARNING "sysdev: class %s: driver (%p) has already"
180 " been registered to a class, something is wrong, but " 179 " been registered to a class, something is wrong, but "
181 "will forge on!\n", cls->name, drv); 180 "will forge on!\n", cls->name, drv);
182 WARN_ON(1);
183 }
184 181
185 mutex_lock(&sysdev_drivers_lock); 182 mutex_lock(&sysdev_drivers_lock);
186 if (cls && kset_get(&cls->kset)) { 183 if (cls && kset_get(&cls->kset)) {
@@ -194,8 +191,7 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv)
194 } 191 }
195 } else { 192 } else {
196 err = -EINVAL; 193 err = -EINVAL;
197 printk(KERN_ERR "%s: invalid device class\n", __func__); 194 WARN(1, KERN_ERR "%s: invalid device class\n", __func__);
198 WARN_ON(1);
199 } 195 }
200 mutex_unlock(&sysdev_drivers_lock); 196 mutex_unlock(&sysdev_drivers_lock);
201 return err; 197 return err;
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index c04440cd6a32..181ebb85f0be 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -6,6 +6,7 @@
6 6
7#include <linux/hdreg.h> 7#include <linux/hdreg.h>
8#include <linux/blkdev.h> 8#include <linux/blkdev.h>
9#include <linux/completion.h>
9#include <linux/delay.h> 10#include <linux/delay.h>
10#include <linux/smp_lock.h> 11#include <linux/smp_lock.h>
11#include "aoe.h" 12#include "aoe.h"
@@ -36,7 +37,7 @@ struct ErrMsg {
36 37
37static struct ErrMsg emsgs[NMSG]; 38static struct ErrMsg emsgs[NMSG];
38static int emsgs_head_idx, emsgs_tail_idx; 39static int emsgs_head_idx, emsgs_tail_idx;
39static struct semaphore emsgs_sema; 40static struct completion emsgs_comp;
40static spinlock_t emsgs_lock; 41static spinlock_t emsgs_lock;
41static int nblocked_emsgs_readers; 42static int nblocked_emsgs_readers;
42static struct class *aoe_class; 43static struct class *aoe_class;
@@ -141,7 +142,7 @@ bail: spin_unlock_irqrestore(&emsgs_lock, flags);
141 spin_unlock_irqrestore(&emsgs_lock, flags); 142 spin_unlock_irqrestore(&emsgs_lock, flags);
142 143
143 if (nblocked_emsgs_readers) 144 if (nblocked_emsgs_readers)
144 up(&emsgs_sema); 145 complete(&emsgs_comp);
145} 146}
146 147
147static ssize_t 148static ssize_t
@@ -221,7 +222,7 @@ aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
221 222
222 spin_unlock_irqrestore(&emsgs_lock, flags); 223 spin_unlock_irqrestore(&emsgs_lock, flags);
223 224
224 n = down_interruptible(&emsgs_sema); 225 n = wait_for_completion_interruptible(&emsgs_comp);
225 226
226 spin_lock_irqsave(&emsgs_lock, flags); 227 spin_lock_irqsave(&emsgs_lock, flags);
227 228
@@ -269,7 +270,7 @@ aoechr_init(void)
269 printk(KERN_ERR "aoe: can't register char device\n"); 270 printk(KERN_ERR "aoe: can't register char device\n");
270 return n; 271 return n;
271 } 272 }
272 sema_init(&emsgs_sema, 0); 273 init_completion(&emsgs_comp);
273 spin_lock_init(&emsgs_lock); 274 spin_lock_init(&emsgs_lock);
274 aoe_class = class_create(THIS_MODULE, "aoe"); 275 aoe_class = class_create(THIS_MODULE, "aoe");
275 if (IS_ERR(aoe_class)) { 276 if (IS_ERR(aoe_class)) {
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index dd7ea203f940..42251095134f 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -196,6 +196,7 @@ static int virtblk_probe(struct virtio_device *vdev)
196 int err; 196 int err;
197 u64 cap; 197 u64 cap;
198 u32 v; 198 u32 v;
199 u32 blk_size;
199 200
200 if (index_to_minor(index) >= 1 << MINORBITS) 201 if (index_to_minor(index) >= 1 << MINORBITS)
201 return -ENOSPC; 202 return -ENOSPC;
@@ -290,6 +291,13 @@ static int virtblk_probe(struct virtio_device *vdev)
290 if (!err) 291 if (!err)
291 blk_queue_max_hw_segments(vblk->disk->queue, v); 292 blk_queue_max_hw_segments(vblk->disk->queue, v);
292 293
294 /* Host can optionally specify the block size of the device */
295 err = virtio_config_val(vdev, VIRTIO_BLK_F_BLK_SIZE,
296 offsetof(struct virtio_blk_config, blk_size),
297 &blk_size);
298 if (!err)
299 blk_queue_hardsect_size(vblk->disk->queue, blk_size);
300
293 add_disk(vblk->disk); 301 add_disk(vblk->disk);
294 return 0; 302 return 0;
295 303
@@ -330,7 +338,7 @@ static struct virtio_device_id id_table[] = {
330 338
331static unsigned int features[] = { 339static unsigned int features[] = {
332 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, 340 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX,
333 VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, 341 VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE,
334}; 342};
335 343
336static struct virtio_driver virtio_blk = { 344static struct virtio_driver virtio_blk = {
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index e0bbbfb6a36b..d0ac944e1696 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -36,6 +36,14 @@ config VT
36 If unsure, say Y, or else you won't be able to do much with your new 36 If unsure, say Y, or else you won't be able to do much with your new
37 shiny Linux system :-) 37 shiny Linux system :-)
38 38
39config CONSOLE_TRANSLATIONS
40 depends on VT
41 default y
42 bool "Enable character translations in console" if EMBEDDED
43 ---help---
44 This enables support for font mapping and Unicode translation
45 on virtual consoles.
46
39config VT_CONSOLE 47config VT_CONSOLE
40 bool "Support for console on virtual terminal" if EMBEDDED 48 bool "Support for console on virtual terminal" if EMBEDDED
41 depends on VT 49 depends on VT
@@ -578,11 +586,14 @@ config HVC_DRIVER
578 It will automatically be selected if one of the back-end console drivers 586 It will automatically be selected if one of the back-end console drivers
579 is selected. 587 is selected.
580 588
589config HVC_IRQ
590 bool
581 591
582config HVC_CONSOLE 592config HVC_CONSOLE
583 bool "pSeries Hypervisor Virtual Console support" 593 bool "pSeries Hypervisor Virtual Console support"
584 depends on PPC_PSERIES 594 depends on PPC_PSERIES
585 select HVC_DRIVER 595 select HVC_DRIVER
596 select HVC_IRQ
586 help 597 help
587 pSeries machines when partitioned support a hypervisor virtual 598 pSeries machines when partitioned support a hypervisor virtual
588 console. This driver allows each pSeries partition to have a console 599 console. This driver allows each pSeries partition to have a console
@@ -593,6 +604,7 @@ config HVC_ISERIES
593 depends on PPC_ISERIES 604 depends on PPC_ISERIES
594 default y 605 default y
595 select HVC_DRIVER 606 select HVC_DRIVER
607 select HVC_IRQ
596 help 608 help
597 iSeries machines support a hypervisor virtual console. 609 iSeries machines support a hypervisor virtual console.
598 610
@@ -614,13 +626,18 @@ config HVC_XEN
614 bool "Xen Hypervisor Console support" 626 bool "Xen Hypervisor Console support"
615 depends on XEN 627 depends on XEN
616 select HVC_DRIVER 628 select HVC_DRIVER
629 select HVC_IRQ
617 default y 630 default y
618 help 631 help
619 Xen virtual console device driver 632 Xen virtual console device driver
620 633
621config VIRTIO_CONSOLE 634config VIRTIO_CONSOLE
622 bool 635 tristate "Virtio console"
636 depends on VIRTIO
623 select HVC_DRIVER 637 select HVC_DRIVER
638 help
639 Virtio console for use with lguest and other hypervisors.
640
624 641
625config HVCS 642config HVCS
626 tristate "IBM Hypervisor Virtual Console Server support" 643 tristate "IBM Hypervisor Virtual Console Server support"
@@ -857,13 +874,6 @@ config DS1302
857 874
858endif # RTC_LIB 875endif # RTC_LIB
859 876
860config COBALT_LCD
861 bool "Support for Cobalt LCD"
862 depends on MIPS_COBALT
863 help
864 This option enables support for the LCD display and buttons found
865 on Cobalt systems through a misc device.
866
867config DTLK 877config DTLK
868 tristate "Double Talk PC internal speech card support" 878 tristate "Double Talk PC internal speech card support"
869 depends on ISA 879 depends on ISA
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index dc5a327d72d5..8a161c30e1dc 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -12,8 +12,8 @@ obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o
12obj-$(CONFIG_LEGACY_PTYS) += pty.o 12obj-$(CONFIG_LEGACY_PTYS) += pty.o
13obj-$(CONFIG_UNIX98_PTYS) += pty.o 13obj-$(CONFIG_UNIX98_PTYS) += pty.o
14obj-y += misc.o 14obj-y += misc.o
15obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o consolemap.o \ 15obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o
16 consolemap_deftbl.o selection.o keyboard.o 16obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o
17obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o 17obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
18obj-$(CONFIG_AUDIT) += tty_audit.o 18obj-$(CONFIG_AUDIT) += tty_audit.o
19obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o 19obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o
@@ -48,6 +48,7 @@ obj-$(CONFIG_HVC_ISERIES) += hvc_iseries.o
48obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o 48obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o
49obj-$(CONFIG_HVC_BEAT) += hvc_beat.o 49obj-$(CONFIG_HVC_BEAT) += hvc_beat.o
50obj-$(CONFIG_HVC_DRIVER) += hvc_console.o 50obj-$(CONFIG_HVC_DRIVER) += hvc_console.o
51obj-$(CONFIG_HVC_IRQ) += hvc_irq.o
51obj-$(CONFIG_HVC_XEN) += hvc_xen.o 52obj-$(CONFIG_HVC_XEN) += hvc_xen.o
52obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o 53obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o
53obj-$(CONFIG_RAW_DRIVER) += raw.o 54obj-$(CONFIG_RAW_DRIVER) += raw.o
@@ -63,7 +64,6 @@ obj-$(CONFIG_BRIQ_PANEL) += briq_panel.o
63obj-$(CONFIG_BFIN_OTP) += bfin-otp.o 64obj-$(CONFIG_BFIN_OTP) += bfin-otp.o
64 65
65obj-$(CONFIG_PRINTER) += lp.o 66obj-$(CONFIG_PRINTER) += lp.o
66obj-$(CONFIG_TIPAR) += tipar.o
67 67
68obj-$(CONFIG_APM_EMULATION) += apm-emulation.o 68obj-$(CONFIG_APM_EMULATION) += apm-emulation.o
69 69
@@ -88,7 +88,6 @@ obj-$(CONFIG_TOSHIBA) += toshiba.o
88obj-$(CONFIG_I8K) += i8k.o 88obj-$(CONFIG_I8K) += i8k.o
89obj-$(CONFIG_DS1620) += ds1620.o 89obj-$(CONFIG_DS1620) += ds1620.o
90obj-$(CONFIG_HW_RANDOM) += hw_random/ 90obj-$(CONFIG_HW_RANDOM) += hw_random/
91obj-$(CONFIG_COBALT_LCD) += lcd.o
92obj-$(CONFIG_PPDEV) += ppdev.o 91obj-$(CONFIG_PPDEV) += ppdev.o
93obj-$(CONFIG_NWBUTTON) += nwbutton.o 92obj-$(CONFIG_NWBUTTON) += nwbutton.o
94obj-$(CONFIG_NWFLASH) += nwflash.o 93obj-$(CONFIG_NWFLASH) += nwflash.o
diff --git a/drivers/char/ds1302.c b/drivers/char/ds1302.c
index fada6ddefbae..c5e67a623951 100644
--- a/drivers/char/ds1302.c
+++ b/drivers/char/ds1302.c
@@ -20,10 +20,11 @@
20#include <linux/miscdevice.h> 20#include <linux/miscdevice.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/bcd.h> 22#include <linux/bcd.h>
23#include <linux/smp_lock.h>
24#include <linux/uaccess.h>
25#include <linux/io.h>
23 26
24#include <asm/uaccess.h>
25#include <asm/system.h> 27#include <asm/system.h>
26#include <asm/io.h>
27#include <asm/rtc.h> 28#include <asm/rtc.h>
28#if defined(CONFIG_M32R) 29#if defined(CONFIG_M32R)
29#include <asm/m32r.h> 30#include <asm/m32r.h>
@@ -153,9 +154,7 @@ static unsigned char days_in_mo[] =
153 154
154/* ioctl that supports RTC_RD_TIME and RTC_SET_TIME (read and set time/date). */ 155/* ioctl that supports RTC_RD_TIME and RTC_SET_TIME (read and set time/date). */
155 156
156static int 157static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
157rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
158 unsigned long arg)
159{ 158{
160 unsigned long flags; 159 unsigned long flags;
161 160
@@ -165,7 +164,9 @@ rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
165 struct rtc_time rtc_tm; 164 struct rtc_time rtc_tm;
166 165
167 memset(&rtc_tm, 0, sizeof (struct rtc_time)); 166 memset(&rtc_tm, 0, sizeof (struct rtc_time));
167 lock_kernel();
168 get_rtc_time(&rtc_tm); 168 get_rtc_time(&rtc_tm);
169 unlock_kernel();
169 if (copy_to_user((struct rtc_time*)arg, &rtc_tm, sizeof(struct rtc_time))) 170 if (copy_to_user((struct rtc_time*)arg, &rtc_tm, sizeof(struct rtc_time)))
170 return -EFAULT; 171 return -EFAULT;
171 return 0; 172 return 0;
@@ -217,6 +218,7 @@ rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
217 BIN_TO_BCD(mon); 218 BIN_TO_BCD(mon);
218 BIN_TO_BCD(yrs); 219 BIN_TO_BCD(yrs);
219 220
221 lock_kernel();
220 local_irq_save(flags); 222 local_irq_save(flags);
221 CMOS_WRITE(yrs, RTC_YEAR); 223 CMOS_WRITE(yrs, RTC_YEAR);
222 CMOS_WRITE(mon, RTC_MONTH); 224 CMOS_WRITE(mon, RTC_MONTH);
@@ -225,6 +227,7 @@ rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
225 CMOS_WRITE(min, RTC_MINUTES); 227 CMOS_WRITE(min, RTC_MINUTES);
226 CMOS_WRITE(sec, RTC_SECONDS); 228 CMOS_WRITE(sec, RTC_SECONDS);
227 local_irq_restore(flags); 229 local_irq_restore(flags);
230 unlock_kernel();
228 231
229 /* Notice that at this point, the RTC is updated but 232 /* Notice that at this point, the RTC is updated but
230 * the kernel is still running with the old time. 233 * the kernel is still running with the old time.
@@ -244,8 +247,10 @@ rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
244 if(copy_from_user(&tcs_val, (int*)arg, sizeof(int))) 247 if(copy_from_user(&tcs_val, (int*)arg, sizeof(int)))
245 return -EFAULT; 248 return -EFAULT;
246 249
250 lock_kernel();
247 tcs_val = RTC_TCR_PATTERN | (tcs_val & 0x0F); 251 tcs_val = RTC_TCR_PATTERN | (tcs_val & 0x0F);
248 ds1302_writereg(RTC_TRICKLECHARGER, tcs_val); 252 ds1302_writereg(RTC_TRICKLECHARGER, tcs_val);
253 unlock_kernel();
249 return 0; 254 return 0;
250 } 255 }
251 default: 256 default:
@@ -282,7 +287,7 @@ get_rtc_status(char *buf)
282 287
283static const struct file_operations rtc_fops = { 288static const struct file_operations rtc_fops = {
284 .owner = THIS_MODULE, 289 .owner = THIS_MODULE,
285 .ioctl = rtc_ioctl, 290 .unlocked_ioctl = rtc_ioctl,
286}; 291};
287 292
288/* Probe for the chip by writing something to its RAM and try reading it back. */ 293/* Probe for the chip by writing something to its RAM and try reading it back. */
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index 33c466a4888f..ca7c72a486b2 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -36,10 +36,10 @@
36#include <linux/smp_lock.h> 36#include <linux/smp_lock.h>
37#include <linux/firmware.h> 37#include <linux/firmware.h>
38#include <linux/platform_device.h> 38#include <linux/platform_device.h>
39#include <linux/uaccess.h> /* For put_user and get_user */
39 40
40#include <asm/atarihw.h> 41#include <asm/atarihw.h>
41#include <asm/traps.h> 42#include <asm/traps.h>
42#include <asm/uaccess.h> /* For put_user and get_user */
43 43
44#include <asm/dsp56k.h> 44#include <asm/dsp56k.h>
45 45
@@ -303,10 +303,10 @@ static ssize_t dsp56k_write(struct file *file, const char __user *buf, size_t co
303 } 303 }
304} 304}
305 305
306static int dsp56k_ioctl(struct inode *inode, struct file *file, 306static long dsp56k_ioctl(struct file *file, unsigned int cmd,
307 unsigned int cmd, unsigned long arg) 307 unsigned long arg)
308{ 308{
309 int dev = iminor(inode) & 0x0f; 309 int dev = iminor(file->f_path.dentry->d_inode) & 0x0f;
310 void __user *argp = (void __user *)arg; 310 void __user *argp = (void __user *)arg;
311 311
312 switch(dev) 312 switch(dev)
@@ -331,8 +331,9 @@ static int dsp56k_ioctl(struct inode *inode, struct file *file,
331 if (len > DSP56K_MAX_BINARY_LENGTH) { 331 if (len > DSP56K_MAX_BINARY_LENGTH) {
332 return -EINVAL; 332 return -EINVAL;
333 } 333 }
334 334 lock_kernel();
335 r = dsp56k_upload(bin, len); 335 r = dsp56k_upload(bin, len);
336 unlock_kernel();
336 if (r < 0) { 337 if (r < 0) {
337 return r; 338 return r;
338 } 339 }
@@ -342,12 +343,16 @@ static int dsp56k_ioctl(struct inode *inode, struct file *file,
342 case DSP56K_SET_TX_WSIZE: 343 case DSP56K_SET_TX_WSIZE:
343 if (arg > 4 || arg < 1) 344 if (arg > 4 || arg < 1)
344 return -EINVAL; 345 return -EINVAL;
346 lock_kernel();
345 dsp56k.tx_wsize = (int) arg; 347 dsp56k.tx_wsize = (int) arg;
348 unlock_kernel();
346 break; 349 break;
347 case DSP56K_SET_RX_WSIZE: 350 case DSP56K_SET_RX_WSIZE:
348 if (arg > 4 || arg < 1) 351 if (arg > 4 || arg < 1)
349 return -EINVAL; 352 return -EINVAL;
353 lock_kernel();
350 dsp56k.rx_wsize = (int) arg; 354 dsp56k.rx_wsize = (int) arg;
355 unlock_kernel();
351 break; 356 break;
352 case DSP56K_HOST_FLAGS: 357 case DSP56K_HOST_FLAGS:
353 { 358 {
@@ -359,6 +364,7 @@ static int dsp56k_ioctl(struct inode *inode, struct file *file,
359 if(get_user(out, &hf->out) < 0) 364 if(get_user(out, &hf->out) < 0)
360 return -EFAULT; 365 return -EFAULT;
361 366
367 lock_kernel();
362 if ((dir & 0x1) && (out & 0x1)) 368 if ((dir & 0x1) && (out & 0x1))
363 dsp56k_host_interface.icr |= DSP56K_ICR_HF0; 369 dsp56k_host_interface.icr |= DSP56K_ICR_HF0;
364 else if (dir & 0x1) 370 else if (dir & 0x1)
@@ -373,14 +379,16 @@ static int dsp56k_ioctl(struct inode *inode, struct file *file,
373 if (dsp56k_host_interface.icr & DSP56K_ICR_HF1) status |= 0x2; 379 if (dsp56k_host_interface.icr & DSP56K_ICR_HF1) status |= 0x2;
374 if (dsp56k_host_interface.isr & DSP56K_ISR_HF2) status |= 0x4; 380 if (dsp56k_host_interface.isr & DSP56K_ISR_HF2) status |= 0x4;
375 if (dsp56k_host_interface.isr & DSP56K_ISR_HF3) status |= 0x8; 381 if (dsp56k_host_interface.isr & DSP56K_ISR_HF3) status |= 0x8;
376 382 unlock_kernel();
377 return put_user(status, &hf->status); 383 return put_user(status, &hf->status);
378 } 384 }
379 case DSP56K_HOST_CMD: 385 case DSP56K_HOST_CMD:
380 if (arg > 31 || arg < 0) 386 if (arg > 31 || arg < 0)
381 return -EINVAL; 387 return -EINVAL;
388 lock_kernel();
382 dsp56k_host_interface.cvr = (u_char)((arg & DSP56K_CVR_HV_MASK) | 389 dsp56k_host_interface.cvr = (u_char)((arg & DSP56K_CVR_HV_MASK) |
383 DSP56K_CVR_HC); 390 DSP56K_CVR_HC);
391 unlock_kernel();
384 break; 392 break;
385 default: 393 default:
386 return -EINVAL; 394 return -EINVAL;
@@ -472,7 +480,7 @@ static const struct file_operations dsp56k_fops = {
472 .owner = THIS_MODULE, 480 .owner = THIS_MODULE,
473 .read = dsp56k_read, 481 .read = dsp56k_read,
474 .write = dsp56k_write, 482 .write = dsp56k_write,
475 .ioctl = dsp56k_ioctl, 483 .unlocked_ioctl = dsp56k_ioctl,
476 .open = dsp56k_open, 484 .open = dsp56k_open,
477 .release = dsp56k_release, 485 .release = dsp56k_release,
478}; 486};
diff --git a/drivers/char/efirtc.c b/drivers/char/efirtc.c
index d57ca3e4e534..67fbd7aab5db 100644
--- a/drivers/char/efirtc.c
+++ b/drivers/char/efirtc.c
@@ -37,8 +37,9 @@
37#include <linux/rtc.h> 37#include <linux/rtc.h>
38#include <linux/proc_fs.h> 38#include <linux/proc_fs.h>
39#include <linux/efi.h> 39#include <linux/efi.h>
40#include <linux/smp_lock.h>
41#include <linux/uaccess.h>
40 42
41#include <asm/uaccess.h>
42#include <asm/system.h> 43#include <asm/system.h>
43 44
44#define EFI_RTC_VERSION "0.4" 45#define EFI_RTC_VERSION "0.4"
@@ -51,8 +52,8 @@
51 52
52static DEFINE_SPINLOCK(efi_rtc_lock); 53static DEFINE_SPINLOCK(efi_rtc_lock);
53 54
54static int efi_rtc_ioctl(struct inode *inode, struct file *file, 55static long efi_rtc_ioctl(struct file *file, unsigned int cmd,
55 unsigned int cmd, unsigned long arg); 56 unsigned long arg);
56 57
57#define is_leap(year) \ 58#define is_leap(year) \
58 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) 59 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
@@ -146,9 +147,8 @@ convert_from_efi_time(efi_time_t *eft, struct rtc_time *wtime)
146 } 147 }
147} 148}
148 149
149static int 150static long efi_rtc_ioctl(struct file *file, unsigned int cmd,
150efi_rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 151 unsigned long arg)
151 unsigned long arg)
152{ 152{
153 153
154 efi_status_t status; 154 efi_status_t status;
@@ -175,13 +175,13 @@ efi_rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
175 return -EINVAL; 175 return -EINVAL;
176 176
177 case RTC_RD_TIME: 177 case RTC_RD_TIME:
178 178 lock_kernel();
179 spin_lock_irqsave(&efi_rtc_lock, flags); 179 spin_lock_irqsave(&efi_rtc_lock, flags);
180 180
181 status = efi.get_time(&eft, &cap); 181 status = efi.get_time(&eft, &cap);
182 182
183 spin_unlock_irqrestore(&efi_rtc_lock,flags); 183 spin_unlock_irqrestore(&efi_rtc_lock,flags);
184 184 unlock_kernel();
185 if (status != EFI_SUCCESS) { 185 if (status != EFI_SUCCESS) {
186 /* should never happen */ 186 /* should never happen */
187 printk(KERN_ERR "efitime: can't read time\n"); 187 printk(KERN_ERR "efitime: can't read time\n");
@@ -203,11 +203,13 @@ efi_rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
203 203
204 convert_to_efi_time(&wtime, &eft); 204 convert_to_efi_time(&wtime, &eft);
205 205
206 lock_kernel();
206 spin_lock_irqsave(&efi_rtc_lock, flags); 207 spin_lock_irqsave(&efi_rtc_lock, flags);
207 208
208 status = efi.set_time(&eft); 209 status = efi.set_time(&eft);
209 210
210 spin_unlock_irqrestore(&efi_rtc_lock,flags); 211 spin_unlock_irqrestore(&efi_rtc_lock,flags);
212 unlock_kernel();
211 213
212 return status == EFI_SUCCESS ? 0 : -EINVAL; 214 return status == EFI_SUCCESS ? 0 : -EINVAL;
213 215
@@ -223,6 +225,7 @@ efi_rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
223 225
224 convert_to_efi_time(&wtime, &eft); 226 convert_to_efi_time(&wtime, &eft);
225 227
228 lock_kernel();
226 spin_lock_irqsave(&efi_rtc_lock, flags); 229 spin_lock_irqsave(&efi_rtc_lock, flags);
227 /* 230 /*
228 * XXX Fixme: 231 * XXX Fixme:
@@ -233,16 +236,19 @@ efi_rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
233 status = efi.set_wakeup_time((efi_bool_t)enabled, &eft); 236 status = efi.set_wakeup_time((efi_bool_t)enabled, &eft);
234 237
235 spin_unlock_irqrestore(&efi_rtc_lock,flags); 238 spin_unlock_irqrestore(&efi_rtc_lock,flags);
239 unlock_kernel();
236 240
237 return status == EFI_SUCCESS ? 0 : -EINVAL; 241 return status == EFI_SUCCESS ? 0 : -EINVAL;
238 242
239 case RTC_WKALM_RD: 243 case RTC_WKALM_RD:
240 244
245 lock_kernel();
241 spin_lock_irqsave(&efi_rtc_lock, flags); 246 spin_lock_irqsave(&efi_rtc_lock, flags);
242 247
243 status = efi.get_wakeup_time((efi_bool_t *)&enabled, (efi_bool_t *)&pending, &eft); 248 status = efi.get_wakeup_time((efi_bool_t *)&enabled, (efi_bool_t *)&pending, &eft);
244 249
245 spin_unlock_irqrestore(&efi_rtc_lock,flags); 250 spin_unlock_irqrestore(&efi_rtc_lock,flags);
251 unlock_kernel();
246 252
247 if (status != EFI_SUCCESS) return -EINVAL; 253 if (status != EFI_SUCCESS) return -EINVAL;
248 254
@@ -256,7 +262,7 @@ efi_rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
256 return copy_to_user(&ewp->time, &wtime, 262 return copy_to_user(&ewp->time, &wtime,
257 sizeof(struct rtc_time)) ? -EFAULT : 0; 263 sizeof(struct rtc_time)) ? -EFAULT : 0;
258 } 264 }
259 return -EINVAL; 265 return -ENOTTY;
260} 266}
261 267
262/* 268/*
@@ -265,8 +271,7 @@ efi_rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
265 * up things on a close. 271 * up things on a close.
266 */ 272 */
267 273
268static int 274static int efi_rtc_open(struct inode *inode, struct file *file)
269efi_rtc_open(struct inode *inode, struct file *file)
270{ 275{
271 /* 276 /*
272 * nothing special to do here 277 * nothing special to do here
@@ -277,8 +282,7 @@ efi_rtc_open(struct inode *inode, struct file *file)
277 return 0; 282 return 0;
278} 283}
279 284
280static int 285static int efi_rtc_close(struct inode *inode, struct file *file)
281efi_rtc_close(struct inode *inode, struct file *file)
282{ 286{
283 return 0; 287 return 0;
284} 288}
@@ -289,13 +293,12 @@ efi_rtc_close(struct inode *inode, struct file *file)
289 293
290static const struct file_operations efi_rtc_fops = { 294static const struct file_operations efi_rtc_fops = {
291 .owner = THIS_MODULE, 295 .owner = THIS_MODULE,
292 .ioctl = efi_rtc_ioctl, 296 .unlocked_ioctl = efi_rtc_ioctl,
293 .open = efi_rtc_open, 297 .open = efi_rtc_open,
294 .release = efi_rtc_close, 298 .release = efi_rtc_close,
295}; 299};
296 300
297static struct miscdevice efi_rtc_dev= 301static struct miscdevice efi_rtc_dev= {
298{
299 EFI_RTC_MINOR, 302 EFI_RTC_MINOR,
300 "efirtc", 303 "efirtc",
301 &efi_rtc_fops 304 &efi_rtc_fops
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index fb0a85a1eb36..b3f5dbc6d880 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -623,6 +623,7 @@ static inline int hpet_tpcheck(struct hpet_task *tp)
623 return -ENXIO; 623 return -ENXIO;
624} 624}
625 625
626#if 0
626int hpet_unregister(struct hpet_task *tp) 627int hpet_unregister(struct hpet_task *tp)
627{ 628{
628 struct hpet_dev *devp; 629 struct hpet_dev *devp;
@@ -652,6 +653,7 @@ int hpet_unregister(struct hpet_task *tp)
652 653
653 return 0; 654 return 0;
654} 655}
656#endif /* 0 */
655 657
656static ctl_table hpet_table[] = { 658static ctl_table hpet_table[] = {
657 { 659 {
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index 2f9759d625cc..02aac104842d 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -27,7 +27,6 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/kbd_kern.h> 28#include <linux/kbd_kern.h>
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/kref.h>
31#include <linux/kthread.h> 30#include <linux/kthread.h>
32#include <linux/list.h> 31#include <linux/list.h>
33#include <linux/module.h> 32#include <linux/module.h>
@@ -75,23 +74,6 @@ static int hvc_init(void);
75static int sysrq_pressed; 74static int sysrq_pressed;
76#endif 75#endif
77 76
78struct hvc_struct {
79 spinlock_t lock;
80 int index;
81 struct tty_struct *tty;
82 unsigned int count;
83 int do_wakeup;
84 char *outbuf;
85 int outbuf_size;
86 int n_outbuf;
87 uint32_t vtermno;
88 struct hv_ops *ops;
89 int irq_requested;
90 int irq;
91 struct list_head next;
92 struct kref kref; /* ref count & hvc_struct lifetime */
93};
94
95/* dynamic list of hvc_struct instances */ 77/* dynamic list of hvc_struct instances */
96static LIST_HEAD(hvc_structs); 78static LIST_HEAD(hvc_structs);
97 79
@@ -298,27 +280,15 @@ int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
298 280
299 return 0; 281 return 0;
300} 282}
283EXPORT_SYMBOL_GPL(hvc_instantiate);
301 284
302/* Wake the sleeping khvcd */ 285/* Wake the sleeping khvcd */
303static void hvc_kick(void) 286void hvc_kick(void)
304{ 287{
305 hvc_kicked = 1; 288 hvc_kicked = 1;
306 wake_up_process(hvc_task); 289 wake_up_process(hvc_task);
307} 290}
308 291EXPORT_SYMBOL_GPL(hvc_kick);
309static int hvc_poll(struct hvc_struct *hp);
310
311/*
312 * NOTE: This API isn't used if the console adapter doesn't support interrupts.
313 * In this case the console is poll driven.
314 */
315static irqreturn_t hvc_handle_interrupt(int irq, void *dev_instance)
316{
317 /* if hvc_poll request a repoll, then kick the hvcd thread */
318 if (hvc_poll(dev_instance))
319 hvc_kick();
320 return IRQ_HANDLED;
321}
322 292
323static void hvc_unthrottle(struct tty_struct *tty) 293static void hvc_unthrottle(struct tty_struct *tty)
324{ 294{
@@ -333,7 +303,6 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
333{ 303{
334 struct hvc_struct *hp; 304 struct hvc_struct *hp;
335 unsigned long flags; 305 unsigned long flags;
336 int irq = 0;
337 int rc = 0; 306 int rc = 0;
338 307
339 /* Auto increments kref reference if found. */ 308 /* Auto increments kref reference if found. */
@@ -352,18 +321,15 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
352 tty->low_latency = 1; /* Makes flushes to ldisc synchronous. */ 321 tty->low_latency = 1; /* Makes flushes to ldisc synchronous. */
353 322
354 hp->tty = tty; 323 hp->tty = tty;
355 /* Save for request_irq outside of spin_lock. */ 324
356 irq = hp->irq; 325 if (hp->ops->notifier_add)
357 if (irq) 326 rc = hp->ops->notifier_add(hp, hp->data);
358 hp->irq_requested = 1;
359 327
360 spin_unlock_irqrestore(&hp->lock, flags); 328 spin_unlock_irqrestore(&hp->lock, flags);
361 /* check error, fallback to non-irq */ 329
362 if (irq)
363 rc = request_irq(irq, hvc_handle_interrupt, IRQF_DISABLED, "hvc_console", hp);
364 330
365 /* 331 /*
366 * If the request_irq() fails and we return an error. The tty layer 332 * If the notifier fails we return an error. The tty layer
367 * will call hvc_close() after a failed open but we don't want to clean 333 * will call hvc_close() after a failed open but we don't want to clean
368 * up there so we'll clean up here and clear out the previously set 334 * up there so we'll clean up here and clear out the previously set
369 * tty fields and return the kref reference. 335 * tty fields and return the kref reference.
@@ -371,7 +337,6 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
371 if (rc) { 337 if (rc) {
372 spin_lock_irqsave(&hp->lock, flags); 338 spin_lock_irqsave(&hp->lock, flags);
373 hp->tty = NULL; 339 hp->tty = NULL;
374 hp->irq_requested = 0;
375 spin_unlock_irqrestore(&hp->lock, flags); 340 spin_unlock_irqrestore(&hp->lock, flags);
376 tty->driver_data = NULL; 341 tty->driver_data = NULL;
377 kref_put(&hp->kref, destroy_hvc_struct); 342 kref_put(&hp->kref, destroy_hvc_struct);
@@ -386,7 +351,6 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
386static void hvc_close(struct tty_struct *tty, struct file * filp) 351static void hvc_close(struct tty_struct *tty, struct file * filp)
387{ 352{
388 struct hvc_struct *hp; 353 struct hvc_struct *hp;
389 int irq = 0;
390 unsigned long flags; 354 unsigned long flags;
391 355
392 if (tty_hung_up_p(filp)) 356 if (tty_hung_up_p(filp))
@@ -404,9 +368,8 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
404 spin_lock_irqsave(&hp->lock, flags); 368 spin_lock_irqsave(&hp->lock, flags);
405 369
406 if (--hp->count == 0) { 370 if (--hp->count == 0) {
407 if (hp->irq_requested) 371 if (hp->ops->notifier_del)
408 irq = hp->irq; 372 hp->ops->notifier_del(hp, hp->data);
409 hp->irq_requested = 0;
410 373
411 /* We are done with the tty pointer now. */ 374 /* We are done with the tty pointer now. */
412 hp->tty = NULL; 375 hp->tty = NULL;
@@ -418,10 +381,6 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
418 * waking periodically to check chars_in_buffer(). 381 * waking periodically to check chars_in_buffer().
419 */ 382 */
420 tty_wait_until_sent(tty, HVC_CLOSE_WAIT); 383 tty_wait_until_sent(tty, HVC_CLOSE_WAIT);
421
422 if (irq)
423 free_irq(irq, hp);
424
425 } else { 384 } else {
426 if (hp->count < 0) 385 if (hp->count < 0)
427 printk(KERN_ERR "hvc_close %X: oops, count is %d\n", 386 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
@@ -436,7 +395,6 @@ static void hvc_hangup(struct tty_struct *tty)
436{ 395{
437 struct hvc_struct *hp = tty->driver_data; 396 struct hvc_struct *hp = tty->driver_data;
438 unsigned long flags; 397 unsigned long flags;
439 int irq = 0;
440 int temp_open_count; 398 int temp_open_count;
441 399
442 if (!hp) 400 if (!hp)
@@ -458,13 +416,12 @@ static void hvc_hangup(struct tty_struct *tty)
458 hp->count = 0; 416 hp->count = 0;
459 hp->n_outbuf = 0; 417 hp->n_outbuf = 0;
460 hp->tty = NULL; 418 hp->tty = NULL;
461 if (hp->irq_requested) 419
462 /* Saved for use outside of spin_lock. */ 420 if (hp->ops->notifier_del)
463 irq = hp->irq; 421 hp->ops->notifier_del(hp, hp->data);
464 hp->irq_requested = 0; 422
465 spin_unlock_irqrestore(&hp->lock, flags); 423 spin_unlock_irqrestore(&hp->lock, flags);
466 if (irq) 424
467 free_irq(irq, hp);
468 while(temp_open_count) { 425 while(temp_open_count) {
469 --temp_open_count; 426 --temp_open_count;
470 kref_put(&hp->kref, destroy_hvc_struct); 427 kref_put(&hp->kref, destroy_hvc_struct);
@@ -575,7 +532,7 @@ static u32 timeout = MIN_TIMEOUT;
575#define HVC_POLL_READ 0x00000001 532#define HVC_POLL_READ 0x00000001
576#define HVC_POLL_WRITE 0x00000002 533#define HVC_POLL_WRITE 0x00000002
577 534
578static int hvc_poll(struct hvc_struct *hp) 535int hvc_poll(struct hvc_struct *hp)
579{ 536{
580 struct tty_struct *tty; 537 struct tty_struct *tty;
581 int i, n, poll_mask = 0; 538 int i, n, poll_mask = 0;
@@ -602,10 +559,10 @@ static int hvc_poll(struct hvc_struct *hp)
602 if (test_bit(TTY_THROTTLED, &tty->flags)) 559 if (test_bit(TTY_THROTTLED, &tty->flags))
603 goto throttled; 560 goto throttled;
604 561
605 /* If we aren't interrupt driven and aren't throttled, we always 562 /* If we aren't notifier driven and aren't throttled, we always
606 * request a reschedule 563 * request a reschedule
607 */ 564 */
608 if (hp->irq == 0) 565 if (!hp->irq_requested)
609 poll_mask |= HVC_POLL_READ; 566 poll_mask |= HVC_POLL_READ;
610 567
611 /* Read data if any */ 568 /* Read data if any */
@@ -674,6 +631,7 @@ static int hvc_poll(struct hvc_struct *hp)
674 631
675 return poll_mask; 632 return poll_mask;
676} 633}
634EXPORT_SYMBOL_GPL(hvc_poll);
677 635
678/* 636/*
679 * This kthread is either polling or interrupt driven. This is determined by 637 * This kthread is either polling or interrupt driven. This is determined by
@@ -733,7 +691,7 @@ static const struct tty_operations hvc_ops = {
733 .chars_in_buffer = hvc_chars_in_buffer, 691 .chars_in_buffer = hvc_chars_in_buffer,
734}; 692};
735 693
736struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq, 694struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data,
737 struct hv_ops *ops, int outbuf_size) 695 struct hv_ops *ops, int outbuf_size)
738{ 696{
739 struct hvc_struct *hp; 697 struct hvc_struct *hp;
@@ -754,7 +712,7 @@ struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
754 memset(hp, 0x00, sizeof(*hp)); 712 memset(hp, 0x00, sizeof(*hp));
755 713
756 hp->vtermno = vtermno; 714 hp->vtermno = vtermno;
757 hp->irq = irq; 715 hp->data = data;
758 hp->ops = ops; 716 hp->ops = ops;
759 hp->outbuf_size = outbuf_size; 717 hp->outbuf_size = outbuf_size;
760 hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))]; 718 hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))];
@@ -784,6 +742,7 @@ struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
784 742
785 return hp; 743 return hp;
786} 744}
745EXPORT_SYMBOL_GPL(hvc_alloc);
787 746
788int __devexit hvc_remove(struct hvc_struct *hp) 747int __devexit hvc_remove(struct hvc_struct *hp)
789{ 748{
diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h
index 42ffb17e15df..d9ce10915625 100644
--- a/drivers/char/hvc_console.h
+++ b/drivers/char/hvc_console.h
@@ -26,6 +26,7 @@
26 26
27#ifndef HVC_CONSOLE_H 27#ifndef HVC_CONSOLE_H
28#define HVC_CONSOLE_H 28#define HVC_CONSOLE_H
29#include <linux/kref.h>
29 30
30/* 31/*
31 * This is the max number of console adapters that can/will be found as 32 * This is the max number of console adapters that can/will be found as
@@ -42,24 +43,50 @@
42 */ 43 */
43#define HVC_ALLOC_TTY_ADAPTERS 8 44#define HVC_ALLOC_TTY_ADAPTERS 8
44 45
46struct hvc_struct {
47 spinlock_t lock;
48 int index;
49 struct tty_struct *tty;
50 unsigned int count;
51 int do_wakeup;
52 char *outbuf;
53 int outbuf_size;
54 int n_outbuf;
55 uint32_t vtermno;
56 struct hv_ops *ops;
57 int irq_requested;
58 int data;
59 struct list_head next;
60 struct kref kref; /* ref count & hvc_struct lifetime */
61};
45 62
46/* implemented by a low level driver */ 63/* implemented by a low level driver */
47struct hv_ops { 64struct hv_ops {
48 int (*get_chars)(uint32_t vtermno, char *buf, int count); 65 int (*get_chars)(uint32_t vtermno, char *buf, int count);
49 int (*put_chars)(uint32_t vtermno, const char *buf, int count); 66 int (*put_chars)(uint32_t vtermno, const char *buf, int count);
50};
51 67
52struct hvc_struct; 68 /* Callbacks for notification. Called in open and close */
69 int (*notifier_add)(struct hvc_struct *hp, int irq);
70 void (*notifier_del)(struct hvc_struct *hp, int irq);
71};
53 72
54/* Register a vterm and a slot index for use as a console (console_init) */ 73/* Register a vterm and a slot index for use as a console (console_init) */
55extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops); 74extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
56 75
57/* register a vterm for hvc tty operation (module_init or hotplug add) */ 76/* register a vterm for hvc tty operation (module_init or hotplug add) */
58extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int irq, 77extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data,
59 struct hv_ops *ops, int outbuf_size); 78 struct hv_ops *ops, int outbuf_size);
60/* remove a vterm from hvc tty operation (modele_exit or hotplug remove) */ 79/* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
61extern int __devexit hvc_remove(struct hvc_struct *hp); 80extern int __devexit hvc_remove(struct hvc_struct *hp);
62 81
82/* data available */
83int hvc_poll(struct hvc_struct *hp);
84void hvc_kick(void);
85
86/* default notifier for irq based notification */
87extern int notifier_add_irq(struct hvc_struct *hp, int data);
88extern void notifier_del_irq(struct hvc_struct *hp, int data);
89
63 90
64#if defined(CONFIG_XMON) && defined(CONFIG_SMP) 91#if defined(CONFIG_XMON) && defined(CONFIG_SMP)
65#include <asm/xmon.h> 92#include <asm/xmon.h>
diff --git a/drivers/char/hvc_irq.c b/drivers/char/hvc_irq.c
new file mode 100644
index 000000000000..73a59cdb8947
--- /dev/null
+++ b/drivers/char/hvc_irq.c
@@ -0,0 +1,44 @@
1/*
2 * Copyright IBM Corp. 2001,2008
3 *
4 * This file contains the IRQ specific code for hvc_console
5 *
6 */
7
8#include <linux/interrupt.h>
9
10#include "hvc_console.h"
11
12static irqreturn_t hvc_handle_interrupt(int irq, void *dev_instance)
13{
14 /* if hvc_poll request a repoll, then kick the hvcd thread */
15 if (hvc_poll(dev_instance))
16 hvc_kick();
17 return IRQ_HANDLED;
18}
19
20/*
21 * For IRQ based systems these callbacks can be used
22 */
23int notifier_add_irq(struct hvc_struct *hp, int irq)
24{
25 int rc;
26
27 if (!irq) {
28 hp->irq_requested = 0;
29 return 0;
30 }
31 rc = request_irq(irq, hvc_handle_interrupt, IRQF_DISABLED,
32 "hvc_console", hp);
33 if (!rc)
34 hp->irq_requested = 1;
35 return rc;
36}
37
38void notifier_del_irq(struct hvc_struct *hp, int irq)
39{
40 if (!irq)
41 return;
42 free_irq(irq, hp);
43 hp->irq_requested = 0;
44}
diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
index a08f8f981c11..b71c610fe5ae 100644
--- a/drivers/char/hvc_iseries.c
+++ b/drivers/char/hvc_iseries.c
@@ -200,6 +200,8 @@ done:
200static struct hv_ops hvc_get_put_ops = { 200static struct hv_ops hvc_get_put_ops = {
201 .get_chars = get_chars, 201 .get_chars = get_chars,
202 .put_chars = put_chars, 202 .put_chars = put_chars,
203 .notifier_add = notifier_add_irq,
204 .notifier_del = notifier_del_irq,
203}; 205};
204 206
205static int __devinit hvc_vio_probe(struct vio_dev *vdev, 207static int __devinit hvc_vio_probe(struct vio_dev *vdev,
diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
index 79711aa4b41d..93f3840c1682 100644
--- a/drivers/char/hvc_vio.c
+++ b/drivers/char/hvc_vio.c
@@ -80,6 +80,8 @@ static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
80static struct hv_ops hvc_get_put_ops = { 80static struct hv_ops hvc_get_put_ops = {
81 .get_chars = filtered_get_chars, 81 .get_chars = filtered_get_chars,
82 .put_chars = hvc_put_chars, 82 .put_chars = hvc_put_chars,
83 .notifier_add = notifier_add_irq,
84 .notifier_del = notifier_del_irq,
83}; 85};
84 86
85static int __devinit hvc_vio_probe(struct vio_dev *vdev, 87static int __devinit hvc_vio_probe(struct vio_dev *vdev,
diff --git a/drivers/char/hvc_xen.c b/drivers/char/hvc_xen.c
index db2ae4216279..6b70aa66a587 100644
--- a/drivers/char/hvc_xen.c
+++ b/drivers/char/hvc_xen.c
@@ -100,6 +100,8 @@ static int read_console(uint32_t vtermno, char *buf, int len)
100static struct hv_ops hvc_ops = { 100static struct hv_ops hvc_ops = {
101 .get_chars = read_console, 101 .get_chars = read_console,
102 .put_chars = write_console, 102 .put_chars = write_console,
103 .notifier_add = notifier_add_irq,
104 .notifier_del = notifier_del_irq,
103}; 105};
104 106
105static int __init xen_init(void) 107static int __init xen_init(void)
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index 9cb48fcd316c..689f9dcd3b86 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -203,7 +203,7 @@ static int set_serial_info(i2ChanStrPtr, struct serial_struct __user *);
203 203
204static ssize_t ip2_ipl_read(struct file *, char __user *, size_t, loff_t *); 204static ssize_t ip2_ipl_read(struct file *, char __user *, size_t, loff_t *);
205static ssize_t ip2_ipl_write(struct file *, const char __user *, size_t, loff_t *); 205static ssize_t ip2_ipl_write(struct file *, const char __user *, size_t, loff_t *);
206static int ip2_ipl_ioctl(struct inode *, struct file *, UINT, ULONG); 206static long ip2_ipl_ioctl(struct file *, UINT, ULONG);
207static int ip2_ipl_open(struct inode *, struct file *); 207static int ip2_ipl_open(struct inode *, struct file *);
208 208
209static int DumpTraceBuffer(char __user *, int); 209static int DumpTraceBuffer(char __user *, int);
@@ -236,7 +236,7 @@ static const struct file_operations ip2_ipl = {
236 .owner = THIS_MODULE, 236 .owner = THIS_MODULE,
237 .read = ip2_ipl_read, 237 .read = ip2_ipl_read,
238 .write = ip2_ipl_write, 238 .write = ip2_ipl_write,
239 .ioctl = ip2_ipl_ioctl, 239 .unlocked_ioctl = ip2_ipl_ioctl,
240 .open = ip2_ipl_open, 240 .open = ip2_ipl_open,
241}; 241};
242 242
@@ -2845,10 +2845,10 @@ ip2_ipl_write(struct file *pFile, const char __user *pData, size_t count, loff_t
2845/* */ 2845/* */
2846/* */ 2846/* */
2847/******************************************************************************/ 2847/******************************************************************************/
2848static int 2848static long
2849ip2_ipl_ioctl ( struct inode *pInode, struct file *pFile, UINT cmd, ULONG arg ) 2849ip2_ipl_ioctl (struct file *pFile, UINT cmd, ULONG arg )
2850{ 2850{
2851 unsigned int iplminor = iminor(pInode); 2851 unsigned int iplminor = iminor(pFile->f_path.dentry->d_inode);
2852 int rc = 0; 2852 int rc = 0;
2853 void __user *argp = (void __user *)arg; 2853 void __user *argp = (void __user *)arg;
2854 ULONG __user *pIndex = argp; 2854 ULONG __user *pIndex = argp;
@@ -2859,6 +2859,8 @@ ip2_ipl_ioctl ( struct inode *pInode, struct file *pFile, UINT cmd, ULONG arg )
2859 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg ); 2859 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg );
2860#endif 2860#endif
2861 2861
2862 lock_kernel();
2863
2862 switch ( iplminor ) { 2864 switch ( iplminor ) {
2863 case 0: // IPL device 2865 case 0: // IPL device
2864 rc = -EINVAL; 2866 rc = -EINVAL;
@@ -2919,6 +2921,7 @@ ip2_ipl_ioctl ( struct inode *pInode, struct file *pFile, UINT cmd, ULONG arg )
2919 rc = -ENODEV; 2921 rc = -ENODEV;
2920 break; 2922 break;
2921 } 2923 }
2924 unlock_kernel();
2922 return rc; 2925 return rc;
2923} 2926}
2924 2927
diff --git a/drivers/char/lcd.c b/drivers/char/lcd.c
deleted file mode 100644
index 1c29b20e4f4c..000000000000
--- a/drivers/char/lcd.c
+++ /dev/null
@@ -1,516 +0,0 @@
1/*
2 * LCD, LED and Button interface for Cobalt
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1996, 1997 by Andrew Bose
9 *
10 * Linux kernel version history:
11 * March 2001: Ported from 2.0.34 by Liam Davies
12 *
13 */
14#include <linux/types.h>
15#include <linux/errno.h>
16#include <linux/miscdevice.h>
17#include <linux/slab.h>
18#include <linux/ioport.h>
19#include <linux/fcntl.h>
20#include <linux/mc146818rtc.h>
21#include <linux/netdevice.h>
22#include <linux/sched.h>
23#include <linux/smp_lock.h>
24#include <linux/delay.h>
25
26#include <asm/io.h>
27#include <asm/uaccess.h>
28#include <asm/system.h>
29
30#include "lcd.h"
31
32static int lcd_ioctl(struct inode *inode, struct file *file,
33 unsigned int cmd, unsigned long arg);
34
35static unsigned int lcd_present = 1;
36
37/* used in arch/mips/cobalt/reset.c */
38int led_state = 0;
39
40#if defined(CONFIG_TULIP) && 0
41
42#define MAX_INTERFACES 8
43static linkcheck_func_t linkcheck_callbacks[MAX_INTERFACES];
44static void *linkcheck_cookies[MAX_INTERFACES];
45
46int lcd_register_linkcheck_func(int iface_num, void *func, void *cookie)
47{
48 if (iface_num < 0 ||
49 iface_num >= MAX_INTERFACES ||
50 linkcheck_callbacks[iface_num] != NULL)
51 return -1;
52 linkcheck_callbacks[iface_num] = (linkcheck_func_t) func;
53 linkcheck_cookies[iface_num] = cookie;
54 return 0;
55}
56#endif
57
58static int lcd_ioctl(struct inode *inode, struct file *file,
59 unsigned int cmd, unsigned long arg)
60{
61 struct lcd_display button_display;
62 unsigned long address, a;
63
64 switch (cmd) {
65 case LCD_On:
66 udelay(150);
67 BusyCheck();
68 LCDWriteInst(0x0F);
69 break;
70
71 case LCD_Off:
72 udelay(150);
73 BusyCheck();
74 LCDWriteInst(0x08);
75 break;
76
77 case LCD_Reset:
78 udelay(150);
79 LCDWriteInst(0x3F);
80 udelay(150);
81 LCDWriteInst(0x3F);
82 udelay(150);
83 LCDWriteInst(0x3F);
84 udelay(150);
85 LCDWriteInst(0x3F);
86 udelay(150);
87 LCDWriteInst(0x01);
88 udelay(150);
89 LCDWriteInst(0x06);
90 break;
91
92 case LCD_Clear:
93 udelay(150);
94 BusyCheck();
95 LCDWriteInst(0x01);
96 break;
97
98 case LCD_Cursor_Left:
99 udelay(150);
100 BusyCheck();
101 LCDWriteInst(0x10);
102 break;
103
104 case LCD_Cursor_Right:
105 udelay(150);
106 BusyCheck();
107 LCDWriteInst(0x14);
108 break;
109
110 case LCD_Cursor_Off:
111 udelay(150);
112 BusyCheck();
113 LCDWriteInst(0x0C);
114 break;
115
116 case LCD_Cursor_On:
117 udelay(150);
118 BusyCheck();
119 LCDWriteInst(0x0F);
120 break;
121
122 case LCD_Blink_Off:
123 udelay(150);
124 BusyCheck();
125 LCDWriteInst(0x0E);
126 break;
127
128 case LCD_Get_Cursor_Pos:{
129 struct lcd_display display;
130
131 udelay(150);
132 BusyCheck();
133 display.cursor_address = (LCDReadInst);
134 display.cursor_address =
135 (display.cursor_address & 0x07F);
136 if (copy_to_user
137 ((struct lcd_display *) arg, &display,
138 sizeof(struct lcd_display)))
139 return -EFAULT;
140
141 break;
142 }
143
144
145 case LCD_Set_Cursor_Pos:{
146 struct lcd_display display;
147
148 if (copy_from_user
149 (&display, (struct lcd_display *) arg,
150 sizeof(struct lcd_display)))
151 return -EFAULT;
152
153 a = (display.cursor_address | kLCD_Addr);
154
155 udelay(150);
156 BusyCheck();
157 LCDWriteInst(a);
158
159 break;
160 }
161
162 case LCD_Get_Cursor:{
163 struct lcd_display display;
164
165 udelay(150);
166 BusyCheck();
167 display.character = LCDReadData;
168
169 if (copy_to_user
170 ((struct lcd_display *) arg, &display,
171 sizeof(struct lcd_display)))
172 return -EFAULT;
173 udelay(150);
174 BusyCheck();
175 LCDWriteInst(0x10);
176
177 break;
178 }
179
180 case LCD_Set_Cursor:{
181 struct lcd_display display;
182
183 if (copy_from_user
184 (&display, (struct lcd_display *) arg,
185 sizeof(struct lcd_display)))
186 return -EFAULT;
187
188 udelay(150);
189 BusyCheck();
190 LCDWriteData(display.character);
191 udelay(150);
192 BusyCheck();
193 LCDWriteInst(0x10);
194
195 break;
196 }
197
198
199 case LCD_Disp_Left:
200 udelay(150);
201 BusyCheck();
202 LCDWriteInst(0x18);
203 break;
204
205 case LCD_Disp_Right:
206 udelay(150);
207 BusyCheck();
208 LCDWriteInst(0x1C);
209 break;
210
211 case LCD_Home:
212 udelay(150);
213 BusyCheck();
214 LCDWriteInst(0x02);
215 break;
216
217 case LCD_Write:{
218 struct lcd_display display;
219 unsigned int index;
220
221
222 if (copy_from_user
223 (&display, (struct lcd_display *) arg,
224 sizeof(struct lcd_display)))
225 return -EFAULT;
226
227 udelay(150);
228 BusyCheck();
229 LCDWriteInst(0x80);
230 udelay(150);
231 BusyCheck();
232
233 for (index = 0; index < (display.size1); index++) {
234 udelay(150);
235 BusyCheck();
236 LCDWriteData(display.line1[index]);
237 BusyCheck();
238 }
239
240 udelay(150);
241 BusyCheck();
242 LCDWriteInst(0xC0);
243 udelay(150);
244 BusyCheck();
245 for (index = 0; index < (display.size2); index++) {
246 udelay(150);
247 BusyCheck();
248 LCDWriteData(display.line2[index]);
249 }
250
251 break;
252 }
253
254 case LCD_Read:{
255 struct lcd_display display;
256
257 BusyCheck();
258 for (address = kDD_R00; address <= kDD_R01;
259 address++) {
260 a = (address | kLCD_Addr);
261
262 udelay(150);
263 BusyCheck();
264 LCDWriteInst(a);
265 udelay(150);
266 BusyCheck();
267 display.line1[address] = LCDReadData;
268 }
269
270 display.line1[0x27] = '\0';
271
272 for (address = kDD_R10; address <= kDD_R11;
273 address++) {
274 a = (address | kLCD_Addr);
275
276 udelay(150);
277 BusyCheck();
278 LCDWriteInst(a);
279
280 udelay(150);
281 BusyCheck();
282 display.line2[address - 0x40] =
283 LCDReadData;
284 }
285
286 display.line2[0x27] = '\0';
287
288 if (copy_to_user
289 ((struct lcd_display *) arg, &display,
290 sizeof(struct lcd_display)))
291 return -EFAULT;
292 break;
293 }
294
295// set all GPIO leds to led_display.leds
296
297 case LED_Set:{
298 struct lcd_display led_display;
299
300
301 if (copy_from_user
302 (&led_display, (struct lcd_display *) arg,
303 sizeof(struct lcd_display)))
304 return -EFAULT;
305
306 led_state = led_display.leds;
307 LEDSet(led_state);
308
309 break;
310 }
311
312
313// set only bit led_display.leds
314
315 case LED_Bit_Set:{
316 unsigned int i;
317 int bit = 1;
318 struct lcd_display led_display;
319
320
321 if (copy_from_user
322 (&led_display, (struct lcd_display *) arg,
323 sizeof(struct lcd_display)))
324 return -EFAULT;
325
326 for (i = 0; i < (int) led_display.leds; i++) {
327 bit = 2 * bit;
328 }
329
330 led_state = led_state | bit;
331 LEDSet(led_state);
332 break;
333 }
334
335// clear only bit led_display.leds
336
337 case LED_Bit_Clear:{
338 unsigned int i;
339 int bit = 1;
340 struct lcd_display led_display;
341
342
343 if (copy_from_user
344 (&led_display, (struct lcd_display *) arg,
345 sizeof(struct lcd_display)))
346 return -EFAULT;
347
348 for (i = 0; i < (int) led_display.leds; i++) {
349 bit = 2 * bit;
350 }
351
352 led_state = led_state & ~bit;
353 LEDSet(led_state);
354 break;
355 }
356
357
358 case BUTTON_Read:{
359 button_display.buttons = GPIRead;
360 if (copy_to_user
361 ((struct lcd_display *) arg, &button_display,
362 sizeof(struct lcd_display)))
363 return -EFAULT;
364 break;
365 }
366
367 case LINK_Check:{
368 button_display.buttons =
369 *((volatile unsigned long *) (0xB0100060));
370 if (copy_to_user
371 ((struct lcd_display *) arg, &button_display,
372 sizeof(struct lcd_display)))
373 return -EFAULT;
374 break;
375 }
376
377 case LINK_Check_2:{
378 int iface_num;
379
380 /* panel-utils should pass in the desired interface status is wanted for
381 * in "buttons" of the structure. We will set this to non-zero if the
382 * link is in fact up for the requested interface. --DaveM
383 */
384 if (copy_from_user
385 (&button_display, (struct lcd_display *) arg,
386 sizeof(button_display)))
387 return -EFAULT;
388 iface_num = button_display.buttons;
389#if defined(CONFIG_TULIP) && 0
390 if (iface_num >= 0 &&
391 iface_num < MAX_INTERFACES &&
392 linkcheck_callbacks[iface_num] != NULL) {
393 button_display.buttons =
394 linkcheck_callbacks[iface_num]
395 (linkcheck_cookies[iface_num]);
396 } else
397#endif
398 button_display.buttons = 0;
399
400 if (__copy_to_user
401 ((struct lcd_display *) arg, &button_display,
402 sizeof(struct lcd_display)))
403 return -EFAULT;
404 break;
405 }
406
407 default:
408 return -EINVAL;
409
410 }
411
412 return 0;
413
414}
415
416static int lcd_open(struct inode *inode, struct file *file)
417{
418 cycle_kernel_lock();
419
420 if (!lcd_present)
421 return -ENXIO;
422 else
423 return 0;
424}
425
426/* Only RESET or NEXT counts as button pressed */
427
428static inline int button_pressed(void)
429{
430 unsigned long buttons = GPIRead;
431
432 if ((buttons == BUTTON_Next) || (buttons == BUTTON_Next_B)
433 || (buttons == BUTTON_Reset_B))
434 return buttons;
435 return 0;
436}
437
438/* LED daemon sits on this and we wake him up once a key is pressed. */
439
440static int lcd_waiters = 0;
441
442static ssize_t lcd_read(struct file *file, char *buf,
443 size_t count, loff_t *ofs)
444{
445 long buttons_now;
446
447 if (lcd_waiters > 0)
448 return -EINVAL;
449
450 lcd_waiters++;
451 while (((buttons_now = (long) button_pressed()) == 0) &&
452 !(signal_pending(current))) {
453 msleep_interruptible(2000);
454 }
455 lcd_waiters--;
456
457 if (signal_pending(current))
458 return -ERESTARTSYS;
459 return buttons_now;
460}
461
462/*
463 * The various file operations we support.
464 */
465
466static const struct file_operations lcd_fops = {
467 .read = lcd_read,
468 .ioctl = lcd_ioctl,
469 .open = lcd_open,
470};
471
472static struct miscdevice lcd_dev = {
473 MISC_DYNAMIC_MINOR,
474 "lcd",
475 &lcd_fops
476};
477
478static int lcd_init(void)
479{
480 int ret;
481 unsigned long data;
482
483 pr_info("%s\n", LCD_DRIVER);
484 ret = misc_register(&lcd_dev);
485 if (ret) {
486 printk(KERN_WARNING LCD "Unable to register misc device.\n");
487 return ret;
488 }
489
490 /* Check region? Naaah! Just snarf it up. */
491/* request_region(RTC_PORT(0), RTC_IO_EXTENT, "lcd");*/
492
493 udelay(150);
494 data = LCDReadData;
495 if ((data & 0x000000FF) == (0x00)) {
496 lcd_present = 0;
497 pr_info(LCD "LCD Not Present\n");
498 } else {
499 lcd_present = 1;
500 WRITE_GAL(kGal_DevBank2PReg, kGal_DevBank2Cfg);
501 WRITE_GAL(kGal_DevBank3PReg, kGal_DevBank3Cfg);
502 }
503
504 return 0;
505}
506
507static void __exit lcd_exit(void)
508{
509 misc_deregister(&lcd_dev);
510}
511
512module_init(lcd_init);
513module_exit(lcd_exit);
514
515MODULE_AUTHOR("Andrew Bose");
516MODULE_LICENSE("GPL");
diff --git a/drivers/char/lcd.h b/drivers/char/lcd.h
deleted file mode 100644
index 290b3ff23b03..000000000000
--- a/drivers/char/lcd.h
+++ /dev/null
@@ -1,154 +0,0 @@
1/*
2 * LED, LCD and Button panel driver for Cobalt
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1996, 1997 by Andrew Bose
9 *
10 * Linux kernel version history:
11 * March 2001: Ported from 2.0.34 by Liam Davies
12 *
13 */
14
15// function headers
16
17#define LCD_CHARS_PER_LINE 40
18#define MAX_IDLE_TIME 120
19
20struct lcd_display {
21 unsigned buttons;
22 int size1;
23 int size2;
24 unsigned char line1[LCD_CHARS_PER_LINE];
25 unsigned char line2[LCD_CHARS_PER_LINE];
26 unsigned char cursor_address;
27 unsigned char character;
28 unsigned char leds;
29 unsigned char *RomImage;
30};
31
32
33
34#define LCD_DRIVER "Cobalt LCD Driver v2.10"
35
36#define LCD "lcd: "
37
38#define kLCD_IR 0x0F000000
39#define kLCD_DR 0x0F000010
40#define kGPI 0x0D000000
41#define kLED 0x0C000000
42
43#define kDD_R00 0x00
44#define kDD_R01 0x27
45#define kDD_R10 0x40
46#define kDD_R11 0x67
47
48#define kLCD_Addr 0x00000080
49
50#define LCDTimeoutValue 0xfff
51
52
53// Macros
54
55#define LCDWriteData(x) outl((x << 24), kLCD_DR)
56#define LCDWriteInst(x) outl((x << 24), kLCD_IR)
57
58#define LCDReadData (inl(kLCD_DR) >> 24)
59#define LCDReadInst (inl(kLCD_IR) >> 24)
60
61#define GPIRead (inl(kGPI) >> 24)
62
63#define LEDSet(x) outb((char)x, kLED)
64
65#define WRITE_GAL(x,y) outl(y, 0x04000000 | (x))
66#define BusyCheck() while ((LCDReadInst & 0x80) == 0x80)
67
68
69
70/*
71 * Function command codes for io_ctl.
72 */
73#define LCD_On 1
74#define LCD_Off 2
75#define LCD_Clear 3
76#define LCD_Reset 4
77#define LCD_Cursor_Left 5
78#define LCD_Cursor_Right 6
79#define LCD_Disp_Left 7
80#define LCD_Disp_Right 8
81#define LCD_Get_Cursor 9
82#define LCD_Set_Cursor 10
83#define LCD_Home 11
84#define LCD_Read 12
85#define LCD_Write 13
86#define LCD_Cursor_Off 14
87#define LCD_Cursor_On 15
88#define LCD_Get_Cursor_Pos 16
89#define LCD_Set_Cursor_Pos 17
90#define LCD_Blink_Off 18
91
92#define LED_Set 40
93#define LED_Bit_Set 41
94#define LED_Bit_Clear 42
95
96
97// Button defs
98#define BUTTON_Read 50
99
100
101// Ethernet LINK check hackaroo
102#define LINK_Check 90
103#define LINK_Check_2 91
104
105// Button patterns _B - single layer lcd boards
106
107#define BUTTON_NONE 0x3F
108#define BUTTON_NONE_B 0xFE
109
110#define BUTTON_Left 0x3B
111#define BUTTON_Left_B 0xFA
112
113#define BUTTON_Right 0x37
114#define BUTTON_Right_B 0xDE
115
116#define BUTTON_Up 0x2F
117#define BUTTON_Up_B 0xF6
118
119#define BUTTON_Down 0x1F
120#define BUTTON_Down_B 0xEE
121
122#define BUTTON_Next 0x3D
123#define BUTTON_Next_B 0x7E
124
125#define BUTTON_Enter 0x3E
126#define BUTTON_Enter_B 0xBE
127
128#define BUTTON_Reset_B 0xFC
129
130
131// debounce constants
132
133#define BUTTON_SENSE 160000
134#define BUTTON_DEBOUNCE 5000
135
136
137// Galileo register stuff
138
139#define kGal_DevBank2Cfg 0x1466DB33
140#define kGal_DevBank2PReg 0x464
141#define kGal_DevBank3Cfg 0x146FDFFB
142#define kGal_DevBank3PReg 0x468
143
144// Network
145
146#define kIPADDR 1
147#define kNETMASK 2
148#define kGATEWAY 3
149#define kDNS 4
150
151#define kClassA 5
152#define kClassB 6
153#define kClassC 7
154
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index c2dba82eb5f7..672b08e694d0 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -327,7 +327,10 @@ static void mmap_mem_close(struct vm_area_struct *vma)
327 327
328static struct vm_operations_struct mmap_mem_ops = { 328static struct vm_operations_struct mmap_mem_ops = {
329 .open = mmap_mem_open, 329 .open = mmap_mem_open,
330 .close = mmap_mem_close 330 .close = mmap_mem_close,
331#ifdef CONFIG_HAVE_IOREMAP_PROT
332 .access = generic_access_phys
333#endif
331}; 334};
332 335
333static int mmap_mem(struct file * file, struct vm_area_struct * vma) 336static int mmap_mem(struct file * file, struct vm_area_struct * vma)
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c
index fe2a95b5d3c0..30f095a8c2d4 100644
--- a/drivers/char/mspec.c
+++ b/drivers/char/mspec.c
@@ -193,25 +193,23 @@ mspec_close(struct vm_area_struct *vma)
193} 193}
194 194
195/* 195/*
196 * mspec_nopfn 196 * mspec_fault
197 * 197 *
198 * Creates a mspec page and maps it to user space. 198 * Creates a mspec page and maps it to user space.
199 */ 199 */
200static unsigned long 200static int
201mspec_nopfn(struct vm_area_struct *vma, unsigned long address) 201mspec_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
202{ 202{
203 unsigned long paddr, maddr; 203 unsigned long paddr, maddr;
204 unsigned long pfn; 204 unsigned long pfn;
205 int index; 205 pgoff_t index = vmf->pgoff;
206 struct vma_data *vdata = vma->vm_private_data; 206 struct vma_data *vdata = vma->vm_private_data;
207 207
208 BUG_ON(address < vdata->vm_start || address >= vdata->vm_end);
209 index = (address - vdata->vm_start) >> PAGE_SHIFT;
210 maddr = (volatile unsigned long) vdata->maddr[index]; 208 maddr = (volatile unsigned long) vdata->maddr[index];
211 if (maddr == 0) { 209 if (maddr == 0) {
212 maddr = uncached_alloc_page(numa_node_id(), 1); 210 maddr = uncached_alloc_page(numa_node_id(), 1);
213 if (maddr == 0) 211 if (maddr == 0)
214 return NOPFN_OOM; 212 return VM_FAULT_OOM;
215 213
216 spin_lock(&vdata->lock); 214 spin_lock(&vdata->lock);
217 if (vdata->maddr[index] == 0) { 215 if (vdata->maddr[index] == 0) {
@@ -231,13 +229,20 @@ mspec_nopfn(struct vm_area_struct *vma, unsigned long address)
231 229
232 pfn = paddr >> PAGE_SHIFT; 230 pfn = paddr >> PAGE_SHIFT;
233 231
234 return pfn; 232 /*
233 * vm_insert_pfn can fail with -EBUSY, but in that case it will
234 * be because another thread has installed the pte first, so it
235 * is no problem.
236 */
237 vm_insert_pfn(vma, (unsigned long)vmf->virtual_address, pfn);
238
239 return VM_FAULT_NOPAGE;
235} 240}
236 241
237static struct vm_operations_struct mspec_vm_ops = { 242static struct vm_operations_struct mspec_vm_ops = {
238 .open = mspec_open, 243 .open = mspec_open,
239 .close = mspec_close, 244 .close = mspec_close,
240 .nopfn = mspec_nopfn 245 .fault = mspec_fault,
241}; 246};
242 247
243/* 248/*
diff --git a/drivers/char/mwave/mwavedd.c b/drivers/char/mwave/mwavedd.c
index 50243fcd87e8..4f8d67fed292 100644
--- a/drivers/char/mwave/mwavedd.c
+++ b/drivers/char/mwave/mwavedd.c
@@ -86,8 +86,8 @@ module_param(mwave_uart_io, int, 0);
86 86
87static int mwave_open(struct inode *inode, struct file *file); 87static int mwave_open(struct inode *inode, struct file *file);
88static int mwave_close(struct inode *inode, struct file *file); 88static int mwave_close(struct inode *inode, struct file *file);
89static int mwave_ioctl(struct inode *inode, struct file *filp, 89static long mwave_ioctl(struct file *filp, unsigned int iocmd,
90 unsigned int iocmd, unsigned long ioarg); 90 unsigned long ioarg);
91 91
92MWAVE_DEVICE_DATA mwave_s_mdd; 92MWAVE_DEVICE_DATA mwave_s_mdd;
93 93
@@ -119,16 +119,16 @@ static int mwave_close(struct inode *inode, struct file *file)
119 return retval; 119 return retval;
120} 120}
121 121
122static int mwave_ioctl(struct inode *inode, struct file *file, 122static long mwave_ioctl(struct file *file, unsigned int iocmd,
123 unsigned int iocmd, unsigned long ioarg) 123 unsigned long ioarg)
124{ 124{
125 unsigned int retval = 0; 125 unsigned int retval = 0;
126 pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd; 126 pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;
127 void __user *arg = (void __user *)ioarg; 127 void __user *arg = (void __user *)ioarg;
128 128
129 PRINTK_5(TRACE_MWAVE, 129 PRINTK_4(TRACE_MWAVE,
130 "mwavedd::mwave_ioctl, entry inode %p file %p cmd %x arg %x\n", 130 "mwavedd::mwave_ioctl, entry file %p cmd %x arg %x\n",
131 inode, file, iocmd, (int) ioarg); 131 file, iocmd, (int) ioarg);
132 132
133 switch (iocmd) { 133 switch (iocmd) {
134 134
@@ -136,7 +136,9 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
136 PRINTK_1(TRACE_MWAVE, 136 PRINTK_1(TRACE_MWAVE,
137 "mwavedd::mwave_ioctl, IOCTL_MW_RESET" 137 "mwavedd::mwave_ioctl, IOCTL_MW_RESET"
138 " calling tp3780I_ResetDSP\n"); 138 " calling tp3780I_ResetDSP\n");
139 lock_kernel();
139 retval = tp3780I_ResetDSP(&pDrvData->rBDData); 140 retval = tp3780I_ResetDSP(&pDrvData->rBDData);
141 unlock_kernel();
140 PRINTK_2(TRACE_MWAVE, 142 PRINTK_2(TRACE_MWAVE,
141 "mwavedd::mwave_ioctl, IOCTL_MW_RESET" 143 "mwavedd::mwave_ioctl, IOCTL_MW_RESET"
142 " retval %x from tp3780I_ResetDSP\n", 144 " retval %x from tp3780I_ResetDSP\n",
@@ -147,7 +149,9 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
147 PRINTK_1(TRACE_MWAVE, 149 PRINTK_1(TRACE_MWAVE,
148 "mwavedd::mwave_ioctl, IOCTL_MW_RUN" 150 "mwavedd::mwave_ioctl, IOCTL_MW_RUN"
149 " calling tp3780I_StartDSP\n"); 151 " calling tp3780I_StartDSP\n");
152 lock_kernel();
150 retval = tp3780I_StartDSP(&pDrvData->rBDData); 153 retval = tp3780I_StartDSP(&pDrvData->rBDData);
154 unlock_kernel();
151 PRINTK_2(TRACE_MWAVE, 155 PRINTK_2(TRACE_MWAVE,
152 "mwavedd::mwave_ioctl, IOCTL_MW_RUN" 156 "mwavedd::mwave_ioctl, IOCTL_MW_RUN"
153 " retval %x from tp3780I_StartDSP\n", 157 " retval %x from tp3780I_StartDSP\n",
@@ -161,8 +165,10 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
161 "mwavedd::mwave_ioctl," 165 "mwavedd::mwave_ioctl,"
162 " IOCTL_MW_DSP_ABILITIES calling" 166 " IOCTL_MW_DSP_ABILITIES calling"
163 " tp3780I_QueryAbilities\n"); 167 " tp3780I_QueryAbilities\n");
168 lock_kernel();
164 retval = tp3780I_QueryAbilities(&pDrvData->rBDData, 169 retval = tp3780I_QueryAbilities(&pDrvData->rBDData,
165 &rAbilities); 170 &rAbilities);
171 unlock_kernel();
166 PRINTK_2(TRACE_MWAVE, 172 PRINTK_2(TRACE_MWAVE,
167 "mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES" 173 "mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES"
168 " retval %x from tp3780I_QueryAbilities\n", 174 " retval %x from tp3780I_QueryAbilities\n",
@@ -193,11 +199,13 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
193 "mwavedd::mwave_ioctl IOCTL_MW_READ_DATA," 199 "mwavedd::mwave_ioctl IOCTL_MW_READ_DATA,"
194 " size %lx, ioarg %lx pusBuffer %p\n", 200 " size %lx, ioarg %lx pusBuffer %p\n",
195 rReadData.ulDataLength, ioarg, pusBuffer); 201 rReadData.ulDataLength, ioarg, pusBuffer);
202 lock_kernel();
196 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 203 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
197 iocmd, 204 iocmd,
198 pusBuffer, 205 pusBuffer,
199 rReadData.ulDataLength, 206 rReadData.ulDataLength,
200 rReadData.usDspAddress); 207 rReadData.usDspAddress);
208 unlock_kernel();
201 } 209 }
202 break; 210 break;
203 211
@@ -215,10 +223,12 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
215 " size %lx, ioarg %lx pusBuffer %p\n", 223 " size %lx, ioarg %lx pusBuffer %p\n",
216 rReadData.ulDataLength / 2, ioarg, 224 rReadData.ulDataLength / 2, ioarg,
217 pusBuffer); 225 pusBuffer);
226 lock_kernel();
218 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 227 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
219 iocmd, pusBuffer, 228 iocmd, pusBuffer,
220 rReadData.ulDataLength / 2, 229 rReadData.ulDataLength / 2,
221 rReadData.usDspAddress); 230 rReadData.usDspAddress);
231 unlock_kernel();
222 } 232 }
223 break; 233 break;
224 234
@@ -236,10 +246,12 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
236 " size %lx, ioarg %lx pusBuffer %p\n", 246 " size %lx, ioarg %lx pusBuffer %p\n",
237 rWriteData.ulDataLength, ioarg, 247 rWriteData.ulDataLength, ioarg,
238 pusBuffer); 248 pusBuffer);
249 lock_kernel();
239 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 250 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
240 iocmd, pusBuffer, 251 iocmd, pusBuffer,
241 rWriteData.ulDataLength, 252 rWriteData.ulDataLength,
242 rWriteData.usDspAddress); 253 rWriteData.usDspAddress);
254 unlock_kernel();
243 } 255 }
244 break; 256 break;
245 257
@@ -257,10 +269,12 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
257 " size %lx, ioarg %lx pusBuffer %p\n", 269 " size %lx, ioarg %lx pusBuffer %p\n",
258 rWriteData.ulDataLength, ioarg, 270 rWriteData.ulDataLength, ioarg,
259 pusBuffer); 271 pusBuffer);
272 lock_kernel();
260 retval = tp3780I_ReadWriteDspIStore(&pDrvData->rBDData, 273 retval = tp3780I_ReadWriteDspIStore(&pDrvData->rBDData,
261 iocmd, pusBuffer, 274 iocmd, pusBuffer,
262 rWriteData.ulDataLength, 275 rWriteData.ulDataLength,
263 rWriteData.usDspAddress); 276 rWriteData.usDspAddress);
277 unlock_kernel();
264 } 278 }
265 break; 279 break;
266 280
@@ -281,8 +295,10 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
281 ipcnum); 295 ipcnum);
282 return -EINVAL; 296 return -EINVAL;
283 } 297 }
298 lock_kernel();
284 pDrvData->IPCs[ipcnum].bIsHere = FALSE; 299 pDrvData->IPCs[ipcnum].bIsHere = FALSE;
285 pDrvData->IPCs[ipcnum].bIsEnabled = TRUE; 300 pDrvData->IPCs[ipcnum].bIsEnabled = TRUE;
301 unlock_kernel();
286 302
287 PRINTK_2(TRACE_MWAVE, 303 PRINTK_2(TRACE_MWAVE,
288 "mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC" 304 "mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC"
@@ -307,6 +323,7 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
307 return -EINVAL; 323 return -EINVAL;
308 } 324 }
309 325
326 lock_kernel();
310 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) { 327 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
311 DECLARE_WAITQUEUE(wait, current); 328 DECLARE_WAITQUEUE(wait, current);
312 329
@@ -347,6 +364,7 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
347 " processing\n", 364 " processing\n",
348 ipcnum); 365 ipcnum);
349 } 366 }
367 unlock_kernel();
350 } 368 }
351 break; 369 break;
352 370
@@ -365,19 +383,18 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
365 ipcnum); 383 ipcnum);
366 return -EINVAL; 384 return -EINVAL;
367 } 385 }
386 lock_kernel();
368 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) { 387 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
369 pDrvData->IPCs[ipcnum].bIsEnabled = FALSE; 388 pDrvData->IPCs[ipcnum].bIsEnabled = FALSE;
370 if (pDrvData->IPCs[ipcnum].bIsHere == TRUE) { 389 if (pDrvData->IPCs[ipcnum].bIsHere == TRUE) {
371 wake_up_interruptible(&pDrvData->IPCs[ipcnum].ipc_wait_queue); 390 wake_up_interruptible(&pDrvData->IPCs[ipcnum].ipc_wait_queue);
372 } 391 }
373 } 392 }
393 unlock_kernel();
374 } 394 }
375 break; 395 break;
376 396
377 default: 397 default:
378 PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::mwave_ioctl:"
379 " Error: Unrecognized iocmd %x\n",
380 iocmd);
381 return -ENOTTY; 398 return -ENOTTY;
382 break; 399 break;
383 } /* switch */ 400 } /* switch */
@@ -460,7 +477,7 @@ static const struct file_operations mwave_fops = {
460 .owner = THIS_MODULE, 477 .owner = THIS_MODULE,
461 .read = mwave_read, 478 .read = mwave_read,
462 .write = mwave_write, 479 .write = mwave_write,
463 .ioctl = mwave_ioctl, 480 .unlocked_ioctl = mwave_ioctl,
464 .open = mwave_open, 481 .open = mwave_open,
465 .release = mwave_close 482 .release = mwave_close
466}; 483};
diff --git a/drivers/char/mwave/mwavedd.h b/drivers/char/mwave/mwavedd.h
index 8eca61e0a19c..7e0d530e2e07 100644
--- a/drivers/char/mwave/mwavedd.h
+++ b/drivers/char/mwave/mwavedd.h
@@ -147,4 +147,6 @@ typedef struct _MWAVE_DEVICE_DATA {
147 147
148} MWAVE_DEVICE_DATA, *pMWAVE_DEVICE_DATA; 148} MWAVE_DEVICE_DATA, *pMWAVE_DEVICE_DATA;
149 149
150extern MWAVE_DEVICE_DATA mwave_s_mdd;
151
150#endif 152#endif
diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
index f282976daaac..c68969708068 100644
--- a/drivers/char/mwave/tp3780i.c
+++ b/drivers/char/mwave/tp3780i.c
@@ -57,8 +57,6 @@
57#include "3780i.h" 57#include "3780i.h"
58#include "mwavepub.h" 58#include "mwavepub.h"
59 59
60extern MWAVE_DEVICE_DATA mwave_s_mdd;
61
62static unsigned short s_ausThinkpadIrqToField[16] = 60static unsigned short s_ausThinkpadIrqToField[16] =
63 { 0xFFFF, 0xFFFF, 0xFFFF, 0x0001, 0x0002, 0x0003, 0xFFFF, 0x0004, 61 { 0xFFFF, 0xFFFF, 0xFFFF, 0x0001, 0x0002, 0x0003, 0xFFFF, 0x0004,
64 0xFFFF, 0xFFFF, 0x0005, 0x0006, 0xFFFF, 0xFFFF, 0xFFFF, 0x0007 }; 62 0xFFFF, 0xFFFF, 0x0005, 0x0006, 0xFFFF, 0xFFFF, 0xFFFF, 0x0007 };
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 4c756bbba948..e30575e87648 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -16,7 +16,6 @@
16 * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox 16 * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
17 * <alan@redhat.com>. The original 1.8 code is available on www.moxa.com. 17 * <alan@redhat.com>. The original 1.8 code is available on www.moxa.com.
18 * - Fixed x86_64 cleanness 18 * - Fixed x86_64 cleanness
19 * - Fixed sleep with spinlock held in mxser_send_break
20 */ 19 */
21 20
22#include <linux/module.h> 21#include <linux/module.h>
@@ -49,18 +48,12 @@
49 48
50#define MXSER_VERSION "2.0.4" /* 1.12 */ 49#define MXSER_VERSION "2.0.4" /* 1.12 */
51#define MXSERMAJOR 174 50#define MXSERMAJOR 174
52#define MXSERCUMAJOR 175
53 51
54#define MXSER_BOARDS 4 /* Max. boards */ 52#define MXSER_BOARDS 4 /* Max. boards */
55#define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */ 53#define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
56#define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD) 54#define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD)
57#define MXSER_ISR_PASS_LIMIT 100 55#define MXSER_ISR_PASS_LIMIT 100
58 56
59#define MXSER_ERR_IOADDR -1
60#define MXSER_ERR_IRQ -2
61#define MXSER_ERR_IRQ_CONFLIT -3
62#define MXSER_ERR_VECTOR -4
63
64/*CheckIsMoxaMust return value*/ 57/*CheckIsMoxaMust return value*/
65#define MOXA_OTHER_UART 0x00 58#define MOXA_OTHER_UART 0x00
66#define MOXA_MUST_MU150_HWID 0x01 59#define MOXA_MUST_MU150_HWID 0x01
@@ -179,14 +172,15 @@ static struct pci_device_id mxser_pcibrds[] = {
179}; 172};
180MODULE_DEVICE_TABLE(pci, mxser_pcibrds); 173MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
181 174
182static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 }; 175static unsigned long ioaddr[MXSER_BOARDS];
183static int ttymajor = MXSERMAJOR; 176static int ttymajor = MXSERMAJOR;
184 177
185/* Variables for insmod */ 178/* Variables for insmod */
186 179
187MODULE_AUTHOR("Casper Yang"); 180MODULE_AUTHOR("Casper Yang");
188MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver"); 181MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
189module_param_array(ioaddr, int, NULL, 0); 182module_param_array(ioaddr, ulong, NULL, 0);
183MODULE_PARM_DESC(ioaddr, "ISA io addresses to look for a moxa board");
190module_param(ttymajor, int, 0); 184module_param(ttymajor, int, 0);
191MODULE_LICENSE("GPL"); 185MODULE_LICENSE("GPL");
192 186
@@ -196,7 +190,6 @@ struct mxser_log {
196 unsigned long txcnt[MXSER_PORTS]; 190 unsigned long txcnt[MXSER_PORTS];
197}; 191};
198 192
199
200struct mxser_mon { 193struct mxser_mon {
201 unsigned long rxcnt; 194 unsigned long rxcnt;
202 unsigned long txcnt; 195 unsigned long txcnt;
@@ -287,19 +280,9 @@ struct mxser_mstatus {
287 int dcd; 280 int dcd;
288}; 281};
289 282
290static struct mxser_mstatus GMStatus[MXSER_PORTS];
291
292static int mxserBoardCAP[MXSER_BOARDS] = {
293 0, 0, 0, 0
294 /* 0x180, 0x280, 0x200, 0x320 */
295};
296
297static struct mxser_board mxser_boards[MXSER_BOARDS]; 283static struct mxser_board mxser_boards[MXSER_BOARDS];
298static struct tty_driver *mxvar_sdriver; 284static struct tty_driver *mxvar_sdriver;
299static struct mxser_log mxvar_log; 285static struct mxser_log mxvar_log;
300static int mxvar_diagflag;
301static unsigned char mxser_msr[MXSER_PORTS + 1];
302static struct mxser_mon_ext mon_data_ext;
303static int mxser_set_baud_method[MXSER_PORTS + 1]; 286static int mxser_set_baud_method[MXSER_PORTS + 1];
304 287
305static void mxser_enable_must_enchance_mode(unsigned long baseio) 288static void mxser_enable_must_enchance_mode(unsigned long baseio)
@@ -543,6 +526,7 @@ static void process_txrx_fifo(struct mxser_port *info)
543 526
544static unsigned char mxser_get_msr(int baseaddr, int mode, int port) 527static unsigned char mxser_get_msr(int baseaddr, int mode, int port)
545{ 528{
529 static unsigned char mxser_msr[MXSER_PORTS + 1];
546 unsigned char status = 0; 530 unsigned char status = 0;
547 531
548 status = inb(baseaddr + UART_MSR); 532 status = inb(baseaddr + UART_MSR);
@@ -1319,13 +1303,9 @@ static void mxser_flush_chars(struct tty_struct *tty)
1319 struct mxser_port *info = tty->driver_data; 1303 struct mxser_port *info = tty->driver_data;
1320 unsigned long flags; 1304 unsigned long flags;
1321 1305
1322 if (info->xmit_cnt <= 0 || 1306 if (info->xmit_cnt <= 0 || tty->stopped || !info->port.xmit_buf ||
1323 tty->stopped || 1307 (tty->hw_stopped && info->type != PORT_16550A &&
1324 !info->port.xmit_buf || 1308 !info->board->chip_flag))
1325 (tty->hw_stopped &&
1326 (info->type != PORT_16550A) &&
1327 (!info->board->chip_flag)
1328 ))
1329 return; 1309 return;
1330 1310
1331 spin_lock_irqsave(&info->slock, flags); 1311 spin_lock_irqsave(&info->slock, flags);
@@ -1343,9 +1323,7 @@ static int mxser_write_room(struct tty_struct *tty)
1343 int ret; 1323 int ret;
1344 1324
1345 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1; 1325 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1346 if (ret < 0) 1326 return ret < 0 ? 0 : ret;
1347 ret = 0;
1348 return ret;
1349} 1327}
1350 1328
1351static int mxser_chars_in_buffer(struct tty_struct *tty) 1329static int mxser_chars_in_buffer(struct tty_struct *tty)
@@ -1634,6 +1612,8 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1634 1612
1635 switch (cmd) { 1613 switch (cmd) {
1636 case MOXA_GET_MAJOR: 1614 case MOXA_GET_MAJOR:
1615 printk(KERN_WARNING "mxser: '%s' uses deprecated ioctl %x, fix "
1616 "your userspace\n", current->comm, cmd);
1637 return put_user(ttymajor, (int __user *)argp); 1617 return put_user(ttymajor, (int __user *)argp);
1638 1618
1639 case MOXA_CHKPORTENABLE: 1619 case MOXA_CHKPORTENABLE:
@@ -1651,62 +1631,60 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1651 ret = -EFAULT; 1631 ret = -EFAULT;
1652 unlock_kernel(); 1632 unlock_kernel();
1653 return ret; 1633 return ret;
1654 case MOXA_GETMSTATUS: 1634 case MOXA_GETMSTATUS: {
1635 struct mxser_mstatus ms, __user *msu = argp;
1655 lock_kernel(); 1636 lock_kernel();
1656 for (i = 0; i < MXSER_BOARDS; i++) 1637 for (i = 0; i < MXSER_BOARDS; i++)
1657 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) { 1638 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) {
1658 port = &mxser_boards[i].ports[j]; 1639 port = &mxser_boards[i].ports[j];
1640 memset(&ms, 0, sizeof(ms));
1659 1641
1660 GMStatus[i].ri = 0; 1642 if (!port->ioaddr)
1661 if (!port->ioaddr) { 1643 goto copy;
1662 GMStatus[i].dcd = 0;
1663 GMStatus[i].dsr = 0;
1664 GMStatus[i].cts = 0;
1665 continue;
1666 }
1667 1644
1668 if (!port->port.tty || !port->port.tty->termios) 1645 if (!port->port.tty || !port->port.tty->termios)
1669 GMStatus[i].cflag = 1646 ms.cflag = port->normal_termios.c_cflag;
1670 port->normal_termios.c_cflag;
1671 else 1647 else
1672 GMStatus[i].cflag = 1648 ms.cflag = port->port.tty->termios->c_cflag;
1673 port->port.tty->termios->c_cflag;
1674 1649
1675 status = inb(port->ioaddr + UART_MSR); 1650 status = inb(port->ioaddr + UART_MSR);
1676 if (status & 0x80 /*UART_MSR_DCD */ ) 1651 if (status & UART_MSR_DCD)
1677 GMStatus[i].dcd = 1; 1652 ms.dcd = 1;
1678 else 1653 if (status & UART_MSR_DSR)
1679 GMStatus[i].dcd = 0; 1654 ms.dsr = 1;
1680 1655 if (status & UART_MSR_CTS)
1681 if (status & 0x20 /*UART_MSR_DSR */ ) 1656 ms.cts = 1;
1682 GMStatus[i].dsr = 1; 1657 copy:
1683 else 1658 if (copy_to_user(msu, &ms, sizeof(ms))) {
1684 GMStatus[i].dsr = 0; 1659 unlock_kernel();
1685 1660 return -EFAULT;
1686 1661 }
1687 if (status & 0x10 /*UART_MSR_CTS */ ) 1662 msu++;
1688 GMStatus[i].cts = 1;
1689 else
1690 GMStatus[i].cts = 0;
1691 } 1663 }
1692 unlock_kernel(); 1664 unlock_kernel();
1693 if (copy_to_user(argp, GMStatus,
1694 sizeof(struct mxser_mstatus) * MXSER_PORTS))
1695 return -EFAULT;
1696 return 0; 1665 return 0;
1666 }
1697 case MOXA_ASPP_MON_EXT: { 1667 case MOXA_ASPP_MON_EXT: {
1698 int p, shiftbit; 1668 struct mxser_mon_ext *me; /* it's 2k, stack unfriendly */
1699 unsigned long opmode; 1669 unsigned int cflag, iflag, p;
1700 unsigned cflag, iflag; 1670 u8 opmode;
1671
1672 me = kzalloc(sizeof(*me), GFP_KERNEL);
1673 if (!me)
1674 return -ENOMEM;
1701 1675
1702 lock_kernel(); 1676 lock_kernel();
1703 for (i = 0; i < MXSER_BOARDS; i++) { 1677 for (i = 0, p = 0; i < MXSER_BOARDS; i++) {
1704 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) { 1678 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++, p++) {
1679 if (p >= ARRAY_SIZE(me->rx_cnt)) {
1680 i = MXSER_BOARDS;
1681 break;
1682 }
1705 port = &mxser_boards[i].ports[j]; 1683 port = &mxser_boards[i].ports[j];
1706 if (!port->ioaddr) 1684 if (!port->ioaddr)
1707 continue; 1685 continue;
1708 1686
1709 status = mxser_get_msr(port->ioaddr, 0, i); 1687 status = mxser_get_msr(port->ioaddr, 0, p);
1710 1688
1711 if (status & UART_MSR_TERI) 1689 if (status & UART_MSR_TERI)
1712 port->icount.rng++; 1690 port->icount.rng++;
@@ -1718,16 +1696,13 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1718 port->icount.cts++; 1696 port->icount.cts++;
1719 1697
1720 port->mon_data.modem_status = status; 1698 port->mon_data.modem_status = status;
1721 mon_data_ext.rx_cnt[i] = port->mon_data.rxcnt; 1699 me->rx_cnt[p] = port->mon_data.rxcnt;
1722 mon_data_ext.tx_cnt[i] = port->mon_data.txcnt; 1700 me->tx_cnt[p] = port->mon_data.txcnt;
1723 mon_data_ext.up_rxcnt[i] = 1701 me->up_rxcnt[p] = port->mon_data.up_rxcnt;
1724 port->mon_data.up_rxcnt; 1702 me->up_txcnt[p] = port->mon_data.up_txcnt;
1725 mon_data_ext.up_txcnt[i] = 1703 me->modem_status[p] =
1726 port->mon_data.up_txcnt;
1727 mon_data_ext.modem_status[i] =
1728 port->mon_data.modem_status; 1704 port->mon_data.modem_status;
1729 mon_data_ext.baudrate[i] = 1705 me->baudrate[p] = tty_get_baud_rate(port->port.tty);
1730 tty_get_baud_rate(port->port.tty);
1731 1706
1732 if (!port->port.tty || !port->port.tty->termios) { 1707 if (!port->port.tty || !port->port.tty->termios) {
1733 cflag = port->normal_termios.c_cflag; 1708 cflag = port->normal_termios.c_cflag;
@@ -1737,40 +1712,31 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1737 iflag = port->port.tty->termios->c_iflag; 1712 iflag = port->port.tty->termios->c_iflag;
1738 } 1713 }
1739 1714
1740 mon_data_ext.databits[i] = cflag & CSIZE; 1715 me->databits[p] = cflag & CSIZE;
1741 1716 me->stopbits[p] = cflag & CSTOPB;
1742 mon_data_ext.stopbits[i] = cflag & CSTOPB; 1717 me->parity[p] = cflag & (PARENB | PARODD |
1743 1718 CMSPAR);
1744 mon_data_ext.parity[i] =
1745 cflag & (PARENB | PARODD | CMSPAR);
1746
1747 mon_data_ext.flowctrl[i] = 0x00;
1748 1719
1749 if (cflag & CRTSCTS) 1720 if (cflag & CRTSCTS)
1750 mon_data_ext.flowctrl[i] |= 0x03; 1721 me->flowctrl[p] |= 0x03;
1751 1722
1752 if (iflag & (IXON | IXOFF)) 1723 if (iflag & (IXON | IXOFF))
1753 mon_data_ext.flowctrl[i] |= 0x0C; 1724 me->flowctrl[p] |= 0x0C;
1754 1725
1755 if (port->type == PORT_16550A) 1726 if (port->type == PORT_16550A)
1756 mon_data_ext.fifo[i] = 1; 1727 me->fifo[p] = 1;
1757 else
1758 mon_data_ext.fifo[i] = 0;
1759 1728
1760 p = i % 4; 1729 opmode = inb(port->opmode_ioaddr) >>
1761 shiftbit = p * 2; 1730 ((p % 4) * 2);
1762 opmode = inb(port->opmode_ioaddr) >> shiftbit;
1763 opmode &= OP_MODE_MASK; 1731 opmode &= OP_MODE_MASK;
1764 1732 me->iftype[p] = opmode;
1765 mon_data_ext.iftype[i] = opmode;
1766
1767 } 1733 }
1768 } 1734 }
1769 unlock_kernel(); 1735 unlock_kernel();
1770 if (copy_to_user(argp, &mon_data_ext, 1736 if (copy_to_user(argp, me, sizeof(*me)))
1771 sizeof(mon_data_ext))) 1737 ret = -EFAULT;
1772 return -EFAULT; 1738 kfree(me);
1773 return 0; 1739 return ret;
1774 } 1740 }
1775 default: 1741 default:
1776 return -ENOIOCTLCMD; 1742 return -ENOIOCTLCMD;
@@ -1804,7 +1770,6 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1804{ 1770{
1805 struct mxser_port *info = tty->driver_data; 1771 struct mxser_port *info = tty->driver_data;
1806 struct async_icount cnow; 1772 struct async_icount cnow;
1807 struct serial_icounter_struct __user *p_cuser;
1808 unsigned long flags; 1773 unsigned long flags;
1809 void __user *argp = (void __user *)arg; 1774 void __user *argp = (void __user *)arg;
1810 int retval; 1775 int retval;
@@ -1884,30 +1849,26 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1884 * NB: both 1->0 and 0->1 transitions are counted except for 1849 * NB: both 1->0 and 0->1 transitions are counted except for
1885 * RI where only 0->1 is counted. 1850 * RI where only 0->1 is counted.
1886 */ 1851 */
1887 case TIOCGICOUNT: 1852 case TIOCGICOUNT: {
1853 struct serial_icounter_struct icnt = { 0 };
1888 spin_lock_irqsave(&info->slock, flags); 1854 spin_lock_irqsave(&info->slock, flags);
1889 cnow = info->icount; 1855 cnow = info->icount;
1890 spin_unlock_irqrestore(&info->slock, flags); 1856 spin_unlock_irqrestore(&info->slock, flags);
1891 p_cuser = argp; 1857
1892 if (put_user(cnow.frame, &p_cuser->frame)) 1858 icnt.frame = cnow.frame;
1893 return -EFAULT; 1859 icnt.brk = cnow.brk;
1894 if (put_user(cnow.brk, &p_cuser->brk)) 1860 icnt.overrun = cnow.overrun;
1895 return -EFAULT; 1861 icnt.buf_overrun = cnow.buf_overrun;
1896 if (put_user(cnow.overrun, &p_cuser->overrun)) 1862 icnt.parity = cnow.parity;
1897 return -EFAULT; 1863 icnt.rx = cnow.rx;
1898 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun)) 1864 icnt.tx = cnow.tx;
1899 return -EFAULT; 1865 icnt.cts = cnow.cts;
1900 if (put_user(cnow.parity, &p_cuser->parity)) 1866 icnt.dsr = cnow.dsr;
1901 return -EFAULT; 1867 icnt.rng = cnow.rng;
1902 if (put_user(cnow.rx, &p_cuser->rx)) 1868 icnt.dcd = cnow.dcd;
1903 return -EFAULT; 1869
1904 if (put_user(cnow.tx, &p_cuser->tx)) 1870 return copy_to_user(argp, &icnt, sizeof(icnt)) ? -EFAULT : 0;
1905 return -EFAULT; 1871 }
1906 put_user(cnow.cts, &p_cuser->cts);
1907 put_user(cnow.dsr, &p_cuser->dsr);
1908 put_user(cnow.rng, &p_cuser->rng);
1909 put_user(cnow.dcd, &p_cuser->dcd);
1910 return 0;
1911 case MOXA_HighSpeedOn: 1872 case MOXA_HighSpeedOn:
1912 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp); 1873 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1913 case MOXA_SDS_RSTICOUNTER: 1874 case MOXA_SDS_RSTICOUNTER:
@@ -2503,7 +2464,8 @@ static int __devinit mxser_initbrd(struct mxser_board *brd,
2503 unsigned int i; 2464 unsigned int i;
2504 int retval; 2465 int retval;
2505 2466
2506 printk(KERN_INFO "max. baud rate = %d bps.\n", brd->ports[0].max_baud); 2467 printk(KERN_INFO "mxser: max. baud rate = %d bps\n",
2468 brd->ports[0].max_baud);
2507 2469
2508 for (i = 0; i < brd->info->nports; i++) { 2470 for (i = 0; i < brd->info->nports; i++) {
2509 info = &brd->ports[i]; 2471 info = &brd->ports[i];
@@ -2586,28 +2548,32 @@ static int __init mxser_get_ISA_conf(int cap, struct mxser_board *brd)
2586 irq = regs[9] & 0xF000; 2548 irq = regs[9] & 0xF000;
2587 irq = irq | (irq >> 4); 2549 irq = irq | (irq >> 4);
2588 if (irq != (regs[9] & 0xFF00)) 2550 if (irq != (regs[9] & 0xFF00))
2589 return MXSER_ERR_IRQ_CONFLIT; 2551 goto err_irqconflict;
2590 } else if (brd->info->nports == 4) { 2552 } else if (brd->info->nports == 4) {
2591 irq = regs[9] & 0xF000; 2553 irq = regs[9] & 0xF000;
2592 irq = irq | (irq >> 4); 2554 irq = irq | (irq >> 4);
2593 irq = irq | (irq >> 8); 2555 irq = irq | (irq >> 8);
2594 if (irq != regs[9]) 2556 if (irq != regs[9])
2595 return MXSER_ERR_IRQ_CONFLIT; 2557 goto err_irqconflict;
2596 } else if (brd->info->nports == 8) { 2558 } else if (brd->info->nports == 8) {
2597 irq = regs[9] & 0xF000; 2559 irq = regs[9] & 0xF000;
2598 irq = irq | (irq >> 4); 2560 irq = irq | (irq >> 4);
2599 irq = irq | (irq >> 8); 2561 irq = irq | (irq >> 8);
2600 if ((irq != regs[9]) || (irq != regs[10])) 2562 if ((irq != regs[9]) || (irq != regs[10]))
2601 return MXSER_ERR_IRQ_CONFLIT; 2563 goto err_irqconflict;
2602 } 2564 }
2603 2565
2604 if (!irq) 2566 if (!irq) {
2605 return MXSER_ERR_IRQ; 2567 printk(KERN_ERR "mxser: interrupt number unset\n");
2568 return -EIO;
2569 }
2606 brd->irq = ((int)(irq & 0xF000) >> 12); 2570 brd->irq = ((int)(irq & 0xF000) >> 12);
2607 for (i = 0; i < 8; i++) 2571 for (i = 0; i < 8; i++)
2608 brd->ports[i].ioaddr = (int) regs[i + 1] & 0xFFF8; 2572 brd->ports[i].ioaddr = (int) regs[i + 1] & 0xFFF8;
2609 if ((regs[12] & 0x80) == 0) 2573 if ((regs[12] & 0x80) == 0) {
2610 return MXSER_ERR_VECTOR; 2574 printk(KERN_ERR "mxser: invalid interrupt vector\n");
2575 return -EIO;
2576 }
2611 brd->vector = (int)regs[11]; /* interrupt vector */ 2577 brd->vector = (int)regs[11]; /* interrupt vector */
2612 if (id == 1) 2578 if (id == 1)
2613 brd->vector_mask = 0x00FF; 2579 brd->vector_mask = 0x00FF;
@@ -2634,13 +2600,26 @@ static int __init mxser_get_ISA_conf(int cap, struct mxser_board *brd)
2634 else 2600 else
2635 brd->uart_type = PORT_16450; 2601 brd->uart_type = PORT_16450;
2636 if (!request_region(brd->ports[0].ioaddr, 8 * brd->info->nports, 2602 if (!request_region(brd->ports[0].ioaddr, 8 * brd->info->nports,
2637 "mxser(IO)")) 2603 "mxser(IO)")) {
2638 return MXSER_ERR_IOADDR; 2604 printk(KERN_ERR "mxser: can't request ports I/O region: "
2605 "0x%.8lx-0x%.8lx\n",
2606 brd->ports[0].ioaddr, brd->ports[0].ioaddr +
2607 8 * brd->info->nports - 1);
2608 return -EIO;
2609 }
2639 if (!request_region(brd->vector, 1, "mxser(vector)")) { 2610 if (!request_region(brd->vector, 1, "mxser(vector)")) {
2640 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports); 2611 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
2641 return MXSER_ERR_VECTOR; 2612 printk(KERN_ERR "mxser: can't request interrupt vector region: "
2613 "0x%.8lx-0x%.8lx\n",
2614 brd->ports[0].ioaddr, brd->ports[0].ioaddr +
2615 8 * brd->info->nports - 1);
2616 return -EIO;
2642 } 2617 }
2643 return brd->info->nports; 2618 return brd->info->nports;
2619
2620err_irqconflict:
2621 printk(KERN_ERR "mxser: invalid interrupt number\n");
2622 return -EIO;
2644} 2623}
2645 2624
2646static int __devinit mxser_probe(struct pci_dev *pdev, 2625static int __devinit mxser_probe(struct pci_dev *pdev,
@@ -2657,20 +2636,20 @@ static int __devinit mxser_probe(struct pci_dev *pdev,
2657 break; 2636 break;
2658 2637
2659 if (i >= MXSER_BOARDS) { 2638 if (i >= MXSER_BOARDS) {
2660 printk(KERN_ERR "Too many Smartio/Industio family boards found " 2639 dev_err(&pdev->dev, "too many boards found (maximum %d), board "
2661 "(maximum %d), board not configured\n", MXSER_BOARDS); 2640 "not configured\n", MXSER_BOARDS);
2662 goto err; 2641 goto err;
2663 } 2642 }
2664 2643
2665 brd = &mxser_boards[i]; 2644 brd = &mxser_boards[i];
2666 brd->idx = i * MXSER_PORTS_PER_BOARD; 2645 brd->idx = i * MXSER_PORTS_PER_BOARD;
2667 printk(KERN_INFO "Found MOXA %s board (BusNo=%d, DevNo=%d)\n", 2646 dev_info(&pdev->dev, "found MOXA %s board (BusNo=%d, DevNo=%d)\n",
2668 mxser_cards[ent->driver_data].name, 2647 mxser_cards[ent->driver_data].name,
2669 pdev->bus->number, PCI_SLOT(pdev->devfn)); 2648 pdev->bus->number, PCI_SLOT(pdev->devfn));
2670 2649
2671 retval = pci_enable_device(pdev); 2650 retval = pci_enable_device(pdev);
2672 if (retval) { 2651 if (retval) {
2673 printk(KERN_ERR "Moxa SmartI/O PCI enable fail !\n"); 2652 dev_err(&pdev->dev, "PCI enable failed\n");
2674 goto err; 2653 goto err;
2675 } 2654 }
2676 2655
@@ -2772,11 +2751,8 @@ static struct pci_driver mxser_driver = {
2772static int __init mxser_module_init(void) 2751static int __init mxser_module_init(void)
2773{ 2752{
2774 struct mxser_board *brd; 2753 struct mxser_board *brd;
2775 unsigned long cap; 2754 unsigned int b, i, m;
2776 unsigned int i, m, isaloop; 2755 int retval;
2777 int retval, b;
2778
2779 pr_debug("Loading module mxser ...\n");
2780 2756
2781 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1); 2757 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
2782 if (!mxvar_sdriver) 2758 if (!mxvar_sdriver)
@@ -2806,74 +2782,43 @@ static int __init mxser_module_init(void)
2806 goto err_put; 2782 goto err_put;
2807 } 2783 }
2808 2784
2809 mxvar_diagflag = 0;
2810
2811 m = 0;
2812 /* Start finding ISA boards here */ 2785 /* Start finding ISA boards here */
2813 for (isaloop = 0; isaloop < 2; isaloop++) 2786 for (m = 0, b = 0; b < MXSER_BOARDS; b++) {
2814 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) { 2787 if (!ioaddr[b])
2815 if (!isaloop) 2788 continue;
2816 cap = mxserBoardCAP[b]; /* predefined */ 2789
2817 else 2790 brd = &mxser_boards[m];
2818 cap = ioaddr[b]; /* module param */ 2791 retval = mxser_get_ISA_conf(!ioaddr[b], brd);
2819 2792 if (retval <= 0) {
2820 if (!cap) 2793 brd->info = NULL;
2821 continue; 2794 continue;
2795 }
2822 2796
2823 brd = &mxser_boards[m]; 2797 printk(KERN_INFO "mxser: found MOXA %s board (CAP=0x%lx)\n",
2824 retval = mxser_get_ISA_conf(cap, brd); 2798 brd->info->name, ioaddr[b]);
2825
2826 if (retval != 0)
2827 printk(KERN_INFO "Found MOXA %s board "
2828 "(CAP=0x%x)\n",
2829 brd->info->name, ioaddr[b]);
2830
2831 if (retval <= 0) {
2832 if (retval == MXSER_ERR_IRQ)
2833 printk(KERN_ERR "Invalid interrupt "
2834 "number, board not "
2835 "configured\n");
2836 else if (retval == MXSER_ERR_IRQ_CONFLIT)
2837 printk(KERN_ERR "Invalid interrupt "
2838 "number, board not "
2839 "configured\n");
2840 else if (retval == MXSER_ERR_VECTOR)
2841 printk(KERN_ERR "Invalid interrupt "
2842 "vector, board not "
2843 "configured\n");
2844 else if (retval == MXSER_ERR_IOADDR)
2845 printk(KERN_ERR "Invalid I/O address, "
2846 "board not configured\n");
2847
2848 brd->info = NULL;
2849 continue;
2850 }
2851 2799
2852 /* mxser_initbrd will hook ISR. */ 2800 /* mxser_initbrd will hook ISR. */
2853 if (mxser_initbrd(brd, NULL) < 0) { 2801 if (mxser_initbrd(brd, NULL) < 0) {
2854 brd->info = NULL; 2802 brd->info = NULL;
2855 continue; 2803 continue;
2856 } 2804 }
2857 2805
2858 brd->idx = m * MXSER_PORTS_PER_BOARD; 2806 brd->idx = m * MXSER_PORTS_PER_BOARD;
2859 for (i = 0; i < brd->info->nports; i++) 2807 for (i = 0; i < brd->info->nports; i++)
2860 tty_register_device(mxvar_sdriver, brd->idx + i, 2808 tty_register_device(mxvar_sdriver, brd->idx + i, NULL);
2861 NULL);
2862 2809
2863 m++; 2810 m++;
2864 } 2811 }
2865 2812
2866 retval = pci_register_driver(&mxser_driver); 2813 retval = pci_register_driver(&mxser_driver);
2867 if (retval) { 2814 if (retval) {
2868 printk(KERN_ERR "Can't register pci driver\n"); 2815 printk(KERN_ERR "mxser: can't register pci driver\n");
2869 if (!m) { 2816 if (!m) {
2870 retval = -ENODEV; 2817 retval = -ENODEV;
2871 goto err_unr; 2818 goto err_unr;
2872 } /* else: we have some ISA cards under control */ 2819 } /* else: we have some ISA cards under control */
2873 } 2820 }
2874 2821
2875 pr_debug("Done.\n");
2876
2877 return 0; 2822 return 0;
2878err_unr: 2823err_unr:
2879 tty_unregister_driver(mxvar_sdriver); 2824 tty_unregister_driver(mxvar_sdriver);
@@ -2886,8 +2831,6 @@ static void __exit mxser_module_exit(void)
2886{ 2831{
2887 unsigned int i, j; 2832 unsigned int i, j;
2888 2833
2889 pr_debug("Unloading module mxser ...\n");
2890
2891 pci_unregister_driver(&mxser_driver); 2834 pci_unregister_driver(&mxser_driver);
2892 2835
2893 for (i = 0; i < MXSER_BOARDS; i++) /* ISA remains */ 2836 for (i = 0; i < MXSER_BOARDS; i++) /* ISA remains */
@@ -2901,8 +2844,6 @@ static void __exit mxser_module_exit(void)
2901 for (i = 0; i < MXSER_BOARDS; i++) 2844 for (i = 0; i < MXSER_BOARDS; i++)
2902 if (mxser_boards[i].info != NULL) 2845 if (mxser_boards[i].info != NULL)
2903 mxser_release_res(&mxser_boards[i], NULL, 1); 2846 mxser_release_res(&mxser_boards[i], NULL, 1);
2904
2905 pr_debug("Done.\n");
2906} 2847}
2907 2848
2908module_init(mxser_module_init); 2849module_init(mxser_module_init);
diff --git a/drivers/char/nwflash.c b/drivers/char/nwflash.c
index ba012c2bdf7a..f9f72a211292 100644
--- a/drivers/char/nwflash.c
+++ b/drivers/char/nwflash.c
@@ -122,35 +122,20 @@ static int flash_ioctl(struct inode *inodep, struct file *filep, unsigned int cm
122static ssize_t flash_read(struct file *file, char __user *buf, size_t size, 122static ssize_t flash_read(struct file *file, char __user *buf, size_t size,
123 loff_t *ppos) 123 loff_t *ppos)
124{ 124{
125 unsigned long p = *ppos; 125 ssize_t ret;
126 unsigned int count = size;
127 int ret = 0;
128 126
129 if (flashdebug) 127 if (flashdebug)
130 printk(KERN_DEBUG "flash_read: flash_read: offset=0x%lX, " 128 printk(KERN_DEBUG "flash_read: flash_read: offset=0x%lX, "
131 "buffer=%p, count=0x%X.\n", p, buf, count); 129 "buffer=%p, count=0x%X.\n", p, buf, count);
130 /*
131 * We now lock against reads and writes. --rmk
132 */
133 if (mutex_lock_interruptible(&nwflash_mutex))
134 return -ERESTARTSYS;
132 135
133 if (count) 136 ret = simple_read_from_buffer(buf, size, ppos, FLASH_BASE, gbFlashSize);
134 ret = -ENXIO; 137 mutex_unlock(&nwflash_mutex);
135
136 if (p < gbFlashSize) {
137 if (count > gbFlashSize - p)
138 count = gbFlashSize - p;
139 138
140 /*
141 * We now lock against reads and writes. --rmk
142 */
143 if (mutex_lock_interruptible(&nwflash_mutex))
144 return -ERESTARTSYS;
145
146 ret = copy_to_user(buf, (void *)(FLASH_BASE + p), count);
147 if (ret == 0) {
148 ret = count;
149 *ppos += count;
150 } else
151 ret = -EFAULT;
152 mutex_unlock(&nwflash_mutex);
153 }
154 return ret; 139 return ret;
155} 140}
156 141
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 7af7a7e6b9c2..bee39fdfba73 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -67,7 +67,7 @@
67#include <linux/major.h> 67#include <linux/major.h>
68#include <linux/ppdev.h> 68#include <linux/ppdev.h>
69#include <linux/smp_lock.h> 69#include <linux/smp_lock.h>
70#include <asm/uaccess.h> 70#include <linux/uaccess.h>
71 71
72#define PP_VERSION "ppdev: user-space parallel port driver" 72#define PP_VERSION "ppdev: user-space parallel port driver"
73#define CHRDEV "ppdev" 73#define CHRDEV "ppdev"
@@ -328,10 +328,9 @@ static enum ieee1284_phase init_phase (int mode)
328 return IEEE1284_PH_FWD_IDLE; 328 return IEEE1284_PH_FWD_IDLE;
329} 329}
330 330
331static int pp_ioctl(struct inode *inode, struct file *file, 331static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
332 unsigned int cmd, unsigned long arg)
333{ 332{
334 unsigned int minor = iminor(inode); 333 unsigned int minor = iminor(file->f_path.dentry->d_inode);
335 struct pp_struct *pp = file->private_data; 334 struct pp_struct *pp = file->private_data;
336 struct parport * port; 335 struct parport * port;
337 void __user *argp = (void __user *)arg; 336 void __user *argp = (void __user *)arg;
@@ -634,6 +633,15 @@ static int pp_ioctl(struct inode *inode, struct file *file,
634 return 0; 633 return 0;
635} 634}
636 635
636static long pp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
637{
638 long ret;
639 lock_kernel();
640 ret = pp_do_ioctl(file, cmd, arg);
641 unlock_kernel();
642 return ret;
643}
644
637static int pp_open (struct inode * inode, struct file * file) 645static int pp_open (struct inode * inode, struct file * file)
638{ 646{
639 unsigned int minor = iminor(inode); 647 unsigned int minor = iminor(inode);
@@ -745,7 +753,7 @@ static const struct file_operations pp_fops = {
745 .read = pp_read, 753 .read = pp_read,
746 .write = pp_write, 754 .write = pp_write,
747 .poll = pp_poll, 755 .poll = pp_poll,
748 .ioctl = pp_ioctl, 756 .unlocked_ioctl = pp_ioctl,
749 .open = pp_open, 757 .open = pp_open,
750 .release = pp_release, 758 .release = pp_release,
751}; 759};
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 0cf98bd4f2d2..e0d0e371909c 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -236,6 +236,7 @@
236#include <linux/fs.h> 236#include <linux/fs.h>
237#include <linux/genhd.h> 237#include <linux/genhd.h>
238#include <linux/interrupt.h> 238#include <linux/interrupt.h>
239#include <linux/mm.h>
239#include <linux/spinlock.h> 240#include <linux/spinlock.h>
240#include <linux/percpu.h> 241#include <linux/percpu.h>
241#include <linux/cryptohash.h> 242#include <linux/cryptohash.h>
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index 0cdfee152916..a8f68a3f14dd 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -179,7 +179,7 @@ static int rio_set_real_termios(void *ptr);
179static void rio_hungup(void *ptr); 179static void rio_hungup(void *ptr);
180static void rio_close(void *ptr); 180static void rio_close(void *ptr);
181static int rio_chars_in_buffer(void *ptr); 181static int rio_chars_in_buffer(void *ptr);
182static int rio_fw_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); 182static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
183static int rio_init_drivers(void); 183static int rio_init_drivers(void);
184 184
185static void my_hd(void *addr, int len); 185static void my_hd(void *addr, int len);
@@ -240,7 +240,7 @@ static struct real_driver rio_real_driver = {
240 240
241static const struct file_operations rio_fw_fops = { 241static const struct file_operations rio_fw_fops = {
242 .owner = THIS_MODULE, 242 .owner = THIS_MODULE,
243 .ioctl = rio_fw_ioctl, 243 .unlocked_ioctl = rio_fw_ioctl,
244}; 244};
245 245
246static struct miscdevice rio_fw_device = { 246static struct miscdevice rio_fw_device = {
@@ -560,13 +560,15 @@ static void rio_close(void *ptr)
560 560
561 561
562 562
563static int rio_fw_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) 563static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
564{ 564{
565 int rc = 0; 565 int rc = 0;
566 func_enter(); 566 func_enter();
567 567
568 /* The "dev" argument isn't used. */ 568 /* The "dev" argument isn't used. */
569 lock_kernel();
569 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN)); 570 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
571 unlock_kernel();
570 572
571 func_exit(); 573 func_exit();
572 return rc; 574 return rc;
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index fa92a8af5a5a..d9799e2bcfbf 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -78,9 +78,10 @@
78#include <linux/wait.h> 78#include <linux/wait.h>
79#include <linux/bcd.h> 79#include <linux/bcd.h>
80#include <linux/delay.h> 80#include <linux/delay.h>
81#include <linux/smp_lock.h>
82#include <linux/uaccess.h>
81 83
82#include <asm/current.h> 84#include <asm/current.h>
83#include <asm/uaccess.h>
84#include <asm/system.h> 85#include <asm/system.h>
85 86
86#ifdef CONFIG_X86 87#ifdef CONFIG_X86
@@ -120,8 +121,6 @@ static irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id)
120 return 0; 121 return 0;
121} 122}
122#endif 123#endif
123#else
124extern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id);
125#endif 124#endif
126 125
127/* 126/*
@@ -144,8 +143,8 @@ static DEFINE_TIMER(rtc_irq_timer, rtc_dropped_irq, 0, 0);
144static ssize_t rtc_read(struct file *file, char __user *buf, 143static ssize_t rtc_read(struct file *file, char __user *buf,
145 size_t count, loff_t *ppos); 144 size_t count, loff_t *ppos);
146 145
147static int rtc_ioctl(struct inode *inode, struct file *file, 146static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
148 unsigned int cmd, unsigned long arg); 147static void rtc_get_rtc_time(struct rtc_time *rtc_tm);
149 148
150#ifdef RTC_IRQ 149#ifdef RTC_IRQ
151static unsigned int rtc_poll(struct file *file, poll_table *wait); 150static unsigned int rtc_poll(struct file *file, poll_table *wait);
@@ -237,7 +236,7 @@ static inline unsigned char rtc_is_updating(void)
237 * (See ./arch/XXXX/kernel/time.c for the set_rtc_mmss() function.) 236 * (See ./arch/XXXX/kernel/time.c for the set_rtc_mmss() function.)
238 */ 237 */
239 238
240irqreturn_t rtc_interrupt(int irq, void *dev_id) 239static irqreturn_t rtc_interrupt(int irq, void *dev_id)
241{ 240{
242 /* 241 /*
243 * Can be an alarm interrupt, update complete interrupt, 242 * Can be an alarm interrupt, update complete interrupt,
@@ -719,10 +718,13 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
719 &wtime, sizeof wtime) ? -EFAULT : 0; 718 &wtime, sizeof wtime) ? -EFAULT : 0;
720} 719}
721 720
722static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 721static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
723 unsigned long arg)
724{ 722{
725 return rtc_do_ioctl(cmd, arg, 0); 723 long ret;
724 lock_kernel();
725 ret = rtc_do_ioctl(cmd, arg, 0);
726 unlock_kernel();
727 return ret;
726} 728}
727 729
728/* 730/*
@@ -915,7 +917,7 @@ static const struct file_operations rtc_fops = {
915#ifdef RTC_IRQ 917#ifdef RTC_IRQ
916 .poll = rtc_poll, 918 .poll = rtc_poll,
917#endif 919#endif
918 .ioctl = rtc_ioctl, 920 .unlocked_ioctl = rtc_ioctl,
919 .open = rtc_open, 921 .open = rtc_open,
920 .release = rtc_release, 922 .release = rtc_release,
921 .fasync = rtc_fasync, 923 .fasync = rtc_fasync,
@@ -1302,7 +1304,7 @@ static int rtc_proc_open(struct inode *inode, struct file *file)
1302} 1304}
1303#endif 1305#endif
1304 1306
1305void rtc_get_rtc_time(struct rtc_time *rtc_tm) 1307static void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1306{ 1308{
1307 unsigned long uip_watchdog = jiffies, flags; 1309 unsigned long uip_watchdog = jiffies, flags;
1308 unsigned char ctrl; 1310 unsigned char ctrl;
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index b976248e1072..19db1eb87c26 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -1256,7 +1256,6 @@ static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1256static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) 1256static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1257{ 1257{
1258 struct stlport *portp; 1258 struct stlport *portp;
1259 unsigned int ival;
1260 int rc; 1259 int rc;
1261 void __user *argp = (void __user *)arg; 1260 void __user *argp = (void __user *)arg;
1262 1261
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index 2162439bbe48..c385206f9db5 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -286,8 +286,8 @@ static void sx_close(void *ptr);
286static int sx_chars_in_buffer(void *ptr); 286static int sx_chars_in_buffer(void *ptr);
287static int sx_init_board(struct sx_board *board); 287static int sx_init_board(struct sx_board *board);
288static int sx_init_portstructs(int nboards, int nports); 288static int sx_init_portstructs(int nboards, int nports);
289static int sx_fw_ioctl(struct inode *inode, struct file *filp, 289static long sx_fw_ioctl(struct file *filp, unsigned int cmd,
290 unsigned int cmd, unsigned long arg); 290 unsigned long arg);
291static int sx_init_drivers(void); 291static int sx_init_drivers(void);
292 292
293static struct tty_driver *sx_driver; 293static struct tty_driver *sx_driver;
@@ -396,7 +396,7 @@ static struct real_driver sx_real_driver = {
396 396
397static const struct file_operations sx_fw_fops = { 397static const struct file_operations sx_fw_fops = {
398 .owner = THIS_MODULE, 398 .owner = THIS_MODULE,
399 .ioctl = sx_fw_ioctl, 399 .unlocked_ioctl = sx_fw_ioctl,
400}; 400};
401 401
402static struct miscdevice sx_fw_device = { 402static struct miscdevice sx_fw_device = {
@@ -1686,10 +1686,10 @@ static int do_memtest_w(struct sx_board *board, int min, int max)
1686} 1686}
1687#endif 1687#endif
1688 1688
1689static int sx_fw_ioctl(struct inode *inode, struct file *filp, 1689static long sx_fw_ioctl(struct file *filp, unsigned int cmd,
1690 unsigned int cmd, unsigned long arg) 1690 unsigned long arg)
1691{ 1691{
1692 int rc = 0; 1692 long rc = 0;
1693 int __user *descr = (int __user *)arg; 1693 int __user *descr = (int __user *)arg;
1694 int i; 1694 int i;
1695 static struct sx_board *board = NULL; 1695 static struct sx_board *board = NULL;
@@ -1699,13 +1699,10 @@ static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1699 1699
1700 func_enter(); 1700 func_enter();
1701 1701
1702#if 0 1702 if (!capable(CAP_SYS_RAWIO))
1703 /* Removed superuser check: Sysops can use the permissions on the device
1704 file to restrict access. Recommendation: Root only. (root.root 600) */
1705 if (!capable(CAP_SYS_ADMIN)) {
1706 return -EPERM; 1703 return -EPERM;
1707 } 1704
1708#endif 1705 lock_kernel();
1709 1706
1710 sx_dprintk(SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg); 1707 sx_dprintk(SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg);
1711 1708
@@ -1720,19 +1717,23 @@ static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1720 for (i = 0; i < SX_NBOARDS; i++) 1717 for (i = 0; i < SX_NBOARDS; i++)
1721 sx_dprintk(SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags); 1718 sx_dprintk(SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags);
1722 sx_dprintk(SX_DEBUG_FIRMWARE, "\n"); 1719 sx_dprintk(SX_DEBUG_FIRMWARE, "\n");
1720 unlock_kernel();
1723 return -EIO; 1721 return -EIO;
1724 } 1722 }
1725 1723
1726 switch (cmd) { 1724 switch (cmd) {
1727 case SXIO_SET_BOARD: 1725 case SXIO_SET_BOARD:
1728 sx_dprintk(SX_DEBUG_FIRMWARE, "set board to %ld\n", arg); 1726 sx_dprintk(SX_DEBUG_FIRMWARE, "set board to %ld\n", arg);
1727 rc = -EIO;
1729 if (arg >= SX_NBOARDS) 1728 if (arg >= SX_NBOARDS)
1730 return -EIO; 1729 break;
1731 sx_dprintk(SX_DEBUG_FIRMWARE, "not out of range\n"); 1730 sx_dprintk(SX_DEBUG_FIRMWARE, "not out of range\n");
1732 if (!(boards[arg].flags & SX_BOARD_PRESENT)) 1731 if (!(boards[arg].flags & SX_BOARD_PRESENT))
1733 return -EIO; 1732 break;
1734 sx_dprintk(SX_DEBUG_FIRMWARE, ".. and present!\n"); 1733 sx_dprintk(SX_DEBUG_FIRMWARE, ".. and present!\n");
1735 board = &boards[arg]; 1734 board = &boards[arg];
1735 rc = 0;
1736 /* FIXME: And this does ... nothing?? */
1736 break; 1737 break;
1737 case SXIO_GET_TYPE: 1738 case SXIO_GET_TYPE:
1738 rc = -ENOENT; /* If we manage to miss one, return error. */ 1739 rc = -ENOENT; /* If we manage to miss one, return error. */
@@ -1746,7 +1747,7 @@ static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1746 rc = SX_TYPE_SI; 1747 rc = SX_TYPE_SI;
1747 if (IS_EISA_BOARD(board)) 1748 if (IS_EISA_BOARD(board))
1748 rc = SX_TYPE_SI; 1749 rc = SX_TYPE_SI;
1749 sx_dprintk(SX_DEBUG_FIRMWARE, "returning type= %d\n", rc); 1750 sx_dprintk(SX_DEBUG_FIRMWARE, "returning type= %ld\n", rc);
1750 break; 1751 break;
1751 case SXIO_DO_RAMTEST: 1752 case SXIO_DO_RAMTEST:
1752 if (sx_initialized) /* Already initialized: better not ramtest the board. */ 1753 if (sx_initialized) /* Already initialized: better not ramtest the board. */
@@ -1760,19 +1761,26 @@ static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1760 rc = do_memtest(board, 0, 0x7ff8); 1761 rc = do_memtest(board, 0, 0x7ff8);
1761 /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */ 1762 /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */
1762 } 1763 }
1763 sx_dprintk(SX_DEBUG_FIRMWARE, "returning memtest result= %d\n", 1764 sx_dprintk(SX_DEBUG_FIRMWARE,
1764 rc); 1765 "returning memtest result= %ld\n", rc);
1765 break; 1766 break;
1766 case SXIO_DOWNLOAD: 1767 case SXIO_DOWNLOAD:
1767 if (sx_initialized) /* Already initialized */ 1768 if (sx_initialized) {/* Already initialized */
1768 return -EEXIST; 1769 rc = -EEXIST;
1769 if (!sx_reset(board)) 1770 break;
1770 return -EIO; 1771 }
1772 if (!sx_reset(board)) {
1773 rc = -EIO;
1774 break;
1775 }
1771 sx_dprintk(SX_DEBUG_INIT, "reset the board...\n"); 1776 sx_dprintk(SX_DEBUG_INIT, "reset the board...\n");
1772 1777
1773 tmp = kmalloc(SX_CHUNK_SIZE, GFP_USER); 1778 tmp = kmalloc(SX_CHUNK_SIZE, GFP_USER);
1774 if (!tmp) 1779 if (!tmp) {
1775 return -ENOMEM; 1780 rc = -ENOMEM;
1781 break;
1782 }
1783 /* FIXME: check returns */
1776 get_user(nbytes, descr++); 1784 get_user(nbytes, descr++);
1777 get_user(offset, descr++); 1785 get_user(offset, descr++);
1778 get_user(data, descr++); 1786 get_user(data, descr++);
@@ -1782,7 +1790,8 @@ static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1782 (i + SX_CHUNK_SIZE > nbytes) ? 1790 (i + SX_CHUNK_SIZE > nbytes) ?
1783 nbytes - i : SX_CHUNK_SIZE)) { 1791 nbytes - i : SX_CHUNK_SIZE)) {
1784 kfree(tmp); 1792 kfree(tmp);
1785 return -EFAULT; 1793 rc = -EFAULT;
1794 break;
1786 } 1795 }
1787 memcpy_toio(board->base2 + offset + i, tmp, 1796 memcpy_toio(board->base2 + offset + i, tmp,
1788 (i + SX_CHUNK_SIZE > nbytes) ? 1797 (i + SX_CHUNK_SIZE > nbytes) ?
@@ -1798,13 +1807,17 @@ static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1798 rc = sx_nports; 1807 rc = sx_nports;
1799 break; 1808 break;
1800 case SXIO_INIT: 1809 case SXIO_INIT:
1801 if (sx_initialized) /* Already initialized */ 1810 if (sx_initialized) { /* Already initialized */
1802 return -EEXIST; 1811 rc = -EEXIST;
1812 break;
1813 }
1803 /* This is not allowed until all boards are initialized... */ 1814 /* This is not allowed until all boards are initialized... */
1804 for (i = 0; i < SX_NBOARDS; i++) { 1815 for (i = 0; i < SX_NBOARDS; i++) {
1805 if ((boards[i].flags & SX_BOARD_PRESENT) && 1816 if ((boards[i].flags & SX_BOARD_PRESENT) &&
1806 !(boards[i].flags & SX_BOARD_INITIALIZED)) 1817 !(boards[i].flags & SX_BOARD_INITIALIZED)) {
1807 return -EIO; 1818 rc = -EIO;
1819 break;
1820 }
1808 } 1821 }
1809 for (i = 0; i < SX_NBOARDS; i++) 1822 for (i = 0; i < SX_NBOARDS; i++)
1810 if (!(boards[i].flags & SX_BOARD_PRESENT)) 1823 if (!(boards[i].flags & SX_BOARD_PRESENT))
@@ -1832,10 +1845,10 @@ static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1832 rc = sx_nports; 1845 rc = sx_nports;
1833 break; 1846 break;
1834 default: 1847 default:
1835 printk(KERN_WARNING "Unknown ioctl on firmware device (%x).\n", 1848 rc = -ENOTTY;
1836 cmd);
1837 break; 1849 break;
1838 } 1850 }
1851 unlock_kernel();
1839 func_exit(); 1852 func_exit();
1840 return rc; 1853 return rc;
1841} 1854}
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index e1fc193d9396..ae766d868454 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -580,91 +580,133 @@ void tpm_continue_selftest(struct tpm_chip *chip)
580} 580}
581EXPORT_SYMBOL_GPL(tpm_continue_selftest); 581EXPORT_SYMBOL_GPL(tpm_continue_selftest);
582 582
583#define TPM_INTERNAL_RESULT_SIZE 200
584
583ssize_t tpm_show_enabled(struct device * dev, struct device_attribute * attr, 585ssize_t tpm_show_enabled(struct device * dev, struct device_attribute * attr,
584 char *buf) 586 char *buf)
585{ 587{
586 u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 35)]; 588 u8 *data;
587 ssize_t rc; 589 ssize_t rc;
588 590
589 struct tpm_chip *chip = dev_get_drvdata(dev); 591 struct tpm_chip *chip = dev_get_drvdata(dev);
590 if (chip == NULL) 592 if (chip == NULL)
591 return -ENODEV; 593 return -ENODEV;
592 594
595 data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL);
596 if (!data)
597 return -ENOMEM;
598
593 memcpy(data, tpm_cap, sizeof(tpm_cap)); 599 memcpy(data, tpm_cap, sizeof(tpm_cap));
594 data[TPM_CAP_IDX] = TPM_CAP_FLAG; 600 data[TPM_CAP_IDX] = TPM_CAP_FLAG;
595 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_PERM; 601 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_PERM;
596 602
597 rc = transmit_cmd(chip, data, sizeof(data), 603 rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE,
598 "attemtping to determine the permanent state"); 604 "attemtping to determine the permanent enabled state");
599 if (rc) 605 if (rc) {
606 kfree(data);
600 return 0; 607 return 0;
601 return sprintf(buf, "%d\n", !data[TPM_GET_CAP_PERM_DISABLE_IDX]); 608 }
609
610 rc = sprintf(buf, "%d\n", !data[TPM_GET_CAP_PERM_DISABLE_IDX]);
611
612 kfree(data);
613 return rc;
602} 614}
603EXPORT_SYMBOL_GPL(tpm_show_enabled); 615EXPORT_SYMBOL_GPL(tpm_show_enabled);
604 616
605ssize_t tpm_show_active(struct device * dev, struct device_attribute * attr, 617ssize_t tpm_show_active(struct device * dev, struct device_attribute * attr,
606 char *buf) 618 char *buf)
607{ 619{
608 u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 35)]; 620 u8 *data;
609 ssize_t rc; 621 ssize_t rc;
610 622
611 struct tpm_chip *chip = dev_get_drvdata(dev); 623 struct tpm_chip *chip = dev_get_drvdata(dev);
612 if (chip == NULL) 624 if (chip == NULL)
613 return -ENODEV; 625 return -ENODEV;
614 626
627 data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL);
628 if (!data)
629 return -ENOMEM;
630
615 memcpy(data, tpm_cap, sizeof(tpm_cap)); 631 memcpy(data, tpm_cap, sizeof(tpm_cap));
616 data[TPM_CAP_IDX] = TPM_CAP_FLAG; 632 data[TPM_CAP_IDX] = TPM_CAP_FLAG;
617 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_PERM; 633 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_PERM;
618 634
619 rc = transmit_cmd(chip, data, sizeof(data), 635 rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE,
620 "attemtping to determine the permanent state"); 636 "attemtping to determine the permanent active state");
621 if (rc) 637 if (rc) {
638 kfree(data);
622 return 0; 639 return 0;
623 return sprintf(buf, "%d\n", !data[TPM_GET_CAP_PERM_INACTIVE_IDX]); 640 }
641
642 rc = sprintf(buf, "%d\n", !data[TPM_GET_CAP_PERM_INACTIVE_IDX]);
643
644 kfree(data);
645 return rc;
624} 646}
625EXPORT_SYMBOL_GPL(tpm_show_active); 647EXPORT_SYMBOL_GPL(tpm_show_active);
626 648
627ssize_t tpm_show_owned(struct device * dev, struct device_attribute * attr, 649ssize_t tpm_show_owned(struct device * dev, struct device_attribute * attr,
628 char *buf) 650 char *buf)
629{ 651{
630 u8 data[sizeof(tpm_cap)]; 652 u8 *data;
631 ssize_t rc; 653 ssize_t rc;
632 654
633 struct tpm_chip *chip = dev_get_drvdata(dev); 655 struct tpm_chip *chip = dev_get_drvdata(dev);
634 if (chip == NULL) 656 if (chip == NULL)
635 return -ENODEV; 657 return -ENODEV;
636 658
659 data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL);
660 if (!data)
661 return -ENOMEM;
662
637 memcpy(data, tpm_cap, sizeof(tpm_cap)); 663 memcpy(data, tpm_cap, sizeof(tpm_cap));
638 data[TPM_CAP_IDX] = TPM_CAP_PROP; 664 data[TPM_CAP_IDX] = TPM_CAP_PROP;
639 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_OWNER; 665 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_OWNER;
640 666
641 rc = transmit_cmd(chip, data, sizeof(data), 667 rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE,
642 "attempting to determine the owner state"); 668 "attempting to determine the owner state");
643 if (rc) 669 if (rc) {
670 kfree(data);
644 return 0; 671 return 0;
645 return sprintf(buf, "%d\n", data[TPM_GET_CAP_RET_BOOL_1_IDX]); 672 }
673
674 rc = sprintf(buf, "%d\n", data[TPM_GET_CAP_RET_BOOL_1_IDX]);
675
676 kfree(data);
677 return rc;
646} 678}
647EXPORT_SYMBOL_GPL(tpm_show_owned); 679EXPORT_SYMBOL_GPL(tpm_show_owned);
648 680
649ssize_t tpm_show_temp_deactivated(struct device * dev, 681ssize_t tpm_show_temp_deactivated(struct device * dev,
650 struct device_attribute * attr, char *buf) 682 struct device_attribute * attr, char *buf)
651{ 683{
652 u8 data[sizeof(tpm_cap)]; 684 u8 *data;
653 ssize_t rc; 685 ssize_t rc;
654 686
655 struct tpm_chip *chip = dev_get_drvdata(dev); 687 struct tpm_chip *chip = dev_get_drvdata(dev);
656 if (chip == NULL) 688 if (chip == NULL)
657 return -ENODEV; 689 return -ENODEV;
658 690
691 data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL);
692 if (!data)
693 return -ENOMEM;
694
659 memcpy(data, tpm_cap, sizeof(tpm_cap)); 695 memcpy(data, tpm_cap, sizeof(tpm_cap));
660 data[TPM_CAP_IDX] = TPM_CAP_FLAG; 696 data[TPM_CAP_IDX] = TPM_CAP_FLAG;
661 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_VOL; 697 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_VOL;
662 698
663 rc = transmit_cmd(chip, data, sizeof(data), 699 rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE,
664 "attempting to determine the temporary state"); 700 "attempting to determine the temporary state");
665 if (rc) 701 if (rc) {
702 kfree(data);
666 return 0; 703 return 0;
667 return sprintf(buf, "%d\n", data[TPM_GET_CAP_TEMP_INACTIVE_IDX]); 704 }
705
706 rc = sprintf(buf, "%d\n", data[TPM_GET_CAP_TEMP_INACTIVE_IDX]);
707
708 kfree(data);
709 return rc;
668} 710}
669EXPORT_SYMBOL_GPL(tpm_show_temp_deactivated); 711EXPORT_SYMBOL_GPL(tpm_show_temp_deactivated);
670 712
@@ -678,7 +720,7 @@ static const u8 pcrread[] = {
678ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr, 720ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
679 char *buf) 721 char *buf)
680{ 722{
681 u8 data[max_t(int, max(ARRAY_SIZE(tpm_cap), ARRAY_SIZE(pcrread)), 30)]; 723 u8 *data;
682 ssize_t rc; 724 ssize_t rc;
683 int i, j, num_pcrs; 725 int i, j, num_pcrs;
684 __be32 index; 726 __be32 index;
@@ -688,21 +730,27 @@ ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
688 if (chip == NULL) 730 if (chip == NULL)
689 return -ENODEV; 731 return -ENODEV;
690 732
733 data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL);
734 if (!data)
735 return -ENOMEM;
736
691 memcpy(data, tpm_cap, sizeof(tpm_cap)); 737 memcpy(data, tpm_cap, sizeof(tpm_cap));
692 data[TPM_CAP_IDX] = TPM_CAP_PROP; 738 data[TPM_CAP_IDX] = TPM_CAP_PROP;
693 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_PCR; 739 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_PCR;
694 740
695 rc = transmit_cmd(chip, data, sizeof(data), 741 rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE,
696 "attempting to determine the number of PCRS"); 742 "attempting to determine the number of PCRS");
697 if (rc) 743 if (rc) {
744 kfree(data);
698 return 0; 745 return 0;
746 }
699 747
700 num_pcrs = be32_to_cpu(*((__be32 *) (data + 14))); 748 num_pcrs = be32_to_cpu(*((__be32 *) (data + 14)));
701 for (i = 0; i < num_pcrs; i++) { 749 for (i = 0; i < num_pcrs; i++) {
702 memcpy(data, pcrread, sizeof(pcrread)); 750 memcpy(data, pcrread, sizeof(pcrread));
703 index = cpu_to_be32(i); 751 index = cpu_to_be32(i);
704 memcpy(data + 10, &index, 4); 752 memcpy(data + 10, &index, 4);
705 rc = transmit_cmd(chip, data, sizeof(data), 753 rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE,
706 "attempting to read a PCR"); 754 "attempting to read a PCR");
707 if (rc) 755 if (rc)
708 goto out; 756 goto out;
@@ -712,6 +760,7 @@ ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
712 str += sprintf(str, "\n"); 760 str += sprintf(str, "\n");
713 } 761 }
714out: 762out:
763 kfree(data);
715 return str - buf; 764 return str - buf;
716} 765}
717EXPORT_SYMBOL_GPL(tpm_show_pcrs); 766EXPORT_SYMBOL_GPL(tpm_show_pcrs);
@@ -795,7 +844,7 @@ static const u8 cap_version[] = {
795ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr, 844ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
796 char *buf) 845 char *buf)
797{ 846{
798 u8 data[max_t(int, max(ARRAY_SIZE(tpm_cap), ARRAY_SIZE(cap_version)), 30)]; 847 u8 *data;
799 ssize_t rc; 848 ssize_t rc;
800 char *str = buf; 849 char *str = buf;
801 850
@@ -803,21 +852,27 @@ ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
803 if (chip == NULL) 852 if (chip == NULL)
804 return -ENODEV; 853 return -ENODEV;
805 854
855 data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL);
856 if (!data)
857 return -ENOMEM;
858
806 memcpy(data, tpm_cap, sizeof(tpm_cap)); 859 memcpy(data, tpm_cap, sizeof(tpm_cap));
807 data[TPM_CAP_IDX] = TPM_CAP_PROP; 860 data[TPM_CAP_IDX] = TPM_CAP_PROP;
808 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_MANUFACTURER; 861 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_MANUFACTURER;
809 862
810 rc = transmit_cmd(chip, data, sizeof(data), 863 rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE,
811 "attempting to determine the manufacturer"); 864 "attempting to determine the manufacturer");
812 if (rc) 865 if (rc) {
866 kfree(data);
813 return 0; 867 return 0;
868 }
814 869
815 str += sprintf(str, "Manufacturer: 0x%x\n", 870 str += sprintf(str, "Manufacturer: 0x%x\n",
816 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)))); 871 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX))));
817 872
818 memcpy(data, cap_version, sizeof(cap_version)); 873 memcpy(data, cap_version, sizeof(cap_version));
819 data[CAP_VERSION_IDX] = CAP_VERSION_1_1; 874 data[CAP_VERSION_IDX] = CAP_VERSION_1_1;
820 rc = transmit_cmd(chip, data, sizeof(data), 875 rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE,
821 "attempting to determine the 1.1 version"); 876 "attempting to determine the 1.1 version");
822 if (rc) 877 if (rc)
823 goto out; 878 goto out;
@@ -828,6 +883,7 @@ ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
828 (int) data[17]); 883 (int) data[17]);
829 884
830out: 885out:
886 kfree(data);
831 return str - buf; 887 return str - buf;
832} 888}
833EXPORT_SYMBOL_GPL(tpm_show_caps); 889EXPORT_SYMBOL_GPL(tpm_show_caps);
@@ -835,7 +891,7 @@ EXPORT_SYMBOL_GPL(tpm_show_caps);
835ssize_t tpm_show_caps_1_2(struct device * dev, 891ssize_t tpm_show_caps_1_2(struct device * dev,
836 struct device_attribute * attr, char *buf) 892 struct device_attribute * attr, char *buf)
837{ 893{
838 u8 data[max_t(int, max(ARRAY_SIZE(tpm_cap), ARRAY_SIZE(cap_version)), 30)]; 894 u8 *data;
839 ssize_t len; 895 ssize_t len;
840 char *str = buf; 896 char *str = buf;
841 897
@@ -843,15 +899,20 @@ ssize_t tpm_show_caps_1_2(struct device * dev,
843 if (chip == NULL) 899 if (chip == NULL)
844 return -ENODEV; 900 return -ENODEV;
845 901
902 data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL);
903 if (!data)
904 return -ENOMEM;
905
846 memcpy(data, tpm_cap, sizeof(tpm_cap)); 906 memcpy(data, tpm_cap, sizeof(tpm_cap));
847 data[TPM_CAP_IDX] = TPM_CAP_PROP; 907 data[TPM_CAP_IDX] = TPM_CAP_PROP;
848 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_MANUFACTURER; 908 data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_MANUFACTURER;
849 909
850 if ((len = tpm_transmit(chip, data, sizeof(data))) <= 910 len = tpm_transmit(chip, data, TPM_INTERNAL_RESULT_SIZE);
851 TPM_ERROR_SIZE) { 911 if (len <= TPM_ERROR_SIZE) {
852 dev_dbg(chip->dev, "A TPM error (%d) occurred " 912 dev_dbg(chip->dev, "A TPM error (%d) occurred "
853 "attempting to determine the manufacturer\n", 913 "attempting to determine the manufacturer\n",
854 be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX)))); 914 be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX))));
915 kfree(data);
855 return 0; 916 return 0;
856 } 917 }
857 918
@@ -861,8 +922,8 @@ ssize_t tpm_show_caps_1_2(struct device * dev,
861 memcpy(data, cap_version, sizeof(cap_version)); 922 memcpy(data, cap_version, sizeof(cap_version));
862 data[CAP_VERSION_IDX] = CAP_VERSION_1_2; 923 data[CAP_VERSION_IDX] = CAP_VERSION_1_2;
863 924
864 if ((len = tpm_transmit(chip, data, sizeof(data))) <= 925 len = tpm_transmit(chip, data, TPM_INTERNAL_RESULT_SIZE);
865 TPM_ERROR_SIZE) { 926 if (len <= TPM_ERROR_SIZE) {
866 dev_err(chip->dev, "A TPM error (%d) occurred " 927 dev_err(chip->dev, "A TPM error (%d) occurred "
867 "attempting to determine the 1.2 version\n", 928 "attempting to determine the 1.2 version\n",
868 be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX)))); 929 be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX))));
@@ -874,6 +935,7 @@ ssize_t tpm_show_caps_1_2(struct device * dev,
874 (int) data[19]); 935 (int) data[19]);
875 936
876out: 937out:
938 kfree(data);
877 return str - buf; 939 return str - buf;
878} 940}
879EXPORT_SYMBOL_GPL(tpm_show_caps_1_2); 941EXPORT_SYMBOL_GPL(tpm_show_caps_1_2);
@@ -966,7 +1028,7 @@ ssize_t tpm_write(struct file *file, const char __user *buf,
966 size_t size, loff_t *off) 1028 size_t size, loff_t *off)
967{ 1029{
968 struct tpm_chip *chip = file->private_data; 1030 struct tpm_chip *chip = file->private_data;
969 int in_size = size, out_size; 1031 size_t in_size = size, out_size;
970 1032
971 /* cannot perform a write until the read has cleared 1033 /* cannot perform a write until the read has cleared
972 either via tpm_read or a user_read_timer timeout */ 1034 either via tpm_read or a user_read_timer timeout */
@@ -1001,7 +1063,7 @@ ssize_t tpm_read(struct file *file, char __user *buf,
1001 size_t size, loff_t *off) 1063 size_t size, loff_t *off)
1002{ 1064{
1003 struct tpm_chip *chip = file->private_data; 1065 struct tpm_chip *chip = file->private_data;
1004 int ret_size; 1066 ssize_t ret_size;
1005 1067
1006 del_singleshot_timer_sync(&chip->user_read_timer); 1068 del_singleshot_timer_sync(&chip->user_read_timer);
1007 flush_scheduled_work(); 1069 flush_scheduled_work();
diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
index 60a2d2630e36..68f052b42ed7 100644
--- a/drivers/char/tpm/tpm_bios.c
+++ b/drivers/char/tpm/tpm_bios.c
@@ -448,7 +448,7 @@ out_free:
448 goto out; 448 goto out;
449} 449}
450 450
451const struct file_operations tpm_ascii_bios_measurements_ops = { 451static const struct file_operations tpm_ascii_bios_measurements_ops = {
452 .open = tpm_ascii_bios_measurements_open, 452 .open = tpm_ascii_bios_measurements_open,
453 .read = seq_read, 453 .read = seq_read,
454 .llseek = seq_lseek, 454 .llseek = seq_lseek,
@@ -486,7 +486,7 @@ out_free:
486 goto out; 486 goto out;
487} 487}
488 488
489const struct file_operations tpm_binary_bios_measurements_ops = { 489static const struct file_operations tpm_binary_bios_measurements_ops = {
490 .open = tpm_binary_bios_measurements_open, 490 .open = tpm_binary_bios_measurements_open,
491 .read = seq_read, 491 .read = seq_read,
492 .llseek = seq_lseek, 492 .llseek = seq_lseek,
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index c7a977bc03e8..ed1879c0dd8d 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -622,6 +622,7 @@ static struct pnp_device_id tpm_pnp_tbl[] __devinitdata = {
622 {"ATM1200", 0}, /* Atmel */ 622 {"ATM1200", 0}, /* Atmel */
623 {"IFX0102", 0}, /* Infineon */ 623 {"IFX0102", 0}, /* Infineon */
624 {"BCM0101", 0}, /* Broadcom */ 624 {"BCM0101", 0}, /* Broadcom */
625 {"BCM0102", 0}, /* Broadcom */
625 {"NSC1200", 0}, /* National */ 626 {"NSC1200", 0}, /* National */
626 {"ICO0102", 0}, /* Intel */ 627 {"ICO0102", 0}, /* Intel */
627 /* Add new here */ 628 /* Add new here */
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index fa48dba5ba5e..e1b46bc7e43c 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -1119,19 +1119,6 @@ int tty_hung_up_p(struct file *filp)
1119 1119
1120EXPORT_SYMBOL(tty_hung_up_p); 1120EXPORT_SYMBOL(tty_hung_up_p);
1121 1121
1122/**
1123 * is_tty - checker whether file is a TTY
1124 * @filp: file handle that may be a tty
1125 *
1126 * Check if the file handle is a tty handle.
1127 */
1128
1129int is_tty(struct file *filp)
1130{
1131 return filp->f_op->read == tty_read
1132 || filp->f_op->read == hung_up_tty_read;
1133}
1134
1135static void session_clear_tty(struct pid *session) 1122static void session_clear_tty(struct pid *session)
1136{ 1123{
1137 struct task_struct *p; 1124 struct task_struct *p;
@@ -3593,7 +3580,6 @@ void proc_clear_tty(struct task_struct *p)
3593 p->signal->tty = NULL; 3580 p->signal->tty = NULL;
3594 spin_unlock_irq(&p->sighand->siglock); 3581 spin_unlock_irq(&p->sighand->siglock);
3595} 3582}
3596EXPORT_SYMBOL(proc_clear_tty);
3597 3583
3598/* Called under the sighand lock */ 3584/* Called under the sighand lock */
3599 3585
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index dc17fe3a88bc..d0f4eb6fdb7f 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -46,6 +46,9 @@ static char *in, *inbuf;
46/* The operations for our console. */ 46/* The operations for our console. */
47static struct hv_ops virtio_cons; 47static struct hv_ops virtio_cons;
48 48
49/* The hvc device */
50static struct hvc_struct *hvc;
51
49/*D:310 The put_chars() callback is pretty straightforward. 52/*D:310 The put_chars() callback is pretty straightforward.
50 * 53 *
51 * We turn the characters into a scatter-gather list, add it to the output 54 * We turn the characters into a scatter-gather list, add it to the output
@@ -134,6 +137,27 @@ int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
134 return hvc_instantiate(0, 0, &virtio_cons); 137 return hvc_instantiate(0, 0, &virtio_cons);
135} 138}
136 139
140/*
141 * we support only one console, the hvc struct is a global var
142 * There is no need to do anything
143 */
144static int notifier_add_vio(struct hvc_struct *hp, int data)
145{
146 hp->irq_requested = 1;
147 return 0;
148}
149
150static void notifier_del_vio(struct hvc_struct *hp, int data)
151{
152 hp->irq_requested = 0;
153}
154
155static void hvc_handle_input(struct virtqueue *vq)
156{
157 if (hvc_poll(hvc))
158 hvc_kick();
159}
160
137/*D:370 Once we're further in boot, we get probed like any other virtio device. 161/*D:370 Once we're further in boot, we get probed like any other virtio device.
138 * At this stage we set up the output virtqueue. 162 * At this stage we set up the output virtqueue.
139 * 163 *
@@ -144,7 +168,6 @@ int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
144static int __devinit virtcons_probe(struct virtio_device *dev) 168static int __devinit virtcons_probe(struct virtio_device *dev)
145{ 169{
146 int err; 170 int err;
147 struct hvc_struct *hvc;
148 171
149 vdev = dev; 172 vdev = dev;
150 173
@@ -158,7 +181,7 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
158 /* Find the input queue. */ 181 /* Find the input queue. */
159 /* FIXME: This is why we want to wean off hvc: we do nothing 182 /* FIXME: This is why we want to wean off hvc: we do nothing
160 * when input comes in. */ 183 * when input comes in. */
161 in_vq = vdev->config->find_vq(vdev, 0, NULL); 184 in_vq = vdev->config->find_vq(vdev, 0, hvc_handle_input);
162 if (IS_ERR(in_vq)) { 185 if (IS_ERR(in_vq)) {
163 err = PTR_ERR(in_vq); 186 err = PTR_ERR(in_vq);
164 goto free; 187 goto free;
@@ -173,15 +196,18 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
173 /* Start using the new console output. */ 196 /* Start using the new console output. */
174 virtio_cons.get_chars = get_chars; 197 virtio_cons.get_chars = get_chars;
175 virtio_cons.put_chars = put_chars; 198 virtio_cons.put_chars = put_chars;
199 virtio_cons.notifier_add = notifier_add_vio;
200 virtio_cons.notifier_del = notifier_del_vio;
176 201
177 /* The first argument of hvc_alloc() is the virtual console number, so 202 /* The first argument of hvc_alloc() is the virtual console number, so
178 * we use zero. The second argument is the interrupt number; we 203 * we use zero. The second argument is the parameter for the
179 * currently leave this as zero: it would be better not to use the 204 * notification mechanism (like irq number). We currently leave this
180 * hvc mechanism and fix this (FIXME!). 205 * as zero, virtqueues have implicit notifications.
181 * 206 *
182 * The third argument is a "struct hv_ops" containing the put_chars() 207 * The third argument is a "struct hv_ops" containing the put_chars()
183 * and get_chars() pointers. The final argument is the output buffer 208 * get_chars(), notifier_add() and notifier_del() pointers.
184 * size: we can do any size, so we put PAGE_SIZE here. */ 209 * The final argument is the output buffer size: we can do any size,
210 * so we put PAGE_SIZE here. */
185 hvc = hvc_alloc(0, 0, &virtio_cons, PAGE_SIZE); 211 hvc = hvc_alloc(0, 0, &virtio_cons, PAGE_SIZE);
186 if (IS_ERR(hvc)) { 212 if (IS_ERR(hvc)) {
187 err = PTR_ERR(hvc); 213 err = PTR_ERR(hvc);
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index e32a076d5f1f..82a51f38a546 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -261,7 +261,7 @@ static void notify_update(struct vc_data *vc)
261#ifdef VT_BUF_VRAM_ONLY 261#ifdef VT_BUF_VRAM_ONLY
262#define DO_UPDATE(vc) 0 262#define DO_UPDATE(vc) 0
263#else 263#else
264#define DO_UPDATE(vc) CON_IS_VISIBLE(vc) 264#define DO_UPDATE(vc) (CON_IS_VISIBLE(vc) && !console_blanked)
265#endif 265#endif
266 266
267static inline unsigned short *screenpos(struct vc_data *vc, int offset, int viewed) 267static inline unsigned short *screenpos(struct vc_data *vc, int offset, int viewed)
@@ -2211,7 +2211,7 @@ rescan_last_byte:
2211 c = 0xfffd; 2211 c = 0xfffd;
2212 tc = c; 2212 tc = c;
2213 } else { /* no utf or alternate charset mode */ 2213 } else { /* no utf or alternate charset mode */
2214 tc = vc->vc_translate[vc->vc_toggle_meta ? (c | 0x80) : c]; 2214 tc = vc_translate(vc, c);
2215 } 2215 }
2216 2216
2217 param.c = tc; 2217 param.c = tc;
@@ -2749,8 +2749,8 @@ static int con_open(struct tty_struct *tty, struct file *filp)
2749 tty->termios->c_iflag |= IUTF8; 2749 tty->termios->c_iflag |= IUTF8;
2750 else 2750 else
2751 tty->termios->c_iflag &= ~IUTF8; 2751 tty->termios->c_iflag &= ~IUTF8;
2752 release_console_sem();
2753 vcs_make_sysfs(tty); 2752 vcs_make_sysfs(tty);
2753 release_console_sem();
2754 return ret; 2754 return ret;
2755 } 2755 }
2756 } 2756 }
@@ -2775,8 +2775,8 @@ static void con_close(struct tty_struct *tty, struct file *filp)
2775 if (vc) 2775 if (vc)
2776 vc->vc_tty = NULL; 2776 vc->vc_tty = NULL;
2777 tty->driver_data = NULL; 2777 tty->driver_data = NULL;
2778 release_console_sem();
2779 vcs_remove_sysfs(tty); 2778 vcs_remove_sysfs(tty);
2779 release_console_sem();
2780 mutex_unlock(&tty_mutex); 2780 mutex_unlock(&tty_mutex);
2781 /* 2781 /*
2782 * tty_mutex is released, but we still hold BKL, so there is 2782 * tty_mutex is released, but we still hold BKL, so there is
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index 51966ccf4ea3..8bfee5fb7223 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -87,7 +87,6 @@
87#include <linux/mutex.h> 87#include <linux/mutex.h>
88#include <linux/smp_lock.h> 88#include <linux/smp_lock.h>
89#include <linux/sysctl.h> 89#include <linux/sysctl.h>
90#include <linux/version.h>
91#include <linux/fs.h> 90#include <linux/fs.h>
92#include <linux/cdev.h> 91#include <linux/cdev.h>
93#include <linux/platform_device.h> 92#include <linux/platform_device.h>
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index ee1df0d45e81..8d6a3ff02672 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -589,7 +589,7 @@ static ssize_t show_cpus(cpumask_t mask, char *buf)
589 ssize_t i = 0; 589 ssize_t i = 0;
590 unsigned int cpu; 590 unsigned int cpu;
591 591
592 for_each_cpu_mask(cpu, mask) { 592 for_each_cpu_mask_nr(cpu, mask) {
593 if (i) 593 if (i)
594 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " "); 594 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
595 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); 595 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
@@ -835,7 +835,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
835 } 835 }
836#endif 836#endif
837 837
838 for_each_cpu_mask(j, policy->cpus) { 838 for_each_cpu_mask_nr(j, policy->cpus) {
839 if (cpu == j) 839 if (cpu == j)
840 continue; 840 continue;
841 841
@@ -898,14 +898,14 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
898 } 898 }
899 899
900 spin_lock_irqsave(&cpufreq_driver_lock, flags); 900 spin_lock_irqsave(&cpufreq_driver_lock, flags);
901 for_each_cpu_mask(j, policy->cpus) { 901 for_each_cpu_mask_nr(j, policy->cpus) {
902 per_cpu(cpufreq_cpu_data, j) = policy; 902 per_cpu(cpufreq_cpu_data, j) = policy;
903 per_cpu(policy_cpu, j) = policy->cpu; 903 per_cpu(policy_cpu, j) = policy->cpu;
904 } 904 }
905 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 905 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
906 906
907 /* symlink affected CPUs */ 907 /* symlink affected CPUs */
908 for_each_cpu_mask(j, policy->cpus) { 908 for_each_cpu_mask_nr(j, policy->cpus) {
909 if (j == cpu) 909 if (j == cpu)
910 continue; 910 continue;
911 if (!cpu_online(j)) 911 if (!cpu_online(j))
@@ -945,7 +945,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
945 945
946err_out_unregister: 946err_out_unregister:
947 spin_lock_irqsave(&cpufreq_driver_lock, flags); 947 spin_lock_irqsave(&cpufreq_driver_lock, flags);
948 for_each_cpu_mask(j, policy->cpus) 948 for_each_cpu_mask_nr(j, policy->cpus)
949 per_cpu(cpufreq_cpu_data, j) = NULL; 949 per_cpu(cpufreq_cpu_data, j) = NULL;
950 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 950 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
951 951
@@ -1028,7 +1028,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
1028 * the sysfs links afterwards. 1028 * the sysfs links afterwards.
1029 */ 1029 */
1030 if (unlikely(cpus_weight(data->cpus) > 1)) { 1030 if (unlikely(cpus_weight(data->cpus) > 1)) {
1031 for_each_cpu_mask(j, data->cpus) { 1031 for_each_cpu_mask_nr(j, data->cpus) {
1032 if (j == cpu) 1032 if (j == cpu)
1033 continue; 1033 continue;
1034 per_cpu(cpufreq_cpu_data, j) = NULL; 1034 per_cpu(cpufreq_cpu_data, j) = NULL;
@@ -1038,7 +1038,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
1038 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 1038 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1039 1039
1040 if (unlikely(cpus_weight(data->cpus) > 1)) { 1040 if (unlikely(cpus_weight(data->cpus) > 1)) {
1041 for_each_cpu_mask(j, data->cpus) { 1041 for_each_cpu_mask_nr(j, data->cpus) {
1042 if (j == cpu) 1042 if (j == cpu)
1043 continue; 1043 continue;
1044 dprintk("removing link for cpu %u\n", j); 1044 dprintk("removing link for cpu %u\n", j);
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index 5d3a04ba6ad2..fe565ee43757 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -497,7 +497,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
497 return rc; 497 return rc;
498 } 498 }
499 499
500 for_each_cpu_mask(j, policy->cpus) { 500 for_each_cpu_mask_nr(j, policy->cpus) {
501 struct cpu_dbs_info_s *j_dbs_info; 501 struct cpu_dbs_info_s *j_dbs_info;
502 j_dbs_info = &per_cpu(cpu_dbs_info, j); 502 j_dbs_info = &per_cpu(cpu_dbs_info, j);
503 j_dbs_info->cur_policy = policy; 503 j_dbs_info->cur_policy = policy;
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index d2af20dda382..33855cb3cf16 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -367,7 +367,7 @@ static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
367 367
368 /* Get Idle Time */ 368 /* Get Idle Time */
369 idle_ticks = UINT_MAX; 369 idle_ticks = UINT_MAX;
370 for_each_cpu_mask(j, policy->cpus) { 370 for_each_cpu_mask_nr(j, policy->cpus) {
371 cputime64_t total_idle_ticks; 371 cputime64_t total_idle_ticks;
372 unsigned int tmp_idle_ticks; 372 unsigned int tmp_idle_ticks;
373 struct cpu_dbs_info_s *j_dbs_info; 373 struct cpu_dbs_info_s *j_dbs_info;
@@ -521,7 +521,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
521 return rc; 521 return rc;
522 } 522 }
523 523
524 for_each_cpu_mask(j, policy->cpus) { 524 for_each_cpu_mask_nr(j, policy->cpus) {
525 struct cpu_dbs_info_s *j_dbs_info; 525 struct cpu_dbs_info_s *j_dbs_info;
526 j_dbs_info = &per_cpu(cpu_dbs_info, j); 526 j_dbs_info = &per_cpu(cpu_dbs_info, j);
527 j_dbs_info->cur_policy = policy; 527 j_dbs_info->cur_policy = policy;
diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c
index cb2ac01a41a1..32244aa7cc0c 100644
--- a/drivers/cpufreq/cpufreq_userspace.c
+++ b/drivers/cpufreq/cpufreq_userspace.c
@@ -30,16 +30,18 @@
30/** 30/**
31 * A few values needed by the userspace governor 31 * A few values needed by the userspace governor
32 */ 32 */
33static unsigned int cpu_max_freq[NR_CPUS]; 33static DEFINE_PER_CPU(unsigned int, cpu_max_freq);
34static unsigned int cpu_min_freq[NR_CPUS]; 34static DEFINE_PER_CPU(unsigned int, cpu_min_freq);
35static unsigned int cpu_cur_freq[NR_CPUS]; /* current CPU freq */ 35static DEFINE_PER_CPU(unsigned int, cpu_cur_freq); /* current CPU freq */
36static unsigned int cpu_set_freq[NR_CPUS]; /* CPU freq desired by userspace */ 36static DEFINE_PER_CPU(unsigned int, cpu_set_freq); /* CPU freq desired by
37static unsigned int cpu_is_managed[NR_CPUS]; 37 userspace */
38static DEFINE_PER_CPU(unsigned int, cpu_is_managed);
38 39
39static DEFINE_MUTEX (userspace_mutex); 40static DEFINE_MUTEX (userspace_mutex);
40static int cpus_using_userspace_governor; 41static int cpus_using_userspace_governor;
41 42
42#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg) 43#define dprintk(msg...) \
44 cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg)
43 45
44/* keep track of frequency transitions */ 46/* keep track of frequency transitions */
45static int 47static int
@@ -48,12 +50,12 @@ userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
48{ 50{
49 struct cpufreq_freqs *freq = data; 51 struct cpufreq_freqs *freq = data;
50 52
51 if (!cpu_is_managed[freq->cpu]) 53 if (!per_cpu(cpu_is_managed, freq->cpu))
52 return 0; 54 return 0;
53 55
54 dprintk("saving cpu_cur_freq of cpu %u to be %u kHz\n", 56 dprintk("saving cpu_cur_freq of cpu %u to be %u kHz\n",
55 freq->cpu, freq->new); 57 freq->cpu, freq->new);
56 cpu_cur_freq[freq->cpu] = freq->new; 58 per_cpu(cpu_cur_freq, freq->cpu) = freq->new;
57 59
58 return 0; 60 return 0;
59} 61}
@@ -77,15 +79,15 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
77 dprintk("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq); 79 dprintk("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq);
78 80
79 mutex_lock(&userspace_mutex); 81 mutex_lock(&userspace_mutex);
80 if (!cpu_is_managed[policy->cpu]) 82 if (!per_cpu(cpu_is_managed, policy->cpu))
81 goto err; 83 goto err;
82 84
83 cpu_set_freq[policy->cpu] = freq; 85 per_cpu(cpu_set_freq, policy->cpu) = freq;
84 86
85 if (freq < cpu_min_freq[policy->cpu]) 87 if (freq < per_cpu(cpu_min_freq, policy->cpu))
86 freq = cpu_min_freq[policy->cpu]; 88 freq = per_cpu(cpu_min_freq, policy->cpu);
87 if (freq > cpu_max_freq[policy->cpu]) 89 if (freq > per_cpu(cpu_max_freq, policy->cpu))
88 freq = cpu_max_freq[policy->cpu]; 90 freq = per_cpu(cpu_max_freq, policy->cpu);
89 91
90 /* 92 /*
91 * We're safe from concurrent calls to ->target() here 93 * We're safe from concurrent calls to ->target() here
@@ -104,7 +106,7 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
104 106
105static ssize_t show_speed(struct cpufreq_policy *policy, char *buf) 107static ssize_t show_speed(struct cpufreq_policy *policy, char *buf)
106{ 108{
107 return sprintf(buf, "%u\n", cpu_cur_freq[policy->cpu]); 109 return sprintf(buf, "%u\n", per_cpu(cpu_cur_freq, policy->cpu));
108} 110}
109 111
110static int cpufreq_governor_userspace(struct cpufreq_policy *policy, 112static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
@@ -127,12 +129,17 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
127 } 129 }
128 cpus_using_userspace_governor++; 130 cpus_using_userspace_governor++;
129 131
130 cpu_is_managed[cpu] = 1; 132 per_cpu(cpu_is_managed, cpu) = 1;
131 cpu_min_freq[cpu] = policy->min; 133 per_cpu(cpu_min_freq, cpu) = policy->min;
132 cpu_max_freq[cpu] = policy->max; 134 per_cpu(cpu_max_freq, cpu) = policy->max;
133 cpu_cur_freq[cpu] = policy->cur; 135 per_cpu(cpu_cur_freq, cpu) = policy->cur;
134 cpu_set_freq[cpu] = policy->cur; 136 per_cpu(cpu_set_freq, cpu) = policy->cur;
135 dprintk("managing cpu %u started (%u - %u kHz, currently %u kHz)\n", cpu, cpu_min_freq[cpu], cpu_max_freq[cpu], cpu_cur_freq[cpu]); 137 dprintk("managing cpu %u started "
138 "(%u - %u kHz, currently %u kHz)\n",
139 cpu,
140 per_cpu(cpu_min_freq, cpu),
141 per_cpu(cpu_max_freq, cpu),
142 per_cpu(cpu_cur_freq, cpu));
136 143
137 mutex_unlock(&userspace_mutex); 144 mutex_unlock(&userspace_mutex);
138 break; 145 break;
@@ -145,34 +152,34 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
145 CPUFREQ_TRANSITION_NOTIFIER); 152 CPUFREQ_TRANSITION_NOTIFIER);
146 } 153 }
147 154
148 cpu_is_managed[cpu] = 0; 155 per_cpu(cpu_is_managed, cpu) = 0;
149 cpu_min_freq[cpu] = 0; 156 per_cpu(cpu_min_freq, cpu) = 0;
150 cpu_max_freq[cpu] = 0; 157 per_cpu(cpu_max_freq, cpu) = 0;
151 cpu_set_freq[cpu] = 0; 158 per_cpu(cpu_set_freq, cpu) = 0;
152 dprintk("managing cpu %u stopped\n", cpu); 159 dprintk("managing cpu %u stopped\n", cpu);
153 mutex_unlock(&userspace_mutex); 160 mutex_unlock(&userspace_mutex);
154 break; 161 break;
155 case CPUFREQ_GOV_LIMITS: 162 case CPUFREQ_GOV_LIMITS:
156 mutex_lock(&userspace_mutex); 163 mutex_lock(&userspace_mutex);
157 dprintk("limit event for cpu %u: %u - %u kHz," 164 dprintk("limit event for cpu %u: %u - %u kHz, "
158 "currently %u kHz, last set to %u kHz\n", 165 "currently %u kHz, last set to %u kHz\n",
159 cpu, policy->min, policy->max, 166 cpu, policy->min, policy->max,
160 cpu_cur_freq[cpu], cpu_set_freq[cpu]); 167 per_cpu(cpu_cur_freq, cpu),
161 if (policy->max < cpu_set_freq[cpu]) { 168 per_cpu(cpu_set_freq, cpu));
169 if (policy->max < per_cpu(cpu_set_freq, cpu)) {
162 __cpufreq_driver_target(policy, policy->max, 170 __cpufreq_driver_target(policy, policy->max,
163 CPUFREQ_RELATION_H); 171 CPUFREQ_RELATION_H);
164 } 172 } else if (policy->min > per_cpu(cpu_set_freq, cpu)) {
165 else if (policy->min > cpu_set_freq[cpu]) {
166 __cpufreq_driver_target(policy, policy->min, 173 __cpufreq_driver_target(policy, policy->min,
167 CPUFREQ_RELATION_L); 174 CPUFREQ_RELATION_L);
168 } 175 } else {
169 else { 176 __cpufreq_driver_target(policy,
170 __cpufreq_driver_target(policy, cpu_set_freq[cpu], 177 per_cpu(cpu_set_freq, cpu),
171 CPUFREQ_RELATION_L); 178 CPUFREQ_RELATION_L);
172 } 179 }
173 cpu_min_freq[cpu] = policy->min; 180 per_cpu(cpu_min_freq, cpu) = policy->min;
174 cpu_max_freq[cpu] = policy->max; 181 per_cpu(cpu_max_freq, cpu) = policy->max;
175 cpu_cur_freq[cpu] = policy->cur; 182 per_cpu(cpu_cur_freq, cpu) = policy->cur;
176 mutex_unlock(&userspace_mutex); 183 mutex_unlock(&userspace_mutex);
177 break; 184 break;
178 } 185 }
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 6e6c3c4aea6b..5a11e3cbcae2 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -123,6 +123,13 @@ config EDAC_I5000
123 Support for error detection and correction the Intel 123 Support for error detection and correction the Intel
124 Greekcreek/Blackford chipsets. 124 Greekcreek/Blackford chipsets.
125 125
126config EDAC_I5100
127 tristate "Intel San Clemente MCH"
128 depends on EDAC_MM_EDAC && X86 && PCI
129 help
130 Support for error detection and correction the Intel
131 San Clemente MCH.
132
126config EDAC_MPC85XX 133config EDAC_MPC85XX
127 tristate "Freescale MPC85xx" 134 tristate "Freescale MPC85xx"
128 depends on EDAC_MM_EDAC && FSL_SOC && MPC85xx 135 depends on EDAC_MM_EDAC && FSL_SOC && MPC85xx
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
index 83807731d4a9..e5e9104b5520 100644
--- a/drivers/edac/Makefile
+++ b/drivers/edac/Makefile
@@ -19,6 +19,7 @@ endif
19 19
20obj-$(CONFIG_EDAC_AMD76X) += amd76x_edac.o 20obj-$(CONFIG_EDAC_AMD76X) += amd76x_edac.o
21obj-$(CONFIG_EDAC_I5000) += i5000_edac.o 21obj-$(CONFIG_EDAC_I5000) += i5000_edac.o
22obj-$(CONFIG_EDAC_I5100) += i5100_edac.o
22obj-$(CONFIG_EDAC_E7XXX) += e7xxx_edac.o 23obj-$(CONFIG_EDAC_E7XXX) += e7xxx_edac.o
23obj-$(CONFIG_EDAC_E752X) += e752x_edac.o 24obj-$(CONFIG_EDAC_E752X) += e752x_edac.o
24obj-$(CONFIG_EDAC_I82443BXGX) += i82443bxgx_edac.o 25obj-$(CONFIG_EDAC_I82443BXGX) += i82443bxgx_edac.o
diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
index c94a0eb492cb..facfdb1fa71c 100644
--- a/drivers/edac/e752x_edac.c
+++ b/drivers/edac/e752x_edac.c
@@ -28,6 +28,7 @@
28#define E752X_REVISION " Ver: 2.0.2 " __DATE__ 28#define E752X_REVISION " Ver: 2.0.2 " __DATE__
29#define EDAC_MOD_STR "e752x_edac" 29#define EDAC_MOD_STR "e752x_edac"
30 30
31static int report_non_memory_errors;
31static int force_function_unhide; 32static int force_function_unhide;
32static int sysbus_parity = -1; 33static int sysbus_parity = -1;
33 34
@@ -117,7 +118,7 @@ static struct edac_pci_ctl_info *e752x_pci;
117#define E752X_BUF_FERR 0x70 /* Memory buffer first error reg (8b) */ 118#define E752X_BUF_FERR 0x70 /* Memory buffer first error reg (8b) */
118#define E752X_BUF_NERR 0x72 /* Memory buffer next error reg (8b) */ 119#define E752X_BUF_NERR 0x72 /* Memory buffer next error reg (8b) */
119#define E752X_BUF_ERRMASK 0x74 /* Memory buffer error mask reg (8b) */ 120#define E752X_BUF_ERRMASK 0x74 /* Memory buffer error mask reg (8b) */
120#define E752X_BUF_SMICMD 0x7A /* Memory buffer SMI command reg (8b) */ 121#define E752X_BUF_SMICMD 0x7A /* Memory buffer SMI cmd reg (8b) */
121#define E752X_DRAM_FERR 0x80 /* DRAM first error register (16b) */ 122#define E752X_DRAM_FERR 0x80 /* DRAM first error register (16b) */
122#define E752X_DRAM_NERR 0x82 /* DRAM next error register (16b) */ 123#define E752X_DRAM_NERR 0x82 /* DRAM next error register (16b) */
123#define E752X_DRAM_ERRMASK 0x84 /* DRAM error mask register (8b) */ 124#define E752X_DRAM_ERRMASK 0x84 /* DRAM error mask register (8b) */
@@ -127,7 +128,7 @@ static struct edac_pci_ctl_info *e752x_pci;
127 /* error address register (32b) */ 128 /* error address register (32b) */
128 /* 129 /*
129 * 31 Reserved 130 * 31 Reserved
130 * 30:2 CE address (64 byte block 34:6) 131 * 30:2 CE address (64 byte block 34:6
131 * 1 Reserved 132 * 1 Reserved
132 * 0 HiLoCS 133 * 0 HiLoCS
133 */ 134 */
@@ -147,11 +148,11 @@ static struct edac_pci_ctl_info *e752x_pci;
147 * 1 Reserved 148 * 1 Reserved
148 * 0 HiLoCS 149 * 0 HiLoCS
149 */ 150 */
150#define E752X_DRAM_SCRB_ADD 0xA8 /* DRAM first uncorrectable scrub memory */ 151#define E752X_DRAM_SCRB_ADD 0xA8 /* DRAM 1st uncorrectable scrub mem */
151 /* error address register (32b) */ 152 /* error address register (32b) */
152 /* 153 /*
153 * 31 Reserved 154 * 31 Reserved
154 * 30:2 CE address (64 byte block 34:6) 155 * 30:2 CE address (64 byte block 34:6
155 * 1 Reserved 156 * 1 Reserved
156 * 0 HiLoCS 157 * 0 HiLoCS
157 */ 158 */
@@ -394,9 +395,12 @@ static void do_process_ded_retry(struct mem_ctl_info *mci, u16 error,
394 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info; 395 struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
395 396
396 error_1b = retry_add; 397 error_1b = retry_add;
397 page = error_1b >> (PAGE_SHIFT - 4); /* convert the addr to 4k page */ 398 page = error_1b >> (PAGE_SHIFT - 4); /* convert the addr to 4k page */
398 row = pvt->mc_symmetric ? ((page >> 1) & 3) : /* chip select are bits 14 & 13 */ 399
400 /* chip select are bits 14 & 13 */
401 row = pvt->mc_symmetric ? ((page >> 1) & 3) :
399 edac_mc_find_csrow_by_page(mci, page); 402 edac_mc_find_csrow_by_page(mci, page);
403
400 e752x_mc_printk(mci, KERN_WARNING, 404 e752x_mc_printk(mci, KERN_WARNING,
401 "CE page 0x%lx, row %d : Memory read retry\n", 405 "CE page 0x%lx, row %d : Memory read retry\n",
402 (long unsigned int)page, row); 406 (long unsigned int)page, row);
@@ -422,12 +426,21 @@ static inline void process_threshold_ce(struct mem_ctl_info *mci, u16 error,
422} 426}
423 427
424static char *global_message[11] = { 428static char *global_message[11] = {
425 "PCI Express C1", "PCI Express C", "PCI Express B1", 429 "PCI Express C1",
426 "PCI Express B", "PCI Express A1", "PCI Express A", 430 "PCI Express C",
427 "DMA Controler", "HUB or NS Interface", "System Bus", 431 "PCI Express B1",
428 "DRAM Controler", "Internal Buffer" 432 "PCI Express B",
433 "PCI Express A1",
434 "PCI Express A",
435 "DMA Controller",
436 "HUB or NS Interface",
437 "System Bus",
438 "DRAM Controller", /* 9th entry */
439 "Internal Buffer"
429}; 440};
430 441
442#define DRAM_ENTRY 9
443
431static char *fatal_message[2] = { "Non-Fatal ", "Fatal " }; 444static char *fatal_message[2] = { "Non-Fatal ", "Fatal " };
432 445
433static void do_global_error(int fatal, u32 errors) 446static void do_global_error(int fatal, u32 errors)
@@ -435,9 +448,16 @@ static void do_global_error(int fatal, u32 errors)
435 int i; 448 int i;
436 449
437 for (i = 0; i < 11; i++) { 450 for (i = 0; i < 11; i++) {
438 if (errors & (1 << i)) 451 if (errors & (1 << i)) {
439 e752x_printk(KERN_WARNING, "%sError %s\n", 452 /* If the error is from DRAM Controller OR
440 fatal_message[fatal], global_message[i]); 453 * we are to report ALL errors, then
454 * report the error
455 */
456 if ((i == DRAM_ENTRY) || report_non_memory_errors)
457 e752x_printk(KERN_WARNING, "%sError %s\n",
458 fatal_message[fatal],
459 global_message[i]);
460 }
441 } 461 }
442} 462}
443 463
@@ -1021,7 +1041,7 @@ static int e752x_get_devs(struct pci_dev *pdev, int dev_idx,
1021 struct pci_dev *dev; 1041 struct pci_dev *dev;
1022 1042
1023 pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL, 1043 pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL,
1024 pvt->dev_info->err_dev, pvt->bridge_ck); 1044 pvt->dev_info->err_dev, pvt->bridge_ck);
1025 1045
1026 if (pvt->bridge_ck == NULL) 1046 if (pvt->bridge_ck == NULL)
1027 pvt->bridge_ck = pci_scan_single_device(pdev->bus, 1047 pvt->bridge_ck = pci_scan_single_device(pdev->bus,
@@ -1034,8 +1054,9 @@ static int e752x_get_devs(struct pci_dev *pdev, int dev_idx,
1034 return 1; 1054 return 1;
1035 } 1055 }
1036 1056
1037 dev = pci_get_device(PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].ctl_dev, 1057 dev = pci_get_device(PCI_VENDOR_ID_INTEL,
1038 NULL); 1058 e752x_devs[dev_idx].ctl_dev,
1059 NULL);
1039 1060
1040 if (dev == NULL) 1061 if (dev == NULL)
1041 goto fail; 1062 goto fail;
@@ -1316,7 +1337,8 @@ MODULE_DESCRIPTION("MC support for Intel e752x/3100 memory controllers");
1316 1337
1317module_param(force_function_unhide, int, 0444); 1338module_param(force_function_unhide, int, 0444);
1318MODULE_PARM_DESC(force_function_unhide, "if BIOS sets Dev0:Fun1 up as hidden:" 1339MODULE_PARM_DESC(force_function_unhide, "if BIOS sets Dev0:Fun1 up as hidden:"
1319 " 1=force unhide and hope BIOS doesn't fight driver for Dev0:Fun1 access"); 1340 " 1=force unhide and hope BIOS doesn't fight driver for "
1341 "Dev0:Fun1 access");
1320 1342
1321module_param(edac_op_state, int, 0444); 1343module_param(edac_op_state, int, 0444);
1322MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); 1344MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
@@ -1324,3 +1346,6 @@ MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1324module_param(sysbus_parity, int, 0444); 1346module_param(sysbus_parity, int, 0444);
1325MODULE_PARM_DESC(sysbus_parity, "0=disable system bus parity checking," 1347MODULE_PARM_DESC(sysbus_parity, "0=disable system bus parity checking,"
1326 " 1=enable system bus parity checking, default=auto-detect"); 1348 " 1=enable system bus parity checking, default=auto-detect");
1349module_param(report_non_memory_errors, int, 0644);
1350MODULE_PARM_DESC(report_non_memory_errors, "0=disable non-memory error "
1351 "reporting, 1=enable non-memory error reporting");
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 021d18795145..ad218fe4942d 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -44,6 +44,25 @@ int edac_mc_get_poll_msec(void)
44 return edac_mc_poll_msec; 44 return edac_mc_poll_msec;
45} 45}
46 46
47static int edac_set_poll_msec(const char *val, struct kernel_param *kp)
48{
49 long l;
50 int ret;
51
52 if (!val)
53 return -EINVAL;
54
55 ret = strict_strtol(val, 0, &l);
56 if (ret == -EINVAL || ((int)l != l))
57 return -EINVAL;
58 *((int *)kp->arg) = l;
59
60 /* notify edac_mc engine to reset the poll period */
61 edac_mc_reset_delay_period(l);
62
63 return 0;
64}
65
47/* Parameter declarations for above */ 66/* Parameter declarations for above */
48module_param(edac_mc_panic_on_ue, int, 0644); 67module_param(edac_mc_panic_on_ue, int, 0644);
49MODULE_PARM_DESC(edac_mc_panic_on_ue, "Panic on uncorrected error: 0=off 1=on"); 68MODULE_PARM_DESC(edac_mc_panic_on_ue, "Panic on uncorrected error: 0=off 1=on");
@@ -53,7 +72,8 @@ MODULE_PARM_DESC(edac_mc_log_ue,
53module_param(edac_mc_log_ce, int, 0644); 72module_param(edac_mc_log_ce, int, 0644);
54MODULE_PARM_DESC(edac_mc_log_ce, 73MODULE_PARM_DESC(edac_mc_log_ce,
55 "Log correctable error to console: 0=off 1=on"); 74 "Log correctable error to console: 0=off 1=on");
56module_param(edac_mc_poll_msec, int, 0644); 75module_param_call(edac_mc_poll_msec, edac_set_poll_msec, param_get_int,
76 &edac_mc_poll_msec, 0644);
57MODULE_PARM_DESC(edac_mc_poll_msec, "Polling period in milliseconds"); 77MODULE_PARM_DESC(edac_mc_poll_msec, "Polling period in milliseconds");
58 78
59/* 79/*
@@ -103,16 +123,6 @@ static const char *edac_caps[] = {
103 123
104 124
105 125
106/*
107 * /sys/devices/system/edac/mc;
108 * data structures and methods
109 */
110static ssize_t memctrl_int_show(void *ptr, char *buffer)
111{
112 int *value = (int *)ptr;
113 return sprintf(buffer, "%u\n", *value);
114}
115
116static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count) 126static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count)
117{ 127{
118 int *value = (int *)ptr; 128 int *value = (int *)ptr;
@@ -123,23 +133,6 @@ static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count)
123 return count; 133 return count;
124} 134}
125 135
126/*
127 * mc poll_msec time value
128 */
129static ssize_t poll_msec_int_store(void *ptr, const char *buffer, size_t count)
130{
131 int *value = (int *)ptr;
132
133 if (isdigit(*buffer)) {
134 *value = simple_strtoul(buffer, NULL, 0);
135
136 /* notify edac_mc engine to reset the poll period */
137 edac_mc_reset_delay_period(*value);
138 }
139
140 return count;
141}
142
143 136
144/* EDAC sysfs CSROW data structures and methods 137/* EDAC sysfs CSROW data structures and methods
145 */ 138 */
@@ -185,7 +178,11 @@ static ssize_t csrow_edac_mode_show(struct csrow_info *csrow, char *data,
185static ssize_t channel_dimm_label_show(struct csrow_info *csrow, 178static ssize_t channel_dimm_label_show(struct csrow_info *csrow,
186 char *data, int channel) 179 char *data, int channel)
187{ 180{
188 return snprintf(data, EDAC_MC_LABEL_LEN, "%s", 181 /* if field has not been initialized, there is nothing to send */
182 if (!csrow->channels[channel].label[0])
183 return 0;
184
185 return snprintf(data, EDAC_MC_LABEL_LEN, "%s\n",
189 csrow->channels[channel].label); 186 csrow->channels[channel].label);
190} 187}
191 188
@@ -649,98 +646,10 @@ static struct kobj_type ktype_mci = {
649 .default_attrs = (struct attribute **)mci_attr, 646 .default_attrs = (struct attribute **)mci_attr,
650}; 647};
651 648
652/* show/store, tables, etc for the MC kset */
653
654
655struct memctrl_dev_attribute {
656 struct attribute attr;
657 void *value;
658 ssize_t(*show) (void *, char *);
659 ssize_t(*store) (void *, const char *, size_t);
660};
661
662/* Set of show/store abstract level functions for memory control object */
663static ssize_t memctrl_dev_show(struct kobject *kobj,
664 struct attribute *attr, char *buffer)
665{
666 struct memctrl_dev_attribute *memctrl_dev;
667 memctrl_dev = (struct memctrl_dev_attribute *)attr;
668
669 if (memctrl_dev->show)
670 return memctrl_dev->show(memctrl_dev->value, buffer);
671
672 return -EIO;
673}
674
675static ssize_t memctrl_dev_store(struct kobject *kobj, struct attribute *attr,
676 const char *buffer, size_t count)
677{
678 struct memctrl_dev_attribute *memctrl_dev;
679 memctrl_dev = (struct memctrl_dev_attribute *)attr;
680
681 if (memctrl_dev->store)
682 return memctrl_dev->store(memctrl_dev->value, buffer, count);
683
684 return -EIO;
685}
686
687static struct sysfs_ops memctrlfs_ops = {
688 .show = memctrl_dev_show,
689 .store = memctrl_dev_store
690};
691
692#define MEMCTRL_ATTR(_name, _mode, _show, _store) \
693static struct memctrl_dev_attribute attr_##_name = { \
694 .attr = {.name = __stringify(_name), .mode = _mode }, \
695 .value = &_name, \
696 .show = _show, \
697 .store = _store, \
698};
699
700#define MEMCTRL_STRING_ATTR(_name, _data, _mode, _show, _store) \
701static struct memctrl_dev_attribute attr_##_name = { \
702 .attr = {.name = __stringify(_name), .mode = _mode }, \
703 .value = _data, \
704 .show = _show, \
705 .store = _store, \
706};
707
708/* csrow<id> control files */
709MEMCTRL_ATTR(edac_mc_panic_on_ue,
710 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store);
711
712MEMCTRL_ATTR(edac_mc_log_ue,
713 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store);
714
715MEMCTRL_ATTR(edac_mc_log_ce,
716 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store);
717
718MEMCTRL_ATTR(edac_mc_poll_msec,
719 S_IRUGO | S_IWUSR, memctrl_int_show, poll_msec_int_store);
720
721/* Base Attributes of the memory ECC object */
722static struct memctrl_dev_attribute *memctrl_attr[] = {
723 &attr_edac_mc_panic_on_ue,
724 &attr_edac_mc_log_ue,
725 &attr_edac_mc_log_ce,
726 &attr_edac_mc_poll_msec,
727 NULL,
728};
729
730
731/* the ktype for the mc_kset internal kobj */
732static struct kobj_type ktype_mc_set_attribs = {
733 .sysfs_ops = &memctrlfs_ops,
734 .default_attrs = (struct attribute **)memctrl_attr,
735};
736
737/* EDAC memory controller sysfs kset: 649/* EDAC memory controller sysfs kset:
738 * /sys/devices/system/edac/mc 650 * /sys/devices/system/edac/mc
739 */ 651 */
740static struct kset mc_kset = { 652static struct kset *mc_kset;
741 .kobj = {.ktype = &ktype_mc_set_attribs },
742};
743
744 653
745/* 654/*
746 * edac_mc_register_sysfs_main_kobj 655 * edac_mc_register_sysfs_main_kobj
@@ -771,7 +680,7 @@ int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci)
771 } 680 }
772 681
773 /* this instance become part of the mc_kset */ 682 /* this instance become part of the mc_kset */
774 kobj_mci->kset = &mc_kset; 683 kobj_mci->kset = mc_kset;
775 684
776 /* register the mc<id> kobject to the mc_kset */ 685 /* register the mc<id> kobject to the mc_kset */
777 err = kobject_init_and_add(kobj_mci, &ktype_mci, NULL, 686 err = kobject_init_and_add(kobj_mci, &ktype_mci, NULL,
@@ -1001,12 +910,9 @@ int edac_sysfs_setup_mc_kset(void)
1001 } 910 }
1002 911
1003 /* Init the MC's kobject */ 912 /* Init the MC's kobject */
1004 kobject_set_name(&mc_kset.kobj, "mc"); 913 mc_kset = kset_create_and_add("mc", NULL, &edac_class->kset.kobj);
1005 mc_kset.kobj.parent = &edac_class->kset.kobj; 914 if (!mc_kset) {
1006 915 err = -ENOMEM;
1007 /* register the mc_kset */
1008 err = kset_register(&mc_kset);
1009 if (err) {
1010 debugf1("%s() Failed to register '.../edac/mc'\n", __func__); 916 debugf1("%s() Failed to register '.../edac/mc'\n", __func__);
1011 goto fail_out; 917 goto fail_out;
1012 } 918 }
@@ -1028,6 +934,6 @@ fail_out:
1028 */ 934 */
1029void edac_sysfs_teardown_mc_kset(void) 935void edac_sysfs_teardown_mc_kset(void)
1030{ 936{
1031 kset_unregister(&mc_kset); 937 kset_unregister(mc_kset);
1032} 938}
1033 939
diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
index 2c1fa1bb6df2..5c153dccc95e 100644
--- a/drivers/edac/edac_pci_sysfs.c
+++ b/drivers/edac/edac_pci_sysfs.c
@@ -28,7 +28,7 @@ static int edac_pci_poll_msec = 1000; /* one second workq period */
28static atomic_t pci_parity_count = ATOMIC_INIT(0); 28static atomic_t pci_parity_count = ATOMIC_INIT(0);
29static atomic_t pci_nonparity_count = ATOMIC_INIT(0); 29static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30 30
31static struct kobject edac_pci_top_main_kobj; 31static struct kobject *edac_pci_top_main_kobj;
32static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0); 32static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
33 33
34/* getter functions for the data variables */ 34/* getter functions for the data variables */
@@ -83,7 +83,7 @@ static void edac_pci_instance_release(struct kobject *kobj)
83 pci = to_instance(kobj); 83 pci = to_instance(kobj);
84 84
85 /* decrement reference count on top main kobj */ 85 /* decrement reference count on top main kobj */
86 kobject_put(&edac_pci_top_main_kobj); 86 kobject_put(edac_pci_top_main_kobj);
87 87
88 kfree(pci); /* Free the control struct */ 88 kfree(pci); /* Free the control struct */
89} 89}
@@ -166,7 +166,7 @@ static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)
166 * track the number of PCI instances we have, and thus nest 166 * track the number of PCI instances we have, and thus nest
167 * properly on keeping the module loaded 167 * properly on keeping the module loaded
168 */ 168 */
169 main_kobj = kobject_get(&edac_pci_top_main_kobj); 169 main_kobj = kobject_get(edac_pci_top_main_kobj);
170 if (!main_kobj) { 170 if (!main_kobj) {
171 err = -ENODEV; 171 err = -ENODEV;
172 goto error_out; 172 goto error_out;
@@ -174,11 +174,11 @@ static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)
174 174
175 /* And now register this new kobject under the main kobj */ 175 /* And now register this new kobject under the main kobj */
176 err = kobject_init_and_add(&pci->kobj, &ktype_pci_instance, 176 err = kobject_init_and_add(&pci->kobj, &ktype_pci_instance,
177 &edac_pci_top_main_kobj, "pci%d", idx); 177 edac_pci_top_main_kobj, "pci%d", idx);
178 if (err != 0) { 178 if (err != 0) {
179 debugf2("%s() failed to register instance pci%d\n", 179 debugf2("%s() failed to register instance pci%d\n",
180 __func__, idx); 180 __func__, idx);
181 kobject_put(&edac_pci_top_main_kobj); 181 kobject_put(edac_pci_top_main_kobj);
182 goto error_out; 182 goto error_out;
183 } 183 }
184 184
@@ -316,9 +316,10 @@ static struct edac_pci_dev_attribute *edac_pci_attr[] = {
316 */ 316 */
317static void edac_pci_release_main_kobj(struct kobject *kobj) 317static void edac_pci_release_main_kobj(struct kobject *kobj)
318{ 318{
319
320 debugf0("%s() here to module_put(THIS_MODULE)\n", __func__); 319 debugf0("%s() here to module_put(THIS_MODULE)\n", __func__);
321 320
321 kfree(kobj);
322
322 /* last reference to top EDAC PCI kobject has been removed, 323 /* last reference to top EDAC PCI kobject has been removed,
323 * NOW release our ref count on the core module 324 * NOW release our ref count on the core module
324 */ 325 */
@@ -369,8 +370,16 @@ static int edac_pci_main_kobj_setup(void)
369 goto decrement_count_fail; 370 goto decrement_count_fail;
370 } 371 }
371 372
373 edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
374 if (!edac_pci_top_main_kobj) {
375 debugf1("Failed to allocate\n");
376 err = -ENOMEM;
377 goto kzalloc_fail;
378 }
379
372 /* Instanstiate the pci object */ 380 /* Instanstiate the pci object */
373 err = kobject_init_and_add(&edac_pci_top_main_kobj, &ktype_edac_pci_main_kobj, 381 err = kobject_init_and_add(edac_pci_top_main_kobj,
382 &ktype_edac_pci_main_kobj,
374 &edac_class->kset.kobj, "pci"); 383 &edac_class->kset.kobj, "pci");
375 if (err) { 384 if (err) {
376 debugf1("Failed to register '.../edac/pci'\n"); 385 debugf1("Failed to register '.../edac/pci'\n");
@@ -381,13 +390,16 @@ static int edac_pci_main_kobj_setup(void)
381 * for EDAC PCI, then edac_pci_main_kobj_teardown() 390 * for EDAC PCI, then edac_pci_main_kobj_teardown()
382 * must be used, for resources to be cleaned up properly 391 * must be used, for resources to be cleaned up properly
383 */ 392 */
384 kobject_uevent(&edac_pci_top_main_kobj, KOBJ_ADD); 393 kobject_uevent(edac_pci_top_main_kobj, KOBJ_ADD);
385 debugf1("Registered '.../edac/pci' kobject\n"); 394 debugf1("Registered '.../edac/pci' kobject\n");
386 395
387 return 0; 396 return 0;
388 397
389 /* Error unwind statck */ 398 /* Error unwind statck */
390kobject_init_and_add_fail: 399kobject_init_and_add_fail:
400 kfree(edac_pci_top_main_kobj);
401
402kzalloc_fail:
391 module_put(THIS_MODULE); 403 module_put(THIS_MODULE);
392 404
393decrement_count_fail: 405decrement_count_fail:
@@ -414,7 +426,7 @@ static void edac_pci_main_kobj_teardown(void)
414 if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) { 426 if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) {
415 debugf0("%s() called kobject_put on main kobj\n", 427 debugf0("%s() called kobject_put on main kobj\n",
416 __func__); 428 __func__);
417 kobject_put(&edac_pci_top_main_kobj); 429 kobject_put(edac_pci_top_main_kobj);
418 } 430 }
419} 431}
420 432
diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
new file mode 100644
index 000000000000..22db05a67bfb
--- /dev/null
+++ b/drivers/edac/i5100_edac.c
@@ -0,0 +1,981 @@
1/*
2 * Intel 5100 Memory Controllers kernel module
3 *
4 * This file may be distributed under the terms of the
5 * GNU General Public License.
6 *
7 * This module is based on the following document:
8 *
9 * Intel 5100X Chipset Memory Controller Hub (MCH) - Datasheet
10 * http://download.intel.com/design/chipsets/datashts/318378.pdf
11 *
12 */
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/pci.h>
16#include <linux/pci_ids.h>
17#include <linux/slab.h>
18#include <linux/edac.h>
19#include <linux/delay.h>
20#include <linux/mmzone.h>
21
22#include "edac_core.h"
23
24/* register addresses */
25
26/* device 16, func 1 */
27#define I5100_MC 0x40 /* Memory Control Register */
28#define I5100_MS 0x44 /* Memory Status Register */
29#define I5100_SPDDATA 0x48 /* Serial Presence Detect Status Reg */
30#define I5100_SPDCMD 0x4c /* Serial Presence Detect Command Reg */
31#define I5100_TOLM 0x6c /* Top of Low Memory */
32#define I5100_MIR0 0x80 /* Memory Interleave Range 0 */
33#define I5100_MIR1 0x84 /* Memory Interleave Range 1 */
34#define I5100_AMIR_0 0x8c /* Adjusted Memory Interleave Range 0 */
35#define I5100_AMIR_1 0x90 /* Adjusted Memory Interleave Range 1 */
36#define I5100_FERR_NF_MEM 0xa0 /* MC First Non Fatal Errors */
37#define I5100_FERR_NF_MEM_M16ERR_MASK (1 << 16)
38#define I5100_FERR_NF_MEM_M15ERR_MASK (1 << 15)
39#define I5100_FERR_NF_MEM_M14ERR_MASK (1 << 14)
40#define I5100_FERR_NF_MEM_M12ERR_MASK (1 << 12)
41#define I5100_FERR_NF_MEM_M11ERR_MASK (1 << 11)
42#define I5100_FERR_NF_MEM_M10ERR_MASK (1 << 10)
43#define I5100_FERR_NF_MEM_M6ERR_MASK (1 << 6)
44#define I5100_FERR_NF_MEM_M5ERR_MASK (1 << 5)
45#define I5100_FERR_NF_MEM_M4ERR_MASK (1 << 4)
46#define I5100_FERR_NF_MEM_M1ERR_MASK 1
47#define I5100_FERR_NF_MEM_ANY_MASK \
48 (I5100_FERR_NF_MEM_M16ERR_MASK | \
49 I5100_FERR_NF_MEM_M15ERR_MASK | \
50 I5100_FERR_NF_MEM_M14ERR_MASK | \
51 I5100_FERR_NF_MEM_M12ERR_MASK | \
52 I5100_FERR_NF_MEM_M11ERR_MASK | \
53 I5100_FERR_NF_MEM_M10ERR_MASK | \
54 I5100_FERR_NF_MEM_M6ERR_MASK | \
55 I5100_FERR_NF_MEM_M5ERR_MASK | \
56 I5100_FERR_NF_MEM_M4ERR_MASK | \
57 I5100_FERR_NF_MEM_M1ERR_MASK)
58#define I5100_NERR_NF_MEM 0xa4 /* MC Next Non-Fatal Errors */
59#define I5100_EMASK_MEM 0xa8 /* MC Error Mask Register */
60
61/* device 21 and 22, func 0 */
62#define I5100_MTR_0 0x154 /* Memory Technology Registers 0-3 */
63#define I5100_DMIR 0x15c /* DIMM Interleave Range */
64#define I5100_VALIDLOG 0x18c /* Valid Log Markers */
65#define I5100_NRECMEMA 0x190 /* Non-Recoverable Memory Error Log Reg A */
66#define I5100_NRECMEMB 0x194 /* Non-Recoverable Memory Error Log Reg B */
67#define I5100_REDMEMA 0x198 /* Recoverable Memory Data Error Log Reg A */
68#define I5100_REDMEMB 0x19c /* Recoverable Memory Data Error Log Reg B */
69#define I5100_RECMEMA 0x1a0 /* Recoverable Memory Error Log Reg A */
70#define I5100_RECMEMB 0x1a4 /* Recoverable Memory Error Log Reg B */
71#define I5100_MTR_4 0x1b0 /* Memory Technology Registers 4,5 */
72
73/* bit field accessors */
74
75static inline u32 i5100_mc_errdeten(u32 mc)
76{
77 return mc >> 5 & 1;
78}
79
80static inline u16 i5100_spddata_rdo(u16 a)
81{
82 return a >> 15 & 1;
83}
84
85static inline u16 i5100_spddata_sbe(u16 a)
86{
87 return a >> 13 & 1;
88}
89
90static inline u16 i5100_spddata_busy(u16 a)
91{
92 return a >> 12 & 1;
93}
94
95static inline u16 i5100_spddata_data(u16 a)
96{
97 return a & ((1 << 8) - 1);
98}
99
100static inline u32 i5100_spdcmd_create(u32 dti, u32 ckovrd, u32 sa, u32 ba,
101 u32 data, u32 cmd)
102{
103 return ((dti & ((1 << 4) - 1)) << 28) |
104 ((ckovrd & 1) << 27) |
105 ((sa & ((1 << 3) - 1)) << 24) |
106 ((ba & ((1 << 8) - 1)) << 16) |
107 ((data & ((1 << 8) - 1)) << 8) |
108 (cmd & 1);
109}
110
111static inline u16 i5100_tolm_tolm(u16 a)
112{
113 return a >> 12 & ((1 << 4) - 1);
114}
115
116static inline u16 i5100_mir_limit(u16 a)
117{
118 return a >> 4 & ((1 << 12) - 1);
119}
120
121static inline u16 i5100_mir_way1(u16 a)
122{
123 return a >> 1 & 1;
124}
125
126static inline u16 i5100_mir_way0(u16 a)
127{
128 return a & 1;
129}
130
131static inline u32 i5100_ferr_nf_mem_chan_indx(u32 a)
132{
133 return a >> 28 & 1;
134}
135
136static inline u32 i5100_ferr_nf_mem_any(u32 a)
137{
138 return a & I5100_FERR_NF_MEM_ANY_MASK;
139}
140
141static inline u32 i5100_nerr_nf_mem_any(u32 a)
142{
143 return i5100_ferr_nf_mem_any(a);
144}
145
146static inline u32 i5100_dmir_limit(u32 a)
147{
148 return a >> 16 & ((1 << 11) - 1);
149}
150
151static inline u32 i5100_dmir_rank(u32 a, u32 i)
152{
153 return a >> (4 * i) & ((1 << 2) - 1);
154}
155
156static inline u16 i5100_mtr_present(u16 a)
157{
158 return a >> 10 & 1;
159}
160
161static inline u16 i5100_mtr_ethrottle(u16 a)
162{
163 return a >> 9 & 1;
164}
165
166static inline u16 i5100_mtr_width(u16 a)
167{
168 return a >> 8 & 1;
169}
170
171static inline u16 i5100_mtr_numbank(u16 a)
172{
173 return a >> 6 & 1;
174}
175
176static inline u16 i5100_mtr_numrow(u16 a)
177{
178 return a >> 2 & ((1 << 2) - 1);
179}
180
181static inline u16 i5100_mtr_numcol(u16 a)
182{
183 return a & ((1 << 2) - 1);
184}
185
186
187static inline u32 i5100_validlog_redmemvalid(u32 a)
188{
189 return a >> 2 & 1;
190}
191
192static inline u32 i5100_validlog_recmemvalid(u32 a)
193{
194 return a >> 1 & 1;
195}
196
197static inline u32 i5100_validlog_nrecmemvalid(u32 a)
198{
199 return a & 1;
200}
201
202static inline u32 i5100_nrecmema_merr(u32 a)
203{
204 return a >> 15 & ((1 << 5) - 1);
205}
206
207static inline u32 i5100_nrecmema_bank(u32 a)
208{
209 return a >> 12 & ((1 << 3) - 1);
210}
211
212static inline u32 i5100_nrecmema_rank(u32 a)
213{
214 return a >> 8 & ((1 << 3) - 1);
215}
216
217static inline u32 i5100_nrecmema_dm_buf_id(u32 a)
218{
219 return a & ((1 << 8) - 1);
220}
221
222static inline u32 i5100_nrecmemb_cas(u32 a)
223{
224 return a >> 16 & ((1 << 13) - 1);
225}
226
227static inline u32 i5100_nrecmemb_ras(u32 a)
228{
229 return a & ((1 << 16) - 1);
230}
231
232static inline u32 i5100_redmemb_ecc_locator(u32 a)
233{
234 return a & ((1 << 18) - 1);
235}
236
237static inline u32 i5100_recmema_merr(u32 a)
238{
239 return i5100_nrecmema_merr(a);
240}
241
242static inline u32 i5100_recmema_bank(u32 a)
243{
244 return i5100_nrecmema_bank(a);
245}
246
247static inline u32 i5100_recmema_rank(u32 a)
248{
249 return i5100_nrecmema_rank(a);
250}
251
252static inline u32 i5100_recmema_dm_buf_id(u32 a)
253{
254 return i5100_nrecmema_dm_buf_id(a);
255}
256
257static inline u32 i5100_recmemb_cas(u32 a)
258{
259 return i5100_nrecmemb_cas(a);
260}
261
262static inline u32 i5100_recmemb_ras(u32 a)
263{
264 return i5100_nrecmemb_ras(a);
265}
266
267/* some generic limits */
268#define I5100_MAX_RANKS_PER_CTLR 6
269#define I5100_MAX_CTLRS 2
270#define I5100_MAX_RANKS_PER_DIMM 4
271#define I5100_DIMM_ADDR_LINES (6 - 3) /* 64 bits / 8 bits per byte */
272#define I5100_MAX_DIMM_SLOTS_PER_CTLR 4
273#define I5100_MAX_RANK_INTERLEAVE 4
274#define I5100_MAX_DMIRS 5
275
276struct i5100_priv {
277 /* ranks on each dimm -- 0 maps to not present -- obtained via SPD */
278 int dimm_numrank[I5100_MAX_CTLRS][I5100_MAX_DIMM_SLOTS_PER_CTLR];
279
280 /*
281 * mainboard chip select map -- maps i5100 chip selects to
282 * DIMM slot chip selects. In the case of only 4 ranks per
283 * controller, the mapping is fairly obvious but not unique.
284 * we map -1 -> NC and assume both controllers use the same
285 * map...
286 *
287 */
288 int dimm_csmap[I5100_MAX_DIMM_SLOTS_PER_CTLR][I5100_MAX_RANKS_PER_DIMM];
289
290 /* memory interleave range */
291 struct {
292 u64 limit;
293 unsigned way[2];
294 } mir[I5100_MAX_CTLRS];
295
296 /* adjusted memory interleave range register */
297 unsigned amir[I5100_MAX_CTLRS];
298
299 /* dimm interleave range */
300 struct {
301 unsigned rank[I5100_MAX_RANK_INTERLEAVE];
302 u64 limit;
303 } dmir[I5100_MAX_CTLRS][I5100_MAX_DMIRS];
304
305 /* memory technology registers... */
306 struct {
307 unsigned present; /* 0 or 1 */
308 unsigned ethrottle; /* 0 or 1 */
309 unsigned width; /* 4 or 8 bits */
310 unsigned numbank; /* 2 or 3 lines */
311 unsigned numrow; /* 13 .. 16 lines */
312 unsigned numcol; /* 11 .. 12 lines */
313 } mtr[I5100_MAX_CTLRS][I5100_MAX_RANKS_PER_CTLR];
314
315 u64 tolm; /* top of low memory in bytes */
316 unsigned ranksperctlr; /* number of ranks per controller */
317
318 struct pci_dev *mc; /* device 16 func 1 */
319 struct pci_dev *ch0mm; /* device 21 func 0 */
320 struct pci_dev *ch1mm; /* device 22 func 0 */
321};
322
323/* map a rank/ctlr to a slot number on the mainboard */
324static int i5100_rank_to_slot(const struct mem_ctl_info *mci,
325 int ctlr, int rank)
326{
327 const struct i5100_priv *priv = mci->pvt_info;
328 int i;
329
330 for (i = 0; i < I5100_MAX_DIMM_SLOTS_PER_CTLR; i++) {
331 int j;
332 const int numrank = priv->dimm_numrank[ctlr][i];
333
334 for (j = 0; j < numrank; j++)
335 if (priv->dimm_csmap[i][j] == rank)
336 return i * 2 + ctlr;
337 }
338
339 return -1;
340}
341
342static const char *i5100_err_msg(unsigned err)
343{
344 static const char *merrs[] = {
345 "unknown", /* 0 */
346 "uncorrectable data ECC on replay", /* 1 */
347 "unknown", /* 2 */
348 "unknown", /* 3 */
349 "aliased uncorrectable demand data ECC", /* 4 */
350 "aliased uncorrectable spare-copy data ECC", /* 5 */
351 "aliased uncorrectable patrol data ECC", /* 6 */
352 "unknown", /* 7 */
353 "unknown", /* 8 */
354 "unknown", /* 9 */
355 "non-aliased uncorrectable demand data ECC", /* 10 */
356 "non-aliased uncorrectable spare-copy data ECC", /* 11 */
357 "non-aliased uncorrectable patrol data ECC", /* 12 */
358 "unknown", /* 13 */
359 "correctable demand data ECC", /* 14 */
360 "correctable spare-copy data ECC", /* 15 */
361 "correctable patrol data ECC", /* 16 */
362 "unknown", /* 17 */
363 "SPD protocol error", /* 18 */
364 "unknown", /* 19 */
365 "spare copy initiated", /* 20 */
366 "spare copy completed", /* 21 */
367 };
368 unsigned i;
369
370 for (i = 0; i < ARRAY_SIZE(merrs); i++)
371 if (1 << i & err)
372 return merrs[i];
373
374 return "none";
375}
376
377/* convert csrow index into a rank (per controller -- 0..5) */
378static int i5100_csrow_to_rank(const struct mem_ctl_info *mci, int csrow)
379{
380 const struct i5100_priv *priv = mci->pvt_info;
381
382 return csrow % priv->ranksperctlr;
383}
384
385/* convert csrow index into a controller (0..1) */
386static int i5100_csrow_to_cntlr(const struct mem_ctl_info *mci, int csrow)
387{
388 const struct i5100_priv *priv = mci->pvt_info;
389
390 return csrow / priv->ranksperctlr;
391}
392
393static unsigned i5100_rank_to_csrow(const struct mem_ctl_info *mci,
394 int ctlr, int rank)
395{
396 const struct i5100_priv *priv = mci->pvt_info;
397
398 return ctlr * priv->ranksperctlr + rank;
399}
400
401static void i5100_handle_ce(struct mem_ctl_info *mci,
402 int ctlr,
403 unsigned bank,
404 unsigned rank,
405 unsigned long syndrome,
406 unsigned cas,
407 unsigned ras,
408 const char *msg)
409{
410 const int csrow = i5100_rank_to_csrow(mci, ctlr, rank);
411
412 printk(KERN_ERR
413 "CE ctlr %d, bank %u, rank %u, syndrome 0x%lx, "
414 "cas %u, ras %u, csrow %u, label \"%s\": %s\n",
415 ctlr, bank, rank, syndrome, cas, ras,
416 csrow, mci->csrows[csrow].channels[0].label, msg);
417
418 mci->ce_count++;
419 mci->csrows[csrow].ce_count++;
420 mci->csrows[csrow].channels[0].ce_count++;
421}
422
423static void i5100_handle_ue(struct mem_ctl_info *mci,
424 int ctlr,
425 unsigned bank,
426 unsigned rank,
427 unsigned long syndrome,
428 unsigned cas,
429 unsigned ras,
430 const char *msg)
431{
432 const int csrow = i5100_rank_to_csrow(mci, ctlr, rank);
433
434 printk(KERN_ERR
435 "UE ctlr %d, bank %u, rank %u, syndrome 0x%lx, "
436 "cas %u, ras %u, csrow %u, label \"%s\": %s\n",
437 ctlr, bank, rank, syndrome, cas, ras,
438 csrow, mci->csrows[csrow].channels[0].label, msg);
439
440 mci->ue_count++;
441 mci->csrows[csrow].ue_count++;
442}
443
444static void i5100_read_log(struct mem_ctl_info *mci, int ctlr,
445 u32 ferr, u32 nerr)
446{
447 struct i5100_priv *priv = mci->pvt_info;
448 struct pci_dev *pdev = (ctlr) ? priv->ch1mm : priv->ch0mm;
449 u32 dw;
450 u32 dw2;
451 unsigned syndrome = 0;
452 unsigned ecc_loc = 0;
453 unsigned merr;
454 unsigned bank;
455 unsigned rank;
456 unsigned cas;
457 unsigned ras;
458
459 pci_read_config_dword(pdev, I5100_VALIDLOG, &dw);
460
461 if (i5100_validlog_redmemvalid(dw)) {
462 pci_read_config_dword(pdev, I5100_REDMEMA, &dw2);
463 syndrome = dw2;
464 pci_read_config_dword(pdev, I5100_REDMEMB, &dw2);
465 ecc_loc = i5100_redmemb_ecc_locator(dw2);
466 }
467
468 if (i5100_validlog_recmemvalid(dw)) {
469 const char *msg;
470
471 pci_read_config_dword(pdev, I5100_RECMEMA, &dw2);
472 merr = i5100_recmema_merr(dw2);
473 bank = i5100_recmema_bank(dw2);
474 rank = i5100_recmema_rank(dw2);
475
476 pci_read_config_dword(pdev, I5100_RECMEMB, &dw2);
477 cas = i5100_recmemb_cas(dw2);
478 ras = i5100_recmemb_ras(dw2);
479
480 /* FIXME: not really sure if this is what merr is...
481 */
482 if (!merr)
483 msg = i5100_err_msg(ferr);
484 else
485 msg = i5100_err_msg(nerr);
486
487 i5100_handle_ce(mci, ctlr, bank, rank, syndrome, cas, ras, msg);
488 }
489
490 if (i5100_validlog_nrecmemvalid(dw)) {
491 const char *msg;
492
493 pci_read_config_dword(pdev, I5100_NRECMEMA, &dw2);
494 merr = i5100_nrecmema_merr(dw2);
495 bank = i5100_nrecmema_bank(dw2);
496 rank = i5100_nrecmema_rank(dw2);
497
498 pci_read_config_dword(pdev, I5100_NRECMEMB, &dw2);
499 cas = i5100_nrecmemb_cas(dw2);
500 ras = i5100_nrecmemb_ras(dw2);
501
502 /* FIXME: not really sure if this is what merr is...
503 */
504 if (!merr)
505 msg = i5100_err_msg(ferr);
506 else
507 msg = i5100_err_msg(nerr);
508
509 i5100_handle_ue(mci, ctlr, bank, rank, syndrome, cas, ras, msg);
510 }
511
512 pci_write_config_dword(pdev, I5100_VALIDLOG, dw);
513}
514
515static void i5100_check_error(struct mem_ctl_info *mci)
516{
517 struct i5100_priv *priv = mci->pvt_info;
518 u32 dw;
519
520
521 pci_read_config_dword(priv->mc, I5100_FERR_NF_MEM, &dw);
522 if (i5100_ferr_nf_mem_any(dw)) {
523 u32 dw2;
524
525 pci_read_config_dword(priv->mc, I5100_NERR_NF_MEM, &dw2);
526 if (dw2)
527 pci_write_config_dword(priv->mc, I5100_NERR_NF_MEM,
528 dw2);
529 pci_write_config_dword(priv->mc, I5100_FERR_NF_MEM, dw);
530
531 i5100_read_log(mci, i5100_ferr_nf_mem_chan_indx(dw),
532 i5100_ferr_nf_mem_any(dw),
533 i5100_nerr_nf_mem_any(dw2));
534 }
535}
536
537static struct pci_dev *pci_get_device_func(unsigned vendor,
538 unsigned device,
539 unsigned func)
540{
541 struct pci_dev *ret = NULL;
542
543 while (1) {
544 ret = pci_get_device(vendor, device, ret);
545
546 if (!ret)
547 break;
548
549 if (PCI_FUNC(ret->devfn) == func)
550 break;
551 }
552
553 return ret;
554}
555
556static unsigned long __devinit i5100_npages(struct mem_ctl_info *mci,
557 int csrow)
558{
559 struct i5100_priv *priv = mci->pvt_info;
560 const unsigned ctlr_rank = i5100_csrow_to_rank(mci, csrow);
561 const unsigned ctlr = i5100_csrow_to_cntlr(mci, csrow);
562 unsigned addr_lines;
563
564 /* dimm present? */
565 if (!priv->mtr[ctlr][ctlr_rank].present)
566 return 0ULL;
567
568 addr_lines =
569 I5100_DIMM_ADDR_LINES +
570 priv->mtr[ctlr][ctlr_rank].numcol +
571 priv->mtr[ctlr][ctlr_rank].numrow +
572 priv->mtr[ctlr][ctlr_rank].numbank;
573
574 return (unsigned long)
575 ((unsigned long long) (1ULL << addr_lines) / PAGE_SIZE);
576}
577
578static void __devinit i5100_init_mtr(struct mem_ctl_info *mci)
579{
580 struct i5100_priv *priv = mci->pvt_info;
581 struct pci_dev *mms[2] = { priv->ch0mm, priv->ch1mm };
582 int i;
583
584 for (i = 0; i < I5100_MAX_CTLRS; i++) {
585 int j;
586 struct pci_dev *pdev = mms[i];
587
588 for (j = 0; j < I5100_MAX_RANKS_PER_CTLR; j++) {
589 const unsigned addr =
590 (j < 4) ? I5100_MTR_0 + j * 2 :
591 I5100_MTR_4 + (j - 4) * 2;
592 u16 w;
593
594 pci_read_config_word(pdev, addr, &w);
595
596 priv->mtr[i][j].present = i5100_mtr_present(w);
597 priv->mtr[i][j].ethrottle = i5100_mtr_ethrottle(w);
598 priv->mtr[i][j].width = 4 + 4 * i5100_mtr_width(w);
599 priv->mtr[i][j].numbank = 2 + i5100_mtr_numbank(w);
600 priv->mtr[i][j].numrow = 13 + i5100_mtr_numrow(w);
601 priv->mtr[i][j].numcol = 10 + i5100_mtr_numcol(w);
602 }
603 }
604}
605
606/*
607 * FIXME: make this into a real i2c adapter (so that dimm-decode
608 * will work)?
609 */
610static int i5100_read_spd_byte(const struct mem_ctl_info *mci,
611 u8 ch, u8 slot, u8 addr, u8 *byte)
612{
613 struct i5100_priv *priv = mci->pvt_info;
614 u16 w;
615 unsigned long et;
616
617 pci_read_config_word(priv->mc, I5100_SPDDATA, &w);
618 if (i5100_spddata_busy(w))
619 return -1;
620
621 pci_write_config_dword(priv->mc, I5100_SPDCMD,
622 i5100_spdcmd_create(0xa, 1, ch * 4 + slot, addr,
623 0, 0));
624
625 /* wait up to 100ms */
626 et = jiffies + HZ / 10;
627 udelay(100);
628 while (1) {
629 pci_read_config_word(priv->mc, I5100_SPDDATA, &w);
630 if (!i5100_spddata_busy(w))
631 break;
632 udelay(100);
633 }
634
635 if (!i5100_spddata_rdo(w) || i5100_spddata_sbe(w))
636 return -1;
637
638 *byte = i5100_spddata_data(w);
639
640 return 0;
641}
642
643/*
644 * fill dimm chip select map
645 *
646 * FIXME:
647 * o only valid for 4 ranks per controller
648 * o not the only way to may chip selects to dimm slots
649 * o investigate if there is some way to obtain this map from the bios
650 */
651static void __devinit i5100_init_dimm_csmap(struct mem_ctl_info *mci)
652{
653 struct i5100_priv *priv = mci->pvt_info;
654 int i;
655
656 WARN_ON(priv->ranksperctlr != 4);
657
658 for (i = 0; i < I5100_MAX_DIMM_SLOTS_PER_CTLR; i++) {
659 int j;
660
661 for (j = 0; j < I5100_MAX_RANKS_PER_DIMM; j++)
662 priv->dimm_csmap[i][j] = -1; /* default NC */
663 }
664
665 /* only 2 chip selects per slot... */
666 priv->dimm_csmap[0][0] = 0;
667 priv->dimm_csmap[0][1] = 3;
668 priv->dimm_csmap[1][0] = 1;
669 priv->dimm_csmap[1][1] = 2;
670 priv->dimm_csmap[2][0] = 2;
671 priv->dimm_csmap[3][0] = 3;
672}
673
674static void __devinit i5100_init_dimm_layout(struct pci_dev *pdev,
675 struct mem_ctl_info *mci)
676{
677 struct i5100_priv *priv = mci->pvt_info;
678 int i;
679
680 for (i = 0; i < I5100_MAX_CTLRS; i++) {
681 int j;
682
683 for (j = 0; j < I5100_MAX_DIMM_SLOTS_PER_CTLR; j++) {
684 u8 rank;
685
686 if (i5100_read_spd_byte(mci, i, j, 5, &rank) < 0)
687 priv->dimm_numrank[i][j] = 0;
688 else
689 priv->dimm_numrank[i][j] = (rank & 3) + 1;
690 }
691 }
692
693 i5100_init_dimm_csmap(mci);
694}
695
696static void __devinit i5100_init_interleaving(struct pci_dev *pdev,
697 struct mem_ctl_info *mci)
698{
699 u16 w;
700 u32 dw;
701 struct i5100_priv *priv = mci->pvt_info;
702 struct pci_dev *mms[2] = { priv->ch0mm, priv->ch1mm };
703 int i;
704
705 pci_read_config_word(pdev, I5100_TOLM, &w);
706 priv->tolm = (u64) i5100_tolm_tolm(w) * 256 * 1024 * 1024;
707
708 pci_read_config_word(pdev, I5100_MIR0, &w);
709 priv->mir[0].limit = (u64) i5100_mir_limit(w) << 28;
710 priv->mir[0].way[1] = i5100_mir_way1(w);
711 priv->mir[0].way[0] = i5100_mir_way0(w);
712
713 pci_read_config_word(pdev, I5100_MIR1, &w);
714 priv->mir[1].limit = (u64) i5100_mir_limit(w) << 28;
715 priv->mir[1].way[1] = i5100_mir_way1(w);
716 priv->mir[1].way[0] = i5100_mir_way0(w);
717
718 pci_read_config_word(pdev, I5100_AMIR_0, &w);
719 priv->amir[0] = w;
720 pci_read_config_word(pdev, I5100_AMIR_1, &w);
721 priv->amir[1] = w;
722
723 for (i = 0; i < I5100_MAX_CTLRS; i++) {
724 int j;
725
726 for (j = 0; j < 5; j++) {
727 int k;
728
729 pci_read_config_dword(mms[i], I5100_DMIR + j * 4, &dw);
730
731 priv->dmir[i][j].limit =
732 (u64) i5100_dmir_limit(dw) << 28;
733 for (k = 0; k < I5100_MAX_RANKS_PER_DIMM; k++)
734 priv->dmir[i][j].rank[k] =
735 i5100_dmir_rank(dw, k);
736 }
737 }
738
739 i5100_init_mtr(mci);
740}
741
742static void __devinit i5100_init_csrows(struct mem_ctl_info *mci)
743{
744 int i;
745 unsigned long total_pages = 0UL;
746 struct i5100_priv *priv = mci->pvt_info;
747
748 for (i = 0; i < mci->nr_csrows; i++) {
749 const unsigned long npages = i5100_npages(mci, i);
750 const unsigned cntlr = i5100_csrow_to_cntlr(mci, i);
751 const unsigned rank = i5100_csrow_to_rank(mci, i);
752
753 if (!npages)
754 continue;
755
756 /*
757 * FIXME: these two are totally bogus -- I don't see how to
758 * map them correctly to this structure...
759 */
760 mci->csrows[i].first_page = total_pages;
761 mci->csrows[i].last_page = total_pages + npages - 1;
762 mci->csrows[i].page_mask = 0UL;
763
764 mci->csrows[i].nr_pages = npages;
765 mci->csrows[i].grain = 32;
766 mci->csrows[i].csrow_idx = i;
767 mci->csrows[i].dtype =
768 (priv->mtr[cntlr][rank].width == 4) ? DEV_X4 : DEV_X8;
769 mci->csrows[i].ue_count = 0;
770 mci->csrows[i].ce_count = 0;
771 mci->csrows[i].mtype = MEM_RDDR2;
772 mci->csrows[i].edac_mode = EDAC_SECDED;
773 mci->csrows[i].mci = mci;
774 mci->csrows[i].nr_channels = 1;
775 mci->csrows[i].channels[0].chan_idx = 0;
776 mci->csrows[i].channels[0].ce_count = 0;
777 mci->csrows[i].channels[0].csrow = mci->csrows + i;
778 snprintf(mci->csrows[i].channels[0].label,
779 sizeof(mci->csrows[i].channels[0].label),
780 "DIMM%u", i5100_rank_to_slot(mci, cntlr, rank));
781
782 total_pages += npages;
783 }
784}
785
786static int __devinit i5100_init_one(struct pci_dev *pdev,
787 const struct pci_device_id *id)
788{
789 int rc;
790 struct mem_ctl_info *mci;
791 struct i5100_priv *priv;
792 struct pci_dev *ch0mm, *ch1mm;
793 int ret = 0;
794 u32 dw;
795 int ranksperch;
796
797 if (PCI_FUNC(pdev->devfn) != 1)
798 return -ENODEV;
799
800 rc = pci_enable_device(pdev);
801 if (rc < 0) {
802 ret = rc;
803 goto bail;
804 }
805
806 /* ECC enabled? */
807 pci_read_config_dword(pdev, I5100_MC, &dw);
808 if (!i5100_mc_errdeten(dw)) {
809 printk(KERN_INFO "i5100_edac: ECC not enabled.\n");
810 ret = -ENODEV;
811 goto bail_pdev;
812 }
813
814 /* figure out how many ranks, from strapped state of 48GB_Mode input */
815 pci_read_config_dword(pdev, I5100_MS, &dw);
816 ranksperch = !!(dw & (1 << 8)) * 2 + 4;
817
818 if (ranksperch != 4) {
819 /* FIXME: get 6 ranks / controller to work - need hw... */
820 printk(KERN_INFO "i5100_edac: unsupported configuration.\n");
821 ret = -ENODEV;
822 goto bail_pdev;
823 }
824
825 /* enable error reporting... */
826 pci_read_config_dword(pdev, I5100_EMASK_MEM, &dw);
827 dw &= ~I5100_FERR_NF_MEM_ANY_MASK;
828 pci_write_config_dword(pdev, I5100_EMASK_MEM, dw);
829
830 /* device 21, func 0, Channel 0 Memory Map, Error Flag/Mask, etc... */
831 ch0mm = pci_get_device_func(PCI_VENDOR_ID_INTEL,
832 PCI_DEVICE_ID_INTEL_5100_21, 0);
833 if (!ch0mm) {
834 ret = -ENODEV;
835 goto bail_pdev;
836 }
837
838 rc = pci_enable_device(ch0mm);
839 if (rc < 0) {
840 ret = rc;
841 goto bail_ch0;
842 }
843
844 /* device 22, func 0, Channel 1 Memory Map, Error Flag/Mask, etc... */
845 ch1mm = pci_get_device_func(PCI_VENDOR_ID_INTEL,
846 PCI_DEVICE_ID_INTEL_5100_22, 0);
847 if (!ch1mm) {
848 ret = -ENODEV;
849 goto bail_disable_ch0;
850 }
851
852 rc = pci_enable_device(ch1mm);
853 if (rc < 0) {
854 ret = rc;
855 goto bail_ch1;
856 }
857
858 mci = edac_mc_alloc(sizeof(*priv), ranksperch * 2, 1, 0);
859 if (!mci) {
860 ret = -ENOMEM;
861 goto bail_disable_ch1;
862 }
863
864 mci->dev = &pdev->dev;
865
866 priv = mci->pvt_info;
867 priv->ranksperctlr = ranksperch;
868 priv->mc = pdev;
869 priv->ch0mm = ch0mm;
870 priv->ch1mm = ch1mm;
871
872 i5100_init_dimm_layout(pdev, mci);
873 i5100_init_interleaving(pdev, mci);
874
875 mci->mtype_cap = MEM_FLAG_FB_DDR2;
876 mci->edac_ctl_cap = EDAC_FLAG_SECDED;
877 mci->edac_cap = EDAC_FLAG_SECDED;
878 mci->mod_name = "i5100_edac.c";
879 mci->mod_ver = "not versioned";
880 mci->ctl_name = "i5100";
881 mci->dev_name = pci_name(pdev);
882 mci->ctl_page_to_phys = NULL;
883
884 mci->edac_check = i5100_check_error;
885
886 i5100_init_csrows(mci);
887
888 /* this strange construction seems to be in every driver, dunno why */
889 switch (edac_op_state) {
890 case EDAC_OPSTATE_POLL:
891 case EDAC_OPSTATE_NMI:
892 break;
893 default:
894 edac_op_state = EDAC_OPSTATE_POLL;
895 break;
896 }
897
898 if (edac_mc_add_mc(mci)) {
899 ret = -ENODEV;
900 goto bail_mc;
901 }
902
903 return ret;
904
905bail_mc:
906 edac_mc_free(mci);
907
908bail_disable_ch1:
909 pci_disable_device(ch1mm);
910
911bail_ch1:
912 pci_dev_put(ch1mm);
913
914bail_disable_ch0:
915 pci_disable_device(ch0mm);
916
917bail_ch0:
918 pci_dev_put(ch0mm);
919
920bail_pdev:
921 pci_disable_device(pdev);
922
923bail:
924 return ret;
925}
926
927static void __devexit i5100_remove_one(struct pci_dev *pdev)
928{
929 struct mem_ctl_info *mci;
930 struct i5100_priv *priv;
931
932 mci = edac_mc_del_mc(&pdev->dev);
933
934 if (!mci)
935 return;
936
937 priv = mci->pvt_info;
938 pci_disable_device(pdev);
939 pci_disable_device(priv->ch0mm);
940 pci_disable_device(priv->ch1mm);
941 pci_dev_put(priv->ch0mm);
942 pci_dev_put(priv->ch1mm);
943
944 edac_mc_free(mci);
945}
946
947static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
948 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
949 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
950 { 0, }
951};
952MODULE_DEVICE_TABLE(pci, i5100_pci_tbl);
953
954static struct pci_driver i5100_driver = {
955 .name = KBUILD_BASENAME,
956 .probe = i5100_init_one,
957 .remove = __devexit_p(i5100_remove_one),
958 .id_table = i5100_pci_tbl,
959};
960
961static int __init i5100_init(void)
962{
963 int pci_rc;
964
965 pci_rc = pci_register_driver(&i5100_driver);
966
967 return (pci_rc < 0) ? pci_rc : 0;
968}
969
970static void __exit i5100_exit(void)
971{
972 pci_unregister_driver(&i5100_driver);
973}
974
975module_init(i5100_init);
976module_exit(i5100_exit);
977
978MODULE_LICENSE("GPL");
979MODULE_AUTHOR
980 ("Arthur Jones <ajones@riverbed.com>");
981MODULE_DESCRIPTION("MC Driver for Intel I5100 memory controllers");
diff --git a/drivers/edac/mpc85xx_edac.c b/drivers/edac/mpc85xx_edac.c
index d49361bfe670..2265d9ca1535 100644
--- a/drivers/edac/mpc85xx_edac.c
+++ b/drivers/edac/mpc85xx_edac.c
@@ -195,14 +195,15 @@ static irqreturn_t mpc85xx_pci_isr(int irq, void *dev_id)
195 return IRQ_HANDLED; 195 return IRQ_HANDLED;
196} 196}
197 197
198static int __devinit mpc85xx_pci_err_probe(struct platform_device *pdev) 198static int __devinit mpc85xx_pci_err_probe(struct of_device *op,
199 const struct of_device_id *match)
199{ 200{
200 struct edac_pci_ctl_info *pci; 201 struct edac_pci_ctl_info *pci;
201 struct mpc85xx_pci_pdata *pdata; 202 struct mpc85xx_pci_pdata *pdata;
202 struct resource *r; 203 struct resource r;
203 int res = 0; 204 int res = 0;
204 205
205 if (!devres_open_group(&pdev->dev, mpc85xx_pci_err_probe, GFP_KERNEL)) 206 if (!devres_open_group(&op->dev, mpc85xx_pci_err_probe, GFP_KERNEL))
206 return -ENOMEM; 207 return -ENOMEM;
207 208
208 pci = edac_pci_alloc_ctl_info(sizeof(*pdata), "mpc85xx_pci_err"); 209 pci = edac_pci_alloc_ctl_info(sizeof(*pdata), "mpc85xx_pci_err");
@@ -212,34 +213,37 @@ static int __devinit mpc85xx_pci_err_probe(struct platform_device *pdev)
212 pdata = pci->pvt_info; 213 pdata = pci->pvt_info;
213 pdata->name = "mpc85xx_pci_err"; 214 pdata->name = "mpc85xx_pci_err";
214 pdata->irq = NO_IRQ; 215 pdata->irq = NO_IRQ;
215 platform_set_drvdata(pdev, pci); 216 dev_set_drvdata(&op->dev, pci);
216 pci->dev = &pdev->dev; 217 pci->dev = &op->dev;
217 pci->mod_name = EDAC_MOD_STR; 218 pci->mod_name = EDAC_MOD_STR;
218 pci->ctl_name = pdata->name; 219 pci->ctl_name = pdata->name;
219 pci->dev_name = pdev->dev.bus_id; 220 pci->dev_name = op->dev.bus_id;
220 221
221 if (edac_op_state == EDAC_OPSTATE_POLL) 222 if (edac_op_state == EDAC_OPSTATE_POLL)
222 pci->edac_check = mpc85xx_pci_check; 223 pci->edac_check = mpc85xx_pci_check;
223 224
224 pdata->edac_idx = edac_pci_idx++; 225 pdata->edac_idx = edac_pci_idx++;
225 226
226 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 227 res = of_address_to_resource(op->node, 0, &r);
227 if (!r) { 228 if (res) {
228 printk(KERN_ERR "%s: Unable to get resource for " 229 printk(KERN_ERR "%s: Unable to get resource for "
229 "PCI err regs\n", __func__); 230 "PCI err regs\n", __func__);
230 goto err; 231 goto err;
231 } 232 }
232 233
233 if (!devm_request_mem_region(&pdev->dev, r->start, 234 /* we only need the error registers */
234 r->end - r->start + 1, pdata->name)) { 235 r.start += 0xe00;
236
237 if (!devm_request_mem_region(&op->dev, r.start,
238 r.end - r.start + 1, pdata->name)) {
235 printk(KERN_ERR "%s: Error while requesting mem region\n", 239 printk(KERN_ERR "%s: Error while requesting mem region\n",
236 __func__); 240 __func__);
237 res = -EBUSY; 241 res = -EBUSY;
238 goto err; 242 goto err;
239 } 243 }
240 244
241 pdata->pci_vbase = devm_ioremap(&pdev->dev, r->start, 245 pdata->pci_vbase = devm_ioremap(&op->dev, r.start,
242 r->end - r->start + 1); 246 r.end - r.start + 1);
243 if (!pdata->pci_vbase) { 247 if (!pdata->pci_vbase) {
244 printk(KERN_ERR "%s: Unable to setup PCI err regs\n", __func__); 248 printk(KERN_ERR "%s: Unable to setup PCI err regs\n", __func__);
245 res = -ENOMEM; 249 res = -ENOMEM;
@@ -266,14 +270,15 @@ static int __devinit mpc85xx_pci_err_probe(struct platform_device *pdev)
266 } 270 }
267 271
268 if (edac_op_state == EDAC_OPSTATE_INT) { 272 if (edac_op_state == EDAC_OPSTATE_INT) {
269 pdata->irq = platform_get_irq(pdev, 0); 273 pdata->irq = irq_of_parse_and_map(op->node, 0);
270 res = devm_request_irq(&pdev->dev, pdata->irq, 274 res = devm_request_irq(&op->dev, pdata->irq,
271 mpc85xx_pci_isr, IRQF_DISABLED, 275 mpc85xx_pci_isr, IRQF_DISABLED,
272 "[EDAC] PCI err", pci); 276 "[EDAC] PCI err", pci);
273 if (res < 0) { 277 if (res < 0) {
274 printk(KERN_ERR 278 printk(KERN_ERR
275 "%s: Unable to requiest irq %d for " 279 "%s: Unable to requiest irq %d for "
276 "MPC85xx PCI err\n", __func__, pdata->irq); 280 "MPC85xx PCI err\n", __func__, pdata->irq);
281 irq_dispose_mapping(pdata->irq);
277 res = -ENODEV; 282 res = -ENODEV;
278 goto err2; 283 goto err2;
279 } 284 }
@@ -282,23 +287,23 @@ static int __devinit mpc85xx_pci_err_probe(struct platform_device *pdev)
282 pdata->irq); 287 pdata->irq);
283 } 288 }
284 289
285 devres_remove_group(&pdev->dev, mpc85xx_pci_err_probe); 290 devres_remove_group(&op->dev, mpc85xx_pci_err_probe);
286 debugf3("%s(): success\n", __func__); 291 debugf3("%s(): success\n", __func__);
287 printk(KERN_INFO EDAC_MOD_STR " PCI err registered\n"); 292 printk(KERN_INFO EDAC_MOD_STR " PCI err registered\n");
288 293
289 return 0; 294 return 0;
290 295
291err2: 296err2:
292 edac_pci_del_device(&pdev->dev); 297 edac_pci_del_device(&op->dev);
293err: 298err:
294 edac_pci_free_ctl_info(pci); 299 edac_pci_free_ctl_info(pci);
295 devres_release_group(&pdev->dev, mpc85xx_pci_err_probe); 300 devres_release_group(&op->dev, mpc85xx_pci_err_probe);
296 return res; 301 return res;
297} 302}
298 303
299static int mpc85xx_pci_err_remove(struct platform_device *pdev) 304static int mpc85xx_pci_err_remove(struct of_device *op)
300{ 305{
301 struct edac_pci_ctl_info *pci = platform_get_drvdata(pdev); 306 struct edac_pci_ctl_info *pci = dev_get_drvdata(&op->dev);
302 struct mpc85xx_pci_pdata *pdata = pci->pvt_info; 307 struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
303 308
304 debugf0("%s()\n", __func__); 309 debugf0("%s()\n", __func__);
@@ -318,12 +323,26 @@ static int mpc85xx_pci_err_remove(struct platform_device *pdev)
318 return 0; 323 return 0;
319} 324}
320 325
321static struct platform_driver mpc85xx_pci_err_driver = { 326static struct of_device_id mpc85xx_pci_err_of_match[] = {
327 {
328 .compatible = "fsl,mpc8540-pcix",
329 },
330 {
331 .compatible = "fsl,mpc8540-pci",
332 },
333 {},
334};
335
336static struct of_platform_driver mpc85xx_pci_err_driver = {
337 .owner = THIS_MODULE,
338 .name = "mpc85xx_pci_err",
339 .match_table = mpc85xx_pci_err_of_match,
322 .probe = mpc85xx_pci_err_probe, 340 .probe = mpc85xx_pci_err_probe,
323 .remove = __devexit_p(mpc85xx_pci_err_remove), 341 .remove = __devexit_p(mpc85xx_pci_err_remove),
324 .driver = { 342 .driver = {
325 .name = "mpc85xx_pci_err", 343 .name = "mpc85xx_pci_err",
326 } 344 .owner = THIS_MODULE,
345 },
327}; 346};
328 347
329#endif /* CONFIG_PCI */ 348#endif /* CONFIG_PCI */
@@ -1002,7 +1021,7 @@ static int __init mpc85xx_mc_init(void)
1002 printk(KERN_WARNING EDAC_MOD_STR "L2 fails to register\n"); 1021 printk(KERN_WARNING EDAC_MOD_STR "L2 fails to register\n");
1003 1022
1004#ifdef CONFIG_PCI 1023#ifdef CONFIG_PCI
1005 res = platform_driver_register(&mpc85xx_pci_err_driver); 1024 res = of_register_platform_driver(&mpc85xx_pci_err_driver);
1006 if (res) 1025 if (res)
1007 printk(KERN_WARNING EDAC_MOD_STR "PCI fails to register\n"); 1026 printk(KERN_WARNING EDAC_MOD_STR "PCI fails to register\n");
1008#endif 1027#endif
@@ -1025,7 +1044,7 @@ static void __exit mpc85xx_mc_exit(void)
1025{ 1044{
1026 mtspr(SPRN_HID1, orig_hid1); 1045 mtspr(SPRN_HID1, orig_hid1);
1027#ifdef CONFIG_PCI 1046#ifdef CONFIG_PCI
1028 platform_driver_unregister(&mpc85xx_pci_err_driver); 1047 of_unregister_platform_driver(&mpc85xx_pci_err_driver);
1029#endif 1048#endif
1030 of_unregister_platform_driver(&mpc85xx_l2_err_driver); 1049 of_unregister_platform_driver(&mpc85xx_l2_err_driver);
1031 of_unregister_platform_driver(&mpc85xx_mc_err_driver); 1050 of_unregister_platform_driver(&mpc85xx_mc_err_driver);
diff --git a/drivers/edac/mv64x60_edac.c b/drivers/edac/mv64x60_edac.c
index bf071f140a05..083ce8d0c63d 100644
--- a/drivers/edac/mv64x60_edac.c
+++ b/drivers/edac/mv64x60_edac.c
@@ -71,6 +71,35 @@ static irqreturn_t mv64x60_pci_isr(int irq, void *dev_id)
71 return IRQ_HANDLED; 71 return IRQ_HANDLED;
72} 72}
73 73
74/*
75 * Bit 0 of MV64x60_PCIx_ERR_MASK does not exist on the 64360 and because of
76 * errata FEr-#11 and FEr-##16 for the 64460, it should be 0 on that chip as
77 * well. IOW, don't set bit 0.
78 */
79
80/* Erratum FEr PCI-#16: clear bit 0 of PCI SERRn Mask reg. */
81static int __init mv64x60_pci_fixup(struct platform_device *pdev)
82{
83 struct resource *r;
84 void __iomem *pci_serr;
85
86 r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
87 if (!r) {
88 printk(KERN_ERR "%s: Unable to get resource for "
89 "PCI err regs\n", __func__);
90 return -ENOENT;
91 }
92
93 pci_serr = ioremap(r->start, r->end - r->start + 1);
94 if (!pci_serr)
95 return -ENOMEM;
96
97 out_le32(pci_serr, in_le32(pci_serr) & ~0x1);
98 iounmap(pci_serr);
99
100 return 0;
101}
102
74static int __devinit mv64x60_pci_err_probe(struct platform_device *pdev) 103static int __devinit mv64x60_pci_err_probe(struct platform_device *pdev)
75{ 104{
76 struct edac_pci_ctl_info *pci; 105 struct edac_pci_ctl_info *pci;
@@ -128,6 +157,12 @@ static int __devinit mv64x60_pci_err_probe(struct platform_device *pdev)
128 goto err; 157 goto err;
129 } 158 }
130 159
160 res = mv64x60_pci_fixup(pdev);
161 if (res < 0) {
162 printk(KERN_ERR "%s: PCI fixup failed\n", __func__);
163 goto err;
164 }
165
131 out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE, 0); 166 out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE, 0);
132 out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_MASK, 0); 167 out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_MASK, 0);
133 out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_MASK, 168 out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_MASK,
@@ -612,7 +647,7 @@ static void get_total_mem(struct mv64x60_mc_pdata *pdata)
612 if (!np) 647 if (!np)
613 return; 648 return;
614 649
615 reg = get_property(np, "reg", NULL); 650 reg = of_get_property(np, "reg", NULL);
616 651
617 pdata->total_mem = reg[1]; 652 pdata->total_mem = reg[1];
618} 653}
diff --git a/drivers/firewire/fw-iso.c b/drivers/firewire/fw-iso.c
index bcbe794a3ea5..e14c03dc0065 100644
--- a/drivers/firewire/fw-iso.c
+++ b/drivers/firewire/fw-iso.c
@@ -50,7 +50,7 @@ fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
50 50
51 address = dma_map_page(card->device, buffer->pages[i], 51 address = dma_map_page(card->device, buffer->pages[i],
52 0, PAGE_SIZE, direction); 52 0, PAGE_SIZE, direction);
53 if (dma_mapping_error(address)) { 53 if (dma_mapping_error(card->device, address)) {
54 __free_page(buffer->pages[i]); 54 __free_page(buffer->pages[i]);
55 goto out_pages; 55 goto out_pages;
56 } 56 }
diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/fw-ohci.c
index 333b12544dd1..566672e0bcff 100644
--- a/drivers/firewire/fw-ohci.c
+++ b/drivers/firewire/fw-ohci.c
@@ -953,7 +953,7 @@ at_context_queue_packet(struct context *ctx, struct fw_packet *packet)
953 payload_bus = 953 payload_bus =
954 dma_map_single(ohci->card.device, packet->payload, 954 dma_map_single(ohci->card.device, packet->payload,
955 packet->payload_length, DMA_TO_DEVICE); 955 packet->payload_length, DMA_TO_DEVICE);
956 if (dma_mapping_error(payload_bus)) { 956 if (dma_mapping_error(ohci->card.device, payload_bus)) {
957 packet->ack = RCODE_SEND_ERROR; 957 packet->ack = RCODE_SEND_ERROR;
958 return -1; 958 return -1;
959 } 959 }
diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c
index 53fc5a641e6d..aaff50ebba1d 100644
--- a/drivers/firewire/fw-sbp2.c
+++ b/drivers/firewire/fw-sbp2.c
@@ -543,7 +543,7 @@ sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
543 orb->response_bus = 543 orb->response_bus =
544 dma_map_single(device->card->device, &orb->response, 544 dma_map_single(device->card->device, &orb->response,
545 sizeof(orb->response), DMA_FROM_DEVICE); 545 sizeof(orb->response), DMA_FROM_DEVICE);
546 if (dma_mapping_error(orb->response_bus)) 546 if (dma_mapping_error(device->card->device, orb->response_bus))
547 goto fail_mapping_response; 547 goto fail_mapping_response;
548 548
549 orb->request.response.high = 0; 549 orb->request.response.high = 0;
@@ -577,7 +577,7 @@ sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
577 orb->base.request_bus = 577 orb->base.request_bus =
578 dma_map_single(device->card->device, &orb->request, 578 dma_map_single(device->card->device, &orb->request,
579 sizeof(orb->request), DMA_TO_DEVICE); 579 sizeof(orb->request), DMA_TO_DEVICE);
580 if (dma_mapping_error(orb->base.request_bus)) 580 if (dma_mapping_error(device->card->device, orb->base.request_bus))
581 goto fail_mapping_request; 581 goto fail_mapping_request;
582 582
583 sbp2_send_orb(&orb->base, lu, node_id, generation, 583 sbp2_send_orb(&orb->base, lu, node_id, generation,
@@ -1424,7 +1424,7 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device,
1424 orb->page_table_bus = 1424 orb->page_table_bus =
1425 dma_map_single(device->card->device, orb->page_table, 1425 dma_map_single(device->card->device, orb->page_table,
1426 sizeof(orb->page_table), DMA_TO_DEVICE); 1426 sizeof(orb->page_table), DMA_TO_DEVICE);
1427 if (dma_mapping_error(orb->page_table_bus)) 1427 if (dma_mapping_error(device->card->device, orb->page_table_bus))
1428 goto fail_page_table; 1428 goto fail_page_table;
1429 1429
1430 /* 1430 /*
@@ -1509,7 +1509,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1509 orb->base.request_bus = 1509 orb->base.request_bus =
1510 dma_map_single(device->card->device, &orb->request, 1510 dma_map_single(device->card->device, &orb->request,
1511 sizeof(orb->request), DMA_TO_DEVICE); 1511 sizeof(orb->request), DMA_TO_DEVICE);
1512 if (dma_mapping_error(orb->base.request_bus)) 1512 if (dma_mapping_error(device->card->device, orb->base.request_bus))
1513 goto out; 1513 goto out;
1514 1514
1515 sbp2_send_orb(&orb->base, lu, lu->tgt->node_id, lu->generation, 1515 sbp2_send_orb(&orb->base, lu, lu->tgt->node_id, lu->generation,
diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c
index 25918f7dfd0f..c66817e7717b 100644
--- a/drivers/firmware/dcdbas.c
+++ b/drivers/firmware/dcdbas.c
@@ -152,20 +152,11 @@ static ssize_t smi_data_read(struct kobject *kobj,
152 struct bin_attribute *bin_attr, 152 struct bin_attribute *bin_attr,
153 char *buf, loff_t pos, size_t count) 153 char *buf, loff_t pos, size_t count)
154{ 154{
155 size_t max_read;
156 ssize_t ret; 155 ssize_t ret;
157 156
158 mutex_lock(&smi_data_lock); 157 mutex_lock(&smi_data_lock);
159 158 ret = memory_read_from_buffer(buf, count, &pos, smi_data_buf,
160 if (pos >= smi_data_buf_size) { 159 smi_data_buf_size);
161 ret = 0;
162 goto out;
163 }
164
165 max_read = smi_data_buf_size - pos;
166 ret = min(max_read, count);
167 memcpy(buf, smi_data_buf + pos, ret);
168out:
169 mutex_unlock(&smi_data_lock); 160 mutex_unlock(&smi_data_lock);
170 return ret; 161 return ret;
171} 162}
@@ -254,6 +245,7 @@ static ssize_t host_control_on_shutdown_store(struct device *dev,
254static int smi_request(struct smi_cmd *smi_cmd) 245static int smi_request(struct smi_cmd *smi_cmd)
255{ 246{
256 cpumask_t old_mask; 247 cpumask_t old_mask;
248 cpumask_of_cpu_ptr(new_mask, 0);
257 int ret = 0; 249 int ret = 0;
258 250
259 if (smi_cmd->magic != SMI_CMD_MAGIC) { 251 if (smi_cmd->magic != SMI_CMD_MAGIC) {
@@ -264,7 +256,7 @@ static int smi_request(struct smi_cmd *smi_cmd)
264 256
265 /* SMI requires CPU 0 */ 257 /* SMI requires CPU 0 */
266 old_mask = current->cpus_allowed; 258 old_mask = current->cpus_allowed;
267 set_cpus_allowed_ptr(current, &cpumask_of_cpu(0)); 259 set_cpus_allowed_ptr(current, new_mask);
268 if (smp_processor_id() != 0) { 260 if (smp_processor_id() != 0) {
269 dev_dbg(&dcdbas_pdev->dev, "%s: failed to get CPU 0\n", 261 dev_dbg(&dcdbas_pdev->dev, "%s: failed to get CPU 0\n",
270 __func__); 262 __func__);
diff --git a/drivers/firmware/dell_rbu.c b/drivers/firmware/dell_rbu.c
index 7430e218cda6..13946ebd77d6 100644
--- a/drivers/firmware/dell_rbu.c
+++ b/drivers/firmware/dell_rbu.c
@@ -507,11 +507,6 @@ static ssize_t read_packet_data(char *buffer, loff_t pos, size_t count)
507 507
508static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count) 508static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count)
509{ 509{
510 unsigned char *ptemp = NULL;
511 size_t bytes_left = 0;
512 size_t data_length = 0;
513 ssize_t ret_count = 0;
514
515 /* check to see if we have something to return */ 510 /* check to see if we have something to return */
516 if ((rbu_data.image_update_buffer == NULL) || 511 if ((rbu_data.image_update_buffer == NULL) ||
517 (rbu_data.bios_image_size == 0)) { 512 (rbu_data.bios_image_size == 0)) {
@@ -519,28 +514,11 @@ static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count)
519 "bios_image_size %lu\n", 514 "bios_image_size %lu\n",
520 rbu_data.image_update_buffer, 515 rbu_data.image_update_buffer,
521 rbu_data.bios_image_size); 516 rbu_data.bios_image_size);
522 ret_count = -ENOMEM; 517 return -ENOMEM;
523 goto read_rbu_data_exit;
524 }
525
526 if (pos > rbu_data.bios_image_size) {
527 ret_count = 0;
528 goto read_rbu_data_exit;
529 } 518 }
530 519
531 bytes_left = rbu_data.bios_image_size - pos; 520 return memory_read_from_buffer(buffer, count, &pos,
532 data_length = min(bytes_left, count); 521 rbu_data.image_update_buffer, rbu_data.bios_image_size);
533
534 ptemp = rbu_data.image_update_buffer;
535 memcpy(buffer, (ptemp + pos), data_length);
536
537 if ((pos + count) > rbu_data.bios_image_size)
538 /* this was the last copy */
539 ret_count = bytes_left;
540 else
541 ret_count = count;
542 read_rbu_data_exit:
543 return ret_count;
544} 522}
545 523
546static ssize_t read_rbu_data(struct kobject *kobj, 524static ssize_t read_rbu_data(struct kobject *kobj,
diff --git a/drivers/firmware/memmap.c b/drivers/firmware/memmap.c
index e23399c7f773..001622eb86f9 100644
--- a/drivers/firmware/memmap.c
+++ b/drivers/firmware/memmap.c
@@ -153,12 +153,14 @@ int __init firmware_map_add_early(resource_size_t start, resource_size_t end,
153 153
154static ssize_t start_show(struct firmware_map_entry *entry, char *buf) 154static ssize_t start_show(struct firmware_map_entry *entry, char *buf)
155{ 155{
156 return snprintf(buf, PAGE_SIZE, "0x%llx\n", entry->start); 156 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
157 (unsigned long long)entry->start);
157} 158}
158 159
159static ssize_t end_show(struct firmware_map_entry *entry, char *buf) 160static ssize_t end_show(struct firmware_map_entry *entry, char *buf)
160{ 161{
161 return snprintf(buf, PAGE_SIZE, "0x%llx\n", entry->end); 162 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
163 (unsigned long long)entry->end);
162} 164}
163 165
164static ssize_t type_show(struct firmware_map_entry *entry, char *buf) 166static ssize_t type_show(struct firmware_map_entry *entry, char *buf)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index fced1909cbba..dbd42d6c93a7 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -2,15 +2,40 @@
2# GPIO infrastructure and expanders 2# GPIO infrastructure and expanders
3# 3#
4 4
5config HAVE_GPIO_LIB 5config ARCH_WANT_OPTIONAL_GPIOLIB
6 bool 6 bool
7 help 7 help
8 Select this config option from the architecture Kconfig, if
9 it is possible to use gpiolib on the architecture, but let the
10 user decide whether to actually build it or not.
11 Select this instead of ARCH_REQUIRE_GPIOLIB, if your architecture does
12 not depend on GPIOs being available, but rather let the user
13 decide whether he needs it or not.
14
15config ARCH_REQUIRE_GPIOLIB
16 bool
17 select GPIOLIB
18 help
8 Platforms select gpiolib if they use this infrastructure 19 Platforms select gpiolib if they use this infrastructure
9 for all their GPIOs, usually starting with ones integrated 20 for all their GPIOs, usually starting with ones integrated
10 into SOC processors. 21 into SOC processors.
22 Selecting this from the architecture code will cause the gpiolib
23 code to always get built in.
24
25
26
27menuconfig GPIOLIB
28 bool "GPIO Support"
29 depends on ARCH_WANT_OPTIONAL_GPIOLIB || ARCH_REQUIRE_GPIOLIB
30 select GENERIC_GPIO
31 help
32 This enables GPIO support through the generic GPIO library.
33 You only need to enable this, if you also want to enable
34 one or more of the GPIO expansion card drivers below.
11 35
12menu "GPIO Support" 36 If unsure, say N.
13 depends on HAVE_GPIO_LIB 37
38if GPIOLIB
14 39
15config DEBUG_GPIO 40config DEBUG_GPIO
16 bool "Debug GPIO calls" 41 bool "Debug GPIO calls"
@@ -23,10 +48,44 @@ config DEBUG_GPIO
23 slower. The diagnostics help catch the type of setup errors 48 slower. The diagnostics help catch the type of setup errors
24 that are most common when setting up new platforms or boards. 49 that are most common when setting up new platforms or boards.
25 50
51config GPIO_SYSFS
52 bool "/sys/class/gpio/... (sysfs interface)"
53 depends on SYSFS && EXPERIMENTAL
54 help
55 Say Y here to add a sysfs interface for GPIOs.
56
57 This is mostly useful to work around omissions in a system's
58 kernel support. Those are common in custom and semicustom
59 hardware assembled using standard kernels with a minimum of
60 custom patches. In those cases, userspace code may import
61 a given GPIO from the kernel, if no kernel driver requested it.
62
63 Kernel drivers may also request that a particular GPIO be
64 exported to userspace; this can be useful when debugging.
65
26# put expanders in the right section, in alphabetical order 66# put expanders in the right section, in alphabetical order
27 67
28comment "I2C GPIO expanders:" 68comment "I2C GPIO expanders:"
29 69
70config GPIO_MAX732X
71 tristate "MAX7319, MAX7320-7327 I2C Port Expanders"
72 depends on I2C
73 help
74 Say yes here to support the MAX7319, MAX7320-7327 series of I2C
75 Port Expanders. Each IO port on these chips has a fixed role of
76 Input (designated by 'I'), Push-Pull Output ('O'), or Open-Drain
77 Input and Output (designed by 'P'). The combinations are listed
78 below:
79
80 8 bits: max7319 (8I), max7320 (8O), max7321 (8P),
81 max7322 (4I4O), max7323 (4P4O)
82
83 16 bits: max7324 (8I8O), max7325 (8P8O),
84 max7326 (4I12O), max7327 (4P12O)
85
86 Board setup code must specify the model to use, and the start
87 number for these GPIOs.
88
30config GPIO_PCA953X 89config GPIO_PCA953X
31 tristate "PCA953x, PCA955x, and MAX7310 I/O ports" 90 tristate "PCA953x, PCA955x, and MAX7310 I/O ports"
32 depends on I2C 91 depends on I2C
@@ -68,6 +127,24 @@ config GPIO_PCF857X
68 This driver provides an in-kernel interface to those GPIOs using 127 This driver provides an in-kernel interface to those GPIOs using
69 platform-neutral GPIO calls. 128 platform-neutral GPIO calls.
70 129
130comment "PCI GPIO expanders:"
131
132config GPIO_BT8XX
133 tristate "BT8XX GPIO abuser"
134 depends on PCI && VIDEO_BT848=n
135 help
136 The BT8xx frame grabber chip has 24 GPIO pins than can be abused
137 as a cheap PCI GPIO card.
138
139 This chip can be found on Miro, Hauppauge and STB TV-cards.
140
141 The card needs to be physically altered for using it as a
142 GPIO card. For more information on how to build a GPIO card
143 from a BT8xx TV card, see the documentation file at
144 Documentation/bt8xxgpio.txt
145
146 If unsure, say N.
147
71comment "SPI GPIO expanders:" 148comment "SPI GPIO expanders:"
72 149
73config GPIO_MAX7301 150config GPIO_MAX7301
@@ -83,4 +160,4 @@ config GPIO_MCP23S08
83 SPI driver for Microchip MCP23S08 I/O expander. This provides 160 SPI driver for Microchip MCP23S08 I/O expander. This provides
84 a GPIO interface supporting inputs and outputs. 161 a GPIO interface supporting inputs and outputs.
85 162
86endmenu 163endif
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 16e796dc5410..01b4bbde1956 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -2,9 +2,11 @@
2 2
3ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG 3ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG
4 4
5obj-$(CONFIG_HAVE_GPIO_LIB) += gpiolib.o 5obj-$(CONFIG_GPIOLIB) += gpiolib.o
6 6
7obj-$(CONFIG_GPIO_MAX7301) += max7301.o 7obj-$(CONFIG_GPIO_MAX7301) += max7301.o
8obj-$(CONFIG_GPIO_MAX732X) += max732x.o
8obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o 9obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
9obj-$(CONFIG_GPIO_PCA953X) += pca953x.o 10obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
10obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o 11obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
12obj-$(CONFIG_GPIO_BT8XX) += bt8xxgpio.o
diff --git a/drivers/gpio/bt8xxgpio.c b/drivers/gpio/bt8xxgpio.c
new file mode 100644
index 000000000000..7a1168249dd5
--- /dev/null
+++ b/drivers/gpio/bt8xxgpio.c
@@ -0,0 +1,348 @@
1/*
2
3 bt8xx GPIO abuser
4
5 Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
6
7 Please do _only_ contact the people listed _above_ with issues related to this driver.
8 All the other people listed below are not related to this driver. Their names
9 are only here, because this driver is derived from the bt848 driver.
10
11
12 Derived from the bt848 driver:
13
14 Copyright (C) 1996,97,98 Ralph Metzler
15 & Marcus Metzler
16 (c) 1999-2002 Gerd Knorr
17
18 some v4l2 code lines are taken from Justin's bttv2 driver which is
19 (c) 2000 Justin Schoeman
20
21 V4L1 removal from:
22 (c) 2005-2006 Nickolay V. Shmyrev
23
24 Fixes to be fully V4L2 compliant by
25 (c) 2006 Mauro Carvalho Chehab
26
27 Cropping and overscan support
28 Copyright (C) 2005, 2006 Michael H. Schimek
29 Sponsored by OPQ Systems AB
30
31 This program is free software; you can redistribute it and/or modify
32 it under the terms of the GNU General Public License as published by
33 the Free Software Foundation; either version 2 of the License, or
34 (at your option) any later version.
35
36 This program is distributed in the hope that it will be useful,
37 but WITHOUT ANY WARRANTY; without even the implied warranty of
38 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 GNU General Public License for more details.
40
41 You should have received a copy of the GNU General Public License
42 along with this program; if not, write to the Free Software
43 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
44*/
45
46#include <linux/module.h>
47#include <linux/pci.h>
48#include <linux/spinlock.h>
49
50#include <asm/gpio.h>
51
52/* Steal the hardware definitions from the bttv driver. */
53#include "../media/video/bt8xx/bt848.h"
54
55
56#define BT8XXGPIO_NR_GPIOS 24 /* We have 24 GPIO pins */
57
58
59struct bt8xxgpio {
60 spinlock_t lock;
61
62 void __iomem *mmio;
63 struct pci_dev *pdev;
64 struct gpio_chip gpio;
65
66#ifdef CONFIG_PM
67 u32 saved_outen;
68 u32 saved_data;
69#endif
70};
71
72#define bgwrite(dat, adr) writel((dat), bg->mmio+(adr))
73#define bgread(adr) readl(bg->mmio+(adr))
74
75
76static int modparam_gpiobase = -1/* dynamic */;
77module_param_named(gpiobase, modparam_gpiobase, int, 0444);
78MODULE_PARM_DESC(gpiobase, "The GPIO number base. -1 means dynamic, which is the default.");
79
80
81static int bt8xxgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
82{
83 struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio);
84 unsigned long flags;
85 u32 outen, data;
86
87 spin_lock_irqsave(&bg->lock, flags);
88
89 data = bgread(BT848_GPIO_DATA);
90 data &= ~(1 << nr);
91 bgwrite(data, BT848_GPIO_DATA);
92
93 outen = bgread(BT848_GPIO_OUT_EN);
94 outen &= ~(1 << nr);
95 bgwrite(outen, BT848_GPIO_OUT_EN);
96
97 spin_unlock_irqrestore(&bg->lock, flags);
98
99 return 0;
100}
101
102static int bt8xxgpio_gpio_get(struct gpio_chip *gpio, unsigned nr)
103{
104 struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio);
105 unsigned long flags;
106 u32 val;
107
108 spin_lock_irqsave(&bg->lock, flags);
109 val = bgread(BT848_GPIO_DATA);
110 spin_unlock_irqrestore(&bg->lock, flags);
111
112 return !!(val & (1 << nr));
113}
114
115static int bt8xxgpio_gpio_direction_output(struct gpio_chip *gpio,
116 unsigned nr, int val)
117{
118 struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio);
119 unsigned long flags;
120 u32 outen, data;
121
122 spin_lock_irqsave(&bg->lock, flags);
123
124 outen = bgread(BT848_GPIO_OUT_EN);
125 outen |= (1 << nr);
126 bgwrite(outen, BT848_GPIO_OUT_EN);
127
128 data = bgread(BT848_GPIO_DATA);
129 if (val)
130 data |= (1 << nr);
131 else
132 data &= ~(1 << nr);
133 bgwrite(data, BT848_GPIO_DATA);
134
135 spin_unlock_irqrestore(&bg->lock, flags);
136
137 return 0;
138}
139
140static void bt8xxgpio_gpio_set(struct gpio_chip *gpio,
141 unsigned nr, int val)
142{
143 struct bt8xxgpio *bg = container_of(gpio, struct bt8xxgpio, gpio);
144 unsigned long flags;
145 u32 data;
146
147 spin_lock_irqsave(&bg->lock, flags);
148
149 data = bgread(BT848_GPIO_DATA);
150 if (val)
151 data |= (1 << nr);
152 else
153 data &= ~(1 << nr);
154 bgwrite(data, BT848_GPIO_DATA);
155
156 spin_unlock_irqrestore(&bg->lock, flags);
157}
158
159static void bt8xxgpio_gpio_setup(struct bt8xxgpio *bg)
160{
161 struct gpio_chip *c = &bg->gpio;
162
163 c->label = bg->pdev->dev.bus_id;
164 c->owner = THIS_MODULE;
165 c->direction_input = bt8xxgpio_gpio_direction_input;
166 c->get = bt8xxgpio_gpio_get;
167 c->direction_output = bt8xxgpio_gpio_direction_output;
168 c->set = bt8xxgpio_gpio_set;
169 c->dbg_show = NULL;
170 c->base = modparam_gpiobase;
171 c->ngpio = BT8XXGPIO_NR_GPIOS;
172 c->can_sleep = 0;
173}
174
175static int bt8xxgpio_probe(struct pci_dev *dev,
176 const struct pci_device_id *pci_id)
177{
178 struct bt8xxgpio *bg;
179 int err;
180
181 bg = kzalloc(sizeof(*bg), GFP_KERNEL);
182 if (!bg)
183 return -ENOMEM;
184
185 bg->pdev = dev;
186 spin_lock_init(&bg->lock);
187
188 err = pci_enable_device(dev);
189 if (err) {
190 printk(KERN_ERR "bt8xxgpio: Can't enable device.\n");
191 goto err_freebg;
192 }
193 if (!request_mem_region(pci_resource_start(dev, 0),
194 pci_resource_len(dev, 0),
195 "bt8xxgpio")) {
196 printk(KERN_WARNING "bt8xxgpio: Can't request iomem (0x%llx).\n",
197 (unsigned long long)pci_resource_start(dev, 0));
198 err = -EBUSY;
199 goto err_disable;
200 }
201 pci_set_master(dev);
202 pci_set_drvdata(dev, bg);
203
204 bg->mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
205 if (!bg->mmio) {
206 printk(KERN_ERR "bt8xxgpio: ioremap() failed\n");
207 err = -EIO;
208 goto err_release_mem;
209 }
210
211 /* Disable interrupts */
212 bgwrite(0, BT848_INT_MASK);
213
214 /* gpio init */
215 bgwrite(0, BT848_GPIO_DMA_CTL);
216 bgwrite(0, BT848_GPIO_REG_INP);
217 bgwrite(0, BT848_GPIO_OUT_EN);
218
219 bt8xxgpio_gpio_setup(bg);
220 err = gpiochip_add(&bg->gpio);
221 if (err) {
222 printk(KERN_ERR "bt8xxgpio: Failed to register GPIOs\n");
223 goto err_release_mem;
224 }
225
226 printk(KERN_INFO "bt8xxgpio: Abusing BT8xx card for GPIOs %d to %d\n",
227 bg->gpio.base, bg->gpio.base + BT8XXGPIO_NR_GPIOS - 1);
228
229 return 0;
230
231err_release_mem:
232 release_mem_region(pci_resource_start(dev, 0),
233 pci_resource_len(dev, 0));
234 pci_set_drvdata(dev, NULL);
235err_disable:
236 pci_disable_device(dev);
237err_freebg:
238 kfree(bg);
239
240 return err;
241}
242
243static void bt8xxgpio_remove(struct pci_dev *pdev)
244{
245 struct bt8xxgpio *bg = pci_get_drvdata(pdev);
246
247 gpiochip_remove(&bg->gpio);
248
249 bgwrite(0, BT848_INT_MASK);
250 bgwrite(~0x0, BT848_INT_STAT);
251 bgwrite(0x0, BT848_GPIO_OUT_EN);
252
253 iounmap(bg->mmio);
254 release_mem_region(pci_resource_start(pdev, 0),
255 pci_resource_len(pdev, 0));
256 pci_disable_device(pdev);
257
258 pci_set_drvdata(pdev, NULL);
259 kfree(bg);
260}
261
262#ifdef CONFIG_PM
263static int bt8xxgpio_suspend(struct pci_dev *pdev, pm_message_t state)
264{
265 struct bt8xxgpio *bg = pci_get_drvdata(pdev);
266 unsigned long flags;
267
268 spin_lock_irqsave(&bg->lock, flags);
269
270 bg->saved_outen = bgread(BT848_GPIO_OUT_EN);
271 bg->saved_data = bgread(BT848_GPIO_DATA);
272
273 bgwrite(0, BT848_INT_MASK);
274 bgwrite(~0x0, BT848_INT_STAT);
275 bgwrite(0x0, BT848_GPIO_OUT_EN);
276
277 spin_unlock_irqrestore(&bg->lock, flags);
278
279 pci_save_state(pdev);
280 pci_disable_device(pdev);
281 pci_set_power_state(pdev, pci_choose_state(pdev, state));
282
283 return 0;
284}
285
286static int bt8xxgpio_resume(struct pci_dev *pdev)
287{
288 struct bt8xxgpio *bg = pci_get_drvdata(pdev);
289 unsigned long flags;
290 int err;
291
292 pci_set_power_state(pdev, 0);
293 err = pci_enable_device(pdev);
294 if (err)
295 return err;
296 pci_restore_state(pdev);
297
298 spin_lock_irqsave(&bg->lock, flags);
299
300 bgwrite(0, BT848_INT_MASK);
301 bgwrite(0, BT848_GPIO_DMA_CTL);
302 bgwrite(0, BT848_GPIO_REG_INP);
303 bgwrite(bg->saved_outen, BT848_GPIO_OUT_EN);
304 bgwrite(bg->saved_data & bg->saved_outen,
305 BT848_GPIO_DATA);
306
307 spin_unlock_irqrestore(&bg->lock, flags);
308
309 return 0;
310}
311#else
312#define bt8xxgpio_suspend NULL
313#define bt8xxgpio_resume NULL
314#endif /* CONFIG_PM */
315
316static struct pci_device_id bt8xxgpio_pci_tbl[] = {
317 { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848) },
318 { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT849) },
319 { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT878) },
320 { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT879) },
321 { 0, },
322};
323MODULE_DEVICE_TABLE(pci, bt8xxgpio_pci_tbl);
324
325static struct pci_driver bt8xxgpio_pci_driver = {
326 .name = "bt8xxgpio",
327 .id_table = bt8xxgpio_pci_tbl,
328 .probe = bt8xxgpio_probe,
329 .remove = bt8xxgpio_remove,
330 .suspend = bt8xxgpio_suspend,
331 .resume = bt8xxgpio_resume,
332};
333
334static int bt8xxgpio_init(void)
335{
336 return pci_register_driver(&bt8xxgpio_pci_driver);
337}
338module_init(bt8xxgpio_init)
339
340static void bt8xxgpio_exit(void)
341{
342 pci_unregister_driver(&bt8xxgpio_pci_driver);
343}
344module_exit(bt8xxgpio_exit)
345
346MODULE_LICENSE("GPL");
347MODULE_AUTHOR("Michael Buesch");
348MODULE_DESCRIPTION("Abuse a BT8xx framegrabber card as generic GPIO card");
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index beaf6b3a37dc..8d2940517c99 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2,8 +2,11 @@
2#include <linux/module.h> 2#include <linux/module.h>
3#include <linux/irq.h> 3#include <linux/irq.h>
4#include <linux/spinlock.h> 4#include <linux/spinlock.h>
5 5#include <linux/device.h>
6#include <asm/gpio.h> 6#include <linux/err.h>
7#include <linux/debugfs.h>
8#include <linux/seq_file.h>
9#include <linux/gpio.h>
7 10
8 11
9/* Optional implementation infrastructure for GPIO interfaces. 12/* Optional implementation infrastructure for GPIO interfaces.
@@ -44,6 +47,8 @@ struct gpio_desc {
44#define FLAG_REQUESTED 0 47#define FLAG_REQUESTED 0
45#define FLAG_IS_OUT 1 48#define FLAG_IS_OUT 1
46#define FLAG_RESERVED 2 49#define FLAG_RESERVED 2
50#define FLAG_EXPORT 3 /* protected by sysfs_lock */
51#define FLAG_SYSFS 4 /* exported via /sys/class/gpio/control */
47 52
48#ifdef CONFIG_DEBUG_FS 53#ifdef CONFIG_DEBUG_FS
49 const char *label; 54 const char *label;
@@ -151,6 +156,482 @@ err:
151 return ret; 156 return ret;
152} 157}
153 158
159#ifdef CONFIG_GPIO_SYSFS
160
161/* lock protects against unexport_gpio() being called while
162 * sysfs files are active.
163 */
164static DEFINE_MUTEX(sysfs_lock);
165
166/*
167 * /sys/class/gpio/gpioN... only for GPIOs that are exported
168 * /direction
169 * * MAY BE OMITTED if kernel won't allow direction changes
170 * * is read/write as "in" or "out"
171 * * may also be written as "high" or "low", initializing
172 * output value as specified ("out" implies "low")
173 * /value
174 * * always readable, subject to hardware behavior
175 * * may be writable, as zero/nonzero
176 *
177 * REVISIT there will likely be an attribute for configuring async
178 * notifications, e.g. to specify polling interval or IRQ trigger type
179 * that would for example trigger a poll() on the "value".
180 */
181
182static ssize_t gpio_direction_show(struct device *dev,
183 struct device_attribute *attr, char *buf)
184{
185 const struct gpio_desc *desc = dev_get_drvdata(dev);
186 ssize_t status;
187
188 mutex_lock(&sysfs_lock);
189
190 if (!test_bit(FLAG_EXPORT, &desc->flags))
191 status = -EIO;
192 else
193 status = sprintf(buf, "%s\n",
194 test_bit(FLAG_IS_OUT, &desc->flags)
195 ? "out" : "in");
196
197 mutex_unlock(&sysfs_lock);
198 return status;
199}
200
201static ssize_t gpio_direction_store(struct device *dev,
202 struct device_attribute *attr, const char *buf, size_t size)
203{
204 const struct gpio_desc *desc = dev_get_drvdata(dev);
205 unsigned gpio = desc - gpio_desc;
206 ssize_t status;
207
208 mutex_lock(&sysfs_lock);
209
210 if (!test_bit(FLAG_EXPORT, &desc->flags))
211 status = -EIO;
212 else if (sysfs_streq(buf, "high"))
213 status = gpio_direction_output(gpio, 1);
214 else if (sysfs_streq(buf, "out") || sysfs_streq(buf, "low"))
215 status = gpio_direction_output(gpio, 0);
216 else if (sysfs_streq(buf, "in"))
217 status = gpio_direction_input(gpio);
218 else
219 status = -EINVAL;
220
221 mutex_unlock(&sysfs_lock);
222 return status ? : size;
223}
224
225static const DEVICE_ATTR(direction, 0644,
226 gpio_direction_show, gpio_direction_store);
227
228static ssize_t gpio_value_show(struct device *dev,
229 struct device_attribute *attr, char *buf)
230{
231 const struct gpio_desc *desc = dev_get_drvdata(dev);
232 unsigned gpio = desc - gpio_desc;
233 ssize_t status;
234
235 mutex_lock(&sysfs_lock);
236
237 if (!test_bit(FLAG_EXPORT, &desc->flags))
238 status = -EIO;
239 else
240 status = sprintf(buf, "%d\n", gpio_get_value_cansleep(gpio));
241
242 mutex_unlock(&sysfs_lock);
243 return status;
244}
245
246static ssize_t gpio_value_store(struct device *dev,
247 struct device_attribute *attr, const char *buf, size_t size)
248{
249 const struct gpio_desc *desc = dev_get_drvdata(dev);
250 unsigned gpio = desc - gpio_desc;
251 ssize_t status;
252
253 mutex_lock(&sysfs_lock);
254
255 if (!test_bit(FLAG_EXPORT, &desc->flags))
256 status = -EIO;
257 else if (!test_bit(FLAG_IS_OUT, &desc->flags))
258 status = -EPERM;
259 else {
260 long value;
261
262 status = strict_strtol(buf, 0, &value);
263 if (status == 0) {
264 gpio_set_value_cansleep(gpio, value != 0);
265 status = size;
266 }
267 }
268
269 mutex_unlock(&sysfs_lock);
270 return status;
271}
272
273static /*const*/ DEVICE_ATTR(value, 0644,
274 gpio_value_show, gpio_value_store);
275
276static const struct attribute *gpio_attrs[] = {
277 &dev_attr_direction.attr,
278 &dev_attr_value.attr,
279 NULL,
280};
281
282static const struct attribute_group gpio_attr_group = {
283 .attrs = (struct attribute **) gpio_attrs,
284};
285
286/*
287 * /sys/class/gpio/gpiochipN/
288 * /base ... matching gpio_chip.base (N)
289 * /label ... matching gpio_chip.label
290 * /ngpio ... matching gpio_chip.ngpio
291 */
292
293static ssize_t chip_base_show(struct device *dev,
294 struct device_attribute *attr, char *buf)
295{
296 const struct gpio_chip *chip = dev_get_drvdata(dev);
297
298 return sprintf(buf, "%d\n", chip->base);
299}
300static DEVICE_ATTR(base, 0444, chip_base_show, NULL);
301
302static ssize_t chip_label_show(struct device *dev,
303 struct device_attribute *attr, char *buf)
304{
305 const struct gpio_chip *chip = dev_get_drvdata(dev);
306
307 return sprintf(buf, "%s\n", chip->label ? : "");
308}
309static DEVICE_ATTR(label, 0444, chip_label_show, NULL);
310
311static ssize_t chip_ngpio_show(struct device *dev,
312 struct device_attribute *attr, char *buf)
313{
314 const struct gpio_chip *chip = dev_get_drvdata(dev);
315
316 return sprintf(buf, "%u\n", chip->ngpio);
317}
318static DEVICE_ATTR(ngpio, 0444, chip_ngpio_show, NULL);
319
320static const struct attribute *gpiochip_attrs[] = {
321 &dev_attr_base.attr,
322 &dev_attr_label.attr,
323 &dev_attr_ngpio.attr,
324 NULL,
325};
326
327static const struct attribute_group gpiochip_attr_group = {
328 .attrs = (struct attribute **) gpiochip_attrs,
329};
330
331/*
332 * /sys/class/gpio/export ... write-only
333 * integer N ... number of GPIO to export (full access)
334 * /sys/class/gpio/unexport ... write-only
335 * integer N ... number of GPIO to unexport
336 */
337static ssize_t export_store(struct class *class, const char *buf, size_t len)
338{
339 long gpio;
340 int status;
341
342 status = strict_strtol(buf, 0, &gpio);
343 if (status < 0)
344 goto done;
345
346 /* No extra locking here; FLAG_SYSFS just signifies that the
347 * request and export were done by on behalf of userspace, so
348 * they may be undone on its behalf too.
349 */
350
351 status = gpio_request(gpio, "sysfs");
352 if (status < 0)
353 goto done;
354
355 status = gpio_export(gpio, true);
356 if (status < 0)
357 gpio_free(gpio);
358 else
359 set_bit(FLAG_SYSFS, &gpio_desc[gpio].flags);
360
361done:
362 if (status)
363 pr_debug("%s: status %d\n", __func__, status);
364 return status ? : len;
365}
366
367static ssize_t unexport_store(struct class *class, const char *buf, size_t len)
368{
369 long gpio;
370 int status;
371
372 status = strict_strtol(buf, 0, &gpio);
373 if (status < 0)
374 goto done;
375
376 status = -EINVAL;
377
378 /* reject bogus commands (gpio_unexport ignores them) */
379 if (!gpio_is_valid(gpio))
380 goto done;
381
382 /* No extra locking here; FLAG_SYSFS just signifies that the
383 * request and export were done by on behalf of userspace, so
384 * they may be undone on its behalf too.
385 */
386 if (test_and_clear_bit(FLAG_SYSFS, &gpio_desc[gpio].flags)) {
387 status = 0;
388 gpio_free(gpio);
389 }
390done:
391 if (status)
392 pr_debug("%s: status %d\n", __func__, status);
393 return status ? : len;
394}
395
396static struct class_attribute gpio_class_attrs[] = {
397 __ATTR(export, 0200, NULL, export_store),
398 __ATTR(unexport, 0200, NULL, unexport_store),
399 __ATTR_NULL,
400};
401
402static struct class gpio_class = {
403 .name = "gpio",
404 .owner = THIS_MODULE,
405
406 .class_attrs = gpio_class_attrs,
407};
408
409
410/**
411 * gpio_export - export a GPIO through sysfs
412 * @gpio: gpio to make available, already requested
413 * @direction_may_change: true if userspace may change gpio direction
414 * Context: arch_initcall or later
415 *
416 * When drivers want to make a GPIO accessible to userspace after they
417 * have requested it -- perhaps while debugging, or as part of their
418 * public interface -- they may use this routine. If the GPIO can
419 * change direction (some can't) and the caller allows it, userspace
420 * will see "direction" sysfs attribute which may be used to change
421 * the gpio's direction. A "value" attribute will always be provided.
422 *
423 * Returns zero on success, else an error.
424 */
425int gpio_export(unsigned gpio, bool direction_may_change)
426{
427 unsigned long flags;
428 struct gpio_desc *desc;
429 int status = -EINVAL;
430
431 /* can't export until sysfs is available ... */
432 if (!gpio_class.p) {
433 pr_debug("%s: called too early!\n", __func__);
434 return -ENOENT;
435 }
436
437 if (!gpio_is_valid(gpio))
438 goto done;
439
440 mutex_lock(&sysfs_lock);
441
442 spin_lock_irqsave(&gpio_lock, flags);
443 desc = &gpio_desc[gpio];
444 if (test_bit(FLAG_REQUESTED, &desc->flags)
445 && !test_bit(FLAG_EXPORT, &desc->flags)) {
446 status = 0;
447 if (!desc->chip->direction_input
448 || !desc->chip->direction_output)
449 direction_may_change = false;
450 }
451 spin_unlock_irqrestore(&gpio_lock, flags);
452
453 if (status == 0) {
454 struct device *dev;
455
456 dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0),
457 desc, "gpio%d", gpio);
458 if (dev) {
459 if (direction_may_change)
460 status = sysfs_create_group(&dev->kobj,
461 &gpio_attr_group);
462 else
463 status = device_create_file(dev,
464 &dev_attr_value);
465 if (status != 0)
466 device_unregister(dev);
467 } else
468 status = -ENODEV;
469 if (status == 0)
470 set_bit(FLAG_EXPORT, &desc->flags);
471 }
472
473 mutex_unlock(&sysfs_lock);
474
475done:
476 if (status)
477 pr_debug("%s: gpio%d status %d\n", __func__, gpio, status);
478
479 return status;
480}
481EXPORT_SYMBOL_GPL(gpio_export);
482
483static int match_export(struct device *dev, void *data)
484{
485 return dev_get_drvdata(dev) == data;
486}
487
488/**
489 * gpio_unexport - reverse effect of gpio_export()
490 * @gpio: gpio to make unavailable
491 *
492 * This is implicit on gpio_free().
493 */
494void gpio_unexport(unsigned gpio)
495{
496 struct gpio_desc *desc;
497 int status = -EINVAL;
498
499 if (!gpio_is_valid(gpio))
500 goto done;
501
502 mutex_lock(&sysfs_lock);
503
504 desc = &gpio_desc[gpio];
505 if (test_bit(FLAG_EXPORT, &desc->flags)) {
506 struct device *dev = NULL;
507
508 dev = class_find_device(&gpio_class, NULL, desc, match_export);
509 if (dev) {
510 clear_bit(FLAG_EXPORT, &desc->flags);
511 put_device(dev);
512 device_unregister(dev);
513 status = 0;
514 } else
515 status = -ENODEV;
516 }
517
518 mutex_unlock(&sysfs_lock);
519done:
520 if (status)
521 pr_debug("%s: gpio%d status %d\n", __func__, gpio, status);
522}
523EXPORT_SYMBOL_GPL(gpio_unexport);
524
525static int gpiochip_export(struct gpio_chip *chip)
526{
527 int status;
528 struct device *dev;
529
530 /* Many systems register gpio chips for SOC support very early,
531 * before driver model support is available. In those cases we
532 * export this later, in gpiolib_sysfs_init() ... here we just
533 * verify that _some_ field of gpio_class got initialized.
534 */
535 if (!gpio_class.p)
536 return 0;
537
538 /* use chip->base for the ID; it's already known to be unique */
539 mutex_lock(&sysfs_lock);
540 dev = device_create(&gpio_class, chip->dev, MKDEV(0, 0), chip,
541 "gpiochip%d", chip->base);
542 if (dev) {
543 status = sysfs_create_group(&dev->kobj,
544 &gpiochip_attr_group);
545 } else
546 status = -ENODEV;
547 chip->exported = (status == 0);
548 mutex_unlock(&sysfs_lock);
549
550 if (status) {
551 unsigned long flags;
552 unsigned gpio;
553
554 spin_lock_irqsave(&gpio_lock, flags);
555 gpio = chip->base;
556 while (gpio_desc[gpio].chip == chip)
557 gpio_desc[gpio++].chip = NULL;
558 spin_unlock_irqrestore(&gpio_lock, flags);
559
560 pr_debug("%s: chip %s status %d\n", __func__,
561 chip->label, status);
562 }
563
564 return status;
565}
566
567static void gpiochip_unexport(struct gpio_chip *chip)
568{
569 int status;
570 struct device *dev;
571
572 mutex_lock(&sysfs_lock);
573 dev = class_find_device(&gpio_class, NULL, chip, match_export);
574 if (dev) {
575 put_device(dev);
576 device_unregister(dev);
577 chip->exported = 0;
578 status = 0;
579 } else
580 status = -ENODEV;
581 mutex_unlock(&sysfs_lock);
582
583 if (status)
584 pr_debug("%s: chip %s status %d\n", __func__,
585 chip->label, status);
586}
587
588static int __init gpiolib_sysfs_init(void)
589{
590 int status;
591 unsigned long flags;
592 unsigned gpio;
593
594 status = class_register(&gpio_class);
595 if (status < 0)
596 return status;
597
598 /* Scan and register the gpio_chips which registered very
599 * early (e.g. before the class_register above was called).
600 *
601 * We run before arch_initcall() so chip->dev nodes can have
602 * registered, and so arch_initcall() can always gpio_export().
603 */
604 spin_lock_irqsave(&gpio_lock, flags);
605 for (gpio = 0; gpio < ARCH_NR_GPIOS; gpio++) {
606 struct gpio_chip *chip;
607
608 chip = gpio_desc[gpio].chip;
609 if (!chip || chip->exported)
610 continue;
611
612 spin_unlock_irqrestore(&gpio_lock, flags);
613 status = gpiochip_export(chip);
614 spin_lock_irqsave(&gpio_lock, flags);
615 }
616 spin_unlock_irqrestore(&gpio_lock, flags);
617
618
619 return status;
620}
621postcore_initcall(gpiolib_sysfs_init);
622
623#else
624static inline int gpiochip_export(struct gpio_chip *chip)
625{
626 return 0;
627}
628
629static inline void gpiochip_unexport(struct gpio_chip *chip)
630{
631}
632
633#endif /* CONFIG_GPIO_SYSFS */
634
154/** 635/**
155 * gpiochip_add() - register a gpio_chip 636 * gpiochip_add() - register a gpio_chip
156 * @chip: the chip to register, with chip->base initialized 637 * @chip: the chip to register, with chip->base initialized
@@ -160,6 +641,11 @@ err:
160 * because the chip->base is invalid or already associated with a 641 * because the chip->base is invalid or already associated with a
161 * different chip. Otherwise it returns zero as a success code. 642 * different chip. Otherwise it returns zero as a success code.
162 * 643 *
644 * When gpiochip_add() is called very early during boot, so that GPIOs
645 * can be freely used, the chip->dev device must be registered before
646 * the gpio framework's arch_initcall(). Otherwise sysfs initialization
647 * for GPIOs will fail rudely.
648 *
163 * If chip->base is negative, this requests dynamic assignment of 649 * If chip->base is negative, this requests dynamic assignment of
164 * a range of valid GPIOs. 650 * a range of valid GPIOs.
165 */ 651 */
@@ -182,7 +668,7 @@ int gpiochip_add(struct gpio_chip *chip)
182 base = gpiochip_find_base(chip->ngpio); 668 base = gpiochip_find_base(chip->ngpio);
183 if (base < 0) { 669 if (base < 0) {
184 status = base; 670 status = base;
185 goto fail_unlock; 671 goto unlock;
186 } 672 }
187 chip->base = base; 673 chip->base = base;
188 } 674 }
@@ -197,12 +683,23 @@ int gpiochip_add(struct gpio_chip *chip)
197 if (status == 0) { 683 if (status == 0) {
198 for (id = base; id < base + chip->ngpio; id++) { 684 for (id = base; id < base + chip->ngpio; id++) {
199 gpio_desc[id].chip = chip; 685 gpio_desc[id].chip = chip;
200 gpio_desc[id].flags = 0; 686
687 /* REVISIT: most hardware initializes GPIOs as
688 * inputs (often with pullups enabled) so power
689 * usage is minimized. Linux code should set the
690 * gpio direction first thing; but until it does,
691 * we may expose the wrong direction in sysfs.
692 */
693 gpio_desc[id].flags = !chip->direction_input
694 ? (1 << FLAG_IS_OUT)
695 : 0;
201 } 696 }
202 } 697 }
203 698
204fail_unlock: 699unlock:
205 spin_unlock_irqrestore(&gpio_lock, flags); 700 spin_unlock_irqrestore(&gpio_lock, flags);
701 if (status == 0)
702 status = gpiochip_export(chip);
206fail: 703fail:
207 /* failures here can mean systems won't boot... */ 704 /* failures here can mean systems won't boot... */
208 if (status) 705 if (status)
@@ -239,6 +736,10 @@ int gpiochip_remove(struct gpio_chip *chip)
239 } 736 }
240 737
241 spin_unlock_irqrestore(&gpio_lock, flags); 738 spin_unlock_irqrestore(&gpio_lock, flags);
739
740 if (status == 0)
741 gpiochip_unexport(chip);
742
242 return status; 743 return status;
243} 744}
244EXPORT_SYMBOL_GPL(gpiochip_remove); 745EXPORT_SYMBOL_GPL(gpiochip_remove);
@@ -296,6 +797,8 @@ void gpio_free(unsigned gpio)
296 return; 797 return;
297 } 798 }
298 799
800 gpio_unexport(gpio);
801
299 spin_lock_irqsave(&gpio_lock, flags); 802 spin_lock_irqsave(&gpio_lock, flags);
300 803
301 desc = &gpio_desc[gpio]; 804 desc = &gpio_desc[gpio];
@@ -534,10 +1037,6 @@ EXPORT_SYMBOL_GPL(gpio_set_value_cansleep);
534 1037
535#ifdef CONFIG_DEBUG_FS 1038#ifdef CONFIG_DEBUG_FS
536 1039
537#include <linux/debugfs.h>
538#include <linux/seq_file.h>
539
540
541static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip) 1040static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip)
542{ 1041{
543 unsigned i; 1042 unsigned i;
@@ -614,17 +1113,28 @@ static int gpiolib_show(struct seq_file *s, void *unused)
614 /* REVISIT this isn't locked against gpio_chip removal ... */ 1113 /* REVISIT this isn't locked against gpio_chip removal ... */
615 1114
616 for (gpio = 0; gpio_is_valid(gpio); gpio++) { 1115 for (gpio = 0; gpio_is_valid(gpio); gpio++) {
1116 struct device *dev;
1117
617 if (chip == gpio_desc[gpio].chip) 1118 if (chip == gpio_desc[gpio].chip)
618 continue; 1119 continue;
619 chip = gpio_desc[gpio].chip; 1120 chip = gpio_desc[gpio].chip;
620 if (!chip) 1121 if (!chip)
621 continue; 1122 continue;
622 1123
623 seq_printf(s, "%sGPIOs %d-%d, %s%s:\n", 1124 seq_printf(s, "%sGPIOs %d-%d",
624 started ? "\n" : "", 1125 started ? "\n" : "",
625 chip->base, chip->base + chip->ngpio - 1, 1126 chip->base, chip->base + chip->ngpio - 1);
626 chip->label ? : "generic", 1127 dev = chip->dev;
627 chip->can_sleep ? ", can sleep" : ""); 1128 if (dev)
1129 seq_printf(s, ", %s/%s",
1130 dev->bus ? dev->bus->name : "no-bus",
1131 dev->bus_id);
1132 if (chip->label)
1133 seq_printf(s, ", %s", chip->label);
1134 if (chip->can_sleep)
1135 seq_printf(s, ", can sleep");
1136 seq_printf(s, ":\n");
1137
628 started = 1; 1138 started = 1;
629 if (chip->dbg_show) 1139 if (chip->dbg_show)
630 chip->dbg_show(s, chip); 1140 chip->dbg_show(s, chip);
diff --git a/drivers/gpio/max732x.c b/drivers/gpio/max732x.c
new file mode 100644
index 000000000000..b51c8135ca28
--- /dev/null
+++ b/drivers/gpio/max732x.c
@@ -0,0 +1,385 @@
1/*
2 * max732x.c - I2C Port Expander with 8/16 I/O
3 *
4 * Copyright (C) 2007 Marvell International Ltd.
5 * Copyright (C) 2008 Jack Ren <jack.ren@marvell.com>
6 * Copyright (C) 2008 Eric Miao <eric.miao@marvell.com>
7 *
8 * Derived from drivers/gpio/pca953x.c
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
13 */
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/slab.h>
18#include <linux/string.h>
19#include <linux/gpio.h>
20
21#include <linux/i2c.h>
22#include <linux/i2c/max732x.h>
23
24
25/*
26 * Each port of MAX732x (including MAX7319) falls into one of the
27 * following three types:
28 *
29 * - Push Pull Output
30 * - Input
31 * - Open Drain I/O
32 *
33 * designated by 'O', 'I' and 'P' individually according to MAXIM's
34 * datasheets.
35 *
36 * There are two groups of I/O ports, each group usually includes
37 * up to 8 I/O ports, and is accessed by a specific I2C address:
38 *
39 * - Group A : by I2C address 0b'110xxxx
40 * - Group B : by I2C address 0b'101xxxx
41 *
42 * where 'xxxx' is decided by the connections of pin AD2/AD0. The
43 * address used also affects the initial state of output signals.
44 *
45 * Within each group of ports, there are five known combinations of
46 * I/O ports: 4I4O, 4P4O, 8I, 8P, 8O, see the definitions below for
47 * the detailed organization of these ports.
48 *
49 * GPIO numbers start from 'gpio_base + 0' to 'gpio_base + 8/16',
50 * and GPIOs from GROUP_A are numbered before those from GROUP_B
51 * (if there are two groups).
52 *
53 * NOTE: MAX7328/MAX7329 are drop-in replacements for PCF8574/a, so
54 * they are not supported by this driver.
55 */
56
57#define PORT_NONE 0x0 /* '/' No Port */
58#define PORT_OUTPUT 0x1 /* 'O' Push-Pull, Output Only */
59#define PORT_INPUT 0x2 /* 'I' Input Only */
60#define PORT_OPENDRAIN 0x3 /* 'P' Open-Drain, I/O */
61
62#define IO_4I4O 0x5AA5 /* O7 O6 I5 I4 I3 I2 O1 O0 */
63#define IO_4P4O 0x5FF5 /* O7 O6 P5 P4 P3 P2 O1 O0 */
64#define IO_8I 0xAAAA /* I7 I6 I5 I4 I3 I2 I1 I0 */
65#define IO_8P 0xFFFF /* P7 P6 P5 P4 P3 P2 P1 P0 */
66#define IO_8O 0x5555 /* O7 O6 O5 O4 O3 O2 O1 O0 */
67
68#define GROUP_A(x) ((x) & 0xffff) /* I2C Addr: 0b'110xxxx */
69#define GROUP_B(x) ((x) << 16) /* I2C Addr: 0b'101xxxx */
70
71static const struct i2c_device_id max732x_id[] = {
72 { "max7319", GROUP_A(IO_8I) },
73 { "max7320", GROUP_B(IO_8O) },
74 { "max7321", GROUP_A(IO_8P) },
75 { "max7322", GROUP_A(IO_4I4O) },
76 { "max7323", GROUP_A(IO_4P4O) },
77 { "max7324", GROUP_A(IO_8I) | GROUP_B(IO_8O) },
78 { "max7325", GROUP_A(IO_8P) | GROUP_B(IO_8O) },
79 { "max7326", GROUP_A(IO_4I4O) | GROUP_B(IO_8O) },
80 { "max7327", GROUP_A(IO_4P4O) | GROUP_B(IO_8O) },
81 { },
82};
83MODULE_DEVICE_TABLE(i2c, max732x_id);
84
85struct max732x_chip {
86 struct gpio_chip gpio_chip;
87
88 struct i2c_client *client; /* "main" client */
89 struct i2c_client *client_dummy;
90 struct i2c_client *client_group_a;
91 struct i2c_client *client_group_b;
92
93 unsigned int mask_group_a;
94 unsigned int dir_input;
95 unsigned int dir_output;
96
97 struct mutex lock;
98 uint8_t reg_out[2];
99};
100
101static int max732x_write(struct max732x_chip *chip, int group_a, uint8_t val)
102{
103 struct i2c_client *client;
104 int ret;
105
106 client = group_a ? chip->client_group_a : chip->client_group_b;
107 ret = i2c_smbus_write_byte(client, val);
108 if (ret < 0) {
109 dev_err(&client->dev, "failed writing\n");
110 return ret;
111 }
112
113 return 0;
114}
115
116static int max732x_read(struct max732x_chip *chip, int group_a, uint8_t *val)
117{
118 struct i2c_client *client;
119 int ret;
120
121 client = group_a ? chip->client_group_a : chip->client_group_b;
122 ret = i2c_smbus_read_byte(client);
123 if (ret < 0) {
124 dev_err(&client->dev, "failed reading\n");
125 return ret;
126 }
127
128 *val = (uint8_t)ret;
129 return 0;
130}
131
132static inline int is_group_a(struct max732x_chip *chip, unsigned off)
133{
134 return (1u << off) & chip->mask_group_a;
135}
136
137static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off)
138{
139 struct max732x_chip *chip;
140 uint8_t reg_val;
141 int ret;
142
143 chip = container_of(gc, struct max732x_chip, gpio_chip);
144
145 ret = max732x_read(chip, is_group_a(chip, off), &reg_val);
146 if (ret < 0)
147 return 0;
148
149 return reg_val & (1u << (off & 0x7));
150}
151
152static void max732x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
153{
154 struct max732x_chip *chip;
155 uint8_t reg_out, mask = 1u << (off & 0x7);
156 int ret;
157
158 chip = container_of(gc, struct max732x_chip, gpio_chip);
159
160 mutex_lock(&chip->lock);
161
162 reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0];
163 reg_out = (val) ? reg_out | mask : reg_out & ~mask;
164
165 ret = max732x_write(chip, is_group_a(chip, off), reg_out);
166 if (ret < 0)
167 goto out;
168
169 /* update the shadow register then */
170 if (off > 7)
171 chip->reg_out[1] = reg_out;
172 else
173 chip->reg_out[0] = reg_out;
174out:
175 mutex_unlock(&chip->lock);
176}
177
178static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off)
179{
180 struct max732x_chip *chip;
181 unsigned int mask = 1u << off;
182
183 chip = container_of(gc, struct max732x_chip, gpio_chip);
184
185 if ((mask & chip->dir_input) == 0) {
186 dev_dbg(&chip->client->dev, "%s port %d is output only\n",
187 chip->client->name, off);
188 return -EACCES;
189 }
190
191 return 0;
192}
193
194static int max732x_gpio_direction_output(struct gpio_chip *gc,
195 unsigned off, int val)
196{
197 struct max732x_chip *chip;
198 unsigned int mask = 1u << off;
199
200 chip = container_of(gc, struct max732x_chip, gpio_chip);
201
202 if ((mask & chip->dir_output) == 0) {
203 dev_dbg(&chip->client->dev, "%s port %d is input only\n",
204 chip->client->name, off);
205 return -EACCES;
206 }
207
208 max732x_gpio_set_value(gc, off, val);
209 return 0;
210}
211
212static int __devinit max732x_setup_gpio(struct max732x_chip *chip,
213 const struct i2c_device_id *id,
214 unsigned gpio_start)
215{
216 struct gpio_chip *gc = &chip->gpio_chip;
217 uint32_t id_data = id->driver_data;
218 int i, port = 0;
219
220 for (i = 0; i < 16; i++, id_data >>= 2) {
221 unsigned int mask = 1 << port;
222
223 switch (id_data & 0x3) {
224 case PORT_OUTPUT:
225 chip->dir_output |= mask;
226 break;
227 case PORT_INPUT:
228 chip->dir_input |= mask;
229 break;
230 case PORT_OPENDRAIN:
231 chip->dir_output |= mask;
232 chip->dir_input |= mask;
233 break;
234 default:
235 continue;
236 }
237
238 if (i < 8)
239 chip->mask_group_a |= mask;
240 port++;
241 }
242
243 if (chip->dir_input)
244 gc->direction_input = max732x_gpio_direction_input;
245 if (chip->dir_output) {
246 gc->direction_output = max732x_gpio_direction_output;
247 gc->set = max732x_gpio_set_value;
248 }
249 gc->get = max732x_gpio_get_value;
250 gc->can_sleep = 1;
251
252 gc->base = gpio_start;
253 gc->ngpio = port;
254 gc->label = chip->client->name;
255 gc->owner = THIS_MODULE;
256
257 return port;
258}
259
260static int __devinit max732x_probe(struct i2c_client *client,
261 const struct i2c_device_id *id)
262{
263 struct max732x_platform_data *pdata;
264 struct max732x_chip *chip;
265 struct i2c_client *c;
266 uint16_t addr_a, addr_b;
267 int ret, nr_port;
268
269 pdata = client->dev.platform_data;
270 if (pdata == NULL)
271 return -ENODEV;
272
273 chip = kzalloc(sizeof(struct max732x_chip), GFP_KERNEL);
274 if (chip == NULL)
275 return -ENOMEM;
276 chip->client = client;
277
278 nr_port = max732x_setup_gpio(chip, id, pdata->gpio_base);
279
280 addr_a = (client->addr & 0x0f) | 0x60;
281 addr_b = (client->addr & 0x0f) | 0x50;
282
283 switch (client->addr & 0x70) {
284 case 0x60:
285 chip->client_group_a = client;
286 if (nr_port > 7) {
287 c = i2c_new_dummy(client->adapter, addr_b);
288 chip->client_group_b = chip->client_dummy = c;
289 }
290 break;
291 case 0x50:
292 chip->client_group_b = client;
293 if (nr_port > 7) {
294 c = i2c_new_dummy(client->adapter, addr_a);
295 chip->client_group_a = chip->client_dummy = c;
296 }
297 break;
298 default:
299 dev_err(&client->dev, "invalid I2C address specified %02x\n",
300 client->addr);
301 ret = -EINVAL;
302 goto out_failed;
303 }
304
305 mutex_init(&chip->lock);
306
307 max732x_read(chip, is_group_a(chip, 0), &chip->reg_out[0]);
308 if (nr_port > 7)
309 max732x_read(chip, is_group_a(chip, 8), &chip->reg_out[1]);
310
311 ret = gpiochip_add(&chip->gpio_chip);
312 if (ret)
313 goto out_failed;
314
315 if (pdata->setup) {
316 ret = pdata->setup(client, chip->gpio_chip.base,
317 chip->gpio_chip.ngpio, pdata->context);
318 if (ret < 0)
319 dev_warn(&client->dev, "setup failed, %d\n", ret);
320 }
321
322 i2c_set_clientdata(client, chip);
323 return 0;
324
325out_failed:
326 kfree(chip);
327 return ret;
328}
329
330static int __devexit max732x_remove(struct i2c_client *client)
331{
332 struct max732x_platform_data *pdata = client->dev.platform_data;
333 struct max732x_chip *chip = i2c_get_clientdata(client);
334 int ret;
335
336 if (pdata->teardown) {
337 ret = pdata->teardown(client, chip->gpio_chip.base,
338 chip->gpio_chip.ngpio, pdata->context);
339 if (ret < 0) {
340 dev_err(&client->dev, "%s failed, %d\n",
341 "teardown", ret);
342 return ret;
343 }
344 }
345
346 ret = gpiochip_remove(&chip->gpio_chip);
347 if (ret) {
348 dev_err(&client->dev, "%s failed, %d\n",
349 "gpiochip_remove()", ret);
350 return ret;
351 }
352
353 /* unregister any dummy i2c_client */
354 if (chip->client_dummy)
355 i2c_unregister_device(chip->client_dummy);
356
357 kfree(chip);
358 return 0;
359}
360
361static struct i2c_driver max732x_driver = {
362 .driver = {
363 .name = "max732x",
364 .owner = THIS_MODULE,
365 },
366 .probe = max732x_probe,
367 .remove = __devexit_p(max732x_remove),
368 .id_table = max732x_id,
369};
370
371static int __init max732x_init(void)
372{
373 return i2c_add_driver(&max732x_driver);
374}
375module_init(max732x_init);
376
377static void __exit max732x_exit(void)
378{
379 i2c_del_driver(&max732x_driver);
380}
381module_exit(max732x_exit);
382
383MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>");
384MODULE_DESCRIPTION("GPIO expander driver for MAX732X");
385MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/mcp23s08.c b/drivers/gpio/mcp23s08.c
index 7f92fdd5f0e2..8a1b405fefda 100644
--- a/drivers/gpio/mcp23s08.c
+++ b/drivers/gpio/mcp23s08.c
@@ -40,15 +40,26 @@ struct mcp23s08 {
40 struct spi_device *spi; 40 struct spi_device *spi;
41 u8 addr; 41 u8 addr;
42 42
43 u8 cache[11];
43 /* lock protects the cached values */ 44 /* lock protects the cached values */
44 struct mutex lock; 45 struct mutex lock;
45 u8 cache[11];
46 46
47 struct gpio_chip chip; 47 struct gpio_chip chip;
48 48
49 struct work_struct work; 49 struct work_struct work;
50}; 50};
51 51
52/* A given spi_device can represent up to four mcp23s08 chips
53 * sharing the same chipselect but using different addresses
54 * (e.g. chips #0 and #3 might be populated, but not #1 or $2).
55 * Driver data holds all the per-chip data.
56 */
57struct mcp23s08_driver_data {
58 unsigned ngpio;
59 struct mcp23s08 *mcp[4];
60 struct mcp23s08 chip[];
61};
62
52static int mcp23s08_read(struct mcp23s08 *mcp, unsigned reg) 63static int mcp23s08_read(struct mcp23s08 *mcp, unsigned reg)
53{ 64{
54 u8 tx[2], rx[1]; 65 u8 tx[2], rx[1];
@@ -208,25 +219,18 @@ done:
208 219
209/*----------------------------------------------------------------------*/ 220/*----------------------------------------------------------------------*/
210 221
211static int mcp23s08_probe(struct spi_device *spi) 222static int mcp23s08_probe_one(struct spi_device *spi, unsigned addr,
223 unsigned base, unsigned pullups)
212{ 224{
213 struct mcp23s08 *mcp; 225 struct mcp23s08_driver_data *data = spi_get_drvdata(spi);
214 struct mcp23s08_platform_data *pdata; 226 struct mcp23s08 *mcp = data->mcp[addr];
215 int status; 227 int status;
216 int do_update = 0; 228 int do_update = 0;
217 229
218 pdata = spi->dev.platform_data;
219 if (!pdata || pdata->slave > 3 || !pdata->base)
220 return -ENODEV;
221
222 mcp = kzalloc(sizeof *mcp, GFP_KERNEL);
223 if (!mcp)
224 return -ENOMEM;
225
226 mutex_init(&mcp->lock); 230 mutex_init(&mcp->lock);
227 231
228 mcp->spi = spi; 232 mcp->spi = spi;
229 mcp->addr = 0x40 | (pdata->slave << 1); 233 mcp->addr = 0x40 | (addr << 1);
230 234
231 mcp->chip.label = "mcp23s08", 235 mcp->chip.label = "mcp23s08",
232 236
@@ -236,26 +240,28 @@ static int mcp23s08_probe(struct spi_device *spi)
236 mcp->chip.set = mcp23s08_set; 240 mcp->chip.set = mcp23s08_set;
237 mcp->chip.dbg_show = mcp23s08_dbg_show; 241 mcp->chip.dbg_show = mcp23s08_dbg_show;
238 242
239 mcp->chip.base = pdata->base; 243 mcp->chip.base = base;
240 mcp->chip.ngpio = 8; 244 mcp->chip.ngpio = 8;
241 mcp->chip.can_sleep = 1; 245 mcp->chip.can_sleep = 1;
246 mcp->chip.dev = &spi->dev;
242 mcp->chip.owner = THIS_MODULE; 247 mcp->chip.owner = THIS_MODULE;
243 248
244 spi_set_drvdata(spi, mcp); 249 /* verify MCP_IOCON.SEQOP = 0, so sequential reads work,
245 250 * and MCP_IOCON.HAEN = 1, so we work with all chips.
246 /* verify MCP_IOCON.SEQOP = 0, so sequential reads work */ 251 */
247 status = mcp23s08_read(mcp, MCP_IOCON); 252 status = mcp23s08_read(mcp, MCP_IOCON);
248 if (status < 0) 253 if (status < 0)
249 goto fail; 254 goto fail;
250 if (status & IOCON_SEQOP) { 255 if ((status & IOCON_SEQOP) || !(status & IOCON_HAEN)) {
251 status &= ~IOCON_SEQOP; 256 status &= ~IOCON_SEQOP;
257 status |= IOCON_HAEN;
252 status = mcp23s08_write(mcp, MCP_IOCON, (u8) status); 258 status = mcp23s08_write(mcp, MCP_IOCON, (u8) status);
253 if (status < 0) 259 if (status < 0)
254 goto fail; 260 goto fail;
255 } 261 }
256 262
257 /* configure ~100K pullups */ 263 /* configure ~100K pullups */
258 status = mcp23s08_write(mcp, MCP_GPPU, pdata->pullups); 264 status = mcp23s08_write(mcp, MCP_GPPU, pullups);
259 if (status < 0) 265 if (status < 0)
260 goto fail; 266 goto fail;
261 267
@@ -282,11 +288,58 @@ static int mcp23s08_probe(struct spi_device *spi)
282 tx[1] = MCP_IPOL; 288 tx[1] = MCP_IPOL;
283 memcpy(&tx[2], &mcp->cache[MCP_IPOL], sizeof(tx) - 2); 289 memcpy(&tx[2], &mcp->cache[MCP_IPOL], sizeof(tx) - 2);
284 status = spi_write_then_read(mcp->spi, tx, sizeof tx, NULL, 0); 290 status = spi_write_then_read(mcp->spi, tx, sizeof tx, NULL, 0);
285 291 if (status < 0)
286 /* FIXME check status... */ 292 goto fail;
287 } 293 }
288 294
289 status = gpiochip_add(&mcp->chip); 295 status = gpiochip_add(&mcp->chip);
296fail:
297 if (status < 0)
298 dev_dbg(&spi->dev, "can't setup chip %d, --> %d\n",
299 addr, status);
300 return status;
301}
302
303static int mcp23s08_probe(struct spi_device *spi)
304{
305 struct mcp23s08_platform_data *pdata;
306 unsigned addr;
307 unsigned chips = 0;
308 struct mcp23s08_driver_data *data;
309 int status;
310 unsigned base;
311
312 pdata = spi->dev.platform_data;
313 if (!pdata || !gpio_is_valid(pdata->base))
314 return -ENODEV;
315
316 for (addr = 0; addr < 4; addr++) {
317 if (!pdata->chip[addr].is_present)
318 continue;
319 chips++;
320 }
321 if (!chips)
322 return -ENODEV;
323
324 data = kzalloc(sizeof *data + chips * sizeof(struct mcp23s08),
325 GFP_KERNEL);
326 if (!data)
327 return -ENOMEM;
328 spi_set_drvdata(spi, data);
329
330 base = pdata->base;
331 for (addr = 0; addr < 4; addr++) {
332 if (!pdata->chip[addr].is_present)
333 continue;
334 chips--;
335 data->mcp[addr] = &data->chip[chips];
336 status = mcp23s08_probe_one(spi, addr, base,
337 pdata->chip[addr].pullups);
338 if (status < 0)
339 goto fail;
340 base += 8;
341 }
342 data->ngpio = base - pdata->base;
290 343
291 /* NOTE: these chips have a relatively sane IRQ framework, with 344 /* NOTE: these chips have a relatively sane IRQ framework, with
292 * per-signal masking and level/edge triggering. It's not yet 345 * per-signal masking and level/edge triggering. It's not yet
@@ -294,8 +347,9 @@ static int mcp23s08_probe(struct spi_device *spi)
294 */ 347 */
295 348
296 if (pdata->setup) { 349 if (pdata->setup) {
297 status = pdata->setup(spi, mcp->chip.base, 350 status = pdata->setup(spi,
298 mcp->chip.ngpio, pdata->context); 351 pdata->base, data->ngpio,
352 pdata->context);
299 if (status < 0) 353 if (status < 0)
300 dev_dbg(&spi->dev, "setup --> %d\n", status); 354 dev_dbg(&spi->dev, "setup --> %d\n", status);
301 } 355 }
@@ -303,19 +357,29 @@ static int mcp23s08_probe(struct spi_device *spi)
303 return 0; 357 return 0;
304 358
305fail: 359fail:
306 kfree(mcp); 360 for (addr = 0; addr < 4; addr++) {
361 int tmp;
362
363 if (!data->mcp[addr])
364 continue;
365 tmp = gpiochip_remove(&data->mcp[addr]->chip);
366 if (tmp < 0)
367 dev_err(&spi->dev, "%s --> %d\n", "remove", tmp);
368 }
369 kfree(data);
307 return status; 370 return status;
308} 371}
309 372
310static int mcp23s08_remove(struct spi_device *spi) 373static int mcp23s08_remove(struct spi_device *spi)
311{ 374{
312 struct mcp23s08 *mcp = spi_get_drvdata(spi); 375 struct mcp23s08_driver_data *data = spi_get_drvdata(spi);
313 struct mcp23s08_platform_data *pdata = spi->dev.platform_data; 376 struct mcp23s08_platform_data *pdata = spi->dev.platform_data;
377 unsigned addr;
314 int status = 0; 378 int status = 0;
315 379
316 if (pdata->teardown) { 380 if (pdata->teardown) {
317 status = pdata->teardown(spi, 381 status = pdata->teardown(spi,
318 mcp->chip.base, mcp->chip.ngpio, 382 pdata->base, data->ngpio,
319 pdata->context); 383 pdata->context);
320 if (status < 0) { 384 if (status < 0) {
321 dev_err(&spi->dev, "%s --> %d\n", "teardown", status); 385 dev_err(&spi->dev, "%s --> %d\n", "teardown", status);
@@ -323,11 +387,20 @@ static int mcp23s08_remove(struct spi_device *spi)
323 } 387 }
324 } 388 }
325 389
326 status = gpiochip_remove(&mcp->chip); 390 for (addr = 0; addr < 4; addr++) {
391 int tmp;
392
393 if (!data->mcp[addr])
394 continue;
395
396 tmp = gpiochip_remove(&data->mcp[addr]->chip);
397 if (tmp < 0) {
398 dev_err(&spi->dev, "%s --> %d\n", "remove", tmp);
399 status = tmp;
400 }
401 }
327 if (status == 0) 402 if (status == 0)
328 kfree(mcp); 403 kfree(data);
329 else
330 dev_err(&spi->dev, "%s --> %d\n", "remove", status);
331 return status; 404 return status;
332} 405}
333 406
@@ -355,4 +428,3 @@ static void __exit mcp23s08_exit(void)
355module_exit(mcp23s08_exit); 428module_exit(mcp23s08_exit);
356 429
357MODULE_LICENSE("GPL"); 430MODULE_LICENSE("GPL");
358
diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index a380730b61ab..cc8468692ae0 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -188,6 +188,7 @@ static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios)
188 gc->base = chip->gpio_start; 188 gc->base = chip->gpio_start;
189 gc->ngpio = gpios; 189 gc->ngpio = gpios;
190 gc->label = chip->client->name; 190 gc->label = chip->client->name;
191 gc->dev = &chip->client->dev;
191 gc->owner = THIS_MODULE; 192 gc->owner = THIS_MODULE;
192} 193}
193 194
diff --git a/drivers/gpio/pcf857x.c b/drivers/gpio/pcf857x.c
index d25d356c4f20..fc9c6ae739ee 100644
--- a/drivers/gpio/pcf857x.c
+++ b/drivers/gpio/pcf857x.c
@@ -200,6 +200,7 @@ static int pcf857x_probe(struct i2c_client *client,
200 200
201 gpio->chip.base = pdata->gpio_base; 201 gpio->chip.base = pdata->gpio_base;
202 gpio->chip.can_sleep = 1; 202 gpio->chip.can_sleep = 1;
203 gpio->chip.dev = &client->dev;
203 gpio->chip.owner = THIS_MODULE; 204 gpio->chip.owner = THIS_MODULE;
204 205
205 /* NOTE: the OnSemi jlc1562b is also largely compatible with 206 /* NOTE: the OnSemi jlc1562b is also largely compatible with
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 564138714bb5..452c2d866ec5 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -318,7 +318,7 @@ static void drm_cleanup(struct drm_device * dev)
318 DRM_ERROR("Cannot unload module\n"); 318 DRM_ERROR("Cannot unload module\n");
319} 319}
320 320
321int drm_minors_cleanup(int id, void *ptr, void *data) 321static int drm_minors_cleanup(int id, void *ptr, void *data)
322{ 322{
323 struct drm_minor *minor = ptr; 323 struct drm_minor *minor = ptr;
324 struct drm_device *dev; 324 struct drm_device *dev;
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 50e0a4653741..a95cb9465d65 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -126,7 +126,7 @@ config ISP1301_OMAP
126 126
127config TPS65010 127config TPS65010
128 tristate "TPS6501x Power Management chips" 128 tristate "TPS6501x Power Management chips"
129 depends on HAVE_GPIO_LIB 129 depends on GPIOLIB
130 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK 130 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK
131 help 131 help
132 If you say yes here you get support for the TPS6501x series of 132 If you say yes here you get support for the TPS6501x series of
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 85949685191b..cf02e8fceb42 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -636,6 +636,8 @@ static int tps65010_probe(struct i2c_client *client,
636 tps->outmask = board->outmask; 636 tps->outmask = board->outmask;
637 637
638 tps->chip.label = client->name; 638 tps->chip.label = client->name;
639 tps->chip.dev = &client->dev;
640 tps->chip.owner = THIS_MODULE;
639 641
640 tps->chip.set = tps65010_gpio_set; 642 tps->chip.set = tps65010_gpio_set;
641 tps->chip.direction_output = tps65010_output; 643 tps->chip.direction_output = tps65010_output;
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 04d9c4d459d0..130ef64b44f7 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -314,7 +314,7 @@ comment "IDE chipset support/bugfixes"
314 314
315config IDE_GENERIC 315config IDE_GENERIC
316 tristate "generic/default IDE chipset support" 316 tristate "generic/default IDE chipset support"
317 depends on ALPHA || X86 || IA64 || M32R || MIPS || PPC32 317 depends on ALPHA || X86 || IA64 || M32R || MIPS
318 help 318 help
319 If unsure, say N. 319 If unsure, say N.
320 320
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 5d414e301a5a..64e0ecdc4ed5 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -1,13 +1,6 @@
1# 1#
2# Makefile for the kernel ata, atapi, and ide block device drivers.
3#
4# 12 September 2000, Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
5# Rewritten to use lists instead of if-statements.
6#
7# Note : at this point, these files are compiled on all systems.
8# In the future, some of these should be built conditionally.
9#
10# link order is important here 2# link order is important here
3#
11 4
12EXTRA_CFLAGS += -Idrivers/ide 5EXTRA_CFLAGS += -Idrivers/ide
13 6
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index f575e8341aec..df4af4083954 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/icside.c
@@ -710,8 +710,14 @@ static int __init icside_init(void)
710 return ecard_register_driver(&icside_driver); 710 return ecard_register_driver(&icside_driver);
711} 711}
712 712
713static void __exit icside_exit(void);
714{
715 ecard_unregister_driver(&icside_driver);
716}
717
713MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); 718MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
714MODULE_LICENSE("GPL"); 719MODULE_LICENSE("GPL");
715MODULE_DESCRIPTION("ICS IDE driver"); 720MODULE_DESCRIPTION("ICS IDE driver");
716 721
717module_init(icside_init); 722module_init(icside_init);
723module_exit(icside_exit);
diff --git a/drivers/ide/arm/palm_bk3710.c b/drivers/ide/arm/palm_bk3710.c
index 65bb4b8fd570..3e842d60eae9 100644
--- a/drivers/ide/arm/palm_bk3710.c
+++ b/drivers/ide/arm/palm_bk3710.c
@@ -82,6 +82,7 @@ static const struct palm_bk3710_udmatiming palm_bk3710_udmatimings[6] = {
82 {100, 120}, /* UDMA Mode 2 */ 82 {100, 120}, /* UDMA Mode 2 */
83 {100, 90}, /* UDMA Mode 3 */ 83 {100, 90}, /* UDMA Mode 3 */
84 {100, 60}, /* UDMA Mode 4 */ 84 {100, 60}, /* UDMA Mode 4 */
85 {85, 40}, /* UDMA Mode 5 */
85}; 86};
86 87
87static void palm_bk3710_setudmamode(void __iomem *base, unsigned int dev, 88static void palm_bk3710_setudmamode(void __iomem *base, unsigned int dev,
@@ -334,12 +335,11 @@ static const struct ide_port_ops palm_bk3710_ports_ops = {
334 .cable_detect = palm_bk3710_cable_detect, 335 .cable_detect = palm_bk3710_cable_detect,
335}; 336};
336 337
337static const struct ide_port_info __devinitdata palm_bk3710_port_info = { 338static struct ide_port_info __devinitdata palm_bk3710_port_info = {
338 .init_dma = palm_bk3710_init_dma, 339 .init_dma = palm_bk3710_init_dma,
339 .port_ops = &palm_bk3710_ports_ops, 340 .port_ops = &palm_bk3710_ports_ops,
340 .host_flags = IDE_HFLAG_MMIO, 341 .host_flags = IDE_HFLAG_MMIO,
341 .pio_mask = ATA_PIO4, 342 .pio_mask = ATA_PIO4,
342 .udma_mask = ATA_UDMA4, /* (input clk 99MHz) */
343 .mwdma_mask = ATA_MWDMA2, 343 .mwdma_mask = ATA_MWDMA2,
344}; 344};
345 345
@@ -352,7 +352,7 @@ static int __devinit palm_bk3710_probe(struct platform_device *pdev)
352 int i, rc; 352 int i, rc;
353 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 353 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
354 354
355 clk = clk_get(NULL, "IDECLK"); 355 clk = clk_get(&pdev->dev, "IDECLK");
356 if (IS_ERR(clk)) 356 if (IS_ERR(clk))
357 return -ENODEV; 357 return -ENODEV;
358 358
@@ -392,6 +392,9 @@ static int __devinit palm_bk3710_probe(struct platform_device *pdev)
392 hw.irq = irq->start; 392 hw.irq = irq->start;
393 hw.chipset = ide_palm3710; 393 hw.chipset = ide_palm3710;
394 394
395 palm_bk3710_port_info.udma_mask = rate < 100000000 ? ATA_UDMA4 :
396 ATA_UDMA5;
397
395 rc = ide_host_add(&palm_bk3710_port_info, hws, NULL); 398 rc = ide_host_add(&palm_bk3710_port_info, hws, NULL);
396 if (rc) 399 if (rc)
397 goto out; 400 goto out;
diff --git a/drivers/ide/arm/rapide.c b/drivers/ide/arm/rapide.c
index 2bdd8b734afb..78d27d9ae430 100644
--- a/drivers/ide/arm/rapide.c
+++ b/drivers/ide/arm/rapide.c
@@ -95,7 +95,13 @@ static int __init rapide_init(void)
95 return ecard_register_driver(&rapide_driver); 95 return ecard_register_driver(&rapide_driver);
96} 96}
97 97
98static void __exit rapide_exit(void)
99{
100 ecard_unregister_driver(&rapide_driver);
101}
102
98MODULE_LICENSE("GPL"); 103MODULE_LICENSE("GPL");
99MODULE_DESCRIPTION("Yellowstone RAPIDE driver"); 104MODULE_DESCRIPTION("Yellowstone RAPIDE driver");
100 105
101module_init(rapide_init); 106module_init(rapide_init);
107module_exit(rapide_exit);
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 4e73aeee4053..e617cf08aef6 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -57,23 +57,29 @@ static DEFINE_MUTEX(idecd_ref_mutex);
57#define ide_cd_g(disk) \ 57#define ide_cd_g(disk) \
58 container_of((disk)->private_data, struct cdrom_info, driver) 58 container_of((disk)->private_data, struct cdrom_info, driver)
59 59
60static void ide_cd_release(struct kref *);
61
60static struct cdrom_info *ide_cd_get(struct gendisk *disk) 62static struct cdrom_info *ide_cd_get(struct gendisk *disk)
61{ 63{
62 struct cdrom_info *cd = NULL; 64 struct cdrom_info *cd = NULL;
63 65
64 mutex_lock(&idecd_ref_mutex); 66 mutex_lock(&idecd_ref_mutex);
65 cd = ide_cd_g(disk); 67 cd = ide_cd_g(disk);
66 if (cd) 68 if (cd) {
67 kref_get(&cd->kref); 69 kref_get(&cd->kref);
70 if (ide_device_get(cd->drive)) {
71 kref_put(&cd->kref, ide_cd_release);
72 cd = NULL;
73 }
74 }
68 mutex_unlock(&idecd_ref_mutex); 75 mutex_unlock(&idecd_ref_mutex);
69 return cd; 76 return cd;
70} 77}
71 78
72static void ide_cd_release(struct kref *);
73
74static void ide_cd_put(struct cdrom_info *cd) 79static void ide_cd_put(struct cdrom_info *cd)
75{ 80{
76 mutex_lock(&idecd_ref_mutex); 81 mutex_lock(&idecd_ref_mutex);
82 ide_device_put(cd->drive);
77 kref_put(&cd->kref, ide_cd_release); 83 kref_put(&cd->kref, ide_cd_release);
78 mutex_unlock(&idecd_ref_mutex); 84 mutex_unlock(&idecd_ref_mutex);
79} 85}
@@ -1305,13 +1311,30 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1305 1311
1306 stat = ide_cd_queue_pc(drive, cmd, 0, &capbuf, &len, sense, 0, 1312 stat = ide_cd_queue_pc(drive, cmd, 0, &capbuf, &len, sense, 0,
1307 REQ_QUIET); 1313 REQ_QUIET);
1308 if (stat == 0) { 1314 if (stat)
1309 *capacity = 1 + be32_to_cpu(capbuf.lba); 1315 return stat;
1310 *sectors_per_frame = 1316
1311 be32_to_cpu(capbuf.blocklen) >> SECTOR_BITS; 1317 /*
1318 * Sanity check the given block size
1319 */
1320 switch (capbuf.blocklen) {
1321 case __constant_cpu_to_be32(512):
1322 case __constant_cpu_to_be32(1024):
1323 case __constant_cpu_to_be32(2048):
1324 case __constant_cpu_to_be32(4096):
1325 break;
1326 default:
1327 printk(KERN_ERR "%s: weird block size %u\n",
1328 drive->name, capbuf.blocklen);
1329 printk(KERN_ERR "%s: default to 2kb block size\n",
1330 drive->name);
1331 capbuf.blocklen = __constant_cpu_to_be32(2048);
1332 break;
1312 } 1333 }
1313 1334
1314 return stat; 1335 *capacity = 1 + be32_to_cpu(capbuf.lba);
1336 *sectors_per_frame = be32_to_cpu(capbuf.blocklen) >> SECTOR_BITS;
1337 return 0;
1315} 1338}
1316 1339
1317static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag, 1340static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag,
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index df5fe5756871..28d85b410f7c 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -56,23 +56,29 @@ static DEFINE_MUTEX(idedisk_ref_mutex);
56#define ide_disk_g(disk) \ 56#define ide_disk_g(disk) \
57 container_of((disk)->private_data, struct ide_disk_obj, driver) 57 container_of((disk)->private_data, struct ide_disk_obj, driver)
58 58
59static void ide_disk_release(struct kref *);
60
59static struct ide_disk_obj *ide_disk_get(struct gendisk *disk) 61static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
60{ 62{
61 struct ide_disk_obj *idkp = NULL; 63 struct ide_disk_obj *idkp = NULL;
62 64
63 mutex_lock(&idedisk_ref_mutex); 65 mutex_lock(&idedisk_ref_mutex);
64 idkp = ide_disk_g(disk); 66 idkp = ide_disk_g(disk);
65 if (idkp) 67 if (idkp) {
66 kref_get(&idkp->kref); 68 kref_get(&idkp->kref);
69 if (ide_device_get(idkp->drive)) {
70 kref_put(&idkp->kref, ide_disk_release);
71 idkp = NULL;
72 }
73 }
67 mutex_unlock(&idedisk_ref_mutex); 74 mutex_unlock(&idedisk_ref_mutex);
68 return idkp; 75 return idkp;
69} 76}
70 77
71static void ide_disk_release(struct kref *);
72
73static void ide_disk_put(struct ide_disk_obj *idkp) 78static void ide_disk_put(struct ide_disk_obj *idkp)
74{ 79{
75 mutex_lock(&idedisk_ref_mutex); 80 mutex_lock(&idedisk_ref_mutex);
81 ide_device_put(idkp->drive);
76 kref_put(&idkp->kref, ide_disk_release); 82 kref_put(&idkp->kref, ide_disk_release);
77 mutex_unlock(&idedisk_ref_mutex); 83 mutex_unlock(&idedisk_ref_mutex);
78} 84}
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index be99d463dcc7..71c377a7bcf2 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -173,7 +173,7 @@ EXPORT_SYMBOL_GPL(ide_build_sglist);
173int ide_build_dmatable (ide_drive_t *drive, struct request *rq) 173int ide_build_dmatable (ide_drive_t *drive, struct request *rq)
174{ 174{
175 ide_hwif_t *hwif = HWIF(drive); 175 ide_hwif_t *hwif = HWIF(drive);
176 unsigned int *table = hwif->dmatable_cpu; 176 __le32 *table = (__le32 *)hwif->dmatable_cpu;
177 unsigned int is_trm290 = (hwif->chipset == ide_trm290) ? 1 : 0; 177 unsigned int is_trm290 = (hwif->chipset == ide_trm290) ? 1 : 0;
178 unsigned int count = 0; 178 unsigned int count = 0;
179 int i; 179 int i;
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 3d8e6dd0f41e..ca11a26746f1 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -158,23 +158,29 @@ static DEFINE_MUTEX(idefloppy_ref_mutex);
158#define ide_floppy_g(disk) \ 158#define ide_floppy_g(disk) \
159 container_of((disk)->private_data, struct ide_floppy_obj, driver) 159 container_of((disk)->private_data, struct ide_floppy_obj, driver)
160 160
161static void idefloppy_cleanup_obj(struct kref *);
162
161static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk) 163static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
162{ 164{
163 struct ide_floppy_obj *floppy = NULL; 165 struct ide_floppy_obj *floppy = NULL;
164 166
165 mutex_lock(&idefloppy_ref_mutex); 167 mutex_lock(&idefloppy_ref_mutex);
166 floppy = ide_floppy_g(disk); 168 floppy = ide_floppy_g(disk);
167 if (floppy) 169 if (floppy) {
168 kref_get(&floppy->kref); 170 kref_get(&floppy->kref);
171 if (ide_device_get(floppy->drive)) {
172 kref_put(&floppy->kref, idefloppy_cleanup_obj);
173 floppy = NULL;
174 }
175 }
169 mutex_unlock(&idefloppy_ref_mutex); 176 mutex_unlock(&idefloppy_ref_mutex);
170 return floppy; 177 return floppy;
171} 178}
172 179
173static void idefloppy_cleanup_obj(struct kref *);
174
175static void ide_floppy_put(struct ide_floppy_obj *floppy) 180static void ide_floppy_put(struct ide_floppy_obj *floppy)
176{ 181{
177 mutex_lock(&idefloppy_ref_mutex); 182 mutex_lock(&idefloppy_ref_mutex);
183 ide_device_put(floppy->drive);
178 kref_put(&floppy->kref, idefloppy_cleanup_obj); 184 kref_put(&floppy->kref, idefloppy_cleanup_obj);
179 mutex_unlock(&idefloppy_ref_mutex); 185 mutex_unlock(&idefloppy_ref_mutex);
180} 186}
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c
index 31d98fec775f..8fe8b5b9cf7d 100644
--- a/drivers/ide/ide-generic.c
+++ b/drivers/ide/ide-generic.c
@@ -20,6 +20,11 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/ide.h> 21#include <linux/ide.h>
22 22
23/* FIXME: convert m32r to use ide_platform host driver */
24#ifdef CONFIG_M32R
25#include <asm/m32r.h>
26#endif
27
23#define DRV_NAME "ide_generic" 28#define DRV_NAME "ide_generic"
24 29
25static int probe_mask = 0x03; 30static int probe_mask = 0x03;
@@ -80,6 +85,21 @@ static int __init ide_generic_sysfs_init(void)
80 return 0; 85 return 0;
81} 86}
82 87
88#if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_MAPPI2) \
89 || defined(CONFIG_PLAT_OPSPUT)
90static const u16 legacy_bases[] = { 0x1f0 };
91static const int legacy_irqs[] = { PLD_IRQ_CFIREQ };
92#elif defined(CONFIG_PLAT_MAPPI3)
93static const u16 legacy_bases[] = { 0x1f0, 0x170 };
94static const int legacy_irqs[] = { PLD_IRQ_CFIREQ, PLD_IRQ_IDEIREQ };
95#elif defined(CONFIG_ALPHA)
96static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168 };
97static const int legacy_irqs[] = { 14, 15, 11, 10 };
98#else
99static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
100static const int legacy_irqs[] = { 14, 15, 11, 10, 8, 12 };
101#endif
102
83static int __init ide_generic_init(void) 103static int __init ide_generic_init(void)
84{ 104{
85 hw_regs_t hw[MAX_HWIFS], *hws[MAX_HWIFS]; 105 hw_regs_t hw[MAX_HWIFS], *hws[MAX_HWIFS];
@@ -87,11 +107,17 @@ static int __init ide_generic_init(void)
87 unsigned long io_addr; 107 unsigned long io_addr;
88 int i, rc; 108 int i, rc;
89 109
110#ifdef CONFIG_MIPS
111 if (!ide_probe_legacy())
112 return -ENODEV;
113#endif
90 printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module " 114 printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module "
91 "parameter for probing all legacy ISA IDE ports\n"); 115 "parameter for probing all legacy ISA IDE ports\n");
92 116
93 for (i = 0; i < MAX_HWIFS; i++) { 117 memset(hws, 0, sizeof(hw_regs_t *) * MAX_HWIFS);
94 io_addr = ide_default_io_base(i); 118
119 for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
120 io_addr = legacy_bases[i];
95 121
96 hws[i] = NULL; 122 hws[i] = NULL;
97 123
@@ -113,7 +139,11 @@ static int __init ide_generic_init(void)
113 139
114 memset(&hw[i], 0, sizeof(hw[i])); 140 memset(&hw[i], 0, sizeof(hw[i]));
115 ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206); 141 ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206);
116 hw[i].irq = ide_default_irq(io_addr); 142#ifdef CONFIG_IA64
143 hw[i].irq = isa_irq_to_vector(legacy_irqs[i]);
144#else
145 hw[i].irq = legacy_irqs[i];
146#endif
117 hw[i].chipset = ide_generic; 147 hw[i].chipset = ide_generic;
118 148
119 hws[i] = &hw[i]; 149 hws[i] = &hw[i];
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 07da5fb9eaff..8aae91764513 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -510,10 +510,8 @@ void ide_fixstring (u8 *s, const int bytecount, const int byteswap)
510 510
511 if (byteswap) { 511 if (byteswap) {
512 /* convert from big-endian to host byte order */ 512 /* convert from big-endian to host byte order */
513 for (p = end ; p != s;) { 513 for (p = end ; p != s;)
514 unsigned short *pp = (unsigned short *) (p -= 2); 514 be16_to_cpus((u16 *)(p -= 2));
515 *pp = ntohs(*pp);
516 }
517 } 515 }
518 /* strip leading blanks */ 516 /* strip leading blanks */
519 while (s != end && *s == ' ') 517 while (s != end && *s == ' ')
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 4aa76c453755..994e41099b42 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -134,18 +134,6 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
134#endif 134#endif
135 ide_fix_driveid(id); 135 ide_fix_driveid(id);
136 136
137#if defined (CONFIG_SCSI_EATA_PIO) || defined (CONFIG_SCSI_EATA)
138 /*
139 * EATA SCSI controllers do a hardware ATA emulation:
140 * Ignore them if there is a driver for them available.
141 */
142 if ((id->model[0] == 'P' && id->model[1] == 'M') ||
143 (id->model[0] == 'S' && id->model[1] == 'K')) {
144 printk("%s: EATA SCSI HBA %.10s\n", drive->name, id->model);
145 goto err_misc;
146 }
147#endif /* CONFIG_SCSI_EATA || CONFIG_SCSI_EATA_PIO */
148
149 /* 137 /*
150 * WIN_IDENTIFY returns little-endian info, 138 * WIN_IDENTIFY returns little-endian info,
151 * WIN_PIDENTIFY *usually* returns little-endian info. 139 * WIN_PIDENTIFY *usually* returns little-endian info.
@@ -167,7 +155,8 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
167 if (strstr(id->model, "E X A B Y T E N E S T")) 155 if (strstr(id->model, "E X A B Y T E N E S T"))
168 goto err_misc; 156 goto err_misc;
169 157
170 printk("%s: %s, ", drive->name, id->model); 158 printk(KERN_INFO "%s: %s, ", drive->name, id->model);
159
171 drive->present = 1; 160 drive->present = 1;
172 drive->dead = 0; 161 drive->dead = 0;
173 162
@@ -176,16 +165,17 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
176 */ 165 */
177 if (cmd == WIN_PIDENTIFY) { 166 if (cmd == WIN_PIDENTIFY) {
178 u8 type = (id->config >> 8) & 0x1f; 167 u8 type = (id->config >> 8) & 0x1f;
179 printk("ATAPI "); 168
169 printk(KERN_CONT "ATAPI ");
180 switch (type) { 170 switch (type) {
181 case ide_floppy: 171 case ide_floppy:
182 if (!strstr(id->model, "CD-ROM")) { 172 if (!strstr(id->model, "CD-ROM")) {
183 if (!strstr(id->model, "oppy") && 173 if (!strstr(id->model, "oppy") &&
184 !strstr(id->model, "poyp") && 174 !strstr(id->model, "poyp") &&
185 !strstr(id->model, "ZIP")) 175 !strstr(id->model, "ZIP"))
186 printk("cdrom or floppy?, assuming "); 176 printk(KERN_CONT "cdrom or floppy?, assuming ");
187 if (drive->media != ide_cdrom) { 177 if (drive->media != ide_cdrom) {
188 printk ("FLOPPY"); 178 printk(KERN_CONT "FLOPPY");
189 drive->removable = 1; 179 drive->removable = 1;
190 break; 180 break;
191 } 181 }
@@ -198,25 +188,25 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
198 /* kludge for Apple PowerBook internal zip */ 188 /* kludge for Apple PowerBook internal zip */
199 if (!strstr(id->model, "CD-ROM") && 189 if (!strstr(id->model, "CD-ROM") &&
200 strstr(id->model, "ZIP")) { 190 strstr(id->model, "ZIP")) {
201 printk ("FLOPPY"); 191 printk(KERN_CONT "FLOPPY");
202 type = ide_floppy; 192 type = ide_floppy;
203 break; 193 break;
204 } 194 }
205#endif 195#endif
206 printk ("CD/DVD-ROM"); 196 printk(KERN_CONT "CD/DVD-ROM");
207 break; 197 break;
208 case ide_tape: 198 case ide_tape:
209 printk ("TAPE"); 199 printk(KERN_CONT "TAPE");
210 break; 200 break;
211 case ide_optical: 201 case ide_optical:
212 printk ("OPTICAL"); 202 printk(KERN_CONT "OPTICAL");
213 drive->removable = 1; 203 drive->removable = 1;
214 break; 204 break;
215 default: 205 default:
216 printk("UNKNOWN (type %d)", type); 206 printk(KERN_CONT "UNKNOWN (type %d)", type);
217 break; 207 break;
218 } 208 }
219 printk (" drive\n"); 209 printk(KERN_CONT " drive\n");
220 drive->media = type; 210 drive->media = type;
221 /* an ATAPI device ignores DRDY */ 211 /* an ATAPI device ignores DRDY */
222 drive->ready_stat = 0; 212 drive->ready_stat = 0;
@@ -236,7 +226,9 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
236 drive->removable = 1; 226 drive->removable = 1;
237 227
238 drive->media = ide_disk; 228 drive->media = ide_disk;
239 printk("%s DISK drive\n", (id->config == 0x848a) ? "CFA" : "ATA" ); 229
230 printk(KERN_CONT "%s DISK drive\n",
231 (id->config == 0x848a) ? "CFA" : "ATA");
240 232
241 return; 233 return;
242 234
@@ -387,7 +379,7 @@ static int try_to_identify (ide_drive_t *drive, u8 cmd)
387 /* Mmmm.. multiple IRQs.. 379 /* Mmmm.. multiple IRQs..
388 * don't know which was ours 380 * don't know which was ours
389 */ 381 */
390 printk("%s: IRQ probe failed (0x%lx)\n", 382 printk(KERN_ERR "%s: IRQ probe failed (0x%lx)\n",
391 drive->name, cookie); 383 drive->name, cookie);
392 } 384 }
393 } 385 }
@@ -456,7 +448,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
456 return 4; 448 return 4;
457 } 449 }
458#ifdef DEBUG 450#ifdef DEBUG
459 printk("probing for %s: present=%d, media=%d, probetype=%s\n", 451 printk(KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n",
460 drive->name, drive->present, drive->media, 452 drive->name, drive->present, drive->media,
461 (cmd == WIN_IDENTIFY) ? "ATA" : "ATAPI"); 453 (cmd == WIN_IDENTIFY) ? "ATA" : "ATAPI");
462#endif 454#endif
@@ -534,7 +526,8 @@ static void enable_nest (ide_drive_t *drive)
534 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 526 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
535 u8 stat; 527 u8 stat;
536 528
537 printk("%s: enabling %s -- ", hwif->name, drive->id->model); 529 printk(KERN_INFO "%s: enabling %s -- ", hwif->name, drive->id->model);
530
538 SELECT_DRIVE(drive); 531 SELECT_DRIVE(drive);
539 msleep(50); 532 msleep(50);
540 tp_ops->exec_command(hwif, EXABYTE_ENABLE_NEST); 533 tp_ops->exec_command(hwif, EXABYTE_ENABLE_NEST);
@@ -883,7 +876,7 @@ static void save_match(ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match)
883 if (m && m->hwgroup && m->hwgroup != new->hwgroup) { 876 if (m && m->hwgroup && m->hwgroup != new->hwgroup) {
884 if (!new->hwgroup) 877 if (!new->hwgroup)
885 return; 878 return;
886 printk("%s: potential irq problem with %s and %s\n", 879 printk(KERN_WARNING "%s: potential IRQ problem with %s and %s\n",
887 hwif->name, new->name, m->name); 880 hwif->name, new->name, m->name);
888 } 881 }
889 if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */ 882 if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */
@@ -1142,17 +1135,17 @@ static int init_irq (ide_hwif_t *hwif)
1142 } 1135 }
1143 1136
1144#if !defined(__mc68000__) 1137#if !defined(__mc68000__)
1145 printk("%s at 0x%03lx-0x%03lx,0x%03lx on irq %d", hwif->name, 1138 printk(KERN_INFO "%s at 0x%03lx-0x%03lx,0x%03lx on irq %d", hwif->name,
1146 io_ports->data_addr, io_ports->status_addr, 1139 io_ports->data_addr, io_ports->status_addr,
1147 io_ports->ctl_addr, hwif->irq); 1140 io_ports->ctl_addr, hwif->irq);
1148#else 1141#else
1149 printk("%s at 0x%08lx on irq %d", hwif->name, 1142 printk(KERN_INFO "%s at 0x%08lx on irq %d", hwif->name,
1150 io_ports->data_addr, hwif->irq); 1143 io_ports->data_addr, hwif->irq);
1151#endif /* __mc68000__ */ 1144#endif /* __mc68000__ */
1152 if (match) 1145 if (match)
1153 printk(" (%sed with %s)", 1146 printk(KERN_CONT " (%sed with %s)",
1154 hwif->sharing_irq ? "shar" : "serializ", match->name); 1147 hwif->sharing_irq ? "shar" : "serializ", match->name);
1155 printk("\n"); 1148 printk(KERN_CONT "\n");
1156 1149
1157 mutex_unlock(&ide_cfg_mtx); 1150 mutex_unlock(&ide_cfg_mtx);
1158 return 0; 1151 return 0;
@@ -1287,7 +1280,7 @@ static int hwif_init(ide_hwif_t *hwif)
1287 if (!hwif->irq) { 1280 if (!hwif->irq) {
1288 hwif->irq = __ide_default_irq(hwif->io_ports.data_addr); 1281 hwif->irq = __ide_default_irq(hwif->io_ports.data_addr);
1289 if (!hwif->irq) { 1282 if (!hwif->irq) {
1290 printk("%s: DISABLED, NO IRQ\n", hwif->name); 1283 printk(KERN_ERR "%s: disabled, no IRQ\n", hwif->name);
1291 return 0; 1284 return 0;
1292 } 1285 }
1293 } 1286 }
@@ -1317,16 +1310,16 @@ static int hwif_init(ide_hwif_t *hwif)
1317 */ 1310 */
1318 hwif->irq = __ide_default_irq(hwif->io_ports.data_addr); 1311 hwif->irq = __ide_default_irq(hwif->io_ports.data_addr);
1319 if (!hwif->irq) { 1312 if (!hwif->irq) {
1320 printk("%s: Disabled unable to get IRQ %d.\n", 1313 printk(KERN_ERR "%s: disabled, unable to get IRQ %d\n",
1321 hwif->name, old_irq); 1314 hwif->name, old_irq);
1322 goto out; 1315 goto out;
1323 } 1316 }
1324 if (init_irq(hwif)) { 1317 if (init_irq(hwif)) {
1325 printk("%s: probed IRQ %d and default IRQ %d failed.\n", 1318 printk(KERN_ERR "%s: probed IRQ %d and default IRQ %d failed\n",
1326 hwif->name, old_irq, hwif->irq); 1319 hwif->name, old_irq, hwif->irq);
1327 goto out; 1320 goto out;
1328 } 1321 }
1329 printk("%s: probed IRQ %d failed, using default.\n", 1322 printk(KERN_WARNING "%s: probed IRQ %d failed, using default\n",
1330 hwif->name, hwif->irq); 1323 hwif->name, hwif->irq);
1331 1324
1332done: 1325done:
@@ -1595,6 +1588,8 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
1595 1588
1596 ide_init_port_data(hwif, idx); 1589 ide_init_port_data(hwif, idx);
1597 1590
1591 hwif->host = host;
1592
1598 host->ports[i] = hwif; 1593 host->ports[i] = hwif;
1599 host->n_ports++; 1594 host->n_ports++;
1600 } 1595 }
@@ -1604,6 +1599,12 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
1604 return NULL; 1599 return NULL;
1605 } 1600 }
1606 1601
1602 if (hws[0])
1603 host->dev[0] = hws[0]->dev;
1604
1605 if (d)
1606 host->host_flags = d->host_flags;
1607
1607 return host; 1608 return host;
1608} 1609}
1609EXPORT_SYMBOL_GPL(ide_host_alloc_all); 1610EXPORT_SYMBOL_GPL(ide_host_alloc_all);
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index 151c91e933da..f66c9c3f6fc6 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -105,7 +105,7 @@ static int proc_ide_read_identify
105 len = sprintf(page, "\n"); 105 len = sprintf(page, "\n");
106 106
107 if (drive) { 107 if (drive) {
108 unsigned short *val = (unsigned short *) page; 108 __le16 *val = (__le16 *)page;
109 109
110 err = taskfile_lib_get_identify(drive, page); 110 err = taskfile_lib_get_identify(drive, page);
111 if (!err) { 111 if (!err) {
@@ -113,7 +113,7 @@ static int proc_ide_read_identify
113 page = out; 113 page = out;
114 do { 114 do {
115 out += sprintf(out, "%04x%c", 115 out += sprintf(out, "%04x%c",
116 le16_to_cpu(*val), (++i & 7) ? ' ' : '\n'); 116 le16_to_cpup(val), (++i & 7) ? ' ' : '\n');
117 val += 1; 117 val += 1;
118 } while (i < (SECTOR_WORDS * 2)); 118 } while (i < (SECTOR_WORDS * 2));
119 len = out - page; 119 len = out - page;
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 6962ca4891a1..82c2afe4d28a 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -322,23 +322,29 @@ static struct class *idetape_sysfs_class;
322#define ide_tape_g(disk) \ 322#define ide_tape_g(disk) \
323 container_of((disk)->private_data, struct ide_tape_obj, driver) 323 container_of((disk)->private_data, struct ide_tape_obj, driver)
324 324
325static void ide_tape_release(struct kref *);
326
325static struct ide_tape_obj *ide_tape_get(struct gendisk *disk) 327static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
326{ 328{
327 struct ide_tape_obj *tape = NULL; 329 struct ide_tape_obj *tape = NULL;
328 330
329 mutex_lock(&idetape_ref_mutex); 331 mutex_lock(&idetape_ref_mutex);
330 tape = ide_tape_g(disk); 332 tape = ide_tape_g(disk);
331 if (tape) 333 if (tape) {
332 kref_get(&tape->kref); 334 kref_get(&tape->kref);
335 if (ide_device_get(tape->drive)) {
336 kref_put(&tape->kref, ide_tape_release);
337 tape = NULL;
338 }
339 }
333 mutex_unlock(&idetape_ref_mutex); 340 mutex_unlock(&idetape_ref_mutex);
334 return tape; 341 return tape;
335} 342}
336 343
337static void ide_tape_release(struct kref *);
338
339static void ide_tape_put(struct ide_tape_obj *tape) 344static void ide_tape_put(struct ide_tape_obj *tape)
340{ 345{
341 mutex_lock(&idetape_ref_mutex); 346 mutex_lock(&idetape_ref_mutex);
347 ide_device_put(tape->drive);
342 kref_put(&tape->kref, ide_tape_release); 348 kref_put(&tape->kref, ide_tape_release);
343 mutex_unlock(&idetape_ref_mutex); 349 mutex_unlock(&idetape_ref_mutex);
344} 350}
@@ -649,10 +655,10 @@ static void ide_tape_callback(ide_drive_t *drive)
649 uptodate = 0; 655 uptodate = 0;
650 } else { 656 } else {
651 debug_log(DBG_SENSE, "Block Location - %u\n", 657 debug_log(DBG_SENSE, "Block Location - %u\n",
652 be32_to_cpu(*(u32 *)&readpos[4])); 658 be32_to_cpup((__be32 *)&readpos[4]));
653 659
654 tape->partition = readpos[1]; 660 tape->partition = readpos[1];
655 tape->first_frame = be32_to_cpu(*(u32 *)&readpos[4]); 661 tape->first_frame = be32_to_cpup((__be32 *)&readpos[4]);
656 set_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags); 662 set_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags);
657 } 663 }
658 } 664 }
@@ -2375,23 +2381,23 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
2375 caps = pc.buf + 4 + pc.buf[3]; 2381 caps = pc.buf + 4 + pc.buf[3];
2376 2382
2377 /* convert to host order and save for later use */ 2383 /* convert to host order and save for later use */
2378 speed = be16_to_cpu(*(u16 *)&caps[14]); 2384 speed = be16_to_cpup((__be16 *)&caps[14]);
2379 max_speed = be16_to_cpu(*(u16 *)&caps[8]); 2385 max_speed = be16_to_cpup((__be16 *)&caps[8]);
2380 2386
2381 put_unaligned(max_speed, (u16 *)&caps[8]); 2387 *(u16 *)&caps[8] = max_speed;
2382 put_unaligned(be16_to_cpu(*(u16 *)&caps[12]), (u16 *)&caps[12]); 2388 *(u16 *)&caps[12] = be16_to_cpup((__be16 *)&caps[12]);
2383 put_unaligned(speed, (u16 *)&caps[14]); 2389 *(u16 *)&caps[14] = speed;
2384 put_unaligned(be16_to_cpu(*(u16 *)&caps[16]), (u16 *)&caps[16]); 2390 *(u16 *)&caps[16] = be16_to_cpup((__be16 *)&caps[16]);
2385 2391
2386 if (!speed) { 2392 if (!speed) {
2387 printk(KERN_INFO "ide-tape: %s: invalid tape speed " 2393 printk(KERN_INFO "ide-tape: %s: invalid tape speed "
2388 "(assuming 650KB/sec)\n", drive->name); 2394 "(assuming 650KB/sec)\n", drive->name);
2389 put_unaligned(650, (u16 *)&caps[14]); 2395 *(u16 *)&caps[14] = 650;
2390 } 2396 }
2391 if (!max_speed) { 2397 if (!max_speed) {
2392 printk(KERN_INFO "ide-tape: %s: invalid max_speed " 2398 printk(KERN_INFO "ide-tape: %s: invalid max_speed "
2393 "(assuming 650KB/sec)\n", drive->name); 2399 "(assuming 650KB/sec)\n", drive->name);
2394 put_unaligned(650, (u16 *)&caps[8]); 2400 *(u16 *)&caps[8] = 650;
2395 } 2401 }
2396 2402
2397 memcpy(&tape->caps, caps, 20); 2403 memcpy(&tape->caps, caps, 20);
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index aeddbbd69e86..7fb6f1c86272 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -126,7 +126,10 @@ EXPORT_SYMBOL_GPL(do_rw_taskfile);
126static ide_startstop_t set_multmode_intr(ide_drive_t *drive) 126static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
127{ 127{
128 ide_hwif_t *hwif = drive->hwif; 128 ide_hwif_t *hwif = drive->hwif;
129 u8 stat = hwif->tp_ops->read_status(hwif); 129 u8 stat;
130
131 local_irq_enable_in_hardirq();
132 stat = hwif->tp_ops->read_status(hwif);
130 133
131 if (OK_STAT(stat, READY_STAT, BAD_STAT)) 134 if (OK_STAT(stat, READY_STAT, BAD_STAT))
132 drive->mult_count = drive->mult_req; 135 drive->mult_count = drive->mult_req;
@@ -147,6 +150,8 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
147 int retries = 5; 150 int retries = 5;
148 u8 stat; 151 u8 stat;
149 152
153 local_irq_enable_in_hardirq();
154
150 while (1) { 155 while (1) {
151 stat = hwif->tp_ops->read_status(hwif); 156 stat = hwif->tp_ops->read_status(hwif);
152 if ((stat & BUSY_STAT) == 0 || retries-- == 0) 157 if ((stat & BUSY_STAT) == 0 || retries-- == 0)
@@ -170,7 +175,10 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
170static ide_startstop_t recal_intr(ide_drive_t *drive) 175static ide_startstop_t recal_intr(ide_drive_t *drive)
171{ 176{
172 ide_hwif_t *hwif = drive->hwif; 177 ide_hwif_t *hwif = drive->hwif;
173 u8 stat = hwif->tp_ops->read_status(hwif); 178 u8 stat;
179
180 local_irq_enable_in_hardirq();
181 stat = hwif->tp_ops->read_status(hwif);
174 182
175 if (!OK_STAT(stat, READY_STAT, BAD_STAT)) 183 if (!OK_STAT(stat, READY_STAT, BAD_STAT))
176 return ide_error(drive, "recal_intr", stat); 184 return ide_error(drive, "recal_intr", stat);
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 60f0ca66aa93..772451600e4d 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -618,6 +618,53 @@ set_val:
618 618
619EXPORT_SYMBOL(generic_ide_ioctl); 619EXPORT_SYMBOL(generic_ide_ioctl);
620 620
621/**
622 * ide_device_get - get an additional reference to a ide_drive_t
623 * @drive: device to get a reference to
624 *
625 * Gets a reference to the ide_drive_t and increments the use count of the
626 * underlying LLDD module.
627 */
628int ide_device_get(ide_drive_t *drive)
629{
630 struct device *host_dev;
631 struct module *module;
632
633 if (!get_device(&drive->gendev))
634 return -ENXIO;
635
636 host_dev = drive->hwif->host->dev[0];
637 module = host_dev ? host_dev->driver->owner : NULL;
638
639 if (module && !try_module_get(module)) {
640 put_device(&drive->gendev);
641 return -ENXIO;
642 }
643
644 return 0;
645}
646EXPORT_SYMBOL_GPL(ide_device_get);
647
648/**
649 * ide_device_put - release a reference to a ide_drive_t
650 * @drive: device to release a reference on
651 *
652 * Release a reference to the ide_drive_t and decrements the use count of
653 * the underlying LLDD module.
654 */
655void ide_device_put(ide_drive_t *drive)
656{
657#ifdef CONFIG_MODULE_UNLOAD
658 struct device *host_dev = drive->hwif->host->dev[0];
659 struct module *module = host_dev ? host_dev->driver->owner : NULL;
660
661 if (module)
662 module_put(module);
663#endif
664 put_device(&drive->gendev);
665}
666EXPORT_SYMBOL_GPL(ide_device_put);
667
621static int ide_bus_match(struct device *dev, struct device_driver *drv) 668static int ide_bus_match(struct device *dev, struct device_driver *drv)
622{ 669{
623 return 1; 670 return 1;
diff --git a/drivers/ide/legacy/gayle.c b/drivers/ide/legacy/gayle.c
index dd5c467d8dd0..51ba085d7aa8 100644
--- a/drivers/ide/legacy/gayle.c
+++ b/drivers/ide/legacy/gayle.c
@@ -127,7 +127,7 @@ static int __init gayle_init(void)
127 unsigned long phys_base, res_start, res_n; 127 unsigned long phys_base, res_start, res_n;
128 unsigned long base, ctrlport, irqport; 128 unsigned long base, ctrlport, irqport;
129 ide_ack_intr_t *ack_intr; 129 ide_ack_intr_t *ack_intr;
130 int a4000, i; 130 int a4000, i, rc;
131 hw_regs_t hw[GAYLE_NUM_HWIFS], *hws[] = { NULL, NULL, NULL, NULL }; 131 hw_regs_t hw[GAYLE_NUM_HWIFS], *hws[] = { NULL, NULL, NULL, NULL };
132 132
133 if (!MACH_IS_AMIGA) 133 if (!MACH_IS_AMIGA)
@@ -179,7 +179,11 @@ found:
179 hws[i] = &hw[i]; 179 hws[i] = &hw[i];
180 } 180 }
181 181
182 return ide_host_add(NULL, hws, NULL); 182 rc = ide_host_add(NULL, hws, NULL);
183 if (rc)
184 release_mem_region(res_start, res_n);
185
186 return rc;
183} 187}
184 188
185module_init(gayle_init); 189module_init(gayle_init);
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c
index 7bc8fd59ea9e..98f7c95e39ed 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/legacy/ht6560b.c
@@ -3,34 +3,12 @@
3 */ 3 */
4 4
5/* 5/*
6 *
7 * Version 0.01 Initial version hacked out of ide.c
8 *
9 * Version 0.02 Added support for PIO modes, auto-tune
10 *
11 * Version 0.03 Some cleanups
12 *
13 * Version 0.05 PIO mode cycle timings auto-tune using bus-speed
14 *
15 * Version 0.06 Prefetch mode now defaults no OFF. To set
16 * prefetch mode OFF/ON use "hdparm -p8/-p9".
17 * Unmask irq is disabled when prefetch mode
18 * is enabled.
19 *
20 * Version 0.07 Trying to fix CD-ROM detection problem.
21 * "Prefetch" mode bit OFF for ide disks and
22 * ON for anything else.
23 *
24 * Version 0.08 Need to force prefetch for CDs and other non-disk
25 * devices. (not sure which devices exactly need
26 * prefetch)
27 *
28 * HT-6560B EIDE-controller support 6 * HT-6560B EIDE-controller support
29 * To activate controller support use kernel parameter "ide0=ht6560b". 7 * To activate controller support use kernel parameter "ide0=ht6560b".
30 * Use hdparm utility to enable PIO mode support. 8 * Use hdparm utility to enable PIO mode support.
31 * 9 *
32 * Author: Mikko Ala-Fossi <maf@iki.fi> 10 * Author: Mikko Ala-Fossi <maf@iki.fi>
33 * Jan Evert van Grootheest <janevert@caiway.nl> 11 * Jan Evert van Grootheest <j.e.van.grootheest@caiway.nl>
34 * 12 *
35 * Try: http://www.maf.iki.fi/~maf/ht6560b/ 13 * Try: http://www.maf.iki.fi/~maf/ht6560b/
36 */ 14 */
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index fbc43e121e6b..e0c8fe7d9fea 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -13,6 +13,8 @@
13 13
14#include <asm/io.h> 14#include <asm/io.h>
15 15
16#define DRV_NAME "aec62xx"
17
16struct chipset_bus_clock_list_entry { 18struct chipset_bus_clock_list_entry {
17 u8 xfer_speed; 19 u8 xfer_speed;
18 u8 chipset_settings; 20 u8 chipset_settings;
@@ -59,10 +61,6 @@ static const struct chipset_bus_clock_list_entry aec6xxx_34_base [] = {
59 { 0, 0x00, 0x00 } 61 { 0, 0x00, 0x00 }
60}; 62};
61 63
62#define BUSCLOCK(D) \
63 ((struct chipset_bus_clock_list_entry *) pci_get_drvdata((D)))
64
65
66/* 64/*
67 * TO DO: active tuning and correction of cards without a bios. 65 * TO DO: active tuning and correction of cards without a bios.
68 */ 66 */
@@ -88,6 +86,8 @@ static void aec6210_set_mode(ide_drive_t *drive, const u8 speed)
88{ 86{
89 ide_hwif_t *hwif = HWIF(drive); 87 ide_hwif_t *hwif = HWIF(drive);
90 struct pci_dev *dev = to_pci_dev(hwif->dev); 88 struct pci_dev *dev = to_pci_dev(hwif->dev);
89 struct ide_host *host = pci_get_drvdata(dev);
90 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv;
91 u16 d_conf = 0; 91 u16 d_conf = 0;
92 u8 ultra = 0, ultra_conf = 0; 92 u8 ultra = 0, ultra_conf = 0;
93 u8 tmp0 = 0, tmp1 = 0, tmp2 = 0; 93 u8 tmp0 = 0, tmp1 = 0, tmp2 = 0;
@@ -96,7 +96,7 @@ static void aec6210_set_mode(ide_drive_t *drive, const u8 speed)
96 local_irq_save(flags); 96 local_irq_save(flags);
97 /* 0x40|(2*drive->dn): Active, 0x41|(2*drive->dn): Recovery */ 97 /* 0x40|(2*drive->dn): Active, 0x41|(2*drive->dn): Recovery */
98 pci_read_config_word(dev, 0x40|(2*drive->dn), &d_conf); 98 pci_read_config_word(dev, 0x40|(2*drive->dn), &d_conf);
99 tmp0 = pci_bus_clock_list(speed, BUSCLOCK(dev)); 99 tmp0 = pci_bus_clock_list(speed, bus_clock);
100 d_conf = ((tmp0 & 0xf0) << 4) | (tmp0 & 0xf); 100 d_conf = ((tmp0 & 0xf0) << 4) | (tmp0 & 0xf);
101 pci_write_config_word(dev, 0x40|(2*drive->dn), d_conf); 101 pci_write_config_word(dev, 0x40|(2*drive->dn), d_conf);
102 102
@@ -104,7 +104,7 @@ static void aec6210_set_mode(ide_drive_t *drive, const u8 speed)
104 tmp2 = 0x00; 104 tmp2 = 0x00;
105 pci_read_config_byte(dev, 0x54, &ultra); 105 pci_read_config_byte(dev, 0x54, &ultra);
106 tmp1 = ((0x00 << (2*drive->dn)) | (ultra & ~(3 << (2*drive->dn)))); 106 tmp1 = ((0x00 << (2*drive->dn)) | (ultra & ~(3 << (2*drive->dn))));
107 ultra_conf = pci_bus_clock_list_ultra(speed, BUSCLOCK(dev)); 107 ultra_conf = pci_bus_clock_list_ultra(speed, bus_clock);
108 tmp2 = ((ultra_conf << (2*drive->dn)) | (tmp1 & ~(3 << (2*drive->dn)))); 108 tmp2 = ((ultra_conf << (2*drive->dn)) | (tmp1 & ~(3 << (2*drive->dn))));
109 pci_write_config_byte(dev, 0x54, tmp2); 109 pci_write_config_byte(dev, 0x54, tmp2);
110 local_irq_restore(flags); 110 local_irq_restore(flags);
@@ -114,6 +114,8 @@ static void aec6260_set_mode(ide_drive_t *drive, const u8 speed)
114{ 114{
115 ide_hwif_t *hwif = HWIF(drive); 115 ide_hwif_t *hwif = HWIF(drive);
116 struct pci_dev *dev = to_pci_dev(hwif->dev); 116 struct pci_dev *dev = to_pci_dev(hwif->dev);
117 struct ide_host *host = pci_get_drvdata(dev);
118 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv;
117 u8 unit = (drive->select.b.unit & 0x01); 119 u8 unit = (drive->select.b.unit & 0x01);
118 u8 tmp1 = 0, tmp2 = 0; 120 u8 tmp1 = 0, tmp2 = 0;
119 u8 ultra = 0, drive_conf = 0, ultra_conf = 0; 121 u8 ultra = 0, drive_conf = 0, ultra_conf = 0;
@@ -122,12 +124,12 @@ static void aec6260_set_mode(ide_drive_t *drive, const u8 speed)
122 local_irq_save(flags); 124 local_irq_save(flags);
123 /* high 4-bits: Active, low 4-bits: Recovery */ 125 /* high 4-bits: Active, low 4-bits: Recovery */
124 pci_read_config_byte(dev, 0x40|drive->dn, &drive_conf); 126 pci_read_config_byte(dev, 0x40|drive->dn, &drive_conf);
125 drive_conf = pci_bus_clock_list(speed, BUSCLOCK(dev)); 127 drive_conf = pci_bus_clock_list(speed, bus_clock);
126 pci_write_config_byte(dev, 0x40|drive->dn, drive_conf); 128 pci_write_config_byte(dev, 0x40|drive->dn, drive_conf);
127 129
128 pci_read_config_byte(dev, (0x44|hwif->channel), &ultra); 130 pci_read_config_byte(dev, (0x44|hwif->channel), &ultra);
129 tmp1 = ((0x00 << (4*unit)) | (ultra & ~(7 << (4*unit)))); 131 tmp1 = ((0x00 << (4*unit)) | (ultra & ~(7 << (4*unit))));
130 ultra_conf = pci_bus_clock_list_ultra(speed, BUSCLOCK(dev)); 132 ultra_conf = pci_bus_clock_list_ultra(speed, bus_clock);
131 tmp2 = ((ultra_conf << (4*unit)) | (tmp1 & ~(7 << (4*unit)))); 133 tmp2 = ((ultra_conf << (4*unit)) | (tmp1 & ~(7 << (4*unit))));
132 pci_write_config_byte(dev, (0x44|hwif->channel), tmp2); 134 pci_write_config_byte(dev, (0x44|hwif->channel), tmp2);
133 local_irq_restore(flags); 135 local_irq_restore(flags);
@@ -138,15 +140,8 @@ static void aec_set_pio_mode(ide_drive_t *drive, const u8 pio)
138 drive->hwif->port_ops->set_dma_mode(drive, pio + XFER_PIO_0); 140 drive->hwif->port_ops->set_dma_mode(drive, pio + XFER_PIO_0);
139} 141}
140 142
141static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev, const char *name) 143static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev)
142{ 144{
143 int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
144
145 if (bus_speed <= 33)
146 pci_set_drvdata(dev, (void *) aec6xxx_33_base);
147 else
148 pci_set_drvdata(dev, (void *) aec6xxx_34_base);
149
150 /* These are necessary to get AEC6280 Macintosh cards to work */ 145 /* These are necessary to get AEC6280 Macintosh cards to work */
151 if ((dev->device == PCI_DEVICE_ID_ARTOP_ATP865) || 146 if ((dev->device == PCI_DEVICE_ID_ARTOP_ATP865) ||
152 (dev->device == PCI_DEVICE_ID_ARTOP_ATP865R)) { 147 (dev->device == PCI_DEVICE_ID_ARTOP_ATP865R)) {
@@ -187,8 +182,8 @@ static const struct ide_port_ops atp86x_port_ops = {
187}; 182};
188 183
189static const struct ide_port_info aec62xx_chipsets[] __devinitdata = { 184static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
190 { /* 0 */ 185 { /* 0: AEC6210 */
191 .name = "AEC6210", 186 .name = DRV_NAME,
192 .init_chipset = init_chipset_aec62xx, 187 .init_chipset = init_chipset_aec62xx,
193 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 188 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
194 .port_ops = &atp850_port_ops, 189 .port_ops = &atp850_port_ops,
@@ -199,8 +194,9 @@ static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
199 .pio_mask = ATA_PIO4, 194 .pio_mask = ATA_PIO4,
200 .mwdma_mask = ATA_MWDMA2, 195 .mwdma_mask = ATA_MWDMA2,
201 .udma_mask = ATA_UDMA2, 196 .udma_mask = ATA_UDMA2,
202 },{ /* 1 */ 197 },
203 .name = "AEC6260", 198 { /* 1: AEC6260 */
199 .name = DRV_NAME,
204 .init_chipset = init_chipset_aec62xx, 200 .init_chipset = init_chipset_aec62xx,
205 .port_ops = &atp86x_port_ops, 201 .port_ops = &atp86x_port_ops,
206 .host_flags = IDE_HFLAG_NO_ATAPI_DMA | IDE_HFLAG_NO_AUTODMA | 202 .host_flags = IDE_HFLAG_NO_ATAPI_DMA | IDE_HFLAG_NO_AUTODMA |
@@ -208,8 +204,9 @@ static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
208 .pio_mask = ATA_PIO4, 204 .pio_mask = ATA_PIO4,
209 .mwdma_mask = ATA_MWDMA2, 205 .mwdma_mask = ATA_MWDMA2,
210 .udma_mask = ATA_UDMA4, 206 .udma_mask = ATA_UDMA4,
211 },{ /* 2 */ 207 },
212 .name = "AEC6260R", 208 { /* 2: AEC6260R */
209 .name = DRV_NAME,
213 .init_chipset = init_chipset_aec62xx, 210 .init_chipset = init_chipset_aec62xx,
214 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 211 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
215 .port_ops = &atp86x_port_ops, 212 .port_ops = &atp86x_port_ops,
@@ -218,8 +215,9 @@ static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
218 .pio_mask = ATA_PIO4, 215 .pio_mask = ATA_PIO4,
219 .mwdma_mask = ATA_MWDMA2, 216 .mwdma_mask = ATA_MWDMA2,
220 .udma_mask = ATA_UDMA4, 217 .udma_mask = ATA_UDMA4,
221 },{ /* 3 */ 218 },
222 .name = "AEC6280", 219 { /* 3: AEC6280 */
220 .name = DRV_NAME,
223 .init_chipset = init_chipset_aec62xx, 221 .init_chipset = init_chipset_aec62xx,
224 .port_ops = &atp86x_port_ops, 222 .port_ops = &atp86x_port_ops,
225 .host_flags = IDE_HFLAG_NO_ATAPI_DMA | 223 .host_flags = IDE_HFLAG_NO_ATAPI_DMA |
@@ -227,8 +225,9 @@ static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
227 .pio_mask = ATA_PIO4, 225 .pio_mask = ATA_PIO4,
228 .mwdma_mask = ATA_MWDMA2, 226 .mwdma_mask = ATA_MWDMA2,
229 .udma_mask = ATA_UDMA5, 227 .udma_mask = ATA_UDMA5,
230 },{ /* 4 */ 228 },
231 .name = "AEC6280R", 229 { /* 4: AEC6280R */
230 .name = DRV_NAME,
232 .init_chipset = init_chipset_aec62xx, 231 .init_chipset = init_chipset_aec62xx,
233 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 232 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
234 .port_ops = &atp86x_port_ops, 233 .port_ops = &atp86x_port_ops,
@@ -254,10 +253,17 @@ static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
254 253
255static int __devinit aec62xx_init_one(struct pci_dev *dev, const struct pci_device_id *id) 254static int __devinit aec62xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
256{ 255{
256 const struct chipset_bus_clock_list_entry *bus_clock;
257 struct ide_port_info d; 257 struct ide_port_info d;
258 u8 idx = id->driver_data; 258 u8 idx = id->driver_data;
259 int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
259 int err; 260 int err;
260 261
262 if (bus_speed <= 33)
263 bus_clock = aec6xxx_33_base;
264 else
265 bus_clock = aec6xxx_34_base;
266
261 err = pci_enable_device(dev); 267 err = pci_enable_device(dev);
262 if (err) 268 if (err)
263 return err; 269 return err;
@@ -268,18 +274,25 @@ static int __devinit aec62xx_init_one(struct pci_dev *dev, const struct pci_devi
268 unsigned long dma_base = pci_resource_start(dev, 4); 274 unsigned long dma_base = pci_resource_start(dev, 4);
269 275
270 if (inb(dma_base + 2) & 0x10) { 276 if (inb(dma_base + 2) & 0x10) {
271 d.name = (idx == 4) ? "AEC6880R" : "AEC6880"; 277 printk(KERN_INFO DRV_NAME " %s: AEC6880%s card detected"
278 "\n", pci_name(dev), (idx == 4) ? "R" : "");
272 d.udma_mask = ATA_UDMA6; 279 d.udma_mask = ATA_UDMA6;
273 } 280 }
274 } 281 }
275 282
276 err = ide_setup_pci_device(dev, &d); 283 err = ide_pci_init_one(dev, &d, (void *)bus_clock);
277 if (err) 284 if (err)
278 pci_disable_device(dev); 285 pci_disable_device(dev);
279 286
280 return err; 287 return err;
281} 288}
282 289
290static void __devexit aec62xx_remove(struct pci_dev *dev)
291{
292 ide_pci_remove(dev);
293 pci_disable_device(dev);
294}
295
283static const struct pci_device_id aec62xx_pci_tbl[] = { 296static const struct pci_device_id aec62xx_pci_tbl[] = {
284 { PCI_VDEVICE(ARTOP, PCI_DEVICE_ID_ARTOP_ATP850UF), 0 }, 297 { PCI_VDEVICE(ARTOP, PCI_DEVICE_ID_ARTOP_ATP850UF), 0 },
285 { PCI_VDEVICE(ARTOP, PCI_DEVICE_ID_ARTOP_ATP860), 1 }, 298 { PCI_VDEVICE(ARTOP, PCI_DEVICE_ID_ARTOP_ATP860), 1 },
@@ -294,6 +307,7 @@ static struct pci_driver driver = {
294 .name = "AEC62xx_IDE", 307 .name = "AEC62xx_IDE",
295 .id_table = aec62xx_pci_tbl, 308 .id_table = aec62xx_pci_tbl,
296 .probe = aec62xx_init_one, 309 .probe = aec62xx_init_one,
310 .remove = aec62xx_remove,
297}; 311};
298 312
299static int __init aec62xx_ide_init(void) 313static int __init aec62xx_ide_init(void)
@@ -301,7 +315,13 @@ static int __init aec62xx_ide_init(void)
301 return ide_pci_register_driver(&driver); 315 return ide_pci_register_driver(&driver);
302} 316}
303 317
318static void __exit aec62xx_ide_exit(void)
319{
320 pci_unregister_driver(&driver);
321}
322
304module_init(aec62xx_ide_init); 323module_init(aec62xx_ide_init);
324module_exit(aec62xx_ide_exit);
305 325
306MODULE_AUTHOR("Andre Hedrick"); 326MODULE_AUTHOR("Andre Hedrick");
307MODULE_DESCRIPTION("PCI driver module for ARTOP AEC62xx IDE"); 327MODULE_DESCRIPTION("PCI driver module for ARTOP AEC62xx IDE");
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 5ef7817ac64f..b582687e0cd4 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -38,6 +38,8 @@
38 38
39#include <asm/io.h> 39#include <asm/io.h>
40 40
41#define DRV_NAME "alim15x3"
42
41/* 43/*
42 * Allow UDMA on M1543C-E chipset for WDC disks that ignore CRC checking 44 * Allow UDMA on M1543C-E chipset for WDC disks that ignore CRC checking
43 * (this is DANGEROUS and could result in data corruption). 45 * (this is DANGEROUS and could result in data corruption).
@@ -207,13 +209,12 @@ static int ali15x3_dma_setup(ide_drive_t *drive)
207/** 209/**
208 * init_chipset_ali15x3 - Initialise an ALi IDE controller 210 * init_chipset_ali15x3 - Initialise an ALi IDE controller
209 * @dev: PCI device 211 * @dev: PCI device
210 * @name: Name of the controller
211 * 212 *
212 * This function initializes the ALI IDE controller and where 213 * This function initializes the ALI IDE controller and where
213 * appropriate also sets up the 1533 southbridge. 214 * appropriate also sets up the 1533 southbridge.
214 */ 215 */
215 216
216static unsigned int __devinit init_chipset_ali15x3 (struct pci_dev *dev, const char *name) 217static unsigned int __devinit init_chipset_ali15x3(struct pci_dev *dev)
217{ 218{
218 unsigned long flags; 219 unsigned long flags;
219 u8 tmpbyte; 220 u8 tmpbyte;
@@ -515,7 +516,7 @@ static const struct ide_dma_ops ali_dma_ops = {
515}; 516};
516 517
517static const struct ide_port_info ali15x3_chipset __devinitdata = { 518static const struct ide_port_info ali15x3_chipset __devinitdata = {
518 .name = "ALI15X3", 519 .name = DRV_NAME,
519 .init_chipset = init_chipset_ali15x3, 520 .init_chipset = init_chipset_ali15x3,
520 .init_hwif = init_hwif_ali15x3, 521 .init_hwif = init_hwif_ali15x3,
521 .init_dma = init_dma_ali15x3, 522 .init_dma = init_dma_ali15x3,
@@ -565,7 +566,7 @@ static int __devinit alim15x3_init_one(struct pci_dev *dev, const struct pci_dev
565 if (idx == 0) 566 if (idx == 0)
566 d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX; 567 d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX;
567 568
568 return ide_setup_pci_device(dev, &d); 569 return ide_pci_init_one(dev, &d, NULL);
569} 570}
570 571
571 572
@@ -580,6 +581,7 @@ static struct pci_driver driver = {
580 .name = "ALI15x3_IDE", 581 .name = "ALI15x3_IDE",
581 .id_table = alim15x3_pci_tbl, 582 .id_table = alim15x3_pci_tbl,
582 .probe = alim15x3_init_one, 583 .probe = alim15x3_init_one,
584 .remove = ide_pci_remove,
583}; 585};
584 586
585static int __init ali15x3_ide_init(void) 587static int __init ali15x3_ide_init(void)
@@ -587,7 +589,13 @@ static int __init ali15x3_ide_init(void)
587 return ide_pci_register_driver(&driver); 589 return ide_pci_register_driver(&driver);
588} 590}
589 591
592static void __exit ali15x3_ide_exit(void)
593{
594 return pci_unregister_driver(&driver);
595}
596
590module_init(ali15x3_ide_init); 597module_init(ali15x3_ide_init);
598module_exit(ali15x3_ide_exit);
591 599
592MODULE_AUTHOR("Michael Aubry, Andrzej Krzysztofowicz, CJ, Andre Hedrick, Alan Cox"); 600MODULE_AUTHOR("Michael Aubry, Andrzej Krzysztofowicz, CJ, Andre Hedrick, Alan Cox");
593MODULE_DESCRIPTION("PCI driver module for ALi 15x3 IDE"); 601MODULE_DESCRIPTION("PCI driver module for ALi 15x3 IDE");
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index ef7d971031ee..2cea7bf51a0f 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -21,6 +21,8 @@
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/ide.h> 22#include <linux/ide.h>
23 23
24#define DRV_NAME "amd74xx"
25
24enum { 26enum {
25 AMD_IDE_CONFIG = 0x41, 27 AMD_IDE_CONFIG = 0x41,
26 AMD_CABLE_DETECT = 0x42, 28 AMD_CABLE_DETECT = 0x42,
@@ -110,15 +112,13 @@ static void amd_set_pio_mode(ide_drive_t *drive, const u8 pio)
110 amd_set_drive(drive, XFER_PIO_0 + pio); 112 amd_set_drive(drive, XFER_PIO_0 + pio);
111} 113}
112 114
113static void __devinit amd7409_cable_detect(struct pci_dev *dev, 115static void __devinit amd7409_cable_detect(struct pci_dev *dev)
114 const char *name)
115{ 116{
116 /* no host side cable detection */ 117 /* no host side cable detection */
117 amd_80w = 0x03; 118 amd_80w = 0x03;
118} 119}
119 120
120static void __devinit amd7411_cable_detect(struct pci_dev *dev, 121static void __devinit amd7411_cable_detect(struct pci_dev *dev)
121 const char *name)
122{ 122{
123 int i; 123 int i;
124 u32 u = 0; 124 u32 u = 0;
@@ -129,9 +129,9 @@ static void __devinit amd7411_cable_detect(struct pci_dev *dev,
129 amd_80w = ((t & 0x3) ? 1 : 0) | ((t & 0xc) ? 2 : 0); 129 amd_80w = ((t & 0x3) ? 1 : 0) | ((t & 0xc) ? 2 : 0);
130 for (i = 24; i >= 0; i -= 8) 130 for (i = 24; i >= 0; i -= 8)
131 if (((u >> i) & 4) && !(amd_80w & (1 << (1 - (i >> 4))))) { 131 if (((u >> i) & 4) && !(amd_80w & (1 << (1 - (i >> 4))))) {
132 printk(KERN_WARNING "%s: BIOS didn't set cable bits " 132 printk(KERN_WARNING DRV_NAME " %s: BIOS didn't set "
133 "correctly. Enabling workaround.\n", 133 "cable bits correctly. Enabling workaround.\n",
134 name); 134 pci_name(dev));
135 amd_80w |= (1 << (1 - (i >> 4))); 135 amd_80w |= (1 << (1 - (i >> 4)));
136 } 136 }
137} 137}
@@ -140,8 +140,7 @@ static void __devinit amd7411_cable_detect(struct pci_dev *dev,
140 * The initialization callback. Initialize drive independent registers. 140 * The initialization callback. Initialize drive independent registers.
141 */ 141 */
142 142
143static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev, 143static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev)
144 const char *name)
145{ 144{
146 u8 t = 0, offset = amd_offset(dev); 145 u8 t = 0, offset = amd_offset(dev);
147 146
@@ -154,9 +153,9 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev,
154 ; /* no UDMA > 2 */ 153 ; /* no UDMA > 2 */
155 else if (dev->vendor == PCI_VENDOR_ID_AMD && 154 else if (dev->vendor == PCI_VENDOR_ID_AMD &&
156 dev->device == PCI_DEVICE_ID_AMD_VIPER_7409) 155 dev->device == PCI_DEVICE_ID_AMD_VIPER_7409)
157 amd7409_cable_detect(dev, name); 156 amd7409_cable_detect(dev);
158 else 157 else
159 amd7411_cable_detect(dev, name); 158 amd7411_cable_detect(dev);
160 159
161/* 160/*
162 * Take care of prefetch & postwrite. 161 * Take care of prefetch & postwrite.
@@ -173,24 +172,6 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev,
173 t |= 0xf0; 172 t |= 0xf0;
174 pci_write_config_byte(dev, AMD_IDE_CONFIG + offset, t); 173 pci_write_config_byte(dev, AMD_IDE_CONFIG + offset, t);
175 174
176/*
177 * Determine the system bus clock.
178 */
179
180 amd_clock = (ide_pci_clk ? ide_pci_clk : 33) * 1000;
181
182 switch (amd_clock) {
183 case 33000: amd_clock = 33333; break;
184 case 37000: amd_clock = 37500; break;
185 case 41000: amd_clock = 41666; break;
186 }
187
188 if (amd_clock < 20000 || amd_clock > 50000) {
189 printk(KERN_WARNING "%s: User given PCI clock speed impossible (%d), using 33 MHz instead.\n",
190 name, amd_clock);
191 amd_clock = 33333;
192 }
193
194 return dev->irq; 175 return dev->irq;
195} 176}
196 177
@@ -222,9 +203,9 @@ static const struct ide_port_ops amd_port_ops = {
222 IDE_HFLAG_IO_32BIT | \ 203 IDE_HFLAG_IO_32BIT | \
223 IDE_HFLAG_UNMASK_IRQS) 204 IDE_HFLAG_UNMASK_IRQS)
224 205
225#define DECLARE_AMD_DEV(name_str, swdma, udma) \ 206#define DECLARE_AMD_DEV(swdma, udma) \
226 { \ 207 { \
227 .name = name_str, \ 208 .name = DRV_NAME, \
228 .init_chipset = init_chipset_amd74xx, \ 209 .init_chipset = init_chipset_amd74xx, \
229 .init_hwif = init_hwif_amd74xx, \ 210 .init_hwif = init_hwif_amd74xx, \
230 .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \ 211 .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \
@@ -236,9 +217,9 @@ static const struct ide_port_ops amd_port_ops = {
236 .udma_mask = udma, \ 217 .udma_mask = udma, \
237 } 218 }
238 219
239#define DECLARE_NV_DEV(name_str, udma) \ 220#define DECLARE_NV_DEV(udma) \
240 { \ 221 { \
241 .name = name_str, \ 222 .name = DRV_NAME, \
242 .init_chipset = init_chipset_amd74xx, \ 223 .init_chipset = init_chipset_amd74xx, \
243 .init_hwif = init_hwif_amd74xx, \ 224 .init_hwif = init_hwif_amd74xx, \
244 .enablebits = {{0x50,0x02,0x02}, {0x50,0x01,0x01}}, \ 225 .enablebits = {{0x50,0x02,0x02}, {0x50,0x01,0x01}}, \
@@ -251,31 +232,15 @@ static const struct ide_port_ops amd_port_ops = {
251 } 232 }
252 233
253static const struct ide_port_info amd74xx_chipsets[] __devinitdata = { 234static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
254 /* 0 */ DECLARE_AMD_DEV("AMD7401", 0x00, ATA_UDMA2), 235 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
255 /* 1 */ DECLARE_AMD_DEV("AMD7409", ATA_SWDMA2, ATA_UDMA4), 236 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
256 /* 2 */ DECLARE_AMD_DEV("AMD7411", ATA_SWDMA2, ATA_UDMA5), 237 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
257 /* 3 */ DECLARE_AMD_DEV("AMD7441", ATA_SWDMA2, ATA_UDMA5), 238 /* 3: AMD8111 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA6),
258 /* 4 */ DECLARE_AMD_DEV("AMD8111", ATA_SWDMA2, ATA_UDMA6), 239
259 240 /* 4: NFORCE */ DECLARE_NV_DEV(ATA_UDMA5),
260 /* 5 */ DECLARE_NV_DEV("NFORCE", ATA_UDMA5), 241 /* 5: >= NFORCE2 */ DECLARE_NV_DEV(ATA_UDMA6),
261 /* 6 */ DECLARE_NV_DEV("NFORCE2", ATA_UDMA6), 242
262 /* 7 */ DECLARE_NV_DEV("NFORCE2-U400R", ATA_UDMA6), 243 /* 6: AMD5536 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
263 /* 8 */ DECLARE_NV_DEV("NFORCE2-U400R-SATA", ATA_UDMA6),
264 /* 9 */ DECLARE_NV_DEV("NFORCE3-150", ATA_UDMA6),
265 /* 10 */ DECLARE_NV_DEV("NFORCE3-250", ATA_UDMA6),
266 /* 11 */ DECLARE_NV_DEV("NFORCE3-250-SATA", ATA_UDMA6),
267 /* 12 */ DECLARE_NV_DEV("NFORCE3-250-SATA2", ATA_UDMA6),
268 /* 13 */ DECLARE_NV_DEV("NFORCE-CK804", ATA_UDMA6),
269 /* 14 */ DECLARE_NV_DEV("NFORCE-MCP04", ATA_UDMA6),
270 /* 15 */ DECLARE_NV_DEV("NFORCE-MCP51", ATA_UDMA6),
271 /* 16 */ DECLARE_NV_DEV("NFORCE-MCP55", ATA_UDMA6),
272 /* 17 */ DECLARE_NV_DEV("NFORCE-MCP61", ATA_UDMA6),
273 /* 18 */ DECLARE_NV_DEV("NFORCE-MCP65", ATA_UDMA6),
274 /* 19 */ DECLARE_NV_DEV("NFORCE-MCP67", ATA_UDMA6),
275 /* 20 */ DECLARE_NV_DEV("NFORCE-MCP73", ATA_UDMA6),
276 /* 21 */ DECLARE_NV_DEV("NFORCE-MCP77", ATA_UDMA6),
277
278 /* 22 */ DECLARE_AMD_DEV("AMD5536", ATA_SWDMA2, ATA_UDMA5),
279}; 244};
280 245
281static int __devinit amd74xx_probe(struct pci_dev *dev, const struct pci_device_id *id) 246static int __devinit amd74xx_probe(struct pci_dev *dev, const struct pci_device_id *id)
@@ -292,47 +257,64 @@ static int __devinit amd74xx_probe(struct pci_dev *dev, const struct pci_device_
292 if (dev->revision <= 7) 257 if (dev->revision <= 7)
293 d.swdma_mask = 0; 258 d.swdma_mask = 0;
294 d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX; 259 d.host_flags |= IDE_HFLAG_CLEAR_SIMPLEX;
295 } else if (idx == 4) { 260 } else if (idx == 3) {
296 if (dev->subsystem_vendor == PCI_VENDOR_ID_AMD && 261 if (dev->subsystem_vendor == PCI_VENDOR_ID_AMD &&
297 dev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE) 262 dev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
298 d.udma_mask = ATA_UDMA5; 263 d.udma_mask = ATA_UDMA5;
299 } 264 }
300 265
301 printk(KERN_INFO "%s: %s (rev %02x) UDMA%s controller\n", 266 printk(KERN_INFO "%s %s: UDMA%s controller\n",
302 d.name, pci_name(dev), dev->revision, 267 d.name, pci_name(dev), amd_dma[fls(d.udma_mask) - 1]);
303 amd_dma[fls(d.udma_mask) - 1]); 268
269 /*
270 * Determine the system bus clock.
271 */
272 amd_clock = (ide_pci_clk ? ide_pci_clk : 33) * 1000;
273
274 switch (amd_clock) {
275 case 33000: amd_clock = 33333; break;
276 case 37000: amd_clock = 37500; break;
277 case 41000: amd_clock = 41666; break;
278 }
279
280 if (amd_clock < 20000 || amd_clock > 50000) {
281 printk(KERN_WARNING "%s: User given PCI clock speed impossible"
282 " (%d), using 33 MHz instead.\n",
283 d.name, amd_clock);
284 amd_clock = 33333;
285 }
304 286
305 return ide_setup_pci_device(dev, &d); 287 return ide_pci_init_one(dev, &d, NULL);
306} 288}
307 289
308static const struct pci_device_id amd74xx_pci_tbl[] = { 290static const struct pci_device_id amd74xx_pci_tbl[] = {
309 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_COBRA_7401), 0 }, 291 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_COBRA_7401), 0 },
310 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7409), 1 }, 292 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7409), 1 },
311 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7411), 2 }, 293 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7411), 2 },
312 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_OPUS_7441), 3 }, 294 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_OPUS_7441), 2 },
313 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_8111_IDE), 4 }, 295 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_8111_IDE), 3 },
314 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_IDE), 5 }, 296 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_IDE), 4 },
315 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE), 6 }, 297 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE), 5 },
316 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE), 7 }, 298 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE), 5 },
317#ifdef CONFIG_BLK_DEV_IDE_SATA 299#ifdef CONFIG_BLK_DEV_IDE_SATA
318 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA), 8 }, 300 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA), 5 },
319#endif 301#endif
320 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE), 9 }, 302 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE), 5 },
321 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE), 10 }, 303 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE), 5 },
322#ifdef CONFIG_BLK_DEV_IDE_SATA 304#ifdef CONFIG_BLK_DEV_IDE_SATA
323 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA), 11 }, 305 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA), 5 },
324 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2), 12 }, 306 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2), 5 },
325#endif 307#endif
326 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE), 13 }, 308 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE), 5 },
327 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE), 14 }, 309 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE), 5 },
328 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE), 15 }, 310 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE), 5 },
329 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE), 16 }, 311 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE), 5 },
330 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE), 17 }, 312 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE), 5 },
331 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE), 18 }, 313 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE), 5 },
332 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE), 19 }, 314 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE), 5 },
333 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_IDE), 20 }, 315 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_IDE), 5 },
334 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP77_IDE), 21 }, 316 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP77_IDE), 5 },
335 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CS5536_IDE), 22 }, 317 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CS5536_IDE), 6 },
336 { 0, }, 318 { 0, },
337}; 319};
338MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl); 320MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl);
@@ -341,6 +323,7 @@ static struct pci_driver driver = {
341 .name = "AMD_IDE", 323 .name = "AMD_IDE",
342 .id_table = amd74xx_pci_tbl, 324 .id_table = amd74xx_pci_tbl,
343 .probe = amd74xx_probe, 325 .probe = amd74xx_probe,
326 .remove = ide_pci_remove,
344}; 327};
345 328
346static int __init amd74xx_ide_init(void) 329static int __init amd74xx_ide_init(void)
@@ -348,7 +331,13 @@ static int __init amd74xx_ide_init(void)
348 return ide_pci_register_driver(&driver); 331 return ide_pci_register_driver(&driver);
349} 332}
350 333
334static void __exit amd74xx_ide_exit(void)
335{
336 pci_unregister_driver(&driver);
337}
338
351module_init(amd74xx_ide_init); 339module_init(amd74xx_ide_init);
340module_exit(amd74xx_ide_exit);
352 341
353MODULE_AUTHOR("Vojtech Pavlik"); 342MODULE_AUTHOR("Vojtech Pavlik");
354MODULE_DESCRIPTION("AMD PCI IDE driver"); 343MODULE_DESCRIPTION("AMD PCI IDE driver");
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index 8b637181681a..332f08f43b56 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -11,6 +11,8 @@
11#include <linux/ide.h> 11#include <linux/ide.h>
12#include <linux/init.h> 12#include <linux/init.h>
13 13
14#define DRV_NAME "atiixp"
15
14#define ATIIXP_IDE_PIO_TIMING 0x40 16#define ATIIXP_IDE_PIO_TIMING 0x40
15#define ATIIXP_IDE_MDMA_TIMING 0x44 17#define ATIIXP_IDE_MDMA_TIMING 0x44
16#define ATIIXP_IDE_PIO_CONTROL 0x48 18#define ATIIXP_IDE_PIO_CONTROL 0x48
@@ -137,16 +139,17 @@ static const struct ide_port_ops atiixp_port_ops = {
137}; 139};
138 140
139static const struct ide_port_info atiixp_pci_info[] __devinitdata = { 141static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
140 { /* 0 */ 142 { /* 0: IXP200/300/400/700 */
141 .name = "ATIIXP", 143 .name = DRV_NAME,
142 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}}, 144 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
143 .port_ops = &atiixp_port_ops, 145 .port_ops = &atiixp_port_ops,
144 .host_flags = IDE_HFLAG_LEGACY_IRQS, 146 .host_flags = IDE_HFLAG_LEGACY_IRQS,
145 .pio_mask = ATA_PIO4, 147 .pio_mask = ATA_PIO4,
146 .mwdma_mask = ATA_MWDMA2, 148 .mwdma_mask = ATA_MWDMA2,
147 .udma_mask = ATA_UDMA5, 149 .udma_mask = ATA_UDMA5,
148 },{ /* 1 */ 150 },
149 .name = "SB600_PATA", 151 { /* 1: IXP600 */
152 .name = DRV_NAME,
150 .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}}, 153 .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}},
151 .port_ops = &atiixp_port_ops, 154 .port_ops = &atiixp_port_ops,
152 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_LEGACY_IRQS, 155 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_LEGACY_IRQS,
@@ -167,7 +170,7 @@ static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
167 170
168static int __devinit atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id) 171static int __devinit atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id)
169{ 172{
170 return ide_setup_pci_device(dev, &atiixp_pci_info[id->driver_data]); 173 return ide_pci_init_one(dev, &atiixp_pci_info[id->driver_data], NULL);
171} 174}
172 175
173static const struct pci_device_id atiixp_pci_tbl[] = { 176static const struct pci_device_id atiixp_pci_tbl[] = {
@@ -184,6 +187,7 @@ static struct pci_driver driver = {
184 .name = "ATIIXP_IDE", 187 .name = "ATIIXP_IDE",
185 .id_table = atiixp_pci_tbl, 188 .id_table = atiixp_pci_tbl,
186 .probe = atiixp_init_one, 189 .probe = atiixp_init_one,
190 .remove = ide_pci_remove,
187}; 191};
188 192
189static int __init atiixp_ide_init(void) 193static int __init atiixp_ide_init(void)
@@ -191,7 +195,13 @@ static int __init atiixp_ide_init(void)
191 return ide_pci_register_driver(&driver); 195 return ide_pci_register_driver(&driver);
192} 196}
193 197
198static void __exit atiixp_ide_exit(void)
199{
200 pci_unregister_driver(&driver);
201}
202
194module_init(atiixp_ide_init); 203module_init(atiixp_ide_init);
204module_exit(atiixp_ide_exit);
195 205
196MODULE_AUTHOR("HUI YU"); 206MODULE_AUTHOR("HUI YU");
197MODULE_DESCRIPTION("PCI driver module for ATI IXP IDE"); 207MODULE_DESCRIPTION("PCI driver module for ATI IXP IDE");
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index ce58bfcdb3c6..1360b4fa9fd3 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -19,6 +19,8 @@
19 19
20#include <asm/io.h> 20#include <asm/io.h>
21 21
22#define DRV_NAME "cmd64x"
23
22#define CMD_DEBUG 0 24#define CMD_DEBUG 0
23 25
24#if CMD_DEBUG 26#if CMD_DEBUG
@@ -330,28 +332,10 @@ static int cmd646_1_dma_end(ide_drive_t *drive)
330 return (dma_stat & 7) != 4; 332 return (dma_stat & 7) != 4;
331} 333}
332 334
333static unsigned int __devinit init_chipset_cmd64x(struct pci_dev *dev, const char *name) 335static unsigned int __devinit init_chipset_cmd64x(struct pci_dev *dev)
334{ 336{
335 u8 mrdmode = 0; 337 u8 mrdmode = 0;
336 338
337 if (dev->device == PCI_DEVICE_ID_CMD_646) {
338
339 switch (dev->revision) {
340 case 0x07:
341 case 0x05:
342 printk("%s: UltraDMA capable\n", name);
343 break;
344 case 0x03:
345 default:
346 printk("%s: MultiWord DMA force limited\n", name);
347 break;
348 case 0x01:
349 printk("%s: MultiWord DMA limited, "
350 "IRQ workaround enabled\n", name);
351 break;
352 }
353 }
354
355 /* Set a good latency timer and cache line size value. */ 339 /* Set a good latency timer and cache line size value. */
356 (void) pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64); 340 (void) pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
357 /* FIXME: pci_set_master() to ensure a good latency timer value */ 341 /* FIXME: pci_set_master() to ensure a good latency timer value */
@@ -425,8 +409,8 @@ static const struct ide_dma_ops cmd648_dma_ops = {
425}; 409};
426 410
427static const struct ide_port_info cmd64x_chipsets[] __devinitdata = { 411static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
428 { /* 0 */ 412 { /* 0: CMD643 */
429 .name = "CMD643", 413 .name = DRV_NAME,
430 .init_chipset = init_chipset_cmd64x, 414 .init_chipset = init_chipset_cmd64x,
431 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}}, 415 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}},
432 .port_ops = &cmd64x_port_ops, 416 .port_ops = &cmd64x_port_ops,
@@ -436,8 +420,9 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
436 .pio_mask = ATA_PIO5, 420 .pio_mask = ATA_PIO5,
437 .mwdma_mask = ATA_MWDMA2, 421 .mwdma_mask = ATA_MWDMA2,
438 .udma_mask = 0x00, /* no udma */ 422 .udma_mask = 0x00, /* no udma */
439 },{ /* 1 */ 423 },
440 .name = "CMD646", 424 { /* 1: CMD646 */
425 .name = DRV_NAME,
441 .init_chipset = init_chipset_cmd64x, 426 .init_chipset = init_chipset_cmd64x,
442 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 427 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
443 .chipset = ide_cmd646, 428 .chipset = ide_cmd646,
@@ -447,8 +432,9 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
447 .pio_mask = ATA_PIO5, 432 .pio_mask = ATA_PIO5,
448 .mwdma_mask = ATA_MWDMA2, 433 .mwdma_mask = ATA_MWDMA2,
449 .udma_mask = ATA_UDMA2, 434 .udma_mask = ATA_UDMA2,
450 },{ /* 2 */ 435 },
451 .name = "CMD648", 436 { /* 2: CMD648 */
437 .name = DRV_NAME,
452 .init_chipset = init_chipset_cmd64x, 438 .init_chipset = init_chipset_cmd64x,
453 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 439 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
454 .port_ops = &cmd64x_port_ops, 440 .port_ops = &cmd64x_port_ops,
@@ -457,8 +443,9 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
457 .pio_mask = ATA_PIO5, 443 .pio_mask = ATA_PIO5,
458 .mwdma_mask = ATA_MWDMA2, 444 .mwdma_mask = ATA_MWDMA2,
459 .udma_mask = ATA_UDMA4, 445 .udma_mask = ATA_UDMA4,
460 },{ /* 3 */ 446 },
461 .name = "CMD649", 447 { /* 3: CMD649 */
448 .name = DRV_NAME,
462 .init_chipset = init_chipset_cmd64x, 449 .init_chipset = init_chipset_cmd64x,
463 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 450 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
464 .port_ops = &cmd64x_port_ops, 451 .port_ops = &cmd64x_port_ops,
@@ -507,7 +494,7 @@ static int __devinit cmd64x_init_one(struct pci_dev *dev, const struct pci_devic
507 } 494 }
508 } 495 }
509 496
510 return ide_setup_pci_device(dev, &d); 497 return ide_pci_init_one(dev, &d, NULL);
511} 498}
512 499
513static const struct pci_device_id cmd64x_pci_tbl[] = { 500static const struct pci_device_id cmd64x_pci_tbl[] = {
@@ -523,6 +510,7 @@ static struct pci_driver driver = {
523 .name = "CMD64x_IDE", 510 .name = "CMD64x_IDE",
524 .id_table = cmd64x_pci_tbl, 511 .id_table = cmd64x_pci_tbl,
525 .probe = cmd64x_init_one, 512 .probe = cmd64x_init_one,
513 .remove = ide_pci_remove,
526}; 514};
527 515
528static int __init cmd64x_ide_init(void) 516static int __init cmd64x_ide_init(void)
@@ -530,7 +518,13 @@ static int __init cmd64x_ide_init(void)
530 return ide_pci_register_driver(&driver); 518 return ide_pci_register_driver(&driver);
531} 519}
532 520
521static void __exit cmd64x_ide_exit(void)
522{
523 pci_unregister_driver(&driver);
524}
525
533module_init(cmd64x_ide_init); 526module_init(cmd64x_ide_init);
527module_exit(cmd64x_ide_exit);
534 528
535MODULE_AUTHOR("Eddie Dost, David Miller, Andre Hedrick"); 529MODULE_AUTHOR("Eddie Dost, David Miller, Andre Hedrick");
536MODULE_DESCRIPTION("PCI driver module for CMD64x IDE"); 530MODULE_DESCRIPTION("PCI driver module for CMD64x IDE");
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index b03d8ae947e6..c0364b287f17 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -41,6 +41,8 @@
41#include <linux/ide.h> 41#include <linux/ide.h>
42#include <linux/dma-mapping.h> 42#include <linux/dma-mapping.h>
43 43
44#define DRV_NAME "cs5520"
45
44struct pio_clocks 46struct pio_clocks
45{ 47{
46 int address; 48 int address;
@@ -92,18 +94,11 @@ static const struct ide_port_ops cs5520_port_ops = {
92 .set_dma_mode = cs5520_set_dma_mode, 94 .set_dma_mode = cs5520_set_dma_mode,
93}; 95};
94 96
95#define DECLARE_CS_DEV(name_str) \ 97static const struct ide_port_info cyrix_chipset __devinitdata = {
96 { \ 98 .name = DRV_NAME,
97 .name = name_str, \ 99 .port_ops = &cs5520_port_ops,
98 .port_ops = &cs5520_port_ops, \ 100 .host_flags = IDE_HFLAG_ISA_PORTS | IDE_HFLAG_CS5520,
99 .host_flags = IDE_HFLAG_ISA_PORTS | \ 101 .pio_mask = ATA_PIO4,
100 IDE_HFLAG_CS5520, \
101 .pio_mask = ATA_PIO4, \
102 }
103
104static const struct ide_port_info cyrix_chipsets[] __devinitdata = {
105 /* 0 */ DECLARE_CS_DEV("Cyrix 5510"),
106 /* 1 */ DECLARE_CS_DEV("Cyrix 5520")
107}; 102};
108 103
109/* 104/*
@@ -114,7 +109,7 @@ static const struct ide_port_info cyrix_chipsets[] __devinitdata = {
114 109
115static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id) 110static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id)
116{ 111{
117 const struct ide_port_info *d = &cyrix_chipsets[id->driver_data]; 112 const struct ide_port_info *d = &cyrix_chipset;
118 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL }; 113 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
119 114
120 ide_setup_pci_noise(dev, d); 115 ide_setup_pci_noise(dev, d);
@@ -128,7 +123,8 @@ static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_devic
128 } 123 }
129 pci_set_master(dev); 124 pci_set_master(dev);
130 if (pci_set_dma_mask(dev, DMA_32BIT_MASK)) { 125 if (pci_set_dma_mask(dev, DMA_32BIT_MASK)) {
131 printk(KERN_WARNING "cs5520: No suitable DMA available.\n"); 126 printk(KERN_WARNING "%s: No suitable DMA available.\n",
127 d->name);
132 return -ENODEV; 128 return -ENODEV;
133 } 129 }
134 130
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index f5534c1ff349..f235db8c678b 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -22,6 +22,8 @@
22 22
23#include <asm/io.h> 23#include <asm/io.h>
24 24
25#define DRV_NAME "cs5530"
26
25/* 27/*
26 * Here are the standard PIO mode 0-4 timings for each "format". 28 * Here are the standard PIO mode 0-4 timings for each "format".
27 * Format-0 uses fast data reg timings, with slower command reg timings. 29 * Format-0 uses fast data reg timings, with slower command reg timings.
@@ -127,12 +129,11 @@ static void cs5530_set_dma_mode(ide_drive_t *drive, const u8 mode)
127/** 129/**
128 * init_chipset_5530 - set up 5530 bridge 130 * init_chipset_5530 - set up 5530 bridge
129 * @dev: PCI device 131 * @dev: PCI device
130 * @name: device name
131 * 132 *
132 * Initialize the cs5530 bridge for reliable IDE DMA operation. 133 * Initialize the cs5530 bridge for reliable IDE DMA operation.
133 */ 134 */
134 135
135static unsigned int __devinit init_chipset_cs5530 (struct pci_dev *dev, const char *name) 136static unsigned int __devinit init_chipset_cs5530(struct pci_dev *dev)
136{ 137{
137 struct pci_dev *master_0 = NULL, *cs5530_0 = NULL; 138 struct pci_dev *master_0 = NULL, *cs5530_0 = NULL;
138 139
@@ -151,11 +152,11 @@ static unsigned int __devinit init_chipset_cs5530 (struct pci_dev *dev, const ch
151 } 152 }
152 } 153 }
153 if (!master_0) { 154 if (!master_0) {
154 printk(KERN_ERR "%s: unable to locate PCI MASTER function\n", name); 155 printk(KERN_ERR DRV_NAME ": unable to locate PCI MASTER function\n");
155 goto out; 156 goto out;
156 } 157 }
157 if (!cs5530_0) { 158 if (!cs5530_0) {
158 printk(KERN_ERR "%s: unable to locate CS5530 LEGACY function\n", name); 159 printk(KERN_ERR DRV_NAME ": unable to locate CS5530 LEGACY function\n");
159 goto out; 160 goto out;
160 } 161 }
161 162
@@ -243,7 +244,7 @@ static const struct ide_port_ops cs5530_port_ops = {
243}; 244};
244 245
245static const struct ide_port_info cs5530_chipset __devinitdata = { 246static const struct ide_port_info cs5530_chipset __devinitdata = {
246 .name = "CS5530", 247 .name = DRV_NAME,
247 .init_chipset = init_chipset_cs5530, 248 .init_chipset = init_chipset_cs5530,
248 .init_hwif = init_hwif_cs5530, 249 .init_hwif = init_hwif_cs5530,
249 .port_ops = &cs5530_port_ops, 250 .port_ops = &cs5530_port_ops,
@@ -256,7 +257,7 @@ static const struct ide_port_info cs5530_chipset __devinitdata = {
256 257
257static int __devinit cs5530_init_one(struct pci_dev *dev, const struct pci_device_id *id) 258static int __devinit cs5530_init_one(struct pci_dev *dev, const struct pci_device_id *id)
258{ 259{
259 return ide_setup_pci_device(dev, &cs5530_chipset); 260 return ide_pci_init_one(dev, &cs5530_chipset, NULL);
260} 261}
261 262
262static const struct pci_device_id cs5530_pci_tbl[] = { 263static const struct pci_device_id cs5530_pci_tbl[] = {
@@ -269,6 +270,7 @@ static struct pci_driver driver = {
269 .name = "CS5530 IDE", 270 .name = "CS5530 IDE",
270 .id_table = cs5530_pci_tbl, 271 .id_table = cs5530_pci_tbl,
271 .probe = cs5530_init_one, 272 .probe = cs5530_init_one,
273 .remove = ide_pci_remove,
272}; 274};
273 275
274static int __init cs5530_ide_init(void) 276static int __init cs5530_ide_init(void)
@@ -276,7 +278,13 @@ static int __init cs5530_ide_init(void)
276 return ide_pci_register_driver(&driver); 278 return ide_pci_register_driver(&driver);
277} 279}
278 280
281static void __exit cs5530_ide_exit(void)
282{
283 pci_unregister_driver(&driver);
284}
285
279module_init(cs5530_ide_init); 286module_init(cs5530_ide_init);
287module_exit(cs5530_ide_exit);
280 288
281MODULE_AUTHOR("Mark Lord"); 289MODULE_AUTHOR("Mark Lord");
282MODULE_DESCRIPTION("PCI driver module for Cyrix/NS 5530 IDE"); 290MODULE_DESCRIPTION("PCI driver module for Cyrix/NS 5530 IDE");
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index 5404fe4f701d..f7b50cdeefa6 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -26,6 +26,8 @@
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/ide.h> 27#include <linux/ide.h>
28 28
29#define DRV_NAME "cs5535"
30
29#define MSR_ATAC_BASE 0x51300000 31#define MSR_ATAC_BASE 0x51300000
30#define ATAC_GLD_MSR_CAP (MSR_ATAC_BASE+0) 32#define ATAC_GLD_MSR_CAP (MSR_ATAC_BASE+0)
31#define ATAC_GLD_MSR_CONFIG (MSR_ATAC_BASE+0x01) 33#define ATAC_GLD_MSR_CONFIG (MSR_ATAC_BASE+0x01)
@@ -169,7 +171,7 @@ static const struct ide_port_ops cs5535_port_ops = {
169}; 171};
170 172
171static const struct ide_port_info cs5535_chipset __devinitdata = { 173static const struct ide_port_info cs5535_chipset __devinitdata = {
172 .name = "CS5535", 174 .name = DRV_NAME,
173 .port_ops = &cs5535_port_ops, 175 .port_ops = &cs5535_port_ops,
174 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE, 176 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
175 .pio_mask = ATA_PIO4, 177 .pio_mask = ATA_PIO4,
@@ -180,7 +182,7 @@ static const struct ide_port_info cs5535_chipset __devinitdata = {
180static int __devinit cs5535_init_one(struct pci_dev *dev, 182static int __devinit cs5535_init_one(struct pci_dev *dev,
181 const struct pci_device_id *id) 183 const struct pci_device_id *id)
182{ 184{
183 return ide_setup_pci_device(dev, &cs5535_chipset); 185 return ide_pci_init_one(dev, &cs5535_chipset, NULL);
184} 186}
185 187
186static const struct pci_device_id cs5535_pci_tbl[] = { 188static const struct pci_device_id cs5535_pci_tbl[] = {
@@ -194,6 +196,7 @@ static struct pci_driver driver = {
194 .name = "CS5535_IDE", 196 .name = "CS5535_IDE",
195 .id_table = cs5535_pci_tbl, 197 .id_table = cs5535_pci_tbl,
196 .probe = cs5535_init_one, 198 .probe = cs5535_init_one,
199 .remove = ide_pci_remove,
197}; 200};
198 201
199static int __init cs5535_ide_init(void) 202static int __init cs5535_ide_init(void)
@@ -201,7 +204,13 @@ static int __init cs5535_ide_init(void)
201 return ide_pci_register_driver(&driver); 204 return ide_pci_register_driver(&driver);
202} 205}
203 206
207static void __exit cs5535_ide_exit(void)
208{
209 pci_unregister_driver(&driver);
210}
211
204module_init(cs5535_ide_init); 212module_init(cs5535_ide_init);
213module_exit(cs5535_ide_exit);
205 214
206MODULE_AUTHOR("AMD"); 215MODULE_AUTHOR("AMD");
207MODULE_DESCRIPTION("PCI driver module for AMD/NS CS5535 IDE"); 216MODULE_DESCRIPTION("PCI driver module for AMD/NS CS5535 IDE");
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index e14ad5530fa4..bfae2f882f48 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -48,6 +48,8 @@
48 48
49#include <asm/io.h> 49#include <asm/io.h>
50 50
51#define DRV_NAME "cy82c693"
52
51/* the current version */ 53/* the current version */
52#define CY82_VERSION "CY82C693U driver v0.34 99-13-12 Andreas S. Krebs (akrebs@altavista.net)" 54#define CY82_VERSION "CY82C693U driver v0.34 99-13-12 Andreas S. Krebs (akrebs@altavista.net)"
53 55
@@ -330,7 +332,7 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
330/* 332/*
331 * this function is called during init and is used to setup the cy82c693 chip 333 * this function is called during init and is used to setup the cy82c693 chip
332 */ 334 */
333static unsigned int __devinit init_chipset_cy82c693(struct pci_dev *dev, const char *name) 335static unsigned int __devinit init_chipset_cy82c693(struct pci_dev *dev)
334{ 336{
335 if (PCI_FUNC(dev->devfn) != 1) 337 if (PCI_FUNC(dev->devfn) != 1)
336 return 0; 338 return 0;
@@ -349,8 +351,8 @@ static unsigned int __devinit init_chipset_cy82c693(struct pci_dev *dev, const c
349 data = inb(CY82_DATA_PORT); 351 data = inb(CY82_DATA_PORT);
350 352
351#if CY82C693_DEBUG_INFO 353#if CY82C693_DEBUG_INFO
352 printk(KERN_INFO "%s: Peripheral Configuration Register: 0x%X\n", 354 printk(KERN_INFO DRV_NAME ": Peripheral Configuration Register: 0x%X\n",
353 name, data); 355 data);
354#endif /* CY82C693_DEBUG_INFO */ 356#endif /* CY82C693_DEBUG_INFO */
355 357
356 /* 358 /*
@@ -371,8 +373,8 @@ static unsigned int __devinit init_chipset_cy82c693(struct pci_dev *dev, const c
371 outb(data, CY82_DATA_PORT); 373 outb(data, CY82_DATA_PORT);
372 374
373#if CY82C693_DEBUG_INFO 375#if CY82C693_DEBUG_INFO
374 printk(KERN_INFO "%s: New Peripheral Configuration Register: 0x%X\n", 376 printk(KERN_INFO ": New Peripheral Configuration Register: 0x%X\n",
375 name, data); 377 data);
376#endif /* CY82C693_DEBUG_INFO */ 378#endif /* CY82C693_DEBUG_INFO */
377 379
378#endif /* CY82C693_SETDMA_CLOCK */ 380#endif /* CY82C693_SETDMA_CLOCK */
@@ -398,7 +400,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
398}; 400};
399 401
400static const struct ide_port_info cy82c693_chipset __devinitdata = { 402static const struct ide_port_info cy82c693_chipset __devinitdata = {
401 .name = "CY82C693", 403 .name = DRV_NAME,
402 .init_chipset = init_chipset_cy82c693, 404 .init_chipset = init_chipset_cy82c693,
403 .init_iops = init_iops_cy82c693, 405 .init_iops = init_iops_cy82c693,
404 .port_ops = &cy82c693_port_ops, 406 .port_ops = &cy82c693_port_ops,
@@ -419,12 +421,22 @@ static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_dev
419 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && 421 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE &&
420 PCI_FUNC(dev->devfn) == 1) { 422 PCI_FUNC(dev->devfn) == 1) {
421 dev2 = pci_get_slot(dev->bus, dev->devfn + 1); 423 dev2 = pci_get_slot(dev->bus, dev->devfn + 1);
422 ret = ide_setup_pci_devices(dev, dev2, &cy82c693_chipset); 424 ret = ide_pci_init_two(dev, dev2, &cy82c693_chipset, NULL);
423 /* We leak pci refs here but thats ok - we can't be unloaded */ 425 if (ret)
426 pci_dev_put(dev2);
424 } 427 }
425 return ret; 428 return ret;
426} 429}
427 430
431static void __devexit cy82c693_remove(struct pci_dev *dev)
432{
433 struct ide_host *host = pci_get_drvdata(dev);
434 struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
435
436 ide_pci_remove(dev);
437 pci_dev_put(dev2);
438}
439
428static const struct pci_device_id cy82c693_pci_tbl[] = { 440static const struct pci_device_id cy82c693_pci_tbl[] = {
429 { PCI_VDEVICE(CONTAQ, PCI_DEVICE_ID_CONTAQ_82C693), 0 }, 441 { PCI_VDEVICE(CONTAQ, PCI_DEVICE_ID_CONTAQ_82C693), 0 },
430 { 0, }, 442 { 0, },
@@ -435,6 +447,7 @@ static struct pci_driver driver = {
435 .name = "Cypress_IDE", 447 .name = "Cypress_IDE",
436 .id_table = cy82c693_pci_tbl, 448 .id_table = cy82c693_pci_tbl,
437 .probe = cy82c693_init_one, 449 .probe = cy82c693_init_one,
450 .remove = cy82c693_remove,
438}; 451};
439 452
440static int __init cy82c693_ide_init(void) 453static int __init cy82c693_ide_init(void)
@@ -442,7 +455,13 @@ static int __init cy82c693_ide_init(void)
442 return ide_pci_register_driver(&driver); 455 return ide_pci_register_driver(&driver);
443} 456}
444 457
458static void __exit cy82c693_ide_exit(void)
459{
460 pci_unregister_driver(&driver);
461}
462
445module_init(cy82c693_ide_init); 463module_init(cy82c693_ide_init);
464module_exit(cy82c693_ide_exit);
446 465
447MODULE_AUTHOR("Andreas Krebs, Andre Hedrick"); 466MODULE_AUTHOR("Andreas Krebs, Andre Hedrick");
448MODULE_DESCRIPTION("PCI driver module for the Cypress CY82C693 IDE"); 467MODULE_DESCRIPTION("PCI driver module for the Cypress CY82C693 IDE");
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 041720e22762..b07d4f4273b3 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -27,6 +27,8 @@
27#include <linux/ide.h> 27#include <linux/ide.h>
28#include <linux/init.h> 28#include <linux/init.h>
29 29
30#define DRV_NAME "ide_pci_generic"
31
30static int ide_generic_all; /* Set to claim all devices */ 32static int ide_generic_all; /* Set to claim all devices */
31 33
32module_param_named(all_generic_ide, ide_generic_all, bool, 0444); 34module_param_named(all_generic_ide, ide_generic_all, bool, 0444);
@@ -34,9 +36,9 @@ MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE st
34 36
35#define IDE_HFLAGS_UMC (IDE_HFLAG_NO_DMA | IDE_HFLAG_FORCE_LEGACY_IRQS) 37#define IDE_HFLAGS_UMC (IDE_HFLAG_NO_DMA | IDE_HFLAG_FORCE_LEGACY_IRQS)
36 38
37#define DECLARE_GENERIC_PCI_DEV(name_str, extra_flags) \ 39#define DECLARE_GENERIC_PCI_DEV(extra_flags) \
38 { \ 40 { \
39 .name = name_str, \ 41 .name = DRV_NAME, \
40 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA | \ 42 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA | \
41 extra_flags, \ 43 extra_flags, \
42 .swdma_mask = ATA_SWDMA2, \ 44 .swdma_mask = ATA_SWDMA2, \
@@ -45,10 +47,11 @@ MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE st
45 } 47 }
46 48
47static const struct ide_port_info generic_chipsets[] __devinitdata = { 49static const struct ide_port_info generic_chipsets[] __devinitdata = {
48 /* 0 */ DECLARE_GENERIC_PCI_DEV("Unknown", 0), 50 /* 0: Unknown */
51 DECLARE_GENERIC_PCI_DEV(0),
49 52
50 { /* 1 */ 53 { /* 1: NS87410 */
51 .name = "NS87410", 54 .name = DRV_NAME,
52 .enablebits = { {0x43, 0x08, 0x08}, {0x47, 0x08, 0x08} }, 55 .enablebits = { {0x43, 0x08, 0x08}, {0x47, 0x08, 0x08} },
53 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA, 56 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA,
54 .swdma_mask = ATA_SWDMA2, 57 .swdma_mask = ATA_SWDMA2,
@@ -56,17 +59,15 @@ static const struct ide_port_info generic_chipsets[] __devinitdata = {
56 .udma_mask = ATA_UDMA6, 59 .udma_mask = ATA_UDMA6,
57 }, 60 },
58 61
59 /* 2 */ DECLARE_GENERIC_PCI_DEV("SAMURAI", 0), 62 /* 2: SAMURAI / HT6565 / HINT_IDE */
60 /* 3 */ DECLARE_GENERIC_PCI_DEV("HT6565", 0), 63 DECLARE_GENERIC_PCI_DEV(0),
61 /* 4 */ DECLARE_GENERIC_PCI_DEV("UM8673F", IDE_HFLAGS_UMC), 64 /* 3: UM8673F / UM8886A / UM8886BF */
62 /* 5 */ DECLARE_GENERIC_PCI_DEV("UM8886A", IDE_HFLAGS_UMC), 65 DECLARE_GENERIC_PCI_DEV(IDE_HFLAGS_UMC),
63 /* 6 */ DECLARE_GENERIC_PCI_DEV("UM8886BF", IDE_HFLAGS_UMC), 66 /* 4: VIA_IDE / OPTI621V / Piccolo010{2,3,5} */
64 /* 7 */ DECLARE_GENERIC_PCI_DEV("HINT_IDE", 0), 67 DECLARE_GENERIC_PCI_DEV(IDE_HFLAG_NO_AUTODMA),
65 /* 8 */ DECLARE_GENERIC_PCI_DEV("VIA_IDE", IDE_HFLAG_NO_AUTODMA), 68
66 /* 9 */ DECLARE_GENERIC_PCI_DEV("OPTI621V", IDE_HFLAG_NO_AUTODMA), 69 { /* 5: VIA8237SATA */
67 70 .name = DRV_NAME,
68 { /* 10 */
69 .name = "VIA8237SATA",
70 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA | 71 .host_flags = IDE_HFLAG_TRUST_BIOS_FOR_DMA |
71 IDE_HFLAG_OFF_BOARD, 72 IDE_HFLAG_OFF_BOARD,
72 .swdma_mask = ATA_SWDMA2, 73 .swdma_mask = ATA_SWDMA2,
@@ -74,12 +75,8 @@ static const struct ide_port_info generic_chipsets[] __devinitdata = {
74 .udma_mask = ATA_UDMA6, 75 .udma_mask = ATA_UDMA6,
75 }, 76 },
76 77
77 /* 11 */ DECLARE_GENERIC_PCI_DEV("Piccolo0102", IDE_HFLAG_NO_AUTODMA), 78 { /* 6: Revolution */
78 /* 12 */ DECLARE_GENERIC_PCI_DEV("Piccolo0103", IDE_HFLAG_NO_AUTODMA), 79 .name = DRV_NAME,
79 /* 13 */ DECLARE_GENERIC_PCI_DEV("Piccolo0105", IDE_HFLAG_NO_AUTODMA),
80
81 { /* 14 */
82 .name = "Revolution",
83 .host_flags = IDE_HFLAG_CLEAR_SIMPLEX | 80 .host_flags = IDE_HFLAG_CLEAR_SIMPLEX |
84 IDE_HFLAG_TRUST_BIOS_FOR_DMA | 81 IDE_HFLAG_TRUST_BIOS_FOR_DMA |
85 IDE_HFLAG_OFF_BOARD, 82 IDE_HFLAG_OFF_BOARD,
@@ -134,12 +131,12 @@ static int __devinit generic_init_one(struct pci_dev *dev, const struct pci_devi
134 u16 command; 131 u16 command;
135 pci_read_config_word(dev, PCI_COMMAND, &command); 132 pci_read_config_word(dev, PCI_COMMAND, &command);
136 if (!(command & PCI_COMMAND_IO)) { 133 if (!(command & PCI_COMMAND_IO)) {
137 printk(KERN_INFO "Skipping disabled %s IDE " 134 printk(KERN_INFO "%s %s: skipping disabled "
138 "controller.\n", d->name); 135 "controller\n", d->name, pci_name(dev));
139 goto out; 136 goto out;
140 } 137 }
141 } 138 }
142 ret = ide_setup_pci_device(dev, d); 139 ret = ide_pci_init_one(dev, d, NULL);
143out: 140out:
144 return ret; 141 return ret;
145} 142}
@@ -147,20 +144,20 @@ out:
147static const struct pci_device_id generic_pci_tbl[] = { 144static const struct pci_device_id generic_pci_tbl[] = {
148 { PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_87410), 1 }, 145 { PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_87410), 1 },
149 { PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE), 2 }, 146 { PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE), 2 },
150 { PCI_VDEVICE(HOLTEK, PCI_DEVICE_ID_HOLTEK_6565), 3 }, 147 { PCI_VDEVICE(HOLTEK, PCI_DEVICE_ID_HOLTEK_6565), 2 },
151 { PCI_VDEVICE(UMC, PCI_DEVICE_ID_UMC_UM8673F), 4 }, 148 { PCI_VDEVICE(UMC, PCI_DEVICE_ID_UMC_UM8673F), 3 },
152 { PCI_VDEVICE(UMC, PCI_DEVICE_ID_UMC_UM8886A), 5 }, 149 { PCI_VDEVICE(UMC, PCI_DEVICE_ID_UMC_UM8886A), 3 },
153 { PCI_VDEVICE(UMC, PCI_DEVICE_ID_UMC_UM8886BF), 6 }, 150 { PCI_VDEVICE(UMC, PCI_DEVICE_ID_UMC_UM8886BF), 3 },
154 { PCI_VDEVICE(HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE), 7 }, 151 { PCI_VDEVICE(HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE), 2 },
155 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C561), 8 }, 152 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C561), 4 },
156 { PCI_VDEVICE(OPTI, PCI_DEVICE_ID_OPTI_82C558), 9 }, 153 { PCI_VDEVICE(OPTI, PCI_DEVICE_ID_OPTI_82C558), 4 },
157#ifdef CONFIG_BLK_DEV_IDE_SATA 154#ifdef CONFIG_BLK_DEV_IDE_SATA
158 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8237_SATA), 10 }, 155 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8237_SATA), 5 },
159#endif 156#endif
160 { PCI_VDEVICE(TOSHIBA, PCI_DEVICE_ID_TOSHIBA_PICCOLO), 11 }, 157 { PCI_VDEVICE(TOSHIBA, PCI_DEVICE_ID_TOSHIBA_PICCOLO), 4 },
161 { PCI_VDEVICE(TOSHIBA, PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), 12 }, 158 { PCI_VDEVICE(TOSHIBA, PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), 4 },
162 { PCI_VDEVICE(TOSHIBA, PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), 13 }, 159 { PCI_VDEVICE(TOSHIBA, PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), 4 },
163 { PCI_VDEVICE(NETCELL, PCI_DEVICE_ID_REVOLUTION), 14 }, 160 { PCI_VDEVICE(NETCELL, PCI_DEVICE_ID_REVOLUTION), 6 },
164 /* 161 /*
165 * Must come last. If you add entries adjust 162 * Must come last. If you add entries adjust
166 * this table and generic_chipsets[] appropriately. 163 * this table and generic_chipsets[] appropriately.
@@ -174,6 +171,7 @@ static struct pci_driver driver = {
174 .name = "PCI_IDE", 171 .name = "PCI_IDE",
175 .id_table = generic_pci_tbl, 172 .id_table = generic_pci_tbl,
176 .probe = generic_init_one, 173 .probe = generic_init_one,
174 .remove = ide_pci_remove,
177}; 175};
178 176
179static int __init generic_ide_init(void) 177static int __init generic_ide_init(void)
@@ -181,7 +179,13 @@ static int __init generic_ide_init(void)
181 return ide_pci_register_driver(&driver); 179 return ide_pci_register_driver(&driver);
182} 180}
183 181
182static void __exit generic_ide_exit(void)
183{
184 pci_unregister_driver(&driver);
185}
186
184module_init(generic_ide_init); 187module_init(generic_ide_init);
188module_exit(generic_ide_exit);
185 189
186MODULE_AUTHOR("Andre Hedrick"); 190MODULE_AUTHOR("Andre Hedrick");
187MODULE_DESCRIPTION("PCI driver module for generic PCI IDE"); 191MODULE_DESCRIPTION("PCI driver module for generic PCI IDE");
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index 9e1d1c4741da..6009b0b9655d 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -33,6 +33,8 @@
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/ide.h> 34#include <linux/ide.h>
35 35
36#define DRV_NAME "hpt34x"
37
36#define HPT343_DEBUG_DRIVE_INFO 0 38#define HPT343_DEBUG_DRIVE_INFO 0
37 39
38static void hpt34x_set_mode(ide_drive_t *drive, const u8 speed) 40static void hpt34x_set_mode(ide_drive_t *drive, const u8 speed)
@@ -77,7 +79,7 @@ static void hpt34x_set_pio_mode(ide_drive_t *drive, const u8 pio)
77 */ 79 */
78#define HPT34X_PCI_INIT_REG 0x80 80#define HPT34X_PCI_INIT_REG 0x80
79 81
80static unsigned int __devinit init_chipset_hpt34x(struct pci_dev *dev, const char *name) 82static unsigned int __devinit init_chipset_hpt34x(struct pci_dev *dev)
81{ 83{
82 int i = 0; 84 int i = 0;
83 unsigned long hpt34xIoBase = pci_resource_start(dev, 4); 85 unsigned long hpt34xIoBase = pci_resource_start(dev, 4);
@@ -126,15 +128,15 @@ static const struct ide_port_ops hpt34x_port_ops = {
126 IDE_HFLAG_NO_AUTODMA) 128 IDE_HFLAG_NO_AUTODMA)
127 129
128static const struct ide_port_info hpt34x_chipsets[] __devinitdata = { 130static const struct ide_port_info hpt34x_chipsets[] __devinitdata = {
129 { /* 0 */ 131 { /* 0: HPT343 */
130 .name = "HPT343", 132 .name = DRV_NAME,
131 .init_chipset = init_chipset_hpt34x, 133 .init_chipset = init_chipset_hpt34x,
132 .port_ops = &hpt34x_port_ops, 134 .port_ops = &hpt34x_port_ops,
133 .host_flags = IDE_HFLAGS_HPT34X | IDE_HFLAG_NON_BOOTABLE, 135 .host_flags = IDE_HFLAGS_HPT34X | IDE_HFLAG_NON_BOOTABLE,
134 .pio_mask = ATA_PIO5, 136 .pio_mask = ATA_PIO5,
135 }, 137 },
136 { /* 1 */ 138 { /* 1: HPT345 */
137 .name = "HPT345", 139 .name = DRV_NAME,
138 .init_chipset = init_chipset_hpt34x, 140 .init_chipset = init_chipset_hpt34x,
139 .port_ops = &hpt34x_port_ops, 141 .port_ops = &hpt34x_port_ops,
140 .host_flags = IDE_HFLAGS_HPT34X | IDE_HFLAG_OFF_BOARD, 142 .host_flags = IDE_HFLAGS_HPT34X | IDE_HFLAG_OFF_BOARD,
@@ -156,7 +158,7 @@ static int __devinit hpt34x_init_one(struct pci_dev *dev, const struct pci_devic
156 158
157 d = &hpt34x_chipsets[(pcicmd & PCI_COMMAND_MEMORY) ? 1 : 0]; 159 d = &hpt34x_chipsets[(pcicmd & PCI_COMMAND_MEMORY) ? 1 : 0];
158 160
159 return ide_setup_pci_device(dev, d); 161 return ide_pci_init_one(dev, d, NULL);
160} 162}
161 163
162static const struct pci_device_id hpt34x_pci_tbl[] = { 164static const struct pci_device_id hpt34x_pci_tbl[] = {
@@ -169,6 +171,7 @@ static struct pci_driver driver = {
169 .name = "HPT34x_IDE", 171 .name = "HPT34x_IDE",
170 .id_table = hpt34x_pci_tbl, 172 .id_table = hpt34x_pci_tbl,
171 .probe = hpt34x_init_one, 173 .probe = hpt34x_init_one,
174 .remove = ide_pci_remove,
172}; 175};
173 176
174static int __init hpt34x_ide_init(void) 177static int __init hpt34x_ide_init(void)
@@ -176,7 +179,13 @@ static int __init hpt34x_ide_init(void)
176 return ide_pci_register_driver(&driver); 179 return ide_pci_register_driver(&driver);
177} 180}
178 181
182static void __exit hpt34x_ide_exit(void)
183{
184 pci_unregister_driver(&driver);
185}
186
179module_init(hpt34x_ide_init); 187module_init(hpt34x_ide_init);
188module_exit(hpt34x_ide_exit);
180 189
181MODULE_AUTHOR("Andre Hedrick"); 190MODULE_AUTHOR("Andre Hedrick");
182MODULE_DESCRIPTION("PCI driver module for Highpoint 34x IDE"); 191MODULE_DESCRIPTION("PCI driver module for Highpoint 34x IDE");
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 1f1135ce7cd6..5271b246b88c 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -131,6 +131,8 @@
131#include <asm/uaccess.h> 131#include <asm/uaccess.h>
132#include <asm/io.h> 132#include <asm/io.h>
133 133
134#define DRV_NAME "hpt366"
135
134/* various tuning parameters */ 136/* various tuning parameters */
135#define HPT_RESET_STATE_ENGINE 137#define HPT_RESET_STATE_ENGINE
136#undef HPT_DELAY_INTERRUPT 138#undef HPT_DELAY_INTERRUPT
@@ -620,7 +622,8 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive)
620{ 622{
621 ide_hwif_t *hwif = HWIF(drive); 623 ide_hwif_t *hwif = HWIF(drive);
622 struct pci_dev *dev = to_pci_dev(hwif->dev); 624 struct pci_dev *dev = to_pci_dev(hwif->dev);
623 struct hpt_info *info = pci_get_drvdata(dev); 625 struct ide_host *host = pci_get_drvdata(dev);
626 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
624 u8 mask = hwif->ultra_mask; 627 u8 mask = hwif->ultra_mask;
625 628
626 switch (info->chip_type) { 629 switch (info->chip_type) {
@@ -660,7 +663,8 @@ static u8 hpt3xx_mdma_filter(ide_drive_t *drive)
660{ 663{
661 ide_hwif_t *hwif = HWIF(drive); 664 ide_hwif_t *hwif = HWIF(drive);
662 struct pci_dev *dev = to_pci_dev(hwif->dev); 665 struct pci_dev *dev = to_pci_dev(hwif->dev);
663 struct hpt_info *info = pci_get_drvdata(dev); 666 struct ide_host *host = pci_get_drvdata(dev);
667 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
664 668
665 switch (info->chip_type) { 669 switch (info->chip_type) {
666 case HPT372 : 670 case HPT372 :
@@ -694,8 +698,10 @@ static u32 get_speed_setting(u8 speed, struct hpt_info *info)
694 698
695static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed) 699static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed)
696{ 700{
697 struct pci_dev *dev = to_pci_dev(drive->hwif->dev); 701 ide_hwif_t *hwif = drive->hwif;
698 struct hpt_info *info = pci_get_drvdata(dev); 702 struct pci_dev *dev = to_pci_dev(hwif->dev);
703 struct ide_host *host = pci_get_drvdata(dev);
704 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
699 struct hpt_timings *t = info->timings; 705 struct hpt_timings *t = info->timings;
700 u8 itr_addr = 0x40 + (drive->dn * 4); 706 u8 itr_addr = 0x40 + (drive->dn * 4);
701 u32 old_itr = 0; 707 u32 old_itr = 0;
@@ -738,7 +744,8 @@ static void hpt3xx_maskproc(ide_drive_t *drive, int mask)
738{ 744{
739 ide_hwif_t *hwif = HWIF(drive); 745 ide_hwif_t *hwif = HWIF(drive);
740 struct pci_dev *dev = to_pci_dev(hwif->dev); 746 struct pci_dev *dev = to_pci_dev(hwif->dev);
741 struct hpt_info *info = pci_get_drvdata(dev); 747 struct ide_host *host = pci_get_drvdata(dev);
748 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
742 749
743 if (drive->quirk_list) { 750 if (drive->quirk_list) {
744 if (info->chip_type >= HPT370) { 751 if (info->chip_type >= HPT370) {
@@ -963,24 +970,16 @@ static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f
963 return 1; 970 return 1;
964} 971}
965 972
966static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name) 973static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev)
967{ 974{
968 struct hpt_info *info = kmalloc(sizeof(struct hpt_info), GFP_KERNEL);
969 unsigned long io_base = pci_resource_start(dev, 4); 975 unsigned long io_base = pci_resource_start(dev, 4);
976 struct ide_host *host = pci_get_drvdata(dev);
977 struct hpt_info *info = host->host_priv + (&dev->dev == host->dev[1]);
978 const char *name = DRV_NAME;
970 u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */ 979 u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */
971 u8 chip_type; 980 u8 chip_type;
972 enum ata_clock clock; 981 enum ata_clock clock;
973 982
974 if (info == NULL) {
975 printk(KERN_ERR "%s: out of memory!\n", name);
976 return -ENOMEM;
977 }
978
979 /*
980 * Copy everything from a static "template" structure
981 * to just allocated per-chip hpt_info structure.
982 */
983 memcpy(info, pci_get_drvdata(dev), sizeof(struct hpt_info));
984 chip_type = info->chip_type; 983 chip_type = info->chip_type;
985 984
986 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4)); 985 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
@@ -1048,8 +1047,8 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1048 if ((temp & 0xFFFFF000) != 0xABCDE000) { 1047 if ((temp & 0xFFFFF000) != 0xABCDE000) {
1049 int i; 1048 int i;
1050 1049
1051 printk(KERN_WARNING "%s: no clock data saved by BIOS\n", 1050 printk(KERN_WARNING "%s %s: no clock data saved by "
1052 name); 1051 "BIOS\n", name, pci_name(dev));
1053 1052
1054 /* Calculate the average value of f_CNT. */ 1053 /* Calculate the average value of f_CNT. */
1055 for (temp = i = 0; i < 128; i++) { 1054 for (temp = i = 0; i < 128; i++) {
@@ -1074,8 +1073,9 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1074 else 1073 else
1075 pci_clk = 66; 1074 pci_clk = 66;
1076 1075
1077 printk(KERN_INFO "%s: DPLL base: %d MHz, f_CNT: %d, " 1076 printk(KERN_INFO "%s %s: DPLL base: %d MHz, f_CNT: %d, "
1078 "assuming %d MHz PCI\n", name, dpll_clk, f_cnt, pci_clk); 1077 "assuming %d MHz PCI\n", name, pci_name(dev),
1078 dpll_clk, f_cnt, pci_clk);
1079 } else { 1079 } else {
1080 u32 itr1 = 0; 1080 u32 itr1 = 0;
1081 1081
@@ -1141,8 +1141,8 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1141 } 1141 }
1142 1142
1143 if (info->timings->clock_table[clock] == NULL) { 1143 if (info->timings->clock_table[clock] == NULL) {
1144 printk(KERN_ERR "%s: unknown bus timing!\n", name); 1144 printk(KERN_ERR "%s %s: unknown bus timing!\n",
1145 kfree(info); 1145 name, pci_name(dev));
1146 return -EIO; 1146 return -EIO;
1147 } 1147 }
1148 1148
@@ -1168,17 +1168,19 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1168 f_low += adjust >> 1; 1168 f_low += adjust >> 1;
1169 } 1169 }
1170 if (adjust == 8) { 1170 if (adjust == 8) {
1171 printk(KERN_ERR "%s: DPLL did not stabilize!\n", name); 1171 printk(KERN_ERR "%s %s: DPLL did not stabilize!\n",
1172 kfree(info); 1172 name, pci_name(dev));
1173 return -EIO; 1173 return -EIO;
1174 } 1174 }
1175 1175
1176 printk("%s: using %d MHz DPLL clock\n", name, dpll_clk); 1176 printk(KERN_INFO "%s %s: using %d MHz DPLL clock\n",
1177 name, pci_name(dev), dpll_clk);
1177 } else { 1178 } else {
1178 /* Mark the fact that we're not using the DPLL. */ 1179 /* Mark the fact that we're not using the DPLL. */
1179 dpll_clk = 0; 1180 dpll_clk = 0;
1180 1181
1181 printk("%s: using %d MHz PCI clock\n", name, pci_clk); 1182 printk(KERN_INFO "%s %s: using %d MHz PCI clock\n",
1183 name, pci_name(dev), pci_clk);
1182 } 1184 }
1183 1185
1184 /* Store the clock frequencies. */ 1186 /* Store the clock frequencies. */
@@ -1186,9 +1188,6 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1186 info->pci_clk = pci_clk; 1188 info->pci_clk = pci_clk;
1187 info->clock = clock; 1189 info->clock = clock;
1188 1190
1189 /* Point to this chip's own instance of the hpt_info structure. */
1190 pci_set_drvdata(dev, info);
1191
1192 if (chip_type >= HPT370) { 1191 if (chip_type >= HPT370) {
1193 u8 mcr1, mcr4; 1192 u8 mcr1, mcr4;
1194 1193
@@ -1218,7 +1217,8 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1218static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif) 1217static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif)
1219{ 1218{
1220 struct pci_dev *dev = to_pci_dev(hwif->dev); 1219 struct pci_dev *dev = to_pci_dev(hwif->dev);
1221 struct hpt_info *info = pci_get_drvdata(dev); 1220 struct ide_host *host = pci_get_drvdata(dev);
1221 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
1222 u8 chip_type = info->chip_type; 1222 u8 chip_type = info->chip_type;
1223 u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02; 1223 u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02;
1224 1224
@@ -1262,7 +1262,8 @@ static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif)
1262static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) 1262static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1263{ 1263{
1264 struct pci_dev *dev = to_pci_dev(hwif->dev); 1264 struct pci_dev *dev = to_pci_dev(hwif->dev);
1265 struct hpt_info *info = pci_get_drvdata(dev); 1265 struct ide_host *host = pci_get_drvdata(dev);
1266 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
1266 int serialize = HPT_SERIALIZE_IO; 1267 int serialize = HPT_SERIALIZE_IO;
1267 u8 chip_type = info->chip_type; 1268 u8 chip_type = info->chip_type;
1268 u8 new_mcr, old_mcr = 0; 1269 u8 new_mcr, old_mcr = 0;
@@ -1364,7 +1365,8 @@ static void __devinit hpt374_init(struct pci_dev *dev, struct pci_dev *dev2)
1364 if (dev2->irq != dev->irq) { 1365 if (dev2->irq != dev->irq) {
1365 /* FIXME: we need a core pci_set_interrupt() */ 1366 /* FIXME: we need a core pci_set_interrupt() */
1366 dev2->irq = dev->irq; 1367 dev2->irq = dev->irq;
1367 printk(KERN_INFO "HPT374: PCI config space interrupt fixed\n"); 1368 printk(KERN_INFO DRV_NAME " %s: PCI config space interrupt "
1369 "fixed\n", pci_name(dev2));
1368 } 1370 }
1369} 1371}
1370 1372
@@ -1399,8 +1401,8 @@ static int __devinit hpt36x_init(struct pci_dev *dev, struct pci_dev *dev2)
1399 pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin2); 1401 pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin2);
1400 1402
1401 if (pin1 != pin2 && dev->irq == dev2->irq) { 1403 if (pin1 != pin2 && dev->irq == dev2->irq) {
1402 printk(KERN_INFO "HPT36x: onboard version of chipset, " 1404 printk(KERN_INFO DRV_NAME " %s: onboard version of chipset, "
1403 "pin1=%d pin2=%d\n", pin1, pin2); 1405 "pin1=%d pin2=%d\n", pci_name(dev), pin1, pin2);
1404 return 1; 1406 return 1;
1405 } 1407 }
1406 1408
@@ -1455,8 +1457,8 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
1455}; 1457};
1456 1458
1457static const struct ide_port_info hpt366_chipsets[] __devinitdata = { 1459static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
1458 { /* 0 */ 1460 { /* 0: HPT36x */
1459 .name = "HPT36x", 1461 .name = DRV_NAME,
1460 .init_chipset = init_chipset_hpt366, 1462 .init_chipset = init_chipset_hpt366,
1461 .init_hwif = init_hwif_hpt366, 1463 .init_hwif = init_hwif_hpt366,
1462 .init_dma = init_dma_hpt366, 1464 .init_dma = init_dma_hpt366,
@@ -1472,53 +1474,9 @@ static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
1472 .host_flags = IDE_HFLAGS_HPT3XX | IDE_HFLAG_SINGLE, 1474 .host_flags = IDE_HFLAGS_HPT3XX | IDE_HFLAG_SINGLE,
1473 .pio_mask = ATA_PIO4, 1475 .pio_mask = ATA_PIO4,
1474 .mwdma_mask = ATA_MWDMA2, 1476 .mwdma_mask = ATA_MWDMA2,
1475 },{ /* 1 */ 1477 },
1476 .name = "HPT372A", 1478 { /* 1: HPT3xx */
1477 .init_chipset = init_chipset_hpt366, 1479 .name = DRV_NAME,
1478 .init_hwif = init_hwif_hpt366,
1479 .init_dma = init_dma_hpt366,
1480 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1481 .port_ops = &hpt3xx_port_ops,
1482 .dma_ops = &hpt37x_dma_ops,
1483 .host_flags = IDE_HFLAGS_HPT3XX,
1484 .pio_mask = ATA_PIO4,
1485 .mwdma_mask = ATA_MWDMA2,
1486 },{ /* 2 */
1487 .name = "HPT302",
1488 .init_chipset = init_chipset_hpt366,
1489 .init_hwif = init_hwif_hpt366,
1490 .init_dma = init_dma_hpt366,
1491 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1492 .port_ops = &hpt3xx_port_ops,
1493 .dma_ops = &hpt37x_dma_ops,
1494 .host_flags = IDE_HFLAGS_HPT3XX,
1495 .pio_mask = ATA_PIO4,
1496 .mwdma_mask = ATA_MWDMA2,
1497 },{ /* 3 */
1498 .name = "HPT371",
1499 .init_chipset = init_chipset_hpt366,
1500 .init_hwif = init_hwif_hpt366,
1501 .init_dma = init_dma_hpt366,
1502 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1503 .port_ops = &hpt3xx_port_ops,
1504 .dma_ops = &hpt37x_dma_ops,
1505 .host_flags = IDE_HFLAGS_HPT3XX,
1506 .pio_mask = ATA_PIO4,
1507 .mwdma_mask = ATA_MWDMA2,
1508 },{ /* 4 */
1509 .name = "HPT374",
1510 .init_chipset = init_chipset_hpt366,
1511 .init_hwif = init_hwif_hpt366,
1512 .init_dma = init_dma_hpt366,
1513 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1514 .udma_mask = ATA_UDMA5,
1515 .port_ops = &hpt3xx_port_ops,
1516 .dma_ops = &hpt37x_dma_ops,
1517 .host_flags = IDE_HFLAGS_HPT3XX,
1518 .pio_mask = ATA_PIO4,
1519 .mwdma_mask = ATA_MWDMA2,
1520 },{ /* 5 */
1521 .name = "HPT372N",
1522 .init_chipset = init_chipset_hpt366, 1480 .init_chipset = init_chipset_hpt366,
1523 .init_hwif = init_hwif_hpt366, 1481 .init_hwif = init_hwif_hpt366,
1524 .init_dma = init_dma_hpt366, 1482 .init_dma = init_dma_hpt366,
@@ -1542,10 +1500,12 @@ static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
1542static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id) 1500static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1543{ 1501{
1544 const struct hpt_info *info = NULL; 1502 const struct hpt_info *info = NULL;
1503 struct hpt_info *dyn_info;
1545 struct pci_dev *dev2 = NULL; 1504 struct pci_dev *dev2 = NULL;
1546 struct ide_port_info d; 1505 struct ide_port_info d;
1547 u8 idx = id->driver_data; 1506 u8 idx = id->driver_data;
1548 u8 rev = dev->revision; 1507 u8 rev = dev->revision;
1508 int ret;
1549 1509
1550 if ((idx == 0 || idx == 4) && (PCI_FUNC(dev->devfn) & 1)) 1510 if ((idx == 0 || idx == 4) && (PCI_FUNC(dev->devfn) & 1))
1551 return -ENODEV; 1511 return -ENODEV;
@@ -1582,24 +1542,35 @@ static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_devic
1582 break; 1542 break;
1583 } 1543 }
1584 1544
1585 d = hpt366_chipsets[idx]; 1545 printk(KERN_INFO DRV_NAME ": %s chipset detected\n", info->chip_name);
1546
1547 d = hpt366_chipsets[min_t(u8, idx, 1)];
1586 1548
1587 d.name = info->chip_name;
1588 d.udma_mask = info->udma_mask; 1549 d.udma_mask = info->udma_mask;
1589 1550
1590 /* fixup ->dma_ops for HPT370/HPT370A */ 1551 /* fixup ->dma_ops for HPT370/HPT370A */
1591 if (info == &hpt370 || info == &hpt370a) 1552 if (info == &hpt370 || info == &hpt370a)
1592 d.dma_ops = &hpt370_dma_ops; 1553 d.dma_ops = &hpt370_dma_ops;
1593 1554
1594 pci_set_drvdata(dev, (void *)info);
1595
1596 if (info == &hpt36x || info == &hpt374) 1555 if (info == &hpt36x || info == &hpt374)
1597 dev2 = pci_get_slot(dev->bus, dev->devfn + 1); 1556 dev2 = pci_get_slot(dev->bus, dev->devfn + 1);
1598 1557
1599 if (dev2) { 1558 dyn_info = kzalloc(sizeof(*dyn_info) * (dev2 ? 2 : 1), GFP_KERNEL);
1600 int ret; 1559 if (dyn_info == NULL) {
1560 printk(KERN_ERR "%s %s: out of memory!\n",
1561 d.name, pci_name(dev));
1562 pci_dev_put(dev2);
1563 return -ENOMEM;
1564 }
1565
1566 /*
1567 * Copy everything from a static "template" structure
1568 * to just allocated per-chip hpt_info structure.
1569 */
1570 memcpy(dyn_info, info, sizeof(*dyn_info));
1601 1571
1602 pci_set_drvdata(dev2, (void *)info); 1572 if (dev2) {
1573 memcpy(dyn_info + 1, info, sizeof(*dyn_info));
1603 1574
1604 if (info == &hpt374) 1575 if (info == &hpt374)
1605 hpt374_init(dev, dev2); 1576 hpt374_init(dev, dev2);
@@ -1608,13 +1579,30 @@ static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_devic
1608 d.host_flags &= ~IDE_HFLAG_NON_BOOTABLE; 1579 d.host_flags &= ~IDE_HFLAG_NON_BOOTABLE;
1609 } 1580 }
1610 1581
1611 ret = ide_setup_pci_devices(dev, dev2, &d); 1582 ret = ide_pci_init_two(dev, dev2, &d, dyn_info);
1612 if (ret < 0) 1583 if (ret < 0) {
1613 pci_dev_put(dev2); 1584 pci_dev_put(dev2);
1585 kfree(dyn_info);
1586 }
1614 return ret; 1587 return ret;
1615 } 1588 }
1616 1589
1617 return ide_setup_pci_device(dev, &d); 1590 ret = ide_pci_init_one(dev, &d, dyn_info);
1591 if (ret < 0)
1592 kfree(dyn_info);
1593
1594 return ret;
1595}
1596
1597static void __devexit hpt366_remove(struct pci_dev *dev)
1598{
1599 struct ide_host *host = pci_get_drvdata(dev);
1600 struct ide_info *info = host->host_priv;
1601 struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
1602
1603 ide_pci_remove(dev);
1604 pci_dev_put(dev2);
1605 kfree(info);
1618} 1606}
1619 1607
1620static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = { 1608static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = {
@@ -1632,6 +1620,7 @@ static struct pci_driver driver = {
1632 .name = "HPT366_IDE", 1620 .name = "HPT366_IDE",
1633 .id_table = hpt366_pci_tbl, 1621 .id_table = hpt366_pci_tbl,
1634 .probe = hpt366_init_one, 1622 .probe = hpt366_init_one,
1623 .remove = hpt366_remove,
1635}; 1624};
1636 1625
1637static int __init hpt366_ide_init(void) 1626static int __init hpt366_ide_init(void)
@@ -1639,7 +1628,13 @@ static int __init hpt366_ide_init(void)
1639 return ide_pci_register_driver(&driver); 1628 return ide_pci_register_driver(&driver);
1640} 1629}
1641 1630
1631static void __exit hpt366_ide_exit(void)
1632{
1633 pci_unregister_driver(&driver);
1634}
1635
1642module_init(hpt366_ide_init); 1636module_init(hpt366_ide_init);
1637module_exit(hpt366_ide_exit);
1643 1638
1644MODULE_AUTHOR("Andre Hedrick"); 1639MODULE_AUTHOR("Andre Hedrick");
1645MODULE_DESCRIPTION("PCI driver module for Highpoint HPT366 IDE"); 1640MODULE_DESCRIPTION("PCI driver module for Highpoint HPT366 IDE");
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index 2b71bdf74e73..6eba8f188264 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -14,6 +14,8 @@
14#include <linux/ide.h> 14#include <linux/ide.h>
15#include <linux/init.h> 15#include <linux/init.h>
16 16
17#define DRV_NAME "it8213"
18
17/** 19/**
18 * it8213_set_pio_mode - set host controller for PIO mode 20 * it8213_set_pio_mode - set host controller for PIO mode
19 * @drive: drive 21 * @drive: drive
@@ -155,23 +157,17 @@ static const struct ide_port_ops it8213_port_ops = {
155 .cable_detect = it8213_cable_detect, 157 .cable_detect = it8213_cable_detect,
156}; 158};
157 159
158#define DECLARE_ITE_DEV(name_str) \ 160static const struct ide_port_info it8213_chipset __devinitdata = {
159 { \ 161 .name = DRV_NAME,
160 .name = name_str, \ 162 .enablebits = { {0x41, 0x80, 0x80} },
161 .enablebits = { {0x41, 0x80, 0x80} }, \ 163 .port_ops = &it8213_port_ops,
162 .port_ops = &it8213_port_ops, \ 164 .host_flags = IDE_HFLAG_SINGLE,
163 .host_flags = IDE_HFLAG_SINGLE, \ 165 .pio_mask = ATA_PIO4,
164 .pio_mask = ATA_PIO4, \ 166 .swdma_mask = ATA_SWDMA2_ONLY,
165 .swdma_mask = ATA_SWDMA2_ONLY, \ 167 .mwdma_mask = ATA_MWDMA12_ONLY,
166 .mwdma_mask = ATA_MWDMA12_ONLY, \ 168 .udma_mask = ATA_UDMA6,
167 .udma_mask = ATA_UDMA6, \
168 }
169
170static const struct ide_port_info it8213_chipsets[] __devinitdata = {
171 /* 0 */ DECLARE_ITE_DEV("IT8213"),
172}; 169};
173 170
174
175/** 171/**
176 * it8213_init_one - pci layer discovery entry 172 * it8213_init_one - pci layer discovery entry
177 * @dev: PCI device 173 * @dev: PCI device
@@ -184,7 +180,7 @@ static const struct ide_port_info it8213_chipsets[] __devinitdata = {
184 180
185static int __devinit it8213_init_one(struct pci_dev *dev, const struct pci_device_id *id) 181static int __devinit it8213_init_one(struct pci_dev *dev, const struct pci_device_id *id)
186{ 182{
187 return ide_setup_pci_device(dev, &it8213_chipsets[id->driver_data]); 183 return ide_pci_init_one(dev, &it8213_chipset, NULL);
188} 184}
189 185
190static const struct pci_device_id it8213_pci_tbl[] = { 186static const struct pci_device_id it8213_pci_tbl[] = {
@@ -198,6 +194,7 @@ static struct pci_driver driver = {
198 .name = "ITE8213_IDE", 194 .name = "ITE8213_IDE",
199 .id_table = it8213_pci_tbl, 195 .id_table = it8213_pci_tbl,
200 .probe = it8213_init_one, 196 .probe = it8213_init_one,
197 .remove = ide_pci_remove,
201}; 198};
202 199
203static int __init it8213_ide_init(void) 200static int __init it8213_ide_init(void)
@@ -205,7 +202,13 @@ static int __init it8213_ide_init(void)
205 return ide_pci_register_driver(&driver); 202 return ide_pci_register_driver(&driver);
206} 203}
207 204
205static void __exit it8213_ide_exit(void)
206{
207 pci_unregister_driver(&driver);
208}
209
208module_init(it8213_ide_init); 210module_init(it8213_ide_init);
211module_exit(it8213_ide_exit);
209 212
210MODULE_AUTHOR("Jack Lee, Alan Cox"); 213MODULE_AUTHOR("Jack Lee, Alan Cox");
211MODULE_DESCRIPTION("PCI driver module for the ITE 8213"); 214MODULE_DESCRIPTION("PCI driver module for the ITE 8213");
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index cbf647202994..e16a1d113a2a 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -67,6 +67,8 @@
67#include <linux/ide.h> 67#include <linux/ide.h>
68#include <linux/init.h> 68#include <linux/init.h>
69 69
70#define DRV_NAME "it821x"
71
70struct it821x_dev 72struct it821x_dev
71{ 73{
72 unsigned int smart:1, /* Are we in smart raid mode */ 74 unsigned int smart:1, /* Are we in smart raid mode */
@@ -534,8 +536,9 @@ static struct ide_dma_ops it821x_pass_through_dma_ops = {
534static void __devinit init_hwif_it821x(ide_hwif_t *hwif) 536static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
535{ 537{
536 struct pci_dev *dev = to_pci_dev(hwif->dev); 538 struct pci_dev *dev = to_pci_dev(hwif->dev);
537 struct it821x_dev **itdevs = (struct it821x_dev **)pci_get_drvdata(dev); 539 struct ide_host *host = pci_get_drvdata(dev);
538 struct it821x_dev *idev = itdevs[hwif->channel]; 540 struct it821x_dev *itdevs = host->host_priv;
541 struct it821x_dev *idev = itdevs + hwif->channel;
539 u8 conf; 542 u8 conf;
540 543
541 ide_set_hwifdata(hwif, idev); 544 ide_set_hwifdata(hwif, idev);
@@ -568,7 +571,8 @@ static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
568 idev->timing10 = 1; 571 idev->timing10 = 1;
569 hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA; 572 hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
570 if (idev->smart == 0) 573 if (idev->smart == 0)
571 printk(KERN_WARNING "it821x: Revision 0x10, workarounds activated.\n"); 574 printk(KERN_WARNING DRV_NAME " %s: revision 0x10, "
575 "workarounds activated\n", pci_name(dev));
572 } 576 }
573 577
574 if (idev->smart == 0) { 578 if (idev->smart == 0) {
@@ -601,18 +605,20 @@ static void __devinit it8212_disable_raid(struct pci_dev *dev)
601 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20); 605 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
602} 606}
603 607
604static unsigned int __devinit init_chipset_it821x(struct pci_dev *dev, const char *name) 608static unsigned int __devinit init_chipset_it821x(struct pci_dev *dev)
605{ 609{
606 u8 conf; 610 u8 conf;
607 static char *mode[2] = { "pass through", "smart" }; 611 static char *mode[2] = { "pass through", "smart" };
608 612
609 /* Force the card into bypass mode if so requested */ 613 /* Force the card into bypass mode if so requested */
610 if (it8212_noraid) { 614 if (it8212_noraid) {
611 printk(KERN_INFO "it8212: forcing bypass mode.\n"); 615 printk(KERN_INFO DRV_NAME " %s: forcing bypass mode\n",
616 pci_name(dev));
612 it8212_disable_raid(dev); 617 it8212_disable_raid(dev);
613 } 618 }
614 pci_read_config_byte(dev, 0x50, &conf); 619 pci_read_config_byte(dev, 0x50, &conf);
615 printk(KERN_INFO "it821x: controller in %s mode.\n", mode[conf & 1]); 620 printk(KERN_INFO DRV_NAME " %s: controller in %s mode\n",
621 pci_name(dev), mode[conf & 1]);
616 return 0; 622 return 0;
617} 623}
618 624
@@ -624,17 +630,12 @@ static const struct ide_port_ops it821x_port_ops = {
624 .cable_detect = it821x_cable_detect, 630 .cable_detect = it821x_cable_detect,
625}; 631};
626 632
627#define DECLARE_ITE_DEV(name_str) \ 633static const struct ide_port_info it821x_chipset __devinitdata = {
628 { \ 634 .name = DRV_NAME,
629 .name = name_str, \ 635 .init_chipset = init_chipset_it821x,
630 .init_chipset = init_chipset_it821x, \ 636 .init_hwif = init_hwif_it821x,
631 .init_hwif = init_hwif_it821x, \ 637 .port_ops = &it821x_port_ops,
632 .port_ops = &it821x_port_ops, \ 638 .pio_mask = ATA_PIO4,
633 .pio_mask = ATA_PIO4, \
634 }
635
636static const struct ide_port_info it821x_chipsets[] __devinitdata = {
637 /* 0 */ DECLARE_ITE_DEV("IT8212"),
638}; 639};
639 640
640/** 641/**
@@ -648,23 +649,29 @@ static const struct ide_port_info it821x_chipsets[] __devinitdata = {
648 649
649static int __devinit it821x_init_one(struct pci_dev *dev, const struct pci_device_id *id) 650static int __devinit it821x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
650{ 651{
651 struct it821x_dev *itdevs[2] = { NULL, NULL} , *itdev; 652 struct it821x_dev *itdevs;
652 unsigned int i; 653 int rc;
653
654 for (i = 0; i < 2; i++) {
655 itdev = kzalloc(sizeof(*itdev), GFP_KERNEL);
656 if (itdev == NULL) {
657 kfree(itdevs[0]);
658 printk(KERN_ERR "it821x: out of memory\n");
659 return -ENOMEM;
660 }
661 654
662 itdevs[i] = itdev; 655 itdevs = kzalloc(2 * sizeof(*itdevs), GFP_KERNEL);
656 if (itdevs == NULL) {
657 printk(KERN_ERR DRV_NAME " %s: out of memory\n", pci_name(dev));
658 return -ENOMEM;
663 } 659 }
664 660
665 pci_set_drvdata(dev, itdevs); 661 rc = ide_pci_init_one(dev, &it821x_chipset, itdevs);
662 if (rc)
663 kfree(itdevs);
666 664
667 return ide_setup_pci_device(dev, &it821x_chipsets[id->driver_data]); 665 return rc;
666}
667
668static void __devexit it821x_remove(struct pci_dev *dev)
669{
670 struct ide_host *host = pci_get_drvdata(dev);
671 struct it821x_dev *itdevs = host->host_priv;
672
673 ide_pci_remove(dev);
674 kfree(itdevs);
668} 675}
669 676
670static const struct pci_device_id it821x_pci_tbl[] = { 677static const struct pci_device_id it821x_pci_tbl[] = {
@@ -679,6 +686,7 @@ static struct pci_driver driver = {
679 .name = "ITE821x IDE", 686 .name = "ITE821x IDE",
680 .id_table = it821x_pci_tbl, 687 .id_table = it821x_pci_tbl,
681 .probe = it821x_init_one, 688 .probe = it821x_init_one,
689 .remove = it821x_remove,
682}; 690};
683 691
684static int __init it821x_ide_init(void) 692static int __init it821x_ide_init(void)
@@ -686,7 +694,13 @@ static int __init it821x_ide_init(void)
686 return ide_pci_register_driver(&driver); 694 return ide_pci_register_driver(&driver);
687} 695}
688 696
697static void __exit it821x_ide_exit(void)
698{
699 pci_unregister_driver(&driver);
700}
701
689module_init(it821x_ide_init); 702module_init(it821x_ide_init);
703module_exit(it821x_ide_exit);
690 704
691module_param_named(noraid, it8212_noraid, int, S_IRUGO); 705module_param_named(noraid, it8212_noraid, int, S_IRUGO);
692MODULE_PARM_DESC(noraid, "Force card into bypass mode"); 706MODULE_PARM_DESC(noraid, "Force card into bypass mode");
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index 96ef7394f283..545b6e172d9b 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -12,6 +12,8 @@
12#include <linux/ide.h> 12#include <linux/ide.h>
13#include <linux/init.h> 13#include <linux/init.h>
14 14
15#define DRV_NAME "jmicron"
16
15typedef enum { 17typedef enum {
16 PORT_PATA0 = 0, 18 PORT_PATA0 = 0,
17 PORT_PATA1 = 1, 19 PORT_PATA1 = 1,
@@ -102,7 +104,7 @@ static const struct ide_port_ops jmicron_port_ops = {
102}; 104};
103 105
104static const struct ide_port_info jmicron_chipset __devinitdata = { 106static const struct ide_port_info jmicron_chipset __devinitdata = {
105 .name = "JMB", 107 .name = DRV_NAME,
106 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } }, 108 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
107 .port_ops = &jmicron_port_ops, 109 .port_ops = &jmicron_port_ops,
108 .pio_mask = ATA_PIO5, 110 .pio_mask = ATA_PIO5,
@@ -121,7 +123,7 @@ static const struct ide_port_info jmicron_chipset __devinitdata = {
121 123
122static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id) 124static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
123{ 125{
124 return ide_setup_pci_device(dev, &jmicron_chipset); 126 return ide_pci_init_one(dev, &jmicron_chipset, NULL);
125} 127}
126 128
127/* All JMB PATA controllers have and will continue to have the same 129/* All JMB PATA controllers have and will continue to have the same
@@ -152,6 +154,7 @@ static struct pci_driver driver = {
152 .name = "JMicron IDE", 154 .name = "JMicron IDE",
153 .id_table = jmicron_pci_tbl, 155 .id_table = jmicron_pci_tbl,
154 .probe = jmicron_init_one, 156 .probe = jmicron_init_one,
157 .remove = ide_pci_remove,
155}; 158};
156 159
157static int __init jmicron_ide_init(void) 160static int __init jmicron_ide_init(void)
@@ -159,7 +162,13 @@ static int __init jmicron_ide_init(void)
159 return ide_pci_register_driver(&driver); 162 return ide_pci_register_driver(&driver);
160} 163}
161 164
165static void __exit jmicron_ide_exit(void)
166{
167 pci_unregister_driver(&driver);
168}
169
162module_init(jmicron_ide_init); 170module_init(jmicron_ide_init);
171module_exit(jmicron_ide_exit);
163 172
164MODULE_AUTHOR("Alan Cox"); 173MODULE_AUTHOR("Alan Cox");
165MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes"); 174MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index 5cd2b32ff0ef..ffefcd15196c 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/ns87415.c
@@ -19,6 +19,8 @@
19 19
20#include <asm/io.h> 20#include <asm/io.h>
21 21
22#define DRV_NAME "ns87415"
23
22#ifdef CONFIG_SUPERIO 24#ifdef CONFIG_SUPERIO
23/* SUPERIO 87560 is a PoS chip that NatSem denies exists. 25/* SUPERIO 87560 is a PoS chip that NatSem denies exists.
24 * Unfortunately, it's built-in on all Astro-based PA-RISC workstations 26 * Unfortunately, it's built-in on all Astro-based PA-RISC workstations
@@ -305,7 +307,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
305}; 307};
306 308
307static const struct ide_port_info ns87415_chipset __devinitdata = { 309static const struct ide_port_info ns87415_chipset __devinitdata = {
308 .name = "NS87415", 310 .name = DRV_NAME,
309 .init_hwif = init_hwif_ns87415, 311 .init_hwif = init_hwif_ns87415,
310 .port_ops = &ns87415_port_ops, 312 .port_ops = &ns87415_port_ops,
311 .dma_ops = &ns87415_dma_ops, 313 .dma_ops = &ns87415_dma_ops,
@@ -324,7 +326,7 @@ static int __devinit ns87415_init_one(struct pci_dev *dev, const struct pci_devi
324 d.tp_ops = &superio_tp_ops; 326 d.tp_ops = &superio_tp_ops;
325 } 327 }
326#endif 328#endif
327 return ide_setup_pci_device(dev, &d); 329 return ide_pci_init_one(dev, &d, NULL);
328} 330}
329 331
330static const struct pci_device_id ns87415_pci_tbl[] = { 332static const struct pci_device_id ns87415_pci_tbl[] = {
@@ -337,6 +339,7 @@ static struct pci_driver driver = {
337 .name = "NS87415_IDE", 339 .name = "NS87415_IDE",
338 .id_table = ns87415_pci_tbl, 340 .id_table = ns87415_pci_tbl,
339 .probe = ns87415_init_one, 341 .probe = ns87415_init_one,
342 .remove = ide_pci_remove,
340}; 343};
341 344
342static int __init ns87415_ide_init(void) 345static int __init ns87415_ide_init(void)
@@ -344,7 +347,13 @@ static int __init ns87415_ide_init(void)
344 return ide_pci_register_driver(&driver); 347 return ide_pci_register_driver(&driver);
345} 348}
346 349
350static void __exit ns87415_ide_exit(void)
351{
352 pci_unregister_driver(&driver);
353}
354
347module_init(ns87415_ide_init); 355module_init(ns87415_ide_init);
356module_exit(ns87415_ide_exit);
348 357
349MODULE_AUTHOR("Mark Lord, Eddie Dost, Andre Hedrick"); 358MODULE_AUTHOR("Mark Lord, Eddie Dost, Andre Hedrick");
350MODULE_DESCRIPTION("PCI driver module for NS87415 IDE"); 359MODULE_DESCRIPTION("PCI driver module for NS87415 IDE");
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index 725c80508d90..e28e672ddafc 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -90,6 +90,8 @@
90 90
91#include <asm/io.h> 91#include <asm/io.h>
92 92
93#define DRV_NAME "opti621"
94
93#define READ_REG 0 /* index of Read cycle timing register */ 95#define READ_REG 0 /* index of Read cycle timing register */
94#define WRITE_REG 1 /* index of Write cycle timing register */ 96#define WRITE_REG 1 /* index of Write cycle timing register */
95#define CNTRL_REG 3 /* index of Control register */ 97#define CNTRL_REG 3 /* index of Control register */
@@ -200,7 +202,7 @@ static const struct ide_port_ops opti621_port_ops = {
200}; 202};
201 203
202static const struct ide_port_info opti621_chipset __devinitdata = { 204static const struct ide_port_info opti621_chipset __devinitdata = {
203 .name = "OPTI621/X", 205 .name = DRV_NAME,
204 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} }, 206 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
205 .port_ops = &opti621_port_ops, 207 .port_ops = &opti621_port_ops,
206 .host_flags = IDE_HFLAG_NO_DMA, 208 .host_flags = IDE_HFLAG_NO_DMA,
@@ -209,7 +211,7 @@ static const struct ide_port_info opti621_chipset __devinitdata = {
209 211
210static int __devinit opti621_init_one(struct pci_dev *dev, const struct pci_device_id *id) 212static int __devinit opti621_init_one(struct pci_dev *dev, const struct pci_device_id *id)
211{ 213{
212 return ide_setup_pci_device(dev, &opti621_chipset); 214 return ide_pci_init_one(dev, &opti621_chipset, NULL);
213} 215}
214 216
215static const struct pci_device_id opti621_pci_tbl[] = { 217static const struct pci_device_id opti621_pci_tbl[] = {
@@ -223,6 +225,7 @@ static struct pci_driver driver = {
223 .name = "Opti621_IDE", 225 .name = "Opti621_IDE",
224 .id_table = opti621_pci_tbl, 226 .id_table = opti621_pci_tbl,
225 .probe = opti621_init_one, 227 .probe = opti621_init_one,
228 .remove = ide_pci_remove,
226}; 229};
227 230
228static int __init opti621_ide_init(void) 231static int __init opti621_ide_init(void)
@@ -230,7 +233,13 @@ static int __init opti621_ide_init(void)
230 return ide_pci_register_driver(&driver); 233 return ide_pci_register_driver(&driver);
231} 234}
232 235
236static void __exit opti621_ide_exit(void)
237{
238 pci_unregister_driver(&driver);
239}
240
233module_init(opti621_ide_init); 241module_init(opti621_ide_init);
242module_exit(opti621_ide_exit);
234 243
235MODULE_AUTHOR("Jaromir Koutek, Jan Harkes, Mark Lord"); 244MODULE_AUTHOR("Jaromir Koutek, Jan Harkes, Mark Lord");
236MODULE_DESCRIPTION("PCI driver module for Opti621 IDE"); 245MODULE_DESCRIPTION("PCI driver module for Opti621 IDE");
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 070df8ab3b21..998615fa285f 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -31,6 +31,8 @@
31#include <asm/pci-bridge.h> 31#include <asm/pci-bridge.h>
32#endif 32#endif
33 33
34#define DRV_NAME "pdc202xx_new"
35
34#undef DEBUG 36#undef DEBUG
35 37
36#ifdef DEBUG 38#ifdef DEBUG
@@ -324,8 +326,9 @@ static void __devinit apple_kiwi_init(struct pci_dev *pdev)
324} 326}
325#endif /* CONFIG_PPC_PMAC */ 327#endif /* CONFIG_PPC_PMAC */
326 328
327static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev, const char *name) 329static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev)
328{ 330{
331 const char *name = DRV_NAME;
329 unsigned long dma_base = pci_resource_start(dev, 4); 332 unsigned long dma_base = pci_resource_start(dev, 4);
330 unsigned long sec_dma_base = dma_base + 0x08; 333 unsigned long sec_dma_base = dma_base + 0x08;
331 long pll_input, pll_output, ratio; 334 long pll_input, pll_output, ratio;
@@ -358,12 +361,13 @@ static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev, const cha
358 * registers setting. 361 * registers setting.
359 */ 362 */
360 pll_input = detect_pll_input_clock(dma_base); 363 pll_input = detect_pll_input_clock(dma_base);
361 printk("%s: PLL input clock is %ld kHz\n", name, pll_input / 1000); 364 printk(KERN_INFO "%s %s: PLL input clock is %ld kHz\n",
365 name, pci_name(dev), pll_input / 1000);
362 366
363 /* Sanity check */ 367 /* Sanity check */
364 if (unlikely(pll_input < 5000000L || pll_input > 70000000L)) { 368 if (unlikely(pll_input < 5000000L || pll_input > 70000000L)) {
365 printk(KERN_ERR "%s: Bad PLL input clock %ld Hz, giving up!\n", 369 printk(KERN_ERR "%s %s: Bad PLL input clock %ld Hz, giving up!"
366 name, pll_input); 370 "\n", name, pci_name(dev), pll_input);
367 goto out; 371 goto out;
368 } 372 }
369 373
@@ -399,7 +403,8 @@ static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev, const cha
399 r = 0x00; 403 r = 0x00;
400 } else { 404 } else {
401 /* Invalid ratio */ 405 /* Invalid ratio */
402 printk(KERN_ERR "%s: Bad ratio %ld, giving up!\n", name, ratio); 406 printk(KERN_ERR "%s %s: Bad ratio %ld, giving up!\n",
407 name, pci_name(dev), ratio);
403 goto out; 408 goto out;
404 } 409 }
405 410
@@ -409,7 +414,8 @@ static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev, const cha
409 414
410 if (unlikely(f < 0 || f > 127)) { 415 if (unlikely(f < 0 || f > 127)) {
411 /* Invalid F */ 416 /* Invalid F */
412 printk(KERN_ERR "%s: F[%d] invalid!\n", name, f); 417 printk(KERN_ERR "%s %s: F[%d] invalid!\n",
418 name, pci_name(dev), f);
413 goto out; 419 goto out;
414 } 420 }
415 421
@@ -455,8 +461,8 @@ static struct pci_dev * __devinit pdc20270_get_dev2(struct pci_dev *dev)
455 461
456 if (dev2->irq != dev->irq) { 462 if (dev2->irq != dev->irq) {
457 dev2->irq = dev->irq; 463 dev2->irq = dev->irq;
458 printk(KERN_INFO "PDC20270: PCI config space " 464 printk(KERN_INFO DRV_NAME " %s: PCI config space "
459 "interrupt fixed\n"); 465 "interrupt fixed\n", pci_name(dev));
460 } 466 }
461 467
462 return dev2; 468 return dev2;
@@ -473,9 +479,9 @@ static const struct ide_port_ops pdcnew_port_ops = {
473 .cable_detect = pdcnew_cable_detect, 479 .cable_detect = pdcnew_cable_detect,
474}; 480};
475 481
476#define DECLARE_PDCNEW_DEV(name_str, udma) \ 482#define DECLARE_PDCNEW_DEV(udma) \
477 { \ 483 { \
478 .name = name_str, \ 484 .name = DRV_NAME, \
479 .init_chipset = init_chipset_pdcnew, \ 485 .init_chipset = init_chipset_pdcnew, \
480 .port_ops = &pdcnew_port_ops, \ 486 .port_ops = &pdcnew_port_ops, \
481 .host_flags = IDE_HFLAG_POST_SET_MODE | \ 487 .host_flags = IDE_HFLAG_POST_SET_MODE | \
@@ -487,13 +493,8 @@ static const struct ide_port_ops pdcnew_port_ops = {
487 } 493 }
488 494
489static const struct ide_port_info pdcnew_chipsets[] __devinitdata = { 495static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
490 /* 0 */ DECLARE_PDCNEW_DEV("PDC20268", ATA_UDMA5), 496 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
491 /* 1 */ DECLARE_PDCNEW_DEV("PDC20269", ATA_UDMA6), 497 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
492 /* 2 */ DECLARE_PDCNEW_DEV("PDC20270", ATA_UDMA5),
493 /* 3 */ DECLARE_PDCNEW_DEV("PDC20271", ATA_UDMA6),
494 /* 4 */ DECLARE_PDCNEW_DEV("PDC20275", ATA_UDMA6),
495 /* 5 */ DECLARE_PDCNEW_DEV("PDC20276", ATA_UDMA6),
496 /* 6 */ DECLARE_PDCNEW_DEV("PDC20277", ATA_UDMA6),
497}; 498};
498 499
499/** 500/**
@@ -507,13 +508,10 @@ static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
507 508
508static int __devinit pdc202new_init_one(struct pci_dev *dev, const struct pci_device_id *id) 509static int __devinit pdc202new_init_one(struct pci_dev *dev, const struct pci_device_id *id)
509{ 510{
510 const struct ide_port_info *d; 511 const struct ide_port_info *d = &pdcnew_chipsets[id->driver_data];
511 struct pci_dev *bridge = dev->bus->self; 512 struct pci_dev *bridge = dev->bus->self;
512 u8 idx = id->driver_data;
513
514 d = &pdcnew_chipsets[idx];
515 513
516 if (idx == 2 && bridge && 514 if (dev->device == PCI_DEVICE_ID_PROMISE_20270 && bridge &&
517 bridge->vendor == PCI_VENDOR_ID_DEC && 515 bridge->vendor == PCI_VENDOR_ID_DEC &&
518 bridge->device == PCI_DEVICE_ID_DEC_21150) { 516 bridge->device == PCI_DEVICE_ID_DEC_21150) {
519 struct pci_dev *dev2; 517 struct pci_dev *dev2;
@@ -524,33 +522,42 @@ static int __devinit pdc202new_init_one(struct pci_dev *dev, const struct pci_de
524 dev2 = pdc20270_get_dev2(dev); 522 dev2 = pdc20270_get_dev2(dev);
525 523
526 if (dev2) { 524 if (dev2) {
527 int ret = ide_setup_pci_devices(dev, dev2, d); 525 int ret = ide_pci_init_two(dev, dev2, d, NULL);
528 if (ret < 0) 526 if (ret < 0)
529 pci_dev_put(dev2); 527 pci_dev_put(dev2);
530 return ret; 528 return ret;
531 } 529 }
532 } 530 }
533 531
534 if (idx == 5 && bridge && 532 if (dev->device == PCI_DEVICE_ID_PROMISE_20276 && bridge &&
535 bridge->vendor == PCI_VENDOR_ID_INTEL && 533 bridge->vendor == PCI_VENDOR_ID_INTEL &&
536 (bridge->device == PCI_DEVICE_ID_INTEL_I960 || 534 (bridge->device == PCI_DEVICE_ID_INTEL_I960 ||
537 bridge->device == PCI_DEVICE_ID_INTEL_I960RM)) { 535 bridge->device == PCI_DEVICE_ID_INTEL_I960RM)) {
538 printk(KERN_INFO "PDC20276: attached to I2O RAID controller, " 536 printk(KERN_INFO DRV_NAME " %s: attached to I2O RAID controller,"
539 "skipping\n"); 537 " skipping\n", pci_name(dev));
540 return -ENODEV; 538 return -ENODEV;
541 } 539 }
542 540
543 return ide_setup_pci_device(dev, d); 541 return ide_pci_init_one(dev, d, NULL);
542}
543
544static void __devexit pdc202new_remove(struct pci_dev *dev)
545{
546 struct ide_host *host = pci_get_drvdata(dev);
547 struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
548
549 ide_pci_remove(dev);
550 pci_dev_put(dev2);
544} 551}
545 552
546static const struct pci_device_id pdc202new_pci_tbl[] = { 553static const struct pci_device_id pdc202new_pci_tbl[] = {
547 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20268), 0 }, 554 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20268), 0 },
548 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20269), 1 }, 555 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20269), 1 },
549 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20270), 2 }, 556 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20270), 0 },
550 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20271), 3 }, 557 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20271), 1 },
551 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20275), 4 }, 558 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20275), 1 },
552 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20276), 5 }, 559 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20276), 1 },
553 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20277), 6 }, 560 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20277), 1 },
554 { 0, }, 561 { 0, },
555}; 562};
556MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl); 563MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl);
@@ -559,6 +566,7 @@ static struct pci_driver driver = {
559 .name = "Promise_IDE", 566 .name = "Promise_IDE",
560 .id_table = pdc202new_pci_tbl, 567 .id_table = pdc202new_pci_tbl,
561 .probe = pdc202new_init_one, 568 .probe = pdc202new_init_one,
569 .remove = pdc202new_remove,
562}; 570};
563 571
564static int __init pdc202new_ide_init(void) 572static int __init pdc202new_ide_init(void)
@@ -566,7 +574,13 @@ static int __init pdc202new_ide_init(void)
566 return ide_pci_register_driver(&driver); 574 return ide_pci_register_driver(&driver);
567} 575}
568 576
577static void __exit pdc202new_ide_exit(void)
578{
579 pci_unregister_driver(&driver);
580}
581
569module_init(pdc202new_ide_init); 582module_init(pdc202new_ide_init);
583module_exit(pdc202new_ide_exit);
570 584
571MODULE_AUTHOR("Andre Hedrick, Frank Tiernan"); 585MODULE_AUTHOR("Andre Hedrick, Frank Tiernan");
572MODULE_DESCRIPTION("PCI driver module for Promise PDC20268 and higher"); 586MODULE_DESCRIPTION("PCI driver module for Promise PDC20268 and higher");
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index e54dc653b8c4..6ff2def58da0 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -20,6 +20,8 @@
20 20
21#include <asm/io.h> 21#include <asm/io.h>
22 22
23#define DRV_NAME "pdc202xx_old"
24
23#define PDC202XX_DEBUG_DRIVE_INFO 0 25#define PDC202XX_DEBUG_DRIVE_INFO 0
24 26
25static const char *pdc_quirk_drives[] = { 27static const char *pdc_quirk_drives[] = {
@@ -263,8 +265,7 @@ static void pdc202xx_dma_timeout(ide_drive_t *drive)
263 ide_dma_timeout(drive); 265 ide_dma_timeout(drive);
264} 266}
265 267
266static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev, 268static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev)
267 const char *name)
268{ 269{
269 unsigned long dmabase = pci_resource_start(dev, 4); 270 unsigned long dmabase = pci_resource_start(dev, 4);
270 u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0; 271 u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0;
@@ -304,8 +305,8 @@ static void __devinit pdc202ata4_fixup_irq(struct pci_dev *dev,
304 if (irq != irq2) { 305 if (irq != irq2) {
305 pci_write_config_byte(dev, 306 pci_write_config_byte(dev,
306 (PCI_INTERRUPT_LINE)|0x80, irq); /* 0xbc */ 307 (PCI_INTERRUPT_LINE)|0x80, irq); /* 0xbc */
307 printk(KERN_INFO "%s: PCI config space interrupt " 308 printk(KERN_INFO "%s %s: PCI config space interrupt "
308 "mirror fixed\n", name); 309 "mirror fixed\n", name, pci_name(dev));
309 } 310 }
310 } 311 }
311} 312}
@@ -350,9 +351,9 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
350 .dma_timeout = pdc202xx_dma_timeout, 351 .dma_timeout = pdc202xx_dma_timeout,
351}; 352};
352 353
353#define DECLARE_PDC2026X_DEV(name_str, udma, extra_flags) \ 354#define DECLARE_PDC2026X_DEV(udma, extra_flags) \
354 { \ 355 { \
355 .name = name_str, \ 356 .name = DRV_NAME, \
356 .init_chipset = init_chipset_pdc202xx, \ 357 .init_chipset = init_chipset_pdc202xx, \
357 .port_ops = &pdc2026x_port_ops, \ 358 .port_ops = &pdc2026x_port_ops, \
358 .dma_ops = &pdc2026x_dma_ops, \ 359 .dma_ops = &pdc2026x_dma_ops, \
@@ -363,8 +364,8 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
363 } 364 }
364 365
365static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = { 366static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
366 { /* 0 */ 367 { /* 0: PDC20246 */
367 .name = "PDC20246", 368 .name = DRV_NAME,
368 .init_chipset = init_chipset_pdc202xx, 369 .init_chipset = init_chipset_pdc202xx,
369 .port_ops = &pdc20246_port_ops, 370 .port_ops = &pdc20246_port_ops,
370 .dma_ops = &pdc20246_dma_ops, 371 .dma_ops = &pdc20246_dma_ops,
@@ -374,10 +375,10 @@ static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
374 .udma_mask = ATA_UDMA2, 375 .udma_mask = ATA_UDMA2,
375 }, 376 },
376 377
377 /* 1 */ DECLARE_PDC2026X_DEV("PDC20262", ATA_UDMA4, 0), 378 /* 1: PDC2026{2,3} */
378 /* 2 */ DECLARE_PDC2026X_DEV("PDC20263", ATA_UDMA4, 0), 379 DECLARE_PDC2026X_DEV(ATA_UDMA4, 0),
379 /* 3 */ DECLARE_PDC2026X_DEV("PDC20265", ATA_UDMA5, IDE_HFLAG_RQSIZE_256), 380 /* 2: PDC2026{5,7} */
380 /* 4 */ DECLARE_PDC2026X_DEV("PDC20267", ATA_UDMA5, IDE_HFLAG_RQSIZE_256), 381 DECLARE_PDC2026X_DEV(ATA_UDMA5, IDE_HFLAG_RQSIZE_256),
381}; 382};
382 383
383/** 384/**
@@ -396,31 +397,32 @@ static int __devinit pdc202xx_init_one(struct pci_dev *dev, const struct pci_dev
396 397
397 d = &pdc202xx_chipsets[idx]; 398 d = &pdc202xx_chipsets[idx];
398 399
399 if (idx < 3) 400 if (idx < 2)
400 pdc202ata4_fixup_irq(dev, d->name); 401 pdc202ata4_fixup_irq(dev, d->name);
401 402
402 if (idx == 3) { 403 if (dev->vendor == PCI_DEVICE_ID_PROMISE_20265) {
403 struct pci_dev *bridge = dev->bus->self; 404 struct pci_dev *bridge = dev->bus->self;
404 405
405 if (bridge && 406 if (bridge &&
406 bridge->vendor == PCI_VENDOR_ID_INTEL && 407 bridge->vendor == PCI_VENDOR_ID_INTEL &&
407 (bridge->device == PCI_DEVICE_ID_INTEL_I960 || 408 (bridge->device == PCI_DEVICE_ID_INTEL_I960 ||
408 bridge->device == PCI_DEVICE_ID_INTEL_I960RM)) { 409 bridge->device == PCI_DEVICE_ID_INTEL_I960RM)) {
409 printk(KERN_INFO "ide: Skipping Promise PDC20265 " 410 printk(KERN_INFO DRV_NAME " %s: skipping Promise "
410 "attached to I2O RAID controller\n"); 411 "PDC20265 attached to I2O RAID controller\n",
412 pci_name(dev));
411 return -ENODEV; 413 return -ENODEV;
412 } 414 }
413 } 415 }
414 416
415 return ide_setup_pci_device(dev, d); 417 return ide_pci_init_one(dev, d, NULL);
416} 418}
417 419
418static const struct pci_device_id pdc202xx_pci_tbl[] = { 420static const struct pci_device_id pdc202xx_pci_tbl[] = {
419 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20246), 0 }, 421 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20246), 0 },
420 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20262), 1 }, 422 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20262), 1 },
421 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20263), 2 }, 423 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20263), 1 },
422 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20265), 3 }, 424 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20265), 2 },
423 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20267), 4 }, 425 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20267), 2 },
424 { 0, }, 426 { 0, },
425}; 427};
426MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl); 428MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl);
@@ -429,6 +431,7 @@ static struct pci_driver driver = {
429 .name = "Promise_Old_IDE", 431 .name = "Promise_Old_IDE",
430 .id_table = pdc202xx_pci_tbl, 432 .id_table = pdc202xx_pci_tbl,
431 .probe = pdc202xx_init_one, 433 .probe = pdc202xx_init_one,
434 .remove = ide_pci_remove,
432}; 435};
433 436
434static int __init pdc202xx_ide_init(void) 437static int __init pdc202xx_ide_init(void)
@@ -436,7 +439,13 @@ static int __init pdc202xx_ide_init(void)
436 return ide_pci_register_driver(&driver); 439 return ide_pci_register_driver(&driver);
437} 440}
438 441
442static void __exit pdc202xx_ide_exit(void)
443{
444 pci_unregister_driver(&driver);
445}
446
439module_init(pdc202xx_ide_init); 447module_init(pdc202xx_ide_init);
448module_exit(pdc202xx_ide_exit);
440 449
441MODULE_AUTHOR("Andre Hedrick, Frank Tiernan"); 450MODULE_AUTHOR("Andre Hedrick, Frank Tiernan");
442MODULE_DESCRIPTION("PCI driver module for older Promise IDE"); 451MODULE_DESCRIPTION("PCI driver module for older Promise IDE");
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index 0ce41b4dddaf..7fc3022dcf68 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -54,6 +54,8 @@
54 54
55#include <asm/io.h> 55#include <asm/io.h>
56 56
57#define DRV_NAME "piix"
58
57static int no_piix_dma; 59static int no_piix_dma;
58 60
59/** 61/**
@@ -198,13 +200,12 @@ static void piix_set_dma_mode(ide_drive_t *drive, const u8 speed)
198/** 200/**
199 * init_chipset_ich - set up the ICH chipset 201 * init_chipset_ich - set up the ICH chipset
200 * @dev: PCI device to set up 202 * @dev: PCI device to set up
201 * @name: Name of the device
202 * 203 *
203 * Initialize the PCI device as required. For the ICH this turns 204 * Initialize the PCI device as required. For the ICH this turns
204 * out to be nice and simple. 205 * out to be nice and simple.
205 */ 206 */
206 207
207static unsigned int __devinit init_chipset_ich(struct pci_dev *dev, const char *name) 208static unsigned int __devinit init_chipset_ich(struct pci_dev *dev)
208{ 209{
209 u32 extra = 0; 210 u32 extra = 0;
210 211
@@ -314,9 +315,9 @@ static const struct ide_port_ops piix_port_ops = {
314 #define IDE_HFLAGS_PIIX 0 315 #define IDE_HFLAGS_PIIX 0
315#endif 316#endif
316 317
317#define DECLARE_PIIX_DEV(name_str, udma) \ 318#define DECLARE_PIIX_DEV(udma) \
318 { \ 319 { \
319 .name = name_str, \ 320 .name = DRV_NAME, \
320 .init_hwif = init_hwif_piix, \ 321 .init_hwif = init_hwif_piix, \
321 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ 322 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \
322 .port_ops = &piix_port_ops, \ 323 .port_ops = &piix_port_ops, \
@@ -327,9 +328,9 @@ static const struct ide_port_ops piix_port_ops = {
327 .udma_mask = udma, \ 328 .udma_mask = udma, \
328 } 329 }
329 330
330#define DECLARE_ICH_DEV(name_str, udma) \ 331#define DECLARE_ICH_DEV(udma) \
331 { \ 332 { \
332 .name = name_str, \ 333 .name = DRV_NAME, \
333 .init_chipset = init_chipset_ich, \ 334 .init_chipset = init_chipset_ich, \
334 .init_hwif = init_hwif_ich, \ 335 .init_hwif = init_hwif_ich, \
335 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ 336 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \
@@ -342,45 +343,31 @@ static const struct ide_port_ops piix_port_ops = {
342 } 343 }
343 344
344static const struct ide_port_info piix_pci_info[] __devinitdata = { 345static const struct ide_port_info piix_pci_info[] __devinitdata = {
345 /* 0 */ DECLARE_PIIX_DEV("PIIXa", 0x00), /* no udma */ 346 /* 0: MPIIX */
346 /* 1 */ DECLARE_PIIX_DEV("PIIXb", 0x00), /* no udma */
347
348 /* 2 */
349 { /* 347 { /*
350 * MPIIX actually has only a single IDE channel mapped to 348 * MPIIX actually has only a single IDE channel mapped to
351 * the primary or secondary ports depending on the value 349 * the primary or secondary ports depending on the value
352 * of the bit 14 of the IDETIM register at offset 0x6c 350 * of the bit 14 of the IDETIM register at offset 0x6c
353 */ 351 */
354 .name = "MPIIX", 352 .name = DRV_NAME,
355 .enablebits = {{0x6d,0xc0,0x80}, {0x6d,0xc0,0xc0}}, 353 .enablebits = {{0x6d,0xc0,0x80}, {0x6d,0xc0,0xc0}},
356 .host_flags = IDE_HFLAG_ISA_PORTS | IDE_HFLAG_NO_DMA | 354 .host_flags = IDE_HFLAG_ISA_PORTS | IDE_HFLAG_NO_DMA |
357 IDE_HFLAGS_PIIX, 355 IDE_HFLAGS_PIIX,
358 .pio_mask = ATA_PIO4, 356 .pio_mask = ATA_PIO4,
359 /* This is a painful system best to let it self tune for now */ 357 /* This is a painful system best to let it self tune for now */
360 }, 358 },
361 359 /* 1: PIIXa/PIIXb/PIIX3 */
362 /* 3 */ DECLARE_PIIX_DEV("PIIX3", 0x00), /* no udma */ 360 DECLARE_PIIX_DEV(0x00), /* no udma */
363 /* 4 */ DECLARE_PIIX_DEV("PIIX4", ATA_UDMA2), 361 /* 2: PIIX4 */
364 /* 5 */ DECLARE_ICH_DEV("ICH0", ATA_UDMA2), 362 DECLARE_PIIX_DEV(ATA_UDMA2),
365 /* 6 */ DECLARE_PIIX_DEV("PIIX4", ATA_UDMA2), 363 /* 3: ICH0 */
366 /* 7 */ DECLARE_ICH_DEV("ICH", ATA_UDMA4), 364 DECLARE_ICH_DEV(ATA_UDMA2),
367 /* 8 */ DECLARE_PIIX_DEV("PIIX4", ATA_UDMA4), 365 /* 4: ICH */
368 /* 9 */ DECLARE_PIIX_DEV("PIIX4", ATA_UDMA2), 366 DECLARE_ICH_DEV(ATA_UDMA4),
369 /* 10 */ DECLARE_ICH_DEV("ICH2", ATA_UDMA5), 367 /* 5: PIIX4 */
370 /* 11 */ DECLARE_ICH_DEV("ICH2M", ATA_UDMA5), 368 DECLARE_PIIX_DEV(ATA_UDMA4),
371 /* 12 */ DECLARE_ICH_DEV("ICH3M", ATA_UDMA5), 369 /* 6: ICH[2-7]/ICH[2-3]M/C-ICH/ICH5-SATA/ESB2/ICH8M */
372 /* 13 */ DECLARE_ICH_DEV("ICH3", ATA_UDMA5), 370 DECLARE_ICH_DEV(ATA_UDMA5),
373 /* 14 */ DECLARE_ICH_DEV("ICH4", ATA_UDMA5),
374 /* 15 */ DECLARE_ICH_DEV("ICH5", ATA_UDMA5),
375 /* 16 */ DECLARE_ICH_DEV("C-ICH", ATA_UDMA5),
376 /* 17 */ DECLARE_ICH_DEV("ICH4", ATA_UDMA5),
377 /* 18 */ DECLARE_ICH_DEV("ICH5-SATA", ATA_UDMA5),
378 /* 19 */ DECLARE_ICH_DEV("ICH5", ATA_UDMA5),
379 /* 20 */ DECLARE_ICH_DEV("ICH6", ATA_UDMA5),
380 /* 21 */ DECLARE_ICH_DEV("ICH7", ATA_UDMA5),
381 /* 22 */ DECLARE_ICH_DEV("ICH4", ATA_UDMA5),
382 /* 23 */ DECLARE_ICH_DEV("ESB2", ATA_UDMA5),
383 /* 24 */ DECLARE_ICH_DEV("ICH8M", ATA_UDMA5),
384}; 371};
385 372
386/** 373/**
@@ -394,7 +381,7 @@ static const struct ide_port_info piix_pci_info[] __devinitdata = {
394 381
395static int __devinit piix_init_one(struct pci_dev *dev, const struct pci_device_id *id) 382static int __devinit piix_init_one(struct pci_dev *dev, const struct pci_device_id *id)
396{ 383{
397 return ide_setup_pci_device(dev, &piix_pci_info[id->driver_data]); 384 return ide_pci_init_one(dev, &piix_pci_info[id->driver_data], NULL);
398} 385}
399 386
400/** 387/**
@@ -421,39 +408,39 @@ static void __devinit piix_check_450nx(void)
421 no_piix_dma = 2; 408 no_piix_dma = 2;
422 } 409 }
423 if(no_piix_dma) 410 if(no_piix_dma)
424 printk(KERN_WARNING "piix: 450NX errata present, disabling IDE DMA.\n"); 411 printk(KERN_WARNING DRV_NAME ": 450NX errata present, disabling IDE DMA.\n");
425 if(no_piix_dma == 2) 412 if(no_piix_dma == 2)
426 printk(KERN_WARNING "piix: A BIOS update may resolve this.\n"); 413 printk(KERN_WARNING DRV_NAME ": A BIOS update may resolve this.\n");
427} 414}
428 415
429static const struct pci_device_id piix_pci_tbl[] = { 416static const struct pci_device_id piix_pci_tbl[] = {
430 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371FB_0), 0 }, 417 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371FB_0), 1 },
431 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371FB_1), 1 }, 418 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371FB_1), 1 },
432 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371MX), 2 }, 419 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371MX), 0 },
433 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371SB_1), 3 }, 420 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371SB_1), 1 },
434 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371AB), 4 }, 421 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371AB), 2 },
435 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801AB_1), 5 }, 422 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801AB_1), 3 },
436 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82443MX_1), 6 }, 423 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82443MX_1), 2 },
437 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801AA_1), 7 }, 424 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801AA_1), 4 },
438 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82372FB_1), 8 }, 425 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82372FB_1), 5 },
439 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82451NX), 9 }, 426 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82451NX), 2 },
440 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801BA_9), 10 }, 427 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801BA_9), 6 },
441 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801BA_8), 11 }, 428 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801BA_8), 6 },
442 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801CA_10), 12 }, 429 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801CA_10), 6 },
443 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801CA_11), 13 }, 430 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801CA_11), 6 },
444 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801DB_11), 14 }, 431 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801DB_11), 6 },
445 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801EB_11), 15 }, 432 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801EB_11), 6 },
446 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801E_11), 16 }, 433 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801E_11), 6 },
447 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801DB_10), 17 }, 434 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801DB_10), 6 },
448#ifdef CONFIG_BLK_DEV_IDE_SATA 435#ifdef CONFIG_BLK_DEV_IDE_SATA
449 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801EB_1), 18 }, 436 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801EB_1), 6 },
450#endif 437#endif
451 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ESB_2), 19 }, 438 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ESB_2), 6 },
452 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH6_19), 20 }, 439 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH6_19), 6 },
453 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH7_21), 21 }, 440 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH7_21), 6 },
454 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801DB_1), 22 }, 441 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801DB_1), 6 },
455 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ESB2_18), 23 }, 442 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ESB2_18), 6 },
456 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH8_6), 24 }, 443 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH8_6), 6 },
457 { 0, }, 444 { 0, },
458}; 445};
459MODULE_DEVICE_TABLE(pci, piix_pci_tbl); 446MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
@@ -462,6 +449,7 @@ static struct pci_driver driver = {
462 .name = "PIIX_IDE", 449 .name = "PIIX_IDE",
463 .id_table = piix_pci_tbl, 450 .id_table = piix_pci_tbl,
464 .probe = piix_init_one, 451 .probe = piix_init_one,
452 .remove = ide_pci_remove,
465}; 453};
466 454
467static int __init piix_ide_init(void) 455static int __init piix_ide_init(void)
@@ -470,7 +458,13 @@ static int __init piix_ide_init(void)
470 return ide_pci_register_driver(&driver); 458 return ide_pci_register_driver(&driver);
471} 459}
472 460
461static void __exit piix_ide_exit(void)
462{
463 pci_unregister_driver(&driver);
464}
465
473module_init(piix_ide_init); 466module_init(piix_ide_init);
467module_exit(piix_ide_exit);
474 468
475MODULE_AUTHOR("Andre Hedrick, Andrzej Krzysztofowicz"); 469MODULE_AUTHOR("Andre Hedrick, Andrzej Krzysztofowicz");
476MODULE_DESCRIPTION("PCI driver module for Intel PIIX IDE"); 470MODULE_DESCRIPTION("PCI driver module for Intel PIIX IDE");
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c
index 532154adba29..8d11ee838a2a 100644
--- a/drivers/ide/pci/rz1000.c
+++ b/drivers/ide/pci/rz1000.c
@@ -21,6 +21,8 @@
21#include <linux/ide.h> 21#include <linux/ide.h>
22#include <linux/init.h> 22#include <linux/init.h>
23 23
24#define DRV_NAME "rz1000"
25
24static void __devinit init_hwif_rz1000 (ide_hwif_t *hwif) 26static void __devinit init_hwif_rz1000 (ide_hwif_t *hwif)
25{ 27{
26 struct pci_dev *dev = to_pci_dev(hwif->dev); 28 struct pci_dev *dev = to_pci_dev(hwif->dev);
@@ -40,7 +42,7 @@ static void __devinit init_hwif_rz1000 (ide_hwif_t *hwif)
40} 42}
41 43
42static const struct ide_port_info rz1000_chipset __devinitdata = { 44static const struct ide_port_info rz1000_chipset __devinitdata = {
43 .name = "RZ100x", 45 .name = DRV_NAME,
44 .init_hwif = init_hwif_rz1000, 46 .init_hwif = init_hwif_rz1000,
45 .chipset = ide_rz1000, 47 .chipset = ide_rz1000,
46 .host_flags = IDE_HFLAG_NO_DMA, 48 .host_flags = IDE_HFLAG_NO_DMA,
@@ -48,7 +50,7 @@ static const struct ide_port_info rz1000_chipset __devinitdata = {
48 50
49static int __devinit rz1000_init_one(struct pci_dev *dev, const struct pci_device_id *id) 51static int __devinit rz1000_init_one(struct pci_dev *dev, const struct pci_device_id *id)
50{ 52{
51 return ide_setup_pci_device(dev, &rz1000_chipset); 53 return ide_pci_init_one(dev, &rz1000_chipset, NULL);
52} 54}
53 55
54static const struct pci_device_id rz1000_pci_tbl[] = { 56static const struct pci_device_id rz1000_pci_tbl[] = {
@@ -62,6 +64,7 @@ static struct pci_driver driver = {
62 .name = "RZ1000_IDE", 64 .name = "RZ1000_IDE",
63 .id_table = rz1000_pci_tbl, 65 .id_table = rz1000_pci_tbl,
64 .probe = rz1000_init_one, 66 .probe = rz1000_init_one,
67 .remove = ide_pci_remove,
65}; 68};
66 69
67static int __init rz1000_ide_init(void) 70static int __init rz1000_ide_init(void)
@@ -69,7 +72,13 @@ static int __init rz1000_ide_init(void)
69 return ide_pci_register_driver(&driver); 72 return ide_pci_register_driver(&driver);
70} 73}
71 74
75static void __exit rz1000_ide_exit(void)
76{
77 pci_unregister_driver(&driver);
78}
79
72module_init(rz1000_ide_init); 80module_init(rz1000_ide_init);
81module_exit(rz1000_ide_exit);
73 82
74MODULE_AUTHOR("Andre Hedrick"); 83MODULE_AUTHOR("Andre Hedrick");
75MODULE_DESCRIPTION("PCI driver module for RZ1000 IDE"); 84MODULE_DESCRIPTION("PCI driver module for RZ1000 IDE");
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index 14c787b5d95f..8efaed16fea3 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -22,6 +22,8 @@
22 22
23#include <asm/io.h> 23#include <asm/io.h>
24 24
25#define DRV_NAME "sc1200"
26
25#define SC1200_REV_A 0x00 27#define SC1200_REV_A 0x00
26#define SC1200_REV_B1 0x01 28#define SC1200_REV_B1 0x01
27#define SC1200_REV_B3 0x02 29#define SC1200_REV_B3 0x02
@@ -234,21 +236,11 @@ static int sc1200_suspend (struct pci_dev *dev, pm_message_t state)
234 * we only save state when going from full power to less 236 * we only save state when going from full power to less
235 */ 237 */
236 if (state.event == PM_EVENT_ON) { 238 if (state.event == PM_EVENT_ON) {
237 struct sc1200_saved_state *ss; 239 struct ide_host *host = pci_get_drvdata(dev);
240 struct sc1200_saved_state *ss = host->host_priv;
238 unsigned int r; 241 unsigned int r;
239 242
240 /* 243 /*
241 * allocate a permanent save area, if not already allocated
242 */
243 ss = (struct sc1200_saved_state *)pci_get_drvdata(dev);
244 if (ss == NULL) {
245 ss = kmalloc(sizeof(*ss), GFP_KERNEL);
246 if (ss == NULL)
247 return -ENOMEM;
248 pci_set_drvdata(dev, ss);
249 }
250
251 /*
252 * save timing registers 244 * save timing registers
253 * (this may be unnecessary if BIOS also does it) 245 * (this may be unnecessary if BIOS also does it)
254 */ 246 */
@@ -263,7 +255,8 @@ static int sc1200_suspend (struct pci_dev *dev, pm_message_t state)
263 255
264static int sc1200_resume (struct pci_dev *dev) 256static int sc1200_resume (struct pci_dev *dev)
265{ 257{
266 struct sc1200_saved_state *ss; 258 struct ide_host *host = pci_get_drvdata(dev);
259 struct sc1200_saved_state *ss = host->host_priv;
267 unsigned int r; 260 unsigned int r;
268 int i; 261 int i;
269 262
@@ -271,16 +264,12 @@ static int sc1200_resume (struct pci_dev *dev)
271 if (i) 264 if (i)
272 return i; 265 return i;
273 266
274 ss = (struct sc1200_saved_state *)pci_get_drvdata(dev);
275
276 /* 267 /*
277 * restore timing registers 268 * restore timing registers
278 * (this may be unnecessary if BIOS also does it) 269 * (this may be unnecessary if BIOS also does it)
279 */ 270 */
280 if (ss) { 271 for (r = 0; r < 8; r++)
281 for (r = 0; r < 8; r++) 272 pci_write_config_dword(dev, 0x40 + r * 4, ss->regs[r]);
282 pci_write_config_dword(dev, 0x40 + r * 4, ss->regs[r]);
283 }
284 273
285 return 0; 274 return 0;
286} 275}
@@ -304,7 +293,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
304}; 293};
305 294
306static const struct ide_port_info sc1200_chipset __devinitdata = { 295static const struct ide_port_info sc1200_chipset __devinitdata = {
307 .name = "SC1200", 296 .name = DRV_NAME,
308 .port_ops = &sc1200_port_ops, 297 .port_ops = &sc1200_port_ops,
309 .dma_ops = &sc1200_dma_ops, 298 .dma_ops = &sc1200_dma_ops,
310 .host_flags = IDE_HFLAG_SERIALIZE | 299 .host_flags = IDE_HFLAG_SERIALIZE |
@@ -317,7 +306,19 @@ static const struct ide_port_info sc1200_chipset __devinitdata = {
317 306
318static int __devinit sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id) 307static int __devinit sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id)
319{ 308{
320 return ide_setup_pci_device(dev, &sc1200_chipset); 309 struct sc1200_saved_state *ss = NULL;
310 int rc;
311
312#ifdef CONFIG_PM
313 ss = kmalloc(sizeof(*ss), GFP_KERNEL);
314 if (ss == NULL)
315 return -ENOMEM;
316#endif
317 rc = ide_pci_init_one(dev, &sc1200_chipset, ss);
318 if (rc)
319 kfree(ss);
320
321 return rc;
321} 322}
322 323
323static const struct pci_device_id sc1200_pci_tbl[] = { 324static const struct pci_device_id sc1200_pci_tbl[] = {
@@ -330,6 +331,7 @@ static struct pci_driver driver = {
330 .name = "SC1200_IDE", 331 .name = "SC1200_IDE",
331 .id_table = sc1200_pci_tbl, 332 .id_table = sc1200_pci_tbl,
332 .probe = sc1200_init_one, 333 .probe = sc1200_init_one,
334 .remove = ide_pci_remove,
333#ifdef CONFIG_PM 335#ifdef CONFIG_PM
334 .suspend = sc1200_suspend, 336 .suspend = sc1200_suspend,
335 .resume = sc1200_resume, 337 .resume = sc1200_resume,
@@ -341,7 +343,13 @@ static int __init sc1200_ide_init(void)
341 return ide_pci_register_driver(&driver); 343 return ide_pci_register_driver(&driver);
342} 344}
343 345
346static void __exit sc1200_ide_exit(void)
347{
348 pci_unregister_driver(&driver);
349}
350
344module_init(sc1200_ide_init); 351module_init(sc1200_ide_init);
352module_exit(sc1200_ide_exit);
345 353
346MODULE_AUTHOR("Mark Lord"); 354MODULE_AUTHOR("Mark Lord");
347MODULE_DESCRIPTION("PCI driver module for NS SC1200 IDE"); 355MODULE_DESCRIPTION("PCI driver module for NS SC1200 IDE");
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index 127ccb45e261..d173f2937722 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -38,6 +38,8 @@
38 38
39#include <asm/io.h> 39#include <asm/io.h>
40 40
41#define DRV_NAME "serverworks"
42
41#define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */ 43#define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */
42#define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */ 44#define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */
43 45
@@ -172,7 +174,7 @@ static void svwks_set_dma_mode(ide_drive_t *drive, const u8 speed)
172 pci_write_config_byte(dev, 0x54, ultra_enable); 174 pci_write_config_byte(dev, 0x54, ultra_enable);
173} 175}
174 176
175static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name) 177static unsigned int __devinit init_chipset_svwks(struct pci_dev *dev)
176{ 178{
177 unsigned int reg; 179 unsigned int reg;
178 u8 btr; 180 u8 btr;
@@ -188,7 +190,8 @@ static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const cha
188 pci_read_config_dword(isa_dev, 0x64, &reg); 190 pci_read_config_dword(isa_dev, 0x64, &reg);
189 reg &= ~0x00002000; /* disable 600ns interrupt mask */ 191 reg &= ~0x00002000; /* disable 600ns interrupt mask */
190 if(!(reg & 0x00004000)) 192 if(!(reg & 0x00004000))
191 printk(KERN_DEBUG "%s: UDMA not BIOS enabled.\n", name); 193 printk(KERN_DEBUG DRV_NAME " %s: UDMA not BIOS "
194 "enabled.\n", pci_name(dev));
192 reg |= 0x00004000; /* enable UDMA/33 support */ 195 reg |= 0x00004000; /* enable UDMA/33 support */
193 pci_write_config_dword(isa_dev, 0x64, reg); 196 pci_write_config_dword(isa_dev, 0x64, reg);
194 } 197 }
@@ -352,40 +355,44 @@ static const struct ide_port_ops svwks_port_ops = {
352#define IDE_HFLAGS_SVWKS IDE_HFLAG_LEGACY_IRQS 355#define IDE_HFLAGS_SVWKS IDE_HFLAG_LEGACY_IRQS
353 356
354static const struct ide_port_info serverworks_chipsets[] __devinitdata = { 357static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
355 { /* 0 */ 358 { /* 0: OSB4 */
356 .name = "SvrWks OSB4", 359 .name = DRV_NAME,
357 .init_chipset = init_chipset_svwks, 360 .init_chipset = init_chipset_svwks,
358 .port_ops = &osb4_port_ops, 361 .port_ops = &osb4_port_ops,
359 .host_flags = IDE_HFLAGS_SVWKS, 362 .host_flags = IDE_HFLAGS_SVWKS,
360 .pio_mask = ATA_PIO4, 363 .pio_mask = ATA_PIO4,
361 .mwdma_mask = ATA_MWDMA2, 364 .mwdma_mask = ATA_MWDMA2,
362 .udma_mask = 0x00, /* UDMA is problematic on OSB4 */ 365 .udma_mask = 0x00, /* UDMA is problematic on OSB4 */
363 },{ /* 1 */ 366 },
364 .name = "SvrWks CSB5", 367 { /* 1: CSB5 */
368 .name = DRV_NAME,
365 .init_chipset = init_chipset_svwks, 369 .init_chipset = init_chipset_svwks,
366 .port_ops = &svwks_port_ops, 370 .port_ops = &svwks_port_ops,
367 .host_flags = IDE_HFLAGS_SVWKS, 371 .host_flags = IDE_HFLAGS_SVWKS,
368 .pio_mask = ATA_PIO4, 372 .pio_mask = ATA_PIO4,
369 .mwdma_mask = ATA_MWDMA2, 373 .mwdma_mask = ATA_MWDMA2,
370 .udma_mask = ATA_UDMA5, 374 .udma_mask = ATA_UDMA5,
371 },{ /* 2 */ 375 },
372 .name = "SvrWks CSB6", 376 { /* 2: CSB6 */
377 .name = DRV_NAME,
373 .init_chipset = init_chipset_svwks, 378 .init_chipset = init_chipset_svwks,
374 .port_ops = &svwks_port_ops, 379 .port_ops = &svwks_port_ops,
375 .host_flags = IDE_HFLAGS_SVWKS, 380 .host_flags = IDE_HFLAGS_SVWKS,
376 .pio_mask = ATA_PIO4, 381 .pio_mask = ATA_PIO4,
377 .mwdma_mask = ATA_MWDMA2, 382 .mwdma_mask = ATA_MWDMA2,
378 .udma_mask = ATA_UDMA5, 383 .udma_mask = ATA_UDMA5,
379 },{ /* 3 */ 384 },
380 .name = "SvrWks CSB6", 385 { /* 3: CSB6-2 */
386 .name = DRV_NAME,
381 .init_chipset = init_chipset_svwks, 387 .init_chipset = init_chipset_svwks,
382 .port_ops = &svwks_port_ops, 388 .port_ops = &svwks_port_ops,
383 .host_flags = IDE_HFLAGS_SVWKS | IDE_HFLAG_SINGLE, 389 .host_flags = IDE_HFLAGS_SVWKS | IDE_HFLAG_SINGLE,
384 .pio_mask = ATA_PIO4, 390 .pio_mask = ATA_PIO4,
385 .mwdma_mask = ATA_MWDMA2, 391 .mwdma_mask = ATA_MWDMA2,
386 .udma_mask = ATA_UDMA5, 392 .udma_mask = ATA_UDMA5,
387 },{ /* 4 */ 393 },
388 .name = "SvrWks HT1000", 394 { /* 4: HT1000 */
395 .name = DRV_NAME,
389 .init_chipset = init_chipset_svwks, 396 .init_chipset = init_chipset_svwks,
390 .port_ops = &svwks_port_ops, 397 .port_ops = &svwks_port_ops,
391 .host_flags = IDE_HFLAGS_SVWKS | IDE_HFLAG_SINGLE, 398 .host_flags = IDE_HFLAGS_SVWKS | IDE_HFLAG_SINGLE,
@@ -422,7 +429,7 @@ static int __devinit svwks_init_one(struct pci_dev *dev, const struct pci_device
422 d.host_flags &= ~IDE_HFLAG_SINGLE; 429 d.host_flags &= ~IDE_HFLAG_SINGLE;
423 } 430 }
424 431
425 return ide_setup_pci_device(dev, &d); 432 return ide_pci_init_one(dev, &d, NULL);
426} 433}
427 434
428static const struct pci_device_id svwks_pci_tbl[] = { 435static const struct pci_device_id svwks_pci_tbl[] = {
@@ -439,6 +446,7 @@ static struct pci_driver driver = {
439 .name = "Serverworks_IDE", 446 .name = "Serverworks_IDE",
440 .id_table = svwks_pci_tbl, 447 .id_table = svwks_pci_tbl,
441 .probe = svwks_init_one, 448 .probe = svwks_init_one,
449 .remove = ide_pci_remove,
442}; 450};
443 451
444static int __init svwks_ide_init(void) 452static int __init svwks_ide_init(void)
@@ -446,7 +454,13 @@ static int __init svwks_ide_init(void)
446 return ide_pci_register_driver(&driver); 454 return ide_pci_register_driver(&driver);
447} 455}
448 456
457static void __exit svwks_ide_exit(void)
458{
459 pci_unregister_driver(&driver);
460}
461
449module_init(svwks_ide_init); 462module_init(svwks_ide_init);
463module_exit(svwks_ide_exit);
450 464
451MODULE_AUTHOR("Michael Aubry. Andrzej Krzysztofowicz, Andre Hedrick"); 465MODULE_AUTHOR("Michael Aubry. Andrzej Krzysztofowicz, Andre Hedrick");
452MODULE_DESCRIPTION("PCI driver module for Serverworks OSB4/CSB5/CSB6 IDE"); 466MODULE_DESCRIPTION("PCI driver module for Serverworks OSB4/CSB5/CSB6 IDE");
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 5965a35d94ae..b8ad9ad6cf0d 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -44,6 +44,8 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/io.h> 45#include <linux/io.h>
46 46
47#define DRV_NAME "siimage"
48
47/** 49/**
48 * pdev_is_sata - check if device is SATA 50 * pdev_is_sata - check if device is SATA
49 * @pdev: PCI device to check 51 * @pdev: PCI device to check
@@ -127,9 +129,10 @@ static inline unsigned long siimage_seldev(ide_drive_t *drive, int r)
127 129
128static u8 sil_ioread8(struct pci_dev *dev, unsigned long addr) 130static u8 sil_ioread8(struct pci_dev *dev, unsigned long addr)
129{ 131{
132 struct ide_host *host = pci_get_drvdata(dev);
130 u8 tmp = 0; 133 u8 tmp = 0;
131 134
132 if (pci_get_drvdata(dev)) 135 if (host->host_priv)
133 tmp = readb((void __iomem *)addr); 136 tmp = readb((void __iomem *)addr);
134 else 137 else
135 pci_read_config_byte(dev, addr, &tmp); 138 pci_read_config_byte(dev, addr, &tmp);
@@ -139,9 +142,10 @@ static u8 sil_ioread8(struct pci_dev *dev, unsigned long addr)
139 142
140static u16 sil_ioread16(struct pci_dev *dev, unsigned long addr) 143static u16 sil_ioread16(struct pci_dev *dev, unsigned long addr)
141{ 144{
145 struct ide_host *host = pci_get_drvdata(dev);
142 u16 tmp = 0; 146 u16 tmp = 0;
143 147
144 if (pci_get_drvdata(dev)) 148 if (host->host_priv)
145 tmp = readw((void __iomem *)addr); 149 tmp = readw((void __iomem *)addr);
146 else 150 else
147 pci_read_config_word(dev, addr, &tmp); 151 pci_read_config_word(dev, addr, &tmp);
@@ -151,7 +155,9 @@ static u16 sil_ioread16(struct pci_dev *dev, unsigned long addr)
151 155
152static void sil_iowrite8(struct pci_dev *dev, u8 val, unsigned long addr) 156static void sil_iowrite8(struct pci_dev *dev, u8 val, unsigned long addr)
153{ 157{
154 if (pci_get_drvdata(dev)) 158 struct ide_host *host = pci_get_drvdata(dev);
159
160 if (host->host_priv)
155 writeb(val, (void __iomem *)addr); 161 writeb(val, (void __iomem *)addr);
156 else 162 else
157 pci_write_config_byte(dev, addr, val); 163 pci_write_config_byte(dev, addr, val);
@@ -159,7 +165,9 @@ static void sil_iowrite8(struct pci_dev *dev, u8 val, unsigned long addr)
159 165
160static void sil_iowrite16(struct pci_dev *dev, u16 val, unsigned long addr) 166static void sil_iowrite16(struct pci_dev *dev, u16 val, unsigned long addr)
161{ 167{
162 if (pci_get_drvdata(dev)) 168 struct ide_host *host = pci_get_drvdata(dev);
169
170 if (host->host_priv)
163 writew(val, (void __iomem *)addr); 171 writew(val, (void __iomem *)addr);
164 else 172 else
165 pci_write_config_word(dev, addr, val); 173 pci_write_config_word(dev, addr, val);
@@ -167,7 +175,9 @@ static void sil_iowrite16(struct pci_dev *dev, u16 val, unsigned long addr)
167 175
168static void sil_iowrite32(struct pci_dev *dev, u32 val, unsigned long addr) 176static void sil_iowrite32(struct pci_dev *dev, u32 val, unsigned long addr)
169{ 177{
170 if (pci_get_drvdata(dev)) 178 struct ide_host *host = pci_get_drvdata(dev);
179
180 if (host->host_priv)
171 writel(val, (void __iomem *)addr); 181 writel(val, (void __iomem *)addr);
172 else 182 else
173 pci_write_config_dword(dev, addr, val); 183 pci_write_config_dword(dev, addr, val);
@@ -445,66 +455,24 @@ static void sil_sata_pre_reset(ide_drive_t *drive)
445} 455}
446 456
447/** 457/**
448 * setup_mmio_siimage - switch controller into MMIO mode
449 * @dev: PCI device we are configuring
450 * @name: device name
451 *
452 * Attempt to put the device into MMIO mode. There are some slight
453 * complications here with certain systems where the MMIO BAR isn't
454 * mapped, so we have to be sure that we can fall back to I/O.
455 */
456
457static unsigned int setup_mmio_siimage(struct pci_dev *dev, const char *name)
458{
459 resource_size_t bar5 = pci_resource_start(dev, 5);
460 unsigned long barsize = pci_resource_len(dev, 5);
461 void __iomem *ioaddr;
462
463 /*
464 * Drop back to PIO if we can't map the MMIO. Some systems
465 * seem to get terminally confused in the PCI spaces.
466 */
467 if (!request_mem_region(bar5, barsize, name)) {
468 printk(KERN_WARNING "siimage: IDE controller MMIO ports not "
469 "available.\n");
470 return 0;
471 }
472
473 ioaddr = ioremap(bar5, barsize);
474 if (ioaddr == NULL) {
475 release_mem_region(bar5, barsize);
476 return 0;
477 }
478
479 pci_set_master(dev);
480 pci_set_drvdata(dev, (void *) ioaddr);
481
482 return 1;
483}
484
485/**
486 * init_chipset_siimage - set up an SI device 458 * init_chipset_siimage - set up an SI device
487 * @dev: PCI device 459 * @dev: PCI device
488 * @name: device name
489 * 460 *
490 * Perform the initial PCI set up for this device. Attempt to switch 461 * Perform the initial PCI set up for this device. Attempt to switch
491 * to 133 MHz clocking if the system isn't already set up to do it. 462 * to 133 MHz clocking if the system isn't already set up to do it.
492 */ 463 */
493 464
494static unsigned int __devinit init_chipset_siimage(struct pci_dev *dev, 465static unsigned int __devinit init_chipset_siimage(struct pci_dev *dev)
495 const char *name)
496{ 466{
467 struct ide_host *host = pci_get_drvdata(dev);
468 void __iomem *ioaddr = host->host_priv;
497 unsigned long base, scsc_addr; 469 unsigned long base, scsc_addr;
498 void __iomem *ioaddr = NULL; 470 u8 rev = dev->revision, tmp;
499 u8 rev = dev->revision, tmp, BA5_EN;
500 471
501 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, rev ? 1 : 255); 472 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, rev ? 1 : 255);
502 473
503 pci_read_config_byte(dev, 0x8A, &BA5_EN); 474 if (ioaddr)
504 475 pci_set_master(dev);
505 if ((BA5_EN & 0x01) || pci_resource_start(dev, 5))
506 if (setup_mmio_siimage(dev, name))
507 ioaddr = pci_get_drvdata(dev);
508 476
509 base = (unsigned long)ioaddr; 477 base = (unsigned long)ioaddr;
510 478
@@ -571,7 +539,8 @@ static unsigned int __devinit init_chipset_siimage(struct pci_dev *dev,
571 { "== 100", "== 133", "== 2X PCI", "DISABLED!" }; 539 { "== 100", "== 133", "== 2X PCI", "DISABLED!" };
572 540
573 tmp >>= 4; 541 tmp >>= 4;
574 printk(KERN_INFO "%s: BASE CLOCK %s\n", name, clk_str[tmp & 3]); 542 printk(KERN_INFO DRV_NAME " %s: BASE CLOCK %s\n",
543 pci_name(dev), clk_str[tmp & 3]);
575 } 544 }
576 545
577 return 0; 546 return 0;
@@ -592,7 +561,8 @@ static unsigned int __devinit init_chipset_siimage(struct pci_dev *dev,
592static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif) 561static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
593{ 562{
594 struct pci_dev *dev = to_pci_dev(hwif->dev); 563 struct pci_dev *dev = to_pci_dev(hwif->dev);
595 void *addr = pci_get_drvdata(dev); 564 struct ide_host *host = pci_get_drvdata(dev);
565 void *addr = host->host_priv;
596 u8 ch = hwif->channel; 566 u8 ch = hwif->channel;
597 struct ide_io_ports *io_ports = &hwif->io_ports; 567 struct ide_io_ports *io_ports = &hwif->io_ports;
598 unsigned long base; 568 unsigned long base;
@@ -691,16 +661,15 @@ static void __devinit sil_quirkproc(ide_drive_t *drive)
691static void __devinit init_iops_siimage(ide_hwif_t *hwif) 661static void __devinit init_iops_siimage(ide_hwif_t *hwif)
692{ 662{
693 struct pci_dev *dev = to_pci_dev(hwif->dev); 663 struct pci_dev *dev = to_pci_dev(hwif->dev);
664 struct ide_host *host = pci_get_drvdata(dev);
694 665
695 hwif->hwif_data = NULL; 666 hwif->hwif_data = NULL;
696 667
697 /* Pessimal until we finish probing */ 668 /* Pessimal until we finish probing */
698 hwif->rqsize = 15; 669 hwif->rqsize = 15;
699 670
700 if (pci_get_drvdata(dev) == NULL) 671 if (host->host_priv)
701 return; 672 init_mmio_iops_siimage(hwif);
702
703 init_mmio_iops_siimage(hwif);
704} 673}
705 674
706/** 675/**
@@ -748,9 +717,9 @@ static const struct ide_dma_ops sil_dma_ops = {
748 .dma_lost_irq = ide_dma_lost_irq, 717 .dma_lost_irq = ide_dma_lost_irq,
749}; 718};
750 719
751#define DECLARE_SII_DEV(name_str, p_ops) \ 720#define DECLARE_SII_DEV(p_ops) \
752 { \ 721 { \
753 .name = name_str, \ 722 .name = DRV_NAME, \
754 .init_chipset = init_chipset_siimage, \ 723 .init_chipset = init_chipset_siimage, \
755 .init_iops = init_iops_siimage, \ 724 .init_iops = init_iops_siimage, \
756 .port_ops = p_ops, \ 725 .port_ops = p_ops, \
@@ -761,9 +730,8 @@ static const struct ide_dma_ops sil_dma_ops = {
761 } 730 }
762 731
763static const struct ide_port_info siimage_chipsets[] __devinitdata = { 732static const struct ide_port_info siimage_chipsets[] __devinitdata = {
764 /* 0 */ DECLARE_SII_DEV("SiI680", &sil_pata_port_ops), 733 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
765 /* 1 */ DECLARE_SII_DEV("SiI3112 Serial ATA", &sil_sata_port_ops), 734 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
766 /* 2 */ DECLARE_SII_DEV("Adaptec AAR-1210SA", &sil_sata_port_ops)
767}; 735};
768 736
769/** 737/**
@@ -778,8 +746,13 @@ static const struct ide_port_info siimage_chipsets[] __devinitdata = {
778static int __devinit siimage_init_one(struct pci_dev *dev, 746static int __devinit siimage_init_one(struct pci_dev *dev,
779 const struct pci_device_id *id) 747 const struct pci_device_id *id)
780{ 748{
749 void __iomem *ioaddr = NULL;
750 resource_size_t bar5 = pci_resource_start(dev, 5);
751 unsigned long barsize = pci_resource_len(dev, 5);
752 int rc;
781 struct ide_port_info d; 753 struct ide_port_info d;
782 u8 idx = id->driver_data; 754 u8 idx = id->driver_data;
755 u8 BA5_EN;
783 756
784 d = siimage_chipsets[idx]; 757 d = siimage_chipsets[idx];
785 758
@@ -787,7 +760,7 @@ static int __devinit siimage_init_one(struct pci_dev *dev,
787 static int first = 1; 760 static int first = 1;
788 761
789 if (first) { 762 if (first) {
790 printk(KERN_INFO "siimage: For full SATA support you " 763 printk(KERN_INFO DRV_NAME ": For full SATA support you "
791 "should use the libata sata_sil module.\n"); 764 "should use the libata sata_sil module.\n");
792 first = 0; 765 first = 0;
793 } 766 }
@@ -795,14 +768,61 @@ static int __devinit siimage_init_one(struct pci_dev *dev,
795 d.host_flags |= IDE_HFLAG_NO_ATAPI_DMA; 768 d.host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
796 } 769 }
797 770
798 return ide_setup_pci_device(dev, &d); 771 rc = pci_enable_device(dev);
772 if (rc)
773 return rc;
774
775 pci_read_config_byte(dev, 0x8A, &BA5_EN);
776 if ((BA5_EN & 0x01) || bar5) {
777 /*
778 * Drop back to PIO if we can't map the MMIO. Some systems
779 * seem to get terminally confused in the PCI spaces.
780 */
781 if (!request_mem_region(bar5, barsize, d.name)) {
782 printk(KERN_WARNING DRV_NAME " %s: MMIO ports not "
783 "available\n", pci_name(dev));
784 } else {
785 ioaddr = ioremap(bar5, barsize);
786 if (ioaddr == NULL)
787 release_mem_region(bar5, barsize);
788 }
789 }
790
791 rc = ide_pci_init_one(dev, &d, ioaddr);
792 if (rc) {
793 if (ioaddr) {
794 iounmap(ioaddr);
795 release_mem_region(bar5, barsize);
796 }
797 pci_disable_device(dev);
798 }
799
800 return rc;
801}
802
803static void __devexit siimage_remove(struct pci_dev *dev)
804{
805 struct ide_host *host = pci_get_drvdata(dev);
806 void __iomem *ioaddr = host->host_priv;
807
808 ide_pci_remove(dev);
809
810 if (ioaddr) {
811 resource_size_t bar5 = pci_resource_start(dev, 5);
812 unsigned long barsize = pci_resource_len(dev, 5);
813
814 iounmap(ioaddr);
815 release_mem_region(bar5, barsize);
816 }
817
818 pci_disable_device(dev);
799} 819}
800 820
801static const struct pci_device_id siimage_pci_tbl[] = { 821static const struct pci_device_id siimage_pci_tbl[] = {
802 { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_680), 0 }, 822 { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_680), 0 },
803#ifdef CONFIG_BLK_DEV_IDE_SATA 823#ifdef CONFIG_BLK_DEV_IDE_SATA
804 { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_3112), 1 }, 824 { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_3112), 1 },
805 { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_1210SA), 2 }, 825 { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_1210SA), 1 },
806#endif 826#endif
807 { 0, }, 827 { 0, },
808}; 828};
@@ -812,6 +832,7 @@ static struct pci_driver driver = {
812 .name = "SiI_IDE", 832 .name = "SiI_IDE",
813 .id_table = siimage_pci_tbl, 833 .id_table = siimage_pci_tbl,
814 .probe = siimage_init_one, 834 .probe = siimage_init_one,
835 .remove = siimage_remove,
815}; 836};
816 837
817static int __init siimage_ide_init(void) 838static int __init siimage_ide_init(void)
@@ -819,7 +840,13 @@ static int __init siimage_ide_init(void)
819 return ide_pci_register_driver(&driver); 840 return ide_pci_register_driver(&driver);
820} 841}
821 842
843static void __exit siimage_ide_exit(void)
844{
845 pci_unregister_driver(&driver);
846}
847
822module_init(siimage_ide_init); 848module_init(siimage_ide_init);
849module_exit(siimage_ide_exit);
823 850
824MODULE_AUTHOR("Andre Hedrick, Alan Cox"); 851MODULE_AUTHOR("Andre Hedrick, Alan Cox");
825MODULE_DESCRIPTION("PCI driver module for SiI IDE"); 852MODULE_DESCRIPTION("PCI driver module for SiI IDE");
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 2389945ca95d..cc95f90b53b7 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -52,6 +52,8 @@
52#include <linux/init.h> 52#include <linux/init.h>
53#include <linux/ide.h> 53#include <linux/ide.h>
54 54
55#define DRV_NAME "sis5513"
56
55/* registers layout and init values are chipset family dependant */ 57/* registers layout and init values are chipset family dependant */
56 58
57#define ATA_16 0x01 59#define ATA_16 0x01
@@ -380,8 +382,9 @@ static int __devinit sis_find_family(struct pci_dev *dev)
380 } 382 }
381 pci_dev_put(host); 383 pci_dev_put(host);
382 384
383 printk(KERN_INFO "SIS5513: %s %s controller\n", 385 printk(KERN_INFO DRV_NAME " %s: %s %s controller\n",
384 SiSHostChipInfo[i].name, chipset_capability[chipset_family]); 386 pci_name(dev), SiSHostChipInfo[i].name,
387 chipset_capability[chipset_family]);
385 } 388 }
386 389
387 if (!chipset_family) { /* Belongs to pci-quirks */ 390 if (!chipset_family) { /* Belongs to pci-quirks */
@@ -396,7 +399,8 @@ static int __devinit sis_find_family(struct pci_dev *dev)
396 pci_write_config_dword(dev, 0x54, idemisc); 399 pci_write_config_dword(dev, 0x54, idemisc);
397 400
398 if (trueid == 0x5518) { 401 if (trueid == 0x5518) {
399 printk(KERN_INFO "SIS5513: SiS 962/963 MuTIOL IDE UDMA133 controller\n"); 402 printk(KERN_INFO DRV_NAME " %s: SiS 962/963 MuTIOL IDE UDMA133 controller\n",
403 pci_name(dev));
400 chipset_family = ATA_133; 404 chipset_family = ATA_133;
401 405
402 /* Check for 5513 compability mapping 406 /* Check for 5513 compability mapping
@@ -405,7 +409,8 @@ static int __devinit sis_find_family(struct pci_dev *dev)
405 */ 409 */
406 if ((idemisc & 0x40000000) == 0) { 410 if ((idemisc & 0x40000000) == 0) {
407 pci_write_config_dword(dev, 0x54, idemisc | 0x40000000); 411 pci_write_config_dword(dev, 0x54, idemisc | 0x40000000);
408 printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n"); 412 printk(KERN_INFO DRV_NAME " %s: Switching to 5513 register mapping\n",
413 pci_name(dev));
409 } 414 }
410 } 415 }
411 } 416 }
@@ -429,10 +434,12 @@ static int __devinit sis_find_family(struct pci_dev *dev)
429 pci_dev_put(lpc_bridge); 434 pci_dev_put(lpc_bridge);
430 435
431 if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) { 436 if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) {
432 printk(KERN_INFO "SIS5513: SiS 961B MuTIOL IDE UDMA133 controller\n"); 437 printk(KERN_INFO DRV_NAME " %s: SiS 961B MuTIOL IDE UDMA133 controller\n",
438 pci_name(dev));
433 chipset_family = ATA_133a; 439 chipset_family = ATA_133a;
434 } else { 440 } else {
435 printk(KERN_INFO "SIS5513: SiS 961 MuTIOL IDE UDMA100 controller\n"); 441 printk(KERN_INFO DRV_NAME " %s: SiS 961 MuTIOL IDE UDMA100 controller\n",
442 pci_name(dev));
436 chipset_family = ATA_100; 443 chipset_family = ATA_100;
437 } 444 }
438 } 445 }
@@ -441,8 +448,7 @@ static int __devinit sis_find_family(struct pci_dev *dev)
441 return chipset_family; 448 return chipset_family;
442} 449}
443 450
444static unsigned int __devinit init_chipset_sis5513(struct pci_dev *dev, 451static unsigned int __devinit init_chipset_sis5513(struct pci_dev *dev)
445 const char *name)
446{ 452{
447 /* Make general config ops here 453 /* Make general config ops here
448 1/ tell IDE channels to operate in Compatibility mode only 454 1/ tell IDE channels to operate in Compatibility mode only
@@ -555,7 +561,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
555}; 561};
556 562
557static const struct ide_port_info sis5513_chipset __devinitdata = { 563static const struct ide_port_info sis5513_chipset __devinitdata = {
558 .name = "SIS5513", 564 .name = DRV_NAME,
559 .init_chipset = init_chipset_sis5513, 565 .init_chipset = init_chipset_sis5513,
560 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} }, 566 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
561 .host_flags = IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_NO_AUTODMA, 567 .host_flags = IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_NO_AUTODMA,
@@ -583,7 +589,13 @@ static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_devi
583 589
584 d.udma_mask = udma_rates[chipset_family]; 590 d.udma_mask = udma_rates[chipset_family];
585 591
586 return ide_setup_pci_device(dev, &d); 592 return ide_pci_init_one(dev, &d, NULL);
593}
594
595static void __devexit sis5513_remove(struct pci_dev *dev)
596{
597 ide_pci_remove(dev);
598 pci_disable_device(dev);
587} 599}
588 600
589static const struct pci_device_id sis5513_pci_tbl[] = { 601static const struct pci_device_id sis5513_pci_tbl[] = {
@@ -598,6 +610,7 @@ static struct pci_driver driver = {
598 .name = "SIS_IDE", 610 .name = "SIS_IDE",
599 .id_table = sis5513_pci_tbl, 611 .id_table = sis5513_pci_tbl,
600 .probe = sis5513_init_one, 612 .probe = sis5513_init_one,
613 .remove = sis5513_remove,
601}; 614};
602 615
603static int __init sis5513_ide_init(void) 616static int __init sis5513_ide_init(void)
@@ -605,7 +618,13 @@ static int __init sis5513_ide_init(void)
605 return ide_pci_register_driver(&driver); 618 return ide_pci_register_driver(&driver);
606} 619}
607 620
621static void __exit sis5513_ide_exit(void)
622{
623 pci_unregister_driver(&driver);
624}
625
608module_init(sis5513_ide_init); 626module_init(sis5513_ide_init);
627module_exit(sis5513_ide_exit);
609 628
610MODULE_AUTHOR("Lionel Bouton, L C Chang, Andre Hedrick, Vojtech Pavlik"); 629MODULE_AUTHOR("Lionel Bouton, L C Chang, Andre Hedrick, Vojtech Pavlik");
611MODULE_DESCRIPTION("PCI driver module for SIS IDE"); 630MODULE_DESCRIPTION("PCI driver module for SIS IDE");
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index f82a6502c1b7..73905bcc08fb 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -23,6 +23,8 @@
23 23
24#include <asm/io.h> 24#include <asm/io.h>
25 25
26#define DRV_NAME "sl82c105"
27
26#undef DEBUG 28#undef DEBUG
27 29
28#ifdef DEBUG 30#ifdef DEBUG
@@ -270,7 +272,7 @@ static u8 sl82c105_bridge_revision(struct pci_dev *dev)
270 * channel 0 here at least, but channel 1 has to be enabled by 272 * channel 0 here at least, but channel 1 has to be enabled by
271 * firmware or arch code. We still set both to 16 bits mode. 273 * firmware or arch code. We still set both to 16 bits mode.
272 */ 274 */
273static unsigned int __devinit init_chipset_sl82c105(struct pci_dev *dev, const char *msg) 275static unsigned int __devinit init_chipset_sl82c105(struct pci_dev *dev)
274{ 276{
275 u32 val; 277 u32 val;
276 278
@@ -301,7 +303,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
301}; 303};
302 304
303static const struct ide_port_info sl82c105_chipset __devinitdata = { 305static const struct ide_port_info sl82c105_chipset __devinitdata = {
304 .name = "W82C105", 306 .name = DRV_NAME,
305 .init_chipset = init_chipset_sl82c105, 307 .init_chipset = init_chipset_sl82c105,
306 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}}, 308 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
307 .port_ops = &sl82c105_port_ops, 309 .port_ops = &sl82c105_port_ops,
@@ -328,14 +330,14 @@ static int __devinit sl82c105_init_one(struct pci_dev *dev, const struct pci_dev
328 * Never ever EVER under any circumstances enable 330 * Never ever EVER under any circumstances enable
329 * DMA when the bridge is this old. 331 * DMA when the bridge is this old.
330 */ 332 */
331 printk(KERN_INFO "W82C105_IDE: Winbond W83C553 bridge " 333 printk(KERN_INFO DRV_NAME ": Winbond W83C553 bridge "
332 "revision %d, BM-DMA disabled\n", rev); 334 "revision %d, BM-DMA disabled\n", rev);
333 d.dma_ops = NULL; 335 d.dma_ops = NULL;
334 d.mwdma_mask = 0; 336 d.mwdma_mask = 0;
335 d.host_flags &= ~IDE_HFLAG_SERIALIZE_DMA; 337 d.host_flags &= ~IDE_HFLAG_SERIALIZE_DMA;
336 } 338 }
337 339
338 return ide_setup_pci_device(dev, &d); 340 return ide_pci_init_one(dev, &d, NULL);
339} 341}
340 342
341static const struct pci_device_id sl82c105_pci_tbl[] = { 343static const struct pci_device_id sl82c105_pci_tbl[] = {
@@ -348,6 +350,7 @@ static struct pci_driver driver = {
348 .name = "W82C105_IDE", 350 .name = "W82C105_IDE",
349 .id_table = sl82c105_pci_tbl, 351 .id_table = sl82c105_pci_tbl,
350 .probe = sl82c105_init_one, 352 .probe = sl82c105_init_one,
353 .remove = ide_pci_remove,
351}; 354};
352 355
353static int __init sl82c105_ide_init(void) 356static int __init sl82c105_ide_init(void)
@@ -355,7 +358,13 @@ static int __init sl82c105_ide_init(void)
355 return ide_pci_register_driver(&driver); 358 return ide_pci_register_driver(&driver);
356} 359}
357 360
361static void __exit sl82c105_ide_exit(void)
362{
363 pci_unregister_driver(&driver);
364}
365
358module_init(sl82c105_ide_init); 366module_init(sl82c105_ide_init);
367module_exit(sl82c105_ide_exit);
359 368
360MODULE_DESCRIPTION("PCI driver module for W82C105 IDE"); 369MODULE_DESCRIPTION("PCI driver module for W82C105 IDE");
361MODULE_LICENSE("GPL"); 370MODULE_LICENSE("GPL");
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index dae6e2c94d86..13d1fa491f26 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -15,6 +15,8 @@
15#include <linux/ide.h> 15#include <linux/ide.h>
16#include <linux/init.h> 16#include <linux/init.h>
17 17
18#define DRV_NAME "slc90e66"
19
18static DEFINE_SPINLOCK(slc90e66_lock); 20static DEFINE_SPINLOCK(slc90e66_lock);
19 21
20static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio) 22static void slc90e66_set_pio_mode(ide_drive_t *drive, const u8 pio)
@@ -132,7 +134,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
132}; 134};
133 135
134static const struct ide_port_info slc90e66_chipset __devinitdata = { 136static const struct ide_port_info slc90e66_chipset __devinitdata = {
135 .name = "SLC90E66", 137 .name = DRV_NAME,
136 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} }, 138 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
137 .port_ops = &slc90e66_port_ops, 139 .port_ops = &slc90e66_port_ops,
138 .host_flags = IDE_HFLAG_LEGACY_IRQS, 140 .host_flags = IDE_HFLAG_LEGACY_IRQS,
@@ -144,7 +146,7 @@ static const struct ide_port_info slc90e66_chipset __devinitdata = {
144 146
145static int __devinit slc90e66_init_one(struct pci_dev *dev, const struct pci_device_id *id) 147static int __devinit slc90e66_init_one(struct pci_dev *dev, const struct pci_device_id *id)
146{ 148{
147 return ide_setup_pci_device(dev, &slc90e66_chipset); 149 return ide_pci_init_one(dev, &slc90e66_chipset, NULL);
148} 150}
149 151
150static const struct pci_device_id slc90e66_pci_tbl[] = { 152static const struct pci_device_id slc90e66_pci_tbl[] = {
@@ -157,6 +159,7 @@ static struct pci_driver driver = {
157 .name = "SLC90e66_IDE", 159 .name = "SLC90e66_IDE",
158 .id_table = slc90e66_pci_tbl, 160 .id_table = slc90e66_pci_tbl,
159 .probe = slc90e66_init_one, 161 .probe = slc90e66_init_one,
162 .remove = ide_pci_remove,
160}; 163};
161 164
162static int __init slc90e66_ide_init(void) 165static int __init slc90e66_ide_init(void)
@@ -164,7 +167,13 @@ static int __init slc90e66_ide_init(void)
164 return ide_pci_register_driver(&driver); 167 return ide_pci_register_driver(&driver);
165} 168}
166 169
170static void __exit slc90e66_ide_exit(void)
171{
172 pci_unregister_driver(&driver);
173}
174
167module_init(slc90e66_ide_init); 175module_init(slc90e66_ide_init);
176module_exit(slc90e66_ide_exit);
168 177
169MODULE_AUTHOR("Andre Hedrick"); 178MODULE_AUTHOR("Andre Hedrick");
170MODULE_DESCRIPTION("PCI driver module for SLC90E66 IDE"); 179MODULE_DESCRIPTION("PCI driver module for SLC90E66 IDE");
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index 477e19790102..b1cb8a9ce5a9 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -11,6 +11,8 @@
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/ide.h> 12#include <linux/ide.h>
13 13
14#define DRV_NAME "tc86c001"
15
14static void tc86c001_set_mode(ide_drive_t *drive, const u8 speed) 16static void tc86c001_set_mode(ide_drive_t *drive, const u8 speed)
15{ 17{
16 ide_hwif_t *hwif = HWIF(drive); 18 ide_hwif_t *hwif = HWIF(drive);
@@ -173,16 +175,6 @@ static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
173 hwif->rqsize = 0xffff; 175 hwif->rqsize = 0xffff;
174} 176}
175 177
176static unsigned int __devinit init_chipset_tc86c001(struct pci_dev *dev,
177 const char *name)
178{
179 int err = pci_request_region(dev, 5, name);
180
181 if (err)
182 printk(KERN_ERR "%s: system control regs already in use", name);
183 return err;
184}
185
186static const struct ide_port_ops tc86c001_port_ops = { 178static const struct ide_port_ops tc86c001_port_ops = {
187 .set_pio_mode = tc86c001_set_pio_mode, 179 .set_pio_mode = tc86c001_set_pio_mode,
188 .set_dma_mode = tc86c001_set_mode, 180 .set_dma_mode = tc86c001_set_mode,
@@ -201,8 +193,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
201}; 193};
202 194
203static const struct ide_port_info tc86c001_chipset __devinitdata = { 195static const struct ide_port_info tc86c001_chipset __devinitdata = {
204 .name = "TC86C001", 196 .name = DRV_NAME,
205 .init_chipset = init_chipset_tc86c001,
206 .init_hwif = init_hwif_tc86c001, 197 .init_hwif = init_hwif_tc86c001,
207 .port_ops = &tc86c001_port_ops, 198 .port_ops = &tc86c001_port_ops,
208 .dma_ops = &tc86c001_dma_ops, 199 .dma_ops = &tc86c001_dma_ops,
@@ -215,7 +206,37 @@ static const struct ide_port_info tc86c001_chipset __devinitdata = {
215static int __devinit tc86c001_init_one(struct pci_dev *dev, 206static int __devinit tc86c001_init_one(struct pci_dev *dev,
216 const struct pci_device_id *id) 207 const struct pci_device_id *id)
217{ 208{
218 return ide_setup_pci_device(dev, &tc86c001_chipset); 209 int rc;
210
211 rc = pci_enable_device(dev);
212 if (rc)
213 goto out;
214
215 rc = pci_request_region(dev, 5, DRV_NAME);
216 if (rc) {
217 printk(KERN_ERR DRV_NAME ": system control regs already in use");
218 goto out_disable;
219 }
220
221 rc = ide_pci_init_one(dev, &tc86c001_chipset, NULL);
222 if (rc)
223 goto out_release;
224
225 goto out;
226
227out_release:
228 pci_release_region(dev, 5);
229out_disable:
230 pci_disable_device(dev);
231out:
232 return rc;
233}
234
235static void __devexit tc86c001_remove(struct pci_dev *dev)
236{
237 ide_pci_remove(dev);
238 pci_release_region(dev, 5);
239 pci_disable_device(dev);
219} 240}
220 241
221static const struct pci_device_id tc86c001_pci_tbl[] = { 242static const struct pci_device_id tc86c001_pci_tbl[] = {
@@ -227,14 +248,22 @@ MODULE_DEVICE_TABLE(pci, tc86c001_pci_tbl);
227static struct pci_driver driver = { 248static struct pci_driver driver = {
228 .name = "TC86C001", 249 .name = "TC86C001",
229 .id_table = tc86c001_pci_tbl, 250 .id_table = tc86c001_pci_tbl,
230 .probe = tc86c001_init_one 251 .probe = tc86c001_init_one,
252 .remove = tc86c001_remove,
231}; 253};
232 254
233static int __init tc86c001_ide_init(void) 255static int __init tc86c001_ide_init(void)
234{ 256{
235 return ide_pci_register_driver(&driver); 257 return ide_pci_register_driver(&driver);
236} 258}
259
260static void __exit tc86c001_ide_exit(void)
261{
262 pci_unregister_driver(&driver);
263}
264
237module_init(tc86c001_ide_init); 265module_init(tc86c001_ide_init);
266module_exit(tc86c001_ide_exit);
238 267
239MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>"); 268MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>");
240MODULE_DESCRIPTION("PCI driver module for TC86C001 IDE"); 269MODULE_DESCRIPTION("PCI driver module for TC86C001 IDE");
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index db65a558d4ec..b77ec35151b3 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -33,6 +33,8 @@
33#include <linux/ide.h> 33#include <linux/ide.h>
34#include <linux/init.h> 34#include <linux/init.h>
35 35
36#define DRV_NAME "triflex"
37
36static void triflex_set_mode(ide_drive_t *drive, const u8 speed) 38static void triflex_set_mode(ide_drive_t *drive, const u8 speed)
37{ 39{
38 ide_hwif_t *hwif = HWIF(drive); 40 ide_hwif_t *hwif = HWIF(drive);
@@ -93,7 +95,7 @@ static const struct ide_port_ops triflex_port_ops = {
93}; 95};
94 96
95static const struct ide_port_info triflex_device __devinitdata = { 97static const struct ide_port_info triflex_device __devinitdata = {
96 .name = "TRIFLEX", 98 .name = DRV_NAME,
97 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}}, 99 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
98 .port_ops = &triflex_port_ops, 100 .port_ops = &triflex_port_ops,
99 .pio_mask = ATA_PIO4, 101 .pio_mask = ATA_PIO4,
@@ -104,7 +106,7 @@ static const struct ide_port_info triflex_device __devinitdata = {
104static int __devinit triflex_init_one(struct pci_dev *dev, 106static int __devinit triflex_init_one(struct pci_dev *dev,
105 const struct pci_device_id *id) 107 const struct pci_device_id *id)
106{ 108{
107 return ide_setup_pci_device(dev, &triflex_device); 109 return ide_pci_init_one(dev, &triflex_device, NULL);
108} 110}
109 111
110static const struct pci_device_id triflex_pci_tbl[] = { 112static const struct pci_device_id triflex_pci_tbl[] = {
@@ -117,6 +119,7 @@ static struct pci_driver driver = {
117 .name = "TRIFLEX_IDE", 119 .name = "TRIFLEX_IDE",
118 .id_table = triflex_pci_tbl, 120 .id_table = triflex_pci_tbl,
119 .probe = triflex_init_one, 121 .probe = triflex_init_one,
122 .remove = ide_pci_remove,
120}; 123};
121 124
122static int __init triflex_ide_init(void) 125static int __init triflex_ide_init(void)
@@ -124,7 +127,13 @@ static int __init triflex_ide_init(void)
124 return ide_pci_register_driver(&driver); 127 return ide_pci_register_driver(&driver);
125} 128}
126 129
130static void __exit triflex_ide_exit(void)
131{
132 pci_unregister_driver(&driver);
133}
134
127module_init(triflex_ide_init); 135module_init(triflex_ide_init);
136module_exit(triflex_ide_exit);
128 137
129MODULE_AUTHOR("Torben Mathiasen"); 138MODULE_AUTHOR("Torben Mathiasen");
130MODULE_DESCRIPTION("PCI driver module for Compaq Triflex IDE"); 139MODULE_DESCRIPTION("PCI driver module for Compaq Triflex IDE");
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index a8a3138682ef..fd28b49977fd 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -141,6 +141,8 @@
141 141
142#include <asm/io.h> 142#include <asm/io.h>
143 143
144#define DRV_NAME "trm290"
145
144static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma) 146static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
145{ 147{
146 ide_hwif_t *hwif = HWIF(drive); 148 ide_hwif_t *hwif = HWIF(drive);
@@ -245,10 +247,10 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
245 u8 reg = 0; 247 u8 reg = 0;
246 248
247 if ((dev->class & 5) && cfg_base) 249 if ((dev->class & 5) && cfg_base)
248 printk(KERN_INFO "TRM290: chip"); 250 printk(KERN_INFO DRV_NAME " %s: chip", pci_name(dev));
249 else { 251 else {
250 cfg_base = 0x3df0; 252 cfg_base = 0x3df0;
251 printk(KERN_INFO "TRM290: using default"); 253 printk(KERN_INFO DRV_NAME " %s: using default", pci_name(dev));
252 } 254 }
253 printk(KERN_CONT " config base at 0x%04x\n", cfg_base); 255 printk(KERN_CONT " config base at 0x%04x\n", cfg_base);
254 hwif->config_data = cfg_base; 256 hwif->config_data = cfg_base;
@@ -325,7 +327,7 @@ static struct ide_dma_ops trm290_dma_ops = {
325}; 327};
326 328
327static const struct ide_port_info trm290_chipset __devinitdata = { 329static const struct ide_port_info trm290_chipset __devinitdata = {
328 .name = "TRM290", 330 .name = DRV_NAME,
329 .init_hwif = init_hwif_trm290, 331 .init_hwif = init_hwif_trm290,
330 .chipset = ide_trm290, 332 .chipset = ide_trm290,
331 .port_ops = &trm290_port_ops, 333 .port_ops = &trm290_port_ops,
@@ -340,7 +342,7 @@ static const struct ide_port_info trm290_chipset __devinitdata = {
340 342
341static int __devinit trm290_init_one(struct pci_dev *dev, const struct pci_device_id *id) 343static int __devinit trm290_init_one(struct pci_dev *dev, const struct pci_device_id *id)
342{ 344{
343 return ide_setup_pci_device(dev, &trm290_chipset); 345 return ide_pci_init_one(dev, &trm290_chipset, NULL);
344} 346}
345 347
346static const struct pci_device_id trm290_pci_tbl[] = { 348static const struct pci_device_id trm290_pci_tbl[] = {
@@ -353,6 +355,7 @@ static struct pci_driver driver = {
353 .name = "TRM290_IDE", 355 .name = "TRM290_IDE",
354 .id_table = trm290_pci_tbl, 356 .id_table = trm290_pci_tbl,
355 .probe = trm290_init_one, 357 .probe = trm290_init_one,
358 .remove = ide_pci_remove,
356}; 359};
357 360
358static int __init trm290_ide_init(void) 361static int __init trm290_ide_init(void)
@@ -360,7 +363,13 @@ static int __init trm290_ide_init(void)
360 return ide_pci_register_driver(&driver); 363 return ide_pci_register_driver(&driver);
361} 364}
362 365
366static void __exit trm290_ide_exit(void)
367{
368 pci_unregister_driver(&driver);
369}
370
363module_init(trm290_ide_init); 371module_init(trm290_ide_init);
372module_exit(trm290_ide_exit);
364 373
365MODULE_AUTHOR("Mark Lord"); 374MODULE_AUTHOR("Mark Lord");
366MODULE_DESCRIPTION("PCI driver module for Tekram TRM290 IDE"); 375MODULE_DESCRIPTION("PCI driver module for Tekram TRM290 IDE");
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 09dc4803ef9d..454d2bf62dce 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -35,6 +35,8 @@
35#include <asm/processor.h> 35#include <asm/processor.h>
36#endif 36#endif
37 37
38#define DRV_NAME "via82cxxx"
39
38#define VIA_IDE_ENABLE 0x40 40#define VIA_IDE_ENABLE 0x40
39#define VIA_IDE_CONFIG 0x41 41#define VIA_IDE_CONFIG 0x41
40#define VIA_FIFO_CONFIG 0x43 42#define VIA_FIFO_CONFIG 0x43
@@ -113,7 +115,8 @@ struct via82cxxx_dev
113static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing) 115static void via_set_speed(ide_hwif_t *hwif, u8 dn, struct ide_timing *timing)
114{ 116{
115 struct pci_dev *dev = to_pci_dev(hwif->dev); 117 struct pci_dev *dev = to_pci_dev(hwif->dev);
116 struct via82cxxx_dev *vdev = pci_get_drvdata(dev); 118 struct ide_host *host = pci_get_drvdata(dev);
119 struct via82cxxx_dev *vdev = host->host_priv;
117 u8 t; 120 u8 t;
118 121
119 if (~vdev->via_config->flags & VIA_BAD_AST) { 122 if (~vdev->via_config->flags & VIA_BAD_AST) {
@@ -153,7 +156,8 @@ static void via_set_drive(ide_drive_t *drive, const u8 speed)
153 ide_hwif_t *hwif = drive->hwif; 156 ide_hwif_t *hwif = drive->hwif;
154 ide_drive_t *peer = hwif->drives + (~drive->dn & 1); 157 ide_drive_t *peer = hwif->drives + (~drive->dn & 1);
155 struct pci_dev *dev = to_pci_dev(hwif->dev); 158 struct pci_dev *dev = to_pci_dev(hwif->dev);
156 struct via82cxxx_dev *vdev = pci_get_drvdata(dev); 159 struct ide_host *host = pci_get_drvdata(dev);
160 struct via82cxxx_dev *vdev = host->host_priv;
157 struct ide_timing t, p; 161 struct ide_timing t, p;
158 unsigned int T, UT; 162 unsigned int T, UT;
159 163
@@ -258,37 +262,19 @@ static void __devinit via_cable_detect(struct via82cxxx_dev *vdev, u32 u)
258/** 262/**
259 * init_chipset_via82cxxx - initialization handler 263 * init_chipset_via82cxxx - initialization handler
260 * @dev: PCI device 264 * @dev: PCI device
261 * @name: Name of interface
262 * 265 *
263 * The initialization callback. Here we determine the IDE chip type 266 * The initialization callback. Here we determine the IDE chip type
264 * and initialize its drive independent registers. 267 * and initialize its drive independent registers.
265 */ 268 */
266 269
267static unsigned int __devinit init_chipset_via82cxxx(struct pci_dev *dev, const char *name) 270static unsigned int __devinit init_chipset_via82cxxx(struct pci_dev *dev)
268{ 271{
269 struct pci_dev *isa = NULL; 272 struct ide_host *host = pci_get_drvdata(dev);
270 struct via82cxxx_dev *vdev; 273 struct via82cxxx_dev *vdev = host->host_priv;
271 struct via_isa_bridge *via_config; 274 struct via_isa_bridge *via_config = vdev->via_config;
272 u8 t, v; 275 u8 t, v;
273 u32 u; 276 u32 u;
274 277
275 vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
276 if (!vdev) {
277 printk(KERN_ERR "VP_IDE: out of memory :(\n");
278 return -ENOMEM;
279 }
280 pci_set_drvdata(dev, vdev);
281
282 /*
283 * Find the ISA bridge to see how good the IDE is.
284 */
285 vdev->via_config = via_config = via_config_find(&isa);
286
287 /* We checked this earlier so if it fails here deeep badness
288 is involved */
289
290 BUG_ON(!via_config->id);
291
292 /* 278 /*
293 * Detect cable and configure Clk66 279 * Detect cable and configure Clk66
294 */ 280 */
@@ -334,39 +320,6 @@ static unsigned int __devinit init_chipset_via82cxxx(struct pci_dev *dev, const
334 320
335 pci_write_config_byte(dev, VIA_FIFO_CONFIG, t); 321 pci_write_config_byte(dev, VIA_FIFO_CONFIG, t);
336 322
337 /*
338 * Determine system bus clock.
339 */
340
341 via_clock = (ide_pci_clk ? ide_pci_clk : 33) * 1000;
342
343 switch (via_clock) {
344 case 33000: via_clock = 33333; break;
345 case 37000: via_clock = 37500; break;
346 case 41000: via_clock = 41666; break;
347 }
348
349 if (via_clock < 20000 || via_clock > 50000) {
350 printk(KERN_WARNING "VP_IDE: User given PCI clock speed "
351 "impossible (%d), using 33 MHz instead.\n", via_clock);
352 printk(KERN_WARNING "VP_IDE: Use ide0=ata66 if you want "
353 "to assume 80-wire cable.\n");
354 via_clock = 33333;
355 }
356
357 /*
358 * Print the boot message.
359 */
360
361 printk(KERN_INFO "VP_IDE: VIA %s (rev %02x) IDE %sDMA%s "
362 "controller on pci%s\n",
363 via_config->name, isa->revision,
364 via_config->udma_mask ? "U" : "MW",
365 via_dma[via_config->udma_mask ?
366 (fls(via_config->udma_mask) - 1) : 0],
367 pci_name(dev));
368
369 pci_dev_put(isa);
370 return 0; 323 return 0;
371} 324}
372 325
@@ -402,7 +355,8 @@ static int via_cable_override(struct pci_dev *pdev)
402static u8 __devinit via82cxxx_cable_detect(ide_hwif_t *hwif) 355static u8 __devinit via82cxxx_cable_detect(ide_hwif_t *hwif)
403{ 356{
404 struct pci_dev *pdev = to_pci_dev(hwif->dev); 357 struct pci_dev *pdev = to_pci_dev(hwif->dev);
405 struct via82cxxx_dev *vdev = pci_get_drvdata(pdev); 358 struct ide_host *host = pci_get_drvdata(pdev);
359 struct via82cxxx_dev *vdev = host->host_priv;
406 360
407 if (via_cable_override(pdev)) 361 if (via_cable_override(pdev))
408 return ATA_CBL_PATA40_SHORT; 362 return ATA_CBL_PATA40_SHORT;
@@ -420,7 +374,7 @@ static const struct ide_port_ops via_port_ops = {
420}; 374};
421 375
422static const struct ide_port_info via82cxxx_chipset __devinitdata = { 376static const struct ide_port_info via82cxxx_chipset __devinitdata = {
423 .name = "VP_IDE", 377 .name = DRV_NAME,
424 .init_chipset = init_chipset_via82cxxx, 378 .init_chipset = init_chipset_via82cxxx,
425 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } }, 379 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
426 .port_ops = &via_port_ops, 380 .port_ops = &via_port_ops,
@@ -436,6 +390,8 @@ static int __devinit via_init_one(struct pci_dev *dev, const struct pci_device_i
436{ 390{
437 struct pci_dev *isa = NULL; 391 struct pci_dev *isa = NULL;
438 struct via_isa_bridge *via_config; 392 struct via_isa_bridge *via_config;
393 struct via82cxxx_dev *vdev;
394 int rc;
439 u8 idx = id->driver_data; 395 u8 idx = id->driver_data;
440 struct ide_port_info d; 396 struct ide_port_info d;
441 397
@@ -445,12 +401,42 @@ static int __devinit via_init_one(struct pci_dev *dev, const struct pci_device_i
445 * Find the ISA bridge and check we know what it is. 401 * Find the ISA bridge and check we know what it is.
446 */ 402 */
447 via_config = via_config_find(&isa); 403 via_config = via_config_find(&isa);
448 pci_dev_put(isa);
449 if (!via_config->id) { 404 if (!via_config->id) {
450 printk(KERN_WARNING "VP_IDE: Unknown VIA SouthBridge, disabling DMA.\n"); 405 printk(KERN_WARNING DRV_NAME " %s: unknown chipset, skipping\n",
406 pci_name(dev));
451 return -ENODEV; 407 return -ENODEV;
452 } 408 }
453 409
410 /*
411 * Print the boot message.
412 */
413 printk(KERN_INFO DRV_NAME " %s: VIA %s (rev %02x) IDE %sDMA%s\n",
414 pci_name(dev), via_config->name, isa->revision,
415 via_config->udma_mask ? "U" : "MW",
416 via_dma[via_config->udma_mask ?
417 (fls(via_config->udma_mask) - 1) : 0]);
418
419 pci_dev_put(isa);
420
421 /*
422 * Determine system bus clock.
423 */
424 via_clock = (ide_pci_clk ? ide_pci_clk : 33) * 1000;
425
426 switch (via_clock) {
427 case 33000: via_clock = 33333; break;
428 case 37000: via_clock = 37500; break;
429 case 41000: via_clock = 41666; break;
430 }
431
432 if (via_clock < 20000 || via_clock > 50000) {
433 printk(KERN_WARNING DRV_NAME ": User given PCI clock speed "
434 "impossible (%d), using 33 MHz instead.\n", via_clock);
435 printk(KERN_WARNING DRV_NAME ": Use ide0=ata66 if you want "
436 "to assume 80-wire cable.\n");
437 via_clock = 33333;
438 }
439
454 if (idx == 0) 440 if (idx == 0)
455 d.host_flags |= IDE_HFLAG_NO_AUTODMA; 441 d.host_flags |= IDE_HFLAG_NO_AUTODMA;
456 else 442 else
@@ -466,7 +452,29 @@ static int __devinit via_init_one(struct pci_dev *dev, const struct pci_device_i
466 452
467 d.udma_mask = via_config->udma_mask; 453 d.udma_mask = via_config->udma_mask;
468 454
469 return ide_setup_pci_device(dev, &d); 455 vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
456 if (!vdev) {
457 printk(KERN_ERR DRV_NAME " %s: out of memory :(\n",
458 pci_name(dev));
459 return -ENOMEM;
460 }
461
462 vdev->via_config = via_config;
463
464 rc = ide_pci_init_one(dev, &d, vdev);
465 if (rc)
466 kfree(vdev);
467
468 return rc;
469}
470
471static void __devexit via_remove(struct pci_dev *dev)
472{
473 struct ide_host *host = pci_get_drvdata(dev);
474 struct via82cxxx_dev *vdev = host->host_priv;
475
476 ide_pci_remove(dev);
477 kfree(vdev);
470} 478}
471 479
472static const struct pci_device_id via_pci_tbl[] = { 480static const struct pci_device_id via_pci_tbl[] = {
@@ -483,6 +491,7 @@ static struct pci_driver driver = {
483 .name = "VIA_IDE", 491 .name = "VIA_IDE",
484 .id_table = via_pci_tbl, 492 .id_table = via_pci_tbl,
485 .probe = via_init_one, 493 .probe = via_init_one,
494 .remove = via_remove,
486}; 495};
487 496
488static int __init via_ide_init(void) 497static int __init via_ide_init(void)
@@ -490,7 +499,13 @@ static int __init via_ide_init(void)
490 return ide_pci_register_driver(&driver); 499 return ide_pci_register_driver(&driver);
491} 500}
492 501
502static void __exit via_ide_exit(void)
503{
504 pci_unregister_driver(&driver);
505}
506
493module_init(via_ide_init); 507module_init(via_ide_init);
508module_exit(via_ide_exit);
494 509
495MODULE_AUTHOR("Vojtech Pavlik, Michel Aubry, Jeff Garzik, Andre Hedrick"); 510MODULE_AUTHOR("Vojtech Pavlik, Michel Aubry, Jeff Garzik, Andre Hedrick");
496MODULE_DESCRIPTION("PCI driver module for VIA IDE"); 511MODULE_DESCRIPTION("PCI driver module for VIA IDE");
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index b15cad58dc81..a8e9e8a69a52 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -39,17 +39,18 @@ static int ide_setup_pci_baseregs(struct pci_dev *dev, const char *name)
39 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) || 39 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
40 (progif & 5) != 5) { 40 (progif & 5) != 5) {
41 if ((progif & 0xa) != 0xa) { 41 if ((progif & 0xa) != 0xa) {
42 printk(KERN_INFO "%s: device not capable of full " 42 printk(KERN_INFO "%s %s: device not capable of full "
43 "native PCI mode\n", name); 43 "native PCI mode\n", name, pci_name(dev));
44 return -EOPNOTSUPP; 44 return -EOPNOTSUPP;
45 } 45 }
46 printk("%s: placing both ports into native PCI mode\n", name); 46 printk(KERN_INFO "%s %s: placing both ports into native PCI "
47 "mode\n", name, pci_name(dev));
47 (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5); 48 (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
48 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) || 49 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
49 (progif & 5) != 5) { 50 (progif & 5) != 5) {
50 printk(KERN_ERR "%s: rewrite of PROGIF failed, wanted " 51 printk(KERN_ERR "%s %s: rewrite of PROGIF failed, "
51 "0x%04x, got 0x%04x\n", 52 "wanted 0x%04x, got 0x%04x\n",
52 name, progif|5, progif); 53 name, pci_name(dev), progif | 5, progif);
53 return -EOPNOTSUPP; 54 return -EOPNOTSUPP;
54 } 55 }
55 } 56 }
@@ -57,14 +58,14 @@ static int ide_setup_pci_baseregs(struct pci_dev *dev, const char *name)
57} 58}
58 59
59#ifdef CONFIG_BLK_DEV_IDEDMA_PCI 60#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
60static void ide_pci_clear_simplex(unsigned long dma_base, const char *name) 61static int ide_pci_clear_simplex(unsigned long dma_base, const char *name)
61{ 62{
62 u8 dma_stat = inb(dma_base + 2); 63 u8 dma_stat = inb(dma_base + 2);
63 64
64 outb(dma_stat & 0x60, dma_base + 2); 65 outb(dma_stat & 0x60, dma_base + 2);
65 dma_stat = inb(dma_base + 2); 66 dma_stat = inb(dma_base + 2);
66 if (dma_stat & 0x80) 67
67 printk(KERN_INFO "%s: simplex device: DMA forced\n", name); 68 return (dma_stat & 0x80) ? 1 : 0;
68} 69}
69 70
70/** 71/**
@@ -91,7 +92,8 @@ unsigned long ide_pci_dma_base(ide_hwif_t *hwif, const struct ide_port_info *d)
91 dma_base = pci_resource_start(dev, baridx); 92 dma_base = pci_resource_start(dev, baridx);
92 93
93 if (dma_base == 0) { 94 if (dma_base == 0) {
94 printk(KERN_ERR "%s: DMA base is invalid\n", d->name); 95 printk(KERN_ERR "%s %s: DMA base is invalid\n",
96 d->name, pci_name(dev));
95 return 0; 97 return 0;
96 } 98 }
97 } 99 }
@@ -105,13 +107,16 @@ EXPORT_SYMBOL_GPL(ide_pci_dma_base);
105 107
106int ide_pci_check_simplex(ide_hwif_t *hwif, const struct ide_port_info *d) 108int ide_pci_check_simplex(ide_hwif_t *hwif, const struct ide_port_info *d)
107{ 109{
110 struct pci_dev *dev = to_pci_dev(hwif->dev);
108 u8 dma_stat; 111 u8 dma_stat;
109 112
110 if (d->host_flags & (IDE_HFLAG_MMIO | IDE_HFLAG_CS5520)) 113 if (d->host_flags & (IDE_HFLAG_MMIO | IDE_HFLAG_CS5520))
111 goto out; 114 goto out;
112 115
113 if (d->host_flags & IDE_HFLAG_CLEAR_SIMPLEX) { 116 if (d->host_flags & IDE_HFLAG_CLEAR_SIMPLEX) {
114 ide_pci_clear_simplex(hwif->dma_base, d->name); 117 if (ide_pci_clear_simplex(hwif->dma_base, d->name))
118 printk(KERN_INFO "%s %s: simplex device: DMA forced\n",
119 d->name, pci_name(dev));
115 goto out; 120 goto out;
116 } 121 }
117 122
@@ -127,7 +132,8 @@ int ide_pci_check_simplex(ide_hwif_t *hwif, const struct ide_port_info *d)
127 */ 132 */
128 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); 133 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
129 if ((dma_stat & 0x80) && hwif->mate && hwif->mate->dma_base) { 134 if ((dma_stat & 0x80) && hwif->mate && hwif->mate->dma_base) {
130 printk(KERN_INFO "%s: simplex device: DMA disabled\n", d->name); 135 printk(KERN_INFO "%s %s: simplex device: DMA disabled\n",
136 d->name, pci_name(dev));
131 return -1; 137 return -1;
132 } 138 }
133out: 139out:
@@ -149,8 +155,8 @@ int ide_pci_set_master(struct pci_dev *dev, const char *name)
149 155
150 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || 156 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) ||
151 (pcicmd & PCI_COMMAND_MASTER) == 0) { 157 (pcicmd & PCI_COMMAND_MASTER) == 0) {
152 printk(KERN_ERR "%s: error updating PCICMD on %s\n", 158 printk(KERN_ERR "%s %s: error updating PCICMD\n",
153 name, pci_name(dev)); 159 name, pci_name(dev));
154 return -EIO; 160 return -EIO;
155 } 161 }
156 } 162 }
@@ -162,9 +168,9 @@ EXPORT_SYMBOL_GPL(ide_pci_set_master);
162 168
163void ide_setup_pci_noise(struct pci_dev *dev, const struct ide_port_info *d) 169void ide_setup_pci_noise(struct pci_dev *dev, const struct ide_port_info *d)
164{ 170{
165 printk(KERN_INFO "%s: IDE controller (0x%04x:0x%04x rev 0x%02x) at " 171 printk(KERN_INFO "%s %s: IDE controller (0x%04x:0x%04x rev 0x%02x)\n",
166 " PCI slot %s\n", d->name, dev->vendor, dev->device, 172 d->name, pci_name(dev),
167 dev->revision, pci_name(dev)); 173 dev->vendor, dev->device, dev->revision);
168} 174}
169EXPORT_SYMBOL_GPL(ide_setup_pci_noise); 175EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
170 176
@@ -189,11 +195,12 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
189 if (pci_enable_device(dev)) { 195 if (pci_enable_device(dev)) {
190 ret = pci_enable_device_io(dev); 196 ret = pci_enable_device_io(dev);
191 if (ret < 0) { 197 if (ret < 0) {
192 printk(KERN_WARNING "%s: (ide_setup_pci_device:) " 198 printk(KERN_WARNING "%s %s: couldn't enable device\n",
193 "Could not enable device.\n", d->name); 199 d->name, pci_name(dev));
194 goto out; 200 goto out;
195 } 201 }
196 printk(KERN_WARNING "%s: BIOS configuration fixed.\n", d->name); 202 printk(KERN_WARNING "%s %s: BIOS configuration fixed\n",
203 d->name, pci_name(dev));
197 } 204 }
198 205
199 /* 206 /*
@@ -203,7 +210,8 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
203 */ 210 */
204 ret = pci_set_dma_mask(dev, DMA_32BIT_MASK); 211 ret = pci_set_dma_mask(dev, DMA_32BIT_MASK);
205 if (ret < 0) { 212 if (ret < 0) {
206 printk(KERN_ERR "%s: can't set dma mask\n", d->name); 213 printk(KERN_ERR "%s %s: can't set DMA mask\n",
214 d->name, pci_name(dev));
207 goto out; 215 goto out;
208 } 216 }
209 217
@@ -221,7 +229,8 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
221 229
222 ret = pci_request_selected_regions(dev, bars, d->name); 230 ret = pci_request_selected_regions(dev, bars, d->name);
223 if (ret < 0) 231 if (ret < 0)
224 printk(KERN_ERR "%s: can't reserve resources\n", d->name); 232 printk(KERN_ERR "%s %s: can't reserve resources\n",
233 d->name, pci_name(dev));
225out: 234out:
226 return ret; 235 return ret;
227} 236}
@@ -247,15 +256,18 @@ static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d)
247 */ 256 */
248 if (ide_setup_pci_baseregs(dev, d->name) || 257 if (ide_setup_pci_baseregs(dev, d->name) ||
249 pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_IO)) { 258 pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_IO)) {
250 printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name); 259 printk(KERN_INFO "%s %s: device disabled (BIOS)\n",
260 d->name, pci_name(dev));
251 return -ENODEV; 261 return -ENODEV;
252 } 262 }
253 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) { 263 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) {
254 printk(KERN_ERR "%s: error accessing PCI regs\n", d->name); 264 printk(KERN_ERR "%s %s: error accessing PCI regs\n",
265 d->name, pci_name(dev));
255 return -EIO; 266 return -EIO;
256 } 267 }
257 if (!(pcicmd & PCI_COMMAND_IO)) { 268 if (!(pcicmd & PCI_COMMAND_IO)) {
258 printk(KERN_ERR "%s: unable to enable IDE controller\n", d->name); 269 printk(KERN_ERR "%s %s: unable to enable IDE controller\n",
270 d->name, pci_name(dev));
259 return -ENXIO; 271 return -ENXIO;
260 } 272 }
261 return 0; 273 return 0;
@@ -311,8 +323,9 @@ static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d,
311 if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) { 323 if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) {
312 if (ide_pci_check_iomem(dev, d, 2 * port) || 324 if (ide_pci_check_iomem(dev, d, 2 * port) ||
313 ide_pci_check_iomem(dev, d, 2 * port + 1)) { 325 ide_pci_check_iomem(dev, d, 2 * port + 1)) {
314 printk(KERN_ERR "%s: I/O baseregs (BIOS) are reported " 326 printk(KERN_ERR "%s %s: I/O baseregs (BIOS) are "
315 "as MEM for port %d!\n", d->name, port); 327 "reported as MEM for port %d!\n",
328 d->name, pci_name(dev), port);
316 return -EINVAL; 329 return -EINVAL;
317 } 330 }
318 331
@@ -325,8 +338,8 @@ static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d,
325 } 338 }
326 339
327 if (!base || !ctl) { 340 if (!base || !ctl) {
328 printk(KERN_ERR "%s: bad PCI BARs for port %d, skipping\n", 341 printk(KERN_ERR "%s %s: bad PCI BARs for port %d, skipping\n",
329 d->name, port); 342 d->name, pci_name(dev), port);
330 return -EINVAL; 343 return -EINVAL;
331 } 344 }
332 345
@@ -393,14 +406,14 @@ int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
393 * @dev: PCI device 406 * @dev: PCI device
394 * @d: IDE port info 407 * @d: IDE port info
395 * @noisy: verbose flag 408 * @noisy: verbose flag
396 * @config: returned as 1 if we configured the hardware
397 * 409 *
398 * Set up the PCI and controller side of the IDE interface. This brings 410 * Set up the PCI and controller side of the IDE interface. This brings
399 * up the PCI side of the device, checks that the device is enabled 411 * up the PCI side of the device, checks that the device is enabled
400 * and enables it if need be 412 * and enables it if need be
401 */ 413 */
402 414
403static int ide_setup_pci_controller(struct pci_dev *dev, const struct ide_port_info *d, int noisy, int *config) 415static int ide_setup_pci_controller(struct pci_dev *dev,
416 const struct ide_port_info *d, int noisy)
404{ 417{
405 int ret; 418 int ret;
406 u16 pcicmd; 419 u16 pcicmd;
@@ -414,15 +427,16 @@ static int ide_setup_pci_controller(struct pci_dev *dev, const struct ide_port_i
414 427
415 ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd); 428 ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
416 if (ret < 0) { 429 if (ret < 0) {
417 printk(KERN_ERR "%s: error accessing PCI regs\n", d->name); 430 printk(KERN_ERR "%s %s: error accessing PCI regs\n",
431 d->name, pci_name(dev));
418 goto out; 432 goto out;
419 } 433 }
420 if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */ 434 if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */
421 ret = ide_pci_configure(dev, d); 435 ret = ide_pci_configure(dev, d);
422 if (ret < 0) 436 if (ret < 0)
423 goto out; 437 goto out;
424 *config = 1; 438 printk(KERN_INFO "%s %s: device enabled (Linux)\n",
425 printk(KERN_INFO "%s: device enabled (Linux)\n", d->name); 439 d->name, pci_name(dev));
426 } 440 }
427 441
428out: 442out:
@@ -461,7 +475,8 @@ void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d,
461 475
462 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || 476 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
463 (tmp & e->mask) != e->val)) { 477 (tmp & e->mask) != e->val)) {
464 printk(KERN_INFO "%s: IDE port disabled\n", d->name); 478 printk(KERN_INFO "%s %s: IDE port disabled\n",
479 d->name, pci_name(dev));
465 continue; /* port not enabled */ 480 continue; /* port not enabled */
466 } 481 }
467 482
@@ -487,51 +502,35 @@ static int do_ide_setup_pci_device(struct pci_dev *dev,
487 const struct ide_port_info *d, 502 const struct ide_port_info *d,
488 u8 noisy) 503 u8 noisy)
489{ 504{
490 int tried_config = 0;
491 int pciirq, ret; 505 int pciirq, ret;
492 506
493 ret = ide_setup_pci_controller(dev, d, noisy, &tried_config);
494 if (ret < 0)
495 goto out;
496
497 /* 507 /*
498 * Can we trust the reported IRQ? 508 * Can we trust the reported IRQ?
499 */ 509 */
500 pciirq = dev->irq; 510 pciirq = dev->irq;
501 511
512 /*
513 * This allows offboard ide-pci cards the enable a BIOS,
514 * verify interrupt settings of split-mirror pci-config
515 * space, place chipset into init-mode, and/or preserve
516 * an interrupt if the card is not native ide support.
517 */
518 ret = d->init_chipset ? d->init_chipset(dev) : 0;
519 if (ret < 0)
520 goto out;
521
502 /* Is it an "IDE storage" device in non-PCI mode? */ 522 /* Is it an "IDE storage" device in non-PCI mode? */
503 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) { 523 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) {
504 if (noisy) 524 if (noisy)
505 printk(KERN_INFO "%s: not 100%% native mode: " 525 printk(KERN_INFO "%s %s: not 100%% native mode: will "
506 "will probe irqs later\n", d->name); 526 "probe irqs later\n", d->name, pci_name(dev));
507 /*
508 * This allows offboard ide-pci cards the enable a BIOS,
509 * verify interrupt settings of split-mirror pci-config
510 * space, place chipset into init-mode, and/or preserve
511 * an interrupt if the card is not native ide support.
512 */
513 ret = d->init_chipset ? d->init_chipset(dev, d->name) : 0;
514 if (ret < 0)
515 goto out;
516 pciirq = ret; 527 pciirq = ret;
517 } else if (tried_config) { 528 } else if (!pciirq && noisy) {
518 if (noisy) 529 printk(KERN_WARNING "%s %s: bad irq (%d): will probe later\n",
519 printk(KERN_INFO "%s: will probe irqs later\n", d->name); 530 d->name, pci_name(dev), pciirq);
520 pciirq = 0; 531 } else if (noisy) {
521 } else if (!pciirq) { 532 printk(KERN_INFO "%s %s: 100%% native mode on irq %d\n",
522 if (noisy) 533 d->name, pci_name(dev), pciirq);
523 printk(KERN_WARNING "%s: bad irq (%d): will probe later\n",
524 d->name, pciirq);
525 pciirq = 0;
526 } else {
527 if (d->init_chipset) {
528 ret = d->init_chipset(dev, d->name);
529 if (ret < 0)
530 goto out;
531 }
532 if (noisy)
533 printk(KERN_INFO "%s: 100%% native mode on irq %d\n",
534 d->name, pciirq);
535 } 534 }
536 535
537 ret = pciirq; 536 ret = pciirq;
@@ -539,32 +538,77 @@ out:
539 return ret; 538 return ret;
540} 539}
541 540
542int ide_setup_pci_device(struct pci_dev *dev, const struct ide_port_info *d) 541int ide_pci_init_one(struct pci_dev *dev, const struct ide_port_info *d,
542 void *priv)
543{ 543{
544 struct ide_host *host;
544 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL }; 545 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
545 int ret; 546 int ret;
546 547
547 ret = do_ide_setup_pci_device(dev, d, 1); 548 ret = ide_setup_pci_controller(dev, d, 1);
549 if (ret < 0)
550 goto out;
548 551
549 if (ret >= 0) { 552 ide_pci_setup_ports(dev, d, 0, &hw[0], &hws[0]);
550 /* FIXME: silent failure can happen */
551 ide_pci_setup_ports(dev, d, ret, &hw[0], &hws[0]);
552 553
553 ret = ide_host_add(d, hws, NULL); 554 host = ide_host_alloc(d, hws);
555 if (host == NULL) {
556 ret = -ENOMEM;
557 goto out;
554 } 558 }
555 559
560 host->dev[0] = &dev->dev;
561
562 host->host_priv = priv;
563
564 pci_set_drvdata(dev, host);
565
566 ret = do_ide_setup_pci_device(dev, d, 1);
567 if (ret < 0)
568 goto out;
569
570 /* fixup IRQ */
571 hw[1].irq = hw[0].irq = ret;
572
573 ret = ide_host_register(host, d, hws);
574 if (ret)
575 ide_host_free(host);
576out:
556 return ret; 577 return ret;
557} 578}
558EXPORT_SYMBOL_GPL(ide_setup_pci_device); 579EXPORT_SYMBOL_GPL(ide_pci_init_one);
559 580
560int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2, 581int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
561 const struct ide_port_info *d) 582 const struct ide_port_info *d, void *priv)
562{ 583{
563 struct pci_dev *pdev[] = { dev1, dev2 }; 584 struct pci_dev *pdev[] = { dev1, dev2 };
585 struct ide_host *host;
564 int ret, i; 586 int ret, i;
565 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL }; 587 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
566 588
567 for (i = 0; i < 2; i++) { 589 for (i = 0; i < 2; i++) {
590 ret = ide_setup_pci_controller(pdev[i], d, !i);
591 if (ret < 0)
592 goto out;
593
594 ide_pci_setup_ports(pdev[i], d, 0, &hw[i*2], &hws[i*2]);
595 }
596
597 host = ide_host_alloc(d, hws);
598 if (host == NULL) {
599 ret = -ENOMEM;
600 goto out;
601 }
602
603 host->dev[0] = &dev1->dev;
604 host->dev[1] = &dev2->dev;
605
606 host->host_priv = priv;
607
608 pci_set_drvdata(pdev[0], host);
609 pci_set_drvdata(pdev[1], host);
610
611 for (i = 0; i < 2; i++) {
568 ret = do_ide_setup_pci_device(pdev[i], d, !i); 612 ret = do_ide_setup_pci_device(pdev[i], d, !i);
569 613
570 /* 614 /*
@@ -574,12 +618,44 @@ int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
574 if (ret < 0) 618 if (ret < 0)
575 goto out; 619 goto out;
576 620
577 /* FIXME: silent failure can happen */ 621 /* fixup IRQ */
578 ide_pci_setup_ports(pdev[i], d, ret, &hw[i*2], &hws[i*2]); 622 hw[i*2 + 1].irq = hw[i*2].irq = ret;
579 } 623 }
580 624
581 ret = ide_host_add(d, hws, NULL); 625 ret = ide_host_register(host, d, hws);
626 if (ret)
627 ide_host_free(host);
582out: 628out:
583 return ret; 629 return ret;
584} 630}
585EXPORT_SYMBOL_GPL(ide_setup_pci_devices); 631EXPORT_SYMBOL_GPL(ide_pci_init_two);
632
633void ide_pci_remove(struct pci_dev *dev)
634{
635 struct ide_host *host = pci_get_drvdata(dev);
636 struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
637 int bars;
638
639 if (host->host_flags & IDE_HFLAG_SINGLE)
640 bars = (1 << 2) - 1;
641 else
642 bars = (1 << 4) - 1;
643
644 if ((host->host_flags & IDE_HFLAG_NO_DMA) == 0) {
645 if (host->host_flags & IDE_HFLAG_CS5520)
646 bars |= (1 << 2);
647 else
648 bars |= (1 << 4);
649 }
650
651 ide_host_remove(host);
652
653 if (dev2)
654 pci_release_selected_regions(dev2, bars);
655 pci_release_selected_regions(dev, bars);
656
657 if (dev2)
658 pci_disable_device(dev2);
659 pci_disable_device(dev);
660}
661EXPORT_SYMBOL_GPL(ide_pci_remove);
diff --git a/drivers/ieee1394/iso.c b/drivers/ieee1394/iso.c
index 07ca35c98f96..1cf6487b65ba 100644
--- a/drivers/ieee1394/iso.c
+++ b/drivers/ieee1394/iso.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/pci.h> 12#include <linux/pci.h>
13#include <linux/sched.h> 13#include <linux/sched.h>
14#include <linux/mm.h>
14#include <linux/slab.h> 15#include <linux/slab.h>
15 16
16#include "hosts.h" 17#include "hosts.h"
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index ae11d5cc74d0..e980ff3335db 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -168,6 +168,12 @@ struct cma_work {
168 struct rdma_cm_event event; 168 struct rdma_cm_event event;
169}; 169};
170 170
171struct cma_ndev_work {
172 struct work_struct work;
173 struct rdma_id_private *id;
174 struct rdma_cm_event event;
175};
176
171union cma_ip_addr { 177union cma_ip_addr {
172 struct in6_addr ip6; 178 struct in6_addr ip6;
173 struct { 179 struct {
@@ -914,7 +920,10 @@ static int cma_ib_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
914 struct rdma_cm_event event; 920 struct rdma_cm_event event;
915 int ret = 0; 921 int ret = 0;
916 922
917 if (cma_disable_callback(id_priv, CMA_CONNECT)) 923 if ((ib_event->event != IB_CM_TIMEWAIT_EXIT &&
924 cma_disable_callback(id_priv, CMA_CONNECT)) ||
925 (ib_event->event == IB_CM_TIMEWAIT_EXIT &&
926 cma_disable_callback(id_priv, CMA_DISCONNECT)))
918 return 0; 927 return 0;
919 928
920 memset(&event, 0, sizeof event); 929 memset(&event, 0, sizeof event);
@@ -950,6 +959,8 @@ static int cma_ib_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
950 event.event = RDMA_CM_EVENT_DISCONNECTED; 959 event.event = RDMA_CM_EVENT_DISCONNECTED;
951 break; 960 break;
952 case IB_CM_TIMEWAIT_EXIT: 961 case IB_CM_TIMEWAIT_EXIT:
962 event.event = RDMA_CM_EVENT_TIMEWAIT_EXIT;
963 break;
953 case IB_CM_MRA_RECEIVED: 964 case IB_CM_MRA_RECEIVED:
954 /* ignore event */ 965 /* ignore event */
955 goto out; 966 goto out;
@@ -1598,6 +1609,30 @@ out:
1598 kfree(work); 1609 kfree(work);
1599} 1610}
1600 1611
1612static void cma_ndev_work_handler(struct work_struct *_work)
1613{
1614 struct cma_ndev_work *work = container_of(_work, struct cma_ndev_work, work);
1615 struct rdma_id_private *id_priv = work->id;
1616 int destroy = 0;
1617
1618 mutex_lock(&id_priv->handler_mutex);
1619 if (id_priv->state == CMA_DESTROYING ||
1620 id_priv->state == CMA_DEVICE_REMOVAL)
1621 goto out;
1622
1623 if (id_priv->id.event_handler(&id_priv->id, &work->event)) {
1624 cma_exch(id_priv, CMA_DESTROYING);
1625 destroy = 1;
1626 }
1627
1628out:
1629 mutex_unlock(&id_priv->handler_mutex);
1630 cma_deref_id(id_priv);
1631 if (destroy)
1632 rdma_destroy_id(&id_priv->id);
1633 kfree(work);
1634}
1635
1601static int cma_resolve_ib_route(struct rdma_id_private *id_priv, int timeout_ms) 1636static int cma_resolve_ib_route(struct rdma_id_private *id_priv, int timeout_ms)
1602{ 1637{
1603 struct rdma_route *route = &id_priv->id.route; 1638 struct rdma_route *route = &id_priv->id.route;
@@ -2723,6 +2758,65 @@ void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr)
2723} 2758}
2724EXPORT_SYMBOL(rdma_leave_multicast); 2759EXPORT_SYMBOL(rdma_leave_multicast);
2725 2760
2761static int cma_netdev_change(struct net_device *ndev, struct rdma_id_private *id_priv)
2762{
2763 struct rdma_dev_addr *dev_addr;
2764 struct cma_ndev_work *work;
2765
2766 dev_addr = &id_priv->id.route.addr.dev_addr;
2767
2768 if ((dev_addr->src_dev == ndev) &&
2769 memcmp(dev_addr->src_dev_addr, ndev->dev_addr, ndev->addr_len)) {
2770 printk(KERN_INFO "RDMA CM addr change for ndev %s used by id %p\n",
2771 ndev->name, &id_priv->id);
2772 work = kzalloc(sizeof *work, GFP_KERNEL);
2773 if (!work)
2774 return -ENOMEM;
2775
2776 INIT_WORK(&work->work, cma_ndev_work_handler);
2777 work->id = id_priv;
2778 work->event.event = RDMA_CM_EVENT_ADDR_CHANGE;
2779 atomic_inc(&id_priv->refcount);
2780 queue_work(cma_wq, &work->work);
2781 }
2782
2783 return 0;
2784}
2785
2786static int cma_netdev_callback(struct notifier_block *self, unsigned long event,
2787 void *ctx)
2788{
2789 struct net_device *ndev = (struct net_device *)ctx;
2790 struct cma_device *cma_dev;
2791 struct rdma_id_private *id_priv;
2792 int ret = NOTIFY_DONE;
2793
2794 if (dev_net(ndev) != &init_net)
2795 return NOTIFY_DONE;
2796
2797 if (event != NETDEV_BONDING_FAILOVER)
2798 return NOTIFY_DONE;
2799
2800 if (!(ndev->flags & IFF_MASTER) || !(ndev->priv_flags & IFF_BONDING))
2801 return NOTIFY_DONE;
2802
2803 mutex_lock(&lock);
2804 list_for_each_entry(cma_dev, &dev_list, list)
2805 list_for_each_entry(id_priv, &cma_dev->id_list, list) {
2806 ret = cma_netdev_change(ndev, id_priv);
2807 if (ret)
2808 goto out;
2809 }
2810
2811out:
2812 mutex_unlock(&lock);
2813 return ret;
2814}
2815
2816static struct notifier_block cma_nb = {
2817 .notifier_call = cma_netdev_callback
2818};
2819
2726static void cma_add_one(struct ib_device *device) 2820static void cma_add_one(struct ib_device *device)
2727{ 2821{
2728 struct cma_device *cma_dev; 2822 struct cma_device *cma_dev;
@@ -2831,6 +2925,7 @@ static int cma_init(void)
2831 2925
2832 ib_sa_register_client(&sa_client); 2926 ib_sa_register_client(&sa_client);
2833 rdma_addr_register_client(&addr_client); 2927 rdma_addr_register_client(&addr_client);
2928 register_netdevice_notifier(&cma_nb);
2834 2929
2835 ret = ib_register_client(&cma_client); 2930 ret = ib_register_client(&cma_client);
2836 if (ret) 2931 if (ret)
@@ -2838,6 +2933,7 @@ static int cma_init(void)
2838 return 0; 2933 return 0;
2839 2934
2840err: 2935err:
2936 unregister_netdevice_notifier(&cma_nb);
2841 rdma_addr_unregister_client(&addr_client); 2937 rdma_addr_unregister_client(&addr_client);
2842 ib_sa_unregister_client(&sa_client); 2938 ib_sa_unregister_client(&sa_client);
2843 destroy_workqueue(cma_wq); 2939 destroy_workqueue(cma_wq);
@@ -2847,6 +2943,7 @@ err:
2847static void cma_cleanup(void) 2943static void cma_cleanup(void)
2848{ 2944{
2849 ib_unregister_client(&cma_client); 2945 ib_unregister_client(&cma_client);
2946 unregister_netdevice_notifier(&cma_nb);
2850 rdma_addr_unregister_client(&addr_client); 2947 rdma_addr_unregister_client(&addr_client);
2851 ib_sa_unregister_client(&sa_client); 2948 ib_sa_unregister_client(&sa_client);
2852 destroy_workqueue(cma_wq); 2949 destroy_workqueue(cma_wq);
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index 81c9195b512a..8f9509e1ebf7 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -942,8 +942,7 @@ static int iwcm_init_qp_init_attr(struct iwcm_id_private *cm_id_priv,
942 case IW_CM_STATE_CONN_RECV: 942 case IW_CM_STATE_CONN_RECV:
943 case IW_CM_STATE_ESTABLISHED: 943 case IW_CM_STATE_ESTABLISHED:
944 *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS; 944 *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS;
945 qp_attr->qp_access_flags = IB_ACCESS_LOCAL_WRITE | 945 qp_attr->qp_access_flags = IB_ACCESS_REMOTE_WRITE|
946 IB_ACCESS_REMOTE_WRITE|
947 IB_ACCESS_REMOTE_READ; 946 IB_ACCESS_REMOTE_READ;
948 ret = 0; 947 ret = 0;
949 break; 948 break;
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index 1341de793e51..7863a50d56f2 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -1064,7 +1064,8 @@ static void ib_sa_remove_one(struct ib_device *device)
1064 1064
1065 for (i = 0; i <= sa_dev->end_port - sa_dev->start_port; ++i) { 1065 for (i = 0; i <= sa_dev->end_port - sa_dev->start_port; ++i) {
1066 ib_unregister_mad_agent(sa_dev->port[i].agent); 1066 ib_unregister_mad_agent(sa_dev->port[i].agent);
1067 kref_put(&sa_dev->port[i].sm_ah->ref, free_sm_ah); 1067 if (sa_dev->port[i].sm_ah)
1068 kref_put(&sa_dev->port[i].sm_ah->ref, free_sm_ah);
1068 } 1069 }
1069 1070
1070 kfree(sa_dev); 1071 kfree(sa_dev);
diff --git a/drivers/infiniband/hw/ehca/ehca_classes.h b/drivers/infiniband/hw/ehca/ehca_classes.h
index 1e9e99a13933..0b0618edd645 100644
--- a/drivers/infiniband/hw/ehca/ehca_classes.h
+++ b/drivers/infiniband/hw/ehca/ehca_classes.h
@@ -194,6 +194,7 @@ struct ehca_qp {
194 u32 packet_count; 194 u32 packet_count;
195 atomic_t nr_events; /* events seen */ 195 atomic_t nr_events; /* events seen */
196 wait_queue_head_t wait_completion; 196 wait_queue_head_t wait_completion;
197 int mig_armed;
197}; 198};
198 199
199#define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ) 200#define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)
diff --git a/drivers/infiniband/hw/ehca/ehca_hca.c b/drivers/infiniband/hw/ehca/ehca_hca.c
index bc3b37d2070f..46288220cfbb 100644
--- a/drivers/infiniband/hw/ehca/ehca_hca.c
+++ b/drivers/infiniband/hw/ehca/ehca_hca.c
@@ -114,7 +114,9 @@ int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
114 } 114 }
115 115
116 props->max_pkeys = 16; 116 props->max_pkeys = 16;
117 props->local_ca_ack_delay = min_t(u8, rblock->local_ca_ack_delay, 255); 117 /* Some FW versions say 0 here; insert sensible value in that case */
118 props->local_ca_ack_delay = rblock->local_ca_ack_delay ?
119 min_t(u8, rblock->local_ca_ack_delay, 255) : 12;
118 props->max_raw_ipv6_qp = limit_uint(rblock->max_raw_ipv6_qp); 120 props->max_raw_ipv6_qp = limit_uint(rblock->max_raw_ipv6_qp);
119 props->max_raw_ethy_qp = limit_uint(rblock->max_raw_ethy_qp); 121 props->max_raw_ethy_qp = limit_uint(rblock->max_raw_ethy_qp);
120 props->max_mcast_grp = limit_uint(rblock->max_mcast_grp); 122 props->max_mcast_grp = limit_uint(rblock->max_mcast_grp);
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.c b/drivers/infiniband/hw/ehca/ehca_irq.c
index 0792d930c481..cb55be04442c 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.c
+++ b/drivers/infiniband/hw/ehca/ehca_irq.c
@@ -178,6 +178,10 @@ static void dispatch_qp_event(struct ehca_shca *shca, struct ehca_qp *qp,
178{ 178{
179 struct ib_event event; 179 struct ib_event event;
180 180
181 /* PATH_MIG without the QP ever having been armed is false alarm */
182 if (event_type == IB_EVENT_PATH_MIG && !qp->mig_armed)
183 return;
184
181 event.device = &shca->ib_device; 185 event.device = &shca->ib_device;
182 event.event = event_type; 186 event.event = event_type;
183 187
@@ -646,8 +650,8 @@ static inline int find_next_online_cpu(struct ehca_comp_pool *pool)
646 ehca_dmp(&cpu_online_map, sizeof(cpumask_t), ""); 650 ehca_dmp(&cpu_online_map, sizeof(cpumask_t), "");
647 651
648 spin_lock_irqsave(&pool->last_cpu_lock, flags); 652 spin_lock_irqsave(&pool->last_cpu_lock, flags);
649 cpu = next_cpu(pool->last_cpu, cpu_online_map); 653 cpu = next_cpu_nr(pool->last_cpu, cpu_online_map);
650 if (cpu == NR_CPUS) 654 if (cpu >= nr_cpu_ids)
651 cpu = first_cpu(cpu_online_map); 655 cpu = first_cpu(cpu_online_map);
652 pool->last_cpu = cpu; 656 pool->last_cpu = cpu;
653 spin_unlock_irqrestore(&pool->last_cpu_lock, flags); 657 spin_unlock_irqrestore(&pool->last_cpu_lock, flags);
diff --git a/drivers/infiniband/hw/ehca/ehca_qp.c b/drivers/infiniband/hw/ehca/ehca_qp.c
index 3f59587338ea..ea13efddf175 100644
--- a/drivers/infiniband/hw/ehca/ehca_qp.c
+++ b/drivers/infiniband/hw/ehca/ehca_qp.c
@@ -1460,6 +1460,8 @@ static int internal_modify_qp(struct ib_qp *ibqp,
1460 goto modify_qp_exit2; 1460 goto modify_qp_exit2;
1461 } 1461 }
1462 mqpcb->path_migration_state = attr->path_mig_state + 1; 1462 mqpcb->path_migration_state = attr->path_mig_state + 1;
1463 if (attr->path_mig_state == IB_MIG_REARM)
1464 my_qp->mig_armed = 1;
1463 update_mask |= 1465 update_mask |=
1464 EHCA_BMASK_SET(MQPCB_MASK_PATH_MIGRATION_STATE, 1); 1466 EHCA_BMASK_SET(MQPCB_MASK_PATH_MIGRATION_STATE, 1);
1465 } 1467 }
diff --git a/drivers/infiniband/hw/ehca/ipz_pt_fn.c b/drivers/infiniband/hw/ehca/ipz_pt_fn.c
index 661f8db62706..c3a328465431 100644
--- a/drivers/infiniband/hw/ehca/ipz_pt_fn.c
+++ b/drivers/infiniband/hw/ehca/ipz_pt_fn.c
@@ -163,6 +163,7 @@ static int alloc_small_queue_page(struct ipz_queue *queue, struct ehca_pd *pd)
163 163
164out: 164out:
165 ehca_err(pd->ib_pd.device, "failed to allocate small queue page"); 165 ehca_err(pd->ib_pd.device, "failed to allocate small queue page");
166 mutex_unlock(&pd->lock);
166 return 0; 167 return 0;
167} 168}
168 169
diff --git a/drivers/infiniband/hw/ipath/ipath_sdma.c b/drivers/infiniband/hw/ipath/ipath_sdma.c
index eaba03273e4f..284c9bca517e 100644
--- a/drivers/infiniband/hw/ipath/ipath_sdma.c
+++ b/drivers/infiniband/hw/ipath/ipath_sdma.c
@@ -698,7 +698,7 @@ retry:
698 698
699 addr = dma_map_single(&dd->pcidev->dev, tx->txreq.map_addr, 699 addr = dma_map_single(&dd->pcidev->dev, tx->txreq.map_addr,
700 tx->map_len, DMA_TO_DEVICE); 700 tx->map_len, DMA_TO_DEVICE);
701 if (dma_mapping_error(addr)) { 701 if (dma_mapping_error(&dd->pcidev->dev, addr)) {
702 ret = -EIO; 702 ret = -EIO;
703 goto unlock; 703 goto unlock;
704 } 704 }
diff --git a/drivers/infiniband/hw/ipath/ipath_user_sdma.c b/drivers/infiniband/hw/ipath/ipath_user_sdma.c
index 86e016916cd1..82d9a0b5ca2f 100644
--- a/drivers/infiniband/hw/ipath/ipath_user_sdma.c
+++ b/drivers/infiniband/hw/ipath/ipath_user_sdma.c
@@ -206,7 +206,7 @@ static int ipath_user_sdma_coalesce(const struct ipath_devdata *dd,
206 206
207 dma_addr = dma_map_page(&dd->pcidev->dev, page, 0, len, 207 dma_addr = dma_map_page(&dd->pcidev->dev, page, 0, len,
208 DMA_TO_DEVICE); 208 DMA_TO_DEVICE);
209 if (dma_mapping_error(dma_addr)) { 209 if (dma_mapping_error(&dd->pcidev->dev, dma_addr)) {
210 ret = -ENOMEM; 210 ret = -ENOMEM;
211 goto free_unmap; 211 goto free_unmap;
212 } 212 }
@@ -301,7 +301,7 @@ static int ipath_user_sdma_pin_pages(const struct ipath_devdata *dd,
301 pages[j], 0, flen, DMA_TO_DEVICE); 301 pages[j], 0, flen, DMA_TO_DEVICE);
302 unsigned long fofs = addr & ~PAGE_MASK; 302 unsigned long fofs = addr & ~PAGE_MASK;
303 303
304 if (dma_mapping_error(dma_addr)) { 304 if (dma_mapping_error(&dd->pcidev->dev, dma_addr)) {
305 ret = -ENOMEM; 305 ret = -ENOMEM;
306 goto done; 306 goto done;
307 } 307 }
@@ -508,7 +508,7 @@ static int ipath_user_sdma_queue_pkts(const struct ipath_devdata *dd,
508 if (page) { 508 if (page) {
509 dma_addr = dma_map_page(&dd->pcidev->dev, 509 dma_addr = dma_map_page(&dd->pcidev->dev,
510 page, 0, len, DMA_TO_DEVICE); 510 page, 0, len, DMA_TO_DEVICE);
511 if (dma_mapping_error(dma_addr)) { 511 if (dma_mapping_error(&dd->pcidev->dev, dma_addr)) {
512 ret = -ENOMEM; 512 ret = -ENOMEM;
513 goto free_pbc; 513 goto free_pbc;
514 } 514 }
diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c
index 299f20832ab6..0b191a4842ce 100644
--- a/drivers/infiniband/hw/mlx4/cq.c
+++ b/drivers/infiniband/hw/mlx4/cq.c
@@ -637,6 +637,7 @@ repoll:
637 case MLX4_OPCODE_SEND_IMM: 637 case MLX4_OPCODE_SEND_IMM:
638 wc->wc_flags |= IB_WC_WITH_IMM; 638 wc->wc_flags |= IB_WC_WITH_IMM;
639 case MLX4_OPCODE_SEND: 639 case MLX4_OPCODE_SEND:
640 case MLX4_OPCODE_SEND_INVAL:
640 wc->opcode = IB_WC_SEND; 641 wc->opcode = IB_WC_SEND;
641 break; 642 break;
642 case MLX4_OPCODE_RDMA_READ: 643 case MLX4_OPCODE_RDMA_READ:
@@ -657,6 +658,12 @@ repoll:
657 case MLX4_OPCODE_LSO: 658 case MLX4_OPCODE_LSO:
658 wc->opcode = IB_WC_LSO; 659 wc->opcode = IB_WC_LSO;
659 break; 660 break;
661 case MLX4_OPCODE_FMR:
662 wc->opcode = IB_WC_FAST_REG_MR;
663 break;
664 case MLX4_OPCODE_LOCAL_INVAL:
665 wc->opcode = IB_WC_LOCAL_INV;
666 break;
660 } 667 }
661 } else { 668 } else {
662 wc->byte_len = be32_to_cpu(cqe->byte_cnt); 669 wc->byte_len = be32_to_cpu(cqe->byte_cnt);
@@ -667,6 +674,11 @@ repoll:
667 wc->wc_flags = IB_WC_WITH_IMM; 674 wc->wc_flags = IB_WC_WITH_IMM;
668 wc->ex.imm_data = cqe->immed_rss_invalid; 675 wc->ex.imm_data = cqe->immed_rss_invalid;
669 break; 676 break;
677 case MLX4_RECV_OPCODE_SEND_INVAL:
678 wc->opcode = IB_WC_RECV;
679 wc->wc_flags = IB_WC_WITH_INVALIDATE;
680 wc->ex.invalidate_rkey = be32_to_cpu(cqe->immed_rss_invalid);
681 break;
670 case MLX4_RECV_OPCODE_SEND: 682 case MLX4_RECV_OPCODE_SEND:
671 wc->opcode = IB_WC_RECV; 683 wc->opcode = IB_WC_RECV;
672 wc->wc_flags = 0; 684 wc->wc_flags = 0;
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index bcf50648fa18..38d6907ab521 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -104,6 +104,12 @@ static int mlx4_ib_query_device(struct ib_device *ibdev,
104 props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM; 104 props->device_cap_flags |= IB_DEVICE_UD_IP_CSUM;
105 if (dev->dev->caps.max_gso_sz) 105 if (dev->dev->caps.max_gso_sz)
106 props->device_cap_flags |= IB_DEVICE_UD_TSO; 106 props->device_cap_flags |= IB_DEVICE_UD_TSO;
107 if (dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_RESERVED_LKEY)
108 props->device_cap_flags |= IB_DEVICE_LOCAL_DMA_LKEY;
109 if ((dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_LOCAL_INV) &&
110 (dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_REMOTE_INV) &&
111 (dev->dev->caps.bmme_flags & MLX4_BMME_FLAG_FAST_REG_WR))
112 props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
107 113
108 props->vendor_id = be32_to_cpup((__be32 *) (out_mad->data + 36)) & 114 props->vendor_id = be32_to_cpup((__be32 *) (out_mad->data + 36)) &
109 0xffffff; 115 0xffffff;
@@ -127,6 +133,7 @@ static int mlx4_ib_query_device(struct ib_device *ibdev,
127 props->max_srq = dev->dev->caps.num_srqs - dev->dev->caps.reserved_srqs; 133 props->max_srq = dev->dev->caps.num_srqs - dev->dev->caps.reserved_srqs;
128 props->max_srq_wr = dev->dev->caps.max_srq_wqes - 1; 134 props->max_srq_wr = dev->dev->caps.max_srq_wqes - 1;
129 props->max_srq_sge = dev->dev->caps.max_srq_sge; 135 props->max_srq_sge = dev->dev->caps.max_srq_sge;
136 props->max_fast_reg_page_list_len = PAGE_SIZE / sizeof (u64);
130 props->local_ca_ack_delay = dev->dev->caps.local_ca_ack_delay; 137 props->local_ca_ack_delay = dev->dev->caps.local_ca_ack_delay;
131 props->atomic_cap = dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_ATOMIC ? 138 props->atomic_cap = dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_ATOMIC ?
132 IB_ATOMIC_HCA : IB_ATOMIC_NONE; 139 IB_ATOMIC_HCA : IB_ATOMIC_NONE;
@@ -565,6 +572,7 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
565 strlcpy(ibdev->ib_dev.name, "mlx4_%d", IB_DEVICE_NAME_MAX); 572 strlcpy(ibdev->ib_dev.name, "mlx4_%d", IB_DEVICE_NAME_MAX);
566 ibdev->ib_dev.owner = THIS_MODULE; 573 ibdev->ib_dev.owner = THIS_MODULE;
567 ibdev->ib_dev.node_type = RDMA_NODE_IB_CA; 574 ibdev->ib_dev.node_type = RDMA_NODE_IB_CA;
575 ibdev->ib_dev.local_dma_lkey = dev->caps.reserved_lkey;
568 ibdev->ib_dev.phys_port_cnt = dev->caps.num_ports; 576 ibdev->ib_dev.phys_port_cnt = dev->caps.num_ports;
569 ibdev->ib_dev.num_comp_vectors = 1; 577 ibdev->ib_dev.num_comp_vectors = 1;
570 ibdev->ib_dev.dma_device = &dev->pdev->dev; 578 ibdev->ib_dev.dma_device = &dev->pdev->dev;
@@ -627,6 +635,9 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
627 ibdev->ib_dev.get_dma_mr = mlx4_ib_get_dma_mr; 635 ibdev->ib_dev.get_dma_mr = mlx4_ib_get_dma_mr;
628 ibdev->ib_dev.reg_user_mr = mlx4_ib_reg_user_mr; 636 ibdev->ib_dev.reg_user_mr = mlx4_ib_reg_user_mr;
629 ibdev->ib_dev.dereg_mr = mlx4_ib_dereg_mr; 637 ibdev->ib_dev.dereg_mr = mlx4_ib_dereg_mr;
638 ibdev->ib_dev.alloc_fast_reg_mr = mlx4_ib_alloc_fast_reg_mr;
639 ibdev->ib_dev.alloc_fast_reg_page_list = mlx4_ib_alloc_fast_reg_page_list;
640 ibdev->ib_dev.free_fast_reg_page_list = mlx4_ib_free_fast_reg_page_list;
630 ibdev->ib_dev.attach_mcast = mlx4_ib_mcg_attach; 641 ibdev->ib_dev.attach_mcast = mlx4_ib_mcg_attach;
631 ibdev->ib_dev.detach_mcast = mlx4_ib_mcg_detach; 642 ibdev->ib_dev.detach_mcast = mlx4_ib_mcg_detach;
632 ibdev->ib_dev.process_mad = mlx4_ib_process_mad; 643 ibdev->ib_dev.process_mad = mlx4_ib_process_mad;
diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
index c4cf5b69eefa..d26a91317d4d 100644
--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
@@ -83,6 +83,11 @@ struct mlx4_ib_mr {
83 struct ib_umem *umem; 83 struct ib_umem *umem;
84}; 84};
85 85
86struct mlx4_ib_fast_reg_page_list {
87 struct ib_fast_reg_page_list ibfrpl;
88 dma_addr_t map;
89};
90
86struct mlx4_ib_fmr { 91struct mlx4_ib_fmr {
87 struct ib_fmr ibfmr; 92 struct ib_fmr ibfmr;
88 struct mlx4_fmr mfmr; 93 struct mlx4_fmr mfmr;
@@ -199,6 +204,11 @@ static inline struct mlx4_ib_mr *to_mmr(struct ib_mr *ibmr)
199 return container_of(ibmr, struct mlx4_ib_mr, ibmr); 204 return container_of(ibmr, struct mlx4_ib_mr, ibmr);
200} 205}
201 206
207static inline struct mlx4_ib_fast_reg_page_list *to_mfrpl(struct ib_fast_reg_page_list *ibfrpl)
208{
209 return container_of(ibfrpl, struct mlx4_ib_fast_reg_page_list, ibfrpl);
210}
211
202static inline struct mlx4_ib_fmr *to_mfmr(struct ib_fmr *ibfmr) 212static inline struct mlx4_ib_fmr *to_mfmr(struct ib_fmr *ibfmr)
203{ 213{
204 return container_of(ibfmr, struct mlx4_ib_fmr, ibfmr); 214 return container_of(ibfmr, struct mlx4_ib_fmr, ibfmr);
@@ -239,6 +249,11 @@ struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
239 u64 virt_addr, int access_flags, 249 u64 virt_addr, int access_flags,
240 struct ib_udata *udata); 250 struct ib_udata *udata);
241int mlx4_ib_dereg_mr(struct ib_mr *mr); 251int mlx4_ib_dereg_mr(struct ib_mr *mr);
252struct ib_mr *mlx4_ib_alloc_fast_reg_mr(struct ib_pd *pd,
253 int max_page_list_len);
254struct ib_fast_reg_page_list *mlx4_ib_alloc_fast_reg_page_list(struct ib_device *ibdev,
255 int page_list_len);
256void mlx4_ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
242 257
243int mlx4_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period); 258int mlx4_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
244int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata); 259int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
diff --git a/drivers/infiniband/hw/mlx4/mr.c b/drivers/infiniband/hw/mlx4/mr.c
index 68e92485fc76..db2086faa4ed 100644
--- a/drivers/infiniband/hw/mlx4/mr.c
+++ b/drivers/infiniband/hw/mlx4/mr.c
@@ -183,6 +183,76 @@ int mlx4_ib_dereg_mr(struct ib_mr *ibmr)
183 return 0; 183 return 0;
184} 184}
185 185
186struct ib_mr *mlx4_ib_alloc_fast_reg_mr(struct ib_pd *pd,
187 int max_page_list_len)
188{
189 struct mlx4_ib_dev *dev = to_mdev(pd->device);
190 struct mlx4_ib_mr *mr;
191 int err;
192
193 mr = kmalloc(sizeof *mr, GFP_KERNEL);
194 if (!mr)
195 return ERR_PTR(-ENOMEM);
196
197 err = mlx4_mr_alloc(dev->dev, to_mpd(pd)->pdn, 0, 0, 0,
198 max_page_list_len, 0, &mr->mmr);
199 if (err)
200 goto err_free;
201
202 err = mlx4_mr_enable(dev->dev, &mr->mmr);
203 if (err)
204 goto err_mr;
205
206 return &mr->ibmr;
207
208err_mr:
209 mlx4_mr_free(dev->dev, &mr->mmr);
210
211err_free:
212 kfree(mr);
213 return ERR_PTR(err);
214}
215
216struct ib_fast_reg_page_list *mlx4_ib_alloc_fast_reg_page_list(struct ib_device *ibdev,
217 int page_list_len)
218{
219 struct mlx4_ib_dev *dev = to_mdev(ibdev);
220 struct mlx4_ib_fast_reg_page_list *mfrpl;
221 int size = page_list_len * sizeof (u64);
222
223 if (size > PAGE_SIZE)
224 return ERR_PTR(-EINVAL);
225
226 mfrpl = kmalloc(sizeof *mfrpl, GFP_KERNEL);
227 if (!mfrpl)
228 return ERR_PTR(-ENOMEM);
229
230 mfrpl->ibfrpl.page_list = dma_alloc_coherent(&dev->dev->pdev->dev,
231 size, &mfrpl->map,
232 GFP_KERNEL);
233 if (!mfrpl->ibfrpl.page_list)
234 goto err_free;
235
236 WARN_ON(mfrpl->map & 0x3f);
237
238 return &mfrpl->ibfrpl;
239
240err_free:
241 kfree(mfrpl);
242 return ERR_PTR(-ENOMEM);
243}
244
245void mlx4_ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list)
246{
247 struct mlx4_ib_dev *dev = to_mdev(page_list->device);
248 struct mlx4_ib_fast_reg_page_list *mfrpl = to_mfrpl(page_list);
249 int size = page_list->max_page_list_len * sizeof (u64);
250
251 dma_free_coherent(&dev->dev->pdev->dev, size, page_list->page_list,
252 mfrpl->map);
253 kfree(mfrpl);
254}
255
186struct ib_fmr *mlx4_ib_fmr_alloc(struct ib_pd *pd, int acc, 256struct ib_fmr *mlx4_ib_fmr_alloc(struct ib_pd *pd, int acc,
187 struct ib_fmr_attr *fmr_attr) 257 struct ib_fmr_attr *fmr_attr)
188{ 258{
diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
index 89eb6cbe592e..02a99bc4442e 100644
--- a/drivers/infiniband/hw/mlx4/qp.c
+++ b/drivers/infiniband/hw/mlx4/qp.c
@@ -78,6 +78,9 @@ static const __be32 mlx4_ib_opcode[] = {
78 [IB_WR_RDMA_READ] = __constant_cpu_to_be32(MLX4_OPCODE_RDMA_READ), 78 [IB_WR_RDMA_READ] = __constant_cpu_to_be32(MLX4_OPCODE_RDMA_READ),
79 [IB_WR_ATOMIC_CMP_AND_SWP] = __constant_cpu_to_be32(MLX4_OPCODE_ATOMIC_CS), 79 [IB_WR_ATOMIC_CMP_AND_SWP] = __constant_cpu_to_be32(MLX4_OPCODE_ATOMIC_CS),
80 [IB_WR_ATOMIC_FETCH_AND_ADD] = __constant_cpu_to_be32(MLX4_OPCODE_ATOMIC_FA), 80 [IB_WR_ATOMIC_FETCH_AND_ADD] = __constant_cpu_to_be32(MLX4_OPCODE_ATOMIC_FA),
81 [IB_WR_SEND_WITH_INV] = __constant_cpu_to_be32(MLX4_OPCODE_SEND_INVAL),
82 [IB_WR_LOCAL_INV] = __constant_cpu_to_be32(MLX4_OPCODE_LOCAL_INVAL),
83 [IB_WR_FAST_REG_MR] = __constant_cpu_to_be32(MLX4_OPCODE_FMR),
81}; 84};
82 85
83static struct mlx4_ib_sqp *to_msqp(struct mlx4_ib_qp *mqp) 86static struct mlx4_ib_sqp *to_msqp(struct mlx4_ib_qp *mqp)
@@ -976,6 +979,10 @@ static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
976 context->pd = cpu_to_be32(to_mpd(ibqp->pd)->pdn); 979 context->pd = cpu_to_be32(to_mpd(ibqp->pd)->pdn);
977 context->params1 = cpu_to_be32(MLX4_IB_ACK_REQ_FREQ << 28); 980 context->params1 = cpu_to_be32(MLX4_IB_ACK_REQ_FREQ << 28);
978 981
982 /* Set "fast registration enabled" for all kernel QPs */
983 if (!qp->ibqp.uobject)
984 context->params1 |= cpu_to_be32(1 << 11);
985
979 if (attr_mask & IB_QP_RNR_RETRY) { 986 if (attr_mask & IB_QP_RNR_RETRY) {
980 context->params1 |= cpu_to_be32(attr->rnr_retry << 13); 987 context->params1 |= cpu_to_be32(attr->rnr_retry << 13);
981 optpar |= MLX4_QP_OPTPAR_RNR_RETRY; 988 optpar |= MLX4_QP_OPTPAR_RNR_RETRY;
@@ -1322,6 +1329,38 @@ static int mlx4_wq_overflow(struct mlx4_ib_wq *wq, int nreq, struct ib_cq *ib_cq
1322 return cur + nreq >= wq->max_post; 1329 return cur + nreq >= wq->max_post;
1323} 1330}
1324 1331
1332static __be32 convert_access(int acc)
1333{
1334 return (acc & IB_ACCESS_REMOTE_ATOMIC ? cpu_to_be32(MLX4_WQE_FMR_PERM_ATOMIC) : 0) |
1335 (acc & IB_ACCESS_REMOTE_WRITE ? cpu_to_be32(MLX4_WQE_FMR_PERM_REMOTE_WRITE) : 0) |
1336 (acc & IB_ACCESS_REMOTE_READ ? cpu_to_be32(MLX4_WQE_FMR_PERM_REMOTE_READ) : 0) |
1337 (acc & IB_ACCESS_LOCAL_WRITE ? cpu_to_be32(MLX4_WQE_FMR_PERM_LOCAL_WRITE) : 0) |
1338 cpu_to_be32(MLX4_WQE_FMR_PERM_LOCAL_READ);
1339}
1340
1341static void set_fmr_seg(struct mlx4_wqe_fmr_seg *fseg, struct ib_send_wr *wr)
1342{
1343 struct mlx4_ib_fast_reg_page_list *mfrpl = to_mfrpl(wr->wr.fast_reg.page_list);
1344
1345 fseg->flags = convert_access(wr->wr.fast_reg.access_flags);
1346 fseg->mem_key = cpu_to_be32(wr->wr.fast_reg.rkey);
1347 fseg->buf_list = cpu_to_be64(mfrpl->map);
1348 fseg->start_addr = cpu_to_be64(wr->wr.fast_reg.iova_start);
1349 fseg->reg_len = cpu_to_be64(wr->wr.fast_reg.length);
1350 fseg->offset = 0; /* XXX -- is this just for ZBVA? */
1351 fseg->page_size = cpu_to_be32(wr->wr.fast_reg.page_shift);
1352 fseg->reserved[0] = 0;
1353 fseg->reserved[1] = 0;
1354}
1355
1356static void set_local_inv_seg(struct mlx4_wqe_local_inval_seg *iseg, u32 rkey)
1357{
1358 iseg->flags = 0;
1359 iseg->mem_key = cpu_to_be32(rkey);
1360 iseg->guest_id = 0;
1361 iseg->pa = 0;
1362}
1363
1325static __always_inline void set_raddr_seg(struct mlx4_wqe_raddr_seg *rseg, 1364static __always_inline void set_raddr_seg(struct mlx4_wqe_raddr_seg *rseg,
1326 u64 remote_addr, u32 rkey) 1365 u64 remote_addr, u32 rkey)
1327{ 1366{
@@ -1395,7 +1434,7 @@ static void __set_data_seg(struct mlx4_wqe_data_seg *dseg, struct ib_sge *sg)
1395 dseg->addr = cpu_to_be64(sg->addr); 1434 dseg->addr = cpu_to_be64(sg->addr);
1396} 1435}
1397 1436
1398static int build_lso_seg(struct mlx4_lso_seg *wqe, struct ib_send_wr *wr, 1437static int build_lso_seg(struct mlx4_wqe_lso_seg *wqe, struct ib_send_wr *wr,
1399 struct mlx4_ib_qp *qp, unsigned *lso_seg_len) 1438 struct mlx4_ib_qp *qp, unsigned *lso_seg_len)
1400{ 1439{
1401 unsigned halign = ALIGN(sizeof *wqe + wr->wr.ud.hlen, 16); 1440 unsigned halign = ALIGN(sizeof *wqe + wr->wr.ud.hlen, 16);
@@ -1423,6 +1462,21 @@ static int build_lso_seg(struct mlx4_lso_seg *wqe, struct ib_send_wr *wr,
1423 return 0; 1462 return 0;
1424} 1463}
1425 1464
1465static __be32 send_ieth(struct ib_send_wr *wr)
1466{
1467 switch (wr->opcode) {
1468 case IB_WR_SEND_WITH_IMM:
1469 case IB_WR_RDMA_WRITE_WITH_IMM:
1470 return wr->ex.imm_data;
1471
1472 case IB_WR_SEND_WITH_INV:
1473 return cpu_to_be32(wr->ex.invalidate_rkey);
1474
1475 default:
1476 return 0;
1477 }
1478}
1479
1426int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, 1480int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1427 struct ib_send_wr **bad_wr) 1481 struct ib_send_wr **bad_wr)
1428{ 1482{
@@ -1469,11 +1523,7 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1469 MLX4_WQE_CTRL_TCP_UDP_CSUM) : 0) | 1523 MLX4_WQE_CTRL_TCP_UDP_CSUM) : 0) |
1470 qp->sq_signal_bits; 1524 qp->sq_signal_bits;
1471 1525
1472 if (wr->opcode == IB_WR_SEND_WITH_IMM || 1526 ctrl->imm = send_ieth(wr);
1473 wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM)
1474 ctrl->imm = wr->ex.imm_data;
1475 else
1476 ctrl->imm = 0;
1477 1527
1478 wqe += sizeof *ctrl; 1528 wqe += sizeof *ctrl;
1479 size = sizeof *ctrl / 16; 1529 size = sizeof *ctrl / 16;
@@ -1505,6 +1555,18 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1505 size += sizeof (struct mlx4_wqe_raddr_seg) / 16; 1555 size += sizeof (struct mlx4_wqe_raddr_seg) / 16;
1506 break; 1556 break;
1507 1557
1558 case IB_WR_LOCAL_INV:
1559 set_local_inv_seg(wqe, wr->ex.invalidate_rkey);
1560 wqe += sizeof (struct mlx4_wqe_local_inval_seg);
1561 size += sizeof (struct mlx4_wqe_local_inval_seg) / 16;
1562 break;
1563
1564 case IB_WR_FAST_REG_MR:
1565 set_fmr_seg(wqe, wr);
1566 wqe += sizeof (struct mlx4_wqe_fmr_seg);
1567 size += sizeof (struct mlx4_wqe_fmr_seg) / 16;
1568 break;
1569
1508 default: 1570 default:
1509 /* No extra segments required for sends */ 1571 /* No extra segments required for sends */
1510 break; 1572 break;
diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h b/drivers/infiniband/hw/mthca/mthca_dev.h
index ee4d073c889f..252590116df5 100644
--- a/drivers/infiniband/hw/mthca/mthca_dev.h
+++ b/drivers/infiniband/hw/mthca/mthca_dev.h
@@ -202,6 +202,7 @@ struct mthca_pd_table {
202 202
203struct mthca_buddy { 203struct mthca_buddy {
204 unsigned long **bits; 204 unsigned long **bits;
205 int *num_free;
205 int max_order; 206 int max_order;
206 spinlock_t lock; 207 spinlock_t lock;
207}; 208};
diff --git a/drivers/infiniband/hw/mthca/mthca_eq.c b/drivers/infiniband/hw/mthca/mthca_eq.c
index 4e36aa7cb3d2..cc6858f0b65b 100644
--- a/drivers/infiniband/hw/mthca/mthca_eq.c
+++ b/drivers/infiniband/hw/mthca/mthca_eq.c
@@ -780,7 +780,7 @@ int mthca_map_eq_icm(struct mthca_dev *dev, u64 icm_virt)
780 return -ENOMEM; 780 return -ENOMEM;
781 dev->eq_table.icm_dma = pci_map_page(dev->pdev, dev->eq_table.icm_page, 0, 781 dev->eq_table.icm_dma = pci_map_page(dev->pdev, dev->eq_table.icm_page, 0,
782 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 782 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
783 if (pci_dma_mapping_error(dev->eq_table.icm_dma)) { 783 if (pci_dma_mapping_error(dev->pdev, dev->eq_table.icm_dma)) {
784 __free_page(dev->eq_table.icm_page); 784 __free_page(dev->eq_table.icm_page);
785 return -ENOMEM; 785 return -ENOMEM;
786 } 786 }
diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
index 8489b1e81c0f..882e6b735915 100644
--- a/drivers/infiniband/hw/mthca/mthca_mr.c
+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
@@ -89,23 +89,26 @@ static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
89 89
90 spin_lock(&buddy->lock); 90 spin_lock(&buddy->lock);
91 91
92 for (o = order; o <= buddy->max_order; ++o) { 92 for (o = order; o <= buddy->max_order; ++o)
93 m = 1 << (buddy->max_order - o); 93 if (buddy->num_free[o]) {
94 seg = find_first_bit(buddy->bits[o], m); 94 m = 1 << (buddy->max_order - o);
95 if (seg < m) 95 seg = find_first_bit(buddy->bits[o], m);
96 goto found; 96 if (seg < m)
97 } 97 goto found;
98 }
98 99
99 spin_unlock(&buddy->lock); 100 spin_unlock(&buddy->lock);
100 return -1; 101 return -1;
101 102
102 found: 103 found:
103 clear_bit(seg, buddy->bits[o]); 104 clear_bit(seg, buddy->bits[o]);
105 --buddy->num_free[o];
104 106
105 while (o > order) { 107 while (o > order) {
106 --o; 108 --o;
107 seg <<= 1; 109 seg <<= 1;
108 set_bit(seg ^ 1, buddy->bits[o]); 110 set_bit(seg ^ 1, buddy->bits[o]);
111 ++buddy->num_free[o];
109 } 112 }
110 113
111 spin_unlock(&buddy->lock); 114 spin_unlock(&buddy->lock);
@@ -123,11 +126,13 @@ static void mthca_buddy_free(struct mthca_buddy *buddy, u32 seg, int order)
123 126
124 while (test_bit(seg ^ 1, buddy->bits[order])) { 127 while (test_bit(seg ^ 1, buddy->bits[order])) {
125 clear_bit(seg ^ 1, buddy->bits[order]); 128 clear_bit(seg ^ 1, buddy->bits[order]);
129 --buddy->num_free[order];
126 seg >>= 1; 130 seg >>= 1;
127 ++order; 131 ++order;
128 } 132 }
129 133
130 set_bit(seg, buddy->bits[order]); 134 set_bit(seg, buddy->bits[order]);
135 ++buddy->num_free[order];
131 136
132 spin_unlock(&buddy->lock); 137 spin_unlock(&buddy->lock);
133} 138}
@@ -141,7 +146,9 @@ static int mthca_buddy_init(struct mthca_buddy *buddy, int max_order)
141 146
142 buddy->bits = kzalloc((buddy->max_order + 1) * sizeof (long *), 147 buddy->bits = kzalloc((buddy->max_order + 1) * sizeof (long *),
143 GFP_KERNEL); 148 GFP_KERNEL);
144 if (!buddy->bits) 149 buddy->num_free = kzalloc((buddy->max_order + 1) * sizeof (int *),
150 GFP_KERNEL);
151 if (!buddy->bits || !buddy->num_free)
145 goto err_out; 152 goto err_out;
146 153
147 for (i = 0; i <= buddy->max_order; ++i) { 154 for (i = 0; i <= buddy->max_order; ++i) {
@@ -154,6 +161,7 @@ static int mthca_buddy_init(struct mthca_buddy *buddy, int max_order)
154 } 161 }
155 162
156 set_bit(0, buddy->bits[buddy->max_order]); 163 set_bit(0, buddy->bits[buddy->max_order]);
164 buddy->num_free[buddy->max_order] = 1;
157 165
158 return 0; 166 return 0;
159 167
@@ -161,9 +169,10 @@ err_out_free:
161 for (i = 0; i <= buddy->max_order; ++i) 169 for (i = 0; i <= buddy->max_order; ++i)
162 kfree(buddy->bits[i]); 170 kfree(buddy->bits[i]);
163 171
172err_out:
164 kfree(buddy->bits); 173 kfree(buddy->bits);
174 kfree(buddy->num_free);
165 175
166err_out:
167 return -ENOMEM; 176 return -ENOMEM;
168} 177}
169 178
@@ -175,6 +184,7 @@ static void mthca_buddy_cleanup(struct mthca_buddy *buddy)
175 kfree(buddy->bits[i]); 184 kfree(buddy->bits[i]);
176 185
177 kfree(buddy->bits); 186 kfree(buddy->bits);
187 kfree(buddy->num_free);
178} 188}
179 189
180static u32 mthca_alloc_mtt_range(struct mthca_dev *dev, int order, 190static u32 mthca_alloc_mtt_range(struct mthca_dev *dev, int order,
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 8be9ea0436e6..f51201b17bfd 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -548,7 +548,7 @@ static int path_rec_start(struct net_device *dev,
548 path_rec_completion, 548 path_rec_completion,
549 path, &path->query); 549 path, &path->query);
550 if (path->query_id < 0) { 550 if (path->query_id < 0) {
551 ipoib_warn(priv, "ib_sa_path_rec_get failed\n"); 551 ipoib_warn(priv, "ib_sa_path_rec_get failed: %d\n", path->query_id);
552 path->query = NULL; 552 path->query = NULL;
553 return path->query_id; 553 return path->query_id;
554 } 554 }
diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
index 3a917c1f796f..63462ecca147 100644
--- a/drivers/infiniband/ulp/iser/iser_verbs.c
+++ b/drivers/infiniband/ulp/iser/iser_verbs.c
@@ -483,6 +483,7 @@ static int iser_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *eve
483 break; 483 break;
484 case RDMA_CM_EVENT_DISCONNECTED: 484 case RDMA_CM_EVENT_DISCONNECTED:
485 case RDMA_CM_EVENT_DEVICE_REMOVAL: 485 case RDMA_CM_EVENT_DEVICE_REMOVAL:
486 case RDMA_CM_EVENT_ADDR_CHANGE:
486 iser_disconnected_handler(cma_id); 487 iser_disconnected_handler(cma_id);
487 break; 488 break;
488 default: 489 default:
diff --git a/drivers/input/keyboard/hil_kbd.c b/drivers/input/keyboard/hil_kbd.c
index adbf29f0169d..71c1971abf80 100644
--- a/drivers/input/keyboard/hil_kbd.c
+++ b/drivers/input/keyboard/hil_kbd.c
@@ -37,6 +37,7 @@
37#include <linux/kernel.h> 37#include <linux/kernel.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/semaphore.h>
40#include <linux/slab.h> 41#include <linux/slab.h>
41#include <linux/pci_ids.h> 42#include <linux/pci_ids.h>
42 43
diff --git a/drivers/input/keyboard/tosakbd.c b/drivers/input/keyboard/tosakbd.c
index 94e444b4ee15..b12b7ee4b6aa 100644
--- a/drivers/input/keyboard/tosakbd.c
+++ b/drivers/input/keyboard/tosakbd.c
@@ -215,8 +215,6 @@ static int tosakbd_suspend(struct platform_device *dev, pm_message_t state)
215 unsigned long flags; 215 unsigned long flags;
216 216
217 spin_lock_irqsave(&tosakbd->lock, flags); 217 spin_lock_irqsave(&tosakbd->lock, flags);
218 PGSR1 = (PGSR1 & ~TOSA_GPIO_LOW_STROBE_BIT);
219 PGSR2 = (PGSR2 & ~TOSA_GPIO_HIGH_STROBE_BIT);
220 tosakbd->suspended = 1; 218 tosakbd->suspended = 1;
221 spin_unlock_irqrestore(&tosakbd->lock, flags); 219 spin_unlock_irqrestore(&tosakbd->lock, flags);
222 220
diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c
index 49d8abfe38fe..daa9d4220331 100644
--- a/drivers/input/misc/hp_sdc_rtc.c
+++ b/drivers/input/misc/hp_sdc_rtc.c
@@ -44,6 +44,7 @@
44#include <linux/proc_fs.h> 44#include <linux/proc_fs.h>
45#include <linux/poll.h> 45#include <linux/poll.h>
46#include <linux/rtc.h> 46#include <linux/rtc.h>
47#include <linux/semaphore.h>
47 48
48MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>"); 49MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
49MODULE_DESCRIPTION("HP i8042 SDC + MSM-58321 RTC Driver"); 50MODULE_DESCRIPTION("HP i8042 SDC + MSM-58321 RTC Driver");
diff --git a/drivers/input/serio/hp_sdc.c b/drivers/input/serio/hp_sdc.c
index 7b233a492ad5..0d395979b2d1 100644
--- a/drivers/input/serio/hp_sdc.c
+++ b/drivers/input/serio/hp_sdc.c
@@ -67,9 +67,9 @@
67#include <linux/module.h> 67#include <linux/module.h>
68#include <linux/ioport.h> 68#include <linux/ioport.h>
69#include <linux/time.h> 69#include <linux/time.h>
70#include <linux/semaphore.h>
70#include <linux/slab.h> 71#include <linux/slab.h>
71#include <linux/hil.h> 72#include <linux/hil.h>
72#include <linux/semaphore.h>
73#include <asm/io.h> 73#include <asm/io.h>
74#include <asm/system.h> 74#include <asm/system.h>
75 75
diff --git a/drivers/isdn/Kconfig b/drivers/isdn/Kconfig
index 66f946aa30b3..3d113c6e4a70 100644
--- a/drivers/isdn/Kconfig
+++ b/drivers/isdn/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4 4
5menuconfig ISDN 5menuconfig ISDN
6 tristate "ISDN support" 6 bool "ISDN support"
7 depends on NET 7 depends on NET
8 depends on !S390 8 depends on !S390
9 ---help--- 9 ---help---
@@ -21,6 +21,8 @@ menuconfig ISDN
21 21
22if ISDN 22if ISDN
23 23
24source "drivers/isdn/mISDN/Kconfig"
25
24menuconfig ISDN_I4L 26menuconfig ISDN_I4L
25 tristate "Old ISDN4Linux (deprecated)" 27 tristate "Old ISDN4Linux (deprecated)"
26 ---help--- 28 ---help---
diff --git a/drivers/isdn/Makefile b/drivers/isdn/Makefile
index 988142c30a6d..8380a4568d11 100644
--- a/drivers/isdn/Makefile
+++ b/drivers/isdn/Makefile
@@ -4,6 +4,7 @@
4 4
5obj-$(CONFIG_ISDN_I4L) += i4l/ 5obj-$(CONFIG_ISDN_I4L) += i4l/
6obj-$(CONFIG_ISDN_CAPI) += capi/ 6obj-$(CONFIG_ISDN_CAPI) += capi/
7obj-$(CONFIG_MISDN) += mISDN/
7obj-$(CONFIG_ISDN_CAPI) += hardware/ 8obj-$(CONFIG_ISDN_CAPI) += hardware/
8obj-$(CONFIG_ISDN_DIVERSION) += divert/ 9obj-$(CONFIG_ISDN_DIVERSION) += divert/
9obj-$(CONFIG_ISDN_DRV_HISAX) += hisax/ 10obj-$(CONFIG_ISDN_DRV_HISAX) += hisax/
diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c
index 091deb9d1c47..c2bd97d29273 100644
--- a/drivers/isdn/gigaset/asyncdata.c
+++ b/drivers/isdn/gigaset/asyncdata.c
@@ -575,7 +575,8 @@ int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb)
575 else 575 else
576 skb = iraw_encode(skb, HW_HDR_LEN, 0); 576 skb = iraw_encode(skb, HW_HDR_LEN, 0);
577 if (!skb) { 577 if (!skb) {
578 err("unable to allocate memory for encoding!\n"); 578 dev_err(bcs->cs->dev,
579 "unable to allocate memory for encoding!\n");
579 return -ENOMEM; 580 return -ENOMEM;
580 } 581 }
581 582
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index 5255b5e20e13..3f11910c7ccd 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -1050,10 +1050,9 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1050 } 1050 }
1051 1051
1052 /* retrieve block of data to send */ 1052 /* retrieve block of data to send */
1053 ifd->offset = gigaset_isowbuf_getbytes(ubc->isooutbuf, 1053 rc = gigaset_isowbuf_getbytes(ubc->isooutbuf, ifd->length);
1054 ifd->length); 1054 if (rc < 0) {
1055 if (ifd->offset < 0) { 1055 if (rc == -EBUSY) {
1056 if (ifd->offset == -EBUSY) {
1057 gig_dbg(DEBUG_ISO, 1056 gig_dbg(DEBUG_ISO,
1058 "%s: buffer busy at frame %d", 1057 "%s: buffer busy at frame %d",
1059 __func__, nframe); 1058 __func__, nframe);
@@ -1062,11 +1061,12 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1062 } else { 1061 } else {
1063 dev_err(ucx->bcs->cs->dev, 1062 dev_err(ucx->bcs->cs->dev,
1064 "%s: buffer error %d at frame %d\n", 1063 "%s: buffer error %d at frame %d\n",
1065 __func__, ifd->offset, nframe); 1064 __func__, rc, nframe);
1066 return ifd->offset; 1065 return rc;
1067 } 1066 }
1068 break; 1067 break;
1069 } 1068 }
1069 ifd->offset = rc;
1070 ucx->limit = ubc->isooutbuf->nextread; 1070 ucx->limit = ubc->isooutbuf->nextread;
1071 ifd->status = 0; 1071 ifd->status = 0;
1072 ifd->actual_length = 0; 1072 ifd->actual_length = 0;
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index 827c32c16795..9d3ce7718e58 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -287,7 +287,7 @@ struct event_t *gigaset_add_event(struct cardstate *cs,
287 tail = cs->ev_tail; 287 tail = cs->ev_tail;
288 next = (tail + 1) % MAX_EVENTS; 288 next = (tail + 1) % MAX_EVENTS;
289 if (unlikely(next == cs->ev_head)) 289 if (unlikely(next == cs->ev_head))
290 err("event queue full"); 290 dev_err(cs->dev, "event queue full\n");
291 else { 291 else {
292 event = cs->events + tail; 292 event = cs->events + tail;
293 event->type = type; 293 event->type = type;
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
index f365993161fc..003752954993 100644
--- a/drivers/isdn/gigaset/gigaset.h
+++ b/drivers/isdn/gigaset/gigaset.h
@@ -106,7 +106,6 @@ enum debuglevel {
106#undef err 106#undef err
107#undef info 107#undef info
108#undef warn 108#undef warn
109#undef notice
110 109
111#define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \ 110#define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \
112 format "\n" , ## arg) 111 format "\n" , ## arg)
@@ -114,8 +113,6 @@ enum debuglevel {
114 format "\n" , ## arg) 113 format "\n" , ## arg)
115#define warn(format, arg...) printk(KERN_WARNING KBUILD_MODNAME ": " \ 114#define warn(format, arg...) printk(KERN_WARNING KBUILD_MODNAME ": " \
116 format "\n" , ## arg) 115 format "\n" , ## arg)
117#define notice(format, arg...) printk(KERN_NOTICE KBUILD_MODNAME ": " \
118 format "\n" , ## arg)
119 116
120#ifdef CONFIG_GIGASET_DEBUG 117#ifdef CONFIG_GIGASET_DEBUG
121 118
diff --git a/drivers/isdn/gigaset/i4l.c b/drivers/isdn/gigaset/i4l.c
index 9e089f06a942..3c127a8cbaf2 100644
--- a/drivers/isdn/gigaset/i4l.c
+++ b/drivers/isdn/gigaset/i4l.c
@@ -46,7 +46,8 @@ static int writebuf_from_LL(int driverID, int channel, int ack,
46 return -ENODEV; 46 return -ENODEV;
47 } 47 }
48 if (channel < 0 || channel >= cs->channels) { 48 if (channel < 0 || channel >= cs->channels) {
49 err("%s: invalid channel ID (%d)", __func__, channel); 49 dev_err(cs->dev, "%s: invalid channel ID (%d)\n",
50 __func__, channel);
50 return -ENODEV; 51 return -ENODEV;
51 } 52 }
52 bcs = &cs->bcs[channel]; 53 bcs = &cs->bcs[channel];
@@ -58,11 +59,13 @@ static int writebuf_from_LL(int driverID, int channel, int ack,
58 59
59 if (!len) { 60 if (!len) {
60 if (ack) 61 if (ack)
61 notice("%s: not ACKing empty packet", __func__); 62 dev_notice(cs->dev, "%s: not ACKing empty packet\n",
63 __func__);
62 return 0; 64 return 0;
63 } 65 }
64 if (len > MAX_BUF_SIZE) { 66 if (len > MAX_BUF_SIZE) {
65 err("%s: packet too large (%d bytes)", __func__, len); 67 dev_err(cs->dev, "%s: packet too large (%d bytes)\n",
68 __func__, len);
66 return -EINVAL; 69 return -EINVAL;
67 } 70 }
68 71
@@ -116,8 +119,7 @@ static int command_from_LL(isdn_ctrl *cntrl)
116 gigaset_debugdrivers(); 119 gigaset_debugdrivers();
117 120
118 if (!cs) { 121 if (!cs) {
119 warn("LL tried to access unknown device with nr. %d", 122 err("%s: invalid driver ID (%d)", __func__, cntrl->driver);
120 cntrl->driver);
121 return -ENODEV; 123 return -ENODEV;
122 } 124 }
123 125
@@ -126,7 +128,7 @@ static int command_from_LL(isdn_ctrl *cntrl)
126 gig_dbg(DEBUG_ANY, "ISDN_CMD_IOCTL (driver: %d, arg: %ld)", 128 gig_dbg(DEBUG_ANY, "ISDN_CMD_IOCTL (driver: %d, arg: %ld)",
127 cntrl->driver, cntrl->arg); 129 cntrl->driver, cntrl->arg);
128 130
129 warn("ISDN_CMD_IOCTL is not supported."); 131 dev_warn(cs->dev, "ISDN_CMD_IOCTL not supported\n");
130 return -EINVAL; 132 return -EINVAL;
131 133
132 case ISDN_CMD_DIAL: 134 case ISDN_CMD_DIAL:
@@ -138,22 +140,23 @@ static int command_from_LL(isdn_ctrl *cntrl)
138 cntrl->parm.setup.si1, cntrl->parm.setup.si2); 140 cntrl->parm.setup.si1, cntrl->parm.setup.si2);
139 141
140 if (cntrl->arg >= cs->channels) { 142 if (cntrl->arg >= cs->channels) {
141 err("ISDN_CMD_DIAL: invalid channel (%d)", 143 dev_err(cs->dev,
142 (int) cntrl->arg); 144 "ISDN_CMD_DIAL: invalid channel (%d)\n",
145 (int) cntrl->arg);
143 return -EINVAL; 146 return -EINVAL;
144 } 147 }
145 148
146 bcs = cs->bcs + cntrl->arg; 149 bcs = cs->bcs + cntrl->arg;
147 150
148 if (!gigaset_get_channel(bcs)) { 151 if (!gigaset_get_channel(bcs)) {
149 err("ISDN_CMD_DIAL: channel not free"); 152 dev_err(cs->dev, "ISDN_CMD_DIAL: channel not free\n");
150 return -EBUSY; 153 return -EBUSY;
151 } 154 }
152 155
153 sp = kmalloc(sizeof *sp, GFP_ATOMIC); 156 sp = kmalloc(sizeof *sp, GFP_ATOMIC);
154 if (!sp) { 157 if (!sp) {
155 gigaset_free_channel(bcs); 158 gigaset_free_channel(bcs);
156 err("ISDN_CMD_DIAL: out of memory"); 159 dev_err(cs->dev, "ISDN_CMD_DIAL: out of memory\n");
157 return -ENOMEM; 160 return -ENOMEM;
158 } 161 }
159 *sp = cntrl->parm.setup; 162 *sp = cntrl->parm.setup;
@@ -173,8 +176,9 @@ static int command_from_LL(isdn_ctrl *cntrl)
173 gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTD"); 176 gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTD");
174 177
175 if (cntrl->arg >= cs->channels) { 178 if (cntrl->arg >= cs->channels) {
176 err("ISDN_CMD_ACCEPTD: invalid channel (%d)", 179 dev_err(cs->dev,
177 (int) cntrl->arg); 180 "ISDN_CMD_ACCEPTD: invalid channel (%d)\n",
181 (int) cntrl->arg);
178 return -EINVAL; 182 return -EINVAL;
179 } 183 }
180 184
@@ -196,8 +200,9 @@ static int command_from_LL(isdn_ctrl *cntrl)
196 (int) cntrl->arg); 200 (int) cntrl->arg);
197 201
198 if (cntrl->arg >= cs->channels) { 202 if (cntrl->arg >= cs->channels) {
199 err("ISDN_CMD_HANGUP: invalid channel (%u)", 203 dev_err(cs->dev,
200 (unsigned) cntrl->arg); 204 "ISDN_CMD_HANGUP: invalid channel (%d)\n",
205 (int) cntrl->arg);
201 return -EINVAL; 206 return -EINVAL;
202 } 207 }
203 208
@@ -224,8 +229,9 @@ static int command_from_LL(isdn_ctrl *cntrl)
224 cntrl->arg & 0xff, (cntrl->arg >> 8)); 229 cntrl->arg & 0xff, (cntrl->arg >> 8));
225 230
226 if ((cntrl->arg & 0xff) >= cs->channels) { 231 if ((cntrl->arg & 0xff) >= cs->channels) {
227 err("ISDN_CMD_SETL2: invalid channel (%u)", 232 dev_err(cs->dev,
228 (unsigned) cntrl->arg & 0xff); 233 "ISDN_CMD_SETL2: invalid channel (%d)\n",
234 (int) cntrl->arg & 0xff);
229 return -EINVAL; 235 return -EINVAL;
230 } 236 }
231 237
@@ -244,14 +250,16 @@ static int command_from_LL(isdn_ctrl *cntrl)
244 cntrl->arg & 0xff, (cntrl->arg >> 8)); 250 cntrl->arg & 0xff, (cntrl->arg >> 8));
245 251
246 if ((cntrl->arg & 0xff) >= cs->channels) { 252 if ((cntrl->arg & 0xff) >= cs->channels) {
247 err("ISDN_CMD_SETL3: invalid channel (%u)", 253 dev_err(cs->dev,
248 (unsigned) cntrl->arg & 0xff); 254 "ISDN_CMD_SETL3: invalid channel (%d)\n",
255 (int) cntrl->arg & 0xff);
249 return -EINVAL; 256 return -EINVAL;
250 } 257 }
251 258
252 if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) { 259 if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) {
253 err("ISDN_CMD_SETL3: invalid protocol %lu", 260 dev_err(cs->dev,
254 cntrl->arg >> 8); 261 "ISDN_CMD_SETL3: invalid protocol %lu\n",
262 cntrl->arg >> 8);
255 return -EINVAL; 263 return -EINVAL;
256 } 264 }
257 265
@@ -262,8 +270,9 @@ static int command_from_LL(isdn_ctrl *cntrl)
262 case ISDN_CMD_ALERT: 270 case ISDN_CMD_ALERT:
263 gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME 271 gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME
264 if (cntrl->arg >= cs->channels) { 272 if (cntrl->arg >= cs->channels) {
265 err("ISDN_CMD_ALERT: invalid channel (%d)", 273 dev_err(cs->dev,
266 (int) cntrl->arg); 274 "ISDN_CMD_ALERT: invalid channel (%d)\n",
275 (int) cntrl->arg);
267 return -EINVAL; 276 return -EINVAL;
268 } 277 }
269 //bcs = cs->bcs + cntrl->arg; 278 //bcs = cs->bcs + cntrl->arg;
@@ -295,7 +304,8 @@ static int command_from_LL(isdn_ctrl *cntrl)
295 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL"); 304 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL");
296 break; 305 break;
297 default: 306 default:
298 err("unknown command %d from LL", cntrl->command); 307 dev_err(cs->dev, "unknown command %d from LL\n",
308 cntrl->command);
299 return -EINVAL; 309 return -EINVAL;
300 } 310 }
301 311
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index af195b07c191..521951a898ec 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -197,7 +197,7 @@ static void if_close(struct tty_struct *tty, struct file *filp)
197 mutex_lock(&cs->mutex); 197 mutex_lock(&cs->mutex);
198 198
199 if (!cs->open_count) 199 if (!cs->open_count)
200 warn("%s: device not opened", __func__); 200 dev_warn(cs->dev, "%s: device not opened\n", __func__);
201 else { 201 else {
202 if (!--cs->open_count) { 202 if (!--cs->open_count) {
203 spin_lock_irqsave(&cs->lock, flags); 203 spin_lock_irqsave(&cs->lock, flags);
@@ -232,7 +232,7 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
232 return -ERESTARTSYS; // FIXME -EINTR? 232 return -ERESTARTSYS; // FIXME -EINTR?
233 233
234 if (!cs->open_count) 234 if (!cs->open_count)
235 warn("%s: device not opened", __func__); 235 dev_warn(cs->dev, "%s: device not opened\n", __func__);
236 else { 236 else {
237 retval = 0; 237 retval = 0;
238 switch (cmd) { 238 switch (cmd) {
@@ -364,9 +364,9 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
364 return -ERESTARTSYS; // FIXME -EINTR? 364 return -ERESTARTSYS; // FIXME -EINTR?
365 365
366 if (!cs->open_count) 366 if (!cs->open_count)
367 warn("%s: device not opened", __func__); 367 dev_warn(cs->dev, "%s: device not opened\n", __func__);
368 else if (cs->mstate != MS_LOCKED) { 368 else if (cs->mstate != MS_LOCKED) {
369 warn("can't write to unlocked device"); 369 dev_warn(cs->dev, "can't write to unlocked device\n");
370 retval = -EBUSY; 370 retval = -EBUSY;
371 } else if (!cs->connected) { 371 } else if (!cs->connected) {
372 gig_dbg(DEBUG_ANY, "can't write to unplugged device"); 372 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
@@ -398,9 +398,9 @@ static int if_write_room(struct tty_struct *tty)
398 return -ERESTARTSYS; // FIXME -EINTR? 398 return -ERESTARTSYS; // FIXME -EINTR?
399 399
400 if (!cs->open_count) 400 if (!cs->open_count)
401 warn("%s: device not opened", __func__); 401 dev_warn(cs->dev, "%s: device not opened\n", __func__);
402 else if (cs->mstate != MS_LOCKED) { 402 else if (cs->mstate != MS_LOCKED) {
403 warn("can't write to unlocked device"); 403 dev_warn(cs->dev, "can't write to unlocked device\n");
404 retval = -EBUSY; 404 retval = -EBUSY;
405 } else if (!cs->connected) { 405 } else if (!cs->connected) {
406 gig_dbg(DEBUG_ANY, "can't write to unplugged device"); 406 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
@@ -430,9 +430,9 @@ static int if_chars_in_buffer(struct tty_struct *tty)
430 return -ERESTARTSYS; // FIXME -EINTR? 430 return -ERESTARTSYS; // FIXME -EINTR?
431 431
432 if (!cs->open_count) 432 if (!cs->open_count)
433 warn("%s: device not opened", __func__); 433 dev_warn(cs->dev, "%s: device not opened\n", __func__);
434 else if (cs->mstate != MS_LOCKED) { 434 else if (cs->mstate != MS_LOCKED) {
435 warn("can't write to unlocked device"); 435 dev_warn(cs->dev, "can't write to unlocked device\n");
436 retval = -EBUSY; 436 retval = -EBUSY;
437 } else if (!cs->connected) { 437 } else if (!cs->connected) {
438 gig_dbg(DEBUG_ANY, "can't write to unplugged device"); 438 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
@@ -460,7 +460,7 @@ static void if_throttle(struct tty_struct *tty)
460 mutex_lock(&cs->mutex); 460 mutex_lock(&cs->mutex);
461 461
462 if (!cs->open_count) 462 if (!cs->open_count)
463 warn("%s: device not opened", __func__); 463 dev_warn(cs->dev, "%s: device not opened\n", __func__);
464 else { 464 else {
465 //FIXME 465 //FIXME
466 } 466 }
@@ -483,7 +483,7 @@ static void if_unthrottle(struct tty_struct *tty)
483 mutex_lock(&cs->mutex); 483 mutex_lock(&cs->mutex);
484 484
485 if (!cs->open_count) 485 if (!cs->open_count)
486 warn("%s: device not opened", __func__); 486 dev_warn(cs->dev, "%s: device not opened\n", __func__);
487 else { 487 else {
488 //FIXME 488 //FIXME
489 } 489 }
@@ -510,7 +510,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
510 mutex_lock(&cs->mutex); 510 mutex_lock(&cs->mutex);
511 511
512 if (!cs->open_count) { 512 if (!cs->open_count) {
513 warn("%s: device not opened", __func__); 513 dev_warn(cs->dev, "%s: device not opened\n", __func__);
514 goto out; 514 goto out;
515 } 515 }
516 516
@@ -623,7 +623,8 @@ void gigaset_if_init(struct cardstate *cs)
623 if (!IS_ERR(cs->tty_dev)) 623 if (!IS_ERR(cs->tty_dev))
624 dev_set_drvdata(cs->tty_dev, cs); 624 dev_set_drvdata(cs->tty_dev, cs);
625 else { 625 else {
626 warn("could not register device to the tty subsystem"); 626 dev_warn(cs->dev,
627 "could not register device to the tty subsystem\n");
627 cs->tty_dev = NULL; 628 cs->tty_dev = NULL;
628 } 629 }
629 mutex_unlock(&cs->mutex); 630 mutex_unlock(&cs->mutex);
diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
index 77d20ab0cd4d..4661830a49db 100644
--- a/drivers/isdn/gigaset/usb-gigaset.c
+++ b/drivers/isdn/gigaset/usb-gigaset.c
@@ -498,8 +498,9 @@ static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
498 498
499 if (status) { 499 if (status) {
500 ucs->busy = 0; 500 ucs->busy = 0;
501 err("could not submit urb (error %d)\n", 501 dev_err(cs->dev,
502 -status); 502 "could not submit urb (error %d)\n",
503 -status);
503 cb->len = 0; /* skip urb => remove cb+wakeup 504 cb->len = 0; /* skip urb => remove cb+wakeup
504 in next loop cycle */ 505 in next loop cycle */
505 } 506 }
@@ -670,7 +671,7 @@ static int write_modem(struct cardstate *cs)
670 spin_unlock_irqrestore(&cs->lock, flags); 671 spin_unlock_irqrestore(&cs->lock, flags);
671 672
672 if (ret) { 673 if (ret) {
673 err("could not submit urb (error %d)\n", -ret); 674 dev_err(cs->dev, "could not submit urb (error %d)\n", -ret);
674 ucs->busy = 0; 675 ucs->busy = 0;
675 } 676 }
676 677
diff --git a/drivers/isdn/hardware/Makefile b/drivers/isdn/hardware/Makefile
index 11c8a183948c..a5d8fce4c4c4 100644
--- a/drivers/isdn/hardware/Makefile
+++ b/drivers/isdn/hardware/Makefile
@@ -4,3 +4,4 @@
4 4
5obj-$(CONFIG_CAPI_AVM) += avm/ 5obj-$(CONFIG_CAPI_AVM) += avm/
6obj-$(CONFIG_CAPI_EICON) += eicon/ 6obj-$(CONFIG_CAPI_EICON) += eicon/
7obj-$(CONFIG_MISDN) += mISDN/
diff --git a/drivers/isdn/hardware/mISDN/Kconfig b/drivers/isdn/hardware/mISDN/Kconfig
new file mode 100644
index 000000000000..14793480c453
--- /dev/null
+++ b/drivers/isdn/hardware/mISDN/Kconfig
@@ -0,0 +1,25 @@
1#
2# Hardware for mISDN
3#
4comment "mISDN hardware drivers"
5
6config MISDN_HFCPCI
7 tristate "Support for HFC PCI cards"
8 depends on MISDN
9 depends on PCI
10 help
11 Enable support for cards with Cologne Chip AG's
12 HFC PCI chip.
13
14config MISDN_HFCMULTI
15 tristate "Support for HFC multiport cards (HFC-4S/8S/E1)"
16 depends on PCI
17 depends on MISDN
18 help
19 Enable support for cards with Cologne Chip AG's HFC multiport
20 chip. There are three types of chips that are quite similar,
21 but the interface is different:
22 * HFC-4S (4 S/T interfaces on one chip)
23 * HFC-8S (8 S/T interfaces on one chip)
24 * HFC-E1 (E1 interface for 2Mbit ISDN)
25
diff --git a/drivers/isdn/hardware/mISDN/Makefile b/drivers/isdn/hardware/mISDN/Makefile
new file mode 100644
index 000000000000..1e7ca5332ad7
--- /dev/null
+++ b/drivers/isdn/hardware/mISDN/Makefile
@@ -0,0 +1,7 @@
1#
2# Makefile for the modular ISDN hardware drivers
3#
4#
5
6obj-$(CONFIG_MISDN_HFCPCI) += hfcpci.o
7obj-$(CONFIG_MISDN_HFCMULTI) += hfcmulti.o
diff --git a/drivers/isdn/hardware/mISDN/hfc_multi.h b/drivers/isdn/hardware/mISDN/hfc_multi.h
new file mode 100644
index 000000000000..a33d87afc843
--- /dev/null
+++ b/drivers/isdn/hardware/mISDN/hfc_multi.h
@@ -0,0 +1,1204 @@
1/*
2 * see notice in hfc_multi.c
3 */
4
5extern void ztdummy_extern_interrupt(void);
6extern void ztdummy_register_interrupt(void);
7extern int ztdummy_unregister_interrupt(void);
8
9#define DEBUG_HFCMULTI_FIFO 0x00010000
10#define DEBUG_HFCMULTI_CRC 0x00020000
11#define DEBUG_HFCMULTI_INIT 0x00040000
12#define DEBUG_HFCMULTI_PLXSD 0x00080000
13#define DEBUG_HFCMULTI_MODE 0x00100000
14#define DEBUG_HFCMULTI_MSG 0x00200000
15#define DEBUG_HFCMULTI_STATE 0x00400000
16#define DEBUG_HFCMULTI_SYNC 0x01000000
17#define DEBUG_HFCMULTI_DTMF 0x02000000
18#define DEBUG_HFCMULTI_LOCK 0x80000000
19
20#define PCI_ENA_REGIO 0x01
21#define PCI_ENA_MEMIO 0x02
22
23/*
24 * NOTE: some registers are assigned multiple times due to different modes
25 * also registers are assigned differen for HFC-4s/8s and HFC-E1
26 */
27
28/*
29#define MAX_FRAME_SIZE 2048
30*/
31
32struct hfc_chan {
33 struct dchannel *dch; /* link if channel is a D-channel */
34 struct bchannel *bch; /* link if channel is a B-channel */
35 int port; /* the interface port this */
36 /* channel is associated with */
37 int nt_timer; /* -1 if off, 0 if elapsed, >0 if running */
38 int los, ais, slip_tx, slip_rx, rdi; /* current alarms */
39 int jitter;
40 u_long cfg; /* port configuration */
41 int sync; /* sync state (used by E1) */
42 u_int protocol; /* current protocol */
43 int slot_tx; /* current pcm slot */
44 int bank_tx; /* current pcm bank */
45 int slot_rx;
46 int bank_rx;
47 int conf; /* conference setting of TX slot */
48 int txpending; /* if there is currently data in */
49 /* the FIFO 0=no, 1=yes, 2=splloop */
50 int rx_off; /* set to turn fifo receive off */
51 int coeff_count; /* curren coeff block */
52 s32 *coeff; /* memory pointer to 8 coeff blocks */
53};
54
55
56struct hfcm_hw {
57 u_char r_ctrl;
58 u_char r_irq_ctrl;
59 u_char r_cirm;
60 u_char r_ram_sz;
61 u_char r_pcm_md0;
62 u_char r_irqmsk_misc;
63 u_char r_dtmf;
64 u_char r_st_sync;
65 u_char r_sci_msk;
66 u_char r_tx0, r_tx1;
67 u_char a_st_ctrl0[8];
68 timer_t timer;
69};
70
71
72/* for each stack these flags are used (cfg) */
73#define HFC_CFG_NONCAP_TX 1 /* S/T TX interface has less capacity */
74#define HFC_CFG_DIS_ECHANNEL 2 /* disable E-channel processing */
75#define HFC_CFG_REG_ECHANNEL 3 /* register E-channel */
76#define HFC_CFG_OPTICAL 4 /* the E1 interface is optical */
77#define HFC_CFG_REPORT_LOS 5 /* the card should report loss of signal */
78#define HFC_CFG_REPORT_AIS 6 /* the card should report alarm ind. sign. */
79#define HFC_CFG_REPORT_SLIP 7 /* the card should report bit slips */
80#define HFC_CFG_REPORT_RDI 8 /* the card should report remote alarm */
81#define HFC_CFG_DTMF 9 /* enable DTMF-detection */
82#define HFC_CFG_CRC4 10 /* disable CRC-4 Multiframe mode, */
83 /* use double frame instead. */
84
85#define HFC_CHIP_EXRAM_128 0 /* external ram 128k */
86#define HFC_CHIP_EXRAM_512 1 /* external ram 256k */
87#define HFC_CHIP_REVISION0 2 /* old fifo handling */
88#define HFC_CHIP_PCM_SLAVE 3 /* PCM is slave */
89#define HFC_CHIP_PCM_MASTER 4 /* PCM is master */
90#define HFC_CHIP_RX_SYNC 5 /* disable pll sync for pcm */
91#define HFC_CHIP_DTMF 6 /* DTMF decoding is enabled */
92#define HFC_CHIP_ULAW 7 /* ULAW mode */
93#define HFC_CHIP_CLOCK2 8 /* double clock mode */
94#define HFC_CHIP_E1CLOCK_GET 9 /* always get clock from E1 interface */
95#define HFC_CHIP_E1CLOCK_PUT 10 /* always put clock from E1 interface */
96#define HFC_CHIP_WATCHDOG 11 /* whether we should send signals */
97 /* to the watchdog */
98#define HFC_CHIP_B410P 12 /* whether we have a b410p with echocan in */
99 /* hw */
100#define HFC_CHIP_PLXSD 13 /* whether we have a Speech-Design PLX */
101
102#define HFC_IO_MODE_PCIMEM 0x00 /* normal memory mapped IO */
103#define HFC_IO_MODE_REGIO 0x01 /* PCI io access */
104#define HFC_IO_MODE_PLXSD 0x02 /* access HFC via PLX9030 */
105
106/* table entry in the PCI devices list */
107struct hm_map {
108 char *vendor_name;
109 char *card_name;
110 int type;
111 int ports;
112 int clock2;
113 int leds;
114 int opticalsupport;
115 int dip_type;
116 int io_mode;
117};
118
119struct hfc_multi {
120 struct list_head list;
121 struct hm_map *mtyp;
122 int id;
123 int pcm; /* id of pcm bus */
124 int type;
125 int ports;
126
127 u_int irq; /* irq used by card */
128 u_int irqcnt;
129 struct pci_dev *pci_dev;
130 int io_mode; /* selects mode */
131#ifdef HFC_REGISTER_DEBUG
132 void (*HFC_outb)(struct hfc_multi *hc, u_char reg,
133 u_char val, const char *function, int line);
134 void (*HFC_outb_nodebug)(struct hfc_multi *hc, u_char reg,
135 u_char val, const char *function, int line);
136 u_char (*HFC_inb)(struct hfc_multi *hc, u_char reg,
137 const char *function, int line);
138 u_char (*HFC_inb_nodebug)(struct hfc_multi *hc, u_char reg,
139 const char *function, int line);
140 u_short (*HFC_inw)(struct hfc_multi *hc, u_char reg,
141 const char *function, int line);
142 u_short (*HFC_inw_nodebug)(struct hfc_multi *hc, u_char reg,
143 const char *function, int line);
144 void (*HFC_wait)(struct hfc_multi *hc,
145 const char *function, int line);
146 void (*HFC_wait_nodebug)(struct hfc_multi *hc,
147 const char *function, int line);
148#else
149 void (*HFC_outb)(struct hfc_multi *hc, u_char reg,
150 u_char val);
151 void (*HFC_outb_nodebug)(struct hfc_multi *hc, u_char reg,
152 u_char val);
153 u_char (*HFC_inb)(struct hfc_multi *hc, u_char reg);
154 u_char (*HFC_inb_nodebug)(struct hfc_multi *hc, u_char reg);
155 u_short (*HFC_inw)(struct hfc_multi *hc, u_char reg);
156 u_short (*HFC_inw_nodebug)(struct hfc_multi *hc, u_char reg);
157 void (*HFC_wait)(struct hfc_multi *hc);
158 void (*HFC_wait_nodebug)(struct hfc_multi *hc);
159#endif
160 void (*read_fifo)(struct hfc_multi *hc, u_char *data,
161 int len);
162 void (*write_fifo)(struct hfc_multi *hc, u_char *data,
163 int len);
164 u_long pci_origmembase, plx_origmembase, dsp_origmembase;
165 u_char *pci_membase; /* PCI memory (MUST BE BYTE POINTER) */
166 u_char *plx_membase; /* PLX memory */
167 u_char *dsp_membase; /* DSP on PLX */
168 u_long pci_iobase; /* PCI IO */
169 struct hfcm_hw hw; /* remember data of write-only-registers */
170
171 u_long chip; /* chip configuration */
172 int masterclk; /* port that provides master clock -1=off */
173 int dtmf; /* flag that dtmf is currently in process */
174 int Flen; /* F-buffer size */
175 int Zlen; /* Z-buffer size (must be int for calculation)*/
176 int max_trans; /* maximum transparent fifo fill */
177 int Zmin; /* Z-buffer offset */
178 int DTMFbase; /* base address of DTMF coefficients */
179
180 u_int slots; /* number of PCM slots */
181 u_int leds; /* type of leds */
182 u_int ledcount; /* used to animate leds */
183 u_long ledstate; /* save last state of leds */
184 int opticalsupport; /* has the e1 board */
185 /* an optical Interface */
186 int dslot; /* channel # of d-channel (E1) default 16 */
187
188 u_long wdcount; /* every 500 ms we need to */
189 /* send the watchdog a signal */
190 u_char wdbyte; /* watchdog toggle byte */
191 u_int activity[8]; /* if there is any action on this */
192 /* port (will be cleared after */
193 /* showing led-states) */
194 int e1_state; /* keep track of last state */
195 int e1_getclock; /* if sync is retrieved from interface */
196 int syncronized; /* keep track of existing sync interface */
197 int e1_resync; /* resync jobs */
198
199 spinlock_t lock; /* the lock */
200
201 /*
202 * the channel index is counted from 0, regardless where the channel
203 * is located on the hfc-channel.
204 * the bch->channel is equvalent to the hfc-channel
205 */
206 struct hfc_chan chan[32];
207 u_char created[8]; /* what port is created */
208 signed char slot_owner[256]; /* owner channel of slot */
209};
210
211/* PLX GPIOs */
212#define PLX_GPIO4_DIR_BIT 13
213#define PLX_GPIO4_BIT 14
214#define PLX_GPIO5_DIR_BIT 16
215#define PLX_GPIO5_BIT 17
216#define PLX_GPIO6_DIR_BIT 19
217#define PLX_GPIO6_BIT 20
218#define PLX_GPIO7_DIR_BIT 22
219#define PLX_GPIO7_BIT 23
220#define PLX_GPIO8_DIR_BIT 25
221#define PLX_GPIO8_BIT 26
222
223#define PLX_GPIO4 (1 << PLX_GPIO4_BIT)
224#define PLX_GPIO5 (1 << PLX_GPIO5_BIT)
225#define PLX_GPIO6 (1 << PLX_GPIO6_BIT)
226#define PLX_GPIO7 (1 << PLX_GPIO7_BIT)
227#define PLX_GPIO8 (1 << PLX_GPIO8_BIT)
228
229#define PLX_GPIO4_DIR (1 << PLX_GPIO4_DIR_BIT)
230#define PLX_GPIO5_DIR (1 << PLX_GPIO5_DIR_BIT)
231#define PLX_GPIO6_DIR (1 << PLX_GPIO6_DIR_BIT)
232#define PLX_GPIO7_DIR (1 << PLX_GPIO7_DIR_BIT)
233#define PLX_GPIO8_DIR (1 << PLX_GPIO8_DIR_BIT)
234
235#define PLX_TERM_ON PLX_GPIO7
236#define PLX_SLAVE_EN_N PLX_GPIO5
237#define PLX_MASTER_EN PLX_GPIO6
238#define PLX_SYNC_O_EN PLX_GPIO4
239#define PLX_DSP_RES_N PLX_GPIO8
240/* GPIO4..8 Enable & Set to OUT, SLAVE_EN_N = 1 */
241#define PLX_GPIOC_INIT (PLX_GPIO4_DIR | PLX_GPIO5_DIR | PLX_GPIO6_DIR \
242 | PLX_GPIO7_DIR | PLX_GPIO8_DIR | PLX_SLAVE_EN_N)
243
244/* PLX Interrupt Control/STATUS */
245#define PLX_INTCSR_LINTI1_ENABLE 0x01
246#define PLX_INTCSR_LINTI1_STATUS 0x04
247#define PLX_INTCSR_LINTI2_ENABLE 0x08
248#define PLX_INTCSR_LINTI2_STATUS 0x20
249#define PLX_INTCSR_PCIINT_ENABLE 0x40
250
251/* PLX Registers */
252#define PLX_INTCSR 0x4c
253#define PLX_CNTRL 0x50
254#define PLX_GPIOC 0x54
255
256
257/*
258 * REGISTER SETTING FOR HFC-4S/8S AND HFC-E1
259 */
260
261/* write only registers */
262#define R_CIRM 0x00
263#define R_CTRL 0x01
264#define R_BRG_PCM_CFG 0x02
265#define R_RAM_ADDR0 0x08
266#define R_RAM_ADDR1 0x09
267#define R_RAM_ADDR2 0x0A
268#define R_FIRST_FIFO 0x0B
269#define R_RAM_SZ 0x0C
270#define R_FIFO_MD 0x0D
271#define R_INC_RES_FIFO 0x0E
272#define R_FSM_IDX 0x0F
273#define R_FIFO 0x0F
274#define R_SLOT 0x10
275#define R_IRQMSK_MISC 0x11
276#define R_SCI_MSK 0x12
277#define R_IRQ_CTRL 0x13
278#define R_PCM_MD0 0x14
279#define R_PCM_MD1 0x15
280#define R_PCM_MD2 0x15
281#define R_SH0H 0x15
282#define R_SH1H 0x15
283#define R_SH0L 0x15
284#define R_SH1L 0x15
285#define R_SL_SEL0 0x15
286#define R_SL_SEL1 0x15
287#define R_SL_SEL2 0x15
288#define R_SL_SEL3 0x15
289#define R_SL_SEL4 0x15
290#define R_SL_SEL5 0x15
291#define R_SL_SEL6 0x15
292#define R_SL_SEL7 0x15
293#define R_ST_SEL 0x16
294#define R_ST_SYNC 0x17
295#define R_CONF_EN 0x18
296#define R_TI_WD 0x1A
297#define R_BERT_WD_MD 0x1B
298#define R_DTMF 0x1C
299#define R_DTMF_N 0x1D
300#define R_E1_WR_STA 0x20
301#define R_E1_RD_STA 0x20
302#define R_LOS0 0x22
303#define R_LOS1 0x23
304#define R_RX0 0x24
305#define R_RX_FR0 0x25
306#define R_RX_FR1 0x26
307#define R_TX0 0x28
308#define R_TX1 0x29
309#define R_TX_FR0 0x2C
310
311#define R_TX_FR1 0x2D
312#define R_TX_FR2 0x2E
313#define R_JATT_ATT 0x2F /* undocumented */
314#define A_ST_RD_STATE 0x30
315#define A_ST_WR_STATE 0x30
316#define R_RX_OFF 0x30
317#define A_ST_CTRL0 0x31
318#define R_SYNC_OUT 0x31
319#define A_ST_CTRL1 0x32
320#define A_ST_CTRL2 0x33
321#define A_ST_SQ_WR 0x34
322#define R_TX_OFF 0x34
323#define R_SYNC_CTRL 0x35
324#define A_ST_CLK_DLY 0x37
325#define R_PWM0 0x38
326#define R_PWM1 0x39
327#define A_ST_B1_TX 0x3C
328#define A_ST_B2_TX 0x3D
329#define A_ST_D_TX 0x3E
330#define R_GPIO_OUT0 0x40
331#define R_GPIO_OUT1 0x41
332#define R_GPIO_EN0 0x42
333#define R_GPIO_EN1 0x43
334#define R_GPIO_SEL 0x44
335#define R_BRG_CTRL 0x45
336#define R_PWM_MD 0x46
337#define R_BRG_MD 0x47
338#define R_BRG_TIM0 0x48
339#define R_BRG_TIM1 0x49
340#define R_BRG_TIM2 0x4A
341#define R_BRG_TIM3 0x4B
342#define R_BRG_TIM_SEL01 0x4C
343#define R_BRG_TIM_SEL23 0x4D
344#define R_BRG_TIM_SEL45 0x4E
345#define R_BRG_TIM_SEL67 0x4F
346#define A_SL_CFG 0xD0
347#define A_CONF 0xD1
348#define A_CH_MSK 0xF4
349#define A_CON_HDLC 0xFA
350#define A_SUBCH_CFG 0xFB
351#define A_CHANNEL 0xFC
352#define A_FIFO_SEQ 0xFD
353#define A_IRQ_MSK 0xFF
354
355/* read only registers */
356#define A_Z12 0x04
357#define A_Z1L 0x04
358#define A_Z1 0x04
359#define A_Z1H 0x05
360#define A_Z2L 0x06
361#define A_Z2 0x06
362#define A_Z2H 0x07
363#define A_F1 0x0C
364#define A_F12 0x0C
365#define A_F2 0x0D
366#define R_IRQ_OVIEW 0x10
367#define R_IRQ_MISC 0x11
368#define R_IRQ_STATECH 0x12
369#define R_CONF_OFLOW 0x14
370#define R_RAM_USE 0x15
371#define R_CHIP_ID 0x16
372#define R_BERT_STA 0x17
373#define R_F0_CNTL 0x18
374#define R_F0_CNTH 0x19
375#define R_BERT_EC 0x1A
376#define R_BERT_ECL 0x1A
377#define R_BERT_ECH 0x1B
378#define R_STATUS 0x1C
379#define R_CHIP_RV 0x1F
380#define R_STATE 0x20
381#define R_SYNC_STA 0x24
382#define R_RX_SL0_0 0x25
383#define R_RX_SL0_1 0x26
384#define R_RX_SL0_2 0x27
385#define R_JATT_DIR 0x2b /* undocumented */
386#define R_SLIP 0x2c
387#define A_ST_RD_STA 0x30
388#define R_FAS_EC 0x30
389#define R_FAS_ECL 0x30
390#define R_FAS_ECH 0x31
391#define R_VIO_EC 0x32
392#define R_VIO_ECL 0x32
393#define R_VIO_ECH 0x33
394#define A_ST_SQ_RD 0x34
395#define R_CRC_EC 0x34
396#define R_CRC_ECL 0x34
397#define R_CRC_ECH 0x35
398#define R_E_EC 0x36
399#define R_E_ECL 0x36
400#define R_E_ECH 0x37
401#define R_SA6_SA13_EC 0x38
402#define R_SA6_SA13_ECL 0x38
403#define R_SA6_SA13_ECH 0x39
404#define R_SA6_SA23_EC 0x3A
405#define R_SA6_SA23_ECL 0x3A
406#define R_SA6_SA23_ECH 0x3B
407#define A_ST_B1_RX 0x3C
408#define A_ST_B2_RX 0x3D
409#define A_ST_D_RX 0x3E
410#define A_ST_E_RX 0x3F
411#define R_GPIO_IN0 0x40
412#define R_GPIO_IN1 0x41
413#define R_GPI_IN0 0x44
414#define R_GPI_IN1 0x45
415#define R_GPI_IN2 0x46
416#define R_GPI_IN3 0x47
417#define R_INT_DATA 0x88
418#define R_IRQ_FIFO_BL0 0xC8
419#define R_IRQ_FIFO_BL1 0xC9
420#define R_IRQ_FIFO_BL2 0xCA
421#define R_IRQ_FIFO_BL3 0xCB
422#define R_IRQ_FIFO_BL4 0xCC
423#define R_IRQ_FIFO_BL5 0xCD
424#define R_IRQ_FIFO_BL6 0xCE
425#define R_IRQ_FIFO_BL7 0xCF
426
427/* read and write registers */
428#define A_FIFO_DATA0 0x80
429#define A_FIFO_DATA1 0x80
430#define A_FIFO_DATA2 0x80
431#define A_FIFO_DATA0_NOINC 0x84
432#define A_FIFO_DATA1_NOINC 0x84
433#define A_FIFO_DATA2_NOINC 0x84
434#define R_RAM_DATA 0xC0
435
436
437/*
438 * BIT SETTING FOR HFC-4S/8S AND HFC-E1
439 */
440
441/* chapter 2: universal bus interface */
442/* R_CIRM */
443#define V_IRQ_SEL 0x01
444#define V_SRES 0x08
445#define V_HFCRES 0x10
446#define V_PCMRES 0x20
447#define V_STRES 0x40
448#define V_ETRES 0x40
449#define V_RLD_EPR 0x80
450/* R_CTRL */
451#define V_FIFO_LPRIO 0x02
452#define V_SLOW_RD 0x04
453#define V_EXT_RAM 0x08
454#define V_CLK_OFF 0x20
455#define V_ST_CLK 0x40
456/* R_RAM_ADDR0 */
457#define V_RAM_ADDR2 0x01
458#define V_ADDR_RES 0x40
459#define V_ADDR_INC 0x80
460/* R_RAM_SZ */
461#define V_RAM_SZ 0x01
462#define V_PWM0_16KHZ 0x10
463#define V_PWM1_16KHZ 0x20
464#define V_FZ_MD 0x80
465/* R_CHIP_ID */
466#define V_PNP_IRQ 0x01
467#define V_CHIP_ID 0x10
468
469/* chapter 3: data flow */
470/* R_FIRST_FIFO */
471#define V_FIRST_FIRO_DIR 0x01
472#define V_FIRST_FIFO_NUM 0x02
473/* R_FIFO_MD */
474#define V_FIFO_MD 0x01
475#define V_CSM_MD 0x04
476#define V_FSM_MD 0x08
477#define V_FIFO_SZ 0x10
478/* R_FIFO */
479#define V_FIFO_DIR 0x01
480#define V_FIFO_NUM 0x02
481#define V_REV 0x80
482/* R_SLOT */
483#define V_SL_DIR 0x01
484#define V_SL_NUM 0x02
485/* A_SL_CFG */
486#define V_CH_DIR 0x01
487#define V_CH_SEL 0x02
488#define V_ROUTING 0x40
489/* A_CON_HDLC */
490#define V_IFF 0x01
491#define V_HDLC_TRP 0x02
492#define V_TRP_IRQ 0x04
493#define V_DATA_FLOW 0x20
494/* A_SUBCH_CFG */
495#define V_BIT_CNT 0x01
496#define V_START_BIT 0x08
497#define V_LOOP_FIFO 0x40
498#define V_INV_DATA 0x80
499/* A_CHANNEL */
500#define V_CH_DIR0 0x01
501#define V_CH_NUM0 0x02
502/* A_FIFO_SEQ */
503#define V_NEXT_FIFO_DIR 0x01
504#define V_NEXT_FIFO_NUM 0x02
505#define V_SEQ_END 0x40
506
507/* chapter 4: FIFO handling and HDLC controller */
508/* R_INC_RES_FIFO */
509#define V_INC_F 0x01
510#define V_RES_F 0x02
511#define V_RES_LOST 0x04
512
513/* chapter 5: S/T interface */
514/* R_SCI_MSK */
515#define V_SCI_MSK_ST0 0x01
516#define V_SCI_MSK_ST1 0x02
517#define V_SCI_MSK_ST2 0x04
518#define V_SCI_MSK_ST3 0x08
519#define V_SCI_MSK_ST4 0x10
520#define V_SCI_MSK_ST5 0x20
521#define V_SCI_MSK_ST6 0x40
522#define V_SCI_MSK_ST7 0x80
523/* R_ST_SEL */
524#define V_ST_SEL 0x01
525#define V_MULT_ST 0x08
526/* R_ST_SYNC */
527#define V_SYNC_SEL 0x01
528#define V_AUTO_SYNC 0x08
529/* A_ST_WR_STA */
530#define V_ST_SET_STA 0x01
531#define V_ST_LD_STA 0x10
532#define V_ST_ACT 0x20
533#define V_SET_G2_G3 0x80
534/* A_ST_CTRL0 */
535#define V_B1_EN 0x01
536#define V_B2_EN 0x02
537#define V_ST_MD 0x04
538#define V_D_PRIO 0x08
539#define V_SQ_EN 0x10
540#define V_96KHZ 0x20
541#define V_TX_LI 0x40
542#define V_ST_STOP 0x80
543/* A_ST_CTRL1 */
544#define V_G2_G3_EN 0x01
545#define V_D_HI 0x04
546#define V_E_IGNO 0x08
547#define V_E_LO 0x10
548#define V_B12_SWAP 0x80
549/* A_ST_CTRL2 */
550#define V_B1_RX_EN 0x01
551#define V_B2_RX_EN 0x02
552#define V_ST_TRIS 0x40
553/* A_ST_CLK_DLY */
554#define V_ST_CK_DLY 0x01
555#define V_ST_SMPL 0x10
556/* A_ST_D_TX */
557#define V_ST_D_TX 0x40
558/* R_IRQ_STATECH */
559#define V_SCI_ST0 0x01
560#define V_SCI_ST1 0x02
561#define V_SCI_ST2 0x04
562#define V_SCI_ST3 0x08
563#define V_SCI_ST4 0x10
564#define V_SCI_ST5 0x20
565#define V_SCI_ST6 0x40
566#define V_SCI_ST7 0x80
567/* A_ST_RD_STA */
568#define V_ST_STA 0x01
569#define V_FR_SYNC_ST 0x10
570#define V_TI2_EXP 0x20
571#define V_INFO0 0x40
572#define V_G2_G3 0x80
573/* A_ST_SQ_RD */
574#define V_ST_SQ 0x01
575#define V_MF_RX_RDY 0x10
576#define V_MF_TX_RDY 0x80
577/* A_ST_D_RX */
578#define V_ST_D_RX 0x40
579/* A_ST_E_RX */
580#define V_ST_E_RX 0x40
581
582/* chapter 5: E1 interface */
583/* R_E1_WR_STA */
584/* R_E1_RD_STA */
585#define V_E1_SET_STA 0x01
586#define V_E1_LD_STA 0x10
587/* R_RX0 */
588#define V_RX_CODE 0x01
589#define V_RX_FBAUD 0x04
590#define V_RX_CMI 0x08
591#define V_RX_INV_CMI 0x10
592#define V_RX_INV_CLK 0x20
593#define V_RX_INV_DATA 0x40
594#define V_AIS_ITU 0x80
595/* R_RX_FR0 */
596#define V_NO_INSYNC 0x01
597#define V_AUTO_RESYNC 0x02
598#define V_AUTO_RECO 0x04
599#define V_SWORD_COND 0x08
600#define V_SYNC_LOSS 0x10
601#define V_XCRC_SYNC 0x20
602#define V_MF_RESYNC 0x40
603#define V_RESYNC 0x80
604/* R_RX_FR1 */
605#define V_RX_MF 0x01
606#define V_RX_MF_SYNC 0x02
607#define V_RX_SL0_RAM 0x04
608#define V_ERR_SIM 0x20
609#define V_RES_NMF 0x40
610/* R_TX0 */
611#define V_TX_CODE 0x01
612#define V_TX_FBAUD 0x04
613#define V_TX_CMI_CODE 0x08
614#define V_TX_INV_CMI_CODE 0x10
615#define V_TX_INV_CLK 0x20
616#define V_TX_INV_DATA 0x40
617#define V_OUT_EN 0x80
618/* R_TX1 */
619#define V_INV_CLK 0x01
620#define V_EXCHG_DATA_LI 0x02
621#define V_AIS_OUT 0x04
622#define V_ATX 0x20
623#define V_NTRI 0x40
624#define V_AUTO_ERR_RES 0x80
625/* R_TX_FR0 */
626#define V_TRP_FAS 0x01
627#define V_TRP_NFAS 0x02
628#define V_TRP_RAL 0x04
629#define V_TRP_SA 0x08
630/* R_TX_FR1 */
631#define V_TX_FAS 0x01
632#define V_TX_NFAS 0x02
633#define V_TX_RAL 0x04
634#define V_TX_SA 0x08
635/* R_TX_FR2 */
636#define V_TX_MF 0x01
637#define V_TRP_SL0 0x02
638#define V_TX_SL0_RAM 0x04
639#define V_TX_E 0x10
640#define V_NEG_E 0x20
641#define V_XS12_ON 0x40
642#define V_XS15_ON 0x80
643/* R_RX_OFF */
644#define V_RX_SZ 0x01
645#define V_RX_INIT 0x04
646/* R_SYNC_OUT */
647#define V_SYNC_E1_RX 0x01
648#define V_IPATS0 0x20
649#define V_IPATS1 0x40
650#define V_IPATS2 0x80
651/* R_TX_OFF */
652#define V_TX_SZ 0x01
653#define V_TX_INIT 0x04
654/* R_SYNC_CTRL */
655#define V_EXT_CLK_SYNC 0x01
656#define V_SYNC_OFFS 0x02
657#define V_PCM_SYNC 0x04
658#define V_NEG_CLK 0x08
659#define V_HCLK 0x10
660/*
661#define V_JATT_AUTO_DEL 0x20
662#define V_JATT_AUTO 0x40
663*/
664#define V_JATT_OFF 0x80
665/* R_STATE */
666#define V_E1_STA 0x01
667#define V_ALT_FR_RX 0x40
668#define V_ALT_FR_TX 0x80
669/* R_SYNC_STA */
670#define V_RX_STA 0x01
671#define V_FR_SYNC_E1 0x04
672#define V_SIG_LOS 0x08
673#define V_MFA_STA 0x10
674#define V_AIS 0x40
675#define V_NO_MF_SYNC 0x80
676/* R_RX_SL0_0 */
677#define V_SI_FAS 0x01
678#define V_SI_NFAS 0x02
679#define V_A 0x04
680#define V_CRC_OK 0x08
681#define V_TX_E1 0x10
682#define V_TX_E2 0x20
683#define V_RX_E1 0x40
684#define V_RX_E2 0x80
685/* R_SLIP */
686#define V_SLIP_RX 0x01
687#define V_FOSLIP_RX 0x08
688#define V_SLIP_TX 0x10
689#define V_FOSLIP_TX 0x80
690
691/* chapter 6: PCM interface */
692/* R_PCM_MD0 */
693#define V_PCM_MD 0x01
694#define V_C4_POL 0x02
695#define V_F0_NEG 0x04
696#define V_F0_LEN 0x08
697#define V_PCM_ADDR 0x10
698/* R_SL_SEL0 */
699#define V_SL_SEL0 0x01
700#define V_SH_SEL0 0x80
701/* R_SL_SEL1 */
702#define V_SL_SEL1 0x01
703#define V_SH_SEL1 0x80
704/* R_SL_SEL2 */
705#define V_SL_SEL2 0x01
706#define V_SH_SEL2 0x80
707/* R_SL_SEL3 */
708#define V_SL_SEL3 0x01
709#define V_SH_SEL3 0x80
710/* R_SL_SEL4 */
711#define V_SL_SEL4 0x01
712#define V_SH_SEL4 0x80
713/* R_SL_SEL5 */
714#define V_SL_SEL5 0x01
715#define V_SH_SEL5 0x80
716/* R_SL_SEL6 */
717#define V_SL_SEL6 0x01
718#define V_SH_SEL6 0x80
719/* R_SL_SEL7 */
720#define V_SL_SEL7 0x01
721#define V_SH_SEL7 0x80
722/* R_PCM_MD1 */
723#define V_ODEC_CON 0x01
724#define V_PLL_ADJ 0x04
725#define V_PCM_DR 0x10
726#define V_PCM_LOOP 0x40
727/* R_PCM_MD2 */
728#define V_SYNC_PLL 0x02
729#define V_SYNC_SRC 0x04
730#define V_SYNC_OUT 0x08
731#define V_ICR_FR_TIME 0x40
732#define V_EN_PLL 0x80
733
734/* chapter 7: pulse width modulation */
735/* R_PWM_MD */
736#define V_EXT_IRQ_EN 0x08
737#define V_PWM0_MD 0x10
738#define V_PWM1_MD 0x40
739
740/* chapter 8: multiparty audio conferences */
741/* R_CONF_EN */
742#define V_CONF_EN 0x01
743#define V_ULAW 0x80
744/* A_CONF */
745#define V_CONF_NUM 0x01
746#define V_NOISE_SUPPR 0x08
747#define V_ATT_LEV 0x20
748#define V_CONF_SL 0x80
749/* R_CONF_OFLOW */
750#define V_CONF_OFLOW0 0x01
751#define V_CONF_OFLOW1 0x02
752#define V_CONF_OFLOW2 0x04
753#define V_CONF_OFLOW3 0x08
754#define V_CONF_OFLOW4 0x10
755#define V_CONF_OFLOW5 0x20
756#define V_CONF_OFLOW6 0x40
757#define V_CONF_OFLOW7 0x80
758
759/* chapter 9: DTMF contoller */
760/* R_DTMF0 */
761#define V_DTMF_EN 0x01
762#define V_HARM_SEL 0x02
763#define V_DTMF_RX_CH 0x04
764#define V_DTMF_STOP 0x08
765#define V_CHBL_SEL 0x10
766#define V_RST_DTMF 0x40
767#define V_ULAW_SEL 0x80
768
769/* chapter 10: BERT */
770/* R_BERT_WD_MD */
771#define V_PAT_SEQ 0x01
772#define V_BERT_ERR 0x08
773#define V_AUTO_WD_RES 0x20
774#define V_WD_RES 0x80
775/* R_BERT_STA */
776#define V_BERT_SYNC_SRC 0x01
777#define V_BERT_SYNC 0x10
778#define V_BERT_INV_DATA 0x20
779
780/* chapter 11: auxiliary interface */
781/* R_BRG_PCM_CFG */
782#define V_BRG_EN 0x01
783#define V_BRG_MD 0x02
784#define V_PCM_CLK 0x20
785#define V_ADDR_WRDLY 0x40
786/* R_BRG_CTRL */
787#define V_BRG_CS 0x01
788#define V_BRG_ADDR 0x08
789#define V_BRG_CS_SRC 0x80
790/* R_BRG_MD */
791#define V_BRG_MD0 0x01
792#define V_BRG_MD1 0x02
793#define V_BRG_MD2 0x04
794#define V_BRG_MD3 0x08
795#define V_BRG_MD4 0x10
796#define V_BRG_MD5 0x20
797#define V_BRG_MD6 0x40
798#define V_BRG_MD7 0x80
799/* R_BRG_TIM0 */
800#define V_BRG_TIM0_IDLE 0x01
801#define V_BRG_TIM0_CLK 0x10
802/* R_BRG_TIM1 */
803#define V_BRG_TIM1_IDLE 0x01
804#define V_BRG_TIM1_CLK 0x10
805/* R_BRG_TIM2 */
806#define V_BRG_TIM2_IDLE 0x01
807#define V_BRG_TIM2_CLK 0x10
808/* R_BRG_TIM3 */
809#define V_BRG_TIM3_IDLE 0x01
810#define V_BRG_TIM3_CLK 0x10
811/* R_BRG_TIM_SEL01 */
812#define V_BRG_WR_SEL0 0x01
813#define V_BRG_RD_SEL0 0x04
814#define V_BRG_WR_SEL1 0x10
815#define V_BRG_RD_SEL1 0x40
816/* R_BRG_TIM_SEL23 */
817#define V_BRG_WR_SEL2 0x01
818#define V_BRG_RD_SEL2 0x04
819#define V_BRG_WR_SEL3 0x10
820#define V_BRG_RD_SEL3 0x40
821/* R_BRG_TIM_SEL45 */
822#define V_BRG_WR_SEL4 0x01
823#define V_BRG_RD_SEL4 0x04
824#define V_BRG_WR_SEL5 0x10
825#define V_BRG_RD_SEL5 0x40
826/* R_BRG_TIM_SEL67 */
827#define V_BRG_WR_SEL6 0x01
828#define V_BRG_RD_SEL6 0x04
829#define V_BRG_WR_SEL7 0x10
830#define V_BRG_RD_SEL7 0x40
831
832/* chapter 12: clock, reset, interrupt, timer and watchdog */
833/* R_IRQMSK_MISC */
834#define V_STA_IRQMSK 0x01
835#define V_TI_IRQMSK 0x02
836#define V_PROC_IRQMSK 0x04
837#define V_DTMF_IRQMSK 0x08
838#define V_IRQ1S_MSK 0x10
839#define V_SA6_IRQMSK 0x20
840#define V_RX_EOMF_MSK 0x40
841#define V_TX_EOMF_MSK 0x80
842/* R_IRQ_CTRL */
843#define V_FIFO_IRQ 0x01
844#define V_GLOB_IRQ_EN 0x08
845#define V_IRQ_POL 0x10
846/* R_TI_WD */
847#define V_EV_TS 0x01
848#define V_WD_TS 0x10
849/* A_IRQ_MSK */
850#define V_IRQ 0x01
851#define V_BERT_EN 0x02
852#define V_MIX_IRQ 0x04
853/* R_IRQ_OVIEW */
854#define V_IRQ_FIFO_BL0 0x01
855#define V_IRQ_FIFO_BL1 0x02
856#define V_IRQ_FIFO_BL2 0x04
857#define V_IRQ_FIFO_BL3 0x08
858#define V_IRQ_FIFO_BL4 0x10
859#define V_IRQ_FIFO_BL5 0x20
860#define V_IRQ_FIFO_BL6 0x40
861#define V_IRQ_FIFO_BL7 0x80
862/* R_IRQ_MISC */
863#define V_STA_IRQ 0x01
864#define V_TI_IRQ 0x02
865#define V_IRQ_PROC 0x04
866#define V_DTMF_IRQ 0x08
867#define V_IRQ1S 0x10
868#define V_SA6_IRQ 0x20
869#define V_RX_EOMF 0x40
870#define V_TX_EOMF 0x80
871/* R_STATUS */
872#define V_BUSY 0x01
873#define V_PROC 0x02
874#define V_DTMF_STA 0x04
875#define V_LOST_STA 0x08
876#define V_SYNC_IN 0x10
877#define V_EXT_IRQSTA 0x20
878#define V_MISC_IRQSTA 0x40
879#define V_FR_IRQSTA 0x80
880/* R_IRQ_FIFO_BL0 */
881#define V_IRQ_FIFO0_TX 0x01
882#define V_IRQ_FIFO0_RX 0x02
883#define V_IRQ_FIFO1_TX 0x04
884#define V_IRQ_FIFO1_RX 0x08
885#define V_IRQ_FIFO2_TX 0x10
886#define V_IRQ_FIFO2_RX 0x20
887#define V_IRQ_FIFO3_TX 0x40
888#define V_IRQ_FIFO3_RX 0x80
889/* R_IRQ_FIFO_BL1 */
890#define V_IRQ_FIFO4_TX 0x01
891#define V_IRQ_FIFO4_RX 0x02
892#define V_IRQ_FIFO5_TX 0x04
893#define V_IRQ_FIFO5_RX 0x08
894#define V_IRQ_FIFO6_TX 0x10
895#define V_IRQ_FIFO6_RX 0x20
896#define V_IRQ_FIFO7_TX 0x40
897#define V_IRQ_FIFO7_RX 0x80
898/* R_IRQ_FIFO_BL2 */
899#define V_IRQ_FIFO8_TX 0x01
900#define V_IRQ_FIFO8_RX 0x02
901#define V_IRQ_FIFO9_TX 0x04
902#define V_IRQ_FIFO9_RX 0x08
903#define V_IRQ_FIFO10_TX 0x10
904#define V_IRQ_FIFO10_RX 0x20
905#define V_IRQ_FIFO11_TX 0x40
906#define V_IRQ_FIFO11_RX 0x80
907/* R_IRQ_FIFO_BL3 */
908#define V_IRQ_FIFO12_TX 0x01
909#define V_IRQ_FIFO12_RX 0x02
910#define V_IRQ_FIFO13_TX 0x04
911#define V_IRQ_FIFO13_RX 0x08
912#define V_IRQ_FIFO14_TX 0x10
913#define V_IRQ_FIFO14_RX 0x20
914#define V_IRQ_FIFO15_TX 0x40
915#define V_IRQ_FIFO15_RX 0x80
916/* R_IRQ_FIFO_BL4 */
917#define V_IRQ_FIFO16_TX 0x01
918#define V_IRQ_FIFO16_RX 0x02
919#define V_IRQ_FIFO17_TX 0x04
920#define V_IRQ_FIFO17_RX 0x08
921#define V_IRQ_FIFO18_TX 0x10
922#define V_IRQ_FIFO18_RX 0x20
923#define V_IRQ_FIFO19_TX 0x40
924#define V_IRQ_FIFO19_RX 0x80
925/* R_IRQ_FIFO_BL5 */
926#define V_IRQ_FIFO20_TX 0x01
927#define V_IRQ_FIFO20_RX 0x02
928#define V_IRQ_FIFO21_TX 0x04
929#define V_IRQ_FIFO21_RX 0x08
930#define V_IRQ_FIFO22_TX 0x10
931#define V_IRQ_FIFO22_RX 0x20
932#define V_IRQ_FIFO23_TX 0x40
933#define V_IRQ_FIFO23_RX 0x80
934/* R_IRQ_FIFO_BL6 */
935#define V_IRQ_FIFO24_TX 0x01
936#define V_IRQ_FIFO24_RX 0x02
937#define V_IRQ_FIFO25_TX 0x04
938#define V_IRQ_FIFO25_RX 0x08
939#define V_IRQ_FIFO26_TX 0x10
940#define V_IRQ_FIFO26_RX 0x20
941#define V_IRQ_FIFO27_TX 0x40
942#define V_IRQ_FIFO27_RX 0x80
943/* R_IRQ_FIFO_BL7 */
944#define V_IRQ_FIFO28_TX 0x01
945#define V_IRQ_FIFO28_RX 0x02
946#define V_IRQ_FIFO29_TX 0x04
947#define V_IRQ_FIFO29_RX 0x08
948#define V_IRQ_FIFO30_TX 0x10
949#define V_IRQ_FIFO30_RX 0x20
950#define V_IRQ_FIFO31_TX 0x40
951#define V_IRQ_FIFO31_RX 0x80
952
953/* chapter 13: general purpose I/O pins (GPIO) and input pins (GPI) */
954/* R_GPIO_OUT0 */
955#define V_GPIO_OUT0 0x01
956#define V_GPIO_OUT1 0x02
957#define V_GPIO_OUT2 0x04
958#define V_GPIO_OUT3 0x08
959#define V_GPIO_OUT4 0x10
960#define V_GPIO_OUT5 0x20
961#define V_GPIO_OUT6 0x40
962#define V_GPIO_OUT7 0x80
963/* R_GPIO_OUT1 */
964#define V_GPIO_OUT8 0x01
965#define V_GPIO_OUT9 0x02
966#define V_GPIO_OUT10 0x04
967#define V_GPIO_OUT11 0x08
968#define V_GPIO_OUT12 0x10
969#define V_GPIO_OUT13 0x20
970#define V_GPIO_OUT14 0x40
971#define V_GPIO_OUT15 0x80
972/* R_GPIO_EN0 */
973#define V_GPIO_EN0 0x01
974#define V_GPIO_EN1 0x02
975#define V_GPIO_EN2 0x04
976#define V_GPIO_EN3 0x08
977#define V_GPIO_EN4 0x10
978#define V_GPIO_EN5 0x20
979#define V_GPIO_EN6 0x40
980#define V_GPIO_EN7 0x80
981/* R_GPIO_EN1 */
982#define V_GPIO_EN8 0x01
983#define V_GPIO_EN9 0x02
984#define V_GPIO_EN10 0x04
985#define V_GPIO_EN11 0x08
986#define V_GPIO_EN12 0x10
987#define V_GPIO_EN13 0x20
988#define V_GPIO_EN14 0x40
989#define V_GPIO_EN15 0x80
990/* R_GPIO_SEL */
991#define V_GPIO_SEL0 0x01
992#define V_GPIO_SEL1 0x02
993#define V_GPIO_SEL2 0x04
994#define V_GPIO_SEL3 0x08
995#define V_GPIO_SEL4 0x10
996#define V_GPIO_SEL5 0x20
997#define V_GPIO_SEL6 0x40
998#define V_GPIO_SEL7 0x80
999/* R_GPIO_IN0 */
1000#define V_GPIO_IN0 0x01
1001#define V_GPIO_IN1 0x02
1002#define V_GPIO_IN2 0x04
1003#define V_GPIO_IN3 0x08
1004#define V_GPIO_IN4 0x10
1005#define V_GPIO_IN5 0x20
1006#define V_GPIO_IN6 0x40
1007#define V_GPIO_IN7 0x80
1008/* R_GPIO_IN1 */
1009#define V_GPIO_IN8 0x01
1010#define V_GPIO_IN9 0x02
1011#define V_GPIO_IN10 0x04
1012#define V_GPIO_IN11 0x08
1013#define V_GPIO_IN12 0x10
1014#define V_GPIO_IN13 0x20
1015#define V_GPIO_IN14 0x40
1016#define V_GPIO_IN15 0x80
1017/* R_GPI_IN0 */
1018#define V_GPI_IN0 0x01
1019#define V_GPI_IN1 0x02
1020#define V_GPI_IN2 0x04
1021#define V_GPI_IN3 0x08
1022#define V_GPI_IN4 0x10
1023#define V_GPI_IN5 0x20
1024#define V_GPI_IN6 0x40
1025#define V_GPI_IN7 0x80
1026/* R_GPI_IN1 */
1027#define V_GPI_IN8 0x01
1028#define V_GPI_IN9 0x02
1029#define V_GPI_IN10 0x04
1030#define V_GPI_IN11 0x08
1031#define V_GPI_IN12 0x10
1032#define V_GPI_IN13 0x20
1033#define V_GPI_IN14 0x40
1034#define V_GPI_IN15 0x80
1035/* R_GPI_IN2 */
1036#define V_GPI_IN16 0x01
1037#define V_GPI_IN17 0x02
1038#define V_GPI_IN18 0x04
1039#define V_GPI_IN19 0x08
1040#define V_GPI_IN20 0x10
1041#define V_GPI_IN21 0x20
1042#define V_GPI_IN22 0x40
1043#define V_GPI_IN23 0x80
1044/* R_GPI_IN3 */
1045#define V_GPI_IN24 0x01
1046#define V_GPI_IN25 0x02
1047#define V_GPI_IN26 0x04
1048#define V_GPI_IN27 0x08
1049#define V_GPI_IN28 0x10
1050#define V_GPI_IN29 0x20
1051#define V_GPI_IN30 0x40
1052#define V_GPI_IN31 0x80
1053
1054/* map of all registers, used for debugging */
1055
1056#ifdef HFC_REGISTER_DEBUG
1057struct hfc_register_names {
1058 char *name;
1059 u_char reg;
1060} hfc_register_names[] = {
1061 /* write registers */
1062 {"R_CIRM", 0x00},
1063 {"R_CTRL", 0x01},
1064 {"R_BRG_PCM_CFG ", 0x02},
1065 {"R_RAM_ADDR0", 0x08},
1066 {"R_RAM_ADDR1", 0x09},
1067 {"R_RAM_ADDR2", 0x0A},
1068 {"R_FIRST_FIFO", 0x0B},
1069 {"R_RAM_SZ", 0x0C},
1070 {"R_FIFO_MD", 0x0D},
1071 {"R_INC_RES_FIFO", 0x0E},
1072 {"R_FIFO / R_FSM_IDX", 0x0F},
1073 {"R_SLOT", 0x10},
1074 {"R_IRQMSK_MISC", 0x11},
1075 {"R_SCI_MSK", 0x12},
1076 {"R_IRQ_CTRL", 0x13},
1077 {"R_PCM_MD0", 0x14},
1078 {"R_0x15", 0x15},
1079 {"R_ST_SEL", 0x16},
1080 {"R_ST_SYNC", 0x17},
1081 {"R_CONF_EN", 0x18},
1082 {"R_TI_WD", 0x1A},
1083 {"R_BERT_WD_MD", 0x1B},
1084 {"R_DTMF", 0x1C},
1085 {"R_DTMF_N", 0x1D},
1086 {"R_E1_XX_STA", 0x20},
1087 {"R_LOS0", 0x22},
1088 {"R_LOS1", 0x23},
1089 {"R_RX0", 0x24},
1090 {"R_RX_FR0", 0x25},
1091 {"R_RX_FR1", 0x26},
1092 {"R_TX0", 0x28},
1093 {"R_TX1", 0x29},
1094 {"R_TX_FR0", 0x2C},
1095 {"R_TX_FR1", 0x2D},
1096 {"R_TX_FR2", 0x2E},
1097 {"R_JATT_ATT", 0x2F},
1098 {"A_ST_xx_STA/R_RX_OFF", 0x30},
1099 {"A_ST_CTRL0/R_SYNC_OUT", 0x31},
1100 {"A_ST_CTRL1", 0x32},
1101 {"A_ST_CTRL2", 0x33},
1102 {"A_ST_SQ_WR", 0x34},
1103 {"R_TX_OFF", 0x34},
1104 {"R_SYNC_CTRL", 0x35},
1105 {"A_ST_CLK_DLY", 0x37},
1106 {"R_PWM0", 0x38},
1107 {"R_PWM1", 0x39},
1108 {"A_ST_B1_TX", 0x3C},
1109 {"A_ST_B2_TX", 0x3D},
1110 {"A_ST_D_TX", 0x3E},
1111 {"R_GPIO_OUT0", 0x40},
1112 {"R_GPIO_OUT1", 0x41},
1113 {"R_GPIO_EN0", 0x42},
1114 {"R_GPIO_EN1", 0x43},
1115 {"R_GPIO_SEL", 0x44},
1116 {"R_BRG_CTRL", 0x45},
1117 {"R_PWM_MD", 0x46},
1118 {"R_BRG_MD", 0x47},
1119 {"R_BRG_TIM0", 0x48},
1120 {"R_BRG_TIM1", 0x49},
1121 {"R_BRG_TIM2", 0x4A},
1122 {"R_BRG_TIM3", 0x4B},
1123 {"R_BRG_TIM_SEL01", 0x4C},
1124 {"R_BRG_TIM_SEL23", 0x4D},
1125 {"R_BRG_TIM_SEL45", 0x4E},
1126 {"R_BRG_TIM_SEL67", 0x4F},
1127 {"A_FIFO_DATA0-2", 0x80},
1128 {"A_FIFO_DATA0-2_NOINC", 0x84},
1129 {"R_RAM_DATA", 0xC0},
1130 {"A_SL_CFG", 0xD0},
1131 {"A_CONF", 0xD1},
1132 {"A_CH_MSK", 0xF4},
1133 {"A_CON_HDLC", 0xFA},
1134 {"A_SUBCH_CFG", 0xFB},
1135 {"A_CHANNEL", 0xFC},
1136 {"A_FIFO_SEQ", 0xFD},
1137 {"A_IRQ_MSK", 0xFF},
1138 {NULL, 0},
1139
1140 /* read registers */
1141 {"A_Z1", 0x04},
1142 {"A_Z1H", 0x05},
1143 {"A_Z2", 0x06},
1144 {"A_Z2H", 0x07},
1145 {"A_F1", 0x0C},
1146 {"A_F2", 0x0D},
1147 {"R_IRQ_OVIEW", 0x10},
1148 {"R_IRQ_MISC", 0x11},
1149 {"R_IRQ_STATECH", 0x12},
1150 {"R_CONF_OFLOW", 0x14},
1151 {"R_RAM_USE", 0x15},
1152 {"R_CHIP_ID", 0x16},
1153 {"R_BERT_STA", 0x17},
1154 {"R_F0_CNTL", 0x18},
1155 {"R_F0_CNTH", 0x19},
1156 {"R_BERT_ECL", 0x1A},
1157 {"R_BERT_ECH", 0x1B},
1158 {"R_STATUS", 0x1C},
1159 {"R_CHIP_RV", 0x1F},
1160 {"R_STATE", 0x20},
1161 {"R_SYNC_STA", 0x24},
1162 {"R_RX_SL0_0", 0x25},
1163 {"R_RX_SL0_1", 0x26},
1164 {"R_RX_SL0_2", 0x27},
1165 {"R_JATT_DIR", 0x2b},
1166 {"R_SLIP", 0x2c},
1167 {"A_ST_RD_STA", 0x30},
1168 {"R_FAS_ECL", 0x30},
1169 {"R_FAS_ECH", 0x31},
1170 {"R_VIO_ECL", 0x32},
1171 {"R_VIO_ECH", 0x33},
1172 {"R_CRC_ECL / A_ST_SQ_RD", 0x34},
1173 {"R_CRC_ECH", 0x35},
1174 {"R_E_ECL", 0x36},
1175 {"R_E_ECH", 0x37},
1176 {"R_SA6_SA13_ECL", 0x38},
1177 {"R_SA6_SA13_ECH", 0x39},
1178 {"R_SA6_SA23_ECL", 0x3A},
1179 {"R_SA6_SA23_ECH", 0x3B},
1180 {"A_ST_B1_RX", 0x3C},
1181 {"A_ST_B2_RX", 0x3D},
1182 {"A_ST_D_RX", 0x3E},
1183 {"A_ST_E_RX", 0x3F},
1184 {"R_GPIO_IN0", 0x40},
1185 {"R_GPIO_IN1", 0x41},
1186 {"R_GPI_IN0", 0x44},
1187 {"R_GPI_IN1", 0x45},
1188 {"R_GPI_IN2", 0x46},
1189 {"R_GPI_IN3", 0x47},
1190 {"A_FIFO_DATA0-2", 0x80},
1191 {"A_FIFO_DATA0-2_NOINC", 0x84},
1192 {"R_INT_DATA", 0x88},
1193 {"R_RAM_DATA", 0xC0},
1194 {"R_IRQ_FIFO_BL0", 0xC8},
1195 {"R_IRQ_FIFO_BL1", 0xC9},
1196 {"R_IRQ_FIFO_BL2", 0xCA},
1197 {"R_IRQ_FIFO_BL3", 0xCB},
1198 {"R_IRQ_FIFO_BL4", 0xCC},
1199 {"R_IRQ_FIFO_BL5", 0xCD},
1200 {"R_IRQ_FIFO_BL6", 0xCE},
1201 {"R_IRQ_FIFO_BL7", 0xCF},
1202};
1203#endif /* HFC_REGISTER_DEBUG */
1204
diff --git a/drivers/isdn/hardware/mISDN/hfc_pci.h b/drivers/isdn/hardware/mISDN/hfc_pci.h
new file mode 100644
index 000000000000..fd2c9be6d849
--- /dev/null
+++ b/drivers/isdn/hardware/mISDN/hfc_pci.h
@@ -0,0 +1,228 @@
1/*
2 * specific defines for CCD's HFC 2BDS0 PCI chips
3 *
4 * Author Werner Cornelius (werner@isdn4linux.de)
5 *
6 * Copyright 1999 by Werner Cornelius (werner@isdn4linux.de)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24/*
25 * thresholds for transparent B-channel mode
26 * change mask and threshold simultaneously
27 */
28#define HFCPCI_BTRANS_THRESHOLD 128
29#define HFCPCI_BTRANS_MAX 256
30#define HFCPCI_BTRANS_THRESMASK 0x00
31
32/* defines for PCI config */
33#define PCI_ENA_MEMIO 0x02
34#define PCI_ENA_MASTER 0x04
35
36/* GCI/IOM bus monitor registers */
37#define HCFPCI_C_I 0x08
38#define HFCPCI_TRxR 0x0C
39#define HFCPCI_MON1_D 0x28
40#define HFCPCI_MON2_D 0x2C
41
42/* GCI/IOM bus timeslot registers */
43#define HFCPCI_B1_SSL 0x80
44#define HFCPCI_B2_SSL 0x84
45#define HFCPCI_AUX1_SSL 0x88
46#define HFCPCI_AUX2_SSL 0x8C
47#define HFCPCI_B1_RSL 0x90
48#define HFCPCI_B2_RSL 0x94
49#define HFCPCI_AUX1_RSL 0x98
50#define HFCPCI_AUX2_RSL 0x9C
51
52/* GCI/IOM bus data registers */
53#define HFCPCI_B1_D 0xA0
54#define HFCPCI_B2_D 0xA4
55#define HFCPCI_AUX1_D 0xA8
56#define HFCPCI_AUX2_D 0xAC
57
58/* GCI/IOM bus configuration registers */
59#define HFCPCI_MST_EMOD 0xB4
60#define HFCPCI_MST_MODE 0xB8
61#define HFCPCI_CONNECT 0xBC
62
63
64/* Interrupt and status registers */
65#define HFCPCI_FIFO_EN 0x44
66#define HFCPCI_TRM 0x48
67#define HFCPCI_B_MODE 0x4C
68#define HFCPCI_CHIP_ID 0x58
69#define HFCPCI_CIRM 0x60
70#define HFCPCI_CTMT 0x64
71#define HFCPCI_INT_M1 0x68
72#define HFCPCI_INT_M2 0x6C
73#define HFCPCI_INT_S1 0x78
74#define HFCPCI_INT_S2 0x7C
75#define HFCPCI_STATUS 0x70
76
77/* S/T section registers */
78#define HFCPCI_STATES 0xC0
79#define HFCPCI_SCTRL 0xC4
80#define HFCPCI_SCTRL_E 0xC8
81#define HFCPCI_SCTRL_R 0xCC
82#define HFCPCI_SQ 0xD0
83#define HFCPCI_CLKDEL 0xDC
84#define HFCPCI_B1_REC 0xF0
85#define HFCPCI_B1_SEND 0xF0
86#define HFCPCI_B2_REC 0xF4
87#define HFCPCI_B2_SEND 0xF4
88#define HFCPCI_D_REC 0xF8
89#define HFCPCI_D_SEND 0xF8
90#define HFCPCI_E_REC 0xFC
91
92
93/* bits in status register (READ) */
94#define HFCPCI_PCI_PROC 0x02
95#define HFCPCI_NBUSY 0x04
96#define HFCPCI_TIMER_ELAP 0x10
97#define HFCPCI_STATINT 0x20
98#define HFCPCI_FRAMEINT 0x40
99#define HFCPCI_ANYINT 0x80
100
101/* bits in CTMT (Write) */
102#define HFCPCI_CLTIMER 0x80
103#define HFCPCI_TIM3_125 0x04
104#define HFCPCI_TIM25 0x10
105#define HFCPCI_TIM50 0x14
106#define HFCPCI_TIM400 0x18
107#define HFCPCI_TIM800 0x1C
108#define HFCPCI_AUTO_TIMER 0x20
109#define HFCPCI_TRANSB2 0x02
110#define HFCPCI_TRANSB1 0x01
111
112/* bits in CIRM (Write) */
113#define HFCPCI_AUX_MSK 0x07
114#define HFCPCI_RESET 0x08
115#define HFCPCI_B1_REV 0x40
116#define HFCPCI_B2_REV 0x80
117
118/* bits in INT_M1 and INT_S1 */
119#define HFCPCI_INTS_B1TRANS 0x01
120#define HFCPCI_INTS_B2TRANS 0x02
121#define HFCPCI_INTS_DTRANS 0x04
122#define HFCPCI_INTS_B1REC 0x08
123#define HFCPCI_INTS_B2REC 0x10
124#define HFCPCI_INTS_DREC 0x20
125#define HFCPCI_INTS_L1STATE 0x40
126#define HFCPCI_INTS_TIMER 0x80
127
128/* bits in INT_M2 */
129#define HFCPCI_PROC_TRANS 0x01
130#define HFCPCI_GCI_I_CHG 0x02
131#define HFCPCI_GCI_MON_REC 0x04
132#define HFCPCI_IRQ_ENABLE 0x08
133#define HFCPCI_PMESEL 0x80
134
135/* bits in STATES */
136#define HFCPCI_STATE_MSK 0x0F
137#define HFCPCI_LOAD_STATE 0x10
138#define HFCPCI_ACTIVATE 0x20
139#define HFCPCI_DO_ACTION 0x40
140#define HFCPCI_NT_G2_G3 0x80
141
142/* bits in HFCD_MST_MODE */
143#define HFCPCI_MASTER 0x01
144#define HFCPCI_SLAVE 0x00
145#define HFCPCI_F0IO_POSITIV 0x02
146#define HFCPCI_F0_NEGATIV 0x04
147#define HFCPCI_F0_2C4 0x08
148/* remaining bits are for codecs control */
149
150/* bits in HFCD_SCTRL */
151#define SCTRL_B1_ENA 0x01
152#define SCTRL_B2_ENA 0x02
153#define SCTRL_MODE_TE 0x00
154#define SCTRL_MODE_NT 0x04
155#define SCTRL_LOW_PRIO 0x08
156#define SCTRL_SQ_ENA 0x10
157#define SCTRL_TEST 0x20
158#define SCTRL_NONE_CAP 0x40
159#define SCTRL_PWR_DOWN 0x80
160
161/* bits in SCTRL_E */
162#define HFCPCI_AUTO_AWAKE 0x01
163#define HFCPCI_DBIT_1 0x04
164#define HFCPCI_IGNORE_COL 0x08
165#define HFCPCI_CHG_B1_B2 0x80
166
167/* bits in FIFO_EN register */
168#define HFCPCI_FIFOEN_B1 0x03
169#define HFCPCI_FIFOEN_B2 0x0C
170#define HFCPCI_FIFOEN_DTX 0x10
171#define HFCPCI_FIFOEN_B1TX 0x01
172#define HFCPCI_FIFOEN_B1RX 0x02
173#define HFCPCI_FIFOEN_B2TX 0x04
174#define HFCPCI_FIFOEN_B2RX 0x08
175
176
177/* definitions of fifo memory area */
178#define MAX_D_FRAMES 15
179#define MAX_B_FRAMES 31
180#define B_SUB_VAL 0x200
181#define B_FIFO_SIZE (0x2000 - B_SUB_VAL)
182#define D_FIFO_SIZE 512
183#define D_FREG_MASK 0xF
184
185struct zt {
186 unsigned short z1; /* Z1 pointer 16 Bit */
187 unsigned short z2; /* Z2 pointer 16 Bit */
188};
189
190struct dfifo {
191 u_char data[D_FIFO_SIZE]; /* FIFO data space */
192 u_char fill1[0x20A0-D_FIFO_SIZE]; /* reserved, do not use */
193 u_char f1, f2; /* f pointers */
194 u_char fill2[0x20C0-0x20A2]; /* reserved, do not use */
195 /* mask index with D_FREG_MASK for access */
196 struct zt za[MAX_D_FRAMES+1];
197 u_char fill3[0x4000-0x2100]; /* align 16K */
198};
199
200struct bzfifo {
201 struct zt za[MAX_B_FRAMES+1]; /* only range 0x0..0x1F allowed */
202 u_char f1, f2; /* f pointers */
203 u_char fill[0x2100-0x2082]; /* alignment */
204};
205
206
207union fifo_area {
208 struct {
209 struct dfifo d_tx; /* D-send channel */
210 struct dfifo d_rx; /* D-receive channel */
211 } d_chan;
212 struct {
213 u_char fill1[0x200];
214 u_char txdat_b1[B_FIFO_SIZE];
215 struct bzfifo txbz_b1;
216 struct bzfifo txbz_b2;
217 u_char txdat_b2[B_FIFO_SIZE];
218 u_char fill2[D_FIFO_SIZE];
219 u_char rxdat_b1[B_FIFO_SIZE];
220 struct bzfifo rxbz_b1;
221 struct bzfifo rxbz_b2;
222 u_char rxdat_b2[B_FIFO_SIZE];
223 } b_chans;
224 u_char fill[32768];
225};
226
227#define Write_hfc(a, b, c) (writeb(c, (a->hw.pci_io)+b))
228#define Read_hfc(a, b) (readb((a->hw.pci_io)+b))
diff --git a/drivers/isdn/hardware/mISDN/hfcmulti.c b/drivers/isdn/hardware/mISDN/hfcmulti.c
new file mode 100644
index 000000000000..2649ea55a9e8
--- /dev/null
+++ b/drivers/isdn/hardware/mISDN/hfcmulti.c
@@ -0,0 +1,5320 @@
1/*
2 * hfcmulti.c low level driver for hfc-4s/hfc-8s/hfc-e1 based cards
3 *
4 * Author Andreas Eversberg (jolly@eversberg.eu)
5 * ported to mqueue mechanism:
6 * Peter Sprenger (sprengermoving-bytes.de)
7 *
8 * inspired by existing hfc-pci driver:
9 * Copyright 1999 by Werner Cornelius (werner@isdn-development.de)
10 * Copyright 2008 by Karsten Keil (kkeil@suse.de)
11 * Copyright 2008 by Andreas Eversberg (jolly@eversberg.eu)
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
16 * any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 *
28 * Thanks to Cologne Chip AG for this great controller!
29 */
30
31/*
32 * module parameters:
33 * type:
34 * By default (0), the card is automatically detected.
35 * Or use the following combinations:
36 * Bit 0-7 = 0x00001 = HFC-E1 (1 port)
37 * or Bit 0-7 = 0x00004 = HFC-4S (4 ports)
38 * or Bit 0-7 = 0x00008 = HFC-8S (8 ports)
39 * Bit 8 = 0x00100 = uLaw (instead of aLaw)
40 * Bit 9 = 0x00200 = Disable DTMF detect on all B-channels via hardware
41 * Bit 10 = spare
42 * Bit 11 = 0x00800 = Force PCM bus into slave mode. (otherwhise auto)
43 * or Bit 12 = 0x01000 = Force PCM bus into master mode. (otherwhise auto)
44 * Bit 13 = spare
45 * Bit 14 = 0x04000 = Use external ram (128K)
46 * Bit 15 = 0x08000 = Use external ram (512K)
47 * Bit 16 = 0x10000 = Use 64 timeslots instead of 32
48 * or Bit 17 = 0x20000 = Use 128 timeslots instead of anything else
49 * Bit 18 = spare
50 * Bit 19 = 0x80000 = Send the Watchdog a Signal (Dual E1 with Watchdog)
51 * (all other bits are reserved and shall be 0)
52 * example: 0x20204 one HFC-4S with dtmf detection and 128 timeslots on PCM
53 * bus (PCM master)
54 *
55 * port: (optional or required for all ports on all installed cards)
56 * HFC-4S/HFC-8S only bits:
57 * Bit 0 = 0x001 = Use master clock for this S/T interface
58 * (ony once per chip).
59 * Bit 1 = 0x002 = transmitter line setup (non capacitive mode)
60 * Don't use this unless you know what you are doing!
61 * Bit 2 = 0x004 = Disable E-channel. (No E-channel processing)
62 * example: 0x0001,0x0000,0x0000,0x0000 one HFC-4S with master clock
63 * received from port 1
64 *
65 * HFC-E1 only bits:
66 * Bit 0 = 0x0001 = interface: 0=copper, 1=optical
67 * Bit 1 = 0x0002 = reserved (later for 32 B-channels transparent mode)
68 * Bit 2 = 0x0004 = Report LOS
69 * Bit 3 = 0x0008 = Report AIS
70 * Bit 4 = 0x0010 = Report SLIP
71 * Bit 5 = 0x0020 = Report RDI
72 * Bit 8 = 0x0100 = Turn off CRC-4 Multiframe Mode, use double frame
73 * mode instead.
74 * Bit 9 = 0x0200 = Force get clock from interface, even in NT mode.
75 * or Bit 10 = 0x0400 = Force put clock to interface, even in TE mode.
76 * Bit 11 = 0x0800 = Use direct RX clock for PCM sync rather than PLL.
77 * (E1 only)
78 * Bit 12-13 = 0xX000 = elastic jitter buffer (1-3), Set both bits to 0
79 * for default.
80 * (all other bits are reserved and shall be 0)
81 *
82 * debug:
83 * NOTE: only one debug value must be given for all cards
84 * enable debugging (see hfc_multi.h for debug options)
85 *
86 * poll:
87 * NOTE: only one poll value must be given for all cards
88 * Give the number of samples for each fifo process.
89 * By default 128 is used. Decrease to reduce delay, increase to
90 * reduce cpu load. If unsure, don't mess with it!
91 * Valid is 8, 16, 32, 64, 128, 256.
92 *
93 * pcm:
94 * NOTE: only one pcm value must be given for every card.
95 * The PCM bus id tells the mISDNdsp module about the connected PCM bus.
96 * By default (0), the PCM bus id is 100 for the card that is PCM master.
97 * If multiple cards are PCM master (because they are not interconnected),
98 * each card with PCM master will have increasing PCM id.
99 * All PCM busses with the same ID are expected to be connected and have
100 * common time slots slots.
101 * Only one chip of the PCM bus must be master, the others slave.
102 * -1 means no support of PCM bus not even.
103 * Omit this value, if all cards are interconnected or none is connected.
104 * If unsure, don't give this parameter.
105 *
106 * dslot:
107 * NOTE: only one poll value must be given for every card.
108 * Also this value must be given for non-E1 cards. If omitted, the E1
109 * card has D-channel on time slot 16, which is default.
110 * If 1..15 or 17..31, an alternate time slot is used for D-channel.
111 * In this case, the application must be able to handle this.
112 * If -1 is given, the D-channel is disabled and all 31 slots can be used
113 * for B-channel. (only for specific applications)
114 * If you don't know how to use it, you don't need it!
115 *
116 * iomode:
117 * NOTE: only one mode value must be given for every card.
118 * -> See hfc_multi.h for HFC_IO_MODE_* values
119 * By default, the IO mode is pci memory IO (MEMIO).
120 * Some cards requre specific IO mode, so it cannot be changed.
121 * It may be usefull to set IO mode to register io (REGIO) to solve
122 * PCI bridge problems.
123 * If unsure, don't give this parameter.
124 *
125 * clockdelay_nt:
126 * NOTE: only one clockdelay_nt value must be given once for all cards.
127 * Give the value of the clock control register (A_ST_CLK_DLY)
128 * of the S/T interfaces in NT mode.
129 * This register is needed for the TBR3 certification, so don't change it.
130 *
131 * clockdelay_te:
132 * NOTE: only one clockdelay_te value must be given once
133 * Give the value of the clock control register (A_ST_CLK_DLY)
134 * of the S/T interfaces in TE mode.
135 * This register is needed for the TBR3 certification, so don't change it.
136 */
137
138/*
139 * debug register access (never use this, it will flood your system log)
140 * #define HFC_REGISTER_DEBUG
141 */
142
143static const char *hfcmulti_revision = "2.00";
144
145#include <linux/module.h>
146#include <linux/pci.h>
147#include <linux/delay.h>
148#include <linux/mISDNhw.h>
149#include <linux/mISDNdsp.h>
150
151/*
152#define IRQCOUNT_DEBUG
153#define IRQ_DEBUG
154*/
155
156#include "hfc_multi.h"
157#ifdef ECHOPREP
158#include "gaintab.h"
159#endif
160
161#define MAX_CARDS 8
162#define MAX_PORTS (8 * MAX_CARDS)
163
164static LIST_HEAD(HFClist);
165static spinlock_t HFClock; /* global hfc list lock */
166
167static void ph_state_change(struct dchannel *);
168static void (*hfc_interrupt)(void);
169static void (*register_interrupt)(void);
170static int (*unregister_interrupt)(void);
171static int interrupt_registered;
172
173static struct hfc_multi *syncmaster;
174int plxsd_master; /* if we have a master card (yet) */
175static spinlock_t plx_lock; /* may not acquire other lock inside */
176EXPORT_SYMBOL(plx_lock);
177
178#define TYP_E1 1
179#define TYP_4S 4
180#define TYP_8S 8
181
182static int poll_timer = 6; /* default = 128 samples = 16ms */
183/* number of POLL_TIMER interrupts for G2 timeout (ca 1s) */
184static int nt_t1_count[] = { 3840, 1920, 960, 480, 240, 120, 60, 30 };
185#define CLKDEL_TE 0x0f /* CLKDEL in TE mode */
186#define CLKDEL_NT 0x6c /* CLKDEL in NT mode
187 (0x60 MUST be included!) */
188static u_char silence = 0xff; /* silence by LAW */
189
190#define DIP_4S 0x1 /* DIP Switches for Beronet 1S/2S/4S cards */
191#define DIP_8S 0x2 /* DIP Switches for Beronet 8S+ cards */
192#define DIP_E1 0x3 /* DIP Switches for Beronet E1 cards */
193
194/*
195 * module stuff
196 */
197
198static uint type[MAX_CARDS];
199static uint pcm[MAX_CARDS];
200static uint dslot[MAX_CARDS];
201static uint iomode[MAX_CARDS];
202static uint port[MAX_PORTS];
203static uint debug;
204static uint poll;
205static uint timer;
206static uint clockdelay_te = CLKDEL_TE;
207static uint clockdelay_nt = CLKDEL_NT;
208
209static int HFC_cnt, Port_cnt, PCM_cnt = 99;
210
211MODULE_AUTHOR("Andreas Eversberg");
212MODULE_LICENSE("GPL");
213module_param(debug, uint, S_IRUGO | S_IWUSR);
214module_param(poll, uint, S_IRUGO | S_IWUSR);
215module_param(timer, uint, S_IRUGO | S_IWUSR);
216module_param(clockdelay_te, uint, S_IRUGO | S_IWUSR);
217module_param(clockdelay_nt, uint, S_IRUGO | S_IWUSR);
218module_param_array(type, uint, NULL, S_IRUGO | S_IWUSR);
219module_param_array(pcm, uint, NULL, S_IRUGO | S_IWUSR);
220module_param_array(dslot, uint, NULL, S_IRUGO | S_IWUSR);
221module_param_array(iomode, uint, NULL, S_IRUGO | S_IWUSR);
222module_param_array(port, uint, NULL, S_IRUGO | S_IWUSR);
223
224#ifdef HFC_REGISTER_DEBUG
225#define HFC_outb(hc, reg, val) \
226 (hc->HFC_outb(hc, reg, val, __func__, __LINE__))
227#define HFC_outb_nodebug(hc, reg, val) \
228 (hc->HFC_outb_nodebug(hc, reg, val, __func__, __LINE__))
229#define HFC_inb(hc, reg) \
230 (hc->HFC_inb(hc, reg, __func__, __LINE__))
231#define HFC_inb_nodebug(hc, reg) \
232 (hc->HFC_inb_nodebug(hc, reg, __func__, __LINE__))
233#define HFC_inw(hc, reg) \
234 (hc->HFC_inw(hc, reg, __func__, __LINE__))
235#define HFC_inw_nodebug(hc, reg) \
236 (hc->HFC_inw_nodebug(hc, reg, __func__, __LINE__))
237#define HFC_wait(hc) \
238 (hc->HFC_wait(hc, __func__, __LINE__))
239#define HFC_wait_nodebug(hc) \
240 (hc->HFC_wait_nodebug(hc, __func__, __LINE__))
241#else
242#define HFC_outb(hc, reg, val) (hc->HFC_outb(hc, reg, val))
243#define HFC_outb_nodebug(hc, reg, val) (hc->HFC_outb_nodebug(hc, reg, val))
244#define HFC_inb(hc, reg) (hc->HFC_inb(hc, reg))
245#define HFC_inb_nodebug(hc, reg) (hc->HFC_inb_nodebug(hc, reg))
246#define HFC_inw(hc, reg) (hc->HFC_inw(hc, reg))
247#define HFC_inw_nodebug(hc, reg) (hc->HFC_inw_nodebug(hc, reg))
248#define HFC_wait(hc) (hc->HFC_wait(hc))
249#define HFC_wait_nodebug(hc) (hc->HFC_wait_nodebug(hc))
250#endif
251
252/* HFC_IO_MODE_PCIMEM */
253static void
254#ifdef HFC_REGISTER_DEBUG
255HFC_outb_pcimem(struct hfc_multi *hc, u_char reg, u_char val,
256 const char *function, int line)
257#else
258HFC_outb_pcimem(struct hfc_multi *hc, u_char reg, u_char val)
259#endif
260{
261 writeb(val, (hc->pci_membase)+reg);
262}
263static u_char
264#ifdef HFC_REGISTER_DEBUG
265HFC_inb_pcimem(struct hfc_multi *hc, u_char reg, const char *function, int line)
266#else
267HFC_inb_pcimem(struct hfc_multi *hc, u_char reg)
268#endif
269{
270 return readb((hc->pci_membase)+reg);
271}
272static u_short
273#ifdef HFC_REGISTER_DEBUG
274HFC_inw_pcimem(struct hfc_multi *hc, u_char reg, const char *function, int line)
275#else
276HFC_inw_pcimem(struct hfc_multi *hc, u_char reg)
277#endif
278{
279 return readw((hc->pci_membase)+reg);
280}
281static void
282#ifdef HFC_REGISTER_DEBUG
283HFC_wait_pcimem(struct hfc_multi *hc, const char *function, int line)
284#else
285HFC_wait_pcimem(struct hfc_multi *hc)
286#endif
287{
288 while (readb((hc->pci_membase)+R_STATUS) & V_BUSY);
289}
290
291/* HFC_IO_MODE_REGIO */
292static void
293#ifdef HFC_REGISTER_DEBUG
294HFC_outb_regio(struct hfc_multi *hc, u_char reg, u_char val,
295 const char *function, int line)
296#else
297HFC_outb_regio(struct hfc_multi *hc, u_char reg, u_char val)
298#endif
299{
300 outb(reg, (hc->pci_iobase)+4);
301 outb(val, hc->pci_iobase);
302}
303static u_char
304#ifdef HFC_REGISTER_DEBUG
305HFC_inb_regio(struct hfc_multi *hc, u_char reg, const char *function, int line)
306#else
307HFC_inb_regio(struct hfc_multi *hc, u_char reg)
308#endif
309{
310 outb(reg, (hc->pci_iobase)+4);
311 return inb(hc->pci_iobase);
312}
313static u_short
314#ifdef HFC_REGISTER_DEBUG
315HFC_inw_regio(struct hfc_multi *hc, u_char reg, const char *function, int line)
316#else
317HFC_inw_regio(struct hfc_multi *hc, u_char reg)
318#endif
319{
320 outb(reg, (hc->pci_iobase)+4);
321 return inw(hc->pci_iobase);
322}
323static void
324#ifdef HFC_REGISTER_DEBUG
325HFC_wait_regio(struct hfc_multi *hc, const char *function, int line)
326#else
327HFC_wait_regio(struct hfc_multi *hc)
328#endif
329{
330 outb(R_STATUS, (hc->pci_iobase)+4);
331 while (inb(hc->pci_iobase) & V_BUSY);
332}
333
334#ifdef HFC_REGISTER_DEBUG
335static void
336HFC_outb_debug(struct hfc_multi *hc, u_char reg, u_char val,
337 const char *function, int line)
338{
339 char regname[256] = "", bits[9] = "xxxxxxxx";
340 int i;
341
342 i = -1;
343 while (hfc_register_names[++i].name) {
344 if (hfc_register_names[i].reg == reg)
345 strcat(regname, hfc_register_names[i].name);
346 }
347 if (regname[0] == '\0')
348 strcpy(regname, "register");
349
350 bits[7] = '0'+(!!(val&1));
351 bits[6] = '0'+(!!(val&2));
352 bits[5] = '0'+(!!(val&4));
353 bits[4] = '0'+(!!(val&8));
354 bits[3] = '0'+(!!(val&16));
355 bits[2] = '0'+(!!(val&32));
356 bits[1] = '0'+(!!(val&64));
357 bits[0] = '0'+(!!(val&128));
358 printk(KERN_DEBUG
359 "HFC_outb(chip %d, %02x=%s, 0x%02x=%s); in %s() line %d\n",
360 hc->id, reg, regname, val, bits, function, line);
361 HFC_outb_nodebug(hc, reg, val);
362}
363static u_char
364HFC_inb_debug(struct hfc_multi *hc, u_char reg, const char *function, int line)
365{
366 char regname[256] = "", bits[9] = "xxxxxxxx";
367 u_char val = HFC_inb_nodebug(hc, reg);
368 int i;
369
370 i = 0;
371 while (hfc_register_names[i++].name)
372 ;
373 while (hfc_register_names[++i].name) {
374 if (hfc_register_names[i].reg == reg)
375 strcat(regname, hfc_register_names[i].name);
376 }
377 if (regname[0] == '\0')
378 strcpy(regname, "register");
379
380 bits[7] = '0'+(!!(val&1));
381 bits[6] = '0'+(!!(val&2));
382 bits[5] = '0'+(!!(val&4));
383 bits[4] = '0'+(!!(val&8));
384 bits[3] = '0'+(!!(val&16));
385 bits[2] = '0'+(!!(val&32));
386 bits[1] = '0'+(!!(val&64));
387 bits[0] = '0'+(!!(val&128));
388 printk(KERN_DEBUG
389 "HFC_inb(chip %d, %02x=%s) = 0x%02x=%s; in %s() line %d\n",
390 hc->id, reg, regname, val, bits, function, line);
391 return val;
392}
393static u_short
394HFC_inw_debug(struct hfc_multi *hc, u_char reg, const char *function, int line)
395{
396 char regname[256] = "";
397 u_short val = HFC_inw_nodebug(hc, reg);
398 int i;
399
400 i = 0;
401 while (hfc_register_names[i++].name)
402 ;
403 while (hfc_register_names[++i].name) {
404 if (hfc_register_names[i].reg == reg)
405 strcat(regname, hfc_register_names[i].name);
406 }
407 if (regname[0] == '\0')
408 strcpy(regname, "register");
409
410 printk(KERN_DEBUG
411 "HFC_inw(chip %d, %02x=%s) = 0x%04x; in %s() line %d\n",
412 hc->id, reg, regname, val, function, line);
413 return val;
414}
415static void
416HFC_wait_debug(struct hfc_multi *hc, const char *function, int line)
417{
418 printk(KERN_DEBUG "HFC_wait(chip %d); in %s() line %d\n",
419 hc->id, function, line);
420 HFC_wait_nodebug(hc);
421}
422#endif
423
424/* write fifo data (REGIO) */
425void
426write_fifo_regio(struct hfc_multi *hc, u_char *data, int len)
427{
428 outb(A_FIFO_DATA0, (hc->pci_iobase)+4);
429 while (len>>2) {
430 outl(*(u32 *)data, hc->pci_iobase);
431 data += 4;
432 len -= 4;
433 }
434 while (len>>1) {
435 outw(*(u16 *)data, hc->pci_iobase);
436 data += 2;
437 len -= 2;
438 }
439 while (len) {
440 outb(*data, hc->pci_iobase);
441 data++;
442 len--;
443 }
444}
445/* write fifo data (PCIMEM) */
446void
447write_fifo_pcimem(struct hfc_multi *hc, u_char *data, int len)
448{
449 while (len>>2) {
450 writel(*(u32 *)data, (hc->pci_membase)+A_FIFO_DATA0);
451 data += 4;
452 len -= 4;
453 }
454 while (len>>1) {
455 writew(*(u16 *)data, (hc->pci_membase)+A_FIFO_DATA0);
456 data += 2;
457 len -= 2;
458 }
459 while (len) {
460 writeb(*data, (hc->pci_membase)+A_FIFO_DATA0);
461 data++;
462 len--;
463 }
464}
465/* read fifo data (REGIO) */
466void
467read_fifo_regio(struct hfc_multi *hc, u_char *data, int len)
468{
469 outb(A_FIFO_DATA0, (hc->pci_iobase)+4);
470 while (len>>2) {
471 *(u32 *)data = inl(hc->pci_iobase);
472 data += 4;
473 len -= 4;
474 }
475 while (len>>1) {
476 *(u16 *)data = inw(hc->pci_iobase);
477 data += 2;
478 len -= 2;
479 }
480 while (len) {
481 *data = inb(hc->pci_iobase);
482 data++;
483 len--;
484 }
485}
486
487/* read fifo data (PCIMEM) */
488void
489read_fifo_pcimem(struct hfc_multi *hc, u_char *data, int len)
490{
491 while (len>>2) {
492 *(u32 *)data =
493 readl((hc->pci_membase)+A_FIFO_DATA0);
494 data += 4;
495 len -= 4;
496 }
497 while (len>>1) {
498 *(u16 *)data =
499 readw((hc->pci_membase)+A_FIFO_DATA0);
500 data += 2;
501 len -= 2;
502 }
503 while (len) {
504 *data = readb((hc->pci_membase)+A_FIFO_DATA0);
505 data++;
506 len--;
507 }
508}
509
510
511static void
512enable_hwirq(struct hfc_multi *hc)
513{
514 hc->hw.r_irq_ctrl |= V_GLOB_IRQ_EN;
515 HFC_outb(hc, R_IRQ_CTRL, hc->hw.r_irq_ctrl);
516}
517
518static void
519disable_hwirq(struct hfc_multi *hc)
520{
521 hc->hw.r_irq_ctrl &= ~((u_char)V_GLOB_IRQ_EN);
522 HFC_outb(hc, R_IRQ_CTRL, hc->hw.r_irq_ctrl);
523}
524
525#define NUM_EC 2
526#define MAX_TDM_CHAN 32
527
528
529inline void
530enablepcibridge(struct hfc_multi *c)
531{
532 HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x3); /* was _io before */
533}
534
535inline void
536disablepcibridge(struct hfc_multi *c)
537{
538 HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x2); /* was _io before */
539}
540
541inline unsigned char
542readpcibridge(struct hfc_multi *hc, unsigned char address)
543{
544 unsigned short cipv;
545 unsigned char data;
546
547 if (!hc->pci_iobase)
548 return 0;
549
550 /* slow down a PCI read access by 1 PCI clock cycle */
551 HFC_outb(hc, R_CTRL, 0x4); /*was _io before*/
552
553 if (address == 0)
554 cipv = 0x4000;
555 else
556 cipv = 0x5800;
557
558 /* select local bridge port address by writing to CIP port */
559 /* data = HFC_inb(c, cipv); * was _io before */
560 outw(cipv, hc->pci_iobase + 4);
561 data = inb(hc->pci_iobase);
562
563 /* restore R_CTRL for normal PCI read cycle speed */
564 HFC_outb(hc, R_CTRL, 0x0); /* was _io before */
565
566 return data;
567}
568
569inline void
570writepcibridge(struct hfc_multi *hc, unsigned char address, unsigned char data)
571{
572 unsigned short cipv;
573 unsigned int datav;
574
575 if (!hc->pci_iobase)
576 return;
577
578 if (address == 0)
579 cipv = 0x4000;
580 else
581 cipv = 0x5800;
582
583 /* select local bridge port address by writing to CIP port */
584 outw(cipv, hc->pci_iobase + 4);
585 /* define a 32 bit dword with 4 identical bytes for write sequence */
586 datav = data | ((__u32) data << 8) | ((__u32) data << 16) |
587 ((__u32) data << 24);
588
589 /*
590 * write this 32 bit dword to the bridge data port
591 * this will initiate a write sequence of up to 4 writes to the same
592 * address on the local bus interface the number of write accesses
593 * is undefined but >=1 and depends on the next PCI transaction
594 * during write sequence on the local bus
595 */
596 outl(datav, hc->pci_iobase);
597}
598
599inline void
600cpld_set_reg(struct hfc_multi *hc, unsigned char reg)
601{
602 /* Do data pin read low byte */
603 HFC_outb(hc, R_GPIO_OUT1, reg);
604}
605
606inline void
607cpld_write_reg(struct hfc_multi *hc, unsigned char reg, unsigned char val)
608{
609 cpld_set_reg(hc, reg);
610
611 enablepcibridge(hc);
612 writepcibridge(hc, 1, val);
613 disablepcibridge(hc);
614
615 return;
616}
617
618inline unsigned char
619cpld_read_reg(struct hfc_multi *hc, unsigned char reg)
620{
621 unsigned char bytein;
622
623 cpld_set_reg(hc, reg);
624
625 /* Do data pin read low byte */
626 HFC_outb(hc, R_GPIO_OUT1, reg);
627
628 enablepcibridge(hc);
629 bytein = readpcibridge(hc, 1);
630 disablepcibridge(hc);
631
632 return bytein;
633}
634
635inline void
636vpm_write_address(struct hfc_multi *hc, unsigned short addr)
637{
638 cpld_write_reg(hc, 0, 0xff & addr);
639 cpld_write_reg(hc, 1, 0x01 & (addr >> 8));
640}
641
642inline unsigned short
643vpm_read_address(struct hfc_multi *c)
644{
645 unsigned short addr;
646 unsigned short highbit;
647
648 addr = cpld_read_reg(c, 0);
649 highbit = cpld_read_reg(c, 1);
650
651 addr = addr | (highbit << 8);
652
653 return addr & 0x1ff;
654}
655
656inline unsigned char
657vpm_in(struct hfc_multi *c, int which, unsigned short addr)
658{
659 unsigned char res;
660
661 vpm_write_address(c, addr);
662
663 if (!which)
664 cpld_set_reg(c, 2);
665 else
666 cpld_set_reg(c, 3);
667
668 enablepcibridge(c);
669 res = readpcibridge(c, 1);
670 disablepcibridge(c);
671
672 cpld_set_reg(c, 0);
673
674 return res;
675}
676
677inline void
678vpm_out(struct hfc_multi *c, int which, unsigned short addr,
679 unsigned char data)
680{
681 vpm_write_address(c, addr);
682
683 enablepcibridge(c);
684
685 if (!which)
686 cpld_set_reg(c, 2);
687 else
688 cpld_set_reg(c, 3);
689
690 writepcibridge(c, 1, data);
691
692 cpld_set_reg(c, 0);
693
694 disablepcibridge(c);
695
696 {
697 unsigned char regin;
698 regin = vpm_in(c, which, addr);
699 if (regin != data)
700 printk(KERN_DEBUG "Wrote 0x%x to register 0x%x but got back "
701 "0x%x\n", data, addr, regin);
702 }
703
704}
705
706
707void
708vpm_init(struct hfc_multi *wc)
709{
710 unsigned char reg;
711 unsigned int mask;
712 unsigned int i, x, y;
713 unsigned int ver;
714
715 for (x = 0; x < NUM_EC; x++) {
716 /* Setup GPIO's */
717 if (!x) {
718 ver = vpm_in(wc, x, 0x1a0);
719 printk(KERN_DEBUG "VPM: Chip %d: ver %02x\n", x, ver);
720 }
721
722 for (y = 0; y < 4; y++) {
723 vpm_out(wc, x, 0x1a8 + y, 0x00); /* GPIO out */
724 vpm_out(wc, x, 0x1ac + y, 0x00); /* GPIO dir */
725 vpm_out(wc, x, 0x1b0 + y, 0x00); /* GPIO sel */
726 }
727
728 /* Setup TDM path - sets fsync and tdm_clk as inputs */
729 reg = vpm_in(wc, x, 0x1a3); /* misc_con */
730 vpm_out(wc, x, 0x1a3, reg & ~2);
731
732 /* Setup Echo length (256 taps) */
733 vpm_out(wc, x, 0x022, 1);
734 vpm_out(wc, x, 0x023, 0xff);
735
736 /* Setup timeslots */
737 vpm_out(wc, x, 0x02f, 0x00);
738 mask = 0x02020202 << (x * 4);
739
740 /* Setup the tdm channel masks for all chips */
741 for (i = 0; i < 4; i++)
742 vpm_out(wc, x, 0x33 - i, (mask >> (i << 3)) & 0xff);
743
744 /* Setup convergence rate */
745 printk(KERN_DEBUG "VPM: A-law mode\n");
746 reg = 0x00 | 0x10 | 0x01;
747 vpm_out(wc, x, 0x20, reg);
748 printk(KERN_DEBUG "VPM reg 0x20 is %x\n", reg);
749 /*vpm_out(wc, x, 0x20, (0x00 | 0x08 | 0x20 | 0x10)); */
750
751 vpm_out(wc, x, 0x24, 0x02);
752 reg = vpm_in(wc, x, 0x24);
753 printk(KERN_DEBUG "NLP Thresh is set to %d (0x%x)\n", reg, reg);
754
755 /* Initialize echo cans */
756 for (i = 0; i < MAX_TDM_CHAN; i++) {
757 if (mask & (0x00000001 << i))
758 vpm_out(wc, x, i, 0x00);
759 }
760
761 /*
762 * ARM arch at least disallows a udelay of
763 * more than 2ms... it gives a fake "__bad_udelay"
764 * reference at link-time.
765 * long delays in kernel code are pretty sucky anyway
766 * for now work around it using 5 x 2ms instead of 1 x 10ms
767 */
768
769 udelay(2000);
770 udelay(2000);
771 udelay(2000);
772 udelay(2000);
773 udelay(2000);
774
775 /* Put in bypass mode */
776 for (i = 0; i < MAX_TDM_CHAN; i++) {
777 if (mask & (0x00000001 << i))
778 vpm_out(wc, x, i, 0x01);
779 }
780
781 /* Enable bypass */
782 for (i = 0; i < MAX_TDM_CHAN; i++) {
783 if (mask & (0x00000001 << i))
784 vpm_out(wc, x, 0x78 + i, 0x01);
785 }
786
787 }
788}
789
790void
791vpm_check(struct hfc_multi *hctmp)
792{
793 unsigned char gpi2;
794
795 gpi2 = HFC_inb(hctmp, R_GPI_IN2);
796
797 if ((gpi2 & 0x3) != 0x3)
798 printk(KERN_DEBUG "Got interrupt 0x%x from VPM!\n", gpi2);
799}
800
801
802/*
803 * Interface to enable/disable the HW Echocan
804 *
805 * these functions are called within a spin_lock_irqsave on
806 * the channel instance lock, so we are not disturbed by irqs
807 *
808 * we can later easily change the interface to make other
809 * things configurable, for now we configure the taps
810 *
811 */
812
813void
814vpm_echocan_on(struct hfc_multi *hc, int ch, int taps)
815{
816 unsigned int timeslot;
817 unsigned int unit;
818 struct bchannel *bch = hc->chan[ch].bch;
819#ifdef TXADJ
820 int txadj = -4;
821 struct sk_buff *skb;
822#endif
823 if (hc->chan[ch].protocol != ISDN_P_B_RAW)
824 return;
825
826 if (!bch)
827 return;
828
829#ifdef TXADJ
830 skb = _alloc_mISDN_skb(PH_CONTROL_IND, HFC_VOL_CHANGE_TX,
831 sizeof(int), &txadj, GFP_ATOMIC);
832 if (skb)
833 recv_Bchannel_skb(bch, skb);
834#endif
835
836 timeslot = ((ch/4)*8) + ((ch%4)*4) + 1;
837 unit = ch % 4;
838
839 printk(KERN_NOTICE "vpm_echocan_on called taps [%d] on timeslot %d\n",
840 taps, timeslot);
841
842 vpm_out(hc, unit, timeslot, 0x7e);
843}
844
845void
846vpm_echocan_off(struct hfc_multi *hc, int ch)
847{
848 unsigned int timeslot;
849 unsigned int unit;
850 struct bchannel *bch = hc->chan[ch].bch;
851#ifdef TXADJ
852 int txadj = 0;
853 struct sk_buff *skb;
854#endif
855
856 if (hc->chan[ch].protocol != ISDN_P_B_RAW)
857 return;
858
859 if (!bch)
860 return;
861
862#ifdef TXADJ
863 skb = _alloc_mISDN_skb(PH_CONTROL_IND, HFC_VOL_CHANGE_TX,
864 sizeof(int), &txadj, GFP_ATOMIC);
865 if (skb)
866 recv_Bchannel_skb(bch, skb);
867#endif
868
869 timeslot = ((ch/4)*8) + ((ch%4)*4) + 1;
870 unit = ch % 4;
871
872 printk(KERN_NOTICE "vpm_echocan_off called on timeslot %d\n",
873 timeslot);
874 /* FILLME */
875 vpm_out(hc, unit, timeslot, 0x01);
876}
877
878
879/*
880 * Speech Design resync feature
881 * NOTE: This is called sometimes outside interrupt handler.
882 * We must lock irqsave, so no other interrupt (other card) will occurr!
883 * Also multiple interrupts may nest, so must lock each access (lists, card)!
884 */
885static inline void
886hfcmulti_resync(struct hfc_multi *locked, struct hfc_multi *newmaster, int rm)
887{
888 struct hfc_multi *hc, *next, *pcmmaster = 0;
889 u_int *plx_acc_32, pv;
890 u_long flags;
891
892 spin_lock_irqsave(&HFClock, flags);
893 spin_lock(&plx_lock); /* must be locked inside other locks */
894
895 if (debug & DEBUG_HFCMULTI_PLXSD)
896 printk(KERN_DEBUG "%s: RESYNC(syncmaster=0x%p)\n",
897 __func__, syncmaster);
898
899 /* select new master */
900 if (newmaster) {
901 if (debug & DEBUG_HFCMULTI_PLXSD)
902 printk(KERN_DEBUG "using provided controller\n");
903 } else {
904 list_for_each_entry_safe(hc, next, &HFClist, list) {
905 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
906 if (hc->syncronized) {
907 newmaster = hc;
908 break;
909 }
910 }
911 }
912 }
913
914 /* Disable sync of all cards */
915 list_for_each_entry_safe(hc, next, &HFClist, list) {
916 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
917 plx_acc_32 = (u_int *)(hc->plx_membase+PLX_GPIOC);
918 pv = readl(plx_acc_32);
919 pv &= ~PLX_SYNC_O_EN;
920 writel(pv, plx_acc_32);
921 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)) {
922 pcmmaster = hc;
923 if (hc->type == 1) {
924 if (debug & DEBUG_HFCMULTI_PLXSD)
925 printk(KERN_DEBUG
926 "Schedule SYNC_I\n");
927 hc->e1_resync |= 1; /* get SYNC_I */
928 }
929 }
930 }
931 }
932
933 if (newmaster) {
934 hc = newmaster;
935 if (debug & DEBUG_HFCMULTI_PLXSD)
936 printk(KERN_DEBUG "id=%d (0x%p) = syncronized with "
937 "interface.\n", hc->id, hc);
938 /* Enable new sync master */
939 plx_acc_32 = (u_int *)(hc->plx_membase+PLX_GPIOC);
940 pv = readl(plx_acc_32);
941 pv |= PLX_SYNC_O_EN;
942 writel(pv, plx_acc_32);
943 /* switch to jatt PLL, if not disabled by RX_SYNC */
944 if (hc->type == 1 && !test_bit(HFC_CHIP_RX_SYNC, &hc->chip)) {
945 if (debug & DEBUG_HFCMULTI_PLXSD)
946 printk(KERN_DEBUG "Schedule jatt PLL\n");
947 hc->e1_resync |= 2; /* switch to jatt */
948 }
949 } else {
950 if (pcmmaster) {
951 hc = pcmmaster;
952 if (debug & DEBUG_HFCMULTI_PLXSD)
953 printk(KERN_DEBUG
954 "id=%d (0x%p) = PCM master syncronized "
955 "with QUARTZ\n", hc->id, hc);
956 if (hc->type == 1) {
957 /* Use the crystal clock for the PCM
958 master card */
959 if (debug & DEBUG_HFCMULTI_PLXSD)
960 printk(KERN_DEBUG
961 "Schedule QUARTZ for HFC-E1\n");
962 hc->e1_resync |= 4; /* switch quartz */
963 } else {
964 if (debug & DEBUG_HFCMULTI_PLXSD)
965 printk(KERN_DEBUG
966 "QUARTZ is automatically "
967 "enabled by HFC-%dS\n", hc->type);
968 }
969 plx_acc_32 = (u_int *)(hc->plx_membase+PLX_GPIOC);
970 pv = readl(plx_acc_32);
971 pv |= PLX_SYNC_O_EN;
972 writel(pv, plx_acc_32);
973 } else
974 if (!rm)
975 printk(KERN_ERR "%s no pcm master, this MUST "
976 "not happen!\n", __func__);
977 }
978 syncmaster = newmaster;
979
980 spin_unlock(&plx_lock);
981 spin_unlock_irqrestore(&HFClock, flags);
982}
983
984/* This must be called AND hc must be locked irqsave!!! */
985inline void
986plxsd_checksync(struct hfc_multi *hc, int rm)
987{
988 if (hc->syncronized) {
989 if (syncmaster == NULL) {
990 if (debug & DEBUG_HFCMULTI_PLXSD)
991 printk(KERN_WARNING "%s: GOT sync on card %d"
992 " (id=%d)\n", __func__, hc->id + 1,
993 hc->id);
994 hfcmulti_resync(hc, hc, rm);
995 }
996 } else {
997 if (syncmaster == hc) {
998 if (debug & DEBUG_HFCMULTI_PLXSD)
999 printk(KERN_WARNING "%s: LOST sync on card %d"
1000 " (id=%d)\n", __func__, hc->id + 1,
1001 hc->id);
1002 hfcmulti_resync(hc, NULL, rm);
1003 }
1004 }
1005}
1006
1007
1008/*
1009 * free hardware resources used by driver
1010 */
1011static void
1012release_io_hfcmulti(struct hfc_multi *hc)
1013{
1014 u_int *plx_acc_32, pv;
1015 u_long plx_flags;
1016
1017 if (debug & DEBUG_HFCMULTI_INIT)
1018 printk(KERN_DEBUG "%s: entered\n", __func__);
1019
1020 /* soft reset also masks all interrupts */
1021 hc->hw.r_cirm |= V_SRES;
1022 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1023 udelay(1000);
1024 hc->hw.r_cirm &= ~V_SRES;
1025 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1026 udelay(1000); /* instead of 'wait' that may cause locking */
1027
1028 /* release Speech Design card, if PLX was initialized */
1029 if (test_bit(HFC_CHIP_PLXSD, &hc->chip) && hc->plx_membase) {
1030 if (debug & DEBUG_HFCMULTI_PLXSD)
1031 printk(KERN_DEBUG "%s: release PLXSD card %d\n",
1032 __func__, hc->id + 1);
1033 spin_lock_irqsave(&plx_lock, plx_flags);
1034 plx_acc_32 = (u_int *)(hc->plx_membase+PLX_GPIOC);
1035 writel(PLX_GPIOC_INIT, plx_acc_32);
1036 pv = readl(plx_acc_32);
1037 /* Termination off */
1038 pv &= ~PLX_TERM_ON;
1039 /* Disconnect the PCM */
1040 pv |= PLX_SLAVE_EN_N;
1041 pv &= ~PLX_MASTER_EN;
1042 pv &= ~PLX_SYNC_O_EN;
1043 /* Put the DSP in Reset */
1044 pv &= ~PLX_DSP_RES_N;
1045 writel(pv, plx_acc_32);
1046 if (debug & DEBUG_HFCMULTI_INIT)
1047 printk(KERN_WARNING "%s: PCM off: PLX_GPIO=%x\n",
1048 __func__, pv);
1049 spin_unlock_irqrestore(&plx_lock, plx_flags);
1050 }
1051
1052 /* disable memory mapped ports / io ports */
1053 test_and_clear_bit(HFC_CHIP_PLXSD, &hc->chip); /* prevent resync */
1054 pci_write_config_word(hc->pci_dev, PCI_COMMAND, 0);
1055 if (hc->pci_membase)
1056 iounmap((void *)hc->pci_membase);
1057 if (hc->plx_membase)
1058 iounmap((void *)hc->plx_membase);
1059 if (hc->pci_iobase)
1060 release_region(hc->pci_iobase, 8);
1061
1062 if (hc->pci_dev) {
1063 pci_disable_device(hc->pci_dev);
1064 pci_set_drvdata(hc->pci_dev, NULL);
1065 }
1066 if (debug & DEBUG_HFCMULTI_INIT)
1067 printk(KERN_DEBUG "%s: done\n", __func__);
1068}
1069
1070/*
1071 * function called to reset the HFC chip. A complete software reset of chip
1072 * and fifos is done. All configuration of the chip is done.
1073 */
1074
1075static int
1076init_chip(struct hfc_multi *hc)
1077{
1078 u_long flags, val, val2 = 0, rev;
1079 int i, err = 0;
1080 u_char r_conf_en, rval;
1081 u_int *plx_acc_32, pv;
1082 u_long plx_flags, hfc_flags;
1083 int plx_count;
1084 struct hfc_multi *pos, *next, *plx_last_hc;
1085
1086 spin_lock_irqsave(&hc->lock, flags);
1087 /* reset all registers */
1088 memset(&hc->hw, 0, sizeof(struct hfcm_hw));
1089
1090 /* revision check */
1091 if (debug & DEBUG_HFCMULTI_INIT)
1092 printk(KERN_DEBUG "%s: entered\n", __func__);
1093 val = HFC_inb(hc, R_CHIP_ID)>>4;
1094 if (val != 0x8 && val != 0xc && val != 0xe) {
1095 printk(KERN_INFO "HFC_multi: unknown CHIP_ID:%x\n", (u_int)val);
1096 err = -EIO;
1097 goto out;
1098 }
1099 rev = HFC_inb(hc, R_CHIP_RV);
1100 printk(KERN_INFO
1101 "HFC_multi: detected HFC with chip ID=0x%lx revision=%ld%s\n",
1102 val, rev, (rev == 0) ? " (old FIFO handling)" : "");
1103 if (rev == 0) {
1104 test_and_set_bit(HFC_CHIP_REVISION0, &hc->chip);
1105 printk(KERN_WARNING
1106 "HFC_multi: NOTE: Your chip is revision 0, "
1107 "ask Cologne Chip for update. Newer chips "
1108 "have a better FIFO handling. Old chips "
1109 "still work but may have slightly lower "
1110 "HDLC transmit performance.\n");
1111 }
1112 if (rev > 1) {
1113 printk(KERN_WARNING "HFC_multi: WARNING: This driver doesn't "
1114 "consider chip revision = %ld. The chip / "
1115 "bridge may not work.\n", rev);
1116 }
1117
1118 /* set s-ram size */
1119 hc->Flen = 0x10;
1120 hc->Zmin = 0x80;
1121 hc->Zlen = 384;
1122 hc->DTMFbase = 0x1000;
1123 if (test_bit(HFC_CHIP_EXRAM_128, &hc->chip)) {
1124 if (debug & DEBUG_HFCMULTI_INIT)
1125 printk(KERN_DEBUG "%s: changing to 128K extenal RAM\n",
1126 __func__);
1127 hc->hw.r_ctrl |= V_EXT_RAM;
1128 hc->hw.r_ram_sz = 1;
1129 hc->Flen = 0x20;
1130 hc->Zmin = 0xc0;
1131 hc->Zlen = 1856;
1132 hc->DTMFbase = 0x2000;
1133 }
1134 if (test_bit(HFC_CHIP_EXRAM_512, &hc->chip)) {
1135 if (debug & DEBUG_HFCMULTI_INIT)
1136 printk(KERN_DEBUG "%s: changing to 512K extenal RAM\n",
1137 __func__);
1138 hc->hw.r_ctrl |= V_EXT_RAM;
1139 hc->hw.r_ram_sz = 2;
1140 hc->Flen = 0x20;
1141 hc->Zmin = 0xc0;
1142 hc->Zlen = 8000;
1143 hc->DTMFbase = 0x2000;
1144 }
1145 hc->max_trans = poll << 1;
1146 if (hc->max_trans > hc->Zlen)
1147 hc->max_trans = hc->Zlen;
1148
1149 /* Speech Design PLX bridge */
1150 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1151 if (debug & DEBUG_HFCMULTI_PLXSD)
1152 printk(KERN_DEBUG "%s: initializing PLXSD card %d\n",
1153 __func__, hc->id + 1);
1154 spin_lock_irqsave(&plx_lock, plx_flags);
1155 plx_acc_32 = (u_int *)(hc->plx_membase+PLX_GPIOC);
1156 writel(PLX_GPIOC_INIT, plx_acc_32);
1157 pv = readl(plx_acc_32);
1158 /* The first and the last cards are terminating the PCM bus */
1159 pv |= PLX_TERM_ON; /* hc is currently the last */
1160 /* Disconnect the PCM */
1161 pv |= PLX_SLAVE_EN_N;
1162 pv &= ~PLX_MASTER_EN;
1163 pv &= ~PLX_SYNC_O_EN;
1164 /* Put the DSP in Reset */
1165 pv &= ~PLX_DSP_RES_N;
1166 writel(pv, plx_acc_32);
1167 spin_unlock_irqrestore(&plx_lock, plx_flags);
1168 if (debug & DEBUG_HFCMULTI_INIT)
1169 printk(KERN_WARNING "%s: slave/term: PLX_GPIO=%x\n",
1170 __func__, pv);
1171 /*
1172 * If we are the 3rd PLXSD card or higher, we must turn
1173 * termination of last PLXSD card off.
1174 */
1175 spin_lock_irqsave(&HFClock, hfc_flags);
1176 plx_count = 0;
1177 plx_last_hc = NULL;
1178 list_for_each_entry_safe(pos, next, &HFClist, list) {
1179 if (test_bit(HFC_CHIP_PLXSD, &pos->chip)) {
1180 plx_count++;
1181 if (pos != hc)
1182 plx_last_hc = pos;
1183 }
1184 }
1185 if (plx_count >= 3) {
1186 if (debug & DEBUG_HFCMULTI_PLXSD)
1187 printk(KERN_DEBUG "%s: card %d is between, so "
1188 "we disable termination\n",
1189 __func__, plx_last_hc->id + 1);
1190 spin_lock_irqsave(&plx_lock, plx_flags);
1191 plx_acc_32 = (u_int *)(plx_last_hc->plx_membase
1192 + PLX_GPIOC);
1193 pv = readl(plx_acc_32);
1194 pv &= ~PLX_TERM_ON;
1195 writel(pv, plx_acc_32);
1196 spin_unlock_irqrestore(&plx_lock, plx_flags);
1197 if (debug & DEBUG_HFCMULTI_INIT)
1198 printk(KERN_WARNING "%s: term off: PLX_GPIO=%x\n",
1199 __func__, pv);
1200 }
1201 spin_unlock_irqrestore(&HFClock, hfc_flags);
1202 hc->hw.r_pcm_md0 = V_F0_LEN; /* shift clock for DSP */
1203 }
1204
1205 /* we only want the real Z2 read-pointer for revision > 0 */
1206 if (!test_bit(HFC_CHIP_REVISION0, &hc->chip))
1207 hc->hw.r_ram_sz |= V_FZ_MD;
1208
1209 /* select pcm mode */
1210 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
1211 if (debug & DEBUG_HFCMULTI_INIT)
1212 printk(KERN_DEBUG "%s: setting PCM into slave mode\n",
1213 __func__);
1214 } else
1215 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip) && !plxsd_master) {
1216 if (debug & DEBUG_HFCMULTI_INIT)
1217 printk(KERN_DEBUG "%s: setting PCM into master mode\n",
1218 __func__);
1219 hc->hw.r_pcm_md0 |= V_PCM_MD;
1220 } else {
1221 if (debug & DEBUG_HFCMULTI_INIT)
1222 printk(KERN_DEBUG "%s: performing PCM auto detect\n",
1223 __func__);
1224 }
1225
1226 /* soft reset */
1227 HFC_outb(hc, R_CTRL, hc->hw.r_ctrl);
1228 HFC_outb(hc, R_RAM_SZ, hc->hw.r_ram_sz);
1229 HFC_outb(hc, R_FIFO_MD, 0);
1230 hc->hw.r_cirm = V_SRES | V_HFCRES | V_PCMRES | V_STRES | V_RLD_EPR;
1231 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1232 udelay(100);
1233 hc->hw.r_cirm = 0;
1234 HFC_outb(hc, R_CIRM, hc->hw.r_cirm);
1235 udelay(100);
1236 HFC_outb(hc, R_RAM_SZ, hc->hw.r_ram_sz);
1237
1238 /* Speech Design PLX bridge pcm and sync mode */
1239 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1240 spin_lock_irqsave(&plx_lock, plx_flags);
1241 plx_acc_32 = (u_int *)(hc->plx_membase+PLX_GPIOC);
1242 pv = readl(plx_acc_32);
1243 /* Connect PCM */
1244 if (hc->hw.r_pcm_md0 & V_PCM_MD) {
1245 pv |= PLX_MASTER_EN | PLX_SLAVE_EN_N;
1246 pv |= PLX_SYNC_O_EN;
1247 if (debug & DEBUG_HFCMULTI_INIT)
1248 printk(KERN_WARNING "%s: master: PLX_GPIO=%x\n",
1249 __func__, pv);
1250 } else {
1251 pv &= ~(PLX_MASTER_EN | PLX_SLAVE_EN_N);
1252 pv &= ~PLX_SYNC_O_EN;
1253 if (debug & DEBUG_HFCMULTI_INIT)
1254 printk(KERN_WARNING "%s: slave: PLX_GPIO=%x\n",
1255 __func__, pv);
1256 }
1257 writel(pv, plx_acc_32);
1258 spin_unlock_irqrestore(&plx_lock, plx_flags);
1259 }
1260
1261 /* PCM setup */
1262 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x90);
1263 if (hc->slots == 32)
1264 HFC_outb(hc, R_PCM_MD1, 0x00);
1265 if (hc->slots == 64)
1266 HFC_outb(hc, R_PCM_MD1, 0x10);
1267 if (hc->slots == 128)
1268 HFC_outb(hc, R_PCM_MD1, 0x20);
1269 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0xa0);
1270 if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
1271 HFC_outb(hc, R_PCM_MD2, V_SYNC_SRC); /* sync via SYNC_I / O */
1272 else
1273 HFC_outb(hc, R_PCM_MD2, 0x00); /* sync from interface */
1274 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x00);
1275 for (i = 0; i < 256; i++) {
1276 HFC_outb_nodebug(hc, R_SLOT, i);
1277 HFC_outb_nodebug(hc, A_SL_CFG, 0);
1278 HFC_outb_nodebug(hc, A_CONF, 0);
1279 hc->slot_owner[i] = -1;
1280 }
1281
1282 /* set clock speed */
1283 if (test_bit(HFC_CHIP_CLOCK2, &hc->chip)) {
1284 if (debug & DEBUG_HFCMULTI_INIT)
1285 printk(KERN_DEBUG
1286 "%s: setting double clock\n", __func__);
1287 HFC_outb(hc, R_BRG_PCM_CFG, V_PCM_CLK);
1288 }
1289
1290 /* B410P GPIO */
1291 if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
1292 printk(KERN_NOTICE "Setting GPIOs\n");
1293 HFC_outb(hc, R_GPIO_SEL, 0x30);
1294 HFC_outb(hc, R_GPIO_EN1, 0x3);
1295 udelay(1000);
1296 printk(KERN_NOTICE "calling vpm_init\n");
1297 vpm_init(hc);
1298 }
1299
1300 /* check if R_F0_CNT counts (8 kHz frame count) */
1301 val = HFC_inb(hc, R_F0_CNTL);
1302 val += HFC_inb(hc, R_F0_CNTH) << 8;
1303 if (debug & DEBUG_HFCMULTI_INIT)
1304 printk(KERN_DEBUG
1305 "HFC_multi F0_CNT %ld after reset\n", val);
1306 spin_unlock_irqrestore(&hc->lock, flags);
1307 set_current_state(TASK_UNINTERRUPTIBLE);
1308 schedule_timeout((HZ/100)?:1); /* Timeout minimum 10ms */
1309 spin_lock_irqsave(&hc->lock, flags);
1310 val2 = HFC_inb(hc, R_F0_CNTL);
1311 val2 += HFC_inb(hc, R_F0_CNTH) << 8;
1312 if (debug & DEBUG_HFCMULTI_INIT)
1313 printk(KERN_DEBUG
1314 "HFC_multi F0_CNT %ld after 10 ms (1st try)\n",
1315 val2);
1316 if (val2 >= val+8) { /* 1 ms */
1317 /* it counts, so we keep the pcm mode */
1318 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip))
1319 printk(KERN_INFO "controller is PCM bus MASTER\n");
1320 else
1321 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip))
1322 printk(KERN_INFO "controller is PCM bus SLAVE\n");
1323 else {
1324 test_and_set_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
1325 printk(KERN_INFO "controller is PCM bus SLAVE "
1326 "(auto detected)\n");
1327 }
1328 } else {
1329 /* does not count */
1330 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)) {
1331controller_fail:
1332 printk(KERN_ERR "HFC_multi ERROR, getting no 125us "
1333 "pulse. Seems that controller fails.\n");
1334 err = -EIO;
1335 goto out;
1336 }
1337 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
1338 printk(KERN_INFO "controller is PCM bus SLAVE "
1339 "(ignoring missing PCM clock)\n");
1340 } else {
1341 /* only one pcm master */
1342 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)
1343 && plxsd_master) {
1344 printk(KERN_ERR "HFC_multi ERROR, no clock "
1345 "on another Speech Design card found. "
1346 "Please be sure to connect PCM cable.\n");
1347 err = -EIO;
1348 goto out;
1349 }
1350 /* retry with master clock */
1351 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1352 spin_lock_irqsave(&plx_lock, plx_flags);
1353 plx_acc_32 = (u_int *)(hc->plx_membase +
1354 PLX_GPIOC);
1355 pv = readl(plx_acc_32);
1356 pv |= PLX_MASTER_EN | PLX_SLAVE_EN_N;
1357 pv |= PLX_SYNC_O_EN;
1358 writel(pv, plx_acc_32);
1359 spin_unlock_irqrestore(&plx_lock, plx_flags);
1360 if (debug & DEBUG_HFCMULTI_INIT)
1361 printk(KERN_WARNING "%s: master: PLX_GPIO"
1362 "=%x\n", __func__, pv);
1363 }
1364 hc->hw.r_pcm_md0 |= V_PCM_MD;
1365 HFC_outb(hc, R_PCM_MD0, hc->hw.r_pcm_md0 | 0x00);
1366 spin_unlock_irqrestore(&hc->lock, flags);
1367 set_current_state(TASK_UNINTERRUPTIBLE);
1368 schedule_timeout((HZ/100)?:1); /* Timeout min. 10ms */
1369 spin_lock_irqsave(&hc->lock, flags);
1370 val2 = HFC_inb(hc, R_F0_CNTL);
1371 val2 += HFC_inb(hc, R_F0_CNTH) << 8;
1372 if (debug & DEBUG_HFCMULTI_INIT)
1373 printk(KERN_DEBUG "HFC_multi F0_CNT %ld after "
1374 "10 ms (2nd try)\n", val2);
1375 if (val2 >= val+8) { /* 1 ms */
1376 test_and_set_bit(HFC_CHIP_PCM_MASTER,
1377 &hc->chip);
1378 printk(KERN_INFO "controller is PCM bus MASTER "
1379 "(auto detected)\n");
1380 } else
1381 goto controller_fail;
1382 }
1383 }
1384
1385 /* Release the DSP Reset */
1386 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1387 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip))
1388 plxsd_master = 1;
1389 spin_lock_irqsave(&plx_lock, plx_flags);
1390 plx_acc_32 = (u_int *)(hc->plx_membase+PLX_GPIOC);
1391 pv = readl(plx_acc_32);
1392 pv |= PLX_DSP_RES_N;
1393 writel(pv, plx_acc_32);
1394 spin_unlock_irqrestore(&plx_lock, plx_flags);
1395 if (debug & DEBUG_HFCMULTI_INIT)
1396 printk(KERN_WARNING "%s: reset off: PLX_GPIO=%x\n",
1397 __func__, pv);
1398 }
1399
1400 /* pcm id */
1401 if (hc->pcm)
1402 printk(KERN_INFO "controller has given PCM BUS ID %d\n",
1403 hc->pcm);
1404 else {
1405 if (test_bit(HFC_CHIP_PCM_MASTER, &hc->chip)
1406 || test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
1407 PCM_cnt++; /* SD has proprietary bridging */
1408 }
1409 hc->pcm = PCM_cnt;
1410 printk(KERN_INFO "controller has PCM BUS ID %d "
1411 "(auto selected)\n", hc->pcm);
1412 }
1413
1414 /* set up timer */
1415 HFC_outb(hc, R_TI_WD, poll_timer);
1416 hc->hw.r_irqmsk_misc |= V_TI_IRQMSK;
1417
1418 /*
1419 * set up 125us interrupt, only if function pointer is available
1420 * and module parameter timer is set
1421 */
1422 if (timer && hfc_interrupt && register_interrupt) {
1423 /* only one chip should use this interrupt */
1424 timer = 0;
1425 interrupt_registered = 1;
1426 hc->hw.r_irqmsk_misc |= V_PROC_IRQMSK;
1427 /* deactivate other interrupts in ztdummy */
1428 register_interrupt();
1429 }
1430
1431 /* set E1 state machine IRQ */
1432 if (hc->type == 1)
1433 hc->hw.r_irqmsk_misc |= V_STA_IRQMSK;
1434
1435 /* set DTMF detection */
1436 if (test_bit(HFC_CHIP_DTMF, &hc->chip)) {
1437 if (debug & DEBUG_HFCMULTI_INIT)
1438 printk(KERN_DEBUG "%s: enabling DTMF detection "
1439 "for all B-channel\n", __func__);
1440 hc->hw.r_dtmf = V_DTMF_EN | V_DTMF_STOP;
1441 if (test_bit(HFC_CHIP_ULAW, &hc->chip))
1442 hc->hw.r_dtmf |= V_ULAW_SEL;
1443 HFC_outb(hc, R_DTMF_N, 102 - 1);
1444 hc->hw.r_irqmsk_misc |= V_DTMF_IRQMSK;
1445 }
1446
1447 /* conference engine */
1448 if (test_bit(HFC_CHIP_ULAW, &hc->chip))
1449 r_conf_en = V_CONF_EN | V_ULAW;
1450 else
1451 r_conf_en = V_CONF_EN;
1452 HFC_outb(hc, R_CONF_EN, r_conf_en);
1453
1454 /* setting leds */
1455 switch (hc->leds) {
1456 case 1: /* HFC-E1 OEM */
1457 if (test_bit(HFC_CHIP_WATCHDOG, &hc->chip))
1458 HFC_outb(hc, R_GPIO_SEL, 0x32);
1459 else
1460 HFC_outb(hc, R_GPIO_SEL, 0x30);
1461
1462 HFC_outb(hc, R_GPIO_EN1, 0x0f);
1463 HFC_outb(hc, R_GPIO_OUT1, 0x00);
1464
1465 HFC_outb(hc, R_GPIO_EN0, V_GPIO_EN2 | V_GPIO_EN3);
1466 break;
1467
1468 case 2: /* HFC-4S OEM */
1469 case 3:
1470 HFC_outb(hc, R_GPIO_SEL, 0xf0);
1471 HFC_outb(hc, R_GPIO_EN1, 0xff);
1472 HFC_outb(hc, R_GPIO_OUT1, 0x00);
1473 break;
1474 }
1475
1476 /* set master clock */
1477 if (hc->masterclk >= 0) {
1478 if (debug & DEBUG_HFCMULTI_INIT)
1479 printk(KERN_DEBUG "%s: setting ST master clock "
1480 "to port %d (0..%d)\n",
1481 __func__, hc->masterclk, hc->ports-1);
1482 hc->hw.r_st_sync = hc->masterclk | V_AUTO_SYNC;
1483 HFC_outb(hc, R_ST_SYNC, hc->hw.r_st_sync);
1484 }
1485
1486 /* setting misc irq */
1487 HFC_outb(hc, R_IRQMSK_MISC, hc->hw.r_irqmsk_misc);
1488 if (debug & DEBUG_HFCMULTI_INIT)
1489 printk(KERN_DEBUG "r_irqmsk_misc.2: 0x%x\n",
1490 hc->hw.r_irqmsk_misc);
1491
1492 /* RAM access test */
1493 HFC_outb(hc, R_RAM_ADDR0, 0);
1494 HFC_outb(hc, R_RAM_ADDR1, 0);
1495 HFC_outb(hc, R_RAM_ADDR2, 0);
1496 for (i = 0; i < 256; i++) {
1497 HFC_outb_nodebug(hc, R_RAM_ADDR0, i);
1498 HFC_outb_nodebug(hc, R_RAM_DATA, ((i*3)&0xff));
1499 }
1500 for (i = 0; i < 256; i++) {
1501 HFC_outb_nodebug(hc, R_RAM_ADDR0, i);
1502 HFC_inb_nodebug(hc, R_RAM_DATA);
1503 rval = HFC_inb_nodebug(hc, R_INT_DATA);
1504 if (rval != ((i * 3) & 0xff)) {
1505 printk(KERN_DEBUG
1506 "addr:%x val:%x should:%x\n", i, rval,
1507 (i * 3) & 0xff);
1508 err++;
1509 }
1510 }
1511 if (err) {
1512 printk(KERN_DEBUG "aborting - %d RAM access errors\n", err);
1513 err = -EIO;
1514 goto out;
1515 }
1516
1517 if (debug & DEBUG_HFCMULTI_INIT)
1518 printk(KERN_DEBUG "%s: done\n", __func__);
1519out:
1520 spin_unlock_irqrestore(&hc->lock, flags);
1521 return err;
1522}
1523
1524
1525/*
1526 * control the watchdog
1527 */
1528static void
1529hfcmulti_watchdog(struct hfc_multi *hc)
1530{
1531 hc->wdcount++;
1532
1533 if (hc->wdcount > 10) {
1534 hc->wdcount = 0;
1535 hc->wdbyte = hc->wdbyte == V_GPIO_OUT2 ?
1536 V_GPIO_OUT3 : V_GPIO_OUT2;
1537
1538 /* printk("Sending Watchdog Kill %x\n",hc->wdbyte); */
1539 HFC_outb(hc, R_GPIO_EN0, V_GPIO_EN2 | V_GPIO_EN3);
1540 HFC_outb(hc, R_GPIO_OUT0, hc->wdbyte);
1541 }
1542}
1543
1544
1545
1546/*
1547 * output leds
1548 */
1549static void
1550hfcmulti_leds(struct hfc_multi *hc)
1551{
1552 unsigned long lled;
1553 unsigned long leddw;
1554 int i, state, active, leds;
1555 struct dchannel *dch;
1556 int led[4];
1557
1558 hc->ledcount += poll;
1559 if (hc->ledcount > 4096) {
1560 hc->ledcount -= 4096;
1561 hc->ledstate = 0xAFFEAFFE;
1562 }
1563
1564 switch (hc->leds) {
1565 case 1: /* HFC-E1 OEM */
1566 /* 2 red blinking: NT mode deactivate
1567 * 2 red steady: TE mode deactivate
1568 * left green: L1 active
1569 * left red: frame sync, but no L1
1570 * right green: L2 active
1571 */
1572 if (hc->chan[hc->dslot].sync != 2) { /* no frame sync */
1573 if (hc->chan[hc->dslot].dch->dev.D.protocol
1574 != ISDN_P_NT_E1) {
1575 led[0] = 1;
1576 led[1] = 1;
1577 } else if (hc->ledcount>>11) {
1578 led[0] = 1;
1579 led[1] = 1;
1580 } else {
1581 led[0] = 0;
1582 led[1] = 0;
1583 }
1584 led[2] = 0;
1585 led[3] = 0;
1586 } else { /* with frame sync */
1587 /* TODO make it work */
1588 led[0] = 0;
1589 led[1] = 0;
1590 led[2] = 0;
1591 led[3] = 1;
1592 }
1593 leds = (led[0] | (led[1]<<2) | (led[2]<<1) | (led[3]<<3))^0xF;
1594 /* leds are inverted */
1595 if (leds != (int)hc->ledstate) {
1596 HFC_outb_nodebug(hc, R_GPIO_OUT1, leds);
1597 hc->ledstate = leds;
1598 }
1599 break;
1600
1601 case 2: /* HFC-4S OEM */
1602 /* red blinking = PH_DEACTIVATE NT Mode
1603 * red steady = PH_DEACTIVATE TE Mode
1604 * green steady = PH_ACTIVATE
1605 */
1606 for (i = 0; i < 4; i++) {
1607 state = 0;
1608 active = -1;
1609 dch = hc->chan[(i << 2) | 2].dch;
1610 if (dch) {
1611 state = dch->state;
1612 if (dch->dev.D.protocol == ISDN_P_NT_S0)
1613 active = 3;
1614 else
1615 active = 7;
1616 }
1617 if (state) {
1618 if (state == active) {
1619 led[i] = 1; /* led green */
1620 } else
1621 if (dch->dev.D.protocol == ISDN_P_TE_S0)
1622 /* TE mode: led red */
1623 led[i] = 2;
1624 else
1625 if (hc->ledcount>>11)
1626 /* led red */
1627 led[i] = 2;
1628 else
1629 /* led off */
1630 led[i] = 0;
1631 } else
1632 led[i] = 0; /* led off */
1633 }
1634 if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
1635 leds = 0;
1636 for (i = 0; i < 4; i++) {
1637 if (led[i] == 1) {
1638 /*green*/
1639 leds |= (0x2 << (i * 2));
1640 } else if (led[i] == 2) {
1641 /*red*/
1642 leds |= (0x1 << (i * 2));
1643 }
1644 }
1645 if (leds != (int)hc->ledstate) {
1646 vpm_out(hc, 0, 0x1a8 + 3, leds);
1647 hc->ledstate = leds;
1648 }
1649 } else {
1650 leds = ((led[3] > 0) << 0) | ((led[1] > 0) << 1) |
1651 ((led[0] > 0) << 2) | ((led[2] > 0) << 3) |
1652 ((led[3] & 1) << 4) | ((led[1] & 1) << 5) |
1653 ((led[0] & 1) << 6) | ((led[2] & 1) << 7);
1654 if (leds != (int)hc->ledstate) {
1655 HFC_outb_nodebug(hc, R_GPIO_EN1, leds & 0x0F);
1656 HFC_outb_nodebug(hc, R_GPIO_OUT1, leds >> 4);
1657 hc->ledstate = leds;
1658 }
1659 }
1660 break;
1661
1662 case 3: /* HFC 1S/2S Beronet */
1663 /* red blinking = PH_DEACTIVATE NT Mode
1664 * red steady = PH_DEACTIVATE TE Mode
1665 * green steady = PH_ACTIVATE
1666 */
1667 for (i = 0; i < 2; i++) {
1668 state = 0;
1669 active = -1;
1670 dch = hc->chan[(i << 2) | 2].dch;
1671 if (dch) {
1672 state = dch->state;
1673 if (dch->dev.D.protocol == ISDN_P_NT_S0)
1674 active = 3;
1675 else
1676 active = 7;
1677 }
1678 if (state) {
1679 if (state == active) {
1680 led[i] = 1; /* led green */
1681 } else
1682 if (dch->dev.D.protocol == ISDN_P_TE_S0)
1683 /* TE mode: led red */
1684 led[i] = 2;
1685 else
1686 if (hc->ledcount >> 11)
1687 /* led red */
1688 led[i] = 2;
1689 else
1690 /* led off */
1691 led[i] = 0;
1692 } else
1693 led[i] = 0; /* led off */
1694 }
1695
1696
1697 leds = (led[0] > 0) | ((led[1] > 0)<<1) | ((led[0]&1)<<2)
1698 | ((led[1]&1)<<3);
1699 if (leds != (int)hc->ledstate) {
1700 HFC_outb_nodebug(hc, R_GPIO_EN1,
1701 ((led[0] > 0) << 2) | ((led[1] > 0) << 3));
1702 HFC_outb_nodebug(hc, R_GPIO_OUT1,
1703 ((led[0] & 1) << 2) | ((led[1] & 1) << 3));
1704 hc->ledstate = leds;
1705 }
1706 break;
1707 case 8: /* HFC 8S+ Beronet */
1708 lled = 0;
1709
1710 for (i = 0; i < 8; i++) {
1711 state = 0;
1712 active = -1;
1713 dch = hc->chan[(i << 2) | 2].dch;
1714 if (dch) {
1715 state = dch->state;
1716 if (dch->dev.D.protocol == ISDN_P_NT_S0)
1717 active = 3;
1718 else
1719 active = 7;
1720 }
1721 if (state) {
1722 if (state == active) {
1723 lled |= 0 << i;
1724 } else
1725 if (hc->ledcount >> 11)
1726 lled |= 0 << i;
1727 else
1728 lled |= 1 << i;
1729 } else
1730 lled |= 1 << i;
1731 }
1732 leddw = lled << 24 | lled << 16 | lled << 8 | lled;
1733 if (leddw != hc->ledstate) {
1734 /* HFC_outb(hc, R_BRG_PCM_CFG, 1);
1735 HFC_outb(c, R_BRG_PCM_CFG, (0x0 << 6) | 0x3); */
1736 /* was _io before */
1737 HFC_outb_nodebug(hc, R_BRG_PCM_CFG, 1 | V_PCM_CLK);
1738 outw(0x4000, hc->pci_iobase + 4);
1739 outl(leddw, hc->pci_iobase);
1740 HFC_outb_nodebug(hc, R_BRG_PCM_CFG, V_PCM_CLK);
1741 hc->ledstate = leddw;
1742 }
1743 break;
1744 }
1745}
1746/*
1747 * read dtmf coefficients
1748 */
1749
1750static void
1751hfcmulti_dtmf(struct hfc_multi *hc)
1752{
1753 s32 *coeff;
1754 u_int mantissa;
1755 int co, ch;
1756 struct bchannel *bch = NULL;
1757 u8 exponent;
1758 int dtmf = 0;
1759 int addr;
1760 u16 w_float;
1761 struct sk_buff *skb;
1762 struct mISDNhead *hh;
1763
1764 if (debug & DEBUG_HFCMULTI_DTMF)
1765 printk(KERN_DEBUG "%s: dtmf detection irq\n", __func__);
1766 for (ch = 0; ch <= 31; ch++) {
1767 /* only process enabled B-channels */
1768 bch = hc->chan[ch].bch;
1769 if (!bch)
1770 continue;
1771 if (!hc->created[hc->chan[ch].port])
1772 continue;
1773 if (!test_bit(FLG_TRANSPARENT, &bch->Flags))
1774 continue;
1775 if (debug & DEBUG_HFCMULTI_DTMF)
1776 printk(KERN_DEBUG "%s: dtmf channel %d:",
1777 __func__, ch);
1778 coeff = &(hc->chan[ch].coeff[hc->chan[ch].coeff_count * 16]);
1779 dtmf = 1;
1780 for (co = 0; co < 8; co++) {
1781 /* read W(n-1) coefficient */
1782 addr = hc->DTMFbase + ((co<<7) | (ch<<2));
1783 HFC_outb_nodebug(hc, R_RAM_ADDR0, addr);
1784 HFC_outb_nodebug(hc, R_RAM_ADDR1, addr>>8);
1785 HFC_outb_nodebug(hc, R_RAM_ADDR2, (addr>>16)
1786 | V_ADDR_INC);
1787 w_float = HFC_inb_nodebug(hc, R_RAM_DATA);
1788 w_float |= (HFC_inb_nodebug(hc, R_RAM_DATA) << 8);
1789 if (debug & DEBUG_HFCMULTI_DTMF)
1790 printk(" %04x", w_float);
1791
1792 /* decode float (see chip doc) */
1793 mantissa = w_float & 0x0fff;
1794 if (w_float & 0x8000)
1795 mantissa |= 0xfffff000;
1796 exponent = (w_float>>12) & 0x7;
1797 if (exponent) {
1798 mantissa ^= 0x1000;
1799 mantissa <<= (exponent-1);
1800 }
1801
1802 /* store coefficient */
1803 coeff[co<<1] = mantissa;
1804
1805 /* read W(n) coefficient */
1806 w_float = HFC_inb_nodebug(hc, R_RAM_DATA);
1807 w_float |= (HFC_inb_nodebug(hc, R_RAM_DATA) << 8);
1808 if (debug & DEBUG_HFCMULTI_DTMF)
1809 printk(" %04x", w_float);
1810
1811 /* decode float (see chip doc) */
1812 mantissa = w_float & 0x0fff;
1813 if (w_float & 0x8000)
1814 mantissa |= 0xfffff000;
1815 exponent = (w_float>>12) & 0x7;
1816 if (exponent) {
1817 mantissa ^= 0x1000;
1818 mantissa <<= (exponent-1);
1819 }
1820
1821 /* store coefficient */
1822 coeff[(co<<1)|1] = mantissa;
1823 }
1824 if (debug & DEBUG_HFCMULTI_DTMF)
1825 printk("%s: DTMF ready %08x %08x %08x %08x "
1826 "%08x %08x %08x %08x\n", __func__,
1827 coeff[0], coeff[1], coeff[2], coeff[3],
1828 coeff[4], coeff[5], coeff[6], coeff[7]);
1829 hc->chan[ch].coeff_count++;
1830 if (hc->chan[ch].coeff_count == 8) {
1831 hc->chan[ch].coeff_count = 0;
1832 skb = mI_alloc_skb(512, GFP_ATOMIC);
1833 if (!skb) {
1834 printk(KERN_WARNING "%s: No memory for skb\n",
1835 __func__);
1836 continue;
1837 }
1838 hh = mISDN_HEAD_P(skb);
1839 hh->prim = PH_CONTROL_IND;
1840 hh->id = DTMF_HFC_COEF;
1841 memcpy(skb_put(skb, 512), hc->chan[ch].coeff, 512);
1842 recv_Bchannel_skb(bch, skb);
1843 }
1844 }
1845
1846 /* restart DTMF processing */
1847 hc->dtmf = dtmf;
1848 if (dtmf)
1849 HFC_outb_nodebug(hc, R_DTMF, hc->hw.r_dtmf | V_RST_DTMF);
1850}
1851
1852
1853/*
1854 * fill fifo as much as possible
1855 */
1856
1857static void
1858hfcmulti_tx(struct hfc_multi *hc, int ch)
1859{
1860 int i, ii, temp, len = 0;
1861 int Zspace, z1, z2; /* must be int for calculation */
1862 int Fspace, f1, f2;
1863 u_char *d;
1864 int *txpending, slot_tx;
1865 struct bchannel *bch;
1866 struct dchannel *dch;
1867 struct sk_buff **sp = NULL;
1868 int *idxp;
1869
1870 bch = hc->chan[ch].bch;
1871 dch = hc->chan[ch].dch;
1872 if ((!dch) && (!bch))
1873 return;
1874
1875 txpending = &hc->chan[ch].txpending;
1876 slot_tx = hc->chan[ch].slot_tx;
1877 if (dch) {
1878 if (!test_bit(FLG_ACTIVE, &dch->Flags))
1879 return;
1880 sp = &dch->tx_skb;
1881 idxp = &dch->tx_idx;
1882 } else {
1883 if (!test_bit(FLG_ACTIVE, &bch->Flags))
1884 return;
1885 sp = &bch->tx_skb;
1886 idxp = &bch->tx_idx;
1887 }
1888 if (*sp)
1889 len = (*sp)->len;
1890
1891 if ((!len) && *txpending != 1)
1892 return; /* no data */
1893
1894 if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
1895 (hc->chan[ch].protocol == ISDN_P_B_RAW) &&
1896 (hc->chan[ch].slot_rx < 0) &&
1897 (hc->chan[ch].slot_tx < 0))
1898 HFC_outb_nodebug(hc, R_FIFO, 0x20 | (ch << 1));
1899 else
1900 HFC_outb_nodebug(hc, R_FIFO, ch << 1);
1901 HFC_wait_nodebug(hc);
1902
1903 if (*txpending == 2) {
1904 /* reset fifo */
1905 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
1906 HFC_wait_nodebug(hc);
1907 HFC_outb(hc, A_SUBCH_CFG, 0);
1908 *txpending = 1;
1909 }
1910next_frame:
1911 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
1912 f1 = HFC_inb_nodebug(hc, A_F1);
1913 f2 = HFC_inb_nodebug(hc, A_F2);
1914 while (f2 != (temp = HFC_inb_nodebug(hc, A_F2))) {
1915 if (debug & DEBUG_HFCMULTI_FIFO)
1916 printk(KERN_DEBUG
1917 "%s(card %d): reread f2 because %d!=%d\n",
1918 __func__, hc->id + 1, temp, f2);
1919 f2 = temp; /* repeat until F2 is equal */
1920 }
1921 Fspace = f2 - f1 - 1;
1922 if (Fspace < 0)
1923 Fspace += hc->Flen;
1924 /*
1925 * Old FIFO handling doesn't give us the current Z2 read
1926 * pointer, so we cannot send the next frame before the fifo
1927 * is empty. It makes no difference except for a slightly
1928 * lower performance.
1929 */
1930 if (test_bit(HFC_CHIP_REVISION0, &hc->chip)) {
1931 if (f1 != f2)
1932 Fspace = 0;
1933 else
1934 Fspace = 1;
1935 }
1936 /* one frame only for ST D-channels, to allow resending */
1937 if (hc->type != 1 && dch) {
1938 if (f1 != f2)
1939 Fspace = 0;
1940 }
1941 /* F-counter full condition */
1942 if (Fspace == 0)
1943 return;
1944 }
1945 z1 = HFC_inw_nodebug(hc, A_Z1) - hc->Zmin;
1946 z2 = HFC_inw_nodebug(hc, A_Z2) - hc->Zmin;
1947 while (z2 != (temp = (HFC_inw_nodebug(hc, A_Z2) - hc->Zmin))) {
1948 if (debug & DEBUG_HFCMULTI_FIFO)
1949 printk(KERN_DEBUG "%s(card %d): reread z2 because "
1950 "%d!=%d\n", __func__, hc->id + 1, temp, z2);
1951 z2 = temp; /* repeat unti Z2 is equal */
1952 }
1953 Zspace = z2 - z1;
1954 if (Zspace <= 0)
1955 Zspace += hc->Zlen;
1956 Zspace -= 4; /* keep not too full, so pointers will not overrun */
1957 /* fill transparent data only to maxinum transparent load (minus 4) */
1958 if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags))
1959 Zspace = Zspace - hc->Zlen + hc->max_trans;
1960 if (Zspace <= 0) /* no space of 4 bytes */
1961 return;
1962
1963 /* if no data */
1964 if (!len) {
1965 if (z1 == z2) { /* empty */
1966 /* if done with FIFO audio data during PCM connection */
1967 if (bch && (!test_bit(FLG_HDLC, &bch->Flags)) &&
1968 *txpending && slot_tx >= 0) {
1969 if (debug & DEBUG_HFCMULTI_MODE)
1970 printk(KERN_DEBUG
1971 "%s: reconnecting PCM due to no "
1972 "more FIFO data: channel %d "
1973 "slot_tx %d\n",
1974 __func__, ch, slot_tx);
1975 /* connect slot */
1976 HFC_outb(hc, A_CON_HDLC, 0xc0 | 0x00 |
1977 V_HDLC_TRP | V_IFF);
1978 HFC_outb_nodebug(hc, R_FIFO, ch<<1 | 1);
1979 HFC_wait_nodebug(hc);
1980 HFC_outb(hc, A_CON_HDLC, 0xc0 | 0x00 |
1981 V_HDLC_TRP | V_IFF);
1982 HFC_outb_nodebug(hc, R_FIFO, ch<<1);
1983 HFC_wait_nodebug(hc);
1984 }
1985 *txpending = 0;
1986 }
1987 return; /* no data */
1988 }
1989
1990 /* if audio data and connected slot */
1991 if (bch && (!test_bit(FLG_HDLC, &bch->Flags)) && (!*txpending)
1992 && slot_tx >= 0) {
1993 if (debug & DEBUG_HFCMULTI_MODE)
1994 printk(KERN_DEBUG "%s: disconnecting PCM due to "
1995 "FIFO data: channel %d slot_tx %d\n",
1996 __func__, ch, slot_tx);
1997 /* disconnect slot */
1998 HFC_outb(hc, A_CON_HDLC, 0x80 | 0x00 | V_HDLC_TRP | V_IFF);
1999 HFC_outb_nodebug(hc, R_FIFO, ch<<1 | 1);
2000 HFC_wait_nodebug(hc);
2001 HFC_outb(hc, A_CON_HDLC, 0x80 | 0x00 | V_HDLC_TRP | V_IFF);
2002 HFC_outb_nodebug(hc, R_FIFO, ch<<1);
2003 HFC_wait_nodebug(hc);
2004 }
2005 *txpending = 1;
2006
2007 /* show activity */
2008 hc->activity[hc->chan[ch].port] = 1;
2009
2010 /* fill fifo to what we have left */
2011 ii = len;
2012 if (dch || test_bit(FLG_HDLC, &bch->Flags))
2013 temp = 1;
2014 else
2015 temp = 0;
2016 i = *idxp;
2017 d = (*sp)->data + i;
2018 if (ii - i > Zspace)
2019 ii = Zspace + i;
2020 if (debug & DEBUG_HFCMULTI_FIFO)
2021 printk(KERN_DEBUG "%s(card %d): fifo(%d) has %d bytes space "
2022 "left (z1=%04x, z2=%04x) sending %d of %d bytes %s\n",
2023 __func__, hc->id + 1, ch, Zspace, z1, z2, ii-i, len-i,
2024 temp ? "HDLC":"TRANS");
2025
2026
2027 /* Have to prep the audio data */
2028 hc->write_fifo(hc, d, ii - i);
2029 *idxp = ii;
2030
2031 /* if not all data has been written */
2032 if (ii != len) {
2033 /* NOTE: fifo is started by the calling function */
2034 return;
2035 }
2036
2037 /* if all data has been written, terminate frame */
2038 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
2039 /* increment f-counter */
2040 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_INC_F);
2041 HFC_wait_nodebug(hc);
2042 }
2043
2044 /* send confirm, since get_net_bframe will not do it with trans */
2045 if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags))
2046 confirm_Bsend(bch);
2047
2048 /* check for next frame */
2049 dev_kfree_skb(*sp);
2050 if (bch && get_next_bframe(bch)) { /* hdlc is confirmed here */
2051 len = (*sp)->len;
2052 goto next_frame;
2053 }
2054 if (dch && get_next_dframe(dch)) {
2055 len = (*sp)->len;
2056 goto next_frame;
2057 }
2058
2059 /*
2060 * now we have no more data, so in case of transparent,
2061 * we set the last byte in fifo to 'silence' in case we will get
2062 * no more data at all. this prevents sending an undefined value.
2063 */
2064 if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags))
2065 HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, silence);
2066}
2067
2068
2069/* NOTE: only called if E1 card is in active state */
2070static void
2071hfcmulti_rx(struct hfc_multi *hc, int ch)
2072{
2073 int temp;
2074 int Zsize, z1, z2 = 0; /* = 0, to make GCC happy */
2075 int f1 = 0, f2 = 0; /* = 0, to make GCC happy */
2076 int again = 0;
2077 struct bchannel *bch;
2078 struct dchannel *dch;
2079 struct sk_buff *skb, **sp = NULL;
2080 int maxlen;
2081
2082 bch = hc->chan[ch].bch;
2083 dch = hc->chan[ch].dch;
2084 if ((!dch) && (!bch))
2085 return;
2086 if (dch) {
2087 if (!test_bit(FLG_ACTIVE, &dch->Flags))
2088 return;
2089 sp = &dch->rx_skb;
2090 maxlen = dch->maxlen;
2091 } else {
2092 if (!test_bit(FLG_ACTIVE, &bch->Flags))
2093 return;
2094 sp = &bch->rx_skb;
2095 maxlen = bch->maxlen;
2096 }
2097next_frame:
2098 /* on first AND before getting next valid frame, R_FIFO must be written
2099 to. */
2100 if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
2101 (hc->chan[ch].protocol == ISDN_P_B_RAW) &&
2102 (hc->chan[ch].slot_rx < 0) &&
2103 (hc->chan[ch].slot_tx < 0))
2104 HFC_outb_nodebug(hc, R_FIFO, 0x20 | (ch<<1) | 1);
2105 else
2106 HFC_outb_nodebug(hc, R_FIFO, (ch<<1)|1);
2107 HFC_wait_nodebug(hc);
2108
2109 /* ignore if rx is off BUT change fifo (above) to start pending TX */
2110 if (hc->chan[ch].rx_off)
2111 return;
2112
2113 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
2114 f1 = HFC_inb_nodebug(hc, A_F1);
2115 while (f1 != (temp = HFC_inb_nodebug(hc, A_F1))) {
2116 if (debug & DEBUG_HFCMULTI_FIFO)
2117 printk(KERN_DEBUG
2118 "%s(card %d): reread f1 because %d!=%d\n",
2119 __func__, hc->id + 1, temp, f1);
2120 f1 = temp; /* repeat until F1 is equal */
2121 }
2122 f2 = HFC_inb_nodebug(hc, A_F2);
2123 }
2124 z1 = HFC_inw_nodebug(hc, A_Z1) - hc->Zmin;
2125 while (z1 != (temp = (HFC_inw_nodebug(hc, A_Z1) - hc->Zmin))) {
2126 if (debug & DEBUG_HFCMULTI_FIFO)
2127 printk(KERN_DEBUG "%s(card %d): reread z2 because "
2128 "%d!=%d\n", __func__, hc->id + 1, temp, z2);
2129 z1 = temp; /* repeat until Z1 is equal */
2130 }
2131 z2 = HFC_inw_nodebug(hc, A_Z2) - hc->Zmin;
2132 Zsize = z1 - z2;
2133 if ((dch || test_bit(FLG_HDLC, &bch->Flags)) && f1 != f2)
2134 /* complete hdlc frame */
2135 Zsize++;
2136 if (Zsize < 0)
2137 Zsize += hc->Zlen;
2138 /* if buffer is empty */
2139 if (Zsize <= 0)
2140 return;
2141
2142 if (*sp == NULL) {
2143 *sp = mI_alloc_skb(maxlen + 3, GFP_ATOMIC);
2144 if (*sp == NULL) {
2145 printk(KERN_DEBUG "%s: No mem for rx_skb\n",
2146 __func__);
2147 return;
2148 }
2149 }
2150 /* show activity */
2151 hc->activity[hc->chan[ch].port] = 1;
2152
2153 /* empty fifo with what we have */
2154 if (dch || test_bit(FLG_HDLC, &bch->Flags)) {
2155 if (debug & DEBUG_HFCMULTI_FIFO)
2156 printk(KERN_DEBUG "%s(card %d): fifo(%d) reading %d "
2157 "bytes (z1=%04x, z2=%04x) HDLC %s (f1=%d, f2=%d) "
2158 "got=%d (again %d)\n", __func__, hc->id + 1, ch,
2159 Zsize, z1, z2, (f1 == f2) ? "fragment" : "COMPLETE",
2160 f1, f2, Zsize + (*sp)->len, again);
2161 /* HDLC */
2162 if ((Zsize + (*sp)->len) > (maxlen + 3)) {
2163 if (debug & DEBUG_HFCMULTI_FIFO)
2164 printk(KERN_DEBUG
2165 "%s(card %d): hdlc-frame too large.\n",
2166 __func__, hc->id + 1);
2167 skb_trim(*sp, 0);
2168 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
2169 HFC_wait_nodebug(hc);
2170 return;
2171 }
2172
2173 hc->read_fifo(hc, skb_put(*sp, Zsize), Zsize);
2174
2175 if (f1 != f2) {
2176 /* increment Z2,F2-counter */
2177 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_INC_F);
2178 HFC_wait_nodebug(hc);
2179 /* check size */
2180 if ((*sp)->len < 4) {
2181 if (debug & DEBUG_HFCMULTI_FIFO)
2182 printk(KERN_DEBUG
2183 "%s(card %d): Frame below minimum "
2184 "size\n", __func__, hc->id + 1);
2185 skb_trim(*sp, 0);
2186 goto next_frame;
2187 }
2188 /* there is at least one complete frame, check crc */
2189 if ((*sp)->data[(*sp)->len - 1]) {
2190 if (debug & DEBUG_HFCMULTI_CRC)
2191 printk(KERN_DEBUG
2192 "%s: CRC-error\n", __func__);
2193 skb_trim(*sp, 0);
2194 goto next_frame;
2195 }
2196 skb_trim(*sp, (*sp)->len - 3);
2197 if ((*sp)->len < MISDN_COPY_SIZE) {
2198 skb = *sp;
2199 *sp = mI_alloc_skb(skb->len, GFP_ATOMIC);
2200 if (*sp) {
2201 memcpy(skb_put(*sp, skb->len),
2202 skb->data, skb->len);
2203 skb_trim(skb, 0);
2204 } else {
2205 printk(KERN_DEBUG "%s: No mem\n",
2206 __func__);
2207 *sp = skb;
2208 skb = NULL;
2209 }
2210 } else {
2211 skb = NULL;
2212 }
2213 if (debug & DEBUG_HFCMULTI_FIFO) {
2214 printk(KERN_DEBUG "%s(card %d):",
2215 __func__, hc->id + 1);
2216 temp = 0;
2217 while (temp < (*sp)->len)
2218 printk(" %02x", (*sp)->data[temp++]);
2219 printk("\n");
2220 }
2221 if (dch)
2222 recv_Dchannel(dch);
2223 else
2224 recv_Bchannel(bch);
2225 *sp = skb;
2226 again++;
2227 goto next_frame;
2228 }
2229 /* there is an incomplete frame */
2230 } else {
2231 /* transparent */
2232 if (Zsize > skb_tailroom(*sp))
2233 Zsize = skb_tailroom(*sp);
2234 hc->read_fifo(hc, skb_put(*sp, Zsize), Zsize);
2235 if (((*sp)->len) < MISDN_COPY_SIZE) {
2236 skb = *sp;
2237 *sp = mI_alloc_skb(skb->len, GFP_ATOMIC);
2238 if (*sp) {
2239 memcpy(skb_put(*sp, skb->len),
2240 skb->data, skb->len);
2241 skb_trim(skb, 0);
2242 } else {
2243 printk(KERN_DEBUG "%s: No mem\n", __func__);
2244 *sp = skb;
2245 skb = NULL;
2246 }
2247 } else {
2248 skb = NULL;
2249 }
2250 if (debug & DEBUG_HFCMULTI_FIFO)
2251 printk(KERN_DEBUG
2252 "%s(card %d): fifo(%d) reading %d bytes "
2253 "(z1=%04x, z2=%04x) TRANS\n",
2254 __func__, hc->id + 1, ch, Zsize, z1, z2);
2255 /* only bch is transparent */
2256 recv_Bchannel(bch);
2257 *sp = skb;
2258 }
2259}
2260
2261
2262/*
2263 * Interrupt handler
2264 */
2265static void
2266signal_state_up(struct dchannel *dch, int info, char *msg)
2267{
2268 struct sk_buff *skb;
2269 int id, data = info;
2270
2271 if (debug & DEBUG_HFCMULTI_STATE)
2272 printk(KERN_DEBUG "%s: %s\n", __func__, msg);
2273
2274 id = TEI_SAPI | (GROUP_TEI << 8); /* manager address */
2275
2276 skb = _alloc_mISDN_skb(MPH_INFORMATION_IND, id, sizeof(data), &data,
2277 GFP_ATOMIC);
2278 if (!skb)
2279 return;
2280 recv_Dchannel_skb(dch, skb);
2281}
2282
2283static inline void
2284handle_timer_irq(struct hfc_multi *hc)
2285{
2286 int ch, temp;
2287 struct dchannel *dch;
2288 u_long flags;
2289
2290 /* process queued resync jobs */
2291 if (hc->e1_resync) {
2292 /* lock, so e1_resync gets not changed */
2293 spin_lock_irqsave(&HFClock, flags);
2294 if (hc->e1_resync & 1) {
2295 if (debug & DEBUG_HFCMULTI_PLXSD)
2296 printk(KERN_DEBUG "Enable SYNC_I\n");
2297 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC);
2298 /* disable JATT, if RX_SYNC is set */
2299 if (test_bit(HFC_CHIP_RX_SYNC, &hc->chip))
2300 HFC_outb(hc, R_SYNC_OUT, V_SYNC_E1_RX);
2301 }
2302 if (hc->e1_resync & 2) {
2303 if (debug & DEBUG_HFCMULTI_PLXSD)
2304 printk(KERN_DEBUG "Enable jatt PLL\n");
2305 HFC_outb(hc, R_SYNC_CTRL, V_SYNC_OFFS);
2306 }
2307 if (hc->e1_resync & 4) {
2308 if (debug & DEBUG_HFCMULTI_PLXSD)
2309 printk(KERN_DEBUG
2310 "Enable QUARTZ for HFC-E1\n");
2311 /* set jatt to quartz */
2312 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC
2313 | V_JATT_OFF);
2314 /* switch to JATT, in case it is not already */
2315 HFC_outb(hc, R_SYNC_OUT, 0);
2316 }
2317 hc->e1_resync = 0;
2318 spin_unlock_irqrestore(&HFClock, flags);
2319 }
2320
2321 if (hc->type != 1 || hc->e1_state == 1)
2322 for (ch = 0; ch <= 31; ch++) {
2323 if (hc->created[hc->chan[ch].port]) {
2324 hfcmulti_tx(hc, ch);
2325 /* fifo is started when switching to rx-fifo */
2326 hfcmulti_rx(hc, ch);
2327 if (hc->chan[ch].dch &&
2328 hc->chan[ch].nt_timer > -1) {
2329 dch = hc->chan[ch].dch;
2330 if (!(--hc->chan[ch].nt_timer)) {
2331 schedule_event(dch,
2332 FLG_PHCHANGE);
2333 if (debug &
2334 DEBUG_HFCMULTI_STATE)
2335 printk(KERN_DEBUG
2336 "%s: nt_timer at "
2337 "state %x\n",
2338 __func__,
2339 dch->state);
2340 }
2341 }
2342 }
2343 }
2344 if (hc->type == 1 && hc->created[0]) {
2345 dch = hc->chan[hc->dslot].dch;
2346 if (test_bit(HFC_CFG_REPORT_LOS, &hc->chan[hc->dslot].cfg)) {
2347 /* LOS */
2348 temp = HFC_inb_nodebug(hc, R_SYNC_STA) & V_SIG_LOS;
2349 if (!temp && hc->chan[hc->dslot].los)
2350 signal_state_up(dch, L1_SIGNAL_LOS_ON,
2351 "LOS detected");
2352 if (temp && !hc->chan[hc->dslot].los)
2353 signal_state_up(dch, L1_SIGNAL_LOS_OFF,
2354 "LOS gone");
2355 hc->chan[hc->dslot].los = temp;
2356 }
2357 if (test_bit(HFC_CFG_REPORT_AIS, &hc->chan[hc->dslot].cfg)) {
2358 /* AIS */
2359 temp = HFC_inb_nodebug(hc, R_SYNC_STA) & V_AIS;
2360 if (!temp && hc->chan[hc->dslot].ais)
2361 signal_state_up(dch, L1_SIGNAL_AIS_ON,
2362 "AIS detected");
2363 if (temp && !hc->chan[hc->dslot].ais)
2364 signal_state_up(dch, L1_SIGNAL_AIS_OFF,
2365 "AIS gone");
2366 hc->chan[hc->dslot].ais = temp;
2367 }
2368 if (test_bit(HFC_CFG_REPORT_SLIP, &hc->chan[hc->dslot].cfg)) {
2369 /* SLIP */
2370 temp = HFC_inb_nodebug(hc, R_SLIP) & V_FOSLIP_RX;
2371 if (!temp && hc->chan[hc->dslot].slip_rx)
2372 signal_state_up(dch, L1_SIGNAL_SLIP_RX,
2373 " bit SLIP detected RX");
2374 hc->chan[hc->dslot].slip_rx = temp;
2375 temp = HFC_inb_nodebug(hc, R_SLIP) & V_FOSLIP_TX;
2376 if (!temp && hc->chan[hc->dslot].slip_tx)
2377 signal_state_up(dch, L1_SIGNAL_SLIP_TX,
2378 " bit SLIP detected TX");
2379 hc->chan[hc->dslot].slip_tx = temp;
2380 }
2381 if (test_bit(HFC_CFG_REPORT_RDI, &hc->chan[hc->dslot].cfg)) {
2382 /* RDI */
2383 temp = HFC_inb_nodebug(hc, R_RX_SL0_0) & V_A;
2384 if (!temp && hc->chan[hc->dslot].rdi)
2385 signal_state_up(dch, L1_SIGNAL_RDI_ON,
2386 "RDI detected");
2387 if (temp && !hc->chan[hc->dslot].rdi)
2388 signal_state_up(dch, L1_SIGNAL_RDI_OFF,
2389 "RDI gone");
2390 hc->chan[hc->dslot].rdi = temp;
2391 }
2392 temp = HFC_inb_nodebug(hc, R_JATT_DIR);
2393 switch (hc->chan[hc->dslot].sync) {
2394 case 0:
2395 if ((temp & 0x60) == 0x60) {
2396 if (debug & DEBUG_HFCMULTI_SYNC)
2397 printk(KERN_DEBUG
2398 "%s: (id=%d) E1 now "
2399 "in clock sync\n",
2400 __func__, hc->id);
2401 HFC_outb(hc, R_RX_OFF,
2402 hc->chan[hc->dslot].jitter | V_RX_INIT);
2403 HFC_outb(hc, R_TX_OFF,
2404 hc->chan[hc->dslot].jitter | V_RX_INIT);
2405 hc->chan[hc->dslot].sync = 1;
2406 goto check_framesync;
2407 }
2408 break;
2409 case 1:
2410 if ((temp & 0x60) != 0x60) {
2411 if (debug & DEBUG_HFCMULTI_SYNC)
2412 printk(KERN_DEBUG
2413 "%s: (id=%d) E1 "
2414 "lost clock sync\n",
2415 __func__, hc->id);
2416 hc->chan[hc->dslot].sync = 0;
2417 break;
2418 }
2419check_framesync:
2420 temp = HFC_inb_nodebug(hc, R_SYNC_STA);
2421 if (temp == 0x27) {
2422 if (debug & DEBUG_HFCMULTI_SYNC)
2423 printk(KERN_DEBUG
2424 "%s: (id=%d) E1 "
2425 "now in frame sync\n",
2426 __func__, hc->id);
2427 hc->chan[hc->dslot].sync = 2;
2428 }
2429 break;
2430 case 2:
2431 if ((temp & 0x60) != 0x60) {
2432 if (debug & DEBUG_HFCMULTI_SYNC)
2433 printk(KERN_DEBUG
2434 "%s: (id=%d) E1 lost "
2435 "clock & frame sync\n",
2436 __func__, hc->id);
2437 hc->chan[hc->dslot].sync = 0;
2438 break;
2439 }
2440 temp = HFC_inb_nodebug(hc, R_SYNC_STA);
2441 if (temp != 0x27) {
2442 if (debug & DEBUG_HFCMULTI_SYNC)
2443 printk(KERN_DEBUG
2444 "%s: (id=%d) E1 "
2445 "lost frame sync\n",
2446 __func__, hc->id);
2447 hc->chan[hc->dslot].sync = 1;
2448 }
2449 break;
2450 }
2451 }
2452
2453 if (test_bit(HFC_CHIP_WATCHDOG, &hc->chip))
2454 hfcmulti_watchdog(hc);
2455
2456 if (hc->leds)
2457 hfcmulti_leds(hc);
2458}
2459
2460static void
2461ph_state_irq(struct hfc_multi *hc, u_char r_irq_statech)
2462{
2463 struct dchannel *dch;
2464 int ch;
2465 int active;
2466 u_char st_status, temp;
2467
2468 /* state machine */
2469 for (ch = 0; ch <= 31; ch++) {
2470 if (hc->chan[ch].dch) {
2471 dch = hc->chan[ch].dch;
2472 if (r_irq_statech & 1) {
2473 HFC_outb_nodebug(hc, R_ST_SEL,
2474 hc->chan[ch].port);
2475 /* undocumented: delay after R_ST_SEL */
2476 udelay(1);
2477 /* undocumented: status changes during read */
2478 st_status = HFC_inb_nodebug(hc, A_ST_RD_STATE);
2479 while (st_status != (temp =
2480 HFC_inb_nodebug(hc, A_ST_RD_STATE))) {
2481 if (debug & DEBUG_HFCMULTI_STATE)
2482 printk(KERN_DEBUG "%s: reread "
2483 "STATE because %d!=%d\n",
2484 __func__, temp,
2485 st_status);
2486 st_status = temp; /* repeat */
2487 }
2488
2489 /* Speech Design TE-sync indication */
2490 if (test_bit(HFC_CHIP_PLXSD, &hc->chip) &&
2491 dch->dev.D.protocol == ISDN_P_TE_S0) {
2492 if (st_status & V_FR_SYNC_ST)
2493 hc->syncronized |=
2494 (1 << hc->chan[ch].port);
2495 else
2496 hc->syncronized &=
2497 ~(1 << hc->chan[ch].port);
2498 }
2499 dch->state = st_status & 0x0f;
2500 if (dch->dev.D.protocol == ISDN_P_NT_S0)
2501 active = 3;
2502 else
2503 active = 7;
2504 if (dch->state == active) {
2505 HFC_outb_nodebug(hc, R_FIFO,
2506 (ch << 1) | 1);
2507 HFC_wait_nodebug(hc);
2508 HFC_outb_nodebug(hc,
2509 R_INC_RES_FIFO, V_RES_F);
2510 HFC_wait_nodebug(hc);
2511 dch->tx_idx = 0;
2512 }
2513 schedule_event(dch, FLG_PHCHANGE);
2514 if (debug & DEBUG_HFCMULTI_STATE)
2515 printk(KERN_DEBUG
2516 "%s: S/T newstate %x port %d\n",
2517 __func__, dch->state,
2518 hc->chan[ch].port);
2519 }
2520 r_irq_statech >>= 1;
2521 }
2522 }
2523 if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
2524 plxsd_checksync(hc, 0);
2525}
2526
2527static void
2528fifo_irq(struct hfc_multi *hc, int block)
2529{
2530 int ch, j;
2531 struct dchannel *dch;
2532 struct bchannel *bch;
2533 u_char r_irq_fifo_bl;
2534
2535 r_irq_fifo_bl = HFC_inb_nodebug(hc, R_IRQ_FIFO_BL0 + block);
2536 j = 0;
2537 while (j < 8) {
2538 ch = (block << 2) + (j >> 1);
2539 dch = hc->chan[ch].dch;
2540 bch = hc->chan[ch].bch;
2541 if (((!dch) && (!bch)) || (!hc->created[hc->chan[ch].port])) {
2542 j += 2;
2543 continue;
2544 }
2545 if (dch && (r_irq_fifo_bl & (1 << j)) &&
2546 test_bit(FLG_ACTIVE, &dch->Flags)) {
2547 hfcmulti_tx(hc, ch);
2548 /* start fifo */
2549 HFC_outb_nodebug(hc, R_FIFO, 0);
2550 HFC_wait_nodebug(hc);
2551 }
2552 if (bch && (r_irq_fifo_bl & (1 << j)) &&
2553 test_bit(FLG_ACTIVE, &bch->Flags)) {
2554 hfcmulti_tx(hc, ch);
2555 /* start fifo */
2556 HFC_outb_nodebug(hc, R_FIFO, 0);
2557 HFC_wait_nodebug(hc);
2558 }
2559 j++;
2560 if (dch && (r_irq_fifo_bl & (1 << j)) &&
2561 test_bit(FLG_ACTIVE, &dch->Flags)) {
2562 hfcmulti_rx(hc, ch);
2563 }
2564 if (bch && (r_irq_fifo_bl & (1 << j)) &&
2565 test_bit(FLG_ACTIVE, &bch->Flags)) {
2566 hfcmulti_rx(hc, ch);
2567 }
2568 j++;
2569 }
2570}
2571
2572#ifdef IRQ_DEBUG
2573int irqsem;
2574#endif
2575static irqreturn_t
2576hfcmulti_interrupt(int intno, void *dev_id)
2577{
2578#ifdef IRQCOUNT_DEBUG
2579 static int iq1 = 0, iq2 = 0, iq3 = 0, iq4 = 0,
2580 iq5 = 0, iq6 = 0, iqcnt = 0;
2581#endif
2582 static int count;
2583 struct hfc_multi *hc = dev_id;
2584 struct dchannel *dch;
2585 u_char r_irq_statech, status, r_irq_misc, r_irq_oview;
2586 int i;
2587 u_short *plx_acc, wval;
2588 u_char e1_syncsta, temp;
2589 u_long flags;
2590
2591 if (!hc) {
2592 printk(KERN_ERR "HFC-multi: Spurious interrupt!\n");
2593 return IRQ_NONE;
2594 }
2595
2596 spin_lock(&hc->lock);
2597
2598#ifdef IRQ_DEBUG
2599 if (irqsem)
2600 printk(KERN_ERR "irq for card %d during irq from "
2601 "card %d, this is no bug.\n", hc->id + 1, irqsem);
2602 irqsem = hc->id + 1;
2603#endif
2604
2605 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
2606 spin_lock_irqsave(&plx_lock, flags);
2607 plx_acc = (u_short *)(hc->plx_membase + PLX_INTCSR);
2608 wval = readw(plx_acc);
2609 spin_unlock_irqrestore(&plx_lock, flags);
2610 if (!(wval & PLX_INTCSR_LINTI1_STATUS))
2611 goto irq_notforus;
2612 }
2613
2614 status = HFC_inb_nodebug(hc, R_STATUS);
2615 r_irq_statech = HFC_inb_nodebug(hc, R_IRQ_STATECH);
2616#ifdef IRQCOUNT_DEBUG
2617 if (r_irq_statech)
2618 iq1++;
2619 if (status & V_DTMF_STA)
2620 iq2++;
2621 if (status & V_LOST_STA)
2622 iq3++;
2623 if (status & V_EXT_IRQSTA)
2624 iq4++;
2625 if (status & V_MISC_IRQSTA)
2626 iq5++;
2627 if (status & V_FR_IRQSTA)
2628 iq6++;
2629 if (iqcnt++ > 5000) {
2630 printk(KERN_ERR "iq1:%x iq2:%x iq3:%x iq4:%x iq5:%x iq6:%x\n",
2631 iq1, iq2, iq3, iq4, iq5, iq6);
2632 iqcnt = 0;
2633 }
2634#endif
2635 if (!r_irq_statech &&
2636 !(status & (V_DTMF_STA | V_LOST_STA | V_EXT_IRQSTA |
2637 V_MISC_IRQSTA | V_FR_IRQSTA))) {
2638 /* irq is not for us */
2639 goto irq_notforus;
2640 }
2641 hc->irqcnt++;
2642 if (r_irq_statech) {
2643 if (hc->type != 1)
2644 ph_state_irq(hc, r_irq_statech);
2645 }
2646 if (status & V_EXT_IRQSTA)
2647 ; /* external IRQ */
2648 if (status & V_LOST_STA) {
2649 /* LOST IRQ */
2650 HFC_outb(hc, R_INC_RES_FIFO, V_RES_LOST); /* clear irq! */
2651 }
2652 if (status & V_MISC_IRQSTA) {
2653 /* misc IRQ */
2654 r_irq_misc = HFC_inb_nodebug(hc, R_IRQ_MISC);
2655 if (r_irq_misc & V_STA_IRQ) {
2656 if (hc->type == 1) {
2657 /* state machine */
2658 dch = hc->chan[hc->dslot].dch;
2659 e1_syncsta = HFC_inb_nodebug(hc, R_SYNC_STA);
2660 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)
2661 && hc->e1_getclock) {
2662 if (e1_syncsta & V_FR_SYNC_E1)
2663 hc->syncronized = 1;
2664 else
2665 hc->syncronized = 0;
2666 }
2667 /* undocumented: status changes during read */
2668 dch->state = HFC_inb_nodebug(hc, R_E1_RD_STA);
2669 while (dch->state != (temp =
2670 HFC_inb_nodebug(hc, R_E1_RD_STA))) {
2671 if (debug & DEBUG_HFCMULTI_STATE)
2672 printk(KERN_DEBUG "%s: reread "
2673 "STATE because %d!=%d\n",
2674 __func__, temp,
2675 dch->state);
2676 dch->state = temp; /* repeat */
2677 }
2678 dch->state = HFC_inb_nodebug(hc, R_E1_RD_STA)
2679 & 0x7;
2680 schedule_event(dch, FLG_PHCHANGE);
2681 if (debug & DEBUG_HFCMULTI_STATE)
2682 printk(KERN_DEBUG
2683 "%s: E1 (id=%d) newstate %x\n",
2684 __func__, hc->id, dch->state);
2685 if (test_bit(HFC_CHIP_PLXSD, &hc->chip))
2686 plxsd_checksync(hc, 0);
2687 }
2688 }
2689 if (r_irq_misc & V_TI_IRQ)
2690 handle_timer_irq(hc);
2691
2692 if (r_irq_misc & V_DTMF_IRQ) {
2693 /* -> DTMF IRQ */
2694 hfcmulti_dtmf(hc);
2695 }
2696 /* TODO: REPLACE !!!! 125 us Interrupts are not acceptable */
2697 if (r_irq_misc & V_IRQ_PROC) {
2698 /* IRQ every 125us */
2699 count++;
2700 /* generate 1kHz signal */
2701 if (count == 8) {
2702 if (hfc_interrupt)
2703 hfc_interrupt();
2704 count = 0;
2705 }
2706 }
2707
2708 }
2709 if (status & V_FR_IRQSTA) {
2710 /* FIFO IRQ */
2711 r_irq_oview = HFC_inb_nodebug(hc, R_IRQ_OVIEW);
2712 for (i = 0; i < 8; i++) {
2713 if (r_irq_oview & (1 << i))
2714 fifo_irq(hc, i);
2715 }
2716 }
2717
2718#ifdef IRQ_DEBUG
2719 irqsem = 0;
2720#endif
2721 spin_unlock(&hc->lock);
2722 return IRQ_HANDLED;
2723
2724irq_notforus:
2725#ifdef IRQ_DEBUG
2726 irqsem = 0;
2727#endif
2728 spin_unlock(&hc->lock);
2729 return IRQ_NONE;
2730}
2731
2732
2733/*
2734 * timer callback for D-chan busy resolution. Currently no function
2735 */
2736
2737static void
2738hfcmulti_dbusy_timer(struct hfc_multi *hc)
2739{
2740}
2741
2742
2743/*
2744 * activate/deactivate hardware for selected channels and mode
2745 *
2746 * configure B-channel with the given protocol
2747 * ch eqals to the HFC-channel (0-31)
2748 * ch is the number of channel (0-4,4-7,8-11,12-15,16-19,20-23,24-27,28-31
2749 * for S/T, 1-31 for E1)
2750 * the hdlc interrupts will be set/unset
2751 */
2752static int
2753mode_hfcmulti(struct hfc_multi *hc, int ch, int protocol, int slot_tx,
2754 int bank_tx, int slot_rx, int bank_rx)
2755{
2756 int flow_tx = 0, flow_rx = 0, routing = 0;
2757 int oslot_tx, oslot_rx;
2758 int conf;
2759
2760 if (ch < 0 || ch > 31)
2761 return EINVAL;
2762 oslot_tx = hc->chan[ch].slot_tx;
2763 oslot_rx = hc->chan[ch].slot_rx;
2764 conf = hc->chan[ch].conf;
2765
2766 if (debug & DEBUG_HFCMULTI_MODE)
2767 printk(KERN_DEBUG
2768 "%s: card %d channel %d protocol %x slot old=%d new=%d "
2769 "bank new=%d (TX) slot old=%d new=%d bank new=%d (RX)\n",
2770 __func__, hc->id, ch, protocol, oslot_tx, slot_tx,
2771 bank_tx, oslot_rx, slot_rx, bank_rx);
2772
2773 if (oslot_tx >= 0 && slot_tx != oslot_tx) {
2774 /* remove from slot */
2775 if (debug & DEBUG_HFCMULTI_MODE)
2776 printk(KERN_DEBUG "%s: remove from slot %d (TX)\n",
2777 __func__, oslot_tx);
2778 if (hc->slot_owner[oslot_tx<<1] == ch) {
2779 HFC_outb(hc, R_SLOT, oslot_tx << 1);
2780 HFC_outb(hc, A_SL_CFG, 0);
2781 HFC_outb(hc, A_CONF, 0);
2782 hc->slot_owner[oslot_tx<<1] = -1;
2783 } else {
2784 if (debug & DEBUG_HFCMULTI_MODE)
2785 printk(KERN_DEBUG
2786 "%s: we are not owner of this tx slot "
2787 "anymore, channel %d is.\n",
2788 __func__, hc->slot_owner[oslot_tx<<1]);
2789 }
2790 }
2791
2792 if (oslot_rx >= 0 && slot_rx != oslot_rx) {
2793 /* remove from slot */
2794 if (debug & DEBUG_HFCMULTI_MODE)
2795 printk(KERN_DEBUG
2796 "%s: remove from slot %d (RX)\n",
2797 __func__, oslot_rx);
2798 if (hc->slot_owner[(oslot_rx << 1) | 1] == ch) {
2799 HFC_outb(hc, R_SLOT, (oslot_rx << 1) | V_SL_DIR);
2800 HFC_outb(hc, A_SL_CFG, 0);
2801 hc->slot_owner[(oslot_rx << 1) | 1] = -1;
2802 } else {
2803 if (debug & DEBUG_HFCMULTI_MODE)
2804 printk(KERN_DEBUG
2805 "%s: we are not owner of this rx slot "
2806 "anymore, channel %d is.\n",
2807 __func__,
2808 hc->slot_owner[(oslot_rx << 1) | 1]);
2809 }
2810 }
2811
2812 if (slot_tx < 0) {
2813 flow_tx = 0x80; /* FIFO->ST */
2814 /* disable pcm slot */
2815 hc->chan[ch].slot_tx = -1;
2816 hc->chan[ch].bank_tx = 0;
2817 } else {
2818 /* set pcm slot */
2819 if (hc->chan[ch].txpending)
2820 flow_tx = 0x80; /* FIFO->ST */
2821 else
2822 flow_tx = 0xc0; /* PCM->ST */
2823 /* put on slot */
2824 routing = bank_tx ? 0xc0 : 0x80;
2825 if (conf >= 0 || bank_tx > 1)
2826 routing = 0x40; /* loop */
2827 if (debug & DEBUG_HFCMULTI_MODE)
2828 printk(KERN_DEBUG "%s: put channel %d to slot %d bank"
2829 " %d flow %02x routing %02x conf %d (TX)\n",
2830 __func__, ch, slot_tx, bank_tx,
2831 flow_tx, routing, conf);
2832 HFC_outb(hc, R_SLOT, slot_tx << 1);
2833 HFC_outb(hc, A_SL_CFG, (ch<<1) | routing);
2834 HFC_outb(hc, A_CONF, (conf < 0) ? 0 : (conf | V_CONF_SL));
2835 hc->slot_owner[slot_tx << 1] = ch;
2836 hc->chan[ch].slot_tx = slot_tx;
2837 hc->chan[ch].bank_tx = bank_tx;
2838 }
2839 if (slot_rx < 0) {
2840 /* disable pcm slot */
2841 flow_rx = 0x80; /* ST->FIFO */
2842 hc->chan[ch].slot_rx = -1;
2843 hc->chan[ch].bank_rx = 0;
2844 } else {
2845 /* set pcm slot */
2846 if (hc->chan[ch].txpending)
2847 flow_rx = 0x80; /* ST->FIFO */
2848 else
2849 flow_rx = 0xc0; /* ST->(FIFO,PCM) */
2850 /* put on slot */
2851 routing = bank_rx?0x80:0xc0; /* reversed */
2852 if (conf >= 0 || bank_rx > 1)
2853 routing = 0x40; /* loop */
2854 if (debug & DEBUG_HFCMULTI_MODE)
2855 printk(KERN_DEBUG "%s: put channel %d to slot %d bank"
2856 " %d flow %02x routing %02x conf %d (RX)\n",
2857 __func__, ch, slot_rx, bank_rx,
2858 flow_rx, routing, conf);
2859 HFC_outb(hc, R_SLOT, (slot_rx<<1) | V_SL_DIR);
2860 HFC_outb(hc, A_SL_CFG, (ch<<1) | V_CH_DIR | routing);
2861 hc->slot_owner[(slot_rx<<1)|1] = ch;
2862 hc->chan[ch].slot_rx = slot_rx;
2863 hc->chan[ch].bank_rx = bank_rx;
2864 }
2865
2866 switch (protocol) {
2867 case (ISDN_P_NONE):
2868 /* disable TX fifo */
2869 HFC_outb(hc, R_FIFO, ch << 1);
2870 HFC_wait(hc);
2871 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x00 | V_IFF);
2872 HFC_outb(hc, A_SUBCH_CFG, 0);
2873 HFC_outb(hc, A_IRQ_MSK, 0);
2874 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2875 HFC_wait(hc);
2876 /* disable RX fifo */
2877 HFC_outb(hc, R_FIFO, (ch<<1)|1);
2878 HFC_wait(hc);
2879 HFC_outb(hc, A_CON_HDLC, flow_rx | 0x00);
2880 HFC_outb(hc, A_SUBCH_CFG, 0);
2881 HFC_outb(hc, A_IRQ_MSK, 0);
2882 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2883 HFC_wait(hc);
2884 if (hc->chan[ch].bch && hc->type != 1) {
2885 hc->hw.a_st_ctrl0[hc->chan[ch].port] &=
2886 ((ch & 0x3) == 0)? ~V_B1_EN: ~V_B2_EN;
2887 HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
2888 /* undocumented: delay after R_ST_SEL */
2889 udelay(1);
2890 HFC_outb(hc, A_ST_CTRL0,
2891 hc->hw.a_st_ctrl0[hc->chan[ch].port]);
2892 }
2893 if (hc->chan[ch].bch) {
2894 test_and_clear_bit(FLG_HDLC, &hc->chan[ch].bch->Flags);
2895 test_and_clear_bit(FLG_TRANSPARENT,
2896 &hc->chan[ch].bch->Flags);
2897 }
2898 break;
2899 case (ISDN_P_B_RAW): /* B-channel */
2900
2901 if (test_bit(HFC_CHIP_B410P, &hc->chip) &&
2902 (hc->chan[ch].slot_rx < 0) &&
2903 (hc->chan[ch].slot_tx < 0)) {
2904
2905 printk(KERN_DEBUG
2906 "Setting B-channel %d to echo cancelable "
2907 "state on PCM slot %d\n", ch,
2908 ((ch / 4) * 8) + ((ch % 4) * 4) + 1);
2909 printk(KERN_DEBUG
2910 "Enabling pass through for channel\n");
2911 vpm_out(hc, ch, ((ch / 4) * 8) +
2912 ((ch % 4) * 4) + 1, 0x01);
2913 /* rx path */
2914 /* S/T -> PCM */
2915 HFC_outb(hc, R_FIFO, (ch << 1));
2916 HFC_wait(hc);
2917 HFC_outb(hc, A_CON_HDLC, 0xc0 | V_HDLC_TRP | V_IFF);
2918 HFC_outb(hc, R_SLOT, (((ch / 4) * 8) +
2919 ((ch % 4) * 4) + 1) << 1);
2920 HFC_outb(hc, A_SL_CFG, 0x80 | (ch << 1));
2921
2922 /* PCM -> FIFO */
2923 HFC_outb(hc, R_FIFO, 0x20 | (ch << 1) | 1);
2924 HFC_wait(hc);
2925 HFC_outb(hc, A_CON_HDLC, 0x20 | V_HDLC_TRP | V_IFF);
2926 HFC_outb(hc, A_SUBCH_CFG, 0);
2927 HFC_outb(hc, A_IRQ_MSK, 0);
2928 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2929 HFC_wait(hc);
2930 HFC_outb(hc, R_SLOT, ((((ch / 4) * 8) +
2931 ((ch % 4) * 4) + 1) << 1) | 1);
2932 HFC_outb(hc, A_SL_CFG, 0x80 | 0x20 | (ch << 1) | 1);
2933
2934 /* tx path */
2935 /* PCM -> S/T */
2936 HFC_outb(hc, R_FIFO, (ch << 1) | 1);
2937 HFC_wait(hc);
2938 HFC_outb(hc, A_CON_HDLC, 0xc0 | V_HDLC_TRP | V_IFF);
2939 HFC_outb(hc, R_SLOT, ((((ch / 4) * 8) +
2940 ((ch % 4) * 4)) << 1) | 1);
2941 HFC_outb(hc, A_SL_CFG, 0x80 | 0x40 | (ch << 1) | 1);
2942
2943 /* FIFO -> PCM */
2944 HFC_outb(hc, R_FIFO, 0x20 | (ch << 1));
2945 HFC_wait(hc);
2946 HFC_outb(hc, A_CON_HDLC, 0x20 | V_HDLC_TRP | V_IFF);
2947 HFC_outb(hc, A_SUBCH_CFG, 0);
2948 HFC_outb(hc, A_IRQ_MSK, 0);
2949 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2950 HFC_wait(hc);
2951 /* tx silence */
2952 HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, silence);
2953 HFC_outb(hc, R_SLOT, (((ch / 4) * 8) +
2954 ((ch % 4) * 4)) << 1);
2955 HFC_outb(hc, A_SL_CFG, 0x80 | 0x20 | (ch << 1));
2956 } else {
2957 /* enable TX fifo */
2958 HFC_outb(hc, R_FIFO, ch << 1);
2959 HFC_wait(hc);
2960 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x00 |
2961 V_HDLC_TRP | V_IFF);
2962 HFC_outb(hc, A_SUBCH_CFG, 0);
2963 HFC_outb(hc, A_IRQ_MSK, 0);
2964 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2965 HFC_wait(hc);
2966 /* tx silence */
2967 HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, silence);
2968 /* enable RX fifo */
2969 HFC_outb(hc, R_FIFO, (ch<<1)|1);
2970 HFC_wait(hc);
2971 HFC_outb(hc, A_CON_HDLC, flow_rx | 0x00 | V_HDLC_TRP);
2972 HFC_outb(hc, A_SUBCH_CFG, 0);
2973 HFC_outb(hc, A_IRQ_MSK, 0);
2974 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
2975 HFC_wait(hc);
2976 }
2977 if (hc->type != 1) {
2978 hc->hw.a_st_ctrl0[hc->chan[ch].port] |=
2979 ((ch & 0x3) == 0) ? V_B1_EN : V_B2_EN;
2980 HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
2981 /* undocumented: delay after R_ST_SEL */
2982 udelay(1);
2983 HFC_outb(hc, A_ST_CTRL0,
2984 hc->hw.a_st_ctrl0[hc->chan[ch].port]);
2985 }
2986 if (hc->chan[ch].bch)
2987 test_and_set_bit(FLG_TRANSPARENT,
2988 &hc->chan[ch].bch->Flags);
2989 break;
2990 case (ISDN_P_B_HDLC): /* B-channel */
2991 case (ISDN_P_TE_S0): /* D-channel */
2992 case (ISDN_P_NT_S0):
2993 case (ISDN_P_TE_E1):
2994 case (ISDN_P_NT_E1):
2995 /* enable TX fifo */
2996 HFC_outb(hc, R_FIFO, ch<<1);
2997 HFC_wait(hc);
2998 if (hc->type == 1 || hc->chan[ch].bch) {
2999 /* E1 or B-channel */
3000 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x04);
3001 HFC_outb(hc, A_SUBCH_CFG, 0);
3002 } else {
3003 /* D-Channel without HDLC fill flags */
3004 HFC_outb(hc, A_CON_HDLC, flow_tx | 0x04 | V_IFF);
3005 HFC_outb(hc, A_SUBCH_CFG, 2);
3006 }
3007 HFC_outb(hc, A_IRQ_MSK, V_IRQ);
3008 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
3009 HFC_wait(hc);
3010 /* enable RX fifo */
3011 HFC_outb(hc, R_FIFO, (ch<<1)|1);
3012 HFC_wait(hc);
3013 HFC_outb(hc, A_CON_HDLC, flow_rx | 0x04);
3014 if (hc->type == 1 || hc->chan[ch].bch)
3015 HFC_outb(hc, A_SUBCH_CFG, 0); /* full 8 bits */
3016 else
3017 HFC_outb(hc, A_SUBCH_CFG, 2); /* 2 bits dchannel */
3018 HFC_outb(hc, A_IRQ_MSK, V_IRQ);
3019 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F);
3020 HFC_wait(hc);
3021 if (hc->chan[ch].bch) {
3022 test_and_set_bit(FLG_HDLC, &hc->chan[ch].bch->Flags);
3023 if (hc->type != 1) {
3024 hc->hw.a_st_ctrl0[hc->chan[ch].port] |=
3025 ((ch&0x3) == 0) ? V_B1_EN : V_B2_EN;
3026 HFC_outb(hc, R_ST_SEL, hc->chan[ch].port);
3027 /* undocumented: delay after R_ST_SEL */
3028 udelay(1);
3029 HFC_outb(hc, A_ST_CTRL0,
3030 hc->hw.a_st_ctrl0[hc->chan[ch].port]);
3031 }
3032 }
3033 break;
3034 default:
3035 printk(KERN_DEBUG "%s: protocol not known %x\n",
3036 __func__, protocol);
3037 hc->chan[ch].protocol = ISDN_P_NONE;
3038 return -ENOPROTOOPT;
3039 }
3040 hc->chan[ch].protocol = protocol;
3041 return 0;
3042}
3043
3044
3045/*
3046 * connect/disconnect PCM
3047 */
3048
3049static void
3050hfcmulti_pcm(struct hfc_multi *hc, int ch, int slot_tx, int bank_tx,
3051 int slot_rx, int bank_rx)
3052{
3053 if (slot_rx < 0 || slot_rx < 0 || bank_tx < 0 || bank_rx < 0) {
3054 /* disable PCM */
3055 mode_hfcmulti(hc, ch, hc->chan[ch].protocol, -1, 0, -1, 0);
3056 return;
3057 }
3058
3059 /* enable pcm */
3060 mode_hfcmulti(hc, ch, hc->chan[ch].protocol, slot_tx, bank_tx,
3061 slot_rx, bank_rx);
3062}
3063
3064/*
3065 * set/disable conference
3066 */
3067
3068static void
3069hfcmulti_conf(struct hfc_multi *hc, int ch, int num)
3070{
3071 if (num >= 0 && num <= 7)
3072 hc->chan[ch].conf = num;
3073 else
3074 hc->chan[ch].conf = -1;
3075 mode_hfcmulti(hc, ch, hc->chan[ch].protocol, hc->chan[ch].slot_tx,
3076 hc->chan[ch].bank_tx, hc->chan[ch].slot_rx,
3077 hc->chan[ch].bank_rx);
3078}
3079
3080
3081/*
3082 * set/disable sample loop
3083 */
3084
3085/* NOTE: this function is experimental and therefore disabled */
3086
3087/*
3088 * Layer 1 callback function
3089 */
3090static int
3091hfcm_l1callback(struct dchannel *dch, u_int cmd)
3092{
3093 struct hfc_multi *hc = dch->hw;
3094 u_long flags;
3095
3096 switch (cmd) {
3097 case INFO3_P8:
3098 case INFO3_P10:
3099 break;
3100 case HW_RESET_REQ:
3101 /* start activation */
3102 spin_lock_irqsave(&hc->lock, flags);
3103 if (hc->type == 1) {
3104 if (debug & DEBUG_HFCMULTI_MSG)
3105 printk(KERN_DEBUG
3106 "%s: HW_RESET_REQ no BRI\n",
3107 __func__);
3108 } else {
3109 HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
3110 /* undocumented: delay after R_ST_SEL */
3111 udelay(1);
3112 HFC_outb(hc, A_ST_WR_STATE, V_ST_LD_STA | 3); /* F3 */
3113 udelay(6); /* wait at least 5,21us */
3114 HFC_outb(hc, A_ST_WR_STATE, 3);
3115 HFC_outb(hc, A_ST_WR_STATE, 3 | (V_ST_ACT*3));
3116 /* activate */
3117 }
3118 spin_unlock_irqrestore(&hc->lock, flags);
3119 l1_event(dch->l1, HW_POWERUP_IND);
3120 break;
3121 case HW_DEACT_REQ:
3122 /* start deactivation */
3123 spin_lock_irqsave(&hc->lock, flags);
3124 if (hc->type == 1) {
3125 if (debug & DEBUG_HFCMULTI_MSG)
3126 printk(KERN_DEBUG
3127 "%s: HW_DEACT_REQ no BRI\n",
3128 __func__);
3129 } else {
3130 HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
3131 /* undocumented: delay after R_ST_SEL */
3132 udelay(1);
3133 HFC_outb(hc, A_ST_WR_STATE, V_ST_ACT*2);
3134 /* deactivate */
3135 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
3136 hc->syncronized &=
3137 ~(1 << hc->chan[dch->slot].port);
3138 plxsd_checksync(hc, 0);
3139 }
3140 }
3141 skb_queue_purge(&dch->squeue);
3142 if (dch->tx_skb) {
3143 dev_kfree_skb(dch->tx_skb);
3144 dch->tx_skb = NULL;
3145 }
3146 dch->tx_idx = 0;
3147 if (dch->rx_skb) {
3148 dev_kfree_skb(dch->rx_skb);
3149 dch->rx_skb = NULL;
3150 }
3151 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
3152 if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
3153 del_timer(&dch->timer);
3154 spin_unlock_irqrestore(&hc->lock, flags);
3155 break;
3156 case HW_POWERUP_REQ:
3157 spin_lock_irqsave(&hc->lock, flags);
3158 if (hc->type == 1) {
3159 if (debug & DEBUG_HFCMULTI_MSG)
3160 printk(KERN_DEBUG
3161 "%s: HW_POWERUP_REQ no BRI\n",
3162 __func__);
3163 } else {
3164 HFC_outb(hc, R_ST_SEL, hc->chan[dch->slot].port);
3165 /* undocumented: delay after R_ST_SEL */
3166 udelay(1);
3167 HFC_outb(hc, A_ST_WR_STATE, 3 | 0x10); /* activate */
3168 udelay(6); /* wait at least 5,21us */
3169 HFC_outb(hc, A_ST_WR_STATE, 3); /* activate */
3170 }
3171 spin_unlock_irqrestore(&hc->lock, flags);
3172 break;
3173 case PH_ACTIVATE_IND:
3174 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
3175 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
3176 GFP_ATOMIC);
3177 break;
3178 case PH_DEACTIVATE_IND:
3179 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
3180 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
3181 GFP_ATOMIC);
3182 break;
3183 default:
3184 if (dch->debug & DEBUG_HW)
3185 printk(KERN_DEBUG "%s: unknown command %x\n",
3186 __func__, cmd);
3187 return -1;
3188 }
3189 return 0;
3190}
3191
3192/*
3193 * Layer2 -> Layer 1 Transfer
3194 */
3195
3196static int
3197handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)
3198{
3199 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
3200 struct dchannel *dch = container_of(dev, struct dchannel, dev);
3201 struct hfc_multi *hc = dch->hw;
3202 struct mISDNhead *hh = mISDN_HEAD_P(skb);
3203 int ret = -EINVAL;
3204 unsigned int id;
3205 u_long flags;
3206
3207 switch (hh->prim) {
3208 case PH_DATA_REQ:
3209 if (skb->len < 1)
3210 break;
3211 spin_lock_irqsave(&hc->lock, flags);
3212 ret = dchannel_senddata(dch, skb);
3213 if (ret > 0) { /* direct TX */
3214 id = hh->id; /* skb can be freed */
3215 hfcmulti_tx(hc, dch->slot);
3216 ret = 0;
3217 /* start fifo */
3218 HFC_outb(hc, R_FIFO, 0);
3219 HFC_wait(hc);
3220 spin_unlock_irqrestore(&hc->lock, flags);
3221 queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
3222 } else
3223 spin_unlock_irqrestore(&hc->lock, flags);
3224 return ret;
3225 case PH_ACTIVATE_REQ:
3226 if (dch->dev.D.protocol != ISDN_P_TE_S0) {
3227 spin_lock_irqsave(&hc->lock, flags);
3228 ret = 0;
3229 if (debug & DEBUG_HFCMULTI_MSG)
3230 printk(KERN_DEBUG
3231 "%s: PH_ACTIVATE port %d (0..%d)\n",
3232 __func__, hc->chan[dch->slot].port,
3233 hc->ports-1);
3234 /* start activation */
3235 if (hc->type == 1) {
3236 ph_state_change(dch);
3237 if (debug & DEBUG_HFCMULTI_STATE)
3238 printk(KERN_DEBUG
3239 "%s: E1 report state %x \n",
3240 __func__, dch->state);
3241 } else {
3242 HFC_outb(hc, R_ST_SEL,
3243 hc->chan[dch->slot].port);
3244 /* undocumented: delay after R_ST_SEL */
3245 udelay(1);
3246 HFC_outb(hc, A_ST_WR_STATE, V_ST_LD_STA | 1);
3247 /* G1 */
3248 udelay(6); /* wait at least 5,21us */
3249 HFC_outb(hc, A_ST_WR_STATE, 1);
3250 HFC_outb(hc, A_ST_WR_STATE, 1 |
3251 (V_ST_ACT*3)); /* activate */
3252 dch->state = 1;
3253 }
3254 spin_unlock_irqrestore(&hc->lock, flags);
3255 } else
3256 ret = l1_event(dch->l1, hh->prim);
3257 break;
3258 case PH_DEACTIVATE_REQ:
3259 test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
3260 if (dch->dev.D.protocol != ISDN_P_TE_S0) {
3261 spin_lock_irqsave(&hc->lock, flags);
3262 if (debug & DEBUG_HFCMULTI_MSG)
3263 printk(KERN_DEBUG
3264 "%s: PH_DEACTIVATE port %d (0..%d)\n",
3265 __func__, hc->chan[dch->slot].port,
3266 hc->ports-1);
3267 /* start deactivation */
3268 if (hc->type == 1) {
3269 if (debug & DEBUG_HFCMULTI_MSG)
3270 printk(KERN_DEBUG
3271 "%s: PH_DEACTIVATE no BRI\n",
3272 __func__);
3273 } else {
3274 HFC_outb(hc, R_ST_SEL,
3275 hc->chan[dch->slot].port);
3276 /* undocumented: delay after R_ST_SEL */
3277 udelay(1);
3278 HFC_outb(hc, A_ST_WR_STATE, V_ST_ACT * 2);
3279 /* deactivate */
3280 dch->state = 1;
3281 }
3282 skb_queue_purge(&dch->squeue);
3283 if (dch->tx_skb) {
3284 dev_kfree_skb(dch->tx_skb);
3285 dch->tx_skb = NULL;
3286 }
3287 dch->tx_idx = 0;
3288 if (dch->rx_skb) {
3289 dev_kfree_skb(dch->rx_skb);
3290 dch->rx_skb = NULL;
3291 }
3292 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
3293 if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
3294 del_timer(&dch->timer);
3295#ifdef FIXME
3296 if (test_and_clear_bit(FLG_L1_BUSY, &dch->Flags))
3297 dchannel_sched_event(&hc->dch, D_CLEARBUSY);
3298#endif
3299 ret = 0;
3300 spin_unlock_irqrestore(&hc->lock, flags);
3301 } else
3302 ret = l1_event(dch->l1, hh->prim);
3303 break;
3304 }
3305 if (!ret)
3306 dev_kfree_skb(skb);
3307 return ret;
3308}
3309
3310static void
3311deactivate_bchannel(struct bchannel *bch)
3312{
3313 struct hfc_multi *hc = bch->hw;
3314 u_long flags;
3315
3316 spin_lock_irqsave(&hc->lock, flags);
3317 if (test_and_clear_bit(FLG_TX_NEXT, &bch->Flags)) {
3318 dev_kfree_skb(bch->next_skb);
3319 bch->next_skb = NULL;
3320 }
3321 if (bch->tx_skb) {
3322 dev_kfree_skb(bch->tx_skb);
3323 bch->tx_skb = NULL;
3324 }
3325 bch->tx_idx = 0;
3326 if (bch->rx_skb) {
3327 dev_kfree_skb(bch->rx_skb);
3328 bch->rx_skb = NULL;
3329 }
3330 hc->chan[bch->slot].coeff_count = 0;
3331 test_and_clear_bit(FLG_ACTIVE, &bch->Flags);
3332 test_and_clear_bit(FLG_TX_BUSY, &bch->Flags);
3333 hc->chan[bch->slot].rx_off = 0;
3334 hc->chan[bch->slot].conf = -1;
3335 mode_hfcmulti(hc, bch->slot, ISDN_P_NONE, -1, 0, -1, 0);
3336 spin_unlock_irqrestore(&hc->lock, flags);
3337}
3338
3339static int
3340handle_bmsg(struct mISDNchannel *ch, struct sk_buff *skb)
3341{
3342 struct bchannel *bch = container_of(ch, struct bchannel, ch);
3343 struct hfc_multi *hc = bch->hw;
3344 int ret = -EINVAL;
3345 struct mISDNhead *hh = mISDN_HEAD_P(skb);
3346 unsigned int id;
3347 u_long flags;
3348
3349 switch (hh->prim) {
3350 case PH_DATA_REQ:
3351 if (!skb->len)
3352 break;
3353 spin_lock_irqsave(&hc->lock, flags);
3354 ret = bchannel_senddata(bch, skb);
3355 if (ret > 0) { /* direct TX */
3356 id = hh->id; /* skb can be freed */
3357 hfcmulti_tx(hc, bch->slot);
3358 ret = 0;
3359 /* start fifo */
3360 HFC_outb_nodebug(hc, R_FIFO, 0);
3361 HFC_wait_nodebug(hc);
3362 if (!test_bit(FLG_TRANSPARENT, &bch->Flags)) {
3363 spin_unlock_irqrestore(&hc->lock, flags);
3364 queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
3365 } else
3366 spin_unlock_irqrestore(&hc->lock, flags);
3367 } else
3368 spin_unlock_irqrestore(&hc->lock, flags);
3369 return ret;
3370 case PH_ACTIVATE_REQ:
3371 if (debug & DEBUG_HFCMULTI_MSG)
3372 printk(KERN_DEBUG "%s: PH_ACTIVATE ch %d (0..32)\n",
3373 __func__, bch->slot);
3374 spin_lock_irqsave(&hc->lock, flags);
3375 /* activate B-channel if not already activated */
3376 if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags)) {
3377 hc->chan[bch->slot].txpending = 0;
3378 ret = mode_hfcmulti(hc, bch->slot,
3379 ch->protocol,
3380 hc->chan[bch->slot].slot_tx,
3381 hc->chan[bch->slot].bank_tx,
3382 hc->chan[bch->slot].slot_rx,
3383 hc->chan[bch->slot].bank_rx);
3384 if (!ret) {
3385 if (ch->protocol == ISDN_P_B_RAW && !hc->dtmf
3386 && test_bit(HFC_CHIP_DTMF, &hc->chip)) {
3387 /* start decoder */
3388 hc->dtmf = 1;
3389 if (debug & DEBUG_HFCMULTI_DTMF)
3390 printk(KERN_DEBUG
3391 "%s: start dtmf decoder\n",
3392 __func__);
3393 HFC_outb(hc, R_DTMF, hc->hw.r_dtmf |
3394 V_RST_DTMF);
3395 }
3396 }
3397 } else
3398 ret = 0;
3399 spin_unlock_irqrestore(&hc->lock, flags);
3400 if (!ret)
3401 _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0, NULL,
3402 GFP_KERNEL);
3403 break;
3404 case PH_CONTROL_REQ:
3405 spin_lock_irqsave(&hc->lock, flags);
3406 switch (hh->id) {
3407 case HFC_SPL_LOOP_ON: /* set sample loop */
3408 if (debug & DEBUG_HFCMULTI_MSG)
3409 printk(KERN_DEBUG
3410 "%s: HFC_SPL_LOOP_ON (len = %d)\n",
3411 __func__, skb->len);
3412 ret = 0;
3413 break;
3414 case HFC_SPL_LOOP_OFF: /* set silence */
3415 if (debug & DEBUG_HFCMULTI_MSG)
3416 printk(KERN_DEBUG "%s: HFC_SPL_LOOP_OFF\n",
3417 __func__);
3418 ret = 0;
3419 break;
3420 default:
3421 printk(KERN_ERR
3422 "%s: unknown PH_CONTROL_REQ info %x\n",
3423 __func__, hh->id);
3424 ret = -EINVAL;
3425 }
3426 spin_unlock_irqrestore(&hc->lock, flags);
3427 break;
3428 case PH_DEACTIVATE_REQ:
3429 deactivate_bchannel(bch); /* locked there */
3430 _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0, NULL,
3431 GFP_KERNEL);
3432 ret = 0;
3433 break;
3434 }
3435 if (!ret)
3436 dev_kfree_skb(skb);
3437 return ret;
3438}
3439
3440/*
3441 * bchannel control function
3442 */
3443static int
3444channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
3445{
3446 int ret = 0;
3447 struct dsp_features *features =
3448 (struct dsp_features *)(*((u_long *)&cq->p1));
3449 struct hfc_multi *hc = bch->hw;
3450 int slot_tx;
3451 int bank_tx;
3452 int slot_rx;
3453 int bank_rx;
3454 int num;
3455
3456 switch (cq->op) {
3457 case MISDN_CTRL_GETOP:
3458 cq->op = MISDN_CTRL_HFC_OP | MISDN_CTRL_HW_FEATURES_OP
3459 | MISDN_CTRL_RX_OFF;
3460 break;
3461 case MISDN_CTRL_RX_OFF: /* turn off / on rx stream */
3462 hc->chan[bch->slot].rx_off = !!cq->p1;
3463 if (!hc->chan[bch->slot].rx_off) {
3464 /* reset fifo on rx on */
3465 HFC_outb_nodebug(hc, R_FIFO, (bch->slot << 1) | 1);
3466 HFC_wait_nodebug(hc);
3467 HFC_outb_nodebug(hc, R_INC_RES_FIFO, V_RES_F);
3468 HFC_wait_nodebug(hc);
3469 }
3470 if (debug & DEBUG_HFCMULTI_MSG)
3471 printk(KERN_DEBUG "%s: RX_OFF request (nr=%d off=%d)\n",
3472 __func__, bch->nr, hc->chan[bch->slot].rx_off);
3473 break;
3474 case MISDN_CTRL_HW_FEATURES: /* fill features structure */
3475 if (debug & DEBUG_HFCMULTI_MSG)
3476 printk(KERN_DEBUG "%s: HW_FEATURE request\n",
3477 __func__);
3478 /* create confirm */
3479 features->hfc_id = hc->id;
3480 if (test_bit(HFC_CHIP_DTMF, &hc->chip))
3481 features->hfc_dtmf = 1;
3482 features->hfc_loops = 0;
3483 if (test_bit(HFC_CHIP_B410P, &hc->chip)) {
3484 features->hfc_echocanhw = 1;
3485 } else {
3486 features->pcm_id = hc->pcm;
3487 features->pcm_slots = hc->slots;
3488 features->pcm_banks = 2;
3489 }
3490 break;
3491 case MISDN_CTRL_HFC_PCM_CONN: /* connect to pcm timeslot (0..N) */
3492 slot_tx = cq->p1 & 0xff;
3493 bank_tx = cq->p1 >> 8;
3494 slot_rx = cq->p2 & 0xff;
3495 bank_rx = cq->p2 >> 8;
3496 if (debug & DEBUG_HFCMULTI_MSG)
3497 printk(KERN_DEBUG
3498 "%s: HFC_PCM_CONN slot %d bank %d (TX) "
3499 "slot %d bank %d (RX)\n",
3500 __func__, slot_tx, bank_tx,
3501 slot_rx, bank_rx);
3502 if (slot_tx < hc->slots && bank_tx <= 2 &&
3503 slot_rx < hc->slots && bank_rx <= 2)
3504 hfcmulti_pcm(hc, bch->slot,
3505 slot_tx, bank_tx, slot_rx, bank_rx);
3506 else {
3507 printk(KERN_WARNING
3508 "%s: HFC_PCM_CONN slot %d bank %d (TX) "
3509 "slot %d bank %d (RX) out of range\n",
3510 __func__, slot_tx, bank_tx,
3511 slot_rx, bank_rx);
3512 ret = -EINVAL;
3513 }
3514 break;
3515 case MISDN_CTRL_HFC_PCM_DISC: /* release interface from pcm timeslot */
3516 if (debug & DEBUG_HFCMULTI_MSG)
3517 printk(KERN_DEBUG "%s: HFC_PCM_DISC\n",
3518 __func__);
3519 hfcmulti_pcm(hc, bch->slot, -1, 0, -1, 0);
3520 break;
3521 case MISDN_CTRL_HFC_CONF_JOIN: /* join conference (0..7) */
3522 num = cq->p1 & 0xff;
3523 if (debug & DEBUG_HFCMULTI_MSG)
3524 printk(KERN_DEBUG "%s: HFC_CONF_JOIN conf %d\n",
3525 __func__, num);
3526 if (num <= 7)
3527 hfcmulti_conf(hc, bch->slot, num);
3528 else {
3529 printk(KERN_WARNING
3530 "%s: HW_CONF_JOIN conf %d out of range\n",
3531 __func__, num);
3532 ret = -EINVAL;
3533 }
3534 break;
3535 case MISDN_CTRL_HFC_CONF_SPLIT: /* split conference */
3536 if (debug & DEBUG_HFCMULTI_MSG)
3537 printk(KERN_DEBUG "%s: HFC_CONF_SPLIT\n", __func__);
3538 hfcmulti_conf(hc, bch->slot, -1);
3539 break;
3540 case MISDN_CTRL_HFC_ECHOCAN_ON:
3541 if (debug & DEBUG_HFCMULTI_MSG)
3542 printk(KERN_DEBUG "%s: HFC_ECHOCAN_ON\n", __func__);
3543 if (test_bit(HFC_CHIP_B410P, &hc->chip))
3544 vpm_echocan_on(hc, bch->slot, cq->p1);
3545 else
3546 ret = -EINVAL;
3547 break;
3548
3549 case MISDN_CTRL_HFC_ECHOCAN_OFF:
3550 if (debug & DEBUG_HFCMULTI_MSG)
3551 printk(KERN_DEBUG "%s: HFC_ECHOCAN_OFF\n",
3552 __func__);
3553 if (test_bit(HFC_CHIP_B410P, &hc->chip))
3554 vpm_echocan_off(hc, bch->slot);
3555 else
3556 ret = -EINVAL;
3557 break;
3558 default:
3559 printk(KERN_WARNING "%s: unknown Op %x\n",
3560 __func__, cq->op);
3561 ret = -EINVAL;
3562 break;
3563 }
3564 return ret;
3565}
3566
3567static int
3568hfcm_bctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
3569{
3570 struct bchannel *bch = container_of(ch, struct bchannel, ch);
3571 struct hfc_multi *hc = bch->hw;
3572 int err = -EINVAL;
3573 u_long flags;
3574
3575 if (bch->debug & DEBUG_HW)
3576 printk(KERN_DEBUG "%s: cmd:%x %p\n",
3577 __func__, cmd, arg);
3578 switch (cmd) {
3579 case CLOSE_CHANNEL:
3580 test_and_clear_bit(FLG_OPEN, &bch->Flags);
3581 if (test_bit(FLG_ACTIVE, &bch->Flags))
3582 deactivate_bchannel(bch); /* locked there */
3583 ch->protocol = ISDN_P_NONE;
3584 ch->peer = NULL;
3585 module_put(THIS_MODULE);
3586 err = 0;
3587 break;
3588 case CONTROL_CHANNEL:
3589 spin_lock_irqsave(&hc->lock, flags);
3590 err = channel_bctrl(bch, arg);
3591 spin_unlock_irqrestore(&hc->lock, flags);
3592 break;
3593 default:
3594 printk(KERN_WARNING "%s: unknown prim(%x)\n",
3595 __func__, cmd);
3596 }
3597 return err;
3598}
3599
3600/*
3601 * handle D-channel events
3602 *
3603 * handle state change event
3604 */
3605static void
3606ph_state_change(struct dchannel *dch)
3607{
3608 struct hfc_multi *hc = dch->hw;
3609 int ch, i;
3610
3611 if (!dch) {
3612 printk(KERN_WARNING "%s: ERROR given dch is NULL\n",
3613 __func__);
3614 return;
3615 }
3616 ch = dch->slot;
3617
3618 if (hc->type == 1) {
3619 if (dch->dev.D.protocol == ISDN_P_TE_E1) {
3620 if (debug & DEBUG_HFCMULTI_STATE)
3621 printk(KERN_DEBUG
3622 "%s: E1 TE (id=%d) newstate %x\n",
3623 __func__, hc->id, dch->state);
3624 } else {
3625 if (debug & DEBUG_HFCMULTI_STATE)
3626 printk(KERN_DEBUG
3627 "%s: E1 NT (id=%d) newstate %x\n",
3628 __func__, hc->id, dch->state);
3629 }
3630 switch (dch->state) {
3631 case (1):
3632 if (hc->e1_state != 1) {
3633 for (i = 1; i <= 31; i++) {
3634 /* reset fifos on e1 activation */
3635 HFC_outb_nodebug(hc, R_FIFO, (i << 1) | 1);
3636 HFC_wait_nodebug(hc);
3637 HFC_outb_nodebug(hc,
3638 R_INC_RES_FIFO, V_RES_F);
3639 HFC_wait_nodebug(hc);
3640 }
3641 }
3642 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
3643 _queue_data(&dch->dev.D, PH_ACTIVATE_IND,
3644 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
3645 break;
3646
3647 default:
3648 if (hc->e1_state != 1)
3649 return;
3650 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
3651 _queue_data(&dch->dev.D, PH_DEACTIVATE_IND,
3652 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
3653 }
3654 hc->e1_state = dch->state;
3655 } else {
3656 if (dch->dev.D.protocol == ISDN_P_TE_S0) {
3657 if (debug & DEBUG_HFCMULTI_STATE)
3658 printk(KERN_DEBUG
3659 "%s: S/T TE newstate %x\n",
3660 __func__, dch->state);
3661 switch (dch->state) {
3662 case (0):
3663 l1_event(dch->l1, HW_RESET_IND);
3664 break;
3665 case (3):
3666 l1_event(dch->l1, HW_DEACT_IND);
3667 break;
3668 case (5):
3669 case (8):
3670 l1_event(dch->l1, ANYSIGNAL);
3671 break;
3672 case (6):
3673 l1_event(dch->l1, INFO2);
3674 break;
3675 case (7):
3676 l1_event(dch->l1, INFO4_P8);
3677 break;
3678 }
3679 } else {
3680 if (debug & DEBUG_HFCMULTI_STATE)
3681 printk(KERN_DEBUG "%s: S/T NT newstate %x\n",
3682 __func__, dch->state);
3683 switch (dch->state) {
3684 case (2):
3685 if (hc->chan[ch].nt_timer == 0) {
3686 hc->chan[ch].nt_timer = -1;
3687 HFC_outb(hc, R_ST_SEL,
3688 hc->chan[ch].port);
3689 /* undocumented: delay after R_ST_SEL */
3690 udelay(1);
3691 HFC_outb(hc, A_ST_WR_STATE, 4 |
3692 V_ST_LD_STA); /* G4 */
3693 udelay(6); /* wait at least 5,21us */
3694 HFC_outb(hc, A_ST_WR_STATE, 4);
3695 dch->state = 4;
3696 } else {
3697 /* one extra count for the next event */
3698 hc->chan[ch].nt_timer =
3699 nt_t1_count[poll_timer] + 1;
3700 HFC_outb(hc, R_ST_SEL,
3701 hc->chan[ch].port);
3702 /* undocumented: delay after R_ST_SEL */
3703 udelay(1);
3704 /* allow G2 -> G3 transition */
3705 HFC_outb(hc, A_ST_WR_STATE, 2 |
3706 V_SET_G2_G3);
3707 }
3708 break;
3709 case (1):
3710 hc->chan[ch].nt_timer = -1;
3711 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
3712 _queue_data(&dch->dev.D, PH_DEACTIVATE_IND,
3713 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
3714 break;
3715 case (4):
3716 hc->chan[ch].nt_timer = -1;
3717 break;
3718 case (3):
3719 hc->chan[ch].nt_timer = -1;
3720 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
3721 _queue_data(&dch->dev.D, PH_ACTIVATE_IND,
3722 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
3723 break;
3724 }
3725 }
3726 }
3727}
3728
3729/*
3730 * called for card mode init message
3731 */
3732
3733static void
3734hfcmulti_initmode(struct dchannel *dch)
3735{
3736 struct hfc_multi *hc = dch->hw;
3737 u_char a_st_wr_state, r_e1_wr_sta;
3738 int i, pt;
3739
3740 if (debug & DEBUG_HFCMULTI_INIT)
3741 printk(KERN_DEBUG "%s: entered\n", __func__);
3742
3743 if (hc->type == 1) {
3744 hc->chan[hc->dslot].slot_tx = -1;
3745 hc->chan[hc->dslot].slot_rx = -1;
3746 hc->chan[hc->dslot].conf = -1;
3747 if (hc->dslot) {
3748 mode_hfcmulti(hc, hc->dslot, dch->dev.D.protocol,
3749 -1, 0, -1, 0);
3750 dch->timer.function = (void *) hfcmulti_dbusy_timer;
3751 dch->timer.data = (long) dch;
3752 init_timer(&dch->timer);
3753 }
3754 for (i = 1; i <= 31; i++) {
3755 if (i == hc->dslot)
3756 continue;
3757 hc->chan[i].slot_tx = -1;
3758 hc->chan[i].slot_rx = -1;
3759 hc->chan[i].conf = -1;
3760 mode_hfcmulti(hc, i, ISDN_P_NONE, -1, 0, -1, 0);
3761 }
3762 /* E1 */
3763 if (test_bit(HFC_CFG_REPORT_LOS, &hc->chan[hc->dslot].cfg)) {
3764 HFC_outb(hc, R_LOS0, 255); /* 2 ms */
3765 HFC_outb(hc, R_LOS1, 255); /* 512 ms */
3766 }
3767 if (test_bit(HFC_CFG_OPTICAL, &hc->chan[hc->dslot].cfg)) {
3768 HFC_outb(hc, R_RX0, 0);
3769 hc->hw.r_tx0 = 0 | V_OUT_EN;
3770 } else {
3771 HFC_outb(hc, R_RX0, 1);
3772 hc->hw.r_tx0 = 1 | V_OUT_EN;
3773 }
3774 hc->hw.r_tx1 = V_ATX | V_NTRI;
3775 HFC_outb(hc, R_TX0, hc->hw.r_tx0);
3776 HFC_outb(hc, R_TX1, hc->hw.r_tx1);
3777 HFC_outb(hc, R_TX_FR0, 0x00);
3778 HFC_outb(hc, R_TX_FR1, 0xf8);
3779
3780 if (test_bit(HFC_CFG_CRC4, &hc->chan[hc->dslot].cfg))
3781 HFC_outb(hc, R_TX_FR2, V_TX_MF | V_TX_E | V_NEG_E);
3782
3783 HFC_outb(hc, R_RX_FR0, V_AUTO_RESYNC | V_AUTO_RECO | 0);
3784
3785 if (test_bit(HFC_CFG_CRC4, &hc->chan[hc->dslot].cfg))
3786 HFC_outb(hc, R_RX_FR1, V_RX_MF | V_RX_MF_SYNC);
3787
3788 if (dch->dev.D.protocol == ISDN_P_NT_E1) {
3789 if (debug & DEBUG_HFCMULTI_INIT)
3790 printk(KERN_DEBUG "%s: E1 port is NT-mode\n",
3791 __func__);
3792 r_e1_wr_sta = 0; /* G0 */
3793 hc->e1_getclock = 0;
3794 } else {
3795 if (debug & DEBUG_HFCMULTI_INIT)
3796 printk(KERN_DEBUG "%s: E1 port is TE-mode\n",
3797 __func__);
3798 r_e1_wr_sta = 0; /* F0 */
3799 hc->e1_getclock = 1;
3800 }
3801 if (test_bit(HFC_CHIP_RX_SYNC, &hc->chip))
3802 HFC_outb(hc, R_SYNC_OUT, V_SYNC_E1_RX);
3803 else
3804 HFC_outb(hc, R_SYNC_OUT, 0);
3805 if (test_bit(HFC_CHIP_E1CLOCK_GET, &hc->chip))
3806 hc->e1_getclock = 1;
3807 if (test_bit(HFC_CHIP_E1CLOCK_PUT, &hc->chip))
3808 hc->e1_getclock = 0;
3809 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
3810 /* SLAVE (clock master) */
3811 if (debug & DEBUG_HFCMULTI_INIT)
3812 printk(KERN_DEBUG
3813 "%s: E1 port is clock master "
3814 "(clock from PCM)\n", __func__);
3815 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC | V_PCM_SYNC);
3816 } else {
3817 if (hc->e1_getclock) {
3818 /* MASTER (clock slave) */
3819 if (debug & DEBUG_HFCMULTI_INIT)
3820 printk(KERN_DEBUG
3821 "%s: E1 port is clock slave "
3822 "(clock to PCM)\n", __func__);
3823 HFC_outb(hc, R_SYNC_CTRL, V_SYNC_OFFS);
3824 } else {
3825 /* MASTER (clock master) */
3826 if (debug & DEBUG_HFCMULTI_INIT)
3827 printk(KERN_DEBUG "%s: E1 port is "
3828 "clock master "
3829 "(clock from QUARTZ)\n",
3830 __func__);
3831 HFC_outb(hc, R_SYNC_CTRL, V_EXT_CLK_SYNC |
3832 V_PCM_SYNC | V_JATT_OFF);
3833 HFC_outb(hc, R_SYNC_OUT, 0);
3834 }
3835 }
3836 HFC_outb(hc, R_JATT_ATT, 0x9c); /* undoc register */
3837 HFC_outb(hc, R_PWM_MD, V_PWM0_MD);
3838 HFC_outb(hc, R_PWM0, 0x50);
3839 HFC_outb(hc, R_PWM1, 0xff);
3840 /* state machine setup */
3841 HFC_outb(hc, R_E1_WR_STA, r_e1_wr_sta | V_E1_LD_STA);
3842 udelay(6); /* wait at least 5,21us */
3843 HFC_outb(hc, R_E1_WR_STA, r_e1_wr_sta);
3844 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
3845 hc->syncronized = 0;
3846 plxsd_checksync(hc, 0);
3847 }
3848 } else {
3849 i = dch->slot;
3850 hc->chan[i].slot_tx = -1;
3851 hc->chan[i].slot_rx = -1;
3852 hc->chan[i].conf = -1;
3853 mode_hfcmulti(hc, i, dch->dev.D.protocol, -1, 0, -1, 0);
3854 dch->timer.function = (void *)hfcmulti_dbusy_timer;
3855 dch->timer.data = (long) dch;
3856 init_timer(&dch->timer);
3857 hc->chan[i - 2].slot_tx = -1;
3858 hc->chan[i - 2].slot_rx = -1;
3859 hc->chan[i - 2].conf = -1;
3860 mode_hfcmulti(hc, i - 2, ISDN_P_NONE, -1, 0, -1, 0);
3861 hc->chan[i - 1].slot_tx = -1;
3862 hc->chan[i - 1].slot_rx = -1;
3863 hc->chan[i - 1].conf = -1;
3864 mode_hfcmulti(hc, i - 1, ISDN_P_NONE, -1, 0, -1, 0);
3865 /* ST */
3866 pt = hc->chan[i].port;
3867 /* select interface */
3868 HFC_outb(hc, R_ST_SEL, pt);
3869 /* undocumented: delay after R_ST_SEL */
3870 udelay(1);
3871 if (dch->dev.D.protocol == ISDN_P_NT_S0) {
3872 if (debug & DEBUG_HFCMULTI_INIT)
3873 printk(KERN_DEBUG
3874 "%s: ST port %d is NT-mode\n",
3875 __func__, pt);
3876 /* clock delay */
3877 HFC_outb(hc, A_ST_CLK_DLY, clockdelay_nt);
3878 a_st_wr_state = 1; /* G1 */
3879 hc->hw.a_st_ctrl0[pt] = V_ST_MD;
3880 } else {
3881 if (debug & DEBUG_HFCMULTI_INIT)
3882 printk(KERN_DEBUG
3883 "%s: ST port %d is TE-mode\n",
3884 __func__, pt);
3885 /* clock delay */
3886 HFC_outb(hc, A_ST_CLK_DLY, clockdelay_te);
3887 a_st_wr_state = 2; /* F2 */
3888 hc->hw.a_st_ctrl0[pt] = 0;
3889 }
3890 if (!test_bit(HFC_CFG_NONCAP_TX, &hc->chan[i].cfg))
3891 hc->hw.a_st_ctrl0[pt] |= V_TX_LI;
3892 /* line setup */
3893 HFC_outb(hc, A_ST_CTRL0, hc->hw.a_st_ctrl0[pt]);
3894 /* disable E-channel */
3895 if ((dch->dev.D.protocol == ISDN_P_NT_S0) ||
3896 test_bit(HFC_CFG_DIS_ECHANNEL, &hc->chan[i].cfg))
3897 HFC_outb(hc, A_ST_CTRL1, V_E_IGNO);
3898 else
3899 HFC_outb(hc, A_ST_CTRL1, 0);
3900 /* enable B-channel receive */
3901 HFC_outb(hc, A_ST_CTRL2, V_B1_RX_EN | V_B2_RX_EN);
3902 /* state machine setup */
3903 HFC_outb(hc, A_ST_WR_STATE, a_st_wr_state | V_ST_LD_STA);
3904 udelay(6); /* wait at least 5,21us */
3905 HFC_outb(hc, A_ST_WR_STATE, a_st_wr_state);
3906 hc->hw.r_sci_msk |= 1 << pt;
3907 /* state machine interrupts */
3908 HFC_outb(hc, R_SCI_MSK, hc->hw.r_sci_msk);
3909 /* unset sync on port */
3910 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
3911 hc->syncronized &=
3912 ~(1 << hc->chan[dch->slot].port);
3913 plxsd_checksync(hc, 0);
3914 }
3915 }
3916 if (debug & DEBUG_HFCMULTI_INIT)
3917 printk("%s: done\n", __func__);
3918}
3919
3920
3921static int
3922open_dchannel(struct hfc_multi *hc, struct dchannel *dch,
3923 struct channel_req *rq)
3924{
3925 int err = 0;
3926 u_long flags;
3927
3928 if (debug & DEBUG_HW_OPEN)
3929 printk(KERN_DEBUG "%s: dev(%d) open from %p\n", __func__,
3930 dch->dev.id, __builtin_return_address(0));
3931 if (rq->protocol == ISDN_P_NONE)
3932 return -EINVAL;
3933 if ((dch->dev.D.protocol != ISDN_P_NONE) &&
3934 (dch->dev.D.protocol != rq->protocol)) {
3935 if (debug & DEBUG_HFCMULTI_MODE)
3936 printk(KERN_WARNING "%s: change protocol %x to %x\n",
3937 __func__, dch->dev.D.protocol, rq->protocol);
3938 }
3939 if ((dch->dev.D.protocol == ISDN_P_TE_S0)
3940 && (rq->protocol != ISDN_P_TE_S0))
3941 l1_event(dch->l1, CLOSE_CHANNEL);
3942 if (dch->dev.D.protocol != rq->protocol) {
3943 if (rq->protocol == ISDN_P_TE_S0) {
3944 err = create_l1(dch, hfcm_l1callback);
3945 if (err)
3946 return err;
3947 }
3948 dch->dev.D.protocol = rq->protocol;
3949 spin_lock_irqsave(&hc->lock, flags);
3950 hfcmulti_initmode(dch);
3951 spin_unlock_irqrestore(&hc->lock, flags);
3952 }
3953
3954 if (((rq->protocol == ISDN_P_NT_S0) && (dch->state == 3)) ||
3955 ((rq->protocol == ISDN_P_TE_S0) && (dch->state == 7)) ||
3956 ((rq->protocol == ISDN_P_NT_E1) && (dch->state == 1)) ||
3957 ((rq->protocol == ISDN_P_TE_E1) && (dch->state == 1))) {
3958 _queue_data(&dch->dev.D, PH_ACTIVATE_IND, MISDN_ID_ANY,
3959 0, NULL, GFP_KERNEL);
3960 }
3961 rq->ch = &dch->dev.D;
3962 if (!try_module_get(THIS_MODULE))
3963 printk(KERN_WARNING "%s:cannot get module\n", __func__);
3964 return 0;
3965}
3966
3967static int
3968open_bchannel(struct hfc_multi *hc, struct dchannel *dch,
3969 struct channel_req *rq)
3970{
3971 struct bchannel *bch;
3972 int ch;
3973
3974 if (!test_bit(rq->adr.channel, &dch->dev.channelmap[0]))
3975 return -EINVAL;
3976 if (rq->protocol == ISDN_P_NONE)
3977 return -EINVAL;
3978 if (hc->type == 1)
3979 ch = rq->adr.channel;
3980 else
3981 ch = (rq->adr.channel - 1) + (dch->slot - 2);
3982 bch = hc->chan[ch].bch;
3983 if (!bch) {
3984 printk(KERN_ERR "%s:internal error ch %d has no bch\n",
3985 __func__, ch);
3986 return -EINVAL;
3987 }
3988 if (test_and_set_bit(FLG_OPEN, &bch->Flags))
3989 return -EBUSY; /* b-channel can be only open once */
3990 bch->ch.protocol = rq->protocol;
3991 hc->chan[ch].rx_off = 0;
3992 rq->ch = &bch->ch;
3993 if (!try_module_get(THIS_MODULE))
3994 printk(KERN_WARNING "%s:cannot get module\n", __func__);
3995 return 0;
3996}
3997
3998/*
3999 * device control function
4000 */
4001static int
4002channel_dctrl(struct dchannel *dch, struct mISDN_ctrl_req *cq)
4003{
4004 int ret = 0;
4005
4006 switch (cq->op) {
4007 case MISDN_CTRL_GETOP:
4008 cq->op = 0;
4009 break;
4010 default:
4011 printk(KERN_WARNING "%s: unknown Op %x\n",
4012 __func__, cq->op);
4013 ret = -EINVAL;
4014 break;
4015 }
4016 return ret;
4017}
4018
4019static int
4020hfcm_dctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
4021{
4022 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
4023 struct dchannel *dch = container_of(dev, struct dchannel, dev);
4024 struct hfc_multi *hc = dch->hw;
4025 struct channel_req *rq;
4026 int err = 0;
4027 u_long flags;
4028
4029 if (dch->debug & DEBUG_HW)
4030 printk(KERN_DEBUG "%s: cmd:%x %p\n",
4031 __func__, cmd, arg);
4032 switch (cmd) {
4033 case OPEN_CHANNEL:
4034 rq = arg;
4035 switch (rq->protocol) {
4036 case ISDN_P_TE_S0:
4037 case ISDN_P_NT_S0:
4038 if (hc->type == 1) {
4039 err = -EINVAL;
4040 break;
4041 }
4042 err = open_dchannel(hc, dch, rq); /* locked there */
4043 break;
4044 case ISDN_P_TE_E1:
4045 case ISDN_P_NT_E1:
4046 if (hc->type != 1) {
4047 err = -EINVAL;
4048 break;
4049 }
4050 err = open_dchannel(hc, dch, rq); /* locked there */
4051 break;
4052 default:
4053 spin_lock_irqsave(&hc->lock, flags);
4054 err = open_bchannel(hc, dch, rq);
4055 spin_unlock_irqrestore(&hc->lock, flags);
4056 }
4057 break;
4058 case CLOSE_CHANNEL:
4059 if (debug & DEBUG_HW_OPEN)
4060 printk(KERN_DEBUG "%s: dev(%d) close from %p\n",
4061 __func__, dch->dev.id,
4062 __builtin_return_address(0));
4063 module_put(THIS_MODULE);
4064 break;
4065 case CONTROL_CHANNEL:
4066 spin_lock_irqsave(&hc->lock, flags);
4067 err = channel_dctrl(dch, arg);
4068 spin_unlock_irqrestore(&hc->lock, flags);
4069 break;
4070 default:
4071 if (dch->debug & DEBUG_HW)
4072 printk(KERN_DEBUG "%s: unknown command %x\n",
4073 __func__, cmd);
4074 err = -EINVAL;
4075 }
4076 return err;
4077}
4078
4079/*
4080 * initialize the card
4081 */
4082
4083/*
4084 * start timer irq, wait some time and check if we have interrupts.
4085 * if not, reset chip and try again.
4086 */
4087static int
4088init_card(struct hfc_multi *hc)
4089{
4090 int err = -EIO;
4091 u_long flags;
4092 u_short *plx_acc;
4093 u_long plx_flags;
4094
4095 if (debug & DEBUG_HFCMULTI_INIT)
4096 printk(KERN_DEBUG "%s: entered\n", __func__);
4097
4098 spin_lock_irqsave(&hc->lock, flags);
4099 /* set interrupts but leave global interrupt disabled */
4100 hc->hw.r_irq_ctrl = V_FIFO_IRQ;
4101 disable_hwirq(hc);
4102 spin_unlock_irqrestore(&hc->lock, flags);
4103
4104 if (request_irq(hc->pci_dev->irq, hfcmulti_interrupt, IRQF_SHARED,
4105 "HFC-multi", hc)) {
4106 printk(KERN_WARNING "mISDN: Could not get interrupt %d.\n",
4107 hc->pci_dev->irq);
4108 return -EIO;
4109 }
4110 hc->irq = hc->pci_dev->irq;
4111
4112 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4113 spin_lock_irqsave(&plx_lock, plx_flags);
4114 plx_acc = (u_short *)(hc->plx_membase+PLX_INTCSR);
4115 writew((PLX_INTCSR_PCIINT_ENABLE | PLX_INTCSR_LINTI1_ENABLE),
4116 plx_acc); /* enable PCI & LINT1 irq */
4117 spin_unlock_irqrestore(&plx_lock, plx_flags);
4118 }
4119
4120 if (debug & DEBUG_HFCMULTI_INIT)
4121 printk(KERN_DEBUG "%s: IRQ %d count %d\n",
4122 __func__, hc->irq, hc->irqcnt);
4123 err = init_chip(hc);
4124 if (err)
4125 goto error;
4126 /*
4127 * Finally enable IRQ output
4128 * this is only allowed, if an IRQ routine is allready
4129 * established for this HFC, so don't do that earlier
4130 */
4131 spin_lock_irqsave(&hc->lock, flags);
4132 enable_hwirq(hc);
4133 spin_unlock_irqrestore(&hc->lock, flags);
4134 /* printk(KERN_DEBUG "no master irq set!!!\n"); */
4135 set_current_state(TASK_UNINTERRUPTIBLE);
4136 schedule_timeout((100*HZ)/1000); /* Timeout 100ms */
4137 /* turn IRQ off until chip is completely initialized */
4138 spin_lock_irqsave(&hc->lock, flags);
4139 disable_hwirq(hc);
4140 spin_unlock_irqrestore(&hc->lock, flags);
4141 if (debug & DEBUG_HFCMULTI_INIT)
4142 printk(KERN_DEBUG "%s: IRQ %d count %d\n",
4143 __func__, hc->irq, hc->irqcnt);
4144 if (hc->irqcnt) {
4145 if (debug & DEBUG_HFCMULTI_INIT)
4146 printk(KERN_DEBUG "%s: done\n", __func__);
4147
4148 return 0;
4149 }
4150 if (test_bit(HFC_CHIP_PCM_SLAVE, &hc->chip)) {
4151 printk(KERN_INFO "ignoring missing interrupts\n");
4152 return 0;
4153 }
4154
4155 printk(KERN_ERR "HFC PCI: IRQ(%d) getting no interrupts during init.\n",
4156 hc->irq);
4157
4158 err = -EIO;
4159
4160error:
4161 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4162 spin_lock_irqsave(&plx_lock, plx_flags);
4163 plx_acc = (u_short *)(hc->plx_membase+PLX_INTCSR);
4164 writew(0x00, plx_acc); /*disable IRQs*/
4165 spin_unlock_irqrestore(&plx_lock, plx_flags);
4166 }
4167
4168 if (debug & DEBUG_HFCMULTI_INIT)
4169 printk(KERN_WARNING "%s: free irq %d\n", __func__, hc->irq);
4170 if (hc->irq) {
4171 free_irq(hc->irq, hc);
4172 hc->irq = 0;
4173 }
4174
4175 if (debug & DEBUG_HFCMULTI_INIT)
4176 printk(KERN_DEBUG "%s: done (err=%d)\n", __func__, err);
4177 return err;
4178}
4179
4180/*
4181 * find pci device and set it up
4182 */
4183
4184static int
4185setup_pci(struct hfc_multi *hc, struct pci_dev *pdev,
4186 const struct pci_device_id *ent)
4187{
4188 struct hm_map *m = (struct hm_map *)ent->driver_data;
4189
4190 printk(KERN_INFO
4191 "HFC-multi: card manufacturer: '%s' card name: '%s' clock: %s\n",
4192 m->vendor_name, m->card_name, m->clock2 ? "double" : "normal");
4193
4194 hc->pci_dev = pdev;
4195 if (m->clock2)
4196 test_and_set_bit(HFC_CHIP_CLOCK2, &hc->chip);
4197
4198 if (ent->device == 0xB410) {
4199 test_and_set_bit(HFC_CHIP_B410P, &hc->chip);
4200 test_and_set_bit(HFC_CHIP_PCM_MASTER, &hc->chip);
4201 test_and_clear_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
4202 hc->slots = 32;
4203 }
4204
4205 if (hc->pci_dev->irq <= 0) {
4206 printk(KERN_WARNING "HFC-multi: No IRQ for PCI card found.\n");
4207 return -EIO;
4208 }
4209 if (pci_enable_device(hc->pci_dev)) {
4210 printk(KERN_WARNING "HFC-multi: Error enabling PCI card.\n");
4211 return -EIO;
4212 }
4213 hc->leds = m->leds;
4214 hc->ledstate = 0xAFFEAFFE;
4215 hc->opticalsupport = m->opticalsupport;
4216
4217 /* set memory access methods */
4218 if (m->io_mode) /* use mode from card config */
4219 hc->io_mode = m->io_mode;
4220 switch (hc->io_mode) {
4221 case HFC_IO_MODE_PLXSD:
4222 test_and_set_bit(HFC_CHIP_PLXSD, &hc->chip);
4223 hc->slots = 128; /* required */
4224 /* fall through */
4225 case HFC_IO_MODE_PCIMEM:
4226 hc->HFC_outb = HFC_outb_pcimem;
4227 hc->HFC_inb = HFC_inb_pcimem;
4228 hc->HFC_inw = HFC_inw_pcimem;
4229 hc->HFC_wait = HFC_wait_pcimem;
4230 hc->read_fifo = read_fifo_pcimem;
4231 hc->write_fifo = write_fifo_pcimem;
4232 break;
4233 case HFC_IO_MODE_REGIO:
4234 hc->HFC_outb = HFC_outb_regio;
4235 hc->HFC_inb = HFC_inb_regio;
4236 hc->HFC_inw = HFC_inw_regio;
4237 hc->HFC_wait = HFC_wait_regio;
4238 hc->read_fifo = read_fifo_regio;
4239 hc->write_fifo = write_fifo_regio;
4240 break;
4241 default:
4242 printk(KERN_WARNING "HFC-multi: Invalid IO mode.\n");
4243 pci_disable_device(hc->pci_dev);
4244 return -EIO;
4245 }
4246 hc->HFC_outb_nodebug = hc->HFC_outb;
4247 hc->HFC_inb_nodebug = hc->HFC_inb;
4248 hc->HFC_inw_nodebug = hc->HFC_inw;
4249 hc->HFC_wait_nodebug = hc->HFC_wait;
4250#ifdef HFC_REGISTER_DEBUG
4251 hc->HFC_outb = HFC_outb_debug;
4252 hc->HFC_inb = HFC_inb_debug;
4253 hc->HFC_inw = HFC_inw_debug;
4254 hc->HFC_wait = HFC_wait_debug;
4255#endif
4256 hc->pci_iobase = 0;
4257 hc->pci_membase = NULL;
4258 hc->plx_membase = NULL;
4259
4260 switch (hc->io_mode) {
4261 case HFC_IO_MODE_PLXSD:
4262 hc->plx_origmembase = hc->pci_dev->resource[0].start;
4263 /* MEMBASE 1 is PLX PCI Bridge */
4264
4265 if (!hc->plx_origmembase) {
4266 printk(KERN_WARNING
4267 "HFC-multi: No IO-Memory for PCI PLX bridge found\n");
4268 pci_disable_device(hc->pci_dev);
4269 return -EIO;
4270 }
4271
4272 hc->plx_membase = ioremap(hc->plx_origmembase, 0x80);
4273 if (!hc->plx_membase) {
4274 printk(KERN_WARNING
4275 "HFC-multi: failed to remap plx address space. "
4276 "(internal error)\n");
4277 pci_disable_device(hc->pci_dev);
4278 return -EIO;
4279 }
4280 printk(KERN_INFO
4281 "HFC-multi: plx_membase:%#lx plx_origmembase:%#lx\n",
4282 (u_long)hc->plx_membase, hc->plx_origmembase);
4283
4284 hc->pci_origmembase = hc->pci_dev->resource[2].start;
4285 /* MEMBASE 1 is PLX PCI Bridge */
4286 if (!hc->pci_origmembase) {
4287 printk(KERN_WARNING
4288 "HFC-multi: No IO-Memory for PCI card found\n");
4289 pci_disable_device(hc->pci_dev);
4290 return -EIO;
4291 }
4292
4293 hc->pci_membase = ioremap(hc->pci_origmembase, 0x400);
4294 if (!hc->pci_membase) {
4295 printk(KERN_WARNING "HFC-multi: failed to remap io "
4296 "address space. (internal error)\n");
4297 pci_disable_device(hc->pci_dev);
4298 return -EIO;
4299 }
4300
4301 printk(KERN_INFO
4302 "card %d: defined at MEMBASE %#lx (%#lx) IRQ %d HZ %d "
4303 "leds-type %d\n",
4304 hc->id, (u_long)hc->pci_membase, hc->pci_origmembase,
4305 hc->pci_dev->irq, HZ, hc->leds);
4306 pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_MEMIO);
4307 break;
4308 case HFC_IO_MODE_PCIMEM:
4309 hc->pci_origmembase = hc->pci_dev->resource[1].start;
4310 if (!hc->pci_origmembase) {
4311 printk(KERN_WARNING
4312 "HFC-multi: No IO-Memory for PCI card found\n");
4313 pci_disable_device(hc->pci_dev);
4314 return -EIO;
4315 }
4316
4317 hc->pci_membase = ioremap(hc->pci_origmembase, 256);
4318 if (!hc->pci_membase) {
4319 printk(KERN_WARNING
4320 "HFC-multi: failed to remap io address space. "
4321 "(internal error)\n");
4322 pci_disable_device(hc->pci_dev);
4323 return -EIO;
4324 }
4325 printk(KERN_INFO "card %d: defined at MEMBASE %#lx (%#lx) IRQ %d "
4326 "HZ %d leds-type %d\n", hc->id, (u_long)hc->pci_membase,
4327 hc->pci_origmembase, hc->pci_dev->irq, HZ, hc->leds);
4328 pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_MEMIO);
4329 break;
4330 case HFC_IO_MODE_REGIO:
4331 hc->pci_iobase = (u_int) hc->pci_dev->resource[0].start;
4332 if (!hc->pci_iobase) {
4333 printk(KERN_WARNING
4334 "HFC-multi: No IO for PCI card found\n");
4335 pci_disable_device(hc->pci_dev);
4336 return -EIO;
4337 }
4338
4339 if (!request_region(hc->pci_iobase, 8, "hfcmulti")) {
4340 printk(KERN_WARNING "HFC-multi: failed to request "
4341 "address space at 0x%08lx (internal error)\n",
4342 hc->pci_iobase);
4343 pci_disable_device(hc->pci_dev);
4344 return -EIO;
4345 }
4346
4347 printk(KERN_INFO
4348 "%s %s: defined at IOBASE %#x IRQ %d HZ %d leds-type %d\n",
4349 m->vendor_name, m->card_name, (u_int) hc->pci_iobase,
4350 hc->pci_dev->irq, HZ, hc->leds);
4351 pci_write_config_word(hc->pci_dev, PCI_COMMAND, PCI_ENA_REGIO);
4352 break;
4353 default:
4354 printk(KERN_WARNING "HFC-multi: Invalid IO mode.\n");
4355 pci_disable_device(hc->pci_dev);
4356 return -EIO;
4357 }
4358
4359 pci_set_drvdata(hc->pci_dev, hc);
4360
4361 /* At this point the needed PCI config is done */
4362 /* fifos are still not enabled */
4363 return 0;
4364}
4365
4366
4367/*
4368 * remove port
4369 */
4370
4371static void
4372release_port(struct hfc_multi *hc, struct dchannel *dch)
4373{
4374 int pt, ci, i = 0;
4375 u_long flags;
4376 struct bchannel *pb;
4377
4378 ci = dch->slot;
4379 pt = hc->chan[ci].port;
4380
4381 if (debug & DEBUG_HFCMULTI_INIT)
4382 printk(KERN_DEBUG "%s: entered for port %d\n",
4383 __func__, pt + 1);
4384
4385 if (pt >= hc->ports) {
4386 printk(KERN_WARNING "%s: ERROR port out of range (%d).\n",
4387 __func__, pt + 1);
4388 return;
4389 }
4390
4391 if (debug & DEBUG_HFCMULTI_INIT)
4392 printk(KERN_DEBUG "%s: releasing port=%d\n",
4393 __func__, pt + 1);
4394
4395 if (dch->dev.D.protocol == ISDN_P_TE_S0)
4396 l1_event(dch->l1, CLOSE_CHANNEL);
4397
4398 hc->chan[ci].dch = NULL;
4399
4400 if (hc->created[pt]) {
4401 hc->created[pt] = 0;
4402 mISDN_unregister_device(&dch->dev);
4403 }
4404
4405 spin_lock_irqsave(&hc->lock, flags);
4406
4407 if (dch->timer.function) {
4408 del_timer(&dch->timer);
4409 dch->timer.function = NULL;
4410 }
4411
4412 if (hc->type == 1) { /* E1 */
4413 /* remove sync */
4414 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4415 hc->syncronized = 0;
4416 plxsd_checksync(hc, 1);
4417 }
4418 /* free channels */
4419 for (i = 0; i <= 31; i++) {
4420 if (hc->chan[i].bch) {
4421 if (debug & DEBUG_HFCMULTI_INIT)
4422 printk(KERN_DEBUG
4423 "%s: free port %d channel %d\n",
4424 __func__, hc->chan[i].port+1, i);
4425 pb = hc->chan[i].bch;
4426 hc->chan[i].bch = NULL;
4427 spin_unlock_irqrestore(&hc->lock, flags);
4428 mISDN_freebchannel(pb);
4429 kfree(pb);
4430 kfree(hc->chan[i].coeff);
4431 spin_lock_irqsave(&hc->lock, flags);
4432 }
4433 }
4434 } else {
4435 /* remove sync */
4436 if (test_bit(HFC_CHIP_PLXSD, &hc->chip)) {
4437 hc->syncronized &=
4438 ~(1 << hc->chan[ci].port);
4439 plxsd_checksync(hc, 1);
4440 }
4441 /* free channels */
4442 if (hc->chan[ci - 2].bch) {
4443 if (debug & DEBUG_HFCMULTI_INIT)
4444 printk(KERN_DEBUG
4445 "%s: free port %d channel %d\n",
4446 __func__, hc->chan[ci - 2].port+1,
4447 ci - 2);
4448 pb = hc->chan[ci - 2].bch;
4449 hc->chan[ci - 2].bch = NULL;
4450 spin_unlock_irqrestore(&hc->lock, flags);
4451 mISDN_freebchannel(pb);
4452 kfree(pb);
4453 kfree(hc->chan[ci - 2].coeff);
4454 spin_lock_irqsave(&hc->lock, flags);
4455 }
4456 if (hc->chan[ci - 1].bch) {
4457 if (debug & DEBUG_HFCMULTI_INIT)
4458 printk(KERN_DEBUG
4459 "%s: free port %d channel %d\n",
4460 __func__, hc->chan[ci - 1].port+1,
4461 ci - 1);
4462 pb = hc->chan[ci - 1].bch;
4463 hc->chan[ci - 1].bch = NULL;
4464 spin_unlock_irqrestore(&hc->lock, flags);
4465 mISDN_freebchannel(pb);
4466 kfree(pb);
4467 kfree(hc->chan[ci - 1].coeff);
4468 spin_lock_irqsave(&hc->lock, flags);
4469 }
4470 }
4471
4472 spin_unlock_irqrestore(&hc->lock, flags);
4473
4474 if (debug & DEBUG_HFCMULTI_INIT)
4475 printk(KERN_DEBUG "%s: free port %d channel D\n", __func__, pt);
4476 mISDN_freedchannel(dch);
4477 kfree(dch);
4478
4479 if (debug & DEBUG_HFCMULTI_INIT)
4480 printk(KERN_DEBUG "%s: done!\n", __func__);
4481}
4482
4483static void
4484release_card(struct hfc_multi *hc)
4485{
4486 u_long flags;
4487 int ch;
4488
4489 if (debug & DEBUG_HFCMULTI_INIT)
4490 printk(KERN_WARNING "%s: release card (%d) entered\n",
4491 __func__, hc->id);
4492
4493 spin_lock_irqsave(&hc->lock, flags);
4494 disable_hwirq(hc);
4495 spin_unlock_irqrestore(&hc->lock, flags);
4496
4497 udelay(1000);
4498
4499 /* dimm leds */
4500 if (hc->leds)
4501 hfcmulti_leds(hc);
4502
4503 /* disable D-channels & B-channels */
4504 if (debug & DEBUG_HFCMULTI_INIT)
4505 printk(KERN_DEBUG "%s: disable all channels (d and b)\n",
4506 __func__);
4507 for (ch = 0; ch <= 31; ch++) {
4508 if (hc->chan[ch].dch)
4509 release_port(hc, hc->chan[ch].dch);
4510 }
4511
4512 /* release hardware & irq */
4513 if (hc->irq) {
4514 if (debug & DEBUG_HFCMULTI_INIT)
4515 printk(KERN_WARNING "%s: free irq %d\n",
4516 __func__, hc->irq);
4517 free_irq(hc->irq, hc);
4518 hc->irq = 0;
4519
4520 }
4521 release_io_hfcmulti(hc);
4522
4523 if (debug & DEBUG_HFCMULTI_INIT)
4524 printk(KERN_WARNING "%s: remove instance from list\n",
4525 __func__);
4526 list_del(&hc->list);
4527
4528 if (debug & DEBUG_HFCMULTI_INIT)
4529 printk(KERN_WARNING "%s: delete instance\n", __func__);
4530 if (hc == syncmaster)
4531 syncmaster = NULL;
4532 kfree(hc);
4533 if (debug & DEBUG_HFCMULTI_INIT)
4534 printk(KERN_WARNING "%s: card successfully removed\n",
4535 __func__);
4536}
4537
4538static int
4539init_e1_port(struct hfc_multi *hc, struct hm_map *m)
4540{
4541 struct dchannel *dch;
4542 struct bchannel *bch;
4543 int ch, ret = 0;
4544 char name[MISDN_MAX_IDLEN];
4545
4546 dch = kzalloc(sizeof(struct dchannel), GFP_KERNEL);
4547 if (!dch)
4548 return -ENOMEM;
4549 dch->debug = debug;
4550 mISDN_initdchannel(dch, MAX_DFRAME_LEN_L1, ph_state_change);
4551 dch->hw = hc;
4552 dch->dev.Dprotocols = (1 << ISDN_P_TE_E1) | (1 << ISDN_P_NT_E1);
4553 dch->dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
4554 (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
4555 dch->dev.D.send = handle_dmsg;
4556 dch->dev.D.ctrl = hfcm_dctrl;
4557 dch->dev.nrbchan = (hc->dslot)?30:31;
4558 dch->slot = hc->dslot;
4559 hc->chan[hc->dslot].dch = dch;
4560 hc->chan[hc->dslot].port = 0;
4561 hc->chan[hc->dslot].nt_timer = -1;
4562 for (ch = 1; ch <= 31; ch++) {
4563 if (ch == hc->dslot) /* skip dchannel */
4564 continue;
4565 bch = kzalloc(sizeof(struct bchannel), GFP_KERNEL);
4566 if (!bch) {
4567 printk(KERN_ERR "%s: no memory for bchannel\n",
4568 __func__);
4569 ret = -ENOMEM;
4570 goto free_chan;
4571 }
4572 hc->chan[ch].coeff = kzalloc(512, GFP_KERNEL);
4573 if (!hc->chan[ch].coeff) {
4574 printk(KERN_ERR "%s: no memory for coeffs\n",
4575 __func__);
4576 ret = -ENOMEM;
4577 goto free_chan;
4578 }
4579 bch->nr = ch;
4580 bch->slot = ch;
4581 bch->debug = debug;
4582 mISDN_initbchannel(bch, MAX_DATA_MEM);
4583 bch->hw = hc;
4584 bch->ch.send = handle_bmsg;
4585 bch->ch.ctrl = hfcm_bctrl;
4586 bch->ch.nr = ch;
4587 list_add(&bch->ch.list, &dch->dev.bchannels);
4588 hc->chan[ch].bch = bch;
4589 hc->chan[ch].port = 0;
4590 test_and_set_bit(bch->nr, &dch->dev.channelmap[0]);
4591 }
4592 /* set optical line type */
4593 if (port[Port_cnt] & 0x001) {
4594 if (!m->opticalsupport) {
4595 printk(KERN_INFO
4596 "This board has no optical "
4597 "support\n");
4598 } else {
4599 if (debug & DEBUG_HFCMULTI_INIT)
4600 printk(KERN_DEBUG
4601 "%s: PORT set optical "
4602 "interfacs: card(%d) "
4603 "port(%d)\n",
4604 __func__,
4605 HFC_cnt + 1, 1);
4606 test_and_set_bit(HFC_CFG_OPTICAL,
4607 &hc->chan[hc->dslot].cfg);
4608 }
4609 }
4610 /* set LOS report */
4611 if (port[Port_cnt] & 0x004) {
4612 if (debug & DEBUG_HFCMULTI_INIT)
4613 printk(KERN_DEBUG "%s: PORT set "
4614 "LOS report: card(%d) port(%d)\n",
4615 __func__, HFC_cnt + 1, 1);
4616 test_and_set_bit(HFC_CFG_REPORT_LOS,
4617 &hc->chan[hc->dslot].cfg);
4618 }
4619 /* set AIS report */
4620 if (port[Port_cnt] & 0x008) {
4621 if (debug & DEBUG_HFCMULTI_INIT)
4622 printk(KERN_DEBUG "%s: PORT set "
4623 "AIS report: card(%d) port(%d)\n",
4624 __func__, HFC_cnt + 1, 1);
4625 test_and_set_bit(HFC_CFG_REPORT_AIS,
4626 &hc->chan[hc->dslot].cfg);
4627 }
4628 /* set SLIP report */
4629 if (port[Port_cnt] & 0x010) {
4630 if (debug & DEBUG_HFCMULTI_INIT)
4631 printk(KERN_DEBUG
4632 "%s: PORT set SLIP report: "
4633 "card(%d) port(%d)\n",
4634 __func__, HFC_cnt + 1, 1);
4635 test_and_set_bit(HFC_CFG_REPORT_SLIP,
4636 &hc->chan[hc->dslot].cfg);
4637 }
4638 /* set RDI report */
4639 if (port[Port_cnt] & 0x020) {
4640 if (debug & DEBUG_HFCMULTI_INIT)
4641 printk(KERN_DEBUG
4642 "%s: PORT set RDI report: "
4643 "card(%d) port(%d)\n",
4644 __func__, HFC_cnt + 1, 1);
4645 test_and_set_bit(HFC_CFG_REPORT_RDI,
4646 &hc->chan[hc->dslot].cfg);
4647 }
4648 /* set CRC-4 Mode */
4649 if (!(port[Port_cnt] & 0x100)) {
4650 if (debug & DEBUG_HFCMULTI_INIT)
4651 printk(KERN_DEBUG "%s: PORT turn on CRC4 report:"
4652 " card(%d) port(%d)\n",
4653 __func__, HFC_cnt + 1, 1);
4654 test_and_set_bit(HFC_CFG_CRC4,
4655 &hc->chan[hc->dslot].cfg);
4656 } else {
4657 if (debug & DEBUG_HFCMULTI_INIT)
4658 printk(KERN_DEBUG "%s: PORT turn off CRC4"
4659 " report: card(%d) port(%d)\n",
4660 __func__, HFC_cnt + 1, 1);
4661 }
4662 /* set forced clock */
4663 if (port[Port_cnt] & 0x0200) {
4664 if (debug & DEBUG_HFCMULTI_INIT)
4665 printk(KERN_DEBUG "%s: PORT force getting clock from "
4666 "E1: card(%d) port(%d)\n",
4667 __func__, HFC_cnt + 1, 1);
4668 test_and_set_bit(HFC_CHIP_E1CLOCK_GET, &hc->chip);
4669 } else
4670 if (port[Port_cnt] & 0x0400) {
4671 if (debug & DEBUG_HFCMULTI_INIT)
4672 printk(KERN_DEBUG "%s: PORT force putting clock to "
4673 "E1: card(%d) port(%d)\n",
4674 __func__, HFC_cnt + 1, 1);
4675 test_and_set_bit(HFC_CHIP_E1CLOCK_PUT, &hc->chip);
4676 }
4677 /* set JATT PLL */
4678 if (port[Port_cnt] & 0x0800) {
4679 if (debug & DEBUG_HFCMULTI_INIT)
4680 printk(KERN_DEBUG "%s: PORT disable JATT PLL on "
4681 "E1: card(%d) port(%d)\n",
4682 __func__, HFC_cnt + 1, 1);
4683 test_and_set_bit(HFC_CHIP_RX_SYNC, &hc->chip);
4684 }
4685 /* set elastic jitter buffer */
4686 if (port[Port_cnt] & 0x3000) {
4687 hc->chan[hc->dslot].jitter = (port[Port_cnt]>>12) & 0x3;
4688 if (debug & DEBUG_HFCMULTI_INIT)
4689 printk(KERN_DEBUG
4690 "%s: PORT set elastic "
4691 "buffer to %d: card(%d) port(%d)\n",
4692 __func__, hc->chan[hc->dslot].jitter,
4693 HFC_cnt + 1, 1);
4694 } else
4695 hc->chan[hc->dslot].jitter = 2; /* default */
4696 snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-e1.%d", HFC_cnt + 1);
4697 ret = mISDN_register_device(&dch->dev, name);
4698 if (ret)
4699 goto free_chan;
4700 hc->created[0] = 1;
4701 return ret;
4702free_chan:
4703 release_port(hc, dch);
4704 return ret;
4705}
4706
4707static int
4708init_multi_port(struct hfc_multi *hc, int pt)
4709{
4710 struct dchannel *dch;
4711 struct bchannel *bch;
4712 int ch, i, ret = 0;
4713 char name[MISDN_MAX_IDLEN];
4714
4715 dch = kzalloc(sizeof(struct dchannel), GFP_KERNEL);
4716 if (!dch)
4717 return -ENOMEM;
4718 dch->debug = debug;
4719 mISDN_initdchannel(dch, MAX_DFRAME_LEN_L1, ph_state_change);
4720 dch->hw = hc;
4721 dch->dev.Dprotocols = (1 << ISDN_P_TE_S0) | (1 << ISDN_P_NT_S0);
4722 dch->dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
4723 (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
4724 dch->dev.D.send = handle_dmsg;
4725 dch->dev.D.ctrl = hfcm_dctrl;
4726 dch->dev.nrbchan = 2;
4727 i = pt << 2;
4728 dch->slot = i + 2;
4729 hc->chan[i + 2].dch = dch;
4730 hc->chan[i + 2].port = pt;
4731 hc->chan[i + 2].nt_timer = -1;
4732 for (ch = 0; ch < dch->dev.nrbchan; ch++) {
4733 bch = kzalloc(sizeof(struct bchannel), GFP_KERNEL);
4734 if (!bch) {
4735 printk(KERN_ERR "%s: no memory for bchannel\n",
4736 __func__);
4737 ret = -ENOMEM;
4738 goto free_chan;
4739 }
4740 hc->chan[i + ch].coeff = kzalloc(512, GFP_KERNEL);
4741 if (!hc->chan[i + ch].coeff) {
4742 printk(KERN_ERR "%s: no memory for coeffs\n",
4743 __func__);
4744 ret = -ENOMEM;
4745 goto free_chan;
4746 }
4747 bch->nr = ch + 1;
4748 bch->slot = i + ch;
4749 bch->debug = debug;
4750 mISDN_initbchannel(bch, MAX_DATA_MEM);
4751 bch->hw = hc;
4752 bch->ch.send = handle_bmsg;
4753 bch->ch.ctrl = hfcm_bctrl;
4754 bch->ch.nr = ch + 1;
4755 list_add(&bch->ch.list, &dch->dev.bchannels);
4756 hc->chan[i + ch].bch = bch;
4757 hc->chan[i + ch].port = pt;
4758 test_and_set_bit(bch->nr, &dch->dev.channelmap[0]);
4759 }
4760 /* set master clock */
4761 if (port[Port_cnt] & 0x001) {
4762 if (debug & DEBUG_HFCMULTI_INIT)
4763 printk(KERN_DEBUG
4764 "%s: PROTOCOL set master clock: "
4765 "card(%d) port(%d)\n",
4766 __func__, HFC_cnt + 1, pt + 1);
4767 if (dch->dev.D.protocol != ISDN_P_TE_S0) {
4768 printk(KERN_ERR "Error: Master clock "
4769 "for port(%d) of card(%d) is only"
4770 " possible with TE-mode\n",
4771 pt + 1, HFC_cnt + 1);
4772 ret = -EINVAL;
4773 goto free_chan;
4774 }
4775 if (hc->masterclk >= 0) {
4776 printk(KERN_ERR "Error: Master clock "
4777 "for port(%d) of card(%d) already "
4778 "defined for port(%d)\n",
4779 pt + 1, HFC_cnt + 1, hc->masterclk+1);
4780 ret = -EINVAL;
4781 goto free_chan;
4782 }
4783 hc->masterclk = pt;
4784 }
4785 /* set transmitter line to non capacitive */
4786 if (port[Port_cnt] & 0x002) {
4787 if (debug & DEBUG_HFCMULTI_INIT)
4788 printk(KERN_DEBUG
4789 "%s: PROTOCOL set non capacitive "
4790 "transmitter: card(%d) port(%d)\n",
4791 __func__, HFC_cnt + 1, pt + 1);
4792 test_and_set_bit(HFC_CFG_NONCAP_TX,
4793 &hc->chan[i + 2].cfg);
4794 }
4795 /* disable E-channel */
4796 if (port[Port_cnt] & 0x004) {
4797 if (debug & DEBUG_HFCMULTI_INIT)
4798 printk(KERN_DEBUG
4799 "%s: PROTOCOL disable E-channel: "
4800 "card(%d) port(%d)\n",
4801 __func__, HFC_cnt + 1, pt + 1);
4802 test_and_set_bit(HFC_CFG_DIS_ECHANNEL,
4803 &hc->chan[i + 2].cfg);
4804 }
4805 snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-%ds.%d/%d",
4806 hc->type, HFC_cnt + 1, pt + 1);
4807 ret = mISDN_register_device(&dch->dev, name);
4808 if (ret)
4809 goto free_chan;
4810 hc->created[pt] = 1;
4811 return ret;
4812free_chan:
4813 release_port(hc, dch);
4814 return ret;
4815}
4816
4817static int
4818hfcmulti_init(struct pci_dev *pdev, const struct pci_device_id *ent)
4819{
4820 struct hm_map *m = (struct hm_map *)ent->driver_data;
4821 int ret_err = 0;
4822 int pt;
4823 struct hfc_multi *hc;
4824 u_long flags;
4825 u_char dips = 0, pmj = 0; /* dip settings, port mode Jumpers */
4826
4827 if (HFC_cnt >= MAX_CARDS) {
4828 printk(KERN_ERR "too many cards (max=%d).\n",
4829 MAX_CARDS);
4830 return -EINVAL;
4831 }
4832 if ((type[HFC_cnt] & 0xff) && (type[HFC_cnt] & 0xff) != m->type) {
4833 printk(KERN_WARNING "HFC-MULTI: Card '%s:%s' type %d found but "
4834 "type[%d] %d was supplied as module parameter\n",
4835 m->vendor_name, m->card_name, m->type, HFC_cnt,
4836 type[HFC_cnt] & 0xff);
4837 printk(KERN_WARNING "HFC-MULTI: Load module without parameters "
4838 "first, to see cards and their types.");
4839 return -EINVAL;
4840 }
4841 if (debug & DEBUG_HFCMULTI_INIT)
4842 printk(KERN_DEBUG "%s: Registering %s:%s chip type %d (0x%x)\n",
4843 __func__, m->vendor_name, m->card_name, m->type,
4844 type[HFC_cnt]);
4845
4846 /* allocate card+fifo structure */
4847 hc = kzalloc(sizeof(struct hfc_multi), GFP_KERNEL);
4848 if (!hc) {
4849 printk(KERN_ERR "No kmem for HFC-Multi card\n");
4850 return -ENOMEM;
4851 }
4852 spin_lock_init(&hc->lock);
4853 hc->mtyp = m;
4854 hc->type = m->type;
4855 hc->ports = m->ports;
4856 hc->id = HFC_cnt;
4857 hc->pcm = pcm[HFC_cnt];
4858 hc->io_mode = iomode[HFC_cnt];
4859 if (dslot[HFC_cnt] < 0) {
4860 hc->dslot = 0;
4861 printk(KERN_INFO "HFC-E1 card has disabled D-channel, but "
4862 "31 B-channels\n");
4863 } if (dslot[HFC_cnt] > 0 && dslot[HFC_cnt] < 32) {
4864 hc->dslot = dslot[HFC_cnt];
4865 printk(KERN_INFO "HFC-E1 card has alternating D-channel on "
4866 "time slot %d\n", dslot[HFC_cnt]);
4867 } else
4868 hc->dslot = 16;
4869
4870 /* set chip specific features */
4871 hc->masterclk = -1;
4872 if (type[HFC_cnt] & 0x100) {
4873 test_and_set_bit(HFC_CHIP_ULAW, &hc->chip);
4874 silence = 0xff; /* ulaw silence */
4875 } else
4876 silence = 0x2a; /* alaw silence */
4877 if (!(type[HFC_cnt] & 0x200))
4878 test_and_set_bit(HFC_CHIP_DTMF, &hc->chip);
4879
4880 if (type[HFC_cnt] & 0x800)
4881 test_and_set_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
4882 if (type[HFC_cnt] & 0x1000) {
4883 test_and_set_bit(HFC_CHIP_PCM_MASTER, &hc->chip);
4884 test_and_clear_bit(HFC_CHIP_PCM_SLAVE, &hc->chip);
4885 }
4886 if (type[HFC_cnt] & 0x4000)
4887 test_and_set_bit(HFC_CHIP_EXRAM_128, &hc->chip);
4888 if (type[HFC_cnt] & 0x8000)
4889 test_and_set_bit(HFC_CHIP_EXRAM_512, &hc->chip);
4890 hc->slots = 32;
4891 if (type[HFC_cnt] & 0x10000)
4892 hc->slots = 64;
4893 if (type[HFC_cnt] & 0x20000)
4894 hc->slots = 128;
4895 if (type[HFC_cnt] & 0x80000) {
4896 test_and_set_bit(HFC_CHIP_WATCHDOG, &hc->chip);
4897 hc->wdcount = 0;
4898 hc->wdbyte = V_GPIO_OUT2;
4899 printk(KERN_NOTICE "Watchdog enabled\n");
4900 }
4901
4902 /* setup pci, hc->slots may change due to PLXSD */
4903 ret_err = setup_pci(hc, pdev, ent);
4904 if (ret_err) {
4905 if (hc == syncmaster)
4906 syncmaster = NULL;
4907 kfree(hc);
4908 return ret_err;
4909 }
4910
4911 /* crate channels */
4912 for (pt = 0; pt < hc->ports; pt++) {
4913 if (Port_cnt >= MAX_PORTS) {
4914 printk(KERN_ERR "too many ports (max=%d).\n",
4915 MAX_PORTS);
4916 ret_err = -EINVAL;
4917 goto free_card;
4918 }
4919 if (hc->type == 1)
4920 ret_err = init_e1_port(hc, m);
4921 else
4922 ret_err = init_multi_port(hc, pt);
4923 if (debug & DEBUG_HFCMULTI_INIT)
4924 printk(KERN_DEBUG
4925 "%s: Registering D-channel, card(%d) port(%d)"
4926 "result %d\n",
4927 __func__, HFC_cnt + 1, pt, ret_err);
4928
4929 if (ret_err) {
4930 while (pt) { /* release already registered ports */
4931 pt--;
4932 release_port(hc, hc->chan[(pt << 2) + 2].dch);
4933 }
4934 goto free_card;
4935 }
4936 Port_cnt++;
4937 }
4938
4939 /* disp switches */
4940 switch (m->dip_type) {
4941 case DIP_4S:
4942 /*
4943 * get DIP Setting for beroNet 1S/2S/4S cards
4944 * check if Port Jumper config matches
4945 * module param 'protocol'
4946 * DIP Setting: (collect GPIO 13/14/15 (R_GPIO_IN1) +
4947 * GPI 19/23 (R_GPI_IN2))
4948 */
4949 dips = ((~HFC_inb(hc, R_GPIO_IN1) & 0xE0) >> 5) |
4950 ((~HFC_inb(hc, R_GPI_IN2) & 0x80) >> 3) |
4951 (~HFC_inb(hc, R_GPI_IN2) & 0x08);
4952
4953 /* Port mode (TE/NT) jumpers */
4954 pmj = ((HFC_inb(hc, R_GPI_IN3) >> 4) & 0xf);
4955
4956 if (test_bit(HFC_CHIP_B410P, &hc->chip))
4957 pmj = ~pmj & 0xf;
4958
4959 printk(KERN_INFO "%s: %s DIPs(0x%x) jumpers(0x%x)\n",
4960 m->vendor_name, m->card_name, dips, pmj);
4961 break;
4962 case DIP_8S:
4963 /*
4964 * get DIP Setting for beroNet 8S0+ cards
4965 *
4966 * enable PCI auxbridge function
4967 */
4968 HFC_outb(hc, R_BRG_PCM_CFG, 1 | V_PCM_CLK);
4969 /* prepare access to auxport */
4970 outw(0x4000, hc->pci_iobase + 4);
4971 /*
4972 * some dummy reads are required to
4973 * read valid DIP switch data
4974 */
4975 dips = inb(hc->pci_iobase);
4976 dips = inb(hc->pci_iobase);
4977 dips = inb(hc->pci_iobase);
4978 dips = ~inb(hc->pci_iobase) & 0x3F;
4979 outw(0x0, hc->pci_iobase + 4);
4980 /* disable PCI auxbridge function */
4981 HFC_outb(hc, R_BRG_PCM_CFG, V_PCM_CLK);
4982 printk(KERN_INFO "%s: %s DIPs(0x%x)\n",
4983 m->vendor_name, m->card_name, dips);
4984 break;
4985 case DIP_E1:
4986 /*
4987 * get DIP Setting for beroNet E1 cards
4988 * DIP Setting: collect GPI 4/5/6/7 (R_GPI_IN0)
4989 */
4990 dips = (~HFC_inb(hc, R_GPI_IN0) & 0xF0)>>4;
4991 printk(KERN_INFO "%s: %s DIPs(0x%x)\n",
4992 m->vendor_name, m->card_name, dips);
4993 break;
4994 }
4995
4996 /* add to list */
4997 spin_lock_irqsave(&HFClock, flags);
4998 list_add_tail(&hc->list, &HFClist);
4999 spin_unlock_irqrestore(&HFClock, flags);
5000
5001 /* initialize hardware */
5002 ret_err = init_card(hc);
5003 if (ret_err) {
5004 printk(KERN_ERR "init card returns %d\n", ret_err);
5005 release_card(hc);
5006 return ret_err;
5007 }
5008
5009 /* start IRQ and return */
5010 spin_lock_irqsave(&hc->lock, flags);
5011 enable_hwirq(hc);
5012 spin_unlock_irqrestore(&hc->lock, flags);
5013 return 0;
5014
5015free_card:
5016 release_io_hfcmulti(hc);
5017 if (hc == syncmaster)
5018 syncmaster = NULL;
5019 kfree(hc);
5020 return ret_err;
5021}
5022
5023static void __devexit hfc_remove_pci(struct pci_dev *pdev)
5024{
5025 struct hfc_multi *card = pci_get_drvdata(pdev);
5026 u_long flags;
5027
5028 if (debug)
5029 printk(KERN_INFO "removing hfc_multi card vendor:%x "
5030 "device:%x subvendor:%x subdevice:%x\n",
5031 pdev->vendor, pdev->device,
5032 pdev->subsystem_vendor, pdev->subsystem_device);
5033
5034 if (card) {
5035 spin_lock_irqsave(&HFClock, flags);
5036 release_card(card);
5037 spin_unlock_irqrestore(&HFClock, flags);
5038 } else {
5039 if (debug)
5040 printk(KERN_WARNING "%s: drvdata allready removed\n",
5041 __func__);
5042 }
5043}
5044
5045#define VENDOR_CCD "Cologne Chip AG"
5046#define VENDOR_BN "beroNet GmbH"
5047#define VENDOR_DIG "Digium Inc."
5048#define VENDOR_JH "Junghanns.NET GmbH"
5049#define VENDOR_PRIM "PrimuX"
5050
5051static const struct hm_map hfcm_map[] = {
5052/*0*/ {VENDOR_BN, "HFC-1S Card (mini PCI)", 4, 1, 1, 3, 0, DIP_4S, 0},
5053/*1*/ {VENDOR_BN, "HFC-2S Card", 4, 2, 1, 3, 0, DIP_4S},
5054/*2*/ {VENDOR_BN, "HFC-2S Card (mini PCI)", 4, 2, 1, 3, 0, DIP_4S, 0},
5055/*3*/ {VENDOR_BN, "HFC-4S Card", 4, 4, 1, 2, 0, DIP_4S, 0},
5056/*4*/ {VENDOR_BN, "HFC-4S Card (mini PCI)", 4, 4, 1, 2, 0, 0, 0},
5057/*5*/ {VENDOR_CCD, "HFC-4S Eval (old)", 4, 4, 0, 0, 0, 0, 0},
5058/*6*/ {VENDOR_CCD, "HFC-4S IOB4ST", 4, 4, 1, 2, 0, 0, 0},
5059/*7*/ {VENDOR_CCD, "HFC-4S", 4, 4, 1, 2, 0, 0, 0},
5060/*8*/ {VENDOR_DIG, "HFC-4S Card", 4, 4, 0, 2, 0, 0, HFC_IO_MODE_REGIO},
5061/*9*/ {VENDOR_CCD, "HFC-4S Swyx 4xS0 SX2 QuadBri", 4, 4, 1, 2, 0, 0, 0},
5062/*10*/ {VENDOR_JH, "HFC-4S (junghanns 2.0)", 4, 4, 1, 2, 0, 0, 0},
5063/*11*/ {VENDOR_PRIM, "HFC-2S Primux Card", 4, 2, 0, 0, 0, 0, 0},
5064
5065/*12*/ {VENDOR_BN, "HFC-8S Card", 8, 8, 1, 0, 0, 0, 0},
5066/*13*/ {VENDOR_BN, "HFC-8S Card (+)", 8, 8, 1, 8, 0, DIP_8S,
5067 HFC_IO_MODE_REGIO},
5068/*14*/ {VENDOR_CCD, "HFC-8S Eval (old)", 8, 8, 0, 0, 0, 0, 0},
5069/*15*/ {VENDOR_CCD, "HFC-8S IOB4ST Recording", 8, 8, 1, 0, 0, 0, 0},
5070
5071/*16*/ {VENDOR_CCD, "HFC-8S IOB8ST", 8, 8, 1, 0, 0, 0, 0},
5072/*17*/ {VENDOR_CCD, "HFC-8S", 8, 8, 1, 0, 0, 0, 0},
5073/*18*/ {VENDOR_CCD, "HFC-8S", 8, 8, 1, 0, 0, 0, 0},
5074
5075/*19*/ {VENDOR_BN, "HFC-E1 Card", 1, 1, 0, 1, 0, DIP_E1, 0},
5076/*20*/ {VENDOR_BN, "HFC-E1 Card (mini PCI)", 1, 1, 0, 1, 0, 0, 0},
5077/*21*/ {VENDOR_BN, "HFC-E1+ Card (Dual)", 1, 1, 0, 1, 0, DIP_E1, 0},
5078/*22*/ {VENDOR_BN, "HFC-E1 Card (Dual)", 1, 1, 0, 1, 0, DIP_E1, 0},
5079
5080/*23*/ {VENDOR_CCD, "HFC-E1 Eval (old)", 1, 1, 0, 0, 0, 0, 0},
5081/*24*/ {VENDOR_CCD, "HFC-E1 IOB1E1", 1, 1, 0, 1, 0, 0, 0},
5082/*25*/ {VENDOR_CCD, "HFC-E1", 1, 1, 0, 1, 0, 0, 0},
5083
5084/*26*/ {VENDOR_CCD, "HFC-4S Speech Design", 4, 4, 0, 0, 0, 0,
5085 HFC_IO_MODE_PLXSD},
5086/*27*/ {VENDOR_CCD, "HFC-E1 Speech Design", 1, 1, 0, 0, 0, 0,
5087 HFC_IO_MODE_PLXSD},
5088/*28*/ {VENDOR_CCD, "HFC-4S OpenVox", 4, 4, 1, 0, 0, 0, 0},
5089/*29*/ {VENDOR_CCD, "HFC-2S OpenVox", 4, 2, 1, 0, 0, 0, 0},
5090/*30*/ {VENDOR_CCD, "HFC-8S OpenVox", 8, 8, 1, 0, 0, 0, 0},
5091};
5092
5093#undef H
5094#define H(x) ((unsigned long)&hfcm_map[x])
5095static struct pci_device_id hfmultipci_ids[] __devinitdata = {
5096
5097 /* Cards with HFC-4S Chip */
5098 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5099 PCI_SUBDEVICE_ID_CCD_BN1SM, 0, 0, H(0)}, /* BN1S mini PCI */
5100 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5101 PCI_SUBDEVICE_ID_CCD_BN2S, 0, 0, H(1)}, /* BN2S */
5102 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5103 PCI_SUBDEVICE_ID_CCD_BN2SM, 0, 0, H(2)}, /* BN2S mini PCI */
5104 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5105 PCI_SUBDEVICE_ID_CCD_BN4S, 0, 0, H(3)}, /* BN4S */
5106 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5107 PCI_SUBDEVICE_ID_CCD_BN4SM, 0, 0, H(4)}, /* BN4S mini PCI */
5108 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5109 PCI_DEVICE_ID_CCD_HFC4S, 0, 0, H(5)}, /* Old Eval */
5110 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5111 PCI_SUBDEVICE_ID_CCD_IOB4ST, 0, 0, H(6)}, /* IOB4ST */
5112 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5113 PCI_SUBDEVICE_ID_CCD_HFC4S, 0, 0, H(7)}, /* 4S */
5114 { PCI_VENDOR_ID_DIGIUM, PCI_DEVICE_ID_DIGIUM_HFC4S,
5115 PCI_VENDOR_ID_DIGIUM, PCI_DEVICE_ID_DIGIUM_HFC4S, 0, 0, H(8)},
5116 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5117 PCI_SUBDEVICE_ID_CCD_SWYX4S, 0, 0, H(9)}, /* 4S Swyx */
5118 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5119 PCI_SUBDEVICE_ID_CCD_JH4S20, 0, 0, H(10)},
5120 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5121 PCI_SUBDEVICE_ID_CCD_PMX2S, 0, 0, H(11)}, /* Primux */
5122 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5123 PCI_SUBDEVICE_ID_CCD_OV4S, 0, 0, H(28)}, /* OpenVox 4 */
5124 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_VENDOR_ID_CCD,
5125 PCI_SUBDEVICE_ID_CCD_OV2S, 0, 0, H(29)}, /* OpenVox 2 */
5126
5127 /* Cards with HFC-8S Chip */
5128 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5129 PCI_SUBDEVICE_ID_CCD_BN8S, 0, 0, H(12)}, /* BN8S */
5130 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5131 PCI_SUBDEVICE_ID_CCD_BN8SP, 0, 0, H(13)}, /* BN8S+ */
5132 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5133 PCI_DEVICE_ID_CCD_HFC8S, 0, 0, H(14)}, /* old Eval */
5134 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5135 PCI_SUBDEVICE_ID_CCD_IOB8STR, 0, 0, H(15)},
5136 /* IOB8ST Recording */
5137 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5138 PCI_SUBDEVICE_ID_CCD_IOB8ST, 0, 0, H(16)}, /* IOB8ST */
5139 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5140 PCI_SUBDEVICE_ID_CCD_IOB8ST_1, 0, 0, H(17)}, /* IOB8ST */
5141 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5142 PCI_SUBDEVICE_ID_CCD_HFC8S, 0, 0, H(18)}, /* 8S */
5143 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD,
5144 PCI_SUBDEVICE_ID_CCD_OV8S, 0, 0, H(30)}, /* OpenVox 8 */
5145
5146
5147 /* Cards with HFC-E1 Chip */
5148 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5149 PCI_SUBDEVICE_ID_CCD_BNE1, 0, 0, H(19)}, /* BNE1 */
5150 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5151 PCI_SUBDEVICE_ID_CCD_BNE1M, 0, 0, H(20)}, /* BNE1 mini PCI */
5152 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5153 PCI_SUBDEVICE_ID_CCD_BNE1DP, 0, 0, H(21)}, /* BNE1 + (Dual) */
5154 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5155 PCI_SUBDEVICE_ID_CCD_BNE1D, 0, 0, H(22)}, /* BNE1 (Dual) */
5156
5157 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5158 PCI_DEVICE_ID_CCD_HFCE1, 0, 0, H(23)}, /* Old Eval */
5159 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5160 PCI_SUBDEVICE_ID_CCD_IOB1E1, 0, 0, H(24)}, /* IOB1E1 */
5161 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_VENDOR_ID_CCD,
5162 PCI_SUBDEVICE_ID_CCD_HFCE1, 0, 0, H(25)}, /* E1 */
5163
5164 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, PCI_VENDOR_ID_CCD,
5165 PCI_SUBDEVICE_ID_CCD_SPD4S, 0, 0, H(26)}, /* PLX PCI Bridge */
5166 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, PCI_VENDOR_ID_CCD,
5167 PCI_SUBDEVICE_ID_CCD_SPDE1, 0, 0, H(27)}, /* PLX PCI Bridge */
5168 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC4S, PCI_ANY_ID, PCI_ANY_ID,
5169 0, 0, 0},
5170 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_ANY_ID, PCI_ANY_ID,
5171 0, 0, 0},
5172 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFCE1, PCI_ANY_ID, PCI_ANY_ID,
5173 0, 0, 0},
5174 {0, }
5175};
5176#undef H
5177
5178MODULE_DEVICE_TABLE(pci, hfmultipci_ids);
5179
5180static int
5181hfcmulti_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5182{
5183 struct hm_map *m = (struct hm_map *)ent->driver_data;
5184 int ret;
5185
5186 if (m == NULL) {
5187 if (ent->vendor == PCI_VENDOR_ID_CCD)
5188 if (ent->device == PCI_DEVICE_ID_CCD_HFC4S ||
5189 ent->device == PCI_DEVICE_ID_CCD_HFC8S ||
5190 ent->device == PCI_DEVICE_ID_CCD_HFCE1)
5191 printk(KERN_ERR
5192 "unknown HFC multiport controller "
5193 "(vendor:%x device:%x subvendor:%x "
5194 "subdevice:%x) Please contact the "
5195 "driver maintainer for support.\n",
5196 ent->vendor, ent->device,
5197 ent->subvendor, ent->subdevice);
5198 return -ENODEV;
5199 }
5200 ret = hfcmulti_init(pdev, ent);
5201 if (ret)
5202 return ret;
5203 HFC_cnt++;
5204 printk(KERN_INFO "%d devices registered\n", HFC_cnt);
5205 return 0;
5206}
5207
5208static struct pci_driver hfcmultipci_driver = {
5209 .name = "hfc_multi",
5210 .probe = hfcmulti_probe,
5211 .remove = __devexit_p(hfc_remove_pci),
5212 .id_table = hfmultipci_ids,
5213};
5214
5215static void __exit
5216HFCmulti_cleanup(void)
5217{
5218 struct hfc_multi *card, *next;
5219
5220 /* unload interrupt function symbol */
5221 if (hfc_interrupt)
5222 symbol_put(ztdummy_extern_interrupt);
5223 if (register_interrupt)
5224 symbol_put(ztdummy_register_interrupt);
5225 if (unregister_interrupt) {
5226 if (interrupt_registered) {
5227 interrupt_registered = 0;
5228 unregister_interrupt();
5229 }
5230 symbol_put(ztdummy_unregister_interrupt);
5231 }
5232
5233 list_for_each_entry_safe(card, next, &HFClist, list)
5234 release_card(card);
5235 /* get rid of all devices of this driver */
5236 pci_unregister_driver(&hfcmultipci_driver);
5237}
5238
5239static int __init
5240HFCmulti_init(void)
5241{
5242 int err;
5243
5244#ifdef IRQ_DEBUG
5245 printk(KERN_ERR "%s: IRQ_DEBUG IS ENABLED!\n", __func__);
5246#endif
5247
5248 spin_lock_init(&HFClock);
5249 spin_lock_init(&plx_lock);
5250
5251 if (debug & DEBUG_HFCMULTI_INIT)
5252 printk(KERN_DEBUG "%s: init entered\n", __func__);
5253
5254#ifdef __BIG_ENDIAN
5255#error "not running on big endian machines now"
5256#endif
5257 hfc_interrupt = symbol_get(ztdummy_extern_interrupt);
5258 register_interrupt = symbol_get(ztdummy_register_interrupt);
5259 unregister_interrupt = symbol_get(ztdummy_unregister_interrupt);
5260 printk(KERN_INFO "mISDN: HFC-multi driver %s\n",
5261 hfcmulti_revision);
5262
5263 switch (poll) {
5264 case 0:
5265 poll_timer = 6;
5266 poll = 128;
5267 break;
5268 /*
5269 * wenn dieses break nochmal verschwindet,
5270 * gibt es heisse ohren :-)
5271 * "without the break you will get hot ears ???"
5272 */
5273 case 8:
5274 poll_timer = 2;
5275 break;
5276 case 16:
5277 poll_timer = 3;
5278 break;
5279 case 32:
5280 poll_timer = 4;
5281 break;
5282 case 64:
5283 poll_timer = 5;
5284 break;
5285 case 128:
5286 poll_timer = 6;
5287 break;
5288 case 256:
5289 poll_timer = 7;
5290 break;
5291 default:
5292 printk(KERN_ERR
5293 "%s: Wrong poll value (%d).\n", __func__, poll);
5294 err = -EINVAL;
5295 return err;
5296
5297 }
5298
5299 err = pci_register_driver(&hfcmultipci_driver);
5300 if (err < 0) {
5301 printk(KERN_ERR "error registering pci driver: %x\n", err);
5302 if (hfc_interrupt)
5303 symbol_put(ztdummy_extern_interrupt);
5304 if (register_interrupt)
5305 symbol_put(ztdummy_register_interrupt);
5306 if (unregister_interrupt) {
5307 if (interrupt_registered) {
5308 interrupt_registered = 0;
5309 unregister_interrupt();
5310 }
5311 symbol_put(ztdummy_unregister_interrupt);
5312 }
5313 return err;
5314 }
5315 return 0;
5316}
5317
5318
5319module_init(HFCmulti_init);
5320module_exit(HFCmulti_cleanup);
diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
new file mode 100644
index 000000000000..917968530e1e
--- /dev/null
+++ b/drivers/isdn/hardware/mISDN/hfcpci.c
@@ -0,0 +1,2256 @@
1/*
2 *
3 * hfcpci.c low level driver for CCD's hfc-pci based cards
4 *
5 * Author Werner Cornelius (werner@isdn4linux.de)
6 * based on existing driver for CCD hfc ISA cards
7 * type approval valid for HFC-S PCI A based card
8 *
9 * Copyright 1999 by Werner Cornelius (werner@isdn-development.de)
10 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 */
27
28#include <linux/module.h>
29#include <linux/pci.h>
30#include <linux/delay.h>
31#include <linux/mISDNhw.h>
32
33#include "hfc_pci.h"
34
35static const char *hfcpci_revision = "2.0";
36
37#define MAX_CARDS 8
38static int HFC_cnt;
39static uint debug;
40
41MODULE_AUTHOR("Karsten Keil");
42MODULE_LICENSE("GPL");
43module_param(debug, uint, 0);
44
45static LIST_HEAD(HFClist);
46DEFINE_RWLOCK(HFClock);
47
48enum {
49 HFC_CCD_2BD0,
50 HFC_CCD_B000,
51 HFC_CCD_B006,
52 HFC_CCD_B007,
53 HFC_CCD_B008,
54 HFC_CCD_B009,
55 HFC_CCD_B00A,
56 HFC_CCD_B00B,
57 HFC_CCD_B00C,
58 HFC_CCD_B100,
59 HFC_CCD_B700,
60 HFC_CCD_B701,
61 HFC_ASUS_0675,
62 HFC_BERKOM_A1T,
63 HFC_BERKOM_TCONCEPT,
64 HFC_ANIGMA_MC145575,
65 HFC_ZOLTRIX_2BD0,
66 HFC_DIGI_DF_M_IOM2_E,
67 HFC_DIGI_DF_M_E,
68 HFC_DIGI_DF_M_IOM2_A,
69 HFC_DIGI_DF_M_A,
70 HFC_ABOCOM_2BD1,
71 HFC_SITECOM_DC105V2,
72};
73
74struct hfcPCI_hw {
75 unsigned char cirm;
76 unsigned char ctmt;
77 unsigned char clkdel;
78 unsigned char states;
79 unsigned char conn;
80 unsigned char mst_m;
81 unsigned char int_m1;
82 unsigned char int_m2;
83 unsigned char sctrl;
84 unsigned char sctrl_r;
85 unsigned char sctrl_e;
86 unsigned char trm;
87 unsigned char fifo_en;
88 unsigned char bswapped;
89 unsigned char protocol;
90 int nt_timer;
91 unsigned char *pci_io; /* start of PCI IO memory */
92 dma_addr_t dmahandle;
93 void *fifos; /* FIFO memory */
94 int last_bfifo_cnt[2];
95 /* marker saving last b-fifo frame count */
96 struct timer_list timer;
97};
98
99#define HFC_CFG_MASTER 1
100#define HFC_CFG_SLAVE 2
101#define HFC_CFG_PCM 3
102#define HFC_CFG_2HFC 4
103#define HFC_CFG_SLAVEHFC 5
104#define HFC_CFG_NEG_F0 6
105#define HFC_CFG_SW_DD_DU 7
106
107#define FLG_HFC_TIMER_T1 16
108#define FLG_HFC_TIMER_T3 17
109
110#define NT_T1_COUNT 1120 /* number of 3.125ms interrupts (3.5s) */
111#define NT_T3_COUNT 31 /* number of 3.125ms interrupts (97 ms) */
112#define CLKDEL_TE 0x0e /* CLKDEL in TE mode */
113#define CLKDEL_NT 0x6c /* CLKDEL in NT mode */
114
115
116struct hfc_pci {
117 struct list_head list;
118 u_char subtype;
119 u_char chanlimit;
120 u_char initdone;
121 u_long cfg;
122 u_int irq;
123 u_int irqcnt;
124 struct pci_dev *pdev;
125 struct hfcPCI_hw hw;
126 spinlock_t lock; /* card lock */
127 struct dchannel dch;
128 struct bchannel bch[2];
129};
130
131/* Interface functions */
132static void
133enable_hwirq(struct hfc_pci *hc)
134{
135 hc->hw.int_m2 |= HFCPCI_IRQ_ENABLE;
136 Write_hfc(hc, HFCPCI_INT_M2, hc->hw.int_m2);
137}
138
139static void
140disable_hwirq(struct hfc_pci *hc)
141{
142 hc->hw.int_m2 &= ~((u_char)HFCPCI_IRQ_ENABLE);
143 Write_hfc(hc, HFCPCI_INT_M2, hc->hw.int_m2);
144}
145
146/*
147 * free hardware resources used by driver
148 */
149static void
150release_io_hfcpci(struct hfc_pci *hc)
151{
152 /* disable memory mapped ports + busmaster */
153 pci_write_config_word(hc->pdev, PCI_COMMAND, 0);
154 del_timer(&hc->hw.timer);
155 pci_free_consistent(hc->pdev, 0x8000, hc->hw.fifos, hc->hw.dmahandle);
156 iounmap((void *)hc->hw.pci_io);
157}
158
159/*
160 * set mode (NT or TE)
161 */
162static void
163hfcpci_setmode(struct hfc_pci *hc)
164{
165 if (hc->hw.protocol == ISDN_P_NT_S0) {
166 hc->hw.clkdel = CLKDEL_NT; /* ST-Bit delay for NT-Mode */
167 hc->hw.sctrl |= SCTRL_MODE_NT; /* NT-MODE */
168 hc->hw.states = 1; /* G1 */
169 } else {
170 hc->hw.clkdel = CLKDEL_TE; /* ST-Bit delay for TE-Mode */
171 hc->hw.sctrl &= ~SCTRL_MODE_NT; /* TE-MODE */
172 hc->hw.states = 2; /* F2 */
173 }
174 Write_hfc(hc, HFCPCI_CLKDEL, hc->hw.clkdel);
175 Write_hfc(hc, HFCPCI_STATES, HFCPCI_LOAD_STATE | hc->hw.states);
176 udelay(10);
177 Write_hfc(hc, HFCPCI_STATES, hc->hw.states | 0x40); /* Deactivate */
178 Write_hfc(hc, HFCPCI_SCTRL, hc->hw.sctrl);
179}
180
181/*
182 * function called to reset the HFC PCI chip. A complete software reset of chip
183 * and fifos is done.
184 */
185static void
186reset_hfcpci(struct hfc_pci *hc)
187{
188 u_char val;
189 int cnt = 0;
190
191 printk(KERN_DEBUG "reset_hfcpci: entered\n");
192 val = Read_hfc(hc, HFCPCI_CHIP_ID);
193 printk(KERN_INFO "HFC_PCI: resetting HFC ChipId(%x)\n", val);
194 /* enable memory mapped ports, disable busmaster */
195 pci_write_config_word(hc->pdev, PCI_COMMAND, PCI_ENA_MEMIO);
196 disable_hwirq(hc);
197 /* enable memory ports + busmaster */
198 pci_write_config_word(hc->pdev, PCI_COMMAND,
199 PCI_ENA_MEMIO + PCI_ENA_MASTER);
200 val = Read_hfc(hc, HFCPCI_STATUS);
201 printk(KERN_DEBUG "HFC-PCI status(%x) before reset\n", val);
202 hc->hw.cirm = HFCPCI_RESET; /* Reset On */
203 Write_hfc(hc, HFCPCI_CIRM, hc->hw.cirm);
204 set_current_state(TASK_UNINTERRUPTIBLE);
205 mdelay(10); /* Timeout 10ms */
206 hc->hw.cirm = 0; /* Reset Off */
207 Write_hfc(hc, HFCPCI_CIRM, hc->hw.cirm);
208 val = Read_hfc(hc, HFCPCI_STATUS);
209 printk(KERN_DEBUG "HFC-PCI status(%x) after reset\n", val);
210 while (cnt < 50000) { /* max 50000 us */
211 udelay(5);
212 cnt += 5;
213 val = Read_hfc(hc, HFCPCI_STATUS);
214 if (!(val & 2))
215 break;
216 }
217 printk(KERN_DEBUG "HFC-PCI status(%x) after %dus\n", val, cnt);
218
219 hc->hw.fifo_en = 0x30; /* only D fifos enabled */
220
221 hc->hw.bswapped = 0; /* no exchange */
222 hc->hw.ctmt = HFCPCI_TIM3_125 | HFCPCI_AUTO_TIMER;
223 hc->hw.trm = HFCPCI_BTRANS_THRESMASK; /* no echo connect , threshold */
224 hc->hw.sctrl = 0x40; /* set tx_lo mode, error in datasheet ! */
225 hc->hw.sctrl_r = 0;
226 hc->hw.sctrl_e = HFCPCI_AUTO_AWAKE; /* S/T Auto awake */
227 hc->hw.mst_m = 0;
228 if (test_bit(HFC_CFG_MASTER, &hc->cfg))
229 hc->hw.mst_m |= HFCPCI_MASTER; /* HFC Master Mode */
230 if (test_bit(HFC_CFG_NEG_F0, &hc->cfg))
231 hc->hw.mst_m |= HFCPCI_F0_NEGATIV;
232 Write_hfc(hc, HFCPCI_FIFO_EN, hc->hw.fifo_en);
233 Write_hfc(hc, HFCPCI_TRM, hc->hw.trm);
234 Write_hfc(hc, HFCPCI_SCTRL_E, hc->hw.sctrl_e);
235 Write_hfc(hc, HFCPCI_CTMT, hc->hw.ctmt);
236
237 hc->hw.int_m1 = HFCPCI_INTS_DTRANS | HFCPCI_INTS_DREC |
238 HFCPCI_INTS_L1STATE | HFCPCI_INTS_TIMER;
239 Write_hfc(hc, HFCPCI_INT_M1, hc->hw.int_m1);
240
241 /* Clear already pending ints */
242 if (Read_hfc(hc, HFCPCI_INT_S1));
243
244 /* set NT/TE mode */
245 hfcpci_setmode(hc);
246
247 Write_hfc(hc, HFCPCI_MST_MODE, hc->hw.mst_m);
248 Write_hfc(hc, HFCPCI_SCTRL_R, hc->hw.sctrl_r);
249
250 /*
251 * Init GCI/IOM2 in master mode
252 * Slots 0 and 1 are set for B-chan 1 and 2
253 * D- and monitor/CI channel are not enabled
254 * STIO1 is used as output for data, B1+B2 from ST->IOM+HFC
255 * STIO2 is used as data input, B1+B2 from IOM->ST
256 * ST B-channel send disabled -> continous 1s
257 * The IOM slots are always enabled
258 */
259 if (test_bit(HFC_CFG_PCM, &hc->cfg)) {
260 /* set data flow directions: connect B1,B2: HFC to/from PCM */
261 hc->hw.conn = 0x09;
262 } else {
263 hc->hw.conn = 0x36; /* set data flow directions */
264 if (test_bit(HFC_CFG_SW_DD_DU, &hc->cfg)) {
265 Write_hfc(hc, HFCPCI_B1_SSL, 0xC0);
266 Write_hfc(hc, HFCPCI_B2_SSL, 0xC1);
267 Write_hfc(hc, HFCPCI_B1_RSL, 0xC0);
268 Write_hfc(hc, HFCPCI_B2_RSL, 0xC1);
269 } else {
270 Write_hfc(hc, HFCPCI_B1_SSL, 0x80);
271 Write_hfc(hc, HFCPCI_B2_SSL, 0x81);
272 Write_hfc(hc, HFCPCI_B1_RSL, 0x80);
273 Write_hfc(hc, HFCPCI_B2_RSL, 0x81);
274 }
275 }
276 Write_hfc(hc, HFCPCI_CONNECT, hc->hw.conn);
277 val = Read_hfc(hc, HFCPCI_INT_S2);
278}
279
280/*
281 * Timer function called when kernel timer expires
282 */
283static void
284hfcpci_Timer(struct hfc_pci *hc)
285{
286 hc->hw.timer.expires = jiffies + 75;
287 /* WD RESET */
288/*
289 * WriteReg(hc, HFCD_DATA, HFCD_CTMT, hc->hw.ctmt | 0x80);
290 * add_timer(&hc->hw.timer);
291 */
292}
293
294
295/*
296 * select a b-channel entry matching and active
297 */
298static struct bchannel *
299Sel_BCS(struct hfc_pci *hc, int channel)
300{
301 if (test_bit(FLG_ACTIVE, &hc->bch[0].Flags) &&
302 (hc->bch[0].nr & channel))
303 return &hc->bch[0];
304 else if (test_bit(FLG_ACTIVE, &hc->bch[1].Flags) &&
305 (hc->bch[1].nr & channel))
306 return &hc->bch[1];
307 else
308 return NULL;
309}
310
311/*
312 * clear the desired B-channel rx fifo
313 */
314static void
315hfcpci_clear_fifo_rx(struct hfc_pci *hc, int fifo)
316{
317 u_char fifo_state;
318 struct bzfifo *bzr;
319
320 if (fifo) {
321 bzr = &((union fifo_area *)(hc->hw.fifos))->b_chans.rxbz_b2;
322 fifo_state = hc->hw.fifo_en & HFCPCI_FIFOEN_B2RX;
323 } else {
324 bzr = &((union fifo_area *)(hc->hw.fifos))->b_chans.rxbz_b1;
325 fifo_state = hc->hw.fifo_en & HFCPCI_FIFOEN_B1RX;
326 }
327 if (fifo_state)
328 hc->hw.fifo_en ^= fifo_state;
329 Write_hfc(hc, HFCPCI_FIFO_EN, hc->hw.fifo_en);
330 hc->hw.last_bfifo_cnt[fifo] = 0;
331 bzr->f1 = MAX_B_FRAMES;
332 bzr->f2 = bzr->f1; /* init F pointers to remain constant */
333 bzr->za[MAX_B_FRAMES].z1 = cpu_to_le16(B_FIFO_SIZE + B_SUB_VAL - 1);
334 bzr->za[MAX_B_FRAMES].z2 = cpu_to_le16(
335 le16_to_cpu(bzr->za[MAX_B_FRAMES].z1));
336 if (fifo_state)
337 hc->hw.fifo_en |= fifo_state;
338 Write_hfc(hc, HFCPCI_FIFO_EN, hc->hw.fifo_en);
339}
340
341/*
342 * clear the desired B-channel tx fifo
343 */
344static void hfcpci_clear_fifo_tx(struct hfc_pci *hc, int fifo)
345{
346 u_char fifo_state;
347 struct bzfifo *bzt;
348
349 if (fifo) {
350 bzt = &((union fifo_area *)(hc->hw.fifos))->b_chans.txbz_b2;
351 fifo_state = hc->hw.fifo_en & HFCPCI_FIFOEN_B2TX;
352 } else {
353 bzt = &((union fifo_area *)(hc->hw.fifos))->b_chans.txbz_b1;
354 fifo_state = hc->hw.fifo_en & HFCPCI_FIFOEN_B1TX;
355 }
356 if (fifo_state)
357 hc->hw.fifo_en ^= fifo_state;
358 Write_hfc(hc, HFCPCI_FIFO_EN, hc->hw.fifo_en);
359 if (hc->bch[fifo].debug & DEBUG_HW_BCHANNEL)
360 printk(KERN_DEBUG "hfcpci_clear_fifo_tx%d f1(%x) f2(%x) "
361 "z1(%x) z2(%x) state(%x)\n",
362 fifo, bzt->f1, bzt->f2,
363 le16_to_cpu(bzt->za[MAX_B_FRAMES].z1),
364 le16_to_cpu(bzt->za[MAX_B_FRAMES].z2),
365 fifo_state);
366 bzt->f2 = MAX_B_FRAMES;
367 bzt->f1 = bzt->f2; /* init F pointers to remain constant */
368 bzt->za[MAX_B_FRAMES].z1 = cpu_to_le16(B_FIFO_SIZE + B_SUB_VAL - 1);
369 bzt->za[MAX_B_FRAMES].z2 = cpu_to_le16(
370 le16_to_cpu(bzt->za[MAX_B_FRAMES].z1 - 1));
371 if (fifo_state)
372 hc->hw.fifo_en |= fifo_state;
373 Write_hfc(hc, HFCPCI_FIFO_EN, hc->hw.fifo_en);
374 if (hc->bch[fifo].debug & DEBUG_HW_BCHANNEL)
375 printk(KERN_DEBUG
376 "hfcpci_clear_fifo_tx%d f1(%x) f2(%x) z1(%x) z2(%x)\n",
377 fifo, bzt->f1, bzt->f2,
378 le16_to_cpu(bzt->za[MAX_B_FRAMES].z1),
379 le16_to_cpu(bzt->za[MAX_B_FRAMES].z2));
380}
381
382/*
383 * read a complete B-frame out of the buffer
384 */
385static void
386hfcpci_empty_bfifo(struct bchannel *bch, struct bzfifo *bz,
387 u_char *bdata, int count)
388{
389 u_char *ptr, *ptr1, new_f2;
390 int total, maxlen, new_z2;
391 struct zt *zp;
392
393 if ((bch->debug & DEBUG_HW_BCHANNEL) && !(bch->debug & DEBUG_HW_BFIFO))
394 printk(KERN_DEBUG "hfcpci_empty_fifo\n");
395 zp = &bz->za[bz->f2]; /* point to Z-Regs */
396 new_z2 = le16_to_cpu(zp->z2) + count; /* new position in fifo */
397 if (new_z2 >= (B_FIFO_SIZE + B_SUB_VAL))
398 new_z2 -= B_FIFO_SIZE; /* buffer wrap */
399 new_f2 = (bz->f2 + 1) & MAX_B_FRAMES;
400 if ((count > MAX_DATA_SIZE + 3) || (count < 4) ||
401 (*(bdata + (le16_to_cpu(zp->z1) - B_SUB_VAL)))) {
402 if (bch->debug & DEBUG_HW)
403 printk(KERN_DEBUG "hfcpci_empty_fifo: incoming packet "
404 "invalid length %d or crc\n", count);
405#ifdef ERROR_STATISTIC
406 bch->err_inv++;
407#endif
408 bz->za[new_f2].z2 = cpu_to_le16(new_z2);
409 bz->f2 = new_f2; /* next buffer */
410 } else {
411 bch->rx_skb = mI_alloc_skb(count - 3, GFP_ATOMIC);
412 if (!bch->rx_skb) {
413 printk(KERN_WARNING "HFCPCI: receive out of memory\n");
414 return;
415 }
416 total = count;
417 count -= 3;
418 ptr = skb_put(bch->rx_skb, count);
419
420 if (le16_to_cpu(zp->z2) + count <= B_FIFO_SIZE + B_SUB_VAL)
421 maxlen = count; /* complete transfer */
422 else
423 maxlen = B_FIFO_SIZE + B_SUB_VAL -
424 le16_to_cpu(zp->z2); /* maximum */
425
426 ptr1 = bdata + (le16_to_cpu(zp->z2) - B_SUB_VAL);
427 /* start of data */
428 memcpy(ptr, ptr1, maxlen); /* copy data */
429 count -= maxlen;
430
431 if (count) { /* rest remaining */
432 ptr += maxlen;
433 ptr1 = bdata; /* start of buffer */
434 memcpy(ptr, ptr1, count); /* rest */
435 }
436 bz->za[new_f2].z2 = cpu_to_le16(new_z2);
437 bz->f2 = new_f2; /* next buffer */
438 recv_Bchannel(bch);
439 }
440}
441
442/*
443 * D-channel receive procedure
444 */
445static int
446receive_dmsg(struct hfc_pci *hc)
447{
448 struct dchannel *dch = &hc->dch;
449 int maxlen;
450 int rcnt, total;
451 int count = 5;
452 u_char *ptr, *ptr1;
453 struct dfifo *df;
454 struct zt *zp;
455
456 df = &((union fifo_area *)(hc->hw.fifos))->d_chan.d_rx;
457 while (((df->f1 & D_FREG_MASK) != (df->f2 & D_FREG_MASK)) && count--) {
458 zp = &df->za[df->f2 & D_FREG_MASK];
459 rcnt = le16_to_cpu(zp->z1) - le16_to_cpu(zp->z2);
460 if (rcnt < 0)
461 rcnt += D_FIFO_SIZE;
462 rcnt++;
463 if (dch->debug & DEBUG_HW_DCHANNEL)
464 printk(KERN_DEBUG
465 "hfcpci recd f1(%d) f2(%d) z1(%x) z2(%x) cnt(%d)\n",
466 df->f1, df->f2,
467 le16_to_cpu(zp->z1),
468 le16_to_cpu(zp->z2),
469 rcnt);
470
471 if ((rcnt > MAX_DFRAME_LEN + 3) || (rcnt < 4) ||
472 (df->data[le16_to_cpu(zp->z1)])) {
473 if (dch->debug & DEBUG_HW)
474 printk(KERN_DEBUG
475 "empty_fifo hfcpci paket inv. len "
476 "%d or crc %d\n",
477 rcnt,
478 df->data[le16_to_cpu(zp->z1)]);
479#ifdef ERROR_STATISTIC
480 cs->err_rx++;
481#endif
482 df->f2 = ((df->f2 + 1) & MAX_D_FRAMES) |
483 (MAX_D_FRAMES + 1); /* next buffer */
484 df->za[df->f2 & D_FREG_MASK].z2 =
485 cpu_to_le16((zp->z2 + rcnt) & (D_FIFO_SIZE - 1));
486 } else {
487 dch->rx_skb = mI_alloc_skb(rcnt - 3, GFP_ATOMIC);
488 if (!dch->rx_skb) {
489 printk(KERN_WARNING
490 "HFC-PCI: D receive out of memory\n");
491 break;
492 }
493 total = rcnt;
494 rcnt -= 3;
495 ptr = skb_put(dch->rx_skb, rcnt);
496
497 if (le16_to_cpu(zp->z2) + rcnt <= D_FIFO_SIZE)
498 maxlen = rcnt; /* complete transfer */
499 else
500 maxlen = D_FIFO_SIZE - le16_to_cpu(zp->z2);
501 /* maximum */
502
503 ptr1 = df->data + le16_to_cpu(zp->z2);
504 /* start of data */
505 memcpy(ptr, ptr1, maxlen); /* copy data */
506 rcnt -= maxlen;
507
508 if (rcnt) { /* rest remaining */
509 ptr += maxlen;
510 ptr1 = df->data; /* start of buffer */
511 memcpy(ptr, ptr1, rcnt); /* rest */
512 }
513 df->f2 = ((df->f2 + 1) & MAX_D_FRAMES) |
514 (MAX_D_FRAMES + 1); /* next buffer */
515 df->za[df->f2 & D_FREG_MASK].z2 = cpu_to_le16((
516 le16_to_cpu(zp->z2) + total) & (D_FIFO_SIZE - 1));
517 recv_Dchannel(dch);
518 }
519 }
520 return 1;
521}
522
523/*
524 * check for transparent receive data and read max one threshold size if avail
525 */
526int
527hfcpci_empty_fifo_trans(struct bchannel *bch, struct bzfifo *bz, u_char *bdata)
528{
529 unsigned short *z1r, *z2r;
530 int new_z2, fcnt, maxlen;
531 u_char *ptr, *ptr1;
532
533 z1r = &bz->za[MAX_B_FRAMES].z1; /* pointer to z reg */
534 z2r = z1r + 1;
535
536 fcnt = le16_to_cpu(*z1r) - le16_to_cpu(*z2r);
537 if (!fcnt)
538 return 0; /* no data avail */
539
540 if (fcnt <= 0)
541 fcnt += B_FIFO_SIZE; /* bytes actually buffered */
542 if (fcnt > HFCPCI_BTRANS_THRESHOLD)
543 fcnt = HFCPCI_BTRANS_THRESHOLD; /* limit size */
544
545 new_z2 = le16_to_cpu(*z2r) + fcnt; /* new position in fifo */
546 if (new_z2 >= (B_FIFO_SIZE + B_SUB_VAL))
547 new_z2 -= B_FIFO_SIZE; /* buffer wrap */
548
549 bch->rx_skb = mI_alloc_skb(fcnt, GFP_ATOMIC);
550 if (bch->rx_skb) {
551 ptr = skb_put(bch->rx_skb, fcnt);
552 if (le16_to_cpu(*z2r) + fcnt <= B_FIFO_SIZE + B_SUB_VAL)
553 maxlen = fcnt; /* complete transfer */
554 else
555 maxlen = B_FIFO_SIZE + B_SUB_VAL - le16_to_cpu(*z2r);
556 /* maximum */
557
558 ptr1 = bdata + (le16_to_cpu(*z2r) - B_SUB_VAL);
559 /* start of data */
560 memcpy(ptr, ptr1, maxlen); /* copy data */
561 fcnt -= maxlen;
562
563 if (fcnt) { /* rest remaining */
564 ptr += maxlen;
565 ptr1 = bdata; /* start of buffer */
566 memcpy(ptr, ptr1, fcnt); /* rest */
567 }
568 recv_Bchannel(bch);
569 } else
570 printk(KERN_WARNING "HFCPCI: receive out of memory\n");
571
572 *z2r = cpu_to_le16(new_z2); /* new position */
573 return 1;
574}
575
576/*
577 * B-channel main receive routine
578 */
579void
580main_rec_hfcpci(struct bchannel *bch)
581{
582 struct hfc_pci *hc = bch->hw;
583 int rcnt, real_fifo;
584 int receive, count = 5;
585 struct bzfifo *bz;
586 u_char *bdata;
587 struct zt *zp;
588
589
590 if ((bch->nr & 2) && (!hc->hw.bswapped)) {
591 bz = &((union fifo_area *)(hc->hw.fifos))->b_chans.rxbz_b2;
592 bdata = ((union fifo_area *)(hc->hw.fifos))->b_chans.rxdat_b2;
593 real_fifo = 1;
594 } else {
595 bz = &((union fifo_area *)(hc->hw.fifos))->b_chans.rxbz_b1;
596 bdata = ((union fifo_area *)(hc->hw.fifos))->b_chans.rxdat_b1;
597 real_fifo = 0;
598 }
599Begin:
600 count--;
601 if (bz->f1 != bz->f2) {
602 if (bch->debug & DEBUG_HW_BCHANNEL)
603 printk(KERN_DEBUG "hfcpci rec ch(%x) f1(%d) f2(%d)\n",
604 bch->nr, bz->f1, bz->f2);
605 zp = &bz->za[bz->f2];
606
607 rcnt = le16_to_cpu(zp->z1) - le16_to_cpu(zp->z2);
608 if (rcnt < 0)
609 rcnt += B_FIFO_SIZE;
610 rcnt++;
611 if (bch->debug & DEBUG_HW_BCHANNEL)
612 printk(KERN_DEBUG
613 "hfcpci rec ch(%x) z1(%x) z2(%x) cnt(%d)\n",
614 bch->nr, le16_to_cpu(zp->z1),
615 le16_to_cpu(zp->z2), rcnt);
616 hfcpci_empty_bfifo(bch, bz, bdata, rcnt);
617 rcnt = bz->f1 - bz->f2;
618 if (rcnt < 0)
619 rcnt += MAX_B_FRAMES + 1;
620 if (hc->hw.last_bfifo_cnt[real_fifo] > rcnt + 1) {
621 rcnt = 0;
622 hfcpci_clear_fifo_rx(hc, real_fifo);
623 }
624 hc->hw.last_bfifo_cnt[real_fifo] = rcnt;
625 if (rcnt > 1)
626 receive = 1;
627 else
628 receive = 0;
629 } else if (test_bit(FLG_TRANSPARENT, &bch->Flags))
630 receive = hfcpci_empty_fifo_trans(bch, bz, bdata);
631 else
632 receive = 0;
633 if (count && receive)
634 goto Begin;
635
636}
637
638/*
639 * D-channel send routine
640 */
641static void
642hfcpci_fill_dfifo(struct hfc_pci *hc)
643{
644 struct dchannel *dch = &hc->dch;
645 int fcnt;
646 int count, new_z1, maxlen;
647 struct dfifo *df;
648 u_char *src, *dst, new_f1;
649
650 if ((dch->debug & DEBUG_HW_DCHANNEL) && !(dch->debug & DEBUG_HW_DFIFO))
651 printk(KERN_DEBUG "%s\n", __func__);
652
653 if (!dch->tx_skb)
654 return;
655 count = dch->tx_skb->len - dch->tx_idx;
656 if (count <= 0)
657 return;
658 df = &((union fifo_area *) (hc->hw.fifos))->d_chan.d_tx;
659
660 if (dch->debug & DEBUG_HW_DFIFO)
661 printk(KERN_DEBUG "%s:f1(%d) f2(%d) z1(f1)(%x)\n", __func__,
662 df->f1, df->f2,
663 le16_to_cpu(df->za[df->f1 & D_FREG_MASK].z1));
664 fcnt = df->f1 - df->f2; /* frame count actually buffered */
665 if (fcnt < 0)
666 fcnt += (MAX_D_FRAMES + 1); /* if wrap around */
667 if (fcnt > (MAX_D_FRAMES - 1)) {
668 if (dch->debug & DEBUG_HW_DCHANNEL)
669 printk(KERN_DEBUG
670 "hfcpci_fill_Dfifo more as 14 frames\n");
671#ifdef ERROR_STATISTIC
672 cs->err_tx++;
673#endif
674 return;
675 }
676 /* now determine free bytes in FIFO buffer */
677 maxlen = le16_to_cpu(df->za[df->f2 & D_FREG_MASK].z2) -
678 le16_to_cpu(df->za[df->f1 & D_FREG_MASK].z1) - 1;
679 if (maxlen <= 0)
680 maxlen += D_FIFO_SIZE; /* count now contains available bytes */
681
682 if (dch->debug & DEBUG_HW_DCHANNEL)
683 printk(KERN_DEBUG "hfcpci_fill_Dfifo count(%d/%d)\n",
684 count, maxlen);
685 if (count > maxlen) {
686 if (dch->debug & DEBUG_HW_DCHANNEL)
687 printk(KERN_DEBUG "hfcpci_fill_Dfifo no fifo mem\n");
688 return;
689 }
690 new_z1 = (le16_to_cpu(df->za[df->f1 & D_FREG_MASK].z1) + count) &
691 (D_FIFO_SIZE - 1);
692 new_f1 = ((df->f1 + 1) & D_FREG_MASK) | (D_FREG_MASK + 1);
693 src = dch->tx_skb->data + dch->tx_idx; /* source pointer */
694 dst = df->data + le16_to_cpu(df->za[df->f1 & D_FREG_MASK].z1);
695 maxlen = D_FIFO_SIZE - le16_to_cpu(df->za[df->f1 & D_FREG_MASK].z1);
696 /* end fifo */
697 if (maxlen > count)
698 maxlen = count; /* limit size */
699 memcpy(dst, src, maxlen); /* first copy */
700
701 count -= maxlen; /* remaining bytes */
702 if (count) {
703 dst = df->data; /* start of buffer */
704 src += maxlen; /* new position */
705 memcpy(dst, src, count);
706 }
707 df->za[new_f1 & D_FREG_MASK].z1 = cpu_to_le16(new_z1);
708 /* for next buffer */
709 df->za[df->f1 & D_FREG_MASK].z1 = cpu_to_le16(new_z1);
710 /* new pos actual buffer */
711 df->f1 = new_f1; /* next frame */
712 dch->tx_idx = dch->tx_skb->len;
713}
714
715/*
716 * B-channel send routine
717 */
718static void
719hfcpci_fill_fifo(struct bchannel *bch)
720{
721 struct hfc_pci *hc = bch->hw;
722 int maxlen, fcnt;
723 int count, new_z1;
724 struct bzfifo *bz;
725 u_char *bdata;
726 u_char new_f1, *src, *dst;
727 unsigned short *z1t, *z2t;
728
729 if ((bch->debug & DEBUG_HW_BCHANNEL) && !(bch->debug & DEBUG_HW_BFIFO))
730 printk(KERN_DEBUG "%s\n", __func__);
731 if ((!bch->tx_skb) || bch->tx_skb->len <= 0)
732 return;
733 count = bch->tx_skb->len - bch->tx_idx;
734 if ((bch->nr & 2) && (!hc->hw.bswapped)) {
735 bz = &((union fifo_area *)(hc->hw.fifos))->b_chans.txbz_b2;
736 bdata = ((union fifo_area *)(hc->hw.fifos))->b_chans.txdat_b2;
737 } else {
738 bz = &((union fifo_area *)(hc->hw.fifos))->b_chans.txbz_b1;
739 bdata = ((union fifo_area *)(hc->hw.fifos))->b_chans.txdat_b1;
740 }
741
742 if (test_bit(FLG_TRANSPARENT, &bch->Flags)) {
743 z1t = &bz->za[MAX_B_FRAMES].z1;
744 z2t = z1t + 1;
745 if (bch->debug & DEBUG_HW_BCHANNEL)
746 printk(KERN_DEBUG "hfcpci_fill_fifo_trans ch(%x) "
747 "cnt(%d) z1(%x) z2(%x)\n", bch->nr, count,
748 le16_to_cpu(*z1t), le16_to_cpu(*z2t));
749 fcnt = le16_to_cpu(*z2t) - le16_to_cpu(*z1t);
750 if (fcnt <= 0)
751 fcnt += B_FIFO_SIZE;
752 /* fcnt contains available bytes in fifo */
753 fcnt = B_FIFO_SIZE - fcnt;
754 /* remaining bytes to send (bytes in fifo) */
755next_t_frame:
756 count = bch->tx_skb->len - bch->tx_idx;
757 /* maximum fill shall be HFCPCI_BTRANS_MAX */
758 if (count > HFCPCI_BTRANS_MAX - fcnt)
759 count = HFCPCI_BTRANS_MAX - fcnt;
760 if (count <= 0)
761 return;
762 /* data is suitable for fifo */
763 new_z1 = le16_to_cpu(*z1t) + count;
764 /* new buffer Position */
765 if (new_z1 >= (B_FIFO_SIZE + B_SUB_VAL))
766 new_z1 -= B_FIFO_SIZE; /* buffer wrap */
767 src = bch->tx_skb->data + bch->tx_idx;
768 /* source pointer */
769 dst = bdata + (le16_to_cpu(*z1t) - B_SUB_VAL);
770 maxlen = (B_FIFO_SIZE + B_SUB_VAL) - le16_to_cpu(*z1t);
771 /* end of fifo */
772 if (bch->debug & DEBUG_HW_BFIFO)
773 printk(KERN_DEBUG "hfcpci_FFt fcnt(%d) "
774 "maxl(%d) nz1(%x) dst(%p)\n",
775 fcnt, maxlen, new_z1, dst);
776 fcnt += count;
777 bch->tx_idx += count;
778 if (maxlen > count)
779 maxlen = count; /* limit size */
780 memcpy(dst, src, maxlen); /* first copy */
781 count -= maxlen; /* remaining bytes */
782 if (count) {
783 dst = bdata; /* start of buffer */
784 src += maxlen; /* new position */
785 memcpy(dst, src, count);
786 }
787 *z1t = cpu_to_le16(new_z1); /* now send data */
788 if (bch->tx_idx < bch->tx_skb->len)
789 return;
790 /* send confirm, on trans, free on hdlc. */
791 if (test_bit(FLG_TRANSPARENT, &bch->Flags))
792 confirm_Bsend(bch);
793 dev_kfree_skb(bch->tx_skb);
794 if (get_next_bframe(bch))
795 goto next_t_frame;
796 return;
797 }
798 if (bch->debug & DEBUG_HW_BCHANNEL)
799 printk(KERN_DEBUG
800 "%s: ch(%x) f1(%d) f2(%d) z1(f1)(%x)\n",
801 __func__, bch->nr, bz->f1, bz->f2,
802 bz->za[bz->f1].z1);
803 fcnt = bz->f1 - bz->f2; /* frame count actually buffered */
804 if (fcnt < 0)
805 fcnt += (MAX_B_FRAMES + 1); /* if wrap around */
806 if (fcnt > (MAX_B_FRAMES - 1)) {
807 if (bch->debug & DEBUG_HW_BCHANNEL)
808 printk(KERN_DEBUG
809 "hfcpci_fill_Bfifo more as 14 frames\n");
810 return;
811 }
812 /* now determine free bytes in FIFO buffer */
813 maxlen = le16_to_cpu(bz->za[bz->f2].z2) -
814 le16_to_cpu(bz->za[bz->f1].z1) - 1;
815 if (maxlen <= 0)
816 maxlen += B_FIFO_SIZE; /* count now contains available bytes */
817
818 if (bch->debug & DEBUG_HW_BCHANNEL)
819 printk(KERN_DEBUG "hfcpci_fill_fifo ch(%x) count(%d/%d)\n",
820 bch->nr, count, maxlen);
821
822 if (maxlen < count) {
823 if (bch->debug & DEBUG_HW_BCHANNEL)
824 printk(KERN_DEBUG "hfcpci_fill_fifo no fifo mem\n");
825 return;
826 }
827 new_z1 = le16_to_cpu(bz->za[bz->f1].z1) + count;
828 /* new buffer Position */
829 if (new_z1 >= (B_FIFO_SIZE + B_SUB_VAL))
830 new_z1 -= B_FIFO_SIZE; /* buffer wrap */
831
832 new_f1 = ((bz->f1 + 1) & MAX_B_FRAMES);
833 src = bch->tx_skb->data + bch->tx_idx; /* source pointer */
834 dst = bdata + (le16_to_cpu(bz->za[bz->f1].z1) - B_SUB_VAL);
835 maxlen = (B_FIFO_SIZE + B_SUB_VAL) - le16_to_cpu(bz->za[bz->f1].z1);
836 /* end fifo */
837 if (maxlen > count)
838 maxlen = count; /* limit size */
839 memcpy(dst, src, maxlen); /* first copy */
840
841 count -= maxlen; /* remaining bytes */
842 if (count) {
843 dst = bdata; /* start of buffer */
844 src += maxlen; /* new position */
845 memcpy(dst, src, count);
846 }
847 bz->za[new_f1].z1 = cpu_to_le16(new_z1); /* for next buffer */
848 bz->f1 = new_f1; /* next frame */
849 dev_kfree_skb(bch->tx_skb);
850 get_next_bframe(bch);
851}
852
853
854
855/*
856 * handle L1 state changes TE
857 */
858
859static void
860ph_state_te(struct dchannel *dch)
861{
862 if (dch->debug)
863 printk(KERN_DEBUG "%s: TE newstate %x\n",
864 __func__, dch->state);
865 switch (dch->state) {
866 case 0:
867 l1_event(dch->l1, HW_RESET_IND);
868 break;
869 case 3:
870 l1_event(dch->l1, HW_DEACT_IND);
871 break;
872 case 5:
873 case 8:
874 l1_event(dch->l1, ANYSIGNAL);
875 break;
876 case 6:
877 l1_event(dch->l1, INFO2);
878 break;
879 case 7:
880 l1_event(dch->l1, INFO4_P8);
881 break;
882 }
883}
884
885/*
886 * handle L1 state changes NT
887 */
888
889static void
890handle_nt_timer3(struct dchannel *dch) {
891 struct hfc_pci *hc = dch->hw;
892
893 test_and_clear_bit(FLG_HFC_TIMER_T3, &dch->Flags);
894 hc->hw.int_m1 &= ~HFCPCI_INTS_TIMER;
895 Write_hfc(hc, HFCPCI_INT_M1, hc->hw.int_m1);
896 hc->hw.nt_timer = 0;
897 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
898 if (test_bit(HFC_CFG_MASTER, &hc->cfg))
899 hc->hw.mst_m |= HFCPCI_MASTER;
900 Write_hfc(hc, HFCPCI_MST_MODE, hc->hw.mst_m);
901 _queue_data(&dch->dev.D, PH_ACTIVATE_IND,
902 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
903}
904
905static void
906ph_state_nt(struct dchannel *dch)
907{
908 struct hfc_pci *hc = dch->hw;
909
910 if (dch->debug)
911 printk(KERN_DEBUG "%s: NT newstate %x\n",
912 __func__, dch->state);
913 switch (dch->state) {
914 case 2:
915 if (hc->hw.nt_timer < 0) {
916 hc->hw.nt_timer = 0;
917 test_and_clear_bit(FLG_HFC_TIMER_T3, &dch->Flags);
918 test_and_clear_bit(FLG_HFC_TIMER_T1, &dch->Flags);
919 hc->hw.int_m1 &= ~HFCPCI_INTS_TIMER;
920 Write_hfc(hc, HFCPCI_INT_M1, hc->hw.int_m1);
921 /* Clear already pending ints */
922 if (Read_hfc(hc, HFCPCI_INT_S1));
923 Write_hfc(hc, HFCPCI_STATES, 4 | HFCPCI_LOAD_STATE);
924 udelay(10);
925 Write_hfc(hc, HFCPCI_STATES, 4);
926 dch->state = 4;
927 } else if (hc->hw.nt_timer == 0) {
928 hc->hw.int_m1 |= HFCPCI_INTS_TIMER;
929 Write_hfc(hc, HFCPCI_INT_M1, hc->hw.int_m1);
930 hc->hw.nt_timer = NT_T1_COUNT;
931 hc->hw.ctmt &= ~HFCPCI_AUTO_TIMER;
932 hc->hw.ctmt |= HFCPCI_TIM3_125;
933 Write_hfc(hc, HFCPCI_CTMT, hc->hw.ctmt |
934 HFCPCI_CLTIMER);
935 test_and_clear_bit(FLG_HFC_TIMER_T3, &dch->Flags);
936 test_and_set_bit(FLG_HFC_TIMER_T1, &dch->Flags);
937 /* allow G2 -> G3 transition */
938 Write_hfc(hc, HFCPCI_STATES, 2 | HFCPCI_NT_G2_G3);
939 } else {
940 Write_hfc(hc, HFCPCI_STATES, 2 | HFCPCI_NT_G2_G3);
941 }
942 break;
943 case 1:
944 hc->hw.nt_timer = 0;
945 test_and_clear_bit(FLG_HFC_TIMER_T3, &dch->Flags);
946 test_and_clear_bit(FLG_HFC_TIMER_T1, &dch->Flags);
947 hc->hw.int_m1 &= ~HFCPCI_INTS_TIMER;
948 Write_hfc(hc, HFCPCI_INT_M1, hc->hw.int_m1);
949 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
950 hc->hw.mst_m &= ~HFCPCI_MASTER;
951 Write_hfc(hc, HFCPCI_MST_MODE, hc->hw.mst_m);
952 test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
953 _queue_data(&dch->dev.D, PH_DEACTIVATE_IND,
954 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
955 break;
956 case 4:
957 hc->hw.nt_timer = 0;
958 test_and_clear_bit(FLG_HFC_TIMER_T3, &dch->Flags);
959 test_and_clear_bit(FLG_HFC_TIMER_T1, &dch->Flags);
960 hc->hw.int_m1 &= ~HFCPCI_INTS_TIMER;
961 Write_hfc(hc, HFCPCI_INT_M1, hc->hw.int_m1);
962 break;
963 case 3:
964 if (!test_and_set_bit(FLG_HFC_TIMER_T3, &dch->Flags)) {
965 if (!test_and_clear_bit(FLG_L2_ACTIVATED,
966 &dch->Flags)) {
967 handle_nt_timer3(dch);
968 break;
969 }
970 test_and_clear_bit(FLG_HFC_TIMER_T1, &dch->Flags);
971 hc->hw.int_m1 |= HFCPCI_INTS_TIMER;
972 Write_hfc(hc, HFCPCI_INT_M1, hc->hw.int_m1);
973 hc->hw.nt_timer = NT_T3_COUNT;
974 hc->hw.ctmt &= ~HFCPCI_AUTO_TIMER;
975 hc->hw.ctmt |= HFCPCI_TIM3_125;
976 Write_hfc(hc, HFCPCI_CTMT, hc->hw.ctmt |
977 HFCPCI_CLTIMER);
978 }
979 break;
980 }
981}
982
983static void
984ph_state(struct dchannel *dch)
985{
986 struct hfc_pci *hc = dch->hw;
987
988 if (hc->hw.protocol == ISDN_P_NT_S0) {
989 if (test_bit(FLG_HFC_TIMER_T3, &dch->Flags) &&
990 hc->hw.nt_timer < 0)
991 handle_nt_timer3(dch);
992 else
993 ph_state_nt(dch);
994 } else
995 ph_state_te(dch);
996}
997
998/*
999 * Layer 1 callback function
1000 */
1001static int
1002hfc_l1callback(struct dchannel *dch, u_int cmd)
1003{
1004 struct hfc_pci *hc = dch->hw;
1005
1006 switch (cmd) {
1007 case INFO3_P8:
1008 case INFO3_P10:
1009 if (test_bit(HFC_CFG_MASTER, &hc->cfg))
1010 hc->hw.mst_m |= HFCPCI_MASTER;
1011 Write_hfc(hc, HFCPCI_MST_MODE, hc->hw.mst_m);
1012 break;
1013 case HW_RESET_REQ:
1014 Write_hfc(hc, HFCPCI_STATES, HFCPCI_LOAD_STATE | 3);
1015 /* HFC ST 3 */
1016 udelay(6);
1017 Write_hfc(hc, HFCPCI_STATES, 3); /* HFC ST 2 */
1018 if (test_bit(HFC_CFG_MASTER, &hc->cfg))
1019 hc->hw.mst_m |= HFCPCI_MASTER;
1020 Write_hfc(hc, HFCPCI_MST_MODE, hc->hw.mst_m);
1021 Write_hfc(hc, HFCPCI_STATES, HFCPCI_ACTIVATE |
1022 HFCPCI_DO_ACTION);
1023 l1_event(dch->l1, HW_POWERUP_IND);
1024 break;
1025 case HW_DEACT_REQ:
1026 hc->hw.mst_m &= ~HFCPCI_MASTER;
1027 Write_hfc(hc, HFCPCI_MST_MODE, hc->hw.mst_m);
1028 skb_queue_purge(&dch->squeue);
1029 if (dch->tx_skb) {
1030 dev_kfree_skb(dch->tx_skb);
1031 dch->tx_skb = NULL;
1032 }
1033 dch->tx_idx = 0;
1034 if (dch->rx_skb) {
1035 dev_kfree_skb(dch->rx_skb);
1036 dch->rx_skb = NULL;
1037 }
1038 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
1039 if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
1040 del_timer(&dch->timer);
1041 break;
1042 case HW_POWERUP_REQ:
1043 Write_hfc(hc, HFCPCI_STATES, HFCPCI_DO_ACTION);
1044 break;
1045 case PH_ACTIVATE_IND:
1046 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
1047 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
1048 GFP_ATOMIC);
1049 break;
1050 case PH_DEACTIVATE_IND:
1051 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
1052 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
1053 GFP_ATOMIC);
1054 break;
1055 default:
1056 if (dch->debug & DEBUG_HW)
1057 printk(KERN_DEBUG "%s: unknown command %x\n",
1058 __func__, cmd);
1059 return -1;
1060 }
1061 return 0;
1062}
1063
1064/*
1065 * Interrupt handler
1066 */
1067static inline void
1068tx_birq(struct bchannel *bch)
1069{
1070 if (bch->tx_skb && bch->tx_idx < bch->tx_skb->len)
1071 hfcpci_fill_fifo(bch);
1072 else {
1073 if (bch->tx_skb)
1074 dev_kfree_skb(bch->tx_skb);
1075 if (get_next_bframe(bch))
1076 hfcpci_fill_fifo(bch);
1077 }
1078}
1079
1080static inline void
1081tx_dirq(struct dchannel *dch)
1082{
1083 if (dch->tx_skb && dch->tx_idx < dch->tx_skb->len)
1084 hfcpci_fill_dfifo(dch->hw);
1085 else {
1086 if (dch->tx_skb)
1087 dev_kfree_skb(dch->tx_skb);
1088 if (get_next_dframe(dch))
1089 hfcpci_fill_dfifo(dch->hw);
1090 }
1091}
1092
1093static irqreturn_t
1094hfcpci_int(int intno, void *dev_id)
1095{
1096 struct hfc_pci *hc = dev_id;
1097 u_char exval;
1098 struct bchannel *bch;
1099 u_char val, stat;
1100
1101 spin_lock(&hc->lock);
1102 if (!(hc->hw.int_m2 & 0x08)) {
1103 spin_unlock(&hc->lock);
1104 return IRQ_NONE; /* not initialised */
1105 }
1106 stat = Read_hfc(hc, HFCPCI_STATUS);
1107 if (HFCPCI_ANYINT & stat) {
1108 val = Read_hfc(hc, HFCPCI_INT_S1);
1109 if (hc->dch.debug & DEBUG_HW_DCHANNEL)
1110 printk(KERN_DEBUG
1111 "HFC-PCI: stat(%02x) s1(%02x)\n", stat, val);
1112 } else {
1113 /* shared */
1114 spin_unlock(&hc->lock);
1115 return IRQ_NONE;
1116 }
1117 hc->irqcnt++;
1118
1119 if (hc->dch.debug & DEBUG_HW_DCHANNEL)
1120 printk(KERN_DEBUG "HFC-PCI irq %x\n", val);
1121 val &= hc->hw.int_m1;
1122 if (val & 0x40) { /* state machine irq */
1123 exval = Read_hfc(hc, HFCPCI_STATES) & 0xf;
1124 if (hc->dch.debug & DEBUG_HW_DCHANNEL)
1125 printk(KERN_DEBUG "ph_state chg %d->%d\n",
1126 hc->dch.state, exval);
1127 hc->dch.state = exval;
1128 schedule_event(&hc->dch, FLG_PHCHANGE);
1129 val &= ~0x40;
1130 }
1131 if (val & 0x80) { /* timer irq */
1132 if (hc->hw.protocol == ISDN_P_NT_S0) {
1133 if ((--hc->hw.nt_timer) < 0)
1134 schedule_event(&hc->dch, FLG_PHCHANGE);
1135 }
1136 val &= ~0x80;
1137 Write_hfc(hc, HFCPCI_CTMT, hc->hw.ctmt | HFCPCI_CLTIMER);
1138 }
1139 if (val & 0x08) {
1140 bch = Sel_BCS(hc, hc->hw.bswapped ? 2 : 1);
1141 if (bch)
1142 main_rec_hfcpci(bch);
1143 else if (hc->dch.debug)
1144 printk(KERN_DEBUG "hfcpci spurious 0x08 IRQ\n");
1145 }
1146 if (val & 0x10) {
1147 bch = Sel_BCS(hc, 2);
1148 if (bch)
1149 main_rec_hfcpci(bch);
1150 else if (hc->dch.debug)
1151 printk(KERN_DEBUG "hfcpci spurious 0x10 IRQ\n");
1152 }
1153 if (val & 0x01) {
1154 bch = Sel_BCS(hc, hc->hw.bswapped ? 2 : 1);
1155 if (bch)
1156 tx_birq(bch);
1157 else if (hc->dch.debug)
1158 printk(KERN_DEBUG "hfcpci spurious 0x01 IRQ\n");
1159 }
1160 if (val & 0x02) {
1161 bch = Sel_BCS(hc, 2);
1162 if (bch)
1163 tx_birq(bch);
1164 else if (hc->dch.debug)
1165 printk(KERN_DEBUG "hfcpci spurious 0x02 IRQ\n");
1166 }
1167 if (val & 0x20)
1168 receive_dmsg(hc);
1169 if (val & 0x04) { /* dframe transmitted */
1170 if (test_and_clear_bit(FLG_BUSY_TIMER, &hc->dch.Flags))
1171 del_timer(&hc->dch.timer);
1172 tx_dirq(&hc->dch);
1173 }
1174 spin_unlock(&hc->lock);
1175 return IRQ_HANDLED;
1176}
1177
1178/*
1179 * timer callback for D-chan busy resolution. Currently no function
1180 */
1181static void
1182hfcpci_dbusy_timer(struct hfc_pci *hc)
1183{
1184}
1185
1186/*
1187 * activate/deactivate hardware for selected channels and mode
1188 */
1189static int
1190mode_hfcpci(struct bchannel *bch, int bc, int protocol)
1191{
1192 struct hfc_pci *hc = bch->hw;
1193 int fifo2;
1194 u_char rx_slot = 0, tx_slot = 0, pcm_mode;
1195
1196 if (bch->debug & DEBUG_HW_BCHANNEL)
1197 printk(KERN_DEBUG
1198 "HFCPCI bchannel protocol %x-->%x ch %x-->%x\n",
1199 bch->state, protocol, bch->nr, bc);
1200
1201 fifo2 = bc;
1202 pcm_mode = (bc>>24) & 0xff;
1203 if (pcm_mode) { /* PCM SLOT USE */
1204 if (!test_bit(HFC_CFG_PCM, &hc->cfg))
1205 printk(KERN_WARNING
1206 "%s: pcm channel id without HFC_CFG_PCM\n",
1207 __func__);
1208 rx_slot = (bc>>8) & 0xff;
1209 tx_slot = (bc>>16) & 0xff;
1210 bc = bc & 0xff;
1211 } else if (test_bit(HFC_CFG_PCM, &hc->cfg) &&
1212 (protocol > ISDN_P_NONE))
1213 printk(KERN_WARNING "%s: no pcm channel id but HFC_CFG_PCM\n",
1214 __func__);
1215 if (hc->chanlimit > 1) {
1216 hc->hw.bswapped = 0; /* B1 and B2 normal mode */
1217 hc->hw.sctrl_e &= ~0x80;
1218 } else {
1219 if (bc & 2) {
1220 if (protocol != ISDN_P_NONE) {
1221 hc->hw.bswapped = 1; /* B1 and B2 exchanged */
1222 hc->hw.sctrl_e |= 0x80;
1223 } else {
1224 hc->hw.bswapped = 0; /* B1 and B2 normal mode */
1225 hc->hw.sctrl_e &= ~0x80;
1226 }
1227 fifo2 = 1;
1228 } else {
1229 hc->hw.bswapped = 0; /* B1 and B2 normal mode */
1230 hc->hw.sctrl_e &= ~0x80;
1231 }
1232 }
1233 switch (protocol) {
1234 case (-1): /* used for init */
1235 bch->state = -1;
1236 bch->nr = bc;
1237 case (ISDN_P_NONE):
1238 if (bch->state == ISDN_P_NONE)
1239 return 0;
1240 if (bc & 2) {
1241 hc->hw.sctrl &= ~SCTRL_B2_ENA;
1242 hc->hw.sctrl_r &= ~SCTRL_B2_ENA;
1243 } else {
1244 hc->hw.sctrl &= ~SCTRL_B1_ENA;
1245 hc->hw.sctrl_r &= ~SCTRL_B1_ENA;
1246 }
1247 if (fifo2 & 2) {
1248 hc->hw.fifo_en &= ~HFCPCI_FIFOEN_B2;
1249 hc->hw.int_m1 &= ~(HFCPCI_INTS_B2TRANS +
1250 HFCPCI_INTS_B2REC);
1251 } else {
1252 hc->hw.fifo_en &= ~HFCPCI_FIFOEN_B1;
1253 hc->hw.int_m1 &= ~(HFCPCI_INTS_B1TRANS +
1254 HFCPCI_INTS_B1REC);
1255 }
1256#ifdef REVERSE_BITORDER
1257 if (bch->nr & 2)
1258 hc->hw.cirm &= 0x7f;
1259 else
1260 hc->hw.cirm &= 0xbf;
1261#endif
1262 bch->state = ISDN_P_NONE;
1263 bch->nr = bc;
1264 test_and_clear_bit(FLG_HDLC, &bch->Flags);
1265 test_and_clear_bit(FLG_TRANSPARENT, &bch->Flags);
1266 break;
1267 case (ISDN_P_B_RAW):
1268 bch->state = protocol;
1269 bch->nr = bc;
1270 hfcpci_clear_fifo_rx(hc, (fifo2 & 2)?1:0);
1271 hfcpci_clear_fifo_tx(hc, (fifo2 & 2)?1:0);
1272 if (bc & 2) {
1273 hc->hw.sctrl |= SCTRL_B2_ENA;
1274 hc->hw.sctrl_r |= SCTRL_B2_ENA;
1275#ifdef REVERSE_BITORDER
1276 hc->hw.cirm |= 0x80;
1277#endif
1278 } else {
1279 hc->hw.sctrl |= SCTRL_B1_ENA;
1280 hc->hw.sctrl_r |= SCTRL_B1_ENA;
1281#ifdef REVERSE_BITORDER
1282 hc->hw.cirm |= 0x40;
1283#endif
1284 }
1285 if (fifo2 & 2) {
1286 hc->hw.fifo_en |= HFCPCI_FIFOEN_B2;
1287 hc->hw.int_m1 |= (HFCPCI_INTS_B2TRANS +
1288 HFCPCI_INTS_B2REC);
1289 hc->hw.ctmt |= 2;
1290 hc->hw.conn &= ~0x18;
1291 } else {
1292 hc->hw.fifo_en |= HFCPCI_FIFOEN_B1;
1293 hc->hw.int_m1 |= (HFCPCI_INTS_B1TRANS +
1294 HFCPCI_INTS_B1REC);
1295 hc->hw.ctmt |= 1;
1296 hc->hw.conn &= ~0x03;
1297 }
1298 test_and_set_bit(FLG_TRANSPARENT, &bch->Flags);
1299 break;
1300 case (ISDN_P_B_HDLC):
1301 bch->state = protocol;
1302 bch->nr = bc;
1303 hfcpci_clear_fifo_rx(hc, (fifo2 & 2)?1:0);
1304 hfcpci_clear_fifo_tx(hc, (fifo2 & 2)?1:0);
1305 if (bc & 2) {
1306 hc->hw.sctrl |= SCTRL_B2_ENA;
1307 hc->hw.sctrl_r |= SCTRL_B2_ENA;
1308 } else {
1309 hc->hw.sctrl |= SCTRL_B1_ENA;
1310 hc->hw.sctrl_r |= SCTRL_B1_ENA;
1311 }
1312 if (fifo2 & 2) {
1313 hc->hw.last_bfifo_cnt[1] = 0;
1314 hc->hw.fifo_en |= HFCPCI_FIFOEN_B2;
1315 hc->hw.int_m1 |= (HFCPCI_INTS_B2TRANS +
1316 HFCPCI_INTS_B2REC);
1317 hc->hw.ctmt &= ~2;
1318 hc->hw.conn &= ~0x18;
1319 } else {
1320 hc->hw.last_bfifo_cnt[0] = 0;
1321 hc->hw.fifo_en |= HFCPCI_FIFOEN_B1;
1322 hc->hw.int_m1 |= (HFCPCI_INTS_B1TRANS +
1323 HFCPCI_INTS_B1REC);
1324 hc->hw.ctmt &= ~1;
1325 hc->hw.conn &= ~0x03;
1326 }
1327 test_and_set_bit(FLG_HDLC, &bch->Flags);
1328 break;
1329 default:
1330 printk(KERN_DEBUG "prot not known %x\n", protocol);
1331 return -ENOPROTOOPT;
1332 }
1333 if (test_bit(HFC_CFG_PCM, &hc->cfg)) {
1334 if ((protocol == ISDN_P_NONE) ||
1335 (protocol == -1)) { /* init case */
1336 rx_slot = 0;
1337 tx_slot = 0;
1338 } else {
1339 if (test_bit(HFC_CFG_SW_DD_DU, &hc->cfg)) {
1340 rx_slot |= 0xC0;
1341 tx_slot |= 0xC0;
1342 } else {
1343 rx_slot |= 0x80;
1344 tx_slot |= 0x80;
1345 }
1346 }
1347 if (bc & 2) {
1348 hc->hw.conn &= 0xc7;
1349 hc->hw.conn |= 0x08;
1350 printk(KERN_DEBUG "%s: Write_hfc: B2_SSL 0x%x\n",
1351 __func__, tx_slot);
1352 printk(KERN_DEBUG "%s: Write_hfc: B2_RSL 0x%x\n",
1353 __func__, rx_slot);
1354 Write_hfc(hc, HFCPCI_B2_SSL, tx_slot);
1355 Write_hfc(hc, HFCPCI_B2_RSL, rx_slot);
1356 } else {
1357 hc->hw.conn &= 0xf8;
1358 hc->hw.conn |= 0x01;
1359 printk(KERN_DEBUG "%s: Write_hfc: B1_SSL 0x%x\n",
1360 __func__, tx_slot);
1361 printk(KERN_DEBUG "%s: Write_hfc: B1_RSL 0x%x\n",
1362 __func__, rx_slot);
1363 Write_hfc(hc, HFCPCI_B1_SSL, tx_slot);
1364 Write_hfc(hc, HFCPCI_B1_RSL, rx_slot);
1365 }
1366 }
1367 Write_hfc(hc, HFCPCI_SCTRL_E, hc->hw.sctrl_e);
1368 Write_hfc(hc, HFCPCI_INT_M1, hc->hw.int_m1);
1369 Write_hfc(hc, HFCPCI_FIFO_EN, hc->hw.fifo_en);
1370 Write_hfc(hc, HFCPCI_SCTRL, hc->hw.sctrl);
1371 Write_hfc(hc, HFCPCI_SCTRL_R, hc->hw.sctrl_r);
1372 Write_hfc(hc, HFCPCI_CTMT, hc->hw.ctmt);
1373 Write_hfc(hc, HFCPCI_CONNECT, hc->hw.conn);
1374#ifdef REVERSE_BITORDER
1375 Write_hfc(hc, HFCPCI_CIRM, hc->hw.cirm);
1376#endif
1377 return 0;
1378}
1379
1380static int
1381set_hfcpci_rxtest(struct bchannel *bch, int protocol, int chan)
1382{
1383 struct hfc_pci *hc = bch->hw;
1384
1385 if (bch->debug & DEBUG_HW_BCHANNEL)
1386 printk(KERN_DEBUG
1387 "HFCPCI bchannel test rx protocol %x-->%x ch %x-->%x\n",
1388 bch->state, protocol, bch->nr, chan);
1389 if (bch->nr != chan) {
1390 printk(KERN_DEBUG
1391 "HFCPCI rxtest wrong channel parameter %x/%x\n",
1392 bch->nr, chan);
1393 return -EINVAL;
1394 }
1395 switch (protocol) {
1396 case (ISDN_P_B_RAW):
1397 bch->state = protocol;
1398 hfcpci_clear_fifo_rx(hc, (chan & 2)?1:0);
1399 if (chan & 2) {
1400 hc->hw.sctrl_r |= SCTRL_B2_ENA;
1401 hc->hw.fifo_en |= HFCPCI_FIFOEN_B2RX;
1402 hc->hw.int_m1 |= HFCPCI_INTS_B2REC;
1403 hc->hw.ctmt |= 2;
1404 hc->hw.conn &= ~0x18;
1405#ifdef REVERSE_BITORDER
1406 hc->hw.cirm |= 0x80;
1407#endif
1408 } else {
1409 hc->hw.sctrl_r |= SCTRL_B1_ENA;
1410 hc->hw.fifo_en |= HFCPCI_FIFOEN_B1RX;
1411 hc->hw.int_m1 |= HFCPCI_INTS_B1REC;
1412 hc->hw.ctmt |= 1;
1413 hc->hw.conn &= ~0x03;
1414#ifdef REVERSE_BITORDER
1415 hc->hw.cirm |= 0x40;
1416#endif
1417 }
1418 break;
1419 case (ISDN_P_B_HDLC):
1420 bch->state = protocol;
1421 hfcpci_clear_fifo_rx(hc, (chan & 2)?1:0);
1422 if (chan & 2) {
1423 hc->hw.sctrl_r |= SCTRL_B2_ENA;
1424 hc->hw.last_bfifo_cnt[1] = 0;
1425 hc->hw.fifo_en |= HFCPCI_FIFOEN_B2RX;
1426 hc->hw.int_m1 |= HFCPCI_INTS_B2REC;
1427 hc->hw.ctmt &= ~2;
1428 hc->hw.conn &= ~0x18;
1429 } else {
1430 hc->hw.sctrl_r |= SCTRL_B1_ENA;
1431 hc->hw.last_bfifo_cnt[0] = 0;
1432 hc->hw.fifo_en |= HFCPCI_FIFOEN_B1RX;
1433 hc->hw.int_m1 |= HFCPCI_INTS_B1REC;
1434 hc->hw.ctmt &= ~1;
1435 hc->hw.conn &= ~0x03;
1436 }
1437 break;
1438 default:
1439 printk(KERN_DEBUG "prot not known %x\n", protocol);
1440 return -ENOPROTOOPT;
1441 }
1442 Write_hfc(hc, HFCPCI_INT_M1, hc->hw.int_m1);
1443 Write_hfc(hc, HFCPCI_FIFO_EN, hc->hw.fifo_en);
1444 Write_hfc(hc, HFCPCI_SCTRL_R, hc->hw.sctrl_r);
1445 Write_hfc(hc, HFCPCI_CTMT, hc->hw.ctmt);
1446 Write_hfc(hc, HFCPCI_CONNECT, hc->hw.conn);
1447#ifdef REVERSE_BITORDER
1448 Write_hfc(hc, HFCPCI_CIRM, hc->hw.cirm);
1449#endif
1450 return 0;
1451}
1452
1453static void
1454deactivate_bchannel(struct bchannel *bch)
1455{
1456 struct hfc_pci *hc = bch->hw;
1457 u_long flags;
1458
1459 spin_lock_irqsave(&hc->lock, flags);
1460 if (test_and_clear_bit(FLG_TX_NEXT, &bch->Flags)) {
1461 dev_kfree_skb(bch->next_skb);
1462 bch->next_skb = NULL;
1463 }
1464 if (bch->tx_skb) {
1465 dev_kfree_skb(bch->tx_skb);
1466 bch->tx_skb = NULL;
1467 }
1468 bch->tx_idx = 0;
1469 if (bch->rx_skb) {
1470 dev_kfree_skb(bch->rx_skb);
1471 bch->rx_skb = NULL;
1472 }
1473 mode_hfcpci(bch, bch->nr, ISDN_P_NONE);
1474 test_and_clear_bit(FLG_ACTIVE, &bch->Flags);
1475 test_and_clear_bit(FLG_TX_BUSY, &bch->Flags);
1476 spin_unlock_irqrestore(&hc->lock, flags);
1477}
1478
1479/*
1480 * Layer 1 B-channel hardware access
1481 */
1482static int
1483channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
1484{
1485 int ret = 0;
1486
1487 switch (cq->op) {
1488 case MISDN_CTRL_GETOP:
1489 cq->op = 0;
1490 break;
1491 default:
1492 printk(KERN_WARNING "%s: unknown Op %x\n", __func__, cq->op);
1493 ret = -EINVAL;
1494 break;
1495 }
1496 return ret;
1497}
1498static int
1499hfc_bctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
1500{
1501 struct bchannel *bch = container_of(ch, struct bchannel, ch);
1502 struct hfc_pci *hc = bch->hw;
1503 int ret = -EINVAL;
1504 u_long flags;
1505
1506 if (bch->debug & DEBUG_HW)
1507 printk(KERN_DEBUG "%s: cmd:%x %p\n", __func__, cmd, arg);
1508 switch (cmd) {
1509 case HW_TESTRX_RAW:
1510 spin_lock_irqsave(&hc->lock, flags);
1511 ret = set_hfcpci_rxtest(bch, ISDN_P_B_RAW, (int)(long)arg);
1512 spin_unlock_irqrestore(&hc->lock, flags);
1513 break;
1514 case HW_TESTRX_HDLC:
1515 spin_lock_irqsave(&hc->lock, flags);
1516 ret = set_hfcpci_rxtest(bch, ISDN_P_B_HDLC, (int)(long)arg);
1517 spin_unlock_irqrestore(&hc->lock, flags);
1518 break;
1519 case HW_TESTRX_OFF:
1520 spin_lock_irqsave(&hc->lock, flags);
1521 mode_hfcpci(bch, bch->nr, ISDN_P_NONE);
1522 spin_unlock_irqrestore(&hc->lock, flags);
1523 ret = 0;
1524 break;
1525 case CLOSE_CHANNEL:
1526 test_and_clear_bit(FLG_OPEN, &bch->Flags);
1527 if (test_bit(FLG_ACTIVE, &bch->Flags))
1528 deactivate_bchannel(bch);
1529 ch->protocol = ISDN_P_NONE;
1530 ch->peer = NULL;
1531 module_put(THIS_MODULE);
1532 ret = 0;
1533 break;
1534 case CONTROL_CHANNEL:
1535 ret = channel_bctrl(bch, arg);
1536 break;
1537 default:
1538 printk(KERN_WARNING "%s: unknown prim(%x)\n",
1539 __func__, cmd);
1540 }
1541 return ret;
1542}
1543
1544/*
1545 * Layer2 -> Layer 1 Dchannel data
1546 */
1547static int
1548hfcpci_l2l1D(struct mISDNchannel *ch, struct sk_buff *skb)
1549{
1550 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
1551 struct dchannel *dch = container_of(dev, struct dchannel, dev);
1552 struct hfc_pci *hc = dch->hw;
1553 int ret = -EINVAL;
1554 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1555 unsigned int id;
1556 u_long flags;
1557
1558 switch (hh->prim) {
1559 case PH_DATA_REQ:
1560 spin_lock_irqsave(&hc->lock, flags);
1561 ret = dchannel_senddata(dch, skb);
1562 if (ret > 0) { /* direct TX */
1563 id = hh->id; /* skb can be freed */
1564 hfcpci_fill_dfifo(dch->hw);
1565 ret = 0;
1566 spin_unlock_irqrestore(&hc->lock, flags);
1567 queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
1568 } else
1569 spin_unlock_irqrestore(&hc->lock, flags);
1570 return ret;
1571 case PH_ACTIVATE_REQ:
1572 spin_lock_irqsave(&hc->lock, flags);
1573 if (hc->hw.protocol == ISDN_P_NT_S0) {
1574 ret = 0;
1575 if (test_bit(HFC_CFG_MASTER, &hc->cfg))
1576 hc->hw.mst_m |= HFCPCI_MASTER;
1577 Write_hfc(hc, HFCPCI_MST_MODE, hc->hw.mst_m);
1578 if (test_bit(FLG_ACTIVE, &dch->Flags)) {
1579 spin_unlock_irqrestore(&hc->lock, flags);
1580 _queue_data(&dch->dev.D, PH_ACTIVATE_IND,
1581 MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
1582 break;
1583 }
1584 test_and_set_bit(FLG_L2_ACTIVATED, &dch->Flags);
1585 Write_hfc(hc, HFCPCI_STATES, HFCPCI_ACTIVATE |
1586 HFCPCI_DO_ACTION | 1);
1587 } else
1588 ret = l1_event(dch->l1, hh->prim);
1589 spin_unlock_irqrestore(&hc->lock, flags);
1590 break;
1591 case PH_DEACTIVATE_REQ:
1592 test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
1593 spin_lock_irqsave(&hc->lock, flags);
1594 if (hc->hw.protocol == ISDN_P_NT_S0) {
1595 /* prepare deactivation */
1596 Write_hfc(hc, HFCPCI_STATES, 0x40);
1597 skb_queue_purge(&dch->squeue);
1598 if (dch->tx_skb) {
1599 dev_kfree_skb(dch->tx_skb);
1600 dch->tx_skb = NULL;
1601 }
1602 dch->tx_idx = 0;
1603 if (dch->rx_skb) {
1604 dev_kfree_skb(dch->rx_skb);
1605 dch->rx_skb = NULL;
1606 }
1607 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
1608 if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
1609 del_timer(&dch->timer);
1610#ifdef FIXME
1611 if (test_and_clear_bit(FLG_L1_BUSY, &dch->Flags))
1612 dchannel_sched_event(&hc->dch, D_CLEARBUSY);
1613#endif
1614 hc->hw.mst_m &= ~HFCPCI_MASTER;
1615 Write_hfc(hc, HFCPCI_MST_MODE, hc->hw.mst_m);
1616 ret = 0;
1617 } else {
1618 ret = l1_event(dch->l1, hh->prim);
1619 }
1620 spin_unlock_irqrestore(&hc->lock, flags);
1621 break;
1622 }
1623 if (!ret)
1624 dev_kfree_skb(skb);
1625 return ret;
1626}
1627
1628/*
1629 * Layer2 -> Layer 1 Bchannel data
1630 */
1631static int
1632hfcpci_l2l1B(struct mISDNchannel *ch, struct sk_buff *skb)
1633{
1634 struct bchannel *bch = container_of(ch, struct bchannel, ch);
1635 struct hfc_pci *hc = bch->hw;
1636 int ret = -EINVAL;
1637 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1638 unsigned int id;
1639 u_long flags;
1640
1641 switch (hh->prim) {
1642 case PH_DATA_REQ:
1643 spin_lock_irqsave(&hc->lock, flags);
1644 ret = bchannel_senddata(bch, skb);
1645 if (ret > 0) { /* direct TX */
1646 id = hh->id; /* skb can be freed */
1647 hfcpci_fill_fifo(bch);
1648 ret = 0;
1649 spin_unlock_irqrestore(&hc->lock, flags);
1650 if (!test_bit(FLG_TRANSPARENT, &bch->Flags))
1651 queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
1652 } else
1653 spin_unlock_irqrestore(&hc->lock, flags);
1654 return ret;
1655 case PH_ACTIVATE_REQ:
1656 spin_lock_irqsave(&hc->lock, flags);
1657 if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags))
1658 ret = mode_hfcpci(bch, bch->nr, ch->protocol);
1659 else
1660 ret = 0;
1661 spin_unlock_irqrestore(&hc->lock, flags);
1662 if (!ret)
1663 _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0,
1664 NULL, GFP_KERNEL);
1665 break;
1666 case PH_DEACTIVATE_REQ:
1667 deactivate_bchannel(bch);
1668 _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0,
1669 NULL, GFP_KERNEL);
1670 ret = 0;
1671 break;
1672 }
1673 if (!ret)
1674 dev_kfree_skb(skb);
1675 return ret;
1676}
1677
1678/*
1679 * called for card init message
1680 */
1681
1682void
1683inithfcpci(struct hfc_pci *hc)
1684{
1685 printk(KERN_DEBUG "inithfcpci: entered\n");
1686 hc->dch.timer.function = (void *) hfcpci_dbusy_timer;
1687 hc->dch.timer.data = (long) &hc->dch;
1688 init_timer(&hc->dch.timer);
1689 hc->chanlimit = 2;
1690 mode_hfcpci(&hc->bch[0], 1, -1);
1691 mode_hfcpci(&hc->bch[1], 2, -1);
1692}
1693
1694
1695static int
1696init_card(struct hfc_pci *hc)
1697{
1698 int cnt = 3;
1699 u_long flags;
1700
1701 printk(KERN_DEBUG "init_card: entered\n");
1702
1703
1704 spin_lock_irqsave(&hc->lock, flags);
1705 disable_hwirq(hc);
1706 spin_unlock_irqrestore(&hc->lock, flags);
1707 if (request_irq(hc->irq, hfcpci_int, IRQF_SHARED, "HFC PCI", hc)) {
1708 printk(KERN_WARNING
1709 "mISDN: couldn't get interrupt %d\n", hc->irq);
1710 return -EIO;
1711 }
1712 spin_lock_irqsave(&hc->lock, flags);
1713 reset_hfcpci(hc);
1714 while (cnt) {
1715 inithfcpci(hc);
1716 /*
1717 * Finally enable IRQ output
1718 * this is only allowed, if an IRQ routine is allready
1719 * established for this HFC, so don't do that earlier
1720 */
1721 enable_hwirq(hc);
1722 spin_unlock_irqrestore(&hc->lock, flags);
1723 /* Timeout 80ms */
1724 current->state = TASK_UNINTERRUPTIBLE;
1725 schedule_timeout((80*HZ)/1000);
1726 printk(KERN_INFO "HFC PCI: IRQ %d count %d\n",
1727 hc->irq, hc->irqcnt);
1728 /* now switch timer interrupt off */
1729 spin_lock_irqsave(&hc->lock, flags);
1730 hc->hw.int_m1 &= ~HFCPCI_INTS_TIMER;
1731 Write_hfc(hc, HFCPCI_INT_M1, hc->hw.int_m1);
1732 /* reinit mode reg */
1733 Write_hfc(hc, HFCPCI_MST_MODE, hc->hw.mst_m);
1734 if (!hc->irqcnt) {
1735 printk(KERN_WARNING
1736 "HFC PCI: IRQ(%d) getting no interrupts "
1737 "during init %d\n", hc->irq, 4 - cnt);
1738 if (cnt == 1) {
1739 spin_unlock_irqrestore(&hc->lock, flags);
1740 return -EIO;
1741 } else {
1742 reset_hfcpci(hc);
1743 cnt--;
1744 }
1745 } else {
1746 spin_unlock_irqrestore(&hc->lock, flags);
1747 hc->initdone = 1;
1748 return 0;
1749 }
1750 }
1751 disable_hwirq(hc);
1752 spin_unlock_irqrestore(&hc->lock, flags);
1753 free_irq(hc->irq, hc);
1754 return -EIO;
1755}
1756
1757static int
1758channel_ctrl(struct hfc_pci *hc, struct mISDN_ctrl_req *cq)
1759{
1760 int ret = 0;
1761 u_char slot;
1762
1763 switch (cq->op) {
1764 case MISDN_CTRL_GETOP:
1765 cq->op = MISDN_CTRL_LOOP | MISDN_CTRL_CONNECT |
1766 MISDN_CTRL_DISCONNECT;
1767 break;
1768 case MISDN_CTRL_LOOP:
1769 /* channel 0 disabled loop */
1770 if (cq->channel < 0 || cq->channel > 2) {
1771 ret = -EINVAL;
1772 break;
1773 }
1774 if (cq->channel & 1) {
1775 if (test_bit(HFC_CFG_SW_DD_DU, &hc->cfg))
1776 slot = 0xC0;
1777 else
1778 slot = 0x80;
1779 printk(KERN_DEBUG "%s: Write_hfc: B1_SSL/RSL 0x%x\n",
1780 __func__, slot);
1781 Write_hfc(hc, HFCPCI_B1_SSL, slot);
1782 Write_hfc(hc, HFCPCI_B1_RSL, slot);
1783 hc->hw.conn = (hc->hw.conn & ~7) | 6;
1784 Write_hfc(hc, HFCPCI_CONNECT, hc->hw.conn);
1785 }
1786 if (cq->channel & 2) {
1787 if (test_bit(HFC_CFG_SW_DD_DU, &hc->cfg))
1788 slot = 0xC1;
1789 else
1790 slot = 0x81;
1791 printk(KERN_DEBUG "%s: Write_hfc: B2_SSL/RSL 0x%x\n",
1792 __func__, slot);
1793 Write_hfc(hc, HFCPCI_B2_SSL, slot);
1794 Write_hfc(hc, HFCPCI_B2_RSL, slot);
1795 hc->hw.conn = (hc->hw.conn & ~0x38) | 0x30;
1796 Write_hfc(hc, HFCPCI_CONNECT, hc->hw.conn);
1797 }
1798 if (cq->channel & 3)
1799 hc->hw.trm |= 0x80; /* enable IOM-loop */
1800 else {
1801 hc->hw.conn = (hc->hw.conn & ~0x3f) | 0x09;
1802 Write_hfc(hc, HFCPCI_CONNECT, hc->hw.conn);
1803 hc->hw.trm &= 0x7f; /* disable IOM-loop */
1804 }
1805 Write_hfc(hc, HFCPCI_TRM, hc->hw.trm);
1806 break;
1807 case MISDN_CTRL_CONNECT:
1808 if (cq->channel == cq->p1) {
1809 ret = -EINVAL;
1810 break;
1811 }
1812 if (cq->channel < 1 || cq->channel > 2 ||
1813 cq->p1 < 1 || cq->p1 > 2) {
1814 ret = -EINVAL;
1815 break;
1816 }
1817 if (test_bit(HFC_CFG_SW_DD_DU, &hc->cfg))
1818 slot = 0xC0;
1819 else
1820 slot = 0x80;
1821 printk(KERN_DEBUG "%s: Write_hfc: B1_SSL/RSL 0x%x\n",
1822 __func__, slot);
1823 Write_hfc(hc, HFCPCI_B1_SSL, slot);
1824 Write_hfc(hc, HFCPCI_B2_RSL, slot);
1825 if (test_bit(HFC_CFG_SW_DD_DU, &hc->cfg))
1826 slot = 0xC1;
1827 else
1828 slot = 0x81;
1829 printk(KERN_DEBUG "%s: Write_hfc: B2_SSL/RSL 0x%x\n",
1830 __func__, slot);
1831 Write_hfc(hc, HFCPCI_B2_SSL, slot);
1832 Write_hfc(hc, HFCPCI_B1_RSL, slot);
1833 hc->hw.conn = (hc->hw.conn & ~0x3f) | 0x36;
1834 Write_hfc(hc, HFCPCI_CONNECT, hc->hw.conn);
1835 hc->hw.trm |= 0x80;
1836 Write_hfc(hc, HFCPCI_TRM, hc->hw.trm);
1837 break;
1838 case MISDN_CTRL_DISCONNECT:
1839 hc->hw.conn = (hc->hw.conn & ~0x3f) | 0x09;
1840 Write_hfc(hc, HFCPCI_CONNECT, hc->hw.conn);
1841 hc->hw.trm &= 0x7f; /* disable IOM-loop */
1842 break;
1843 default:
1844 printk(KERN_WARNING "%s: unknown Op %x\n",
1845 __func__, cq->op);
1846 ret = -EINVAL;
1847 break;
1848 }
1849 return ret;
1850}
1851
1852static int
1853open_dchannel(struct hfc_pci *hc, struct mISDNchannel *ch,
1854 struct channel_req *rq)
1855{
1856 int err = 0;
1857
1858 if (debug & DEBUG_HW_OPEN)
1859 printk(KERN_DEBUG "%s: dev(%d) open from %p\n", __func__,
1860 hc->dch.dev.id, __builtin_return_address(0));
1861 if (rq->protocol == ISDN_P_NONE)
1862 return -EINVAL;
1863 if (!hc->initdone) {
1864 if (rq->protocol == ISDN_P_TE_S0) {
1865 err = create_l1(&hc->dch, hfc_l1callback);
1866 if (err)
1867 return err;
1868 }
1869 hc->hw.protocol = rq->protocol;
1870 ch->protocol = rq->protocol;
1871 err = init_card(hc);
1872 if (err)
1873 return err;
1874 } else {
1875 if (rq->protocol != ch->protocol) {
1876 if (hc->hw.protocol == ISDN_P_TE_S0)
1877 l1_event(hc->dch.l1, CLOSE_CHANNEL);
1878 hc->hw.protocol = rq->protocol;
1879 ch->protocol = rq->protocol;
1880 hfcpci_setmode(hc);
1881 }
1882 }
1883
1884 if (((ch->protocol == ISDN_P_NT_S0) && (hc->dch.state == 3)) ||
1885 ((ch->protocol == ISDN_P_TE_S0) && (hc->dch.state == 7))) {
1886 _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY,
1887 0, NULL, GFP_KERNEL);
1888 }
1889 rq->ch = ch;
1890 if (!try_module_get(THIS_MODULE))
1891 printk(KERN_WARNING "%s:cannot get module\n", __func__);
1892 return 0;
1893}
1894
1895static int
1896open_bchannel(struct hfc_pci *hc, struct channel_req *rq)
1897{
1898 struct bchannel *bch;
1899
1900 if (rq->adr.channel > 2)
1901 return -EINVAL;
1902 if (rq->protocol == ISDN_P_NONE)
1903 return -EINVAL;
1904 bch = &hc->bch[rq->adr.channel - 1];
1905 if (test_and_set_bit(FLG_OPEN, &bch->Flags))
1906 return -EBUSY; /* b-channel can be only open once */
1907 bch->ch.protocol = rq->protocol;
1908 rq->ch = &bch->ch; /* TODO: E-channel */
1909 if (!try_module_get(THIS_MODULE))
1910 printk(KERN_WARNING "%s:cannot get module\n", __func__);
1911 return 0;
1912}
1913
1914/*
1915 * device control function
1916 */
1917static int
1918hfc_dctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
1919{
1920 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
1921 struct dchannel *dch = container_of(dev, struct dchannel, dev);
1922 struct hfc_pci *hc = dch->hw;
1923 struct channel_req *rq;
1924 int err = 0;
1925
1926 if (dch->debug & DEBUG_HW)
1927 printk(KERN_DEBUG "%s: cmd:%x %p\n",
1928 __func__, cmd, arg);
1929 switch (cmd) {
1930 case OPEN_CHANNEL:
1931 rq = arg;
1932 if (rq->adr.channel == 0)
1933 err = open_dchannel(hc, ch, rq);
1934 else
1935 err = open_bchannel(hc, rq);
1936 break;
1937 case CLOSE_CHANNEL:
1938 if (debug & DEBUG_HW_OPEN)
1939 printk(KERN_DEBUG "%s: dev(%d) close from %p\n",
1940 __func__, hc->dch.dev.id,
1941 __builtin_return_address(0));
1942 module_put(THIS_MODULE);
1943 break;
1944 case CONTROL_CHANNEL:
1945 err = channel_ctrl(hc, arg);
1946 break;
1947 default:
1948 if (dch->debug & DEBUG_HW)
1949 printk(KERN_DEBUG "%s: unknown command %x\n",
1950 __func__, cmd);
1951 return -EINVAL;
1952 }
1953 return err;
1954}
1955
1956static int
1957setup_hw(struct hfc_pci *hc)
1958{
1959 void *buffer;
1960
1961 printk(KERN_INFO "mISDN: HFC-PCI driver %s\n", hfcpci_revision);
1962 hc->hw.cirm = 0;
1963 hc->dch.state = 0;
1964 pci_set_master(hc->pdev);
1965 if (!hc->irq) {
1966 printk(KERN_WARNING "HFC-PCI: No IRQ for PCI card found\n");
1967 return 1;
1968 }
1969 hc->hw.pci_io = (char *)(ulong)hc->pdev->resource[1].start;
1970
1971 if (!hc->hw.pci_io) {
1972 printk(KERN_WARNING "HFC-PCI: No IO-Mem for PCI card found\n");
1973 return 1;
1974 }
1975 /* Allocate memory for FIFOS */
1976 /* the memory needs to be on a 32k boundary within the first 4G */
1977 pci_set_dma_mask(hc->pdev, 0xFFFF8000);
1978 buffer = pci_alloc_consistent(hc->pdev, 0x8000, &hc->hw.dmahandle);
1979 /* We silently assume the address is okay if nonzero */
1980 if (!buffer) {
1981 printk(KERN_WARNING
1982 "HFC-PCI: Error allocating memory for FIFO!\n");
1983 return 1;
1984 }
1985 hc->hw.fifos = buffer;
1986 pci_write_config_dword(hc->pdev, 0x80, hc->hw.dmahandle);
1987 hc->hw.pci_io = ioremap((ulong) hc->hw.pci_io, 256);
1988 printk(KERN_INFO
1989 "HFC-PCI: defined at mem %#lx fifo %#lx(%#lx) IRQ %d HZ %d\n",
1990 (u_long) hc->hw.pci_io, (u_long) hc->hw.fifos,
1991 (u_long) virt_to_bus(hc->hw.fifos),
1992 hc->irq, HZ);
1993 /* enable memory mapped ports, disable busmaster */
1994 pci_write_config_word(hc->pdev, PCI_COMMAND, PCI_ENA_MEMIO);
1995 hc->hw.int_m2 = 0;
1996 disable_hwirq(hc);
1997 hc->hw.int_m1 = 0;
1998 Write_hfc(hc, HFCPCI_INT_M1, hc->hw.int_m1);
1999 /* At this point the needed PCI config is done */
2000 /* fifos are still not enabled */
2001 hc->hw.timer.function = (void *) hfcpci_Timer;
2002 hc->hw.timer.data = (long) hc;
2003 init_timer(&hc->hw.timer);
2004 /* default PCM master */
2005 test_and_set_bit(HFC_CFG_MASTER, &hc->cfg);
2006 return 0;
2007}
2008
2009static void
2010release_card(struct hfc_pci *hc) {
2011 u_long flags;
2012
2013 spin_lock_irqsave(&hc->lock, flags);
2014 hc->hw.int_m2 = 0; /* interrupt output off ! */
2015 disable_hwirq(hc);
2016 mode_hfcpci(&hc->bch[0], 1, ISDN_P_NONE);
2017 mode_hfcpci(&hc->bch[1], 2, ISDN_P_NONE);
2018 if (hc->dch.timer.function != NULL) {
2019 del_timer(&hc->dch.timer);
2020 hc->dch.timer.function = NULL;
2021 }
2022 spin_unlock_irqrestore(&hc->lock, flags);
2023 if (hc->hw.protocol == ISDN_P_TE_S0)
2024 l1_event(hc->dch.l1, CLOSE_CHANNEL);
2025 if (hc->initdone)
2026 free_irq(hc->irq, hc);
2027 release_io_hfcpci(hc); /* must release after free_irq! */
2028 mISDN_unregister_device(&hc->dch.dev);
2029 mISDN_freebchannel(&hc->bch[1]);
2030 mISDN_freebchannel(&hc->bch[0]);
2031 mISDN_freedchannel(&hc->dch);
2032 list_del(&hc->list);
2033 pci_set_drvdata(hc->pdev, NULL);
2034 kfree(hc);
2035}
2036
2037static int
2038setup_card(struct hfc_pci *card)
2039{
2040 int err = -EINVAL;
2041 u_int i;
2042 u_long flags;
2043 char name[MISDN_MAX_IDLEN];
2044
2045 if (HFC_cnt >= MAX_CARDS)
2046 return -EINVAL; /* maybe better value */
2047
2048 card->dch.debug = debug;
2049 spin_lock_init(&card->lock);
2050 mISDN_initdchannel(&card->dch, MAX_DFRAME_LEN_L1, ph_state);
2051 card->dch.hw = card;
2052 card->dch.dev.Dprotocols = (1 << ISDN_P_TE_S0) | (1 << ISDN_P_NT_S0);
2053 card->dch.dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
2054 (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
2055 card->dch.dev.D.send = hfcpci_l2l1D;
2056 card->dch.dev.D.ctrl = hfc_dctrl;
2057 card->dch.dev.nrbchan = 2;
2058 for (i = 0; i < 2; i++) {
2059 card->bch[i].nr = i + 1;
2060 test_and_set_bit(i + 1, &card->dch.dev.channelmap[0]);
2061 card->bch[i].debug = debug;
2062 mISDN_initbchannel(&card->bch[i], MAX_DATA_MEM);
2063 card->bch[i].hw = card;
2064 card->bch[i].ch.send = hfcpci_l2l1B;
2065 card->bch[i].ch.ctrl = hfc_bctrl;
2066 card->bch[i].ch.nr = i + 1;
2067 list_add(&card->bch[i].ch.list, &card->dch.dev.bchannels);
2068 }
2069 err = setup_hw(card);
2070 if (err)
2071 goto error;
2072 snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-pci.%d", HFC_cnt + 1);
2073 err = mISDN_register_device(&card->dch.dev, name);
2074 if (err)
2075 goto error;
2076 HFC_cnt++;
2077 write_lock_irqsave(&HFClock, flags);
2078 list_add_tail(&card->list, &HFClist);
2079 write_unlock_irqrestore(&HFClock, flags);
2080 printk(KERN_INFO "HFC %d cards installed\n", HFC_cnt);
2081 return 0;
2082error:
2083 mISDN_freebchannel(&card->bch[1]);
2084 mISDN_freebchannel(&card->bch[0]);
2085 mISDN_freedchannel(&card->dch);
2086 kfree(card);
2087 return err;
2088}
2089
2090/* private data in the PCI devices list */
2091struct _hfc_map {
2092 u_int subtype;
2093 u_int flag;
2094 char *name;
2095};
2096
2097static const struct _hfc_map hfc_map[] =
2098{
2099 {HFC_CCD_2BD0, 0, "CCD/Billion/Asuscom 2BD0"},
2100 {HFC_CCD_B000, 0, "Billion B000"},
2101 {HFC_CCD_B006, 0, "Billion B006"},
2102 {HFC_CCD_B007, 0, "Billion B007"},
2103 {HFC_CCD_B008, 0, "Billion B008"},
2104 {HFC_CCD_B009, 0, "Billion B009"},
2105 {HFC_CCD_B00A, 0, "Billion B00A"},
2106 {HFC_CCD_B00B, 0, "Billion B00B"},
2107 {HFC_CCD_B00C, 0, "Billion B00C"},
2108 {HFC_CCD_B100, 0, "Seyeon B100"},
2109 {HFC_CCD_B700, 0, "Primux II S0 B700"},
2110 {HFC_CCD_B701, 0, "Primux II S0 NT B701"},
2111 {HFC_ABOCOM_2BD1, 0, "Abocom/Magitek 2BD1"},
2112 {HFC_ASUS_0675, 0, "Asuscom/Askey 675"},
2113 {HFC_BERKOM_TCONCEPT, 0, "German telekom T-Concept"},
2114 {HFC_BERKOM_A1T, 0, "German telekom A1T"},
2115 {HFC_ANIGMA_MC145575, 0, "Motorola MC145575"},
2116 {HFC_ZOLTRIX_2BD0, 0, "Zoltrix 2BD0"},
2117 {HFC_DIGI_DF_M_IOM2_E, 0,
2118 "Digi International DataFire Micro V IOM2 (Europe)"},
2119 {HFC_DIGI_DF_M_E, 0,
2120 "Digi International DataFire Micro V (Europe)"},
2121 {HFC_DIGI_DF_M_IOM2_A, 0,
2122 "Digi International DataFire Micro V IOM2 (North America)"},
2123 {HFC_DIGI_DF_M_A, 0,
2124 "Digi International DataFire Micro V (North America)"},
2125 {HFC_SITECOM_DC105V2, 0, "Sitecom Connectivity DC-105 ISDN TA"},
2126 {},
2127};
2128
2129static struct pci_device_id hfc_ids[] =
2130{
2131 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_2BD0,
2132 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[0]},
2133 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B000,
2134 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[1]},
2135 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B006,
2136 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[2]},
2137 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B007,
2138 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[3]},
2139 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B008,
2140 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[4]},
2141 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B009,
2142 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[5]},
2143 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00A,
2144 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[6]},
2145 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00B,
2146 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[7]},
2147 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00C,
2148 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[8]},
2149 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B100,
2150 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[9]},
2151 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B700,
2152 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[10]},
2153 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B701,
2154 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[11]},
2155 {PCI_VENDOR_ID_ABOCOM, PCI_DEVICE_ID_ABOCOM_2BD1,
2156 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[12]},
2157 {PCI_VENDOR_ID_ASUSTEK, PCI_DEVICE_ID_ASUSTEK_0675,
2158 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[13]},
2159 {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_T_CONCEPT,
2160 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[14]},
2161 {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_A1T,
2162 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[15]},
2163 {PCI_VENDOR_ID_ANIGMA, PCI_DEVICE_ID_ANIGMA_MC145575,
2164 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[16]},
2165 {PCI_VENDOR_ID_ZOLTRIX, PCI_DEVICE_ID_ZOLTRIX_2BD0,
2166 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[17]},
2167 {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E,
2168 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[18]},
2169 {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_E,
2170 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[19]},
2171 {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A,
2172 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[20]},
2173 {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_A,
2174 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[21]},
2175 {PCI_VENDOR_ID_SITECOM, PCI_DEVICE_ID_SITECOM_DC105V2,
2176 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) &hfc_map[22]},
2177 {},
2178};
2179
2180static int __devinit
2181hfc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2182{
2183 int err = -ENOMEM;
2184 struct hfc_pci *card;
2185 struct _hfc_map *m = (struct _hfc_map *)ent->driver_data;
2186
2187 card = kzalloc(sizeof(struct hfc_pci), GFP_ATOMIC);
2188 if (!card) {
2189 printk(KERN_ERR "No kmem for HFC card\n");
2190 return err;
2191 }
2192 card->pdev = pdev;
2193 card->subtype = m->subtype;
2194 err = pci_enable_device(pdev);
2195 if (err) {
2196 kfree(card);
2197 return err;
2198 }
2199
2200 printk(KERN_INFO "mISDN_hfcpci: found adapter %s at %s\n",
2201 m->name, pci_name(pdev));
2202
2203 card->irq = pdev->irq;
2204 pci_set_drvdata(pdev, card);
2205 err = setup_card(card);
2206 if (err)
2207 pci_set_drvdata(pdev, NULL);
2208 return err;
2209}
2210
2211static void __devexit
2212hfc_remove_pci(struct pci_dev *pdev)
2213{
2214 struct hfc_pci *card = pci_get_drvdata(pdev);
2215 u_long flags;
2216
2217 if (card) {
2218 write_lock_irqsave(&HFClock, flags);
2219 release_card(card);
2220 write_unlock_irqrestore(&HFClock, flags);
2221 } else
2222 if (debug)
2223 printk(KERN_WARNING "%s: drvdata allready removed\n",
2224 __func__);
2225}
2226
2227
2228static struct pci_driver hfc_driver = {
2229 .name = "hfcpci",
2230 .probe = hfc_probe,
2231 .remove = __devexit_p(hfc_remove_pci),
2232 .id_table = hfc_ids,
2233};
2234
2235static int __init
2236HFC_init(void)
2237{
2238 int err;
2239
2240 err = pci_register_driver(&hfc_driver);
2241 return err;
2242}
2243
2244static void __exit
2245HFC_cleanup(void)
2246{
2247 struct hfc_pci *card, *next;
2248
2249 list_for_each_entry_safe(card, next, &HFClist, list) {
2250 release_card(card);
2251 }
2252 pci_unregister_driver(&hfc_driver);
2253}
2254
2255module_init(HFC_init);
2256module_exit(HFC_cleanup);
diff --git a/drivers/isdn/hisax/hisax_fcpcipnp.c b/drivers/isdn/hisax/hisax_fcpcipnp.c
index c0b4db2f8364..1925118122f8 100644
--- a/drivers/isdn/hisax/hisax_fcpcipnp.c
+++ b/drivers/isdn/hisax/hisax_fcpcipnp.c
@@ -974,8 +974,6 @@ static struct pnp_driver fcpnp_driver = {
974 .remove = __devexit_p(fcpnp_remove), 974 .remove = __devexit_p(fcpnp_remove),
975 .id_table = fcpnp_ids, 975 .id_table = fcpnp_ids,
976}; 976};
977#else
978static struct pnp_driver fcpnp_driver;
979#endif 977#endif
980 978
981static void __devexit fcpci_remove(struct pci_dev *pdev) 979static void __devexit fcpci_remove(struct pci_dev *pdev)
diff --git a/drivers/isdn/hisax/st5481.h b/drivers/isdn/hisax/st5481.h
index 2044e7173ab4..cff7a6354334 100644
--- a/drivers/isdn/hisax/st5481.h
+++ b/drivers/isdn/hisax/st5481.h
@@ -220,7 +220,7 @@ enum {
220#define ERR(format, arg...) \ 220#define ERR(format, arg...) \
221printk(KERN_ERR "%s:%s: " format "\n" , __FILE__, __func__ , ## arg) 221printk(KERN_ERR "%s:%s: " format "\n" , __FILE__, __func__ , ## arg)
222 222
223#define WARN(format, arg...) \ 223#define WARNING(format, arg...) \
224printk(KERN_WARNING "%s:%s: " format "\n" , __FILE__, __func__ , ## arg) 224printk(KERN_WARNING "%s:%s: " format "\n" , __FILE__, __func__ , ## arg)
225 225
226#define INFO(format, arg...) \ 226#define INFO(format, arg...) \
@@ -412,7 +412,7 @@ struct st5481_adapter {
412({ \ 412({ \
413 int status; \ 413 int status; \
414 if ((status = usb_submit_urb(urb, mem_flags)) < 0) { \ 414 if ((status = usb_submit_urb(urb, mem_flags)) < 0) { \
415 WARN("usb_submit_urb failed,status=%d", status); \ 415 WARNING("usb_submit_urb failed,status=%d", status); \
416 } \ 416 } \
417 status; \ 417 status; \
418}) 418})
diff --git a/drivers/isdn/hisax/st5481_b.c b/drivers/isdn/hisax/st5481_b.c
index fa64115cd7c7..0074b600a0ef 100644
--- a/drivers/isdn/hisax/st5481_b.c
+++ b/drivers/isdn/hisax/st5481_b.c
@@ -180,7 +180,7 @@ static void usb_b_out_complete(struct urb *urb)
180 DBG(4,"urb killed status %d", urb->status); 180 DBG(4,"urb killed status %d", urb->status);
181 return; // Give up 181 return; // Give up
182 default: 182 default:
183 WARN("urb status %d",urb->status); 183 WARNING("urb status %d",urb->status);
184 if (b_out->busy == 0) { 184 if (b_out->busy == 0) {
185 st5481_usb_pipe_reset(adapter, (bcs->channel+1)*2 | USB_DIR_OUT, NULL, NULL); 185 st5481_usb_pipe_reset(adapter, (bcs->channel+1)*2 | USB_DIR_OUT, NULL, NULL);
186 } 186 }
@@ -372,6 +372,6 @@ void st5481_b_l2l1(struct hisax_if *ifc, int pr, void *arg)
372 B_L1L2(bcs, PH_DEACTIVATE | INDICATION, NULL); 372 B_L1L2(bcs, PH_DEACTIVATE | INDICATION, NULL);
373 break; 373 break;
374 default: 374 default:
375 WARN("pr %#x\n", pr); 375 WARNING("pr %#x\n", pr);
376 } 376 }
377} 377}
diff --git a/drivers/isdn/hisax/st5481_d.c b/drivers/isdn/hisax/st5481_d.c
index b8c4855cc889..077991c1cd05 100644
--- a/drivers/isdn/hisax/st5481_d.c
+++ b/drivers/isdn/hisax/st5481_d.c
@@ -389,7 +389,7 @@ static void usb_d_out_complete(struct urb *urb)
389 DBG(1,"urb killed status %d", urb->status); 389 DBG(1,"urb killed status %d", urb->status);
390 break; 390 break;
391 default: 391 default:
392 WARN("urb status %d",urb->status); 392 WARNING("urb status %d",urb->status);
393 if (d_out->busy == 0) { 393 if (d_out->busy == 0) {
394 st5481_usb_pipe_reset(adapter, EP_D_OUT | USB_DIR_OUT, fifo_reseted, adapter); 394 st5481_usb_pipe_reset(adapter, EP_D_OUT | USB_DIR_OUT, fifo_reseted, adapter);
395 } 395 }
@@ -420,7 +420,7 @@ static void dout_start_xmit(struct FsmInst *fsm, int event, void *arg)
420 isdnhdlc_out_init(&d_out->hdlc_state, 1, 0); 420 isdnhdlc_out_init(&d_out->hdlc_state, 1, 0);
421 421
422 if (test_and_set_bit(buf_nr, &d_out->busy)) { 422 if (test_and_set_bit(buf_nr, &d_out->busy)) {
423 WARN("ep %d urb %d busy %#lx", EP_D_OUT, buf_nr, d_out->busy); 423 WARNING("ep %d urb %d busy %#lx", EP_D_OUT, buf_nr, d_out->busy);
424 return; 424 return;
425 } 425 }
426 urb = d_out->urb[buf_nr]; 426 urb = d_out->urb[buf_nr];
@@ -601,7 +601,7 @@ void st5481_d_l2l1(struct hisax_if *hisax_d_if, int pr, void *arg)
601 FsmEvent(&adapter->d_out.fsm, EV_DOUT_START_XMIT, NULL); 601 FsmEvent(&adapter->d_out.fsm, EV_DOUT_START_XMIT, NULL);
602 break; 602 break;
603 default: 603 default:
604 WARN("pr %#x\n", pr); 604 WARNING("pr %#x\n", pr);
605 break; 605 break;
606 } 606 }
607} 607}
diff --git a/drivers/isdn/hisax/st5481_usb.c b/drivers/isdn/hisax/st5481_usb.c
index 427a8b0520f5..ec3c0e507669 100644
--- a/drivers/isdn/hisax/st5481_usb.c
+++ b/drivers/isdn/hisax/st5481_usb.c
@@ -66,7 +66,7 @@ static void usb_ctrl_msg(struct st5481_adapter *adapter,
66 struct ctrl_msg *ctrl_msg; 66 struct ctrl_msg *ctrl_msg;
67 67
68 if ((w_index = fifo_add(&ctrl->msg_fifo.f)) < 0) { 68 if ((w_index = fifo_add(&ctrl->msg_fifo.f)) < 0) {
69 WARN("control msg FIFO full"); 69 WARNING("control msg FIFO full");
70 return; 70 return;
71 } 71 }
72 ctrl_msg = &ctrl->msg_fifo.data[w_index]; 72 ctrl_msg = &ctrl->msg_fifo.data[w_index];
@@ -139,7 +139,7 @@ static void usb_ctrl_complete(struct urb *urb)
139 DBG(1,"urb killed status %d", urb->status); 139 DBG(1,"urb killed status %d", urb->status);
140 return; // Give up 140 return; // Give up
141 default: 141 default:
142 WARN("urb status %d",urb->status); 142 WARNING("urb status %d",urb->status);
143 break; 143 break;
144 } 144 }
145 } 145 }
@@ -198,7 +198,7 @@ static void usb_int_complete(struct urb *urb)
198 DBG(2, "urb shutting down with status: %d", urb->status); 198 DBG(2, "urb shutting down with status: %d", urb->status);
199 return; 199 return;
200 default: 200 default:
201 WARN("nonzero urb status received: %d", urb->status); 201 WARNING("nonzero urb status received: %d", urb->status);
202 goto exit; 202 goto exit;
203 } 203 }
204 204
@@ -235,7 +235,7 @@ static void usb_int_complete(struct urb *urb)
235exit: 235exit:
236 status = usb_submit_urb (urb, GFP_ATOMIC); 236 status = usb_submit_urb (urb, GFP_ATOMIC);
237 if (status) 237 if (status)
238 WARN("usb_submit_urb failed with result %d", status); 238 WARNING("usb_submit_urb failed with result %d", status);
239} 239}
240 240
241/* ====================================================================== 241/* ======================================================================
@@ -257,7 +257,7 @@ int st5481_setup_usb(struct st5481_adapter *adapter)
257 DBG(2,""); 257 DBG(2,"");
258 258
259 if ((status = usb_reset_configuration (dev)) < 0) { 259 if ((status = usb_reset_configuration (dev)) < 0) {
260 WARN("reset_configuration failed,status=%d",status); 260 WARNING("reset_configuration failed,status=%d",status);
261 return status; 261 return status;
262 } 262 }
263 263
@@ -269,7 +269,7 @@ int st5481_setup_usb(struct st5481_adapter *adapter)
269 269
270 // Check if the config is sane 270 // Check if the config is sane
271 if ( altsetting->desc.bNumEndpoints != 7 ) { 271 if ( altsetting->desc.bNumEndpoints != 7 ) {
272 WARN("expecting 7 got %d endpoints!", altsetting->desc.bNumEndpoints); 272 WARNING("expecting 7 got %d endpoints!", altsetting->desc.bNumEndpoints);
273 return -EINVAL; 273 return -EINVAL;
274 } 274 }
275 275
@@ -279,7 +279,7 @@ int st5481_setup_usb(struct st5481_adapter *adapter)
279 279
280 // Use alternative setting 3 on interface 0 to have 2B+D 280 // Use alternative setting 3 on interface 0 to have 2B+D
281 if ((status = usb_set_interface (dev, 0, 3)) < 0) { 281 if ((status = usb_set_interface (dev, 0, 3)) < 0) {
282 WARN("usb_set_interface failed,status=%d",status); 282 WARNING("usb_set_interface failed,status=%d",status);
283 return status; 283 return status;
284 } 284 }
285 285
@@ -497,7 +497,7 @@ static void usb_in_complete(struct urb *urb)
497 DBG(1,"urb killed status %d", urb->status); 497 DBG(1,"urb killed status %d", urb->status);
498 return; // Give up 498 return; // Give up
499 default: 499 default:
500 WARN("urb status %d",urb->status); 500 WARNING("urb status %d",urb->status);
501 break; 501 break;
502 } 502 }
503 } 503 }
@@ -523,7 +523,7 @@ static void usb_in_complete(struct urb *urb)
523 DBG(4,"count=%d",status); 523 DBG(4,"count=%d",status);
524 DBG_PACKET(0x400, in->rcvbuf, status); 524 DBG_PACKET(0x400, in->rcvbuf, status);
525 if (!(skb = dev_alloc_skb(status))) { 525 if (!(skb = dev_alloc_skb(status))) {
526 WARN("receive out of memory\n"); 526 WARNING("receive out of memory\n");
527 break; 527 break;
528 } 528 }
529 memcpy(skb_put(skb, status), in->rcvbuf, status); 529 memcpy(skb_put(skb, status), in->rcvbuf, status);
diff --git a/drivers/isdn/mISDN/Kconfig b/drivers/isdn/mISDN/Kconfig
new file mode 100644
index 000000000000..4938355c4072
--- /dev/null
+++ b/drivers/isdn/mISDN/Kconfig
@@ -0,0 +1,44 @@
1#
2# modularer ISDN driver
3#
4
5menuconfig MISDN
6 tristate "Modular ISDN driver"
7 help
8 Enable support for the modular ISDN driver.
9
10if MISDN != n
11
12config MISDN_DSP
13 tristate "Digital Audio Processing of transparent data"
14 depends on MISDN
15 help
16 Enable support for digital audio processing capability.
17 This module may be used for special applications that require
18 cross connecting of bchannels, conferencing, dtmf decoding
19 echo cancelation, tone generation, and Blowfish encryption and
20 decryption.
21 It may use hardware features if available.
22 E.g. it is required for PBX4Linux. Go to http://isdn.eversberg.eu
23 and get more informations about this module and it's usage.
24 If unsure, say 'N'.
25
26config MISDN_L1OIP
27 tristate "ISDN over IP tunnel"
28 depends on MISDN
29 help
30 Enable support for ISDN over IP tunnel.
31
32 It features:
33 - dynamic IP exchange, if one or both peers have dynamic IPs
34 - BRI (S0) and PRI (S2M) interface
35 - layer 1 control via network keepalive frames
36 - direct tunneling of physical interface via IP
37
38 NOTE: This protocol is called 'Layer 1 over IP' and is not
39 compatible with ISDNoIP (Agfeo) or TDMoIP. Protocol description is
40 provided in the source code.
41
42source "drivers/isdn/hardware/mISDN/Kconfig"
43
44endif #MISDN
diff --git a/drivers/isdn/mISDN/Makefile b/drivers/isdn/mISDN/Makefile
new file mode 100644
index 000000000000..1cb5e633cf75
--- /dev/null
+++ b/drivers/isdn/mISDN/Makefile
@@ -0,0 +1,13 @@
1#
2# Makefile for the modular ISDN driver
3#
4
5obj-$(CONFIG_MISDN) += mISDN_core.o
6obj-$(CONFIG_MISDN_DSP) += mISDN_dsp.o
7obj-$(CONFIG_MISDN_L1OIP) += l1oip.o
8
9# multi objects
10
11mISDN_core-objs := core.o fsm.o socket.o hwchannel.o stack.o layer1.o layer2.o tei.o timerdev.o
12mISDN_dsp-objs := dsp_core.o dsp_cmx.o dsp_tones.o dsp_dtmf.o dsp_audio.o dsp_blowfish.o dsp_pipeline.o dsp_hwec.o
13l1oip-objs := l1oip_core.o l1oip_codec.o
diff --git a/drivers/isdn/mISDN/core.c b/drivers/isdn/mISDN/core.c
new file mode 100644
index 000000000000..33068177b7c9
--- /dev/null
+++ b/drivers/isdn/mISDN/core.c
@@ -0,0 +1,244 @@
1/*
2 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#include <linux/types.h>
16#include <linux/stddef.h>
17#include <linux/module.h>
18#include <linux/spinlock.h>
19#include <linux/mISDNif.h>
20#include "core.h"
21
22static u_int debug;
23
24MODULE_AUTHOR("Karsten Keil");
25MODULE_LICENSE("GPL");
26module_param(debug, uint, S_IRUGO | S_IWUSR);
27
28static LIST_HEAD(devices);
29DEFINE_RWLOCK(device_lock);
30static u64 device_ids;
31#define MAX_DEVICE_ID 63
32
33static LIST_HEAD(Bprotocols);
34DEFINE_RWLOCK(bp_lock);
35
36struct mISDNdevice
37*get_mdevice(u_int id)
38{
39 struct mISDNdevice *dev;
40
41 read_lock(&device_lock);
42 list_for_each_entry(dev, &devices, D.list)
43 if (dev->id == id) {
44 read_unlock(&device_lock);
45 return dev;
46 }
47 read_unlock(&device_lock);
48 return NULL;
49}
50
51int
52get_mdevice_count(void)
53{
54 struct mISDNdevice *dev;
55 int cnt = 0;
56
57 read_lock(&device_lock);
58 list_for_each_entry(dev, &devices, D.list)
59 cnt++;
60 read_unlock(&device_lock);
61 return cnt;
62}
63
64static int
65get_free_devid(void)
66{
67 u_int i;
68
69 for (i = 0; i <= MAX_DEVICE_ID; i++)
70 if (!test_and_set_bit(i, (u_long *)&device_ids))
71 return i;
72 return -1;
73}
74
75int
76mISDN_register_device(struct mISDNdevice *dev, char *name)
77{
78 u_long flags;
79 int err;
80
81 dev->id = get_free_devid();
82 if (dev->id < 0)
83 return -EBUSY;
84 if (name && name[0])
85 strcpy(dev->name, name);
86 else
87 sprintf(dev->name, "mISDN%d", dev->id);
88 if (debug & DEBUG_CORE)
89 printk(KERN_DEBUG "mISDN_register %s %d\n",
90 dev->name, dev->id);
91 err = create_stack(dev);
92 if (err)
93 return err;
94 write_lock_irqsave(&device_lock, flags);
95 list_add_tail(&dev->D.list, &devices);
96 write_unlock_irqrestore(&device_lock, flags);
97 return 0;
98}
99EXPORT_SYMBOL(mISDN_register_device);
100
101void
102mISDN_unregister_device(struct mISDNdevice *dev) {
103 u_long flags;
104
105 if (debug & DEBUG_CORE)
106 printk(KERN_DEBUG "mISDN_unregister %s %d\n",
107 dev->name, dev->id);
108 write_lock_irqsave(&device_lock, flags);
109 list_del(&dev->D.list);
110 write_unlock_irqrestore(&device_lock, flags);
111 test_and_clear_bit(dev->id, (u_long *)&device_ids);
112 delete_stack(dev);
113}
114EXPORT_SYMBOL(mISDN_unregister_device);
115
116u_int
117get_all_Bprotocols(void)
118{
119 struct Bprotocol *bp;
120 u_int m = 0;
121
122 read_lock(&bp_lock);
123 list_for_each_entry(bp, &Bprotocols, list)
124 m |= bp->Bprotocols;
125 read_unlock(&bp_lock);
126 return m;
127}
128
129struct Bprotocol *
130get_Bprotocol4mask(u_int m)
131{
132 struct Bprotocol *bp;
133
134 read_lock(&bp_lock);
135 list_for_each_entry(bp, &Bprotocols, list)
136 if (bp->Bprotocols & m) {
137 read_unlock(&bp_lock);
138 return bp;
139 }
140 read_unlock(&bp_lock);
141 return NULL;
142}
143
144struct Bprotocol *
145get_Bprotocol4id(u_int id)
146{
147 u_int m;
148
149 if (id < ISDN_P_B_START || id > 63) {
150 printk(KERN_WARNING "%s id not in range %d\n",
151 __func__, id);
152 return NULL;
153 }
154 m = 1 << (id & ISDN_P_B_MASK);
155 return get_Bprotocol4mask(m);
156}
157
158int
159mISDN_register_Bprotocol(struct Bprotocol *bp)
160{
161 u_long flags;
162 struct Bprotocol *old;
163
164 if (debug & DEBUG_CORE)
165 printk(KERN_DEBUG "%s: %s/%x\n", __func__,
166 bp->name, bp->Bprotocols);
167 old = get_Bprotocol4mask(bp->Bprotocols);
168 if (old) {
169 printk(KERN_WARNING
170 "register duplicate protocol old %s/%x new %s/%x\n",
171 old->name, old->Bprotocols, bp->name, bp->Bprotocols);
172 return -EBUSY;
173 }
174 write_lock_irqsave(&bp_lock, flags);
175 list_add_tail(&bp->list, &Bprotocols);
176 write_unlock_irqrestore(&bp_lock, flags);
177 return 0;
178}
179EXPORT_SYMBOL(mISDN_register_Bprotocol);
180
181void
182mISDN_unregister_Bprotocol(struct Bprotocol *bp)
183{
184 u_long flags;
185
186 if (debug & DEBUG_CORE)
187 printk(KERN_DEBUG "%s: %s/%x\n", __func__, bp->name,
188 bp->Bprotocols);
189 write_lock_irqsave(&bp_lock, flags);
190 list_del(&bp->list);
191 write_unlock_irqrestore(&bp_lock, flags);
192}
193EXPORT_SYMBOL(mISDN_unregister_Bprotocol);
194
195int
196mISDNInit(void)
197{
198 int err;
199
200 printk(KERN_INFO "Modular ISDN core version %d.%d.%d\n",
201 MISDN_MAJOR_VERSION, MISDN_MINOR_VERSION, MISDN_RELEASE);
202 mISDN_initstack(&debug);
203 err = mISDN_inittimer(&debug);
204 if (err)
205 goto error;
206 err = l1_init(&debug);
207 if (err) {
208 mISDN_timer_cleanup();
209 goto error;
210 }
211 err = Isdnl2_Init(&debug);
212 if (err) {
213 mISDN_timer_cleanup();
214 l1_cleanup();
215 goto error;
216 }
217 err = misdn_sock_init(&debug);
218 if (err) {
219 mISDN_timer_cleanup();
220 l1_cleanup();
221 Isdnl2_cleanup();
222 }
223error:
224 return err;
225}
226
227void mISDN_cleanup(void)
228{
229 misdn_sock_cleanup();
230 mISDN_timer_cleanup();
231 l1_cleanup();
232 Isdnl2_cleanup();
233
234 if (!list_empty(&devices))
235 printk(KERN_ERR "%s devices still registered\n", __func__);
236
237 if (!list_empty(&Bprotocols))
238 printk(KERN_ERR "%s Bprotocols still registered\n", __func__);
239 printk(KERN_DEBUG "mISDNcore unloaded\n");
240}
241
242module_init(mISDNInit);
243module_exit(mISDN_cleanup);
244
diff --git a/drivers/isdn/mISDN/core.h b/drivers/isdn/mISDN/core.h
new file mode 100644
index 000000000000..7da7233b4c1a
--- /dev/null
+++ b/drivers/isdn/mISDN/core.h
@@ -0,0 +1,77 @@
1/*
2 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#ifndef mISDN_CORE_H
16#define mISDN_CORE_H
17
18extern struct mISDNdevice *get_mdevice(u_int);
19extern int get_mdevice_count(void);
20
21/* stack status flag */
22#define mISDN_STACK_ACTION_MASK 0x0000ffff
23#define mISDN_STACK_COMMAND_MASK 0x000f0000
24#define mISDN_STACK_STATUS_MASK 0xfff00000
25/* action bits 0-15 */
26#define mISDN_STACK_WORK 0
27#define mISDN_STACK_SETUP 1
28#define mISDN_STACK_CLEARING 2
29#define mISDN_STACK_RESTART 3
30#define mISDN_STACK_WAKEUP 4
31#define mISDN_STACK_ABORT 15
32/* command bits 16-19 */
33#define mISDN_STACK_STOPPED 16
34#define mISDN_STACK_INIT 17
35#define mISDN_STACK_THREADSTART 18
36/* status bits 20-31 */
37#define mISDN_STACK_BCHANNEL 20
38#define mISDN_STACK_ACTIVE 29
39#define mISDN_STACK_RUNNING 30
40#define mISDN_STACK_KILLED 31
41
42
43/* manager options */
44#define MGR_OPT_USER 24
45#define MGR_OPT_NETWORK 25
46
47extern int connect_Bstack(struct mISDNdevice *, struct mISDNchannel *,
48 u_int, struct sockaddr_mISDN *);
49extern int connect_layer1(struct mISDNdevice *, struct mISDNchannel *,
50 u_int, struct sockaddr_mISDN *);
51extern int create_l2entity(struct mISDNdevice *, struct mISDNchannel *,
52 u_int, struct sockaddr_mISDN *);
53
54extern int create_stack(struct mISDNdevice *);
55extern int create_teimanager(struct mISDNdevice *);
56extern void delete_teimanager(struct mISDNchannel *);
57extern void delete_channel(struct mISDNchannel *);
58extern void delete_stack(struct mISDNdevice *);
59extern void mISDN_initstack(u_int *);
60extern int misdn_sock_init(u_int *);
61extern void misdn_sock_cleanup(void);
62extern void add_layer2(struct mISDNchannel *, struct mISDNstack *);
63extern void __add_layer2(struct mISDNchannel *, struct mISDNstack *);
64
65extern u_int get_all_Bprotocols(void);
66struct Bprotocol *get_Bprotocol4mask(u_int);
67struct Bprotocol *get_Bprotocol4id(u_int);
68
69extern int mISDN_inittimer(u_int *);
70extern void mISDN_timer_cleanup(void);
71
72extern int l1_init(u_int *);
73extern void l1_cleanup(void);
74extern int Isdnl2_Init(u_int *);
75extern void Isdnl2_cleanup(void);
76
77#endif
diff --git a/drivers/isdn/mISDN/dsp.h b/drivers/isdn/mISDN/dsp.h
new file mode 100644
index 000000000000..6c3fed6b8d4f
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp.h
@@ -0,0 +1,263 @@
1/*
2 * Audio support data for ISDN4Linux.
3 *
4 * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu)
5 *
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
8 *
9 */
10
11#define DEBUG_DSP_CTRL 0x0001
12#define DEBUG_DSP_CORE 0x0002
13#define DEBUG_DSP_DTMF 0x0004
14#define DEBUG_DSP_CMX 0x0010
15#define DEBUG_DSP_TONE 0x0020
16#define DEBUG_DSP_BLOWFISH 0x0040
17#define DEBUG_DSP_DELAY 0x0100
18#define DEBUG_DSP_DTMFCOEFF 0x8000 /* heavy output */
19
20/* options may be:
21 *
22 * bit 0 = use ulaw instead of alaw
23 * bit 1 = enable hfc hardware accelleration for all channels
24 *
25 */
26#define DSP_OPT_ULAW (1<<0)
27#define DSP_OPT_NOHARDWARE (1<<1)
28
29#include <linux/timer.h>
30#include <linux/workqueue.h>
31
32#include "dsp_ecdis.h"
33
34extern int dsp_options;
35extern int dsp_debug;
36extern int dsp_poll;
37extern int dsp_tics;
38extern spinlock_t dsp_lock;
39extern struct work_struct dsp_workq;
40extern u32 dsp_poll_diff; /* calculated fix-comma corrected poll value */
41
42/***************
43 * audio stuff *
44 ***************/
45
46extern s32 dsp_audio_alaw_to_s32[256];
47extern s32 dsp_audio_ulaw_to_s32[256];
48extern s32 *dsp_audio_law_to_s32;
49extern u8 dsp_audio_s16_to_law[65536];
50extern u8 dsp_audio_alaw_to_ulaw[256];
51extern u8 dsp_audio_mix_law[65536];
52extern u8 dsp_audio_seven2law[128];
53extern u8 dsp_audio_law2seven[256];
54extern void dsp_audio_generate_law_tables(void);
55extern void dsp_audio_generate_s2law_table(void);
56extern void dsp_audio_generate_seven(void);
57extern void dsp_audio_generate_mix_table(void);
58extern void dsp_audio_generate_ulaw_samples(void);
59extern void dsp_audio_generate_volume_changes(void);
60extern u8 dsp_silence;
61
62
63/*************
64 * cmx stuff *
65 *************/
66
67#define MAX_POLL 256 /* maximum number of send-chunks */
68
69#define CMX_BUFF_SIZE 0x8000 /* must be 2**n (0x1000 about 1/2 second) */
70#define CMX_BUFF_HALF 0x4000 /* CMX_BUFF_SIZE / 2 */
71#define CMX_BUFF_MASK 0x7fff /* CMX_BUFF_SIZE - 1 */
72
73/* how many seconds will we check the lowest delay until the jitter buffer
74 is reduced by that delay */
75#define MAX_SECONDS_JITTER_CHECK 5
76
77extern struct timer_list dsp_spl_tl;
78extern u32 dsp_spl_jiffies;
79
80/* the structure of conferences:
81 *
82 * each conference has a unique number, given by user space.
83 * the conferences are linked in a chain.
84 * each conference has members linked in a chain.
85 * each dsplayer points to a member, each member points to a dsplayer.
86 */
87
88/* all members within a conference (this is linked 1:1 with the dsp) */
89struct dsp;
90struct dsp_conf_member {
91 struct list_head list;
92 struct dsp *dsp;
93};
94
95/* the list of all conferences */
96struct dsp_conf {
97 struct list_head list;
98 u32 id;
99 /* all cmx stacks with the same ID are
100 connected */
101 struct list_head mlist;
102 int software; /* conf is processed by software */
103 int hardware; /* conf is processed by hardware */
104 /* note: if both unset, has only one member */
105};
106
107
108/**************
109 * DTMF stuff *
110 **************/
111
112#define DSP_DTMF_NPOINTS 102
113
114#define ECHOCAN_BUFLEN (4*128)
115
116struct dsp_dtmf {
117 int treshold; /* above this is dtmf (square of) */
118 int software; /* dtmf uses software decoding */
119 int hardware; /* dtmf uses hardware decoding */
120 int size; /* number of bytes in buffer */
121 signed short buffer[DSP_DTMF_NPOINTS];
122 /* buffers one full dtmf frame */
123 u8 lastwhat, lastdigit;
124 int count;
125 u8 digits[16]; /* just the dtmf result */
126};
127
128
129/******************
130 * pipeline stuff *
131 ******************/
132struct dsp_pipeline {
133 rwlock_t lock;
134 struct list_head list;
135 int inuse;
136};
137
138/***************
139 * tones stuff *
140 ***************/
141
142struct dsp_tone {
143 int software; /* tones are generated by software */
144 int hardware; /* tones are generated by hardware */
145 int tone;
146 void *pattern;
147 int count;
148 int index;
149 struct timer_list tl;
150};
151
152/*****************
153 * general stuff *
154 *****************/
155
156struct dsp {
157 struct list_head list;
158 struct mISDNchannel ch;
159 struct mISDNchannel *up;
160 unsigned char name[64];
161 int b_active;
162 int echo; /* echo is enabled */
163 int rx_disabled; /* what the user wants */
164 int rx_is_off; /* what the card is */
165 int tx_mix;
166 struct dsp_tone tone;
167 struct dsp_dtmf dtmf;
168 int tx_volume, rx_volume;
169
170 /* queue for sending frames */
171 struct work_struct workq;
172 struct sk_buff_head sendq;
173 int hdlc; /* if mode is hdlc */
174 int data_pending; /* currently an unconfirmed frame */
175
176 /* conference stuff */
177 u32 conf_id;
178 struct dsp_conf *conf;
179 struct dsp_conf_member
180 *member;
181
182 /* buffer stuff */
183 int rx_W; /* current write pos for data without timestamp */
184 int rx_R; /* current read pos for transmit clock */
185 int rx_init; /* if set, pointers will be adjusted first */
186 int tx_W; /* current write pos for transmit data */
187 int tx_R; /* current read pos for transmit clock */
188 int rx_delay[MAX_SECONDS_JITTER_CHECK];
189 int tx_delay[MAX_SECONDS_JITTER_CHECK];
190 u8 tx_buff[CMX_BUFF_SIZE];
191 u8 rx_buff[CMX_BUFF_SIZE];
192 int last_tx; /* if set, we transmitted last poll interval */
193 int cmx_delay; /* initial delay of buffers,
194 or 0 for dynamic jitter buffer */
195 int tx_dejitter; /* if set, dejitter tx buffer */
196 int tx_data; /* enables tx-data of CMX to upper layer */
197
198 /* hardware stuff */
199 struct dsp_features features;
200 int features_rx_off; /* set if rx_off is featured */
201 int pcm_slot_rx; /* current PCM slot (or -1) */
202 int pcm_bank_rx;
203 int pcm_slot_tx;
204 int pcm_bank_tx;
205 int hfc_conf; /* unique id of current conference (or -1) */
206
207 /* encryption stuff */
208 int bf_enable;
209 u32 bf_p[18];
210 u32 bf_s[1024];
211 int bf_crypt_pos;
212 u8 bf_data_in[9];
213 u8 bf_crypt_out[9];
214 int bf_decrypt_in_pos;
215 int bf_decrypt_out_pos;
216 u8 bf_crypt_inring[16];
217 u8 bf_data_out[9];
218 int bf_sync;
219
220 struct dsp_pipeline
221 pipeline;
222};
223
224/* functions */
225
226extern void dsp_change_volume(struct sk_buff *skb, int volume);
227
228extern struct list_head dsp_ilist;
229extern struct list_head conf_ilist;
230extern void dsp_cmx_debug(struct dsp *dsp);
231extern void dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp);
232extern int dsp_cmx_conf(struct dsp *dsp, u32 conf_id);
233extern void dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb);
234extern void dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb);
235extern void dsp_cmx_send(void *arg);
236extern void dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb);
237extern int dsp_cmx_del_conf_member(struct dsp *dsp);
238extern int dsp_cmx_del_conf(struct dsp_conf *conf);
239
240extern void dsp_dtmf_goertzel_init(struct dsp *dsp);
241extern void dsp_dtmf_hardware(struct dsp *dsp);
242extern u8 *dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 *data, int len,
243 int fmt);
244
245extern int dsp_tone(struct dsp *dsp, int tone);
246extern void dsp_tone_copy(struct dsp *dsp, u8 *data, int len);
247extern void dsp_tone_timeout(void *arg);
248
249extern void dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len);
250extern void dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len);
251extern int dsp_bf_init(struct dsp *dsp, const u8 *key, unsigned int keylen);
252extern void dsp_bf_cleanup(struct dsp *dsp);
253
254extern int dsp_pipeline_module_init(void);
255extern void dsp_pipeline_module_exit(void);
256extern int dsp_pipeline_init(struct dsp_pipeline *pipeline);
257extern void dsp_pipeline_destroy(struct dsp_pipeline *pipeline);
258extern int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg);
259extern void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data,
260 int len);
261extern void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data,
262 int len);
263
diff --git a/drivers/isdn/mISDN/dsp_audio.c b/drivers/isdn/mISDN/dsp_audio.c
new file mode 100644
index 000000000000..1c2dd5694773
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp_audio.c
@@ -0,0 +1,434 @@
1/*
2 * Audio support data for mISDN_dsp.
3 *
4 * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu)
5 * Rewritten by Peter
6 *
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
9 *
10 */
11
12#include <linux/delay.h>
13#include <linux/mISDNif.h>
14#include <linux/mISDNdsp.h>
15#include "core.h"
16#include "dsp.h"
17
18/* ulaw[unsigned char] -> signed 16-bit */
19s32 dsp_audio_ulaw_to_s32[256];
20/* alaw[unsigned char] -> signed 16-bit */
21s32 dsp_audio_alaw_to_s32[256];
22
23s32 *dsp_audio_law_to_s32;
24EXPORT_SYMBOL(dsp_audio_law_to_s32);
25
26/* signed 16-bit -> law */
27u8 dsp_audio_s16_to_law[65536];
28EXPORT_SYMBOL(dsp_audio_s16_to_law);
29
30/* alaw -> ulaw */
31u8 dsp_audio_alaw_to_ulaw[256];
32/* ulaw -> alaw */
33u8 dsp_audio_ulaw_to_alaw[256];
34u8 dsp_silence;
35
36
37/*****************************************************
38 * generate table for conversion of s16 to alaw/ulaw *
39 *****************************************************/
40
41#define AMI_MASK 0x55
42
43static inline unsigned char linear2alaw(short int linear)
44{
45 int mask;
46 int seg;
47 int pcm_val;
48 static int seg_end[8] = {
49 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
50 };
51
52 pcm_val = linear;
53 if (pcm_val >= 0) {
54 /* Sign (7th) bit = 1 */
55 mask = AMI_MASK | 0x80;
56 } else {
57 /* Sign bit = 0 */
58 mask = AMI_MASK;
59 pcm_val = -pcm_val;
60 }
61
62 /* Convert the scaled magnitude to segment number. */
63 for (seg = 0; seg < 8; seg++) {
64 if (pcm_val <= seg_end[seg])
65 break;
66 }
67 /* Combine the sign, segment, and quantization bits. */
68 return ((seg << 4) |
69 ((pcm_val >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask;
70}
71
72
73static inline short int alaw2linear(unsigned char alaw)
74{
75 int i;
76 int seg;
77
78 alaw ^= AMI_MASK;
79 i = ((alaw & 0x0F) << 4) + 8 /* rounding error */;
80 seg = (((int) alaw & 0x70) >> 4);
81 if (seg)
82 i = (i + 0x100) << (seg - 1);
83 return (short int) ((alaw & 0x80) ? i : -i);
84}
85
86static inline short int ulaw2linear(unsigned char ulaw)
87{
88 short mu, e, f, y;
89 static short etab[] = {0, 132, 396, 924, 1980, 4092, 8316, 16764};
90
91 mu = 255 - ulaw;
92 e = (mu & 0x70) / 16;
93 f = mu & 0x0f;
94 y = f * (1 << (e + 3));
95 y += etab[e];
96 if (mu & 0x80)
97 y = -y;
98 return y;
99}
100
101#define BIAS 0x84 /*!< define the add-in bias for 16 bit samples */
102
103static unsigned char linear2ulaw(short sample)
104{
105 static int exp_lut[256] = {
106 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
107 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
108 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
109 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
110 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
111 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
112 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
113 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
114 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
115 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
116 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
117 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
118 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
119 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
120 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
121 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
122 int sign, exponent, mantissa;
123 unsigned char ulawbyte;
124
125 /* Get the sample into sign-magnitude. */
126 sign = (sample >> 8) & 0x80; /* set aside the sign */
127 if (sign != 0)
128 sample = -sample; /* get magnitude */
129
130 /* Convert from 16 bit linear to ulaw. */
131 sample = sample + BIAS;
132 exponent = exp_lut[(sample >> 7) & 0xFF];
133 mantissa = (sample >> (exponent + 3)) & 0x0F;
134 ulawbyte = ~(sign | (exponent << 4) | mantissa);
135
136 return ulawbyte;
137}
138
139static int reverse_bits(int i)
140{
141 int z, j;
142 z = 0;
143
144 for (j = 0; j < 8; j++) {
145 if ((i & (1 << j)) != 0)
146 z |= 1 << (7 - j);
147 }
148 return z;
149}
150
151
152void dsp_audio_generate_law_tables(void)
153{
154 int i;
155 for (i = 0; i < 256; i++)
156 dsp_audio_alaw_to_s32[i] = alaw2linear(reverse_bits(i));
157
158 for (i = 0; i < 256; i++)
159 dsp_audio_ulaw_to_s32[i] = ulaw2linear(reverse_bits(i));
160
161 for (i = 0; i < 256; i++) {
162 dsp_audio_alaw_to_ulaw[i] =
163 linear2ulaw(dsp_audio_alaw_to_s32[i]);
164 dsp_audio_ulaw_to_alaw[i] =
165 linear2alaw(dsp_audio_ulaw_to_s32[i]);
166 }
167}
168
169void
170dsp_audio_generate_s2law_table(void)
171{
172 int i;
173
174 if (dsp_options & DSP_OPT_ULAW) {
175 /* generating ulaw-table */
176 for (i = -32768; i < 32768; i++) {
177 dsp_audio_s16_to_law[i & 0xffff] =
178 reverse_bits(linear2ulaw(i));
179 }
180 } else {
181 /* generating alaw-table */
182 for (i = -32768; i < 32768; i++) {
183 dsp_audio_s16_to_law[i & 0xffff] =
184 reverse_bits(linear2alaw(i));
185 }
186 }
187}
188
189
190/*
191 * the seven bit sample is the number of every second alaw-sample ordered by
192 * aplitude. 0x00 is negative, 0x7f is positive amplitude.
193 */
194u8 dsp_audio_seven2law[128];
195u8 dsp_audio_law2seven[256];
196
197/********************************************************************
198 * generate table for conversion law from/to 7-bit alaw-like sample *
199 ********************************************************************/
200
201void
202dsp_audio_generate_seven(void)
203{
204 int i, j, k;
205 u8 spl;
206 u8 sorted_alaw[256];
207
208 /* generate alaw table, sorted by the linear value */
209 for (i = 0; i < 256; i++) {
210 j = 0;
211 for (k = 0; k < 256; k++) {
212 if (dsp_audio_alaw_to_s32[k]
213 < dsp_audio_alaw_to_s32[i]) {
214 j++;
215 }
216 }
217 sorted_alaw[j] = i;
218 }
219
220 /* generate tabels */
221 for (i = 0; i < 256; i++) {
222 /* spl is the source: the law-sample (converted to alaw) */
223 spl = i;
224 if (dsp_options & DSP_OPT_ULAW)
225 spl = dsp_audio_ulaw_to_alaw[i];
226 /* find the 7-bit-sample */
227 for (j = 0; j < 256; j++) {
228 if (sorted_alaw[j] == spl)
229 break;
230 }
231 /* write 7-bit audio value */
232 dsp_audio_law2seven[i] = j >> 1;
233 }
234 for (i = 0; i < 128; i++) {
235 spl = sorted_alaw[i << 1];
236 if (dsp_options & DSP_OPT_ULAW)
237 spl = dsp_audio_alaw_to_ulaw[spl];
238 dsp_audio_seven2law[i] = spl;
239 }
240}
241
242
243/* mix 2*law -> law */
244u8 dsp_audio_mix_law[65536];
245
246/******************************************************
247 * generate mix table to mix two law samples into one *
248 ******************************************************/
249
250void
251dsp_audio_generate_mix_table(void)
252{
253 int i, j;
254 s32 sample;
255
256 i = 0;
257 while (i < 256) {
258 j = 0;
259 while (j < 256) {
260 sample = dsp_audio_law_to_s32[i];
261 sample += dsp_audio_law_to_s32[j];
262 if (sample > 32767)
263 sample = 32767;
264 if (sample < -32768)
265 sample = -32768;
266 dsp_audio_mix_law[(i<<8)|j] =
267 dsp_audio_s16_to_law[sample & 0xffff];
268 j++;
269 }
270 i++;
271 }
272}
273
274
275/*************************************
276 * generate different volume changes *
277 *************************************/
278
279static u8 dsp_audio_reduce8[256];
280static u8 dsp_audio_reduce7[256];
281static u8 dsp_audio_reduce6[256];
282static u8 dsp_audio_reduce5[256];
283static u8 dsp_audio_reduce4[256];
284static u8 dsp_audio_reduce3[256];
285static u8 dsp_audio_reduce2[256];
286static u8 dsp_audio_reduce1[256];
287static u8 dsp_audio_increase1[256];
288static u8 dsp_audio_increase2[256];
289static u8 dsp_audio_increase3[256];
290static u8 dsp_audio_increase4[256];
291static u8 dsp_audio_increase5[256];
292static u8 dsp_audio_increase6[256];
293static u8 dsp_audio_increase7[256];
294static u8 dsp_audio_increase8[256];
295
296static u8 *dsp_audio_volume_change[16] = {
297 dsp_audio_reduce8,
298 dsp_audio_reduce7,
299 dsp_audio_reduce6,
300 dsp_audio_reduce5,
301 dsp_audio_reduce4,
302 dsp_audio_reduce3,
303 dsp_audio_reduce2,
304 dsp_audio_reduce1,
305 dsp_audio_increase1,
306 dsp_audio_increase2,
307 dsp_audio_increase3,
308 dsp_audio_increase4,
309 dsp_audio_increase5,
310 dsp_audio_increase6,
311 dsp_audio_increase7,
312 dsp_audio_increase8,
313};
314
315void
316dsp_audio_generate_volume_changes(void)
317{
318 register s32 sample;
319 int i;
320 int num[] = { 110, 125, 150, 175, 200, 300, 400, 500 };
321 int denum[] = { 100, 100, 100, 100, 100, 100, 100, 100 };
322
323 i = 0;
324 while (i < 256) {
325 dsp_audio_reduce8[i] = dsp_audio_s16_to_law[
326 (dsp_audio_law_to_s32[i] * denum[7] / num[7]) & 0xffff];
327 dsp_audio_reduce7[i] = dsp_audio_s16_to_law[
328 (dsp_audio_law_to_s32[i] * denum[6] / num[6]) & 0xffff];
329 dsp_audio_reduce6[i] = dsp_audio_s16_to_law[
330 (dsp_audio_law_to_s32[i] * denum[5] / num[5]) & 0xffff];
331 dsp_audio_reduce5[i] = dsp_audio_s16_to_law[
332 (dsp_audio_law_to_s32[i] * denum[4] / num[4]) & 0xffff];
333 dsp_audio_reduce4[i] = dsp_audio_s16_to_law[
334 (dsp_audio_law_to_s32[i] * denum[3] / num[3]) & 0xffff];
335 dsp_audio_reduce3[i] = dsp_audio_s16_to_law[
336 (dsp_audio_law_to_s32[i] * denum[2] / num[2]) & 0xffff];
337 dsp_audio_reduce2[i] = dsp_audio_s16_to_law[
338 (dsp_audio_law_to_s32[i] * denum[1] / num[1]) & 0xffff];
339 dsp_audio_reduce1[i] = dsp_audio_s16_to_law[
340 (dsp_audio_law_to_s32[i] * denum[0] / num[0]) & 0xffff];
341 sample = dsp_audio_law_to_s32[i] * num[0] / denum[0];
342 if (sample < -32768)
343 sample = -32768;
344 else if (sample > 32767)
345 sample = 32767;
346 dsp_audio_increase1[i] = dsp_audio_s16_to_law[sample & 0xffff];
347 sample = dsp_audio_law_to_s32[i] * num[1] / denum[1];
348 if (sample < -32768)
349 sample = -32768;
350 else if (sample > 32767)
351 sample = 32767;
352 dsp_audio_increase2[i] = dsp_audio_s16_to_law[sample & 0xffff];
353 sample = dsp_audio_law_to_s32[i] * num[2] / denum[2];
354 if (sample < -32768)
355 sample = -32768;
356 else if (sample > 32767)
357 sample = 32767;
358 dsp_audio_increase3[i] = dsp_audio_s16_to_law[sample & 0xffff];
359 sample = dsp_audio_law_to_s32[i] * num[3] / denum[3];
360 if (sample < -32768)
361 sample = -32768;
362 else if (sample > 32767)
363 sample = 32767;
364 dsp_audio_increase4[i] = dsp_audio_s16_to_law[sample & 0xffff];
365 sample = dsp_audio_law_to_s32[i] * num[4] / denum[4];
366 if (sample < -32768)
367 sample = -32768;
368 else if (sample > 32767)
369 sample = 32767;
370 dsp_audio_increase5[i] = dsp_audio_s16_to_law[sample & 0xffff];
371 sample = dsp_audio_law_to_s32[i] * num[5] / denum[5];
372 if (sample < -32768)
373 sample = -32768;
374 else if (sample > 32767)
375 sample = 32767;
376 dsp_audio_increase6[i] = dsp_audio_s16_to_law[sample & 0xffff];
377 sample = dsp_audio_law_to_s32[i] * num[6] / denum[6];
378 if (sample < -32768)
379 sample = -32768;
380 else if (sample > 32767)
381 sample = 32767;
382 dsp_audio_increase7[i] = dsp_audio_s16_to_law[sample & 0xffff];
383 sample = dsp_audio_law_to_s32[i] * num[7] / denum[7];
384 if (sample < -32768)
385 sample = -32768;
386 else if (sample > 32767)
387 sample = 32767;
388 dsp_audio_increase8[i] = dsp_audio_s16_to_law[sample & 0xffff];
389
390 i++;
391 }
392}
393
394
395/**************************************
396 * change the volume of the given skb *
397 **************************************/
398
399/* this is a helper function for changing volume of skb. the range may be
400 * -8 to 8, which is a shift to the power of 2. 0 == no volume, 3 == volume*8
401 */
402void
403dsp_change_volume(struct sk_buff *skb, int volume)
404{
405 u8 *volume_change;
406 int i, ii;
407 u8 *p;
408 int shift;
409
410 if (volume == 0)
411 return;
412
413 /* get correct conversion table */
414 if (volume < 0) {
415 shift = volume + 8;
416 if (shift < 0)
417 shift = 0;
418 } else {
419 shift = volume + 7;
420 if (shift > 15)
421 shift = 15;
422 }
423 volume_change = dsp_audio_volume_change[shift];
424 i = 0;
425 ii = skb->len;
426 p = skb->data;
427 /* change volume */
428 while (i < ii) {
429 *p = volume_change[*p];
430 p++;
431 i++;
432 }
433}
434
diff --git a/drivers/isdn/mISDN/dsp_biquad.h b/drivers/isdn/mISDN/dsp_biquad.h
new file mode 100644
index 000000000000..038191bc45f5
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp_biquad.h
@@ -0,0 +1,65 @@
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * biquad.h - General telephony bi-quad section routines (currently this just
5 * handles canonic/type 2 form)
6 *
7 * Written by Steve Underwood <steveu@coppice.org>
8 *
9 * Copyright (C) 2001 Steve Underwood
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 */
28
29struct biquad2_state {
30 int32_t gain;
31 int32_t a1;
32 int32_t a2;
33 int32_t b1;
34 int32_t b2;
35
36 int32_t z1;
37 int32_t z2;
38};
39
40static inline void biquad2_init(struct biquad2_state *bq,
41 int32_t gain, int32_t a1, int32_t a2, int32_t b1, int32_t b2)
42{
43 bq->gain = gain;
44 bq->a1 = a1;
45 bq->a2 = a2;
46 bq->b1 = b1;
47 bq->b2 = b2;
48
49 bq->z1 = 0;
50 bq->z2 = 0;
51}
52
53static inline int16_t biquad2(struct biquad2_state *bq, int16_t sample)
54{
55 int32_t y;
56 int32_t z0;
57
58 z0 = sample*bq->gain + bq->z1*bq->a1 + bq->z2*bq->a2;
59 y = z0 + bq->z1*bq->b1 + bq->z2*bq->b2;
60
61 bq->z2 = bq->z1;
62 bq->z1 = z0 >> 15;
63 y >>= 15;
64 return y;
65}
diff --git a/drivers/isdn/mISDN/dsp_blowfish.c b/drivers/isdn/mISDN/dsp_blowfish.c
new file mode 100644
index 000000000000..18e411e95bba
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp_blowfish.c
@@ -0,0 +1,672 @@
1/*
2 * Blowfish encryption/decryption for mISDN_dsp.
3 *
4 * Copyright Andreas Eversberg (jolly@eversberg.eu)
5 *
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
8 *
9 */
10
11#include <linux/mISDNif.h>
12#include <linux/mISDNdsp.h>
13#include "core.h"
14#include "dsp.h"
15
16/*
17 * how to encode a sample stream to 64-bit blocks that will be encryped
18 *
19 * first of all, data is collected until a block of 9 samples are received.
20 * of course, a packet may have much more than 9 sample, but is may have
21 * not excacly the multiple of 9 samples. if there is a rest, the next
22 * received data will complete the block.
23 *
24 * the block is then converted to 9 uLAW samples without the least sigificant
25 * bit. the result is a 7-bit encoded sample.
26 *
27 * the samples will be reoganised to form 8 bytes of data:
28 * (5(6) means: encoded sample no. 5, bit 6)
29 *
30 * 0(6) 0(5) 0(4) 0(3) 0(2) 0(1) 0(0) 1(6)
31 * 1(5) 1(4) 1(3) 1(2) 1(1) 1(0) 2(6) 2(5)
32 * 2(4) 2(3) 2(2) 2(1) 2(0) 3(6) 3(5) 3(4)
33 * 3(3) 3(2) 3(1) 3(0) 4(6) 4(5) 4(4) 4(3)
34 * 4(2) 4(1) 4(0) 5(6) 5(5) 5(4) 5(3) 5(2)
35 * 5(1) 5(0) 6(6) 6(5) 6(4) 6(3) 6(2) 6(1)
36 * 6(0) 7(6) 7(5) 7(4) 7(3) 7(2) 7(1) 7(0)
37 * 8(6) 8(5) 8(4) 8(3) 8(2) 8(1) 8(0)
38 *
39 * the missing bit 0 of the last byte is filled with some
40 * random noise, to fill all 8 bytes.
41 *
42 * the 8 bytes will be encrypted using blowfish.
43 *
44 * the result will be converted into 9 bytes. the bit 7 is used for
45 * checksumme (CS) for sync (0, 1) and for the last bit:
46 * (5(6) means: crypted byte 5, bit 6)
47 *
48 * 1 0(7) 0(6) 0(5) 0(4) 0(3) 0(2) 0(1)
49 * 0 0(0) 1(7) 1(6) 1(5) 1(4) 1(3) 1(2)
50 * 0 1(1) 1(0) 2(7) 2(6) 2(5) 2(4) 2(3)
51 * 0 2(2) 2(1) 2(0) 3(7) 3(6) 3(5) 3(4)
52 * 0 3(3) 3(2) 3(1) 3(0) 4(7) 4(6) 4(5)
53 * CS 4(4) 4(3) 4(2) 4(1) 4(0) 5(7) 5(6)
54 * CS 5(5) 5(4) 5(3) 5(2) 5(1) 5(0) 6(7)
55 * CS 6(6) 6(5) 6(4) 6(3) 6(2) 6(1) 6(0)
56 * 7(0) 7(6) 7(5) 7(4) 7(3) 7(2) 7(1) 7(0)
57 *
58 * the checksum is used to detect transmission errors and frame drops.
59 *
60 * synchronisation of received block is done by shifting the upper bit of each
61 * byte (bit 7) to a shift register. if the rigister has the first five bits
62 * (10000), this is used to find the sync. only if sync has been found, the
63 * current block of 9 received bytes are decrypted. before that the check
64 * sum is calculated. if it is incorrect the block is dropped.
65 * this will avoid loud noise due to corrupt encrypted data.
66 *
67 * if the last block is corrupt, the current decoded block is repeated
68 * until a valid block has been received.
69 */
70
71/*
72 * some blowfish parts are taken from the
73 * crypto-api for faster implementation
74 */
75
76struct bf_ctx {
77 u32 p[18];
78 u32 s[1024];
79};
80
81static const u32 bf_pbox[16 + 2] = {
82 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
83 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
84 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
85 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
86 0x9216d5d9, 0x8979fb1b,
87};
88
89static const u32 bf_sbox[256 * 4] = {
90 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
91 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
92 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
93 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
94 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
95 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
96 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
97 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
98 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
99 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
100 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
101 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
102 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
103 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
104 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
105 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
106 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
107 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
108 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
109 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
110 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
111 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
112 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
113 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
114 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
115 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
116 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
117 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
118 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
119 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
120 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
121 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
122 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
123 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
124 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
125 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
126 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
127 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
128 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
129 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
130 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
131 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
132 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
133 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
134 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
135 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
136 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
137 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
138 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
139 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
140 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
141 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
142 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
143 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
144 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
145 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
146 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
147 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
148 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
149 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
150 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
151 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
152 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
153 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
154 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
155 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
156 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
157 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
158 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
159 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
160 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
161 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
162 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
163 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
164 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
165 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
166 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
167 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
168 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
169 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
170 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
171 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
172 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
173 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
174 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
175 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
176 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
177 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
178 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
179 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
180 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
181 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
182 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
183 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
184 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
185 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
186 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
187 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
188 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
189 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
190 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
191 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
192 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
193 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
194 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
195 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
196 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
197 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
198 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
199 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
200 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
201 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
202 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
203 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
204 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
205 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
206 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
207 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
208 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
209 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
210 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
211 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
212 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
213 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
214 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
215 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
216 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
217 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
218 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
219 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
220 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
221 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
222 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
223 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
224 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
225 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
226 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
227 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
228 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
229 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
230 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
231 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
232 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
233 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
234 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
235 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
236 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
237 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
238 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
239 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
240 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
241 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
242 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
243 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
244 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
245 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
246 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
247 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
248 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
249 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
250 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
251 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
252 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
253 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
254 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
255 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
256 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
257 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
258 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
259 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
260 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
261 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
262 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
263 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
264 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
265 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
266 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
267 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
268 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
269 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
270 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
271 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
272 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
273 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
274 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
275 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
276 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
277 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
278 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
279 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
280 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
281 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
282 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
283 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
284 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
285 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
286 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
287 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
288 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
289 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
290 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
291 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
292 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
293 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
294 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
295 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
296 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
297 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
298 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
299 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
300 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
301 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
302 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
303 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
304 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
305 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
306 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
307 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
308 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
309 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
310 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
311 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
312 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
313 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
314 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
315 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
316 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
317 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
318 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
319 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
320 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
321 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
322 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
323 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
324 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
325 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
326 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
327 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
328 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
329 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
330 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
331 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
332 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
333 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
334 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
335 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
336 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
337 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
338 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
339 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
340 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
341 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
342 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
343 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
344 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
345 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6,
346};
347
348/*
349 * Round loop unrolling macros, S is a pointer to a S-Box array
350 * organized in 4 unsigned longs at a row.
351 */
352#define GET32_3(x) (((x) & 0xff))
353#define GET32_2(x) (((x) >> (8)) & (0xff))
354#define GET32_1(x) (((x) >> (16)) & (0xff))
355#define GET32_0(x) (((x) >> (24)) & (0xff))
356
357#define bf_F(x) (((S[GET32_0(x)] + S[256 + GET32_1(x)]) ^ \
358 S[512 + GET32_2(x)]) + S[768 + GET32_3(x)])
359
360#define EROUND(a, b, n) do { b ^= P[n]; a ^= bf_F(b); } while (0)
361#define DROUND(a, b, n) do { a ^= bf_F(b); b ^= P[n]; } while (0)
362
363
364/*
365 * encrypt isdn data frame
366 * every block with 9 samples is encrypted
367 */
368void
369dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len)
370{
371 int i = 0, j = dsp->bf_crypt_pos;
372 u8 *bf_data_in = dsp->bf_data_in;
373 u8 *bf_crypt_out = dsp->bf_crypt_out;
374 u32 *P = dsp->bf_p;
375 u32 *S = dsp->bf_s;
376 u32 yl, yr;
377 u32 cs;
378 u8 nibble;
379
380 while (i < len) {
381 /* collect a block of 9 samples */
382 if (j < 9) {
383 bf_data_in[j] = *data;
384 *data++ = bf_crypt_out[j++];
385 i++;
386 continue;
387 }
388 j = 0;
389 /* transcode 9 samples xlaw to 8 bytes */
390 yl = dsp_audio_law2seven[bf_data_in[0]];
391 yl = (yl<<7) | dsp_audio_law2seven[bf_data_in[1]];
392 yl = (yl<<7) | dsp_audio_law2seven[bf_data_in[2]];
393 yl = (yl<<7) | dsp_audio_law2seven[bf_data_in[3]];
394 nibble = dsp_audio_law2seven[bf_data_in[4]];
395 yr = nibble;
396 yl = (yl<<4) | (nibble>>3);
397 yr = (yr<<7) | dsp_audio_law2seven[bf_data_in[5]];
398 yr = (yr<<7) | dsp_audio_law2seven[bf_data_in[6]];
399 yr = (yr<<7) | dsp_audio_law2seven[bf_data_in[7]];
400 yr = (yr<<7) | dsp_audio_law2seven[bf_data_in[8]];
401 yr = (yr<<1) | (bf_data_in[0] & 1);
402
403 /* fill unused bit with random noise of audio input */
404 /* encrypt */
405
406 EROUND(yr, yl, 0);
407 EROUND(yl, yr, 1);
408 EROUND(yr, yl, 2);
409 EROUND(yl, yr, 3);
410 EROUND(yr, yl, 4);
411 EROUND(yl, yr, 5);
412 EROUND(yr, yl, 6);
413 EROUND(yl, yr, 7);
414 EROUND(yr, yl, 8);
415 EROUND(yl, yr, 9);
416 EROUND(yr, yl, 10);
417 EROUND(yl, yr, 11);
418 EROUND(yr, yl, 12);
419 EROUND(yl, yr, 13);
420 EROUND(yr, yl, 14);
421 EROUND(yl, yr, 15);
422 yl ^= P[16];
423 yr ^= P[17];
424
425 /* calculate 3-bit checksumme */
426 cs = yl ^ (yl>>3) ^ (yl>>6) ^ (yl>>9) ^ (yl>>12) ^ (yl>>15)
427 ^ (yl>>18) ^ (yl>>21) ^ (yl>>24) ^ (yl>>27) ^ (yl>>30)
428 ^ (yr<<2) ^ (yr>>1) ^ (yr>>4) ^ (yr>>7) ^ (yr>>10)
429 ^ (yr>>13) ^ (yr>>16) ^ (yr>>19) ^ (yr>>22) ^ (yr>>25)
430 ^ (yr>>28) ^ (yr>>31);
431
432 /*
433 * transcode 8 crypted bytes to 9 data bytes with sync
434 * and checksum information
435 */
436 bf_crypt_out[0] = (yl>>25) | 0x80;
437 bf_crypt_out[1] = (yl>>18) & 0x7f;
438 bf_crypt_out[2] = (yl>>11) & 0x7f;
439 bf_crypt_out[3] = (yl>>4) & 0x7f;
440 bf_crypt_out[4] = ((yl<<3) & 0x78) | ((yr>>29) & 0x07);
441 bf_crypt_out[5] = ((yr>>22) & 0x7f) | ((cs<<5) & 0x80);
442 bf_crypt_out[6] = ((yr>>15) & 0x7f) | ((cs<<6) & 0x80);
443 bf_crypt_out[7] = ((yr>>8) & 0x7f) | (cs<<7);
444 bf_crypt_out[8] = yr;
445 }
446
447 /* write current count */
448 dsp->bf_crypt_pos = j;
449
450}
451
452
453/*
454 * decrypt isdn data frame
455 * every block with 9 bytes is decrypted
456 */
457void
458dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len)
459{
460 int i = 0;
461 u8 j = dsp->bf_decrypt_in_pos;
462 u8 k = dsp->bf_decrypt_out_pos;
463 u8 *bf_crypt_inring = dsp->bf_crypt_inring;
464 u8 *bf_data_out = dsp->bf_data_out;
465 u16 sync = dsp->bf_sync;
466 u32 *P = dsp->bf_p;
467 u32 *S = dsp->bf_s;
468 u32 yl, yr;
469 u8 nibble;
470 u8 cs, cs0, cs1, cs2;
471
472 while (i < len) {
473 /*
474 * shift upper bit and rotate data to buffer ring
475 * send current decrypted data
476 */
477 sync = (sync<<1) | ((*data)>>7);
478 bf_crypt_inring[j++ & 15] = *data;
479 *data++ = bf_data_out[k++];
480 i++;
481 if (k == 9)
482 k = 0; /* repeat if no sync has been found */
483 /* check if not in sync */
484 if ((sync&0x1f0) != 0x100)
485 continue;
486 j -= 9;
487 /* transcode receive data to 64 bit block of encrypted data */
488 yl = bf_crypt_inring[j++ & 15];
489 yl = (yl<<7) | bf_crypt_inring[j++ & 15]; /* bit7 = 0 */
490 yl = (yl<<7) | bf_crypt_inring[j++ & 15]; /* bit7 = 0 */
491 yl = (yl<<7) | bf_crypt_inring[j++ & 15]; /* bit7 = 0 */
492 nibble = bf_crypt_inring[j++ & 15]; /* bit7 = 0 */
493 yr = nibble;
494 yl = (yl<<4) | (nibble>>3);
495 cs2 = bf_crypt_inring[j++ & 15];
496 yr = (yr<<7) | (cs2 & 0x7f);
497 cs1 = bf_crypt_inring[j++ & 15];
498 yr = (yr<<7) | (cs1 & 0x7f);
499 cs0 = bf_crypt_inring[j++ & 15];
500 yr = (yr<<7) | (cs0 & 0x7f);
501 yr = (yr<<8) | bf_crypt_inring[j++ & 15];
502
503 /* calculate 3-bit checksumme */
504 cs = yl ^ (yl>>3) ^ (yl>>6) ^ (yl>>9) ^ (yl>>12) ^ (yl>>15)
505 ^ (yl>>18) ^ (yl>>21) ^ (yl>>24) ^ (yl>>27) ^ (yl>>30)
506 ^ (yr<<2) ^ (yr>>1) ^ (yr>>4) ^ (yr>>7) ^ (yr>>10)
507 ^ (yr>>13) ^ (yr>>16) ^ (yr>>19) ^ (yr>>22) ^ (yr>>25)
508 ^ (yr>>28) ^ (yr>>31);
509
510 /* check if frame is valid */
511 if ((cs&0x7) != (((cs2>>5)&4) | ((cs1>>6)&2) | (cs0 >> 7))) {
512 if (dsp_debug & DEBUG_DSP_BLOWFISH)
513 printk(KERN_DEBUG
514 "DSP BLOWFISH: received corrupt frame, "
515 "checksumme is not correct\n");
516 continue;
517 }
518
519 /* decrypt */
520 yr ^= P[17];
521 yl ^= P[16];
522 DROUND(yl, yr, 15);
523 DROUND(yr, yl, 14);
524 DROUND(yl, yr, 13);
525 DROUND(yr, yl, 12);
526 DROUND(yl, yr, 11);
527 DROUND(yr, yl, 10);
528 DROUND(yl, yr, 9);
529 DROUND(yr, yl, 8);
530 DROUND(yl, yr, 7);
531 DROUND(yr, yl, 6);
532 DROUND(yl, yr, 5);
533 DROUND(yr, yl, 4);
534 DROUND(yl, yr, 3);
535 DROUND(yr, yl, 2);
536 DROUND(yl, yr, 1);
537 DROUND(yr, yl, 0);
538
539 /* transcode 8 crypted bytes to 9 sample bytes */
540 bf_data_out[0] = dsp_audio_seven2law[(yl>>25) & 0x7f];
541 bf_data_out[1] = dsp_audio_seven2law[(yl>>18) & 0x7f];
542 bf_data_out[2] = dsp_audio_seven2law[(yl>>11) & 0x7f];
543 bf_data_out[3] = dsp_audio_seven2law[(yl>>4) & 0x7f];
544 bf_data_out[4] = dsp_audio_seven2law[((yl<<3) & 0x78) |
545 ((yr>>29) & 0x07)];
546
547 bf_data_out[5] = dsp_audio_seven2law[(yr>>22) & 0x7f];
548 bf_data_out[6] = dsp_audio_seven2law[(yr>>15) & 0x7f];
549 bf_data_out[7] = dsp_audio_seven2law[(yr>>8) & 0x7f];
550 bf_data_out[8] = dsp_audio_seven2law[(yr>>1) & 0x7f];
551 k = 0; /* start with new decoded frame */
552 }
553
554 /* write current count and sync */
555 dsp->bf_decrypt_in_pos = j;
556 dsp->bf_decrypt_out_pos = k;
557 dsp->bf_sync = sync;
558}
559
560
561/* used to encrypt S and P boxes */
562static inline void
563encrypt_block(const u32 *P, const u32 *S, u32 *dst, u32 *src)
564{
565 u32 yl = src[0];
566 u32 yr = src[1];
567
568 EROUND(yr, yl, 0);
569 EROUND(yl, yr, 1);
570 EROUND(yr, yl, 2);
571 EROUND(yl, yr, 3);
572 EROUND(yr, yl, 4);
573 EROUND(yl, yr, 5);
574 EROUND(yr, yl, 6);
575 EROUND(yl, yr, 7);
576 EROUND(yr, yl, 8);
577 EROUND(yl, yr, 9);
578 EROUND(yr, yl, 10);
579 EROUND(yl, yr, 11);
580 EROUND(yr, yl, 12);
581 EROUND(yl, yr, 13);
582 EROUND(yr, yl, 14);
583 EROUND(yl, yr, 15);
584
585 yl ^= P[16];
586 yr ^= P[17];
587
588 dst[0] = yr;
589 dst[1] = yl;
590}
591
592/*
593 * initialize the dsp for encryption and decryption using the same key
594 * Calculates the blowfish S and P boxes for encryption and decryption.
595 * The margin of keylen must be 4-56 bytes.
596 * returns 0 if ok.
597 */
598int
599dsp_bf_init(struct dsp *dsp, const u8 *key, uint keylen)
600{
601 short i, j, count;
602 u32 data[2], temp;
603 u32 *P = (u32 *)dsp->bf_p;
604 u32 *S = (u32 *)dsp->bf_s;
605
606 if (keylen < 4 || keylen > 56)
607 return 1;
608
609 /* Set dsp states */
610 i = 0;
611 while (i < 9) {
612 dsp->bf_crypt_out[i] = 0xff;
613 dsp->bf_data_out[i] = dsp_silence;
614 i++;
615 }
616 dsp->bf_crypt_pos = 0;
617 dsp->bf_decrypt_in_pos = 0;
618 dsp->bf_decrypt_out_pos = 0;
619 dsp->bf_sync = 0x1ff;
620 dsp->bf_enable = 1;
621
622 /* Copy the initialization s-boxes */
623 for (i = 0, count = 0; i < 256; i++)
624 for (j = 0; j < 4; j++, count++)
625 S[count] = bf_sbox[count];
626
627 /* Set the p-boxes */
628 for (i = 0; i < 16 + 2; i++)
629 P[i] = bf_pbox[i];
630
631 /* Actual subkey generation */
632 for (j = 0, i = 0; i < 16 + 2; i++) {
633 temp = (((u32)key[j] << 24) |
634 ((u32)key[(j + 1) % keylen] << 16) |
635 ((u32)key[(j + 2) % keylen] << 8) |
636 ((u32)key[(j + 3) % keylen]));
637
638 P[i] = P[i] ^ temp;
639 j = (j + 4) % keylen;
640 }
641
642 data[0] = 0x00000000;
643 data[1] = 0x00000000;
644
645 for (i = 0; i < 16 + 2; i += 2) {
646 encrypt_block(P, S, data, data);
647
648 P[i] = data[0];
649 P[i + 1] = data[1];
650 }
651
652 for (i = 0; i < 4; i++) {
653 for (j = 0, count = i * 256; j < 256; j += 2, count += 2) {
654 encrypt_block(P, S, data, data);
655
656 S[count] = data[0];
657 S[count + 1] = data[1];
658 }
659 }
660
661 return 0;
662}
663
664
665/*
666 * turn encryption off
667 */
668void
669dsp_bf_cleanup(struct dsp *dsp)
670{
671 dsp->bf_enable = 0;
672}
diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
new file mode 100644
index 000000000000..e92b1ba4b45e
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp_cmx.c
@@ -0,0 +1,1886 @@
1/*
2 * Audio crossconnecting/conferrencing (hardware level).
3 *
4 * Copyright 2002 by Andreas Eversberg (jolly@eversberg.eu)
5 *
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
8 *
9 */
10
11/*
12 * The process of adding and removing parties to/from a conference:
13 *
14 * There is a chain of struct dsp_conf which has one or more members in a chain
15 * of struct dsp_conf_member.
16 *
17 * After a party is added, the conference is checked for hardware capability.
18 * Also if a party is removed, the conference is checked again.
19 *
20 * There are 3 different solutions: -1 = software, 0 = hardware-crossconnect
21 * 1-n = hardware-conference. The n will give the conference number.
22 *
23 * Depending on the change after removal or insertion of a party, hardware
24 * commands are given.
25 *
26 * The current solution is stored within the struct dsp_conf entry.
27 */
28
29/*
30 * HOW THE CMX WORKS:
31 *
32 * There are 3 types of interaction: One member is alone, in this case only
33 * data flow from upper to lower layer is done.
34 * Two members will also exchange their data so they are crossconnected.
35 * Three or more members will be added in a conference and will hear each
36 * other but will not receive their own speech (echo) if not enabled.
37 *
38 * Features of CMX are:
39 * - Crossconnecting or even conference, if more than two members are together.
40 * - Force mixing of transmit data with other crossconnect/conference members.
41 * - Echo generation to benchmark the delay of audio processing.
42 * - Use hardware to minimize cpu load, disable FIFO load and minimize delay.
43 * - Dejittering and clock generation.
44 *
45 * There are 2 buffers:
46 *
47 *
48 * RX-Buffer
49 * R W
50 * | |
51 * ----------------+-------------+-------------------
52 *
53 * The rx-buffer is a ring buffer used to store the received data for each
54 * individual member. This is only the case if data needs to be dejittered
55 * or in case of a conference where different clocks require reclocking.
56 * The transmit-clock (R) will read the buffer.
57 * If the clock overruns the write-pointer, we will have a buffer underrun.
58 * If the write pointer always has a certain distance from the transmit-
59 * clock, we will have a delay. The delay will dynamically be increased and
60 * reduced.
61 *
62 *
63 * TX-Buffer
64 * R W
65 * | |
66 * -----------------+--------+-----------------------
67 *
68 * The tx-buffer is a ring buffer to queue the transmit data from user space
69 * until it will be mixed or sent. There are two pointers, R and W. If the write
70 * pointer W would reach or overrun R, the buffer would overrun. In this case
71 * (some) data is dropped so that it will not overrun.
72 * Additionally a dynamic dejittering can be enabled. this allows data from
73 * user space that have jitter and different clock source.
74 *
75 *
76 * Clock:
77 *
78 * A Clock is not required, if the data source has exactly one clock. In this
79 * case the data source is forwarded to the destination.
80 *
81 * A Clock is required, because the data source
82 * - has multiple clocks.
83 * - has no usable clock due to jitter or packet loss (VoIP).
84 * In this case the system's clock is used. The clock resolution depends on
85 * the jiffie resolution.
86 *
87 * If a member joins a conference:
88 *
89 * - If a member joins, its rx_buff is set to silence and change read pointer
90 * to transmit clock.
91 *
92 * The procedure of received data from card is explained in cmx_receive.
93 * The procedure of received data from user space is explained in cmx_transmit.
94 * The procedure of transmit data to card is cmx_send.
95 *
96 *
97 * Interaction with other features:
98 *
99 * DTMF:
100 * DTMF decoding is done before the data is crossconnected.
101 *
102 * Volume change:
103 * Changing rx-volume is done before the data is crossconnected. The tx-volume
104 * must be changed whenever data is transmitted to the card by the cmx.
105 *
106 * Tones:
107 * If a tone is enabled, it will be processed whenever data is transmitted to
108 * the card. It will replace the tx-data from the user space.
109 * If tones are generated by hardware, this conference member is removed for
110 * this time.
111 *
112 * Disable rx-data:
113 * If cmx is realized in hardware, rx data will be disabled if requested by
114 * the upper layer. If dtmf decoding is done by software and enabled, rx data
115 * will not be diabled but blocked to the upper layer.
116 *
117 * HFC conference engine:
118 * If it is possible to realize all features using hardware, hardware will be
119 * used if not forbidden by control command. Disabling rx-data provides
120 * absolutely traffic free audio processing. (except for the quick 1-frame
121 * upload of a tone loop, only once for a new tone)
122 *
123 */
124
125/* delay.h is required for hw_lock.h */
126
127#include <linux/delay.h>
128#include <linux/mISDNif.h>
129#include <linux/mISDNdsp.h>
130#include "core.h"
131#include "dsp.h"
132/*
133 * debugging of multi party conference,
134 * by using conference even with two members
135 */
136
137/* #define CMX_CONF_DEBUG */
138
139/*#define CMX_DEBUG * massive read/write pointer output */
140/*#define CMX_TX_DEBUG * massive read/write on tx-buffer with content */
141
142static inline int
143count_list_member(struct list_head *head)
144{
145 int cnt = 0;
146 struct list_head *m;
147
148 list_for_each(m, head)
149 cnt++;
150 return cnt;
151}
152
153/*
154 * debug cmx memory structure
155 */
156void
157dsp_cmx_debug(struct dsp *dsp)
158{
159 struct dsp_conf *conf;
160 struct dsp_conf_member *member;
161 struct dsp *odsp;
162
163 printk(KERN_DEBUG "-----Current DSP\n");
164 list_for_each_entry(odsp, &dsp_ilist, list) {
165 printk(KERN_DEBUG "* %s echo=%d txmix=%d",
166 odsp->name, odsp->echo, odsp->tx_mix);
167 if (odsp->conf)
168 printk(" (Conf %d)", odsp->conf->id);
169 if (dsp == odsp)
170 printk(" *this*");
171 printk("\n");
172 }
173 printk(KERN_DEBUG "-----Current Conf:\n");
174 list_for_each_entry(conf, &conf_ilist, list) {
175 printk(KERN_DEBUG "* Conf %d (%p)\n", conf->id, conf);
176 list_for_each_entry(member, &conf->mlist, list) {
177 printk(KERN_DEBUG
178 " - member = %s (slot_tx %d, bank_tx %d, "
179 "slot_rx %d, bank_rx %d hfc_conf %d)%s\n",
180 member->dsp->name, member->dsp->pcm_slot_tx,
181 member->dsp->pcm_bank_tx, member->dsp->pcm_slot_rx,
182 member->dsp->pcm_bank_rx, member->dsp->hfc_conf,
183 (member->dsp == dsp) ? " *this*" : "");
184 }
185 }
186 printk(KERN_DEBUG "-----end\n");
187}
188
189/*
190 * search conference
191 */
192static struct dsp_conf *
193dsp_cmx_search_conf(u32 id)
194{
195 struct dsp_conf *conf;
196
197 if (!id) {
198 printk(KERN_WARNING "%s: conference ID is 0.\n", __func__);
199 return NULL;
200 }
201
202 /* search conference */
203 list_for_each_entry(conf, &conf_ilist, list)
204 if (conf->id == id)
205 return conf;
206
207 return NULL;
208}
209
210
211/*
212 * add member to conference
213 */
214static int
215dsp_cmx_add_conf_member(struct dsp *dsp, struct dsp_conf *conf)
216{
217 struct dsp_conf_member *member;
218
219 if (!conf || !dsp) {
220 printk(KERN_WARNING "%s: conf or dsp is 0.\n", __func__);
221 return -EINVAL;
222 }
223 if (dsp->member) {
224 printk(KERN_WARNING "%s: dsp is already member in a conf.\n",
225 __func__);
226 return -EINVAL;
227 }
228
229 if (dsp->conf) {
230 printk(KERN_WARNING "%s: dsp is already in a conf.\n",
231 __func__);
232 return -EINVAL;
233 }
234
235 member = kzalloc(sizeof(struct dsp_conf_member), GFP_ATOMIC);
236 if (!member) {
237 printk(KERN_ERR "kmalloc struct dsp_conf_member failed\n");
238 return -ENOMEM;
239 }
240 member->dsp = dsp;
241 /* clear rx buffer */
242 memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
243 dsp->rx_init = 1; /* rx_W and rx_R will be adjusted on first frame */
244 dsp->rx_W = 0;
245 dsp->rx_R = 0;
246
247 list_add_tail(&member->list, &conf->mlist);
248
249 dsp->conf = conf;
250 dsp->member = member;
251
252 return 0;
253}
254
255
256/*
257 * del member from conference
258 */
259int
260dsp_cmx_del_conf_member(struct dsp *dsp)
261{
262 struct dsp_conf_member *member;
263
264 if (!dsp) {
265 printk(KERN_WARNING "%s: dsp is 0.\n",
266 __func__);
267 return -EINVAL;
268 }
269
270 if (!dsp->conf) {
271 printk(KERN_WARNING "%s: dsp is not in a conf.\n",
272 __func__);
273 return -EINVAL;
274 }
275
276 if (list_empty(&dsp->conf->mlist)) {
277 printk(KERN_WARNING "%s: dsp has linked an empty conf.\n",
278 __func__);
279 return -EINVAL;
280 }
281
282 /* find us in conf */
283 list_for_each_entry(member, &dsp->conf->mlist, list) {
284 if (member->dsp == dsp) {
285 list_del(&member->list);
286 dsp->conf = NULL;
287 dsp->member = NULL;
288 kfree(member);
289 return 0;
290 }
291 }
292 printk(KERN_WARNING
293 "%s: dsp is not present in its own conf_meber list.\n",
294 __func__);
295
296 return -EINVAL;
297}
298
299
300/*
301 * new conference
302 */
303static struct dsp_conf
304*dsp_cmx_new_conf(u32 id)
305{
306 struct dsp_conf *conf;
307
308 if (!id) {
309 printk(KERN_WARNING "%s: id is 0.\n",
310 __func__);
311 return NULL;
312 }
313
314 conf = kzalloc(sizeof(struct dsp_conf), GFP_ATOMIC);
315 if (!conf) {
316 printk(KERN_ERR "kmalloc struct dsp_conf failed\n");
317 return NULL;
318 }
319 INIT_LIST_HEAD(&conf->mlist);
320 conf->id = id;
321
322 list_add_tail(&conf->list, &conf_ilist);
323
324 return conf;
325}
326
327
328/*
329 * del conference
330 */
331int
332dsp_cmx_del_conf(struct dsp_conf *conf)
333{
334 if (!conf) {
335 printk(KERN_WARNING "%s: conf is null.\n",
336 __func__);
337 return -EINVAL;
338 }
339
340 if (!list_empty(&conf->mlist)) {
341 printk(KERN_WARNING "%s: conf not empty.\n",
342 __func__);
343 return -EINVAL;
344 }
345 list_del(&conf->list);
346 kfree(conf);
347
348 return 0;
349}
350
351
352/*
353 * send HW message to hfc card
354 */
355static void
356dsp_cmx_hw_message(struct dsp *dsp, u32 message, u32 param1, u32 param2,
357 u32 param3, u32 param4)
358{
359 struct mISDN_ctrl_req cq;
360
361 memset(&cq, 0, sizeof(cq));
362 cq.op = message;
363 cq.p1 = param1 | (param2 << 8);
364 cq.p2 = param3 | (param4 << 8);
365 if (dsp->ch.peer)
366 dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq);
367}
368
369
370/*
371 * do hardware update and set the software/hardware flag
372 *
373 * either a conference or a dsp instance can be given
374 * if only dsp instance is given, the instance is not associated with a conf
375 * and therefore removed. if a conference is given, the dsp is expected to
376 * be member of that conference.
377 */
378void
379dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp)
380{
381 struct dsp_conf_member *member, *nextm;
382 struct dsp *finddsp;
383 int memb = 0, i, ii, i1, i2;
384 int freeunits[8];
385 u_char freeslots[256];
386 int same_hfc = -1, same_pcm = -1, current_conf = -1,
387 all_conf = 1;
388
389 /* dsp gets updated (no conf) */
390 if (!conf) {
391 if (!dsp)
392 return;
393 if (dsp_debug & DEBUG_DSP_CMX)
394 printk(KERN_DEBUG "%s checking dsp %s\n",
395 __func__, dsp->name);
396one_member:
397 /* remove HFC conference if enabled */
398 if (dsp->hfc_conf >= 0) {
399 if (dsp_debug & DEBUG_DSP_CMX)
400 printk(KERN_DEBUG
401 "%s removing %s from HFC conf %d "
402 "because dsp is split\n", __func__,
403 dsp->name, dsp->hfc_conf);
404 dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_CONF_SPLIT,
405 0, 0, 0, 0);
406 dsp->hfc_conf = -1;
407 }
408 /* process hw echo */
409 if (dsp->features.pcm_banks < 1)
410 return;
411 if (!dsp->echo) {
412 /* NO ECHO: remove PCM slot if assigned */
413 if (dsp->pcm_slot_tx >= 0 || dsp->pcm_slot_rx >= 0) {
414 if (dsp_debug & DEBUG_DSP_CMX)
415 printk(KERN_DEBUG "%s removing %s from"
416 " PCM slot %d (TX) %d (RX) because"
417 " dsp is split (no echo)\n",
418 __func__, dsp->name,
419 dsp->pcm_slot_tx, dsp->pcm_slot_rx);
420 dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_DISC,
421 0, 0, 0, 0);
422 dsp->pcm_slot_tx = -1;
423 dsp->pcm_bank_tx = -1;
424 dsp->pcm_slot_rx = -1;
425 dsp->pcm_bank_rx = -1;
426 }
427 return;
428 }
429 /* ECHO: already echo */
430 if (dsp->pcm_slot_tx >= 0 && dsp->pcm_slot_rx < 0 &&
431 dsp->pcm_bank_tx == 2 && dsp->pcm_bank_rx == 2)
432 return;
433 /* ECHO: if slot already assigned */
434 if (dsp->pcm_slot_tx >= 0) {
435 dsp->pcm_slot_rx = dsp->pcm_slot_tx;
436 dsp->pcm_bank_tx = 2; /* 2 means loop */
437 dsp->pcm_bank_rx = 2;
438 if (dsp_debug & DEBUG_DSP_CMX)
439 printk(KERN_DEBUG
440 "%s refresh %s for echo using slot %d\n",
441 __func__, dsp->name,
442 dsp->pcm_slot_tx);
443 dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_CONN,
444 dsp->pcm_slot_tx, 2, dsp->pcm_slot_rx, 2);
445 return;
446 }
447 /* ECHO: find slot */
448 dsp->pcm_slot_tx = -1;
449 dsp->pcm_slot_rx = -1;
450 memset(freeslots, 1, sizeof(freeslots));
451 list_for_each_entry(finddsp, &dsp_ilist, list) {
452 if (finddsp->features.pcm_id == dsp->features.pcm_id) {
453 if (finddsp->pcm_slot_rx >= 0 &&
454 finddsp->pcm_slot_rx < sizeof(freeslots))
455 freeslots[finddsp->pcm_slot_tx] = 0;
456 if (finddsp->pcm_slot_tx >= 0 &&
457 finddsp->pcm_slot_tx < sizeof(freeslots))
458 freeslots[finddsp->pcm_slot_rx] = 0;
459 }
460 }
461 i = 0;
462 ii = dsp->features.pcm_slots;
463 while (i < ii) {
464 if (freeslots[i])
465 break;
466 i++;
467 }
468 if (i == ii) {
469 if (dsp_debug & DEBUG_DSP_CMX)
470 printk(KERN_DEBUG
471 "%s no slot available for echo\n",
472 __func__);
473 /* no more slots available */
474 return;
475 }
476 /* assign free slot */
477 dsp->pcm_slot_tx = i;
478 dsp->pcm_slot_rx = i;
479 dsp->pcm_bank_tx = 2; /* loop */
480 dsp->pcm_bank_rx = 2;
481 if (dsp_debug & DEBUG_DSP_CMX)
482 printk(KERN_DEBUG
483 "%s assign echo for %s using slot %d\n",
484 __func__, dsp->name, dsp->pcm_slot_tx);
485 dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_CONN,
486 dsp->pcm_slot_tx, 2, dsp->pcm_slot_rx, 2);
487 return;
488 }
489
490 /* conf gets updated (all members) */
491 if (dsp_debug & DEBUG_DSP_CMX)
492 printk(KERN_DEBUG "%s checking conference %d\n",
493 __func__, conf->id);
494
495 if (list_empty(&conf->mlist)) {
496 printk(KERN_ERR "%s: conference whithout members\n",
497 __func__);
498 return;
499 }
500 member = list_entry(conf->mlist.next, struct dsp_conf_member, list);
501 same_hfc = member->dsp->features.hfc_id;
502 same_pcm = member->dsp->features.pcm_id;
503 /* check all members in our conference */
504 list_for_each_entry(member, &conf->mlist, list) {
505 /* check if member uses mixing */
506 if (member->dsp->tx_mix) {
507 if (dsp_debug & DEBUG_DSP_CMX)
508 printk(KERN_DEBUG
509 "%s dsp %s cannot form a conf, because "
510 "tx_mix is turned on\n", __func__,
511 member->dsp->name);
512conf_software:
513 list_for_each_entry(member, &conf->mlist, list) {
514 dsp = member->dsp;
515 /* remove HFC conference if enabled */
516 if (dsp->hfc_conf >= 0) {
517 if (dsp_debug & DEBUG_DSP_CMX)
518 printk(KERN_DEBUG
519 "%s removing %s from HFC "
520 "conf %d because not "
521 "possible with hardware\n",
522 __func__,
523 dsp->name,
524 dsp->hfc_conf);
525 dsp_cmx_hw_message(dsp,
526 MISDN_CTRL_HFC_CONF_SPLIT,
527 0, 0, 0, 0);
528 dsp->hfc_conf = -1;
529 }
530 /* remove PCM slot if assigned */
531 if (dsp->pcm_slot_tx >= 0 ||
532 dsp->pcm_slot_rx >= 0) {
533 if (dsp_debug & DEBUG_DSP_CMX)
534 printk(KERN_DEBUG "%s removing "
535 "%s from PCM slot %d (TX)"
536 " slot %d (RX) because not"
537 " possible with hardware\n",
538 __func__,
539 dsp->name,
540 dsp->pcm_slot_tx,
541 dsp->pcm_slot_rx);
542 dsp_cmx_hw_message(dsp,
543 MISDN_CTRL_HFC_PCM_DISC,
544 0, 0, 0, 0);
545 dsp->pcm_slot_tx = -1;
546 dsp->pcm_bank_tx = -1;
547 dsp->pcm_slot_rx = -1;
548 dsp->pcm_bank_rx = -1;
549 }
550 }
551 conf->hardware = 0;
552 conf->software = 1;
553 return;
554 }
555 /* check if member has echo turned on */
556 if (member->dsp->echo) {
557 if (dsp_debug & DEBUG_DSP_CMX)
558 printk(KERN_DEBUG
559 "%s dsp %s cannot form a conf, because "
560 "echo is turned on\n", __func__,
561 member->dsp->name);
562 goto conf_software;
563 }
564 /* check if member has tx_mix turned on */
565 if (member->dsp->tx_mix) {
566 if (dsp_debug & DEBUG_DSP_CMX)
567 printk(KERN_DEBUG
568 "%s dsp %s cannot form a conf, because "
569 "tx_mix is turned on\n",
570 __func__, member->dsp->name);
571 goto conf_software;
572 }
573 /* check if member changes volume at an not suppoted level */
574 if (member->dsp->tx_volume) {
575 if (dsp_debug & DEBUG_DSP_CMX)
576 printk(KERN_DEBUG
577 "%s dsp %s cannot form a conf, because "
578 "tx_volume is changed\n",
579 __func__, member->dsp->name);
580 goto conf_software;
581 }
582 if (member->dsp->rx_volume) {
583 if (dsp_debug & DEBUG_DSP_CMX)
584 printk(KERN_DEBUG
585 "%s dsp %s cannot form a conf, because "
586 "rx_volume is changed\n",
587 __func__, member->dsp->name);
588 goto conf_software;
589 }
590 /* check if tx-data turned on */
591 if (member->dsp->tx_data) {
592 if (dsp_debug & DEBUG_DSP_CMX)
593 printk(KERN_DEBUG
594 "%s dsp %s cannot form a conf, because "
595 "tx_data is turned on\n",
596 __func__, member->dsp->name);
597 goto conf_software;
598 }
599 /* check if pipeline exists */
600 if (member->dsp->pipeline.inuse) {
601 if (dsp_debug & DEBUG_DSP_CMX)
602 printk(KERN_DEBUG
603 "%s dsp %s cannot form a conf, because "
604 "pipeline exists\n", __func__,
605 member->dsp->name);
606 goto conf_software;
607 }
608 /* check if encryption is enabled */
609 if (member->dsp->bf_enable) {
610 if (dsp_debug & DEBUG_DSP_CMX)
611 printk(KERN_DEBUG "%s dsp %s cannot form a "
612 "conf, because encryption is enabled\n",
613 __func__, member->dsp->name);
614 goto conf_software;
615 }
616 /* check if member is on a card with PCM support */
617 if (member->dsp->features.pcm_id < 0) {
618 if (dsp_debug & DEBUG_DSP_CMX)
619 printk(KERN_DEBUG
620 "%s dsp %s cannot form a conf, because "
621 "dsp has no PCM bus\n",
622 __func__, member->dsp->name);
623 goto conf_software;
624 }
625 /* check if relations are on the same PCM bus */
626 if (member->dsp->features.pcm_id != same_pcm) {
627 if (dsp_debug & DEBUG_DSP_CMX)
628 printk(KERN_DEBUG
629 "%s dsp %s cannot form a conf, because "
630 "dsp is on a different PCM bus than the "
631 "first dsp\n",
632 __func__, member->dsp->name);
633 goto conf_software;
634 }
635 /* determine if members are on the same hfc chip */
636 if (same_hfc != member->dsp->features.hfc_id)
637 same_hfc = -1;
638 /* if there are members already in a conference */
639 if (current_conf < 0 && member->dsp->hfc_conf >= 0)
640 current_conf = member->dsp->hfc_conf;
641 /* if any member is not in a conference */
642 if (member->dsp->hfc_conf < 0)
643 all_conf = 0;
644
645 memb++;
646 }
647
648 /* if no member, this is an error */
649 if (memb < 1)
650 return;
651
652 /* one member */
653 if (memb == 1) {
654 if (dsp_debug & DEBUG_DSP_CMX)
655 printk(KERN_DEBUG
656 "%s conf %d cannot form a HW conference, "
657 "because dsp is alone\n", __func__, conf->id);
658 conf->hardware = 0;
659 conf->software = 0;
660 member = list_entry(conf->mlist.next, struct dsp_conf_member,
661 list);
662 dsp = member->dsp;
663 goto one_member;
664 }
665
666 /*
667 * ok, now we are sure that all members are on the same pcm.
668 * now we will see if we have only two members, so we can do
669 * crossconnections, which don't have any limitations.
670 */
671
672 /* if we have only two members */
673 if (memb == 2) {
674 member = list_entry(conf->mlist.next, struct dsp_conf_member,
675 list);
676 nextm = list_entry(member->list.next, struct dsp_conf_member,
677 list);
678 /* remove HFC conference if enabled */
679 if (member->dsp->hfc_conf >= 0) {
680 if (dsp_debug & DEBUG_DSP_CMX)
681 printk(KERN_DEBUG
682 "%s removing %s from HFC conf %d because "
683 "two parties require only a PCM slot\n",
684 __func__, member->dsp->name,
685 member->dsp->hfc_conf);
686 dsp_cmx_hw_message(member->dsp,
687 MISDN_CTRL_HFC_CONF_SPLIT, 0, 0, 0, 0);
688 member->dsp->hfc_conf = -1;
689 }
690 if (nextm->dsp->hfc_conf >= 0) {
691 if (dsp_debug & DEBUG_DSP_CMX)
692 printk(KERN_DEBUG
693 "%s removing %s from HFC conf %d because "
694 "two parties require only a PCM slot\n",
695 __func__, nextm->dsp->name,
696 nextm->dsp->hfc_conf);
697 dsp_cmx_hw_message(nextm->dsp,
698 MISDN_CTRL_HFC_CONF_SPLIT, 0, 0, 0, 0);
699 nextm->dsp->hfc_conf = -1;
700 }
701 /* if members have two banks (and not on the same chip) */
702 if (member->dsp->features.pcm_banks > 1 &&
703 nextm->dsp->features.pcm_banks > 1 &&
704 member->dsp->features.hfc_id !=
705 nextm->dsp->features.hfc_id) {
706 /* if both members have same slots with crossed banks */
707 if (member->dsp->pcm_slot_tx >= 0 &&
708 member->dsp->pcm_slot_rx >= 0 &&
709 nextm->dsp->pcm_slot_tx >= 0 &&
710 nextm->dsp->pcm_slot_rx >= 0 &&
711 nextm->dsp->pcm_slot_tx ==
712 member->dsp->pcm_slot_rx &&
713 nextm->dsp->pcm_slot_rx ==
714 member->dsp->pcm_slot_tx &&
715 nextm->dsp->pcm_slot_tx ==
716 member->dsp->pcm_slot_tx &&
717 member->dsp->pcm_bank_tx !=
718 member->dsp->pcm_bank_rx &&
719 nextm->dsp->pcm_bank_tx !=
720 nextm->dsp->pcm_bank_rx) {
721 /* all members have same slot */
722 if (dsp_debug & DEBUG_DSP_CMX)
723 printk(KERN_DEBUG
724 "%s dsp %s & %s stay joined on "
725 "PCM slot %d bank %d (TX) bank %d "
726 "(RX) (on different chips)\n",
727 __func__,
728 member->dsp->name,
729 nextm->dsp->name,
730 member->dsp->pcm_slot_tx,
731 member->dsp->pcm_bank_tx,
732 member->dsp->pcm_bank_rx);
733 conf->hardware = 0;
734 conf->software = 1;
735 return;
736 }
737 /* find a new slot */
738 memset(freeslots, 1, sizeof(freeslots));
739 list_for_each_entry(dsp, &dsp_ilist, list) {
740 if (dsp != member->dsp &&
741 dsp != nextm->dsp &&
742 member->dsp->features.pcm_id ==
743 dsp->features.pcm_id) {
744 if (dsp->pcm_slot_rx >= 0 &&
745 dsp->pcm_slot_rx <
746 sizeof(freeslots))
747 freeslots[dsp->pcm_slot_tx] = 0;
748 if (dsp->pcm_slot_tx >= 0 &&
749 dsp->pcm_slot_tx <
750 sizeof(freeslots))
751 freeslots[dsp->pcm_slot_rx] = 0;
752 }
753 }
754 i = 0;
755 ii = member->dsp->features.pcm_slots;
756 while (i < ii) {
757 if (freeslots[i])
758 break;
759 i++;
760 }
761 if (i == ii) {
762 if (dsp_debug & DEBUG_DSP_CMX)
763 printk(KERN_DEBUG
764 "%s no slot available for "
765 "%s & %s\n", __func__,
766 member->dsp->name,
767 nextm->dsp->name);
768 /* no more slots available */
769 goto conf_software;
770 }
771 /* assign free slot */
772 member->dsp->pcm_slot_tx = i;
773 member->dsp->pcm_slot_rx = i;
774 nextm->dsp->pcm_slot_tx = i;
775 nextm->dsp->pcm_slot_rx = i;
776 member->dsp->pcm_bank_rx = 0;
777 member->dsp->pcm_bank_tx = 1;
778 nextm->dsp->pcm_bank_rx = 1;
779 nextm->dsp->pcm_bank_tx = 0;
780 if (dsp_debug & DEBUG_DSP_CMX)
781 printk(KERN_DEBUG
782 "%s adding %s & %s to new PCM slot %d "
783 "(TX and RX on different chips) because "
784 "both members have not same slots\n",
785 __func__,
786 member->dsp->name,
787 nextm->dsp->name,
788 member->dsp->pcm_slot_tx);
789 dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
790 member->dsp->pcm_slot_tx, member->dsp->pcm_bank_tx,
791 member->dsp->pcm_slot_rx, member->dsp->pcm_bank_rx);
792 dsp_cmx_hw_message(nextm->dsp, MISDN_CTRL_HFC_PCM_CONN,
793 nextm->dsp->pcm_slot_tx, nextm->dsp->pcm_bank_tx,
794 nextm->dsp->pcm_slot_rx, nextm->dsp->pcm_bank_rx);
795 conf->hardware = 1;
796 conf->software = 0;
797 return;
798 /* if members have one bank (or on the same chip) */
799 } else {
800 /* if both members have different crossed slots */
801 if (member->dsp->pcm_slot_tx >= 0 &&
802 member->dsp->pcm_slot_rx >= 0 &&
803 nextm->dsp->pcm_slot_tx >= 0 &&
804 nextm->dsp->pcm_slot_rx >= 0 &&
805 nextm->dsp->pcm_slot_tx ==
806 member->dsp->pcm_slot_rx &&
807 nextm->dsp->pcm_slot_rx ==
808 member->dsp->pcm_slot_tx &&
809 member->dsp->pcm_slot_tx !=
810 member->dsp->pcm_slot_rx &&
811 member->dsp->pcm_bank_tx == 0 &&
812 member->dsp->pcm_bank_rx == 0 &&
813 nextm->dsp->pcm_bank_tx == 0 &&
814 nextm->dsp->pcm_bank_rx == 0) {
815 /* all members have same slot */
816 if (dsp_debug & DEBUG_DSP_CMX)
817 printk(KERN_DEBUG
818 "%s dsp %s & %s stay joined on PCM "
819 "slot %d (TX) %d (RX) on same chip "
820 "or one bank PCM)\n", __func__,
821 member->dsp->name,
822 nextm->dsp->name,
823 member->dsp->pcm_slot_tx,
824 member->dsp->pcm_slot_rx);
825 conf->hardware = 0;
826 conf->software = 1;
827 return;
828 }
829 /* find two new slot */
830 memset(freeslots, 1, sizeof(freeslots));
831 list_for_each_entry(dsp, &dsp_ilist, list) {
832 if (dsp != member->dsp &&
833 dsp != nextm->dsp &&
834 member->dsp->features.pcm_id ==
835 dsp->features.pcm_id) {
836 if (dsp->pcm_slot_rx >= 0 &&
837 dsp->pcm_slot_rx <
838 sizeof(freeslots))
839 freeslots[dsp->pcm_slot_tx] = 0;
840 if (dsp->pcm_slot_tx >= 0 &&
841 dsp->pcm_slot_tx <
842 sizeof(freeslots))
843 freeslots[dsp->pcm_slot_rx] = 0;
844 }
845 }
846 i1 = 0;
847 ii = member->dsp->features.pcm_slots;
848 while (i1 < ii) {
849 if (freeslots[i1])
850 break;
851 i1++;
852 }
853 if (i1 == ii) {
854 if (dsp_debug & DEBUG_DSP_CMX)
855 printk(KERN_DEBUG
856 "%s no slot available "
857 "for %s & %s\n", __func__,
858 member->dsp->name,
859 nextm->dsp->name);
860 /* no more slots available */
861 goto conf_software;
862 }
863 i2 = i1+1;
864 while (i2 < ii) {
865 if (freeslots[i2])
866 break;
867 i2++;
868 }
869 if (i2 == ii) {
870 if (dsp_debug & DEBUG_DSP_CMX)
871 printk(KERN_DEBUG
872 "%s no slot available "
873 "for %s & %s\n",
874 __func__,
875 member->dsp->name,
876 nextm->dsp->name);
877 /* no more slots available */
878 goto conf_software;
879 }
880 /* assign free slots */
881 member->dsp->pcm_slot_tx = i1;
882 member->dsp->pcm_slot_rx = i2;
883 nextm->dsp->pcm_slot_tx = i2;
884 nextm->dsp->pcm_slot_rx = i1;
885 member->dsp->pcm_bank_rx = 0;
886 member->dsp->pcm_bank_tx = 0;
887 nextm->dsp->pcm_bank_rx = 0;
888 nextm->dsp->pcm_bank_tx = 0;
889 if (dsp_debug & DEBUG_DSP_CMX)
890 printk(KERN_DEBUG
891 "%s adding %s & %s to new PCM slot %d "
892 "(TX) %d (RX) on same chip or one bank "
893 "PCM, because both members have not "
894 "crossed slots\n", __func__,
895 member->dsp->name,
896 nextm->dsp->name,
897 member->dsp->pcm_slot_tx,
898 member->dsp->pcm_slot_rx);
899 dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
900 member->dsp->pcm_slot_tx, member->dsp->pcm_bank_tx,
901 member->dsp->pcm_slot_rx, member->dsp->pcm_bank_rx);
902 dsp_cmx_hw_message(nextm->dsp, MISDN_CTRL_HFC_PCM_CONN,
903 nextm->dsp->pcm_slot_tx, nextm->dsp->pcm_bank_tx,
904 nextm->dsp->pcm_slot_rx, nextm->dsp->pcm_bank_rx);
905 conf->hardware = 1;
906 conf->software = 0;
907 return;
908 }
909 }
910
911 /*
912 * if we have more than two, we may check if we have a conference
913 * unit available on the chip. also all members must be on the same
914 */
915
916 /* if not the same HFC chip */
917 if (same_hfc < 0) {
918 if (dsp_debug & DEBUG_DSP_CMX)
919 printk(KERN_DEBUG
920 "%s conference %d cannot be formed, because "
921 "members are on different chips or not "
922 "on HFC chip\n",
923 __func__, conf->id);
924 goto conf_software;
925 }
926
927 /* for more than two members.. */
928
929 /* in case of hdlc, we change to software */
930 if (dsp->hdlc)
931 goto conf_software;
932
933 /* if all members already have the same conference */
934 if (all_conf)
935 return;
936
937 /*
938 * if there is an existing conference, but not all members have joined
939 */
940 if (current_conf >= 0) {
941join_members:
942 list_for_each_entry(member, &conf->mlist, list) {
943 /* join to current conference */
944 if (member->dsp->hfc_conf == current_conf)
945 continue;
946 /* get a free timeslot first */
947 memset(freeslots, 1, sizeof(freeslots));
948 list_for_each_entry(dsp, &dsp_ilist, list) {
949 /*
950 * not checking current member, because
951 * slot will be overwritten.
952 */
953 if (
954 dsp != member->dsp &&
955 /* dsp must be on the same PCM */
956 member->dsp->features.pcm_id ==
957 dsp->features.pcm_id) {
958 /* dsp must be on a slot */
959 if (dsp->pcm_slot_tx >= 0 &&
960 dsp->pcm_slot_tx <
961 sizeof(freeslots))
962 freeslots[dsp->pcm_slot_tx] = 0;
963 if (dsp->pcm_slot_rx >= 0 &&
964 dsp->pcm_slot_rx <
965 sizeof(freeslots))
966 freeslots[dsp->pcm_slot_rx] = 0;
967 }
968 }
969 i = 0;
970 ii = member->dsp->features.pcm_slots;
971 while (i < ii) {
972 if (freeslots[i])
973 break;
974 i++;
975 }
976 if (i == ii) {
977 /* no more slots available */
978 if (dsp_debug & DEBUG_DSP_CMX)
979 printk(KERN_DEBUG
980 "%s conference %d cannot be formed,"
981 " because no slot free\n",
982 __func__, conf->id);
983 goto conf_software;
984 }
985 if (dsp_debug & DEBUG_DSP_CMX)
986 printk(KERN_DEBUG
987 "%s changing dsp %s to HW conference "
988 "%d slot %d\n", __func__,
989 member->dsp->name, current_conf, i);
990 /* assign free slot & set PCM & join conf */
991 member->dsp->pcm_slot_tx = i;
992 member->dsp->pcm_slot_rx = i;
993 member->dsp->pcm_bank_tx = 2; /* loop */
994 member->dsp->pcm_bank_rx = 2;
995 member->dsp->hfc_conf = current_conf;
996 dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
997 i, 2, i, 2);
998 dsp_cmx_hw_message(member->dsp,
999 MISDN_CTRL_HFC_CONF_JOIN, current_conf, 0, 0, 0);
1000 }
1001 return;
1002 }
1003
1004 /*
1005 * no member is in a conference yet, so we find a free one
1006 */
1007 memset(freeunits, 1, sizeof(freeunits));
1008 list_for_each_entry(dsp, &dsp_ilist, list) {
1009 /* dsp must be on the same chip */
1010 if (dsp->features.hfc_id == same_hfc &&
1011 /* dsp must have joined a HW conference */
1012 dsp->hfc_conf >= 0 &&
1013 /* slot must be within range */
1014 dsp->hfc_conf < 8)
1015 freeunits[dsp->hfc_conf] = 0;
1016 }
1017 i = 0;
1018 ii = 8;
1019 while (i < ii) {
1020 if (freeunits[i])
1021 break;
1022 i++;
1023 }
1024 if (i == ii) {
1025 /* no more conferences available */
1026 if (dsp_debug & DEBUG_DSP_CMX)
1027 printk(KERN_DEBUG
1028 "%s conference %d cannot be formed, because "
1029 "no conference number free\n",
1030 __func__, conf->id);
1031 goto conf_software;
1032 }
1033 /* join all members */
1034 current_conf = i;
1035 goto join_members;
1036}
1037
1038
1039/*
1040 * conf_id != 0: join or change conference
1041 * conf_id == 0: split from conference if not already
1042 */
1043int
1044dsp_cmx_conf(struct dsp *dsp, u32 conf_id)
1045{
1046 int err;
1047 struct dsp_conf *conf;
1048 struct dsp_conf_member *member;
1049
1050 /* if conference doesn't change */
1051 if (dsp->conf_id == conf_id)
1052 return 0;
1053
1054 /* first remove us from current conf */
1055 if (dsp->conf_id) {
1056 if (dsp_debug & DEBUG_DSP_CMX)
1057 printk(KERN_DEBUG "removing us from conference %d\n",
1058 dsp->conf->id);
1059 /* remove us from conf */
1060 conf = dsp->conf;
1061 err = dsp_cmx_del_conf_member(dsp);
1062 if (err)
1063 return err;
1064 dsp->conf_id = 0;
1065
1066 /* update hardware */
1067 dsp_cmx_hardware(NULL, dsp);
1068
1069 /* conf now empty? */
1070 if (list_empty(&conf->mlist)) {
1071 if (dsp_debug & DEBUG_DSP_CMX)
1072 printk(KERN_DEBUG
1073 "conference is empty, so we remove it.\n");
1074 err = dsp_cmx_del_conf(conf);
1075 if (err)
1076 return err;
1077 } else {
1078 /* update members left on conf */
1079 dsp_cmx_hardware(conf, NULL);
1080 }
1081 }
1082
1083 /* if split */
1084 if (!conf_id)
1085 return 0;
1086
1087 /* now add us to conf */
1088 if (dsp_debug & DEBUG_DSP_CMX)
1089 printk(KERN_DEBUG "searching conference %d\n",
1090 conf_id);
1091 conf = dsp_cmx_search_conf(conf_id);
1092 if (!conf) {
1093 if (dsp_debug & DEBUG_DSP_CMX)
1094 printk(KERN_DEBUG
1095 "conference doesn't exist yet, creating.\n");
1096 /* the conference doesn't exist, so we create */
1097 conf = dsp_cmx_new_conf(conf_id);
1098 if (!conf)
1099 return -EINVAL;
1100 } else if (!list_empty(&conf->mlist)) {
1101 member = list_entry(conf->mlist.next, struct dsp_conf_member,
1102 list);
1103 if (dsp->hdlc && !member->dsp->hdlc) {
1104 if (dsp_debug & DEBUG_DSP_CMX)
1105 printk(KERN_DEBUG
1106 "cannot join transparent conference.\n");
1107 return -EINVAL;
1108 }
1109 if (!dsp->hdlc && member->dsp->hdlc) {
1110 if (dsp_debug & DEBUG_DSP_CMX)
1111 printk(KERN_DEBUG
1112 "cannot join hdlc conference.\n");
1113 return -EINVAL;
1114 }
1115 }
1116 /* add conference member */
1117 err = dsp_cmx_add_conf_member(dsp, conf);
1118 if (err)
1119 return err;
1120 dsp->conf_id = conf_id;
1121
1122 /* if we are alone, we do nothing! */
1123 if (list_empty(&conf->mlist)) {
1124 if (dsp_debug & DEBUG_DSP_CMX)
1125 printk(KERN_DEBUG
1126 "we are alone in this conference, so exit.\n");
1127 /* update hardware */
1128 dsp_cmx_hardware(NULL, dsp);
1129 return 0;
1130 }
1131
1132 /* update members on conf */
1133 dsp_cmx_hardware(conf, NULL);
1134
1135 return 0;
1136}
1137
1138
1139/*
1140 * audio data is received from card
1141 */
1142void
1143dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb)
1144{
1145 u8 *d, *p;
1146 int len = skb->len;
1147 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1148 int w, i, ii;
1149
1150 /* check if we have sompen */
1151 if (len < 1)
1152 return;
1153
1154 /* half of the buffer should be larger than maximum packet size */
1155 if (len >= CMX_BUFF_HALF) {
1156 printk(KERN_ERR
1157 "%s line %d: packet from card is too large (%d bytes). "
1158 "please make card send smaller packets OR increase "
1159 "CMX_BUFF_SIZE\n", __FILE__, __LINE__, len);
1160 return;
1161 }
1162
1163 /*
1164 * initialize pointers if not already -
1165 * also add delay if requested by PH_SIGNAL
1166 */
1167 if (dsp->rx_init) {
1168 dsp->rx_init = 0;
1169 if (dsp->features.unordered) {
1170 dsp->rx_R = (hh->id & CMX_BUFF_MASK);
1171 dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
1172 & CMX_BUFF_MASK;
1173 } else {
1174 dsp->rx_R = 0;
1175 dsp->rx_W = dsp->cmx_delay;
1176 }
1177 }
1178 /* if frame contains time code, write directly */
1179 if (dsp->features.unordered) {
1180 dsp->rx_W = (hh->id & CMX_BUFF_MASK);
1181 /* printk(KERN_DEBUG "%s %08x\n", dsp->name, hh->id); */
1182 }
1183 /*
1184 * if we underrun (or maybe overrun),
1185 * we set our new read pointer, and write silence to buffer
1186 */
1187 if (((dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK) >= CMX_BUFF_HALF) {
1188 if (dsp_debug & DEBUG_DSP_CMX)
1189 printk(KERN_DEBUG
1190 "cmx_receive(dsp=%lx): UNDERRUN (or overrun the "
1191 "maximum delay), adjusting read pointer! "
1192 "(inst %s)\n", (u_long)dsp, dsp->name);
1193 /* flush buffer */
1194 if (dsp->features.unordered) {
1195 dsp->rx_R = (hh->id & CMX_BUFF_MASK);
1196 dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
1197 & CMX_BUFF_MASK;
1198 } else {
1199 dsp->rx_R = 0;
1200 dsp->rx_W = dsp->cmx_delay;
1201 }
1202 memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
1203 }
1204 /* if we have reached double delay, jump back to middle */
1205 if (dsp->cmx_delay)
1206 if (((dsp->rx_W - dsp->rx_R) & CMX_BUFF_MASK) >=
1207 (dsp->cmx_delay << 1)) {
1208 if (dsp_debug & DEBUG_DSP_CMX)
1209 printk(KERN_DEBUG
1210 "cmx_receive(dsp=%lx): OVERRUN (because "
1211 "twice the delay is reached), adjusting "
1212 "read pointer! (inst %s)\n",
1213 (u_long)dsp, dsp->name);
1214 /* flush buffer */
1215 if (dsp->features.unordered) {
1216 dsp->rx_R = (hh->id & CMX_BUFF_MASK);
1217 dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
1218 & CMX_BUFF_MASK;
1219 } else {
1220 dsp->rx_R = 0;
1221 dsp->rx_W = dsp->cmx_delay;
1222 }
1223 memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
1224 }
1225
1226 /* show where to write */
1227#ifdef CMX_DEBUG
1228 printk(KERN_DEBUG
1229 "cmx_receive(dsp=%lx): rx_R(dsp)=%05x rx_W(dsp)=%05x len=%d %s\n",
1230 (u_long)dsp, dsp->rx_R, dsp->rx_W, len, dsp->name);
1231#endif
1232
1233 /* write data into rx_buffer */
1234 p = skb->data;
1235 d = dsp->rx_buff;
1236 w = dsp->rx_W;
1237 i = 0;
1238 ii = len;
1239 while (i < ii) {
1240 d[w++ & CMX_BUFF_MASK] = *p++;
1241 i++;
1242 }
1243
1244 /* increase write-pointer */
1245 dsp->rx_W = ((dsp->rx_W+len) & CMX_BUFF_MASK);
1246}
1247
1248
1249/*
1250 * send (mixed) audio data to card and control jitter
1251 */
1252static void
1253dsp_cmx_send_member(struct dsp *dsp, int len, s32 *c, int members)
1254{
1255 struct dsp_conf *conf = dsp->conf;
1256 struct dsp *member, *other;
1257 register s32 sample;
1258 u8 *d, *p, *q, *o_q;
1259 struct sk_buff *nskb, *txskb;
1260 int r, rr, t, tt, o_r, o_rr;
1261 int preload = 0;
1262 struct mISDNhead *hh, *thh;
1263
1264 /* don't process if: */
1265 if (!dsp->b_active) { /* if not active */
1266 dsp->last_tx = 0;
1267 return;
1268 }
1269 if (dsp->pcm_slot_tx >= 0 && /* connected to pcm slot */
1270 dsp->tx_R == dsp->tx_W && /* AND no tx-data */
1271 !(dsp->tone.tone && dsp->tone.software)) { /* AND not soft tones */
1272 dsp->last_tx = 0;
1273 return;
1274 }
1275
1276#ifdef CMX_DEBUG
1277 printk(KERN_DEBUG
1278 "SEND members=%d dsp=%s, conf=%p, rx_R=%05x rx_W=%05x\n",
1279 members, dsp->name, conf, dsp->rx_R, dsp->rx_W);
1280#endif
1281
1282 /* preload if we have delay set */
1283 if (dsp->cmx_delay && !dsp->last_tx) {
1284 preload = len;
1285 if (preload < 128)
1286 preload = 128;
1287 }
1288
1289 /* PREPARE RESULT */
1290 nskb = mI_alloc_skb(len + preload, GFP_ATOMIC);
1291 if (!nskb) {
1292 printk(KERN_ERR
1293 "FATAL ERROR in mISDN_dsp.o: cannot alloc %d bytes\n",
1294 len + preload);
1295 return;
1296 }
1297 hh = mISDN_HEAD_P(nskb);
1298 hh->prim = PH_DATA_REQ;
1299 hh->id = 0;
1300 dsp->last_tx = 1;
1301
1302 /* set pointers, indexes and stuff */
1303 member = dsp;
1304 p = dsp->tx_buff; /* transmit data */
1305 q = dsp->rx_buff; /* received data */
1306 d = skb_put(nskb, preload + len); /* result */
1307 t = dsp->tx_R; /* tx-pointers */
1308 tt = dsp->tx_W;
1309 r = dsp->rx_R; /* rx-pointers */
1310 rr = (r + len) & CMX_BUFF_MASK;
1311
1312 /* preload with silence, if required */
1313 if (preload) {
1314 memset(d, dsp_silence, preload);
1315 d += preload;
1316 }
1317
1318 /* PROCESS TONES/TX-DATA ONLY */
1319 if (dsp->tone.tone && dsp->tone.software) {
1320 /* -> copy tone */
1321 dsp_tone_copy(dsp, d, len);
1322 dsp->tx_R = 0; /* clear tx buffer */
1323 dsp->tx_W = 0;
1324 goto send_packet;
1325 }
1326 /* if we have tx-data but do not use mixing */
1327 if (!dsp->tx_mix && t != tt) {
1328 /* -> send tx-data and continue when not enough */
1329#ifdef CMX_TX_DEBUG
1330 sprintf(debugbuf, "TX sending (%04x-%04x)%p: ", t, tt, p);
1331#endif
1332 while (r != rr && t != tt) {
1333#ifdef CMX_TX_DEBUG
1334 if (strlen(debugbuf) < 48)
1335 sprintf(debugbuf+strlen(debugbuf), " %02x", p[t]);
1336#endif
1337 *d++ = p[t]; /* write tx_buff */
1338 t = (t+1) & CMX_BUFF_MASK;
1339 r = (r+1) & CMX_BUFF_MASK;
1340 }
1341 if (r == rr) {
1342 dsp->tx_R = t;
1343#ifdef CMX_TX_DEBUG
1344 printk(KERN_DEBUG "%s\n", debugbuf);
1345#endif
1346 goto send_packet;
1347 }
1348 }
1349#ifdef CMX_TX_DEBUG
1350 printk(KERN_DEBUG "%s\n", debugbuf);
1351#endif
1352
1353 /* PROCESS DATA (one member / no conf) */
1354 if (!conf || members <= 1) {
1355 /* -> if echo is NOT enabled */
1356 if (!dsp->echo) {
1357 /* -> send tx-data if available or use 0-volume */
1358 while (r != rr && t != tt) {
1359 *d++ = p[t]; /* write tx_buff */
1360 t = (t+1) & CMX_BUFF_MASK;
1361 r = (r+1) & CMX_BUFF_MASK;
1362 }
1363 if (r != rr)
1364 memset(d, dsp_silence, (rr-r)&CMX_BUFF_MASK);
1365 /* -> if echo is enabled */
1366 } else {
1367 /*
1368 * -> mix tx-data with echo if available,
1369 * or use echo only
1370 */
1371 while (r != rr && t != tt) {
1372 *d++ = dsp_audio_mix_law[(p[t]<<8)|q[r]];
1373 t = (t+1) & CMX_BUFF_MASK;
1374 r = (r+1) & CMX_BUFF_MASK;
1375 }
1376 while (r != rr) {
1377 *d++ = q[r]; /* echo */
1378 r = (r+1) & CMX_BUFF_MASK;
1379 }
1380 }
1381 dsp->tx_R = t;
1382 goto send_packet;
1383 }
1384 /* PROCESS DATA (two members) */
1385#ifdef CMX_CONF_DEBUG
1386 if (0) {
1387#else
1388 if (members == 2) {
1389#endif
1390 /* "other" becomes other party */
1391 other = (list_entry(conf->mlist.next,
1392 struct dsp_conf_member, list))->dsp;
1393 if (other == member)
1394 other = (list_entry(conf->mlist.prev,
1395 struct dsp_conf_member, list))->dsp;
1396 o_q = other->rx_buff; /* received data */
1397 o_rr = (other->rx_R + len) & CMX_BUFF_MASK;
1398 /* end of rx-pointer */
1399 o_r = (o_rr - rr + r) & CMX_BUFF_MASK;
1400 /* start rx-pointer at current read position*/
1401 /* -> if echo is NOT enabled */
1402 if (!dsp->echo) {
1403 /*
1404 * -> copy other member's rx-data,
1405 * if tx-data is available, mix
1406 */
1407 while (o_r != o_rr && t != tt) {
1408 *d++ = dsp_audio_mix_law[(p[t]<<8)|o_q[o_r]];
1409 t = (t+1) & CMX_BUFF_MASK;
1410 o_r = (o_r+1) & CMX_BUFF_MASK;
1411 }
1412 while (o_r != o_rr) {
1413 *d++ = o_q[o_r];
1414 o_r = (o_r+1) & CMX_BUFF_MASK;
1415 }
1416 /* -> if echo is enabled */
1417 } else {
1418 /*
1419 * -> mix other member's rx-data with echo,
1420 * if tx-data is available, mix
1421 */
1422 while (r != rr && t != tt) {
1423 sample = dsp_audio_law_to_s32[p[t]] +
1424 dsp_audio_law_to_s32[q[r]] +
1425 dsp_audio_law_to_s32[o_q[o_r]];
1426 if (sample < -32768)
1427 sample = -32768;
1428 else if (sample > 32767)
1429 sample = 32767;
1430 *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1431 /* tx-data + rx_data + echo */
1432 t = (t+1) & CMX_BUFF_MASK;
1433 r = (r+1) & CMX_BUFF_MASK;
1434 o_r = (o_r+1) & CMX_BUFF_MASK;
1435 }
1436 while (r != rr) {
1437 *d++ = dsp_audio_mix_law[(q[r]<<8)|o_q[o_r]];
1438 r = (r+1) & CMX_BUFF_MASK;
1439 o_r = (o_r+1) & CMX_BUFF_MASK;
1440 }
1441 }
1442 dsp->tx_R = t;
1443 goto send_packet;
1444 }
1445#ifdef DSP_NEVER_DEFINED
1446 }
1447#endif
1448 /* PROCESS DATA (three or more members) */
1449 /* -> if echo is NOT enabled */
1450 if (!dsp->echo) {
1451 /*
1452 * -> substract rx-data from conf-data,
1453 * if tx-data is available, mix
1454 */
1455 while (r != rr && t != tt) {
1456 sample = dsp_audio_law_to_s32[p[t]] + *c++ -
1457 dsp_audio_law_to_s32[q[r]];
1458 if (sample < -32768)
1459 sample = -32768;
1460 else if (sample > 32767)
1461 sample = 32767;
1462 *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1463 /* conf-rx+tx */
1464 r = (r+1) & CMX_BUFF_MASK;
1465 t = (t+1) & CMX_BUFF_MASK;
1466 }
1467 while (r != rr) {
1468 sample = *c++ - dsp_audio_law_to_s32[q[r]];
1469 if (sample < -32768)
1470 sample = -32768;
1471 else if (sample > 32767)
1472 sample = 32767;
1473 *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1474 /* conf-rx */
1475 r = (r+1) & CMX_BUFF_MASK;
1476 }
1477 /* -> if echo is enabled */
1478 } else {
1479 /*
1480 * -> encode conf-data, if tx-data
1481 * is available, mix
1482 */
1483 while (r != rr && t != tt) {
1484 sample = dsp_audio_law_to_s32[p[t]] + *c++;
1485 if (sample < -32768)
1486 sample = -32768;
1487 else if (sample > 32767)
1488 sample = 32767;
1489 *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1490 /* conf(echo)+tx */
1491 t = (t+1) & CMX_BUFF_MASK;
1492 r = (r+1) & CMX_BUFF_MASK;
1493 }
1494 while (r != rr) {
1495 sample = *c++;
1496 if (sample < -32768)
1497 sample = -32768;
1498 else if (sample > 32767)
1499 sample = 32767;
1500 *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1501 /* conf(echo) */
1502 r = (r+1) & CMX_BUFF_MASK;
1503 }
1504 }
1505 dsp->tx_R = t;
1506 goto send_packet;
1507
1508send_packet:
1509 /*
1510 * send tx-data if enabled - don't filter,
1511 * becuase we want what we send, not what we filtered
1512 */
1513 if (dsp->tx_data) {
1514 /* PREPARE RESULT */
1515 txskb = mI_alloc_skb(len, GFP_ATOMIC);
1516 if (!txskb) {
1517 printk(KERN_ERR
1518 "FATAL ERROR in mISDN_dsp.o: "
1519 "cannot alloc %d bytes\n", len);
1520 } else {
1521 thh = mISDN_HEAD_P(txskb);
1522 thh->prim = DL_DATA_REQ;
1523 thh->id = 0;
1524 memcpy(skb_put(txskb, len), nskb->data+preload, len);
1525 /* queue (trigger later) */
1526 skb_queue_tail(&dsp->sendq, txskb);
1527 }
1528 }
1529 /* adjust volume */
1530 if (dsp->tx_volume)
1531 dsp_change_volume(nskb, dsp->tx_volume);
1532 /* pipeline */
1533 if (dsp->pipeline.inuse)
1534 dsp_pipeline_process_tx(&dsp->pipeline, nskb->data, nskb->len);
1535 /* crypt */
1536 if (dsp->bf_enable)
1537 dsp_bf_encrypt(dsp, nskb->data, nskb->len);
1538 /* queue and trigger */
1539 skb_queue_tail(&dsp->sendq, nskb);
1540 schedule_work(&dsp->workq);
1541}
1542
1543u32 samplecount;
1544struct timer_list dsp_spl_tl;
1545u32 dsp_spl_jiffies; /* calculate the next time to fire */
1546u32 dsp_start_jiffies; /* jiffies at the time, the calculation begins */
1547struct timeval dsp_start_tv; /* time at start of calculation */
1548
1549void
1550dsp_cmx_send(void *arg)
1551{
1552 struct dsp_conf *conf;
1553 struct dsp_conf_member *member;
1554 struct dsp *dsp;
1555 int mustmix, members;
1556 s32 mixbuffer[MAX_POLL+100], *c;
1557 u8 *p, *q;
1558 int r, rr;
1559 int jittercheck = 0, delay, i;
1560 u_long flags;
1561 struct timeval tv;
1562 u32 elapsed;
1563 s16 length;
1564
1565 /* lock */
1566 spin_lock_irqsave(&dsp_lock, flags);
1567
1568 if (!dsp_start_tv.tv_sec) {
1569 do_gettimeofday(&dsp_start_tv);
1570 length = dsp_poll;
1571 } else {
1572 do_gettimeofday(&tv);
1573 elapsed = ((tv.tv_sec - dsp_start_tv.tv_sec) * 8000)
1574 + ((s32)(tv.tv_usec / 125) - (dsp_start_tv.tv_usec / 125));
1575 dsp_start_tv.tv_sec = tv.tv_sec;
1576 dsp_start_tv.tv_usec = tv.tv_usec;
1577 length = elapsed;
1578 }
1579 if (length > MAX_POLL + 100)
1580 length = MAX_POLL + 100;
1581/* printk(KERN_DEBUG "len=%d dsp_count=0x%x.%04x dsp_poll_diff=0x%x.%04x\n",
1582 length, dsp_count >> 16, dsp_count & 0xffff, dsp_poll_diff >> 16,
1583 dsp_poll_diff & 0xffff);
1584 */
1585
1586 /*
1587 * check if jitter needs to be checked
1588 * (this is about every second = 8192 samples)
1589 */
1590 samplecount += length;
1591 if ((samplecount & 8191) < length)
1592 jittercheck = 1;
1593
1594 /* loop all members that do not require conference mixing */
1595 list_for_each_entry(dsp, &dsp_ilist, list) {
1596 if (dsp->hdlc)
1597 continue;
1598 conf = dsp->conf;
1599 mustmix = 0;
1600 members = 0;
1601 if (conf) {
1602 members = count_list_member(&conf->mlist);
1603#ifdef CMX_CONF_DEBUG
1604 if (conf->software && members > 1)
1605#else
1606 if (conf->software && members > 2)
1607#endif
1608 mustmix = 1;
1609 }
1610
1611 /* transmission required */
1612 if (!mustmix) {
1613 dsp_cmx_send_member(dsp, length, mixbuffer, members);
1614
1615 /*
1616 * unused mixbuffer is given to prevent a
1617 * potential null-pointer-bug
1618 */
1619 }
1620 }
1621
1622 /* loop all members that require conference mixing */
1623 list_for_each_entry(conf, &conf_ilist, list) {
1624 /* count members and check hardware */
1625 members = count_list_member(&conf->mlist);
1626#ifdef CMX_CONF_DEBUG
1627 if (conf->software && members > 1) {
1628#else
1629 if (conf->software && members > 2) {
1630#endif
1631 /* check for hdlc conf */
1632 member = list_entry(conf->mlist.next,
1633 struct dsp_conf_member, list);
1634 if (member->dsp->hdlc)
1635 continue;
1636 /* mix all data */
1637 memset(mixbuffer, 0, length*sizeof(s32));
1638 list_for_each_entry(member, &conf->mlist, list) {
1639 dsp = member->dsp;
1640 /* get range of data to mix */
1641 c = mixbuffer;
1642 q = dsp->rx_buff;
1643 r = dsp->rx_R;
1644 rr = (r + length) & CMX_BUFF_MASK;
1645 /* add member's data */
1646 while (r != rr) {
1647 *c++ += dsp_audio_law_to_s32[q[r]];
1648 r = (r+1) & CMX_BUFF_MASK;
1649 }
1650 }
1651
1652 /* process each member */
1653 list_for_each_entry(member, &conf->mlist, list) {
1654 /* transmission */
1655 dsp_cmx_send_member(member->dsp, length,
1656 mixbuffer, members);
1657 }
1658 }
1659 }
1660
1661 /* delete rx-data, increment buffers, change pointers */
1662 list_for_each_entry(dsp, &dsp_ilist, list) {
1663 if (dsp->hdlc)
1664 continue;
1665 p = dsp->rx_buff;
1666 q = dsp->tx_buff;
1667 r = dsp->rx_R;
1668 /* move receive pointer when receiving */
1669 if (!dsp->rx_is_off) {
1670 rr = (r + length) & CMX_BUFF_MASK;
1671 /* delete rx-data */
1672 while (r != rr) {
1673 p[r] = dsp_silence;
1674 r = (r+1) & CMX_BUFF_MASK;
1675 }
1676 /* increment rx-buffer pointer */
1677 dsp->rx_R = r; /* write incremented read pointer */
1678 }
1679
1680 /* check current rx_delay */
1681 delay = (dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK;
1682 if (delay >= CMX_BUFF_HALF)
1683 delay = 0; /* will be the delay before next write */
1684 /* check for lower delay */
1685 if (delay < dsp->rx_delay[0])
1686 dsp->rx_delay[0] = delay;
1687 /* check current tx_delay */
1688 delay = (dsp->tx_W-dsp->tx_R) & CMX_BUFF_MASK;
1689 if (delay >= CMX_BUFF_HALF)
1690 delay = 0; /* will be the delay before next write */
1691 /* check for lower delay */
1692 if (delay < dsp->tx_delay[0])
1693 dsp->tx_delay[0] = delay;
1694 if (jittercheck) {
1695 /* find the lowest of all rx_delays */
1696 delay = dsp->rx_delay[0];
1697 i = 1;
1698 while (i < MAX_SECONDS_JITTER_CHECK) {
1699 if (delay > dsp->rx_delay[i])
1700 delay = dsp->rx_delay[i];
1701 i++;
1702 }
1703 /*
1704 * remove rx_delay only if we have delay AND we
1705 * have not preset cmx_delay
1706 */
1707 if (delay && !dsp->cmx_delay) {
1708 if (dsp_debug & DEBUG_DSP_CMX)
1709 printk(KERN_DEBUG
1710 "%s lowest rx_delay of %d bytes for"
1711 " dsp %s are now removed.\n",
1712 __func__, delay,
1713 dsp->name);
1714 r = dsp->rx_R;
1715 rr = (r + delay) & CMX_BUFF_MASK;
1716 /* delete rx-data */
1717 while (r != rr) {
1718 p[r] = dsp_silence;
1719 r = (r+1) & CMX_BUFF_MASK;
1720 }
1721 /* increment rx-buffer pointer */
1722 dsp->rx_R = r;
1723 /* write incremented read pointer */
1724 }
1725 /* find the lowest of all tx_delays */
1726 delay = dsp->tx_delay[0];
1727 i = 1;
1728 while (i < MAX_SECONDS_JITTER_CHECK) {
1729 if (delay > dsp->tx_delay[i])
1730 delay = dsp->tx_delay[i];
1731 i++;
1732 }
1733 /*
1734 * remove delay only if we have delay AND we
1735 * have enabled tx_dejitter
1736 */
1737 if (delay && dsp->tx_dejitter) {
1738 if (dsp_debug & DEBUG_DSP_CMX)
1739 printk(KERN_DEBUG
1740 "%s lowest tx_delay of %d bytes for"
1741 " dsp %s are now removed.\n",
1742 __func__, delay,
1743 dsp->name);
1744 r = dsp->tx_R;
1745 rr = (r + delay) & CMX_BUFF_MASK;
1746 /* delete tx-data */
1747 while (r != rr) {
1748 q[r] = dsp_silence;
1749 r = (r+1) & CMX_BUFF_MASK;
1750 }
1751 /* increment rx-buffer pointer */
1752 dsp->tx_R = r;
1753 /* write incremented read pointer */
1754 }
1755 /* scroll up delays */
1756 i = MAX_SECONDS_JITTER_CHECK - 1;
1757 while (i) {
1758 dsp->rx_delay[i] = dsp->rx_delay[i-1];
1759 dsp->tx_delay[i] = dsp->tx_delay[i-1];
1760 i--;
1761 }
1762 dsp->tx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
1763 dsp->rx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
1764 }
1765 }
1766
1767 /* if next event would be in the past ... */
1768 if ((s32)(dsp_spl_jiffies+dsp_tics-jiffies) <= 0)
1769 dsp_spl_jiffies = jiffies + 1;
1770 else
1771 dsp_spl_jiffies += dsp_tics;
1772
1773 dsp_spl_tl.expires = dsp_spl_jiffies;
1774 add_timer(&dsp_spl_tl);
1775
1776 /* unlock */
1777 spin_unlock_irqrestore(&dsp_lock, flags);
1778}
1779
1780/*
1781 * audio data is transmitted from upper layer to the dsp
1782 */
1783void
1784dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb)
1785{
1786 u_int w, ww;
1787 u8 *d, *p;
1788 int space; /* todo: , l = skb->len; */
1789#ifdef CMX_TX_DEBUG
1790 char debugbuf[256] = "";
1791#endif
1792
1793 /* check if there is enough space, and then copy */
1794 w = dsp->tx_W;
1795 ww = dsp->tx_R;
1796 p = dsp->tx_buff;
1797 d = skb->data;
1798 space = ww-w;
1799 if (space <= 0)
1800 space += CMX_BUFF_SIZE;
1801 /* write-pointer should not overrun nor reach read pointer */
1802 if (space-1 < skb->len)
1803 /* write to the space we have left */
1804 ww = (ww - 1) & CMX_BUFF_MASK;
1805 else
1806 /* write until all byte are copied */
1807 ww = (w + skb->len) & CMX_BUFF_MASK;
1808 dsp->tx_W = ww;
1809
1810 /* show current buffer */
1811#ifdef CMX_DEBUG
1812 printk(KERN_DEBUG
1813 "cmx_transmit(dsp=%lx) %d bytes to 0x%x-0x%x. %s\n",
1814 (u_long)dsp, (ww-w)&CMX_BUFF_MASK, w, ww, dsp->name);
1815#endif
1816
1817 /* copy transmit data to tx-buffer */
1818#ifdef CMX_TX_DEBUG
1819 sprintf(debugbuf, "TX getting (%04x-%04x)%p: ", w, ww, p);
1820#endif
1821 while (w != ww) {
1822#ifdef CMX_TX_DEBUG
1823 if (strlen(debugbuf) < 48)
1824 sprintf(debugbuf+strlen(debugbuf), " %02x", *d);
1825#endif
1826 p[w] = *d++;
1827 w = (w+1) & CMX_BUFF_MASK;
1828 }
1829#ifdef CMX_TX_DEBUG
1830 printk(KERN_DEBUG "%s\n", debugbuf);
1831#endif
1832
1833}
1834
1835/*
1836 * hdlc data is received from card and sent to all members.
1837 */
1838void
1839dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb)
1840{
1841 struct sk_buff *nskb = NULL;
1842 struct dsp_conf_member *member;
1843 struct mISDNhead *hh;
1844
1845 /* not if not active */
1846 if (!dsp->b_active)
1847 return;
1848
1849 /* check if we have sompen */
1850 if (skb->len < 1)
1851 return;
1852
1853 /* no conf */
1854 if (!dsp->conf) {
1855 /* in case of hardware (echo) */
1856 if (dsp->pcm_slot_tx >= 0)
1857 return;
1858 if (dsp->echo)
1859 nskb = skb_clone(skb, GFP_ATOMIC);
1860 if (nskb) {
1861 hh = mISDN_HEAD_P(nskb);
1862 hh->prim = PH_DATA_REQ;
1863 hh->id = 0;
1864 skb_queue_tail(&dsp->sendq, nskb);
1865 schedule_work(&dsp->workq);
1866 }
1867 return;
1868 }
1869 /* in case of hardware conference */
1870 if (dsp->conf->hardware)
1871 return;
1872 list_for_each_entry(member, &dsp->conf->mlist, list) {
1873 if (dsp->echo || member->dsp != dsp) {
1874 nskb = skb_clone(skb, GFP_ATOMIC);
1875 if (nskb) {
1876 hh = mISDN_HEAD_P(nskb);
1877 hh->prim = PH_DATA_REQ;
1878 hh->id = 0;
1879 skb_queue_tail(&member->dsp->sendq, nskb);
1880 schedule_work(&member->dsp->workq);
1881 }
1882 }
1883 }
1884}
1885
1886
diff --git a/drivers/isdn/mISDN/dsp_core.c b/drivers/isdn/mISDN/dsp_core.c
new file mode 100644
index 000000000000..2f10ed82c0db
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp_core.c
@@ -0,0 +1,1191 @@
1/*
2 * Author Andreas Eversberg (jolly@eversberg.eu)
3 * Based on source code structure by
4 * Karsten Keil (keil@isdn4linux.de)
5 *
6 * This file is (c) under GNU PUBLIC LICENSE
7 * For changes and modifications please read
8 * ../../../Documentation/isdn/mISDN.cert
9 *
10 * Thanks to Karsten Keil (great drivers)
11 * Cologne Chip (great chips)
12 *
13 * This module does:
14 * Real-time tone generation
15 * DTMF detection
16 * Real-time cross-connection and conferrence
17 * Compensate jitter due to system load and hardware fault.
18 * All features are done in kernel space and will be realized
19 * using hardware, if available and supported by chip set.
20 * Blowfish encryption/decryption
21 */
22
23/* STRUCTURE:
24 *
25 * The dsp module provides layer 2 for b-channels (64kbit). It provides
26 * transparent audio forwarding with special digital signal processing:
27 *
28 * - (1) generation of tones
29 * - (2) detection of dtmf tones
30 * - (3) crossconnecting and conferences (clocking)
31 * - (4) echo generation for delay test
32 * - (5) volume control
33 * - (6) disable receive data
34 * - (7) pipeline
35 * - (8) encryption/decryption
36 *
37 * Look:
38 * TX RX
39 * ------upper layer------
40 * | ^
41 * | |(6)
42 * v |
43 * +-----+-------------+-----+
44 * |(3)(4) |
45 * | CMX |
46 * | |
47 * | +-------------+
48 * | | ^
49 * | | |
50 * |+---------+| +----+----+
51 * ||(1) || |(2) |
52 * || || | |
53 * || Tones || | DTMF |
54 * || || | |
55 * || || | |
56 * |+----+----+| +----+----+
57 * +-----+-----+ ^
58 * | |
59 * v |
60 * +----+----+ +----+----+
61 * |(5) | |(5) |
62 * | | | |
63 * |TX Volume| |RX Volume|
64 * | | | |
65 * | | | |
66 * +----+----+ +----+----+
67 * | ^
68 * | |
69 * v |
70 * +----+-------------+----+
71 * |(7) |
72 * | |
73 * | Pipeline Processing |
74 * | |
75 * | |
76 * +----+-------------+----+
77 * | ^
78 * | |
79 * v |
80 * +----+----+ +----+----+
81 * |(8) | |(8) |
82 * | | | |
83 * | Encrypt | | Decrypt |
84 * | | | |
85 * | | | |
86 * +----+----+ +----+----+
87 * | ^
88 * | |
89 * v |
90 * ------card layer------
91 * TX RX
92 *
93 * Above you can see the logical data flow. If software is used to do the
94 * process, it is actually the real data flow. If hardware is used, data
95 * may not flow, but hardware commands to the card, to provide the data flow
96 * as shown.
97 *
98 * NOTE: The channel must be activated in order to make dsp work, even if
99 * no data flow to the upper layer is intended. Activation can be done
100 * after and before controlling the setting using PH_CONTROL requests.
101 *
102 * DTMF: Will be detected by hardware if possible. It is done before CMX
103 * processing.
104 *
105 * Tones: Will be generated via software if endless looped audio fifos are
106 * not supported by hardware. Tones will override all data from CMX.
107 * It is not required to join a conference to use tones at any time.
108 *
109 * CMX: Is transparent when not used. When it is used, it will do
110 * crossconnections and conferences via software if not possible through
111 * hardware. If hardware capability is available, hardware is used.
112 *
113 * Echo: Is generated by CMX and is used to check performane of hard and
114 * software CMX.
115 *
116 * The CMX has special functions for conferences with one, two and more
117 * members. It will allow different types of data flow. Receive and transmit
118 * data to/form upper layer may be swithed on/off individually without loosing
119 * features of CMX, Tones and DTMF.
120 *
121 * Echo Cancellation: Sometimes we like to cancel echo from the interface.
122 * Note that a VoIP call may not have echo caused by the IP phone. The echo
123 * is generated by the telephone line connected to it. Because the delay
124 * is high, it becomes an echo. RESULT: Echo Cachelation is required if
125 * both echo AND delay is applied to an interface.
126 * Remember that software CMX always generates a more or less delay.
127 *
128 * If all used features can be realized in hardware, and if transmit and/or
129 * receive data ist disabled, the card may not send/receive any data at all.
130 * Not receiving is usefull if only announcements are played. Not sending is
131 * usefull if an answering machine records audio. Not sending and receiving is
132 * usefull during most states of the call. If supported by hardware, tones
133 * will be played without cpu load. Small PBXs and NT-Mode applications will
134 * not need expensive hardware when processing calls.
135 *
136 *
137 * LOCKING:
138 *
139 * When data is received from upper or lower layer (card), the complete dsp
140 * module is locked by a global lock. This lock MUST lock irq, because it
141 * must lock timer events by DSP poll timer.
142 * When data is ready to be transmitted down, the data is queued and sent
143 * outside lock and timer event.
144 * PH_CONTROL must not change any settings, join or split conference members
145 * during process of data.
146 *
147 * HDLC:
148 *
149 * It works quite the same as transparent, except that HDLC data is forwarded
150 * to all other conference members if no hardware bridging is possible.
151 * Send data will be writte to sendq. Sendq will be sent if confirm is received.
152 * Conference cannot join, if one member is not hdlc.
153 *
154 */
155
156#include <linux/delay.h>
157#include <linux/mISDNif.h>
158#include <linux/mISDNdsp.h>
159#include <linux/module.h>
160#include <linux/vmalloc.h>
161#include "core.h"
162#include "dsp.h"
163
164const char *mISDN_dsp_revision = "2.0";
165
166static int debug;
167static int options;
168static int poll;
169static int dtmfthreshold = 100;
170
171MODULE_AUTHOR("Andreas Eversberg");
172module_param(debug, uint, S_IRUGO | S_IWUSR);
173module_param(options, uint, S_IRUGO | S_IWUSR);
174module_param(poll, uint, S_IRUGO | S_IWUSR);
175module_param(dtmfthreshold, uint, S_IRUGO | S_IWUSR);
176MODULE_LICENSE("GPL");
177
178/*int spinnest = 0;*/
179
180spinlock_t dsp_lock; /* global dsp lock */
181struct list_head dsp_ilist;
182struct list_head conf_ilist;
183int dsp_debug;
184int dsp_options;
185int dsp_poll, dsp_tics;
186
187/* check if rx may be turned off or must be turned on */
188static void
189dsp_rx_off_member(struct dsp *dsp)
190{
191 struct mISDN_ctrl_req cq;
192 int rx_off = 1;
193
194 if (!dsp->features_rx_off)
195 return;
196
197 /* not disabled */
198 if (!dsp->rx_disabled)
199 rx_off = 0;
200 /* software dtmf */
201 else if (dsp->dtmf.software)
202 rx_off = 0;
203 /* echo in software */
204 else if (dsp->echo && dsp->pcm_slot_tx < 0)
205 rx_off = 0;
206 /* bridge in software */
207 else if (dsp->conf) {
208 if (dsp->conf->software)
209 rx_off = 0;
210 }
211
212 if (rx_off == dsp->rx_is_off)
213 return;
214
215 if (!dsp->ch.peer) {
216 if (dsp_debug & DEBUG_DSP_CORE)
217 printk(KERN_DEBUG "%s: no peer, no rx_off\n",
218 __func__);
219 return;
220 }
221 cq.op = MISDN_CTRL_RX_OFF;
222 cq.p1 = rx_off;
223 if (dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq)) {
224 printk(KERN_DEBUG "%s: 2nd CONTROL_CHANNEL failed\n",
225 __func__);
226 return;
227 }
228 dsp->rx_is_off = rx_off;
229 if (dsp_debug & DEBUG_DSP_CORE)
230 printk(KERN_DEBUG "%s: %s set rx_off = %d\n",
231 __func__, dsp->name, rx_off);
232}
233static void
234dsp_rx_off(struct dsp *dsp)
235{
236 struct dsp_conf_member *member;
237
238 if (dsp_options & DSP_OPT_NOHARDWARE)
239 return;
240
241 /* no conf */
242 if (!dsp->conf) {
243 dsp_rx_off_member(dsp);
244 return;
245 }
246 /* check all members in conf */
247 list_for_each_entry(member, &dsp->conf->mlist, list) {
248 dsp_rx_off_member(member->dsp);
249 }
250}
251
252static int
253dsp_control_req(struct dsp *dsp, struct mISDNhead *hh, struct sk_buff *skb)
254{
255 struct sk_buff *nskb;
256 int ret = 0;
257 int cont;
258 u8 *data;
259 int len;
260
261 if (skb->len < sizeof(int))
262 printk(KERN_ERR "%s: PH_CONTROL message too short\n", __func__);
263 cont = *((int *)skb->data);
264 len = skb->len - sizeof(int);
265 data = skb->data + sizeof(int);
266
267 switch (cont) {
268 case DTMF_TONE_START: /* turn on DTMF */
269 if (dsp->hdlc) {
270 ret = -EINVAL;
271 break;
272 }
273 if (dsp_debug & DEBUG_DSP_CORE)
274 printk(KERN_DEBUG "%s: start dtmf\n", __func__);
275 if (len == sizeof(int)) {
276 printk(KERN_NOTICE "changing DTMF Threshold "
277 "to %d\n", *((int *)data));
278 dsp->dtmf.treshold = (*(int *)data) * 10000;
279 }
280 /* init goertzel */
281 dsp_dtmf_goertzel_init(dsp);
282
283 /* check dtmf hardware */
284 dsp_dtmf_hardware(dsp);
285 break;
286 case DTMF_TONE_STOP: /* turn off DTMF */
287 if (dsp_debug & DEBUG_DSP_CORE)
288 printk(KERN_DEBUG "%s: stop dtmf\n", __func__);
289 dsp->dtmf.hardware = 0;
290 dsp->dtmf.software = 0;
291 break;
292 case DSP_CONF_JOIN: /* join / update conference */
293 if (len < sizeof(int)) {
294 ret = -EINVAL;
295 break;
296 }
297 if (*((u32 *)data) == 0)
298 goto conf_split;
299 if (dsp_debug & DEBUG_DSP_CORE)
300 printk(KERN_DEBUG "%s: join conference %d\n",
301 __func__, *((u32 *)data));
302 ret = dsp_cmx_conf(dsp, *((u32 *)data));
303 /* dsp_cmx_hardware will also be called here */
304 dsp_rx_off(dsp);
305 if (dsp_debug & DEBUG_DSP_CMX)
306 dsp_cmx_debug(dsp);
307 break;
308 case DSP_CONF_SPLIT: /* remove from conference */
309conf_split:
310 if (dsp_debug & DEBUG_DSP_CORE)
311 printk(KERN_DEBUG "%s: release conference\n", __func__);
312 ret = dsp_cmx_conf(dsp, 0);
313 /* dsp_cmx_hardware will also be called here */
314 if (dsp_debug & DEBUG_DSP_CMX)
315 dsp_cmx_debug(dsp);
316 dsp_rx_off(dsp);
317 break;
318 case DSP_TONE_PATT_ON: /* play tone */
319 if (dsp->hdlc) {
320 ret = -EINVAL;
321 break;
322 }
323 if (len < sizeof(int)) {
324 ret = -EINVAL;
325 break;
326 }
327 if (dsp_debug & DEBUG_DSP_CORE)
328 printk(KERN_DEBUG "%s: turn tone 0x%x on\n",
329 __func__, *((int *)skb->data));
330 ret = dsp_tone(dsp, *((int *)data));
331 if (!ret) {
332 dsp_cmx_hardware(dsp->conf, dsp);
333 dsp_rx_off(dsp);
334 }
335 if (!dsp->tone.tone)
336 goto tone_off;
337 break;
338 case DSP_TONE_PATT_OFF: /* stop tone */
339 if (dsp->hdlc) {
340 ret = -EINVAL;
341 break;
342 }
343 if (dsp_debug & DEBUG_DSP_CORE)
344 printk(KERN_DEBUG "%s: turn tone off\n", __func__);
345 dsp_tone(dsp, 0);
346 dsp_cmx_hardware(dsp->conf, dsp);
347 dsp_rx_off(dsp);
348 /* reset tx buffers (user space data) */
349tone_off:
350 dsp->rx_W = 0;
351 dsp->rx_R = 0;
352 break;
353 case DSP_VOL_CHANGE_TX: /* change volume */
354 if (dsp->hdlc) {
355 ret = -EINVAL;
356 break;
357 }
358 if (len < sizeof(int)) {
359 ret = -EINVAL;
360 break;
361 }
362 dsp->tx_volume = *((int *)data);
363 if (dsp_debug & DEBUG_DSP_CORE)
364 printk(KERN_DEBUG "%s: change tx vol to %d\n",
365 __func__, dsp->tx_volume);
366 dsp_cmx_hardware(dsp->conf, dsp);
367 dsp_dtmf_hardware(dsp);
368 dsp_rx_off(dsp);
369 break;
370 case DSP_VOL_CHANGE_RX: /* change volume */
371 if (dsp->hdlc) {
372 ret = -EINVAL;
373 break;
374 }
375 if (len < sizeof(int)) {
376 ret = -EINVAL;
377 break;
378 }
379 dsp->rx_volume = *((int *)data);
380 if (dsp_debug & DEBUG_DSP_CORE)
381 printk(KERN_DEBUG "%s: change rx vol to %d\n",
382 __func__, dsp->tx_volume);
383 dsp_cmx_hardware(dsp->conf, dsp);
384 dsp_dtmf_hardware(dsp);
385 dsp_rx_off(dsp);
386 break;
387 case DSP_ECHO_ON: /* enable echo */
388 dsp->echo = 1; /* soft echo */
389 if (dsp_debug & DEBUG_DSP_CORE)
390 printk(KERN_DEBUG "%s: enable cmx-echo\n", __func__);
391 dsp_cmx_hardware(dsp->conf, dsp);
392 dsp_rx_off(dsp);
393 if (dsp_debug & DEBUG_DSP_CMX)
394 dsp_cmx_debug(dsp);
395 break;
396 case DSP_ECHO_OFF: /* disable echo */
397 dsp->echo = 0;
398 if (dsp_debug & DEBUG_DSP_CORE)
399 printk(KERN_DEBUG "%s: disable cmx-echo\n", __func__);
400 dsp_cmx_hardware(dsp->conf, dsp);
401 dsp_rx_off(dsp);
402 if (dsp_debug & DEBUG_DSP_CMX)
403 dsp_cmx_debug(dsp);
404 break;
405 case DSP_RECEIVE_ON: /* enable receive to user space */
406 if (dsp_debug & DEBUG_DSP_CORE)
407 printk(KERN_DEBUG "%s: enable receive to user "
408 "space\n", __func__);
409 dsp->rx_disabled = 0;
410 dsp_rx_off(dsp);
411 break;
412 case DSP_RECEIVE_OFF: /* disable receive to user space */
413 if (dsp_debug & DEBUG_DSP_CORE)
414 printk(KERN_DEBUG "%s: disable receive to "
415 "user space\n", __func__);
416 dsp->rx_disabled = 1;
417 dsp_rx_off(dsp);
418 break;
419 case DSP_MIX_ON: /* enable mixing of tx data */
420 if (dsp->hdlc) {
421 ret = -EINVAL;
422 break;
423 }
424 if (dsp_debug & DEBUG_DSP_CORE)
425 printk(KERN_DEBUG "%s: enable mixing of "
426 "tx-data with conf mebers\n", __func__);
427 dsp->tx_mix = 1;
428 dsp_cmx_hardware(dsp->conf, dsp);
429 dsp_rx_off(dsp);
430 if (dsp_debug & DEBUG_DSP_CMX)
431 dsp_cmx_debug(dsp);
432 break;
433 case DSP_MIX_OFF: /* disable mixing of tx data */
434 if (dsp->hdlc) {
435 ret = -EINVAL;
436 break;
437 }
438 if (dsp_debug & DEBUG_DSP_CORE)
439 printk(KERN_DEBUG "%s: disable mixing of "
440 "tx-data with conf mebers\n", __func__);
441 dsp->tx_mix = 0;
442 dsp_cmx_hardware(dsp->conf, dsp);
443 dsp_rx_off(dsp);
444 if (dsp_debug & DEBUG_DSP_CMX)
445 dsp_cmx_debug(dsp);
446 break;
447 case DSP_TXDATA_ON: /* enable txdata */
448 dsp->tx_data = 1;
449 if (dsp_debug & DEBUG_DSP_CORE)
450 printk(KERN_DEBUG "%s: enable tx-data\n", __func__);
451 dsp_cmx_hardware(dsp->conf, dsp);
452 dsp_rx_off(dsp);
453 if (dsp_debug & DEBUG_DSP_CMX)
454 dsp_cmx_debug(dsp);
455 break;
456 case DSP_TXDATA_OFF: /* disable txdata */
457 dsp->tx_data = 0;
458 if (dsp_debug & DEBUG_DSP_CORE)
459 printk(KERN_DEBUG "%s: disable tx-data\n", __func__);
460 dsp_cmx_hardware(dsp->conf, dsp);
461 dsp_rx_off(dsp);
462 if (dsp_debug & DEBUG_DSP_CMX)
463 dsp_cmx_debug(dsp);
464 break;
465 case DSP_DELAY: /* use delay algorithm instead of dynamic
466 jitter algorithm */
467 if (dsp->hdlc) {
468 ret = -EINVAL;
469 break;
470 }
471 if (len < sizeof(int)) {
472 ret = -EINVAL;
473 break;
474 }
475 dsp->cmx_delay = (*((int *)data)) << 3;
476 /* miliseconds to samples */
477 if (dsp->cmx_delay >= (CMX_BUFF_HALF>>1))
478 /* clip to half of maximum usable buffer
479 (half of half buffer) */
480 dsp->cmx_delay = (CMX_BUFF_HALF>>1) - 1;
481 if (dsp_debug & DEBUG_DSP_CORE)
482 printk(KERN_DEBUG "%s: use delay algorithm to "
483 "compensate jitter (%d samples)\n",
484 __func__, dsp->cmx_delay);
485 break;
486 case DSP_JITTER: /* use dynamic jitter algorithm instead of
487 delay algorithm */
488 if (dsp->hdlc) {
489 ret = -EINVAL;
490 break;
491 }
492 dsp->cmx_delay = 0;
493 if (dsp_debug & DEBUG_DSP_CORE)
494 printk(KERN_DEBUG "%s: use jitter algorithm to "
495 "compensate jitter\n", __func__);
496 break;
497 case DSP_TX_DEJITTER: /* use dynamic jitter algorithm for tx-buffer */
498 if (dsp->hdlc) {
499 ret = -EINVAL;
500 break;
501 }
502 dsp->tx_dejitter = 1;
503 if (dsp_debug & DEBUG_DSP_CORE)
504 printk(KERN_DEBUG "%s: use dejitter on TX "
505 "buffer\n", __func__);
506 break;
507 case DSP_TX_DEJ_OFF: /* use tx-buffer without dejittering*/
508 if (dsp->hdlc) {
509 ret = -EINVAL;
510 break;
511 }
512 dsp->tx_dejitter = 0;
513 if (dsp_debug & DEBUG_DSP_CORE)
514 printk(KERN_DEBUG "%s: use TX buffer without "
515 "dejittering\n", __func__);
516 break;
517 case DSP_PIPELINE_CFG:
518 if (dsp->hdlc) {
519 ret = -EINVAL;
520 break;
521 }
522 if (len > 0 && ((char *)data)[len - 1]) {
523 printk(KERN_DEBUG "%s: pipeline config string "
524 "is not NULL terminated!\n", __func__);
525 ret = -EINVAL;
526 } else {
527 dsp->pipeline.inuse = 1;
528 dsp_cmx_hardware(dsp->conf, dsp);
529 ret = dsp_pipeline_build(&dsp->pipeline,
530 len > 0 ? (char *)data : NULL);
531 dsp_cmx_hardware(dsp->conf, dsp);
532 dsp_rx_off(dsp);
533 }
534 break;
535 case DSP_BF_ENABLE_KEY: /* turn blowfish on */
536 if (dsp->hdlc) {
537 ret = -EINVAL;
538 break;
539 }
540 if (len < 4 || len > 56) {
541 ret = -EINVAL;
542 break;
543 }
544 if (dsp_debug & DEBUG_DSP_CORE)
545 printk(KERN_DEBUG "%s: turn blowfish on (key "
546 "not shown)\n", __func__);
547 ret = dsp_bf_init(dsp, (u8 *)data, len);
548 /* set new cont */
549 if (!ret)
550 cont = DSP_BF_ACCEPT;
551 else
552 cont = DSP_BF_REJECT;
553 /* send indication if it worked to set it */
554 nskb = _alloc_mISDN_skb(PH_CONTROL_IND, MISDN_ID_ANY,
555 sizeof(int), &cont, GFP_ATOMIC);
556 if (nskb) {
557 if (dsp->up) {
558 if (dsp->up->send(dsp->up, nskb))
559 dev_kfree_skb(nskb);
560 } else
561 dev_kfree_skb(nskb);
562 }
563 if (!ret) {
564 dsp_cmx_hardware(dsp->conf, dsp);
565 dsp_dtmf_hardware(dsp);
566 dsp_rx_off(dsp);
567 }
568 break;
569 case DSP_BF_DISABLE: /* turn blowfish off */
570 if (dsp->hdlc) {
571 ret = -EINVAL;
572 break;
573 }
574 if (dsp_debug & DEBUG_DSP_CORE)
575 printk(KERN_DEBUG "%s: turn blowfish off\n", __func__);
576 dsp_bf_cleanup(dsp);
577 dsp_cmx_hardware(dsp->conf, dsp);
578 dsp_dtmf_hardware(dsp);
579 dsp_rx_off(dsp);
580 break;
581 default:
582 if (dsp_debug & DEBUG_DSP_CORE)
583 printk(KERN_DEBUG "%s: ctrl req %x unhandled\n",
584 __func__, cont);
585 ret = -EINVAL;
586 }
587 return ret;
588}
589
590static void
591get_features(struct mISDNchannel *ch)
592{
593 struct dsp *dsp = container_of(ch, struct dsp, ch);
594 struct mISDN_ctrl_req cq;
595
596 if (dsp_options & DSP_OPT_NOHARDWARE)
597 return;
598 if (!ch->peer) {
599 if (dsp_debug & DEBUG_DSP_CORE)
600 printk(KERN_DEBUG "%s: no peer, no features\n",
601 __func__);
602 return;
603 }
604 memset(&cq, 0, sizeof(cq));
605 cq.op = MISDN_CTRL_GETOP;
606 if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq) < 0) {
607 printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
608 __func__);
609 return;
610 }
611 if (cq.op & MISDN_CTRL_RX_OFF)
612 dsp->features_rx_off = 1;
613 if ((cq.op & MISDN_CTRL_HW_FEATURES_OP)) {
614 cq.op = MISDN_CTRL_HW_FEATURES;
615 *((u_long *)&cq.p1) = (u_long)&dsp->features;
616 if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq)) {
617 printk(KERN_DEBUG "%s: 2nd CONTROL_CHANNEL failed\n",
618 __func__);
619 }
620 } else
621 if (dsp_debug & DEBUG_DSP_CORE)
622 printk(KERN_DEBUG "%s: features not supported for %s\n",
623 __func__, dsp->name);
624}
625
626static int
627dsp_function(struct mISDNchannel *ch, struct sk_buff *skb)
628{
629 struct dsp *dsp = container_of(ch, struct dsp, ch);
630 struct mISDNhead *hh;
631 int ret = 0;
632 u8 *digits;
633 int cont;
634 struct sk_buff *nskb;
635 u_long flags;
636
637 hh = mISDN_HEAD_P(skb);
638 switch (hh->prim) {
639 /* FROM DOWN */
640 case (PH_DATA_CNF):
641 dsp->data_pending = 0;
642 /* trigger next hdlc frame, if any */
643 if (dsp->hdlc) {
644 spin_lock_irqsave(&dsp_lock, flags);
645 if (dsp->b_active)
646 schedule_work(&dsp->workq);
647 spin_unlock_irqrestore(&dsp_lock, flags);
648 }
649 break;
650 case (PH_DATA_IND):
651 case (DL_DATA_IND):
652 if (skb->len < 1) {
653 ret = -EINVAL;
654 break;
655 }
656 if (dsp->rx_is_off) {
657 if (dsp_debug & DEBUG_DSP_CORE)
658 printk(KERN_DEBUG "%s: rx-data during rx_off"
659 " for %s\n",
660 __func__, dsp->name);
661 }
662 if (dsp->hdlc) {
663 /* hdlc */
664 spin_lock_irqsave(&dsp_lock, flags);
665 dsp_cmx_hdlc(dsp, skb);
666 spin_unlock_irqrestore(&dsp_lock, flags);
667 if (dsp->rx_disabled) {
668 /* if receive is not allowed */
669 break;
670 }
671 hh->prim = DL_DATA_IND;
672 if (dsp->up)
673 return dsp->up->send(dsp->up, skb);
674 break;
675 }
676
677 /* decrypt if enabled */
678 if (dsp->bf_enable)
679 dsp_bf_decrypt(dsp, skb->data, skb->len);
680 /* pipeline */
681 if (dsp->pipeline.inuse)
682 dsp_pipeline_process_rx(&dsp->pipeline, skb->data,
683 skb->len);
684 /* change volume if requested */
685 if (dsp->rx_volume)
686 dsp_change_volume(skb, dsp->rx_volume);
687
688 /* check if dtmf soft decoding is turned on */
689 if (dsp->dtmf.software) {
690 digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
691 skb->len, (dsp_options&DSP_OPT_ULAW)?1:0);
692 while (*digits) {
693 if (dsp_debug & DEBUG_DSP_DTMF)
694 printk(KERN_DEBUG "%s: digit"
695 "(%c) to layer %s\n",
696 __func__, *digits, dsp->name);
697 cont = DTMF_TONE_VAL | *digits;
698 nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
699 MISDN_ID_ANY, sizeof(int), &cont,
700 GFP_ATOMIC);
701 if (nskb) {
702 if (dsp->up) {
703 if (dsp->up->send(
704 dsp->up, nskb))
705 dev_kfree_skb(nskb);
706 } else
707 dev_kfree_skb(nskb);
708 }
709 digits++;
710 }
711 }
712 /* we need to process receive data if software */
713 spin_lock_irqsave(&dsp_lock, flags);
714 if (dsp->pcm_slot_tx < 0 && dsp->pcm_slot_rx < 0) {
715 /* process data from card at cmx */
716 dsp_cmx_receive(dsp, skb);
717 }
718 spin_unlock_irqrestore(&dsp_lock, flags);
719
720 if (dsp->rx_disabled) {
721 /* if receive is not allowed */
722 break;
723 }
724 hh->prim = DL_DATA_IND;
725 if (dsp->up)
726 return dsp->up->send(dsp->up, skb);
727 break;
728 case (PH_CONTROL_IND):
729 if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
730 printk(KERN_DEBUG "%s: PH_CONTROL INDICATION "
731 "received: %x (len %d) %s\n", __func__,
732 hh->id, skb->len, dsp->name);
733 switch (hh->id) {
734 case (DTMF_HFC_COEF): /* getting coefficients */
735 if (!dsp->dtmf.hardware) {
736 if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
737 printk(KERN_DEBUG "%s: ignoring DTMF "
738 "coefficients from HFC\n",
739 __func__);
740 break;
741 }
742 digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
743 skb->len, 2);
744 while (*digits) {
745 int k;
746 struct sk_buff *nskb;
747 if (dsp_debug & DEBUG_DSP_DTMF)
748 printk(KERN_DEBUG "%s: digit"
749 "(%c) to layer %s\n",
750 __func__, *digits, dsp->name);
751 k = *digits | DTMF_TONE_VAL;
752 nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
753 MISDN_ID_ANY, sizeof(int), &k,
754 GFP_ATOMIC);
755 if (nskb) {
756 if (dsp->up) {
757 if (dsp->up->send(
758 dsp->up, nskb))
759 dev_kfree_skb(nskb);
760 } else
761 dev_kfree_skb(nskb);
762 }
763 digits++;
764 }
765 break;
766 case (HFC_VOL_CHANGE_TX): /* change volume */
767 if (skb->len != sizeof(int)) {
768 ret = -EINVAL;
769 break;
770 }
771 spin_lock_irqsave(&dsp_lock, flags);
772 dsp->tx_volume = *((int *)skb->data);
773 if (dsp_debug & DEBUG_DSP_CORE)
774 printk(KERN_DEBUG "%s: change tx volume to "
775 "%d\n", __func__, dsp->tx_volume);
776 dsp_cmx_hardware(dsp->conf, dsp);
777 dsp_dtmf_hardware(dsp);
778 dsp_rx_off(dsp);
779 spin_unlock_irqrestore(&dsp_lock, flags);
780 break;
781 default:
782 if (dsp_debug & DEBUG_DSP_CORE)
783 printk(KERN_DEBUG "%s: ctrl ind %x unhandled "
784 "%s\n", __func__, hh->id, dsp->name);
785 ret = -EINVAL;
786 }
787 break;
788 case (PH_ACTIVATE_IND):
789 case (PH_ACTIVATE_CNF):
790 if (dsp_debug & DEBUG_DSP_CORE)
791 printk(KERN_DEBUG "%s: b_channel is now active %s\n",
792 __func__, dsp->name);
793 /* bchannel now active */
794 spin_lock_irqsave(&dsp_lock, flags);
795 dsp->b_active = 1;
796 dsp->data_pending = 0;
797 dsp->rx_init = 1;
798 /* rx_W and rx_R will be adjusted on first frame */
799 dsp->rx_W = 0;
800 dsp->rx_R = 0;
801 memset(dsp->rx_buff, 0, sizeof(dsp->rx_buff));
802 dsp_cmx_hardware(dsp->conf, dsp);
803 dsp_dtmf_hardware(dsp);
804 dsp_rx_off(dsp);
805 spin_unlock_irqrestore(&dsp_lock, flags);
806 if (dsp_debug & DEBUG_DSP_CORE)
807 printk(KERN_DEBUG "%s: done with activation, sending "
808 "confirm to user space. %s\n", __func__,
809 dsp->name);
810 /* send activation to upper layer */
811 hh->prim = DL_ESTABLISH_CNF;
812 if (dsp->up)
813 return dsp->up->send(dsp->up, skb);
814 break;
815 case (PH_DEACTIVATE_IND):
816 case (PH_DEACTIVATE_CNF):
817 if (dsp_debug & DEBUG_DSP_CORE)
818 printk(KERN_DEBUG "%s: b_channel is now inactive %s\n",
819 __func__, dsp->name);
820 /* bchannel now inactive */
821 spin_lock_irqsave(&dsp_lock, flags);
822 dsp->b_active = 0;
823 dsp->data_pending = 0;
824 dsp_cmx_hardware(dsp->conf, dsp);
825 dsp_rx_off(dsp);
826 spin_unlock_irqrestore(&dsp_lock, flags);
827 hh->prim = DL_RELEASE_CNF;
828 if (dsp->up)
829 return dsp->up->send(dsp->up, skb);
830 break;
831 /* FROM UP */
832 case (DL_DATA_REQ):
833 case (PH_DATA_REQ):
834 if (skb->len < 1) {
835 ret = -EINVAL;
836 break;
837 }
838 if (dsp->hdlc) {
839 /* hdlc */
840 spin_lock_irqsave(&dsp_lock, flags);
841 if (dsp->b_active) {
842 skb_queue_tail(&dsp->sendq, skb);
843 schedule_work(&dsp->workq);
844 }
845 spin_unlock_irqrestore(&dsp_lock, flags);
846 return 0;
847 }
848 /* send data to tx-buffer (if no tone is played) */
849 if (!dsp->tone.tone) {
850 spin_lock_irqsave(&dsp_lock, flags);
851 dsp_cmx_transmit(dsp, skb);
852 spin_unlock_irqrestore(&dsp_lock, flags);
853 }
854 break;
855 case (PH_CONTROL_REQ):
856 spin_lock_irqsave(&dsp_lock, flags);
857 ret = dsp_control_req(dsp, hh, skb);
858 spin_unlock_irqrestore(&dsp_lock, flags);
859 break;
860 case (DL_ESTABLISH_REQ):
861 case (PH_ACTIVATE_REQ):
862 if (dsp_debug & DEBUG_DSP_CORE)
863 printk(KERN_DEBUG "%s: activating b_channel %s\n",
864 __func__, dsp->name);
865 if (dsp->dtmf.hardware || dsp->dtmf.software)
866 dsp_dtmf_goertzel_init(dsp);
867 get_features(ch);
868 /* send ph_activate */
869 hh->prim = PH_ACTIVATE_REQ;
870 if (ch->peer)
871 return ch->recv(ch->peer, skb);
872 break;
873 case (DL_RELEASE_REQ):
874 case (PH_DEACTIVATE_REQ):
875 if (dsp_debug & DEBUG_DSP_CORE)
876 printk(KERN_DEBUG "%s: releasing b_channel %s\n",
877 __func__, dsp->name);
878 spin_lock_irqsave(&dsp_lock, flags);
879 dsp->tone.tone = 0;
880 dsp->tone.hardware = 0;
881 dsp->tone.software = 0;
882 if (timer_pending(&dsp->tone.tl))
883 del_timer(&dsp->tone.tl);
884 if (dsp->conf)
885 dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be
886 called here */
887 skb_queue_purge(&dsp->sendq);
888 spin_unlock_irqrestore(&dsp_lock, flags);
889 hh->prim = PH_DEACTIVATE_REQ;
890 if (ch->peer)
891 return ch->recv(ch->peer, skb);
892 break;
893 default:
894 if (dsp_debug & DEBUG_DSP_CORE)
895 printk(KERN_DEBUG "%s: msg %x unhandled %s\n",
896 __func__, hh->prim, dsp->name);
897 ret = -EINVAL;
898 }
899 if (!ret)
900 dev_kfree_skb(skb);
901 return ret;
902}
903
904static int
905dsp_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
906{
907 struct dsp *dsp = container_of(ch, struct dsp, ch);
908 u_long flags;
909 int err = 0;
910
911 if (debug & DEBUG_DSP_CTRL)
912 printk(KERN_DEBUG "%s:(%x)\n", __func__, cmd);
913
914 switch (cmd) {
915 case OPEN_CHANNEL:
916 break;
917 case CLOSE_CHANNEL:
918 if (dsp->ch.peer)
919 dsp->ch.peer->ctrl(dsp->ch.peer, CLOSE_CHANNEL, NULL);
920
921 /* wait until workqueue has finished,
922 * must lock here, or we may hit send-process currently
923 * queueing. */
924 spin_lock_irqsave(&dsp_lock, flags);
925 dsp->b_active = 0;
926 spin_unlock_irqrestore(&dsp_lock, flags);
927 /* MUST not be locked, because it waits until queue is done. */
928 cancel_work_sync(&dsp->workq);
929 spin_lock_irqsave(&dsp_lock, flags);
930 if (timer_pending(&dsp->tone.tl))
931 del_timer(&dsp->tone.tl);
932 skb_queue_purge(&dsp->sendq);
933 if (dsp_debug & DEBUG_DSP_CTRL)
934 printk(KERN_DEBUG "%s: releasing member %s\n",
935 __func__, dsp->name);
936 dsp->b_active = 0;
937 dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be called
938 here */
939 dsp_pipeline_destroy(&dsp->pipeline);
940
941 if (dsp_debug & DEBUG_DSP_CTRL)
942 printk(KERN_DEBUG "%s: remove & destroy object %s\n",
943 __func__, dsp->name);
944 list_del(&dsp->list);
945 spin_unlock_irqrestore(&dsp_lock, flags);
946
947 if (dsp_debug & DEBUG_DSP_CTRL)
948 printk(KERN_DEBUG "%s: dsp instance released\n",
949 __func__);
950 vfree(dsp);
951 module_put(THIS_MODULE);
952 break;
953 }
954 return err;
955}
956
957static void
958dsp_send_bh(struct work_struct *work)
959{
960 struct dsp *dsp = container_of(work, struct dsp, workq);
961 struct sk_buff *skb;
962 struct mISDNhead *hh;
963
964 if (dsp->hdlc && dsp->data_pending)
965 return; /* wait until data has been acknowledged */
966
967 /* send queued data */
968 while ((skb = skb_dequeue(&dsp->sendq))) {
969 /* in locked date, we must have still data in queue */
970 if (dsp->data_pending) {
971 if (dsp_debug & DEBUG_DSP_CORE)
972 printk(KERN_DEBUG "%s: fifo full %s, this is "
973 "no bug!\n", __func__, dsp->name);
974 /* flush transparent data, if not acked */
975 dev_kfree_skb(skb);
976 continue;
977 }
978 hh = mISDN_HEAD_P(skb);
979 if (hh->prim == DL_DATA_REQ) {
980 /* send packet up */
981 if (dsp->up) {
982 if (dsp->up->send(dsp->up, skb))
983 dev_kfree_skb(skb);
984 } else
985 dev_kfree_skb(skb);
986 } else {
987 /* send packet down */
988 if (dsp->ch.peer) {
989 dsp->data_pending = 1;
990 if (dsp->ch.recv(dsp->ch.peer, skb)) {
991 dev_kfree_skb(skb);
992 dsp->data_pending = 0;
993 }
994 } else
995 dev_kfree_skb(skb);
996 }
997 }
998}
999
1000static int
1001dspcreate(struct channel_req *crq)
1002{
1003 struct dsp *ndsp;
1004 u_long flags;
1005
1006 if (crq->protocol != ISDN_P_B_L2DSP
1007 && crq->protocol != ISDN_P_B_L2DSPHDLC)
1008 return -EPROTONOSUPPORT;
1009 ndsp = vmalloc(sizeof(struct dsp));
1010 if (!ndsp) {
1011 printk(KERN_ERR "%s: vmalloc struct dsp failed\n", __func__);
1012 return -ENOMEM;
1013 }
1014 memset(ndsp, 0, sizeof(struct dsp));
1015 if (dsp_debug & DEBUG_DSP_CTRL)
1016 printk(KERN_DEBUG "%s: creating new dsp instance\n", __func__);
1017
1018 /* default enabled */
1019 INIT_WORK(&ndsp->workq, (void *)dsp_send_bh);
1020 skb_queue_head_init(&ndsp->sendq);
1021 ndsp->ch.send = dsp_function;
1022 ndsp->ch.ctrl = dsp_ctrl;
1023 ndsp->up = crq->ch;
1024 crq->ch = &ndsp->ch;
1025 if (crq->protocol == ISDN_P_B_L2DSP) {
1026 crq->protocol = ISDN_P_B_RAW;
1027 ndsp->hdlc = 0;
1028 } else {
1029 crq->protocol = ISDN_P_B_HDLC;
1030 ndsp->hdlc = 1;
1031 }
1032 if (!try_module_get(THIS_MODULE))
1033 printk(KERN_WARNING "%s:cannot get module\n",
1034 __func__);
1035
1036 sprintf(ndsp->name, "DSP_C%x(0x%p)",
1037 ndsp->up->st->dev->id + 1, ndsp);
1038 /* set frame size to start */
1039 ndsp->features.hfc_id = -1; /* current PCM id */
1040 ndsp->features.pcm_id = -1; /* current PCM id */
1041 ndsp->pcm_slot_rx = -1; /* current CPM slot */
1042 ndsp->pcm_slot_tx = -1;
1043 ndsp->pcm_bank_rx = -1;
1044 ndsp->pcm_bank_tx = -1;
1045 ndsp->hfc_conf = -1; /* current conference number */
1046 /* set tone timer */
1047 ndsp->tone.tl.function = (void *)dsp_tone_timeout;
1048 ndsp->tone.tl.data = (long) ndsp;
1049 init_timer(&ndsp->tone.tl);
1050
1051 if (dtmfthreshold < 20 || dtmfthreshold > 500)
1052 dtmfthreshold = 200;
1053 ndsp->dtmf.treshold = dtmfthreshold*10000;
1054
1055 /* init pipeline append to list */
1056 spin_lock_irqsave(&dsp_lock, flags);
1057 dsp_pipeline_init(&ndsp->pipeline);
1058 list_add_tail(&ndsp->list, &dsp_ilist);
1059 spin_unlock_irqrestore(&dsp_lock, flags);
1060
1061 return 0;
1062}
1063
1064
1065static struct Bprotocol DSP = {
1066 .Bprotocols = (1 << (ISDN_P_B_L2DSP & ISDN_P_B_MASK))
1067 | (1 << (ISDN_P_B_L2DSPHDLC & ISDN_P_B_MASK)),
1068 .name = "dsp",
1069 .create = dspcreate
1070};
1071
1072static int dsp_init(void)
1073{
1074 int err;
1075 int tics;
1076
1077 printk(KERN_INFO "DSP modul %s\n", mISDN_dsp_revision);
1078
1079 dsp_options = options;
1080 dsp_debug = debug;
1081
1082 /* set packet size */
1083 dsp_poll = poll;
1084 if (dsp_poll) {
1085 if (dsp_poll > MAX_POLL) {
1086 printk(KERN_ERR "%s: Wrong poll value (%d), use %d "
1087 "maximum.\n", __func__, poll, MAX_POLL);
1088 err = -EINVAL;
1089 return err;
1090 }
1091 if (dsp_poll < 8) {
1092 printk(KERN_ERR "%s: Wrong poll value (%d), use 8 "
1093 "minimum.\n", __func__, dsp_poll);
1094 err = -EINVAL;
1095 return err;
1096 }
1097 dsp_tics = poll * HZ / 8000;
1098 if (dsp_tics * 8000 != poll * HZ) {
1099 printk(KERN_INFO "mISDN_dsp: Cannot clock every %d "
1100 "samples (0,125 ms). It is not a multiple of "
1101 "%d HZ.\n", poll, HZ);
1102 err = -EINVAL;
1103 return err;
1104 }
1105 } else {
1106 poll = 8;
1107 while (poll <= MAX_POLL) {
1108 tics = poll * HZ / 8000;
1109 if (tics * 8000 == poll * HZ) {
1110 dsp_tics = tics;
1111 dsp_poll = poll;
1112 if (poll >= 64)
1113 break;
1114 }
1115 poll++;
1116 }
1117 }
1118 if (dsp_poll == 0) {
1119 printk(KERN_INFO "mISDN_dsp: There is no multiple of kernel "
1120 "clock that equals exactly the duration of 8-256 "
1121 "samples. (Choose kernel clock speed like 100, 250, "
1122 "300, 1000)\n");
1123 err = -EINVAL;
1124 return err;
1125 }
1126 printk(KERN_INFO "mISDN_dsp: DSP clocks every %d samples. This equals "
1127 "%d jiffies.\n", dsp_poll, dsp_tics);
1128
1129 spin_lock_init(&dsp_lock);
1130 INIT_LIST_HEAD(&dsp_ilist);
1131 INIT_LIST_HEAD(&conf_ilist);
1132
1133 /* init conversion tables */
1134 dsp_audio_generate_law_tables();
1135 dsp_silence = (dsp_options&DSP_OPT_ULAW)?0xff:0x2a;
1136 dsp_audio_law_to_s32 = (dsp_options&DSP_OPT_ULAW)?dsp_audio_ulaw_to_s32:
1137 dsp_audio_alaw_to_s32;
1138 dsp_audio_generate_s2law_table();
1139 dsp_audio_generate_seven();
1140 dsp_audio_generate_mix_table();
1141 if (dsp_options & DSP_OPT_ULAW)
1142 dsp_audio_generate_ulaw_samples();
1143 dsp_audio_generate_volume_changes();
1144
1145 err = dsp_pipeline_module_init();
1146 if (err) {
1147 printk(KERN_ERR "mISDN_dsp: Can't initialize pipeline, "
1148 "error(%d)\n", err);
1149 return err;
1150 }
1151
1152 err = mISDN_register_Bprotocol(&DSP);
1153 if (err) {
1154 printk(KERN_ERR "Can't register %s error(%d)\n", DSP.name, err);
1155 return err;
1156 }
1157
1158 /* set sample timer */
1159 dsp_spl_tl.function = (void *)dsp_cmx_send;
1160 dsp_spl_tl.data = 0;
1161 init_timer(&dsp_spl_tl);
1162 dsp_spl_tl.expires = jiffies + dsp_tics;
1163 dsp_spl_jiffies = dsp_spl_tl.expires;
1164 add_timer(&dsp_spl_tl);
1165
1166 return 0;
1167}
1168
1169
1170static void dsp_cleanup(void)
1171{
1172 mISDN_unregister_Bprotocol(&DSP);
1173
1174 if (timer_pending(&dsp_spl_tl))
1175 del_timer(&dsp_spl_tl);
1176
1177 if (!list_empty(&dsp_ilist)) {
1178 printk(KERN_ERR "mISDN_dsp: Audio DSP object inst list not "
1179 "empty.\n");
1180 }
1181 if (!list_empty(&conf_ilist)) {
1182 printk(KERN_ERR "mISDN_dsp: Conference list not empty. Not "
1183 "all memory freed.\n");
1184 }
1185
1186 dsp_pipeline_module_exit();
1187}
1188
1189module_init(dsp_init);
1190module_exit(dsp_cleanup);
1191
diff --git a/drivers/isdn/mISDN/dsp_dtmf.c b/drivers/isdn/mISDN/dsp_dtmf.c
new file mode 100644
index 000000000000..efc371c1f0dc
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp_dtmf.c
@@ -0,0 +1,303 @@
1/*
2 * DTMF decoder.
3 *
4 * Copyright by Andreas Eversberg (jolly@eversberg.eu)
5 * based on different decoders such as ISDN4Linux
6 *
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
9 *
10 */
11
12#include <linux/mISDNif.h>
13#include <linux/mISDNdsp.h>
14#include "core.h"
15#include "dsp.h"
16
17#define NCOEFF 8 /* number of frequencies to be analyzed */
18
19/* For DTMF recognition:
20 * 2 * cos(2 * PI * k / N) precalculated for all k
21 */
22static u64 cos2pik[NCOEFF] =
23{
24 /* k << 15 (source: hfc-4s/8s documentation (www.colognechip.de)) */
25 55960, 53912, 51402, 48438, 38146, 32650, 26170, 18630
26};
27
28/* digit matrix */
29static char dtmf_matrix[4][4] =
30{
31 {'1', '2', '3', 'A'},
32 {'4', '5', '6', 'B'},
33 {'7', '8', '9', 'C'},
34 {'*', '0', '#', 'D'}
35};
36
37/* dtmf detection using goertzel algorithm
38 * init function
39 */
40void dsp_dtmf_goertzel_init(struct dsp *dsp)
41{
42 dsp->dtmf.size = 0;
43 dsp->dtmf.lastwhat = '\0';
44 dsp->dtmf.lastdigit = '\0';
45 dsp->dtmf.count = 0;
46}
47
48/* check for hardware or software features
49 */
50void dsp_dtmf_hardware(struct dsp *dsp)
51{
52 int hardware = 1;
53
54 if (!dsp->features.hfc_dtmf)
55 hardware = 0;
56
57 /* check for volume change */
58 if (dsp->tx_volume) {
59 if (dsp_debug & DEBUG_DSP_DTMF)
60 printk(KERN_DEBUG "%s dsp %s cannot do hardware DTMF, "
61 "because tx_volume is changed\n",
62 __func__, dsp->name);
63 hardware = 0;
64 }
65 if (dsp->rx_volume) {
66 if (dsp_debug & DEBUG_DSP_DTMF)
67 printk(KERN_DEBUG "%s dsp %s cannot do hardware DTMF, "
68 "because rx_volume is changed\n",
69 __func__, dsp->name);
70 hardware = 0;
71 }
72 /* check if encryption is enabled */
73 if (dsp->bf_enable) {
74 if (dsp_debug & DEBUG_DSP_DTMF)
75 printk(KERN_DEBUG "%s dsp %s cannot do hardware DTMF, "
76 "because encryption is enabled\n",
77 __func__, dsp->name);
78 hardware = 0;
79 }
80 /* check if pipeline exists */
81 if (dsp->pipeline.inuse) {
82 if (dsp_debug & DEBUG_DSP_DTMF)
83 printk(KERN_DEBUG "%s dsp %s cannot do hardware DTMF, "
84 "because pipeline exists.\n",
85 __func__, dsp->name);
86 hardware = 0;
87 }
88
89 dsp->dtmf.hardware = hardware;
90 dsp->dtmf.software = !hardware;
91}
92
93
94/*************************************************************
95 * calculate the coefficients of the given sample and decode *
96 *************************************************************/
97
98/* the given sample is decoded. if the sample is not long enough for a
99 * complete frame, the decoding is finished and continued with the next
100 * call of this function.
101 *
102 * the algorithm is very good for detection with a minimum of errors. i
103 * tested it allot. it even works with very short tones (40ms). the only
104 * disadvantage is, that it doesn't work good with different volumes of both
105 * tones. this will happen, if accoustically coupled dialers are used.
106 * it sometimes detects tones during speach, which is normal for decoders.
107 * use sequences to given commands during calls.
108 *
109 * dtmf - points to a structure of the current dtmf state
110 * spl and len - the sample
111 * fmt - 0 = alaw, 1 = ulaw, 2 = coefficients from HFC DTMF hw-decoder
112 */
113
114u8
115*dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 *data, int len, int fmt)
116{
117 u8 what;
118 int size;
119 signed short *buf;
120 s32 sk, sk1, sk2;
121 int k, n, i;
122 s32 *hfccoeff;
123 s32 result[NCOEFF], tresh, treshl;
124 int lowgroup, highgroup;
125 s64 cos2pik_;
126
127 dsp->dtmf.digits[0] = '\0';
128
129 /* Note: The function will loop until the buffer has not enough samples
130 * left to decode a full frame.
131 */
132again:
133 /* convert samples */
134 size = dsp->dtmf.size;
135 buf = dsp->dtmf.buffer;
136 switch (fmt) {
137 case 0: /* alaw */
138 case 1: /* ulaw */
139 while (size < DSP_DTMF_NPOINTS && len) {
140 buf[size++] = dsp_audio_law_to_s32[*data++];
141 len--;
142 }
143 break;
144
145 case 2: /* HFC coefficients */
146 default:
147 if (len < 64) {
148 if (len > 0)
149 printk(KERN_ERR "%s: coefficients have invalid "
150 "size. (is=%d < must=%d)\n",
151 __func__, len, 64);
152 return dsp->dtmf.digits;
153 }
154 hfccoeff = (s32 *)data;
155 for (k = 0; k < NCOEFF; k++) {
156 sk2 = (*hfccoeff++)>>4;
157 sk = (*hfccoeff++)>>4;
158 if (sk > 32767 || sk < -32767 || sk2 > 32767
159 || sk2 < -32767)
160 printk(KERN_WARNING
161 "DTMF-Detection overflow\n");
162 /* compute |X(k)|**2 */
163 result[k] =
164 (sk * sk) -
165 (((cos2pik[k] * sk) >> 15) * sk2) +
166 (sk2 * sk2);
167 }
168 data += 64;
169 len -= 64;
170 goto coefficients;
171 break;
172 }
173 dsp->dtmf.size = size;
174
175 if (size < DSP_DTMF_NPOINTS)
176 return dsp->dtmf.digits;
177
178 dsp->dtmf.size = 0;
179
180 /* now we have a full buffer of signed long samples - we do goertzel */
181 for (k = 0; k < NCOEFF; k++) {
182 sk = 0;
183 sk1 = 0;
184 sk2 = 0;
185 buf = dsp->dtmf.buffer;
186 cos2pik_ = cos2pik[k];
187 for (n = 0; n < DSP_DTMF_NPOINTS; n++) {
188 sk = ((cos2pik_*sk1)>>15) - sk2 + (*buf++);
189 sk2 = sk1;
190 sk1 = sk;
191 }
192 sk >>= 8;
193 sk2 >>= 8;
194 if (sk > 32767 || sk < -32767 || sk2 > 32767 || sk2 < -32767)
195 printk(KERN_WARNING "DTMF-Detection overflow\n");
196 /* compute |X(k)|**2 */
197 result[k] =
198 (sk * sk) -
199 (((cos2pik[k] * sk) >> 15) * sk2) +
200 (sk2 * sk2);
201 }
202
203 /* our (squared) coefficients have been calculated, we need to process
204 * them.
205 */
206coefficients:
207 tresh = 0;
208 for (i = 0; i < NCOEFF; i++) {
209 if (result[i] < 0)
210 result[i] = 0;
211 if (result[i] > dsp->dtmf.treshold) {
212 if (result[i] > tresh)
213 tresh = result[i];
214 }
215 }
216
217 if (tresh == 0) {
218 what = 0;
219 goto storedigit;
220 }
221
222 if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
223 printk(KERN_DEBUG "a %3d %3d %3d %3d %3d %3d %3d %3d"
224 " tr:%3d r %3d %3d %3d %3d %3d %3d %3d %3d\n",
225 result[0]/10000, result[1]/10000, result[2]/10000,
226 result[3]/10000, result[4]/10000, result[5]/10000,
227 result[6]/10000, result[7]/10000, tresh/10000,
228 result[0]/(tresh/100), result[1]/(tresh/100),
229 result[2]/(tresh/100), result[3]/(tresh/100),
230 result[4]/(tresh/100), result[5]/(tresh/100),
231 result[6]/(tresh/100), result[7]/(tresh/100));
232
233 /* calc digit (lowgroup/highgroup) */
234 lowgroup = -1;
235 highgroup = -1;
236 treshl = tresh >> 3; /* tones which are not on, must be below 9 dB */
237 tresh = tresh >> 2; /* touchtones must match within 6 dB */
238 for (i = 0; i < NCOEFF; i++) {
239 if (result[i] < treshl)
240 continue; /* ignore */
241 if (result[i] < tresh) {
242 lowgroup = -1;
243 highgroup = -1;
244 break; /* noise inbetween */
245 }
246 /* good level found. This is allowed only one time per group */
247 if (i < NCOEFF/2) {
248 /* lowgroup */
249 if (lowgroup >= 0) {
250 /* Bad. Another tone found. */
251 lowgroup = -1;
252 break;
253 } else
254 lowgroup = i;
255 } else {
256 /* higroup */
257 if (highgroup >= 0) {
258 /* Bad. Another tone found. */
259 highgroup = -1;
260 break;
261 } else
262 highgroup = i-(NCOEFF/2);
263 }
264 }
265
266 /* get digit or null */
267 what = 0;
268 if (lowgroup >= 0 && highgroup >= 0)
269 what = dtmf_matrix[lowgroup][highgroup];
270
271storedigit:
272 if (what && (dsp_debug & DEBUG_DSP_DTMF))
273 printk(KERN_DEBUG "DTMF what: %c\n", what);
274
275 if (dsp->dtmf.lastwhat != what)
276 dsp->dtmf.count = 0;
277
278 /* the tone (or no tone) must remain 3 times without change */
279 if (dsp->dtmf.count == 2) {
280 if (dsp->dtmf.lastdigit != what) {
281 dsp->dtmf.lastdigit = what;
282 if (what) {
283 if (dsp_debug & DEBUG_DSP_DTMF)
284 printk(KERN_DEBUG "DTMF digit: %c\n",
285 what);
286 if ((strlen(dsp->dtmf.digits)+1)
287 < sizeof(dsp->dtmf.digits)) {
288 dsp->dtmf.digits[strlen(
289 dsp->dtmf.digits)+1] = '\0';
290 dsp->dtmf.digits[strlen(
291 dsp->dtmf.digits)] = what;
292 }
293 }
294 }
295 } else
296 dsp->dtmf.count++;
297
298 dsp->dtmf.lastwhat = what;
299
300 goto again;
301}
302
303
diff --git a/drivers/isdn/mISDN/dsp_ecdis.h b/drivers/isdn/mISDN/dsp_ecdis.h
new file mode 100644
index 000000000000..8a20af43308b
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp_ecdis.h
@@ -0,0 +1,110 @@
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * ec_disable_detector.h - A detector which should eventually meet the
5 * G.164/G.165 requirements for detecting the
6 * 2100Hz echo cancellor disable tone.
7 *
8 * Written by Steve Underwood <steveu@coppice.org>
9 *
10 * Copyright (C) 2001 Steve Underwood
11 *
12 * All rights reserved.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 */
29
30#include "dsp_biquad.h"
31
32struct ec_disable_detector_state {
33 struct biquad2_state notch;
34 int notch_level;
35 int channel_level;
36 int tone_present;
37 int tone_cycle_duration;
38 int good_cycles;
39 int hit;
40};
41
42
43#define FALSE 0
44#define TRUE (!FALSE)
45
46static inline void
47echo_can_disable_detector_init(struct ec_disable_detector_state *det)
48{
49 /* Elliptic notch */
50 /* This is actually centred at 2095Hz, but gets the balance we want, due
51 to the asymmetric walls of the notch */
52 biquad2_init(&det->notch,
53 (int32_t) (-0.7600000*32768.0),
54 (int32_t) (-0.1183852*32768.0),
55 (int32_t) (-0.5104039*32768.0),
56 (int32_t) (0.1567596*32768.0),
57 (int32_t) (1.0000000*32768.0));
58
59 det->channel_level = 0;
60 det->notch_level = 0;
61 det->tone_present = FALSE;
62 det->tone_cycle_duration = 0;
63 det->good_cycles = 0;
64 det->hit = 0;
65}
66/*- End of function --------------------------------------------------------*/
67
68static inline int
69echo_can_disable_detector_update(struct ec_disable_detector_state *det,
70int16_t amp)
71{
72 int16_t notched;
73
74 notched = biquad2(&det->notch, amp);
75 /* Estimate the overall energy in the channel, and the energy in
76 the notch (i.e. overall channel energy - tone energy => noise).
77 Use abs instead of multiply for speed (is it really faster?).
78 Damp the overall energy a little more for a stable result.
79 Damp the notch energy a little less, so we don't damp out the
80 blip every time the phase reverses */
81 det->channel_level += ((abs(amp) - det->channel_level) >> 5);
82 det->notch_level += ((abs(notched) - det->notch_level) >> 4);
83 if (det->channel_level > 280) {
84 /* There is adequate energy in the channel.
85 Is it mostly at 2100Hz? */
86 if (det->notch_level*6 < det->channel_level) {
87 /* The notch says yes, so we have the tone. */
88 if (!det->tone_present) {
89 /* Do we get a kick every 450+-25ms? */
90 if (det->tone_cycle_duration >= 425*8
91 && det->tone_cycle_duration <= 475*8) {
92 det->good_cycles++;
93 if (det->good_cycles > 2)
94 det->hit = TRUE;
95 }
96 det->tone_cycle_duration = 0;
97 }
98 det->tone_present = TRUE;
99 } else
100 det->tone_present = FALSE;
101 det->tone_cycle_duration++;
102 } else {
103 det->tone_present = FALSE;
104 det->tone_cycle_duration = 0;
105 det->good_cycles = 0;
106 }
107 return det->hit;
108}
109/*- End of function --------------------------------------------------------*/
110/*- End of file ------------------------------------------------------------*/
diff --git a/drivers/isdn/mISDN/dsp_hwec.c b/drivers/isdn/mISDN/dsp_hwec.c
new file mode 100644
index 000000000000..eb892d9dd5c6
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp_hwec.c
@@ -0,0 +1,138 @@
1/*
2 * dsp_hwec.c:
3 * builtin mISDN dsp pipeline element for enabling the hw echocanceller
4 *
5 * Copyright (C) 2007, Nadi Sarrar
6 *
7 * Nadi Sarrar <nadi@beronet.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program; if not, write to the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 * The full GNU General Public License is included in this distribution in the
24 * file called LICENSE.
25 *
26 */
27
28#include <linux/kernel.h>
29#include <linux/string.h>
30#include <linux/mISDNdsp.h>
31#include <linux/mISDNif.h>
32#include "core.h"
33#include "dsp.h"
34#include "dsp_hwec.h"
35
36static struct mISDN_dsp_element_arg args[] = {
37 { "deftaps", "128", "Set the number of taps of cancellation." },
38};
39
40static struct mISDN_dsp_element dsp_hwec_p = {
41 .name = "hwec",
42 .new = NULL,
43 .free = NULL,
44 .process_tx = NULL,
45 .process_rx = NULL,
46 .num_args = sizeof(args) / sizeof(struct mISDN_dsp_element_arg),
47 .args = args,
48};
49struct mISDN_dsp_element *dsp_hwec = &dsp_hwec_p;
50
51void dsp_hwec_enable(struct dsp *dsp, const char *arg)
52{
53 int deftaps = 128,
54 len;
55 struct mISDN_ctrl_req cq;
56
57 if (!dsp) {
58 printk(KERN_ERR "%s: failed to enable hwec: dsp is NULL\n",
59 __func__);
60 return;
61 }
62
63 if (!arg)
64 goto _do;
65
66 len = strlen(arg);
67 if (!len)
68 goto _do;
69
70 {
71 char _dup[len + 1];
72 char *dup, *tok, *name, *val;
73 int tmp;
74
75 strcpy(_dup, arg);
76 dup = _dup;
77
78 while ((tok = strsep(&dup, ","))) {
79 if (!strlen(tok))
80 continue;
81 name = strsep(&tok, "=");
82 val = tok;
83
84 if (!val)
85 continue;
86
87 if (!strcmp(name, "deftaps")) {
88 if (sscanf(val, "%d", &tmp) == 1)
89 deftaps = tmp;
90 }
91 }
92 }
93
94_do:
95 printk(KERN_DEBUG "%s: enabling hwec with deftaps=%d\n",
96 __func__, deftaps);
97 memset(&cq, 0, sizeof(cq));
98 cq.op = MISDN_CTRL_HFC_ECHOCAN_ON;
99 cq.p1 = deftaps;
100 if (!dsp->ch.peer->ctrl(&dsp->ch, CONTROL_CHANNEL, &cq)) {
101 printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
102 __func__);
103 return;
104 }
105}
106
107void dsp_hwec_disable(struct dsp *dsp)
108{
109 struct mISDN_ctrl_req cq;
110
111 if (!dsp) {
112 printk(KERN_ERR "%s: failed to disable hwec: dsp is NULL\n",
113 __func__);
114 return;
115 }
116
117 printk(KERN_DEBUG "%s: disabling hwec\n", __func__);
118 memset(&cq, 0, sizeof(cq));
119 cq.op = MISDN_CTRL_HFC_ECHOCAN_OFF;
120 if (!dsp->ch.peer->ctrl(&dsp->ch, CONTROL_CHANNEL, &cq)) {
121 printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
122 __func__);
123 return;
124 }
125}
126
127int dsp_hwec_init(void)
128{
129 mISDN_dsp_element_register(dsp_hwec);
130
131 return 0;
132}
133
134void dsp_hwec_exit(void)
135{
136 mISDN_dsp_element_unregister(dsp_hwec);
137}
138
diff --git a/drivers/isdn/mISDN/dsp_hwec.h b/drivers/isdn/mISDN/dsp_hwec.h
new file mode 100644
index 000000000000..eebe80c3f713
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp_hwec.h
@@ -0,0 +1,10 @@
1/*
2 * dsp_hwec.h
3 */
4
5extern struct mISDN_dsp_element *dsp_hwec;
6extern void dsp_hwec_enable(struct dsp *dsp, const char *arg);
7extern void dsp_hwec_disable(struct dsp *dsp);
8extern int dsp_hwec_init(void);
9extern void dsp_hwec_exit(void);
10
diff --git a/drivers/isdn/mISDN/dsp_pipeline.c b/drivers/isdn/mISDN/dsp_pipeline.c
new file mode 100644
index 000000000000..850260ab57d0
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp_pipeline.c
@@ -0,0 +1,348 @@
1/*
2 * dsp_pipeline.c: pipelined audio processing
3 *
4 * Copyright (C) 2007, Nadi Sarrar
5 *
6 * Nadi Sarrar <nadi@beronet.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 * The full GNU General Public License is included in this distribution in the
23 * file called LICENSE.
24 *
25 */
26
27#include <linux/kernel.h>
28#include <linux/list.h>
29#include <linux/string.h>
30#include <linux/mISDNif.h>
31#include <linux/mISDNdsp.h>
32#include "dsp.h"
33#include "dsp_hwec.h"
34
35/* uncomment for debugging */
36/*#define PIPELINE_DEBUG*/
37
38struct dsp_pipeline_entry {
39 struct mISDN_dsp_element *elem;
40 void *p;
41 struct list_head list;
42};
43struct dsp_element_entry {
44 struct mISDN_dsp_element *elem;
45 struct device dev;
46 struct list_head list;
47};
48
49static LIST_HEAD(dsp_elements);
50
51/* sysfs */
52static struct class *elements_class;
53
54static ssize_t
55attr_show_args(struct device *dev, struct device_attribute *attr, char *buf)
56{
57 struct mISDN_dsp_element *elem = dev_get_drvdata(dev);
58 ssize_t len = 0;
59 int i = 0;
60
61 *buf = 0;
62 for (; i < elem->num_args; ++i)
63 len = sprintf(buf, "%sName: %s\n%s%s%sDescription: %s\n"
64 "\n", buf,
65 elem->args[i].name,
66 elem->args[i].def ? "Default: " : "",
67 elem->args[i].def ? elem->args[i].def : "",
68 elem->args[i].def ? "\n" : "",
69 elem->args[i].desc);
70
71 return len;
72}
73
74static struct device_attribute element_attributes[] = {
75 __ATTR(args, 0444, attr_show_args, NULL),
76};
77
78int mISDN_dsp_element_register(struct mISDN_dsp_element *elem)
79{
80 struct dsp_element_entry *entry;
81 int ret, i;
82
83 if (!elem)
84 return -EINVAL;
85
86 entry = kzalloc(sizeof(struct dsp_element_entry), GFP_KERNEL);
87 if (!entry)
88 return -ENOMEM;
89
90 entry->elem = elem;
91
92 entry->dev.class = elements_class;
93 dev_set_drvdata(&entry->dev, elem);
94 snprintf(entry->dev.bus_id, BUS_ID_SIZE, elem->name);
95 ret = device_register(&entry->dev);
96 if (ret) {
97 printk(KERN_ERR "%s: failed to register %s\n",
98 __func__, elem->name);
99 goto err1;
100 }
101
102 for (i = 0; i < (sizeof(element_attributes)
103 / sizeof(struct device_attribute)); ++i)
104 ret = device_create_file(&entry->dev,
105 &element_attributes[i]);
106 if (ret) {
107 printk(KERN_ERR "%s: failed to create device file\n",
108 __func__);
109 goto err2;
110 }
111
112 list_add_tail(&entry->list, &dsp_elements);
113
114 printk(KERN_DEBUG "%s: %s registered\n", __func__, elem->name);
115
116 return 0;
117
118err2:
119 device_unregister(&entry->dev);
120err1:
121 kfree(entry);
122 return ret;
123}
124EXPORT_SYMBOL(mISDN_dsp_element_register);
125
126void mISDN_dsp_element_unregister(struct mISDN_dsp_element *elem)
127{
128 struct dsp_element_entry *entry, *n;
129
130 if (!elem)
131 return;
132
133 list_for_each_entry_safe(entry, n, &dsp_elements, list)
134 if (entry->elem == elem) {
135 list_del(&entry->list);
136 device_unregister(&entry->dev);
137 kfree(entry);
138 printk(KERN_DEBUG "%s: %s unregistered\n",
139 __func__, elem->name);
140 return;
141 }
142 printk(KERN_ERR "%s: element %s not in list.\n", __func__, elem->name);
143}
144EXPORT_SYMBOL(mISDN_dsp_element_unregister);
145
146int dsp_pipeline_module_init(void)
147{
148 elements_class = class_create(THIS_MODULE, "dsp_pipeline");
149 if (IS_ERR(elements_class))
150 return PTR_ERR(elements_class);
151
152#ifdef PIPELINE_DEBUG
153 printk(KERN_DEBUG "%s: dsp pipeline module initialized\n", __func__);
154#endif
155
156 dsp_hwec_init();
157
158 return 0;
159}
160
161void dsp_pipeline_module_exit(void)
162{
163 struct dsp_element_entry *entry, *n;
164
165 dsp_hwec_exit();
166
167 class_destroy(elements_class);
168
169 list_for_each_entry_safe(entry, n, &dsp_elements, list) {
170 list_del(&entry->list);
171 printk(KERN_WARNING "%s: element was still registered: %s\n",
172 __func__, entry->elem->name);
173 kfree(entry);
174 }
175
176 printk(KERN_DEBUG "%s: dsp pipeline module exited\n", __func__);
177}
178
179int dsp_pipeline_init(struct dsp_pipeline *pipeline)
180{
181 if (!pipeline)
182 return -EINVAL;
183
184 INIT_LIST_HEAD(&pipeline->list);
185
186#ifdef PIPELINE_DEBUG
187 printk(KERN_DEBUG "%s: dsp pipeline ready\n", __func__);
188#endif
189
190 return 0;
191}
192
193static inline void _dsp_pipeline_destroy(struct dsp_pipeline *pipeline)
194{
195 struct dsp_pipeline_entry *entry, *n;
196
197 list_for_each_entry_safe(entry, n, &pipeline->list, list) {
198 list_del(&entry->list);
199 if (entry->elem == dsp_hwec)
200 dsp_hwec_disable(container_of(pipeline, struct dsp,
201 pipeline));
202 else
203 entry->elem->free(entry->p);
204 kfree(entry);
205 }
206}
207
208void dsp_pipeline_destroy(struct dsp_pipeline *pipeline)
209{
210
211 if (!pipeline)
212 return;
213
214 _dsp_pipeline_destroy(pipeline);
215
216#ifdef PIPELINE_DEBUG
217 printk(KERN_DEBUG "%s: dsp pipeline destroyed\n", __func__);
218#endif
219}
220
221int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg)
222{
223 int len, incomplete = 0, found = 0;
224 char *dup, *tok, *name, *args;
225 struct dsp_element_entry *entry, *n;
226 struct dsp_pipeline_entry *pipeline_entry;
227 struct mISDN_dsp_element *elem;
228
229 if (!pipeline)
230 return -EINVAL;
231
232 if (!list_empty(&pipeline->list))
233 _dsp_pipeline_destroy(pipeline);
234
235 if (!cfg)
236 return 0;
237
238 len = strlen(cfg);
239 if (!len)
240 return 0;
241
242 dup = kmalloc(len + 1, GFP_KERNEL);
243 if (!dup)
244 return 0;
245 strcpy(dup, cfg);
246 while ((tok = strsep(&dup, "|"))) {
247 if (!strlen(tok))
248 continue;
249 name = strsep(&tok, "(");
250 args = strsep(&tok, ")");
251 if (args && !*args)
252 args = 0;
253
254 list_for_each_entry_safe(entry, n, &dsp_elements, list)
255 if (!strcmp(entry->elem->name, name)) {
256 elem = entry->elem;
257
258 pipeline_entry = kmalloc(sizeof(struct
259 dsp_pipeline_entry), GFP_KERNEL);
260 if (!pipeline_entry) {
261 printk(KERN_DEBUG "%s: failed to add "
262 "entry to pipeline: %s (out of "
263 "memory)\n", __func__, elem->name);
264 incomplete = 1;
265 goto _out;
266 }
267 pipeline_entry->elem = elem;
268
269 if (elem == dsp_hwec) {
270 /* This is a hack to make the hwec
271 available as a pipeline module */
272 dsp_hwec_enable(container_of(pipeline,
273 struct dsp, pipeline), args);
274 list_add_tail(&pipeline_entry->list,
275 &pipeline->list);
276 } else {
277 pipeline_entry->p = elem->new(args);
278 if (pipeline_entry->p) {
279 list_add_tail(&pipeline_entry->
280 list, &pipeline->list);
281#ifdef PIPELINE_DEBUG
282 printk(KERN_DEBUG "%s: created "
283 "instance of %s%s%s\n",
284 __func__, name, args ?
285 " with args " : "", args ?
286 args : "");
287#endif
288 } else {
289 printk(KERN_DEBUG "%s: failed "
290 "to add entry to pipeline: "
291 "%s (new() returned NULL)\n",
292 __func__, elem->name);
293 kfree(pipeline_entry);
294 incomplete = 1;
295 }
296 }
297 found = 1;
298 break;
299 }
300
301 if (found)
302 found = 0;
303 else {
304 printk(KERN_DEBUG "%s: element not found, skipping: "
305 "%s\n", __func__, name);
306 incomplete = 1;
307 }
308 }
309
310_out:
311 if (!list_empty(&pipeline->list))
312 pipeline->inuse = 1;
313 else
314 pipeline->inuse = 0;
315
316#ifdef PIPELINE_DEBUG
317 printk(KERN_DEBUG "%s: dsp pipeline built%s: %s\n",
318 __func__, incomplete ? " incomplete" : "", cfg);
319#endif
320 kfree(dup);
321 return 0;
322}
323
324void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data, int len)
325{
326 struct dsp_pipeline_entry *entry;
327
328 if (!pipeline)
329 return;
330
331 list_for_each_entry(entry, &pipeline->list, list)
332 if (entry->elem->process_tx)
333 entry->elem->process_tx(entry->p, data, len);
334}
335
336void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data, int len)
337{
338 struct dsp_pipeline_entry *entry;
339
340 if (!pipeline)
341 return;
342
343 list_for_each_entry_reverse(entry, &pipeline->list, list)
344 if (entry->elem->process_rx)
345 entry->elem->process_rx(entry->p, data, len);
346}
347
348
diff --git a/drivers/isdn/mISDN/dsp_tones.c b/drivers/isdn/mISDN/dsp_tones.c
new file mode 100644
index 000000000000..23dd0dd21524
--- /dev/null
+++ b/drivers/isdn/mISDN/dsp_tones.c
@@ -0,0 +1,551 @@
1/*
2 * Audio support data for ISDN4Linux.
3 *
4 * Copyright Andreas Eversberg (jolly@eversberg.eu)
5 *
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
8 *
9 */
10
11#include <linux/mISDNif.h>
12#include <linux/mISDNdsp.h>
13#include "core.h"
14#include "dsp.h"
15
16
17#define DATA_S sample_silence
18#define SIZE_S (&sizeof_silence)
19#define DATA_GA sample_german_all
20#define SIZE_GA (&sizeof_german_all)
21#define DATA_GO sample_german_old
22#define SIZE_GO (&sizeof_german_old)
23#define DATA_DT sample_american_dialtone
24#define SIZE_DT (&sizeof_american_dialtone)
25#define DATA_RI sample_american_ringing
26#define SIZE_RI (&sizeof_american_ringing)
27#define DATA_BU sample_american_busy
28#define SIZE_BU (&sizeof_american_busy)
29#define DATA_S1 sample_special1
30#define SIZE_S1 (&sizeof_special1)
31#define DATA_S2 sample_special2
32#define SIZE_S2 (&sizeof_special2)
33#define DATA_S3 sample_special3
34#define SIZE_S3 (&sizeof_special3)
35
36/***************/
37/* tones loops */
38/***************/
39
40/* all tones are alaw encoded */
41/* the last sample+1 is in phase with the first sample. the error is low */
42
43static u8 sample_german_all[] = {
44 0x80, 0xab, 0x81, 0x6d, 0xfd, 0xdd, 0x5d, 0x9d,
45 0x4d, 0xd1, 0x89, 0x88, 0xd0, 0x4c, 0x9c, 0x5c,
46 0xdc, 0xfc, 0x6c,
47 0x80, 0xab, 0x81, 0x6d, 0xfd, 0xdd, 0x5d, 0x9d,
48 0x4d, 0xd1, 0x89, 0x88, 0xd0, 0x4c, 0x9c, 0x5c,
49 0xdc, 0xfc, 0x6c,
50 0x80, 0xab, 0x81, 0x6d, 0xfd, 0xdd, 0x5d, 0x9d,
51 0x4d, 0xd1, 0x89, 0x88, 0xd0, 0x4c, 0x9c, 0x5c,
52 0xdc, 0xfc, 0x6c,
53 0x80, 0xab, 0x81, 0x6d, 0xfd, 0xdd, 0x5d, 0x9d,
54 0x4d, 0xd1, 0x89, 0x88, 0xd0, 0x4c, 0x9c, 0x5c,
55 0xdc, 0xfc, 0x6c,
56};
57static u32 sizeof_german_all = sizeof(sample_german_all);
58
59static u8 sample_german_old[] = {
60 0xec, 0x68, 0xe1, 0x6d, 0x6d, 0x91, 0x51, 0xed,
61 0x6d, 0x01, 0x1e, 0x10, 0x0c, 0x90, 0x60, 0x70,
62 0x8c,
63 0xec, 0x68, 0xe1, 0x6d, 0x6d, 0x91, 0x51, 0xed,
64 0x6d, 0x01, 0x1e, 0x10, 0x0c, 0x90, 0x60, 0x70,
65 0x8c,
66 0xec, 0x68, 0xe1, 0x6d, 0x6d, 0x91, 0x51, 0xed,
67 0x6d, 0x01, 0x1e, 0x10, 0x0c, 0x90, 0x60, 0x70,
68 0x8c,
69 0xec, 0x68, 0xe1, 0x6d, 0x6d, 0x91, 0x51, 0xed,
70 0x6d, 0x01, 0x1e, 0x10, 0x0c, 0x90, 0x60, 0x70,
71 0x8c,
72};
73static u32 sizeof_german_old = sizeof(sample_german_old);
74
75static u8 sample_american_dialtone[] = {
76 0x2a, 0x18, 0x90, 0x6c, 0x4c, 0xbc, 0x4c, 0x6c,
77 0x10, 0x58, 0x32, 0xb9, 0x31, 0x2d, 0x8d, 0x0d,
78 0x8d, 0x2d, 0x31, 0x99, 0x0f, 0x28, 0x60, 0xf0,
79 0xd0, 0x50, 0xd0, 0x30, 0x60, 0x08, 0x8e, 0x67,
80 0x09, 0x19, 0x21, 0xe1, 0xd9, 0xb9, 0x29, 0x67,
81 0x83, 0x02, 0xce, 0xbe, 0xee, 0x1a, 0x1b, 0xef,
82 0xbf, 0xcf, 0x03, 0x82, 0x66, 0x28, 0xb8, 0xd8,
83 0xe0, 0x20, 0x18, 0x08, 0x66, 0x8f, 0x09, 0x61,
84 0x31, 0xd1, 0x51, 0xd1, 0xf1, 0x61, 0x29, 0x0e,
85 0x98, 0x30, 0x2c, 0x8c, 0x0c, 0x8c, 0x2c, 0x30,
86 0xb8, 0x33, 0x59, 0x11, 0x6d, 0x4d, 0xbd, 0x4d,
87 0x6d, 0x91, 0x19,
88};
89static u32 sizeof_american_dialtone = sizeof(sample_american_dialtone);
90
91static u8 sample_american_ringing[] = {
92 0x2a, 0xe0, 0xac, 0x0c, 0xbc, 0x4c, 0x8c, 0x90,
93 0x48, 0xc7, 0xc1, 0xed, 0xcd, 0x4d, 0xcd, 0xed,
94 0xc1, 0xb7, 0x08, 0x30, 0xec, 0xcc, 0xcc, 0x8c,
95 0x10, 0x58, 0x1a, 0x99, 0x71, 0xed, 0x8d, 0x8d,
96 0x2d, 0x41, 0x89, 0x9e, 0x20, 0x70, 0x2c, 0xec,
97 0x2c, 0x70, 0x20, 0x86, 0x77, 0xe1, 0x31, 0x11,
98 0xd1, 0xf1, 0x81, 0x09, 0xa3, 0x56, 0x58, 0x00,
99 0x40, 0xc0, 0x60, 0x38, 0x46, 0x43, 0x57, 0x39,
100 0xd9, 0x59, 0x99, 0xc9, 0x77, 0x2f, 0x2e, 0xc6,
101 0xd6, 0x28, 0xd6, 0x36, 0x26, 0x2e, 0x8a, 0xa3,
102 0x43, 0x63, 0x4b, 0x4a, 0x62, 0x42, 0xa2, 0x8b,
103 0x2f, 0x27, 0x37, 0xd7, 0x29, 0xd7, 0xc7, 0x2f,
104 0x2e, 0x76, 0xc8, 0x98, 0x58, 0xd8, 0x38, 0x56,
105 0x42, 0x47, 0x39, 0x61, 0xc1, 0x41, 0x01, 0x59,
106 0x57, 0xa2, 0x08, 0x80, 0xf0, 0xd0, 0x10, 0x30,
107 0xe0, 0x76, 0x87, 0x21, 0x71, 0x2d, 0xed, 0x2d,
108 0x71, 0x21, 0x9f, 0x88, 0x40, 0x2c, 0x8c, 0x8c,
109 0xec, 0x70, 0x98, 0x1b, 0x59, 0x11, 0x8d, 0xcd,
110 0xcd, 0xed, 0x31, 0x09, 0xb6, 0xc0, 0xec, 0xcc,
111 0x4c, 0xcc, 0xec, 0xc0, 0xc6, 0x49, 0x91, 0x8d,
112 0x4d, 0xbd, 0x0d, 0xad, 0xe1,
113};
114static u32 sizeof_american_ringing = sizeof(sample_american_ringing);
115
116static u8 sample_american_busy[] = {
117 0x2a, 0x00, 0x6c, 0x4c, 0x4c, 0x6c, 0xb0, 0x66,
118 0x99, 0x11, 0x6d, 0x8d, 0x2d, 0x41, 0xd7, 0x96,
119 0x60, 0xf0, 0x70, 0x40, 0x58, 0xf6, 0x53, 0x57,
120 0x09, 0x89, 0xd7, 0x5f, 0xe3, 0x2a, 0xe3, 0x5f,
121 0xd7, 0x89, 0x09, 0x57, 0x53, 0xf6, 0x58, 0x40,
122 0x70, 0xf0, 0x60, 0x96, 0xd7, 0x41, 0x2d, 0x8d,
123 0x6d, 0x11, 0x99, 0x66, 0xb0, 0x6c, 0x4c, 0x4c,
124 0x6c, 0x00, 0x2a, 0x01, 0x6d, 0x4d, 0x4d, 0x6d,
125 0xb1, 0x67, 0x98, 0x10, 0x6c, 0x8c, 0x2c, 0x40,
126 0xd6, 0x97, 0x61, 0xf1, 0x71, 0x41, 0x59, 0xf7,
127 0x52, 0x56, 0x08, 0x88, 0xd6, 0x5e, 0xe2, 0x2a,
128 0xe2, 0x5e, 0xd6, 0x88, 0x08, 0x56, 0x52, 0xf7,
129 0x59, 0x41, 0x71, 0xf1, 0x61, 0x97, 0xd6, 0x40,
130 0x2c, 0x8c, 0x6c, 0x10, 0x98, 0x67, 0xb1, 0x6d,
131 0x4d, 0x4d, 0x6d, 0x01,
132};
133static u32 sizeof_american_busy = sizeof(sample_american_busy);
134
135static u8 sample_special1[] = {
136 0x2a, 0x2c, 0xbc, 0x6c, 0xd6, 0x71, 0xbd, 0x0d,
137 0xd9, 0x80, 0xcc, 0x4c, 0x40, 0x39, 0x0d, 0xbd,
138 0x11, 0x86, 0xec, 0xbc, 0xec, 0x0e, 0x51, 0xbd,
139 0x8d, 0x89, 0x30, 0x4c, 0xcc, 0xe0, 0xe1, 0xcd,
140 0x4d, 0x31, 0x88, 0x8c, 0xbc, 0x50, 0x0f, 0xed,
141 0xbd, 0xed, 0x87, 0x10, 0xbc, 0x0c, 0x38, 0x41,
142 0x4d, 0xcd, 0x81, 0xd8, 0x0c, 0xbc, 0x70, 0xd7,
143 0x6d, 0xbd, 0x2d,
144};
145static u32 sizeof_special1 = sizeof(sample_special1);
146
147static u8 sample_special2[] = {
148 0x2a, 0xcc, 0x8c, 0xd7, 0x4d, 0x2d, 0x18, 0xbc,
149 0x10, 0xc1, 0xbd, 0xc1, 0x10, 0xbc, 0x18, 0x2d,
150 0x4d, 0xd7, 0x8c, 0xcc, 0x2a, 0xcd, 0x8d, 0xd6,
151 0x4c, 0x2c, 0x19, 0xbd, 0x11, 0xc0, 0xbc, 0xc0,
152 0x11, 0xbd, 0x19, 0x2c, 0x4c, 0xd6, 0x8d, 0xcd,
153 0x2a, 0xcc, 0x8c, 0xd7, 0x4d, 0x2d, 0x18, 0xbc,
154 0x10, 0xc1, 0xbd, 0xc1, 0x10, 0xbc, 0x18, 0x2d,
155 0x4d, 0xd7, 0x8c, 0xcc, 0x2a, 0xcd, 0x8d, 0xd6,
156 0x4c, 0x2c, 0x19, 0xbd, 0x11, 0xc0, 0xbc, 0xc0,
157 0x11, 0xbd, 0x19, 0x2c, 0x4c, 0xd6, 0x8d, 0xcd,
158};
159static u32 sizeof_special2 = sizeof(sample_special2);
160
161static u8 sample_special3[] = {
162 0x2a, 0xbc, 0x18, 0xcd, 0x11, 0x2c, 0x8c, 0xc1,
163 0x4d, 0xd6, 0xbc, 0xd6, 0x4d, 0xc1, 0x8c, 0x2c,
164 0x11, 0xcd, 0x18, 0xbc, 0x2a, 0xbd, 0x19, 0xcc,
165 0x10, 0x2d, 0x8d, 0xc0, 0x4c, 0xd7, 0xbd, 0xd7,
166 0x4c, 0xc0, 0x8d, 0x2d, 0x10, 0xcc, 0x19, 0xbd,
167 0x2a, 0xbc, 0x18, 0xcd, 0x11, 0x2c, 0x8c, 0xc1,
168 0x4d, 0xd6, 0xbc, 0xd6, 0x4d, 0xc1, 0x8c, 0x2c,
169 0x11, 0xcd, 0x18, 0xbc, 0x2a, 0xbd, 0x19, 0xcc,
170 0x10, 0x2d, 0x8d, 0xc0, 0x4c, 0xd7, 0xbd, 0xd7,
171 0x4c, 0xc0, 0x8d, 0x2d, 0x10, 0xcc, 0x19, 0xbd,
172};
173static u32 sizeof_special3 = sizeof(sample_special3);
174
175static u8 sample_silence[] = {
176 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
177 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
178 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
179 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
180 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
181 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
182 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
183 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
184 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
185 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
186 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
187 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
188};
189static u32 sizeof_silence = sizeof(sample_silence);
190
191struct tones_samples {
192 u32 *len;
193 u8 *data;
194};
195static struct
196tones_samples samples[] = {
197 {&sizeof_german_all, sample_german_all},
198 {&sizeof_german_old, sample_german_old},
199 {&sizeof_american_dialtone, sample_american_dialtone},
200 {&sizeof_american_ringing, sample_american_ringing},
201 {&sizeof_american_busy, sample_american_busy},
202 {&sizeof_special1, sample_special1},
203 {&sizeof_special2, sample_special2},
204 {&sizeof_special3, sample_special3},
205 {NULL, NULL},
206};
207
208/***********************************
209 * generate ulaw from alaw samples *
210 ***********************************/
211
212void
213dsp_audio_generate_ulaw_samples(void)
214{
215 int i, j;
216
217 i = 0;
218 while (samples[i].len) {
219 j = 0;
220 while (j < (*samples[i].len)) {
221 samples[i].data[j] =
222 dsp_audio_alaw_to_ulaw[samples[i].data[j]];
223 j++;
224 }
225 i++;
226 }
227}
228
229
230/****************************
231 * tone sequence definition *
232 ****************************/
233
234struct pattern {
235 int tone;
236 u8 *data[10];
237 u32 *siz[10];
238 u32 seq[10];
239} pattern[] = {
240 {TONE_GERMAN_DIALTONE,
241 {DATA_GA, 0, 0, 0, 0, 0, 0, 0, 0, 0},
242 {SIZE_GA, 0, 0, 0, 0, 0, 0, 0, 0, 0},
243 {1900, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
244
245 {TONE_GERMAN_OLDDIALTONE,
246 {DATA_GO, 0, 0, 0, 0, 0, 0, 0, 0, 0},
247 {SIZE_GO, 0, 0, 0, 0, 0, 0, 0, 0, 0},
248 {1998, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
249
250 {TONE_AMERICAN_DIALTONE,
251 {DATA_DT, 0, 0, 0, 0, 0, 0, 0, 0, 0},
252 {SIZE_DT, 0, 0, 0, 0, 0, 0, 0, 0, 0},
253 {8000, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
254
255 {TONE_GERMAN_DIALPBX,
256 {DATA_GA, DATA_S, DATA_GA, DATA_S, DATA_GA, DATA_S, 0, 0, 0, 0},
257 {SIZE_GA, SIZE_S, SIZE_GA, SIZE_S, SIZE_GA, SIZE_S, 0, 0, 0, 0},
258 {2000, 2000, 2000, 2000, 2000, 12000, 0, 0, 0, 0} },
259
260 {TONE_GERMAN_OLDDIALPBX,
261 {DATA_GO, DATA_S, DATA_GO, DATA_S, DATA_GO, DATA_S, 0, 0, 0, 0},
262 {SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, 0, 0, 0, 0},
263 {2000, 2000, 2000, 2000, 2000, 12000, 0, 0, 0, 0} },
264
265 {TONE_AMERICAN_DIALPBX,
266 {DATA_DT, DATA_S, DATA_DT, DATA_S, DATA_DT, DATA_S, 0, 0, 0, 0},
267 {SIZE_DT, SIZE_S, SIZE_DT, SIZE_S, SIZE_DT, SIZE_S, 0, 0, 0, 0},
268 {2000, 2000, 2000, 2000, 2000, 12000, 0, 0, 0, 0} },
269
270 {TONE_GERMAN_RINGING,
271 {DATA_GA, DATA_S, 0, 0, 0, 0, 0, 0, 0, 0},
272 {SIZE_GA, SIZE_S, 0, 0, 0, 0, 0, 0, 0, 0},
273 {8000, 32000, 0, 0, 0, 0, 0, 0, 0, 0} },
274
275 {TONE_GERMAN_OLDRINGING,
276 {DATA_GO, DATA_S, 0, 0, 0, 0, 0, 0, 0, 0},
277 {SIZE_GO, SIZE_S, 0, 0, 0, 0, 0, 0, 0, 0},
278 {8000, 40000, 0, 0, 0, 0, 0, 0, 0, 0} },
279
280 {TONE_AMERICAN_RINGING,
281 {DATA_RI, DATA_S, 0, 0, 0, 0, 0, 0, 0, 0},
282 {SIZE_RI, SIZE_S, 0, 0, 0, 0, 0, 0, 0, 0},
283 {8000, 32000, 0, 0, 0, 0, 0, 0, 0, 0} },
284
285 {TONE_GERMAN_RINGPBX,
286 {DATA_GA, DATA_S, DATA_GA, DATA_S, 0, 0, 0, 0, 0, 0},
287 {SIZE_GA, SIZE_S, SIZE_GA, SIZE_S, 0, 0, 0, 0, 0, 0},
288 {4000, 4000, 4000, 28000, 0, 0, 0, 0, 0, 0} },
289
290 {TONE_GERMAN_OLDRINGPBX,
291 {DATA_GO, DATA_S, DATA_GO, DATA_S, 0, 0, 0, 0, 0, 0},
292 {SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, 0, 0, 0, 0, 0, 0},
293 {4000, 4000, 4000, 28000, 0, 0, 0, 0, 0, 0} },
294
295 {TONE_AMERICAN_RINGPBX,
296 {DATA_RI, DATA_S, DATA_RI, DATA_S, 0, 0, 0, 0, 0, 0},
297 {SIZE_RI, SIZE_S, SIZE_RI, SIZE_S, 0, 0, 0, 0, 0, 0},
298 {4000, 4000, 4000, 28000, 0, 0, 0, 0, 0, 0} },
299
300 {TONE_GERMAN_BUSY,
301 {DATA_GA, DATA_S, 0, 0, 0, 0, 0, 0, 0, 0},
302 {SIZE_GA, SIZE_S, 0, 0, 0, 0, 0, 0, 0, 0},
303 {4000, 4000, 0, 0, 0, 0, 0, 0, 0, 0} },
304
305 {TONE_GERMAN_OLDBUSY,
306 {DATA_GO, DATA_S, 0, 0, 0, 0, 0, 0, 0, 0},
307 {SIZE_GO, SIZE_S, 0, 0, 0, 0, 0, 0, 0, 0},
308 {1000, 5000, 0, 0, 0, 0, 0, 0, 0, 0} },
309
310 {TONE_AMERICAN_BUSY,
311 {DATA_BU, DATA_S, 0, 0, 0, 0, 0, 0, 0, 0},
312 {SIZE_BU, SIZE_S, 0, 0, 0, 0, 0, 0, 0, 0},
313 {4000, 4000, 0, 0, 0, 0, 0, 0, 0, 0} },
314
315 {TONE_GERMAN_HANGUP,
316 {DATA_GA, DATA_S, 0, 0, 0, 0, 0, 0, 0, 0},
317 {SIZE_GA, SIZE_S, 0, 0, 0, 0, 0, 0, 0, 0},
318 {4000, 4000, 0, 0, 0, 0, 0, 0, 0, 0} },
319
320 {TONE_GERMAN_OLDHANGUP,
321 {DATA_GO, DATA_S, 0, 0, 0, 0, 0, 0, 0, 0},
322 {SIZE_GO, SIZE_S, 0, 0, 0, 0, 0, 0, 0, 0},
323 {1000, 5000, 0, 0, 0, 0, 0, 0, 0, 0} },
324
325 {TONE_AMERICAN_HANGUP,
326 {DATA_DT, 0, 0, 0, 0, 0, 0, 0, 0, 0},
327 {SIZE_DT, 0, 0, 0, 0, 0, 0, 0, 0, 0},
328 {8000, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
329
330 {TONE_SPECIAL_INFO,
331 {DATA_S1, DATA_S2, DATA_S3, DATA_S, 0, 0, 0, 0, 0, 0},
332 {SIZE_S1, SIZE_S2, SIZE_S3, SIZE_S, 0, 0, 0, 0, 0, 0},
333 {2666, 2666, 2666, 8002, 0, 0, 0, 0, 0, 0} },
334
335 {TONE_GERMAN_GASSENBESETZT,
336 {DATA_GA, DATA_S, 0, 0, 0, 0, 0, 0, 0, 0},
337 {SIZE_GA, SIZE_S, 0, 0, 0, 0, 0, 0, 0, 0},
338 {2000, 2000, 0, 0, 0, 0, 0, 0, 0, 0} },
339
340 {TONE_GERMAN_AUFSCHALTTON,
341 {DATA_GO, DATA_S, DATA_GO, DATA_S, 0, 0, 0, 0, 0, 0},
342 {SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, 0, 0, 0, 0, 0, 0},
343 {1000, 5000, 1000, 17000, 0, 0, 0, 0, 0, 0} },
344
345 {0,
346 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
347 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
348 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
349};
350
351/******************
352 * copy tone data *
353 ******************/
354
355/* an sk_buff is generated from the number of samples needed.
356 * the count will be changed and may begin from 0 each pattern period.
357 * the clue is to precalculate the pointers and legths to use only one
358 * memcpy per function call, or two memcpy if the tone sequence changes.
359 *
360 * pattern - the type of the pattern
361 * count - the sample from the beginning of the pattern (phase)
362 * len - the number of bytes
363 *
364 * return - the sk_buff with the sample
365 *
366 * if tones has finished (e.g. knocking tone), dsp->tones is turned off
367 */
368void dsp_tone_copy(struct dsp *dsp, u8 *data, int len)
369{
370 int index, count, start, num;
371 struct pattern *pat;
372 struct dsp_tone *tone = &dsp->tone;
373
374 /* if we have no tone, we copy silence */
375 if (!tone->tone) {
376 memset(data, dsp_silence, len);
377 return;
378 }
379
380 /* process pattern */
381 pat = (struct pattern *)tone->pattern;
382 /* points to the current pattern */
383 index = tone->index; /* gives current sequence index */
384 count = tone->count; /* gives current sample */
385
386 /* copy sample */
387 while (len) {
388 /* find sample to start with */
389 while (42) {
390 /* warp arround */
391 if (!pat->seq[index]) {
392 count = 0;
393 index = 0;
394 }
395 /* check if we are currently playing this tone */
396 if (count < pat->seq[index])
397 break;
398 if (dsp_debug & DEBUG_DSP_TONE)
399 printk(KERN_DEBUG "%s: reaching next sequence "
400 "(index=%d)\n", __func__, index);
401 count -= pat->seq[index];
402 index++;
403 }
404 /* calculate start and number of samples */
405 start = count % (*(pat->siz[index]));
406 num = len;
407 if (num+count > pat->seq[index])
408 num = pat->seq[index] - count;
409 if (num+start > (*(pat->siz[index])))
410 num = (*(pat->siz[index])) - start;
411 /* copy memory */
412 memcpy(data, pat->data[index]+start, num);
413 /* reduce length */
414 data += num;
415 count += num;
416 len -= num;
417 }
418 tone->index = index;
419 tone->count = count;
420
421 /* return sk_buff */
422 return;
423}
424
425
426/*******************************
427 * send HW message to hfc card *
428 *******************************/
429
430static void
431dsp_tone_hw_message(struct dsp *dsp, u8 *sample, int len)
432{
433 struct sk_buff *nskb;
434
435 /* unlocking is not required, because we don't expect a response */
436 nskb = _alloc_mISDN_skb(PH_CONTROL_REQ,
437 (len)?HFC_SPL_LOOP_ON:HFC_SPL_LOOP_OFF, len, sample,
438 GFP_ATOMIC);
439 if (nskb) {
440 if (dsp->ch.peer) {
441 if (dsp->ch.recv(dsp->ch.peer, nskb))
442 dev_kfree_skb(nskb);
443 } else
444 dev_kfree_skb(nskb);
445 }
446}
447
448
449/*****************
450 * timer expires *
451 *****************/
452void
453dsp_tone_timeout(void *arg)
454{
455 struct dsp *dsp = arg;
456 struct dsp_tone *tone = &dsp->tone;
457 struct pattern *pat = (struct pattern *)tone->pattern;
458 int index = tone->index;
459
460 if (!tone->tone)
461 return;
462
463 index++;
464 if (!pat->seq[index])
465 index = 0;
466 tone->index = index;
467
468 /* set next tone */
469 if (pat->data[index] == DATA_S)
470 dsp_tone_hw_message(dsp, 0, 0);
471 else
472 dsp_tone_hw_message(dsp, pat->data[index], *(pat->siz[index]));
473 /* set timer */
474 init_timer(&tone->tl);
475 tone->tl.expires = jiffies + (pat->seq[index] * HZ) / 8000;
476 add_timer(&tone->tl);
477}
478
479
480/********************
481 * set/release tone *
482 ********************/
483
484/*
485 * tones are relaized by streaming or by special loop commands if supported
486 * by hardware. when hardware is used, the patterns will be controlled by
487 * timers.
488 */
489int
490dsp_tone(struct dsp *dsp, int tone)
491{
492 struct pattern *pat;
493 int i;
494 struct dsp_tone *tonet = &dsp->tone;
495
496 tonet->software = 0;
497 tonet->hardware = 0;
498
499 /* we turn off the tone */
500 if (!tone) {
501 if (dsp->features.hfc_loops)
502 if (timer_pending(&tonet->tl))
503 del_timer(&tonet->tl);
504 if (dsp->features.hfc_loops)
505 dsp_tone_hw_message(dsp, NULL, 0);
506 tonet->tone = 0;
507 return 0;
508 }
509
510 pat = NULL;
511 i = 0;
512 while (pattern[i].tone) {
513 if (pattern[i].tone == tone) {
514 pat = &pattern[i];
515 break;
516 }
517 i++;
518 }
519 if (!pat) {
520 printk(KERN_WARNING "dsp: given tone 0x%x is invalid\n", tone);
521 return -EINVAL;
522 }
523 if (dsp_debug & DEBUG_DSP_TONE)
524 printk(KERN_DEBUG "%s: now starting tone %d (index=%d)\n",
525 __func__, tone, 0);
526 tonet->tone = tone;
527 tonet->pattern = pat;
528 tonet->index = 0;
529 tonet->count = 0;
530
531 if (dsp->features.hfc_loops) {
532 tonet->hardware = 1;
533 /* set first tone */
534 dsp_tone_hw_message(dsp, pat->data[0], *(pat->siz[0]));
535 /* set timer */
536 if (timer_pending(&tonet->tl))
537 del_timer(&tonet->tl);
538 init_timer(&tonet->tl);
539 tonet->tl.expires = jiffies + (pat->seq[0] * HZ) / 8000;
540 add_timer(&tonet->tl);
541 } else {
542 tonet->software = 1;
543 }
544
545 return 0;
546}
547
548
549
550
551
diff --git a/drivers/isdn/mISDN/fsm.c b/drivers/isdn/mISDN/fsm.c
new file mode 100644
index 000000000000..b5d6553f2dc8
--- /dev/null
+++ b/drivers/isdn/mISDN/fsm.c
@@ -0,0 +1,183 @@
1/*
2 * finite state machine implementation
3 *
4 * Author Karsten Keil <kkeil@novell.com>
5 *
6 * Thanks to Jan den Ouden
7 * Fritz Elfert
8 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 */
20
21#include <linux/kernel.h>
22#include <linux/slab.h>
23#include <linux/module.h>
24#include <linux/string.h>
25#include "fsm.h"
26
27#define FSM_TIMER_DEBUG 0
28
29void
30mISDN_FsmNew(struct Fsm *fsm,
31 struct FsmNode *fnlist, int fncount)
32{
33 int i;
34
35 fsm->jumpmatrix = kzalloc(sizeof(FSMFNPTR) * fsm->state_count *
36 fsm->event_count, GFP_KERNEL);
37
38 for (i = 0; i < fncount; i++)
39 if ((fnlist[i].state >= fsm->state_count) ||
40 (fnlist[i].event >= fsm->event_count)) {
41 printk(KERN_ERR
42 "mISDN_FsmNew Error: %d st(%ld/%ld) ev(%ld/%ld)\n",
43 i, (long)fnlist[i].state, (long)fsm->state_count,
44 (long)fnlist[i].event, (long)fsm->event_count);
45 } else
46 fsm->jumpmatrix[fsm->state_count * fnlist[i].event +
47 fnlist[i].state] = (FSMFNPTR) fnlist[i].routine;
48}
49EXPORT_SYMBOL(mISDN_FsmNew);
50
51void
52mISDN_FsmFree(struct Fsm *fsm)
53{
54 kfree((void *) fsm->jumpmatrix);
55}
56EXPORT_SYMBOL(mISDN_FsmFree);
57
58int
59mISDN_FsmEvent(struct FsmInst *fi, int event, void *arg)
60{
61 FSMFNPTR r;
62
63 if ((fi->state >= fi->fsm->state_count) ||
64 (event >= fi->fsm->event_count)) {
65 printk(KERN_ERR
66 "mISDN_FsmEvent Error st(%ld/%ld) ev(%d/%ld)\n",
67 (long)fi->state, (long)fi->fsm->state_count, event,
68 (long)fi->fsm->event_count);
69 return 1;
70 }
71 r = fi->fsm->jumpmatrix[fi->fsm->state_count * event + fi->state];
72 if (r) {
73 if (fi->debug)
74 fi->printdebug(fi, "State %s Event %s",
75 fi->fsm->strState[fi->state],
76 fi->fsm->strEvent[event]);
77 r(fi, event, arg);
78 return 0;
79 } else {
80 if (fi->debug)
81 fi->printdebug(fi, "State %s Event %s no action",
82 fi->fsm->strState[fi->state],
83 fi->fsm->strEvent[event]);
84 return 1;
85 }
86}
87EXPORT_SYMBOL(mISDN_FsmEvent);
88
89void
90mISDN_FsmChangeState(struct FsmInst *fi, int newstate)
91{
92 fi->state = newstate;
93 if (fi->debug)
94 fi->printdebug(fi, "ChangeState %s",
95 fi->fsm->strState[newstate]);
96}
97EXPORT_SYMBOL(mISDN_FsmChangeState);
98
99static void
100FsmExpireTimer(struct FsmTimer *ft)
101{
102#if FSM_TIMER_DEBUG
103 if (ft->fi->debug)
104 ft->fi->printdebug(ft->fi, "FsmExpireTimer %lx", (long) ft);
105#endif
106 mISDN_FsmEvent(ft->fi, ft->event, ft->arg);
107}
108
109void
110mISDN_FsmInitTimer(struct FsmInst *fi, struct FsmTimer *ft)
111{
112 ft->fi = fi;
113 ft->tl.function = (void *) FsmExpireTimer;
114 ft->tl.data = (long) ft;
115#if FSM_TIMER_DEBUG
116 if (ft->fi->debug)
117 ft->fi->printdebug(ft->fi, "mISDN_FsmInitTimer %lx", (long) ft);
118#endif
119 init_timer(&ft->tl);
120}
121EXPORT_SYMBOL(mISDN_FsmInitTimer);
122
123void
124mISDN_FsmDelTimer(struct FsmTimer *ft, int where)
125{
126#if FSM_TIMER_DEBUG
127 if (ft->fi->debug)
128 ft->fi->printdebug(ft->fi, "mISDN_FsmDelTimer %lx %d",
129 (long) ft, where);
130#endif
131 del_timer(&ft->tl);
132}
133EXPORT_SYMBOL(mISDN_FsmDelTimer);
134
135int
136mISDN_FsmAddTimer(struct FsmTimer *ft,
137 int millisec, int event, void *arg, int where)
138{
139
140#if FSM_TIMER_DEBUG
141 if (ft->fi->debug)
142 ft->fi->printdebug(ft->fi, "mISDN_FsmAddTimer %lx %d %d",
143 (long) ft, millisec, where);
144#endif
145
146 if (timer_pending(&ft->tl)) {
147 if (ft->fi->debug) {
148 printk(KERN_WARNING
149 "mISDN_FsmAddTimer: timer already active!\n");
150 ft->fi->printdebug(ft->fi,
151 "mISDN_FsmAddTimer already active!");
152 }
153 return -1;
154 }
155 init_timer(&ft->tl);
156 ft->event = event;
157 ft->arg = arg;
158 ft->tl.expires = jiffies + (millisec * HZ) / 1000;
159 add_timer(&ft->tl);
160 return 0;
161}
162EXPORT_SYMBOL(mISDN_FsmAddTimer);
163
164void
165mISDN_FsmRestartTimer(struct FsmTimer *ft,
166 int millisec, int event, void *arg, int where)
167{
168
169#if FSM_TIMER_DEBUG
170 if (ft->fi->debug)
171 ft->fi->printdebug(ft->fi, "mISDN_FsmRestartTimer %lx %d %d",
172 (long) ft, millisec, where);
173#endif
174
175 if (timer_pending(&ft->tl))
176 del_timer(&ft->tl);
177 init_timer(&ft->tl);
178 ft->event = event;
179 ft->arg = arg;
180 ft->tl.expires = jiffies + (millisec * HZ) / 1000;
181 add_timer(&ft->tl);
182}
183EXPORT_SYMBOL(mISDN_FsmRestartTimer);
diff --git a/drivers/isdn/mISDN/fsm.h b/drivers/isdn/mISDN/fsm.h
new file mode 100644
index 000000000000..928f5be192c1
--- /dev/null
+++ b/drivers/isdn/mISDN/fsm.h
@@ -0,0 +1,67 @@
1/*
2 *
3 * Author Karsten Keil <kkeil@novell.com>
4 *
5 * Thanks to Jan den Ouden
6 * Fritz Elfert
7 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 */
19
20#ifndef _MISDN_FSM_H
21#define _MISDN_FSM_H
22
23#include <linux/timer.h>
24
25/* Statemachine */
26
27struct FsmInst;
28
29typedef void (*FSMFNPTR)(struct FsmInst *, int, void *);
30
31struct Fsm {
32 FSMFNPTR *jumpmatrix;
33 int state_count, event_count;
34 char **strEvent, **strState;
35};
36
37struct FsmInst {
38 struct Fsm *fsm;
39 int state;
40 int debug;
41 void *userdata;
42 int userint;
43 void (*printdebug) (struct FsmInst *, char *, ...);
44};
45
46struct FsmNode {
47 int state, event;
48 void (*routine) (struct FsmInst *, int, void *);
49};
50
51struct FsmTimer {
52 struct FsmInst *fi;
53 struct timer_list tl;
54 int event;
55 void *arg;
56};
57
58extern void mISDN_FsmNew(struct Fsm *, struct FsmNode *, int);
59extern void mISDN_FsmFree(struct Fsm *);
60extern int mISDN_FsmEvent(struct FsmInst *, int , void *);
61extern void mISDN_FsmChangeState(struct FsmInst *, int);
62extern void mISDN_FsmInitTimer(struct FsmInst *, struct FsmTimer *);
63extern int mISDN_FsmAddTimer(struct FsmTimer *, int, int, void *, int);
64extern void mISDN_FsmRestartTimer(struct FsmTimer *, int, int, void *, int);
65extern void mISDN_FsmDelTimer(struct FsmTimer *, int);
66
67#endif
diff --git a/drivers/isdn/mISDN/hwchannel.c b/drivers/isdn/mISDN/hwchannel.c
new file mode 100644
index 000000000000..2596fba4e614
--- /dev/null
+++ b/drivers/isdn/mISDN/hwchannel.c
@@ -0,0 +1,365 @@
1/*
2 *
3 * Author Karsten Keil <kkeil@novell.com>
4 *
5 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/mISDNhw.h>
20
21static void
22dchannel_bh(struct work_struct *ws)
23{
24 struct dchannel *dch = container_of(ws, struct dchannel, workq);
25 struct sk_buff *skb;
26 int err;
27
28 if (test_and_clear_bit(FLG_RECVQUEUE, &dch->Flags)) {
29 while ((skb = skb_dequeue(&dch->rqueue))) {
30 if (likely(dch->dev.D.peer)) {
31 err = dch->dev.D.recv(dch->dev.D.peer, skb);
32 if (err)
33 dev_kfree_skb(skb);
34 } else
35 dev_kfree_skb(skb);
36 }
37 }
38 if (test_and_clear_bit(FLG_PHCHANGE, &dch->Flags)) {
39 if (dch->phfunc)
40 dch->phfunc(dch);
41 }
42}
43
44static void
45bchannel_bh(struct work_struct *ws)
46{
47 struct bchannel *bch = container_of(ws, struct bchannel, workq);
48 struct sk_buff *skb;
49 int err;
50
51 if (test_and_clear_bit(FLG_RECVQUEUE, &bch->Flags)) {
52 while ((skb = skb_dequeue(&bch->rqueue))) {
53 if (bch->rcount >= 64)
54 printk(KERN_WARNING "B-channel %p receive "
55 "queue if full, but empties...\n", bch);
56 bch->rcount--;
57 if (likely(bch->ch.peer)) {
58 err = bch->ch.recv(bch->ch.peer, skb);
59 if (err)
60 dev_kfree_skb(skb);
61 } else
62 dev_kfree_skb(skb);
63 }
64 }
65}
66
67int
68mISDN_initdchannel(struct dchannel *ch, int maxlen, void *phf)
69{
70 test_and_set_bit(FLG_HDLC, &ch->Flags);
71 ch->maxlen = maxlen;
72 ch->hw = NULL;
73 ch->rx_skb = NULL;
74 ch->tx_skb = NULL;
75 ch->tx_idx = 0;
76 ch->phfunc = phf;
77 skb_queue_head_init(&ch->squeue);
78 skb_queue_head_init(&ch->rqueue);
79 INIT_LIST_HEAD(&ch->dev.bchannels);
80 INIT_WORK(&ch->workq, dchannel_bh);
81 return 0;
82}
83EXPORT_SYMBOL(mISDN_initdchannel);
84
85int
86mISDN_initbchannel(struct bchannel *ch, int maxlen)
87{
88 ch->Flags = 0;
89 ch->maxlen = maxlen;
90 ch->hw = NULL;
91 ch->rx_skb = NULL;
92 ch->tx_skb = NULL;
93 ch->tx_idx = 0;
94 skb_queue_head_init(&ch->rqueue);
95 ch->rcount = 0;
96 ch->next_skb = NULL;
97 INIT_WORK(&ch->workq, bchannel_bh);
98 return 0;
99}
100EXPORT_SYMBOL(mISDN_initbchannel);
101
102int
103mISDN_freedchannel(struct dchannel *ch)
104{
105 if (ch->tx_skb) {
106 dev_kfree_skb(ch->tx_skb);
107 ch->tx_skb = NULL;
108 }
109 if (ch->rx_skb) {
110 dev_kfree_skb(ch->rx_skb);
111 ch->rx_skb = NULL;
112 }
113 skb_queue_purge(&ch->squeue);
114 skb_queue_purge(&ch->rqueue);
115 flush_scheduled_work();
116 return 0;
117}
118EXPORT_SYMBOL(mISDN_freedchannel);
119
120int
121mISDN_freebchannel(struct bchannel *ch)
122{
123 if (ch->tx_skb) {
124 dev_kfree_skb(ch->tx_skb);
125 ch->tx_skb = NULL;
126 }
127 if (ch->rx_skb) {
128 dev_kfree_skb(ch->rx_skb);
129 ch->rx_skb = NULL;
130 }
131 if (ch->next_skb) {
132 dev_kfree_skb(ch->next_skb);
133 ch->next_skb = NULL;
134 }
135 skb_queue_purge(&ch->rqueue);
136 ch->rcount = 0;
137 flush_scheduled_work();
138 return 0;
139}
140EXPORT_SYMBOL(mISDN_freebchannel);
141
142static inline u_int
143get_sapi_tei(u_char *p)
144{
145 u_int sapi, tei;
146
147 sapi = *p >> 2;
148 tei = p[1] >> 1;
149 return sapi | (tei << 8);
150}
151
152void
153recv_Dchannel(struct dchannel *dch)
154{
155 struct mISDNhead *hh;
156
157 if (dch->rx_skb->len < 2) { /* at least 2 for sapi / tei */
158 dev_kfree_skb(dch->rx_skb);
159 dch->rx_skb = NULL;
160 return;
161 }
162 hh = mISDN_HEAD_P(dch->rx_skb);
163 hh->prim = PH_DATA_IND;
164 hh->id = get_sapi_tei(dch->rx_skb->data);
165 skb_queue_tail(&dch->rqueue, dch->rx_skb);
166 dch->rx_skb = NULL;
167 schedule_event(dch, FLG_RECVQUEUE);
168}
169EXPORT_SYMBOL(recv_Dchannel);
170
171void
172recv_Bchannel(struct bchannel *bch)
173{
174 struct mISDNhead *hh;
175
176 hh = mISDN_HEAD_P(bch->rx_skb);
177 hh->prim = PH_DATA_IND;
178 hh->id = MISDN_ID_ANY;
179 if (bch->rcount >= 64) {
180 dev_kfree_skb(bch->rx_skb);
181 bch->rx_skb = NULL;
182 return;
183 }
184 bch->rcount++;
185 skb_queue_tail(&bch->rqueue, bch->rx_skb);
186 bch->rx_skb = NULL;
187 schedule_event(bch, FLG_RECVQUEUE);
188}
189EXPORT_SYMBOL(recv_Bchannel);
190
191void
192recv_Dchannel_skb(struct dchannel *dch, struct sk_buff *skb)
193{
194 skb_queue_tail(&dch->rqueue, skb);
195 schedule_event(dch, FLG_RECVQUEUE);
196}
197EXPORT_SYMBOL(recv_Dchannel_skb);
198
199void
200recv_Bchannel_skb(struct bchannel *bch, struct sk_buff *skb)
201{
202 if (bch->rcount >= 64) {
203 dev_kfree_skb(skb);
204 return;
205 }
206 bch->rcount++;
207 skb_queue_tail(&bch->rqueue, skb);
208 schedule_event(bch, FLG_RECVQUEUE);
209}
210EXPORT_SYMBOL(recv_Bchannel_skb);
211
212static void
213confirm_Dsend(struct dchannel *dch)
214{
215 struct sk_buff *skb;
216
217 skb = _alloc_mISDN_skb(PH_DATA_CNF, mISDN_HEAD_ID(dch->tx_skb),
218 0, NULL, GFP_ATOMIC);
219 if (!skb) {
220 printk(KERN_ERR "%s: no skb id %x\n", __func__,
221 mISDN_HEAD_ID(dch->tx_skb));
222 return;
223 }
224 skb_queue_tail(&dch->rqueue, skb);
225 schedule_event(dch, FLG_RECVQUEUE);
226}
227
228int
229get_next_dframe(struct dchannel *dch)
230{
231 dch->tx_idx = 0;
232 dch->tx_skb = skb_dequeue(&dch->squeue);
233 if (dch->tx_skb) {
234 confirm_Dsend(dch);
235 return 1;
236 }
237 dch->tx_skb = NULL;
238 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
239 return 0;
240}
241EXPORT_SYMBOL(get_next_dframe);
242
243void
244confirm_Bsend(struct bchannel *bch)
245{
246 struct sk_buff *skb;
247
248 if (bch->rcount >= 64)
249 return;
250 skb = _alloc_mISDN_skb(PH_DATA_CNF, mISDN_HEAD_ID(bch->tx_skb),
251 0, NULL, GFP_ATOMIC);
252 if (!skb) {
253 printk(KERN_ERR "%s: no skb id %x\n", __func__,
254 mISDN_HEAD_ID(bch->tx_skb));
255 return;
256 }
257 bch->rcount++;
258 skb_queue_tail(&bch->rqueue, skb);
259 schedule_event(bch, FLG_RECVQUEUE);
260}
261EXPORT_SYMBOL(confirm_Bsend);
262
263int
264get_next_bframe(struct bchannel *bch)
265{
266 bch->tx_idx = 0;
267 if (test_bit(FLG_TX_NEXT, &bch->Flags)) {
268 bch->tx_skb = bch->next_skb;
269 if (bch->tx_skb) {
270 bch->next_skb = NULL;
271 test_and_clear_bit(FLG_TX_NEXT, &bch->Flags);
272 if (!test_bit(FLG_TRANSPARENT, &bch->Flags))
273 confirm_Bsend(bch); /* not for transparent */
274 return 1;
275 } else {
276 test_and_clear_bit(FLG_TX_NEXT, &bch->Flags);
277 printk(KERN_WARNING "B TX_NEXT without skb\n");
278 }
279 }
280 bch->tx_skb = NULL;
281 test_and_clear_bit(FLG_TX_BUSY, &bch->Flags);
282 return 0;
283}
284EXPORT_SYMBOL(get_next_bframe);
285
286void
287queue_ch_frame(struct mISDNchannel *ch, u_int pr, int id, struct sk_buff *skb)
288{
289 struct mISDNhead *hh;
290
291 if (!skb) {
292 _queue_data(ch, pr, id, 0, NULL, GFP_ATOMIC);
293 } else {
294 if (ch->peer) {
295 hh = mISDN_HEAD_P(skb);
296 hh->prim = pr;
297 hh->id = id;
298 if (!ch->recv(ch->peer, skb))
299 return;
300 }
301 dev_kfree_skb(skb);
302 }
303}
304EXPORT_SYMBOL(queue_ch_frame);
305
306int
307dchannel_senddata(struct dchannel *ch, struct sk_buff *skb)
308{
309 /* check oversize */
310 if (skb->len <= 0) {
311 printk(KERN_WARNING "%s: skb too small\n", __func__);
312 return -EINVAL;
313 }
314 if (skb->len > ch->maxlen) {
315 printk(KERN_WARNING "%s: skb too large(%d/%d)\n",
316 __func__, skb->len, ch->maxlen);
317 return -EINVAL;
318 }
319 /* HW lock must be obtained */
320 if (test_and_set_bit(FLG_TX_BUSY, &ch->Flags)) {
321 skb_queue_tail(&ch->squeue, skb);
322 return 0;
323 } else {
324 /* write to fifo */
325 ch->tx_skb = skb;
326 ch->tx_idx = 0;
327 return 1;
328 }
329}
330EXPORT_SYMBOL(dchannel_senddata);
331
332int
333bchannel_senddata(struct bchannel *ch, struct sk_buff *skb)
334{
335
336 /* check oversize */
337 if (skb->len <= 0) {
338 printk(KERN_WARNING "%s: skb too small\n", __func__);
339 return -EINVAL;
340 }
341 if (skb->len > ch->maxlen) {
342 printk(KERN_WARNING "%s: skb too large(%d/%d)\n",
343 __func__, skb->len, ch->maxlen);
344 return -EINVAL;
345 }
346 /* HW lock must be obtained */
347 /* check for pending next_skb */
348 if (ch->next_skb) {
349 printk(KERN_WARNING
350 "%s: next_skb exist ERROR (skb->len=%d next_skb->len=%d)\n",
351 __func__, skb->len, ch->next_skb->len);
352 return -EBUSY;
353 }
354 if (test_and_set_bit(FLG_TX_BUSY, &ch->Flags)) {
355 test_and_set_bit(FLG_TX_NEXT, &ch->Flags);
356 ch->next_skb = skb;
357 return 0;
358 } else {
359 /* write to fifo */
360 ch->tx_skb = skb;
361 ch->tx_idx = 0;
362 return 1;
363 }
364}
365EXPORT_SYMBOL(bchannel_senddata);
diff --git a/drivers/isdn/mISDN/l1oip.h b/drivers/isdn/mISDN/l1oip.h
new file mode 100644
index 000000000000..a23d575449f6
--- /dev/null
+++ b/drivers/isdn/mISDN/l1oip.h
@@ -0,0 +1,91 @@
1/*
2 * see notice in l1oip.c
3 */
4
5/* debugging */
6#define DEBUG_L1OIP_INIT 0x00010000
7#define DEBUG_L1OIP_SOCKET 0x00020000
8#define DEBUG_L1OIP_MGR 0x00040000
9#define DEBUG_L1OIP_MSG 0x00080000
10
11/* enable to disorder received bchannels by sequence 2143658798... */
12/*
13#define REORDER_DEBUG
14*/
15
16/* frames */
17#define L1OIP_MAX_LEN 2048 /* max packet size form l2 */
18#define L1OIP_MAX_PERFRAME 1400 /* max data size in one frame */
19
20
21/* timers */
22#define L1OIP_KEEPALIVE 15
23#define L1OIP_TIMEOUT 65
24
25
26/* socket */
27#define L1OIP_DEFAULTPORT 931
28
29
30/* channel structure */
31struct l1oip_chan {
32 struct dchannel *dch;
33 struct bchannel *bch;
34 u32 tx_counter; /* counts xmit bytes/packets */
35 u32 rx_counter; /* counts recv bytes/packets */
36 u32 codecstate; /* used by codec to save data */
37#ifdef REORDER_DEBUG
38 int disorder_flag;
39 struct sk_buff *disorder_skb;
40 u32 disorder_cnt;
41#endif
42};
43
44
45/* card structure */
46struct l1oip {
47 struct list_head list;
48
49 /* card */
50 int registered; /* if registered with mISDN */
51 char name[MISDN_MAX_IDLEN];
52 int idx; /* card index */
53 int pri; /* 1=pri, 0=bri */
54 int d_idx; /* current dchannel number */
55 int b_num; /* number of bchannels */
56 u32 id; /* id of connection */
57 int ondemand; /* if transmis. is on demand */
58 int bundle; /* bundle channels in one frm */
59 int codec; /* codec to use for transmis. */
60 int limit; /* limit number of bchannels */
61
62 /* timer */
63 struct timer_list keep_tl;
64 struct timer_list timeout_tl;
65 int timeout_on;
66 struct work_struct workq;
67
68 /* socket */
69 struct socket *socket; /* if set, socket is created */
70 struct completion socket_complete;/* completion of sock thread */
71 struct task_struct *socket_thread;
72 spinlock_t socket_lock; /* access sock outside thread */
73 u32 remoteip; /* if all set, ip is assigned */
74 u16 localport; /* must always be set */
75 u16 remoteport; /* must always be set */
76 struct sockaddr_in sin_local; /* local socket name */
77 struct sockaddr_in sin_remote; /* remote socket name */
78 struct msghdr sendmsg; /* ip message to send */
79 struct iovec sendiov; /* iov for message */
80
81 /* frame */
82 struct l1oip_chan chan[128]; /* channel instances */
83};
84
85extern int l1oip_law_to_4bit(u8 *data, int len, u8 *result, u32 *state);
86extern int l1oip_4bit_to_law(u8 *data, int len, u8 *result);
87extern int l1oip_alaw_to_ulaw(u8 *data, int len, u8 *result);
88extern int l1oip_ulaw_to_alaw(u8 *data, int len, u8 *result);
89extern void l1oip_4bit_free(void);
90extern int l1oip_4bit_alloc(int ulaw);
91
diff --git a/drivers/isdn/mISDN/l1oip_codec.c b/drivers/isdn/mISDN/l1oip_codec.c
new file mode 100644
index 000000000000..a2dc4570ef43
--- /dev/null
+++ b/drivers/isdn/mISDN/l1oip_codec.c
@@ -0,0 +1,374 @@
1/*
2
3 * l1oip_codec.c generic codec using lookup table
4 * -> conversion from a-Law to u-Law
5 * -> conversion from u-Law to a-Law
6 * -> compression by reducing the number of sample resolution to 4
7 *
8 * NOTE: It is not compatible with any standard codec like ADPCM.
9 *
10 * Author Andreas Eversberg (jolly@eversberg.eu)
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
26 */
27
28/*
29
30How the codec works:
31--------------------
32
33The volume is increased to increase the dynamic range of the audio signal.
34Each sample is converted to a-LAW with only 16 steps of level resolution.
35A pair of two samples are stored in one byte.
36
37The first byte is stored in the upper bits, the second byte is stored in the
38lower bits.
39
40To speed up compression and decompression, two lookup tables are formed:
41
42- 16 bits index for two samples (law encoded) with 8 bit compressed result.
43- 8 bits index for one compressed data with 16 bits decompressed result.
44
45NOTE: The bytes are handled as they are law-encoded.
46
47*/
48
49#include <linux/vmalloc.h>
50#include <linux/mISDNif.h>
51#include "core.h"
52
53/* definitions of codec. don't use calculations, code may run slower. */
54
55static u8 *table_com;
56static u16 *table_dec;
57
58
59/* alaw -> ulaw */
60static u8 alaw_to_ulaw[256] =
61{
62 0xab, 0x2b, 0xe3, 0x63, 0x8b, 0x0b, 0xc9, 0x49,
63 0xba, 0x3a, 0xf6, 0x76, 0x9b, 0x1b, 0xd7, 0x57,
64 0xa3, 0x23, 0xdd, 0x5d, 0x83, 0x03, 0xc1, 0x41,
65 0xb2, 0x32, 0xeb, 0x6b, 0x93, 0x13, 0xcf, 0x4f,
66 0xaf, 0x2f, 0xe7, 0x67, 0x8f, 0x0f, 0xcd, 0x4d,
67 0xbe, 0x3e, 0xfe, 0x7e, 0x9f, 0x1f, 0xdb, 0x5b,
68 0xa7, 0x27, 0xdf, 0x5f, 0x87, 0x07, 0xc5, 0x45,
69 0xb6, 0x36, 0xef, 0x6f, 0x97, 0x17, 0xd3, 0x53,
70 0xa9, 0x29, 0xe1, 0x61, 0x89, 0x09, 0xc7, 0x47,
71 0xb8, 0x38, 0xf2, 0x72, 0x99, 0x19, 0xd5, 0x55,
72 0xa1, 0x21, 0xdc, 0x5c, 0x81, 0x01, 0xbf, 0x3f,
73 0xb0, 0x30, 0xe9, 0x69, 0x91, 0x11, 0xce, 0x4e,
74 0xad, 0x2d, 0xe5, 0x65, 0x8d, 0x0d, 0xcb, 0x4b,
75 0xbc, 0x3c, 0xfa, 0x7a, 0x9d, 0x1d, 0xd9, 0x59,
76 0xa5, 0x25, 0xde, 0x5e, 0x85, 0x05, 0xc3, 0x43,
77 0xb4, 0x34, 0xed, 0x6d, 0x95, 0x15, 0xd1, 0x51,
78 0xac, 0x2c, 0xe4, 0x64, 0x8c, 0x0c, 0xca, 0x4a,
79 0xbb, 0x3b, 0xf8, 0x78, 0x9c, 0x1c, 0xd8, 0x58,
80 0xa4, 0x24, 0xde, 0x5e, 0x84, 0x04, 0xc2, 0x42,
81 0xb3, 0x33, 0xec, 0x6c, 0x94, 0x14, 0xd0, 0x50,
82 0xb0, 0x30, 0xe8, 0x68, 0x90, 0x10, 0xce, 0x4e,
83 0xbf, 0x3f, 0xfe, 0x7e, 0xa0, 0x20, 0xdc, 0x5c,
84 0xa8, 0x28, 0xe0, 0x60, 0x88, 0x08, 0xc6, 0x46,
85 0xb7, 0x37, 0xf0, 0x70, 0x98, 0x18, 0xd4, 0x54,
86 0xaa, 0x2a, 0xe2, 0x62, 0x8a, 0x0a, 0xc8, 0x48,
87 0xb9, 0x39, 0xf4, 0x74, 0x9a, 0x1a, 0xd6, 0x56,
88 0xa2, 0x22, 0xdd, 0x5d, 0x82, 0x02, 0xc0, 0x40,
89 0xb1, 0x31, 0xea, 0x6a, 0x92, 0x12, 0xcf, 0x4f,
90 0xae, 0x2e, 0xe6, 0x66, 0x8e, 0x0e, 0xcc, 0x4c,
91 0xbd, 0x3d, 0xfc, 0x7c, 0x9e, 0x1e, 0xda, 0x5a,
92 0xa6, 0x26, 0xdf, 0x5f, 0x86, 0x06, 0xc4, 0x44,
93 0xb5, 0x35, 0xee, 0x6e, 0x96, 0x16, 0xd2, 0x52
94};
95
96/* ulaw -> alaw */
97static u8 ulaw_to_alaw[256] =
98{
99 0xab, 0x55, 0xd5, 0x15, 0x95, 0x75, 0xf5, 0x35,
100 0xb5, 0x45, 0xc5, 0x05, 0x85, 0x65, 0xe5, 0x25,
101 0xa5, 0x5d, 0xdd, 0x1d, 0x9d, 0x7d, 0xfd, 0x3d,
102 0xbd, 0x4d, 0xcd, 0x0d, 0x8d, 0x6d, 0xed, 0x2d,
103 0xad, 0x51, 0xd1, 0x11, 0x91, 0x71, 0xf1, 0x31,
104 0xb1, 0x41, 0xc1, 0x01, 0x81, 0x61, 0xe1, 0x21,
105 0x59, 0xd9, 0x19, 0x99, 0x79, 0xf9, 0x39, 0xb9,
106 0x49, 0xc9, 0x09, 0x89, 0x69, 0xe9, 0x29, 0xa9,
107 0xd7, 0x17, 0x97, 0x77, 0xf7, 0x37, 0xb7, 0x47,
108 0xc7, 0x07, 0x87, 0x67, 0xe7, 0x27, 0xa7, 0xdf,
109 0x9f, 0x7f, 0xff, 0x3f, 0xbf, 0x4f, 0xcf, 0x0f,
110 0x8f, 0x6f, 0xef, 0x2f, 0x53, 0x13, 0x73, 0x33,
111 0xb3, 0x43, 0xc3, 0x03, 0x83, 0x63, 0xe3, 0x23,
112 0xa3, 0x5b, 0xdb, 0x1b, 0x9b, 0x7b, 0xfb, 0x3b,
113 0xbb, 0xbb, 0x4b, 0x4b, 0xcb, 0xcb, 0x0b, 0x0b,
114 0x8b, 0x8b, 0x6b, 0x6b, 0xeb, 0xeb, 0x2b, 0x2b,
115 0xab, 0x54, 0xd4, 0x14, 0x94, 0x74, 0xf4, 0x34,
116 0xb4, 0x44, 0xc4, 0x04, 0x84, 0x64, 0xe4, 0x24,
117 0xa4, 0x5c, 0xdc, 0x1c, 0x9c, 0x7c, 0xfc, 0x3c,
118 0xbc, 0x4c, 0xcc, 0x0c, 0x8c, 0x6c, 0xec, 0x2c,
119 0xac, 0x50, 0xd0, 0x10, 0x90, 0x70, 0xf0, 0x30,
120 0xb0, 0x40, 0xc0, 0x00, 0x80, 0x60, 0xe0, 0x20,
121 0x58, 0xd8, 0x18, 0x98, 0x78, 0xf8, 0x38, 0xb8,
122 0x48, 0xc8, 0x08, 0x88, 0x68, 0xe8, 0x28, 0xa8,
123 0xd6, 0x16, 0x96, 0x76, 0xf6, 0x36, 0xb6, 0x46,
124 0xc6, 0x06, 0x86, 0x66, 0xe6, 0x26, 0xa6, 0xde,
125 0x9e, 0x7e, 0xfe, 0x3e, 0xbe, 0x4e, 0xce, 0x0e,
126 0x8e, 0x6e, 0xee, 0x2e, 0x52, 0x12, 0x72, 0x32,
127 0xb2, 0x42, 0xc2, 0x02, 0x82, 0x62, 0xe2, 0x22,
128 0xa2, 0x5a, 0xda, 0x1a, 0x9a, 0x7a, 0xfa, 0x3a,
129 0xba, 0xba, 0x4a, 0x4a, 0xca, 0xca, 0x0a, 0x0a,
130 0x8a, 0x8a, 0x6a, 0x6a, 0xea, 0xea, 0x2a, 0x2a
131};
132
133/* alaw -> 4bit compression */
134static u8 alaw_to_4bit[256] = {
135 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
136 0x0d, 0x02, 0x08, 0x07, 0x0f, 0x00, 0x0b, 0x04,
137 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
138 0x0d, 0x02, 0x09, 0x06, 0x0f, 0x00, 0x0b, 0x04,
139 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
140 0x0d, 0x02, 0x08, 0x07, 0x0f, 0x00, 0x0b, 0x04,
141 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
142 0x0d, 0x02, 0x09, 0x06, 0x0f, 0x00, 0x0b, 0x04,
143 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
144 0x0d, 0x02, 0x08, 0x07, 0x0f, 0x00, 0x0b, 0x04,
145 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0d, 0x02,
146 0x0e, 0x02, 0x09, 0x06, 0x0f, 0x00, 0x0b, 0x04,
147 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
148 0x0d, 0x02, 0x08, 0x07, 0x0f, 0x00, 0x0b, 0x04,
149 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
150 0x0d, 0x02, 0x09, 0x06, 0x0f, 0x00, 0x0b, 0x04,
151 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
152 0x0d, 0x02, 0x08, 0x07, 0x0f, 0x00, 0x0b, 0x04,
153 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
154 0x0d, 0x02, 0x09, 0x06, 0x0f, 0x00, 0x0b, 0x04,
155 0x0e, 0x02, 0x09, 0x06, 0x0f, 0x00, 0x0b, 0x04,
156 0x0d, 0x02, 0x08, 0x07, 0x0f, 0x01, 0x0a, 0x05,
157 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
158 0x0d, 0x02, 0x09, 0x07, 0x0f, 0x00, 0x0b, 0x04,
159 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
160 0x0d, 0x02, 0x08, 0x07, 0x0f, 0x00, 0x0b, 0x04,
161 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
162 0x0d, 0x02, 0x09, 0x06, 0x0f, 0x00, 0x0b, 0x04,
163 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
164 0x0d, 0x02, 0x08, 0x07, 0x0f, 0x00, 0x0b, 0x04,
165 0x0e, 0x01, 0x0a, 0x05, 0x0f, 0x00, 0x0c, 0x03,
166 0x0d, 0x02, 0x09, 0x06, 0x0f, 0x00, 0x0b, 0x04,
167};
168
169/* 4bit -> alaw decompression */
170static u8 _4bit_to_alaw[16] = {
171 0x5d, 0x51, 0xd9, 0xd7, 0x5f, 0x53, 0xa3, 0x4b,
172 0x2a, 0x3a, 0x22, 0x2e, 0x26, 0x56, 0x20, 0x2c,
173};
174
175/* ulaw -> 4bit compression */
176static u8 ulaw_to_4bit[256] = {
177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
182 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
183 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
184 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
185 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
186 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04,
187 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
188 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05,
189 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
190 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
191 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
192 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x08,
193 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
194 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
195 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
196 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
197 0x0f, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
198 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
199 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d,
200 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d,
201 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
202 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b,
203 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
204 0x0b, 0x0b, 0x0b, 0x0b, 0x0a, 0x0a, 0x0a, 0x0a,
205 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
206 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
207 0x09, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
208 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
209};
210
211/* 4bit -> ulaw decompression */
212static u8 _4bit_to_ulaw[16] = {
213 0x11, 0x21, 0x31, 0x40, 0x4e, 0x5c, 0x68, 0x71,
214 0xfe, 0xef, 0xe7, 0xdb, 0xcd, 0xbf, 0xaf, 0x9f,
215};
216
217
218/*
219 * Compresses data to the result buffer
220 * The result size must be at least half of the input buffer.
221 * The number of samples also must be even!
222 */
223int
224l1oip_law_to_4bit(u8 *data, int len, u8 *result, u32 *state)
225{
226 int ii, i = 0, o = 0;
227
228 if (!len)
229 return 0;
230
231 /* send saved byte and first input byte */
232 if (*state) {
233 *result++ = table_com[(((*state)<<8)&0xff00) | (*data++)];
234 len--;
235 o++;
236 }
237
238 ii = len >> 1;
239
240 while (i < ii) {
241 *result++ = table_com[(data[0]<<8) | (data[1])];
242 data += 2;
243 i++;
244 o++;
245 }
246
247 /* if len has an odd number, we save byte for next call */
248 if (len & 1)
249 *state = 0x100 + *data;
250 else
251 *state = 0;
252
253 return o;
254}
255
256/* Decompress data to the result buffer
257 * The result size must be the number of sample in packet. (2 * input data)
258 * The number of samples in the result are even!
259 */
260int
261l1oip_4bit_to_law(u8 *data, int len, u8 *result)
262{
263 int i = 0;
264 u16 r;
265
266 while (i < len) {
267 r = table_dec[*data++];
268 *result++ = r>>8;
269 *result++ = r;
270 i++;
271 }
272
273 return len << 1;
274}
275
276
277/*
278 * law conversion
279 */
280int
281l1oip_alaw_to_ulaw(u8 *data, int len, u8 *result)
282{
283 int i = 0;
284
285 while (i < len) {
286 *result++ = alaw_to_ulaw[*data++];
287 i++;
288 }
289
290 return len;
291}
292
293int
294l1oip_ulaw_to_alaw(u8 *data, int len, u8 *result)
295{
296 int i = 0;
297
298 while (i < len) {
299 *result++ = ulaw_to_alaw[*data++];
300 i++;
301 }
302
303 return len;
304}
305
306
307/*
308 * generate/free compression and decompression table
309 */
310void
311l1oip_4bit_free(void)
312{
313 if (table_dec)
314 vfree(table_dec);
315 if (table_com)
316 vfree(table_com);
317 table_com = NULL;
318 table_dec = NULL;
319}
320
321int
322l1oip_4bit_alloc(int ulaw)
323{
324 int i1, i2, c, sample;
325
326 /* in case, it is called again */
327 if (table_dec)
328 return 0;
329
330 /* alloc conversion tables */
331 table_com = vmalloc(65536);
332 table_dec = vmalloc(512);
333 if (!table_com | !table_dec) {
334 l1oip_4bit_free();
335 return -ENOMEM;
336 }
337 memset(table_com, 0, 65536);
338 memset(table_dec, 0, 512);
339 /* generate compression table */
340 i1 = 0;
341 while (i1 < 256) {
342 if (ulaw)
343 c = ulaw_to_4bit[i1];
344 else
345 c = alaw_to_4bit[i1];
346 i2 = 0;
347 while (i2 < 256) {
348 table_com[(i1<<8) | i2] |= (c<<4);
349 table_com[(i2<<8) | i1] |= c;
350 i2++;
351 }
352 i1++;
353 }
354
355 /* generate decompression table */
356 i1 = 0;
357 while (i1 < 16) {
358 if (ulaw)
359 sample = _4bit_to_ulaw[i1];
360 else
361 sample = _4bit_to_alaw[i1];
362 i2 = 0;
363 while (i2 < 16) {
364 table_dec[(i1<<4) | i2] |= (sample<<8);
365 table_dec[(i2<<4) | i1] |= sample;
366 i2++;
367 }
368 i1++;
369 }
370
371 return 0;
372}
373
374
diff --git a/drivers/isdn/mISDN/l1oip_core.c b/drivers/isdn/mISDN/l1oip_core.c
new file mode 100644
index 000000000000..155b99780c4f
--- /dev/null
+++ b/drivers/isdn/mISDN/l1oip_core.c
@@ -0,0 +1,1518 @@
1/*
2
3 * l1oip.c low level driver for tunneling layer 1 over IP
4 *
5 * NOTE: It is not compatible with TDMoIP nor "ISDN over IP".
6 *
7 * Author Andreas Eversberg (jolly@eversberg.eu)
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25/* module parameters:
26 * type:
27 Value 1 = BRI
28 Value 2 = PRI
29 Value 3 = BRI (multi channel frame, not supported yet)
30 Value 4 = PRI (multi channel frame, not supported yet)
31 A multi channel frame reduces overhead to a single frame for all
32 b-channels, but increases delay.
33 (NOTE: Multi channel frames are not implemented yet.)
34
35 * codec:
36 Value 0 = transparent (default)
37 Value 1 = transfer ALAW
38 Value 2 = transfer ULAW
39 Value 3 = transfer generic 4 bit compression.
40
41 * ulaw:
42 0 = we use a-Law (default)
43 1 = we use u-Law
44
45 * limit:
46 limitation of B-channels to control bandwidth (1...126)
47 BRI: 1 or 2
48 PRI: 1-30, 31-126 (126, because dchannel ist not counted here)
49 Also limited ressources are used for stack, resulting in less channels.
50 It is possible to have more channels than 30 in PRI mode, this must
51 be supported by the application.
52
53 * ip:
54 byte representation of remote ip address (127.0.0.1 -> 127,0,0,1)
55 If not given or four 0, no remote address is set.
56 For multiple interfaces, concat ip addresses. (127,0,0,1,127,0,0,1)
57
58 * port:
59 port number (local interface)
60 If not given or 0, port 931 is used for fist instance, 932 for next...
61 For multiple interfaces, different ports must be given.
62
63 * remoteport:
64 port number (remote interface)
65 If not given or 0, remote port equals local port
66 For multiple interfaces on equal sites, different ports must be given.
67
68 * ondemand:
69 0 = fixed (always transmit packets, even when remote side timed out)
70 1 = on demand (only transmit packets, when remote side is detected)
71 the default is 0
72 NOTE: ID must also be set for on demand.
73
74 * id:
75 optional value to identify frames. This value must be equal on both
76 peers and should be random. If omitted or 0, no ID is transmitted.
77
78 * debug:
79 NOTE: only one debug value must be given for all cards
80 enable debugging (see l1oip.h for debug options)
81
82
83Special mISDN controls:
84
85 op = MISDN_CTRL_SETPEER*
86 p1 = bytes 0-3 : remote IP address in network order (left element first)
87 p2 = bytes 1-2 : remote port in network order (high byte first)
88 optional:
89 p2 = bytes 3-4 : local port in network order (high byte first)
90
91 op = MISDN_CTRL_UNSETPEER*
92
93 * Use l1oipctrl for comfortable setting or removing ip address.
94 (Layer 1 Over IP CTRL)
95
96
97L1oIP-Protocol
98--------------
99
100Frame Header:
101
102 7 6 5 4 3 2 1 0
103+---------------+
104|Ver|T|I|Coding |
105+---------------+
106| ID byte 3 * |
107+---------------+
108| ID byte 2 * |
109+---------------+
110| ID byte 1 * |
111+---------------+
112| ID byte 0 * |
113+---------------+
114|M| Channel |
115+---------------+
116| Length * |
117+---------------+
118| Time Base MSB |
119+---------------+
120| Time Base LSB |
121+---------------+
122| Data.... |
123
124...
125
126| |
127+---------------+
128|M| Channel |
129+---------------+
130| Length * |
131+---------------+
132| Time Base MSB |
133+---------------+
134| Time Base LSB |
135+---------------+
136| Data.... |
137
138...
139
140
141* Only included in some cases.
142
143- Ver = Version
144If version is missmatch, the frame must be ignored.
145
146- T = Type of interface
147Must be 0 for S0 or 1 for E1.
148
149- I = Id present
150If bit is set, four ID bytes are included in frame.
151
152- ID = Connection ID
153Additional ID to prevent Denial of Service attacs. Also it prevents hijacking
154connections with dynamic IP. The ID should be random and must not be 0.
155
156- Coding = Type of codec
157Must be 0 for no transcoding. Also for D-channel and other HDLC frames.
158 1 and 2 are reserved for explicitly use of a-LAW or u-LAW codec.
159 3 is used for generic table compressor.
160
161- M = More channels to come. If this flag is 1, the following byte contains
162the length of the channel data. After the data block, the next channel will
163be defined. The flag for the last channel block (or if only one channel is
164transmitted), must be 0 and no length is given.
165
166- Channel = Channel number
1670 reserved
1681-3 channel data for S0 (3 is D-channel)
1691-31 channel data for E1 (16 is D-channel)
17032-127 channel data for extended E1 (16 is D-channel)
171
172- The length is used if the M-flag is 1. It is used to find the next channel
173inside frame.
174NOTE: A value of 0 equals 256 bytes of data.
175 -> For larger data blocks, a single frame must be used.
176 -> For larger streams, a single frame or multiple blocks with same channel ID
177 must be used.
178
179- Time Base = Timestamp of first sample in frame
180The "Time Base" is used to rearange packets and to detect packet loss.
181The 16 bits are sent in network order (MSB first) and count 1/8000 th of a
182second. This causes a wrap arround each 8,192 seconds. There is no requirement
183for the initial "Time Base", but 0 should be used for the first packet.
184In case of HDLC data, this timestamp counts the packet or byte number.
185
186
187Two Timers:
188
189After initialisation, a timer of 15 seconds is started. Whenever a packet is
190transmitted, the timer is reset to 15 seconds again. If the timer expires, an
191empty packet is transmitted. This keep the connection alive.
192
193When a valid packet is received, a timer 65 seconds is started. The interface
194become ACTIVE. If the timer expires, the interface becomes INACTIVE.
195
196
197Dynamic IP handling:
198
199To allow dynamic IP, the ID must be non 0. In this case, any packet with the
200correct port number and ID will be accepted. If the remote side changes its IP
201the new IP is used for all transmitted packets until it changes again.
202
203
204On Demand:
205
206If the ondemand parameter is given, the remote IP is set to 0 on timeout.
207This will stop keepalive traffic to remote. If the remote is online again,
208traffic will continue to the remote address. This is usefull for road warriors.
209This feature only works with ID set, otherwhise it is highly unsecure.
210
211
212Socket and Thread
213-----------------
214
215The complete socket opening and closing is done by a thread.
216When the thread opened a socket, the hc->socket descriptor is set. Whenever a
217packet shall be sent to the socket, the hc->socket must be checked wheter not
218NULL. To prevent change in socket descriptor, the hc->socket_lock must be used.
219To change the socket, a recall of l1oip_socket_open() will safely kill the
220socket process and create a new one.
221
222*/
223
224#define L1OIP_VERSION 0 /* 0...3 */
225
226#include <linux/module.h>
227#include <linux/delay.h>
228#include <linux/mISDNif.h>
229#include <linux/mISDNhw.h>
230#include <linux/mISDNdsp.h>
231#include <linux/init.h>
232#include <linux/in.h>
233#include <linux/inet.h>
234#include <linux/workqueue.h>
235#include <linux/kthread.h>
236#include <net/sock.h>
237#include "core.h"
238#include "l1oip.h"
239
240static const char *l1oip_revision = "2.00";
241
242static int l1oip_cnt;
243static spinlock_t l1oip_lock;
244static struct list_head l1oip_ilist;
245
246#define MAX_CARDS 16
247static u_int type[MAX_CARDS];
248static u_int codec[MAX_CARDS];
249static u_int ip[MAX_CARDS*4];
250static u_int port[MAX_CARDS];
251static u_int remoteport[MAX_CARDS];
252static u_int ondemand[MAX_CARDS];
253static u_int limit[MAX_CARDS];
254static u_int id[MAX_CARDS];
255static int debug;
256static int ulaw;
257
258MODULE_AUTHOR("Andreas Eversberg");
259MODULE_LICENSE("GPL");
260module_param_array(type, uint, NULL, S_IRUGO | S_IWUSR);
261module_param_array(codec, uint, NULL, S_IRUGO | S_IWUSR);
262module_param_array(ip, uint, NULL, S_IRUGO | S_IWUSR);
263module_param_array(port, uint, NULL, S_IRUGO | S_IWUSR);
264module_param_array(remoteport, uint, NULL, S_IRUGO | S_IWUSR);
265module_param_array(ondemand, uint, NULL, S_IRUGO | S_IWUSR);
266module_param_array(limit, uint, NULL, S_IRUGO | S_IWUSR);
267module_param_array(id, uint, NULL, S_IRUGO | S_IWUSR);
268module_param(ulaw, uint, S_IRUGO | S_IWUSR);
269module_param(debug, uint, S_IRUGO | S_IWUSR);
270
271/*
272 * send a frame via socket, if open and restart timer
273 */
274static int
275l1oip_socket_send(struct l1oip *hc, u8 localcodec, u8 channel, u32 chanmask,
276 u16 timebase, u8 *buf, int len)
277{
278 u8 *p;
279 int multi = 0;
280 u8 frame[len+32];
281 struct socket *socket = NULL;
282 mm_segment_t oldfs;
283
284 if (debug & DEBUG_L1OIP_MSG)
285 printk(KERN_DEBUG "%s: sending data to socket (len = %d)\n",
286 __func__, len);
287
288 p = frame;
289
290 /* restart timer */
291 if ((int)(hc->keep_tl.expires-jiffies) < 5*HZ) {
292 del_timer(&hc->keep_tl);
293 hc->keep_tl.expires = jiffies + L1OIP_KEEPALIVE*HZ;
294 add_timer(&hc->keep_tl);
295 } else
296 hc->keep_tl.expires = jiffies + L1OIP_KEEPALIVE*HZ;
297
298 if (debug & DEBUG_L1OIP_MSG)
299 printk(KERN_DEBUG "%s: resetting timer\n", __func__);
300
301 /* drop if we have no remote ip or port */
302 if (!hc->sin_remote.sin_addr.s_addr || !hc->sin_remote.sin_port) {
303 if (debug & DEBUG_L1OIP_MSG)
304 printk(KERN_DEBUG "%s: dropping frame, because remote "
305 "IP is not set.\n", __func__);
306 return len;
307 }
308
309 /* assemble frame */
310 *p++ = (L1OIP_VERSION<<6) /* version and coding */
311 | (hc->pri?0x20:0x00) /* type */
312 | (hc->id?0x10:0x00) /* id */
313 | localcodec;
314 if (hc->id) {
315 *p++ = hc->id>>24; /* id */
316 *p++ = hc->id>>16;
317 *p++ = hc->id>>8;
318 *p++ = hc->id;
319 }
320 *p++ = (multi == 1)?0x80:0x00 + channel; /* m-flag, channel */
321 if (multi == 1)
322 *p++ = len; /* length */
323 *p++ = timebase>>8; /* time base */
324 *p++ = timebase;
325
326 if (buf && len) { /* add data to frame */
327 if (localcodec == 1 && ulaw)
328 l1oip_ulaw_to_alaw(buf, len, p);
329 else if (localcodec == 2 && !ulaw)
330 l1oip_alaw_to_ulaw(buf, len, p);
331 else if (localcodec == 3)
332 len = l1oip_law_to_4bit(buf, len, p,
333 &hc->chan[channel].codecstate);
334 else
335 memcpy(p, buf, len);
336 }
337 len += p - frame;
338
339 /* check for socket in safe condition */
340 spin_lock(&hc->socket_lock);
341 if (!hc->socket) {
342 spin_unlock(&hc->socket_lock);
343 return 0;
344 }
345 /* seize socket */
346 socket = hc->socket;
347 hc->socket = NULL;
348 spin_unlock(&hc->socket_lock);
349 /* send packet */
350 if (debug & DEBUG_L1OIP_MSG)
351 printk(KERN_DEBUG "%s: sending packet to socket (len "
352 "= %d)\n", __func__, len);
353 hc->sendiov.iov_base = frame;
354 hc->sendiov.iov_len = len;
355 oldfs = get_fs();
356 set_fs(KERNEL_DS);
357 len = sock_sendmsg(socket, &hc->sendmsg, len);
358 set_fs(oldfs);
359 /* give socket back */
360 hc->socket = socket; /* no locking required */
361
362 return len;
363}
364
365
366/*
367 * receive channel data from socket
368 */
369static void
370l1oip_socket_recv(struct l1oip *hc, u8 remotecodec, u8 channel, u16 timebase,
371 u8 *buf, int len)
372{
373 struct sk_buff *nskb;
374 struct bchannel *bch;
375 struct dchannel *dch;
376 u8 *p;
377 u32 rx_counter;
378
379 if (len == 0) {
380 if (debug & DEBUG_L1OIP_MSG)
381 printk(KERN_DEBUG "%s: received empty keepalive data, "
382 "ignoring\n", __func__);
383 return;
384 }
385
386 if (debug & DEBUG_L1OIP_MSG)
387 printk(KERN_DEBUG "%s: received data, sending to mISDN (%d)\n",
388 __func__, len);
389
390 if (channel < 1 || channel > 127) {
391 printk(KERN_WARNING "%s: packet error - channel %d out of "
392 "range\n", __func__, channel);
393 return;
394 }
395 dch = hc->chan[channel].dch;
396 bch = hc->chan[channel].bch;
397 if (!dch && !bch) {
398 printk(KERN_WARNING "%s: packet error - channel %d not in "
399 "stack\n", __func__, channel);
400 return;
401 }
402
403 /* prepare message */
404 nskb = mI_alloc_skb((remotecodec == 3)?(len<<1):len, GFP_ATOMIC);
405 if (!nskb) {
406 printk(KERN_ERR "%s: No mem for skb.\n", __func__);
407 return;
408 }
409 p = skb_put(nskb, (remotecodec == 3)?(len<<1):len);
410
411 if (remotecodec == 1 && ulaw)
412 l1oip_alaw_to_ulaw(buf, len, p);
413 else if (remotecodec == 2 && !ulaw)
414 l1oip_ulaw_to_alaw(buf, len, p);
415 else if (remotecodec == 3)
416 len = l1oip_4bit_to_law(buf, len, p);
417 else
418 memcpy(p, buf, len);
419
420 /* send message up */
421 if (dch && len >= 2) {
422 dch->rx_skb = nskb;
423 recv_Dchannel(dch);
424 }
425 if (bch) {
426 /* expand 16 bit sequence number to 32 bit sequence number */
427 rx_counter = hc->chan[channel].rx_counter;
428 if (((s16)(timebase - rx_counter)) >= 0) {
429 /* time has changed forward */
430 if (timebase >= (rx_counter & 0xffff))
431 rx_counter =
432 (rx_counter & 0xffff0000) | timebase;
433 else
434 rx_counter = ((rx_counter & 0xffff0000)+0x10000)
435 | timebase;
436 } else {
437 /* time has changed backwards */
438 if (timebase < (rx_counter & 0xffff))
439 rx_counter =
440 (rx_counter & 0xffff0000) | timebase;
441 else
442 rx_counter = ((rx_counter & 0xffff0000)-0x10000)
443 | timebase;
444 }
445 hc->chan[channel].rx_counter = rx_counter;
446
447#ifdef REORDER_DEBUG
448 if (hc->chan[channel].disorder_flag) {
449 struct sk_buff *skb;
450 int cnt;
451 skb = hc->chan[channel].disorder_skb;
452 hc->chan[channel].disorder_skb = nskb;
453 nskb = skb;
454 cnt = hc->chan[channel].disorder_cnt;
455 hc->chan[channel].disorder_cnt = rx_counter;
456 rx_counter = cnt;
457 }
458 hc->chan[channel].disorder_flag ^= 1;
459 if (nskb)
460#endif
461 queue_ch_frame(&bch->ch, PH_DATA_IND, rx_counter, nskb);
462 }
463}
464
465
466/*
467 * parse frame and extract channel data
468 */
469static void
470l1oip_socket_parse(struct l1oip *hc, struct sockaddr_in *sin, u8 *buf, int len)
471{
472 u32 id;
473 u8 channel;
474 u8 remotecodec;
475 u16 timebase;
476 int m, mlen;
477 int len_start = len; /* initial frame length */
478 struct dchannel *dch = hc->chan[hc->d_idx].dch;
479
480 if (debug & DEBUG_L1OIP_MSG)
481 printk(KERN_DEBUG "%s: received frame, parsing... (%d)\n",
482 __func__, len);
483
484 /* check lenght */
485 if (len < 1+1+2) {
486 printk(KERN_WARNING "%s: packet error - length %d below "
487 "4 bytes\n", __func__, len);
488 return;
489 }
490
491 /* check version */
492 if (((*buf)>>6) != L1OIP_VERSION) {
493 printk(KERN_WARNING "%s: packet error - unknown version %d\n",
494 __func__, buf[0]>>6);
495 return;
496 }
497
498 /* check type */
499 if (((*buf)&0x20) && !hc->pri) {
500 printk(KERN_WARNING "%s: packet error - received E1 packet "
501 "on S0 interface\n", __func__);
502 return;
503 }
504 if (!((*buf)&0x20) && hc->pri) {
505 printk(KERN_WARNING "%s: packet error - received S0 packet "
506 "on E1 interface\n", __func__);
507 return;
508 }
509
510 /* get id flag */
511 id = (*buf>>4)&1;
512
513 /* check coding */
514 remotecodec = (*buf) & 0x0f;
515 if (remotecodec > 3) {
516 printk(KERN_WARNING "%s: packet error - remotecodec %d "
517 "unsupported\n", __func__, remotecodec);
518 return;
519 }
520 buf++;
521 len--;
522
523 /* check id */
524 if (id) {
525 if (!hc->id) {
526 printk(KERN_WARNING "%s: packet error - packet has id "
527 "0x%x, but we have not\n", __func__, id);
528 return;
529 }
530 if (len < 4) {
531 printk(KERN_WARNING "%s: packet error - packet too "
532 "short for ID value\n", __func__);
533 return;
534 }
535 id = (*buf++) << 24;
536 id += (*buf++) << 16;
537 id += (*buf++) << 8;
538 id += (*buf++);
539 len -= 4;
540
541 if (id != hc->id) {
542 printk(KERN_WARNING "%s: packet error - ID mismatch, "
543 "got 0x%x, we 0x%x\n",
544 __func__, id, hc->id);
545 return;
546 }
547 } else {
548 if (hc->id) {
549 printk(KERN_WARNING "%s: packet error - packet has no "
550 "ID, but we have\n", __func__);
551 return;
552 }
553 }
554
555multiframe:
556 if (len < 1) {
557 printk(KERN_WARNING "%s: packet error - packet too short, "
558 "channel expected at position %d.\n",
559 __func__, len-len_start+1);
560 return;
561 }
562
563 /* get channel and multiframe flag */
564 channel = *buf&0x7f;
565 m = *buf >> 7;
566 buf++;
567 len--;
568
569 /* check length on multiframe */
570 if (m) {
571 if (len < 1) {
572 printk(KERN_WARNING "%s: packet error - packet too "
573 "short, length expected at position %d.\n",
574 __func__, len_start-len-1);
575 return;
576 }
577
578 mlen = *buf++;
579 len--;
580 if (mlen == 0)
581 mlen = 256;
582 if (len < mlen+3) {
583 printk(KERN_WARNING "%s: packet error - length %d at "
584 "position %d exceeds total length %d.\n",
585 __func__, mlen, len_start-len-1, len_start);
586 return;
587 }
588 if (len == mlen+3) {
589 printk(KERN_WARNING "%s: packet error - length %d at "
590 "position %d will not allow additional "
591 "packet.\n",
592 __func__, mlen, len_start-len+1);
593 return;
594 }
595 } else
596 mlen = len-2; /* single frame, substract timebase */
597
598 if (len < 2) {
599 printk(KERN_WARNING "%s: packet error - packet too short, time "
600 "base expected at position %d.\n",
601 __func__, len-len_start+1);
602 return;
603 }
604
605 /* get time base */
606 timebase = (*buf++) << 8;
607 timebase |= (*buf++);
608 len -= 2;
609
610 /* if inactive, we send up a PH_ACTIVATE and activate */
611 if (!test_bit(FLG_ACTIVE, &dch->Flags)) {
612 if (debug & (DEBUG_L1OIP_MSG|DEBUG_L1OIP_SOCKET))
613 printk(KERN_DEBUG "%s: interface become active due to "
614 "received packet\n", __func__);
615 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
616 _queue_data(&dch->dev.D, PH_ACTIVATE_IND, MISDN_ID_ANY, 0,
617 NULL, GFP_ATOMIC);
618 }
619
620 /* distribute packet */
621 l1oip_socket_recv(hc, remotecodec, channel, timebase, buf, mlen);
622 buf += mlen;
623 len -= mlen;
624
625 /* multiframe */
626 if (m)
627 goto multiframe;
628
629 /* restart timer */
630 if ((int)(hc->timeout_tl.expires-jiffies) < 5*HZ || !hc->timeout_on) {
631 hc->timeout_on = 1;
632 del_timer(&hc->timeout_tl);
633 hc->timeout_tl.expires = jiffies + L1OIP_TIMEOUT*HZ;
634 add_timer(&hc->timeout_tl);
635 } else /* only adjust timer */
636 hc->timeout_tl.expires = jiffies + L1OIP_TIMEOUT*HZ;
637
638 /* if ip or source port changes */
639 if ((hc->sin_remote.sin_addr.s_addr != sin->sin_addr.s_addr)
640 || (hc->sin_remote.sin_port != sin->sin_port)) {
641 if (debug & DEBUG_L1OIP_SOCKET)
642 printk(KERN_DEBUG "%s: remote address changes from "
643 "0x%08x to 0x%08x (port %d to %d)\n", __func__,
644 ntohl(hc->sin_remote.sin_addr.s_addr),
645 ntohl(sin->sin_addr.s_addr),
646 ntohs(hc->sin_remote.sin_port),
647 ntohs(sin->sin_port));
648 hc->sin_remote.sin_addr.s_addr = sin->sin_addr.s_addr;
649 hc->sin_remote.sin_port = sin->sin_port;
650 }
651}
652
653
654/*
655 * socket stuff
656 */
657static int
658l1oip_socket_thread(void *data)
659{
660 struct l1oip *hc = (struct l1oip *)data;
661 int ret = 0;
662 struct msghdr msg;
663 struct iovec iov;
664 mm_segment_t oldfs;
665 struct sockaddr_in sin_rx;
666 unsigned char recvbuf[1500];
667 int recvlen;
668 struct socket *socket = NULL;
669 DECLARE_COMPLETION(wait);
670
671 /* make daemon */
672 allow_signal(SIGTERM);
673
674 /* create socket */
675 if (sock_create(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &socket)) {
676 printk(KERN_ERR "%s: Failed to create socket.\n", __func__);
677 return -EIO;
678 }
679
680 /* set incoming address */
681 hc->sin_local.sin_family = AF_INET;
682 hc->sin_local.sin_addr.s_addr = INADDR_ANY;
683 hc->sin_local.sin_port = htons((unsigned short)hc->localport);
684
685 /* set outgoing address */
686 hc->sin_remote.sin_family = AF_INET;
687 hc->sin_remote.sin_addr.s_addr = htonl(hc->remoteip);
688 hc->sin_remote.sin_port = htons((unsigned short)hc->remoteport);
689
690 /* bind to incomming port */
691 if (socket->ops->bind(socket, (struct sockaddr *)&hc->sin_local,
692 sizeof(hc->sin_local))) {
693 printk(KERN_ERR "%s: Failed to bind socket to port %d.\n",
694 __func__, hc->localport);
695 ret = -EINVAL;
696 goto fail;
697 }
698
699 /* check sk */
700 if (socket->sk == NULL) {
701 printk(KERN_ERR "%s: socket->sk == NULL\n", __func__);
702 ret = -EIO;
703 goto fail;
704 }
705
706 /* build receive message */
707 msg.msg_name = &sin_rx;
708 msg.msg_namelen = sizeof(sin_rx);
709 msg.msg_control = NULL;
710 msg.msg_controllen = 0;
711 msg.msg_iov = &iov;
712 msg.msg_iovlen = 1;
713
714 /* build send message */
715 hc->sendmsg.msg_name = &hc->sin_remote;
716 hc->sendmsg.msg_namelen = sizeof(hc->sin_remote);
717 hc->sendmsg.msg_control = NULL;
718 hc->sendmsg.msg_controllen = 0;
719 hc->sendmsg.msg_iov = &hc->sendiov;
720 hc->sendmsg.msg_iovlen = 1;
721
722 /* give away socket */
723 spin_lock(&hc->socket_lock);
724 hc->socket = socket;
725 spin_unlock(&hc->socket_lock);
726
727 /* read loop */
728 if (debug & DEBUG_L1OIP_SOCKET)
729 printk(KERN_DEBUG "%s: socket created and open\n",
730 __func__);
731 while (!signal_pending(current)) {
732 iov.iov_base = recvbuf;
733 iov.iov_len = sizeof(recvbuf);
734 oldfs = get_fs();
735 set_fs(KERNEL_DS);
736 recvlen = sock_recvmsg(socket, &msg, sizeof(recvbuf), 0);
737 set_fs(oldfs);
738 if (recvlen > 0) {
739 l1oip_socket_parse(hc, &sin_rx, recvbuf, recvlen);
740 } else {
741 if (debug & DEBUG_L1OIP_SOCKET)
742 printk(KERN_WARNING "%s: broken pipe on socket\n",
743 __func__);
744 }
745 }
746
747 /* get socket back, check first if in use, maybe by send function */
748 spin_lock(&hc->socket_lock);
749 /* if hc->socket is NULL, it is in use until it is given back */
750 while (!hc->socket) {
751 spin_unlock(&hc->socket_lock);
752 schedule_timeout(HZ/10);
753 spin_lock(&hc->socket_lock);
754 }
755 hc->socket = NULL;
756 spin_unlock(&hc->socket_lock);
757
758 if (debug & DEBUG_L1OIP_SOCKET)
759 printk(KERN_DEBUG "%s: socket thread terminating\n",
760 __func__);
761
762fail:
763 /* close socket */
764 if (socket)
765 sock_release(socket);
766
767 /* if we got killed, signal completion */
768 complete(&hc->socket_complete);
769 hc->socket_thread = NULL; /* show termination of thread */
770
771 if (debug & DEBUG_L1OIP_SOCKET)
772 printk(KERN_DEBUG "%s: socket thread terminated\n",
773 __func__);
774 return ret;
775}
776
777static void
778l1oip_socket_close(struct l1oip *hc)
779{
780 /* kill thread */
781 if (hc->socket_thread) {
782 if (debug & DEBUG_L1OIP_SOCKET)
783 printk(KERN_DEBUG "%s: socket thread exists, "
784 "killing...\n", __func__);
785 send_sig(SIGTERM, hc->socket_thread, 0);
786 wait_for_completion(&hc->socket_complete);
787 }
788}
789
790static int
791l1oip_socket_open(struct l1oip *hc)
792{
793 /* in case of reopen, we need to close first */
794 l1oip_socket_close(hc);
795
796 init_completion(&hc->socket_complete);
797
798 /* create receive process */
799 hc->socket_thread = kthread_run(l1oip_socket_thread, hc, "l1oip_%s",
800 hc->name);
801 if (IS_ERR(hc->socket_thread)) {
802 int err = PTR_ERR(hc->socket_thread);
803 printk(KERN_ERR "%s: Failed (%d) to create socket process.\n",
804 __func__, err);
805 hc->socket_thread = NULL;
806 sock_release(hc->socket);
807 return err;
808 }
809 if (debug & DEBUG_L1OIP_SOCKET)
810 printk(KERN_DEBUG "%s: socket thread created\n", __func__);
811
812 return 0;
813}
814
815
816static void
817l1oip_send_bh(struct work_struct *work)
818{
819 struct l1oip *hc = container_of(work, struct l1oip, workq);
820
821 if (debug & (DEBUG_L1OIP_MSG|DEBUG_L1OIP_SOCKET))
822 printk(KERN_DEBUG "%s: keepalive timer expired, sending empty "
823 "frame on dchannel\n", __func__);
824
825 /* send an empty l1oip frame at D-channel */
826 l1oip_socket_send(hc, 0, hc->d_idx, 0, 0, NULL, 0);
827}
828
829
830/*
831 * timer stuff
832 */
833static void
834l1oip_keepalive(void *data)
835{
836 struct l1oip *hc = (struct l1oip *)data;
837
838 schedule_work(&hc->workq);
839}
840
841static void
842l1oip_timeout(void *data)
843{
844 struct l1oip *hc = (struct l1oip *)data;
845 struct dchannel *dch = hc->chan[hc->d_idx].dch;
846
847 if (debug & DEBUG_L1OIP_MSG)
848 printk(KERN_DEBUG "%s: timeout timer expired, turn layer one "
849 "down.\n", __func__);
850
851 hc->timeout_on = 0; /* state that timer must be initialized next time */
852
853 /* if timeout, we send up a PH_DEACTIVATE and deactivate */
854 if (test_bit(FLG_ACTIVE, &dch->Flags)) {
855 if (debug & (DEBUG_L1OIP_MSG|DEBUG_L1OIP_SOCKET))
856 printk(KERN_DEBUG "%s: interface become deactivated "
857 "due to timeout\n", __func__);
858 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
859 _queue_data(&dch->dev.D, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0,
860 NULL, GFP_ATOMIC);
861 }
862
863 /* if we have ondemand set, we remove ip address */
864 if (hc->ondemand) {
865 if (debug & DEBUG_L1OIP_MSG)
866 printk(KERN_DEBUG "%s: on demand causes ip address to "
867 "be removed\n", __func__);
868 hc->sin_remote.sin_addr.s_addr = 0;
869 }
870}
871
872
873/*
874 * message handling
875 */
876static int
877handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)
878{
879 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
880 struct dchannel *dch = container_of(dev, struct dchannel, dev);
881 struct l1oip *hc = dch->hw;
882 struct mISDNhead *hh = mISDN_HEAD_P(skb);
883 int ret = -EINVAL;
884 int l, ll;
885 unsigned char *p;
886
887 switch (hh->prim) {
888 case PH_DATA_REQ:
889 if (skb->len < 1) {
890 printk(KERN_WARNING "%s: skb too small\n",
891 __func__);
892 break;
893 }
894 if (skb->len > MAX_DFRAME_LEN_L1 || skb->len > L1OIP_MAX_LEN) {
895 printk(KERN_WARNING "%s: skb too large\n",
896 __func__);
897 break;
898 }
899 /* send frame */
900 p = skb->data;
901 l = skb->len;
902 while (l) {
903 ll = (l < L1OIP_MAX_PERFRAME)?l:L1OIP_MAX_PERFRAME;
904 l1oip_socket_send(hc, 0, dch->slot, 0,
905 hc->chan[dch->slot].tx_counter++, p, ll);
906 p += ll;
907 l -= ll;
908 }
909 skb_trim(skb, 0);
910 queue_ch_frame(ch, PH_DATA_CNF, hh->id, skb);
911 return 0;
912 case PH_ACTIVATE_REQ:
913 if (debug & (DEBUG_L1OIP_MSG|DEBUG_L1OIP_SOCKET))
914 printk(KERN_DEBUG "%s: PH_ACTIVATE channel %d (1..%d)\n"
915 , __func__, dch->slot, hc->b_num+1);
916 skb_trim(skb, 0);
917 if (test_bit(FLG_ACTIVE, &dch->Flags))
918 queue_ch_frame(ch, PH_ACTIVATE_IND, hh->id, skb);
919 else
920 queue_ch_frame(ch, PH_DEACTIVATE_IND, hh->id, skb);
921 return 0;
922 case PH_DEACTIVATE_REQ:
923 if (debug & (DEBUG_L1OIP_MSG|DEBUG_L1OIP_SOCKET))
924 printk(KERN_DEBUG "%s: PH_DEACTIVATE channel %d "
925 "(1..%d)\n", __func__, dch->slot,
926 hc->b_num+1);
927 skb_trim(skb, 0);
928 if (test_bit(FLG_ACTIVE, &dch->Flags))
929 queue_ch_frame(ch, PH_ACTIVATE_IND, hh->id, skb);
930 else
931 queue_ch_frame(ch, PH_DEACTIVATE_IND, hh->id, skb);
932 return 0;
933 }
934 if (!ret)
935 dev_kfree_skb(skb);
936 return ret;
937}
938
939static int
940channel_dctrl(struct dchannel *dch, struct mISDN_ctrl_req *cq)
941{
942 int ret = 0;
943 struct l1oip *hc = dch->hw;
944
945 switch (cq->op) {
946 case MISDN_CTRL_GETOP:
947 cq->op = MISDN_CTRL_SETPEER | MISDN_CTRL_UNSETPEER;
948 break;
949 case MISDN_CTRL_SETPEER:
950 hc->remoteip = (u32)cq->p1;
951 hc->remoteport = cq->p2 & 0xffff;
952 hc->localport = cq->p2 >> 16;
953 if (!hc->remoteport)
954 hc->remoteport = hc->localport;
955 if (debug & DEBUG_L1OIP_SOCKET)
956 printk(KERN_DEBUG "%s: got new ip address from user "
957 "space.\n", __func__);
958 l1oip_socket_open(hc);
959 break;
960 case MISDN_CTRL_UNSETPEER:
961 if (debug & DEBUG_L1OIP_SOCKET)
962 printk(KERN_DEBUG "%s: removing ip address.\n",
963 __func__);
964 hc->remoteip = 0;
965 l1oip_socket_open(hc);
966 break;
967 default:
968 printk(KERN_WARNING "%s: unknown Op %x\n",
969 __func__, cq->op);
970 ret = -EINVAL;
971 break;
972 }
973 return ret;
974}
975
976static int
977open_dchannel(struct l1oip *hc, struct dchannel *dch, struct channel_req *rq)
978{
979 if (debug & DEBUG_HW_OPEN)
980 printk(KERN_DEBUG "%s: dev(%d) open from %p\n", __func__,
981 dch->dev.id, __builtin_return_address(0));
982 if (rq->protocol == ISDN_P_NONE)
983 return -EINVAL;
984 if ((dch->dev.D.protocol != ISDN_P_NONE) &&
985 (dch->dev.D.protocol != rq->protocol)) {
986 if (debug & DEBUG_HW_OPEN)
987 printk(KERN_WARNING "%s: change protocol %x to %x\n",
988 __func__, dch->dev.D.protocol, rq->protocol);
989 }
990 if (dch->dev.D.protocol != rq->protocol)
991 dch->dev.D.protocol = rq->protocol;
992
993 if (test_bit(FLG_ACTIVE, &dch->Flags)) {
994 _queue_data(&dch->dev.D, PH_ACTIVATE_IND, MISDN_ID_ANY,
995 0, NULL, GFP_KERNEL);
996 }
997 rq->ch = &dch->dev.D;
998 if (!try_module_get(THIS_MODULE))
999 printk(KERN_WARNING "%s:cannot get module\n", __func__);
1000 return 0;
1001}
1002
1003static int
1004open_bchannel(struct l1oip *hc, struct dchannel *dch, struct channel_req *rq)
1005{
1006 struct bchannel *bch;
1007 int ch;
1008
1009 if (!test_bit(rq->adr.channel & 0x1f,
1010 &dch->dev.channelmap[rq->adr.channel >> 5]))
1011 return -EINVAL;
1012 if (rq->protocol == ISDN_P_NONE)
1013 return -EINVAL;
1014 ch = rq->adr.channel; /* BRI: 1=B1 2=B2 PRI: 1..15,17.. */
1015 bch = hc->chan[ch].bch;
1016 if (!bch) {
1017 printk(KERN_ERR "%s:internal error ch %d has no bch\n",
1018 __func__, ch);
1019 return -EINVAL;
1020 }
1021 if (test_and_set_bit(FLG_OPEN, &bch->Flags))
1022 return -EBUSY; /* b-channel can be only open once */
1023 bch->ch.protocol = rq->protocol;
1024 rq->ch = &bch->ch;
1025 if (!try_module_get(THIS_MODULE))
1026 printk(KERN_WARNING "%s:cannot get module\n", __func__);
1027 return 0;
1028}
1029
1030static int
1031l1oip_dctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
1032{
1033 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
1034 struct dchannel *dch = container_of(dev, struct dchannel, dev);
1035 struct l1oip *hc = dch->hw;
1036 struct channel_req *rq;
1037 int err = 0;
1038
1039 if (dch->debug & DEBUG_HW)
1040 printk(KERN_DEBUG "%s: cmd:%x %p\n",
1041 __func__, cmd, arg);
1042 switch (cmd) {
1043 case OPEN_CHANNEL:
1044 rq = arg;
1045 switch (rq->protocol) {
1046 case ISDN_P_TE_S0:
1047 case ISDN_P_NT_S0:
1048 if (hc->pri) {
1049 err = -EINVAL;
1050 break;
1051 }
1052 err = open_dchannel(hc, dch, rq);
1053 break;
1054 case ISDN_P_TE_E1:
1055 case ISDN_P_NT_E1:
1056 if (!hc->pri) {
1057 err = -EINVAL;
1058 break;
1059 }
1060 err = open_dchannel(hc, dch, rq);
1061 break;
1062 default:
1063 err = open_bchannel(hc, dch, rq);
1064 }
1065 break;
1066 case CLOSE_CHANNEL:
1067 if (debug & DEBUG_HW_OPEN)
1068 printk(KERN_DEBUG "%s: dev(%d) close from %p\n",
1069 __func__, dch->dev.id,
1070 __builtin_return_address(0));
1071 module_put(THIS_MODULE);
1072 break;
1073 case CONTROL_CHANNEL:
1074 err = channel_dctrl(dch, arg);
1075 break;
1076 default:
1077 if (dch->debug & DEBUG_HW)
1078 printk(KERN_DEBUG "%s: unknown command %x\n",
1079 __func__, cmd);
1080 err = -EINVAL;
1081 }
1082 return err;
1083}
1084
1085static int
1086handle_bmsg(struct mISDNchannel *ch, struct sk_buff *skb)
1087{
1088 struct bchannel *bch = container_of(ch, struct bchannel, ch);
1089 struct l1oip *hc = bch->hw;
1090 int ret = -EINVAL;
1091 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1092 int l, ll, i;
1093 unsigned char *p;
1094
1095 switch (hh->prim) {
1096 case PH_DATA_REQ:
1097 if (skb->len <= 0) {
1098 printk(KERN_WARNING "%s: skb too small\n",
1099 __func__);
1100 break;
1101 }
1102 if (skb->len > MAX_DFRAME_LEN_L1 || skb->len > L1OIP_MAX_LEN) {
1103 printk(KERN_WARNING "%s: skb too large\n",
1104 __func__);
1105 break;
1106 }
1107 /* check for AIS / ulaw-silence */
1108 p = skb->data;
1109 l = skb->len;
1110 for (i = 0; i < l; i++) {
1111 if (*p++ != 0xff)
1112 break;
1113 }
1114 if (i == l) {
1115 if (debug & DEBUG_L1OIP_MSG)
1116 printk(KERN_DEBUG "%s: got AIS, not sending, "
1117 "but counting\n", __func__);
1118 hc->chan[bch->slot].tx_counter += l;
1119 skb_trim(skb, 0);
1120 queue_ch_frame(ch, PH_DATA_CNF, hh->id, skb);
1121 return 0;
1122 }
1123 /* check for silence */
1124 p = skb->data;
1125 l = skb->len;
1126 for (i = 0; i < l; i++) {
1127 if (*p++ != 0x2a)
1128 break;
1129 }
1130 if (i == l) {
1131 if (debug & DEBUG_L1OIP_MSG)
1132 printk(KERN_DEBUG "%s: got silence, not sending"
1133 ", but counting\n", __func__);
1134 hc->chan[bch->slot].tx_counter += l;
1135 skb_trim(skb, 0);
1136 queue_ch_frame(ch, PH_DATA_CNF, hh->id, skb);
1137 return 0;
1138 }
1139
1140 /* send frame */
1141 p = skb->data;
1142 l = skb->len;
1143 while (l) {
1144 ll = (l < L1OIP_MAX_PERFRAME)?l:L1OIP_MAX_PERFRAME;
1145 l1oip_socket_send(hc, hc->codec, bch->slot, 0,
1146 hc->chan[bch->slot].tx_counter, p, ll);
1147 hc->chan[bch->slot].tx_counter += ll;
1148 p += ll;
1149 l -= ll;
1150 }
1151 skb_trim(skb, 0);
1152 queue_ch_frame(ch, PH_DATA_CNF, hh->id, skb);
1153 return 0;
1154 case PH_ACTIVATE_REQ:
1155 if (debug & (DEBUG_L1OIP_MSG|DEBUG_L1OIP_SOCKET))
1156 printk(KERN_DEBUG "%s: PH_ACTIVATE channel %d (1..%d)\n"
1157 , __func__, bch->slot, hc->b_num+1);
1158 hc->chan[bch->slot].codecstate = 0;
1159 test_and_set_bit(FLG_ACTIVE, &bch->Flags);
1160 skb_trim(skb, 0);
1161 queue_ch_frame(ch, PH_ACTIVATE_IND, hh->id, skb);
1162 return 0;
1163 case PH_DEACTIVATE_REQ:
1164 if (debug & (DEBUG_L1OIP_MSG|DEBUG_L1OIP_SOCKET))
1165 printk(KERN_DEBUG "%s: PH_DEACTIVATE channel %d "
1166 "(1..%d)\n", __func__, bch->slot,
1167 hc->b_num+1);
1168 test_and_clear_bit(FLG_ACTIVE, &bch->Flags);
1169 skb_trim(skb, 0);
1170 queue_ch_frame(ch, PH_DEACTIVATE_IND, hh->id, skb);
1171 return 0;
1172 }
1173 if (!ret)
1174 dev_kfree_skb(skb);
1175 return ret;
1176}
1177
1178static int
1179channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
1180{
1181 int ret = 0;
1182 struct dsp_features *features =
1183 (struct dsp_features *)(*((u_long *)&cq->p1));
1184
1185 switch (cq->op) {
1186 case MISDN_CTRL_GETOP:
1187 cq->op = MISDN_CTRL_HW_FEATURES_OP;
1188 break;
1189 case MISDN_CTRL_HW_FEATURES: /* fill features structure */
1190 if (debug & DEBUG_L1OIP_MSG)
1191 printk(KERN_DEBUG "%s: HW_FEATURE request\n",
1192 __func__);
1193 /* create confirm */
1194 features->unclocked = 1;
1195 features->unordered = 1;
1196 break;
1197 default:
1198 printk(KERN_WARNING "%s: unknown Op %x\n",
1199 __func__, cq->op);
1200 ret = -EINVAL;
1201 break;
1202 }
1203 return ret;
1204}
1205
1206static int
1207l1oip_bctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
1208{
1209 struct bchannel *bch = container_of(ch, struct bchannel, ch);
1210 int err = -EINVAL;
1211
1212 if (bch->debug & DEBUG_HW)
1213 printk(KERN_DEBUG "%s: cmd:%x %p\n",
1214 __func__, cmd, arg);
1215 switch (cmd) {
1216 case CLOSE_CHANNEL:
1217 test_and_clear_bit(FLG_OPEN, &bch->Flags);
1218 test_and_clear_bit(FLG_ACTIVE, &bch->Flags);
1219 ch->protocol = ISDN_P_NONE;
1220 ch->peer = NULL;
1221 module_put(THIS_MODULE);
1222 err = 0;
1223 break;
1224 case CONTROL_CHANNEL:
1225 err = channel_bctrl(bch, arg);
1226 break;
1227 default:
1228 printk(KERN_WARNING "%s: unknown prim(%x)\n",
1229 __func__, cmd);
1230 }
1231 return err;
1232}
1233
1234
1235/*
1236 * cleanup module and stack
1237 */
1238static void
1239release_card(struct l1oip *hc)
1240{
1241 int ch;
1242
1243 if (timer_pending(&hc->keep_tl))
1244 del_timer(&hc->keep_tl);
1245
1246 if (timer_pending(&hc->timeout_tl))
1247 del_timer(&hc->timeout_tl);
1248
1249 if (hc->socket_thread)
1250 l1oip_socket_close(hc);
1251
1252 if (hc->registered && hc->chan[hc->d_idx].dch)
1253 mISDN_unregister_device(&hc->chan[hc->d_idx].dch->dev);
1254 for (ch = 0; ch < 128; ch++) {
1255 if (hc->chan[ch].dch) {
1256 mISDN_freedchannel(hc->chan[ch].dch);
1257 kfree(hc->chan[ch].dch);
1258 }
1259 if (hc->chan[ch].bch) {
1260 mISDN_freebchannel(hc->chan[ch].bch);
1261 kfree(hc->chan[ch].bch);
1262#ifdef REORDER_DEBUG
1263 if (hc->chan[ch].disorder_skb)
1264 dev_kfree_skb(hc->chan[ch].disorder_skb);
1265#endif
1266 }
1267 }
1268
1269 spin_lock(&l1oip_lock);
1270 list_del(&hc->list);
1271 spin_unlock(&l1oip_lock);
1272
1273 kfree(hc);
1274}
1275
1276static void
1277l1oip_cleanup(void)
1278{
1279 struct l1oip *hc, *next;
1280
1281 list_for_each_entry_safe(hc, next, &l1oip_ilist, list)
1282 release_card(hc);
1283
1284 l1oip_4bit_free();
1285}
1286
1287
1288/*
1289 * module and stack init
1290 */
1291static int
1292init_card(struct l1oip *hc, int pri, int bundle)
1293{
1294 struct dchannel *dch;
1295 struct bchannel *bch;
1296 int ret;
1297 int i, ch;
1298
1299 spin_lock_init(&hc->socket_lock);
1300 hc->idx = l1oip_cnt;
1301 hc->pri = pri;
1302 hc->d_idx = pri?16:3;
1303 hc->b_num = pri?30:2;
1304 hc->bundle = bundle;
1305 if (hc->pri)
1306 sprintf(hc->name, "l1oip-e1.%d", l1oip_cnt + 1);
1307 else
1308 sprintf(hc->name, "l1oip-s0.%d", l1oip_cnt + 1);
1309
1310 switch (codec[l1oip_cnt]) {
1311 case 0: /* as is */
1312 case 1: /* alaw */
1313 case 2: /* ulaw */
1314 case 3: /* 4bit */
1315 break;
1316 default:
1317 printk(KERN_ERR "Codec(%d) not supported.\n",
1318 codec[l1oip_cnt]);
1319 return -EINVAL;
1320 }
1321 hc->codec = codec[l1oip_cnt];
1322 if (debug & DEBUG_L1OIP_INIT)
1323 printk(KERN_DEBUG "%s: using codec %d\n",
1324 __func__, hc->codec);
1325
1326 if (id[l1oip_cnt] == 0) {
1327 printk(KERN_WARNING "Warning: No 'id' value given or "
1328 "0, this is highly unsecure. Please use 32 "
1329 "bit randmom number 0x...\n");
1330 }
1331 hc->id = id[l1oip_cnt];
1332 if (debug & DEBUG_L1OIP_INIT)
1333 printk(KERN_DEBUG "%s: using id 0x%x\n", __func__, hc->id);
1334
1335 hc->ondemand = ondemand[l1oip_cnt];
1336 if (hc->ondemand && !hc->id) {
1337 printk(KERN_ERR "%s: ondemand option only allowed in "
1338 "conjunction with non 0 ID\n", __func__);
1339 return -EINVAL;
1340 }
1341
1342 if (limit[l1oip_cnt])
1343 hc->b_num = limit[l1oip_cnt];
1344 if (!pri && hc->b_num > 2) {
1345 printk(KERN_ERR "Maximum limit for BRI interface is 2 "
1346 "channels.\n");
1347 return -EINVAL;
1348 }
1349 if (pri && hc->b_num > 126) {
1350 printk(KERN_ERR "Maximum limit for PRI interface is 126 "
1351 "channels.\n");
1352 return -EINVAL;
1353 }
1354 if (pri && hc->b_num > 30) {
1355 printk(KERN_WARNING "Maximum limit for BRI interface is 30 "
1356 "channels.\n");
1357 printk(KERN_WARNING "Your selection of %d channels must be "
1358 "supported by application.\n", hc->limit);
1359 }
1360
1361 hc->remoteip = ip[l1oip_cnt<<2] << 24
1362 | ip[(l1oip_cnt<<2)+1] << 16
1363 | ip[(l1oip_cnt<<2)+2] << 8
1364 | ip[(l1oip_cnt<<2)+3];
1365 hc->localport = port[l1oip_cnt]?:(L1OIP_DEFAULTPORT+l1oip_cnt);
1366 if (remoteport[l1oip_cnt])
1367 hc->remoteport = remoteport[l1oip_cnt];
1368 else
1369 hc->remoteport = hc->localport;
1370 if (debug & DEBUG_L1OIP_INIT)
1371 printk(KERN_DEBUG "%s: using local port %d remote ip "
1372 "%d.%d.%d.%d port %d ondemand %d\n", __func__,
1373 hc->localport, hc->remoteip >> 24,
1374 (hc->remoteip >> 16) & 0xff,
1375 (hc->remoteip >> 8) & 0xff, hc->remoteip & 0xff,
1376 hc->remoteport, hc->ondemand);
1377
1378 dch = kzalloc(sizeof(struct dchannel), GFP_KERNEL);
1379 if (!dch)
1380 return -ENOMEM;
1381 dch->debug = debug;
1382 mISDN_initdchannel(dch, MAX_DFRAME_LEN_L1, NULL);
1383 dch->hw = hc;
1384 if (pri)
1385 dch->dev.Dprotocols = (1 << ISDN_P_TE_E1) | (1 << ISDN_P_NT_E1);
1386 else
1387 dch->dev.Dprotocols = (1 << ISDN_P_TE_S0) | (1 << ISDN_P_NT_S0);
1388 dch->dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
1389 (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
1390 dch->dev.D.send = handle_dmsg;
1391 dch->dev.D.ctrl = l1oip_dctrl;
1392 dch->dev.nrbchan = hc->b_num;
1393 dch->slot = hc->d_idx;
1394 hc->chan[hc->d_idx].dch = dch;
1395 i = 1;
1396 for (ch = 0; ch < dch->dev.nrbchan; ch++) {
1397 if (ch == 15)
1398 i++;
1399 bch = kzalloc(sizeof(struct bchannel), GFP_KERNEL);
1400 if (!bch) {
1401 printk(KERN_ERR "%s: no memory for bchannel\n",
1402 __func__);
1403 return -ENOMEM;
1404 }
1405 bch->nr = i + ch;
1406 bch->slot = i + ch;
1407 bch->debug = debug;
1408 mISDN_initbchannel(bch, MAX_DATA_MEM);
1409 bch->hw = hc;
1410 bch->ch.send = handle_bmsg;
1411 bch->ch.ctrl = l1oip_bctrl;
1412 bch->ch.nr = i + ch;
1413 list_add(&bch->ch.list, &dch->dev.bchannels);
1414 hc->chan[i + ch].bch = bch;
1415 test_and_set_bit(bch->nr & 0x1f,
1416 &dch->dev.channelmap[bch->nr >> 5]);
1417 }
1418 ret = mISDN_register_device(&dch->dev, hc->name);
1419 if (ret)
1420 return ret;
1421 hc->registered = 1;
1422
1423 if (debug & DEBUG_L1OIP_INIT)
1424 printk(KERN_DEBUG "%s: Setting up network card(%d)\n",
1425 __func__, l1oip_cnt + 1);
1426 ret = l1oip_socket_open(hc);
1427 if (ret)
1428 return ret;
1429
1430 hc->keep_tl.function = (void *)l1oip_keepalive;
1431 hc->keep_tl.data = (ulong)hc;
1432 init_timer(&hc->keep_tl);
1433 hc->keep_tl.expires = jiffies + 2*HZ; /* two seconds first time */
1434 add_timer(&hc->keep_tl);
1435
1436 hc->timeout_tl.function = (void *)l1oip_timeout;
1437 hc->timeout_tl.data = (ulong)hc;
1438 init_timer(&hc->timeout_tl);
1439 hc->timeout_on = 0; /* state that we have timer off */
1440
1441 return 0;
1442}
1443
1444static int __init
1445l1oip_init(void)
1446{
1447 int pri, bundle;
1448 struct l1oip *hc;
1449 int ret;
1450
1451 printk(KERN_INFO "mISDN: Layer-1-over-IP driver Rev. %s\n",
1452 l1oip_revision);
1453
1454 INIT_LIST_HEAD(&l1oip_ilist);
1455 spin_lock_init(&l1oip_lock);
1456
1457 if (l1oip_4bit_alloc(ulaw))
1458 return -ENOMEM;
1459
1460 l1oip_cnt = 0;
1461 while (type[l1oip_cnt] && l1oip_cnt < MAX_CARDS) {
1462 switch (type[l1oip_cnt] & 0xff) {
1463 case 1:
1464 pri = 0;
1465 bundle = 0;
1466 break;
1467 case 2:
1468 pri = 1;
1469 bundle = 0;
1470 break;
1471 case 3:
1472 pri = 0;
1473 bundle = 1;
1474 break;
1475 case 4:
1476 pri = 1;
1477 bundle = 1;
1478 break;
1479 default:
1480 printk(KERN_ERR "Card type(%d) not supported.\n",
1481 type[l1oip_cnt] & 0xff);
1482 l1oip_cleanup();
1483 return -EINVAL;
1484 }
1485
1486 if (debug & DEBUG_L1OIP_INIT)
1487 printk(KERN_DEBUG "%s: interface %d is %s with %s.\n",
1488 __func__, l1oip_cnt, pri?"PRI":"BRI",
1489 bundle?"bundled IP packet for all B-channels"
1490 :"seperate IP packets for every B-channel");
1491
1492 hc = kzalloc(sizeof(struct l1oip), GFP_ATOMIC);
1493 if (!hc) {
1494 printk(KERN_ERR "No kmem for L1-over-IP driver.\n");
1495 l1oip_cleanup();
1496 return -ENOMEM;
1497 }
1498 INIT_WORK(&hc->workq, (void *)l1oip_send_bh);
1499
1500 spin_lock(&l1oip_lock);
1501 list_add_tail(&hc->list, &l1oip_ilist);
1502 spin_unlock(&l1oip_lock);
1503
1504 ret = init_card(hc, pri, bundle);
1505 if (ret) {
1506 l1oip_cleanup();
1507 return ret;
1508 }
1509
1510 l1oip_cnt++;
1511 }
1512 printk(KERN_INFO "%d virtual devices registered\n", l1oip_cnt);
1513 return 0;
1514}
1515
1516module_init(l1oip_init);
1517module_exit(l1oip_cleanup);
1518
diff --git a/drivers/isdn/mISDN/layer1.c b/drivers/isdn/mISDN/layer1.c
new file mode 100644
index 000000000000..fced1a2755f8
--- /dev/null
+++ b/drivers/isdn/mISDN/layer1.c
@@ -0,0 +1,403 @@
1/*
2 *
3 * Author Karsten Keil <kkeil@novell.com>
4 *
5 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18
19#include <linux/module.h>
20#include <linux/mISDNhw.h>
21#include "layer1.h"
22#include "fsm.h"
23
24static int *debug;
25
26struct layer1 {
27 u_long Flags;
28 struct FsmInst l1m;
29 struct FsmTimer timer;
30 int delay;
31 struct dchannel *dch;
32 dchannel_l1callback *dcb;
33};
34
35#define TIMER3_VALUE 7000
36
37static
38struct Fsm l1fsm_s = {NULL, 0, 0, NULL, NULL};
39
40enum {
41 ST_L1_F2,
42 ST_L1_F3,
43 ST_L1_F4,
44 ST_L1_F5,
45 ST_L1_F6,
46 ST_L1_F7,
47 ST_L1_F8,
48};
49
50#define L1S_STATE_COUNT (ST_L1_F8+1)
51
52static char *strL1SState[] =
53{
54 "ST_L1_F2",
55 "ST_L1_F3",
56 "ST_L1_F4",
57 "ST_L1_F5",
58 "ST_L1_F6",
59 "ST_L1_F7",
60 "ST_L1_F8",
61};
62
63enum {
64 EV_PH_ACTIVATE,
65 EV_PH_DEACTIVATE,
66 EV_RESET_IND,
67 EV_DEACT_CNF,
68 EV_DEACT_IND,
69 EV_POWER_UP,
70 EV_ANYSIG_IND,
71 EV_INFO2_IND,
72 EV_INFO4_IND,
73 EV_TIMER_DEACT,
74 EV_TIMER_ACT,
75 EV_TIMER3,
76};
77
78#define L1_EVENT_COUNT (EV_TIMER3 + 1)
79
80static char *strL1Event[] =
81{
82 "EV_PH_ACTIVATE",
83 "EV_PH_DEACTIVATE",
84 "EV_RESET_IND",
85 "EV_DEACT_CNF",
86 "EV_DEACT_IND",
87 "EV_POWER_UP",
88 "EV_ANYSIG_IND",
89 "EV_INFO2_IND",
90 "EV_INFO4_IND",
91 "EV_TIMER_DEACT",
92 "EV_TIMER_ACT",
93 "EV_TIMER3",
94};
95
96static void
97l1m_debug(struct FsmInst *fi, char *fmt, ...)
98{
99 struct layer1 *l1 = fi->userdata;
100 va_list va;
101
102 va_start(va, fmt);
103 printk(KERN_DEBUG "%s: ", l1->dch->dev.name);
104 vprintk(fmt, va);
105 printk("\n");
106 va_end(va);
107}
108
109static void
110l1_reset(struct FsmInst *fi, int event, void *arg)
111{
112 mISDN_FsmChangeState(fi, ST_L1_F3);
113}
114
115static void
116l1_deact_cnf(struct FsmInst *fi, int event, void *arg)
117{
118 struct layer1 *l1 = fi->userdata;
119
120 mISDN_FsmChangeState(fi, ST_L1_F3);
121 if (test_bit(FLG_L1_ACTIVATING, &l1->Flags))
122 l1->dcb(l1->dch, HW_POWERUP_REQ);
123}
124
125static void
126l1_deact_req_s(struct FsmInst *fi, int event, void *arg)
127{
128 struct layer1 *l1 = fi->userdata;
129
130 mISDN_FsmChangeState(fi, ST_L1_F3);
131 mISDN_FsmRestartTimer(&l1->timer, 550, EV_TIMER_DEACT, NULL, 2);
132 test_and_set_bit(FLG_L1_DEACTTIMER, &l1->Flags);
133}
134
135static void
136l1_power_up_s(struct FsmInst *fi, int event, void *arg)
137{
138 struct layer1 *l1 = fi->userdata;
139
140 if (test_bit(FLG_L1_ACTIVATING, &l1->Flags)) {
141 mISDN_FsmChangeState(fi, ST_L1_F4);
142 l1->dcb(l1->dch, INFO3_P8);
143 } else
144 mISDN_FsmChangeState(fi, ST_L1_F3);
145}
146
147static void
148l1_go_F5(struct FsmInst *fi, int event, void *arg)
149{
150 mISDN_FsmChangeState(fi, ST_L1_F5);
151}
152
153static void
154l1_go_F8(struct FsmInst *fi, int event, void *arg)
155{
156 mISDN_FsmChangeState(fi, ST_L1_F8);
157}
158
159static void
160l1_info2_ind(struct FsmInst *fi, int event, void *arg)
161{
162 struct layer1 *l1 = fi->userdata;
163
164 mISDN_FsmChangeState(fi, ST_L1_F6);
165 l1->dcb(l1->dch, INFO3_P8);
166}
167
168static void
169l1_info4_ind(struct FsmInst *fi, int event, void *arg)
170{
171 struct layer1 *l1 = fi->userdata;
172
173 mISDN_FsmChangeState(fi, ST_L1_F7);
174 l1->dcb(l1->dch, INFO3_P8);
175 if (test_and_clear_bit(FLG_L1_DEACTTIMER, &l1->Flags))
176 mISDN_FsmDelTimer(&l1->timer, 4);
177 if (!test_bit(FLG_L1_ACTIVATED, &l1->Flags)) {
178 if (test_and_clear_bit(FLG_L1_T3RUN, &l1->Flags))
179 mISDN_FsmDelTimer(&l1->timer, 3);
180 mISDN_FsmRestartTimer(&l1->timer, 110, EV_TIMER_ACT, NULL, 2);
181 test_and_set_bit(FLG_L1_ACTTIMER, &l1->Flags);
182 }
183}
184
185static void
186l1_timer3(struct FsmInst *fi, int event, void *arg)
187{
188 struct layer1 *l1 = fi->userdata;
189
190 test_and_clear_bit(FLG_L1_T3RUN, &l1->Flags);
191 if (test_and_clear_bit(FLG_L1_ACTIVATING, &l1->Flags)) {
192 if (test_and_clear_bit(FLG_L1_DBLOCKED, &l1->Flags))
193 l1->dcb(l1->dch, HW_D_NOBLOCKED);
194 l1->dcb(l1->dch, PH_DEACTIVATE_IND);
195 }
196 if (l1->l1m.state != ST_L1_F6) {
197 mISDN_FsmChangeState(fi, ST_L1_F3);
198 l1->dcb(l1->dch, HW_POWERUP_REQ);
199 }
200}
201
202static void
203l1_timer_act(struct FsmInst *fi, int event, void *arg)
204{
205 struct layer1 *l1 = fi->userdata;
206
207 test_and_clear_bit(FLG_L1_ACTTIMER, &l1->Flags);
208 test_and_set_bit(FLG_L1_ACTIVATED, &l1->Flags);
209 l1->dcb(l1->dch, PH_ACTIVATE_IND);
210}
211
212static void
213l1_timer_deact(struct FsmInst *fi, int event, void *arg)
214{
215 struct layer1 *l1 = fi->userdata;
216
217 test_and_clear_bit(FLG_L1_DEACTTIMER, &l1->Flags);
218 test_and_clear_bit(FLG_L1_ACTIVATED, &l1->Flags);
219 if (test_and_clear_bit(FLG_L1_DBLOCKED, &l1->Flags))
220 l1->dcb(l1->dch, HW_D_NOBLOCKED);
221 l1->dcb(l1->dch, PH_DEACTIVATE_IND);
222 l1->dcb(l1->dch, HW_DEACT_REQ);
223}
224
225static void
226l1_activate_s(struct FsmInst *fi, int event, void *arg)
227{
228 struct layer1 *l1 = fi->userdata;
229
230 mISDN_FsmRestartTimer(&l1->timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
231 test_and_set_bit(FLG_L1_T3RUN, &l1->Flags);
232 l1->dcb(l1->dch, HW_RESET_REQ);
233}
234
235static void
236l1_activate_no(struct FsmInst *fi, int event, void *arg)
237{
238 struct layer1 *l1 = fi->userdata;
239
240 if ((!test_bit(FLG_L1_DEACTTIMER, &l1->Flags)) &&
241 (!test_bit(FLG_L1_T3RUN, &l1->Flags))) {
242 test_and_clear_bit(FLG_L1_ACTIVATING, &l1->Flags);
243 if (test_and_clear_bit(FLG_L1_DBLOCKED, &l1->Flags))
244 l1->dcb(l1->dch, HW_D_NOBLOCKED);
245 l1->dcb(l1->dch, PH_DEACTIVATE_IND);
246 }
247}
248
249static struct FsmNode L1SFnList[] =
250{
251 {ST_L1_F3, EV_PH_ACTIVATE, l1_activate_s},
252 {ST_L1_F6, EV_PH_ACTIVATE, l1_activate_no},
253 {ST_L1_F8, EV_PH_ACTIVATE, l1_activate_no},
254 {ST_L1_F3, EV_RESET_IND, l1_reset},
255 {ST_L1_F4, EV_RESET_IND, l1_reset},
256 {ST_L1_F5, EV_RESET_IND, l1_reset},
257 {ST_L1_F6, EV_RESET_IND, l1_reset},
258 {ST_L1_F7, EV_RESET_IND, l1_reset},
259 {ST_L1_F8, EV_RESET_IND, l1_reset},
260 {ST_L1_F3, EV_DEACT_CNF, l1_deact_cnf},
261 {ST_L1_F4, EV_DEACT_CNF, l1_deact_cnf},
262 {ST_L1_F5, EV_DEACT_CNF, l1_deact_cnf},
263 {ST_L1_F6, EV_DEACT_CNF, l1_deact_cnf},
264 {ST_L1_F7, EV_DEACT_CNF, l1_deact_cnf},
265 {ST_L1_F8, EV_DEACT_CNF, l1_deact_cnf},
266 {ST_L1_F6, EV_DEACT_IND, l1_deact_req_s},
267 {ST_L1_F7, EV_DEACT_IND, l1_deact_req_s},
268 {ST_L1_F8, EV_DEACT_IND, l1_deact_req_s},
269 {ST_L1_F3, EV_POWER_UP, l1_power_up_s},
270 {ST_L1_F4, EV_ANYSIG_IND, l1_go_F5},
271 {ST_L1_F6, EV_ANYSIG_IND, l1_go_F8},
272 {ST_L1_F7, EV_ANYSIG_IND, l1_go_F8},
273 {ST_L1_F3, EV_INFO2_IND, l1_info2_ind},
274 {ST_L1_F4, EV_INFO2_IND, l1_info2_ind},
275 {ST_L1_F5, EV_INFO2_IND, l1_info2_ind},
276 {ST_L1_F7, EV_INFO2_IND, l1_info2_ind},
277 {ST_L1_F8, EV_INFO2_IND, l1_info2_ind},
278 {ST_L1_F3, EV_INFO4_IND, l1_info4_ind},
279 {ST_L1_F4, EV_INFO4_IND, l1_info4_ind},
280 {ST_L1_F5, EV_INFO4_IND, l1_info4_ind},
281 {ST_L1_F6, EV_INFO4_IND, l1_info4_ind},
282 {ST_L1_F8, EV_INFO4_IND, l1_info4_ind},
283 {ST_L1_F3, EV_TIMER3, l1_timer3},
284 {ST_L1_F4, EV_TIMER3, l1_timer3},
285 {ST_L1_F5, EV_TIMER3, l1_timer3},
286 {ST_L1_F6, EV_TIMER3, l1_timer3},
287 {ST_L1_F8, EV_TIMER3, l1_timer3},
288 {ST_L1_F7, EV_TIMER_ACT, l1_timer_act},
289 {ST_L1_F3, EV_TIMER_DEACT, l1_timer_deact},
290 {ST_L1_F4, EV_TIMER_DEACT, l1_timer_deact},
291 {ST_L1_F5, EV_TIMER_DEACT, l1_timer_deact},
292 {ST_L1_F6, EV_TIMER_DEACT, l1_timer_deact},
293 {ST_L1_F7, EV_TIMER_DEACT, l1_timer_deact},
294 {ST_L1_F8, EV_TIMER_DEACT, l1_timer_deact},
295};
296
297static void
298release_l1(struct layer1 *l1) {
299 mISDN_FsmDelTimer(&l1->timer, 0);
300 if (l1->dch)
301 l1->dch->l1 = NULL;
302 module_put(THIS_MODULE);
303 kfree(l1);
304}
305
306int
307l1_event(struct layer1 *l1, u_int event)
308{
309 int err = 0;
310
311 if (!l1)
312 return -EINVAL;
313 switch (event) {
314 case HW_RESET_IND:
315 mISDN_FsmEvent(&l1->l1m, EV_RESET_IND, NULL);
316 break;
317 case HW_DEACT_IND:
318 mISDN_FsmEvent(&l1->l1m, EV_DEACT_IND, NULL);
319 break;
320 case HW_POWERUP_IND:
321 mISDN_FsmEvent(&l1->l1m, EV_POWER_UP, NULL);
322 break;
323 case HW_DEACT_CNF:
324 mISDN_FsmEvent(&l1->l1m, EV_DEACT_CNF, NULL);
325 break;
326 case ANYSIGNAL:
327 mISDN_FsmEvent(&l1->l1m, EV_ANYSIG_IND, NULL);
328 break;
329 case LOSTFRAMING:
330 mISDN_FsmEvent(&l1->l1m, EV_ANYSIG_IND, NULL);
331 break;
332 case INFO2:
333 mISDN_FsmEvent(&l1->l1m, EV_INFO2_IND, NULL);
334 break;
335 case INFO4_P8:
336 mISDN_FsmEvent(&l1->l1m, EV_INFO4_IND, NULL);
337 break;
338 case INFO4_P10:
339 mISDN_FsmEvent(&l1->l1m, EV_INFO4_IND, NULL);
340 break;
341 case PH_ACTIVATE_REQ:
342 if (test_bit(FLG_L1_ACTIVATED, &l1->Flags))
343 l1->dcb(l1->dch, PH_ACTIVATE_IND);
344 else {
345 test_and_set_bit(FLG_L1_ACTIVATING, &l1->Flags);
346 mISDN_FsmEvent(&l1->l1m, EV_PH_ACTIVATE, NULL);
347 }
348 break;
349 case CLOSE_CHANNEL:
350 release_l1(l1);
351 break;
352 default:
353 if (*debug & DEBUG_L1)
354 printk(KERN_DEBUG "%s %x unhandled\n",
355 __func__, event);
356 err = -EINVAL;
357 }
358 return err;
359}
360EXPORT_SYMBOL(l1_event);
361
362int
363create_l1(struct dchannel *dch, dchannel_l1callback *dcb) {
364 struct layer1 *nl1;
365
366 nl1 = kzalloc(sizeof(struct layer1), GFP_ATOMIC);
367 if (!nl1) {
368 printk(KERN_ERR "kmalloc struct layer1 failed\n");
369 return -ENOMEM;
370 }
371 nl1->l1m.fsm = &l1fsm_s;
372 nl1->l1m.state = ST_L1_F3;
373 nl1->Flags = 0;
374 nl1->l1m.debug = *debug & DEBUG_L1_FSM;
375 nl1->l1m.userdata = nl1;
376 nl1->l1m.userint = 0;
377 nl1->l1m.printdebug = l1m_debug;
378 nl1->dch = dch;
379 nl1->dcb = dcb;
380 mISDN_FsmInitTimer(&nl1->l1m, &nl1->timer);
381 __module_get(THIS_MODULE);
382 dch->l1 = nl1;
383 return 0;
384}
385EXPORT_SYMBOL(create_l1);
386
387int
388l1_init(u_int *deb)
389{
390 debug = deb;
391 l1fsm_s.state_count = L1S_STATE_COUNT;
392 l1fsm_s.event_count = L1_EVENT_COUNT;
393 l1fsm_s.strEvent = strL1Event;
394 l1fsm_s.strState = strL1SState;
395 mISDN_FsmNew(&l1fsm_s, L1SFnList, ARRAY_SIZE(L1SFnList));
396 return 0;
397}
398
399void
400l1_cleanup(void)
401{
402 mISDN_FsmFree(&l1fsm_s);
403}
diff --git a/drivers/isdn/mISDN/layer1.h b/drivers/isdn/mISDN/layer1.h
new file mode 100644
index 000000000000..9c8125fd89af
--- /dev/null
+++ b/drivers/isdn/mISDN/layer1.h
@@ -0,0 +1,26 @@
1/*
2 *
3 * Layer 1 defines
4 *
5 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#define FLG_L1_ACTIVATING 1
19#define FLG_L1_ACTIVATED 2
20#define FLG_L1_DEACTTIMER 3
21#define FLG_L1_ACTTIMER 4
22#define FLG_L1_T3RUN 5
23#define FLG_L1_PULL_REQ 6
24#define FLG_L1_UINT 7
25#define FLG_L1_DBLOCKED 8
26
diff --git a/drivers/isdn/mISDN/layer2.c b/drivers/isdn/mISDN/layer2.c
new file mode 100644
index 000000000000..f5ad888ee71e
--- /dev/null
+++ b/drivers/isdn/mISDN/layer2.c
@@ -0,0 +1,2216 @@
1/*
2 *
3 * Author Karsten Keil <kkeil@novell.com>
4 *
5 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#include "fsm.h"
19#include "layer2.h"
20
21static int *debug;
22
23static
24struct Fsm l2fsm = {NULL, 0, 0, NULL, NULL};
25
26static char *strL2State[] =
27{
28 "ST_L2_1",
29 "ST_L2_2",
30 "ST_L2_3",
31 "ST_L2_4",
32 "ST_L2_5",
33 "ST_L2_6",
34 "ST_L2_7",
35 "ST_L2_8",
36};
37
38enum {
39 EV_L2_UI,
40 EV_L2_SABME,
41 EV_L2_DISC,
42 EV_L2_DM,
43 EV_L2_UA,
44 EV_L2_FRMR,
45 EV_L2_SUPER,
46 EV_L2_I,
47 EV_L2_DL_DATA,
48 EV_L2_ACK_PULL,
49 EV_L2_DL_UNITDATA,
50 EV_L2_DL_ESTABLISH_REQ,
51 EV_L2_DL_RELEASE_REQ,
52 EV_L2_MDL_ASSIGN,
53 EV_L2_MDL_REMOVE,
54 EV_L2_MDL_ERROR,
55 EV_L1_DEACTIVATE,
56 EV_L2_T200,
57 EV_L2_T203,
58 EV_L2_SET_OWN_BUSY,
59 EV_L2_CLEAR_OWN_BUSY,
60 EV_L2_FRAME_ERROR,
61};
62
63#define L2_EVENT_COUNT (EV_L2_FRAME_ERROR+1)
64
65static char *strL2Event[] =
66{
67 "EV_L2_UI",
68 "EV_L2_SABME",
69 "EV_L2_DISC",
70 "EV_L2_DM",
71 "EV_L2_UA",
72 "EV_L2_FRMR",
73 "EV_L2_SUPER",
74 "EV_L2_I",
75 "EV_L2_DL_DATA",
76 "EV_L2_ACK_PULL",
77 "EV_L2_DL_UNITDATA",
78 "EV_L2_DL_ESTABLISH_REQ",
79 "EV_L2_DL_RELEASE_REQ",
80 "EV_L2_MDL_ASSIGN",
81 "EV_L2_MDL_REMOVE",
82 "EV_L2_MDL_ERROR",
83 "EV_L1_DEACTIVATE",
84 "EV_L2_T200",
85 "EV_L2_T203",
86 "EV_L2_SET_OWN_BUSY",
87 "EV_L2_CLEAR_OWN_BUSY",
88 "EV_L2_FRAME_ERROR",
89};
90
91static void
92l2m_debug(struct FsmInst *fi, char *fmt, ...)
93{
94 struct layer2 *l2 = fi->userdata;
95 va_list va;
96
97 if (!(*debug & DEBUG_L2_FSM))
98 return;
99 va_start(va, fmt);
100 printk(KERN_DEBUG "l2 (tei %d): ", l2->tei);
101 vprintk(fmt, va);
102 printk("\n");
103 va_end(va);
104}
105
106inline u_int
107l2headersize(struct layer2 *l2, int ui)
108{
109 return ((test_bit(FLG_MOD128, &l2->flag) && (!ui)) ? 2 : 1) +
110 (test_bit(FLG_LAPD, &l2->flag) ? 2 : 1);
111}
112
113inline u_int
114l2addrsize(struct layer2 *l2)
115{
116 return test_bit(FLG_LAPD, &l2->flag) ? 2 : 1;
117}
118
119static u_int
120l2_newid(struct layer2 *l2)
121{
122 u_int id;
123
124 id = l2->next_id++;
125 if (id == 0x7fff)
126 l2->next_id = 1;
127 id <<= 16;
128 id |= l2->tei << 8;
129 id |= l2->sapi;
130 return id;
131}
132
133static void
134l2up(struct layer2 *l2, u_int prim, struct sk_buff *skb)
135{
136 int err;
137
138 if (!l2->up)
139 return;
140 mISDN_HEAD_PRIM(skb) = prim;
141 mISDN_HEAD_ID(skb) = (l2->ch.nr << 16) | l2->ch.addr;
142 err = l2->up->send(l2->up, skb);
143 if (err) {
144 printk(KERN_WARNING "%s: err=%d\n", __func__, err);
145 dev_kfree_skb(skb);
146 }
147}
148
149static void
150l2up_create(struct layer2 *l2, u_int prim, int len, void *arg)
151{
152 struct sk_buff *skb;
153 struct mISDNhead *hh;
154 int err;
155
156 if (!l2->up)
157 return;
158 skb = mI_alloc_skb(len, GFP_ATOMIC);
159 if (!skb)
160 return;
161 hh = mISDN_HEAD_P(skb);
162 hh->prim = prim;
163 hh->id = (l2->ch.nr << 16) | l2->ch.addr;
164 if (len)
165 memcpy(skb_put(skb, len), arg, len);
166 err = l2->up->send(l2->up, skb);
167 if (err) {
168 printk(KERN_WARNING "%s: err=%d\n", __func__, err);
169 dev_kfree_skb(skb);
170 }
171}
172
173static int
174l2down_skb(struct layer2 *l2, struct sk_buff *skb) {
175 int ret;
176
177 ret = l2->ch.recv(l2->ch.peer, skb);
178 if (ret && (*debug & DEBUG_L2_RECV))
179 printk(KERN_DEBUG "l2down_skb: ret(%d)\n", ret);
180 return ret;
181}
182
183static int
184l2down_raw(struct layer2 *l2, struct sk_buff *skb)
185{
186 struct mISDNhead *hh = mISDN_HEAD_P(skb);
187
188 if (hh->prim == PH_DATA_REQ) {
189 if (test_and_set_bit(FLG_L1_NOTREADY, &l2->flag)) {
190 skb_queue_tail(&l2->down_queue, skb);
191 return 0;
192 }
193 l2->down_id = mISDN_HEAD_ID(skb);
194 }
195 return l2down_skb(l2, skb);
196}
197
198static int
199l2down(struct layer2 *l2, u_int prim, u_int id, struct sk_buff *skb)
200{
201 struct mISDNhead *hh = mISDN_HEAD_P(skb);
202
203 hh->prim = prim;
204 hh->id = id;
205 return l2down_raw(l2, skb);
206}
207
208static int
209l2down_create(struct layer2 *l2, u_int prim, u_int id, int len, void *arg)
210{
211 struct sk_buff *skb;
212 int err;
213 struct mISDNhead *hh;
214
215 skb = mI_alloc_skb(len, GFP_ATOMIC);
216 if (!skb)
217 return -ENOMEM;
218 hh = mISDN_HEAD_P(skb);
219 hh->prim = prim;
220 hh->id = id;
221 if (len)
222 memcpy(skb_put(skb, len), arg, len);
223 err = l2down_raw(l2, skb);
224 if (err)
225 dev_kfree_skb(skb);
226 return err;
227}
228
229static int
230ph_data_confirm(struct layer2 *l2, struct mISDNhead *hh, struct sk_buff *skb) {
231 struct sk_buff *nskb = skb;
232 int ret = -EAGAIN;
233
234 if (test_bit(FLG_L1_NOTREADY, &l2->flag)) {
235 if (hh->id == l2->down_id) {
236 nskb = skb_dequeue(&l2->down_queue);
237 if (nskb) {
238 l2->down_id = mISDN_HEAD_ID(nskb);
239 if (l2down_skb(l2, nskb)) {
240 dev_kfree_skb(nskb);
241 l2->down_id = MISDN_ID_NONE;
242 }
243 } else
244 l2->down_id = MISDN_ID_NONE;
245 if (ret) {
246 dev_kfree_skb(skb);
247 ret = 0;
248 }
249 if (l2->down_id == MISDN_ID_NONE) {
250 test_and_clear_bit(FLG_L1_NOTREADY, &l2->flag);
251 mISDN_FsmEvent(&l2->l2m, EV_L2_ACK_PULL, NULL);
252 }
253 }
254 }
255 if (!test_and_set_bit(FLG_L1_NOTREADY, &l2->flag)) {
256 nskb = skb_dequeue(&l2->down_queue);
257 if (nskb) {
258 l2->down_id = mISDN_HEAD_ID(nskb);
259 if (l2down_skb(l2, nskb)) {
260 dev_kfree_skb(nskb);
261 l2->down_id = MISDN_ID_NONE;
262 test_and_clear_bit(FLG_L1_NOTREADY, &l2->flag);
263 }
264 } else
265 test_and_clear_bit(FLG_L1_NOTREADY, &l2->flag);
266 }
267 return ret;
268}
269
270static int
271l2mgr(struct layer2 *l2, u_int prim, void *arg) {
272 long c = (long)arg;
273
274 printk(KERN_WARNING
275 "l2mgr: addr:%x prim %x %c\n", l2->id, prim, (char)c);
276 if (test_bit(FLG_LAPD, &l2->flag) &&
277 !test_bit(FLG_FIXED_TEI, &l2->flag)) {
278 switch (c) {
279 case 'C':
280 case 'D':
281 case 'G':
282 case 'H':
283 l2_tei(l2, prim, (u_long)arg);
284 break;
285 }
286 }
287 return 0;
288}
289
290static void
291set_peer_busy(struct layer2 *l2) {
292 test_and_set_bit(FLG_PEER_BUSY, &l2->flag);
293 if (skb_queue_len(&l2->i_queue) || skb_queue_len(&l2->ui_queue))
294 test_and_set_bit(FLG_L2BLOCK, &l2->flag);
295}
296
297static void
298clear_peer_busy(struct layer2 *l2) {
299 if (test_and_clear_bit(FLG_PEER_BUSY, &l2->flag))
300 test_and_clear_bit(FLG_L2BLOCK, &l2->flag);
301}
302
303static void
304InitWin(struct layer2 *l2)
305{
306 int i;
307
308 for (i = 0; i < MAX_WINDOW; i++)
309 l2->windowar[i] = NULL;
310}
311
312static int
313freewin(struct layer2 *l2)
314{
315 int i, cnt = 0;
316
317 for (i = 0; i < MAX_WINDOW; i++) {
318 if (l2->windowar[i]) {
319 cnt++;
320 dev_kfree_skb(l2->windowar[i]);
321 l2->windowar[i] = NULL;
322 }
323 }
324 return cnt;
325}
326
327static void
328ReleaseWin(struct layer2 *l2)
329{
330 int cnt = freewin(l2);
331
332 if (cnt)
333 printk(KERN_WARNING
334 "isdnl2 freed %d skbuffs in release\n", cnt);
335}
336
337inline unsigned int
338cansend(struct layer2 *l2)
339{
340 unsigned int p1;
341
342 if (test_bit(FLG_MOD128, &l2->flag))
343 p1 = (l2->vs - l2->va) % 128;
344 else
345 p1 = (l2->vs - l2->va) % 8;
346 return (p1 < l2->window) && !test_bit(FLG_PEER_BUSY, &l2->flag);
347}
348
349inline void
350clear_exception(struct layer2 *l2)
351{
352 test_and_clear_bit(FLG_ACK_PEND, &l2->flag);
353 test_and_clear_bit(FLG_REJEXC, &l2->flag);
354 test_and_clear_bit(FLG_OWN_BUSY, &l2->flag);
355 clear_peer_busy(l2);
356}
357
358static int
359sethdraddr(struct layer2 *l2, u_char *header, int rsp)
360{
361 u_char *ptr = header;
362 int crbit = rsp;
363
364 if (test_bit(FLG_LAPD, &l2->flag)) {
365 if (test_bit(FLG_LAPD_NET, &l2->flag))
366 crbit = !crbit;
367 *ptr++ = (l2->sapi << 2) | (crbit ? 2 : 0);
368 *ptr++ = (l2->tei << 1) | 1;
369 return 2;
370 } else {
371 if (test_bit(FLG_ORIG, &l2->flag))
372 crbit = !crbit;
373 if (crbit)
374 *ptr++ = l2->addr.B;
375 else
376 *ptr++ = l2->addr.A;
377 return 1;
378 }
379}
380
381static inline void
382enqueue_super(struct layer2 *l2, struct sk_buff *skb)
383{
384 if (l2down(l2, PH_DATA_REQ, l2_newid(l2), skb))
385 dev_kfree_skb(skb);
386}
387
388static inline void
389enqueue_ui(struct layer2 *l2, struct sk_buff *skb)
390{
391 if (l2->tm)
392 l2_tei(l2, MDL_STATUS_UI_IND, 0);
393 if (l2down(l2, PH_DATA_REQ, l2_newid(l2), skb))
394 dev_kfree_skb(skb);
395}
396
397inline int
398IsUI(u_char *data)
399{
400 return (data[0] & 0xef) == UI;
401}
402
403inline int
404IsUA(u_char *data)
405{
406 return (data[0] & 0xef) == UA;
407}
408
409inline int
410IsDM(u_char *data)
411{
412 return (data[0] & 0xef) == DM;
413}
414
415inline int
416IsDISC(u_char *data)
417{
418 return (data[0] & 0xef) == DISC;
419}
420
421inline int
422IsRR(u_char *data, struct layer2 *l2)
423{
424 if (test_bit(FLG_MOD128, &l2->flag))
425 return data[0] == RR;
426 else
427 return (data[0] & 0xf) == 1;
428}
429
430inline int
431IsSFrame(u_char *data, struct layer2 *l2)
432{
433 register u_char d = *data;
434
435 if (!test_bit(FLG_MOD128, &l2->flag))
436 d &= 0xf;
437 return ((d & 0xf3) == 1) && ((d & 0x0c) != 0x0c);
438}
439
440inline int
441IsSABME(u_char *data, struct layer2 *l2)
442{
443 u_char d = data[0] & ~0x10;
444
445 return test_bit(FLG_MOD128, &l2->flag) ? d == SABME : d == SABM;
446}
447
448inline int
449IsREJ(u_char *data, struct layer2 *l2)
450{
451 return test_bit(FLG_MOD128, &l2->flag) ?
452 data[0] == REJ : (data[0] & 0xf) == REJ;
453}
454
455inline int
456IsFRMR(u_char *data)
457{
458 return (data[0] & 0xef) == FRMR;
459}
460
461inline int
462IsRNR(u_char *data, struct layer2 *l2)
463{
464 return test_bit(FLG_MOD128, &l2->flag) ?
465 data[0] == RNR : (data[0] & 0xf) == RNR;
466}
467
468int
469iframe_error(struct layer2 *l2, struct sk_buff *skb)
470{
471 u_int i;
472 int rsp = *skb->data & 0x2;
473
474 i = l2addrsize(l2) + (test_bit(FLG_MOD128, &l2->flag) ? 2 : 1);
475 if (test_bit(FLG_ORIG, &l2->flag))
476 rsp = !rsp;
477 if (rsp)
478 return 'L';
479 if (skb->len < i)
480 return 'N';
481 if ((skb->len - i) > l2->maxlen)
482 return 'O';
483 return 0;
484}
485
486int
487super_error(struct layer2 *l2, struct sk_buff *skb)
488{
489 if (skb->len != l2addrsize(l2) +
490 (test_bit(FLG_MOD128, &l2->flag) ? 2 : 1))
491 return 'N';
492 return 0;
493}
494
495int
496unnum_error(struct layer2 *l2, struct sk_buff *skb, int wantrsp)
497{
498 int rsp = (*skb->data & 0x2) >> 1;
499 if (test_bit(FLG_ORIG, &l2->flag))
500 rsp = !rsp;
501 if (rsp != wantrsp)
502 return 'L';
503 if (skb->len != l2addrsize(l2) + 1)
504 return 'N';
505 return 0;
506}
507
508int
509UI_error(struct layer2 *l2, struct sk_buff *skb)
510{
511 int rsp = *skb->data & 0x2;
512 if (test_bit(FLG_ORIG, &l2->flag))
513 rsp = !rsp;
514 if (rsp)
515 return 'L';
516 if (skb->len > l2->maxlen + l2addrsize(l2) + 1)
517 return 'O';
518 return 0;
519}
520
521int
522FRMR_error(struct layer2 *l2, struct sk_buff *skb)
523{
524 u_int headers = l2addrsize(l2) + 1;
525 u_char *datap = skb->data + headers;
526 int rsp = *skb->data & 0x2;
527
528 if (test_bit(FLG_ORIG, &l2->flag))
529 rsp = !rsp;
530 if (!rsp)
531 return 'L';
532 if (test_bit(FLG_MOD128, &l2->flag)) {
533 if (skb->len < headers + 5)
534 return 'N';
535 else if (*debug & DEBUG_L2)
536 l2m_debug(&l2->l2m,
537 "FRMR information %2x %2x %2x %2x %2x",
538 datap[0], datap[1], datap[2], datap[3], datap[4]);
539 } else {
540 if (skb->len < headers + 3)
541 return 'N';
542 else if (*debug & DEBUG_L2)
543 l2m_debug(&l2->l2m,
544 "FRMR information %2x %2x %2x",
545 datap[0], datap[1], datap[2]);
546 }
547 return 0;
548}
549
550static unsigned int
551legalnr(struct layer2 *l2, unsigned int nr)
552{
553 if (test_bit(FLG_MOD128, &l2->flag))
554 return ((nr - l2->va) % 128) <= ((l2->vs - l2->va) % 128);
555 else
556 return ((nr - l2->va) % 8) <= ((l2->vs - l2->va) % 8);
557}
558
559static void
560setva(struct layer2 *l2, unsigned int nr)
561{
562 struct sk_buff *skb;
563
564 while (l2->va != nr) {
565 l2->va++;
566 if (test_bit(FLG_MOD128, &l2->flag))
567 l2->va %= 128;
568 else
569 l2->va %= 8;
570 if (l2->windowar[l2->sow]) {
571 skb_trim(l2->windowar[l2->sow], 0);
572 skb_queue_tail(&l2->tmp_queue, l2->windowar[l2->sow]);
573 l2->windowar[l2->sow] = NULL;
574 }
575 l2->sow = (l2->sow + 1) % l2->window;
576 }
577 skb = skb_dequeue(&l2->tmp_queue);
578 while (skb) {
579 dev_kfree_skb(skb);
580 skb = skb_dequeue(&l2->tmp_queue);
581 }
582}
583
584static void
585send_uframe(struct layer2 *l2, struct sk_buff *skb, u_char cmd, u_char cr)
586{
587 u_char tmp[MAX_L2HEADER_LEN];
588 int i;
589
590 i = sethdraddr(l2, tmp, cr);
591 tmp[i++] = cmd;
592 if (skb)
593 skb_trim(skb, 0);
594 else {
595 skb = mI_alloc_skb(i, GFP_ATOMIC);
596 if (!skb) {
597 printk(KERN_WARNING "%s: can't alloc skbuff\n",
598 __func__);
599 return;
600 }
601 }
602 memcpy(skb_put(skb, i), tmp, i);
603 enqueue_super(l2, skb);
604}
605
606
607inline u_char
608get_PollFlag(struct layer2 *l2, struct sk_buff *skb)
609{
610 return skb->data[l2addrsize(l2)] & 0x10;
611}
612
613inline u_char
614get_PollFlagFree(struct layer2 *l2, struct sk_buff *skb)
615{
616 u_char PF;
617
618 PF = get_PollFlag(l2, skb);
619 dev_kfree_skb(skb);
620 return PF;
621}
622
623inline void
624start_t200(struct layer2 *l2, int i)
625{
626 mISDN_FsmAddTimer(&l2->t200, l2->T200, EV_L2_T200, NULL, i);
627 test_and_set_bit(FLG_T200_RUN, &l2->flag);
628}
629
630inline void
631restart_t200(struct layer2 *l2, int i)
632{
633 mISDN_FsmRestartTimer(&l2->t200, l2->T200, EV_L2_T200, NULL, i);
634 test_and_set_bit(FLG_T200_RUN, &l2->flag);
635}
636
637inline void
638stop_t200(struct layer2 *l2, int i)
639{
640 if (test_and_clear_bit(FLG_T200_RUN, &l2->flag))
641 mISDN_FsmDelTimer(&l2->t200, i);
642}
643
644inline void
645st5_dl_release_l2l3(struct layer2 *l2)
646{
647 int pr;
648
649 if (test_and_clear_bit(FLG_PEND_REL, &l2->flag))
650 pr = DL_RELEASE_CNF;
651 else
652 pr = DL_RELEASE_IND;
653 l2up_create(l2, pr, 0, NULL);
654}
655
656inline void
657lapb_dl_release_l2l3(struct layer2 *l2, int f)
658{
659 if (test_bit(FLG_LAPB, &l2->flag))
660 l2down_create(l2, PH_DEACTIVATE_REQ, l2_newid(l2), 0, NULL);
661 l2up_create(l2, f, 0, NULL);
662}
663
664static void
665establishlink(struct FsmInst *fi)
666{
667 struct layer2 *l2 = fi->userdata;
668 u_char cmd;
669
670 clear_exception(l2);
671 l2->rc = 0;
672 cmd = (test_bit(FLG_MOD128, &l2->flag) ? SABME : SABM) | 0x10;
673 send_uframe(l2, NULL, cmd, CMD);
674 mISDN_FsmDelTimer(&l2->t203, 1);
675 restart_t200(l2, 1);
676 test_and_clear_bit(FLG_PEND_REL, &l2->flag);
677 freewin(l2);
678 mISDN_FsmChangeState(fi, ST_L2_5);
679}
680
681static void
682l2_mdl_error_ua(struct FsmInst *fi, int event, void *arg)
683{
684 struct sk_buff *skb = arg;
685 struct layer2 *l2 = fi->userdata;
686
687 if (get_PollFlagFree(l2, skb))
688 l2mgr(l2, MDL_ERROR_IND, (void *) 'C');
689 else
690 l2mgr(l2, MDL_ERROR_IND, (void *) 'D');
691
692}
693
694static void
695l2_mdl_error_dm(struct FsmInst *fi, int event, void *arg)
696{
697 struct sk_buff *skb = arg;
698 struct layer2 *l2 = fi->userdata;
699
700 if (get_PollFlagFree(l2, skb))
701 l2mgr(l2, MDL_ERROR_IND, (void *) 'B');
702 else {
703 l2mgr(l2, MDL_ERROR_IND, (void *) 'E');
704 establishlink(fi);
705 test_and_clear_bit(FLG_L3_INIT, &l2->flag);
706 }
707}
708
709static void
710l2_st8_mdl_error_dm(struct FsmInst *fi, int event, void *arg)
711{
712 struct sk_buff *skb = arg;
713 struct layer2 *l2 = fi->userdata;
714
715 if (get_PollFlagFree(l2, skb))
716 l2mgr(l2, MDL_ERROR_IND, (void *) 'B');
717 else
718 l2mgr(l2, MDL_ERROR_IND, (void *) 'E');
719 establishlink(fi);
720 test_and_clear_bit(FLG_L3_INIT, &l2->flag);
721}
722
723static void
724l2_go_st3(struct FsmInst *fi, int event, void *arg)
725{
726 dev_kfree_skb((struct sk_buff *)arg);
727 mISDN_FsmChangeState(fi, ST_L2_3);
728}
729
730static void
731l2_mdl_assign(struct FsmInst *fi, int event, void *arg)
732{
733 struct layer2 *l2 = fi->userdata;
734
735 mISDN_FsmChangeState(fi, ST_L2_3);
736 dev_kfree_skb((struct sk_buff *)arg);
737 l2_tei(l2, MDL_ASSIGN_IND, 0);
738}
739
740static void
741l2_queue_ui_assign(struct FsmInst *fi, int event, void *arg)
742{
743 struct layer2 *l2 = fi->userdata;
744 struct sk_buff *skb = arg;
745
746 skb_queue_tail(&l2->ui_queue, skb);
747 mISDN_FsmChangeState(fi, ST_L2_2);
748 l2_tei(l2, MDL_ASSIGN_IND, 0);
749}
750
751static void
752l2_queue_ui(struct FsmInst *fi, int event, void *arg)
753{
754 struct layer2 *l2 = fi->userdata;
755 struct sk_buff *skb = arg;
756
757 skb_queue_tail(&l2->ui_queue, skb);
758}
759
760static void
761tx_ui(struct layer2 *l2)
762{
763 struct sk_buff *skb;
764 u_char header[MAX_L2HEADER_LEN];
765 int i;
766
767 i = sethdraddr(l2, header, CMD);
768 if (test_bit(FLG_LAPD_NET, &l2->flag))
769 header[1] = 0xff; /* tei 127 */
770 header[i++] = UI;
771 while ((skb = skb_dequeue(&l2->ui_queue))) {
772 memcpy(skb_push(skb, i), header, i);
773 enqueue_ui(l2, skb);
774 }
775}
776
777static void
778l2_send_ui(struct FsmInst *fi, int event, void *arg)
779{
780 struct layer2 *l2 = fi->userdata;
781 struct sk_buff *skb = arg;
782
783 skb_queue_tail(&l2->ui_queue, skb);
784 tx_ui(l2);
785}
786
787static void
788l2_got_ui(struct FsmInst *fi, int event, void *arg)
789{
790 struct layer2 *l2 = fi->userdata;
791 struct sk_buff *skb = arg;
792
793 skb_pull(skb, l2headersize(l2, 1));
794/*
795 * in states 1-3 for broadcast
796 */
797
798 if (l2->tm)
799 l2_tei(l2, MDL_STATUS_UI_IND, 0);
800 l2up(l2, DL_UNITDATA_IND, skb);
801}
802
803static void
804l2_establish(struct FsmInst *fi, int event, void *arg)
805{
806 struct sk_buff *skb = arg;
807 struct layer2 *l2 = fi->userdata;
808
809 establishlink(fi);
810 test_and_set_bit(FLG_L3_INIT, &l2->flag);
811 dev_kfree_skb(skb);
812}
813
814static void
815l2_discard_i_setl3(struct FsmInst *fi, int event, void *arg)
816{
817 struct sk_buff *skb = arg;
818 struct layer2 *l2 = fi->userdata;
819
820 skb_queue_purge(&l2->i_queue);
821 test_and_set_bit(FLG_L3_INIT, &l2->flag);
822 test_and_clear_bit(FLG_PEND_REL, &l2->flag);
823 dev_kfree_skb(skb);
824}
825
826static void
827l2_l3_reestablish(struct FsmInst *fi, int event, void *arg)
828{
829 struct sk_buff *skb = arg;
830 struct layer2 *l2 = fi->userdata;
831
832 skb_queue_purge(&l2->i_queue);
833 establishlink(fi);
834 test_and_set_bit(FLG_L3_INIT, &l2->flag);
835 dev_kfree_skb(skb);
836}
837
838static void
839l2_release(struct FsmInst *fi, int event, void *arg)
840{
841 struct layer2 *l2 = fi->userdata;
842 struct sk_buff *skb = arg;
843
844 skb_trim(skb, 0);
845 l2up(l2, DL_RELEASE_CNF, skb);
846}
847
848static void
849l2_pend_rel(struct FsmInst *fi, int event, void *arg)
850{
851 struct sk_buff *skb = arg;
852 struct layer2 *l2 = fi->userdata;
853
854 test_and_set_bit(FLG_PEND_REL, &l2->flag);
855 dev_kfree_skb(skb);
856}
857
858static void
859l2_disconnect(struct FsmInst *fi, int event, void *arg)
860{
861 struct layer2 *l2 = fi->userdata;
862 struct sk_buff *skb = arg;
863
864 skb_queue_purge(&l2->i_queue);
865 freewin(l2);
866 mISDN_FsmChangeState(fi, ST_L2_6);
867 l2->rc = 0;
868 send_uframe(l2, NULL, DISC | 0x10, CMD);
869 mISDN_FsmDelTimer(&l2->t203, 1);
870 restart_t200(l2, 2);
871 if (skb)
872 dev_kfree_skb(skb);
873}
874
875static void
876l2_start_multi(struct FsmInst *fi, int event, void *arg)
877{
878 struct layer2 *l2 = fi->userdata;
879 struct sk_buff *skb = arg;
880
881 l2->vs = 0;
882 l2->va = 0;
883 l2->vr = 0;
884 l2->sow = 0;
885 clear_exception(l2);
886 send_uframe(l2, NULL, UA | get_PollFlag(l2, skb), RSP);
887 mISDN_FsmChangeState(fi, ST_L2_7);
888 mISDN_FsmAddTimer(&l2->t203, l2->T203, EV_L2_T203, NULL, 3);
889 skb_trim(skb, 0);
890 l2up(l2, DL_ESTABLISH_IND, skb);
891 if (l2->tm)
892 l2_tei(l2, MDL_STATUS_UP_IND, 0);
893}
894
895static void
896l2_send_UA(struct FsmInst *fi, int event, void *arg)
897{
898 struct layer2 *l2 = fi->userdata;
899 struct sk_buff *skb = arg;
900
901 send_uframe(l2, skb, UA | get_PollFlag(l2, skb), RSP);
902}
903
904static void
905l2_send_DM(struct FsmInst *fi, int event, void *arg)
906{
907 struct layer2 *l2 = fi->userdata;
908 struct sk_buff *skb = arg;
909
910 send_uframe(l2, skb, DM | get_PollFlag(l2, skb), RSP);
911}
912
913static void
914l2_restart_multi(struct FsmInst *fi, int event, void *arg)
915{
916 struct layer2 *l2 = fi->userdata;
917 struct sk_buff *skb = arg;
918 int est = 0;
919
920 send_uframe(l2, skb, UA | get_PollFlag(l2, skb), RSP);
921
922 l2mgr(l2, MDL_ERROR_IND, (void *) 'F');
923
924 if (l2->vs != l2->va) {
925 skb_queue_purge(&l2->i_queue);
926 est = 1;
927 }
928
929 clear_exception(l2);
930 l2->vs = 0;
931 l2->va = 0;
932 l2->vr = 0;
933 l2->sow = 0;
934 mISDN_FsmChangeState(fi, ST_L2_7);
935 stop_t200(l2, 3);
936 mISDN_FsmRestartTimer(&l2->t203, l2->T203, EV_L2_T203, NULL, 3);
937
938 if (est)
939 l2up_create(l2, DL_ESTABLISH_IND, 0, NULL);
940/* mISDN_queue_data(&l2->inst, l2->inst.id | MSG_BROADCAST,
941 * MGR_SHORTSTATUS | INDICATION, SSTATUS_L2_ESTABLISHED,
942 * 0, NULL, 0);
943 */
944 if (skb_queue_len(&l2->i_queue) && cansend(l2))
945 mISDN_FsmEvent(fi, EV_L2_ACK_PULL, NULL);
946}
947
948static void
949l2_stop_multi(struct FsmInst *fi, int event, void *arg)
950{
951 struct layer2 *l2 = fi->userdata;
952 struct sk_buff *skb = arg;
953
954 mISDN_FsmChangeState(fi, ST_L2_4);
955 mISDN_FsmDelTimer(&l2->t203, 3);
956 stop_t200(l2, 4);
957
958 send_uframe(l2, skb, UA | get_PollFlag(l2, skb), RSP);
959 skb_queue_purge(&l2->i_queue);
960 freewin(l2);
961 lapb_dl_release_l2l3(l2, DL_RELEASE_IND);
962 if (l2->tm)
963 l2_tei(l2, MDL_STATUS_DOWN_IND, 0);
964}
965
966static void
967l2_connected(struct FsmInst *fi, int event, void *arg)
968{
969 struct layer2 *l2 = fi->userdata;
970 struct sk_buff *skb = arg;
971 int pr = -1;
972
973 if (!get_PollFlag(l2, skb)) {
974 l2_mdl_error_ua(fi, event, arg);
975 return;
976 }
977 dev_kfree_skb(skb);
978 if (test_and_clear_bit(FLG_PEND_REL, &l2->flag))
979 l2_disconnect(fi, event, NULL);
980 if (test_and_clear_bit(FLG_L3_INIT, &l2->flag)) {
981 pr = DL_ESTABLISH_CNF;
982 } else if (l2->vs != l2->va) {
983 skb_queue_purge(&l2->i_queue);
984 pr = DL_ESTABLISH_IND;
985 }
986 stop_t200(l2, 5);
987 l2->vr = 0;
988 l2->vs = 0;
989 l2->va = 0;
990 l2->sow = 0;
991 mISDN_FsmChangeState(fi, ST_L2_7);
992 mISDN_FsmAddTimer(&l2->t203, l2->T203, EV_L2_T203, NULL, 4);
993 if (pr != -1)
994 l2up_create(l2, pr, 0, NULL);
995
996 if (skb_queue_len(&l2->i_queue) && cansend(l2))
997 mISDN_FsmEvent(fi, EV_L2_ACK_PULL, NULL);
998
999 if (l2->tm)
1000 l2_tei(l2, MDL_STATUS_UP_IND, 0);
1001}
1002
1003static void
1004l2_released(struct FsmInst *fi, int event, void *arg)
1005{
1006 struct layer2 *l2 = fi->userdata;
1007 struct sk_buff *skb = arg;
1008
1009 if (!get_PollFlag(l2, skb)) {
1010 l2_mdl_error_ua(fi, event, arg);
1011 return;
1012 }
1013 dev_kfree_skb(skb);
1014 stop_t200(l2, 6);
1015 lapb_dl_release_l2l3(l2, DL_RELEASE_CNF);
1016 mISDN_FsmChangeState(fi, ST_L2_4);
1017 if (l2->tm)
1018 l2_tei(l2, MDL_STATUS_DOWN_IND, 0);
1019}
1020
1021static void
1022l2_reestablish(struct FsmInst *fi, int event, void *arg)
1023{
1024 struct layer2 *l2 = fi->userdata;
1025 struct sk_buff *skb = arg;
1026
1027 if (!get_PollFlagFree(l2, skb)) {
1028 establishlink(fi);
1029 test_and_set_bit(FLG_L3_INIT, &l2->flag);
1030 }
1031}
1032
1033static void
1034l2_st5_dm_release(struct FsmInst *fi, int event, void *arg)
1035{
1036 struct layer2 *l2 = fi->userdata;
1037 struct sk_buff *skb = arg;
1038
1039 if (get_PollFlagFree(l2, skb)) {
1040 stop_t200(l2, 7);
1041 if (!test_bit(FLG_L3_INIT, &l2->flag))
1042 skb_queue_purge(&l2->i_queue);
1043 if (test_bit(FLG_LAPB, &l2->flag))
1044 l2down_create(l2, PH_DEACTIVATE_REQ,
1045 l2_newid(l2), 0, NULL);
1046 st5_dl_release_l2l3(l2);
1047 mISDN_FsmChangeState(fi, ST_L2_4);
1048 if (l2->tm)
1049 l2_tei(l2, MDL_STATUS_DOWN_IND, 0);
1050 }
1051}
1052
1053static void
1054l2_st6_dm_release(struct FsmInst *fi, int event, void *arg)
1055{
1056 struct layer2 *l2 = fi->userdata;
1057 struct sk_buff *skb = arg;
1058
1059 if (get_PollFlagFree(l2, skb)) {
1060 stop_t200(l2, 8);
1061 lapb_dl_release_l2l3(l2, DL_RELEASE_CNF);
1062 mISDN_FsmChangeState(fi, ST_L2_4);
1063 if (l2->tm)
1064 l2_tei(l2, MDL_STATUS_DOWN_IND, 0);
1065 }
1066}
1067
1068void
1069enquiry_cr(struct layer2 *l2, u_char typ, u_char cr, u_char pf)
1070{
1071 struct sk_buff *skb;
1072 u_char tmp[MAX_L2HEADER_LEN];
1073 int i;
1074
1075 i = sethdraddr(l2, tmp, cr);
1076 if (test_bit(FLG_MOD128, &l2->flag)) {
1077 tmp[i++] = typ;
1078 tmp[i++] = (l2->vr << 1) | (pf ? 1 : 0);
1079 } else
1080 tmp[i++] = (l2->vr << 5) | typ | (pf ? 0x10 : 0);
1081 skb = mI_alloc_skb(i, GFP_ATOMIC);
1082 if (!skb) {
1083 printk(KERN_WARNING
1084 "isdnl2 can't alloc sbbuff for enquiry_cr\n");
1085 return;
1086 }
1087 memcpy(skb_put(skb, i), tmp, i);
1088 enqueue_super(l2, skb);
1089}
1090
1091inline void
1092enquiry_response(struct layer2 *l2)
1093{
1094 if (test_bit(FLG_OWN_BUSY, &l2->flag))
1095 enquiry_cr(l2, RNR, RSP, 1);
1096 else
1097 enquiry_cr(l2, RR, RSP, 1);
1098 test_and_clear_bit(FLG_ACK_PEND, &l2->flag);
1099}
1100
1101inline void
1102transmit_enquiry(struct layer2 *l2)
1103{
1104 if (test_bit(FLG_OWN_BUSY, &l2->flag))
1105 enquiry_cr(l2, RNR, CMD, 1);
1106 else
1107 enquiry_cr(l2, RR, CMD, 1);
1108 test_and_clear_bit(FLG_ACK_PEND, &l2->flag);
1109 start_t200(l2, 9);
1110}
1111
1112
1113static void
1114nrerrorrecovery(struct FsmInst *fi)
1115{
1116 struct layer2 *l2 = fi->userdata;
1117
1118 l2mgr(l2, MDL_ERROR_IND, (void *) 'J');
1119 establishlink(fi);
1120 test_and_clear_bit(FLG_L3_INIT, &l2->flag);
1121}
1122
1123static void
1124invoke_retransmission(struct layer2 *l2, unsigned int nr)
1125{
1126 u_int p1;
1127
1128 if (l2->vs != nr) {
1129 while (l2->vs != nr) {
1130 (l2->vs)--;
1131 if (test_bit(FLG_MOD128, &l2->flag)) {
1132 l2->vs %= 128;
1133 p1 = (l2->vs - l2->va) % 128;
1134 } else {
1135 l2->vs %= 8;
1136 p1 = (l2->vs - l2->va) % 8;
1137 }
1138 p1 = (p1 + l2->sow) % l2->window;
1139 if (l2->windowar[p1])
1140 skb_queue_head(&l2->i_queue, l2->windowar[p1]);
1141 else
1142 printk(KERN_WARNING
1143 "%s: windowar[%d] is NULL\n",
1144 __func__, p1);
1145 l2->windowar[p1] = NULL;
1146 }
1147 mISDN_FsmEvent(&l2->l2m, EV_L2_ACK_PULL, NULL);
1148 }
1149}
1150
1151static void
1152l2_st7_got_super(struct FsmInst *fi, int event, void *arg)
1153{
1154 struct layer2 *l2 = fi->userdata;
1155 struct sk_buff *skb = arg;
1156 int PollFlag, rsp, typ = RR;
1157 unsigned int nr;
1158
1159 rsp = *skb->data & 0x2;
1160 if (test_bit(FLG_ORIG, &l2->flag))
1161 rsp = !rsp;
1162
1163 skb_pull(skb, l2addrsize(l2));
1164 if (IsRNR(skb->data, l2)) {
1165 set_peer_busy(l2);
1166 typ = RNR;
1167 } else
1168 clear_peer_busy(l2);
1169 if (IsREJ(skb->data, l2))
1170 typ = REJ;
1171
1172 if (test_bit(FLG_MOD128, &l2->flag)) {
1173 PollFlag = (skb->data[1] & 0x1) == 0x1;
1174 nr = skb->data[1] >> 1;
1175 } else {
1176 PollFlag = (skb->data[0] & 0x10);
1177 nr = (skb->data[0] >> 5) & 0x7;
1178 }
1179 dev_kfree_skb(skb);
1180
1181 if (PollFlag) {
1182 if (rsp)
1183 l2mgr(l2, MDL_ERROR_IND, (void *) 'A');
1184 else
1185 enquiry_response(l2);
1186 }
1187 if (legalnr(l2, nr)) {
1188 if (typ == REJ) {
1189 setva(l2, nr);
1190 invoke_retransmission(l2, nr);
1191 stop_t200(l2, 10);
1192 if (mISDN_FsmAddTimer(&l2->t203, l2->T203,
1193 EV_L2_T203, NULL, 6))
1194 l2m_debug(&l2->l2m, "Restart T203 ST7 REJ");
1195 } else if ((nr == l2->vs) && (typ == RR)) {
1196 setva(l2, nr);
1197 stop_t200(l2, 11);
1198 mISDN_FsmRestartTimer(&l2->t203, l2->T203,
1199 EV_L2_T203, NULL, 7);
1200 } else if ((l2->va != nr) || (typ == RNR)) {
1201 setva(l2, nr);
1202 if (typ != RR)
1203 mISDN_FsmDelTimer(&l2->t203, 9);
1204 restart_t200(l2, 12);
1205 }
1206 if (skb_queue_len(&l2->i_queue) && (typ == RR))
1207 mISDN_FsmEvent(fi, EV_L2_ACK_PULL, NULL);
1208 } else
1209 nrerrorrecovery(fi);
1210}
1211
1212static void
1213l2_feed_i_if_reest(struct FsmInst *fi, int event, void *arg)
1214{
1215 struct layer2 *l2 = fi->userdata;
1216 struct sk_buff *skb = arg;
1217
1218 if (!test_bit(FLG_L3_INIT, &l2->flag))
1219 skb_queue_tail(&l2->i_queue, skb);
1220 else
1221 dev_kfree_skb(skb);
1222}
1223
1224static void
1225l2_feed_i_pull(struct FsmInst *fi, int event, void *arg)
1226{
1227 struct layer2 *l2 = fi->userdata;
1228 struct sk_buff *skb = arg;
1229
1230 skb_queue_tail(&l2->i_queue, skb);
1231 mISDN_FsmEvent(fi, EV_L2_ACK_PULL, NULL);
1232}
1233
1234static void
1235l2_feed_iqueue(struct FsmInst *fi, int event, void *arg)
1236{
1237 struct layer2 *l2 = fi->userdata;
1238 struct sk_buff *skb = arg;
1239
1240 skb_queue_tail(&l2->i_queue, skb);
1241}
1242
1243static void
1244l2_got_iframe(struct FsmInst *fi, int event, void *arg)
1245{
1246 struct layer2 *l2 = fi->userdata;
1247 struct sk_buff *skb = arg;
1248 int PollFlag, i;
1249 u_int ns, nr;
1250
1251 i = l2addrsize(l2);
1252 if (test_bit(FLG_MOD128, &l2->flag)) {
1253 PollFlag = ((skb->data[i + 1] & 0x1) == 0x1);
1254 ns = skb->data[i] >> 1;
1255 nr = (skb->data[i + 1] >> 1) & 0x7f;
1256 } else {
1257 PollFlag = (skb->data[i] & 0x10);
1258 ns = (skb->data[i] >> 1) & 0x7;
1259 nr = (skb->data[i] >> 5) & 0x7;
1260 }
1261 if (test_bit(FLG_OWN_BUSY, &l2->flag)) {
1262 dev_kfree_skb(skb);
1263 if (PollFlag)
1264 enquiry_response(l2);
1265 } else {
1266 if (l2->vr == ns) {
1267 l2->vr++;
1268 if (test_bit(FLG_MOD128, &l2->flag))
1269 l2->vr %= 128;
1270 else
1271 l2->vr %= 8;
1272 test_and_clear_bit(FLG_REJEXC, &l2->flag);
1273 if (PollFlag)
1274 enquiry_response(l2);
1275 else
1276 test_and_set_bit(FLG_ACK_PEND, &l2->flag);
1277 skb_pull(skb, l2headersize(l2, 0));
1278 l2up(l2, DL_DATA_IND, skb);
1279 } else {
1280 /* n(s)!=v(r) */
1281 dev_kfree_skb(skb);
1282 if (test_and_set_bit(FLG_REJEXC, &l2->flag)) {
1283 if (PollFlag)
1284 enquiry_response(l2);
1285 } else {
1286 enquiry_cr(l2, REJ, RSP, PollFlag);
1287 test_and_clear_bit(FLG_ACK_PEND, &l2->flag);
1288 }
1289 }
1290 }
1291 if (legalnr(l2, nr)) {
1292 if (!test_bit(FLG_PEER_BUSY, &l2->flag) &&
1293 (fi->state == ST_L2_7)) {
1294 if (nr == l2->vs) {
1295 stop_t200(l2, 13);
1296 mISDN_FsmRestartTimer(&l2->t203, l2->T203,
1297 EV_L2_T203, NULL, 7);
1298 } else if (nr != l2->va)
1299 restart_t200(l2, 14);
1300 }
1301 setva(l2, nr);
1302 } else {
1303 nrerrorrecovery(fi);
1304 return;
1305 }
1306 if (skb_queue_len(&l2->i_queue) && (fi->state == ST_L2_7))
1307 mISDN_FsmEvent(fi, EV_L2_ACK_PULL, NULL);
1308 if (test_and_clear_bit(FLG_ACK_PEND, &l2->flag))
1309 enquiry_cr(l2, RR, RSP, 0);
1310}
1311
1312static void
1313l2_got_tei(struct FsmInst *fi, int event, void *arg)
1314{
1315 struct layer2 *l2 = fi->userdata;
1316 u_int info;
1317
1318 l2->tei = (signed char)(long)arg;
1319 set_channel_address(&l2->ch, l2->sapi, l2->tei);
1320 info = DL_INFO_L2_CONNECT;
1321 l2up_create(l2, DL_INFORMATION_IND, sizeof(info), &info);
1322 if (fi->state == ST_L2_3) {
1323 establishlink(fi);
1324 test_and_set_bit(FLG_L3_INIT, &l2->flag);
1325 } else
1326 mISDN_FsmChangeState(fi, ST_L2_4);
1327 if (skb_queue_len(&l2->ui_queue))
1328 tx_ui(l2);
1329}
1330
1331static void
1332l2_st5_tout_200(struct FsmInst *fi, int event, void *arg)
1333{
1334 struct layer2 *l2 = fi->userdata;
1335
1336 if (test_bit(FLG_LAPD, &l2->flag) &&
1337 test_bit(FLG_DCHAN_BUSY, &l2->flag)) {
1338 mISDN_FsmAddTimer(&l2->t200, l2->T200, EV_L2_T200, NULL, 9);
1339 } else if (l2->rc == l2->N200) {
1340 mISDN_FsmChangeState(fi, ST_L2_4);
1341 test_and_clear_bit(FLG_T200_RUN, &l2->flag);
1342 skb_queue_purge(&l2->i_queue);
1343 l2mgr(l2, MDL_ERROR_IND, (void *) 'G');
1344 if (test_bit(FLG_LAPB, &l2->flag))
1345 l2down_create(l2, PH_DEACTIVATE_REQ,
1346 l2_newid(l2), 0, NULL);
1347 st5_dl_release_l2l3(l2);
1348 if (l2->tm)
1349 l2_tei(l2, MDL_STATUS_DOWN_IND, 0);
1350 } else {
1351 l2->rc++;
1352 mISDN_FsmAddTimer(&l2->t200, l2->T200, EV_L2_T200, NULL, 9);
1353 send_uframe(l2, NULL, (test_bit(FLG_MOD128, &l2->flag) ?
1354 SABME : SABM) | 0x10, CMD);
1355 }
1356}
1357
1358static void
1359l2_st6_tout_200(struct FsmInst *fi, int event, void *arg)
1360{
1361 struct layer2 *l2 = fi->userdata;
1362
1363 if (test_bit(FLG_LAPD, &l2->flag) &&
1364 test_bit(FLG_DCHAN_BUSY, &l2->flag)) {
1365 mISDN_FsmAddTimer(&l2->t200, l2->T200, EV_L2_T200, NULL, 9);
1366 } else if (l2->rc == l2->N200) {
1367 mISDN_FsmChangeState(fi, ST_L2_4);
1368 test_and_clear_bit(FLG_T200_RUN, &l2->flag);
1369 l2mgr(l2, MDL_ERROR_IND, (void *) 'H');
1370 lapb_dl_release_l2l3(l2, DL_RELEASE_CNF);
1371 if (l2->tm)
1372 l2_tei(l2, MDL_STATUS_DOWN_IND, 0);
1373 } else {
1374 l2->rc++;
1375 mISDN_FsmAddTimer(&l2->t200, l2->T200, EV_L2_T200,
1376 NULL, 9);
1377 send_uframe(l2, NULL, DISC | 0x10, CMD);
1378 }
1379}
1380
1381static void
1382l2_st7_tout_200(struct FsmInst *fi, int event, void *arg)
1383{
1384 struct layer2 *l2 = fi->userdata;
1385
1386 if (test_bit(FLG_LAPD, &l2->flag) &&
1387 test_bit(FLG_DCHAN_BUSY, &l2->flag)) {
1388 mISDN_FsmAddTimer(&l2->t200, l2->T200, EV_L2_T200, NULL, 9);
1389 return;
1390 }
1391 test_and_clear_bit(FLG_T200_RUN, &l2->flag);
1392 l2->rc = 0;
1393 mISDN_FsmChangeState(fi, ST_L2_8);
1394 transmit_enquiry(l2);
1395 l2->rc++;
1396}
1397
1398static void
1399l2_st8_tout_200(struct FsmInst *fi, int event, void *arg)
1400{
1401 struct layer2 *l2 = fi->userdata;
1402
1403 if (test_bit(FLG_LAPD, &l2->flag) &&
1404 test_bit(FLG_DCHAN_BUSY, &l2->flag)) {
1405 mISDN_FsmAddTimer(&l2->t200, l2->T200, EV_L2_T200, NULL, 9);
1406 return;
1407 }
1408 test_and_clear_bit(FLG_T200_RUN, &l2->flag);
1409 if (l2->rc == l2->N200) {
1410 l2mgr(l2, MDL_ERROR_IND, (void *) 'I');
1411 establishlink(fi);
1412 test_and_clear_bit(FLG_L3_INIT, &l2->flag);
1413 } else {
1414 transmit_enquiry(l2);
1415 l2->rc++;
1416 }
1417}
1418
1419static void
1420l2_st7_tout_203(struct FsmInst *fi, int event, void *arg)
1421{
1422 struct layer2 *l2 = fi->userdata;
1423
1424 if (test_bit(FLG_LAPD, &l2->flag) &&
1425 test_bit(FLG_DCHAN_BUSY, &l2->flag)) {
1426 mISDN_FsmAddTimer(&l2->t203, l2->T203, EV_L2_T203, NULL, 9);
1427 return;
1428 }
1429 mISDN_FsmChangeState(fi, ST_L2_8);
1430 transmit_enquiry(l2);
1431 l2->rc = 0;
1432}
1433
1434static void
1435l2_pull_iqueue(struct FsmInst *fi, int event, void *arg)
1436{
1437 struct layer2 *l2 = fi->userdata;
1438 struct sk_buff *skb, *nskb, *oskb;
1439 u_char header[MAX_L2HEADER_LEN];
1440 u_int i, p1;
1441
1442 if (!cansend(l2))
1443 return;
1444
1445 skb = skb_dequeue(&l2->i_queue);
1446 if (!skb)
1447 return;
1448
1449 if (test_bit(FLG_MOD128, &l2->flag))
1450 p1 = (l2->vs - l2->va) % 128;
1451 else
1452 p1 = (l2->vs - l2->va) % 8;
1453 p1 = (p1 + l2->sow) % l2->window;
1454 if (l2->windowar[p1]) {
1455 printk(KERN_WARNING "isdnl2 try overwrite ack queue entry %d\n",
1456 p1);
1457 dev_kfree_skb(l2->windowar[p1]);
1458 }
1459 l2->windowar[p1] = skb;
1460 i = sethdraddr(l2, header, CMD);
1461 if (test_bit(FLG_MOD128, &l2->flag)) {
1462 header[i++] = l2->vs << 1;
1463 header[i++] = l2->vr << 1;
1464 l2->vs = (l2->vs + 1) % 128;
1465 } else {
1466 header[i++] = (l2->vr << 5) | (l2->vs << 1);
1467 l2->vs = (l2->vs + 1) % 8;
1468 }
1469
1470 nskb = skb_clone(skb, GFP_ATOMIC);
1471 p1 = skb_headroom(nskb);
1472 if (p1 >= i)
1473 memcpy(skb_push(nskb, i), header, i);
1474 else {
1475 printk(KERN_WARNING
1476 "isdnl2 pull_iqueue skb header(%d/%d) too short\n", i, p1);
1477 oskb = nskb;
1478 nskb = mI_alloc_skb(oskb->len + i, GFP_ATOMIC);
1479 if (!nskb) {
1480 dev_kfree_skb(oskb);
1481 printk(KERN_WARNING "%s: no skb mem\n", __func__);
1482 return;
1483 }
1484 memcpy(skb_put(nskb, i), header, i);
1485 memcpy(skb_put(nskb, oskb->len), oskb->data, oskb->len);
1486 dev_kfree_skb(oskb);
1487 }
1488 l2down(l2, PH_DATA_REQ, l2_newid(l2), nskb);
1489 test_and_clear_bit(FLG_ACK_PEND, &l2->flag);
1490 if (!test_and_set_bit(FLG_T200_RUN, &l2->flag)) {
1491 mISDN_FsmDelTimer(&l2->t203, 13);
1492 mISDN_FsmAddTimer(&l2->t200, l2->T200, EV_L2_T200, NULL, 11);
1493 }
1494}
1495
1496static void
1497l2_st8_got_super(struct FsmInst *fi, int event, void *arg)
1498{
1499 struct layer2 *l2 = fi->userdata;
1500 struct sk_buff *skb = arg;
1501 int PollFlag, rsp, rnr = 0;
1502 unsigned int nr;
1503
1504 rsp = *skb->data & 0x2;
1505 if (test_bit(FLG_ORIG, &l2->flag))
1506 rsp = !rsp;
1507
1508 skb_pull(skb, l2addrsize(l2));
1509
1510 if (IsRNR(skb->data, l2)) {
1511 set_peer_busy(l2);
1512 rnr = 1;
1513 } else
1514 clear_peer_busy(l2);
1515
1516 if (test_bit(FLG_MOD128, &l2->flag)) {
1517 PollFlag = (skb->data[1] & 0x1) == 0x1;
1518 nr = skb->data[1] >> 1;
1519 } else {
1520 PollFlag = (skb->data[0] & 0x10);
1521 nr = (skb->data[0] >> 5) & 0x7;
1522 }
1523 dev_kfree_skb(skb);
1524 if (rsp && PollFlag) {
1525 if (legalnr(l2, nr)) {
1526 if (rnr) {
1527 restart_t200(l2, 15);
1528 } else {
1529 stop_t200(l2, 16);
1530 mISDN_FsmAddTimer(&l2->t203, l2->T203,
1531 EV_L2_T203, NULL, 5);
1532 setva(l2, nr);
1533 }
1534 invoke_retransmission(l2, nr);
1535 mISDN_FsmChangeState(fi, ST_L2_7);
1536 if (skb_queue_len(&l2->i_queue) && cansend(l2))
1537 mISDN_FsmEvent(fi, EV_L2_ACK_PULL, NULL);
1538 } else
1539 nrerrorrecovery(fi);
1540 } else {
1541 if (!rsp && PollFlag)
1542 enquiry_response(l2);
1543 if (legalnr(l2, nr))
1544 setva(l2, nr);
1545 else
1546 nrerrorrecovery(fi);
1547 }
1548}
1549
1550static void
1551l2_got_FRMR(struct FsmInst *fi, int event, void *arg)
1552{
1553 struct layer2 *l2 = fi->userdata;
1554 struct sk_buff *skb = arg;
1555
1556 skb_pull(skb, l2addrsize(l2) + 1);
1557
1558 if (!(skb->data[0] & 1) || ((skb->data[0] & 3) == 1) || /* I or S */
1559 (IsUA(skb->data) && (fi->state == ST_L2_7))) {
1560 l2mgr(l2, MDL_ERROR_IND, (void *) 'K');
1561 establishlink(fi);
1562 test_and_clear_bit(FLG_L3_INIT, &l2->flag);
1563 }
1564 dev_kfree_skb(skb);
1565}
1566
1567static void
1568l2_st24_tei_remove(struct FsmInst *fi, int event, void *arg)
1569{
1570 struct layer2 *l2 = fi->userdata;
1571
1572 skb_queue_purge(&l2->ui_queue);
1573 l2->tei = GROUP_TEI;
1574 mISDN_FsmChangeState(fi, ST_L2_1);
1575}
1576
1577static void
1578l2_st3_tei_remove(struct FsmInst *fi, int event, void *arg)
1579{
1580 struct layer2 *l2 = fi->userdata;
1581
1582 skb_queue_purge(&l2->ui_queue);
1583 l2->tei = GROUP_TEI;
1584 l2up_create(l2, DL_RELEASE_IND, 0, NULL);
1585 mISDN_FsmChangeState(fi, ST_L2_1);
1586}
1587
1588static void
1589l2_st5_tei_remove(struct FsmInst *fi, int event, void *arg)
1590{
1591 struct layer2 *l2 = fi->userdata;
1592
1593 skb_queue_purge(&l2->i_queue);
1594 skb_queue_purge(&l2->ui_queue);
1595 freewin(l2);
1596 l2->tei = GROUP_TEI;
1597 stop_t200(l2, 17);
1598 st5_dl_release_l2l3(l2);
1599 mISDN_FsmChangeState(fi, ST_L2_1);
1600}
1601
1602static void
1603l2_st6_tei_remove(struct FsmInst *fi, int event, void *arg)
1604{
1605 struct layer2 *l2 = fi->userdata;
1606
1607 skb_queue_purge(&l2->ui_queue);
1608 l2->tei = GROUP_TEI;
1609 stop_t200(l2, 18);
1610 l2up_create(l2, DL_RELEASE_IND, 0, NULL);
1611 mISDN_FsmChangeState(fi, ST_L2_1);
1612}
1613
1614static void
1615l2_tei_remove(struct FsmInst *fi, int event, void *arg)
1616{
1617 struct layer2 *l2 = fi->userdata;
1618
1619 skb_queue_purge(&l2->i_queue);
1620 skb_queue_purge(&l2->ui_queue);
1621 freewin(l2);
1622 l2->tei = GROUP_TEI;
1623 stop_t200(l2, 17);
1624 mISDN_FsmDelTimer(&l2->t203, 19);
1625 l2up_create(l2, DL_RELEASE_IND, 0, NULL);
1626/* mISDN_queue_data(&l2->inst, l2->inst.id | MSG_BROADCAST,
1627 * MGR_SHORTSTATUS_IND, SSTATUS_L2_RELEASED,
1628 * 0, NULL, 0);
1629 */
1630 mISDN_FsmChangeState(fi, ST_L2_1);
1631}
1632
1633static void
1634l2_st14_persistant_da(struct FsmInst *fi, int event, void *arg)
1635{
1636 struct layer2 *l2 = fi->userdata;
1637 struct sk_buff *skb = arg;
1638
1639 skb_queue_purge(&l2->i_queue);
1640 skb_queue_purge(&l2->ui_queue);
1641 if (test_and_clear_bit(FLG_ESTAB_PEND, &l2->flag))
1642 l2up(l2, DL_RELEASE_IND, skb);
1643 else
1644 dev_kfree_skb(skb);
1645}
1646
1647static void
1648l2_st5_persistant_da(struct FsmInst *fi, int event, void *arg)
1649{
1650 struct layer2 *l2 = fi->userdata;
1651 struct sk_buff *skb = arg;
1652
1653 skb_queue_purge(&l2->i_queue);
1654 skb_queue_purge(&l2->ui_queue);
1655 freewin(l2);
1656 stop_t200(l2, 19);
1657 st5_dl_release_l2l3(l2);
1658 mISDN_FsmChangeState(fi, ST_L2_4);
1659 if (l2->tm)
1660 l2_tei(l2, MDL_STATUS_DOWN_IND, 0);
1661 dev_kfree_skb(skb);
1662}
1663
1664static void
1665l2_st6_persistant_da(struct FsmInst *fi, int event, void *arg)
1666{
1667 struct layer2 *l2 = fi->userdata;
1668 struct sk_buff *skb = arg;
1669
1670 skb_queue_purge(&l2->ui_queue);
1671 stop_t200(l2, 20);
1672 l2up(l2, DL_RELEASE_CNF, skb);
1673 mISDN_FsmChangeState(fi, ST_L2_4);
1674 if (l2->tm)
1675 l2_tei(l2, MDL_STATUS_DOWN_IND, 0);
1676}
1677
1678static void
1679l2_persistant_da(struct FsmInst *fi, int event, void *arg)
1680{
1681 struct layer2 *l2 = fi->userdata;
1682 struct sk_buff *skb = arg;
1683
1684 skb_queue_purge(&l2->i_queue);
1685 skb_queue_purge(&l2->ui_queue);
1686 freewin(l2);
1687 stop_t200(l2, 19);
1688 mISDN_FsmDelTimer(&l2->t203, 19);
1689 l2up(l2, DL_RELEASE_IND, skb);
1690 mISDN_FsmChangeState(fi, ST_L2_4);
1691 if (l2->tm)
1692 l2_tei(l2, MDL_STATUS_DOWN_IND, 0);
1693}
1694
1695static void
1696l2_set_own_busy(struct FsmInst *fi, int event, void *arg)
1697{
1698 struct layer2 *l2 = fi->userdata;
1699 struct sk_buff *skb = arg;
1700
1701 if (!test_and_set_bit(FLG_OWN_BUSY, &l2->flag)) {
1702 enquiry_cr(l2, RNR, RSP, 0);
1703 test_and_clear_bit(FLG_ACK_PEND, &l2->flag);
1704 }
1705 if (skb)
1706 dev_kfree_skb(skb);
1707}
1708
1709static void
1710l2_clear_own_busy(struct FsmInst *fi, int event, void *arg)
1711{
1712 struct layer2 *l2 = fi->userdata;
1713 struct sk_buff *skb = arg;
1714
1715 if (!test_and_clear_bit(FLG_OWN_BUSY, &l2->flag)) {
1716 enquiry_cr(l2, RR, RSP, 0);
1717 test_and_clear_bit(FLG_ACK_PEND, &l2->flag);
1718 }
1719 if (skb)
1720 dev_kfree_skb(skb);
1721}
1722
1723static void
1724l2_frame_error(struct FsmInst *fi, int event, void *arg)
1725{
1726 struct layer2 *l2 = fi->userdata;
1727
1728 l2mgr(l2, MDL_ERROR_IND, arg);
1729}
1730
1731static void
1732l2_frame_error_reest(struct FsmInst *fi, int event, void *arg)
1733{
1734 struct layer2 *l2 = fi->userdata;
1735
1736 l2mgr(l2, MDL_ERROR_IND, arg);
1737 establishlink(fi);
1738 test_and_clear_bit(FLG_L3_INIT, &l2->flag);
1739}
1740
1741static struct FsmNode L2FnList[] =
1742{
1743 {ST_L2_1, EV_L2_DL_ESTABLISH_REQ, l2_mdl_assign},
1744 {ST_L2_2, EV_L2_DL_ESTABLISH_REQ, l2_go_st3},
1745 {ST_L2_4, EV_L2_DL_ESTABLISH_REQ, l2_establish},
1746 {ST_L2_5, EV_L2_DL_ESTABLISH_REQ, l2_discard_i_setl3},
1747 {ST_L2_7, EV_L2_DL_ESTABLISH_REQ, l2_l3_reestablish},
1748 {ST_L2_8, EV_L2_DL_ESTABLISH_REQ, l2_l3_reestablish},
1749 {ST_L2_4, EV_L2_DL_RELEASE_REQ, l2_release},
1750 {ST_L2_5, EV_L2_DL_RELEASE_REQ, l2_pend_rel},
1751 {ST_L2_7, EV_L2_DL_RELEASE_REQ, l2_disconnect},
1752 {ST_L2_8, EV_L2_DL_RELEASE_REQ, l2_disconnect},
1753 {ST_L2_5, EV_L2_DL_DATA, l2_feed_i_if_reest},
1754 {ST_L2_7, EV_L2_DL_DATA, l2_feed_i_pull},
1755 {ST_L2_8, EV_L2_DL_DATA, l2_feed_iqueue},
1756 {ST_L2_1, EV_L2_DL_UNITDATA, l2_queue_ui_assign},
1757 {ST_L2_2, EV_L2_DL_UNITDATA, l2_queue_ui},
1758 {ST_L2_3, EV_L2_DL_UNITDATA, l2_queue_ui},
1759 {ST_L2_4, EV_L2_DL_UNITDATA, l2_send_ui},
1760 {ST_L2_5, EV_L2_DL_UNITDATA, l2_send_ui},
1761 {ST_L2_6, EV_L2_DL_UNITDATA, l2_send_ui},
1762 {ST_L2_7, EV_L2_DL_UNITDATA, l2_send_ui},
1763 {ST_L2_8, EV_L2_DL_UNITDATA, l2_send_ui},
1764 {ST_L2_1, EV_L2_MDL_ASSIGN, l2_got_tei},
1765 {ST_L2_2, EV_L2_MDL_ASSIGN, l2_got_tei},
1766 {ST_L2_3, EV_L2_MDL_ASSIGN, l2_got_tei},
1767 {ST_L2_2, EV_L2_MDL_ERROR, l2_st24_tei_remove},
1768 {ST_L2_3, EV_L2_MDL_ERROR, l2_st3_tei_remove},
1769 {ST_L2_4, EV_L2_MDL_REMOVE, l2_st24_tei_remove},
1770 {ST_L2_5, EV_L2_MDL_REMOVE, l2_st5_tei_remove},
1771 {ST_L2_6, EV_L2_MDL_REMOVE, l2_st6_tei_remove},
1772 {ST_L2_7, EV_L2_MDL_REMOVE, l2_tei_remove},
1773 {ST_L2_8, EV_L2_MDL_REMOVE, l2_tei_remove},
1774 {ST_L2_4, EV_L2_SABME, l2_start_multi},
1775 {ST_L2_5, EV_L2_SABME, l2_send_UA},
1776 {ST_L2_6, EV_L2_SABME, l2_send_DM},
1777 {ST_L2_7, EV_L2_SABME, l2_restart_multi},
1778 {ST_L2_8, EV_L2_SABME, l2_restart_multi},
1779 {ST_L2_4, EV_L2_DISC, l2_send_DM},
1780 {ST_L2_5, EV_L2_DISC, l2_send_DM},
1781 {ST_L2_6, EV_L2_DISC, l2_send_UA},
1782 {ST_L2_7, EV_L2_DISC, l2_stop_multi},
1783 {ST_L2_8, EV_L2_DISC, l2_stop_multi},
1784 {ST_L2_4, EV_L2_UA, l2_mdl_error_ua},
1785 {ST_L2_5, EV_L2_UA, l2_connected},
1786 {ST_L2_6, EV_L2_UA, l2_released},
1787 {ST_L2_7, EV_L2_UA, l2_mdl_error_ua},
1788 {ST_L2_8, EV_L2_UA, l2_mdl_error_ua},
1789 {ST_L2_4, EV_L2_DM, l2_reestablish},
1790 {ST_L2_5, EV_L2_DM, l2_st5_dm_release},
1791 {ST_L2_6, EV_L2_DM, l2_st6_dm_release},
1792 {ST_L2_7, EV_L2_DM, l2_mdl_error_dm},
1793 {ST_L2_8, EV_L2_DM, l2_st8_mdl_error_dm},
1794 {ST_L2_1, EV_L2_UI, l2_got_ui},
1795 {ST_L2_2, EV_L2_UI, l2_got_ui},
1796 {ST_L2_3, EV_L2_UI, l2_got_ui},
1797 {ST_L2_4, EV_L2_UI, l2_got_ui},
1798 {ST_L2_5, EV_L2_UI, l2_got_ui},
1799 {ST_L2_6, EV_L2_UI, l2_got_ui},
1800 {ST_L2_7, EV_L2_UI, l2_got_ui},
1801 {ST_L2_8, EV_L2_UI, l2_got_ui},
1802 {ST_L2_7, EV_L2_FRMR, l2_got_FRMR},
1803 {ST_L2_8, EV_L2_FRMR, l2_got_FRMR},
1804 {ST_L2_7, EV_L2_SUPER, l2_st7_got_super},
1805 {ST_L2_8, EV_L2_SUPER, l2_st8_got_super},
1806 {ST_L2_7, EV_L2_I, l2_got_iframe},
1807 {ST_L2_8, EV_L2_I, l2_got_iframe},
1808 {ST_L2_5, EV_L2_T200, l2_st5_tout_200},
1809 {ST_L2_6, EV_L2_T200, l2_st6_tout_200},
1810 {ST_L2_7, EV_L2_T200, l2_st7_tout_200},
1811 {ST_L2_8, EV_L2_T200, l2_st8_tout_200},
1812 {ST_L2_7, EV_L2_T203, l2_st7_tout_203},
1813 {ST_L2_7, EV_L2_ACK_PULL, l2_pull_iqueue},
1814 {ST_L2_7, EV_L2_SET_OWN_BUSY, l2_set_own_busy},
1815 {ST_L2_8, EV_L2_SET_OWN_BUSY, l2_set_own_busy},
1816 {ST_L2_7, EV_L2_CLEAR_OWN_BUSY, l2_clear_own_busy},
1817 {ST_L2_8, EV_L2_CLEAR_OWN_BUSY, l2_clear_own_busy},
1818 {ST_L2_4, EV_L2_FRAME_ERROR, l2_frame_error},
1819 {ST_L2_5, EV_L2_FRAME_ERROR, l2_frame_error},
1820 {ST_L2_6, EV_L2_FRAME_ERROR, l2_frame_error},
1821 {ST_L2_7, EV_L2_FRAME_ERROR, l2_frame_error_reest},
1822 {ST_L2_8, EV_L2_FRAME_ERROR, l2_frame_error_reest},
1823 {ST_L2_1, EV_L1_DEACTIVATE, l2_st14_persistant_da},
1824 {ST_L2_2, EV_L1_DEACTIVATE, l2_st24_tei_remove},
1825 {ST_L2_3, EV_L1_DEACTIVATE, l2_st3_tei_remove},
1826 {ST_L2_4, EV_L1_DEACTIVATE, l2_st14_persistant_da},
1827 {ST_L2_5, EV_L1_DEACTIVATE, l2_st5_persistant_da},
1828 {ST_L2_6, EV_L1_DEACTIVATE, l2_st6_persistant_da},
1829 {ST_L2_7, EV_L1_DEACTIVATE, l2_persistant_da},
1830 {ST_L2_8, EV_L1_DEACTIVATE, l2_persistant_da},
1831};
1832
1833#define L2_FN_COUNT (sizeof(L2FnList)/sizeof(struct FsmNode))
1834
1835static int
1836ph_data_indication(struct layer2 *l2, struct mISDNhead *hh, struct sk_buff *skb)
1837{
1838 u_char *datap = skb->data;
1839 int ret = -EINVAL;
1840 int psapi, ptei;
1841 u_int l;
1842 int c = 0;
1843
1844 l = l2addrsize(l2);
1845 if (skb->len <= l) {
1846 mISDN_FsmEvent(&l2->l2m, EV_L2_FRAME_ERROR, (void *) 'N');
1847 return ret;
1848 }
1849 if (test_bit(FLG_LAPD, &l2->flag)) { /* Maybe not needed */
1850 psapi = *datap++;
1851 ptei = *datap++;
1852 if ((psapi & 1) || !(ptei & 1)) {
1853 printk(KERN_WARNING
1854 "l2 D-channel frame wrong EA0/EA1\n");
1855 return ret;
1856 }
1857 psapi >>= 2;
1858 ptei >>= 1;
1859 if (psapi != l2->sapi) {
1860 /* not our bussiness
1861 * printk(KERN_DEBUG "%s: sapi %d/%d sapi mismatch\n",
1862 * __func__,
1863 * psapi, l2->sapi);
1864 */
1865 dev_kfree_skb(skb);
1866 return 0;
1867 }
1868 if ((ptei != l2->tei) && (ptei != GROUP_TEI)) {
1869 /* not our bussiness
1870 * printk(KERN_DEBUG "%s: tei %d/%d sapi %d mismatch\n",
1871 * __func__,
1872 * ptei, l2->tei, psapi);
1873 */
1874 dev_kfree_skb(skb);
1875 return 0;
1876 }
1877 } else
1878 datap += l;
1879 if (!(*datap & 1)) { /* I-Frame */
1880 c = iframe_error(l2, skb);
1881 if (!c)
1882 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_I, skb);
1883 } else if (IsSFrame(datap, l2)) { /* S-Frame */
1884 c = super_error(l2, skb);
1885 if (!c)
1886 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_SUPER, skb);
1887 } else if (IsUI(datap)) {
1888 c = UI_error(l2, skb);
1889 if (!c)
1890 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_UI, skb);
1891 } else if (IsSABME(datap, l2)) {
1892 c = unnum_error(l2, skb, CMD);
1893 if (!c)
1894 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_SABME, skb);
1895 } else if (IsUA(datap)) {
1896 c = unnum_error(l2, skb, RSP);
1897 if (!c)
1898 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_UA, skb);
1899 } else if (IsDISC(datap)) {
1900 c = unnum_error(l2, skb, CMD);
1901 if (!c)
1902 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_DISC, skb);
1903 } else if (IsDM(datap)) {
1904 c = unnum_error(l2, skb, RSP);
1905 if (!c)
1906 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_DM, skb);
1907 } else if (IsFRMR(datap)) {
1908 c = FRMR_error(l2, skb);
1909 if (!c)
1910 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_FRMR, skb);
1911 } else
1912 c = 'L';
1913 if (c) {
1914 printk(KERN_WARNING "l2 D-channel frame error %c\n", c);
1915 mISDN_FsmEvent(&l2->l2m, EV_L2_FRAME_ERROR, (void *)(long)c);
1916 }
1917 return ret;
1918}
1919
1920static int
1921l2_send(struct mISDNchannel *ch, struct sk_buff *skb)
1922{
1923 struct layer2 *l2 = container_of(ch, struct layer2, ch);
1924 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1925 int ret = -EINVAL;
1926
1927 if (*debug & DEBUG_L2_RECV)
1928 printk(KERN_DEBUG "%s: prim(%x) id(%x) tei(%d)\n",
1929 __func__, hh->prim, hh->id, l2->tei);
1930 switch (hh->prim) {
1931 case PH_DATA_IND:
1932 ret = ph_data_indication(l2, hh, skb);
1933 break;
1934 case PH_DATA_CNF:
1935 ret = ph_data_confirm(l2, hh, skb);
1936 break;
1937 case PH_ACTIVATE_IND:
1938 test_and_set_bit(FLG_L1_ACTIV, &l2->flag);
1939 l2up_create(l2, MPH_ACTIVATE_IND, 0, NULL);
1940 if (test_and_clear_bit(FLG_ESTAB_PEND, &l2->flag))
1941 ret = mISDN_FsmEvent(&l2->l2m,
1942 EV_L2_DL_ESTABLISH_REQ, skb);
1943 break;
1944 case PH_DEACTIVATE_IND:
1945 test_and_clear_bit(FLG_L1_ACTIV, &l2->flag);
1946 l2up_create(l2, MPH_DEACTIVATE_IND, 0, NULL);
1947 ret = mISDN_FsmEvent(&l2->l2m, EV_L1_DEACTIVATE, skb);
1948 break;
1949 case MPH_INFORMATION_IND:
1950 if (!l2->up)
1951 break;
1952 ret = l2->up->send(l2->up, skb);
1953 break;
1954 case DL_DATA_REQ:
1955 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_DL_DATA, skb);
1956 break;
1957 case DL_UNITDATA_REQ:
1958 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_DL_UNITDATA, skb);
1959 break;
1960 case DL_ESTABLISH_REQ:
1961 if (test_bit(FLG_LAPB, &l2->flag))
1962 test_and_set_bit(FLG_ORIG, &l2->flag);
1963 if (test_bit(FLG_L1_ACTIV, &l2->flag)) {
1964 if (test_bit(FLG_LAPD, &l2->flag) ||
1965 test_bit(FLG_ORIG, &l2->flag))
1966 ret = mISDN_FsmEvent(&l2->l2m,
1967 EV_L2_DL_ESTABLISH_REQ, skb);
1968 } else {
1969 if (test_bit(FLG_LAPD, &l2->flag) ||
1970 test_bit(FLG_ORIG, &l2->flag)) {
1971 test_and_set_bit(FLG_ESTAB_PEND,
1972 &l2->flag);
1973 }
1974 ret = l2down(l2, PH_ACTIVATE_REQ, l2_newid(l2),
1975 skb);
1976 }
1977 break;
1978 case DL_RELEASE_REQ:
1979 if (test_bit(FLG_LAPB, &l2->flag))
1980 l2down_create(l2, PH_DEACTIVATE_REQ,
1981 l2_newid(l2), 0, NULL);
1982 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_DL_RELEASE_REQ,
1983 skb);
1984 break;
1985 default:
1986 if (*debug & DEBUG_L2)
1987 l2m_debug(&l2->l2m, "l2 unknown pr %04x",
1988 hh->prim);
1989 }
1990 if (ret) {
1991 dev_kfree_skb(skb);
1992 ret = 0;
1993 }
1994 return ret;
1995}
1996
1997int
1998tei_l2(struct layer2 *l2, u_int cmd, u_long arg)
1999{
2000 int ret = -EINVAL;
2001
2002 if (*debug & DEBUG_L2_TEI)
2003 printk(KERN_DEBUG "%s: cmd(%x)\n", __func__, cmd);
2004 switch (cmd) {
2005 case (MDL_ASSIGN_REQ):
2006 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_MDL_ASSIGN, (void *)arg);
2007 break;
2008 case (MDL_REMOVE_REQ):
2009 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_MDL_REMOVE, NULL);
2010 break;
2011 case (MDL_ERROR_IND):
2012 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_MDL_ERROR, NULL);
2013 break;
2014 case (MDL_ERROR_RSP):
2015 /* ETS 300-125 5.3.2.1 Test: TC13010 */
2016 printk(KERN_NOTICE "MDL_ERROR|REQ (tei_l2)\n");
2017 ret = mISDN_FsmEvent(&l2->l2m, EV_L2_MDL_ERROR, NULL);
2018 break;
2019 }
2020 return ret;
2021}
2022
2023static void
2024release_l2(struct layer2 *l2)
2025{
2026 mISDN_FsmDelTimer(&l2->t200, 21);
2027 mISDN_FsmDelTimer(&l2->t203, 16);
2028 skb_queue_purge(&l2->i_queue);
2029 skb_queue_purge(&l2->ui_queue);
2030 skb_queue_purge(&l2->down_queue);
2031 ReleaseWin(l2);
2032 if (test_bit(FLG_LAPD, &l2->flag)) {
2033 release_tei(l2);
2034 if (l2->ch.st)
2035 l2->ch.st->dev->D.ctrl(&l2->ch.st->dev->D,
2036 CLOSE_CHANNEL, NULL);
2037 }
2038 kfree(l2);
2039}
2040
2041static int
2042l2_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
2043{
2044 struct layer2 *l2 = container_of(ch, struct layer2, ch);
2045 u_int info;
2046
2047 if (*debug & DEBUG_L2_CTRL)
2048 printk(KERN_DEBUG "%s:(%x)\n", __func__, cmd);
2049
2050 switch (cmd) {
2051 case OPEN_CHANNEL:
2052 if (test_bit(FLG_LAPD, &l2->flag)) {
2053 set_channel_address(&l2->ch, l2->sapi, l2->tei);
2054 info = DL_INFO_L2_CONNECT;
2055 l2up_create(l2, DL_INFORMATION_IND,
2056 sizeof(info), &info);
2057 }
2058 break;
2059 case CLOSE_CHANNEL:
2060 if (l2->ch.peer)
2061 l2->ch.peer->ctrl(l2->ch.peer, CLOSE_CHANNEL, NULL);
2062 release_l2(l2);
2063 break;
2064 }
2065 return 0;
2066}
2067
2068struct layer2 *
2069create_l2(struct mISDNchannel *ch, u_int protocol, u_long options, u_long arg)
2070{
2071 struct layer2 *l2;
2072 struct channel_req rq;
2073
2074 l2 = kzalloc(sizeof(struct layer2), GFP_KERNEL);
2075 if (!l2) {
2076 printk(KERN_ERR "kzalloc layer2 failed\n");
2077 return NULL;
2078 }
2079 l2->next_id = 1;
2080 l2->down_id = MISDN_ID_NONE;
2081 l2->up = ch;
2082 l2->ch.st = ch->st;
2083 l2->ch.send = l2_send;
2084 l2->ch.ctrl = l2_ctrl;
2085 switch (protocol) {
2086 case ISDN_P_LAPD_NT:
2087 test_and_set_bit(FLG_LAPD, &l2->flag);
2088 test_and_set_bit(FLG_LAPD_NET, &l2->flag);
2089 test_and_set_bit(FLG_MOD128, &l2->flag);
2090 l2->sapi = 0;
2091 l2->maxlen = MAX_DFRAME_LEN;
2092 if (test_bit(OPTION_L2_PMX, &options))
2093 l2->window = 7;
2094 else
2095 l2->window = 1;
2096 if (test_bit(OPTION_L2_PTP, &options))
2097 test_and_set_bit(FLG_PTP, &l2->flag);
2098 if (test_bit(OPTION_L2_FIXEDTEI, &options))
2099 test_and_set_bit(FLG_FIXED_TEI, &l2->flag);
2100 l2->tei = (u_int)arg;
2101 l2->T200 = 1000;
2102 l2->N200 = 3;
2103 l2->T203 = 10000;
2104 if (test_bit(OPTION_L2_PMX, &options))
2105 rq.protocol = ISDN_P_NT_E1;
2106 else
2107 rq.protocol = ISDN_P_NT_S0;
2108 rq.adr.channel = 0;
2109 l2->ch.st->dev->D.ctrl(&l2->ch.st->dev->D, OPEN_CHANNEL, &rq);
2110 break;
2111 case ISDN_P_LAPD_TE:
2112 test_and_set_bit(FLG_LAPD, &l2->flag);
2113 test_and_set_bit(FLG_MOD128, &l2->flag);
2114 test_and_set_bit(FLG_ORIG, &l2->flag);
2115 l2->sapi = 0;
2116 l2->maxlen = MAX_DFRAME_LEN;
2117 if (test_bit(OPTION_L2_PMX, &options))
2118 l2->window = 7;
2119 else
2120 l2->window = 1;
2121 if (test_bit(OPTION_L2_PTP, &options))
2122 test_and_set_bit(FLG_PTP, &l2->flag);
2123 if (test_bit(OPTION_L2_FIXEDTEI, &options))
2124 test_and_set_bit(FLG_FIXED_TEI, &l2->flag);
2125 l2->tei = (u_int)arg;
2126 l2->T200 = 1000;
2127 l2->N200 = 3;
2128 l2->T203 = 10000;
2129 if (test_bit(OPTION_L2_PMX, &options))
2130 rq.protocol = ISDN_P_TE_E1;
2131 else
2132 rq.protocol = ISDN_P_TE_S0;
2133 rq.adr.channel = 0;
2134 l2->ch.st->dev->D.ctrl(&l2->ch.st->dev->D, OPEN_CHANNEL, &rq);
2135 break;
2136 case ISDN_P_B_X75SLP:
2137 test_and_set_bit(FLG_LAPB, &l2->flag);
2138 l2->window = 7;
2139 l2->maxlen = MAX_DATA_SIZE;
2140 l2->T200 = 1000;
2141 l2->N200 = 4;
2142 l2->T203 = 5000;
2143 l2->addr.A = 3;
2144 l2->addr.B = 1;
2145 break;
2146 default:
2147 printk(KERN_ERR "layer2 create failed prt %x\n",
2148 protocol);
2149 kfree(l2);
2150 return NULL;
2151 }
2152 skb_queue_head_init(&l2->i_queue);
2153 skb_queue_head_init(&l2->ui_queue);
2154 skb_queue_head_init(&l2->down_queue);
2155 skb_queue_head_init(&l2->tmp_queue);
2156 InitWin(l2);
2157 l2->l2m.fsm = &l2fsm;
2158 if (test_bit(FLG_LAPB, &l2->flag) ||
2159 test_bit(FLG_PTP, &l2->flag) ||
2160 test_bit(FLG_LAPD_NET, &l2->flag))
2161 l2->l2m.state = ST_L2_4;
2162 else
2163 l2->l2m.state = ST_L2_1;
2164 l2->l2m.debug = *debug;
2165 l2->l2m.userdata = l2;
2166 l2->l2m.userint = 0;
2167 l2->l2m.printdebug = l2m_debug;
2168
2169 mISDN_FsmInitTimer(&l2->l2m, &l2->t200);
2170 mISDN_FsmInitTimer(&l2->l2m, &l2->t203);
2171 return l2;
2172}
2173
2174static int
2175x75create(struct channel_req *crq)
2176{
2177 struct layer2 *l2;
2178
2179 if (crq->protocol != ISDN_P_B_X75SLP)
2180 return -EPROTONOSUPPORT;
2181 l2 = create_l2(crq->ch, crq->protocol, 0, 0);
2182 if (!l2)
2183 return -ENOMEM;
2184 crq->ch = &l2->ch;
2185 crq->protocol = ISDN_P_B_HDLC;
2186 return 0;
2187}
2188
2189static struct Bprotocol X75SLP = {
2190 .Bprotocols = (1 << (ISDN_P_B_X75SLP & ISDN_P_B_MASK)),
2191 .name = "X75SLP",
2192 .create = x75create
2193};
2194
2195int
2196Isdnl2_Init(u_int *deb)
2197{
2198 debug = deb;
2199 mISDN_register_Bprotocol(&X75SLP);
2200 l2fsm.state_count = L2_STATE_COUNT;
2201 l2fsm.event_count = L2_EVENT_COUNT;
2202 l2fsm.strEvent = strL2Event;
2203 l2fsm.strState = strL2State;
2204 mISDN_FsmNew(&l2fsm, L2FnList, ARRAY_SIZE(L2FnList));
2205 TEIInit(deb);
2206 return 0;
2207}
2208
2209void
2210Isdnl2_cleanup(void)
2211{
2212 mISDN_unregister_Bprotocol(&X75SLP);
2213 TEIFree();
2214 mISDN_FsmFree(&l2fsm);
2215}
2216
diff --git a/drivers/isdn/mISDN/layer2.h b/drivers/isdn/mISDN/layer2.h
new file mode 100644
index 000000000000..de2dd02056a3
--- /dev/null
+++ b/drivers/isdn/mISDN/layer2.h
@@ -0,0 +1,140 @@
1/*
2 * Layer 2 defines
3 *
4 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/mISDNif.h>
18#include <linux/skbuff.h>
19#include "fsm.h"
20
21#define MAX_WINDOW 8
22
23struct manager {
24 struct mISDNchannel ch;
25 struct mISDNchannel bcast;
26 u_long options;
27 struct list_head layer2;
28 rwlock_t lock;
29 struct FsmInst deact;
30 struct FsmTimer datimer;
31 struct sk_buff_head sendq;
32 struct mISDNchannel *up;
33 u_int nextid;
34 u_int lastid;
35};
36
37struct teimgr {
38 int ri;
39 int rcnt;
40 struct FsmInst tei_m;
41 struct FsmTimer timer;
42 int tval, nval;
43 struct layer2 *l2;
44 struct manager *mgr;
45};
46
47struct laddr {
48 u_char A;
49 u_char B;
50};
51
52struct layer2 {
53 struct list_head list;
54 struct mISDNchannel ch;
55 u_long flag;
56 int id;
57 struct mISDNchannel *up;
58 signed char sapi;
59 signed char tei;
60 struct laddr addr;
61 u_int maxlen;
62 struct teimgr *tm;
63 u_int vs, va, vr;
64 int rc;
65 u_int window;
66 u_int sow;
67 struct FsmInst l2m;
68 struct FsmTimer t200, t203;
69 int T200, N200, T203;
70 u_int next_id;
71 u_int down_id;
72 struct sk_buff *windowar[MAX_WINDOW];
73 struct sk_buff_head i_queue;
74 struct sk_buff_head ui_queue;
75 struct sk_buff_head down_queue;
76 struct sk_buff_head tmp_queue;
77};
78
79enum {
80 ST_L2_1,
81 ST_L2_2,
82 ST_L2_3,
83 ST_L2_4,
84 ST_L2_5,
85 ST_L2_6,
86 ST_L2_7,
87 ST_L2_8,
88};
89
90#define L2_STATE_COUNT (ST_L2_8+1)
91
92extern struct layer2 *create_l2(struct mISDNchannel *, u_int,
93 u_long, u_long);
94extern int tei_l2(struct layer2 *, u_int, u_long arg);
95
96
97/* from tei.c */
98extern int l2_tei(struct layer2 *, u_int, u_long arg);
99extern void release_tei(struct layer2 *);
100extern int TEIInit(u_int *);
101extern void TEIFree(void);
102
103#define MAX_L2HEADER_LEN 4
104
105#define RR 0x01
106#define RNR 0x05
107#define REJ 0x09
108#define SABME 0x6f
109#define SABM 0x2f
110#define DM 0x0f
111#define UI 0x03
112#define DISC 0x43
113#define UA 0x63
114#define FRMR 0x87
115#define XID 0xaf
116
117#define CMD 0
118#define RSP 1
119
120#define LC_FLUSH_WAIT 1
121
122#define FLG_LAPB 0
123#define FLG_LAPD 1
124#define FLG_ORIG 2
125#define FLG_MOD128 3
126#define FLG_PEND_REL 4
127#define FLG_L3_INIT 5
128#define FLG_T200_RUN 6
129#define FLG_ACK_PEND 7
130#define FLG_REJEXC 8
131#define FLG_OWN_BUSY 9
132#define FLG_PEER_BUSY 10
133#define FLG_DCHAN_BUSY 11
134#define FLG_L1_ACTIV 12
135#define FLG_ESTAB_PEND 13
136#define FLG_PTP 14
137#define FLG_FIXED_TEI 15
138#define FLG_L2BLOCK 16
139#define FLG_L1_NOTREADY 17
140#define FLG_LAPD_NET 18
diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c
new file mode 100644
index 000000000000..4ba4cc364c9e
--- /dev/null
+++ b/drivers/isdn/mISDN/socket.c
@@ -0,0 +1,781 @@
1/*
2 *
3 * Author Karsten Keil <kkeil@novell.com>
4 *
5 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#include <linux/mISDNif.h>
19#include "core.h"
20
21static int *debug;
22
23static struct proto mISDN_proto = {
24 .name = "misdn",
25 .owner = THIS_MODULE,
26 .obj_size = sizeof(struct mISDN_sock)
27};
28
29#define _pms(sk) ((struct mISDN_sock *)sk)
30
31static struct mISDN_sock_list data_sockets = {
32 .lock = __RW_LOCK_UNLOCKED(data_sockets.lock)
33};
34
35static struct mISDN_sock_list base_sockets = {
36 .lock = __RW_LOCK_UNLOCKED(base_sockets.lock)
37};
38
39#define L2_HEADER_LEN 4
40
41static inline struct sk_buff *
42_l2_alloc_skb(unsigned int len, gfp_t gfp_mask)
43{
44 struct sk_buff *skb;
45
46 skb = alloc_skb(len + L2_HEADER_LEN, gfp_mask);
47 if (likely(skb))
48 skb_reserve(skb, L2_HEADER_LEN);
49 return skb;
50}
51
52static void
53mISDN_sock_link(struct mISDN_sock_list *l, struct sock *sk)
54{
55 write_lock_bh(&l->lock);
56 sk_add_node(sk, &l->head);
57 write_unlock_bh(&l->lock);
58}
59
60static void mISDN_sock_unlink(struct mISDN_sock_list *l, struct sock *sk)
61{
62 write_lock_bh(&l->lock);
63 sk_del_node_init(sk);
64 write_unlock_bh(&l->lock);
65}
66
67static int
68mISDN_send(struct mISDNchannel *ch, struct sk_buff *skb)
69{
70 struct mISDN_sock *msk;
71 int err;
72
73 msk = container_of(ch, struct mISDN_sock, ch);
74 if (*debug & DEBUG_SOCKET)
75 printk(KERN_DEBUG "%s len %d %p\n", __func__, skb->len, skb);
76 if (msk->sk.sk_state == MISDN_CLOSED)
77 return -EUNATCH;
78 __net_timestamp(skb);
79 err = sock_queue_rcv_skb(&msk->sk, skb);
80 if (err)
81 printk(KERN_WARNING "%s: error %d\n", __func__, err);
82 return err;
83}
84
85static int
86mISDN_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
87{
88 struct mISDN_sock *msk;
89
90 msk = container_of(ch, struct mISDN_sock, ch);
91 if (*debug & DEBUG_SOCKET)
92 printk(KERN_DEBUG "%s(%p, %x, %p)\n", __func__, ch, cmd, arg);
93 switch (cmd) {
94 case CLOSE_CHANNEL:
95 msk->sk.sk_state = MISDN_CLOSED;
96 break;
97 }
98 return 0;
99}
100
101static inline void
102mISDN_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_buff *skb)
103{
104 struct timeval tv;
105
106 if (_pms(sk)->cmask & MISDN_TIME_STAMP) {
107 skb_get_timestamp(skb, &tv);
108 put_cmsg(msg, SOL_MISDN, MISDN_TIME_STAMP, sizeof(tv), &tv);
109 }
110}
111
112static int
113mISDN_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
114 struct msghdr *msg, size_t len, int flags)
115{
116 struct sk_buff *skb;
117 struct sock *sk = sock->sk;
118 struct sockaddr_mISDN *maddr;
119
120 int copied, err;
121
122 if (*debug & DEBUG_SOCKET)
123 printk(KERN_DEBUG "%s: len %d, flags %x ch.nr %d, proto %x\n",
124 __func__, (int)len, flags, _pms(sk)->ch.nr,
125 sk->sk_protocol);
126 if (flags & (MSG_OOB))
127 return -EOPNOTSUPP;
128
129 if (sk->sk_state == MISDN_CLOSED)
130 return 0;
131
132 skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &err);
133 if (!skb)
134 return err;
135
136 if (msg->msg_namelen >= sizeof(struct sockaddr_mISDN)) {
137 msg->msg_namelen = sizeof(struct sockaddr_mISDN);
138 maddr = (struct sockaddr_mISDN *)msg->msg_name;
139 maddr->family = AF_ISDN;
140 maddr->dev = _pms(sk)->dev->id;
141 if ((sk->sk_protocol == ISDN_P_LAPD_TE) ||
142 (sk->sk_protocol == ISDN_P_LAPD_NT)) {
143 maddr->channel = (mISDN_HEAD_ID(skb) >> 16) & 0xff;
144 maddr->tei = (mISDN_HEAD_ID(skb) >> 8) & 0xff;
145 maddr->sapi = mISDN_HEAD_ID(skb) & 0xff;
146 } else {
147 maddr->channel = _pms(sk)->ch.nr;
148 maddr->sapi = _pms(sk)->ch.addr & 0xFF;
149 maddr->tei = (_pms(sk)->ch.addr >> 8) & 0xFF;
150 }
151 } else {
152 if (msg->msg_namelen)
153 printk(KERN_WARNING "%s: too small namelen %d\n",
154 __func__, msg->msg_namelen);
155 msg->msg_namelen = 0;
156 }
157
158 copied = skb->len + MISDN_HEADER_LEN;
159 if (len < copied) {
160 if (flags & MSG_PEEK)
161 atomic_dec(&skb->users);
162 else
163 skb_queue_head(&sk->sk_receive_queue, skb);
164 return -ENOSPC;
165 }
166 memcpy(skb_push(skb, MISDN_HEADER_LEN), mISDN_HEAD_P(skb),
167 MISDN_HEADER_LEN);
168
169 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
170
171 mISDN_sock_cmsg(sk, msg, skb);
172
173 skb_free_datagram(sk, skb);
174
175 return err ? : copied;
176}
177
178static int
179mISDN_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
180 struct msghdr *msg, size_t len)
181{
182 struct sock *sk = sock->sk;
183 struct sk_buff *skb;
184 int err = -ENOMEM;
185 struct sockaddr_mISDN *maddr;
186
187 if (*debug & DEBUG_SOCKET)
188 printk(KERN_DEBUG "%s: len %d flags %x ch %d proto %x\n",
189 __func__, (int)len, msg->msg_flags, _pms(sk)->ch.nr,
190 sk->sk_protocol);
191
192 if (msg->msg_flags & MSG_OOB)
193 return -EOPNOTSUPP;
194
195 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_NOSIGNAL|MSG_ERRQUEUE))
196 return -EINVAL;
197
198 if (len < MISDN_HEADER_LEN)
199 return -EINVAL;
200
201 if (sk->sk_state != MISDN_BOUND)
202 return -EBADFD;
203
204 lock_sock(sk);
205
206 skb = _l2_alloc_skb(len, GFP_KERNEL);
207 if (!skb)
208 goto done;
209
210 if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) {
211 err = -EFAULT;
212 goto drop;
213 }
214
215 memcpy(mISDN_HEAD_P(skb), skb->data, MISDN_HEADER_LEN);
216 skb_pull(skb, MISDN_HEADER_LEN);
217
218 if (msg->msg_namelen >= sizeof(struct sockaddr_mISDN)) {
219 /* if we have a address, we use it */
220 maddr = (struct sockaddr_mISDN *)msg->msg_name;
221 mISDN_HEAD_ID(skb) = maddr->channel;
222 } else { /* use default for L2 messages */
223 if ((sk->sk_protocol == ISDN_P_LAPD_TE) ||
224 (sk->sk_protocol == ISDN_P_LAPD_NT))
225 mISDN_HEAD_ID(skb) = _pms(sk)->ch.nr;
226 }
227
228 if (*debug & DEBUG_SOCKET)
229 printk(KERN_DEBUG "%s: ID:%x\n",
230 __func__, mISDN_HEAD_ID(skb));
231
232 err = -ENODEV;
233 if (!_pms(sk)->ch.peer ||
234 (err = _pms(sk)->ch.recv(_pms(sk)->ch.peer, skb)))
235 goto drop;
236
237 err = len;
238
239done:
240 release_sock(sk);
241 return err;
242
243drop:
244 kfree_skb(skb);
245 goto done;
246}
247
248static int
249data_sock_release(struct socket *sock)
250{
251 struct sock *sk = sock->sk;
252
253 if (*debug & DEBUG_SOCKET)
254 printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
255 if (!sk)
256 return 0;
257 switch (sk->sk_protocol) {
258 case ISDN_P_TE_S0:
259 case ISDN_P_NT_S0:
260 case ISDN_P_TE_E1:
261 case ISDN_P_NT_E1:
262 if (sk->sk_state == MISDN_BOUND)
263 delete_channel(&_pms(sk)->ch);
264 else
265 mISDN_sock_unlink(&data_sockets, sk);
266 break;
267 case ISDN_P_LAPD_TE:
268 case ISDN_P_LAPD_NT:
269 case ISDN_P_B_RAW:
270 case ISDN_P_B_HDLC:
271 case ISDN_P_B_X75SLP:
272 case ISDN_P_B_L2DTMF:
273 case ISDN_P_B_L2DSP:
274 case ISDN_P_B_L2DSPHDLC:
275 delete_channel(&_pms(sk)->ch);
276 mISDN_sock_unlink(&data_sockets, sk);
277 break;
278 }
279
280 lock_sock(sk);
281
282 sock_orphan(sk);
283 skb_queue_purge(&sk->sk_receive_queue);
284
285 release_sock(sk);
286 sock_put(sk);
287
288 return 0;
289}
290
291static int
292data_sock_ioctl_bound(struct sock *sk, unsigned int cmd, void __user *p)
293{
294 struct mISDN_ctrl_req cq;
295 int err = -EINVAL, val;
296 struct mISDNchannel *bchan, *next;
297
298 lock_sock(sk);
299 if (!_pms(sk)->dev) {
300 err = -ENODEV;
301 goto done;
302 }
303 switch (cmd) {
304 case IMCTRLREQ:
305 if (copy_from_user(&cq, p, sizeof(cq))) {
306 err = -EFAULT;
307 break;
308 }
309 if ((sk->sk_protocol & ~ISDN_P_B_MASK) == ISDN_P_B_START) {
310 list_for_each_entry_safe(bchan, next,
311 &_pms(sk)->dev->bchannels, list) {
312 if (bchan->nr == cq.channel) {
313 err = bchan->ctrl(bchan,
314 CONTROL_CHANNEL, &cq);
315 break;
316 }
317 }
318 } else
319 err = _pms(sk)->dev->D.ctrl(&_pms(sk)->dev->D,
320 CONTROL_CHANNEL, &cq);
321 if (err)
322 break;
323 if (copy_to_user(p, &cq, sizeof(cq)))
324 err = -EFAULT;
325 break;
326 case IMCLEAR_L2:
327 if (sk->sk_protocol != ISDN_P_LAPD_NT) {
328 err = -EINVAL;
329 break;
330 }
331 if (get_user(val, (int __user *)p)) {
332 err = -EFAULT;
333 break;
334 }
335 err = _pms(sk)->dev->teimgr->ctrl(_pms(sk)->dev->teimgr,
336 CONTROL_CHANNEL, &val);
337 break;
338 default:
339 err = -EINVAL;
340 break;
341 }
342done:
343 release_sock(sk);
344 return err;
345}
346
347static int
348data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
349{
350 int err = 0, id;
351 struct sock *sk = sock->sk;
352 struct mISDNdevice *dev;
353 struct mISDNversion ver;
354
355 switch (cmd) {
356 case IMGETVERSION:
357 ver.major = MISDN_MAJOR_VERSION;
358 ver.minor = MISDN_MINOR_VERSION;
359 ver.release = MISDN_RELEASE;
360 if (copy_to_user((void __user *)arg, &ver, sizeof(ver)))
361 err = -EFAULT;
362 break;
363 case IMGETCOUNT:
364 id = get_mdevice_count();
365 if (put_user(id, (int __user *)arg))
366 err = -EFAULT;
367 break;
368 case IMGETDEVINFO:
369 if (get_user(id, (int __user *)arg)) {
370 err = -EFAULT;
371 break;
372 }
373 dev = get_mdevice(id);
374 if (dev) {
375 struct mISDN_devinfo di;
376
377 di.id = dev->id;
378 di.Dprotocols = dev->Dprotocols;
379 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
380 di.protocol = dev->D.protocol;
381 memcpy(di.channelmap, dev->channelmap,
382 MISDN_CHMAP_SIZE * 4);
383 di.nrbchan = dev->nrbchan;
384 strcpy(di.name, dev->name);
385 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
386 err = -EFAULT;
387 } else
388 err = -ENODEV;
389 break;
390 default:
391 if (sk->sk_state == MISDN_BOUND)
392 err = data_sock_ioctl_bound(sk, cmd,
393 (void __user *)arg);
394 else
395 err = -ENOTCONN;
396 }
397 return err;
398}
399
400static int data_sock_setsockopt(struct socket *sock, int level, int optname,
401 char __user *optval, int len)
402{
403 struct sock *sk = sock->sk;
404 int err = 0, opt = 0;
405
406 if (*debug & DEBUG_SOCKET)
407 printk(KERN_DEBUG "%s(%p, %d, %x, %p, %d)\n", __func__, sock,
408 level, optname, optval, len);
409
410 lock_sock(sk);
411
412 switch (optname) {
413 case MISDN_TIME_STAMP:
414 if (get_user(opt, (int __user *)optval)) {
415 err = -EFAULT;
416 break;
417 }
418
419 if (opt)
420 _pms(sk)->cmask |= MISDN_TIME_STAMP;
421 else
422 _pms(sk)->cmask &= ~MISDN_TIME_STAMP;
423 break;
424 default:
425 err = -ENOPROTOOPT;
426 break;
427 }
428 release_sock(sk);
429 return err;
430}
431
432static int data_sock_getsockopt(struct socket *sock, int level, int optname,
433 char __user *optval, int __user *optlen)
434{
435 struct sock *sk = sock->sk;
436 int len, opt;
437
438 if (get_user(len, optlen))
439 return -EFAULT;
440
441 switch (optname) {
442 case MISDN_TIME_STAMP:
443 if (_pms(sk)->cmask & MISDN_TIME_STAMP)
444 opt = 1;
445 else
446 opt = 0;
447
448 if (put_user(opt, optval))
449 return -EFAULT;
450 break;
451 default:
452 return -ENOPROTOOPT;
453 }
454
455 return 0;
456}
457
458static int
459data_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
460{
461 struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
462 struct sock *sk = sock->sk;
463 int err = 0;
464
465 if (*debug & DEBUG_SOCKET)
466 printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
467 if (addr_len != sizeof(struct sockaddr_mISDN))
468 return -EINVAL;
469 if (!maddr || maddr->family != AF_ISDN)
470 return -EINVAL;
471
472 lock_sock(sk);
473
474 if (_pms(sk)->dev) {
475 err = -EALREADY;
476 goto done;
477 }
478 _pms(sk)->dev = get_mdevice(maddr->dev);
479 if (!_pms(sk)->dev) {
480 err = -ENODEV;
481 goto done;
482 }
483 _pms(sk)->ch.send = mISDN_send;
484 _pms(sk)->ch.ctrl = mISDN_ctrl;
485
486 switch (sk->sk_protocol) {
487 case ISDN_P_TE_S0:
488 case ISDN_P_NT_S0:
489 case ISDN_P_TE_E1:
490 case ISDN_P_NT_E1:
491 mISDN_sock_unlink(&data_sockets, sk);
492 err = connect_layer1(_pms(sk)->dev, &_pms(sk)->ch,
493 sk->sk_protocol, maddr);
494 if (err)
495 mISDN_sock_link(&data_sockets, sk);
496 break;
497 case ISDN_P_LAPD_TE:
498 case ISDN_P_LAPD_NT:
499 err = create_l2entity(_pms(sk)->dev, &_pms(sk)->ch,
500 sk->sk_protocol, maddr);
501 break;
502 case ISDN_P_B_RAW:
503 case ISDN_P_B_HDLC:
504 case ISDN_P_B_X75SLP:
505 case ISDN_P_B_L2DTMF:
506 case ISDN_P_B_L2DSP:
507 case ISDN_P_B_L2DSPHDLC:
508 err = connect_Bstack(_pms(sk)->dev, &_pms(sk)->ch,
509 sk->sk_protocol, maddr);
510 break;
511 default:
512 err = -EPROTONOSUPPORT;
513 }
514 if (err)
515 goto done;
516 sk->sk_state = MISDN_BOUND;
517 _pms(sk)->ch.protocol = sk->sk_protocol;
518
519done:
520 release_sock(sk);
521 return err;
522}
523
524static int
525data_sock_getname(struct socket *sock, struct sockaddr *addr,
526 int *addr_len, int peer)
527{
528 struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
529 struct sock *sk = sock->sk;
530
531 if (!_pms(sk)->dev)
532 return -EBADFD;
533
534 lock_sock(sk);
535
536 *addr_len = sizeof(*maddr);
537 maddr->dev = _pms(sk)->dev->id;
538 maddr->channel = _pms(sk)->ch.nr;
539 maddr->sapi = _pms(sk)->ch.addr & 0xff;
540 maddr->tei = (_pms(sk)->ch.addr >> 8) & 0xff;
541 release_sock(sk);
542 return 0;
543}
544
545static const struct proto_ops data_sock_ops = {
546 .family = PF_ISDN,
547 .owner = THIS_MODULE,
548 .release = data_sock_release,
549 .ioctl = data_sock_ioctl,
550 .bind = data_sock_bind,
551 .getname = data_sock_getname,
552 .sendmsg = mISDN_sock_sendmsg,
553 .recvmsg = mISDN_sock_recvmsg,
554 .poll = datagram_poll,
555 .listen = sock_no_listen,
556 .shutdown = sock_no_shutdown,
557 .setsockopt = data_sock_setsockopt,
558 .getsockopt = data_sock_getsockopt,
559 .connect = sock_no_connect,
560 .socketpair = sock_no_socketpair,
561 .accept = sock_no_accept,
562 .mmap = sock_no_mmap
563};
564
565static int
566data_sock_create(struct net *net, struct socket *sock, int protocol)
567{
568 struct sock *sk;
569
570 if (sock->type != SOCK_DGRAM)
571 return -ESOCKTNOSUPPORT;
572
573 sk = sk_alloc(net, PF_ISDN, GFP_KERNEL, &mISDN_proto);
574 if (!sk)
575 return -ENOMEM;
576
577 sock_init_data(sock, sk);
578
579 sock->ops = &data_sock_ops;
580 sock->state = SS_UNCONNECTED;
581 sock_reset_flag(sk, SOCK_ZAPPED);
582
583 sk->sk_protocol = protocol;
584 sk->sk_state = MISDN_OPEN;
585 mISDN_sock_link(&data_sockets, sk);
586
587 return 0;
588}
589
590static int
591base_sock_release(struct socket *sock)
592{
593 struct sock *sk = sock->sk;
594
595 printk(KERN_DEBUG "%s(%p) sk=%p\n", __func__, sock, sk);
596 if (!sk)
597 return 0;
598
599 mISDN_sock_unlink(&base_sockets, sk);
600 sock_orphan(sk);
601 sock_put(sk);
602
603 return 0;
604}
605
606static int
607base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
608{
609 int err = 0, id;
610 struct mISDNdevice *dev;
611 struct mISDNversion ver;
612
613 switch (cmd) {
614 case IMGETVERSION:
615 ver.major = MISDN_MAJOR_VERSION;
616 ver.minor = MISDN_MINOR_VERSION;
617 ver.release = MISDN_RELEASE;
618 if (copy_to_user((void __user *)arg, &ver, sizeof(ver)))
619 err = -EFAULT;
620 break;
621 case IMGETCOUNT:
622 id = get_mdevice_count();
623 if (put_user(id, (int __user *)arg))
624 err = -EFAULT;
625 break;
626 case IMGETDEVINFO:
627 if (get_user(id, (int __user *)arg)) {
628 err = -EFAULT;
629 break;
630 }
631 dev = get_mdevice(id);
632 if (dev) {
633 struct mISDN_devinfo di;
634
635 di.id = dev->id;
636 di.Dprotocols = dev->Dprotocols;
637 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
638 di.protocol = dev->D.protocol;
639 memcpy(di.channelmap, dev->channelmap,
640 MISDN_CHMAP_SIZE * 4);
641 di.nrbchan = dev->nrbchan;
642 strcpy(di.name, dev->name);
643 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
644 err = -EFAULT;
645 } else
646 err = -ENODEV;
647 break;
648 default:
649 err = -EINVAL;
650 }
651 return err;
652}
653
654static int
655base_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
656{
657 struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr;
658 struct sock *sk = sock->sk;
659 int err = 0;
660
661 if (!maddr || maddr->family != AF_ISDN)
662 return -EINVAL;
663
664 lock_sock(sk);
665
666 if (_pms(sk)->dev) {
667 err = -EALREADY;
668 goto done;
669 }
670
671 _pms(sk)->dev = get_mdevice(maddr->dev);
672 if (!_pms(sk)->dev) {
673 err = -ENODEV;
674 goto done;
675 }
676 sk->sk_state = MISDN_BOUND;
677
678done:
679 release_sock(sk);
680 return err;
681}
682
683static const struct proto_ops base_sock_ops = {
684 .family = PF_ISDN,
685 .owner = THIS_MODULE,
686 .release = base_sock_release,
687 .ioctl = base_sock_ioctl,
688 .bind = base_sock_bind,
689 .getname = sock_no_getname,
690 .sendmsg = sock_no_sendmsg,
691 .recvmsg = sock_no_recvmsg,
692 .poll = sock_no_poll,
693 .listen = sock_no_listen,
694 .shutdown = sock_no_shutdown,
695 .setsockopt = sock_no_setsockopt,
696 .getsockopt = sock_no_getsockopt,
697 .connect = sock_no_connect,
698 .socketpair = sock_no_socketpair,
699 .accept = sock_no_accept,
700 .mmap = sock_no_mmap
701};
702
703
704static int
705base_sock_create(struct net *net, struct socket *sock, int protocol)
706{
707 struct sock *sk;
708
709 if (sock->type != SOCK_RAW)
710 return -ESOCKTNOSUPPORT;
711
712 sk = sk_alloc(net, PF_ISDN, GFP_KERNEL, &mISDN_proto);
713 if (!sk)
714 return -ENOMEM;
715
716 sock_init_data(sock, sk);
717 sock->ops = &base_sock_ops;
718 sock->state = SS_UNCONNECTED;
719 sock_reset_flag(sk, SOCK_ZAPPED);
720 sk->sk_protocol = protocol;
721 sk->sk_state = MISDN_OPEN;
722 mISDN_sock_link(&base_sockets, sk);
723
724 return 0;
725}
726
727static int
728mISDN_sock_create(struct net *net, struct socket *sock, int proto)
729{
730 int err = -EPROTONOSUPPORT;
731
732 switch (proto) {
733 case ISDN_P_BASE:
734 err = base_sock_create(net, sock, proto);
735 break;
736 case ISDN_P_TE_S0:
737 case ISDN_P_NT_S0:
738 case ISDN_P_TE_E1:
739 case ISDN_P_NT_E1:
740 case ISDN_P_LAPD_TE:
741 case ISDN_P_LAPD_NT:
742 case ISDN_P_B_RAW:
743 case ISDN_P_B_HDLC:
744 case ISDN_P_B_X75SLP:
745 case ISDN_P_B_L2DTMF:
746 case ISDN_P_B_L2DSP:
747 case ISDN_P_B_L2DSPHDLC:
748 err = data_sock_create(net, sock, proto);
749 break;
750 default:
751 return err;
752 }
753
754 return err;
755}
756
757static struct
758net_proto_family mISDN_sock_family_ops = {
759 .owner = THIS_MODULE,
760 .family = PF_ISDN,
761 .create = mISDN_sock_create,
762};
763
764int
765misdn_sock_init(u_int *deb)
766{
767 int err;
768
769 debug = deb;
770 err = sock_register(&mISDN_sock_family_ops);
771 if (err)
772 printk(KERN_ERR "%s: error(%d)\n", __func__, err);
773 return err;
774}
775
776void
777misdn_sock_cleanup(void)
778{
779 sock_unregister(PF_ISDN);
780}
781
diff --git a/drivers/isdn/mISDN/stack.c b/drivers/isdn/mISDN/stack.c
new file mode 100644
index 000000000000..54cfddcc4784
--- /dev/null
+++ b/drivers/isdn/mISDN/stack.c
@@ -0,0 +1,674 @@
1/*
2 *
3 * Author Karsten Keil <kkeil@novell.com>
4 *
5 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#include <linux/mISDNif.h>
19#include <linux/kthread.h>
20#include "core.h"
21
22static u_int *debug;
23
24static inline void
25_queue_message(struct mISDNstack *st, struct sk_buff *skb)
26{
27 struct mISDNhead *hh = mISDN_HEAD_P(skb);
28
29 if (*debug & DEBUG_QUEUE_FUNC)
30 printk(KERN_DEBUG "%s prim(%x) id(%x) %p\n",
31 __func__, hh->prim, hh->id, skb);
32 skb_queue_tail(&st->msgq, skb);
33 if (likely(!test_bit(mISDN_STACK_STOPPED, &st->status))) {
34 test_and_set_bit(mISDN_STACK_WORK, &st->status);
35 wake_up_interruptible(&st->workq);
36 }
37}
38
39int
40mISDN_queue_message(struct mISDNchannel *ch, struct sk_buff *skb)
41{
42 _queue_message(ch->st, skb);
43 return 0;
44}
45
46static struct mISDNchannel *
47get_channel4id(struct mISDNstack *st, u_int id)
48{
49 struct mISDNchannel *ch;
50
51 mutex_lock(&st->lmutex);
52 list_for_each_entry(ch, &st->layer2, list) {
53 if (id == ch->nr)
54 goto unlock;
55 }
56 ch = NULL;
57unlock:
58 mutex_unlock(&st->lmutex);
59 return ch;
60}
61
62static void
63send_socklist(struct mISDN_sock_list *sl, struct sk_buff *skb)
64{
65 struct hlist_node *node;
66 struct sock *sk;
67 struct sk_buff *cskb = NULL;
68
69 read_lock(&sl->lock);
70 sk_for_each(sk, node, &sl->head) {
71 if (sk->sk_state != MISDN_BOUND)
72 continue;
73 if (!cskb)
74 cskb = skb_copy(skb, GFP_KERNEL);
75 if (!cskb) {
76 printk(KERN_WARNING "%s no skb\n", __func__);
77 break;
78 }
79 if (!sock_queue_rcv_skb(sk, cskb))
80 cskb = NULL;
81 }
82 read_unlock(&sl->lock);
83 if (cskb)
84 dev_kfree_skb(cskb);
85}
86
87static void
88send_layer2(struct mISDNstack *st, struct sk_buff *skb)
89{
90 struct sk_buff *cskb;
91 struct mISDNhead *hh = mISDN_HEAD_P(skb);
92 struct mISDNchannel *ch;
93 int ret;
94
95 if (!st)
96 return;
97 mutex_lock(&st->lmutex);
98 if ((hh->id & MISDN_ID_ADDR_MASK) == MISDN_ID_ANY) { /* L2 for all */
99 list_for_each_entry(ch, &st->layer2, list) {
100 if (list_is_last(&ch->list, &st->layer2)) {
101 cskb = skb;
102 skb = NULL;
103 } else {
104 cskb = skb_copy(skb, GFP_KERNEL);
105 }
106 if (cskb) {
107 ret = ch->send(ch, cskb);
108 if (ret) {
109 if (*debug & DEBUG_SEND_ERR)
110 printk(KERN_DEBUG
111 "%s ch%d prim(%x) addr(%x)"
112 " err %d\n",
113 __func__, ch->nr,
114 hh->prim, ch->addr, ret);
115 dev_kfree_skb(cskb);
116 }
117 } else {
118 printk(KERN_WARNING "%s ch%d addr %x no mem\n",
119 __func__, ch->nr, ch->addr);
120 goto out;
121 }
122 }
123 } else {
124 list_for_each_entry(ch, &st->layer2, list) {
125 if ((hh->id & MISDN_ID_ADDR_MASK) == ch->addr) {
126 ret = ch->send(ch, skb);
127 if (!ret)
128 skb = NULL;
129 goto out;
130 }
131 }
132 ret = st->dev->teimgr->ctrl(st->dev->teimgr, CHECK_DATA, skb);
133 if (!ret)
134 skb = NULL;
135 else if (*debug & DEBUG_SEND_ERR)
136 printk(KERN_DEBUG
137 "%s ch%d mgr prim(%x) addr(%x) err %d\n",
138 __func__, ch->nr, hh->prim, ch->addr, ret);
139 }
140out:
141 mutex_unlock(&st->lmutex);
142 if (skb)
143 dev_kfree_skb(skb);
144}
145
146static inline int
147send_msg_to_layer(struct mISDNstack *st, struct sk_buff *skb)
148{
149 struct mISDNhead *hh = mISDN_HEAD_P(skb);
150 struct mISDNchannel *ch;
151 int lm;
152
153 lm = hh->prim & MISDN_LAYERMASK;
154 if (*debug & DEBUG_QUEUE_FUNC)
155 printk(KERN_DEBUG "%s prim(%x) id(%x) %p\n",
156 __func__, hh->prim, hh->id, skb);
157 if (lm == 0x1) {
158 if (!hlist_empty(&st->l1sock.head)) {
159 __net_timestamp(skb);
160 send_socklist(&st->l1sock, skb);
161 }
162 return st->layer1->send(st->layer1, skb);
163 } else if (lm == 0x2) {
164 if (!hlist_empty(&st->l1sock.head))
165 send_socklist(&st->l1sock, skb);
166 send_layer2(st, skb);
167 return 0;
168 } else if (lm == 0x4) {
169 ch = get_channel4id(st, hh->id);
170 if (ch)
171 return ch->send(ch, skb);
172 else
173 printk(KERN_WARNING
174 "%s: dev(%s) prim(%x) id(%x) no channel\n",
175 __func__, st->dev->name, hh->prim, hh->id);
176 } else if (lm == 0x8) {
177 WARN_ON(lm == 0x8);
178 ch = get_channel4id(st, hh->id);
179 if (ch)
180 return ch->send(ch, skb);
181 else
182 printk(KERN_WARNING
183 "%s: dev(%s) prim(%x) id(%x) no channel\n",
184 __func__, st->dev->name, hh->prim, hh->id);
185 } else {
186 /* broadcast not handled yet */
187 printk(KERN_WARNING "%s: dev(%s) prim %x not delivered\n",
188 __func__, st->dev->name, hh->prim);
189 }
190 return -ESRCH;
191}
192
193static void
194do_clear_stack(struct mISDNstack *st)
195{
196}
197
198static int
199mISDNStackd(void *data)
200{
201 struct mISDNstack *st = data;
202 int err = 0;
203
204#ifdef CONFIG_SMP
205 lock_kernel();
206#endif
207 sigfillset(&current->blocked);
208#ifdef CONFIG_SMP
209 unlock_kernel();
210#endif
211 if (*debug & DEBUG_MSG_THREAD)
212 printk(KERN_DEBUG "mISDNStackd %s started\n", st->dev->name);
213
214 if (st->notify != NULL) {
215 complete(st->notify);
216 st->notify = NULL;
217 }
218
219 for (;;) {
220 struct sk_buff *skb;
221
222 if (unlikely(test_bit(mISDN_STACK_STOPPED, &st->status))) {
223 test_and_clear_bit(mISDN_STACK_WORK, &st->status);
224 test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
225 } else
226 test_and_set_bit(mISDN_STACK_RUNNING, &st->status);
227 while (test_bit(mISDN_STACK_WORK, &st->status)) {
228 skb = skb_dequeue(&st->msgq);
229 if (!skb) {
230 test_and_clear_bit(mISDN_STACK_WORK,
231 &st->status);
232 /* test if a race happens */
233 skb = skb_dequeue(&st->msgq);
234 if (!skb)
235 continue;
236 test_and_set_bit(mISDN_STACK_WORK,
237 &st->status);
238 }
239#ifdef MISDN_MSG_STATS
240 st->msg_cnt++;
241#endif
242 err = send_msg_to_layer(st, skb);
243 if (unlikely(err)) {
244 if (*debug & DEBUG_SEND_ERR)
245 printk(KERN_DEBUG
246 "%s: %s prim(%x) id(%x) "
247 "send call(%d)\n",
248 __func__, st->dev->name,
249 mISDN_HEAD_PRIM(skb),
250 mISDN_HEAD_ID(skb), err);
251 dev_kfree_skb(skb);
252 continue;
253 }
254 if (unlikely(test_bit(mISDN_STACK_STOPPED,
255 &st->status))) {
256 test_and_clear_bit(mISDN_STACK_WORK,
257 &st->status);
258 test_and_clear_bit(mISDN_STACK_RUNNING,
259 &st->status);
260 break;
261 }
262 }
263 if (test_bit(mISDN_STACK_CLEARING, &st->status)) {
264 test_and_set_bit(mISDN_STACK_STOPPED, &st->status);
265 test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
266 do_clear_stack(st);
267 test_and_clear_bit(mISDN_STACK_CLEARING, &st->status);
268 test_and_set_bit(mISDN_STACK_RESTART, &st->status);
269 }
270 if (test_and_clear_bit(mISDN_STACK_RESTART, &st->status)) {
271 test_and_clear_bit(mISDN_STACK_STOPPED, &st->status);
272 test_and_set_bit(mISDN_STACK_RUNNING, &st->status);
273 if (!skb_queue_empty(&st->msgq))
274 test_and_set_bit(mISDN_STACK_WORK,
275 &st->status);
276 }
277 if (test_bit(mISDN_STACK_ABORT, &st->status))
278 break;
279 if (st->notify != NULL) {
280 complete(st->notify);
281 st->notify = NULL;
282 }
283#ifdef MISDN_MSG_STATS
284 st->sleep_cnt++;
285#endif
286 test_and_clear_bit(mISDN_STACK_ACTIVE, &st->status);
287 wait_event_interruptible(st->workq, (st->status &
288 mISDN_STACK_ACTION_MASK));
289 if (*debug & DEBUG_MSG_THREAD)
290 printk(KERN_DEBUG "%s: %s wake status %08lx\n",
291 __func__, st->dev->name, st->status);
292 test_and_set_bit(mISDN_STACK_ACTIVE, &st->status);
293
294 test_and_clear_bit(mISDN_STACK_WAKEUP, &st->status);
295
296 if (test_bit(mISDN_STACK_STOPPED, &st->status)) {
297 test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
298#ifdef MISDN_MSG_STATS
299 st->stopped_cnt++;
300#endif
301 }
302 }
303#ifdef MISDN_MSG_STATS
304 printk(KERN_DEBUG "mISDNStackd daemon for %s proceed %d "
305 "msg %d sleep %d stopped\n",
306 st->dev->name, st->msg_cnt, st->sleep_cnt, st->stopped_cnt);
307 printk(KERN_DEBUG
308 "mISDNStackd daemon for %s utime(%ld) stime(%ld)\n",
309 st->dev->name, st->thread->utime, st->thread->stime);
310 printk(KERN_DEBUG
311 "mISDNStackd daemon for %s nvcsw(%ld) nivcsw(%ld)\n",
312 st->dev->name, st->thread->nvcsw, st->thread->nivcsw);
313 printk(KERN_DEBUG "mISDNStackd daemon for %s killed now\n",
314 st->dev->name);
315#endif
316 test_and_set_bit(mISDN_STACK_KILLED, &st->status);
317 test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
318 test_and_clear_bit(mISDN_STACK_ACTIVE, &st->status);
319 test_and_clear_bit(mISDN_STACK_ABORT, &st->status);
320 skb_queue_purge(&st->msgq);
321 st->thread = NULL;
322 if (st->notify != NULL) {
323 complete(st->notify);
324 st->notify = NULL;
325 }
326 return 0;
327}
328
329static int
330l1_receive(struct mISDNchannel *ch, struct sk_buff *skb)
331{
332 if (!ch->st)
333 return -ENODEV;
334 __net_timestamp(skb);
335 _queue_message(ch->st, skb);
336 return 0;
337}
338
339void
340set_channel_address(struct mISDNchannel *ch, u_int sapi, u_int tei)
341{
342 ch->addr = sapi | (tei << 8);
343}
344
345void
346__add_layer2(struct mISDNchannel *ch, struct mISDNstack *st)
347{
348 list_add_tail(&ch->list, &st->layer2);
349}
350
351void
352add_layer2(struct mISDNchannel *ch, struct mISDNstack *st)
353{
354 mutex_lock(&st->lmutex);
355 __add_layer2(ch, st);
356 mutex_unlock(&st->lmutex);
357}
358
359static int
360st_own_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
361{
362 if (!ch->st || ch->st->layer1)
363 return -EINVAL;
364 return ch->st->layer1->ctrl(ch->st->layer1, cmd, arg);
365}
366
367int
368create_stack(struct mISDNdevice *dev)
369{
370 struct mISDNstack *newst;
371 int err;
372 DECLARE_COMPLETION_ONSTACK(done);
373
374 newst = kzalloc(sizeof(struct mISDNstack), GFP_KERNEL);
375 if (!newst) {
376 printk(KERN_ERR "kmalloc mISDN_stack failed\n");
377 return -ENOMEM;
378 }
379 newst->dev = dev;
380 INIT_LIST_HEAD(&newst->layer2);
381 INIT_HLIST_HEAD(&newst->l1sock.head);
382 rwlock_init(&newst->l1sock.lock);
383 init_waitqueue_head(&newst->workq);
384 skb_queue_head_init(&newst->msgq);
385 mutex_init(&newst->lmutex);
386 dev->D.st = newst;
387 err = create_teimanager(dev);
388 if (err) {
389 printk(KERN_ERR "kmalloc teimanager failed\n");
390 kfree(newst);
391 return err;
392 }
393 dev->teimgr->peer = &newst->own;
394 dev->teimgr->recv = mISDN_queue_message;
395 dev->teimgr->st = newst;
396 newst->layer1 = &dev->D;
397 dev->D.recv = l1_receive;
398 dev->D.peer = &newst->own;
399 newst->own.st = newst;
400 newst->own.ctrl = st_own_ctrl;
401 newst->own.send = mISDN_queue_message;
402 newst->own.recv = mISDN_queue_message;
403 if (*debug & DEBUG_CORE_FUNC)
404 printk(KERN_DEBUG "%s: st(%s)\n", __func__, newst->dev->name);
405 newst->notify = &done;
406 newst->thread = kthread_run(mISDNStackd, (void *)newst, "mISDN_%s",
407 newst->dev->name);
408 if (IS_ERR(newst->thread)) {
409 err = PTR_ERR(newst->thread);
410 printk(KERN_ERR
411 "mISDN:cannot create kernel thread for %s (%d)\n",
412 newst->dev->name, err);
413 delete_teimanager(dev->teimgr);
414 kfree(newst);
415 } else
416 wait_for_completion(&done);
417 return err;
418}
419
420int
421connect_layer1(struct mISDNdevice *dev, struct mISDNchannel *ch,
422 u_int protocol, struct sockaddr_mISDN *adr)
423{
424 struct mISDN_sock *msk = container_of(ch, struct mISDN_sock, ch);
425 struct channel_req rq;
426 int err;
427
428
429 if (*debug & DEBUG_CORE_FUNC)
430 printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n",
431 __func__, dev->name, protocol, adr->dev, adr->channel,
432 adr->sapi, adr->tei);
433 switch (protocol) {
434 case ISDN_P_NT_S0:
435 case ISDN_P_NT_E1:
436 case ISDN_P_TE_S0:
437 case ISDN_P_TE_E1:
438#ifdef PROTOCOL_CHECK
439 /* this should be enhanced */
440 if (!list_empty(&dev->D.st->layer2)
441 && dev->D.protocol != protocol)
442 return -EBUSY;
443 if (!hlist_empty(&dev->D.st->l1sock.head)
444 && dev->D.protocol != protocol)
445 return -EBUSY;
446#endif
447 ch->recv = mISDN_queue_message;
448 ch->peer = &dev->D.st->own;
449 ch->st = dev->D.st;
450 rq.protocol = protocol;
451 rq.adr.channel = 0;
452 err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
453 printk(KERN_DEBUG "%s: ret 1 %d\n", __func__, err);
454 if (err)
455 return err;
456 write_lock_bh(&dev->D.st->l1sock.lock);
457 sk_add_node(&msk->sk, &dev->D.st->l1sock.head);
458 write_unlock_bh(&dev->D.st->l1sock.lock);
459 break;
460 default:
461 return -ENOPROTOOPT;
462 }
463 return 0;
464}
465
466int
467connect_Bstack(struct mISDNdevice *dev, struct mISDNchannel *ch,
468 u_int protocol, struct sockaddr_mISDN *adr)
469{
470 struct channel_req rq, rq2;
471 int pmask, err;
472 struct Bprotocol *bp;
473
474 if (*debug & DEBUG_CORE_FUNC)
475 printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n",
476 __func__, dev->name, protocol,
477 adr->dev, adr->channel, adr->sapi,
478 adr->tei);
479 ch->st = dev->D.st;
480 pmask = 1 << (protocol & ISDN_P_B_MASK);
481 if (pmask & dev->Bprotocols) {
482 rq.protocol = protocol;
483 rq.adr = *adr;
484 err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
485 if (err)
486 return err;
487 ch->recv = rq.ch->send;
488 ch->peer = rq.ch;
489 rq.ch->recv = ch->send;
490 rq.ch->peer = ch;
491 rq.ch->st = dev->D.st;
492 } else {
493 bp = get_Bprotocol4mask(pmask);
494 if (!bp)
495 return -ENOPROTOOPT;
496 rq2.protocol = protocol;
497 rq2.adr = *adr;
498 rq2.ch = ch;
499 err = bp->create(&rq2);
500 if (err)
501 return err;
502 ch->recv = rq2.ch->send;
503 ch->peer = rq2.ch;
504 rq2.ch->st = dev->D.st;
505 rq.protocol = rq2.protocol;
506 rq.adr = *adr;
507 err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
508 if (err) {
509 rq2.ch->ctrl(rq2.ch, CLOSE_CHANNEL, NULL);
510 return err;
511 }
512 rq2.ch->recv = rq.ch->send;
513 rq2.ch->peer = rq.ch;
514 rq.ch->recv = rq2.ch->send;
515 rq.ch->peer = rq2.ch;
516 rq.ch->st = dev->D.st;
517 }
518 ch->protocol = protocol;
519 ch->nr = rq.ch->nr;
520 return 0;
521}
522
523int
524create_l2entity(struct mISDNdevice *dev, struct mISDNchannel *ch,
525 u_int protocol, struct sockaddr_mISDN *adr)
526{
527 struct channel_req rq;
528 int err;
529
530 if (*debug & DEBUG_CORE_FUNC)
531 printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n",
532 __func__, dev->name, protocol,
533 adr->dev, adr->channel, adr->sapi,
534 adr->tei);
535 rq.protocol = ISDN_P_TE_S0;
536 if (dev->Dprotocols & (1 << ISDN_P_TE_E1))
537 rq.protocol = ISDN_P_TE_E1;
538 switch (protocol) {
539 case ISDN_P_LAPD_NT:
540 rq.protocol = ISDN_P_NT_S0;
541 if (dev->Dprotocols & (1 << ISDN_P_NT_E1))
542 rq.protocol = ISDN_P_NT_E1;
543 case ISDN_P_LAPD_TE:
544#ifdef PROTOCOL_CHECK
545 /* this should be enhanced */
546 if (!list_empty(&dev->D.st->layer2)
547 && dev->D.protocol != protocol)
548 return -EBUSY;
549 if (!hlist_empty(&dev->D.st->l1sock.head)
550 && dev->D.protocol != protocol)
551 return -EBUSY;
552#endif
553 ch->recv = mISDN_queue_message;
554 ch->peer = &dev->D.st->own;
555 ch->st = dev->D.st;
556 rq.adr.channel = 0;
557 err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
558 printk(KERN_DEBUG "%s: ret 1 %d\n", __func__, err);
559 if (err)
560 break;
561 rq.protocol = protocol;
562 rq.adr = *adr;
563 rq.ch = ch;
564 err = dev->teimgr->ctrl(dev->teimgr, OPEN_CHANNEL, &rq);
565 printk(KERN_DEBUG "%s: ret 2 %d\n", __func__, err);
566 if (!err) {
567 if ((protocol == ISDN_P_LAPD_NT) && !rq.ch)
568 break;
569 add_layer2(rq.ch, dev->D.st);
570 rq.ch->recv = mISDN_queue_message;
571 rq.ch->peer = &dev->D.st->own;
572 rq.ch->ctrl(rq.ch, OPEN_CHANNEL, NULL); /* can't fail */
573 }
574 break;
575 default:
576 err = -EPROTONOSUPPORT;
577 }
578 return err;
579}
580
581void
582delete_channel(struct mISDNchannel *ch)
583{
584 struct mISDN_sock *msk = container_of(ch, struct mISDN_sock, ch);
585 struct mISDNchannel *pch;
586
587 if (!ch->st) {
588 printk(KERN_WARNING "%s: no stack\n", __func__);
589 return;
590 }
591 if (*debug & DEBUG_CORE_FUNC)
592 printk(KERN_DEBUG "%s: st(%s) protocol(%x)\n", __func__,
593 ch->st->dev->name, ch->protocol);
594 if (ch->protocol >= ISDN_P_B_START) {
595 if (ch->peer) {
596 ch->peer->ctrl(ch->peer, CLOSE_CHANNEL, NULL);
597 ch->peer = NULL;
598 }
599 return;
600 }
601 switch (ch->protocol) {
602 case ISDN_P_NT_S0:
603 case ISDN_P_TE_S0:
604 case ISDN_P_NT_E1:
605 case ISDN_P_TE_E1:
606 write_lock_bh(&ch->st->l1sock.lock);
607 sk_del_node_init(&msk->sk);
608 write_unlock_bh(&ch->st->l1sock.lock);
609 ch->st->dev->D.ctrl(&ch->st->dev->D, CLOSE_CHANNEL, NULL);
610 break;
611 case ISDN_P_LAPD_TE:
612 pch = get_channel4id(ch->st, ch->nr);
613 if (pch) {
614 mutex_lock(&ch->st->lmutex);
615 list_del(&pch->list);
616 mutex_unlock(&ch->st->lmutex);
617 pch->ctrl(pch, CLOSE_CHANNEL, NULL);
618 pch = ch->st->dev->teimgr;
619 pch->ctrl(pch, CLOSE_CHANNEL, NULL);
620 } else
621 printk(KERN_WARNING "%s: no l2 channel\n",
622 __func__);
623 break;
624 case ISDN_P_LAPD_NT:
625 pch = ch->st->dev->teimgr;
626 if (pch) {
627 pch->ctrl(pch, CLOSE_CHANNEL, NULL);
628 } else
629 printk(KERN_WARNING "%s: no l2 channel\n",
630 __func__);
631 break;
632 default:
633 break;
634 }
635 return;
636}
637
638void
639delete_stack(struct mISDNdevice *dev)
640{
641 struct mISDNstack *st = dev->D.st;
642 DECLARE_COMPLETION_ONSTACK(done);
643
644 if (*debug & DEBUG_CORE_FUNC)
645 printk(KERN_DEBUG "%s: st(%s)\n", __func__,
646 st->dev->name);
647 if (dev->teimgr)
648 delete_teimanager(dev->teimgr);
649 if (st->thread) {
650 if (st->notify) {
651 printk(KERN_WARNING "%s: notifier in use\n",
652 __func__);
653 complete(st->notify);
654 }
655 st->notify = &done;
656 test_and_set_bit(mISDN_STACK_ABORT, &st->status);
657 test_and_set_bit(mISDN_STACK_WAKEUP, &st->status);
658 wake_up_interruptible(&st->workq);
659 wait_for_completion(&done);
660 }
661 if (!list_empty(&st->layer2))
662 printk(KERN_WARNING "%s: layer2 list not empty\n",
663 __func__);
664 if (!hlist_empty(&st->l1sock.head))
665 printk(KERN_WARNING "%s: layer1 list not empty\n",
666 __func__);
667 kfree(st);
668}
669
670void
671mISDN_initstack(u_int *dp)
672{
673 debug = dp;
674}
diff --git a/drivers/isdn/mISDN/tei.c b/drivers/isdn/mISDN/tei.c
new file mode 100644
index 000000000000..56a76a0ffddd
--- /dev/null
+++ b/drivers/isdn/mISDN/tei.c
@@ -0,0 +1,1340 @@
1/*
2 *
3 * Author Karsten Keil <kkeil@novell.com>
4 *
5 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17#include "layer2.h"
18#include <linux/random.h>
19#include "core.h"
20
21#define ID_REQUEST 1
22#define ID_ASSIGNED 2
23#define ID_DENIED 3
24#define ID_CHK_REQ 4
25#define ID_CHK_RES 5
26#define ID_REMOVE 6
27#define ID_VERIFY 7
28
29#define TEI_ENTITY_ID 0xf
30
31#define MGR_PH_ACTIVE 16
32#define MGR_PH_NOTREADY 17
33
34#define DATIMER_VAL 10000
35
36static u_int *debug;
37
38static struct Fsm deactfsm = {NULL, 0, 0, NULL, NULL};
39static struct Fsm teifsmu = {NULL, 0, 0, NULL, NULL};
40static struct Fsm teifsmn = {NULL, 0, 0, NULL, NULL};
41
42enum {
43 ST_L1_DEACT,
44 ST_L1_DEACT_PENDING,
45 ST_L1_ACTIV,
46};
47#define DEACT_STATE_COUNT (ST_L1_ACTIV+1)
48
49static char *strDeactState[] =
50{
51 "ST_L1_DEACT",
52 "ST_L1_DEACT_PENDING",
53 "ST_L1_ACTIV",
54};
55
56enum {
57 EV_ACTIVATE,
58 EV_ACTIVATE_IND,
59 EV_DEACTIVATE,
60 EV_DEACTIVATE_IND,
61 EV_UI,
62 EV_DATIMER,
63};
64
65#define DEACT_EVENT_COUNT (EV_DATIMER+1)
66
67static char *strDeactEvent[] =
68{
69 "EV_ACTIVATE",
70 "EV_ACTIVATE_IND",
71 "EV_DEACTIVATE",
72 "EV_DEACTIVATE_IND",
73 "EV_UI",
74 "EV_DATIMER",
75};
76
77static void
78da_debug(struct FsmInst *fi, char *fmt, ...)
79{
80 struct manager *mgr = fi->userdata;
81 va_list va;
82
83 if (!(*debug & DEBUG_L2_TEIFSM))
84 return;
85 va_start(va, fmt);
86 printk(KERN_DEBUG "mgr(%d): ", mgr->ch.st->dev->id);
87 vprintk(fmt, va);
88 printk("\n");
89 va_end(va);
90}
91
92static void
93da_activate(struct FsmInst *fi, int event, void *arg)
94{
95 struct manager *mgr = fi->userdata;
96
97 if (fi->state == ST_L1_DEACT_PENDING)
98 mISDN_FsmDelTimer(&mgr->datimer, 1);
99 mISDN_FsmChangeState(fi, ST_L1_ACTIV);
100}
101
102static void
103da_deactivate_ind(struct FsmInst *fi, int event, void *arg)
104{
105 mISDN_FsmChangeState(fi, ST_L1_DEACT);
106}
107
108static void
109da_deactivate(struct FsmInst *fi, int event, void *arg)
110{
111 struct manager *mgr = fi->userdata;
112 struct layer2 *l2;
113 u_long flags;
114
115 read_lock_irqsave(&mgr->lock, flags);
116 list_for_each_entry(l2, &mgr->layer2, list) {
117 if (l2->l2m.state > ST_L2_4) {
118 /* have still activ TEI */
119 read_unlock_irqrestore(&mgr->lock, flags);
120 return;
121 }
122 }
123 read_unlock_irqrestore(&mgr->lock, flags);
124 /* All TEI are inactiv */
125 mISDN_FsmAddTimer(&mgr->datimer, DATIMER_VAL, EV_DATIMER, NULL, 1);
126 mISDN_FsmChangeState(fi, ST_L1_DEACT_PENDING);
127}
128
129static void
130da_ui(struct FsmInst *fi, int event, void *arg)
131{
132 struct manager *mgr = fi->userdata;
133
134 /* restart da timer */
135 mISDN_FsmDelTimer(&mgr->datimer, 2);
136 mISDN_FsmAddTimer(&mgr->datimer, DATIMER_VAL, EV_DATIMER, NULL, 2);
137
138}
139
140static void
141da_timer(struct FsmInst *fi, int event, void *arg)
142{
143 struct manager *mgr = fi->userdata;
144 struct layer2 *l2;
145 u_long flags;
146
147 /* check again */
148 read_lock_irqsave(&mgr->lock, flags);
149 list_for_each_entry(l2, &mgr->layer2, list) {
150 if (l2->l2m.state > ST_L2_4) {
151 /* have still activ TEI */
152 read_unlock_irqrestore(&mgr->lock, flags);
153 mISDN_FsmChangeState(fi, ST_L1_ACTIV);
154 return;
155 }
156 }
157 read_unlock_irqrestore(&mgr->lock, flags);
158 /* All TEI are inactiv */
159 mISDN_FsmChangeState(fi, ST_L1_DEACT);
160 _queue_data(&mgr->ch, PH_DEACTIVATE_REQ, MISDN_ID_ANY, 0, NULL,
161 GFP_ATOMIC);
162}
163
164static struct FsmNode DeactFnList[] =
165{
166 {ST_L1_DEACT, EV_ACTIVATE_IND, da_activate},
167 {ST_L1_ACTIV, EV_DEACTIVATE_IND, da_deactivate_ind},
168 {ST_L1_ACTIV, EV_DEACTIVATE, da_deactivate},
169 {ST_L1_DEACT_PENDING, EV_ACTIVATE, da_activate},
170 {ST_L1_DEACT_PENDING, EV_UI, da_ui},
171 {ST_L1_DEACT_PENDING, EV_DATIMER, da_timer},
172};
173
174enum {
175 ST_TEI_NOP,
176 ST_TEI_IDREQ,
177 ST_TEI_IDVERIFY,
178};
179
180#define TEI_STATE_COUNT (ST_TEI_IDVERIFY+1)
181
182static char *strTeiState[] =
183{
184 "ST_TEI_NOP",
185 "ST_TEI_IDREQ",
186 "ST_TEI_IDVERIFY",
187};
188
189enum {
190 EV_IDREQ,
191 EV_ASSIGN,
192 EV_ASSIGN_REQ,
193 EV_DENIED,
194 EV_CHKREQ,
195 EV_CHKRESP,
196 EV_REMOVE,
197 EV_VERIFY,
198 EV_TIMER,
199};
200
201#define TEI_EVENT_COUNT (EV_TIMER+1)
202
203static char *strTeiEvent[] =
204{
205 "EV_IDREQ",
206 "EV_ASSIGN",
207 "EV_ASSIGN_REQ",
208 "EV_DENIED",
209 "EV_CHKREQ",
210 "EV_CHKRESP",
211 "EV_REMOVE",
212 "EV_VERIFY",
213 "EV_TIMER",
214};
215
216static void
217tei_debug(struct FsmInst *fi, char *fmt, ...)
218{
219 struct teimgr *tm = fi->userdata;
220 va_list va;
221
222 if (!(*debug & DEBUG_L2_TEIFSM))
223 return;
224 va_start(va, fmt);
225 printk(KERN_DEBUG "tei(%d): ", tm->l2->tei);
226 vprintk(fmt, va);
227 printk("\n");
228 va_end(va);
229}
230
231
232
233static int
234get_free_id(struct manager *mgr)
235{
236 u64 ids = 0;
237 int i;
238 struct layer2 *l2;
239
240 list_for_each_entry(l2, &mgr->layer2, list) {
241 if (l2->ch.nr > 63) {
242 printk(KERN_WARNING
243 "%s: more as 63 layer2 for one device\n",
244 __func__);
245 return -EBUSY;
246 }
247 test_and_set_bit(l2->ch.nr, (u_long *)&ids);
248 }
249 for (i = 1; i < 64; i++)
250 if (!test_bit(i, (u_long *)&ids))
251 return i;
252 printk(KERN_WARNING "%s: more as 63 layer2 for one device\n",
253 __func__);
254 return -EBUSY;
255}
256
257static int
258get_free_tei(struct manager *mgr)
259{
260 u64 ids = 0;
261 int i;
262 struct layer2 *l2;
263
264 list_for_each_entry(l2, &mgr->layer2, list) {
265 if (l2->ch.nr == 0)
266 continue;
267 if ((l2->ch.addr & 0xff) != 0)
268 continue;
269 i = l2->ch.addr >> 8;
270 if (i < 64)
271 continue;
272 i -= 64;
273
274 test_and_set_bit(i, (u_long *)&ids);
275 }
276 for (i = 0; i < 64; i++)
277 if (!test_bit(i, (u_long *)&ids))
278 return i + 64;
279 printk(KERN_WARNING "%s: more as 63 dynamic tei for one device\n",
280 __func__);
281 return -1;
282}
283
284static void
285teiup_create(struct manager *mgr, u_int prim, int len, void *arg)
286{
287 struct sk_buff *skb;
288 struct mISDNhead *hh;
289 int err;
290
291 skb = mI_alloc_skb(len, GFP_ATOMIC);
292 if (!skb)
293 return;
294 hh = mISDN_HEAD_P(skb);
295 hh->prim = prim;
296 hh->id = (mgr->ch.nr << 16) | mgr->ch.addr;
297 if (len)
298 memcpy(skb_put(skb, len), arg, len);
299 err = mgr->up->send(mgr->up, skb);
300 if (err) {
301 printk(KERN_WARNING "%s: err=%d\n", __func__, err);
302 dev_kfree_skb(skb);
303 }
304}
305
306static u_int
307new_id(struct manager *mgr)
308{
309 u_int id;
310
311 id = mgr->nextid++;
312 if (id == 0x7fff)
313 mgr->nextid = 1;
314 id <<= 16;
315 id |= GROUP_TEI << 8;
316 id |= TEI_SAPI;
317 return id;
318}
319
320static void
321do_send(struct manager *mgr)
322{
323 if (!test_bit(MGR_PH_ACTIVE, &mgr->options))
324 return;
325
326 if (!test_and_set_bit(MGR_PH_NOTREADY, &mgr->options)) {
327 struct sk_buff *skb = skb_dequeue(&mgr->sendq);
328
329 if (!skb) {
330 test_and_clear_bit(MGR_PH_NOTREADY, &mgr->options);
331 return;
332 }
333 mgr->lastid = mISDN_HEAD_ID(skb);
334 mISDN_FsmEvent(&mgr->deact, EV_UI, NULL);
335 if (mgr->ch.recv(mgr->ch.peer, skb)) {
336 dev_kfree_skb(skb);
337 test_and_clear_bit(MGR_PH_NOTREADY, &mgr->options);
338 mgr->lastid = MISDN_ID_NONE;
339 }
340 }
341}
342
343static void
344do_ack(struct manager *mgr, u_int id)
345{
346 if (test_bit(MGR_PH_NOTREADY, &mgr->options)) {
347 if (id == mgr->lastid) {
348 if (test_bit(MGR_PH_ACTIVE, &mgr->options)) {
349 struct sk_buff *skb;
350
351 skb = skb_dequeue(&mgr->sendq);
352 if (skb) {
353 mgr->lastid = mISDN_HEAD_ID(skb);
354 if (!mgr->ch.recv(mgr->ch.peer, skb))
355 return;
356 dev_kfree_skb(skb);
357 }
358 }
359 mgr->lastid = MISDN_ID_NONE;
360 test_and_clear_bit(MGR_PH_NOTREADY, &mgr->options);
361 }
362 }
363}
364
365static void
366mgr_send_down(struct manager *mgr, struct sk_buff *skb)
367{
368 skb_queue_tail(&mgr->sendq, skb);
369 if (!test_bit(MGR_PH_ACTIVE, &mgr->options)) {
370 _queue_data(&mgr->ch, PH_ACTIVATE_REQ, MISDN_ID_ANY, 0,
371 NULL, GFP_KERNEL);
372 } else {
373 do_send(mgr);
374 }
375}
376
377static int
378dl_unit_data(struct manager *mgr, struct sk_buff *skb)
379{
380 if (!test_bit(MGR_OPT_NETWORK, &mgr->options)) /* only net send UI */
381 return -EINVAL;
382 if (!test_bit(MGR_PH_ACTIVE, &mgr->options))
383 _queue_data(&mgr->ch, PH_ACTIVATE_REQ, MISDN_ID_ANY, 0,
384 NULL, GFP_KERNEL);
385 skb_push(skb, 3);
386 skb->data[0] = 0x02; /* SAPI 0 C/R = 1 */
387 skb->data[1] = 0xff; /* TEI 127 */
388 skb->data[2] = UI; /* UI frame */
389 mISDN_HEAD_PRIM(skb) = PH_DATA_REQ;
390 mISDN_HEAD_ID(skb) = new_id(mgr);
391 skb_queue_tail(&mgr->sendq, skb);
392 do_send(mgr);
393 return 0;
394}
395
396unsigned int
397random_ri(void)
398{
399 u16 x;
400
401 get_random_bytes(&x, sizeof(x));
402 return x;
403}
404
405static struct layer2 *
406findtei(struct manager *mgr, int tei)
407{
408 struct layer2 *l2;
409 u_long flags;
410
411 read_lock_irqsave(&mgr->lock, flags);
412 list_for_each_entry(l2, &mgr->layer2, list) {
413 if ((l2->sapi == 0) && (l2->tei > 0) &&
414 (l2->tei != GROUP_TEI) && (l2->tei == tei))
415 goto done;
416 }
417 l2 = NULL;
418done:
419 read_unlock_irqrestore(&mgr->lock, flags);
420 return l2;
421}
422
423static void
424put_tei_msg(struct manager *mgr, u_char m_id, unsigned int ri, u_char tei)
425{
426 struct sk_buff *skb;
427 u_char bp[8];
428
429 bp[0] = (TEI_SAPI << 2);
430 if (test_bit(MGR_OPT_NETWORK, &mgr->options))
431 bp[0] |= 2; /* CR:=1 for net command */
432 bp[1] = (GROUP_TEI << 1) | 0x1;
433 bp[2] = UI;
434 bp[3] = TEI_ENTITY_ID;
435 bp[4] = ri >> 8;
436 bp[5] = ri & 0xff;
437 bp[6] = m_id;
438 bp[7] = (tei << 1) | 1;
439 skb = _alloc_mISDN_skb(PH_DATA_REQ, new_id(mgr),
440 8, bp, GFP_ATOMIC);
441 if (!skb) {
442 printk(KERN_WARNING "%s: no skb for tei msg\n", __func__);
443 return;
444 }
445 mgr_send_down(mgr, skb);
446}
447
448static void
449tei_id_request(struct FsmInst *fi, int event, void *arg)
450{
451 struct teimgr *tm = fi->userdata;
452
453 if (tm->l2->tei != GROUP_TEI) {
454 tm->tei_m.printdebug(&tm->tei_m,
455 "assign request for allready assigned tei %d",
456 tm->l2->tei);
457 return;
458 }
459 tm->ri = random_ri();
460 if (*debug & DEBUG_L2_TEI)
461 tm->tei_m.printdebug(&tm->tei_m,
462 "assign request ri %d", tm->ri);
463 put_tei_msg(tm->mgr, ID_REQUEST, tm->ri, GROUP_TEI);
464 mISDN_FsmChangeState(fi, ST_TEI_IDREQ);
465 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 1);
466 tm->nval = 3;
467}
468
469static void
470tei_id_assign(struct FsmInst *fi, int event, void *arg)
471{
472 struct teimgr *tm = fi->userdata;
473 struct layer2 *l2;
474 u_char *dp = arg;
475 int ri, tei;
476
477 ri = ((unsigned int) *dp++ << 8);
478 ri += *dp++;
479 dp++;
480 tei = *dp >> 1;
481 if (*debug & DEBUG_L2_TEI)
482 tm->tei_m.printdebug(fi, "identity assign ri %d tei %d",
483 ri, tei);
484 l2 = findtei(tm->mgr, tei);
485 if (l2) { /* same tei is in use */
486 if (ri != l2->tm->ri) {
487 tm->tei_m.printdebug(fi,
488 "possible duplicate assignment tei %d", tei);
489 tei_l2(l2, MDL_ERROR_RSP, 0);
490 }
491 } else if (ri == tm->ri) {
492 mISDN_FsmDelTimer(&tm->timer, 1);
493 mISDN_FsmChangeState(fi, ST_TEI_NOP);
494 tei_l2(tm->l2, MDL_ASSIGN_REQ, tei);
495 }
496}
497
498static void
499tei_id_test_dup(struct FsmInst *fi, int event, void *arg)
500{
501 struct teimgr *tm = fi->userdata;
502 struct layer2 *l2;
503 u_char *dp = arg;
504 int tei, ri;
505
506 ri = ((unsigned int) *dp++ << 8);
507 ri += *dp++;
508 dp++;
509 tei = *dp >> 1;
510 if (*debug & DEBUG_L2_TEI)
511 tm->tei_m.printdebug(fi, "foreign identity assign ri %d tei %d",
512 ri, tei);
513 l2 = findtei(tm->mgr, tei);
514 if (l2) { /* same tei is in use */
515 if (ri != l2->tm->ri) { /* and it wasn't our request */
516 tm->tei_m.printdebug(fi,
517 "possible duplicate assignment tei %d", tei);
518 mISDN_FsmEvent(&l2->tm->tei_m, EV_VERIFY, NULL);
519 }
520 }
521}
522
523static void
524tei_id_denied(struct FsmInst *fi, int event, void *arg)
525{
526 struct teimgr *tm = fi->userdata;
527 u_char *dp = arg;
528 int ri, tei;
529
530 ri = ((unsigned int) *dp++ << 8);
531 ri += *dp++;
532 dp++;
533 tei = *dp >> 1;
534 if (*debug & DEBUG_L2_TEI)
535 tm->tei_m.printdebug(fi, "identity denied ri %d tei %d",
536 ri, tei);
537}
538
539static void
540tei_id_chk_req(struct FsmInst *fi, int event, void *arg)
541{
542 struct teimgr *tm = fi->userdata;
543 u_char *dp = arg;
544 int tei;
545
546 tei = *(dp+3) >> 1;
547 if (*debug & DEBUG_L2_TEI)
548 tm->tei_m.printdebug(fi, "identity check req tei %d", tei);
549 if ((tm->l2->tei != GROUP_TEI) && ((tei == GROUP_TEI) ||
550 (tei == tm->l2->tei))) {
551 mISDN_FsmDelTimer(&tm->timer, 4);
552 mISDN_FsmChangeState(&tm->tei_m, ST_TEI_NOP);
553 put_tei_msg(tm->mgr, ID_CHK_RES, random_ri(), tm->l2->tei);
554 }
555}
556
557static void
558tei_id_remove(struct FsmInst *fi, int event, void *arg)
559{
560 struct teimgr *tm = fi->userdata;
561 u_char *dp = arg;
562 int tei;
563
564 tei = *(dp+3) >> 1;
565 if (*debug & DEBUG_L2_TEI)
566 tm->tei_m.printdebug(fi, "identity remove tei %d", tei);
567 if ((tm->l2->tei != GROUP_TEI) &&
568 ((tei == GROUP_TEI) || (tei == tm->l2->tei))) {
569 mISDN_FsmDelTimer(&tm->timer, 5);
570 mISDN_FsmChangeState(&tm->tei_m, ST_TEI_NOP);
571 tei_l2(tm->l2, MDL_REMOVE_REQ, 0);
572 }
573}
574
575static void
576tei_id_verify(struct FsmInst *fi, int event, void *arg)
577{
578 struct teimgr *tm = fi->userdata;
579
580 if (*debug & DEBUG_L2_TEI)
581 tm->tei_m.printdebug(fi, "id verify request for tei %d",
582 tm->l2->tei);
583 put_tei_msg(tm->mgr, ID_VERIFY, 0, tm->l2->tei);
584 mISDN_FsmChangeState(&tm->tei_m, ST_TEI_IDVERIFY);
585 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 2);
586 tm->nval = 2;
587}
588
589static void
590tei_id_req_tout(struct FsmInst *fi, int event, void *arg)
591{
592 struct teimgr *tm = fi->userdata;
593
594 if (--tm->nval) {
595 tm->ri = random_ri();
596 if (*debug & DEBUG_L2_TEI)
597 tm->tei_m.printdebug(fi, "assign req(%d) ri %d",
598 4 - tm->nval, tm->ri);
599 put_tei_msg(tm->mgr, ID_REQUEST, tm->ri, GROUP_TEI);
600 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 3);
601 } else {
602 tm->tei_m.printdebug(fi, "assign req failed");
603 tei_l2(tm->l2, MDL_ERROR_RSP, 0);
604 mISDN_FsmChangeState(fi, ST_TEI_NOP);
605 }
606}
607
608static void
609tei_id_ver_tout(struct FsmInst *fi, int event, void *arg)
610{
611 struct teimgr *tm = fi->userdata;
612
613 if (--tm->nval) {
614 if (*debug & DEBUG_L2_TEI)
615 tm->tei_m.printdebug(fi,
616 "id verify req(%d) for tei %d",
617 3 - tm->nval, tm->l2->tei);
618 put_tei_msg(tm->mgr, ID_VERIFY, 0, tm->l2->tei);
619 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 4);
620 } else {
621 tm->tei_m.printdebug(fi, "verify req for tei %d failed",
622 tm->l2->tei);
623 tei_l2(tm->l2, MDL_REMOVE_REQ, 0);
624 mISDN_FsmChangeState(fi, ST_TEI_NOP);
625 }
626}
627
628static struct FsmNode TeiFnListUser[] =
629{
630 {ST_TEI_NOP, EV_IDREQ, tei_id_request},
631 {ST_TEI_NOP, EV_ASSIGN, tei_id_test_dup},
632 {ST_TEI_NOP, EV_VERIFY, tei_id_verify},
633 {ST_TEI_NOP, EV_REMOVE, tei_id_remove},
634 {ST_TEI_NOP, EV_CHKREQ, tei_id_chk_req},
635 {ST_TEI_IDREQ, EV_TIMER, tei_id_req_tout},
636 {ST_TEI_IDREQ, EV_ASSIGN, tei_id_assign},
637 {ST_TEI_IDREQ, EV_DENIED, tei_id_denied},
638 {ST_TEI_IDVERIFY, EV_TIMER, tei_id_ver_tout},
639 {ST_TEI_IDVERIFY, EV_REMOVE, tei_id_remove},
640 {ST_TEI_IDVERIFY, EV_CHKREQ, tei_id_chk_req},
641};
642
643static void
644tei_l2remove(struct layer2 *l2)
645{
646 put_tei_msg(l2->tm->mgr, ID_REMOVE, 0, l2->tei);
647 tei_l2(l2, MDL_REMOVE_REQ, 0);
648 list_del(&l2->ch.list);
649 l2->ch.ctrl(&l2->ch, CLOSE_CHANNEL, NULL);
650}
651
652static void
653tei_assign_req(struct FsmInst *fi, int event, void *arg)
654{
655 struct teimgr *tm = fi->userdata;
656 u_char *dp = arg;
657
658 if (tm->l2->tei == GROUP_TEI) {
659 tm->tei_m.printdebug(&tm->tei_m,
660 "net tei assign request without tei");
661 return;
662 }
663 tm->ri = ((unsigned int) *dp++ << 8);
664 tm->ri += *dp++;
665 if (*debug & DEBUG_L2_TEI)
666 tm->tei_m.printdebug(&tm->tei_m,
667 "net assign request ri %d teim %d", tm->ri, *dp);
668 put_tei_msg(tm->mgr, ID_ASSIGNED, tm->ri, tm->l2->tei);
669 mISDN_FsmChangeState(fi, ST_TEI_NOP);
670}
671
672static void
673tei_id_chk_req_net(struct FsmInst *fi, int event, void *arg)
674{
675 struct teimgr *tm = fi->userdata;
676
677 if (*debug & DEBUG_L2_TEI)
678 tm->tei_m.printdebug(fi, "id check request for tei %d",
679 tm->l2->tei);
680 tm->rcnt = 0;
681 put_tei_msg(tm->mgr, ID_CHK_REQ, 0, tm->l2->tei);
682 mISDN_FsmChangeState(&tm->tei_m, ST_TEI_IDVERIFY);
683 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 2);
684 tm->nval = 2;
685}
686
687static void
688tei_id_chk_resp(struct FsmInst *fi, int event, void *arg)
689{
690 struct teimgr *tm = fi->userdata;
691 u_char *dp = arg;
692 int tei;
693
694 tei = dp[3] >> 1;
695 if (*debug & DEBUG_L2_TEI)
696 tm->tei_m.printdebug(fi, "identity check resp tei %d", tei);
697 if (tei == tm->l2->tei)
698 tm->rcnt++;
699}
700
701static void
702tei_id_verify_net(struct FsmInst *fi, int event, void *arg)
703{
704 struct teimgr *tm = fi->userdata;
705 u_char *dp = arg;
706 int tei;
707
708 tei = dp[3] >> 1;
709 if (*debug & DEBUG_L2_TEI)
710 tm->tei_m.printdebug(fi, "identity verify req tei %d/%d",
711 tei, tm->l2->tei);
712 if (tei == tm->l2->tei)
713 tei_id_chk_req_net(fi, event, arg);
714}
715
716static void
717tei_id_ver_tout_net(struct FsmInst *fi, int event, void *arg)
718{
719 struct teimgr *tm = fi->userdata;
720
721 if (tm->rcnt == 1) {
722 if (*debug & DEBUG_L2_TEI)
723 tm->tei_m.printdebug(fi,
724 "check req for tei %d sucessful\n", tm->l2->tei);
725 mISDN_FsmChangeState(fi, ST_TEI_NOP);
726 } else if (tm->rcnt > 1) {
727 /* duplicate assignment; remove */
728 tei_l2remove(tm->l2);
729 } else if (--tm->nval) {
730 if (*debug & DEBUG_L2_TEI)
731 tm->tei_m.printdebug(fi,
732 "id check req(%d) for tei %d",
733 3 - tm->nval, tm->l2->tei);
734 put_tei_msg(tm->mgr, ID_CHK_REQ, 0, tm->l2->tei);
735 mISDN_FsmAddTimer(&tm->timer, tm->tval, EV_TIMER, NULL, 4);
736 } else {
737 tm->tei_m.printdebug(fi, "check req for tei %d failed",
738 tm->l2->tei);
739 mISDN_FsmChangeState(fi, ST_TEI_NOP);
740 tei_l2remove(tm->l2);
741 }
742}
743
744static struct FsmNode TeiFnListNet[] =
745{
746 {ST_TEI_NOP, EV_ASSIGN_REQ, tei_assign_req},
747 {ST_TEI_NOP, EV_VERIFY, tei_id_verify_net},
748 {ST_TEI_NOP, EV_CHKREQ, tei_id_chk_req_net},
749 {ST_TEI_IDVERIFY, EV_TIMER, tei_id_ver_tout_net},
750 {ST_TEI_IDVERIFY, EV_CHKRESP, tei_id_chk_resp},
751};
752
753static void
754tei_ph_data_ind(struct teimgr *tm, u_int mt, u_char *dp, int len)
755{
756 if (test_bit(FLG_FIXED_TEI, &tm->l2->flag))
757 return;
758 if (*debug & DEBUG_L2_TEI)
759 tm->tei_m.printdebug(&tm->tei_m, "tei handler mt %x", mt);
760 if (mt == ID_ASSIGNED)
761 mISDN_FsmEvent(&tm->tei_m, EV_ASSIGN, dp);
762 else if (mt == ID_DENIED)
763 mISDN_FsmEvent(&tm->tei_m, EV_DENIED, dp);
764 else if (mt == ID_CHK_REQ)
765 mISDN_FsmEvent(&tm->tei_m, EV_CHKREQ, dp);
766 else if (mt == ID_REMOVE)
767 mISDN_FsmEvent(&tm->tei_m, EV_REMOVE, dp);
768 else if (mt == ID_VERIFY)
769 mISDN_FsmEvent(&tm->tei_m, EV_VERIFY, dp);
770 else if (mt == ID_CHK_RES)
771 mISDN_FsmEvent(&tm->tei_m, EV_CHKRESP, dp);
772}
773
774static struct layer2 *
775create_new_tei(struct manager *mgr, int tei)
776{
777 u_long opt = 0;
778 u_long flags;
779 int id;
780 struct layer2 *l2;
781
782 if (!mgr->up)
783 return NULL;
784 if (tei < 64)
785 test_and_set_bit(OPTION_L2_FIXEDTEI, &opt);
786 if (mgr->ch.st->dev->Dprotocols
787 & ((1 << ISDN_P_TE_E1) | (1 << ISDN_P_NT_E1)))
788 test_and_set_bit(OPTION_L2_PMX, &opt);
789 l2 = create_l2(mgr->up, ISDN_P_LAPD_NT, (u_int)opt, (u_long)tei);
790 if (!l2) {
791 printk(KERN_WARNING "%s:no memory for layer2\n", __func__);
792 return NULL;
793 }
794 l2->tm = kzalloc(sizeof(struct teimgr), GFP_KERNEL);
795 if (!l2->tm) {
796 kfree(l2);
797 printk(KERN_WARNING "%s:no memory for teimgr\n", __func__);
798 return NULL;
799 }
800 l2->tm->mgr = mgr;
801 l2->tm->l2 = l2;
802 l2->tm->tei_m.debug = *debug & DEBUG_L2_TEIFSM;
803 l2->tm->tei_m.userdata = l2->tm;
804 l2->tm->tei_m.printdebug = tei_debug;
805 l2->tm->tei_m.fsm = &teifsmn;
806 l2->tm->tei_m.state = ST_TEI_NOP;
807 l2->tm->tval = 2000; /* T202 2 sec */
808 mISDN_FsmInitTimer(&l2->tm->tei_m, &l2->tm->timer);
809 write_lock_irqsave(&mgr->lock, flags);
810 id = get_free_id(mgr);
811 list_add_tail(&l2->list, &mgr->layer2);
812 write_unlock_irqrestore(&mgr->lock, flags);
813 if (id < 0) {
814 l2->ch.ctrl(&l2->ch, CLOSE_CHANNEL, NULL);
815 printk(KERN_WARNING "%s:no free id\n", __func__);
816 return NULL;
817 } else {
818 l2->ch.nr = id;
819 __add_layer2(&l2->ch, mgr->ch.st);
820 l2->ch.recv = mgr->ch.recv;
821 l2->ch.peer = mgr->ch.peer;
822 l2->ch.ctrl(&l2->ch, OPEN_CHANNEL, NULL);
823 }
824 return l2;
825}
826
827static void
828new_tei_req(struct manager *mgr, u_char *dp)
829{
830 int tei, ri;
831 struct layer2 *l2;
832
833 ri = dp[0] << 8;
834 ri += dp[1];
835 if (!mgr->up)
836 goto denied;
837 tei = get_free_tei(mgr);
838 if (tei < 0) {
839 printk(KERN_WARNING "%s:No free tei\n", __func__);
840 goto denied;
841 }
842 l2 = create_new_tei(mgr, tei);
843 if (!l2)
844 goto denied;
845 else
846 mISDN_FsmEvent(&l2->tm->tei_m, EV_ASSIGN_REQ, dp);
847 return;
848denied:
849 put_tei_msg(mgr, ID_DENIED, ri, GROUP_TEI);
850}
851
852static int
853ph_data_ind(struct manager *mgr, struct sk_buff *skb)
854{
855 int ret = -EINVAL;
856 struct layer2 *l2;
857 u_long flags;
858 u_char mt;
859
860 if (skb->len < 8) {
861 if (*debug & DEBUG_L2_TEI)
862 printk(KERN_DEBUG "%s: short mgr frame %d/8\n",
863 __func__, skb->len);
864 goto done;
865 }
866 if (*debug & DEBUG_L2_TEI)
867
868 if ((skb->data[0] >> 2) != TEI_SAPI) /* not for us */
869 goto done;
870 if (skb->data[0] & 1) /* EA0 formal error */
871 goto done;
872 if (!(skb->data[1] & 1)) /* EA1 formal error */
873 goto done;
874 if ((skb->data[1] >> 1) != GROUP_TEI) /* not for us */
875 goto done;
876 if ((skb->data[2] & 0xef) != UI) /* not UI */
877 goto done;
878 if (skb->data[3] != TEI_ENTITY_ID) /* not tei entity */
879 goto done;
880 mt = skb->data[6];
881 switch (mt) {
882 case ID_REQUEST:
883 case ID_CHK_RES:
884 case ID_VERIFY:
885 if (!test_bit(MGR_OPT_NETWORK, &mgr->options))
886 goto done;
887 break;
888 case ID_ASSIGNED:
889 case ID_DENIED:
890 case ID_CHK_REQ:
891 case ID_REMOVE:
892 if (test_bit(MGR_OPT_NETWORK, &mgr->options))
893 goto done;
894 break;
895 default:
896 goto done;
897 }
898 ret = 0;
899 if (mt == ID_REQUEST) {
900 new_tei_req(mgr, &skb->data[4]);
901 goto done;
902 }
903 read_lock_irqsave(&mgr->lock, flags);
904 list_for_each_entry(l2, &mgr->layer2, list) {
905 tei_ph_data_ind(l2->tm, mt, &skb->data[4], skb->len - 4);
906 }
907 read_unlock_irqrestore(&mgr->lock, flags);
908done:
909 return ret;
910}
911
912int
913l2_tei(struct layer2 *l2, u_int cmd, u_long arg)
914{
915 struct teimgr *tm = l2->tm;
916
917 if (test_bit(FLG_FIXED_TEI, &l2->flag))
918 return 0;
919 if (*debug & DEBUG_L2_TEI)
920 printk(KERN_DEBUG "%s: cmd(%x)\n", __func__, cmd);
921 switch (cmd) {
922 case MDL_ASSIGN_IND:
923 mISDN_FsmEvent(&tm->tei_m, EV_IDREQ, NULL);
924 break;
925 case MDL_ERROR_IND:
926 if (test_bit(MGR_OPT_NETWORK, &tm->mgr->options))
927 mISDN_FsmEvent(&tm->tei_m, EV_CHKREQ, &l2->tei);
928 if (test_bit(MGR_OPT_USER, &tm->mgr->options))
929 mISDN_FsmEvent(&tm->tei_m, EV_VERIFY, NULL);
930 break;
931 case MDL_STATUS_UP_IND:
932 if (test_bit(MGR_OPT_NETWORK, &tm->mgr->options))
933 mISDN_FsmEvent(&tm->mgr->deact, EV_ACTIVATE, NULL);
934 break;
935 case MDL_STATUS_DOWN_IND:
936 if (test_bit(MGR_OPT_NETWORK, &tm->mgr->options))
937 mISDN_FsmEvent(&tm->mgr->deact, EV_DEACTIVATE, NULL);
938 break;
939 case MDL_STATUS_UI_IND:
940 if (test_bit(MGR_OPT_NETWORK, &tm->mgr->options))
941 mISDN_FsmEvent(&tm->mgr->deact, EV_UI, NULL);
942 break;
943 }
944 return 0;
945}
946
947void
948release_tei(struct layer2 *l2)
949{
950 struct teimgr *tm = l2->tm;
951 u_long flags;
952
953 mISDN_FsmDelTimer(&tm->timer, 1);
954 write_lock_irqsave(&tm->mgr->lock, flags);
955 list_del(&l2->list);
956 write_unlock_irqrestore(&tm->mgr->lock, flags);
957 l2->tm = NULL;
958 kfree(tm);
959}
960
961static int
962create_teimgr(struct manager *mgr, struct channel_req *crq)
963{
964 struct layer2 *l2;
965 u_long opt = 0;
966 u_long flags;
967 int id;
968
969 if (*debug & DEBUG_L2_TEI)
970 printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n",
971 __func__, mgr->ch.st->dev->name, crq->protocol,
972 crq->adr.dev, crq->adr.channel, crq->adr.sapi,
973 crq->adr.tei);
974 if (crq->adr.sapi != 0) /* not supported yet */
975 return -EINVAL;
976 if (crq->adr.tei > GROUP_TEI)
977 return -EINVAL;
978 if (crq->adr.tei < 64)
979 test_and_set_bit(OPTION_L2_FIXEDTEI, &opt);
980 if (crq->adr.tei == 0)
981 test_and_set_bit(OPTION_L2_PTP, &opt);
982 if (test_bit(MGR_OPT_NETWORK, &mgr->options)) {
983 if (crq->protocol == ISDN_P_LAPD_TE)
984 return -EPROTONOSUPPORT;
985 if ((crq->adr.tei != 0) && (crq->adr.tei != 127))
986 return -EINVAL;
987 if (mgr->up) {
988 printk(KERN_WARNING
989 "%s: only one network manager is allowed\n",
990 __func__);
991 return -EBUSY;
992 }
993 } else if (test_bit(MGR_OPT_USER, &mgr->options)) {
994 if (crq->protocol == ISDN_P_LAPD_NT)
995 return -EPROTONOSUPPORT;
996 if ((crq->adr.tei >= 64) && (crq->adr.tei < GROUP_TEI))
997 return -EINVAL; /* dyn tei */
998 } else {
999 if (crq->protocol == ISDN_P_LAPD_NT)
1000 test_and_set_bit(MGR_OPT_NETWORK, &mgr->options);
1001 if (crq->protocol == ISDN_P_LAPD_TE)
1002 test_and_set_bit(MGR_OPT_USER, &mgr->options);
1003 }
1004 if (mgr->ch.st->dev->Dprotocols
1005 & ((1 << ISDN_P_TE_E1) | (1 << ISDN_P_NT_E1)))
1006 test_and_set_bit(OPTION_L2_PMX, &opt);
1007 if ((crq->protocol == ISDN_P_LAPD_NT) && (crq->adr.tei == 127)) {
1008 mgr->up = crq->ch;
1009 id = DL_INFO_L2_CONNECT;
1010 teiup_create(mgr, DL_INFORMATION_IND, sizeof(id), &id);
1011 crq->ch = NULL;
1012 if (!list_empty(&mgr->layer2)) {
1013 read_lock_irqsave(&mgr->lock, flags);
1014 list_for_each_entry(l2, &mgr->layer2, list) {
1015 l2->up = mgr->up;
1016 l2->ch.ctrl(&l2->ch, OPEN_CHANNEL, NULL);
1017 }
1018 read_unlock_irqrestore(&mgr->lock, flags);
1019 }
1020 return 0;
1021 }
1022 l2 = create_l2(crq->ch, crq->protocol, (u_int)opt,
1023 (u_long)crq->adr.tei);
1024 if (!l2)
1025 return -ENOMEM;
1026 l2->tm = kzalloc(sizeof(struct teimgr), GFP_KERNEL);
1027 if (!l2->tm) {
1028 kfree(l2);
1029 printk(KERN_ERR "kmalloc teimgr failed\n");
1030 return -ENOMEM;
1031 }
1032 l2->tm->mgr = mgr;
1033 l2->tm->l2 = l2;
1034 l2->tm->tei_m.debug = *debug & DEBUG_L2_TEIFSM;
1035 l2->tm->tei_m.userdata = l2->tm;
1036 l2->tm->tei_m.printdebug = tei_debug;
1037 if (crq->protocol == ISDN_P_LAPD_TE) {
1038 l2->tm->tei_m.fsm = &teifsmu;
1039 l2->tm->tei_m.state = ST_TEI_NOP;
1040 l2->tm->tval = 1000; /* T201 1 sec */
1041 } else {
1042 l2->tm->tei_m.fsm = &teifsmn;
1043 l2->tm->tei_m.state = ST_TEI_NOP;
1044 l2->tm->tval = 2000; /* T202 2 sec */
1045 }
1046 mISDN_FsmInitTimer(&l2->tm->tei_m, &l2->tm->timer);
1047 write_lock_irqsave(&mgr->lock, flags);
1048 id = get_free_id(mgr);
1049 list_add_tail(&l2->list, &mgr->layer2);
1050 write_unlock_irqrestore(&mgr->lock, flags);
1051 if (id < 0) {
1052 l2->ch.ctrl(&l2->ch, CLOSE_CHANNEL, NULL);
1053 } else {
1054 l2->ch.nr = id;
1055 l2->up->nr = id;
1056 crq->ch = &l2->ch;
1057 id = 0;
1058 }
1059 return id;
1060}
1061
1062static int
1063mgr_send(struct mISDNchannel *ch, struct sk_buff *skb)
1064{
1065 struct manager *mgr;
1066 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1067 int ret = -EINVAL;
1068
1069 mgr = container_of(ch, struct manager, ch);
1070 if (*debug & DEBUG_L2_RECV)
1071 printk(KERN_DEBUG "%s: prim(%x) id(%x)\n",
1072 __func__, hh->prim, hh->id);
1073 switch (hh->prim) {
1074 case PH_DATA_IND:
1075 mISDN_FsmEvent(&mgr->deact, EV_UI, NULL);
1076 ret = ph_data_ind(mgr, skb);
1077 break;
1078 case PH_DATA_CNF:
1079 do_ack(mgr, hh->id);
1080 ret = 0;
1081 break;
1082 case PH_ACTIVATE_IND:
1083 test_and_set_bit(MGR_PH_ACTIVE, &mgr->options);
1084 mISDN_FsmEvent(&mgr->deact, EV_ACTIVATE_IND, NULL);
1085 do_send(mgr);
1086 ret = 0;
1087 break;
1088 case PH_DEACTIVATE_IND:
1089 test_and_clear_bit(MGR_PH_ACTIVE, &mgr->options);
1090 mISDN_FsmEvent(&mgr->deact, EV_DEACTIVATE_IND, NULL);
1091 ret = 0;
1092 break;
1093 case DL_UNITDATA_REQ:
1094 return dl_unit_data(mgr, skb);
1095 }
1096 if (!ret)
1097 dev_kfree_skb(skb);
1098 return ret;
1099}
1100
1101static int
1102free_teimanager(struct manager *mgr)
1103{
1104 struct layer2 *l2, *nl2;
1105
1106 if (test_bit(MGR_OPT_NETWORK, &mgr->options)) {
1107 /* not locked lock is taken in release tei */
1108 mgr->up = NULL;
1109 if (test_bit(OPTION_L2_CLEANUP, &mgr->options)) {
1110 list_for_each_entry_safe(l2, nl2, &mgr->layer2, list) {
1111 put_tei_msg(mgr, ID_REMOVE, 0, l2->tei);
1112 mutex_lock(&mgr->ch.st->lmutex);
1113 list_del(&l2->ch.list);
1114 mutex_unlock(&mgr->ch.st->lmutex);
1115 l2->ch.ctrl(&l2->ch, CLOSE_CHANNEL, NULL);
1116 }
1117 test_and_clear_bit(MGR_OPT_NETWORK, &mgr->options);
1118 } else {
1119 list_for_each_entry_safe(l2, nl2, &mgr->layer2, list) {
1120 l2->up = NULL;
1121 }
1122 }
1123 }
1124 if (test_bit(MGR_OPT_USER, &mgr->options)) {
1125 if (list_empty(&mgr->layer2))
1126 test_and_clear_bit(MGR_OPT_USER, &mgr->options);
1127 }
1128 mgr->ch.st->dev->D.ctrl(&mgr->ch.st->dev->D, CLOSE_CHANNEL, NULL);
1129 return 0;
1130}
1131
1132static int
1133ctrl_teimanager(struct manager *mgr, void *arg)
1134{
1135 /* currently we only have one option */
1136 int clean = *((int *)arg);
1137
1138 if (clean)
1139 test_and_set_bit(OPTION_L2_CLEANUP, &mgr->options);
1140 else
1141 test_and_clear_bit(OPTION_L2_CLEANUP, &mgr->options);
1142 return 0;
1143}
1144
1145/* This function does create a L2 for fixed TEI in NT Mode */
1146static int
1147check_data(struct manager *mgr, struct sk_buff *skb)
1148{
1149 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1150 int ret, tei;
1151 struct layer2 *l2;
1152
1153 if (*debug & DEBUG_L2_CTRL)
1154 printk(KERN_DEBUG "%s: prim(%x) id(%x)\n",
1155 __func__, hh->prim, hh->id);
1156 if (test_bit(MGR_OPT_USER, &mgr->options))
1157 return -ENOTCONN;
1158 if (hh->prim != PH_DATA_IND)
1159 return -ENOTCONN;
1160 if (skb->len != 3)
1161 return -ENOTCONN;
1162 if (skb->data[0] != 0)
1163 /* only SAPI 0 command */
1164 return -ENOTCONN;
1165 if (!(skb->data[1] & 1)) /* invalid EA1 */
1166 return -EINVAL;
1167 tei = skb->data[1] >> 0;
1168 if (tei > 63) /* not a fixed tei */
1169 return -ENOTCONN;
1170 if ((skb->data[2] & ~0x10) != SABME)
1171 return -ENOTCONN;
1172 /* We got a SABME for a fixed TEI */
1173 l2 = create_new_tei(mgr, tei);
1174 if (!l2)
1175 return -ENOMEM;
1176 ret = l2->ch.send(&l2->ch, skb);
1177 return ret;
1178}
1179
1180void
1181delete_teimanager(struct mISDNchannel *ch)
1182{
1183 struct manager *mgr;
1184 struct layer2 *l2, *nl2;
1185
1186 mgr = container_of(ch, struct manager, ch);
1187 /* not locked lock is taken in release tei */
1188 list_for_each_entry_safe(l2, nl2, &mgr->layer2, list) {
1189 mutex_lock(&mgr->ch.st->lmutex);
1190 list_del(&l2->ch.list);
1191 mutex_unlock(&mgr->ch.st->lmutex);
1192 l2->ch.ctrl(&l2->ch, CLOSE_CHANNEL, NULL);
1193 }
1194 list_del(&mgr->ch.list);
1195 list_del(&mgr->bcast.list);
1196 skb_queue_purge(&mgr->sendq);
1197 kfree(mgr);
1198}
1199
1200static int
1201mgr_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
1202{
1203 struct manager *mgr;
1204 int ret = -EINVAL;
1205
1206 mgr = container_of(ch, struct manager, ch);
1207 if (*debug & DEBUG_L2_CTRL)
1208 printk(KERN_DEBUG "%s(%x, %p)\n", __func__, cmd, arg);
1209 switch (cmd) {
1210 case OPEN_CHANNEL:
1211 ret = create_teimgr(mgr, arg);
1212 break;
1213 case CLOSE_CHANNEL:
1214 ret = free_teimanager(mgr);
1215 break;
1216 case CONTROL_CHANNEL:
1217 ret = ctrl_teimanager(mgr, arg);
1218 break;
1219 case CHECK_DATA:
1220 ret = check_data(mgr, arg);
1221 break;
1222 }
1223 return ret;
1224}
1225
1226static int
1227mgr_bcast(struct mISDNchannel *ch, struct sk_buff *skb)
1228{
1229 struct manager *mgr = container_of(ch, struct manager, bcast);
1230 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1231 struct sk_buff *cskb = NULL;
1232 struct layer2 *l2;
1233 u_long flags;
1234 int ret;
1235
1236 read_lock_irqsave(&mgr->lock, flags);
1237 list_for_each_entry(l2, &mgr->layer2, list) {
1238 if ((hh->id & MISDN_ID_SAPI_MASK) ==
1239 (l2->ch.addr & MISDN_ID_SAPI_MASK)) {
1240 if (list_is_last(&l2->list, &mgr->layer2)) {
1241 cskb = skb;
1242 skb = NULL;
1243 } else {
1244 if (!cskb)
1245 cskb = skb_copy(skb, GFP_KERNEL);
1246 }
1247 if (cskb) {
1248 ret = l2->ch.send(&l2->ch, cskb);
1249 if (ret) {
1250 if (*debug & DEBUG_SEND_ERR)
1251 printk(KERN_DEBUG
1252 "%s ch%d prim(%x) addr(%x)"
1253 " err %d\n",
1254 __func__, l2->ch.nr,
1255 hh->prim, l2->ch.addr, ret);
1256 } else
1257 cskb = NULL;
1258 } else {
1259 printk(KERN_WARNING "%s ch%d addr %x no mem\n",
1260 __func__, ch->nr, ch->addr);
1261 goto out;
1262 }
1263 }
1264 }
1265out:
1266 read_unlock_irqrestore(&mgr->lock, flags);
1267 if (cskb)
1268 dev_kfree_skb(cskb);
1269 if (skb)
1270 dev_kfree_skb(skb);
1271 return 0;
1272}
1273
1274static int
1275mgr_bcast_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
1276{
1277
1278 return -EINVAL;
1279}
1280
1281int
1282create_teimanager(struct mISDNdevice *dev)
1283{
1284 struct manager *mgr;
1285
1286 mgr = kzalloc(sizeof(struct manager), GFP_KERNEL);
1287 if (!mgr)
1288 return -ENOMEM;
1289 INIT_LIST_HEAD(&mgr->layer2);
1290 mgr->lock = __RW_LOCK_UNLOCKED(mgr->lock);
1291 skb_queue_head_init(&mgr->sendq);
1292 mgr->nextid = 1;
1293 mgr->lastid = MISDN_ID_NONE;
1294 mgr->ch.send = mgr_send;
1295 mgr->ch.ctrl = mgr_ctrl;
1296 mgr->ch.st = dev->D.st;
1297 set_channel_address(&mgr->ch, TEI_SAPI, GROUP_TEI);
1298 add_layer2(&mgr->ch, dev->D.st);
1299 mgr->bcast.send = mgr_bcast;
1300 mgr->bcast.ctrl = mgr_bcast_ctrl;
1301 mgr->bcast.st = dev->D.st;
1302 set_channel_address(&mgr->bcast, 0, GROUP_TEI);
1303 add_layer2(&mgr->bcast, dev->D.st);
1304 mgr->deact.debug = *debug & DEBUG_MANAGER;
1305 mgr->deact.userdata = mgr;
1306 mgr->deact.printdebug = da_debug;
1307 mgr->deact.fsm = &deactfsm;
1308 mgr->deact.state = ST_L1_DEACT;
1309 mISDN_FsmInitTimer(&mgr->deact, &mgr->datimer);
1310 dev->teimgr = &mgr->ch;
1311 return 0;
1312}
1313
1314int TEIInit(u_int *deb)
1315{
1316 debug = deb;
1317 teifsmu.state_count = TEI_STATE_COUNT;
1318 teifsmu.event_count = TEI_EVENT_COUNT;
1319 teifsmu.strEvent = strTeiEvent;
1320 teifsmu.strState = strTeiState;
1321 mISDN_FsmNew(&teifsmu, TeiFnListUser, ARRAY_SIZE(TeiFnListUser));
1322 teifsmn.state_count = TEI_STATE_COUNT;
1323 teifsmn.event_count = TEI_EVENT_COUNT;
1324 teifsmn.strEvent = strTeiEvent;
1325 teifsmn.strState = strTeiState;
1326 mISDN_FsmNew(&teifsmn, TeiFnListNet, ARRAY_SIZE(TeiFnListNet));
1327 deactfsm.state_count = DEACT_STATE_COUNT;
1328 deactfsm.event_count = DEACT_EVENT_COUNT;
1329 deactfsm.strEvent = strDeactEvent;
1330 deactfsm.strState = strDeactState;
1331 mISDN_FsmNew(&deactfsm, DeactFnList, ARRAY_SIZE(DeactFnList));
1332 return 0;
1333}
1334
1335void TEIFree(void)
1336{
1337 mISDN_FsmFree(&teifsmu);
1338 mISDN_FsmFree(&teifsmn);
1339 mISDN_FsmFree(&deactfsm);
1340}
diff --git a/drivers/isdn/mISDN/timerdev.c b/drivers/isdn/mISDN/timerdev.c
new file mode 100644
index 000000000000..b5fabc7019d8
--- /dev/null
+++ b/drivers/isdn/mISDN/timerdev.c
@@ -0,0 +1,301 @@
1/*
2 *
3 * general timer device for using in ISDN stacks
4 *
5 * Author Karsten Keil <kkeil@novell.com>
6 *
7 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 */
19
20#include <linux/poll.h>
21#include <linux/vmalloc.h>
22#include <linux/timer.h>
23#include <linux/miscdevice.h>
24#include <linux/module.h>
25#include <linux/mISDNif.h>
26
27static int *debug;
28
29
30struct mISDNtimerdev {
31 int next_id;
32 struct list_head pending;
33 struct list_head expired;
34 wait_queue_head_t wait;
35 u_int work;
36 spinlock_t lock; /* protect lists */
37};
38
39struct mISDNtimer {
40 struct list_head list;
41 struct mISDNtimerdev *dev;
42 struct timer_list tl;
43 int id;
44};
45
46static int
47mISDN_open(struct inode *ino, struct file *filep)
48{
49 struct mISDNtimerdev *dev;
50
51 if (*debug & DEBUG_TIMER)
52 printk(KERN_DEBUG "%s(%p,%p)\n", __func__, ino, filep);
53 dev = kmalloc(sizeof(struct mISDNtimerdev) , GFP_KERNEL);
54 if (!dev)
55 return -ENOMEM;
56 dev->next_id = 1;
57 INIT_LIST_HEAD(&dev->pending);
58 INIT_LIST_HEAD(&dev->expired);
59 spin_lock_init(&dev->lock);
60 dev->work = 0;
61 init_waitqueue_head(&dev->wait);
62 filep->private_data = dev;
63 __module_get(THIS_MODULE);
64 return 0;
65}
66
67static int
68mISDN_close(struct inode *ino, struct file *filep)
69{
70 struct mISDNtimerdev *dev = filep->private_data;
71 struct mISDNtimer *timer, *next;
72
73 if (*debug & DEBUG_TIMER)
74 printk(KERN_DEBUG "%s(%p,%p)\n", __func__, ino, filep);
75 list_for_each_entry_safe(timer, next, &dev->pending, list) {
76 del_timer(&timer->tl);
77 kfree(timer);
78 }
79 list_for_each_entry_safe(timer, next, &dev->expired, list) {
80 kfree(timer);
81 }
82 kfree(dev);
83 module_put(THIS_MODULE);
84 return 0;
85}
86
87static ssize_t
88mISDN_read(struct file *filep, char *buf, size_t count, loff_t *off)
89{
90 struct mISDNtimerdev *dev = filep->private_data;
91 struct mISDNtimer *timer;
92 u_long flags;
93 int ret = 0;
94
95 if (*debug & DEBUG_TIMER)
96 printk(KERN_DEBUG "%s(%p, %p, %d, %p)\n", __func__,
97 filep, buf, (int)count, off);
98 if (*off != filep->f_pos)
99 return -ESPIPE;
100
101 if (list_empty(&dev->expired) && (dev->work == 0)) {
102 if (filep->f_flags & O_NONBLOCK)
103 return -EAGAIN;
104 wait_event_interruptible(dev->wait, (dev->work ||
105 !list_empty(&dev->expired)));
106 if (signal_pending(current))
107 return -ERESTARTSYS;
108 }
109 if (count < sizeof(int))
110 return -ENOSPC;
111 if (dev->work)
112 dev->work = 0;
113 if (!list_empty(&dev->expired)) {
114 spin_lock_irqsave(&dev->lock, flags);
115 timer = (struct mISDNtimer *)dev->expired.next;
116 list_del(&timer->list);
117 spin_unlock_irqrestore(&dev->lock, flags);
118 if (put_user(timer->id, (int *)buf))
119 ret = -EFAULT;
120 else
121 ret = sizeof(int);
122 kfree(timer);
123 }
124 return ret;
125}
126
127static loff_t
128mISDN_llseek(struct file *filep, loff_t offset, int orig)
129{
130 return -ESPIPE;
131}
132
133static ssize_t
134mISDN_write(struct file *filep, const char *buf, size_t count, loff_t *off)
135{
136 return -EOPNOTSUPP;
137}
138
139static unsigned int
140mISDN_poll(struct file *filep, poll_table *wait)
141{
142 struct mISDNtimerdev *dev = filep->private_data;
143 unsigned int mask = POLLERR;
144
145 if (*debug & DEBUG_TIMER)
146 printk(KERN_DEBUG "%s(%p, %p)\n", __func__, filep, wait);
147 if (dev) {
148 poll_wait(filep, &dev->wait, wait);
149 mask = 0;
150 if (dev->work || !list_empty(&dev->expired))
151 mask |= (POLLIN | POLLRDNORM);
152 if (*debug & DEBUG_TIMER)
153 printk(KERN_DEBUG "%s work(%d) empty(%d)\n", __func__,
154 dev->work, list_empty(&dev->expired));
155 }
156 return mask;
157}
158
159static void
160dev_expire_timer(struct mISDNtimer *timer)
161{
162 u_long flags;
163
164 spin_lock_irqsave(&timer->dev->lock, flags);
165 list_del(&timer->list);
166 list_add_tail(&timer->list, &timer->dev->expired);
167 spin_unlock_irqrestore(&timer->dev->lock, flags);
168 wake_up_interruptible(&timer->dev->wait);
169}
170
171static int
172misdn_add_timer(struct mISDNtimerdev *dev, int timeout)
173{
174 int id;
175 u_long flags;
176 struct mISDNtimer *timer;
177
178 if (!timeout) {
179 dev->work = 1;
180 wake_up_interruptible(&dev->wait);
181 id = 0;
182 } else {
183 timer = kzalloc(sizeof(struct mISDNtimer), GFP_KERNEL);
184 if (!timer)
185 return -ENOMEM;
186 spin_lock_irqsave(&dev->lock, flags);
187 timer->id = dev->next_id++;
188 if (dev->next_id < 0)
189 dev->next_id = 1;
190 list_add_tail(&timer->list, &dev->pending);
191 spin_unlock_irqrestore(&dev->lock, flags);
192 timer->dev = dev;
193 timer->tl.data = (long)timer;
194 timer->tl.function = (void *) dev_expire_timer;
195 init_timer(&timer->tl);
196 timer->tl.expires = jiffies + ((HZ * (u_long)timeout) / 1000);
197 add_timer(&timer->tl);
198 id = timer->id;
199 }
200 return id;
201}
202
203static int
204misdn_del_timer(struct mISDNtimerdev *dev, int id)
205{
206 u_long flags;
207 struct mISDNtimer *timer;
208 int ret = 0;
209
210 spin_lock_irqsave(&dev->lock, flags);
211 list_for_each_entry(timer, &dev->pending, list) {
212 if (timer->id == id) {
213 list_del_init(&timer->list);
214 del_timer(&timer->tl);
215 ret = timer->id;
216 kfree(timer);
217 goto unlock;
218 }
219 }
220unlock:
221 spin_unlock_irqrestore(&dev->lock, flags);
222 return ret;
223}
224
225static int
226mISDN_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
227 unsigned long arg)
228{
229 struct mISDNtimerdev *dev = filep->private_data;
230 int id, tout, ret = 0;
231
232
233 if (*debug & DEBUG_TIMER)
234 printk(KERN_DEBUG "%s(%p, %x, %lx)\n", __func__,
235 filep, cmd, arg);
236 switch (cmd) {
237 case IMADDTIMER:
238 if (get_user(tout, (int __user *)arg)) {
239 ret = -EFAULT;
240 break;
241 }
242 id = misdn_add_timer(dev, tout);
243 if (*debug & DEBUG_TIMER)
244 printk(KERN_DEBUG "%s add %d id %d\n", __func__,
245 tout, id);
246 if (id < 0) {
247 ret = id;
248 break;
249 }
250 if (put_user(id, (int __user *)arg))
251 ret = -EFAULT;
252 break;
253 case IMDELTIMER:
254 if (get_user(id, (int __user *)arg)) {
255 ret = -EFAULT;
256 break;
257 }
258 if (*debug & DEBUG_TIMER)
259 printk(KERN_DEBUG "%s del id %d\n", __func__, id);
260 id = misdn_del_timer(dev, id);
261 if (put_user(id, (int __user *)arg))
262 ret = -EFAULT;
263 break;
264 default:
265 ret = -EINVAL;
266 }
267 return ret;
268}
269
270static struct file_operations mISDN_fops = {
271 .llseek = mISDN_llseek,
272 .read = mISDN_read,
273 .write = mISDN_write,
274 .poll = mISDN_poll,
275 .ioctl = mISDN_ioctl,
276 .open = mISDN_open,
277 .release = mISDN_close,
278};
279
280static struct miscdevice mISDNtimer = {
281 .minor = MISC_DYNAMIC_MINOR,
282 .name = "mISDNtimer",
283 .fops = &mISDN_fops,
284};
285
286int
287mISDN_inittimer(int *deb)
288{
289 int err;
290
291 debug = deb;
292 err = misc_register(&mISDNtimer);
293 if (err)
294 printk(KERN_WARNING "mISDN: Could not register timer device\n");
295 return err;
296}
297
298void mISDN_timer_cleanup(void)
299{
300 misc_deregister(&mISDNtimer);
301}
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 86a369bc57d6..9556262dda5a 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -103,6 +103,14 @@ config LEDS_HP6XX
103 This option enables led support for the handheld 103 This option enables led support for the handheld
104 HP Jornada 620/660/680/690. 104 HP Jornada 620/660/680/690.
105 105
106config LEDS_PCA9532
107 tristate "LED driver for PCA9532 dimmer"
108 depends on LEDS_CLASS && I2C && INPUT && EXPERIMENTAL
109 help
110 This option enables support for NXP pca9532
111 led controller. It is generally only usefull
112 as a platform driver
113
106config LEDS_GPIO 114config LEDS_GPIO
107 tristate "LED Support for GPIO connected LEDs" 115 tristate "LED Support for GPIO connected LEDs"
108 depends on LEDS_CLASS && GENERIC_GPIO 116 depends on LEDS_CLASS && GENERIC_GPIO
@@ -147,6 +155,14 @@ config LEDS_CLEVO_MAIL
147 To compile this driver as a module, choose M here: the 155 To compile this driver as a module, choose M here: the
148 module will be called leds-clevo-mail. 156 module will be called leds-clevo-mail.
149 157
158config LEDS_PCA955X
159 tristate "LED Support for PCA955x I2C chips"
160 depends on LEDS_CLASS && I2C
161 help
162 This option enables support for LEDs connected to PCA955x
163 LED driver chips accessed via the I2C bus. Supported
164 devices include PCA9550, PCA9551, PCA9552, and PCA9553.
165
150comment "LED Triggers" 166comment "LED Triggers"
151 167
152config LEDS_TRIGGERS 168config LEDS_TRIGGERS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 973d626f5f4a..ff7982b44565 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -16,11 +16,13 @@ obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
16obj-$(CONFIG_LEDS_H1940) += leds-h1940.o 16obj-$(CONFIG_LEDS_H1940) += leds-h1940.o
17obj-$(CONFIG_LEDS_COBALT_QUBE) += leds-cobalt-qube.o 17obj-$(CONFIG_LEDS_COBALT_QUBE) += leds-cobalt-qube.o
18obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o 18obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o
19obj-$(CONFIG_LEDS_PCA9532) += leds-pca9532.o
19obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o 20obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
20obj-$(CONFIG_LEDS_CM_X270) += leds-cm-x270.o 21obj-$(CONFIG_LEDS_CM_X270) += leds-cm-x270.o
21obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o 22obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o
22obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o 23obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o
23obj-$(CONFIG_LEDS_FSG) += leds-fsg.o 24obj-$(CONFIG_LEDS_FSG) += leds-fsg.o
25obj-$(CONFIG_LEDS_PCA955X) += leds-pca955x.o
24 26
25# LED Triggers 27# LED Triggers
26obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o 28obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 0f242b3f09b6..f910eaffe3a6 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -111,16 +111,17 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger)
111 flags); 111 flags);
112 if (led_cdev->trigger->deactivate) 112 if (led_cdev->trigger->deactivate)
113 led_cdev->trigger->deactivate(led_cdev); 113 led_cdev->trigger->deactivate(led_cdev);
114 led_cdev->trigger = NULL;
114 led_set_brightness(led_cdev, LED_OFF); 115 led_set_brightness(led_cdev, LED_OFF);
115 } 116 }
116 if (trigger) { 117 if (trigger) {
117 write_lock_irqsave(&trigger->leddev_list_lock, flags); 118 write_lock_irqsave(&trigger->leddev_list_lock, flags);
118 list_add_tail(&led_cdev->trig_list, &trigger->led_cdevs); 119 list_add_tail(&led_cdev->trig_list, &trigger->led_cdevs);
119 write_unlock_irqrestore(&trigger->leddev_list_lock, flags); 120 write_unlock_irqrestore(&trigger->leddev_list_lock, flags);
121 led_cdev->trigger = trigger;
120 if (trigger->activate) 122 if (trigger->activate)
121 trigger->activate(led_cdev); 123 trigger->activate(led_cdev);
122 } 124 }
123 led_cdev->trigger = trigger;
124} 125}
125EXPORT_SYMBOL_GPL(led_trigger_set); 126EXPORT_SYMBOL_GPL(led_trigger_set);
126 127
diff --git a/drivers/leds/leds-atmel-pwm.c b/drivers/leds/leds-atmel-pwm.c
index 28db6c1444ed..52297c3ab246 100644
--- a/drivers/leds/leds-atmel-pwm.c
+++ b/drivers/leds/leds-atmel-pwm.c
@@ -37,7 +37,7 @@ static int __init pwmled_probe(struct platform_device *pdev)
37{ 37{
38 const struct gpio_led_platform_data *pdata; 38 const struct gpio_led_platform_data *pdata;
39 struct pwmled *leds; 39 struct pwmled *leds;
40 unsigned i; 40 int i;
41 int status; 41 int status;
42 42
43 pdata = pdev->dev.platform_data; 43 pdata = pdev->dev.platform_data;
diff --git a/drivers/leds/leds-h1940.c b/drivers/leds/leds-h1940.c
index bcec42230389..73c705021686 100644
--- a/drivers/leds/leds-h1940.c
+++ b/drivers/leds/leds-h1940.c
@@ -23,7 +23,8 @@
23/* 23/*
24 * Green led. 24 * Green led.
25 */ 25 */
26void h1940_greenled_set(struct led_classdev *led_dev, enum led_brightness value) 26static void h1940_greenled_set(struct led_classdev *led_dev,
27 enum led_brightness value)
27{ 28{
28 switch (value) { 29 switch (value) {
29 case LED_HALF: 30 case LED_HALF:
@@ -52,7 +53,8 @@ static struct led_classdev h1940_greenled = {
52/* 53/*
53 * Red led. 54 * Red led.
54 */ 55 */
55void h1940_redled_set(struct led_classdev *led_dev, enum led_brightness value) 56static void h1940_redled_set(struct led_classdev *led_dev,
57 enum led_brightness value)
56{ 58{
57 switch (value) { 59 switch (value) {
58 case LED_HALF: 60 case LED_HALF:
@@ -82,7 +84,8 @@ static struct led_classdev h1940_redled = {
82 * Blue led. 84 * Blue led.
83 * (it can only be blue flashing led) 85 * (it can only be blue flashing led)
84 */ 86 */
85void h1940_blueled_set(struct led_classdev *led_dev, enum led_brightness value) 87static void h1940_blueled_set(struct led_classdev *led_dev,
88 enum led_brightness value)
86{ 89{
87 if (value) { 90 if (value) {
88 /* flashing Blue */ 91 /* flashing Blue */
diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
new file mode 100644
index 000000000000..4064d4f6b33b
--- /dev/null
+++ b/drivers/leds/leds-pca9532.c
@@ -0,0 +1,337 @@
1/*
2 * pca9532.c - 16-bit Led dimmer
3 *
4 * Copyright (C) 2008 Riku Voipio <riku.voipio@movial.fi>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * Datasheet: http://www.nxp.com/acrobat/datasheets/PCA9532_3.pdf
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/i2c.h>
16#include <linux/leds.h>
17#include <linux/input.h>
18#include <linux/mutex.h>
19#include <linux/leds-pca9532.h>
20
21static const unsigned short normal_i2c[] = { /*0x60,*/ I2C_CLIENT_END};
22I2C_CLIENT_INSMOD_1(pca9532);
23
24#define PCA9532_REG_PSC(i) (0x2+(i)*2)
25#define PCA9532_REG_PWM(i) (0x3+(i)*2)
26#define PCA9532_REG_LS0 0x6
27#define LED_REG(led) ((led>>2)+PCA9532_REG_LS0)
28#define LED_NUM(led) (led & 0x3)
29
30#define ldev_to_led(c) container_of(c, struct pca9532_led, ldev)
31
32struct pca9532_data {
33 struct i2c_client *client;
34 struct pca9532_led leds[16];
35 struct mutex update_lock;
36 struct input_dev *idev;
37 u8 pwm[2];
38 u8 psc[2];
39};
40
41static int pca9532_probe(struct i2c_client *client,
42 const struct i2c_device_id *id);
43static int pca9532_remove(struct i2c_client *client);
44
45static const struct i2c_device_id pca9532_id[] = {
46 { "pca9532", 0 },
47 { }
48};
49
50MODULE_DEVICE_TABLE(i2c, pca9532_id);
51
52static struct i2c_driver pca9532_driver = {
53 .driver = {
54 .name = "pca9532",
55 },
56 .probe = pca9532_probe,
57 .remove = pca9532_remove,
58 .id_table = pca9532_id,
59};
60
61/* We have two pwm/blinkers, but 16 possible leds to drive. Additionaly,
62 * the clever Thecus people are using one pwm to drive the beeper. So,
63 * as a compromise we average one pwm to the values requested by all
64 * leds that are not ON/OFF.
65 * */
66static int pca9532_setpwm(struct i2c_client *client, int pwm, int blink,
67 enum led_brightness value)
68{
69 int a = 0, b = 0, i = 0;
70 struct pca9532_data *data = i2c_get_clientdata(client);
71 for (i = 0; i < 16; i++) {
72 if (data->leds[i].type == PCA9532_TYPE_LED &&
73 data->leds[i].state == PCA9532_PWM0+pwm) {
74 a++;
75 b += data->leds[i].ldev.brightness;
76 }
77 }
78 if (a == 0) {
79 dev_err(&client->dev,
80 "fear of division by zero %d/%d, wanted %d\n",
81 b, a, value);
82 return -EINVAL;
83 }
84 b = b/a;
85 if (b > 0xFF)
86 return -EINVAL;
87 mutex_lock(&data->update_lock);
88 data->pwm[pwm] = b;
89 i2c_smbus_write_byte_data(client, PCA9532_REG_PWM(pwm),
90 data->pwm[pwm]);
91 data->psc[pwm] = blink;
92 i2c_smbus_write_byte_data(client, PCA9532_REG_PSC(pwm),
93 data->psc[pwm]);
94 mutex_unlock(&data->update_lock);
95 return 0;
96}
97
98/* Set LED routing */
99static void pca9532_setled(struct pca9532_led *led)
100{
101 struct i2c_client *client = led->client;
102 struct pca9532_data *data = i2c_get_clientdata(client);
103 char reg;
104
105 mutex_lock(&data->update_lock);
106 reg = i2c_smbus_read_byte_data(client, LED_REG(led->id));
107 /* zero led bits */
108 reg = reg & ~(0x3<<LED_NUM(led->id)*2);
109 /* set the new value */
110 reg = reg | (led->state << LED_NUM(led->id)*2);
111 i2c_smbus_write_byte_data(client, LED_REG(led->id), reg);
112 mutex_unlock(&data->update_lock);
113}
114
115static void pca9532_set_brightness(struct led_classdev *led_cdev,
116 enum led_brightness value)
117{
118 int err = 0;
119 struct pca9532_led *led = ldev_to_led(led_cdev);
120
121 if (value == LED_OFF)
122 led->state = PCA9532_OFF;
123 else if (value == LED_FULL)
124 led->state = PCA9532_ON;
125 else {
126 led->state = PCA9532_PWM0; /* Thecus: hardcode one pwm */
127 err = pca9532_setpwm(led->client, 0, 0, value);
128 if (err)
129 return; /* XXX: led api doesn't allow error code? */
130 }
131 pca9532_setled(led);
132}
133
134static int pca9532_set_blink(struct led_classdev *led_cdev,
135 unsigned long *delay_on, unsigned long *delay_off)
136{
137 struct pca9532_led *led = ldev_to_led(led_cdev);
138 struct i2c_client *client = led->client;
139 int psc;
140
141 if (*delay_on == 0 && *delay_off == 0) {
142 /* led subsystem ask us for a blink rate */
143 *delay_on = 1000;
144 *delay_off = 1000;
145 }
146 if (*delay_on != *delay_off || *delay_on > 1690 || *delay_on < 6)
147 return -EINVAL;
148
149 /* Thecus specific: only use PSC/PWM 0 */
150 psc = (*delay_on * 152-1)/1000;
151 return pca9532_setpwm(client, 0, psc, led_cdev->brightness);
152}
153
154int pca9532_event(struct input_dev *dev, unsigned int type, unsigned int code,
155 int value)
156{
157 struct pca9532_data *data = input_get_drvdata(dev);
158
159 if (type != EV_SND && (code != SND_BELL || code != SND_TONE))
160 return -1;
161
162 /* XXX: allow different kind of beeps with psc/pwm modifications */
163 if (value > 1 && value < 32767)
164 data->pwm[1] = 127;
165 else
166 data->pwm[1] = 0;
167
168 dev_info(&dev->dev, "setting beep to %d \n", data->pwm[1]);
169 mutex_lock(&data->update_lock);
170 i2c_smbus_write_byte_data(data->client, PCA9532_REG_PWM(1),
171 data->pwm[1]);
172 mutex_unlock(&data->update_lock);
173
174 return 0;
175}
176
177static int pca9532_configure(struct i2c_client *client,
178 struct pca9532_data *data, struct pca9532_platform_data *pdata)
179{
180 int i, err = 0;
181
182 for (i = 0; i < 2; i++) {
183 data->pwm[i] = pdata->pwm[i];
184 data->psc[i] = pdata->psc[i];
185 i2c_smbus_write_byte_data(client, PCA9532_REG_PWM(i),
186 data->pwm[i]);
187 i2c_smbus_write_byte_data(client, PCA9532_REG_PSC(i),
188 data->psc[i]);
189 }
190
191 for (i = 0; i < 16; i++) {
192 struct pca9532_led *led = &data->leds[i];
193 struct pca9532_led *pled = &pdata->leds[i];
194 led->client = client;
195 led->id = i;
196 led->type = pled->type;
197 switch (led->type) {
198 case PCA9532_TYPE_NONE:
199 break;
200 case PCA9532_TYPE_LED:
201 led->state = pled->state;
202 led->name = pled->name;
203 led->ldev.name = led->name;
204 led->ldev.brightness = LED_OFF;
205 led->ldev.brightness_set = pca9532_set_brightness;
206 led->ldev.blink_set = pca9532_set_blink;
207 if (led_classdev_register(&client->dev,
208 &led->ldev) < 0) {
209 dev_err(&client->dev,
210 "couldn't register LED %s\n",
211 led->name);
212 goto exit;
213 }
214 pca9532_setled(led);
215 break;
216 case PCA9532_TYPE_N2100_BEEP:
217 BUG_ON(data->idev);
218 led->state = PCA9532_PWM1;
219 pca9532_setled(led);
220 data->idev = input_allocate_device();
221 if (data->idev == NULL) {
222 err = -ENOMEM;
223 goto exit;
224 }
225 data->idev->name = pled->name;
226 data->idev->phys = "i2c/pca9532";
227 data->idev->id.bustype = BUS_HOST;
228 data->idev->id.vendor = 0x001f;
229 data->idev->id.product = 0x0001;
230 data->idev->id.version = 0x0100;
231 data->idev->evbit[0] = BIT_MASK(EV_SND);
232 data->idev->sndbit[0] = BIT_MASK(SND_BELL) |
233 BIT_MASK(SND_TONE);
234 data->idev->event = pca9532_event;
235 input_set_drvdata(data->idev, data);
236 err = input_register_device(data->idev);
237 if (err) {
238 input_free_device(data->idev);
239 data->idev = NULL;
240 goto exit;
241 }
242 break;
243 }
244 }
245 return 0;
246
247exit:
248 if (i > 0)
249 for (i = i - 1; i >= 0; i--)
250 switch (data->leds[i].type) {
251 case PCA9532_TYPE_NONE:
252 break;
253 case PCA9532_TYPE_LED:
254 led_classdev_unregister(&data->leds[i].ldev);
255 break;
256 case PCA9532_TYPE_N2100_BEEP:
257 if (data->idev != NULL) {
258 input_unregister_device(data->idev);
259 input_free_device(data->idev);
260 data->idev = NULL;
261 }
262 break;
263 }
264
265 return err;
266
267}
268
269static int pca9532_probe(struct i2c_client *client,
270 const struct i2c_device_id *id)
271{
272 struct pca9532_data *data = i2c_get_clientdata(client);
273 struct pca9532_platform_data *pca9532_pdata = client->dev.platform_data;
274
275 if (!i2c_check_functionality(client->adapter,
276 I2C_FUNC_SMBUS_BYTE_DATA))
277 return -EIO;
278
279 data = kzalloc(sizeof(struct pca9532_data), GFP_KERNEL);
280 if (!data)
281 return -ENOMEM;
282
283 dev_info(&client->dev, "setting platform data\n");
284 i2c_set_clientdata(client, data);
285 data->client = client;
286 mutex_init(&data->update_lock);
287
288 if (pca9532_pdata == NULL)
289 return -EIO;
290
291 pca9532_configure(client, data, pca9532_pdata);
292 return 0;
293
294}
295
296static int pca9532_remove(struct i2c_client *client)
297{
298 struct pca9532_data *data = i2c_get_clientdata(client);
299 int i;
300 for (i = 0; i < 16; i++)
301 switch (data->leds[i].type) {
302 case PCA9532_TYPE_NONE:
303 break;
304 case PCA9532_TYPE_LED:
305 led_classdev_unregister(&data->leds[i].ldev);
306 break;
307 case PCA9532_TYPE_N2100_BEEP:
308 if (data->idev != NULL) {
309 input_unregister_device(data->idev);
310 input_free_device(data->idev);
311 data->idev = NULL;
312 }
313 break;
314 }
315
316 kfree(data);
317 i2c_set_clientdata(client, NULL);
318 return 0;
319}
320
321static int __init pca9532_init(void)
322{
323 return i2c_add_driver(&pca9532_driver);
324}
325
326static void __exit pca9532_exit(void)
327{
328 i2c_del_driver(&pca9532_driver);
329}
330
331MODULE_AUTHOR("Riku Voipio <riku.voipio@movial.fi>");
332MODULE_LICENSE("GPL");
333MODULE_DESCRIPTION("PCA 9532 LED dimmer");
334
335module_init(pca9532_init);
336module_exit(pca9532_exit);
337
diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
new file mode 100644
index 000000000000..146c06972863
--- /dev/null
+++ b/drivers/leds/leds-pca955x.c
@@ -0,0 +1,384 @@
1/*
2 * Copyright 2007-2008 Extreme Engineering Solutions, Inc.
3 *
4 * Author: Nate Case <ncase@xes-inc.com>
5 *
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
9 *
10 * LED driver for various PCA955x I2C LED drivers
11 *
12 * Supported devices:
13 *
14 * Device Description 7-bit slave address
15 * ------ ----------- -------------------
16 * PCA9550 2-bit driver 0x60 .. 0x61
17 * PCA9551 8-bit driver 0x60 .. 0x67
18 * PCA9552 16-bit driver 0x60 .. 0x67
19 * PCA9553/01 4-bit driver 0x62
20 * PCA9553/02 4-bit driver 0x63
21 *
22 * Philips PCA955x LED driver chips follow a register map as shown below:
23 *
24 * Control Register Description
25 * ---------------- -----------
26 * 0x0 Input register 0
27 * ..
28 * NUM_INPUT_REGS - 1 Last Input register X
29 *
30 * NUM_INPUT_REGS Frequency prescaler 0
31 * NUM_INPUT_REGS + 1 PWM register 0
32 * NUM_INPUT_REGS + 2 Frequency prescaler 1
33 * NUM_INPUT_REGS + 3 PWM register 1
34 *
35 * NUM_INPUT_REGS + 4 LED selector 0
36 * NUM_INPUT_REGS + 4
37 * + NUM_LED_REGS - 1 Last LED selector
38 *
39 * where NUM_INPUT_REGS and NUM_LED_REGS vary depending on how many
40 * bits the chip supports.
41 */
42
43#include <linux/module.h>
44#include <linux/delay.h>
45#include <linux/string.h>
46#include <linux/ctype.h>
47#include <linux/leds.h>
48#include <linux/err.h>
49#include <linux/i2c.h>
50#include <linux/workqueue.h>
51
52/* LED select registers determine the source that drives LED outputs */
53#define PCA955X_LS_LED_ON 0x0 /* Output LOW */
54#define PCA955X_LS_LED_OFF 0x1 /* Output HI-Z */
55#define PCA955X_LS_BLINK0 0x2 /* Blink at PWM0 rate */
56#define PCA955X_LS_BLINK1 0x3 /* Blink at PWM1 rate */
57
58enum pca955x_type {
59 pca9550,
60 pca9551,
61 pca9552,
62 pca9553,
63};
64
65struct pca955x_chipdef {
66 int bits;
67 u8 slv_addr; /* 7-bit slave address mask */
68 int slv_addr_shift; /* Number of bits to ignore */
69};
70
71static struct pca955x_chipdef pca955x_chipdefs[] = {
72 [pca9550] = {
73 .bits = 2,
74 .slv_addr = /* 110000x */ 0x60,
75 .slv_addr_shift = 1,
76 },
77 [pca9551] = {
78 .bits = 8,
79 .slv_addr = /* 1100xxx */ 0x60,
80 .slv_addr_shift = 3,
81 },
82 [pca9552] = {
83 .bits = 16,
84 .slv_addr = /* 1100xxx */ 0x60,
85 .slv_addr_shift = 3,
86 },
87 [pca9553] = {
88 .bits = 4,
89 .slv_addr = /* 110001x */ 0x62,
90 .slv_addr_shift = 1,
91 },
92};
93
94static const struct i2c_device_id pca955x_id[] = {
95 { "pca9550", pca9550 },
96 { "pca9551", pca9551 },
97 { "pca9552", pca9552 },
98 { "pca9553", pca9553 },
99 { }
100};
101MODULE_DEVICE_TABLE(i2c, pca955x_id);
102
103struct pca955x_led {
104 struct pca955x_chipdef *chipdef;
105 struct i2c_client *client;
106 struct work_struct work;
107 spinlock_t lock;
108 enum led_brightness brightness;
109 struct led_classdev led_cdev;
110 int led_num; /* 0 .. 15 potentially */
111 char name[32];
112};
113
114/* 8 bits per input register */
115static inline int pca95xx_num_input_regs(int bits)
116{
117 return (bits + 7) / 8;
118}
119
120/* 4 bits per LED selector register */
121static inline int pca95xx_num_led_regs(int bits)
122{
123 return (bits + 3) / 4;
124}
125
126/*
127 * Return an LED selector register value based on an existing one, with
128 * the appropriate 2-bit state value set for the given LED number (0-3).
129 */
130static inline u8 pca955x_ledsel(u8 oldval, int led_num, int state)
131{
132 return (oldval & (~(0x3 << (led_num << 1)))) |
133 ((state & 0x3) << (led_num << 1));
134}
135
136/*
137 * Write to frequency prescaler register, used to program the
138 * period of the PWM output. period = (PSCx + 1) / 38
139 */
140static void pca955x_write_psc(struct i2c_client *client, int n, u8 val)
141{
142 struct pca955x_led *pca955x = i2c_get_clientdata(client);
143
144 i2c_smbus_write_byte_data(client,
145 pca95xx_num_input_regs(pca955x->chipdef->bits) + 2*n,
146 val);
147}
148
149/*
150 * Write to PWM register, which determines the duty cycle of the
151 * output. LED is OFF when the count is less than the value of this
152 * register, and ON when it is greater. If PWMx == 0, LED is always OFF.
153 *
154 * Duty cycle is (256 - PWMx) / 256
155 */
156static void pca955x_write_pwm(struct i2c_client *client, int n, u8 val)
157{
158 struct pca955x_led *pca955x = i2c_get_clientdata(client);
159
160 i2c_smbus_write_byte_data(client,
161 pca95xx_num_input_regs(pca955x->chipdef->bits) + 1 + 2*n,
162 val);
163}
164
165/*
166 * Write to LED selector register, which determines the source that
167 * drives the LED output.
168 */
169static void pca955x_write_ls(struct i2c_client *client, int n, u8 val)
170{
171 struct pca955x_led *pca955x = i2c_get_clientdata(client);
172
173 i2c_smbus_write_byte_data(client,
174 pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n,
175 val);
176}
177
178/*
179 * Read the LED selector register, which determines the source that
180 * drives the LED output.
181 */
182static u8 pca955x_read_ls(struct i2c_client *client, int n)
183{
184 struct pca955x_led *pca955x = i2c_get_clientdata(client);
185
186 return (u8) i2c_smbus_read_byte_data(client,
187 pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n);
188}
189
190static void pca955x_led_work(struct work_struct *work)
191{
192 struct pca955x_led *pca955x;
193 u8 ls;
194 int chip_ls; /* which LSx to use (0-3 potentially) */
195 int ls_led; /* which set of bits within LSx to use (0-3) */
196
197 pca955x = container_of(work, struct pca955x_led, work);
198 chip_ls = pca955x->led_num / 4;
199 ls_led = pca955x->led_num % 4;
200
201 ls = pca955x_read_ls(pca955x->client, chip_ls);
202
203 switch (pca955x->brightness) {
204 case LED_FULL:
205 ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_LED_ON);
206 break;
207 case LED_OFF:
208 ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_LED_OFF);
209 break;
210 case LED_HALF:
211 ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_BLINK0);
212 break;
213 default:
214 /*
215 * Use PWM1 for all other values. This has the unwanted
216 * side effect of making all LEDs on the chip share the
217 * same brightness level if set to a value other than
218 * OFF, HALF, or FULL. But, this is probably better than
219 * just turning off for all other values.
220 */
221 pca955x_write_pwm(pca955x->client, 1, 255-pca955x->brightness);
222 ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_BLINK1);
223 break;
224 }
225
226 pca955x_write_ls(pca955x->client, chip_ls, ls);
227}
228
229void pca955x_led_set(struct led_classdev *led_cdev, enum led_brightness value)
230{
231 struct pca955x_led *pca955x;
232
233 pca955x = container_of(led_cdev, struct pca955x_led, led_cdev);
234
235 spin_lock(&pca955x->lock);
236 pca955x->brightness = value;
237
238 /*
239 * Must use workqueue for the actual I/O since I2C operations
240 * can sleep.
241 */
242 schedule_work(&pca955x->work);
243
244 spin_unlock(&pca955x->lock);
245}
246
247static int __devinit pca955x_probe(struct i2c_client *client,
248 const struct i2c_device_id *id)
249{
250 struct pca955x_led *pca955x;
251 int i;
252 int err = -ENODEV;
253 struct pca955x_chipdef *chip;
254 struct i2c_adapter *adapter;
255 struct led_platform_data *pdata;
256
257 chip = &pca955x_chipdefs[id->driver_data];
258 adapter = to_i2c_adapter(client->dev.parent);
259 pdata = client->dev.platform_data;
260
261 /* Make sure the slave address / chip type combo given is possible */
262 if ((client->addr & ~((1 << chip->slv_addr_shift) - 1)) !=
263 chip->slv_addr) {
264 dev_err(&client->dev, "invalid slave address %02x\n",
265 client->addr);
266 return -ENODEV;
267 }
268
269 printk(KERN_INFO "leds-pca955x: Using %s %d-bit LED driver at "
270 "slave address 0x%02x\n",
271 id->name, chip->bits, client->addr);
272
273 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
274 return -EIO;
275
276 if (pdata) {
277 if (pdata->num_leds != chip->bits) {
278 dev_err(&client->dev, "board info claims %d LEDs"
279 " on a %d-bit chip\n",
280 pdata->num_leds, chip->bits);
281 return -ENODEV;
282 }
283 }
284
285 for (i = 0; i < chip->bits; i++) {
286 pca955x = kzalloc(sizeof(struct pca955x_led), GFP_KERNEL);
287 if (!pca955x) {
288 err = -ENOMEM;
289 goto exit;
290 }
291
292 pca955x->chipdef = chip;
293 pca955x->client = client;
294 pca955x->led_num = i;
295 /* Platform data can specify LED names and default triggers */
296 if (pdata) {
297 if (pdata->leds[i].name)
298 snprintf(pca955x->name, 32, "pca955x:%s",
299 pdata->leds[i].name);
300 if (pdata->leds[i].default_trigger)
301 pca955x->led_cdev.default_trigger =
302 pdata->leds[i].default_trigger;
303 } else {
304 snprintf(pca955x->name, 32, "pca955x:%d", i);
305 }
306 spin_lock_init(&pca955x->lock);
307
308 pca955x->led_cdev.name = pca955x->name;
309 pca955x->led_cdev.brightness_set =
310 pca955x_led_set;
311
312 /*
313 * Client data is a pointer to the _first_ pca955x_led
314 * struct
315 */
316 if (i == 0)
317 i2c_set_clientdata(client, pca955x);
318
319 INIT_WORK(&(pca955x->work), pca955x_led_work);
320
321 led_classdev_register(&client->dev, &(pca955x->led_cdev));
322 }
323
324 /* Turn off LEDs */
325 for (i = 0; i < pca95xx_num_led_regs(chip->bits); i++)
326 pca955x_write_ls(client, i, 0x55);
327
328 /* PWM0 is used for half brightness or 50% duty cycle */
329 pca955x_write_pwm(client, 0, 255-LED_HALF);
330
331 /* PWM1 is used for variable brightness, default to OFF */
332 pca955x_write_pwm(client, 1, 0);
333
334 /* Set to fast frequency so we do not see flashing */
335 pca955x_write_psc(client, 0, 0);
336 pca955x_write_psc(client, 1, 0);
337
338 return 0;
339exit:
340 return err;
341}
342
343static int __devexit pca955x_remove(struct i2c_client *client)
344{
345 struct pca955x_led *pca955x = i2c_get_clientdata(client);
346 int leds = pca955x->chipdef->bits;
347 int i;
348
349 for (i = 0; i < leds; i++) {
350 led_classdev_unregister(&(pca955x->led_cdev));
351 cancel_work_sync(&(pca955x->work));
352 kfree(pca955x);
353 pca955x = pca955x + 1;
354 }
355
356 return 0;
357}
358
359static struct i2c_driver pca955x_driver = {
360 .driver = {
361 .name = "leds-pca955x",
362 .owner = THIS_MODULE,
363 },
364 .probe = pca955x_probe,
365 .remove = __devexit_p(pca955x_remove),
366 .id_table = pca955x_id,
367};
368
369static int __init pca955x_leds_init(void)
370{
371 return i2c_add_driver(&pca955x_driver);
372}
373
374static void __exit pca955x_leds_exit(void)
375{
376 i2c_del_driver(&pca955x_driver);
377}
378
379module_init(pca955x_leds_init);
380module_exit(pca955x_leds_exit);
381
382MODULE_AUTHOR("Nate Case <ncase@xes-inc.com>");
383MODULE_DESCRIPTION("PCA955x LED driver");
384MODULE_LICENSE("GPL v2");
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index 1a8de57289eb..37344aaee22f 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -98,16 +98,20 @@ static u32 lg_get_features(struct virtio_device *vdev)
98 return features; 98 return features;
99} 99}
100 100
101static void lg_set_features(struct virtio_device *vdev, u32 features) 101static void lg_finalize_features(struct virtio_device *vdev)
102{ 102{
103 unsigned int i; 103 unsigned int i, bits;
104 struct lguest_device_desc *desc = to_lgdev(vdev)->desc; 104 struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
105 /* Second half of bitmap is features we accept. */ 105 /* Second half of bitmap is features we accept. */
106 u8 *out_features = lg_features(desc) + desc->feature_len; 106 u8 *out_features = lg_features(desc) + desc->feature_len;
107 107
108 /* Give virtio_ring a chance to accept features. */
109 vring_transport_features(vdev);
110
108 memset(out_features, 0, desc->feature_len); 111 memset(out_features, 0, desc->feature_len);
109 for (i = 0; i < min(desc->feature_len * 8, 32); i++) { 112 bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
110 if (features & (1 << i)) 113 for (i = 0; i < bits; i++) {
114 if (test_bit(i, vdev->features))
111 out_features[i / 8] |= (1 << (i % 8)); 115 out_features[i / 8] |= (1 << (i % 8));
112 } 116 }
113} 117}
@@ -297,7 +301,7 @@ static void lg_del_vq(struct virtqueue *vq)
297/* The ops structure which hooks everything together. */ 301/* The ops structure which hooks everything together. */
298static struct virtio_config_ops lguest_config_ops = { 302static struct virtio_config_ops lguest_config_ops = {
299 .get_features = lg_get_features, 303 .get_features = lg_get_features,
300 .set_features = lg_set_features, 304 .finalize_features = lg_finalize_features,
301 .get = lg_get, 305 .get = lg_get,
302 .set = lg_set, 306 .set = lg_set,
303 .get_status = lg_get_status, 307 .get_status = lg_get_status,
diff --git a/drivers/media/dvb/pluto2/pluto2.c b/drivers/media/dvb/pluto2/pluto2.c
index 1360403b88b6..a9653c63f4db 100644
--- a/drivers/media/dvb/pluto2/pluto2.c
+++ b/drivers/media/dvb/pluto2/pluto2.c
@@ -242,7 +242,7 @@ static int __devinit pluto_dma_map(struct pluto *pluto)
242 pluto->dma_addr = pci_map_single(pluto->pdev, pluto->dma_buf, 242 pluto->dma_addr = pci_map_single(pluto->pdev, pluto->dma_buf,
243 TS_DMA_BYTES, PCI_DMA_FROMDEVICE); 243 TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
244 244
245 return pci_dma_mapping_error(pluto->dma_addr); 245 return pci_dma_mapping_error(pluto->pdev, pluto->dma_addr);
246} 246}
247 247
248static void pluto_dma_unmap(struct pluto *pluto) 248static void pluto_dma_unmap(struct pluto *pluto)
diff --git a/drivers/media/video/pvrusb2/pvrusb2-dvb.c b/drivers/media/video/pvrusb2/pvrusb2-dvb.c
index 6ec4bf81fc7f..77b3c3385066 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-dvb.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-dvb.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/kthread.h> 21#include <linux/kthread.h>
22#include <linux/freezer.h> 22#include <linux/freezer.h>
23#include <linux/mm.h>
23#include "dvbdev.h" 24#include "dvbdev.h"
24#include "pvrusb2-debug.h" 25#include "pvrusb2-debug.h"
25#include "pvrusb2-hdw-internal.h" 26#include "pvrusb2-hdw-internal.h"
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ioread.c b/drivers/media/video/pvrusb2/pvrusb2-ioread.c
index 05a1376405e7..b4824782d858 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ioread.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ioread.c
@@ -22,6 +22,7 @@
22#include "pvrusb2-debug.h" 22#include "pvrusb2-debug.h"
23#include <linux/errno.h> 23#include <linux/errno.h>
24#include <linux/string.h> 24#include <linux/string.h>
25#include <linux/mm.h>
25#include <linux/slab.h> 26#include <linux/slab.h>
26#include <linux/mutex.h> 27#include <linux/mutex.h>
27#include <asm/uaccess.h> 28#include <asm/uaccess.h>
diff --git a/drivers/media/video/uvc/uvc_queue.c b/drivers/media/video/uvc/uvc_queue.c
index 7388d0cee3d4..5646a6a32939 100644
--- a/drivers/media/video/uvc/uvc_queue.c
+++ b/drivers/media/video/uvc/uvc_queue.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/version.h> 15#include <linux/version.h>
16#include <linux/mm.h>
16#include <linux/list.h> 17#include <linux/list.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/usb.h> 19#include <linux/usb.h>
diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c
index 0a88c44ace00..b7b05842cf28 100644
--- a/drivers/media/video/videobuf-core.c
+++ b/drivers/media/video/videobuf-core.c
@@ -16,6 +16,7 @@
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/moduleparam.h> 18#include <linux/moduleparam.h>
19#include <linux/mm.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20#include <linux/interrupt.h> 21#include <linux/interrupt.h>
21 22
diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index 61b98c333cb0..a38005008a20 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -249,8 +249,11 @@ EXPORT_SYMBOL(memstick_next_req);
249 */ 249 */
250void memstick_new_req(struct memstick_host *host) 250void memstick_new_req(struct memstick_host *host)
251{ 251{
252 host->retries = cmd_retries; 252 if (host->card) {
253 host->request(host); 253 host->retries = cmd_retries;
254 INIT_COMPLETION(host->card->mrq_complete);
255 host->request(host);
256 }
254} 257}
255EXPORT_SYMBOL(memstick_new_req); 258EXPORT_SYMBOL(memstick_new_req);
256 259
@@ -415,10 +418,14 @@ err_out:
415 return NULL; 418 return NULL;
416} 419}
417 420
418static void memstick_power_on(struct memstick_host *host) 421static int memstick_power_on(struct memstick_host *host)
419{ 422{
420 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_ON); 423 int rc = host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_ON);
421 host->set_param(host, MEMSTICK_INTERFACE, MEMSTICK_SERIAL); 424
425 if (!rc)
426 rc = host->set_param(host, MEMSTICK_INTERFACE, MEMSTICK_SERIAL);
427
428 return rc;
422} 429}
423 430
424static void memstick_check(struct work_struct *work) 431static void memstick_check(struct work_struct *work)
@@ -429,8 +436,11 @@ static void memstick_check(struct work_struct *work)
429 436
430 dev_dbg(&host->dev, "memstick_check started\n"); 437 dev_dbg(&host->dev, "memstick_check started\n");
431 mutex_lock(&host->lock); 438 mutex_lock(&host->lock);
432 if (!host->card) 439 if (!host->card) {
433 memstick_power_on(host); 440 if (memstick_power_on(host))
441 goto out_power_off;
442 } else
443 host->card->stop(host->card);
434 444
435 card = memstick_alloc_card(host); 445 card = memstick_alloc_card(host);
436 446
@@ -448,7 +458,8 @@ static void memstick_check(struct work_struct *work)
448 || !(host->card->check(host->card))) { 458 || !(host->card->check(host->card))) {
449 device_unregister(&host->card->dev); 459 device_unregister(&host->card->dev);
450 host->card = NULL; 460 host->card = NULL;
451 } 461 } else
462 host->card->start(host->card);
452 } 463 }
453 464
454 if (!host->card) { 465 if (!host->card) {
@@ -461,6 +472,7 @@ static void memstick_check(struct work_struct *work)
461 kfree(card); 472 kfree(card);
462 } 473 }
463 474
475out_power_off:
464 if (!host->card) 476 if (!host->card)
465 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); 477 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF);
466 478
@@ -573,11 +585,15 @@ EXPORT_SYMBOL(memstick_suspend_host);
573 */ 585 */
574void memstick_resume_host(struct memstick_host *host) 586void memstick_resume_host(struct memstick_host *host)
575{ 587{
588 int rc = 0;
589
576 mutex_lock(&host->lock); 590 mutex_lock(&host->lock);
577 if (host->card) 591 if (host->card)
578 memstick_power_on(host); 592 rc = memstick_power_on(host);
579 mutex_unlock(&host->lock); 593 mutex_unlock(&host->lock);
580 memstick_detect_change(host); 594
595 if (!rc)
596 memstick_detect_change(host);
581} 597}
582EXPORT_SYMBOL(memstick_resume_host); 598EXPORT_SYMBOL(memstick_resume_host);
583 599
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index 477d0fb6e588..44b1817f2f2f 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -136,9 +136,8 @@ struct mspro_block_data {
136 unsigned int caps; 136 unsigned int caps;
137 struct gendisk *disk; 137 struct gendisk *disk;
138 struct request_queue *queue; 138 struct request_queue *queue;
139 struct request *block_req;
139 spinlock_t q_lock; 140 spinlock_t q_lock;
140 wait_queue_head_t q_wait;
141 struct task_struct *q_thread;
142 141
143 unsigned short page_size; 142 unsigned short page_size;
144 unsigned short cylinders; 143 unsigned short cylinders;
@@ -147,9 +146,10 @@ struct mspro_block_data {
147 146
148 unsigned char system; 147 unsigned char system;
149 unsigned char read_only:1, 148 unsigned char read_only:1,
150 active:1, 149 eject:1,
151 has_request:1, 150 has_request:1,
152 data_dir:1; 151 data_dir:1,
152 active:1;
153 unsigned char transfer_cmd; 153 unsigned char transfer_cmd;
154 154
155 int (*mrq_handler)(struct memstick_dev *card, 155 int (*mrq_handler)(struct memstick_dev *card,
@@ -160,12 +160,14 @@ struct mspro_block_data {
160 struct scatterlist req_sg[MSPRO_BLOCK_MAX_SEGS]; 160 struct scatterlist req_sg[MSPRO_BLOCK_MAX_SEGS];
161 unsigned int seg_count; 161 unsigned int seg_count;
162 unsigned int current_seg; 162 unsigned int current_seg;
163 unsigned short current_page; 163 unsigned int current_page;
164}; 164};
165 165
166static DEFINE_IDR(mspro_block_disk_idr); 166static DEFINE_IDR(mspro_block_disk_idr);
167static DEFINE_MUTEX(mspro_block_disk_lock); 167static DEFINE_MUTEX(mspro_block_disk_lock);
168 168
169static int mspro_block_complete_req(struct memstick_dev *card, int error);
170
169/*** Block device ***/ 171/*** Block device ***/
170 172
171static int mspro_block_bd_open(struct inode *inode, struct file *filp) 173static int mspro_block_bd_open(struct inode *inode, struct file *filp)
@@ -197,8 +199,10 @@ static int mspro_block_disk_release(struct gendisk *disk)
197 199
198 mutex_lock(&mspro_block_disk_lock); 200 mutex_lock(&mspro_block_disk_lock);
199 201
200 if (msb->usage_count) { 202 if (msb) {
201 msb->usage_count--; 203 if (msb->usage_count)
204 msb->usage_count--;
205
202 if (!msb->usage_count) { 206 if (!msb->usage_count) {
203 kfree(msb); 207 kfree(msb);
204 disk->private_data = NULL; 208 disk->private_data = NULL;
@@ -523,11 +527,13 @@ static int h_mspro_block_req_init(struct memstick_dev *card,
523static int h_mspro_block_default(struct memstick_dev *card, 527static int h_mspro_block_default(struct memstick_dev *card,
524 struct memstick_request **mrq) 528 struct memstick_request **mrq)
525{ 529{
526 complete(&card->mrq_complete); 530 return mspro_block_complete_req(card, (*mrq)->error);
527 if (!(*mrq)->error) 531}
528 return -EAGAIN; 532
529 else 533static int h_mspro_block_default_bad(struct memstick_dev *card,
530 return (*mrq)->error; 534 struct memstick_request **mrq)
535{
536 return -ENXIO;
531} 537}
532 538
533static int h_mspro_block_get_ro(struct memstick_dev *card, 539static int h_mspro_block_get_ro(struct memstick_dev *card,
@@ -535,44 +541,30 @@ static int h_mspro_block_get_ro(struct memstick_dev *card,
535{ 541{
536 struct mspro_block_data *msb = memstick_get_drvdata(card); 542 struct mspro_block_data *msb = memstick_get_drvdata(card);
537 543
538 if ((*mrq)->error) { 544 if (!(*mrq)->error) {
539 complete(&card->mrq_complete); 545 if ((*mrq)->data[offsetof(struct ms_status_register, status0)]
540 return (*mrq)->error; 546 & MEMSTICK_STATUS0_WP)
547 msb->read_only = 1;
548 else
549 msb->read_only = 0;
541 } 550 }
542 551
543 if ((*mrq)->data[offsetof(struct ms_status_register, status0)] 552 return mspro_block_complete_req(card, (*mrq)->error);
544 & MEMSTICK_STATUS0_WP)
545 msb->read_only = 1;
546 else
547 msb->read_only = 0;
548
549 complete(&card->mrq_complete);
550 return -EAGAIN;
551} 553}
552 554
553static int h_mspro_block_wait_for_ced(struct memstick_dev *card, 555static int h_mspro_block_wait_for_ced(struct memstick_dev *card,
554 struct memstick_request **mrq) 556 struct memstick_request **mrq)
555{ 557{
556 if ((*mrq)->error) {
557 complete(&card->mrq_complete);
558 return (*mrq)->error;
559 }
560
561 dev_dbg(&card->dev, "wait for ced: value %x\n", (*mrq)->data[0]); 558 dev_dbg(&card->dev, "wait for ced: value %x\n", (*mrq)->data[0]);
562 559
563 if ((*mrq)->data[0] & (MEMSTICK_INT_CMDNAK | MEMSTICK_INT_ERR)) { 560 if (!(*mrq)->error) {
564 card->current_mrq.error = -EFAULT; 561 if ((*mrq)->data[0] & (MEMSTICK_INT_CMDNAK | MEMSTICK_INT_ERR))
565 complete(&card->mrq_complete); 562 (*mrq)->error = -EFAULT;
566 return card->current_mrq.error; 563 else if (!((*mrq)->data[0] & MEMSTICK_INT_CED))
564 return 0;
567 } 565 }
568 566
569 if (!((*mrq)->data[0] & MEMSTICK_INT_CED)) 567 return mspro_block_complete_req(card, (*mrq)->error);
570 return 0;
571 else {
572 card->current_mrq.error = 0;
573 complete(&card->mrq_complete);
574 return -EAGAIN;
575 }
576} 568}
577 569
578static int h_mspro_block_transfer_data(struct memstick_dev *card, 570static int h_mspro_block_transfer_data(struct memstick_dev *card,
@@ -583,10 +575,8 @@ static int h_mspro_block_transfer_data(struct memstick_dev *card,
583 struct scatterlist t_sg = { 0 }; 575 struct scatterlist t_sg = { 0 };
584 size_t t_offset; 576 size_t t_offset;
585 577
586 if ((*mrq)->error) { 578 if ((*mrq)->error)
587 complete(&card->mrq_complete); 579 return mspro_block_complete_req(card, (*mrq)->error);
588 return (*mrq)->error;
589 }
590 580
591 switch ((*mrq)->tpc) { 581 switch ((*mrq)->tpc) {
592 case MS_TPC_WRITE_REG: 582 case MS_TPC_WRITE_REG:
@@ -617,8 +607,8 @@ has_int_reg:
617 607
618 if (msb->current_seg == msb->seg_count) { 608 if (msb->current_seg == msb->seg_count) {
619 if (t_val & MEMSTICK_INT_CED) { 609 if (t_val & MEMSTICK_INT_CED) {
620 complete(&card->mrq_complete); 610 return mspro_block_complete_req(card,
621 return -EAGAIN; 611 0);
622 } else { 612 } else {
623 card->next_request 613 card->next_request
624 = h_mspro_block_wait_for_ced; 614 = h_mspro_block_wait_for_ced;
@@ -666,140 +656,184 @@ has_int_reg:
666 656
667/*** Data transfer ***/ 657/*** Data transfer ***/
668 658
669static void mspro_block_process_request(struct memstick_dev *card, 659static int mspro_block_issue_req(struct memstick_dev *card, int chunk)
670 struct request *req)
671{ 660{
672 struct mspro_block_data *msb = memstick_get_drvdata(card); 661 struct mspro_block_data *msb = memstick_get_drvdata(card);
673 struct mspro_param_register param;
674 int rc, chunk, cnt;
675 unsigned short page_count;
676 sector_t t_sec; 662 sector_t t_sec;
677 unsigned long flags; 663 unsigned int count;
664 struct mspro_param_register param;
678 665
679 do { 666try_again:
680 page_count = 0; 667 while (chunk) {
668 msb->current_page = 0;
681 msb->current_seg = 0; 669 msb->current_seg = 0;
682 msb->seg_count = blk_rq_map_sg(req->q, req, msb->req_sg); 670 msb->seg_count = blk_rq_map_sg(msb->block_req->q,
671 msb->block_req,
672 msb->req_sg);
683 673
684 if (msb->seg_count) { 674 if (!msb->seg_count) {
685 msb->current_page = 0; 675 chunk = __blk_end_request(msb->block_req, -ENOMEM,
686 for (rc = 0; rc < msb->seg_count; rc++) 676 blk_rq_cur_bytes(msb->block_req));
687 page_count += msb->req_sg[rc].length 677 continue;
688 / msb->page_size; 678 }
689
690 t_sec = req->sector;
691 sector_div(t_sec, msb->page_size >> 9);
692 param.system = msb->system;
693 param.data_count = cpu_to_be16(page_count);
694 param.data_address = cpu_to_be32((uint32_t)t_sec);
695 param.tpc_param = 0;
696
697 msb->data_dir = rq_data_dir(req);
698 msb->transfer_cmd = msb->data_dir == READ
699 ? MSPRO_CMD_READ_DATA
700 : MSPRO_CMD_WRITE_DATA;
701
702 dev_dbg(&card->dev, "data transfer: cmd %x, "
703 "lba %x, count %x\n", msb->transfer_cmd,
704 be32_to_cpu(param.data_address),
705 page_count);
706
707 card->next_request = h_mspro_block_req_init;
708 msb->mrq_handler = h_mspro_block_transfer_data;
709 memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG,
710 &param, sizeof(param));
711 memstick_new_req(card->host);
712 wait_for_completion(&card->mrq_complete);
713 rc = card->current_mrq.error;
714 679
715 if (rc || (card->current_mrq.tpc == MSPRO_CMD_STOP)) { 680 t_sec = msb->block_req->sector << 9;
716 for (cnt = 0; cnt < msb->current_seg; cnt++) 681 sector_div(t_sec, msb->page_size);
717 page_count += msb->req_sg[cnt].length
718 / msb->page_size;
719
720 if (msb->current_page)
721 page_count += msb->current_page - 1;
722
723 if (page_count && (msb->data_dir == READ))
724 rc = msb->page_size * page_count;
725 else
726 rc = -EIO;
727 } else
728 rc = msb->page_size * page_count;
729 } else
730 rc = -EFAULT;
731 682
732 spin_lock_irqsave(&msb->q_lock, flags); 683 count = msb->block_req->nr_sectors << 9;
733 if (rc >= 0) 684 count /= msb->page_size;
734 chunk = __blk_end_request(req, 0, rc);
735 else
736 chunk = __blk_end_request(req, rc, 0);
737 685
738 dev_dbg(&card->dev, "end chunk %d, %d\n", rc, chunk); 686 param.system = msb->system;
739 spin_unlock_irqrestore(&msb->q_lock, flags); 687 param.data_count = cpu_to_be16(count);
740 } while (chunk); 688 param.data_address = cpu_to_be32((uint32_t)t_sec);
689 param.tpc_param = 0;
690
691 msb->data_dir = rq_data_dir(msb->block_req);
692 msb->transfer_cmd = msb->data_dir == READ
693 ? MSPRO_CMD_READ_DATA
694 : MSPRO_CMD_WRITE_DATA;
695
696 dev_dbg(&card->dev, "data transfer: cmd %x, "
697 "lba %x, count %x\n", msb->transfer_cmd,
698 be32_to_cpu(param.data_address), count);
699
700 card->next_request = h_mspro_block_req_init;
701 msb->mrq_handler = h_mspro_block_transfer_data;
702 memstick_init_req(&card->current_mrq, MS_TPC_WRITE_REG,
703 &param, sizeof(param));
704 memstick_new_req(card->host);
705 return 0;
706 }
707
708 dev_dbg(&card->dev, "elv_next\n");
709 msb->block_req = elv_next_request(msb->queue);
710 if (!msb->block_req) {
711 dev_dbg(&card->dev, "issue end\n");
712 return -EAGAIN;
713 }
714
715 dev_dbg(&card->dev, "trying again\n");
716 chunk = 1;
717 goto try_again;
741} 718}
742 719
743static int mspro_block_has_request(struct mspro_block_data *msb) 720static int mspro_block_complete_req(struct memstick_dev *card, int error)
744{ 721{
745 int rc = 0; 722 struct mspro_block_data *msb = memstick_get_drvdata(card);
723 int chunk, cnt;
724 unsigned int t_len = 0;
746 unsigned long flags; 725 unsigned long flags;
747 726
748 spin_lock_irqsave(&msb->q_lock, flags); 727 spin_lock_irqsave(&msb->q_lock, flags);
749 if (kthread_should_stop() || msb->has_request) 728 dev_dbg(&card->dev, "complete %d, %d\n", msb->has_request ? 1 : 0,
750 rc = 1; 729 error);
730
731 if (msb->has_request) {
732 /* Nothing to do - not really an error */
733 if (error == -EAGAIN)
734 error = 0;
735
736 if (error || (card->current_mrq.tpc == MSPRO_CMD_STOP)) {
737 if (msb->data_dir == READ) {
738 for (cnt = 0; cnt < msb->current_seg; cnt++)
739 t_len += msb->req_sg[cnt].length
740 / msb->page_size;
741
742 if (msb->current_page)
743 t_len += msb->current_page - 1;
744
745 t_len *= msb->page_size;
746 }
747 } else
748 t_len = msb->block_req->nr_sectors << 9;
749
750 dev_dbg(&card->dev, "transferred %x (%d)\n", t_len, error);
751
752 if (error && !t_len)
753 t_len = blk_rq_cur_bytes(msb->block_req);
754
755 chunk = __blk_end_request(msb->block_req, error, t_len);
756
757 error = mspro_block_issue_req(card, chunk);
758
759 if (!error)
760 goto out;
761 else
762 msb->has_request = 0;
763 } else {
764 if (!error)
765 error = -EAGAIN;
766 }
767
768 card->next_request = h_mspro_block_default_bad;
769 complete_all(&card->mrq_complete);
770out:
751 spin_unlock_irqrestore(&msb->q_lock, flags); 771 spin_unlock_irqrestore(&msb->q_lock, flags);
752 return rc; 772 return error;
753} 773}
754 774
755static int mspro_block_queue_thread(void *data) 775static void mspro_block_stop(struct memstick_dev *card)
756{ 776{
757 struct memstick_dev *card = data;
758 struct memstick_host *host = card->host;
759 struct mspro_block_data *msb = memstick_get_drvdata(card); 777 struct mspro_block_data *msb = memstick_get_drvdata(card);
760 struct request *req; 778 int rc = 0;
761 unsigned long flags; 779 unsigned long flags;
762 780
763 while (1) { 781 while (1) {
764 wait_event(msb->q_wait, mspro_block_has_request(msb));
765 dev_dbg(&card->dev, "thread iter\n");
766
767 spin_lock_irqsave(&msb->q_lock, flags); 782 spin_lock_irqsave(&msb->q_lock, flags);
768 req = elv_next_request(msb->queue); 783 if (!msb->has_request) {
769 dev_dbg(&card->dev, "next req %p\n", req); 784 blk_stop_queue(msb->queue);
770 if (!req) { 785 rc = 1;
771 msb->has_request = 0; 786 }
772 if (kthread_should_stop()) {
773 spin_unlock_irqrestore(&msb->q_lock, flags);
774 break;
775 }
776 } else
777 msb->has_request = 1;
778 spin_unlock_irqrestore(&msb->q_lock, flags); 787 spin_unlock_irqrestore(&msb->q_lock, flags);
779 788
780 if (req) { 789 if (rc)
781 mutex_lock(&host->lock); 790 break;
782 mspro_block_process_request(card, req); 791
783 mutex_unlock(&host->lock); 792 wait_for_completion(&card->mrq_complete);
784 }
785 } 793 }
786 dev_dbg(&card->dev, "thread finished\n");
787 return 0;
788} 794}
789 795
790static void mspro_block_request(struct request_queue *q) 796static void mspro_block_start(struct memstick_dev *card)
797{
798 struct mspro_block_data *msb = memstick_get_drvdata(card);
799 unsigned long flags;
800
801 spin_lock_irqsave(&msb->q_lock, flags);
802 blk_start_queue(msb->queue);
803 spin_unlock_irqrestore(&msb->q_lock, flags);
804}
805
806static int mspro_block_prepare_req(struct request_queue *q, struct request *req)
807{
808 if (!blk_fs_request(req) && !blk_pc_request(req)) {
809 blk_dump_rq_flags(req, "MSPro unsupported request");
810 return BLKPREP_KILL;
811 }
812
813 req->cmd_flags |= REQ_DONTPREP;
814
815 return BLKPREP_OK;
816}
817
818static void mspro_block_submit_req(struct request_queue *q)
791{ 819{
792 struct memstick_dev *card = q->queuedata; 820 struct memstick_dev *card = q->queuedata;
793 struct mspro_block_data *msb = memstick_get_drvdata(card); 821 struct mspro_block_data *msb = memstick_get_drvdata(card);
794 struct request *req = NULL; 822 struct request *req = NULL;
795 823
796 if (msb->q_thread) { 824 if (msb->has_request)
797 msb->has_request = 1; 825 return;
798 wake_up_all(&msb->q_wait); 826
799 } else { 827 if (msb->eject) {
800 while ((req = elv_next_request(q)) != NULL) 828 while ((req = elv_next_request(q)) != NULL)
801 end_queued_request(req, -ENODEV); 829 end_queued_request(req, -ENODEV);
830
831 return;
802 } 832 }
833
834 msb->has_request = 1;
835 if (mspro_block_issue_req(card, 0))
836 msb->has_request = 0;
803} 837}
804 838
805/*** Initialization ***/ 839/*** Initialization ***/
@@ -1169,16 +1203,14 @@ static int mspro_block_init_disk(struct memstick_dev *card)
1169 goto out_release_id; 1203 goto out_release_id;
1170 } 1204 }
1171 1205
1172 spin_lock_init(&msb->q_lock); 1206 msb->queue = blk_init_queue(mspro_block_submit_req, &msb->q_lock);
1173 init_waitqueue_head(&msb->q_wait);
1174
1175 msb->queue = blk_init_queue(mspro_block_request, &msb->q_lock);
1176 if (!msb->queue) { 1207 if (!msb->queue) {
1177 rc = -ENOMEM; 1208 rc = -ENOMEM;
1178 goto out_put_disk; 1209 goto out_put_disk;
1179 } 1210 }
1180 1211
1181 msb->queue->queuedata = card; 1212 msb->queue->queuedata = card;
1213 blk_queue_prep_rq(msb->queue, mspro_block_prepare_req);
1182 1214
1183 blk_queue_bounce_limit(msb->queue, limit); 1215 blk_queue_bounce_limit(msb->queue, limit);
1184 blk_queue_max_sectors(msb->queue, MSPRO_BLOCK_MAX_PAGES); 1216 blk_queue_max_sectors(msb->queue, MSPRO_BLOCK_MAX_PAGES);
@@ -1204,14 +1236,8 @@ static int mspro_block_init_disk(struct memstick_dev *card)
1204 capacity *= msb->page_size >> 9; 1236 capacity *= msb->page_size >> 9;
1205 set_capacity(msb->disk, capacity); 1237 set_capacity(msb->disk, capacity);
1206 dev_dbg(&card->dev, "capacity set %ld\n", capacity); 1238 dev_dbg(&card->dev, "capacity set %ld\n", capacity);
1207 msb->q_thread = kthread_run(mspro_block_queue_thread, card,
1208 DRIVER_NAME"d");
1209 if (IS_ERR(msb->q_thread))
1210 goto out_put_disk;
1211 1239
1212 mutex_unlock(&host->lock);
1213 add_disk(msb->disk); 1240 add_disk(msb->disk);
1214 mutex_lock(&host->lock);
1215 msb->active = 1; 1241 msb->active = 1;
1216 return 0; 1242 return 0;
1217 1243
@@ -1259,6 +1285,7 @@ static int mspro_block_probe(struct memstick_dev *card)
1259 return -ENOMEM; 1285 return -ENOMEM;
1260 memstick_set_drvdata(card, msb); 1286 memstick_set_drvdata(card, msb);
1261 msb->card = card; 1287 msb->card = card;
1288 spin_lock_init(&msb->q_lock);
1262 1289
1263 rc = mspro_block_init_card(card); 1290 rc = mspro_block_init_card(card);
1264 1291
@@ -1272,6 +1299,8 @@ static int mspro_block_probe(struct memstick_dev *card)
1272 rc = mspro_block_init_disk(card); 1299 rc = mspro_block_init_disk(card);
1273 if (!rc) { 1300 if (!rc) {
1274 card->check = mspro_block_check_card; 1301 card->check = mspro_block_check_card;
1302 card->stop = mspro_block_stop;
1303 card->start = mspro_block_start;
1275 return 0; 1304 return 0;
1276 } 1305 }
1277 1306
@@ -1286,26 +1315,17 @@ out_free:
1286static void mspro_block_remove(struct memstick_dev *card) 1315static void mspro_block_remove(struct memstick_dev *card)
1287{ 1316{
1288 struct mspro_block_data *msb = memstick_get_drvdata(card); 1317 struct mspro_block_data *msb = memstick_get_drvdata(card);
1289 struct task_struct *q_thread = NULL;
1290 unsigned long flags; 1318 unsigned long flags;
1291 1319
1292 del_gendisk(msb->disk); 1320 del_gendisk(msb->disk);
1293 dev_dbg(&card->dev, "mspro block remove\n"); 1321 dev_dbg(&card->dev, "mspro block remove\n");
1294 spin_lock_irqsave(&msb->q_lock, flags); 1322 spin_lock_irqsave(&msb->q_lock, flags);
1295 q_thread = msb->q_thread; 1323 msb->eject = 1;
1296 msb->q_thread = NULL; 1324 blk_start_queue(msb->queue);
1297 msb->active = 0;
1298 spin_unlock_irqrestore(&msb->q_lock, flags); 1325 spin_unlock_irqrestore(&msb->q_lock, flags);
1299 1326
1300 if (q_thread) {
1301 mutex_unlock(&card->host->lock);
1302 kthread_stop(q_thread);
1303 mutex_lock(&card->host->lock);
1304 }
1305
1306 dev_dbg(&card->dev, "queue thread stopped\n");
1307
1308 blk_cleanup_queue(msb->queue); 1327 blk_cleanup_queue(msb->queue);
1328 msb->queue = NULL;
1309 1329
1310 sysfs_remove_group(&card->dev.kobj, &msb->attr_group); 1330 sysfs_remove_group(&card->dev.kobj, &msb->attr_group);
1311 1331
@@ -1322,19 +1342,13 @@ static void mspro_block_remove(struct memstick_dev *card)
1322static int mspro_block_suspend(struct memstick_dev *card, pm_message_t state) 1342static int mspro_block_suspend(struct memstick_dev *card, pm_message_t state)
1323{ 1343{
1324 struct mspro_block_data *msb = memstick_get_drvdata(card); 1344 struct mspro_block_data *msb = memstick_get_drvdata(card);
1325 struct task_struct *q_thread = NULL;
1326 unsigned long flags; 1345 unsigned long flags;
1327 1346
1328 spin_lock_irqsave(&msb->q_lock, flags); 1347 spin_lock_irqsave(&msb->q_lock, flags);
1329 q_thread = msb->q_thread;
1330 msb->q_thread = NULL;
1331 msb->active = 0;
1332 blk_stop_queue(msb->queue); 1348 blk_stop_queue(msb->queue);
1349 msb->active = 0;
1333 spin_unlock_irqrestore(&msb->q_lock, flags); 1350 spin_unlock_irqrestore(&msb->q_lock, flags);
1334 1351
1335 if (q_thread)
1336 kthread_stop(q_thread);
1337
1338 return 0; 1352 return 0;
1339} 1353}
1340 1354
@@ -1373,14 +1387,7 @@ static int mspro_block_resume(struct memstick_dev *card)
1373 if (memcmp(s_attr->data, r_attr->data, s_attr->size)) 1387 if (memcmp(s_attr->data, r_attr->data, s_attr->size))
1374 break; 1388 break;
1375 1389
1376 memstick_set_drvdata(card, msb); 1390 msb->active = 1;
1377 msb->q_thread = kthread_run(mspro_block_queue_thread,
1378 card, DRIVER_NAME"d");
1379 if (IS_ERR(msb->q_thread))
1380 msb->q_thread = NULL;
1381 else
1382 msb->active = 1;
1383
1384 break; 1391 break;
1385 } 1392 }
1386 } 1393 }
diff --git a/drivers/memstick/host/jmb38x_ms.c b/drivers/memstick/host/jmb38x_ms.c
index 4e3bfbcdf155..3485c63d20b0 100644
--- a/drivers/memstick/host/jmb38x_ms.c
+++ b/drivers/memstick/host/jmb38x_ms.c
@@ -50,6 +50,7 @@ struct jmb38x_ms_host {
50 struct jmb38x_ms *chip; 50 struct jmb38x_ms *chip;
51 void __iomem *addr; 51 void __iomem *addr;
52 spinlock_t lock; 52 spinlock_t lock;
53 struct tasklet_struct notify;
53 int id; 54 int id;
54 char host_id[32]; 55 char host_id[32];
55 int irq; 56 int irq;
@@ -590,55 +591,97 @@ static void jmb38x_ms_abort(unsigned long data)
590 spin_unlock_irqrestore(&host->lock, flags); 591 spin_unlock_irqrestore(&host->lock, flags);
591} 592}
592 593
593static void jmb38x_ms_request(struct memstick_host *msh) 594static void jmb38x_ms_req_tasklet(unsigned long data)
594{ 595{
596 struct memstick_host *msh = (struct memstick_host *)data;
595 struct jmb38x_ms_host *host = memstick_priv(msh); 597 struct jmb38x_ms_host *host = memstick_priv(msh);
596 unsigned long flags; 598 unsigned long flags;
597 int rc; 599 int rc;
598 600
599 spin_lock_irqsave(&host->lock, flags); 601 spin_lock_irqsave(&host->lock, flags);
600 if (host->req) { 602 if (!host->req) {
601 spin_unlock_irqrestore(&host->lock, flags); 603 do {
602 BUG(); 604 rc = memstick_next_req(msh, &host->req);
603 return; 605 dev_dbg(&host->chip->pdev->dev, "tasklet req %d\n", rc);
606 } while (!rc && jmb38x_ms_issue_cmd(msh));
604 } 607 }
605
606 do {
607 rc = memstick_next_req(msh, &host->req);
608 } while (!rc && jmb38x_ms_issue_cmd(msh));
609 spin_unlock_irqrestore(&host->lock, flags); 608 spin_unlock_irqrestore(&host->lock, flags);
610} 609}
611 610
612static void jmb38x_ms_reset(struct jmb38x_ms_host *host) 611static void jmb38x_ms_dummy_submit(struct memstick_host *msh)
613{ 612{
614 unsigned int host_ctl = readl(host->addr + HOST_CONTROL); 613 return;
614}
615
616static void jmb38x_ms_submit_req(struct memstick_host *msh)
617{
618 struct jmb38x_ms_host *host = memstick_priv(msh);
619
620 tasklet_schedule(&host->notify);
621}
622
623static int jmb38x_ms_reset(struct jmb38x_ms_host *host)
624{
625 int cnt;
626
627 writel(HOST_CONTROL_RESET_REQ | HOST_CONTROL_CLOCK_EN
628 | readl(host->addr + HOST_CONTROL),
629 host->addr + HOST_CONTROL);
630 mmiowb();
631
632 for (cnt = 0; cnt < 20; ++cnt) {
633 if (!(HOST_CONTROL_RESET_REQ
634 & readl(host->addr + HOST_CONTROL)))
635 goto reset_next;
615 636
616 writel(HOST_CONTROL_RESET_REQ, host->addr + HOST_CONTROL); 637 ndelay(20);
638 }
639 dev_dbg(&host->chip->pdev->dev, "reset_req timeout\n");
640 return -EIO;
641
642reset_next:
643 writel(HOST_CONTROL_RESET | HOST_CONTROL_CLOCK_EN
644 | readl(host->addr + HOST_CONTROL),
645 host->addr + HOST_CONTROL);
646 mmiowb();
647
648 for (cnt = 0; cnt < 20; ++cnt) {
649 if (!(HOST_CONTROL_RESET
650 & readl(host->addr + HOST_CONTROL)))
651 goto reset_ok;
617 652
618 while (HOST_CONTROL_RESET_REQ
619 & (host_ctl = readl(host->addr + HOST_CONTROL))) {
620 ndelay(20); 653 ndelay(20);
621 dev_dbg(&host->chip->pdev->dev, "reset %08x\n", host_ctl);
622 } 654 }
655 dev_dbg(&host->chip->pdev->dev, "reset timeout\n");
656 return -EIO;
623 657
624 writel(HOST_CONTROL_RESET, host->addr + HOST_CONTROL); 658reset_ok:
625 mmiowb(); 659 mmiowb();
626 writel(INT_STATUS_ALL, host->addr + INT_SIGNAL_ENABLE); 660 writel(INT_STATUS_ALL, host->addr + INT_SIGNAL_ENABLE);
627 writel(INT_STATUS_ALL, host->addr + INT_STATUS_ENABLE); 661 writel(INT_STATUS_ALL, host->addr + INT_STATUS_ENABLE);
662 return 0;
628} 663}
629 664
630static void jmb38x_ms_set_param(struct memstick_host *msh, 665static int jmb38x_ms_set_param(struct memstick_host *msh,
631 enum memstick_param param, 666 enum memstick_param param,
632 int value) 667 int value)
633{ 668{
634 struct jmb38x_ms_host *host = memstick_priv(msh); 669 struct jmb38x_ms_host *host = memstick_priv(msh);
635 unsigned int host_ctl = readl(host->addr + HOST_CONTROL); 670 unsigned int host_ctl = readl(host->addr + HOST_CONTROL);
636 unsigned int clock_ctl = CLOCK_CONTROL_40MHZ, clock_delay = 0; 671 unsigned int clock_ctl = CLOCK_CONTROL_40MHZ, clock_delay = 0;
672 int rc = 0;
637 673
638 switch (param) { 674 switch (param) {
639 case MEMSTICK_POWER: 675 case MEMSTICK_POWER:
640 if (value == MEMSTICK_POWER_ON) { 676 if (value == MEMSTICK_POWER_ON) {
641 jmb38x_ms_reset(host); 677 rc = jmb38x_ms_reset(host);
678 if (rc)
679 return rc;
680
681 host_ctl = 7;
682 host_ctl |= HOST_CONTROL_POWER_EN
683 | HOST_CONTROL_CLOCK_EN;
684 writel(host_ctl, host->addr + HOST_CONTROL);
642 685
643 writel(host->id ? PAD_PU_PD_ON_MS_SOCK1 686 writel(host->id ? PAD_PU_PD_ON_MS_SOCK1
644 : PAD_PU_PD_ON_MS_SOCK0, 687 : PAD_PU_PD_ON_MS_SOCK0,
@@ -647,11 +690,7 @@ static void jmb38x_ms_set_param(struct memstick_host *msh,
647 writel(PAD_OUTPUT_ENABLE_MS, 690 writel(PAD_OUTPUT_ENABLE_MS,
648 host->addr + PAD_OUTPUT_ENABLE); 691 host->addr + PAD_OUTPUT_ENABLE);
649 692
650 host_ctl = 7; 693 msleep(10);
651 host_ctl |= HOST_CONTROL_POWER_EN
652 | HOST_CONTROL_CLOCK_EN;
653 writel(host_ctl, host->addr + HOST_CONTROL);
654
655 dev_dbg(&host->chip->pdev->dev, "power on\n"); 694 dev_dbg(&host->chip->pdev->dev, "power on\n");
656 } else if (value == MEMSTICK_POWER_OFF) { 695 } else if (value == MEMSTICK_POWER_OFF) {
657 host_ctl &= ~(HOST_CONTROL_POWER_EN 696 host_ctl &= ~(HOST_CONTROL_POWER_EN
@@ -660,7 +699,8 @@ static void jmb38x_ms_set_param(struct memstick_host *msh,
660 writel(0, host->addr + PAD_OUTPUT_ENABLE); 699 writel(0, host->addr + PAD_OUTPUT_ENABLE);
661 writel(PAD_PU_PD_OFF, host->addr + PAD_PU_PD); 700 writel(PAD_PU_PD_OFF, host->addr + PAD_PU_PD);
662 dev_dbg(&host->chip->pdev->dev, "power off\n"); 701 dev_dbg(&host->chip->pdev->dev, "power off\n");
663 } 702 } else
703 return -EINVAL;
664 break; 704 break;
665 case MEMSTICK_INTERFACE: 705 case MEMSTICK_INTERFACE:
666 host_ctl &= ~(3 << HOST_CONTROL_IF_SHIFT); 706 host_ctl &= ~(3 << HOST_CONTROL_IF_SHIFT);
@@ -686,12 +726,14 @@ static void jmb38x_ms_set_param(struct memstick_host *msh,
686 host_ctl &= ~HOST_CONTROL_REI; 726 host_ctl &= ~HOST_CONTROL_REI;
687 clock_ctl = CLOCK_CONTROL_60MHZ; 727 clock_ctl = CLOCK_CONTROL_60MHZ;
688 clock_delay = 0; 728 clock_delay = 0;
689 } 729 } else
730 return -EINVAL;
690 writel(host_ctl, host->addr + HOST_CONTROL); 731 writel(host_ctl, host->addr + HOST_CONTROL);
691 writel(clock_ctl, host->addr + CLOCK_CONTROL); 732 writel(clock_ctl, host->addr + CLOCK_CONTROL);
692 writel(clock_delay, host->addr + CLOCK_DELAY); 733 writel(clock_delay, host->addr + CLOCK_DELAY);
693 break; 734 break;
694 }; 735 };
736 return 0;
695} 737}
696 738
697#ifdef CONFIG_PM 739#ifdef CONFIG_PM
@@ -785,7 +827,9 @@ static struct memstick_host *jmb38x_ms_alloc_host(struct jmb38x_ms *jm, int cnt)
785 host->id); 827 host->id);
786 host->irq = jm->pdev->irq; 828 host->irq = jm->pdev->irq;
787 host->timeout_jiffies = msecs_to_jiffies(1000); 829 host->timeout_jiffies = msecs_to_jiffies(1000);
788 msh->request = jmb38x_ms_request; 830
831 tasklet_init(&host->notify, jmb38x_ms_req_tasklet, (unsigned long)msh);
832 msh->request = jmb38x_ms_submit_req;
789 msh->set_param = jmb38x_ms_set_param; 833 msh->set_param = jmb38x_ms_set_param;
790 834
791 msh->caps = MEMSTICK_CAP_PAR4 | MEMSTICK_CAP_PAR8; 835 msh->caps = MEMSTICK_CAP_PAR4 | MEMSTICK_CAP_PAR8;
@@ -897,6 +941,8 @@ static void jmb38x_ms_remove(struct pci_dev *dev)
897 941
898 host = memstick_priv(jm->hosts[cnt]); 942 host = memstick_priv(jm->hosts[cnt]);
899 943
944 jm->hosts[cnt]->request = jmb38x_ms_dummy_submit;
945 tasklet_kill(&host->notify);
900 writel(0, host->addr + INT_SIGNAL_ENABLE); 946 writel(0, host->addr + INT_SIGNAL_ENABLE);
901 writel(0, host->addr + INT_STATUS_ENABLE); 947 writel(0, host->addr + INT_STATUS_ENABLE);
902 mmiowb(); 948 mmiowb();
diff --git a/drivers/memstick/host/tifm_ms.c b/drivers/memstick/host/tifm_ms.c
index 8577de4ebb0e..d32d6ad8f3fc 100644
--- a/drivers/memstick/host/tifm_ms.c
+++ b/drivers/memstick/host/tifm_ms.c
@@ -71,6 +71,7 @@ struct tifm_ms {
71 struct tifm_dev *dev; 71 struct tifm_dev *dev;
72 struct timer_list timer; 72 struct timer_list timer;
73 struct memstick_request *req; 73 struct memstick_request *req;
74 struct tasklet_struct notify;
74 unsigned int mode_mask; 75 unsigned int mode_mask;
75 unsigned int block_pos; 76 unsigned int block_pos;
76 unsigned long timeout_jiffies; 77 unsigned long timeout_jiffies;
@@ -455,49 +456,51 @@ static void tifm_ms_card_event(struct tifm_dev *sock)
455 return; 456 return;
456} 457}
457 458
458static void tifm_ms_request(struct memstick_host *msh) 459static void tifm_ms_req_tasklet(unsigned long data)
459{ 460{
461 struct memstick_host *msh = (struct memstick_host *)data;
460 struct tifm_ms *host = memstick_priv(msh); 462 struct tifm_ms *host = memstick_priv(msh);
461 struct tifm_dev *sock = host->dev; 463 struct tifm_dev *sock = host->dev;
462 unsigned long flags; 464 unsigned long flags;
463 int rc; 465 int rc;
464 466
465 spin_lock_irqsave(&sock->lock, flags); 467 spin_lock_irqsave(&sock->lock, flags);
466 if (host->req) { 468 if (!host->req) {
467 printk(KERN_ERR "%s : unfinished request detected\n", 469 if (host->eject) {
468 sock->dev.bus_id); 470 do {
469 spin_unlock_irqrestore(&sock->lock, flags); 471 rc = memstick_next_req(msh, &host->req);
470 tifm_eject(host->dev); 472 if (!rc)
471 return; 473 host->req->error = -ETIME;
472 } 474 } while (!rc);
475 spin_unlock_irqrestore(&sock->lock, flags);
476 return;
477 }
473 478
474 if (host->eject) {
475 do { 479 do {
476 rc = memstick_next_req(msh, &host->req); 480 rc = memstick_next_req(msh, &host->req);
477 if (!rc) 481 } while (!rc && tifm_ms_issue_cmd(host));
478 host->req->error = -ETIME;
479 } while (!rc);
480 spin_unlock_irqrestore(&sock->lock, flags);
481 return;
482 } 482 }
483
484 do {
485 rc = memstick_next_req(msh, &host->req);
486 } while (!rc && tifm_ms_issue_cmd(host));
487
488 spin_unlock_irqrestore(&sock->lock, flags); 483 spin_unlock_irqrestore(&sock->lock, flags);
484}
485
486static void tifm_ms_dummy_submit(struct memstick_host *msh)
487{
489 return; 488 return;
490} 489}
491 490
492static void tifm_ms_set_param(struct memstick_host *msh, 491static void tifm_ms_submit_req(struct memstick_host *msh)
493 enum memstick_param param,
494 int value)
495{ 492{
496 struct tifm_ms *host = memstick_priv(msh); 493 struct tifm_ms *host = memstick_priv(msh);
497 struct tifm_dev *sock = host->dev;
498 unsigned long flags;
499 494
500 spin_lock_irqsave(&sock->lock, flags); 495 tasklet_schedule(&host->notify);
496}
497
498static int tifm_ms_set_param(struct memstick_host *msh,
499 enum memstick_param param,
500 int value)
501{
502 struct tifm_ms *host = memstick_priv(msh);
503 struct tifm_dev *sock = host->dev;
501 504
502 switch (param) { 505 switch (param) {
503 case MEMSTICK_POWER: 506 case MEMSTICK_POWER:
@@ -512,7 +515,8 @@ static void tifm_ms_set_param(struct memstick_host *msh,
512 writel(TIFM_MS_SYS_FCLR | TIFM_MS_SYS_INTCLR, 515 writel(TIFM_MS_SYS_FCLR | TIFM_MS_SYS_INTCLR,
513 sock->addr + SOCK_MS_SYSTEM); 516 sock->addr + SOCK_MS_SYSTEM);
514 writel(0xffffffff, sock->addr + SOCK_MS_STATUS); 517 writel(0xffffffff, sock->addr + SOCK_MS_STATUS);
515 } 518 } else
519 return -EINVAL;
516 break; 520 break;
517 case MEMSTICK_INTERFACE: 521 case MEMSTICK_INTERFACE:
518 if (value == MEMSTICK_SERIAL) { 522 if (value == MEMSTICK_SERIAL) {
@@ -525,11 +529,12 @@ static void tifm_ms_set_param(struct memstick_host *msh,
525 writel(TIFM_CTRL_FAST_CLK 529 writel(TIFM_CTRL_FAST_CLK
526 | readl(sock->addr + SOCK_CONTROL), 530 | readl(sock->addr + SOCK_CONTROL),
527 sock->addr + SOCK_CONTROL); 531 sock->addr + SOCK_CONTROL);
528 } 532 } else
533 return -EINVAL;
529 break; 534 break;
530 }; 535 };
531 536
532 spin_unlock_irqrestore(&sock->lock, flags); 537 return 0;
533} 538}
534 539
535static void tifm_ms_abort(unsigned long data) 540static void tifm_ms_abort(unsigned long data)
@@ -570,8 +575,9 @@ static int tifm_ms_probe(struct tifm_dev *sock)
570 host->timeout_jiffies = msecs_to_jiffies(1000); 575 host->timeout_jiffies = msecs_to_jiffies(1000);
571 576
572 setup_timer(&host->timer, tifm_ms_abort, (unsigned long)host); 577 setup_timer(&host->timer, tifm_ms_abort, (unsigned long)host);
578 tasklet_init(&host->notify, tifm_ms_req_tasklet, (unsigned long)msh);
573 579
574 msh->request = tifm_ms_request; 580 msh->request = tifm_ms_submit_req;
575 msh->set_param = tifm_ms_set_param; 581 msh->set_param = tifm_ms_set_param;
576 sock->card_event = tifm_ms_card_event; 582 sock->card_event = tifm_ms_card_event;
577 sock->data_event = tifm_ms_data_event; 583 sock->data_event = tifm_ms_data_event;
@@ -593,6 +599,8 @@ static void tifm_ms_remove(struct tifm_dev *sock)
593 int rc = 0; 599 int rc = 0;
594 unsigned long flags; 600 unsigned long flags;
595 601
602 msh->request = tifm_ms_dummy_submit;
603 tasklet_kill(&host->notify);
596 spin_lock_irqsave(&sock->lock, flags); 604 spin_lock_irqsave(&sock->lock, flags);
597 host->eject = 1; 605 host->eject = 1;
598 if (host->req) { 606 if (host->req) {
diff --git a/drivers/message/fusion/lsi/mpi_history.txt b/drivers/message/fusion/lsi/mpi_history.txt
index 241592ab13ad..3f15fcfe4a2e 100644
--- a/drivers/message/fusion/lsi/mpi_history.txt
+++ b/drivers/message/fusion/lsi/mpi_history.txt
@@ -127,7 +127,7 @@ mpi_ioc.h
127 * 08-08-01 01.02.01 Original release for v1.2 work. 127 * 08-08-01 01.02.01 Original release for v1.2 work.
128 * New format for FWVersion and ProductId in 128 * New format for FWVersion and ProductId in
129 * MSG_IOC_FACTS_REPLY and MPI_FW_HEADER. 129 * MSG_IOC_FACTS_REPLY and MPI_FW_HEADER.
130 * 08-31-01 01.02.02 Addded event MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE and 130 * 08-31-01 01.02.02 Added event MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE and
131 * related structure and defines. 131 * related structure and defines.
132 * Added event MPI_EVENT_ON_BUS_TIMER_EXPIRED. 132 * Added event MPI_EVENT_ON_BUS_TIMER_EXPIRED.
133 * Added MPI_IOCINIT_FLAGS_DISCARD_FW_IMAGE. 133 * Added MPI_IOCINIT_FLAGS_DISCARD_FW_IMAGE.
@@ -187,7 +187,7 @@ mpi_ioc.h
187 * 10-11-06 01.05.12 Added MPI_IOCFACTS_EXCEPT_METADATA_UNSUPPORTED. 187 * 10-11-06 01.05.12 Added MPI_IOCFACTS_EXCEPT_METADATA_UNSUPPORTED.
188 * Added MaxInitiators field to PortFacts reply. 188 * Added MaxInitiators field to PortFacts reply.
189 * Added SAS Device Status Change ReasonCode for 189 * Added SAS Device Status Change ReasonCode for
190 * asynchronous notificaiton. 190 * asynchronous notification.
191 * Added MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE and event 191 * Added MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE and event
192 * data structure. 192 * data structure.
193 * Added new ImageType values for FWDownload and FWUpload 193 * Added new ImageType values for FWDownload and FWUpload
@@ -213,7 +213,7 @@ mpi_cnfg.h
213 * Added _RESPONSE_ID_MASK definition to SCSI_PORT_1 213 * Added _RESPONSE_ID_MASK definition to SCSI_PORT_1
214 * page and updated the page version. 214 * page and updated the page version.
215 * Added Information field and _INFO_PARAMS_NEGOTIATED 215 * Added Information field and _INFO_PARAMS_NEGOTIATED
216 * definitionto SCSI_DEVICE_0 page. 216 * definition to SCSI_DEVICE_0 page.
217 * 06-22-00 01.00.03 Removed batch controls from LAN_0 page and updated the 217 * 06-22-00 01.00.03 Removed batch controls from LAN_0 page and updated the
218 * page version. 218 * page version.
219 * Added BucketsRemaining to LAN_1 page, redefined the 219 * Added BucketsRemaining to LAN_1 page, redefined the
diff --git a/drivers/message/i2o/device.c b/drivers/message/i2o/device.c
index 489d7c5c4965..8774c670e668 100644
--- a/drivers/message/i2o/device.c
+++ b/drivers/message/i2o/device.c
@@ -243,29 +243,41 @@ static int i2o_device_add(struct i2o_controller *c, i2o_lct_entry *entry)
243 243
244 /* create user entries for this device */ 244 /* create user entries for this device */
245 tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.user_tid); 245 tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.user_tid);
246 if (tmp && (tmp != i2o_dev)) 246 if (tmp && (tmp != i2o_dev)) {
247 sysfs_create_link(&i2o_dev->device.kobj, &tmp->device.kobj, 247 rc = sysfs_create_link(&i2o_dev->device.kobj,
248 "user"); 248 &tmp->device.kobj, "user");
249 if (rc)
250 goto unreg_dev;
251 }
249 252
250 /* create user entries refering to this device */ 253 /* create user entries refering to this device */
251 list_for_each_entry(tmp, &c->devices, list) 254 list_for_each_entry(tmp, &c->devices, list)
252 if ((tmp->lct_data.user_tid == i2o_dev->lct_data.tid) 255 if ((tmp->lct_data.user_tid == i2o_dev->lct_data.tid)
253 && (tmp != i2o_dev)) 256 && (tmp != i2o_dev)) {
254 sysfs_create_link(&tmp->device.kobj, 257 rc = sysfs_create_link(&tmp->device.kobj,
255 &i2o_dev->device.kobj, "user"); 258 &i2o_dev->device.kobj, "user");
259 if (rc)
260 goto rmlink1;
261 }
256 262
257 /* create parent entries for this device */ 263 /* create parent entries for this device */
258 tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.parent_tid); 264 tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.parent_tid);
259 if (tmp && (tmp != i2o_dev)) 265 if (tmp && (tmp != i2o_dev)) {
260 sysfs_create_link(&i2o_dev->device.kobj, &tmp->device.kobj, 266 rc = sysfs_create_link(&i2o_dev->device.kobj,
261 "parent"); 267 &tmp->device.kobj, "parent");
268 if (rc)
269 goto rmlink1;
270 }
262 271
263 /* create parent entries refering to this device */ 272 /* create parent entries refering to this device */
264 list_for_each_entry(tmp, &c->devices, list) 273 list_for_each_entry(tmp, &c->devices, list)
265 if ((tmp->lct_data.parent_tid == i2o_dev->lct_data.tid) 274 if ((tmp->lct_data.parent_tid == i2o_dev->lct_data.tid)
266 && (tmp != i2o_dev)) 275 && (tmp != i2o_dev)) {
267 sysfs_create_link(&tmp->device.kobj, 276 rc = sysfs_create_link(&tmp->device.kobj,
268 &i2o_dev->device.kobj, "parent"); 277 &i2o_dev->device.kobj, "parent");
278 if (rc)
279 goto rmlink2;
280 }
269 281
270 i2o_driver_notify_device_add_all(i2o_dev); 282 i2o_driver_notify_device_add_all(i2o_dev);
271 283
@@ -273,6 +285,24 @@ static int i2o_device_add(struct i2o_controller *c, i2o_lct_entry *entry)
273 285
274 return 0; 286 return 0;
275 287
288rmlink2:
289 /* If link creating failed halfway, we loop whole list to cleanup.
290 * And we don't care wrong removing of link, because sysfs_remove_link
291 * will take care of it.
292 */
293 list_for_each_entry(tmp, &c->devices, list) {
294 if (tmp->lct_data.parent_tid == i2o_dev->lct_data.tid)
295 sysfs_remove_link(&tmp->device.kobj, "parent");
296 }
297 sysfs_remove_link(&i2o_dev->device.kobj, "parent");
298rmlink1:
299 list_for_each_entry(tmp, &c->devices, list)
300 if (tmp->lct_data.user_tid == i2o_dev->lct_data.tid)
301 sysfs_remove_link(&tmp->device.kobj, "user");
302 sysfs_remove_link(&i2o_dev->device.kobj, "user");
303unreg_dev:
304 list_del(&i2o_dev->list);
305 device_unregister(&i2o_dev->device);
276err: 306err:
277 kfree(i2o_dev); 307 kfree(i2o_dev);
278 return rc; 308 return rc;
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 260bade0a5ec..883e7ea31de2 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -5,6 +5,10 @@
5menu "Multifunction device drivers" 5menu "Multifunction device drivers"
6 depends on HAS_IOMEM 6 depends on HAS_IOMEM
7 7
8config MFD_CORE
9 tristate
10 default n
11
8config MFD_SM501 12config MFD_SM501
9 tristate "Support for Silicon Motion SM501" 13 tristate "Support for Silicon Motion SM501"
10 ---help--- 14 ---help---
@@ -15,6 +19,14 @@ config MFD_SM501
15 interface. The device may be connected by PCI or local bus with 19 interface. The device may be connected by PCI or local bus with
16 varying functions enabled. 20 varying functions enabled.
17 21
22config MFD_SM501_GPIO
23 bool "Export GPIO via GPIO layer"
24 depends on MFD_SM501 && HAVE_GPIO_LIB
25 ---help---
26 This option uses the gpio library layer to export the 64 GPIO
27 lines on the SM501. The platform data is used to supply the
28 base number for the first GPIO line to register.
29
18config MFD_ASIC3 30config MFD_ASIC3
19 bool "Support for Compaq ASIC3" 31 bool "Support for Compaq ASIC3"
20 depends on GENERIC_HARDIRQS && HAVE_GPIO_LIB && ARM 32 depends on GENERIC_HARDIRQS && HAVE_GPIO_LIB && ARM
@@ -24,7 +36,7 @@ config MFD_ASIC3
24 36
25config HTC_EGPIO 37config HTC_EGPIO
26 bool "HTC EGPIO support" 38 bool "HTC EGPIO support"
27 depends on GENERIC_HARDIRQS && HAVE_GPIO_LIB && ARM 39 depends on GENERIC_HARDIRQS && GPIOLIB && ARM
28 help 40 help
29 This driver supports the CPLD egpio chip present on 41 This driver supports the CPLD egpio chip present on
30 several HTC phones. It provides basic support for input 42 several HTC phones. It provides basic support for input
@@ -38,6 +50,13 @@ config HTC_PASIC3
38 HTC Magician devices, respectively. Actual functionality is 50 HTC Magician devices, respectively. Actual functionality is
39 handled by the leds-pasic3 and ds1wm drivers. 51 handled by the leds-pasic3 and ds1wm drivers.
40 52
53config MFD_TC6393XB
54 bool "Support Toshiba TC6393XB"
55 depends on GPIOLIB && ARM
56 select MFD_CORE
57 help
58 Support for Toshiba Mobile IO Controller TC6393XB
59
41endmenu 60endmenu
42 61
43menu "Multimedia Capabilities Port drivers" 62menu "Multimedia Capabilities Port drivers"
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index eef4e26807df..33daa2f45dd8 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -8,6 +8,10 @@ obj-$(CONFIG_MFD_ASIC3) += asic3.o
8obj-$(CONFIG_HTC_EGPIO) += htc-egpio.o 8obj-$(CONFIG_HTC_EGPIO) += htc-egpio.o
9obj-$(CONFIG_HTC_PASIC3) += htc-pasic3.o 9obj-$(CONFIG_HTC_PASIC3) += htc-pasic3.o
10 10
11obj-$(CONFIG_MFD_TC6393XB) += tc6393xb.o
12
13obj-$(CONFIG_MFD_CORE) += mfd-core.o
14
11obj-$(CONFIG_MCP) += mcp-core.o 15obj-$(CONFIG_MCP) += mcp-core.o
12obj-$(CONFIG_MCP_SA11X0) += mcp-sa11x0.o 16obj-$(CONFIG_MCP_SA11X0) += mcp-sa11x0.o
13obj-$(CONFIG_MCP_UCB1200) += ucb1x00-core.o 17obj-$(CONFIG_MCP_UCB1200) += ucb1x00-core.o
diff --git a/drivers/mfd/asic3.c b/drivers/mfd/asic3.c
index 3b870e7fb3e1..eabf0bfccab4 100644
--- a/drivers/mfd/asic3.c
+++ b/drivers/mfd/asic3.c
@@ -314,10 +314,12 @@ static int __init asic3_irq_probe(struct platform_device *pdev)
314 unsigned long clksel = 0; 314 unsigned long clksel = 0;
315 unsigned int irq, irq_base; 315 unsigned int irq, irq_base;
316 int map_size; 316 int map_size;
317 int ret;
317 318
318 asic->irq_nr = platform_get_irq(pdev, 0); 319 ret = platform_get_irq(pdev, 0);
319 if (asic->irq_nr < 0) 320 if (ret < 0)
320 return asic->irq_nr; 321 return ret;
322 asic->irq_nr = ret;
321 323
322 /* turn on clock to IRQ controller */ 324 /* turn on clock to IRQ controller */
323 clksel |= CLOCK_SEL_CX; 325 clksel |= CLOCK_SEL_CX;
diff --git a/drivers/mfd/htc-egpio.c b/drivers/mfd/htc-egpio.c
index 8872cc077519..6be43172dc65 100644
--- a/drivers/mfd/htc-egpio.c
+++ b/drivers/mfd/htc-egpio.c
@@ -318,6 +318,8 @@ static int __init egpio_probe(struct platform_device *pdev)
318 ei->chip[i].dev = &(pdev->dev); 318 ei->chip[i].dev = &(pdev->dev);
319 chip = &(ei->chip[i].chip); 319 chip = &(ei->chip[i].chip);
320 chip->label = "htc-egpio"; 320 chip->label = "htc-egpio";
321 chip->dev = &pdev->dev;
322 chip->owner = THIS_MODULE;
321 chip->get = egpio_get; 323 chip->get = egpio_get;
322 chip->set = egpio_set; 324 chip->set = egpio_set;
323 chip->direction_input = egpio_direction_input; 325 chip->direction_input = egpio_direction_input;
diff --git a/drivers/mfd/htc-pasic3.c b/drivers/mfd/htc-pasic3.c
index 633cbba072f0..91b294dcc133 100644
--- a/drivers/mfd/htc-pasic3.c
+++ b/drivers/mfd/htc-pasic3.c
@@ -238,6 +238,8 @@ static int pasic3_remove(struct platform_device *pdev)
238 return 0; 238 return 0;
239} 239}
240 240
241MODULE_ALIAS("platform:pasic3");
242
241static struct platform_driver pasic3_driver = { 243static struct platform_driver pasic3_driver = {
242 .driver = { 244 .driver = {
243 .name = "pasic3", 245 .name = "pasic3",
diff --git a/drivers/mfd/mcp-sa11x0.c b/drivers/mfd/mcp-sa11x0.c
index 1eab7cffceaa..b5272b5ce3fa 100644
--- a/drivers/mfd/mcp-sa11x0.c
+++ b/drivers/mfd/mcp-sa11x0.c
@@ -242,6 +242,8 @@ static int mcp_sa11x0_resume(struct platform_device *dev)
242/* 242/*
243 * The driver for the SA11x0 MCP port. 243 * The driver for the SA11x0 MCP port.
244 */ 244 */
245MODULE_ALIAS("platform:sa11x0-mcp");
246
245static struct platform_driver mcp_sa11x0_driver = { 247static struct platform_driver mcp_sa11x0_driver = {
246 .probe = mcp_sa11x0_probe, 248 .probe = mcp_sa11x0_probe,
247 .remove = mcp_sa11x0_remove, 249 .remove = mcp_sa11x0_remove,
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
new file mode 100644
index 000000000000..0454be4266c1
--- /dev/null
+++ b/drivers/mfd/mfd-core.c
@@ -0,0 +1,114 @@
1/*
2 * drivers/mfd/mfd-core.c
3 *
4 * core MFD support
5 * Copyright (c) 2006 Ian Molton
6 * Copyright (c) 2007,2008 Dmitry Baryshkov
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/kernel.h>
15#include <linux/platform_device.h>
16#include <linux/mfd/core.h>
17
18static int mfd_add_device(struct platform_device *parent,
19 const struct mfd_cell *cell,
20 struct resource *mem_base,
21 int irq_base)
22{
23 struct resource res[cell->num_resources];
24 struct platform_device *pdev;
25 int ret = -ENOMEM;
26 int r;
27
28 pdev = platform_device_alloc(cell->name, parent->id);
29 if (!pdev)
30 goto fail_alloc;
31
32 pdev->dev.parent = &parent->dev;
33
34 ret = platform_device_add_data(pdev,
35 cell, sizeof(struct mfd_cell));
36 if (ret)
37 goto fail_device;
38
39 memset(res, 0, sizeof(res));
40 for (r = 0; r < cell->num_resources; r++) {
41 res[r].name = cell->resources[r].name;
42 res[r].flags = cell->resources[r].flags;
43
44 /* Find out base to use */
45 if (cell->resources[r].flags & IORESOURCE_MEM) {
46 res[r].parent = mem_base;
47 res[r].start = mem_base->start +
48 cell->resources[r].start;
49 res[r].end = mem_base->start +
50 cell->resources[r].end;
51 } else if (cell->resources[r].flags & IORESOURCE_IRQ) {
52 res[r].start = irq_base +
53 cell->resources[r].start;
54 res[r].end = irq_base +
55 cell->resources[r].end;
56 } else {
57 res[r].parent = cell->resources[r].parent;
58 res[r].start = cell->resources[r].start;
59 res[r].end = cell->resources[r].end;
60 }
61 }
62
63 platform_device_add_resources(pdev, res, cell->num_resources);
64
65 ret = platform_device_add(pdev);
66 if (ret)
67 goto fail_device;
68
69 return 0;
70
71/* platform_device_del(pdev); */
72fail_device:
73 platform_device_put(pdev);
74fail_alloc:
75 return ret;
76}
77
78int mfd_add_devices(
79 struct platform_device *parent,
80 const struct mfd_cell *cells, int n_devs,
81 struct resource *mem_base,
82 int irq_base)
83{
84 int i;
85 int ret = 0;
86
87 for (i = 0; i < n_devs; i++) {
88 ret = mfd_add_device(parent, cells + i, mem_base, irq_base);
89 if (ret)
90 break;
91 }
92
93 if (ret)
94 mfd_remove_devices(parent);
95
96 return ret;
97}
98EXPORT_SYMBOL(mfd_add_devices);
99
100static int mfd_remove_devices_fn(struct device *dev, void *unused)
101{
102 platform_device_unregister(
103 container_of(dev, struct platform_device, dev));
104 return 0;
105}
106
107void mfd_remove_devices(struct platform_device *parent)
108{
109 device_for_each_child(&parent->dev, NULL, mfd_remove_devices_fn);
110}
111EXPORT_SYMBOL(mfd_remove_devices);
112
113MODULE_LICENSE("GPL");
114MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov");
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 2fe64734d8af..7aebad4c06ff 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -19,6 +19,7 @@
19#include <linux/device.h> 19#include <linux/device.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/i2c-gpio.h>
22 23
23#include <linux/sm501.h> 24#include <linux/sm501.h>
24#include <linux/sm501-regs.h> 25#include <linux/sm501-regs.h>
@@ -31,10 +32,37 @@ struct sm501_device {
31 struct platform_device pdev; 32 struct platform_device pdev;
32}; 33};
33 34
35struct sm501_gpio;
36
37#ifdef CONFIG_MFD_SM501_GPIO
38#include <linux/gpio.h>
39
40struct sm501_gpio_chip {
41 struct gpio_chip gpio;
42 struct sm501_gpio *ourgpio; /* to get back to parent. */
43 void __iomem *regbase;
44};
45
46struct sm501_gpio {
47 struct sm501_gpio_chip low;
48 struct sm501_gpio_chip high;
49 spinlock_t lock;
50
51 unsigned int registered : 1;
52 void __iomem *regs;
53 struct resource *regs_res;
54};
55#else
56struct sm501_gpio {
57 /* no gpio support, empty definition for sm501_devdata. */
58};
59#endif
60
34struct sm501_devdata { 61struct sm501_devdata {
35 spinlock_t reg_lock; 62 spinlock_t reg_lock;
36 struct mutex clock_lock; 63 struct mutex clock_lock;
37 struct list_head devices; 64 struct list_head devices;
65 struct sm501_gpio gpio;
38 66
39 struct device *dev; 67 struct device *dev;
40 struct resource *io_res; 68 struct resource *io_res;
@@ -42,6 +70,7 @@ struct sm501_devdata {
42 struct resource *regs_claim; 70 struct resource *regs_claim;
43 struct sm501_platdata *platdata; 71 struct sm501_platdata *platdata;
44 72
73
45 unsigned int in_suspend; 74 unsigned int in_suspend;
46 unsigned long pm_misc; 75 unsigned long pm_misc;
47 76
@@ -52,6 +81,7 @@ struct sm501_devdata {
52 unsigned int rev; 81 unsigned int rev;
53}; 82};
54 83
84
55#define MHZ (1000 * 1000) 85#define MHZ (1000 * 1000)
56 86
57#ifdef DEBUG 87#ifdef DEBUG
@@ -276,58 +306,6 @@ unsigned long sm501_modify_reg(struct device *dev,
276 306
277EXPORT_SYMBOL_GPL(sm501_modify_reg); 307EXPORT_SYMBOL_GPL(sm501_modify_reg);
278 308
279unsigned long sm501_gpio_get(struct device *dev,
280 unsigned long gpio)
281{
282 struct sm501_devdata *sm = dev_get_drvdata(dev);
283 unsigned long result;
284 unsigned long reg;
285
286 reg = (gpio > 32) ? SM501_GPIO_DATA_HIGH : SM501_GPIO_DATA_LOW;
287 result = readl(sm->regs + reg);
288
289 result >>= (gpio & 31);
290 return result & 1UL;
291}
292
293EXPORT_SYMBOL_GPL(sm501_gpio_get);
294
295void sm501_gpio_set(struct device *dev,
296 unsigned long gpio,
297 unsigned int to,
298 unsigned int dir)
299{
300 struct sm501_devdata *sm = dev_get_drvdata(dev);
301
302 unsigned long bit = 1 << (gpio & 31);
303 unsigned long base;
304 unsigned long save;
305 unsigned long val;
306
307 base = (gpio > 32) ? SM501_GPIO_DATA_HIGH : SM501_GPIO_DATA_LOW;
308 base += SM501_GPIO;
309
310 spin_lock_irqsave(&sm->reg_lock, save);
311
312 val = readl(sm->regs + base) & ~bit;
313 if (to)
314 val |= bit;
315 writel(val, sm->regs + base);
316
317 val = readl(sm->regs + SM501_GPIO_DDR_LOW) & ~bit;
318 if (dir)
319 val |= bit;
320
321 writel(val, sm->regs + SM501_GPIO_DDR_LOW);
322 sm501_sync_regs(sm);
323
324 spin_unlock_irqrestore(&sm->reg_lock, save);
325
326}
327
328EXPORT_SYMBOL_GPL(sm501_gpio_set);
329
330
331/* sm501_unit_power 309/* sm501_unit_power
332 * 310 *
333 * alters the power active gate to set specific units on or off 311 * alters the power active gate to set specific units on or off
@@ -906,6 +884,313 @@ static int sm501_register_display(struct sm501_devdata *sm,
906 return sm501_register_device(sm, pdev); 884 return sm501_register_device(sm, pdev);
907} 885}
908 886
887#ifdef CONFIG_MFD_SM501_GPIO
888
889static inline struct sm501_gpio_chip *to_sm501_gpio(struct gpio_chip *gc)
890{
891 return container_of(gc, struct sm501_gpio_chip, gpio);
892}
893
894static inline struct sm501_devdata *sm501_gpio_to_dev(struct sm501_gpio *gpio)
895{
896 return container_of(gpio, struct sm501_devdata, gpio);
897}
898
899static int sm501_gpio_get(struct gpio_chip *chip, unsigned offset)
900
901{
902 struct sm501_gpio_chip *smgpio = to_sm501_gpio(chip);
903 unsigned long result;
904
905 result = readl(smgpio->regbase + SM501_GPIO_DATA_LOW);
906 result >>= offset;
907
908 return result & 1UL;
909}
910
911static void sm501_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
912
913{
914 struct sm501_gpio_chip *smchip = to_sm501_gpio(chip);
915 struct sm501_gpio *smgpio = smchip->ourgpio;
916 unsigned long bit = 1 << offset;
917 void __iomem *regs = smchip->regbase;
918 unsigned long save;
919 unsigned long val;
920
921 dev_dbg(sm501_gpio_to_dev(smgpio)->dev, "%s(%p,%d)\n",
922 __func__, chip, offset);
923
924 spin_lock_irqsave(&smgpio->lock, save);
925
926 val = readl(regs + SM501_GPIO_DATA_LOW) & ~bit;
927 if (value)
928 val |= bit;
929 writel(val, regs);
930
931 sm501_sync_regs(sm501_gpio_to_dev(smgpio));
932 spin_unlock_irqrestore(&smgpio->lock, save);
933}
934
935static int sm501_gpio_input(struct gpio_chip *chip, unsigned offset)
936{
937 struct sm501_gpio_chip *smchip = to_sm501_gpio(chip);
938 struct sm501_gpio *smgpio = smchip->ourgpio;
939 void __iomem *regs = smchip->regbase;
940 unsigned long bit = 1 << offset;
941 unsigned long save;
942 unsigned long ddr;
943
944 dev_info(sm501_gpio_to_dev(smgpio)->dev, "%s(%p,%d)\n",
945 __func__, chip, offset);
946
947 spin_lock_irqsave(&smgpio->lock, save);
948
949 ddr = readl(regs + SM501_GPIO_DDR_LOW);
950 writel(ddr & ~bit, regs + SM501_GPIO_DDR_LOW);
951
952 sm501_sync_regs(sm501_gpio_to_dev(smgpio));
953 spin_unlock_irqrestore(&smgpio->lock, save);
954
955 return 0;
956}
957
958static int sm501_gpio_output(struct gpio_chip *chip,
959 unsigned offset, int value)
960{
961 struct sm501_gpio_chip *smchip = to_sm501_gpio(chip);
962 struct sm501_gpio *smgpio = smchip->ourgpio;
963 unsigned long bit = 1 << offset;
964 void __iomem *regs = smchip->regbase;
965 unsigned long save;
966 unsigned long val;
967 unsigned long ddr;
968
969 dev_dbg(sm501_gpio_to_dev(smgpio)->dev, "%s(%p,%d,%d)\n",
970 __func__, chip, offset, value);
971
972 spin_lock_irqsave(&smgpio->lock, save);
973
974 val = readl(regs + SM501_GPIO_DATA_LOW);
975 if (value)
976 val |= bit;
977 else
978 val &= ~bit;
979 writel(val, regs);
980
981 ddr = readl(regs + SM501_GPIO_DDR_LOW);
982 writel(ddr | bit, regs + SM501_GPIO_DDR_LOW);
983
984 sm501_sync_regs(sm501_gpio_to_dev(smgpio));
985 writel(val, regs + SM501_GPIO_DATA_LOW);
986
987 sm501_sync_regs(sm501_gpio_to_dev(smgpio));
988 spin_unlock_irqrestore(&smgpio->lock, save);
989
990 return 0;
991}
992
993static struct gpio_chip gpio_chip_template = {
994 .ngpio = 32,
995 .direction_input = sm501_gpio_input,
996 .direction_output = sm501_gpio_output,
997 .set = sm501_gpio_set,
998 .get = sm501_gpio_get,
999};
1000
1001static int __devinit sm501_gpio_register_chip(struct sm501_devdata *sm,
1002 struct sm501_gpio *gpio,
1003 struct sm501_gpio_chip *chip)
1004{
1005 struct sm501_platdata *pdata = sm->platdata;
1006 struct gpio_chip *gchip = &chip->gpio;
1007 int base = pdata->gpio_base;
1008
1009 chip->gpio = gpio_chip_template;
1010
1011 if (chip == &gpio->high) {
1012 if (base > 0)
1013 base += 32;
1014 chip->regbase = gpio->regs + SM501_GPIO_DATA_HIGH;
1015 gchip->label = "SM501-HIGH";
1016 } else {
1017 chip->regbase = gpio->regs + SM501_GPIO_DATA_LOW;
1018 gchip->label = "SM501-LOW";
1019 }
1020
1021 gchip->base = base;
1022 chip->ourgpio = gpio;
1023
1024 return gpiochip_add(gchip);
1025}
1026
1027static int sm501_register_gpio(struct sm501_devdata *sm)
1028{
1029 struct sm501_gpio *gpio = &sm->gpio;
1030 resource_size_t iobase = sm->io_res->start + SM501_GPIO;
1031 int ret;
1032 int tmp;
1033
1034 dev_dbg(sm->dev, "registering gpio block %08llx\n",
1035 (unsigned long long)iobase);
1036
1037 spin_lock_init(&gpio->lock);
1038
1039 gpio->regs_res = request_mem_region(iobase, 0x20, "sm501-gpio");
1040 if (gpio->regs_res == NULL) {
1041 dev_err(sm->dev, "gpio: failed to request region\n");
1042 return -ENXIO;
1043 }
1044
1045 gpio->regs = ioremap(iobase, 0x20);
1046 if (gpio->regs == NULL) {
1047 dev_err(sm->dev, "gpio: failed to remap registers\n");
1048 ret = -ENXIO;
1049 goto err_claimed;
1050 }
1051
1052 /* Register both our chips. */
1053
1054 ret = sm501_gpio_register_chip(sm, gpio, &gpio->low);
1055 if (ret) {
1056 dev_err(sm->dev, "failed to add low chip\n");
1057 goto err_mapped;
1058 }
1059
1060 ret = sm501_gpio_register_chip(sm, gpio, &gpio->high);
1061 if (ret) {
1062 dev_err(sm->dev, "failed to add high chip\n");
1063 goto err_low_chip;
1064 }
1065
1066 gpio->registered = 1;
1067
1068 return 0;
1069
1070 err_low_chip:
1071 tmp = gpiochip_remove(&gpio->low.gpio);
1072 if (tmp) {
1073 dev_err(sm->dev, "cannot remove low chip, cannot tidy up\n");
1074 return ret;
1075 }
1076
1077 err_mapped:
1078 iounmap(gpio->regs);
1079
1080 err_claimed:
1081 release_resource(gpio->regs_res);
1082 kfree(gpio->regs_res);
1083
1084 return ret;
1085}
1086
1087static void sm501_gpio_remove(struct sm501_devdata *sm)
1088{
1089 struct sm501_gpio *gpio = &sm->gpio;
1090 int ret;
1091
1092 if (!sm->gpio.registered)
1093 return;
1094
1095 ret = gpiochip_remove(&gpio->low.gpio);
1096 if (ret)
1097 dev_err(sm->dev, "cannot remove low chip, cannot tidy up\n");
1098
1099 ret = gpiochip_remove(&gpio->high.gpio);
1100 if (ret)
1101 dev_err(sm->dev, "cannot remove high chip, cannot tidy up\n");
1102
1103 iounmap(gpio->regs);
1104 release_resource(gpio->regs_res);
1105 kfree(gpio->regs_res);
1106}
1107
1108static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin)
1109{
1110 struct sm501_gpio *gpio = &sm->gpio;
1111 int base = (pin < 32) ? gpio->low.gpio.base : gpio->high.gpio.base;
1112
1113 return (pin % 32) + base;
1114}
1115
1116static inline int sm501_gpio_isregistered(struct sm501_devdata *sm)
1117{
1118 return sm->gpio.registered;
1119}
1120#else
1121static inline int sm501_register_gpio(struct sm501_devdata *sm)
1122{
1123 return 0;
1124}
1125
1126static inline void sm501_gpio_remove(struct sm501_devdata *sm)
1127{
1128}
1129
1130static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin)
1131{
1132 return -1;
1133}
1134
1135static inline int sm501_gpio_isregistered(struct sm501_devdata *sm)
1136{
1137 return 0;
1138}
1139#endif
1140
1141static int sm501_register_gpio_i2c_instance(struct sm501_devdata *sm,
1142 struct sm501_platdata_gpio_i2c *iic)
1143{
1144 struct i2c_gpio_platform_data *icd;
1145 struct platform_device *pdev;
1146
1147 pdev = sm501_create_subdev(sm, "i2c-gpio", 0,
1148 sizeof(struct i2c_gpio_platform_data));
1149 if (!pdev)
1150 return -ENOMEM;
1151
1152 icd = pdev->dev.platform_data;
1153
1154 /* We keep the pin_sda and pin_scl fields relative in case the
1155 * same platform data is passed to >1 SM501.
1156 */
1157
1158 icd->sda_pin = sm501_gpio_pin2nr(sm, iic->pin_sda);
1159 icd->scl_pin = sm501_gpio_pin2nr(sm, iic->pin_scl);
1160 icd->timeout = iic->timeout;
1161 icd->udelay = iic->udelay;
1162
1163 /* note, we can't use either of the pin numbers, as the i2c-gpio
1164 * driver uses the platform.id field to generate the bus number
1165 * to register with the i2c core; The i2c core doesn't have enough
1166 * entries to deal with anything we currently use.
1167 */
1168
1169 pdev->id = iic->bus_num;
1170
1171 dev_info(sm->dev, "registering i2c-%d: sda=%d (%d), scl=%d (%d)\n",
1172 iic->bus_num,
1173 icd->sda_pin, iic->pin_sda, icd->scl_pin, iic->pin_scl);
1174
1175 return sm501_register_device(sm, pdev);
1176}
1177
1178static int sm501_register_gpio_i2c(struct sm501_devdata *sm,
1179 struct sm501_platdata *pdata)
1180{
1181 struct sm501_platdata_gpio_i2c *iic = pdata->gpio_i2c;
1182 int index;
1183 int ret;
1184
1185 for (index = 0; index < pdata->gpio_i2c_nr; index++, iic++) {
1186 ret = sm501_register_gpio_i2c_instance(sm, iic);
1187 if (ret < 0)
1188 return ret;
1189 }
1190
1191 return 0;
1192}
1193
909/* sm501_dbg_regs 1194/* sm501_dbg_regs
910 * 1195 *
911 * Debug attribute to attach to parent device to show core registers 1196 * Debug attribute to attach to parent device to show core registers
@@ -1013,6 +1298,7 @@ static unsigned int sm501_mem_local[] = {
1013static int sm501_init_dev(struct sm501_devdata *sm) 1298static int sm501_init_dev(struct sm501_devdata *sm)
1014{ 1299{
1015 struct sm501_initdata *idata; 1300 struct sm501_initdata *idata;
1301 struct sm501_platdata *pdata;
1016 resource_size_t mem_avail; 1302 resource_size_t mem_avail;
1017 unsigned long dramctrl; 1303 unsigned long dramctrl;
1018 unsigned long devid; 1304 unsigned long devid;
@@ -1051,7 +1337,9 @@ static int sm501_init_dev(struct sm501_devdata *sm)
1051 1337
1052 /* check to see if we have some device initialisation */ 1338 /* check to see if we have some device initialisation */
1053 1339
1054 idata = sm->platdata ? sm->platdata->init : NULL; 1340 pdata = sm->platdata;
1341 idata = pdata ? pdata->init : NULL;
1342
1055 if (idata) { 1343 if (idata) {
1056 sm501_init_regs(sm, idata); 1344 sm501_init_regs(sm, idata);
1057 1345
@@ -1059,6 +1347,15 @@ static int sm501_init_dev(struct sm501_devdata *sm)
1059 sm501_register_usbhost(sm, &mem_avail); 1347 sm501_register_usbhost(sm, &mem_avail);
1060 if (idata->devices & (SM501_USE_UART0 | SM501_USE_UART1)) 1348 if (idata->devices & (SM501_USE_UART0 | SM501_USE_UART1))
1061 sm501_register_uart(sm, idata->devices); 1349 sm501_register_uart(sm, idata->devices);
1350 if (idata->devices & SM501_USE_GPIO)
1351 sm501_register_gpio(sm);
1352 }
1353
1354 if (pdata->gpio_i2c != NULL && pdata->gpio_i2c_nr > 0) {
1355 if (!sm501_gpio_isregistered(sm))
1356 dev_err(sm->dev, "no gpio available for i2c gpio.\n");
1357 else
1358 sm501_register_gpio_i2c(sm, pdata);
1062 } 1359 }
1063 1360
1064 ret = sm501_check_clocks(sm); 1361 ret = sm501_check_clocks(sm);
@@ -1138,8 +1435,31 @@ static int sm501_plat_probe(struct platform_device *dev)
1138} 1435}
1139 1436
1140#ifdef CONFIG_PM 1437#ifdef CONFIG_PM
1438
1141/* power management support */ 1439/* power management support */
1142 1440
1441static void sm501_set_power(struct sm501_devdata *sm, int on)
1442{
1443 struct sm501_platdata *pd = sm->platdata;
1444
1445 if (pd == NULL)
1446 return;
1447
1448 if (pd->get_power) {
1449 if (pd->get_power(sm->dev) == on) {
1450 dev_dbg(sm->dev, "is already %d\n", on);
1451 return;
1452 }
1453 }
1454
1455 if (pd->set_power) {
1456 dev_dbg(sm->dev, "setting power to %d\n", on);
1457
1458 pd->set_power(sm->dev, on);
1459 sm501_mdelay(sm, 10);
1460 }
1461}
1462
1143static int sm501_plat_suspend(struct platform_device *pdev, pm_message_t state) 1463static int sm501_plat_suspend(struct platform_device *pdev, pm_message_t state)
1144{ 1464{
1145 struct sm501_devdata *sm = platform_get_drvdata(pdev); 1465 struct sm501_devdata *sm = platform_get_drvdata(pdev);
@@ -1148,6 +1468,12 @@ static int sm501_plat_suspend(struct platform_device *pdev, pm_message_t state)
1148 sm->pm_misc = readl(sm->regs + SM501_MISC_CONTROL); 1468 sm->pm_misc = readl(sm->regs + SM501_MISC_CONTROL);
1149 1469
1150 sm501_dump_regs(sm); 1470 sm501_dump_regs(sm);
1471
1472 if (sm->platdata) {
1473 if (sm->platdata->flags & SM501_FLAG_SUSPEND_OFF)
1474 sm501_set_power(sm, 0);
1475 }
1476
1151 return 0; 1477 return 0;
1152} 1478}
1153 1479
@@ -1155,6 +1481,8 @@ static int sm501_plat_resume(struct platform_device *pdev)
1155{ 1481{
1156 struct sm501_devdata *sm = platform_get_drvdata(pdev); 1482 struct sm501_devdata *sm = platform_get_drvdata(pdev);
1157 1483
1484 sm501_set_power(sm, 1);
1485
1158 sm501_dump_regs(sm); 1486 sm501_dump_regs(sm);
1159 sm501_dump_gate(sm); 1487 sm501_dump_gate(sm);
1160 sm501_dump_clk(sm); 1488 sm501_dump_clk(sm);
@@ -1229,6 +1557,7 @@ static struct sm501_platdata_fb sm501_fb_pdata = {
1229static struct sm501_platdata sm501_pci_platdata = { 1557static struct sm501_platdata sm501_pci_platdata = {
1230 .init = &sm501_pci_initdata, 1558 .init = &sm501_pci_initdata,
1231 .fb = &sm501_fb_pdata, 1559 .fb = &sm501_fb_pdata,
1560 .gpio_base = -1,
1232}; 1561};
1233 1562
1234static int sm501_pci_probe(struct pci_dev *dev, 1563static int sm501_pci_probe(struct pci_dev *dev,
@@ -1335,6 +1664,8 @@ static void sm501_dev_remove(struct sm501_devdata *sm)
1335 sm501_remove_sub(sm, smdev); 1664 sm501_remove_sub(sm, smdev);
1336 1665
1337 device_remove_file(sm->dev, &dev_attr_dbg_regs); 1666 device_remove_file(sm->dev, &dev_attr_dbg_regs);
1667
1668 sm501_gpio_remove(sm);
1338} 1669}
1339 1670
1340static void sm501_pci_remove(struct pci_dev *dev) 1671static void sm501_pci_remove(struct pci_dev *dev)
@@ -1378,6 +1709,8 @@ static struct pci_driver sm501_pci_drv = {
1378 .remove = sm501_pci_remove, 1709 .remove = sm501_pci_remove,
1379}; 1710};
1380 1711
1712MODULE_ALIAS("platform:sm501");
1713
1381static struct platform_driver sm501_plat_drv = { 1714static struct platform_driver sm501_plat_drv = {
1382 .driver = { 1715 .driver = {
1383 .name = "sm501", 1716 .name = "sm501",
diff --git a/drivers/mfd/tc6393xb.c b/drivers/mfd/tc6393xb.c
new file mode 100644
index 000000000000..2d87501b6fd4
--- /dev/null
+++ b/drivers/mfd/tc6393xb.c
@@ -0,0 +1,600 @@
1/*
2 * Toshiba TC6393XB SoC support
3 *
4 * Copyright(c) 2005-2006 Chris Humbert
5 * Copyright(c) 2005 Dirk Opfer
6 * Copyright(c) 2005 Ian Molton <spyro@f2s.com>
7 * Copyright(c) 2007 Dmitry Baryshkov
8 *
9 * Based on code written by Sharp/Lineo for 2.4 kernels
10 * Based on locomo.c
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/io.h>
20#include <linux/irq.h>
21#include <linux/platform_device.h>
22#include <linux/fb.h>
23#include <linux/clk.h>
24#include <linux/mfd/core.h>
25#include <linux/mfd/tmio.h>
26#include <linux/mfd/tc6393xb.h>
27#include <linux/gpio.h>
28
29#define SCR_REVID 0x08 /* b Revision ID */
30#define SCR_ISR 0x50 /* b Interrupt Status */
31#define SCR_IMR 0x52 /* b Interrupt Mask */
32#define SCR_IRR 0x54 /* b Interrupt Routing */
33#define SCR_GPER 0x60 /* w GP Enable */
34#define SCR_GPI_SR(i) (0x64 + (i)) /* b3 GPI Status */
35#define SCR_GPI_IMR(i) (0x68 + (i)) /* b3 GPI INT Mask */
36#define SCR_GPI_EDER(i) (0x6c + (i)) /* b3 GPI Edge Detect Enable */
37#define SCR_GPI_LIR(i) (0x70 + (i)) /* b3 GPI Level Invert */
38#define SCR_GPO_DSR(i) (0x78 + (i)) /* b3 GPO Data Set */
39#define SCR_GPO_DOECR(i) (0x7c + (i)) /* b3 GPO Data OE Control */
40#define SCR_GP_IARCR(i) (0x80 + (i)) /* b3 GP Internal Active Register Control */
41#define SCR_GP_IARLCR(i) (0x84 + (i)) /* b3 GP INTERNAL Active Register Level Control */
42#define SCR_GPI_BCR(i) (0x88 + (i)) /* b3 GPI Buffer Control */
43#define SCR_GPA_IARCR 0x8c /* w GPa Internal Active Register Control */
44#define SCR_GPA_IARLCR 0x90 /* w GPa Internal Active Register Level Control */
45#define SCR_GPA_BCR 0x94 /* w GPa Buffer Control */
46#define SCR_CCR 0x98 /* w Clock Control */
47#define SCR_PLL2CR 0x9a /* w PLL2 Control */
48#define SCR_PLL1CR 0x9c /* l PLL1 Control */
49#define SCR_DIARCR 0xa0 /* b Device Internal Active Register Control */
50#define SCR_DBOCR 0xa1 /* b Device Buffer Off Control */
51#define SCR_FER 0xe0 /* b Function Enable */
52#define SCR_MCR 0xe4 /* w Mode Control */
53#define SCR_CONFIG 0xfc /* b Configuration Control */
54#define SCR_DEBUG 0xff /* b Debug */
55
56#define SCR_CCR_CK32K BIT(0)
57#define SCR_CCR_USBCK BIT(1)
58#define SCR_CCR_UNK1 BIT(4)
59#define SCR_CCR_MCLK_MASK (7 << 8)
60#define SCR_CCR_MCLK_OFF (0 << 8)
61#define SCR_CCR_MCLK_12 (1 << 8)
62#define SCR_CCR_MCLK_24 (2 << 8)
63#define SCR_CCR_MCLK_48 (3 << 8)
64#define SCR_CCR_HCLK_MASK (3 << 12)
65#define SCR_CCR_HCLK_24 (0 << 12)
66#define SCR_CCR_HCLK_48 (1 << 12)
67
68#define SCR_FER_USBEN BIT(0) /* USB host enable */
69#define SCR_FER_LCDCVEN BIT(1) /* polysilicon TFT enable */
70#define SCR_FER_SLCDEN BIT(2) /* SLCD enable */
71
72#define SCR_MCR_RDY_MASK (3 << 0)
73#define SCR_MCR_RDY_OPENDRAIN (0 << 0)
74#define SCR_MCR_RDY_TRISTATE (1 << 0)
75#define SCR_MCR_RDY_PUSHPULL (2 << 0)
76#define SCR_MCR_RDY_UNK BIT(2)
77#define SCR_MCR_RDY_EN BIT(3)
78#define SCR_MCR_INT_MASK (3 << 4)
79#define SCR_MCR_INT_OPENDRAIN (0 << 4)
80#define SCR_MCR_INT_TRISTATE (1 << 4)
81#define SCR_MCR_INT_PUSHPULL (2 << 4)
82#define SCR_MCR_INT_UNK BIT(6)
83#define SCR_MCR_INT_EN BIT(7)
84/* bits 8 - 16 are unknown */
85
86#define TC_GPIO_BIT(i) (1 << (i & 0x7))
87
88/*--------------------------------------------------------------------------*/
89
90struct tc6393xb {
91 void __iomem *scr;
92
93 struct gpio_chip gpio;
94
95 struct clk *clk; /* 3,6 Mhz */
96
97 spinlock_t lock; /* protects RMW cycles */
98
99 struct {
100 u8 fer;
101 u16 ccr;
102 u8 gpi_bcr[3];
103 u8 gpo_dsr[3];
104 u8 gpo_doecr[3];
105 } suspend_state;
106
107 struct resource rscr;
108 struct resource *iomem;
109 int irq;
110 int irq_base;
111};
112
113enum {
114 TC6393XB_CELL_NAND,
115};
116
117/*--------------------------------------------------------------------------*/
118
119static int tc6393xb_nand_enable(struct platform_device *nand)
120{
121 struct platform_device *dev = to_platform_device(nand->dev.parent);
122 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
123 unsigned long flags;
124
125 spin_lock_irqsave(&tc6393xb->lock, flags);
126
127 /* SMD buffer on */
128 dev_dbg(&dev->dev, "SMD buffer on\n");
129 iowrite8(0xff, tc6393xb->scr + SCR_GPI_BCR(1));
130
131 spin_unlock_irqrestore(&tc6393xb->lock, flags);
132
133 return 0;
134}
135
136static struct resource __devinitdata tc6393xb_nand_resources[] = {
137 {
138 .name = TMIO_NAND_CONFIG,
139 .start = 0x0100,
140 .end = 0x01ff,
141 .flags = IORESOURCE_MEM,
142 },
143 {
144 .name = TMIO_NAND_CONTROL,
145 .start = 0x1000,
146 .end = 0x1007,
147 .flags = IORESOURCE_MEM,
148 },
149 {
150 .name = TMIO_NAND_IRQ,
151 .start = IRQ_TC6393_NAND,
152 .end = IRQ_TC6393_NAND,
153 .flags = IORESOURCE_IRQ,
154 },
155};
156
157static struct mfd_cell __devinitdata tc6393xb_cells[] = {
158 [TC6393XB_CELL_NAND] = {
159 .name = "tmio-nand",
160 .enable = tc6393xb_nand_enable,
161 .num_resources = ARRAY_SIZE(tc6393xb_nand_resources),
162 .resources = tc6393xb_nand_resources,
163 },
164};
165
166/*--------------------------------------------------------------------------*/
167
168static int tc6393xb_gpio_get(struct gpio_chip *chip,
169 unsigned offset)
170{
171 struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
172
173 /* XXX: does dsr also represent inputs? */
174 return ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8))
175 & TC_GPIO_BIT(offset);
176}
177
178static void __tc6393xb_gpio_set(struct gpio_chip *chip,
179 unsigned offset, int value)
180{
181 struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
182 u8 dsr;
183
184 dsr = ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8));
185 if (value)
186 dsr |= TC_GPIO_BIT(offset);
187 else
188 dsr &= ~TC_GPIO_BIT(offset);
189
190 iowrite8(dsr, tc6393xb->scr + SCR_GPO_DSR(offset / 8));
191}
192
193static void tc6393xb_gpio_set(struct gpio_chip *chip,
194 unsigned offset, int value)
195{
196 struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
197 unsigned long flags;
198
199 spin_lock_irqsave(&tc6393xb->lock, flags);
200
201 __tc6393xb_gpio_set(chip, offset, value);
202
203 spin_unlock_irqrestore(&tc6393xb->lock, flags);
204}
205
206static int tc6393xb_gpio_direction_input(struct gpio_chip *chip,
207 unsigned offset)
208{
209 struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
210 unsigned long flags;
211 u8 doecr;
212
213 spin_lock_irqsave(&tc6393xb->lock, flags);
214
215 doecr = ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
216 doecr &= ~TC_GPIO_BIT(offset);
217 iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
218
219 spin_unlock_irqrestore(&tc6393xb->lock, flags);
220
221 return 0;
222}
223
224static int tc6393xb_gpio_direction_output(struct gpio_chip *chip,
225 unsigned offset, int value)
226{
227 struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
228 unsigned long flags;
229 u8 doecr;
230
231 spin_lock_irqsave(&tc6393xb->lock, flags);
232
233 __tc6393xb_gpio_set(chip, offset, value);
234
235 doecr = ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
236 doecr |= TC_GPIO_BIT(offset);
237 iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
238
239 spin_unlock_irqrestore(&tc6393xb->lock, flags);
240
241 return 0;
242}
243
244static int tc6393xb_register_gpio(struct tc6393xb *tc6393xb, int gpio_base)
245{
246 tc6393xb->gpio.label = "tc6393xb";
247 tc6393xb->gpio.base = gpio_base;
248 tc6393xb->gpio.ngpio = 16;
249 tc6393xb->gpio.set = tc6393xb_gpio_set;
250 tc6393xb->gpio.get = tc6393xb_gpio_get;
251 tc6393xb->gpio.direction_input = tc6393xb_gpio_direction_input;
252 tc6393xb->gpio.direction_output = tc6393xb_gpio_direction_output;
253
254 return gpiochip_add(&tc6393xb->gpio);
255}
256
257/*--------------------------------------------------------------------------*/
258
259static void
260tc6393xb_irq(unsigned int irq, struct irq_desc *desc)
261{
262 struct tc6393xb *tc6393xb = get_irq_data(irq);
263 unsigned int isr;
264 unsigned int i, irq_base;
265
266 irq_base = tc6393xb->irq_base;
267
268 while ((isr = ioread8(tc6393xb->scr + SCR_ISR) &
269 ~ioread8(tc6393xb->scr + SCR_IMR)))
270 for (i = 0; i < TC6393XB_NR_IRQS; i++) {
271 if (isr & (1 << i))
272 generic_handle_irq(irq_base + i);
273 }
274}
275
276static void tc6393xb_irq_ack(unsigned int irq)
277{
278}
279
280static void tc6393xb_irq_mask(unsigned int irq)
281{
282 struct tc6393xb *tc6393xb = get_irq_chip_data(irq);
283 unsigned long flags;
284 u8 imr;
285
286 spin_lock_irqsave(&tc6393xb->lock, flags);
287 imr = ioread8(tc6393xb->scr + SCR_IMR);
288 imr |= 1 << (irq - tc6393xb->irq_base);
289 iowrite8(imr, tc6393xb->scr + SCR_IMR);
290 spin_unlock_irqrestore(&tc6393xb->lock, flags);
291}
292
293static void tc6393xb_irq_unmask(unsigned int irq)
294{
295 struct tc6393xb *tc6393xb = get_irq_chip_data(irq);
296 unsigned long flags;
297 u8 imr;
298
299 spin_lock_irqsave(&tc6393xb->lock, flags);
300 imr = ioread8(tc6393xb->scr + SCR_IMR);
301 imr &= ~(1 << (irq - tc6393xb->irq_base));
302 iowrite8(imr, tc6393xb->scr + SCR_IMR);
303 spin_unlock_irqrestore(&tc6393xb->lock, flags);
304}
305
306static struct irq_chip tc6393xb_chip = {
307 .name = "tc6393xb",
308 .ack = tc6393xb_irq_ack,
309 .mask = tc6393xb_irq_mask,
310 .unmask = tc6393xb_irq_unmask,
311};
312
313static void tc6393xb_attach_irq(struct platform_device *dev)
314{
315 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
316 unsigned int irq, irq_base;
317
318 irq_base = tc6393xb->irq_base;
319
320 for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
321 set_irq_chip(irq, &tc6393xb_chip);
322 set_irq_chip_data(irq, tc6393xb);
323 set_irq_handler(irq, handle_edge_irq);
324 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
325 }
326
327 set_irq_type(tc6393xb->irq, IRQT_FALLING);
328 set_irq_data(tc6393xb->irq, tc6393xb);
329 set_irq_chained_handler(tc6393xb->irq, tc6393xb_irq);
330}
331
332static void tc6393xb_detach_irq(struct platform_device *dev)
333{
334 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
335 unsigned int irq, irq_base;
336
337 set_irq_chained_handler(tc6393xb->irq, NULL);
338 set_irq_data(tc6393xb->irq, NULL);
339
340 irq_base = tc6393xb->irq_base;
341
342 for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
343 set_irq_flags(irq, 0);
344 set_irq_chip(irq, NULL);
345 set_irq_chip_data(irq, NULL);
346 }
347}
348
349/*--------------------------------------------------------------------------*/
350
351static int tc6393xb_hw_init(struct platform_device *dev)
352{
353 struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
354 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
355 int i;
356
357 iowrite8(tc6393xb->suspend_state.fer, tc6393xb->scr + SCR_FER);
358 iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
359 iowrite16(tc6393xb->suspend_state.ccr, tc6393xb->scr + SCR_CCR);
360 iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
361 SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
362 BIT(15), tc6393xb->scr + SCR_MCR);
363 iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
364 iowrite8(0, tc6393xb->scr + SCR_IRR);
365 iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
366
367 for (i = 0; i < 3; i++) {
368 iowrite8(tc6393xb->suspend_state.gpo_dsr[i],
369 tc6393xb->scr + SCR_GPO_DSR(i));
370 iowrite8(tc6393xb->suspend_state.gpo_doecr[i],
371 tc6393xb->scr + SCR_GPO_DOECR(i));
372 iowrite8(tc6393xb->suspend_state.gpi_bcr[i],
373 tc6393xb->scr + SCR_GPI_BCR(i));
374 }
375
376 return 0;
377}
378
379static int __devinit tc6393xb_probe(struct platform_device *dev)
380{
381 struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
382 struct tc6393xb *tc6393xb;
383 struct resource *iomem;
384 struct resource *rscr;
385 int retval, temp;
386 int i;
387
388 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
389 if (!iomem)
390 return -EINVAL;
391
392 tc6393xb = kzalloc(sizeof *tc6393xb, GFP_KERNEL);
393 if (!tc6393xb) {
394 retval = -ENOMEM;
395 goto err_kzalloc;
396 }
397
398 spin_lock_init(&tc6393xb->lock);
399
400 platform_set_drvdata(dev, tc6393xb);
401 tc6393xb->iomem = iomem;
402 tc6393xb->irq = platform_get_irq(dev, 0);
403 tc6393xb->irq_base = tcpd->irq_base;
404
405 tc6393xb->clk = clk_get(&dev->dev, "GPIO27_CLK" /* "CK3P6MI" */);
406 if (IS_ERR(tc6393xb->clk)) {
407 retval = PTR_ERR(tc6393xb->clk);
408 goto err_clk_get;
409 }
410
411 rscr = &tc6393xb->rscr;
412 rscr->name = "tc6393xb-core";
413 rscr->start = iomem->start;
414 rscr->end = iomem->start + 0xff;
415 rscr->flags = IORESOURCE_MEM;
416
417 retval = request_resource(iomem, rscr);
418 if (retval)
419 goto err_request_scr;
420
421 tc6393xb->scr = ioremap(rscr->start, rscr->end - rscr->start + 1);
422 if (!tc6393xb->scr) {
423 retval = -ENOMEM;
424 goto err_ioremap;
425 }
426
427 retval = clk_enable(tc6393xb->clk);
428 if (retval)
429 goto err_clk_enable;
430
431 retval = tcpd->enable(dev);
432 if (retval)
433 goto err_enable;
434
435 tc6393xb->suspend_state.fer = 0;
436 for (i = 0; i < 3; i++) {
437 tc6393xb->suspend_state.gpo_dsr[i] =
438 (tcpd->scr_gpo_dsr >> (8 * i)) & 0xff;
439 tc6393xb->suspend_state.gpo_doecr[i] =
440 (tcpd->scr_gpo_doecr >> (8 * i)) & 0xff;
441 }
442 /*
443 * It may be necessary to change this back to
444 * platform-dependant code
445 */
446 tc6393xb->suspend_state.ccr = SCR_CCR_UNK1 |
447 SCR_CCR_HCLK_48;
448
449 retval = tc6393xb_hw_init(dev);
450 if (retval)
451 goto err_hw_init;
452
453 printk(KERN_INFO "Toshiba tc6393xb revision %d at 0x%08lx, irq %d\n",
454 ioread8(tc6393xb->scr + SCR_REVID),
455 (unsigned long) iomem->start, tc6393xb->irq);
456
457 tc6393xb->gpio.base = -1;
458
459 if (tcpd->gpio_base >= 0) {
460 retval = tc6393xb_register_gpio(tc6393xb, tcpd->gpio_base);
461 if (retval)
462 goto err_gpio_add;
463 }
464
465 if (tc6393xb->irq)
466 tc6393xb_attach_irq(dev);
467
468 tc6393xb_cells[TC6393XB_CELL_NAND].driver_data = tcpd->nand_data;
469
470 retval = mfd_add_devices(dev,
471 tc6393xb_cells, ARRAY_SIZE(tc6393xb_cells),
472 iomem, tcpd->irq_base);
473
474 return 0;
475
476 if (tc6393xb->irq)
477 tc6393xb_detach_irq(dev);
478
479err_gpio_add:
480 if (tc6393xb->gpio.base != -1)
481 temp = gpiochip_remove(&tc6393xb->gpio);
482err_hw_init:
483 tcpd->disable(dev);
484err_clk_enable:
485 clk_disable(tc6393xb->clk);
486err_enable:
487 iounmap(tc6393xb->scr);
488err_ioremap:
489 release_resource(&tc6393xb->rscr);
490err_request_scr:
491 clk_put(tc6393xb->clk);
492err_clk_get:
493 kfree(tc6393xb);
494err_kzalloc:
495 return retval;
496}
497
498static int __devexit tc6393xb_remove(struct platform_device *dev)
499{
500 struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
501 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
502 int ret;
503
504 mfd_remove_devices(dev);
505
506 if (tc6393xb->irq)
507 tc6393xb_detach_irq(dev);
508
509 if (tc6393xb->gpio.base != -1) {
510 ret = gpiochip_remove(&tc6393xb->gpio);
511 if (ret) {
512 dev_err(&dev->dev, "Can't remove gpio chip: %d\n", ret);
513 return ret;
514 }
515 }
516
517 ret = tcpd->disable(dev);
518
519 clk_disable(tc6393xb->clk);
520
521 iounmap(tc6393xb->scr);
522
523 release_resource(&tc6393xb->rscr);
524
525 platform_set_drvdata(dev, NULL);
526
527 clk_put(tc6393xb->clk);
528
529 kfree(tc6393xb);
530
531 return ret;
532}
533
534#ifdef CONFIG_PM
535static int tc6393xb_suspend(struct platform_device *dev, pm_message_t state)
536{
537 struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
538 struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
539 int i;
540
541
542 tc6393xb->suspend_state.ccr = ioread16(tc6393xb->scr + SCR_CCR);
543 tc6393xb->suspend_state.fer = ioread8(tc6393xb->scr + SCR_FER);
544
545 for (i = 0; i < 3; i++) {
546 tc6393xb->suspend_state.gpo_dsr[i] =
547 ioread8(tc6393xb->scr + SCR_GPO_DSR(i));
548 tc6393xb->suspend_state.gpo_doecr[i] =
549 ioread8(tc6393xb->scr + SCR_GPO_DOECR(i));
550 tc6393xb->suspend_state.gpi_bcr[i] =
551 ioread8(tc6393xb->scr + SCR_GPI_BCR(i));
552 }
553
554 return tcpd->suspend(dev);
555}
556
557static int tc6393xb_resume(struct platform_device *dev)
558{
559 struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
560 int ret = tcpd->resume(dev);
561
562 if (ret)
563 return ret;
564
565 return tc6393xb_hw_init(dev);
566}
567#else
568#define tc6393xb_suspend NULL
569#define tc6393xb_resume NULL
570#endif
571
572static struct platform_driver tc6393xb_driver = {
573 .probe = tc6393xb_probe,
574 .remove = __devexit_p(tc6393xb_remove),
575 .suspend = tc6393xb_suspend,
576 .resume = tc6393xb_resume,
577
578 .driver = {
579 .name = "tc6393xb",
580 .owner = THIS_MODULE,
581 },
582};
583
584static int __init tc6393xb_init(void)
585{
586 return platform_driver_register(&tc6393xb_driver);
587}
588
589static void __exit tc6393xb_exit(void)
590{
591 platform_driver_unregister(&tc6393xb_driver);
592}
593
594subsys_initcall(tc6393xb_init);
595module_exit(tc6393xb_exit);
596
597MODULE_LICENSE("GPL");
598MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov and Dirk Opfer");
599MODULE_DESCRIPTION("tc6393xb Toshiba Mobile IO Controller");
600MODULE_ALIAS("platform:tc6393xb");
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index ce67d973d349..321eb9134635 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -77,11 +77,13 @@ config IBM_ASM
77 for your IBM server. 77 for your IBM server.
78 78
79config PHANTOM 79config PHANTOM
80 tristate "Sensable PHANToM" 80 tristate "Sensable PHANToM (PCI)"
81 depends on PCI 81 depends on PCI
82 help 82 help
83 Say Y here if you want to build a driver for Sensable PHANToM device. 83 Say Y here if you want to build a driver for Sensable PHANToM device.
84 84
85 This driver is only for PCI PHANToMs.
86
85 If you choose to build module, its name will be phantom. If unsure, 87 If you choose to build module, its name will be phantom. If unsure,
86 say N here. 88 say N here.
87 89
@@ -212,6 +214,18 @@ config TC1100_WMI
212 This is a driver for the WMI extensions (wireless and bluetooth power 214 This is a driver for the WMI extensions (wireless and bluetooth power
213 control) of the HP Compaq TC1100 tablet. 215 control) of the HP Compaq TC1100 tablet.
214 216
217config HP_WMI
218 tristate "HP WMI extras"
219 depends on ACPI_WMI
220 depends on INPUT
221 depends on RFKILL
222 help
223 Say Y here if you want to support WMI-based hotkeys on HP laptops and
224 to read data from WMI such as docking or ambient light sensor state.
225
226 To compile this driver as a module, choose M here: the module will
227 be called hp-wmi.
228
215config MSI_LAPTOP 229config MSI_LAPTOP
216 tristate "MSI Laptop Extras" 230 tristate "MSI Laptop Extras"
217 depends on X86 231 depends on X86
@@ -279,6 +293,8 @@ config THINKPAD_ACPI
279 select INPUT 293 select INPUT
280 select NEW_LEDS 294 select NEW_LEDS
281 select LEDS_CLASS 295 select LEDS_CLASS
296 select NET
297 select RFKILL
282 ---help--- 298 ---help---
283 This is a driver for the IBM and Lenovo ThinkPad laptops. It adds 299 This is a driver for the IBM and Lenovo ThinkPad laptops. It adds
284 support for Fn-Fx key combinations, Bluetooth control, video 300 support for Fn-Fx key combinations, Bluetooth control, video
@@ -422,6 +438,7 @@ config SGI_XP
422 438
423config HP_ILO 439config HP_ILO
424 tristate "Channel interface driver for HP iLO/iLO2 processor" 440 tristate "Channel interface driver for HP iLO/iLO2 processor"
441 depends on PCI
425 default n 442 default n
426 help 443 help
427 The channel interface driver allows applications to communicate 444 The channel interface driver allows applications to communicate
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 688fe76135e0..f5e273420c09 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_ACER_WMI) += acer-wmi.o
13obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o 13obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o
14obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o 14obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o
15obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o 15obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o
16obj-$(CONFIG_HP_WMI) += hp-wmi.o
16obj-$(CONFIG_TC1100_WMI) += tc1100-wmi.o 17obj-$(CONFIG_TC1100_WMI) += tc1100-wmi.o
17obj-$(CONFIG_LKDTM) += lkdtm.o 18obj-$(CONFIG_LKDTM) += lkdtm.o
18obj-$(CONFIG_TIFM_CORE) += tifm_core.o 19obj-$(CONFIG_TIFM_CORE) += tifm_core.o
diff --git a/drivers/misc/atmel_pwm.c b/drivers/misc/atmel_pwm.c
index 5b5a14dab3d3..6aa5294dfec4 100644
--- a/drivers/misc/atmel_pwm.c
+++ b/drivers/misc/atmel_pwm.c
@@ -211,8 +211,7 @@ int pwm_clk_alloc(unsigned prescale, unsigned div)
211 if ((mr & 0xffff) == 0) { 211 if ((mr & 0xffff) == 0) {
212 mr |= val; 212 mr |= val;
213 ret = PWM_CPR_CLKA; 213 ret = PWM_CPR_CLKA;
214 } 214 } else if ((mr & (0xffff << 16)) == 0) {
215 if ((mr & (0xffff << 16)) == 0) {
216 mr |= val << 16; 215 mr |= val << 16;
217 ret = PWM_CPR_CLKB; 216 ret = PWM_CPR_CLKB;
218 } 217 }
diff --git a/drivers/misc/hp-wmi.c b/drivers/misc/hp-wmi.c
new file mode 100644
index 000000000000..1dbcbcb323a2
--- /dev/null
+++ b/drivers/misc/hp-wmi.c
@@ -0,0 +1,494 @@
1/*
2 * HP WMI hotkeys
3 *
4 * Copyright (C) 2008 Red Hat <mjg@redhat.com>
5 *
6 * Portions based on wistron_btns.c:
7 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
8 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
9 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/types.h>
30#include <linux/input.h>
31#include <acpi/acpi_drivers.h>
32#include <linux/platform_device.h>
33#include <linux/acpi.h>
34#include <linux/rfkill.h>
35#include <linux/string.h>
36
37MODULE_AUTHOR("Matthew Garrett <mjg59@srcf.ucam.org>");
38MODULE_DESCRIPTION("HP laptop WMI hotkeys driver");
39MODULE_LICENSE("GPL");
40
41MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C");
42MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4");
43
44#define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C"
45#define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4"
46
47#define HPWMI_DISPLAY_QUERY 0x1
48#define HPWMI_HDDTEMP_QUERY 0x2
49#define HPWMI_ALS_QUERY 0x3
50#define HPWMI_DOCK_QUERY 0x4
51#define HPWMI_WIRELESS_QUERY 0x5
52
53static int __init hp_wmi_bios_setup(struct platform_device *device);
54static int __exit hp_wmi_bios_remove(struct platform_device *device);
55
56struct bios_args {
57 u32 signature;
58 u32 command;
59 u32 commandtype;
60 u32 datasize;
61 u32 data;
62};
63
64struct bios_return {
65 u32 sigpass;
66 u32 return_code;
67 u32 value;
68};
69
70struct key_entry {
71 char type; /* See KE_* below */
72 u8 code;
73 u16 keycode;
74};
75
76enum { KE_KEY, KE_SW, KE_END };
77
78static struct key_entry hp_wmi_keymap[] = {
79 {KE_SW, 0x01, SW_DOCK},
80 {KE_KEY, 0x02, KEY_BRIGHTNESSUP},
81 {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN},
82 {KE_KEY, 0x04, KEY_HELP},
83 {KE_END, 0}
84};
85
86static struct input_dev *hp_wmi_input_dev;
87static struct platform_device *hp_wmi_platform_dev;
88
89static struct rfkill *wifi_rfkill;
90static struct rfkill *bluetooth_rfkill;
91static struct rfkill *wwan_rfkill;
92
93static struct platform_driver hp_wmi_driver = {
94 .driver = {
95 .name = "hp-wmi",
96 .owner = THIS_MODULE,
97 },
98 .probe = hp_wmi_bios_setup,
99 .remove = hp_wmi_bios_remove,
100};
101
102static int hp_wmi_perform_query(int query, int write, int value)
103{
104 struct bios_return bios_return;
105 acpi_status status;
106 union acpi_object *obj;
107 struct bios_args args = {
108 .signature = 0x55434553,
109 .command = write ? 0x2 : 0x1,
110 .commandtype = query,
111 .datasize = write ? 0x4 : 0,
112 .data = value,
113 };
114 struct acpi_buffer input = { sizeof(struct bios_args), &args };
115 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
116
117 status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output);
118
119 obj = output.pointer;
120
121 if (!obj || obj->type != ACPI_TYPE_BUFFER)
122 return -EINVAL;
123
124 bios_return = *((struct bios_return *)obj->buffer.pointer);
125 if (bios_return.return_code > 0)
126 return bios_return.return_code * -1;
127 else
128 return bios_return.value;
129}
130
131static int hp_wmi_display_state(void)
132{
133 return hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, 0);
134}
135
136static int hp_wmi_hddtemp_state(void)
137{
138 return hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, 0);
139}
140
141static int hp_wmi_als_state(void)
142{
143 return hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, 0);
144}
145
146static int hp_wmi_dock_state(void)
147{
148 return hp_wmi_perform_query(HPWMI_DOCK_QUERY, 0, 0);
149}
150
151static int hp_wmi_wifi_set(void *data, enum rfkill_state state)
152{
153 if (state)
154 return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x101);
155 else
156 return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x100);
157}
158
159static int hp_wmi_bluetooth_set(void *data, enum rfkill_state state)
160{
161 if (state)
162 return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x202);
163 else
164 return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x200);
165}
166
167static int hp_wmi_wwan_set(void *data, enum rfkill_state state)
168{
169 if (state)
170 return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x404);
171 else
172 return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x400);
173}
174
175static int hp_wmi_wifi_state(void)
176{
177 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
178
179 if (wireless & 0x100)
180 return 1;
181 else
182 return 0;
183}
184
185static int hp_wmi_bluetooth_state(void)
186{
187 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
188
189 if (wireless & 0x10000)
190 return 1;
191 else
192 return 0;
193}
194
195static int hp_wmi_wwan_state(void)
196{
197 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
198
199 if (wireless & 0x1000000)
200 return 1;
201 else
202 return 0;
203}
204
205static ssize_t show_display(struct device *dev, struct device_attribute *attr,
206 char *buf)
207{
208 int value = hp_wmi_display_state();
209 if (value < 0)
210 return -EINVAL;
211 return sprintf(buf, "%d\n", value);
212}
213
214static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr,
215 char *buf)
216{
217 int value = hp_wmi_hddtemp_state();
218 if (value < 0)
219 return -EINVAL;
220 return sprintf(buf, "%d\n", value);
221}
222
223static ssize_t show_als(struct device *dev, struct device_attribute *attr,
224 char *buf)
225{
226 int value = hp_wmi_als_state();
227 if (value < 0)
228 return -EINVAL;
229 return sprintf(buf, "%d\n", value);
230}
231
232static ssize_t show_dock(struct device *dev, struct device_attribute *attr,
233 char *buf)
234{
235 int value = hp_wmi_dock_state();
236 if (value < 0)
237 return -EINVAL;
238 return sprintf(buf, "%d\n", value);
239}
240
241static ssize_t set_als(struct device *dev, struct device_attribute *attr,
242 const char *buf, size_t count)
243{
244 u32 tmp = simple_strtoul(buf, NULL, 10);
245 hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, tmp);
246 return count;
247}
248
249static DEVICE_ATTR(display, S_IRUGO, show_display, NULL);
250static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL);
251static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
252static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
253
254static struct key_entry *hp_wmi_get_entry_by_scancode(int code)
255{
256 struct key_entry *key;
257
258 for (key = hp_wmi_keymap; key->type != KE_END; key++)
259 if (code == key->code)
260 return key;
261
262 return NULL;
263}
264
265static struct key_entry *hp_wmi_get_entry_by_keycode(int keycode)
266{
267 struct key_entry *key;
268
269 for (key = hp_wmi_keymap; key->type != KE_END; key++)
270 if (key->type == KE_KEY && keycode == key->keycode)
271 return key;
272
273 return NULL;
274}
275
276static int hp_wmi_getkeycode(struct input_dev *dev, int scancode, int *keycode)
277{
278 struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode);
279
280 if (key && key->type == KE_KEY) {
281 *keycode = key->keycode;
282 return 0;
283 }
284
285 return -EINVAL;
286}
287
288static int hp_wmi_setkeycode(struct input_dev *dev, int scancode, int keycode)
289{
290 struct key_entry *key;
291 int old_keycode;
292
293 if (keycode < 0 || keycode > KEY_MAX)
294 return -EINVAL;
295
296 key = hp_wmi_get_entry_by_scancode(scancode);
297 if (key && key->type == KE_KEY) {
298 old_keycode = key->keycode;
299 key->keycode = keycode;
300 set_bit(keycode, dev->keybit);
301 if (!hp_wmi_get_entry_by_keycode(old_keycode))
302 clear_bit(old_keycode, dev->keybit);
303 return 0;
304 }
305
306 return -EINVAL;
307}
308
309void hp_wmi_notify(u32 value, void *context)
310{
311 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
312 static struct key_entry *key;
313 union acpi_object *obj;
314
315 wmi_get_event_data(value, &response);
316
317 obj = (union acpi_object *)response.pointer;
318
319 if (obj && obj->type == ACPI_TYPE_BUFFER && obj->buffer.length == 8) {
320 int eventcode = *((u8 *) obj->buffer.pointer);
321 key = hp_wmi_get_entry_by_scancode(eventcode);
322 if (key) {
323 switch (key->type) {
324 case KE_KEY:
325 input_report_key(hp_wmi_input_dev,
326 key->keycode, 1);
327 input_sync(hp_wmi_input_dev);
328 input_report_key(hp_wmi_input_dev,
329 key->keycode, 0);
330 input_sync(hp_wmi_input_dev);
331 break;
332 case KE_SW:
333 input_report_switch(hp_wmi_input_dev,
334 key->keycode,
335 hp_wmi_dock_state());
336 input_sync(hp_wmi_input_dev);
337 break;
338 }
339 } else if (eventcode == 0x5) {
340 if (wifi_rfkill)
341 wifi_rfkill->state = hp_wmi_wifi_state();
342 if (bluetooth_rfkill)
343 bluetooth_rfkill->state =
344 hp_wmi_bluetooth_state();
345 if (wwan_rfkill)
346 wwan_rfkill->state = hp_wmi_wwan_state();
347 } else
348 printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n",
349 eventcode);
350 } else
351 printk(KERN_INFO "HP WMI: Unknown response received\n");
352}
353
354static int __init hp_wmi_input_setup(void)
355{
356 struct key_entry *key;
357 int err;
358
359 hp_wmi_input_dev = input_allocate_device();
360
361 hp_wmi_input_dev->name = "HP WMI hotkeys";
362 hp_wmi_input_dev->phys = "wmi/input0";
363 hp_wmi_input_dev->id.bustype = BUS_HOST;
364 hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode;
365 hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode;
366
367 for (key = hp_wmi_keymap; key->type != KE_END; key++) {
368 switch (key->type) {
369 case KE_KEY:
370 set_bit(EV_KEY, hp_wmi_input_dev->evbit);
371 set_bit(key->keycode, hp_wmi_input_dev->keybit);
372 break;
373 case KE_SW:
374 set_bit(EV_SW, hp_wmi_input_dev->evbit);
375 set_bit(key->keycode, hp_wmi_input_dev->swbit);
376 break;
377 }
378 }
379
380 err = input_register_device(hp_wmi_input_dev);
381
382 if (err) {
383 input_free_device(hp_wmi_input_dev);
384 return err;
385 }
386
387 return 0;
388}
389
390static void cleanup_sysfs(struct platform_device *device)
391{
392 device_remove_file(&device->dev, &dev_attr_display);
393 device_remove_file(&device->dev, &dev_attr_hddtemp);
394 device_remove_file(&device->dev, &dev_attr_als);
395 device_remove_file(&device->dev, &dev_attr_dock);
396}
397
398static int __init hp_wmi_bios_setup(struct platform_device *device)
399{
400 int err;
401
402 err = device_create_file(&device->dev, &dev_attr_display);
403 if (err)
404 goto add_sysfs_error;
405 err = device_create_file(&device->dev, &dev_attr_hddtemp);
406 if (err)
407 goto add_sysfs_error;
408 err = device_create_file(&device->dev, &dev_attr_als);
409 if (err)
410 goto add_sysfs_error;
411 err = device_create_file(&device->dev, &dev_attr_dock);
412 if (err)
413 goto add_sysfs_error;
414
415 wifi_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WLAN);
416 wifi_rfkill->name = "hp-wifi";
417 wifi_rfkill->state = hp_wmi_wifi_state();
418 wifi_rfkill->toggle_radio = hp_wmi_wifi_set;
419 wifi_rfkill->user_claim_unsupported = 1;
420
421 bluetooth_rfkill = rfkill_allocate(&device->dev,
422 RFKILL_TYPE_BLUETOOTH);
423 bluetooth_rfkill->name = "hp-bluetooth";
424 bluetooth_rfkill->state = hp_wmi_bluetooth_state();
425 bluetooth_rfkill->toggle_radio = hp_wmi_bluetooth_set;
426 bluetooth_rfkill->user_claim_unsupported = 1;
427
428 wwan_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WIMAX);
429 wwan_rfkill->name = "hp-wwan";
430 wwan_rfkill->state = hp_wmi_wwan_state();
431 wwan_rfkill->toggle_radio = hp_wmi_wwan_set;
432 wwan_rfkill->user_claim_unsupported = 1;
433
434 rfkill_register(wifi_rfkill);
435 rfkill_register(bluetooth_rfkill);
436 rfkill_register(wwan_rfkill);
437
438 return 0;
439add_sysfs_error:
440 cleanup_sysfs(device);
441 return err;
442}
443
444static int __exit hp_wmi_bios_remove(struct platform_device *device)
445{
446 cleanup_sysfs(device);
447
448 rfkill_unregister(wifi_rfkill);
449 rfkill_unregister(bluetooth_rfkill);
450 rfkill_unregister(wwan_rfkill);
451
452 return 0;
453}
454
455static int __init hp_wmi_init(void)
456{
457 int err;
458
459 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
460 err = wmi_install_notify_handler(HPWMI_EVENT_GUID,
461 hp_wmi_notify, NULL);
462 if (!err)
463 hp_wmi_input_setup();
464 }
465
466 if (wmi_has_guid(HPWMI_BIOS_GUID)) {
467 err = platform_driver_register(&hp_wmi_driver);
468 if (err)
469 return 0;
470 hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1);
471 if (!hp_wmi_platform_dev) {
472 platform_driver_unregister(&hp_wmi_driver);
473 return 0;
474 }
475 platform_device_add(hp_wmi_platform_dev);
476 }
477
478 return 0;
479}
480
481static void __exit hp_wmi_exit(void)
482{
483 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
484 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
485 input_unregister_device(hp_wmi_input_dev);
486 }
487 if (hp_wmi_platform_dev) {
488 platform_device_del(hp_wmi_platform_dev);
489 platform_driver_unregister(&hp_wmi_driver);
490 }
491}
492
493module_init(hp_wmi_init);
494module_exit(hp_wmi_exit);
diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
index 4ce3bdc2f959..daf585689ce3 100644
--- a/drivers/misc/phantom.c
+++ b/drivers/misc/phantom.c
@@ -563,6 +563,6 @@ module_init(phantom_init);
563module_exit(phantom_exit); 563module_exit(phantom_exit);
564 564
565MODULE_AUTHOR("Jiri Slaby <jirislaby@gmail.com>"); 565MODULE_AUTHOR("Jiri Slaby <jirislaby@gmail.com>");
566MODULE_DESCRIPTION("Sensable Phantom driver"); 566MODULE_DESCRIPTION("Sensable Phantom driver (PCI devices)");
567MODULE_LICENSE("GPL"); 567MODULE_LICENSE("GPL");
568MODULE_VERSION(PHANTOM_VERSION); 568MODULE_VERSION(PHANTOM_VERSION);
diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
index 08256ed0d9a6..579b01ff82d4 100644
--- a/drivers/misc/sgi-xp/xpc_main.c
+++ b/drivers/misc/sgi-xp/xpc_main.c
@@ -229,10 +229,11 @@ xpc_hb_checker(void *ignore)
229 int last_IRQ_count = 0; 229 int last_IRQ_count = 0;
230 int new_IRQ_count; 230 int new_IRQ_count;
231 int force_IRQ = 0; 231 int force_IRQ = 0;
232 cpumask_of_cpu_ptr(cpumask, XPC_HB_CHECK_CPU);
232 233
233 /* this thread was marked active by xpc_hb_init() */ 234 /* this thread was marked active by xpc_hb_init() */
234 235
235 set_cpus_allowed(current, cpumask_of_cpu(XPC_HB_CHECK_CPU)); 236 set_cpus_allowed_ptr(current, cpumask);
236 237
237 /* set our heartbeating to other partitions into motion */ 238 /* set our heartbeating to other partitions into motion */
238 xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ); 239 xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ);
diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
index b5969298f3d3..d3eb7903c346 100644
--- a/drivers/misc/thinkpad_acpi.c
+++ b/drivers/misc/thinkpad_acpi.c
@@ -21,7 +21,7 @@
21 * 02110-1301, USA. 21 * 02110-1301, USA.
22 */ 22 */
23 23
24#define TPACPI_VERSION "0.20" 24#define TPACPI_VERSION "0.21"
25#define TPACPI_SYSFS_VERSION 0x020200 25#define TPACPI_SYSFS_VERSION 0x020200
26 26
27/* 27/*
@@ -68,6 +68,7 @@
68#include <linux/hwmon-sysfs.h> 68#include <linux/hwmon-sysfs.h>
69#include <linux/input.h> 69#include <linux/input.h>
70#include <linux/leds.h> 70#include <linux/leds.h>
71#include <linux/rfkill.h>
71#include <asm/uaccess.h> 72#include <asm/uaccess.h>
72 73
73#include <linux/dmi.h> 74#include <linux/dmi.h>
@@ -144,6 +145,12 @@ enum {
144 145
145#define TPACPI_MAX_ACPI_ARGS 3 146#define TPACPI_MAX_ACPI_ARGS 3
146 147
148/* rfkill switches */
149enum {
150 TPACPI_RFK_BLUETOOTH_SW_ID = 0,
151 TPACPI_RFK_WWAN_SW_ID,
152};
153
147/* Debugging */ 154/* Debugging */
148#define TPACPI_LOG TPACPI_FILE ": " 155#define TPACPI_LOG TPACPI_FILE ": "
149#define TPACPI_ERR KERN_ERR TPACPI_LOG 156#define TPACPI_ERR KERN_ERR TPACPI_LOG
@@ -905,6 +912,43 @@ static int __init tpacpi_check_std_acpi_brightness_support(void)
905 return 0; 912 return 0;
906} 913}
907 914
915static int __init tpacpi_new_rfkill(const unsigned int id,
916 struct rfkill **rfk,
917 const enum rfkill_type rfktype,
918 const char *name,
919 int (*toggle_radio)(void *, enum rfkill_state),
920 int (*get_state)(void *, enum rfkill_state *))
921{
922 int res;
923 enum rfkill_state initial_state;
924
925 *rfk = rfkill_allocate(&tpacpi_pdev->dev, rfktype);
926 if (!*rfk) {
927 printk(TPACPI_ERR
928 "failed to allocate memory for rfkill class\n");
929 return -ENOMEM;
930 }
931
932 (*rfk)->name = name;
933 (*rfk)->get_state = get_state;
934 (*rfk)->toggle_radio = toggle_radio;
935
936 if (!get_state(NULL, &initial_state))
937 (*rfk)->state = initial_state;
938
939 res = rfkill_register(*rfk);
940 if (res < 0) {
941 printk(TPACPI_ERR
942 "failed to register %s rfkill switch: %d\n",
943 name, res);
944 rfkill_free(*rfk);
945 *rfk = NULL;
946 return res;
947 }
948
949 return 0;
950}
951
908/************************************************************************* 952/*************************************************************************
909 * thinkpad-acpi driver attributes 953 * thinkpad-acpi driver attributes
910 */ 954 */
@@ -1285,21 +1329,6 @@ static int hotkey_status_set(int status)
1285 return 0; 1329 return 0;
1286} 1330}
1287 1331
1288static void tpacpi_input_send_radiosw(void)
1289{
1290 int wlsw;
1291
1292 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) {
1293 mutex_lock(&tpacpi_inputdev_send_mutex);
1294
1295 input_report_switch(tpacpi_inputdev,
1296 SW_RFKILL_ALL, !!wlsw);
1297 input_sync(tpacpi_inputdev);
1298
1299 mutex_unlock(&tpacpi_inputdev_send_mutex);
1300 }
1301}
1302
1303static void tpacpi_input_send_tabletsw(void) 1332static void tpacpi_input_send_tabletsw(void)
1304{ 1333{
1305 int state; 1334 int state;
@@ -1921,6 +1950,30 @@ static struct attribute *hotkey_mask_attributes[] __initdata = {
1921 &dev_attr_hotkey_wakeup_hotunplug_complete.attr, 1950 &dev_attr_hotkey_wakeup_hotunplug_complete.attr,
1922}; 1951};
1923 1952
1953static void bluetooth_update_rfk(void);
1954static void wan_update_rfk(void);
1955static void tpacpi_send_radiosw_update(void)
1956{
1957 int wlsw;
1958
1959 /* Sync these BEFORE sending any rfkill events */
1960 if (tp_features.bluetooth)
1961 bluetooth_update_rfk();
1962 if (tp_features.wan)
1963 wan_update_rfk();
1964
1965 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) {
1966 mutex_lock(&tpacpi_inputdev_send_mutex);
1967
1968 input_report_switch(tpacpi_inputdev,
1969 SW_RFKILL_ALL, !!wlsw);
1970 input_sync(tpacpi_inputdev);
1971
1972 mutex_unlock(&tpacpi_inputdev_send_mutex);
1973 }
1974 hotkey_radio_sw_notify_change();
1975}
1976
1924static void hotkey_exit(void) 1977static void hotkey_exit(void)
1925{ 1978{
1926#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL 1979#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
@@ -2167,9 +2220,10 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
2167 printk(TPACPI_INFO 2220 printk(TPACPI_INFO
2168 "radio switch found; radios are %s\n", 2221 "radio switch found; radios are %s\n",
2169 enabled(status, 0)); 2222 enabled(status, 0));
2223 }
2224 if (tp_features.hotkey_wlsw)
2170 res = add_to_attr_set(hotkey_dev_attributes, 2225 res = add_to_attr_set(hotkey_dev_attributes,
2171 &dev_attr_hotkey_radio_sw.attr); 2226 &dev_attr_hotkey_radio_sw.attr);
2172 }
2173 2227
2174 /* For X41t, X60t, X61t Tablets... */ 2228 /* For X41t, X60t, X61t Tablets... */
2175 if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { 2229 if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) {
@@ -2287,7 +2341,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
2287 tpacpi_inputdev->close = &hotkey_inputdev_close; 2341 tpacpi_inputdev->close = &hotkey_inputdev_close;
2288 2342
2289 hotkey_poll_setup_safe(1); 2343 hotkey_poll_setup_safe(1);
2290 tpacpi_input_send_radiosw(); 2344 tpacpi_send_radiosw_update();
2291 tpacpi_input_send_tabletsw(); 2345 tpacpi_input_send_tabletsw();
2292 2346
2293 return 0; 2347 return 0;
@@ -2419,8 +2473,7 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
2419 case 7: 2473 case 7:
2420 /* 0x7000-0x7FFF: misc */ 2474 /* 0x7000-0x7FFF: misc */
2421 if (tp_features.hotkey_wlsw && hkey == 0x7000) { 2475 if (tp_features.hotkey_wlsw && hkey == 0x7000) {
2422 tpacpi_input_send_radiosw(); 2476 tpacpi_send_radiosw_update();
2423 hotkey_radio_sw_notify_change();
2424 send_acpi_ev = 0; 2477 send_acpi_ev = 0;
2425 break; 2478 break;
2426 } 2479 }
@@ -2463,8 +2516,7 @@ static void hotkey_resume(void)
2463 printk(TPACPI_ERR 2516 printk(TPACPI_ERR
2464 "error while trying to read hot key mask " 2517 "error while trying to read hot key mask "
2465 "from firmware\n"); 2518 "from firmware\n");
2466 tpacpi_input_send_radiosw(); 2519 tpacpi_send_radiosw_update();
2467 hotkey_radio_sw_notify_change();
2468 hotkey_tablet_mode_notify_change(); 2520 hotkey_tablet_mode_notify_change();
2469 hotkey_wakeup_reason_notify_change(); 2521 hotkey_wakeup_reason_notify_change();
2470 hotkey_wakeup_hotunplug_complete_notify_change(); 2522 hotkey_wakeup_hotunplug_complete_notify_change();
@@ -2581,8 +2633,66 @@ enum {
2581 TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */ 2633 TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */
2582}; 2634};
2583 2635
2584static int bluetooth_get_radiosw(void); 2636static struct rfkill *tpacpi_bluetooth_rfkill;
2585static int bluetooth_set_radiosw(int radio_on); 2637
2638static int bluetooth_get_radiosw(void)
2639{
2640 int status;
2641
2642 if (!tp_features.bluetooth)
2643 return -ENODEV;
2644
2645 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
2646 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status)
2647 return RFKILL_STATE_HARD_BLOCKED;
2648
2649 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
2650 return -EIO;
2651
2652 return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ?
2653 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
2654}
2655
2656static void bluetooth_update_rfk(void)
2657{
2658 int status;
2659
2660 if (!tpacpi_bluetooth_rfkill)
2661 return;
2662
2663 status = bluetooth_get_radiosw();
2664 if (status < 0)
2665 return;
2666 rfkill_force_state(tpacpi_bluetooth_rfkill, status);
2667}
2668
2669static int bluetooth_set_radiosw(int radio_on, int update_rfk)
2670{
2671 int status;
2672
2673 if (!tp_features.bluetooth)
2674 return -ENODEV;
2675
2676 /* WLSW overrides bluetooth in firmware/hardware, but there is no
2677 * reason to risk weird behaviour. */
2678 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status
2679 && radio_on)
2680 return -EPERM;
2681
2682 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
2683 return -EIO;
2684 if (radio_on)
2685 status |= TP_ACPI_BLUETOOTH_RADIOSSW;
2686 else
2687 status &= ~TP_ACPI_BLUETOOTH_RADIOSSW;
2688 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
2689 return -EIO;
2690
2691 if (update_rfk)
2692 bluetooth_update_rfk();
2693
2694 return 0;
2695}
2586 2696
2587/* sysfs bluetooth enable ---------------------------------------------- */ 2697/* sysfs bluetooth enable ---------------------------------------------- */
2588static ssize_t bluetooth_enable_show(struct device *dev, 2698static ssize_t bluetooth_enable_show(struct device *dev,
@@ -2595,7 +2705,8 @@ static ssize_t bluetooth_enable_show(struct device *dev,
2595 if (status < 0) 2705 if (status < 0)
2596 return status; 2706 return status;
2597 2707
2598 return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); 2708 return snprintf(buf, PAGE_SIZE, "%d\n",
2709 (status == RFKILL_STATE_UNBLOCKED) ? 1 : 0);
2599} 2710}
2600 2711
2601static ssize_t bluetooth_enable_store(struct device *dev, 2712static ssize_t bluetooth_enable_store(struct device *dev,
@@ -2608,7 +2719,7 @@ static ssize_t bluetooth_enable_store(struct device *dev,
2608 if (parse_strtoul(buf, 1, &t)) 2719 if (parse_strtoul(buf, 1, &t))
2609 return -EINVAL; 2720 return -EINVAL;
2610 2721
2611 res = bluetooth_set_radiosw(t); 2722 res = bluetooth_set_radiosw(t, 1);
2612 2723
2613 return (res) ? res : count; 2724 return (res) ? res : count;
2614} 2725}
@@ -2628,6 +2739,31 @@ static const struct attribute_group bluetooth_attr_group = {
2628 .attrs = bluetooth_attributes, 2739 .attrs = bluetooth_attributes,
2629}; 2740};
2630 2741
2742static int tpacpi_bluetooth_rfk_get(void *data, enum rfkill_state *state)
2743{
2744 int bts = bluetooth_get_radiosw();
2745
2746 if (bts < 0)
2747 return bts;
2748
2749 *state = bts;
2750 return 0;
2751}
2752
2753static int tpacpi_bluetooth_rfk_set(void *data, enum rfkill_state state)
2754{
2755 return bluetooth_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0);
2756}
2757
2758static void bluetooth_exit(void)
2759{
2760 if (tpacpi_bluetooth_rfkill)
2761 rfkill_unregister(tpacpi_bluetooth_rfkill);
2762
2763 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2764 &bluetooth_attr_group);
2765}
2766
2631static int __init bluetooth_init(struct ibm_init_struct *iibm) 2767static int __init bluetooth_init(struct ibm_init_struct *iibm)
2632{ 2768{
2633 int res; 2769 int res;
@@ -2646,57 +2782,32 @@ static int __init bluetooth_init(struct ibm_init_struct *iibm)
2646 str_supported(tp_features.bluetooth), 2782 str_supported(tp_features.bluetooth),
2647 status); 2783 status);
2648 2784
2649 if (tp_features.bluetooth) { 2785 if (tp_features.bluetooth &&
2650 if (!(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { 2786 !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
2651 /* no bluetooth hardware present in system */ 2787 /* no bluetooth hardware present in system */
2652 tp_features.bluetooth = 0; 2788 tp_features.bluetooth = 0;
2653 dbg_printk(TPACPI_DBG_INIT, 2789 dbg_printk(TPACPI_DBG_INIT,
2654 "bluetooth hardware not installed\n"); 2790 "bluetooth hardware not installed\n");
2655 } else {
2656 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2657 &bluetooth_attr_group);
2658 if (res)
2659 return res;
2660 }
2661 } 2791 }
2662 2792
2663 return (tp_features.bluetooth)? 0 : 1;
2664}
2665
2666static void bluetooth_exit(void)
2667{
2668 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2669 &bluetooth_attr_group);
2670}
2671
2672static int bluetooth_get_radiosw(void)
2673{
2674 int status;
2675
2676 if (!tp_features.bluetooth) 2793 if (!tp_features.bluetooth)
2677 return -ENODEV; 2794 return 1;
2678
2679 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
2680 return -EIO;
2681
2682 return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0);
2683}
2684
2685static int bluetooth_set_radiosw(int radio_on)
2686{
2687 int status;
2688 2795
2689 if (!tp_features.bluetooth) 2796 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2690 return -ENODEV; 2797 &bluetooth_attr_group);
2798 if (res)
2799 return res;
2691 2800
2692 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) 2801 res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID,
2693 return -EIO; 2802 &tpacpi_bluetooth_rfkill,
2694 if (radio_on) 2803 RFKILL_TYPE_BLUETOOTH,
2695 status |= TP_ACPI_BLUETOOTH_RADIOSSW; 2804 "tpacpi_bluetooth_sw",
2696 else 2805 tpacpi_bluetooth_rfk_set,
2697 status &= ~TP_ACPI_BLUETOOTH_RADIOSSW; 2806 tpacpi_bluetooth_rfk_get);
2698 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) 2807 if (res) {
2699 return -EIO; 2808 bluetooth_exit();
2809 return res;
2810 }
2700 2811
2701 return 0; 2812 return 0;
2702} 2813}
@@ -2711,7 +2822,8 @@ static int bluetooth_read(char *p)
2711 len += sprintf(p + len, "status:\t\tnot supported\n"); 2822 len += sprintf(p + len, "status:\t\tnot supported\n");
2712 else { 2823 else {
2713 len += sprintf(p + len, "status:\t\t%s\n", 2824 len += sprintf(p + len, "status:\t\t%s\n",
2714 (status)? "enabled" : "disabled"); 2825 (status == RFKILL_STATE_UNBLOCKED) ?
2826 "enabled" : "disabled");
2715 len += sprintf(p + len, "commands:\tenable, disable\n"); 2827 len += sprintf(p + len, "commands:\tenable, disable\n");
2716 } 2828 }
2717 2829
@@ -2727,9 +2839,9 @@ static int bluetooth_write(char *buf)
2727 2839
2728 while ((cmd = next_cmd(&buf))) { 2840 while ((cmd = next_cmd(&buf))) {
2729 if (strlencmp(cmd, "enable") == 0) { 2841 if (strlencmp(cmd, "enable") == 0) {
2730 bluetooth_set_radiosw(1); 2842 bluetooth_set_radiosw(1, 1);
2731 } else if (strlencmp(cmd, "disable") == 0) { 2843 } else if (strlencmp(cmd, "disable") == 0) {
2732 bluetooth_set_radiosw(0); 2844 bluetooth_set_radiosw(0, 1);
2733 } else 2845 } else
2734 return -EINVAL; 2846 return -EINVAL;
2735 } 2847 }
@@ -2755,8 +2867,66 @@ enum {
2755 TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */ 2867 TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */
2756}; 2868};
2757 2869
2758static int wan_get_radiosw(void); 2870static struct rfkill *tpacpi_wan_rfkill;
2759static int wan_set_radiosw(int radio_on); 2871
2872static int wan_get_radiosw(void)
2873{
2874 int status;
2875
2876 if (!tp_features.wan)
2877 return -ENODEV;
2878
2879 /* WLSW overrides WWAN in firmware/hardware, reflect that */
2880 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status)
2881 return RFKILL_STATE_HARD_BLOCKED;
2882
2883 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
2884 return -EIO;
2885
2886 return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ?
2887 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
2888}
2889
2890static void wan_update_rfk(void)
2891{
2892 int status;
2893
2894 if (!tpacpi_wan_rfkill)
2895 return;
2896
2897 status = wan_get_radiosw();
2898 if (status < 0)
2899 return;
2900 rfkill_force_state(tpacpi_wan_rfkill, status);
2901}
2902
2903static int wan_set_radiosw(int radio_on, int update_rfk)
2904{
2905 int status;
2906
2907 if (!tp_features.wan)
2908 return -ENODEV;
2909
2910 /* WLSW overrides bluetooth in firmware/hardware, but there is no
2911 * reason to risk weird behaviour. */
2912 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status
2913 && radio_on)
2914 return -EPERM;
2915
2916 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
2917 return -EIO;
2918 if (radio_on)
2919 status |= TP_ACPI_WANCARD_RADIOSSW;
2920 else
2921 status &= ~TP_ACPI_WANCARD_RADIOSSW;
2922 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
2923 return -EIO;
2924
2925 if (update_rfk)
2926 wan_update_rfk();
2927
2928 return 0;
2929}
2760 2930
2761/* sysfs wan enable ---------------------------------------------------- */ 2931/* sysfs wan enable ---------------------------------------------------- */
2762static ssize_t wan_enable_show(struct device *dev, 2932static ssize_t wan_enable_show(struct device *dev,
@@ -2769,7 +2939,8 @@ static ssize_t wan_enable_show(struct device *dev,
2769 if (status < 0) 2939 if (status < 0)
2770 return status; 2940 return status;
2771 2941
2772 return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); 2942 return snprintf(buf, PAGE_SIZE, "%d\n",
2943 (status == RFKILL_STATE_UNBLOCKED) ? 1 : 0);
2773} 2944}
2774 2945
2775static ssize_t wan_enable_store(struct device *dev, 2946static ssize_t wan_enable_store(struct device *dev,
@@ -2782,7 +2953,7 @@ static ssize_t wan_enable_store(struct device *dev,
2782 if (parse_strtoul(buf, 1, &t)) 2953 if (parse_strtoul(buf, 1, &t))
2783 return -EINVAL; 2954 return -EINVAL;
2784 2955
2785 res = wan_set_radiosw(t); 2956 res = wan_set_radiosw(t, 1);
2786 2957
2787 return (res) ? res : count; 2958 return (res) ? res : count;
2788} 2959}
@@ -2802,6 +2973,31 @@ static const struct attribute_group wan_attr_group = {
2802 .attrs = wan_attributes, 2973 .attrs = wan_attributes,
2803}; 2974};
2804 2975
2976static int tpacpi_wan_rfk_get(void *data, enum rfkill_state *state)
2977{
2978 int wans = wan_get_radiosw();
2979
2980 if (wans < 0)
2981 return wans;
2982
2983 *state = wans;
2984 return 0;
2985}
2986
2987static int tpacpi_wan_rfk_set(void *data, enum rfkill_state state)
2988{
2989 return wan_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0);
2990}
2991
2992static void wan_exit(void)
2993{
2994 if (tpacpi_wan_rfkill)
2995 rfkill_unregister(tpacpi_wan_rfkill);
2996
2997 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2998 &wan_attr_group);
2999}
3000
2805static int __init wan_init(struct ibm_init_struct *iibm) 3001static int __init wan_init(struct ibm_init_struct *iibm)
2806{ 3002{
2807 int res; 3003 int res;
@@ -2818,57 +3014,32 @@ static int __init wan_init(struct ibm_init_struct *iibm)
2818 str_supported(tp_features.wan), 3014 str_supported(tp_features.wan),
2819 status); 3015 status);
2820 3016
2821 if (tp_features.wan) { 3017 if (tp_features.wan &&
2822 if (!(status & TP_ACPI_WANCARD_HWPRESENT)) { 3018 !(status & TP_ACPI_WANCARD_HWPRESENT)) {
2823 /* no wan hardware present in system */ 3019 /* no wan hardware present in system */
2824 tp_features.wan = 0; 3020 tp_features.wan = 0;
2825 dbg_printk(TPACPI_DBG_INIT, 3021 dbg_printk(TPACPI_DBG_INIT,
2826 "wan hardware not installed\n"); 3022 "wan hardware not installed\n");
2827 } else {
2828 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2829 &wan_attr_group);
2830 if (res)
2831 return res;
2832 }
2833 } 3023 }
2834 3024
2835 return (tp_features.wan)? 0 : 1;
2836}
2837
2838static void wan_exit(void)
2839{
2840 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2841 &wan_attr_group);
2842}
2843
2844static int wan_get_radiosw(void)
2845{
2846 int status;
2847
2848 if (!tp_features.wan) 3025 if (!tp_features.wan)
2849 return -ENODEV; 3026 return 1;
2850
2851 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
2852 return -EIO;
2853
2854 return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0);
2855}
2856
2857static int wan_set_radiosw(int radio_on)
2858{
2859 int status;
2860 3027
2861 if (!tp_features.wan) 3028 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2862 return -ENODEV; 3029 &wan_attr_group);
3030 if (res)
3031 return res;
2863 3032
2864 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) 3033 res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID,
2865 return -EIO; 3034 &tpacpi_wan_rfkill,
2866 if (radio_on) 3035 RFKILL_TYPE_WWAN,
2867 status |= TP_ACPI_WANCARD_RADIOSSW; 3036 "tpacpi_wwan_sw",
2868 else 3037 tpacpi_wan_rfk_set,
2869 status &= ~TP_ACPI_WANCARD_RADIOSSW; 3038 tpacpi_wan_rfk_get);
2870 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) 3039 if (res) {
2871 return -EIO; 3040 wan_exit();
3041 return res;
3042 }
2872 3043
2873 return 0; 3044 return 0;
2874} 3045}
@@ -2883,7 +3054,8 @@ static int wan_read(char *p)
2883 len += sprintf(p + len, "status:\t\tnot supported\n"); 3054 len += sprintf(p + len, "status:\t\tnot supported\n");
2884 else { 3055 else {
2885 len += sprintf(p + len, "status:\t\t%s\n", 3056 len += sprintf(p + len, "status:\t\t%s\n",
2886 (status)? "enabled" : "disabled"); 3057 (status == RFKILL_STATE_UNBLOCKED) ?
3058 "enabled" : "disabled");
2887 len += sprintf(p + len, "commands:\tenable, disable\n"); 3059 len += sprintf(p + len, "commands:\tenable, disable\n");
2888 } 3060 }
2889 3061
@@ -2899,9 +3071,9 @@ static int wan_write(char *buf)
2899 3071
2900 while ((cmd = next_cmd(&buf))) { 3072 while ((cmd = next_cmd(&buf))) {
2901 if (strlencmp(cmd, "enable") == 0) { 3073 if (strlencmp(cmd, "enable") == 0) {
2902 wan_set_radiosw(1); 3074 wan_set_radiosw(1, 1);
2903 } else if (strlencmp(cmd, "disable") == 0) { 3075 } else if (strlencmp(cmd, "disable") == 0) {
2904 wan_set_radiosw(0); 3076 wan_set_radiosw(0, 1);
2905 } else 3077 } else
2906 return -EINVAL; 3078 return -EINVAL;
2907 } 3079 }
@@ -6168,13 +6340,18 @@ err_out:
6168 6340
6169/* Probing */ 6341/* Probing */
6170 6342
6171static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp) 6343/* returns 0 - probe ok, or < 0 - probe error.
6344 * Probe ok doesn't mean thinkpad found.
6345 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
6346static int __must_check __init get_thinkpad_model_data(
6347 struct thinkpad_id_data *tp)
6172{ 6348{
6173 const struct dmi_device *dev = NULL; 6349 const struct dmi_device *dev = NULL;
6174 char ec_fw_string[18]; 6350 char ec_fw_string[18];
6351 char const *s;
6175 6352
6176 if (!tp) 6353 if (!tp)
6177 return; 6354 return -EINVAL;
6178 6355
6179 memset(tp, 0, sizeof(*tp)); 6356 memset(tp, 0, sizeof(*tp));
6180 6357
@@ -6183,12 +6360,14 @@ static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp)
6183 else if (dmi_name_in_vendors("LENOVO")) 6360 else if (dmi_name_in_vendors("LENOVO"))
6184 tp->vendor = PCI_VENDOR_ID_LENOVO; 6361 tp->vendor = PCI_VENDOR_ID_LENOVO;
6185 else 6362 else
6186 return; 6363 return 0;
6187 6364
6188 tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION), 6365 s = dmi_get_system_info(DMI_BIOS_VERSION);
6189 GFP_KERNEL); 6366 tp->bios_version_str = kstrdup(s, GFP_KERNEL);
6367 if (s && !tp->bios_version_str)
6368 return -ENOMEM;
6190 if (!tp->bios_version_str) 6369 if (!tp->bios_version_str)
6191 return; 6370 return 0;
6192 tp->bios_model = tp->bios_version_str[0] 6371 tp->bios_model = tp->bios_version_str[0]
6193 | (tp->bios_version_str[1] << 8); 6372 | (tp->bios_version_str[1] << 8);
6194 6373
@@ -6207,21 +6386,27 @@ static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp)
6207 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; 6386 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
6208 6387
6209 tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); 6388 tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL);
6389 if (!tp->ec_version_str)
6390 return -ENOMEM;
6210 tp->ec_model = ec_fw_string[0] 6391 tp->ec_model = ec_fw_string[0]
6211 | (ec_fw_string[1] << 8); 6392 | (ec_fw_string[1] << 8);
6212 break; 6393 break;
6213 } 6394 }
6214 } 6395 }
6215 6396
6216 tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION), 6397 s = dmi_get_system_info(DMI_PRODUCT_VERSION);
6217 GFP_KERNEL); 6398 if (s && !strnicmp(s, "ThinkPad", 8)) {
6218 if (tp->model_str && strnicmp(tp->model_str, "ThinkPad", 8) != 0) { 6399 tp->model_str = kstrdup(s, GFP_KERNEL);
6219 kfree(tp->model_str); 6400 if (!tp->model_str)
6220 tp->model_str = NULL; 6401 return -ENOMEM;
6221 } 6402 }
6222 6403
6223 tp->nummodel_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_NAME), 6404 s = dmi_get_system_info(DMI_PRODUCT_NAME);
6224 GFP_KERNEL); 6405 tp->nummodel_str = kstrdup(s, GFP_KERNEL);
6406 if (s && !tp->nummodel_str)
6407 return -ENOMEM;
6408
6409 return 0;
6225} 6410}
6226 6411
6227static int __init probe_for_thinkpad(void) 6412static int __init probe_for_thinkpad(void)
@@ -6484,7 +6669,13 @@ static int __init thinkpad_acpi_module_init(void)
6484 6669
6485 /* Driver-level probe */ 6670 /* Driver-level probe */
6486 6671
6487 get_thinkpad_model_data(&thinkpad_id); 6672 ret = get_thinkpad_model_data(&thinkpad_id);
6673 if (ret) {
6674 printk(TPACPI_ERR
6675 "unable to get DMI data: %d\n", ret);
6676 thinkpad_acpi_module_exit();
6677 return ret;
6678 }
6488 ret = probe_for_thinkpad(); 6679 ret = probe_for_thinkpad();
6489 if (ret) { 6680 if (ret) {
6490 thinkpad_acpi_module_exit(); 6681 thinkpad_acpi_module_exit();
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index c3a5db72ddd7..5f95e10229b5 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -337,7 +337,7 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
337 337
338 host->align_addr = dma_map_single(mmc_dev(host->mmc), 338 host->align_addr = dma_map_single(mmc_dev(host->mmc),
339 host->align_buffer, 128 * 4, direction); 339 host->align_buffer, 128 * 4, direction);
340 if (dma_mapping_error(host->align_addr)) 340 if (dma_mapping_error(mmc_dev(host->mmc), host->align_addr))
341 goto fail; 341 goto fail;
342 BUG_ON(host->align_addr & 0x3); 342 BUG_ON(host->align_addr & 0x3);
343 343
@@ -439,7 +439,7 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
439 439
440 host->adma_addr = dma_map_single(mmc_dev(host->mmc), 440 host->adma_addr = dma_map_single(mmc_dev(host->mmc),
441 host->adma_desc, (128 * 2 + 1) * 4, DMA_TO_DEVICE); 441 host->adma_desc, (128 * 2 + 1) * 4, DMA_TO_DEVICE);
442 if (dma_mapping_error(host->align_addr)) 442 if (dma_mapping_error(mmc_dev(host->mmc), host->align_addr))
443 goto unmap_entries; 443 goto unmap_entries;
444 BUG_ON(host->adma_addr & 0x3); 444 BUG_ON(host->adma_addr & 0x3);
445 445
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index a06bf8b89343..e354faee5df0 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -9,6 +9,8 @@
9 * your option) any later version. 9 * your option) any later version.
10 */ 10 */
11 11
12#include <linux/scatterlist.h>
13
12/* 14/*
13 * Controller registers 15 * Controller registers
14 */ 16 */
diff --git a/drivers/mtd/maps/uclinux.c b/drivers/mtd/maps/uclinux.c
index c42f4b83f686..3fcf92130aa4 100644
--- a/drivers/mtd/maps/uclinux.c
+++ b/drivers/mtd/maps/uclinux.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/mm.h>
18#include <linux/major.h> 19#include <linux/major.h>
19#include <linux/mtd/mtd.h> 20#include <linux/mtd/mtd.h>
20#include <linux/mtd/map.h> 21#include <linux/mtd/map.h>
diff --git a/drivers/mtd/nand/cmx270_nand.c b/drivers/mtd/nand/cmx270_nand.c
index cb663ef245d5..fc8529bedfdf 100644
--- a/drivers/mtd/nand/cmx270_nand.c
+++ b/drivers/mtd/nand/cmx270_nand.c
@@ -20,9 +20,11 @@
20 20
21#include <linux/mtd/nand.h> 21#include <linux/mtd/nand.h>
22#include <linux/mtd/partitions.h> 22#include <linux/mtd/partitions.h>
23#include <linux/gpio.h>
23 24
24#include <asm/io.h> 25#include <asm/io.h>
25#include <asm/irq.h> 26#include <asm/irq.h>
27#include <asm/mach-types.h>
26 28
27#include <asm/arch/hardware.h> 29#include <asm/arch/hardware.h>
28#include <asm/arch/pxa-regs.h> 30#include <asm/arch/pxa-regs.h>
@@ -30,20 +32,6 @@
30#define GPIO_NAND_CS (11) 32#define GPIO_NAND_CS (11)
31#define GPIO_NAND_RB (89) 33#define GPIO_NAND_RB (89)
32 34
33/* This macro needed to ensure in-order operation of GPIO and local
34 * bus. Without both asm command and dummy uncached read there're
35 * states when NAND access is broken. I've looked for such macro(s) in
36 * include/asm-arm but found nothing approptiate.
37 * dmac_clean_range is close, but is makes cache invalidation
38 * unnecessary here and it cannot be used in module
39 */
40#define DRAIN_WB() \
41 do { \
42 unsigned char dummy; \
43 asm volatile ("mcr p15, 0, r0, c7, c10, 4":::"r0"); \
44 dummy=*((unsigned char*)UNCACHED_ADDR); \
45 } while(0)
46
47/* MTD structure for CM-X270 board */ 35/* MTD structure for CM-X270 board */
48static struct mtd_info *cmx270_nand_mtd; 36static struct mtd_info *cmx270_nand_mtd;
49 37
@@ -103,14 +91,14 @@ static int cmx270_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
103 91
104static inline void nand_cs_on(void) 92static inline void nand_cs_on(void)
105{ 93{
106 GPCR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS); 94 gpio_set_value(GPIO_NAND_CS, 0);
107} 95}
108 96
109static void nand_cs_off(void) 97static void nand_cs_off(void)
110{ 98{
111 DRAIN_WB(); 99 dsb();
112 100
113 GPSR(GPIO_NAND_CS) = GPIO_bit(GPIO_NAND_CS); 101 gpio_set_value(GPIO_NAND_CS, 1);
114} 102}
115 103
116/* 104/*
@@ -122,7 +110,7 @@ static void cmx270_hwcontrol(struct mtd_info *mtd, int dat,
122 struct nand_chip* this = mtd->priv; 110 struct nand_chip* this = mtd->priv;
123 unsigned int nandaddr = (unsigned int)this->IO_ADDR_W; 111 unsigned int nandaddr = (unsigned int)this->IO_ADDR_W;
124 112
125 DRAIN_WB(); 113 dsb();
126 114
127 if (ctrl & NAND_CTRL_CHANGE) { 115 if (ctrl & NAND_CTRL_CHANGE) {
128 if ( ctrl & NAND_ALE ) 116 if ( ctrl & NAND_ALE )
@@ -139,12 +127,12 @@ static void cmx270_hwcontrol(struct mtd_info *mtd, int dat,
139 nand_cs_off(); 127 nand_cs_off();
140 } 128 }
141 129
142 DRAIN_WB(); 130 dsb();
143 this->IO_ADDR_W = (void __iomem*)nandaddr; 131 this->IO_ADDR_W = (void __iomem*)nandaddr;
144 if (dat != NAND_CMD_NONE) 132 if (dat != NAND_CMD_NONE)
145 writel((dat << 16), this->IO_ADDR_W); 133 writel((dat << 16), this->IO_ADDR_W);
146 134
147 DRAIN_WB(); 135 dsb();
148} 136}
149 137
150/* 138/*
@@ -152,9 +140,9 @@ static void cmx270_hwcontrol(struct mtd_info *mtd, int dat,
152 */ 140 */
153static int cmx270_device_ready(struct mtd_info *mtd) 141static int cmx270_device_ready(struct mtd_info *mtd)
154{ 142{
155 DRAIN_WB(); 143 dsb();
156 144
157 return (GPLR(GPIO_NAND_RB) & GPIO_bit(GPIO_NAND_RB)); 145 return (gpio_get_value(GPIO_NAND_RB));
158} 146}
159 147
160/* 148/*
@@ -168,20 +156,40 @@ static int cmx270_init(void)
168 int mtd_parts_nb = 0; 156 int mtd_parts_nb = 0;
169 int ret; 157 int ret;
170 158
159 if (!machine_is_armcore())
160 return -ENODEV;
161
162 ret = gpio_request(GPIO_NAND_CS, "NAND CS");
163 if (ret) {
164 pr_warning("CM-X270: failed to request NAND CS gpio\n");
165 return ret;
166 }
167
168 gpio_direction_output(GPIO_NAND_CS, 1);
169
170 ret = gpio_request(GPIO_NAND_RB, "NAND R/B");
171 if (ret) {
172 pr_warning("CM-X270: failed to request NAND R/B gpio\n");
173 goto err_gpio_request;
174 }
175
176 gpio_direction_input(GPIO_NAND_RB);
177
171 /* Allocate memory for MTD device structure and private data */ 178 /* Allocate memory for MTD device structure and private data */
172 cmx270_nand_mtd = kzalloc(sizeof(struct mtd_info) + 179 cmx270_nand_mtd = kzalloc(sizeof(struct mtd_info) +
173 sizeof(struct nand_chip), 180 sizeof(struct nand_chip),
174 GFP_KERNEL); 181 GFP_KERNEL);
175 if (!cmx270_nand_mtd) { 182 if (!cmx270_nand_mtd) {
176 printk("Unable to allocate CM-X270 NAND MTD device structure.\n"); 183 pr_debug("Unable to allocate CM-X270 NAND MTD device structure.\n");
177 return -ENOMEM; 184 ret = -ENOMEM;
185 goto err_kzalloc;
178 } 186 }
179 187
180 cmx270_nand_io = ioremap(PXA_CS1_PHYS, 12); 188 cmx270_nand_io = ioremap(PXA_CS1_PHYS, 12);
181 if (!cmx270_nand_io) { 189 if (!cmx270_nand_io) {
182 printk("Unable to ioremap NAND device\n"); 190 pr_debug("Unable to ioremap NAND device\n");
183 ret = -EINVAL; 191 ret = -EINVAL;
184 goto err1; 192 goto err_ioremap;
185 } 193 }
186 194
187 /* Get pointer to private data */ 195 /* Get pointer to private data */
@@ -209,9 +217,9 @@ static int cmx270_init(void)
209 217
210 /* Scan to find existence of the device */ 218 /* Scan to find existence of the device */
211 if (nand_scan (cmx270_nand_mtd, 1)) { 219 if (nand_scan (cmx270_nand_mtd, 1)) {
212 printk(KERN_NOTICE "No NAND device\n"); 220 pr_notice("No NAND device\n");
213 ret = -ENXIO; 221 ret = -ENXIO;
214 goto err2; 222 goto err_scan;
215 } 223 }
216 224
217#ifdef CONFIG_MTD_CMDLINE_PARTS 225#ifdef CONFIG_MTD_CMDLINE_PARTS
@@ -229,18 +237,22 @@ static int cmx270_init(void)
229 } 237 }
230 238
231 /* Register the partitions */ 239 /* Register the partitions */
232 printk(KERN_NOTICE "Using %s partition definition\n", part_type); 240 pr_notice("Using %s partition definition\n", part_type);
233 ret = add_mtd_partitions(cmx270_nand_mtd, mtd_parts, mtd_parts_nb); 241 ret = add_mtd_partitions(cmx270_nand_mtd, mtd_parts, mtd_parts_nb);
234 if (ret) 242 if (ret)
235 goto err2; 243 goto err_scan;
236 244
237 /* Return happy */ 245 /* Return happy */
238 return 0; 246 return 0;
239 247
240err2: 248err_scan:
241 iounmap(cmx270_nand_io); 249 iounmap(cmx270_nand_io);
242err1: 250err_ioremap:
243 kfree(cmx270_nand_mtd); 251 kfree(cmx270_nand_mtd);
252err_kzalloc:
253 gpio_free(GPIO_NAND_RB);
254err_gpio_request:
255 gpio_free(GPIO_NAND_CS);
244 256
245 return ret; 257 return ret;
246 258
@@ -255,6 +267,9 @@ static void cmx270_cleanup(void)
255 /* Release resources, unregister device */ 267 /* Release resources, unregister device */
256 nand_release(cmx270_nand_mtd); 268 nand_release(cmx270_nand_mtd);
257 269
270 gpio_free(GPIO_NAND_RB);
271 gpio_free(GPIO_NAND_CS);
272
258 iounmap(cmx270_nand_io); 273 iounmap(cmx270_nand_io);
259 274
260 /* Free the MTD device structure */ 275 /* Free the MTD device structure */
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 961416ac0616..c7630a228310 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -51,14 +51,13 @@
51 * @name: MTD device name or number string 51 * @name: MTD device name or number string
52 * @vid_hdr_offs: VID header offset 52 * @vid_hdr_offs: VID header offset
53 */ 53 */
54struct mtd_dev_param 54struct mtd_dev_param {
55{
56 char name[MTD_PARAM_LEN_MAX]; 55 char name[MTD_PARAM_LEN_MAX];
57 int vid_hdr_offs; 56 int vid_hdr_offs;
58}; 57};
59 58
60/* Numbers of elements set in the @mtd_dev_param array */ 59/* Numbers of elements set in the @mtd_dev_param array */
61static int mtd_devs = 0; 60static int mtd_devs;
62 61
63/* MTD devices specification parameters */ 62/* MTD devices specification parameters */
64static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES]; 63static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES];
@@ -160,8 +159,7 @@ void ubi_put_device(struct ubi_device *ubi)
160} 159}
161 160
162/** 161/**
163 * ubi_get_by_major - get UBI device description object by character device 162 * ubi_get_by_major - get UBI device by character device major number.
164 * major number.
165 * @major: major number 163 * @major: major number
166 * 164 *
167 * This function is similar to 'ubi_get_device()', but it searches the device 165 * This function is similar to 'ubi_get_device()', but it searches the device
@@ -355,15 +353,34 @@ static void kill_volumes(struct ubi_device *ubi)
355} 353}
356 354
357/** 355/**
356 * free_user_volumes - free all user volumes.
357 * @ubi: UBI device description object
358 *
359 * Normally the volumes are freed at the release function of the volume device
360 * objects. However, on error paths the volumes have to be freed before the
361 * device objects have been initialized.
362 */
363static void free_user_volumes(struct ubi_device *ubi)
364{
365 int i;
366
367 for (i = 0; i < ubi->vtbl_slots; i++)
368 if (ubi->volumes[i]) {
369 kfree(ubi->volumes[i]->eba_tbl);
370 kfree(ubi->volumes[i]);
371 }
372}
373
374/**
358 * uif_init - initialize user interfaces for an UBI device. 375 * uif_init - initialize user interfaces for an UBI device.
359 * @ubi: UBI device description object 376 * @ubi: UBI device description object
360 * 377 *
361 * This function returns zero in case of success and a negative error code in 378 * This function returns zero in case of success and a negative error code in
362 * case of failure. 379 * case of failure. Note, this function destroys all volumes if it failes.
363 */ 380 */
364static int uif_init(struct ubi_device *ubi) 381static int uif_init(struct ubi_device *ubi)
365{ 382{
366 int i, err; 383 int i, err, do_free = 0;
367 dev_t dev; 384 dev_t dev;
368 385
369 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); 386 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num);
@@ -384,7 +401,7 @@ static int uif_init(struct ubi_device *ubi)
384 401
385 ubi_assert(MINOR(dev) == 0); 402 ubi_assert(MINOR(dev) == 0);
386 cdev_init(&ubi->cdev, &ubi_cdev_operations); 403 cdev_init(&ubi->cdev, &ubi_cdev_operations);
387 dbg_msg("%s major is %u", ubi->ubi_name, MAJOR(dev)); 404 dbg_gen("%s major is %u", ubi->ubi_name, MAJOR(dev));
388 ubi->cdev.owner = THIS_MODULE; 405 ubi->cdev.owner = THIS_MODULE;
389 406
390 err = cdev_add(&ubi->cdev, dev, 1); 407 err = cdev_add(&ubi->cdev, dev, 1);
@@ -410,10 +427,13 @@ static int uif_init(struct ubi_device *ubi)
410 427
411out_volumes: 428out_volumes:
412 kill_volumes(ubi); 429 kill_volumes(ubi);
430 do_free = 0;
413out_sysfs: 431out_sysfs:
414 ubi_sysfs_close(ubi); 432 ubi_sysfs_close(ubi);
415 cdev_del(&ubi->cdev); 433 cdev_del(&ubi->cdev);
416out_unreg: 434out_unreg:
435 if (do_free)
436 free_user_volumes(ubi);
417 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); 437 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1);
418 ubi_err("cannot initialize UBI %s, error %d", ubi->ubi_name, err); 438 ubi_err("cannot initialize UBI %s, error %d", ubi->ubi_name, err);
419 return err; 439 return err;
@@ -422,6 +442,10 @@ out_unreg:
422/** 442/**
423 * uif_close - close user interfaces for an UBI device. 443 * uif_close - close user interfaces for an UBI device.
424 * @ubi: UBI device description object 444 * @ubi: UBI device description object
445 *
446 * Note, since this function un-registers UBI volume device objects (@vol->dev),
447 * the memory allocated voe the volumes is freed as well (in the release
448 * function).
425 */ 449 */
426static void uif_close(struct ubi_device *ubi) 450static void uif_close(struct ubi_device *ubi)
427{ 451{
@@ -432,6 +456,21 @@ static void uif_close(struct ubi_device *ubi)
432} 456}
433 457
434/** 458/**
459 * free_internal_volumes - free internal volumes.
460 * @ubi: UBI device description object
461 */
462static void free_internal_volumes(struct ubi_device *ubi)
463{
464 int i;
465
466 for (i = ubi->vtbl_slots;
467 i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
468 kfree(ubi->volumes[i]->eba_tbl);
469 kfree(ubi->volumes[i]);
470 }
471}
472
473/**
435 * attach_by_scanning - attach an MTD device using scanning method. 474 * attach_by_scanning - attach an MTD device using scanning method.
436 * @ubi: UBI device descriptor 475 * @ubi: UBI device descriptor
437 * 476 *
@@ -475,6 +514,7 @@ static int attach_by_scanning(struct ubi_device *ubi)
475out_wl: 514out_wl:
476 ubi_wl_close(ubi); 515 ubi_wl_close(ubi);
477out_vtbl: 516out_vtbl:
517 free_internal_volumes(ubi);
478 vfree(ubi->vtbl); 518 vfree(ubi->vtbl);
479out_si: 519out_si:
480 ubi_scan_destroy_si(si); 520 ubi_scan_destroy_si(si);
@@ -482,7 +522,7 @@ out_si:
482} 522}
483 523
484/** 524/**
485 * io_init - initialize I/O unit for a given UBI device. 525 * io_init - initialize I/O sub-system for a given UBI device.
486 * @ubi: UBI device description object 526 * @ubi: UBI device description object
487 * 527 *
488 * If @ubi->vid_hdr_offset or @ubi->leb_start is zero, default offsets are 528 * If @ubi->vid_hdr_offset or @ubi->leb_start is zero, default offsets are
@@ -530,7 +570,11 @@ static int io_init(struct ubi_device *ubi)
530 ubi->min_io_size = ubi->mtd->writesize; 570 ubi->min_io_size = ubi->mtd->writesize;
531 ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft; 571 ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft;
532 572
533 /* Make sure minimal I/O unit is power of 2 */ 573 /*
574 * Make sure minimal I/O unit is power of 2. Note, there is no
575 * fundamental reason for this assumption. It is just an optimization
576 * which allows us to avoid costly division operations.
577 */
534 if (!is_power_of_2(ubi->min_io_size)) { 578 if (!is_power_of_2(ubi->min_io_size)) {
535 ubi_err("min. I/O unit (%d) is not power of 2", 579 ubi_err("min. I/O unit (%d) is not power of 2",
536 ubi->min_io_size); 580 ubi->min_io_size);
@@ -581,7 +625,7 @@ static int io_init(struct ubi_device *ubi)
581 if (ubi->vid_hdr_offset < UBI_EC_HDR_SIZE || 625 if (ubi->vid_hdr_offset < UBI_EC_HDR_SIZE ||
582 ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE || 626 ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE ||
583 ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE || 627 ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE ||
584 ubi->leb_start % ubi->min_io_size) { 628 ubi->leb_start & (ubi->min_io_size - 1)) {
585 ubi_err("bad VID header (%d) or data offsets (%d)", 629 ubi_err("bad VID header (%d) or data offsets (%d)",
586 ubi->vid_hdr_offset, ubi->leb_start); 630 ubi->vid_hdr_offset, ubi->leb_start);
587 return -EINVAL; 631 return -EINVAL;
@@ -646,7 +690,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
646 690
647 /* 691 /*
648 * Clear the auto-resize flag in the volume in-memory copy of the 692 * Clear the auto-resize flag in the volume in-memory copy of the
649 * volume table, and 'ubi_resize_volume()' will propogate this change 693 * volume table, and 'ubi_resize_volume()' will propagate this change
650 * to the flash. 694 * to the flash.
651 */ 695 */
652 ubi->vtbl[vol_id].flags &= ~UBI_VTBL_AUTORESIZE_FLG; 696 ubi->vtbl[vol_id].flags &= ~UBI_VTBL_AUTORESIZE_FLG;
@@ -655,7 +699,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
655 struct ubi_vtbl_record vtbl_rec; 699 struct ubi_vtbl_record vtbl_rec;
656 700
657 /* 701 /*
658 * No avalilable PEBs to re-size the volume, clear the flag on 702 * No available PEBs to re-size the volume, clear the flag on
659 * flash and exit. 703 * flash and exit.
660 */ 704 */
661 memcpy(&vtbl_rec, &ubi->vtbl[vol_id], 705 memcpy(&vtbl_rec, &ubi->vtbl[vol_id],
@@ -682,13 +726,13 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
682 726
683/** 727/**
684 * ubi_attach_mtd_dev - attach an MTD device. 728 * ubi_attach_mtd_dev - attach an MTD device.
685 * @mtd_dev: MTD device description object 729 * @mtd: MTD device description object
686 * @ubi_num: number to assign to the new UBI device 730 * @ubi_num: number to assign to the new UBI device
687 * @vid_hdr_offset: VID header offset 731 * @vid_hdr_offset: VID header offset
688 * 732 *
689 * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number 733 * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number
690 * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in 734 * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
691 * which case this function finds a vacant device nubert and assings it 735 * which case this function finds a vacant device number and assigns it
692 * automatically. Returns the new UBI device number in case of success and a 736 * automatically. Returns the new UBI device number in case of success and a
693 * negative error code in case of failure. 737 * negative error code in case of failure.
694 * 738 *
@@ -698,7 +742,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id)
698int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) 742int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
699{ 743{
700 struct ubi_device *ubi; 744 struct ubi_device *ubi;
701 int i, err; 745 int i, err, do_free = 1;
702 746
703 /* 747 /*
704 * Check if we already have the same MTD device attached. 748 * Check if we already have the same MTD device attached.
@@ -735,7 +779,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
735 if (!ubi_devices[ubi_num]) 779 if (!ubi_devices[ubi_num])
736 break; 780 break;
737 if (ubi_num == UBI_MAX_DEVICES) { 781 if (ubi_num == UBI_MAX_DEVICES) {
738 dbg_err("only %d UBI devices may be created", UBI_MAX_DEVICES); 782 dbg_err("only %d UBI devices may be created",
783 UBI_MAX_DEVICES);
739 return -ENFILE; 784 return -ENFILE;
740 } 785 }
741 } else { 786 } else {
@@ -760,6 +805,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
760 805
761 mutex_init(&ubi->buf_mutex); 806 mutex_init(&ubi->buf_mutex);
762 mutex_init(&ubi->ckvol_mutex); 807 mutex_init(&ubi->ckvol_mutex);
808 mutex_init(&ubi->mult_mutex);
763 mutex_init(&ubi->volumes_mutex); 809 mutex_init(&ubi->volumes_mutex);
764 spin_lock_init(&ubi->volumes_lock); 810 spin_lock_init(&ubi->volumes_lock);
765 811
@@ -798,7 +844,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
798 844
799 err = uif_init(ubi); 845 err = uif_init(ubi);
800 if (err) 846 if (err)
801 goto out_detach; 847 goto out_nofree;
802 848
803 ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name); 849 ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name);
804 if (IS_ERR(ubi->bgt_thread)) { 850 if (IS_ERR(ubi->bgt_thread)) {
@@ -824,20 +870,22 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
824 ubi->beb_rsvd_pebs); 870 ubi->beb_rsvd_pebs);
825 ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec); 871 ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec);
826 872
827 /* Enable the background thread */ 873 if (!DBG_DISABLE_BGT)
828 if (!DBG_DISABLE_BGT) {
829 ubi->thread_enabled = 1; 874 ubi->thread_enabled = 1;
830 wake_up_process(ubi->bgt_thread); 875 wake_up_process(ubi->bgt_thread);
831 }
832 876
833 ubi_devices[ubi_num] = ubi; 877 ubi_devices[ubi_num] = ubi;
834 return ubi_num; 878 return ubi_num;
835 879
836out_uif: 880out_uif:
837 uif_close(ubi); 881 uif_close(ubi);
882out_nofree:
883 do_free = 0;
838out_detach: 884out_detach:
839 ubi_eba_close(ubi);
840 ubi_wl_close(ubi); 885 ubi_wl_close(ubi);
886 if (do_free)
887 free_user_volumes(ubi);
888 free_internal_volumes(ubi);
841 vfree(ubi->vtbl); 889 vfree(ubi->vtbl);
842out_free: 890out_free:
843 vfree(ubi->peb_buf1); 891 vfree(ubi->peb_buf1);
@@ -899,8 +947,8 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
899 kthread_stop(ubi->bgt_thread); 947 kthread_stop(ubi->bgt_thread);
900 948
901 uif_close(ubi); 949 uif_close(ubi);
902 ubi_eba_close(ubi);
903 ubi_wl_close(ubi); 950 ubi_wl_close(ubi);
951 free_internal_volumes(ubi);
904 vfree(ubi->vtbl); 952 vfree(ubi->vtbl);
905 put_mtd_device(ubi->mtd); 953 put_mtd_device(ubi->mtd);
906 vfree(ubi->peb_buf1); 954 vfree(ubi->peb_buf1);
@@ -1044,8 +1092,7 @@ static void __exit ubi_exit(void)
1044module_exit(ubi_exit); 1092module_exit(ubi_exit);
1045 1093
1046/** 1094/**
1047 * bytes_str_to_int - convert a string representing number of bytes to an 1095 * bytes_str_to_int - convert a number of bytes string into an integer.
1048 * integer.
1049 * @str: the string to convert 1096 * @str: the string to convert
1050 * 1097 *
1051 * This function returns positive resulting integer in case of success and a 1098 * This function returns positive resulting integer in case of success and a
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 89193ba9451e..03c759b4eeb5 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -39,9 +39,9 @@
39#include <linux/stat.h> 39#include <linux/stat.h>
40#include <linux/ioctl.h> 40#include <linux/ioctl.h>
41#include <linux/capability.h> 41#include <linux/capability.h>
42#include <linux/uaccess.h>
42#include <linux/smp_lock.h> 43#include <linux/smp_lock.h>
43#include <mtd/ubi-user.h> 44#include <mtd/ubi-user.h>
44#include <asm/uaccess.h>
45#include <asm/div64.h> 45#include <asm/div64.h>
46#include "ubi.h" 46#include "ubi.h"
47 47
@@ -116,7 +116,7 @@ static int vol_cdev_open(struct inode *inode, struct file *file)
116 else 116 else
117 mode = UBI_READONLY; 117 mode = UBI_READONLY;
118 118
119 dbg_msg("open volume %d, mode %d", vol_id, mode); 119 dbg_gen("open volume %d, mode %d", vol_id, mode);
120 120
121 desc = ubi_open_volume(ubi_num, vol_id, mode); 121 desc = ubi_open_volume(ubi_num, vol_id, mode);
122 unlock_kernel(); 122 unlock_kernel();
@@ -132,7 +132,7 @@ static int vol_cdev_release(struct inode *inode, struct file *file)
132 struct ubi_volume_desc *desc = file->private_data; 132 struct ubi_volume_desc *desc = file->private_data;
133 struct ubi_volume *vol = desc->vol; 133 struct ubi_volume *vol = desc->vol;
134 134
135 dbg_msg("release volume %d, mode %d", vol->vol_id, desc->mode); 135 dbg_gen("release volume %d, mode %d", vol->vol_id, desc->mode);
136 136
137 if (vol->updating) { 137 if (vol->updating) {
138 ubi_warn("update of volume %d not finished, volume is damaged", 138 ubi_warn("update of volume %d not finished, volume is damaged",
@@ -141,7 +141,7 @@ static int vol_cdev_release(struct inode *inode, struct file *file)
141 vol->updating = 0; 141 vol->updating = 0;
142 vfree(vol->upd_buf); 142 vfree(vol->upd_buf);
143 } else if (vol->changing_leb) { 143 } else if (vol->changing_leb) {
144 dbg_msg("only %lld of %lld bytes received for atomic LEB change" 144 dbg_gen("only %lld of %lld bytes received for atomic LEB change"
145 " for volume %d:%d, cancel", vol->upd_received, 145 " for volume %d:%d, cancel", vol->upd_received,
146 vol->upd_bytes, vol->ubi->ubi_num, vol->vol_id); 146 vol->upd_bytes, vol->ubi->ubi_num, vol->vol_id);
147 vol->changing_leb = 0; 147 vol->changing_leb = 0;
@@ -183,7 +183,7 @@ static loff_t vol_cdev_llseek(struct file *file, loff_t offset, int origin)
183 return -EINVAL; 183 return -EINVAL;
184 } 184 }
185 185
186 dbg_msg("seek volume %d, offset %lld, origin %d, new offset %lld", 186 dbg_gen("seek volume %d, offset %lld, origin %d, new offset %lld",
187 vol->vol_id, offset, origin, new_offset); 187 vol->vol_id, offset, origin, new_offset);
188 188
189 file->f_pos = new_offset; 189 file->f_pos = new_offset;
@@ -201,7 +201,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
201 void *tbuf; 201 void *tbuf;
202 uint64_t tmp; 202 uint64_t tmp;
203 203
204 dbg_msg("read %zd bytes from offset %lld of volume %d", 204 dbg_gen("read %zd bytes from offset %lld of volume %d",
205 count, *offp, vol->vol_id); 205 count, *offp, vol->vol_id);
206 206
207 if (vol->updating) { 207 if (vol->updating) {
@@ -216,7 +216,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
216 return 0; 216 return 0;
217 217
218 if (vol->corrupted) 218 if (vol->corrupted)
219 dbg_msg("read from corrupted volume %d", vol->vol_id); 219 dbg_gen("read from corrupted volume %d", vol->vol_id);
220 220
221 if (*offp + count > vol->used_bytes) 221 if (*offp + count > vol->used_bytes)
222 count_save = count = vol->used_bytes - *offp; 222 count_save = count = vol->used_bytes - *offp;
@@ -285,7 +285,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
285 char *tbuf; 285 char *tbuf;
286 uint64_t tmp; 286 uint64_t tmp;
287 287
288 dbg_msg("requested: write %zd bytes to offset %lld of volume %u", 288 dbg_gen("requested: write %zd bytes to offset %lld of volume %u",
289 count, *offp, vol->vol_id); 289 count, *offp, vol->vol_id);
290 290
291 if (vol->vol_type == UBI_STATIC_VOLUME) 291 if (vol->vol_type == UBI_STATIC_VOLUME)
@@ -295,7 +295,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
295 off = do_div(tmp, vol->usable_leb_size); 295 off = do_div(tmp, vol->usable_leb_size);
296 lnum = tmp; 296 lnum = tmp;
297 297
298 if (off % ubi->min_io_size) { 298 if (off & (ubi->min_io_size - 1)) {
299 dbg_err("unaligned position"); 299 dbg_err("unaligned position");
300 return -EINVAL; 300 return -EINVAL;
301 } 301 }
@@ -304,7 +304,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
304 count_save = count = vol->used_bytes - *offp; 304 count_save = count = vol->used_bytes - *offp;
305 305
306 /* We can write only in fractions of the minimum I/O unit */ 306 /* We can write only in fractions of the minimum I/O unit */
307 if (count % ubi->min_io_size) { 307 if (count & (ubi->min_io_size - 1)) {
308 dbg_err("unaligned write length"); 308 dbg_err("unaligned write length");
309 return -EINVAL; 309 return -EINVAL;
310 } 310 }
@@ -352,7 +352,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
352} 352}
353 353
354#else 354#else
355#define vol_cdev_direct_write(file, buf, count, offp) -EPERM 355#define vol_cdev_direct_write(file, buf, count, offp) (-EPERM)
356#endif /* CONFIG_MTD_UBI_DEBUG_USERSPACE_IO */ 356#endif /* CONFIG_MTD_UBI_DEBUG_USERSPACE_IO */
357 357
358static ssize_t vol_cdev_write(struct file *file, const char __user *buf, 358static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
@@ -437,7 +437,8 @@ static int vol_cdev_ioctl(struct inode *inode, struct file *file,
437 break; 437 break;
438 } 438 }
439 439
440 rsvd_bytes = vol->reserved_pebs * (ubi->leb_size-vol->data_pad); 440 rsvd_bytes = (long long)vol->reserved_pebs *
441 ubi->leb_size-vol->data_pad;
441 if (bytes < 0 || bytes > rsvd_bytes) { 442 if (bytes < 0 || bytes > rsvd_bytes) {
442 err = -EINVAL; 443 err = -EINVAL;
443 break; 444 break;
@@ -513,7 +514,7 @@ static int vol_cdev_ioctl(struct inode *inode, struct file *file,
513 break; 514 break;
514 } 515 }
515 516
516 dbg_msg("erase LEB %d:%d", vol->vol_id, lnum); 517 dbg_gen("erase LEB %d:%d", vol->vol_id, lnum);
517 err = ubi_eba_unmap_leb(ubi, vol, lnum); 518 err = ubi_eba_unmap_leb(ubi, vol, lnum);
518 if (err) 519 if (err)
519 break; 520 break;
@@ -564,7 +565,7 @@ static int verify_mkvol_req(const struct ubi_device *ubi,
564 if (req->alignment > ubi->leb_size) 565 if (req->alignment > ubi->leb_size)
565 goto bad; 566 goto bad;
566 567
567 n = req->alignment % ubi->min_io_size; 568 n = req->alignment & (ubi->min_io_size - 1);
568 if (req->alignment != 1 && n) 569 if (req->alignment != 1 && n)
569 goto bad; 570 goto bad;
570 571
@@ -573,6 +574,10 @@ static int verify_mkvol_req(const struct ubi_device *ubi,
573 goto bad; 574 goto bad;
574 } 575 }
575 576
577 n = strnlen(req->name, req->name_len + 1);
578 if (n != req->name_len)
579 goto bad;
580
576 return 0; 581 return 0;
577 582
578bad: 583bad:
@@ -600,6 +605,166 @@ static int verify_rsvol_req(const struct ubi_device *ubi,
600 return 0; 605 return 0;
601} 606}
602 607
608/**
609 * rename_volumes - rename UBI volumes.
610 * @ubi: UBI device description object
611 * @req: volumes re-name request
612 *
613 * This is a helper function for the volume re-name IOCTL which validates the
614 * the request, opens the volume and calls corresponding volumes management
615 * function. Returns zero in case of success and a negative error code in case
616 * of failure.
617 */
618static int rename_volumes(struct ubi_device *ubi,
619 struct ubi_rnvol_req *req)
620{
621 int i, n, err;
622 struct list_head rename_list;
623 struct ubi_rename_entry *re, *re1;
624
625 if (req->count < 0 || req->count > UBI_MAX_RNVOL)
626 return -EINVAL;
627
628 if (req->count == 0)
629 return 0;
630
631 /* Validate volume IDs and names in the request */
632 for (i = 0; i < req->count; i++) {
633 if (req->ents[i].vol_id < 0 ||
634 req->ents[i].vol_id >= ubi->vtbl_slots)
635 return -EINVAL;
636 if (req->ents[i].name_len < 0)
637 return -EINVAL;
638 if (req->ents[i].name_len > UBI_VOL_NAME_MAX)
639 return -ENAMETOOLONG;
640 req->ents[i].name[req->ents[i].name_len] = '\0';
641 n = strlen(req->ents[i].name);
642 if (n != req->ents[i].name_len)
643 err = -EINVAL;
644 }
645
646 /* Make sure volume IDs and names are unique */
647 for (i = 0; i < req->count - 1; i++) {
648 for (n = i + 1; n < req->count; n++) {
649 if (req->ents[i].vol_id == req->ents[n].vol_id) {
650 dbg_err("duplicated volume id %d",
651 req->ents[i].vol_id);
652 return -EINVAL;
653 }
654 if (!strcmp(req->ents[i].name, req->ents[n].name)) {
655 dbg_err("duplicated volume name \"%s\"",
656 req->ents[i].name);
657 return -EINVAL;
658 }
659 }
660 }
661
662 /* Create the re-name list */
663 INIT_LIST_HEAD(&rename_list);
664 for (i = 0; i < req->count; i++) {
665 int vol_id = req->ents[i].vol_id;
666 int name_len = req->ents[i].name_len;
667 const char *name = req->ents[i].name;
668
669 re = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL);
670 if (!re) {
671 err = -ENOMEM;
672 goto out_free;
673 }
674
675 re->desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_EXCLUSIVE);
676 if (IS_ERR(re->desc)) {
677 err = PTR_ERR(re->desc);
678 dbg_err("cannot open volume %d, error %d", vol_id, err);
679 kfree(re);
680 goto out_free;
681 }
682
683 /* Skip this re-naming if the name does not really change */
684 if (re->desc->vol->name_len == name_len &&
685 !memcmp(re->desc->vol->name, name, name_len)) {
686 ubi_close_volume(re->desc);
687 kfree(re);
688 continue;
689 }
690
691 re->new_name_len = name_len;
692 memcpy(re->new_name, name, name_len);
693 list_add_tail(&re->list, &rename_list);
694 dbg_msg("will rename volume %d from \"%s\" to \"%s\"",
695 vol_id, re->desc->vol->name, name);
696 }
697
698 if (list_empty(&rename_list))
699 return 0;
700
701 /* Find out the volumes which have to be removed */
702 list_for_each_entry(re, &rename_list, list) {
703 struct ubi_volume_desc *desc;
704 int no_remove_needed = 0;
705
706 /*
707 * Volume @re->vol_id is going to be re-named to
708 * @re->new_name, while its current name is @name. If a volume
709 * with name @re->new_name currently exists, it has to be
710 * removed, unless it is also re-named in the request (@req).
711 */
712 list_for_each_entry(re1, &rename_list, list) {
713 if (re->new_name_len == re1->desc->vol->name_len &&
714 !memcmp(re->new_name, re1->desc->vol->name,
715 re1->desc->vol->name_len)) {
716 no_remove_needed = 1;
717 break;
718 }
719 }
720
721 if (no_remove_needed)
722 continue;
723
724 /*
725 * It seems we need to remove volume with name @re->new_name,
726 * if it exists.
727 */
728 desc = ubi_open_volume_nm(ubi->ubi_num, re->new_name, UBI_EXCLUSIVE);
729 if (IS_ERR(desc)) {
730 err = PTR_ERR(desc);
731 if (err == -ENODEV)
732 /* Re-naming into a non-existing volume name */
733 continue;
734
735 /* The volume exists but busy, or an error occurred */
736 dbg_err("cannot open volume \"%s\", error %d",
737 re->new_name, err);
738 goto out_free;
739 }
740
741 re = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL);
742 if (!re) {
743 err = -ENOMEM;
744 ubi_close_volume(desc);
745 goto out_free;
746 }
747
748 re->remove = 1;
749 re->desc = desc;
750 list_add(&re->list, &rename_list);
751 dbg_msg("will remove volume %d, name \"%s\"",
752 re->desc->vol->vol_id, re->desc->vol->name);
753 }
754
755 mutex_lock(&ubi->volumes_mutex);
756 err = ubi_rename_volumes(ubi, &rename_list);
757 mutex_unlock(&ubi->volumes_mutex);
758
759out_free:
760 list_for_each_entry_safe(re, re1, &rename_list, list) {
761 ubi_close_volume(re->desc);
762 list_del(&re->list);
763 kfree(re);
764 }
765 return err;
766}
767
603static int ubi_cdev_ioctl(struct inode *inode, struct file *file, 768static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
604 unsigned int cmd, unsigned long arg) 769 unsigned int cmd, unsigned long arg)
605{ 770{
@@ -621,19 +786,18 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
621 { 786 {
622 struct ubi_mkvol_req req; 787 struct ubi_mkvol_req req;
623 788
624 dbg_msg("create volume"); 789 dbg_gen("create volume");
625 err = copy_from_user(&req, argp, sizeof(struct ubi_mkvol_req)); 790 err = copy_from_user(&req, argp, sizeof(struct ubi_mkvol_req));
626 if (err) { 791 if (err) {
627 err = -EFAULT; 792 err = -EFAULT;
628 break; 793 break;
629 } 794 }
630 795
796 req.name[req.name_len] = '\0';
631 err = verify_mkvol_req(ubi, &req); 797 err = verify_mkvol_req(ubi, &req);
632 if (err) 798 if (err)
633 break; 799 break;
634 800
635 req.name[req.name_len] = '\0';
636
637 mutex_lock(&ubi->volumes_mutex); 801 mutex_lock(&ubi->volumes_mutex);
638 err = ubi_create_volume(ubi, &req); 802 err = ubi_create_volume(ubi, &req);
639 mutex_unlock(&ubi->volumes_mutex); 803 mutex_unlock(&ubi->volumes_mutex);
@@ -652,7 +816,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
652 { 816 {
653 int vol_id; 817 int vol_id;
654 818
655 dbg_msg("remove volume"); 819 dbg_gen("remove volume");
656 err = get_user(vol_id, (__user int32_t *)argp); 820 err = get_user(vol_id, (__user int32_t *)argp);
657 if (err) { 821 if (err) {
658 err = -EFAULT; 822 err = -EFAULT;
@@ -666,7 +830,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
666 } 830 }
667 831
668 mutex_lock(&ubi->volumes_mutex); 832 mutex_lock(&ubi->volumes_mutex);
669 err = ubi_remove_volume(desc); 833 err = ubi_remove_volume(desc, 0);
670 mutex_unlock(&ubi->volumes_mutex); 834 mutex_unlock(&ubi->volumes_mutex);
671 835
672 /* 836 /*
@@ -685,7 +849,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
685 uint64_t tmp; 849 uint64_t tmp;
686 struct ubi_rsvol_req req; 850 struct ubi_rsvol_req req;
687 851
688 dbg_msg("re-size volume"); 852 dbg_gen("re-size volume");
689 err = copy_from_user(&req, argp, sizeof(struct ubi_rsvol_req)); 853 err = copy_from_user(&req, argp, sizeof(struct ubi_rsvol_req));
690 if (err) { 854 if (err) {
691 err = -EFAULT; 855 err = -EFAULT;
@@ -713,6 +877,32 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
713 break; 877 break;
714 } 878 }
715 879
880 /* Re-name volumes command */
881 case UBI_IOCRNVOL:
882 {
883 struct ubi_rnvol_req *req;
884
885 dbg_msg("re-name volumes");
886 req = kmalloc(sizeof(struct ubi_rnvol_req), GFP_KERNEL);
887 if (!req) {
888 err = -ENOMEM;
889 break;
890 };
891
892 err = copy_from_user(req, argp, sizeof(struct ubi_rnvol_req));
893 if (err) {
894 err = -EFAULT;
895 kfree(req);
896 break;
897 }
898
899 mutex_lock(&ubi->mult_mutex);
900 err = rename_volumes(ubi, req);
901 mutex_unlock(&ubi->mult_mutex);
902 kfree(req);
903 break;
904 }
905
716 default: 906 default:
717 err = -ENOTTY; 907 err = -ENOTTY;
718 break; 908 break;
@@ -738,7 +928,7 @@ static int ctrl_cdev_ioctl(struct inode *inode, struct file *file,
738 struct ubi_attach_req req; 928 struct ubi_attach_req req;
739 struct mtd_info *mtd; 929 struct mtd_info *mtd;
740 930
741 dbg_msg("attach MTD device"); 931 dbg_gen("attach MTD device");
742 err = copy_from_user(&req, argp, sizeof(struct ubi_attach_req)); 932 err = copy_from_user(&req, argp, sizeof(struct ubi_attach_req));
743 if (err) { 933 if (err) {
744 err = -EFAULT; 934 err = -EFAULT;
@@ -778,7 +968,7 @@ static int ctrl_cdev_ioctl(struct inode *inode, struct file *file,
778 { 968 {
779 int ubi_num; 969 int ubi_num;
780 970
781 dbg_msg("dettach MTD device"); 971 dbg_gen("dettach MTD device");
782 err = get_user(ubi_num, (__user int32_t *)argp); 972 err = get_user(ubi_num, (__user int32_t *)argp);
783 if (err) { 973 if (err) {
784 err = -EFAULT; 974 err = -EFAULT;
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
index 56956ec2845f..c0ed60e8ade9 100644
--- a/drivers/mtd/ubi/debug.c
+++ b/drivers/mtd/ubi/debug.c
@@ -24,7 +24,7 @@
24 * changes. 24 * changes.
25 */ 25 */
26 26
27#ifdef CONFIG_MTD_UBI_DEBUG_MSG 27#ifdef CONFIG_MTD_UBI_DEBUG
28 28
29#include "ubi.h" 29#include "ubi.h"
30 30
@@ -34,14 +34,19 @@
34 */ 34 */
35void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) 35void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
36{ 36{
37 dbg_msg("erase counter header dump:"); 37 printk(KERN_DEBUG "Erase counter header dump:\n");
38 dbg_msg("magic %#08x", be32_to_cpu(ec_hdr->magic)); 38 printk(KERN_DEBUG "\tmagic %#08x\n",
39 dbg_msg("version %d", (int)ec_hdr->version); 39 be32_to_cpu(ec_hdr->magic));
40 dbg_msg("ec %llu", (long long)be64_to_cpu(ec_hdr->ec)); 40 printk(KERN_DEBUG "\tversion %d\n", (int)ec_hdr->version);
41 dbg_msg("vid_hdr_offset %d", be32_to_cpu(ec_hdr->vid_hdr_offset)); 41 printk(KERN_DEBUG "\tec %llu\n",
42 dbg_msg("data_offset %d", be32_to_cpu(ec_hdr->data_offset)); 42 (long long)be64_to_cpu(ec_hdr->ec));
43 dbg_msg("hdr_crc %#08x", be32_to_cpu(ec_hdr->hdr_crc)); 43 printk(KERN_DEBUG "\tvid_hdr_offset %d\n",
44 dbg_msg("erase counter header hexdump:"); 44 be32_to_cpu(ec_hdr->vid_hdr_offset));
45 printk(KERN_DEBUG "\tdata_offset %d\n",
46 be32_to_cpu(ec_hdr->data_offset));
47 printk(KERN_DEBUG "\thdr_crc %#08x\n",
48 be32_to_cpu(ec_hdr->hdr_crc));
49 printk(KERN_DEBUG "erase counter header hexdump:\n");
45 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 50 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
46 ec_hdr, UBI_EC_HDR_SIZE, 1); 51 ec_hdr, UBI_EC_HDR_SIZE, 1);
47} 52}
@@ -52,22 +57,23 @@ void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
52 */ 57 */
53void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) 58void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
54{ 59{
55 dbg_msg("volume identifier header dump:"); 60 printk(KERN_DEBUG "Volume identifier header dump:\n");
56 dbg_msg("magic %08x", be32_to_cpu(vid_hdr->magic)); 61 printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic));
57 dbg_msg("version %d", (int)vid_hdr->version); 62 printk(KERN_DEBUG "\tversion %d\n", (int)vid_hdr->version);
58 dbg_msg("vol_type %d", (int)vid_hdr->vol_type); 63 printk(KERN_DEBUG "\tvol_type %d\n", (int)vid_hdr->vol_type);
59 dbg_msg("copy_flag %d", (int)vid_hdr->copy_flag); 64 printk(KERN_DEBUG "\tcopy_flag %d\n", (int)vid_hdr->copy_flag);
60 dbg_msg("compat %d", (int)vid_hdr->compat); 65 printk(KERN_DEBUG "\tcompat %d\n", (int)vid_hdr->compat);
61 dbg_msg("vol_id %d", be32_to_cpu(vid_hdr->vol_id)); 66 printk(KERN_DEBUG "\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id));
62 dbg_msg("lnum %d", be32_to_cpu(vid_hdr->lnum)); 67 printk(KERN_DEBUG "\tlnum %d\n", be32_to_cpu(vid_hdr->lnum));
63 dbg_msg("leb_ver %u", be32_to_cpu(vid_hdr->leb_ver)); 68 printk(KERN_DEBUG "\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size));
64 dbg_msg("data_size %d", be32_to_cpu(vid_hdr->data_size)); 69 printk(KERN_DEBUG "\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs));
65 dbg_msg("used_ebs %d", be32_to_cpu(vid_hdr->used_ebs)); 70 printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad));
66 dbg_msg("data_pad %d", be32_to_cpu(vid_hdr->data_pad)); 71 printk(KERN_DEBUG "\tsqnum %llu\n",
67 dbg_msg("sqnum %llu",
68 (unsigned long long)be64_to_cpu(vid_hdr->sqnum)); 72 (unsigned long long)be64_to_cpu(vid_hdr->sqnum));
69 dbg_msg("hdr_crc %08x", be32_to_cpu(vid_hdr->hdr_crc)); 73 printk(KERN_DEBUG "\thdr_crc %08x\n", be32_to_cpu(vid_hdr->hdr_crc));
70 dbg_msg("volume identifier header hexdump:"); 74 printk(KERN_DEBUG "Volume identifier header hexdump:\n");
75 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
76 vid_hdr, UBI_VID_HDR_SIZE, 1);
71} 77}
72 78
73/** 79/**
@@ -76,27 +82,27 @@ void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
76 */ 82 */
77void ubi_dbg_dump_vol_info(const struct ubi_volume *vol) 83void ubi_dbg_dump_vol_info(const struct ubi_volume *vol)
78{ 84{
79 dbg_msg("volume information dump:"); 85 printk(KERN_DEBUG "Volume information dump:\n");
80 dbg_msg("vol_id %d", vol->vol_id); 86 printk(KERN_DEBUG "\tvol_id %d\n", vol->vol_id);
81 dbg_msg("reserved_pebs %d", vol->reserved_pebs); 87 printk(KERN_DEBUG "\treserved_pebs %d\n", vol->reserved_pebs);
82 dbg_msg("alignment %d", vol->alignment); 88 printk(KERN_DEBUG "\talignment %d\n", vol->alignment);
83 dbg_msg("data_pad %d", vol->data_pad); 89 printk(KERN_DEBUG "\tdata_pad %d\n", vol->data_pad);
84 dbg_msg("vol_type %d", vol->vol_type); 90 printk(KERN_DEBUG "\tvol_type %d\n", vol->vol_type);
85 dbg_msg("name_len %d", vol->name_len); 91 printk(KERN_DEBUG "\tname_len %d\n", vol->name_len);
86 dbg_msg("usable_leb_size %d", vol->usable_leb_size); 92 printk(KERN_DEBUG "\tusable_leb_size %d\n", vol->usable_leb_size);
87 dbg_msg("used_ebs %d", vol->used_ebs); 93 printk(KERN_DEBUG "\tused_ebs %d\n", vol->used_ebs);
88 dbg_msg("used_bytes %lld", vol->used_bytes); 94 printk(KERN_DEBUG "\tused_bytes %lld\n", vol->used_bytes);
89 dbg_msg("last_eb_bytes %d", vol->last_eb_bytes); 95 printk(KERN_DEBUG "\tlast_eb_bytes %d\n", vol->last_eb_bytes);
90 dbg_msg("corrupted %d", vol->corrupted); 96 printk(KERN_DEBUG "\tcorrupted %d\n", vol->corrupted);
91 dbg_msg("upd_marker %d", vol->upd_marker); 97 printk(KERN_DEBUG "\tupd_marker %d\n", vol->upd_marker);
92 98
93 if (vol->name_len <= UBI_VOL_NAME_MAX && 99 if (vol->name_len <= UBI_VOL_NAME_MAX &&
94 strnlen(vol->name, vol->name_len + 1) == vol->name_len) { 100 strnlen(vol->name, vol->name_len + 1) == vol->name_len) {
95 dbg_msg("name %s", vol->name); 101 printk(KERN_DEBUG "\tname %s\n", vol->name);
96 } else { 102 } else {
97 dbg_msg("the 1st 5 characters of the name: %c%c%c%c%c", 103 printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n",
98 vol->name[0], vol->name[1], vol->name[2], 104 vol->name[0], vol->name[1], vol->name[2],
99 vol->name[3], vol->name[4]); 105 vol->name[3], vol->name[4]);
100 } 106 }
101} 107}
102 108
@@ -109,28 +115,29 @@ void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
109{ 115{
110 int name_len = be16_to_cpu(r->name_len); 116 int name_len = be16_to_cpu(r->name_len);
111 117
112 dbg_msg("volume table record %d dump:", idx); 118 printk(KERN_DEBUG "Volume table record %d dump:\n", idx);
113 dbg_msg("reserved_pebs %d", be32_to_cpu(r->reserved_pebs)); 119 printk(KERN_DEBUG "\treserved_pebs %d\n",
114 dbg_msg("alignment %d", be32_to_cpu(r->alignment)); 120 be32_to_cpu(r->reserved_pebs));
115 dbg_msg("data_pad %d", be32_to_cpu(r->data_pad)); 121 printk(KERN_DEBUG "\talignment %d\n", be32_to_cpu(r->alignment));
116 dbg_msg("vol_type %d", (int)r->vol_type); 122 printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(r->data_pad));
117 dbg_msg("upd_marker %d", (int)r->upd_marker); 123 printk(KERN_DEBUG "\tvol_type %d\n", (int)r->vol_type);
118 dbg_msg("name_len %d", name_len); 124 printk(KERN_DEBUG "\tupd_marker %d\n", (int)r->upd_marker);
125 printk(KERN_DEBUG "\tname_len %d\n", name_len);
119 126
120 if (r->name[0] == '\0') { 127 if (r->name[0] == '\0') {
121 dbg_msg("name NULL"); 128 printk(KERN_DEBUG "\tname NULL\n");
122 return; 129 return;
123 } 130 }
124 131
125 if (name_len <= UBI_VOL_NAME_MAX && 132 if (name_len <= UBI_VOL_NAME_MAX &&
126 strnlen(&r->name[0], name_len + 1) == name_len) { 133 strnlen(&r->name[0], name_len + 1) == name_len) {
127 dbg_msg("name %s", &r->name[0]); 134 printk(KERN_DEBUG "\tname %s\n", &r->name[0]);
128 } else { 135 } else {
129 dbg_msg("1st 5 characters of the name: %c%c%c%c%c", 136 printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n",
130 r->name[0], r->name[1], r->name[2], r->name[3], 137 r->name[0], r->name[1], r->name[2], r->name[3],
131 r->name[4]); 138 r->name[4]);
132 } 139 }
133 dbg_msg("crc %#08x", be32_to_cpu(r->crc)); 140 printk(KERN_DEBUG "\tcrc %#08x\n", be32_to_cpu(r->crc));
134} 141}
135 142
136/** 143/**
@@ -139,15 +146,15 @@ void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
139 */ 146 */
140void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv) 147void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv)
141{ 148{
142 dbg_msg("volume scanning information dump:"); 149 printk(KERN_DEBUG "Volume scanning information dump:\n");
143 dbg_msg("vol_id %d", sv->vol_id); 150 printk(KERN_DEBUG "\tvol_id %d\n", sv->vol_id);
144 dbg_msg("highest_lnum %d", sv->highest_lnum); 151 printk(KERN_DEBUG "\thighest_lnum %d\n", sv->highest_lnum);
145 dbg_msg("leb_count %d", sv->leb_count); 152 printk(KERN_DEBUG "\tleb_count %d\n", sv->leb_count);
146 dbg_msg("compat %d", sv->compat); 153 printk(KERN_DEBUG "\tcompat %d\n", sv->compat);
147 dbg_msg("vol_type %d", sv->vol_type); 154 printk(KERN_DEBUG "\tvol_type %d\n", sv->vol_type);
148 dbg_msg("used_ebs %d", sv->used_ebs); 155 printk(KERN_DEBUG "\tused_ebs %d\n", sv->used_ebs);
149 dbg_msg("last_data_size %d", sv->last_data_size); 156 printk(KERN_DEBUG "\tlast_data_size %d\n", sv->last_data_size);
150 dbg_msg("data_pad %d", sv->data_pad); 157 printk(KERN_DEBUG "\tdata_pad %d\n", sv->data_pad);
151} 158}
152 159
153/** 160/**
@@ -157,14 +164,13 @@ void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv)
157 */ 164 */
158void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type) 165void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type)
159{ 166{
160 dbg_msg("eraseblock scanning information dump:"); 167 printk(KERN_DEBUG "eraseblock scanning information dump:\n");
161 dbg_msg("ec %d", seb->ec); 168 printk(KERN_DEBUG "\tec %d\n", seb->ec);
162 dbg_msg("pnum %d", seb->pnum); 169 printk(KERN_DEBUG "\tpnum %d\n", seb->pnum);
163 if (type == 0) { 170 if (type == 0) {
164 dbg_msg("lnum %d", seb->lnum); 171 printk(KERN_DEBUG "\tlnum %d\n", seb->lnum);
165 dbg_msg("scrub %d", seb->scrub); 172 printk(KERN_DEBUG "\tscrub %d\n", seb->scrub);
166 dbg_msg("sqnum %llu", seb->sqnum); 173 printk(KERN_DEBUG "\tsqnum %llu\n", seb->sqnum);
167 dbg_msg("leb_ver %u", seb->leb_ver);
168 } 174 }
169} 175}
170 176
@@ -176,16 +182,16 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req)
176{ 182{
177 char nm[17]; 183 char nm[17];
178 184
179 dbg_msg("volume creation request dump:"); 185 printk(KERN_DEBUG "Volume creation request dump:\n");
180 dbg_msg("vol_id %d", req->vol_id); 186 printk(KERN_DEBUG "\tvol_id %d\n", req->vol_id);
181 dbg_msg("alignment %d", req->alignment); 187 printk(KERN_DEBUG "\talignment %d\n", req->alignment);
182 dbg_msg("bytes %lld", (long long)req->bytes); 188 printk(KERN_DEBUG "\tbytes %lld\n", (long long)req->bytes);
183 dbg_msg("vol_type %d", req->vol_type); 189 printk(KERN_DEBUG "\tvol_type %d\n", req->vol_type);
184 dbg_msg("name_len %d", req->name_len); 190 printk(KERN_DEBUG "\tname_len %d\n", req->name_len);
185 191
186 memcpy(nm, req->name, 16); 192 memcpy(nm, req->name, 16);
187 nm[16] = 0; 193 nm[16] = 0;
188 dbg_msg("the 1st 16 characters of the name: %s", nm); 194 printk(KERN_DEBUG "\t1st 16 characters of name: %s\n", nm);
189} 195}
190 196
191#endif /* CONFIG_MTD_UBI_DEBUG_MSG */ 197#endif /* CONFIG_MTD_UBI_DEBUG */
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index 8ea99d8c9e1f..78e914d23ece 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -24,21 +24,16 @@
24#ifdef CONFIG_MTD_UBI_DEBUG 24#ifdef CONFIG_MTD_UBI_DEBUG
25#include <linux/random.h> 25#include <linux/random.h>
26 26
27#define ubi_assert(expr) BUG_ON(!(expr))
28#define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__) 27#define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__)
29#else
30#define ubi_assert(expr) ({})
31#define dbg_err(fmt, ...) ({})
32#endif
33 28
34#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT 29#define ubi_assert(expr) do { \
35#define DBG_DISABLE_BGT 1 30 if (unlikely(!(expr))) { \
36#else 31 printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \
37#define DBG_DISABLE_BGT 0 32 __func__, __LINE__, current->pid); \
38#endif 33 ubi_dbg_dump_stack(); \
34 } \
35} while (0)
39 36
40#ifdef CONFIG_MTD_UBI_DEBUG_MSG
41/* Generic debugging message */
42#define dbg_msg(fmt, ...) \ 37#define dbg_msg(fmt, ...) \
43 printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \ 38 printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \
44 current->pid, __func__, ##__VA_ARGS__) 39 current->pid, __func__, ##__VA_ARGS__)
@@ -61,36 +56,29 @@ void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
61void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); 56void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
62void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); 57void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
63 58
59#ifdef CONFIG_MTD_UBI_DEBUG_MSG
60/* General debugging messages */
61#define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
64#else 62#else
65 63#define dbg_gen(fmt, ...) ({})
66#define dbg_msg(fmt, ...) ({}) 64#endif
67#define ubi_dbg_dump_stack() ({})
68#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
69#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
70#define ubi_dbg_dump_vol_info(vol) ({})
71#define ubi_dbg_dump_vtbl_record(r, idx) ({})
72#define ubi_dbg_dump_sv(sv) ({})
73#define ubi_dbg_dump_seb(seb, type) ({})
74#define ubi_dbg_dump_mkvol_req(req) ({})
75
76#endif /* CONFIG_MTD_UBI_DEBUG_MSG */
77 65
78#ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA 66#ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA
79/* Messages from the eraseblock association unit */ 67/* Messages from the eraseblock association sub-system */
80#define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) 68#define dbg_eba(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
81#else 69#else
82#define dbg_eba(fmt, ...) ({}) 70#define dbg_eba(fmt, ...) ({})
83#endif 71#endif
84 72
85#ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL 73#ifdef CONFIG_MTD_UBI_DEBUG_MSG_WL
86/* Messages from the wear-leveling unit */ 74/* Messages from the wear-leveling sub-system */
87#define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) 75#define dbg_wl(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
88#else 76#else
89#define dbg_wl(fmt, ...) ({}) 77#define dbg_wl(fmt, ...) ({})
90#endif 78#endif
91 79
92#ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO 80#ifdef CONFIG_MTD_UBI_DEBUG_MSG_IO
93/* Messages from the input/output unit */ 81/* Messages from the input/output sub-system */
94#define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) 82#define dbg_io(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
95#else 83#else
96#define dbg_io(fmt, ...) ({}) 84#define dbg_io(fmt, ...) ({})
@@ -105,6 +93,12 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
105#define UBI_IO_DEBUG 0 93#define UBI_IO_DEBUG 0
106#endif 94#endif
107 95
96#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
97#define DBG_DISABLE_BGT 1
98#else
99#define DBG_DISABLE_BGT 0
100#endif
101
108#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS 102#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
109/** 103/**
110 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. 104 * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
@@ -149,4 +143,30 @@ static inline int ubi_dbg_is_erase_failure(void)
149#define ubi_dbg_is_erase_failure() 0 143#define ubi_dbg_is_erase_failure() 0
150#endif 144#endif
151 145
146#else
147
148#define ubi_assert(expr) ({})
149#define dbg_err(fmt, ...) ({})
150#define dbg_msg(fmt, ...) ({})
151#define dbg_gen(fmt, ...) ({})
152#define dbg_eba(fmt, ...) ({})
153#define dbg_wl(fmt, ...) ({})
154#define dbg_io(fmt, ...) ({})
155#define dbg_bld(fmt, ...) ({})
156#define ubi_dbg_dump_stack() ({})
157#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
158#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
159#define ubi_dbg_dump_vol_info(vol) ({})
160#define ubi_dbg_dump_vtbl_record(r, idx) ({})
161#define ubi_dbg_dump_sv(sv) ({})
162#define ubi_dbg_dump_seb(seb, type) ({})
163#define ubi_dbg_dump_mkvol_req(req) ({})
164
165#define UBI_IO_DEBUG 0
166#define DBG_DISABLE_BGT 0
167#define ubi_dbg_is_bitflip() 0
168#define ubi_dbg_is_write_failure() 0
169#define ubi_dbg_is_erase_failure() 0
170
171#endif /* !CONFIG_MTD_UBI_DEBUG */
152#endif /* !__UBI_DEBUG_H__ */ 172#endif /* !__UBI_DEBUG_H__ */
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 7ce91ca742b1..e04bcf1dff87 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -19,20 +19,20 @@
19 */ 19 */
20 20
21/* 21/*
22 * The UBI Eraseblock Association (EBA) unit. 22 * The UBI Eraseblock Association (EBA) sub-system.
23 * 23 *
24 * This unit is responsible for I/O to/from logical eraseblock. 24 * This sub-system is responsible for I/O to/from logical eraseblock.
25 * 25 *
26 * Although in this implementation the EBA table is fully kept and managed in 26 * Although in this implementation the EBA table is fully kept and managed in
27 * RAM, which assumes poor scalability, it might be (partially) maintained on 27 * RAM, which assumes poor scalability, it might be (partially) maintained on
28 * flash in future implementations. 28 * flash in future implementations.
29 * 29 *
30 * The EBA unit implements per-logical eraseblock locking. Before accessing a 30 * The EBA sub-system implements per-logical eraseblock locking. Before
31 * logical eraseblock it is locked for reading or writing. The per-logical 31 * accessing a logical eraseblock it is locked for reading or writing. The
32 * eraseblock locking is implemented by means of the lock tree. The lock tree 32 * per-logical eraseblock locking is implemented by means of the lock tree. The
33 * is an RB-tree which refers all the currently locked logical eraseblocks. The 33 * lock tree is an RB-tree which refers all the currently locked logical
34 * lock tree elements are &struct ubi_ltree_entry objects. They are indexed by 34 * eraseblocks. The lock tree elements are &struct ubi_ltree_entry objects.
35 * (@vol_id, @lnum) pairs. 35 * They are indexed by (@vol_id, @lnum) pairs.
36 * 36 *
37 * EBA also maintains the global sequence counter which is incremented each 37 * EBA also maintains the global sequence counter which is incremented each
38 * time a logical eraseblock is mapped to a physical eraseblock and it is 38 * time a logical eraseblock is mapped to a physical eraseblock and it is
@@ -189,9 +189,7 @@ static struct ubi_ltree_entry *ltree_add_entry(struct ubi_device *ubi,
189 le->users += 1; 189 le->users += 1;
190 spin_unlock(&ubi->ltree_lock); 190 spin_unlock(&ubi->ltree_lock);
191 191
192 if (le_free) 192 kfree(le_free);
193 kfree(le_free);
194
195 return le; 193 return le;
196} 194}
197 195
@@ -223,22 +221,18 @@ static int leb_read_lock(struct ubi_device *ubi, int vol_id, int lnum)
223 */ 221 */
224static void leb_read_unlock(struct ubi_device *ubi, int vol_id, int lnum) 222static void leb_read_unlock(struct ubi_device *ubi, int vol_id, int lnum)
225{ 223{
226 int free = 0;
227 struct ubi_ltree_entry *le; 224 struct ubi_ltree_entry *le;
228 225
229 spin_lock(&ubi->ltree_lock); 226 spin_lock(&ubi->ltree_lock);
230 le = ltree_lookup(ubi, vol_id, lnum); 227 le = ltree_lookup(ubi, vol_id, lnum);
231 le->users -= 1; 228 le->users -= 1;
232 ubi_assert(le->users >= 0); 229 ubi_assert(le->users >= 0);
230 up_read(&le->mutex);
233 if (le->users == 0) { 231 if (le->users == 0) {
234 rb_erase(&le->rb, &ubi->ltree); 232 rb_erase(&le->rb, &ubi->ltree);
235 free = 1; 233 kfree(le);
236 } 234 }
237 spin_unlock(&ubi->ltree_lock); 235 spin_unlock(&ubi->ltree_lock);
238
239 up_read(&le->mutex);
240 if (free)
241 kfree(le);
242} 236}
243 237
244/** 238/**
@@ -274,7 +268,6 @@ static int leb_write_lock(struct ubi_device *ubi, int vol_id, int lnum)
274 */ 268 */
275static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum) 269static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum)
276{ 270{
277 int free;
278 struct ubi_ltree_entry *le; 271 struct ubi_ltree_entry *le;
279 272
280 le = ltree_add_entry(ubi, vol_id, lnum); 273 le = ltree_add_entry(ubi, vol_id, lnum);
@@ -289,12 +282,9 @@ static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum)
289 ubi_assert(le->users >= 0); 282 ubi_assert(le->users >= 0);
290 if (le->users == 0) { 283 if (le->users == 0) {
291 rb_erase(&le->rb, &ubi->ltree); 284 rb_erase(&le->rb, &ubi->ltree);
292 free = 1;
293 } else
294 free = 0;
295 spin_unlock(&ubi->ltree_lock);
296 if (free)
297 kfree(le); 285 kfree(le);
286 }
287 spin_unlock(&ubi->ltree_lock);
298 288
299 return 1; 289 return 1;
300} 290}
@@ -307,23 +297,18 @@ static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum)
307 */ 297 */
308static void leb_write_unlock(struct ubi_device *ubi, int vol_id, int lnum) 298static void leb_write_unlock(struct ubi_device *ubi, int vol_id, int lnum)
309{ 299{
310 int free;
311 struct ubi_ltree_entry *le; 300 struct ubi_ltree_entry *le;
312 301
313 spin_lock(&ubi->ltree_lock); 302 spin_lock(&ubi->ltree_lock);
314 le = ltree_lookup(ubi, vol_id, lnum); 303 le = ltree_lookup(ubi, vol_id, lnum);
315 le->users -= 1; 304 le->users -= 1;
316 ubi_assert(le->users >= 0); 305 ubi_assert(le->users >= 0);
306 up_write(&le->mutex);
317 if (le->users == 0) { 307 if (le->users == 0) {
318 rb_erase(&le->rb, &ubi->ltree); 308 rb_erase(&le->rb, &ubi->ltree);
319 free = 1;
320 } else
321 free = 0;
322 spin_unlock(&ubi->ltree_lock);
323
324 up_write(&le->mutex);
325 if (free)
326 kfree(le); 309 kfree(le);
310 }
311 spin_unlock(&ubi->ltree_lock);
327} 312}
328 313
329/** 314/**
@@ -516,9 +501,8 @@ static int recover_peb(struct ubi_device *ubi, int pnum, int vol_id, int lnum,
516 struct ubi_vid_hdr *vid_hdr; 501 struct ubi_vid_hdr *vid_hdr;
517 502
518 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); 503 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
519 if (!vid_hdr) { 504 if (!vid_hdr)
520 return -ENOMEM; 505 return -ENOMEM;
521 }
522 506
523 mutex_lock(&ubi->buf_mutex); 507 mutex_lock(&ubi->buf_mutex);
524 508
@@ -752,7 +736,7 @@ int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
752 /* If this is the last LEB @len may be unaligned */ 736 /* If this is the last LEB @len may be unaligned */
753 len = ALIGN(data_size, ubi->min_io_size); 737 len = ALIGN(data_size, ubi->min_io_size);
754 else 738 else
755 ubi_assert(len % ubi->min_io_size == 0); 739 ubi_assert(!(len & (ubi->min_io_size - 1)));
756 740
757 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); 741 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
758 if (!vid_hdr) 742 if (!vid_hdr)
@@ -919,7 +903,7 @@ retry:
919 } 903 }
920 904
921 if (vol->eba_tbl[lnum] >= 0) { 905 if (vol->eba_tbl[lnum] >= 0) {
922 err = ubi_wl_put_peb(ubi, vol->eba_tbl[lnum], 1); 906 err = ubi_wl_put_peb(ubi, vol->eba_tbl[lnum], 0);
923 if (err) 907 if (err)
924 goto out_leb_unlock; 908 goto out_leb_unlock;
925 } 909 }
@@ -1141,7 +1125,7 @@ out_unlock_leb:
1141} 1125}
1142 1126
1143/** 1127/**
1144 * ubi_eba_init_scan - initialize the EBA unit using scanning information. 1128 * ubi_eba_init_scan - initialize the EBA sub-system using scanning information.
1145 * @ubi: UBI device description object 1129 * @ubi: UBI device description object
1146 * @si: scanning information 1130 * @si: scanning information
1147 * 1131 *
@@ -1156,7 +1140,7 @@ int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si)
1156 struct ubi_scan_leb *seb; 1140 struct ubi_scan_leb *seb;
1157 struct rb_node *rb; 1141 struct rb_node *rb;
1158 1142
1159 dbg_eba("initialize EBA unit"); 1143 dbg_eba("initialize EBA sub-system");
1160 1144
1161 spin_lock_init(&ubi->ltree_lock); 1145 spin_lock_init(&ubi->ltree_lock);
1162 mutex_init(&ubi->alc_mutex); 1146 mutex_init(&ubi->alc_mutex);
@@ -1222,7 +1206,7 @@ int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si)
1222 ubi->rsvd_pebs += ubi->beb_rsvd_pebs; 1206 ubi->rsvd_pebs += ubi->beb_rsvd_pebs;
1223 } 1207 }
1224 1208
1225 dbg_eba("EBA unit is initialized"); 1209 dbg_eba("EBA sub-system is initialized");
1226 return 0; 1210 return 0;
1227 1211
1228out_free: 1212out_free:
@@ -1233,20 +1217,3 @@ out_free:
1233 } 1217 }
1234 return err; 1218 return err;
1235} 1219}
1236
1237/**
1238 * ubi_eba_close - close EBA unit.
1239 * @ubi: UBI device description object
1240 */
1241void ubi_eba_close(const struct ubi_device *ubi)
1242{
1243 int i, num_volumes = ubi->vtbl_slots + UBI_INT_VOL_COUNT;
1244
1245 dbg_eba("close EBA unit");
1246
1247 for (i = 0; i < num_volumes; i++) {
1248 if (!ubi->volumes[i])
1249 continue;
1250 kfree(ubi->volumes[i]->eba_tbl);
1251 }
1252}
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index e909b390069a..605812bb0b1a 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -111,7 +111,7 @@ static int gluebi_read(struct mtd_info *mtd, loff_t from, size_t len,
111 struct ubi_device *ubi; 111 struct ubi_device *ubi;
112 uint64_t tmp = from; 112 uint64_t tmp = from;
113 113
114 dbg_msg("read %zd bytes from offset %lld", len, from); 114 dbg_gen("read %zd bytes from offset %lld", len, from);
115 115
116 if (len < 0 || from < 0 || from + len > mtd->size) 116 if (len < 0 || from < 0 || from + len > mtd->size)
117 return -EINVAL; 117 return -EINVAL;
@@ -162,7 +162,7 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len,
162 struct ubi_device *ubi; 162 struct ubi_device *ubi;
163 uint64_t tmp = to; 163 uint64_t tmp = to;
164 164
165 dbg_msg("write %zd bytes to offset %lld", len, to); 165 dbg_gen("write %zd bytes to offset %lld", len, to);
166 166
167 if (len < 0 || to < 0 || len + to > mtd->size) 167 if (len < 0 || to < 0 || len + to > mtd->size)
168 return -EINVAL; 168 return -EINVAL;
@@ -215,7 +215,7 @@ static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr)
215 struct ubi_volume *vol; 215 struct ubi_volume *vol;
216 struct ubi_device *ubi; 216 struct ubi_device *ubi;
217 217
218 dbg_msg("erase %u bytes at offset %u", instr->len, instr->addr); 218 dbg_gen("erase %u bytes at offset %u", instr->len, instr->addr);
219 219
220 if (instr->addr < 0 || instr->addr > mtd->size - mtd->erasesize) 220 if (instr->addr < 0 || instr->addr > mtd->size - mtd->erasesize)
221 return -EINVAL; 221 return -EINVAL;
@@ -249,8 +249,8 @@ static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr)
249 if (err) 249 if (err)
250 goto out_err; 250 goto out_err;
251 251
252 instr->state = MTD_ERASE_DONE; 252 instr->state = MTD_ERASE_DONE;
253 mtd_erase_callback(instr); 253 mtd_erase_callback(instr);
254 return 0; 254 return 0;
255 255
256out_err: 256out_err:
@@ -299,12 +299,12 @@ int ubi_create_gluebi(struct ubi_device *ubi, struct ubi_volume *vol)
299 mtd->size = vol->used_bytes; 299 mtd->size = vol->used_bytes;
300 300
301 if (add_mtd_device(mtd)) { 301 if (add_mtd_device(mtd)) {
302 ubi_err("cannot not add MTD device\n"); 302 ubi_err("cannot not add MTD device");
303 kfree(mtd->name); 303 kfree(mtd->name);
304 return -ENFILE; 304 return -ENFILE;
305 } 305 }
306 306
307 dbg_msg("added mtd%d (\"%s\"), size %u, EB size %u", 307 dbg_gen("added mtd%d (\"%s\"), size %u, EB size %u",
308 mtd->index, mtd->name, mtd->size, mtd->erasesize); 308 mtd->index, mtd->name, mtd->size, mtd->erasesize);
309 return 0; 309 return 0;
310} 310}
@@ -322,7 +322,7 @@ int ubi_destroy_gluebi(struct ubi_volume *vol)
322 int err; 322 int err;
323 struct mtd_info *mtd = &vol->gluebi_mtd; 323 struct mtd_info *mtd = &vol->gluebi_mtd;
324 324
325 dbg_msg("remove mtd%d", mtd->index); 325 dbg_gen("remove mtd%d", mtd->index);
326 err = del_mtd_device(mtd); 326 err = del_mtd_device(mtd);
327 if (err) 327 if (err)
328 return err; 328 return err;
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 4ac11df7b048..2fb64be44f1b 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -20,15 +20,15 @@
20 */ 20 */
21 21
22/* 22/*
23 * UBI input/output unit. 23 * UBI input/output sub-system.
24 * 24 *
25 * This unit provides a uniform way to work with all kinds of the underlying 25 * This sub-system provides a uniform way to work with all kinds of the
26 * MTD devices. It also implements handy functions for reading and writing UBI 26 * underlying MTD devices. It also implements handy functions for reading and
27 * headers. 27 * writing UBI headers.
28 * 28 *
29 * We are trying to have a paranoid mindset and not to trust to what we read 29 * We are trying to have a paranoid mindset and not to trust to what we read
30 * from the flash media in order to be more secure and robust. So this unit 30 * from the flash media in order to be more secure and robust. So this
31 * validates every single header it reads from the flash media. 31 * sub-system validates every single header it reads from the flash media.
32 * 32 *
33 * Some words about how the eraseblock headers are stored. 33 * Some words about how the eraseblock headers are stored.
34 * 34 *
@@ -79,11 +79,11 @@
79 * 512-byte chunks, we have to allocate one more buffer and copy our VID header 79 * 512-byte chunks, we have to allocate one more buffer and copy our VID header
80 * to offset 448 of this buffer. 80 * to offset 448 of this buffer.
81 * 81 *
82 * The I/O unit does the following trick in order to avoid this extra copy. 82 * The I/O sub-system does the following trick in order to avoid this extra
83 * It always allocates a @ubi->vid_hdr_alsize bytes buffer for the VID header 83 * copy. It always allocates a @ubi->vid_hdr_alsize bytes buffer for the VID
84 * and returns a pointer to offset @ubi->vid_hdr_shift of this buffer. When the 84 * header and returns a pointer to offset @ubi->vid_hdr_shift of this buffer.
85 * VID header is being written out, it shifts the VID header pointer back and 85 * When the VID header is being written out, it shifts the VID header pointer
86 * writes the whole sub-page. 86 * back and writes the whole sub-page.
87 */ 87 */
88 88
89#include <linux/crc32.h> 89#include <linux/crc32.h>
@@ -156,15 +156,19 @@ retry:
156 /* 156 /*
157 * -EUCLEAN is reported if there was a bit-flip which 157 * -EUCLEAN is reported if there was a bit-flip which
158 * was corrected, so this is harmless. 158 * was corrected, so this is harmless.
159 *
160 * We do not report about it here unless debugging is
161 * enabled. A corresponding message will be printed
162 * later, when it is has been scrubbed.
159 */ 163 */
160 ubi_msg("fixable bit-flip detected at PEB %d", pnum); 164 dbg_msg("fixable bit-flip detected at PEB %d", pnum);
161 ubi_assert(len == read); 165 ubi_assert(len == read);
162 return UBI_IO_BITFLIPS; 166 return UBI_IO_BITFLIPS;
163 } 167 }
164 168
165 if (read != len && retries++ < UBI_IO_RETRIES) { 169 if (read != len && retries++ < UBI_IO_RETRIES) {
166 dbg_io("error %d while reading %d bytes from PEB %d:%d, " 170 dbg_io("error %d while reading %d bytes from PEB %d:%d,"
167 "read only %zd bytes, retry", 171 " read only %zd bytes, retry",
168 err, len, pnum, offset, read); 172 err, len, pnum, offset, read);
169 yield(); 173 yield();
170 goto retry; 174 goto retry;
@@ -187,7 +191,7 @@ retry:
187 ubi_assert(len == read); 191 ubi_assert(len == read);
188 192
189 if (ubi_dbg_is_bitflip()) { 193 if (ubi_dbg_is_bitflip()) {
190 dbg_msg("bit-flip (emulated)"); 194 dbg_gen("bit-flip (emulated)");
191 err = UBI_IO_BITFLIPS; 195 err = UBI_IO_BITFLIPS;
192 } 196 }
193 } 197 }
@@ -391,6 +395,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
391{ 395{
392 int err, i, patt_count; 396 int err, i, patt_count;
393 397
398 ubi_msg("run torture test for PEB %d", pnum);
394 patt_count = ARRAY_SIZE(patterns); 399 patt_count = ARRAY_SIZE(patterns);
395 ubi_assert(patt_count > 0); 400 ubi_assert(patt_count > 0);
396 401
@@ -434,6 +439,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
434 } 439 }
435 440
436 err = patt_count; 441 err = patt_count;
442 ubi_msg("PEB %d passed torture test, do not mark it a bad", pnum);
437 443
438out: 444out:
439 mutex_unlock(&ubi->buf_mutex); 445 mutex_unlock(&ubi->buf_mutex);
@@ -699,8 +705,8 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
699 705
700 if (hdr_crc != crc) { 706 if (hdr_crc != crc) {
701 if (verbose) { 707 if (verbose) {
702 ubi_warn("bad EC header CRC at PEB %d, calculated %#08x," 708 ubi_warn("bad EC header CRC at PEB %d, calculated "
703 " read %#08x", pnum, crc, hdr_crc); 709 "%#08x, read %#08x", pnum, crc, hdr_crc);
704 ubi_dbg_dump_ec_hdr(ec_hdr); 710 ubi_dbg_dump_ec_hdr(ec_hdr);
705 } 711 }
706 return UBI_IO_BAD_EC_HDR; 712 return UBI_IO_BAD_EC_HDR;
@@ -1095,8 +1101,7 @@ fail:
1095} 1101}
1096 1102
1097/** 1103/**
1098 * paranoid_check_peb_ec_hdr - check that the erase counter header of a 1104 * paranoid_check_peb_ec_hdr - check erase counter header.
1099 * physical eraseblock is in-place and is all right.
1100 * @ubi: UBI device description object 1105 * @ubi: UBI device description object
1101 * @pnum: the physical eraseblock number to check 1106 * @pnum: the physical eraseblock number to check
1102 * 1107 *
@@ -1174,8 +1179,7 @@ fail:
1174} 1179}
1175 1180
1176/** 1181/**
1177 * paranoid_check_peb_vid_hdr - check that the volume identifier header of a 1182 * paranoid_check_peb_vid_hdr - check volume identifier header.
1178 * physical eraseblock is in-place and is all right.
1179 * @ubi: UBI device description object 1183 * @ubi: UBI device description object
1180 * @pnum: the physical eraseblock number to check 1184 * @pnum: the physical eraseblock number to check
1181 * 1185 *
@@ -1256,7 +1260,7 @@ static int paranoid_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
1256 1260
1257fail: 1261fail:
1258 ubi_err("paranoid check failed for PEB %d", pnum); 1262 ubi_err("paranoid check failed for PEB %d", pnum);
1259 dbg_msg("hex dump of the %d-%d region", offset, offset + len); 1263 ubi_msg("hex dump of the %d-%d region", offset, offset + len);
1260 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1264 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1261 ubi->dbg_peb_buf, len, 1); 1265 ubi->dbg_peb_buf, len, 1);
1262 err = 1; 1266 err = 1;
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index a70d58823f8d..5d9bcf109c13 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -106,7 +106,7 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
106 struct ubi_device *ubi; 106 struct ubi_device *ubi;
107 struct ubi_volume *vol; 107 struct ubi_volume *vol;
108 108
109 dbg_msg("open device %d volume %d, mode %d", ubi_num, vol_id, mode); 109 dbg_gen("open device %d volume %d, mode %d", ubi_num, vol_id, mode);
110 110
111 if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES) 111 if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES)
112 return ERR_PTR(-EINVAL); 112 return ERR_PTR(-EINVAL);
@@ -215,7 +215,7 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
215 struct ubi_device *ubi; 215 struct ubi_device *ubi;
216 struct ubi_volume_desc *ret; 216 struct ubi_volume_desc *ret;
217 217
218 dbg_msg("open volume %s, mode %d", name, mode); 218 dbg_gen("open volume %s, mode %d", name, mode);
219 219
220 if (!name) 220 if (!name)
221 return ERR_PTR(-EINVAL); 221 return ERR_PTR(-EINVAL);
@@ -266,7 +266,7 @@ void ubi_close_volume(struct ubi_volume_desc *desc)
266 struct ubi_volume *vol = desc->vol; 266 struct ubi_volume *vol = desc->vol;
267 struct ubi_device *ubi = vol->ubi; 267 struct ubi_device *ubi = vol->ubi;
268 268
269 dbg_msg("close volume %d, mode %d", vol->vol_id, desc->mode); 269 dbg_gen("close volume %d, mode %d", vol->vol_id, desc->mode);
270 270
271 spin_lock(&ubi->volumes_lock); 271 spin_lock(&ubi->volumes_lock);
272 switch (desc->mode) { 272 switch (desc->mode) {
@@ -323,7 +323,7 @@ int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
323 struct ubi_device *ubi = vol->ubi; 323 struct ubi_device *ubi = vol->ubi;
324 int err, vol_id = vol->vol_id; 324 int err, vol_id = vol->vol_id;
325 325
326 dbg_msg("read %d bytes from LEB %d:%d:%d", len, vol_id, lnum, offset); 326 dbg_gen("read %d bytes from LEB %d:%d:%d", len, vol_id, lnum, offset);
327 327
328 if (vol_id < 0 || vol_id >= ubi->vtbl_slots || lnum < 0 || 328 if (vol_id < 0 || vol_id >= ubi->vtbl_slots || lnum < 0 ||
329 lnum >= vol->used_ebs || offset < 0 || len < 0 || 329 lnum >= vol->used_ebs || offset < 0 || len < 0 ||
@@ -388,7 +388,7 @@ int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
388 struct ubi_device *ubi = vol->ubi; 388 struct ubi_device *ubi = vol->ubi;
389 int vol_id = vol->vol_id; 389 int vol_id = vol->vol_id;
390 390
391 dbg_msg("write %d bytes to LEB %d:%d:%d", len, vol_id, lnum, offset); 391 dbg_gen("write %d bytes to LEB %d:%d:%d", len, vol_id, lnum, offset);
392 392
393 if (vol_id < 0 || vol_id >= ubi->vtbl_slots) 393 if (vol_id < 0 || vol_id >= ubi->vtbl_slots)
394 return -EINVAL; 394 return -EINVAL;
@@ -397,8 +397,8 @@ int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
397 return -EROFS; 397 return -EROFS;
398 398
399 if (lnum < 0 || lnum >= vol->reserved_pebs || offset < 0 || len < 0 || 399 if (lnum < 0 || lnum >= vol->reserved_pebs || offset < 0 || len < 0 ||
400 offset + len > vol->usable_leb_size || offset % ubi->min_io_size || 400 offset + len > vol->usable_leb_size ||
401 len % ubi->min_io_size) 401 offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1))
402 return -EINVAL; 402 return -EINVAL;
403 403
404 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM && 404 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM &&
@@ -438,7 +438,7 @@ int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
438 struct ubi_device *ubi = vol->ubi; 438 struct ubi_device *ubi = vol->ubi;
439 int vol_id = vol->vol_id; 439 int vol_id = vol->vol_id;
440 440
441 dbg_msg("atomically write %d bytes to LEB %d:%d", len, vol_id, lnum); 441 dbg_gen("atomically write %d bytes to LEB %d:%d", len, vol_id, lnum);
442 442
443 if (vol_id < 0 || vol_id >= ubi->vtbl_slots) 443 if (vol_id < 0 || vol_id >= ubi->vtbl_slots)
444 return -EINVAL; 444 return -EINVAL;
@@ -447,7 +447,7 @@ int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
447 return -EROFS; 447 return -EROFS;
448 448
449 if (lnum < 0 || lnum >= vol->reserved_pebs || len < 0 || 449 if (lnum < 0 || lnum >= vol->reserved_pebs || len < 0 ||
450 len > vol->usable_leb_size || len % ubi->min_io_size) 450 len > vol->usable_leb_size || len & (ubi->min_io_size - 1))
451 return -EINVAL; 451 return -EINVAL;
452 452
453 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM && 453 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM &&
@@ -482,7 +482,7 @@ int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum)
482 struct ubi_device *ubi = vol->ubi; 482 struct ubi_device *ubi = vol->ubi;
483 int err; 483 int err;
484 484
485 dbg_msg("erase LEB %d:%d", vol->vol_id, lnum); 485 dbg_gen("erase LEB %d:%d", vol->vol_id, lnum);
486 486
487 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) 487 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
488 return -EROFS; 488 return -EROFS;
@@ -542,7 +542,7 @@ int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum)
542 struct ubi_volume *vol = desc->vol; 542 struct ubi_volume *vol = desc->vol;
543 struct ubi_device *ubi = vol->ubi; 543 struct ubi_device *ubi = vol->ubi;
544 544
545 dbg_msg("unmap LEB %d:%d", vol->vol_id, lnum); 545 dbg_gen("unmap LEB %d:%d", vol->vol_id, lnum);
546 546
547 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) 547 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
548 return -EROFS; 548 return -EROFS;
@@ -579,7 +579,7 @@ int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype)
579 struct ubi_volume *vol = desc->vol; 579 struct ubi_volume *vol = desc->vol;
580 struct ubi_device *ubi = vol->ubi; 580 struct ubi_device *ubi = vol->ubi;
581 581
582 dbg_msg("unmap LEB %d:%d", vol->vol_id, lnum); 582 dbg_gen("unmap LEB %d:%d", vol->vol_id, lnum);
583 583
584 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) 584 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
585 return -EROFS; 585 return -EROFS;
@@ -621,7 +621,7 @@ int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum)
621{ 621{
622 struct ubi_volume *vol = desc->vol; 622 struct ubi_volume *vol = desc->vol;
623 623
624 dbg_msg("test LEB %d:%d", vol->vol_id, lnum); 624 dbg_gen("test LEB %d:%d", vol->vol_id, lnum);
625 625
626 if (lnum < 0 || lnum >= vol->reserved_pebs) 626 if (lnum < 0 || lnum >= vol->reserved_pebs)
627 return -EINVAL; 627 return -EINVAL;
@@ -632,3 +632,27 @@ int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum)
632 return vol->eba_tbl[lnum] >= 0; 632 return vol->eba_tbl[lnum] >= 0;
633} 633}
634EXPORT_SYMBOL_GPL(ubi_is_mapped); 634EXPORT_SYMBOL_GPL(ubi_is_mapped);
635
636/**
637 * ubi_sync - synchronize UBI device buffers.
638 * @ubi_num: UBI device to synchronize
639 *
640 * The underlying MTD device may cache data in hardware or in software. This
641 * function ensures the caches are flushed. Returns zero in case of success and
642 * a negative error code in case of failure.
643 */
644int ubi_sync(int ubi_num)
645{
646 struct ubi_device *ubi;
647
648 ubi = ubi_get_device(ubi_num);
649 if (!ubi)
650 return -ENODEV;
651
652 if (ubi->mtd->sync)
653 ubi->mtd->sync(ubi->mtd);
654
655 ubi_put_device(ubi);
656 return 0;
657}
658EXPORT_SYMBOL_GPL(ubi_sync);
diff --git a/drivers/mtd/ubi/misc.c b/drivers/mtd/ubi/misc.c
index 93e052812012..22ad31402945 100644
--- a/drivers/mtd/ubi/misc.c
+++ b/drivers/mtd/ubi/misc.c
@@ -37,7 +37,7 @@ int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf,
37{ 37{
38 int i; 38 int i;
39 39
40 ubi_assert(length % ubi->min_io_size == 0); 40 ubi_assert(!(length & (ubi->min_io_size - 1)));
41 41
42 for (i = length - 1; i >= 0; i--) 42 for (i = length - 1; i >= 0; i--)
43 if (((const uint8_t *)buf)[i] != 0xFF) 43 if (((const uint8_t *)buf)[i] != 0xFF)
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 96d410e106ab..967bb4406df9 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -19,9 +19,9 @@
19 */ 19 */
20 20
21/* 21/*
22 * UBI scanning unit. 22 * UBI scanning sub-system.
23 * 23 *
24 * This unit is responsible for scanning the flash media, checking UBI 24 * This sub-system is responsible for scanning the flash media, checking UBI
25 * headers and providing complete information about the UBI flash image. 25 * headers and providing complete information about the UBI flash image.
26 * 26 *
27 * The scanning information is represented by a &struct ubi_scan_info' object. 27 * The scanning information is represented by a &struct ubi_scan_info' object.
@@ -93,8 +93,7 @@ static int add_to_list(struct ubi_scan_info *si, int pnum, int ec,
93} 93}
94 94
95/** 95/**
96 * validate_vid_hdr - check that volume identifier header is correct and 96 * validate_vid_hdr - check volume identifier header.
97 * consistent.
98 * @vid_hdr: the volume identifier header to check 97 * @vid_hdr: the volume identifier header to check
99 * @sv: information about the volume this logical eraseblock belongs to 98 * @sv: information about the volume this logical eraseblock belongs to
100 * @pnum: physical eraseblock number the VID header came from 99 * @pnum: physical eraseblock number the VID header came from
@@ -103,7 +102,7 @@ static int add_to_list(struct ubi_scan_info *si, int pnum, int ec,
103 * non-zero if an inconsistency was found and zero if not. 102 * non-zero if an inconsistency was found and zero if not.
104 * 103 *
105 * Note, UBI does sanity check of everything it reads from the flash media. 104 * Note, UBI does sanity check of everything it reads from the flash media.
106 * Most of the checks are done in the I/O unit. Here we check that the 105 * Most of the checks are done in the I/O sub-system. Here we check that the
107 * information in the VID header is consistent to the information in other VID 106 * information in the VID header is consistent to the information in other VID
108 * headers of the same volume. 107 * headers of the same volume.
109 */ 108 */
@@ -247,45 +246,21 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb,
247 struct ubi_vid_hdr *vh = NULL; 246 struct ubi_vid_hdr *vh = NULL;
248 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); 247 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum);
249 248
250 if (seb->sqnum == 0 && sqnum2 == 0) { 249 if (sqnum2 == seb->sqnum) {
251 long long abs, v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver);
252
253 /* 250 /*
254 * UBI constantly increases the logical eraseblock version 251 * This must be a really ancient UBI image which has been
255 * number and it can overflow. Thus, we have to bear in mind 252 * created before sequence numbers support has been added. At
256 * that versions that are close to %0xFFFFFFFF are less then 253 * that times we used 32-bit LEB versions stored in logical
257 * versions that are close to %0. 254 * eraseblocks. That was before UBI got into mainline. We do not
258 * 255 * support these images anymore. Well, those images will work
259 * The UBI WL unit guarantees that the number of pending tasks 256 * still work, but only if no unclean reboots happened.
260 * is not greater then %0x7FFFFFFF. So, if the difference
261 * between any two versions is greater or equivalent to
262 * %0x7FFFFFFF, there was an overflow and the logical
263 * eraseblock with lower version is actually newer then the one
264 * with higher version.
265 *
266 * FIXME: but this is anyway obsolete and will be removed at
267 * some point.
268 */ 257 */
269 dbg_bld("using old crappy leb_ver stuff"); 258 ubi_err("unsupported on-flash UBI format\n");
270 259 return -EINVAL;
271 if (v1 == v2) { 260 }
272 ubi_err("PEB %d and PEB %d have the same version %lld",
273 seb->pnum, pnum, v1);
274 return -EINVAL;
275 }
276
277 abs = v1 - v2;
278 if (abs < 0)
279 abs = -abs;
280 261
281 if (abs < 0x7FFFFFFF) 262 /* Obviously the LEB with lower sequence counter is older */
282 /* Non-overflow situation */ 263 second_is_newer = !!(sqnum2 > seb->sqnum);
283 second_is_newer = (v2 > v1);
284 else
285 second_is_newer = (v2 < v1);
286 } else
287 /* Obviously the LEB with lower sequence counter is older */
288 second_is_newer = sqnum2 > seb->sqnum;
289 264
290 /* 265 /*
291 * Now we know which copy is newer. If the copy flag of the PEB with 266 * Now we know which copy is newer. If the copy flag of the PEB with
@@ -293,7 +268,7 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb,
293 * check data CRC. For the second PEB we already have the VID header, 268 * check data CRC. For the second PEB we already have the VID header,
294 * for the first one - we'll need to re-read it from flash. 269 * for the first one - we'll need to re-read it from flash.
295 * 270 *
296 * FIXME: this may be optimized so that we wouldn't read twice. 271 * Note: this may be optimized so that we wouldn't read twice.
297 */ 272 */
298 273
299 if (second_is_newer) { 274 if (second_is_newer) {
@@ -379,8 +354,7 @@ out_free_vidh:
379} 354}
380 355
381/** 356/**
382 * ubi_scan_add_used - add information about a physical eraseblock to the 357 * ubi_scan_add_used - add physical eraseblock to the scanning information.
383 * scanning information.
384 * @ubi: UBI device description object 358 * @ubi: UBI device description object
385 * @si: scanning information 359 * @si: scanning information
386 * @pnum: the physical eraseblock number 360 * @pnum: the physical eraseblock number
@@ -400,7 +374,6 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
400 int bitflips) 374 int bitflips)
401{ 375{
402 int err, vol_id, lnum; 376 int err, vol_id, lnum;
403 uint32_t leb_ver;
404 unsigned long long sqnum; 377 unsigned long long sqnum;
405 struct ubi_scan_volume *sv; 378 struct ubi_scan_volume *sv;
406 struct ubi_scan_leb *seb; 379 struct ubi_scan_leb *seb;
@@ -409,10 +382,9 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
409 vol_id = be32_to_cpu(vid_hdr->vol_id); 382 vol_id = be32_to_cpu(vid_hdr->vol_id);
410 lnum = be32_to_cpu(vid_hdr->lnum); 383 lnum = be32_to_cpu(vid_hdr->lnum);
411 sqnum = be64_to_cpu(vid_hdr->sqnum); 384 sqnum = be64_to_cpu(vid_hdr->sqnum);
412 leb_ver = be32_to_cpu(vid_hdr->leb_ver);
413 385
414 dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, ver %u, bitflips %d", 386 dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, bitflips %d",
415 pnum, vol_id, lnum, ec, sqnum, leb_ver, bitflips); 387 pnum, vol_id, lnum, ec, sqnum, bitflips);
416 388
417 sv = add_volume(si, vol_id, pnum, vid_hdr); 389 sv = add_volume(si, vol_id, pnum, vid_hdr);
418 if (IS_ERR(sv) < 0) 390 if (IS_ERR(sv) < 0)
@@ -445,25 +417,20 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
445 */ 417 */
446 418
447 dbg_bld("this LEB already exists: PEB %d, sqnum %llu, " 419 dbg_bld("this LEB already exists: PEB %d, sqnum %llu, "
448 "LEB ver %u, EC %d", seb->pnum, seb->sqnum, 420 "EC %d", seb->pnum, seb->sqnum, seb->ec);
449 seb->leb_ver, seb->ec);
450
451 /*
452 * Make sure that the logical eraseblocks have different
453 * versions. Otherwise the image is bad.
454 */
455 if (seb->leb_ver == leb_ver && leb_ver != 0) {
456 ubi_err("two LEBs with same version %u", leb_ver);
457 ubi_dbg_dump_seb(seb, 0);
458 ubi_dbg_dump_vid_hdr(vid_hdr);
459 return -EINVAL;
460 }
461 421
462 /* 422 /*
463 * Make sure that the logical eraseblocks have different 423 * Make sure that the logical eraseblocks have different
464 * sequence numbers. Otherwise the image is bad. 424 * sequence numbers. Otherwise the image is bad.
465 * 425 *
466 * FIXME: remove 'sqnum != 0' check when leb_ver is removed. 426 * However, if the sequence number is zero, we assume it must
427 * be an ancient UBI image from the era when UBI did not have
428 * sequence numbers. We still can attach these images, unless
429 * there is a need to distinguish between old and new
430 * eraseblocks, in which case we'll refuse the image in
431 * 'compare_lebs()'. In other words, we attach old clean
432 * images, but refuse attaching old images with duplicated
433 * logical eraseblocks because there was an unclean reboot.
467 */ 434 */
468 if (seb->sqnum == sqnum && sqnum != 0) { 435 if (seb->sqnum == sqnum && sqnum != 0) {
469 ubi_err("two LEBs with same sequence number %llu", 436 ubi_err("two LEBs with same sequence number %llu",
@@ -503,7 +470,6 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
503 seb->pnum = pnum; 470 seb->pnum = pnum;
504 seb->scrub = ((cmp_res & 2) || bitflips); 471 seb->scrub = ((cmp_res & 2) || bitflips);
505 seb->sqnum = sqnum; 472 seb->sqnum = sqnum;
506 seb->leb_ver = leb_ver;
507 473
508 if (sv->highest_lnum == lnum) 474 if (sv->highest_lnum == lnum)
509 sv->last_data_size = 475 sv->last_data_size =
@@ -540,7 +506,6 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
540 seb->lnum = lnum; 506 seb->lnum = lnum;
541 seb->sqnum = sqnum; 507 seb->sqnum = sqnum;
542 seb->scrub = bitflips; 508 seb->scrub = bitflips;
543 seb->leb_ver = leb_ver;
544 509
545 if (sv->highest_lnum <= lnum) { 510 if (sv->highest_lnum <= lnum) {
546 sv->highest_lnum = lnum; 511 sv->highest_lnum = lnum;
@@ -554,8 +519,7 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
554} 519}
555 520
556/** 521/**
557 * ubi_scan_find_sv - find information about a particular volume in the 522 * ubi_scan_find_sv - find volume in the scanning information.
558 * scanning information.
559 * @si: scanning information 523 * @si: scanning information
560 * @vol_id: the requested volume ID 524 * @vol_id: the requested volume ID
561 * 525 *
@@ -584,8 +548,7 @@ struct ubi_scan_volume *ubi_scan_find_sv(const struct ubi_scan_info *si,
584} 548}
585 549
586/** 550/**
587 * ubi_scan_find_seb - find information about a particular logical 551 * ubi_scan_find_seb - find LEB in the volume scanning information.
588 * eraseblock in the volume scanning information.
589 * @sv: a pointer to the volume scanning information 552 * @sv: a pointer to the volume scanning information
590 * @lnum: the requested logical eraseblock 553 * @lnum: the requested logical eraseblock
591 * 554 *
@@ -645,9 +608,9 @@ void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv)
645 * 608 *
646 * This function erases physical eraseblock 'pnum', and writes the erase 609 * This function erases physical eraseblock 'pnum', and writes the erase
647 * counter header to it. This function should only be used on UBI device 610 * counter header to it. This function should only be used on UBI device
648 * initialization stages, when the EBA unit had not been yet initialized. This 611 * initialization stages, when the EBA sub-system had not been yet initialized.
649 * function returns zero in case of success and a negative error code in case 612 * This function returns zero in case of success and a negative error code in
650 * of failure. 613 * case of failure.
651 */ 614 */
652int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si, 615int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si,
653 int pnum, int ec) 616 int pnum, int ec)
@@ -687,9 +650,10 @@ out_free:
687 * @si: scanning information 650 * @si: scanning information
688 * 651 *
689 * This function returns a free physical eraseblock. It is supposed to be 652 * This function returns a free physical eraseblock. It is supposed to be
690 * called on the UBI initialization stages when the wear-leveling unit is not 653 * called on the UBI initialization stages when the wear-leveling sub-system is
691 * initialized yet. This function picks a physical eraseblocks from one of the 654 * not initialized yet. This function picks a physical eraseblocks from one of
692 * lists, writes the EC header if it is needed, and removes it from the list. 655 * the lists, writes the EC header if it is needed, and removes it from the
656 * list.
693 * 657 *
694 * This function returns scanning physical eraseblock information in case of 658 * This function returns scanning physical eraseblock information in case of
695 * success and an error code in case of failure. 659 * success and an error code in case of failure.
@@ -742,8 +706,7 @@ struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi,
742} 706}
743 707
744/** 708/**
745 * process_eb - read UBI headers, check them and add corresponding data 709 * process_eb - read, check UBI headers, and add them to scanning information.
746 * to the scanning information.
747 * @ubi: UBI device description object 710 * @ubi: UBI device description object
748 * @si: scanning information 711 * @si: scanning information
749 * @pnum: the physical eraseblock number 712 * @pnum: the physical eraseblock number
@@ -751,7 +714,8 @@ struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi,
751 * This function returns a zero if the physical eraseblock was successfully 714 * This function returns a zero if the physical eraseblock was successfully
752 * handled and a negative error code in case of failure. 715 * handled and a negative error code in case of failure.
753 */ 716 */
754static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum) 717static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
718 int pnum)
755{ 719{
756 long long uninitialized_var(ec); 720 long long uninitialized_var(ec);
757 int err, bitflips = 0, vol_id, ec_corr = 0; 721 int err, bitflips = 0, vol_id, ec_corr = 0;
@@ -764,8 +728,9 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum
764 return err; 728 return err;
765 else if (err) { 729 else if (err) {
766 /* 730 /*
767 * FIXME: this is actually duty of the I/O unit to initialize 731 * FIXME: this is actually duty of the I/O sub-system to
768 * this, but MTD does not provide enough information. 732 * initialize this, but MTD does not provide enough
733 * information.
769 */ 734 */
770 si->bad_peb_count += 1; 735 si->bad_peb_count += 1;
771 return 0; 736 return 0;
@@ -930,7 +895,7 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
930 for (pnum = 0; pnum < ubi->peb_count; pnum++) { 895 for (pnum = 0; pnum < ubi->peb_count; pnum++) {
931 cond_resched(); 896 cond_resched();
932 897
933 dbg_msg("process PEB %d", pnum); 898 dbg_gen("process PEB %d", pnum);
934 err = process_eb(ubi, si, pnum); 899 err = process_eb(ubi, si, pnum);
935 if (err < 0) 900 if (err < 0)
936 goto out_vidh; 901 goto out_vidh;
@@ -1079,8 +1044,7 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si)
1079#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 1044#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
1080 1045
1081/** 1046/**
1082 * paranoid_check_si - check if the scanning information is correct and 1047 * paranoid_check_si - check the scanning information.
1083 * consistent.
1084 * @ubi: UBI device description object 1048 * @ubi: UBI device description object
1085 * @si: scanning information 1049 * @si: scanning information
1086 * 1050 *
@@ -1265,11 +1229,6 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
1265 ubi_err("bad data_pad %d", sv->data_pad); 1229 ubi_err("bad data_pad %d", sv->data_pad);
1266 goto bad_vid_hdr; 1230 goto bad_vid_hdr;
1267 } 1231 }
1268
1269 if (seb->leb_ver != be32_to_cpu(vidh->leb_ver)) {
1270 ubi_err("bad leb_ver %u", seb->leb_ver);
1271 goto bad_vid_hdr;
1272 }
1273 } 1232 }
1274 1233
1275 if (!last_seb) 1234 if (!last_seb)
@@ -1299,8 +1258,7 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
1299 if (err < 0) { 1258 if (err < 0) {
1300 kfree(buf); 1259 kfree(buf);
1301 return err; 1260 return err;
1302 } 1261 } else if (err)
1303 else if (err)
1304 buf[pnum] = 1; 1262 buf[pnum] = 1;
1305 } 1263 }
1306 1264
diff --git a/drivers/mtd/ubi/scan.h b/drivers/mtd/ubi/scan.h
index 966b9b682a42..61df208e2f20 100644
--- a/drivers/mtd/ubi/scan.h
+++ b/drivers/mtd/ubi/scan.h
@@ -34,7 +34,6 @@
34 * @u: unions RB-tree or @list links 34 * @u: unions RB-tree or @list links
35 * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects 35 * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects
36 * @u.list: link in one of the eraseblock lists 36 * @u.list: link in one of the eraseblock lists
37 * @leb_ver: logical eraseblock version (obsolete)
38 * 37 *
39 * One object of this type is allocated for each physical eraseblock during 38 * One object of this type is allocated for each physical eraseblock during
40 * scanning. 39 * scanning.
@@ -49,7 +48,6 @@ struct ubi_scan_leb {
49 struct rb_node rb; 48 struct rb_node rb;
50 struct list_head list; 49 struct list_head list;
51 } u; 50 } u;
52 uint32_t leb_ver;
53}; 51};
54 52
55/** 53/**
@@ -59,16 +57,16 @@ struct ubi_scan_leb {
59 * @leb_count: number of logical eraseblocks in this volume 57 * @leb_count: number of logical eraseblocks in this volume
60 * @vol_type: volume type 58 * @vol_type: volume type
61 * @used_ebs: number of used logical eraseblocks in this volume (only for 59 * @used_ebs: number of used logical eraseblocks in this volume (only for
62 * static volumes) 60 * static volumes)
63 * @last_data_size: amount of data in the last logical eraseblock of this 61 * @last_data_size: amount of data in the last logical eraseblock of this
64 * volume (always equivalent to the usable logical eraseblock size in case of 62 * volume (always equivalent to the usable logical eraseblock
65 * dynamic volumes) 63 * size in case of dynamic volumes)
66 * @data_pad: how many bytes at the end of logical eraseblocks of this volume 64 * @data_pad: how many bytes at the end of logical eraseblocks of this volume
67 * are not used (due to volume alignment) 65 * are not used (due to volume alignment)
68 * @compat: compatibility flags of this volume 66 * @compat: compatibility flags of this volume
69 * @rb: link in the volume RB-tree 67 * @rb: link in the volume RB-tree
70 * @root: root of the RB-tree containing all the eraseblock belonging to this 68 * @root: root of the RB-tree containing all the eraseblock belonging to this
71 * volume (&struct ubi_scan_leb objects) 69 * volume (&struct ubi_scan_leb objects)
72 * 70 *
73 * One object of this type is allocated for each volume during scanning. 71 * One object of this type is allocated for each volume during scanning.
74 */ 72 */
@@ -92,8 +90,8 @@ struct ubi_scan_volume {
92 * @free: list of free physical eraseblocks 90 * @free: list of free physical eraseblocks
93 * @erase: list of physical eraseblocks which have to be erased 91 * @erase: list of physical eraseblocks which have to be erased
94 * @alien: list of physical eraseblocks which should not be used by UBI (e.g., 92 * @alien: list of physical eraseblocks which should not be used by UBI (e.g.,
93 * those belonging to "preserve"-compatible internal volumes)
95 * @bad_peb_count: count of bad physical eraseblocks 94 * @bad_peb_count: count of bad physical eraseblocks
96 * those belonging to "preserve"-compatible internal volumes)
97 * @vols_found: number of volumes found during scanning 95 * @vols_found: number of volumes found during scanning
98 * @highest_vol_id: highest volume ID 96 * @highest_vol_id: highest volume ID
99 * @alien_peb_count: count of physical eraseblocks in the @alien list 97 * @alien_peb_count: count of physical eraseblocks in the @alien list
@@ -106,8 +104,8 @@ struct ubi_scan_volume {
106 * @ec_count: a temporary variable used when calculating @mean_ec 104 * @ec_count: a temporary variable used when calculating @mean_ec
107 * 105 *
108 * This data structure contains the result of scanning and may be used by other 106 * This data structure contains the result of scanning and may be used by other
109 * UBI units to build final UBI data structures, further error-recovery and so 107 * UBI sub-systems to build final UBI data structures, further error-recovery
110 * on. 108 * and so on.
111 */ 109 */
112struct ubi_scan_info { 110struct ubi_scan_info {
113 struct rb_root volumes; 111 struct rb_root volumes;
@@ -132,8 +130,7 @@ struct ubi_device;
132struct ubi_vid_hdr; 130struct ubi_vid_hdr;
133 131
134/* 132/*
135 * ubi_scan_move_to_list - move a physical eraseblock from the volume tree to a 133 * ubi_scan_move_to_list - move a PEB from the volume tree to a list.
136 * list.
137 * 134 *
138 * @sv: volume scanning information 135 * @sv: volume scanning information
139 * @seb: scanning eraseblock infprmation 136 * @seb: scanning eraseblock infprmation
diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h
index c3185d9fd048..2ad940409053 100644
--- a/drivers/mtd/ubi/ubi-media.h
+++ b/drivers/mtd/ubi/ubi-media.h
@@ -98,10 +98,11 @@ enum {
98 * Compatibility constants used by internal volumes. 98 * Compatibility constants used by internal volumes.
99 * 99 *
100 * @UBI_COMPAT_DELETE: delete this internal volume before anything is written 100 * @UBI_COMPAT_DELETE: delete this internal volume before anything is written
101 * to the flash 101 * to the flash
102 * @UBI_COMPAT_RO: attach this device in read-only mode 102 * @UBI_COMPAT_RO: attach this device in read-only mode
103 * @UBI_COMPAT_PRESERVE: preserve this internal volume - do not touch its 103 * @UBI_COMPAT_PRESERVE: preserve this internal volume - do not touch its
104 * physical eraseblocks, don't allow the wear-leveling unit to move them 104 * physical eraseblocks, don't allow the wear-leveling
105 * sub-system to move them
105 * @UBI_COMPAT_REJECT: reject this UBI image 106 * @UBI_COMPAT_REJECT: reject this UBI image
106 */ 107 */
107enum { 108enum {
@@ -123,7 +124,7 @@ enum {
123 * struct ubi_ec_hdr - UBI erase counter header. 124 * struct ubi_ec_hdr - UBI erase counter header.
124 * @magic: erase counter header magic number (%UBI_EC_HDR_MAGIC) 125 * @magic: erase counter header magic number (%UBI_EC_HDR_MAGIC)
125 * @version: version of UBI implementation which is supposed to accept this 126 * @version: version of UBI implementation which is supposed to accept this
126 * UBI image 127 * UBI image
127 * @padding1: reserved for future, zeroes 128 * @padding1: reserved for future, zeroes
128 * @ec: the erase counter 129 * @ec: the erase counter
129 * @vid_hdr_offset: where the VID header starts 130 * @vid_hdr_offset: where the VID header starts
@@ -159,24 +160,23 @@ struct ubi_ec_hdr {
159 * struct ubi_vid_hdr - on-flash UBI volume identifier header. 160 * struct ubi_vid_hdr - on-flash UBI volume identifier header.
160 * @magic: volume identifier header magic number (%UBI_VID_HDR_MAGIC) 161 * @magic: volume identifier header magic number (%UBI_VID_HDR_MAGIC)
161 * @version: UBI implementation version which is supposed to accept this UBI 162 * @version: UBI implementation version which is supposed to accept this UBI
162 * image (%UBI_VERSION) 163 * image (%UBI_VERSION)
163 * @vol_type: volume type (%UBI_VID_DYNAMIC or %UBI_VID_STATIC) 164 * @vol_type: volume type (%UBI_VID_DYNAMIC or %UBI_VID_STATIC)
164 * @copy_flag: if this logical eraseblock was copied from another physical 165 * @copy_flag: if this logical eraseblock was copied from another physical
165 * eraseblock (for wear-leveling reasons) 166 * eraseblock (for wear-leveling reasons)
166 * @compat: compatibility of this volume (%0, %UBI_COMPAT_DELETE, 167 * @compat: compatibility of this volume (%0, %UBI_COMPAT_DELETE,
167 * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT) 168 * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT)
168 * @vol_id: ID of this volume 169 * @vol_id: ID of this volume
169 * @lnum: logical eraseblock number 170 * @lnum: logical eraseblock number
170 * @leb_ver: version of this logical eraseblock (IMPORTANT: obsolete, to be 171 * @padding1: reserved for future, zeroes
171 * removed, kept only for not breaking older UBI users)
172 * @data_size: how many bytes of data this logical eraseblock contains 172 * @data_size: how many bytes of data this logical eraseblock contains
173 * @used_ebs: total number of used logical eraseblocks in this volume 173 * @used_ebs: total number of used logical eraseblocks in this volume
174 * @data_pad: how many bytes at the end of this physical eraseblock are not 174 * @data_pad: how many bytes at the end of this physical eraseblock are not
175 * used 175 * used
176 * @data_crc: CRC checksum of the data stored in this logical eraseblock 176 * @data_crc: CRC checksum of the data stored in this logical eraseblock
177 * @padding1: reserved for future, zeroes
178 * @sqnum: sequence number
179 * @padding2: reserved for future, zeroes 177 * @padding2: reserved for future, zeroes
178 * @sqnum: sequence number
179 * @padding3: reserved for future, zeroes
180 * @hdr_crc: volume identifier header CRC checksum 180 * @hdr_crc: volume identifier header CRC checksum
181 * 181 *
182 * The @sqnum is the value of the global sequence counter at the time when this 182 * The @sqnum is the value of the global sequence counter at the time when this
@@ -224,10 +224,6 @@ struct ubi_ec_hdr {
224 * checksum is correct, this physical eraseblock is selected (P1). Otherwise 224 * checksum is correct, this physical eraseblock is selected (P1). Otherwise
225 * the older one (P) is selected. 225 * the older one (P) is selected.
226 * 226 *
227 * Note, there is an obsolete @leb_ver field which was used instead of @sqnum
228 * in the past. But it is not used anymore and we keep it in order to be able
229 * to deal with old UBI images. It will be removed at some point.
230 *
231 * There are 2 sorts of volumes in UBI: user volumes and internal volumes. 227 * There are 2 sorts of volumes in UBI: user volumes and internal volumes.
232 * Internal volumes are not seen from outside and are used for various internal 228 * Internal volumes are not seen from outside and are used for various internal
233 * UBI purposes. In this implementation there is only one internal volume - the 229 * UBI purposes. In this implementation there is only one internal volume - the
@@ -248,9 +244,9 @@ struct ubi_ec_hdr {
248 * The @data_crc field contains the CRC checksum of the contents of the logical 244 * The @data_crc field contains the CRC checksum of the contents of the logical
249 * eraseblock if this is a static volume. In case of dynamic volumes, it does 245 * eraseblock if this is a static volume. In case of dynamic volumes, it does
250 * not contain the CRC checksum as a rule. The only exception is when the 246 * not contain the CRC checksum as a rule. The only exception is when the
251 * data of the physical eraseblock was moved by the wear-leveling unit, then 247 * data of the physical eraseblock was moved by the wear-leveling sub-system,
252 * the wear-leveling unit calculates the data CRC and stores it in the 248 * then the wear-leveling sub-system calculates the data CRC and stores it in
253 * @data_crc field. And of course, the @copy_flag is %in this case. 249 * the @data_crc field. And of course, the @copy_flag is %in this case.
254 * 250 *
255 * The @data_size field is used only for static volumes because UBI has to know 251 * The @data_size field is used only for static volumes because UBI has to know
256 * how many bytes of data are stored in this eraseblock. For dynamic volumes, 252 * how many bytes of data are stored in this eraseblock. For dynamic volumes,
@@ -277,14 +273,14 @@ struct ubi_vid_hdr {
277 __u8 compat; 273 __u8 compat;
278 __be32 vol_id; 274 __be32 vol_id;
279 __be32 lnum; 275 __be32 lnum;
280 __be32 leb_ver; /* obsolete, to be removed, don't use */ 276 __u8 padding1[4];
281 __be32 data_size; 277 __be32 data_size;
282 __be32 used_ebs; 278 __be32 used_ebs;
283 __be32 data_pad; 279 __be32 data_pad;
284 __be32 data_crc; 280 __be32 data_crc;
285 __u8 padding1[4]; 281 __u8 padding2[4];
286 __be64 sqnum; 282 __be64 sqnum;
287 __u8 padding2[12]; 283 __u8 padding3[12];
288 __be32 hdr_crc; 284 __be32 hdr_crc;
289} __attribute__ ((packed)); 285} __attribute__ ((packed));
290 286
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 67dcbd11c15c..1c3fa18c26a7 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -74,15 +74,15 @@
74#define UBI_IO_RETRIES 3 74#define UBI_IO_RETRIES 3
75 75
76/* 76/*
77 * Error codes returned by the I/O unit. 77 * Error codes returned by the I/O sub-system.
78 * 78 *
79 * UBI_IO_PEB_EMPTY: the physical eraseblock is empty, i.e. it contains only 79 * UBI_IO_PEB_EMPTY: the physical eraseblock is empty, i.e. it contains only
80 * 0xFF bytes 80 * %0xFF bytes
81 * UBI_IO_PEB_FREE: the physical eraseblock is free, i.e. it contains only a 81 * UBI_IO_PEB_FREE: the physical eraseblock is free, i.e. it contains only a
82 * valid erase counter header, and the rest are %0xFF bytes 82 * valid erase counter header, and the rest are %0xFF bytes
83 * UBI_IO_BAD_EC_HDR: the erase counter header is corrupted (bad magic or CRC) 83 * UBI_IO_BAD_EC_HDR: the erase counter header is corrupted (bad magic or CRC)
84 * UBI_IO_BAD_VID_HDR: the volume identifier header is corrupted (bad magic or 84 * UBI_IO_BAD_VID_HDR: the volume identifier header is corrupted (bad magic or
85 * CRC) 85 * CRC)
86 * UBI_IO_BITFLIPS: bit-flips were detected and corrected 86 * UBI_IO_BITFLIPS: bit-flips were detected and corrected
87 */ 87 */
88enum { 88enum {
@@ -99,9 +99,9 @@ enum {
99 * @ec: erase counter 99 * @ec: erase counter
100 * @pnum: physical eraseblock number 100 * @pnum: physical eraseblock number
101 * 101 *
102 * This data structure is used in the WL unit. Each physical eraseblock has a 102 * This data structure is used in the WL sub-system. Each physical eraseblock
103 * corresponding &struct wl_entry object which may be kept in different 103 * has a corresponding &struct wl_entry object which may be kept in different
104 * RB-trees. See WL unit for details. 104 * RB-trees. See WL sub-system for details.
105 */ 105 */
106struct ubi_wl_entry { 106struct ubi_wl_entry {
107 struct rb_node rb; 107 struct rb_node rb;
@@ -118,10 +118,10 @@ struct ubi_wl_entry {
118 * @mutex: read/write mutex to implement read/write access serialization to 118 * @mutex: read/write mutex to implement read/write access serialization to
119 * the (@vol_id, @lnum) logical eraseblock 119 * the (@vol_id, @lnum) logical eraseblock
120 * 120 *
121 * This data structure is used in the EBA unit to implement per-LEB locking. 121 * This data structure is used in the EBA sub-system to implement per-LEB
122 * When a logical eraseblock is being locked - corresponding 122 * locking. When a logical eraseblock is being locked - corresponding
123 * &struct ubi_ltree_entry object is inserted to the lock tree (@ubi->ltree). 123 * &struct ubi_ltree_entry object is inserted to the lock tree (@ubi->ltree).
124 * See EBA unit for details. 124 * See EBA sub-system for details.
125 */ 125 */
126struct ubi_ltree_entry { 126struct ubi_ltree_entry {
127 struct rb_node rb; 127 struct rb_node rb;
@@ -131,6 +131,27 @@ struct ubi_ltree_entry {
131 struct rw_semaphore mutex; 131 struct rw_semaphore mutex;
132}; 132};
133 133
134/**
135 * struct ubi_rename_entry - volume re-name description data structure.
136 * @new_name_len: new volume name length
137 * @new_name: new volume name
138 * @remove: if not zero, this volume should be removed, not re-named
139 * @desc: descriptor of the volume
140 * @list: links re-name entries into a list
141 *
142 * This data structure is utilized in the multiple volume re-name code. Namely,
143 * UBI first creates a list of &struct ubi_rename_entry objects from the
144 * &struct ubi_rnvol_req request object, and then utilizes this list to do all
145 * the job.
146 */
147struct ubi_rename_entry {
148 int new_name_len;
149 char new_name[UBI_VOL_NAME_MAX + 1];
150 int remove;
151 struct ubi_volume_desc *desc;
152 struct list_head list;
153};
154
134struct ubi_volume_desc; 155struct ubi_volume_desc;
135 156
136/** 157/**
@@ -206,7 +227,7 @@ struct ubi_volume {
206 int alignment; 227 int alignment;
207 int data_pad; 228 int data_pad;
208 int name_len; 229 int name_len;
209 char name[UBI_VOL_NAME_MAX+1]; 230 char name[UBI_VOL_NAME_MAX + 1];
210 231
211 int upd_ebs; 232 int upd_ebs;
212 int ch_lnum; 233 int ch_lnum;
@@ -225,7 +246,7 @@ struct ubi_volume {
225#ifdef CONFIG_MTD_UBI_GLUEBI 246#ifdef CONFIG_MTD_UBI_GLUEBI
226 /* 247 /*
227 * Gluebi-related stuff may be compiled out. 248 * Gluebi-related stuff may be compiled out.
228 * TODO: this should not be built into UBI but should be a separate 249 * Note: this should not be built into UBI but should be a separate
229 * ubimtd driver which works on top of UBI and emulates MTD devices. 250 * ubimtd driver which works on top of UBI and emulates MTD devices.
230 */ 251 */
231 struct ubi_volume_desc *gluebi_desc; 252 struct ubi_volume_desc *gluebi_desc;
@@ -235,8 +256,7 @@ struct ubi_volume {
235}; 256};
236 257
237/** 258/**
238 * struct ubi_volume_desc - descriptor of the UBI volume returned when it is 259 * struct ubi_volume_desc - UBI volume descriptor returned when it is opened.
239 * opened.
240 * @vol: reference to the corresponding volume description object 260 * @vol: reference to the corresponding volume description object
241 * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, or %UBI_EXCLUSIVE) 261 * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, or %UBI_EXCLUSIVE)
242 */ 262 */
@@ -273,7 +293,7 @@ struct ubi_wl_entry;
273 * @vtbl_size: size of the volume table in bytes 293 * @vtbl_size: size of the volume table in bytes
274 * @vtbl: in-RAM volume table copy 294 * @vtbl: in-RAM volume table copy
275 * @volumes_mutex: protects on-flash volume table and serializes volume 295 * @volumes_mutex: protects on-flash volume table and serializes volume
276 * changes, like creation, deletion, update, resize 296 * changes, like creation, deletion, update, re-size and re-name
277 * 297 *
278 * @max_ec: current highest erase counter value 298 * @max_ec: current highest erase counter value
279 * @mean_ec: current mean erase counter value 299 * @mean_ec: current mean erase counter value
@@ -293,6 +313,7 @@ struct ubi_wl_entry;
293 * @move_to, @move_to_put @erase_pending, @wl_scheduled, and @works 313 * @move_to, @move_to_put @erase_pending, @wl_scheduled, and @works
294 * fields 314 * fields
295 * @move_mutex: serializes eraseblock moves 315 * @move_mutex: serializes eraseblock moves
316 * @work_sem: sycnhronizes the WL worker with use tasks
296 * @wl_scheduled: non-zero if the wear-leveling was scheduled 317 * @wl_scheduled: non-zero if the wear-leveling was scheduled
297 * @lookuptbl: a table to quickly find a &struct ubi_wl_entry object for any 318 * @lookuptbl: a table to quickly find a &struct ubi_wl_entry object for any
298 * physical eraseblock 319 * physical eraseblock
@@ -316,11 +337,11 @@ struct ubi_wl_entry;
316 * @ro_mode: if the UBI device is in read-only mode 337 * @ro_mode: if the UBI device is in read-only mode
317 * @leb_size: logical eraseblock size 338 * @leb_size: logical eraseblock size
318 * @leb_start: starting offset of logical eraseblocks within physical 339 * @leb_start: starting offset of logical eraseblocks within physical
319 * eraseblocks 340 * eraseblocks
320 * @ec_hdr_alsize: size of the EC header aligned to @hdrs_min_io_size 341 * @ec_hdr_alsize: size of the EC header aligned to @hdrs_min_io_size
321 * @vid_hdr_alsize: size of the VID header aligned to @hdrs_min_io_size 342 * @vid_hdr_alsize: size of the VID header aligned to @hdrs_min_io_size
322 * @vid_hdr_offset: starting offset of the volume identifier header (might be 343 * @vid_hdr_offset: starting offset of the volume identifier header (might be
323 * unaligned) 344 * unaligned)
324 * @vid_hdr_aloffset: starting offset of the VID header aligned to 345 * @vid_hdr_aloffset: starting offset of the VID header aligned to
325 * @hdrs_min_io_size 346 * @hdrs_min_io_size
326 * @vid_hdr_shift: contains @vid_hdr_offset - @vid_hdr_aloffset 347 * @vid_hdr_shift: contains @vid_hdr_offset - @vid_hdr_aloffset
@@ -331,6 +352,8 @@ struct ubi_wl_entry;
331 * @peb_buf1: a buffer of PEB size used for different purposes 352 * @peb_buf1: a buffer of PEB size used for different purposes
332 * @peb_buf2: another buffer of PEB size used for different purposes 353 * @peb_buf2: another buffer of PEB size used for different purposes
333 * @buf_mutex: proptects @peb_buf1 and @peb_buf2 354 * @buf_mutex: proptects @peb_buf1 and @peb_buf2
355 * @ckvol_mutex: serializes static volume checking when opening
356 * @mult_mutex: serializes operations on multiple volumes, like re-nameing
334 * @dbg_peb_buf: buffer of PEB size used for debugging 357 * @dbg_peb_buf: buffer of PEB size used for debugging
335 * @dbg_buf_mutex: proptects @dbg_peb_buf 358 * @dbg_buf_mutex: proptects @dbg_peb_buf
336 */ 359 */
@@ -356,16 +379,16 @@ struct ubi_device {
356 struct mutex volumes_mutex; 379 struct mutex volumes_mutex;
357 380
358 int max_ec; 381 int max_ec;
359 /* TODO: mean_ec is not updated run-time, fix */ 382 /* Note, mean_ec is not updated run-time - should be fixed */
360 int mean_ec; 383 int mean_ec;
361 384
362 /* EBA unit's stuff */ 385 /* EBA sub-system's stuff */
363 unsigned long long global_sqnum; 386 unsigned long long global_sqnum;
364 spinlock_t ltree_lock; 387 spinlock_t ltree_lock;
365 struct rb_root ltree; 388 struct rb_root ltree;
366 struct mutex alc_mutex; 389 struct mutex alc_mutex;
367 390
368 /* Wear-leveling unit's stuff */ 391 /* Wear-leveling sub-system's stuff */
369 struct rb_root used; 392 struct rb_root used;
370 struct rb_root free; 393 struct rb_root free;
371 struct rb_root scrub; 394 struct rb_root scrub;
@@ -388,7 +411,7 @@ struct ubi_device {
388 int thread_enabled; 411 int thread_enabled;
389 char bgt_name[sizeof(UBI_BGT_NAME_PATTERN)+2]; 412 char bgt_name[sizeof(UBI_BGT_NAME_PATTERN)+2];
390 413
391 /* I/O unit's stuff */ 414 /* I/O sub-system's stuff */
392 long long flash_size; 415 long long flash_size;
393 int peb_count; 416 int peb_count;
394 int peb_size; 417 int peb_size;
@@ -411,6 +434,7 @@ struct ubi_device {
411 void *peb_buf2; 434 void *peb_buf2;
412 struct mutex buf_mutex; 435 struct mutex buf_mutex;
413 struct mutex ckvol_mutex; 436 struct mutex ckvol_mutex;
437 struct mutex mult_mutex;
414#ifdef CONFIG_MTD_UBI_DEBUG 438#ifdef CONFIG_MTD_UBI_DEBUG
415 void *dbg_peb_buf; 439 void *dbg_peb_buf;
416 struct mutex dbg_buf_mutex; 440 struct mutex dbg_buf_mutex;
@@ -427,12 +451,15 @@ extern struct mutex ubi_devices_mutex;
427/* vtbl.c */ 451/* vtbl.c */
428int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, 452int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
429 struct ubi_vtbl_record *vtbl_rec); 453 struct ubi_vtbl_record *vtbl_rec);
454int ubi_vtbl_rename_volumes(struct ubi_device *ubi,
455 struct list_head *rename_list);
430int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si); 456int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si);
431 457
432/* vmt.c */ 458/* vmt.c */
433int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req); 459int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req);
434int ubi_remove_volume(struct ubi_volume_desc *desc); 460int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl);
435int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs); 461int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs);
462int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list);
436int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol); 463int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol);
437void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol); 464void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol);
438 465
@@ -447,7 +474,8 @@ int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vol,
447 const void __user *buf, int count); 474 const void __user *buf, int count);
448 475
449/* misc.c */ 476/* misc.c */
450int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf, int length); 477int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf,
478 int length);
451int ubi_check_volume(struct ubi_device *ubi, int vol_id); 479int ubi_check_volume(struct ubi_device *ubi, int vol_id);
452void ubi_calculate_reserved(struct ubi_device *ubi); 480void ubi_calculate_reserved(struct ubi_device *ubi);
453 481
@@ -477,7 +505,6 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
477int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, 505int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
478 struct ubi_vid_hdr *vid_hdr); 506 struct ubi_vid_hdr *vid_hdr);
479int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si); 507int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si);
480void ubi_eba_close(const struct ubi_device *ubi);
481 508
482/* wl.c */ 509/* wl.c */
483int ubi_wl_get_peb(struct ubi_device *ubi, int dtype); 510int ubi_wl_get_peb(struct ubi_device *ubi, int dtype);
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c
index ddaa1a56cc69..8b89cc18ff0b 100644
--- a/drivers/mtd/ubi/upd.c
+++ b/drivers/mtd/ubi/upd.c
@@ -39,7 +39,7 @@
39 */ 39 */
40 40
41#include <linux/err.h> 41#include <linux/err.h>
42#include <asm/uaccess.h> 42#include <linux/uaccess.h>
43#include <asm/div64.h> 43#include <asm/div64.h>
44#include "ubi.h" 44#include "ubi.h"
45 45
@@ -56,11 +56,11 @@ static int set_update_marker(struct ubi_device *ubi, struct ubi_volume *vol)
56 int err; 56 int err;
57 struct ubi_vtbl_record vtbl_rec; 57 struct ubi_vtbl_record vtbl_rec;
58 58
59 dbg_msg("set update marker for volume %d", vol->vol_id); 59 dbg_gen("set update marker for volume %d", vol->vol_id);
60 60
61 if (vol->upd_marker) { 61 if (vol->upd_marker) {
62 ubi_assert(ubi->vtbl[vol->vol_id].upd_marker); 62 ubi_assert(ubi->vtbl[vol->vol_id].upd_marker);
63 dbg_msg("already set"); 63 dbg_gen("already set");
64 return 0; 64 return 0;
65 } 65 }
66 66
@@ -92,7 +92,7 @@ static int clear_update_marker(struct ubi_device *ubi, struct ubi_volume *vol,
92 uint64_t tmp; 92 uint64_t tmp;
93 struct ubi_vtbl_record vtbl_rec; 93 struct ubi_vtbl_record vtbl_rec;
94 94
95 dbg_msg("clear update marker for volume %d", vol->vol_id); 95 dbg_gen("clear update marker for volume %d", vol->vol_id);
96 96
97 memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id], 97 memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id],
98 sizeof(struct ubi_vtbl_record)); 98 sizeof(struct ubi_vtbl_record));
@@ -133,7 +133,7 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
133 int i, err; 133 int i, err;
134 uint64_t tmp; 134 uint64_t tmp;
135 135
136 dbg_msg("start update of volume %d, %llu bytes", vol->vol_id, bytes); 136 dbg_gen("start update of volume %d, %llu bytes", vol->vol_id, bytes);
137 ubi_assert(!vol->updating && !vol->changing_leb); 137 ubi_assert(!vol->updating && !vol->changing_leb);
138 vol->updating = 1; 138 vol->updating = 1;
139 139
@@ -183,7 +183,7 @@ int ubi_start_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
183{ 183{
184 ubi_assert(!vol->updating && !vol->changing_leb); 184 ubi_assert(!vol->updating && !vol->changing_leb);
185 185
186 dbg_msg("start changing LEB %d:%d, %u bytes", 186 dbg_gen("start changing LEB %d:%d, %u bytes",
187 vol->vol_id, req->lnum, req->bytes); 187 vol->vol_id, req->lnum, req->bytes);
188 if (req->bytes == 0) 188 if (req->bytes == 0)
189 return ubi_eba_atomic_leb_change(ubi, vol, req->lnum, NULL, 0, 189 return ubi_eba_atomic_leb_change(ubi, vol, req->lnum, NULL, 0,
@@ -237,16 +237,17 @@ static int write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
237 int err; 237 int err;
238 238
239 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { 239 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
240 len = ALIGN(len, ubi->min_io_size); 240 int l = ALIGN(len, ubi->min_io_size);
241 memset(buf + len, 0xFF, len - len);
242 241
243 len = ubi_calc_data_len(ubi, buf, len); 242 memset(buf + len, 0xFF, l - len);
243 len = ubi_calc_data_len(ubi, buf, l);
244 if (len == 0) { 244 if (len == 0) {
245 dbg_msg("all %d bytes contain 0xFF - skip", len); 245 dbg_gen("all %d bytes contain 0xFF - skip", len);
246 return 0; 246 return 0;
247 } 247 }
248 248
249 err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len, UBI_UNKNOWN); 249 err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len,
250 UBI_UNKNOWN);
250 } else { 251 } else {
251 /* 252 /*
252 * When writing static volume, and this is the last logical 253 * When writing static volume, and this is the last logical
@@ -267,6 +268,7 @@ static int write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
267 268
268/** 269/**
269 * ubi_more_update_data - write more update data. 270 * ubi_more_update_data - write more update data.
271 * @ubi: UBI device description object
270 * @vol: volume description object 272 * @vol: volume description object
271 * @buf: write data (user-space memory buffer) 273 * @buf: write data (user-space memory buffer)
272 * @count: how much bytes to write 274 * @count: how much bytes to write
@@ -283,7 +285,7 @@ int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol,
283 uint64_t tmp; 285 uint64_t tmp;
284 int lnum, offs, err = 0, len, to_write = count; 286 int lnum, offs, err = 0, len, to_write = count;
285 287
286 dbg_msg("write %d of %lld bytes, %lld already passed", 288 dbg_gen("write %d of %lld bytes, %lld already passed",
287 count, vol->upd_bytes, vol->upd_received); 289 count, vol->upd_bytes, vol->upd_received);
288 290
289 if (ubi->ro_mode) 291 if (ubi->ro_mode)
@@ -384,6 +386,7 @@ int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol,
384 386
385/** 387/**
386 * ubi_more_leb_change_data - accept more data for atomic LEB change. 388 * ubi_more_leb_change_data - accept more data for atomic LEB change.
389 * @ubi: UBI device description object
387 * @vol: volume description object 390 * @vol: volume description object
388 * @buf: write data (user-space memory buffer) 391 * @buf: write data (user-space memory buffer)
389 * @count: how much bytes to write 392 * @count: how much bytes to write
@@ -400,7 +403,7 @@ int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vol,
400{ 403{
401 int err; 404 int err;
402 405
403 dbg_msg("write %d of %lld bytes, %lld already passed", 406 dbg_gen("write %d of %lld bytes, %lld already passed",
404 count, vol->upd_bytes, vol->upd_received); 407 count, vol->upd_bytes, vol->upd_received);
405 408
406 if (ubi->ro_mode) 409 if (ubi->ro_mode)
@@ -418,7 +421,8 @@ int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vol,
418 if (vol->upd_received == vol->upd_bytes) { 421 if (vol->upd_received == vol->upd_bytes) {
419 int len = ALIGN((int)vol->upd_bytes, ubi->min_io_size); 422 int len = ALIGN((int)vol->upd_bytes, ubi->min_io_size);
420 423
421 memset(vol->upd_buf + vol->upd_bytes, 0xFF, len - vol->upd_bytes); 424 memset(vol->upd_buf + vol->upd_bytes, 0xFF,
425 len - vol->upd_bytes);
422 len = ubi_calc_data_len(ubi, vol->upd_buf, len); 426 len = ubi_calc_data_len(ubi, vol->upd_buf, len);
423 err = ubi_eba_atomic_leb_change(ubi, vol, vol->ch_lnum, 427 err = ubi_eba_atomic_leb_change(ubi, vol, vol->ch_lnum,
424 vol->upd_buf, len, UBI_UNKNOWN); 428 vol->upd_buf, len, UBI_UNKNOWN);
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 5be58d85c639..3531ca9a1e24 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -28,9 +28,9 @@
28#include "ubi.h" 28#include "ubi.h"
29 29
30#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 30#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
31static void paranoid_check_volumes(struct ubi_device *ubi); 31static int paranoid_check_volumes(struct ubi_device *ubi);
32#else 32#else
33#define paranoid_check_volumes(ubi) 33#define paranoid_check_volumes(ubi) 0
34#endif 34#endif
35 35
36static ssize_t vol_attribute_show(struct device *dev, 36static ssize_t vol_attribute_show(struct device *dev,
@@ -127,6 +127,7 @@ static void vol_release(struct device *dev)
127{ 127{
128 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev); 128 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
129 129
130 kfree(vol->eba_tbl);
130 kfree(vol); 131 kfree(vol);
131} 132}
132 133
@@ -201,7 +202,7 @@ static void volume_sysfs_close(struct ubi_volume *vol)
201 */ 202 */
202int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) 203int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
203{ 204{
204 int i, err, vol_id = req->vol_id, dont_free = 0; 205 int i, err, vol_id = req->vol_id, do_free = 1;
205 struct ubi_volume *vol; 206 struct ubi_volume *vol;
206 struct ubi_vtbl_record vtbl_rec; 207 struct ubi_vtbl_record vtbl_rec;
207 uint64_t bytes; 208 uint64_t bytes;
@@ -217,7 +218,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
217 spin_lock(&ubi->volumes_lock); 218 spin_lock(&ubi->volumes_lock);
218 if (vol_id == UBI_VOL_NUM_AUTO) { 219 if (vol_id == UBI_VOL_NUM_AUTO) {
219 /* Find unused volume ID */ 220 /* Find unused volume ID */
220 dbg_msg("search for vacant volume ID"); 221 dbg_gen("search for vacant volume ID");
221 for (i = 0; i < ubi->vtbl_slots; i++) 222 for (i = 0; i < ubi->vtbl_slots; i++)
222 if (!ubi->volumes[i]) { 223 if (!ubi->volumes[i]) {
223 vol_id = i; 224 vol_id = i;
@@ -232,7 +233,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
232 req->vol_id = vol_id; 233 req->vol_id = vol_id;
233 } 234 }
234 235
235 dbg_msg("volume ID %d, %llu bytes, type %d, name %s", 236 dbg_gen("volume ID %d, %llu bytes, type %d, name %s",
236 vol_id, (unsigned long long)req->bytes, 237 vol_id, (unsigned long long)req->bytes,
237 (int)req->vol_type, req->name); 238 (int)req->vol_type, req->name);
238 239
@@ -252,7 +253,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
252 goto out_unlock; 253 goto out_unlock;
253 } 254 }
254 255
255 /* Calculate how many eraseblocks are requested */ 256 /* Calculate how many eraseblocks are requested */
256 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment; 257 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment;
257 bytes = req->bytes; 258 bytes = req->bytes;
258 if (do_div(bytes, vol->usable_leb_size)) 259 if (do_div(bytes, vol->usable_leb_size))
@@ -274,7 +275,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
274 vol->data_pad = ubi->leb_size % vol->alignment; 275 vol->data_pad = ubi->leb_size % vol->alignment;
275 vol->vol_type = req->vol_type; 276 vol->vol_type = req->vol_type;
276 vol->name_len = req->name_len; 277 vol->name_len = req->name_len;
277 memcpy(vol->name, req->name, vol->name_len + 1); 278 memcpy(vol->name, req->name, vol->name_len);
278 vol->ubi = ubi; 279 vol->ubi = ubi;
279 280
280 /* 281 /*
@@ -349,7 +350,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
349 vtbl_rec.vol_type = UBI_VID_DYNAMIC; 350 vtbl_rec.vol_type = UBI_VID_DYNAMIC;
350 else 351 else
351 vtbl_rec.vol_type = UBI_VID_STATIC; 352 vtbl_rec.vol_type = UBI_VID_STATIC;
352 memcpy(vtbl_rec.name, vol->name, vol->name_len + 1); 353 memcpy(vtbl_rec.name, vol->name, vol->name_len);
353 354
354 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); 355 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
355 if (err) 356 if (err)
@@ -360,19 +361,19 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
360 ubi->vol_count += 1; 361 ubi->vol_count += 1;
361 spin_unlock(&ubi->volumes_lock); 362 spin_unlock(&ubi->volumes_lock);
362 363
363 paranoid_check_volumes(ubi); 364 err = paranoid_check_volumes(ubi);
364 return 0; 365 return err;
365 366
366out_sysfs: 367out_sysfs:
367 /* 368 /*
368 * We have registered our device, we should not free the volume* 369 * We have registered our device, we should not free the volume
369 * description object in this function in case of an error - it is 370 * description object in this function in case of an error - it is
370 * freed by the release function. 371 * freed by the release function.
371 * 372 *
372 * Get device reference to prevent the release function from being 373 * Get device reference to prevent the release function from being
373 * called just after sysfs has been closed. 374 * called just after sysfs has been closed.
374 */ 375 */
375 dont_free = 1; 376 do_free = 0;
376 get_device(&vol->dev); 377 get_device(&vol->dev);
377 volume_sysfs_close(vol); 378 volume_sysfs_close(vol);
378out_gluebi: 379out_gluebi:
@@ -382,17 +383,18 @@ out_gluebi:
382out_cdev: 383out_cdev:
383 cdev_del(&vol->cdev); 384 cdev_del(&vol->cdev);
384out_mapping: 385out_mapping:
385 kfree(vol->eba_tbl); 386 if (do_free)
387 kfree(vol->eba_tbl);
386out_acc: 388out_acc:
387 spin_lock(&ubi->volumes_lock); 389 spin_lock(&ubi->volumes_lock);
388 ubi->rsvd_pebs -= vol->reserved_pebs; 390 ubi->rsvd_pebs -= vol->reserved_pebs;
389 ubi->avail_pebs += vol->reserved_pebs; 391 ubi->avail_pebs += vol->reserved_pebs;
390out_unlock: 392out_unlock:
391 spin_unlock(&ubi->volumes_lock); 393 spin_unlock(&ubi->volumes_lock);
392 if (dont_free) 394 if (do_free)
393 put_device(&vol->dev);
394 else
395 kfree(vol); 395 kfree(vol);
396 else
397 put_device(&vol->dev);
396 ubi_err("cannot create volume %d, error %d", vol_id, err); 398 ubi_err("cannot create volume %d, error %d", vol_id, err);
397 return err; 399 return err;
398} 400}
@@ -400,19 +402,20 @@ out_unlock:
400/** 402/**
401 * ubi_remove_volume - remove volume. 403 * ubi_remove_volume - remove volume.
402 * @desc: volume descriptor 404 * @desc: volume descriptor
405 * @no_vtbl: do not change volume table if not zero
403 * 406 *
404 * This function removes volume described by @desc. The volume has to be opened 407 * This function removes volume described by @desc. The volume has to be opened
405 * in "exclusive" mode. Returns zero in case of success and a negative error 408 * in "exclusive" mode. Returns zero in case of success and a negative error
406 * code in case of failure. The caller has to have the @ubi->volumes_mutex 409 * code in case of failure. The caller has to have the @ubi->volumes_mutex
407 * locked. 410 * locked.
408 */ 411 */
409int ubi_remove_volume(struct ubi_volume_desc *desc) 412int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)
410{ 413{
411 struct ubi_volume *vol = desc->vol; 414 struct ubi_volume *vol = desc->vol;
412 struct ubi_device *ubi = vol->ubi; 415 struct ubi_device *ubi = vol->ubi;
413 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs; 416 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs;
414 417
415 dbg_msg("remove UBI volume %d", vol_id); 418 dbg_gen("remove UBI volume %d", vol_id);
416 ubi_assert(desc->mode == UBI_EXCLUSIVE); 419 ubi_assert(desc->mode == UBI_EXCLUSIVE);
417 ubi_assert(vol == ubi->volumes[vol_id]); 420 ubi_assert(vol == ubi->volumes[vol_id]);
418 421
@@ -435,9 +438,11 @@ int ubi_remove_volume(struct ubi_volume_desc *desc)
435 if (err) 438 if (err)
436 goto out_err; 439 goto out_err;
437 440
438 err = ubi_change_vtbl_record(ubi, vol_id, NULL); 441 if (!no_vtbl) {
439 if (err) 442 err = ubi_change_vtbl_record(ubi, vol_id, NULL);
440 goto out_err; 443 if (err)
444 goto out_err;
445 }
441 446
442 for (i = 0; i < vol->reserved_pebs; i++) { 447 for (i = 0; i < vol->reserved_pebs; i++) {
443 err = ubi_eba_unmap_leb(ubi, vol, i); 448 err = ubi_eba_unmap_leb(ubi, vol, i);
@@ -445,8 +450,6 @@ int ubi_remove_volume(struct ubi_volume_desc *desc)
445 goto out_err; 450 goto out_err;
446 } 451 }
447 452
448 kfree(vol->eba_tbl);
449 vol->eba_tbl = NULL;
450 cdev_del(&vol->cdev); 453 cdev_del(&vol->cdev);
451 volume_sysfs_close(vol); 454 volume_sysfs_close(vol);
452 455
@@ -465,8 +468,9 @@ int ubi_remove_volume(struct ubi_volume_desc *desc)
465 ubi->vol_count -= 1; 468 ubi->vol_count -= 1;
466 spin_unlock(&ubi->volumes_lock); 469 spin_unlock(&ubi->volumes_lock);
467 470
468 paranoid_check_volumes(ubi); 471 if (!no_vtbl)
469 return 0; 472 err = paranoid_check_volumes(ubi);
473 return err;
470 474
471out_err: 475out_err:
472 ubi_err("cannot remove volume %d, error %d", vol_id, err); 476 ubi_err("cannot remove volume %d, error %d", vol_id, err);
@@ -497,7 +501,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
497 if (ubi->ro_mode) 501 if (ubi->ro_mode)
498 return -EROFS; 502 return -EROFS;
499 503
500 dbg_msg("re-size volume %d to from %d to %d PEBs", 504 dbg_gen("re-size volume %d to from %d to %d PEBs",
501 vol_id, vol->reserved_pebs, reserved_pebs); 505 vol_id, vol->reserved_pebs, reserved_pebs);
502 506
503 if (vol->vol_type == UBI_STATIC_VOLUME && 507 if (vol->vol_type == UBI_STATIC_VOLUME &&
@@ -586,8 +590,8 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
586 (long long)vol->used_ebs * vol->usable_leb_size; 590 (long long)vol->used_ebs * vol->usable_leb_size;
587 } 591 }
588 592
589 paranoid_check_volumes(ubi); 593 err = paranoid_check_volumes(ubi);
590 return 0; 594 return err;
591 595
592out_acc: 596out_acc:
593 if (pebs > 0) { 597 if (pebs > 0) {
@@ -602,6 +606,44 @@ out_free:
602} 606}
603 607
604/** 608/**
609 * ubi_rename_volumes - re-name UBI volumes.
610 * @ubi: UBI device description object
611 * @rename_list: list of &struct ubi_rename_entry objects
612 *
613 * This function re-names or removes volumes specified in the re-name list.
614 * Returns zero in case of success and a negative error code in case of
615 * failure.
616 */
617int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list)
618{
619 int err;
620 struct ubi_rename_entry *re;
621
622 err = ubi_vtbl_rename_volumes(ubi, rename_list);
623 if (err)
624 return err;
625
626 list_for_each_entry(re, rename_list, list) {
627 if (re->remove) {
628 err = ubi_remove_volume(re->desc, 1);
629 if (err)
630 break;
631 } else {
632 struct ubi_volume *vol = re->desc->vol;
633
634 spin_lock(&ubi->volumes_lock);
635 vol->name_len = re->new_name_len;
636 memcpy(vol->name, re->new_name, re->new_name_len + 1);
637 spin_unlock(&ubi->volumes_lock);
638 }
639 }
640
641 if (!err)
642 err = paranoid_check_volumes(ubi);
643 return err;
644}
645
646/**
605 * ubi_add_volume - add volume. 647 * ubi_add_volume - add volume.
606 * @ubi: UBI device description object 648 * @ubi: UBI device description object
607 * @vol: volume description object 649 * @vol: volume description object
@@ -615,8 +657,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
615 int err, vol_id = vol->vol_id; 657 int err, vol_id = vol->vol_id;
616 dev_t dev; 658 dev_t dev;
617 659
618 dbg_msg("add volume %d", vol_id); 660 dbg_gen("add volume %d", vol_id);
619 ubi_dbg_dump_vol_info(vol);
620 661
621 /* Register character device for the volume */ 662 /* Register character device for the volume */
622 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); 663 cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
@@ -650,8 +691,8 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
650 return err; 691 return err;
651 } 692 }
652 693
653 paranoid_check_volumes(ubi); 694 err = paranoid_check_volumes(ubi);
654 return 0; 695 return err;
655 696
656out_gluebi: 697out_gluebi:
657 err = ubi_destroy_gluebi(vol); 698 err = ubi_destroy_gluebi(vol);
@@ -672,7 +713,7 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
672{ 713{
673 int err; 714 int err;
674 715
675 dbg_msg("free volume %d", vol->vol_id); 716 dbg_gen("free volume %d", vol->vol_id);
676 717
677 ubi->volumes[vol->vol_id] = NULL; 718 ubi->volumes[vol->vol_id] = NULL;
678 err = ubi_destroy_gluebi(vol); 719 err = ubi_destroy_gluebi(vol);
@@ -686,8 +727,10 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
686 * paranoid_check_volume - check volume information. 727 * paranoid_check_volume - check volume information.
687 * @ubi: UBI device description object 728 * @ubi: UBI device description object
688 * @vol_id: volume ID 729 * @vol_id: volume ID
730 *
731 * Returns zero if volume is all right and a a negative error code if not.
689 */ 732 */
690static void paranoid_check_volume(struct ubi_device *ubi, int vol_id) 733static int paranoid_check_volume(struct ubi_device *ubi, int vol_id)
691{ 734{
692 int idx = vol_id2idx(ubi, vol_id); 735 int idx = vol_id2idx(ubi, vol_id);
693 int reserved_pebs, alignment, data_pad, vol_type, name_len, upd_marker; 736 int reserved_pebs, alignment, data_pad, vol_type, name_len, upd_marker;
@@ -705,16 +748,7 @@ static void paranoid_check_volume(struct ubi_device *ubi, int vol_id)
705 goto fail; 748 goto fail;
706 } 749 }
707 spin_unlock(&ubi->volumes_lock); 750 spin_unlock(&ubi->volumes_lock);
708 return; 751 return 0;
709 }
710
711 if (vol->exclusive) {
712 /*
713 * The volume may be being created at the moment, do not check
714 * it (e.g., it may be in the middle of ubi_create_volume().
715 */
716 spin_unlock(&ubi->volumes_lock);
717 return;
718 } 752 }
719 753
720 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 || 754 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 ||
@@ -727,7 +761,7 @@ static void paranoid_check_volume(struct ubi_device *ubi, int vol_id)
727 goto fail; 761 goto fail;
728 } 762 }
729 763
730 n = vol->alignment % ubi->min_io_size; 764 n = vol->alignment & (ubi->min_io_size - 1);
731 if (vol->alignment != 1 && n) { 765 if (vol->alignment != 1 && n) {
732 ubi_err("alignment is not multiple of min I/O unit"); 766 ubi_err("alignment is not multiple of min I/O unit");
733 goto fail; 767 goto fail;
@@ -824,31 +858,39 @@ static void paranoid_check_volume(struct ubi_device *ubi, int vol_id)
824 858
825 if (alignment != vol->alignment || data_pad != vol->data_pad || 859 if (alignment != vol->alignment || data_pad != vol->data_pad ||
826 upd_marker != vol->upd_marker || vol_type != vol->vol_type || 860 upd_marker != vol->upd_marker || vol_type != vol->vol_type ||
827 name_len!= vol->name_len || strncmp(name, vol->name, name_len)) { 861 name_len != vol->name_len || strncmp(name, vol->name, name_len)) {
828 ubi_err("volume info is different"); 862 ubi_err("volume info is different");
829 goto fail; 863 goto fail;
830 } 864 }
831 865
832 spin_unlock(&ubi->volumes_lock); 866 spin_unlock(&ubi->volumes_lock);
833 return; 867 return 0;
834 868
835fail: 869fail:
836 ubi_err("paranoid check failed for volume %d", vol_id); 870 ubi_err("paranoid check failed for volume %d", vol_id);
837 ubi_dbg_dump_vol_info(vol); 871 if (vol)
872 ubi_dbg_dump_vol_info(vol);
838 ubi_dbg_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id); 873 ubi_dbg_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id);
839 spin_unlock(&ubi->volumes_lock); 874 spin_unlock(&ubi->volumes_lock);
840 BUG(); 875 return -EINVAL;
841} 876}
842 877
843/** 878/**
844 * paranoid_check_volumes - check information about all volumes. 879 * paranoid_check_volumes - check information about all volumes.
845 * @ubi: UBI device description object 880 * @ubi: UBI device description object
881 *
882 * Returns zero if volumes are all right and a a negative error code if not.
846 */ 883 */
847static void paranoid_check_volumes(struct ubi_device *ubi) 884static int paranoid_check_volumes(struct ubi_device *ubi)
848{ 885{
849 int i; 886 int i, err = 0;
850 887
851 for (i = 0; i < ubi->vtbl_slots; i++) 888 for (i = 0; i < ubi->vtbl_slots; i++) {
852 paranoid_check_volume(ubi, i); 889 err = paranoid_check_volume(ubi, i);
890 if (err)
891 break;
892 }
893
894 return err;
853} 895}
854#endif 896#endif
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index af36b12be278..217d0e111b2a 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -115,8 +115,58 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
115} 115}
116 116
117/** 117/**
118 * vtbl_check - check if volume table is not corrupted and contains sensible 118 * ubi_vtbl_rename_volumes - rename UBI volumes in the volume table.
119 * data. 119 * @ubi: UBI device description object
120 * @rename_list: list of &struct ubi_rename_entry objects
121 *
122 * This function re-names multiple volumes specified in @req in the volume
123 * table. Returns zero in case of success and a negative error code in case of
124 * failure.
125 */
126int ubi_vtbl_rename_volumes(struct ubi_device *ubi,
127 struct list_head *rename_list)
128{
129 int i, err;
130 struct ubi_rename_entry *re;
131 struct ubi_volume *layout_vol;
132
133 list_for_each_entry(re, rename_list, list) {
134 uint32_t crc;
135 struct ubi_volume *vol = re->desc->vol;
136 struct ubi_vtbl_record *vtbl_rec = &ubi->vtbl[vol->vol_id];
137
138 if (re->remove) {
139 memcpy(vtbl_rec, &empty_vtbl_record,
140 sizeof(struct ubi_vtbl_record));
141 continue;
142 }
143
144 vtbl_rec->name_len = cpu_to_be16(re->new_name_len);
145 memcpy(vtbl_rec->name, re->new_name, re->new_name_len);
146 memset(vtbl_rec->name + re->new_name_len, 0,
147 UBI_VOL_NAME_MAX + 1 - re->new_name_len);
148 crc = crc32(UBI_CRC32_INIT, vtbl_rec,
149 UBI_VTBL_RECORD_SIZE_CRC);
150 vtbl_rec->crc = cpu_to_be32(crc);
151 }
152
153 layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)];
154 for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
155 err = ubi_eba_unmap_leb(ubi, layout_vol, i);
156 if (err)
157 return err;
158
159 err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0,
160 ubi->vtbl_size, UBI_LONGTERM);
161 if (err)
162 return err;
163 }
164
165 return 0;
166}
167
168/**
169 * vtbl_check - check if volume table is not corrupted and sensible.
120 * @ubi: UBI device description object 170 * @ubi: UBI device description object
121 * @vtbl: volume table 171 * @vtbl: volume table
122 * 172 *
@@ -127,7 +177,7 @@ static int vtbl_check(const struct ubi_device *ubi,
127 const struct ubi_vtbl_record *vtbl) 177 const struct ubi_vtbl_record *vtbl)
128{ 178{
129 int i, n, reserved_pebs, alignment, data_pad, vol_type, name_len; 179 int i, n, reserved_pebs, alignment, data_pad, vol_type, name_len;
130 int upd_marker; 180 int upd_marker, err;
131 uint32_t crc; 181 uint32_t crc;
132 const char *name; 182 const char *name;
133 183
@@ -153,7 +203,7 @@ static int vtbl_check(const struct ubi_device *ubi,
153 if (reserved_pebs == 0) { 203 if (reserved_pebs == 0) {
154 if (memcmp(&vtbl[i], &empty_vtbl_record, 204 if (memcmp(&vtbl[i], &empty_vtbl_record,
155 UBI_VTBL_RECORD_SIZE)) { 205 UBI_VTBL_RECORD_SIZE)) {
156 dbg_err("bad empty record"); 206 err = 2;
157 goto bad; 207 goto bad;
158 } 208 }
159 continue; 209 continue;
@@ -161,56 +211,57 @@ static int vtbl_check(const struct ubi_device *ubi,
161 211
162 if (reserved_pebs < 0 || alignment < 0 || data_pad < 0 || 212 if (reserved_pebs < 0 || alignment < 0 || data_pad < 0 ||
163 name_len < 0) { 213 name_len < 0) {
164 dbg_err("negative values"); 214 err = 3;
165 goto bad; 215 goto bad;
166 } 216 }
167 217
168 if (alignment > ubi->leb_size || alignment == 0) { 218 if (alignment > ubi->leb_size || alignment == 0) {
169 dbg_err("bad alignment"); 219 err = 4;
170 goto bad; 220 goto bad;
171 } 221 }
172 222
173 n = alignment % ubi->min_io_size; 223 n = alignment & (ubi->min_io_size - 1);
174 if (alignment != 1 && n) { 224 if (alignment != 1 && n) {
175 dbg_err("alignment is not multiple of min I/O unit"); 225 err = 5;
176 goto bad; 226 goto bad;
177 } 227 }
178 228
179 n = ubi->leb_size % alignment; 229 n = ubi->leb_size % alignment;
180 if (data_pad != n) { 230 if (data_pad != n) {
181 dbg_err("bad data_pad, has to be %d", n); 231 dbg_err("bad data_pad, has to be %d", n);
232 err = 6;
182 goto bad; 233 goto bad;
183 } 234 }
184 235
185 if (vol_type != UBI_VID_DYNAMIC && vol_type != UBI_VID_STATIC) { 236 if (vol_type != UBI_VID_DYNAMIC && vol_type != UBI_VID_STATIC) {
186 dbg_err("bad vol_type"); 237 err = 7;
187 goto bad; 238 goto bad;
188 } 239 }
189 240
190 if (upd_marker != 0 && upd_marker != 1) { 241 if (upd_marker != 0 && upd_marker != 1) {
191 dbg_err("bad upd_marker"); 242 err = 8;
192 goto bad; 243 goto bad;
193 } 244 }
194 245
195 if (reserved_pebs > ubi->good_peb_count) { 246 if (reserved_pebs > ubi->good_peb_count) {
196 dbg_err("too large reserved_pebs, good PEBs %d", 247 dbg_err("too large reserved_pebs, good PEBs %d",
197 ubi->good_peb_count); 248 ubi->good_peb_count);
249 err = 9;
198 goto bad; 250 goto bad;
199 } 251 }
200 252
201 if (name_len > UBI_VOL_NAME_MAX) { 253 if (name_len > UBI_VOL_NAME_MAX) {
202 dbg_err("too long volume name, max %d", 254 err = 10;
203 UBI_VOL_NAME_MAX);
204 goto bad; 255 goto bad;
205 } 256 }
206 257
207 if (name[0] == '\0') { 258 if (name[0] == '\0') {
208 dbg_err("NULL volume name"); 259 err = 11;
209 goto bad; 260 goto bad;
210 } 261 }
211 262
212 if (name_len != strnlen(name, name_len + 1)) { 263 if (name_len != strnlen(name, name_len + 1)) {
213 dbg_err("bad name_len"); 264 err = 12;
214 goto bad; 265 goto bad;
215 } 266 }
216 } 267 }
@@ -235,7 +286,7 @@ static int vtbl_check(const struct ubi_device *ubi,
235 return 0; 286 return 0;
236 287
237bad: 288bad:
238 ubi_err("volume table check failed, record %d", i); 289 ubi_err("volume table check failed: record %d, error %d", i, err);
239 ubi_dbg_dump_vtbl_record(&vtbl[i], i); 290 ubi_dbg_dump_vtbl_record(&vtbl[i], i);
240 return -EINVAL; 291 return -EINVAL;
241} 292}
@@ -287,7 +338,6 @@ retry:
287 vid_hdr->data_pad = cpu_to_be32(0); 338 vid_hdr->data_pad = cpu_to_be32(0);
288 vid_hdr->lnum = cpu_to_be32(copy); 339 vid_hdr->lnum = cpu_to_be32(copy);
289 vid_hdr->sqnum = cpu_to_be64(++si->max_sqnum); 340 vid_hdr->sqnum = cpu_to_be64(++si->max_sqnum);
290 vid_hdr->leb_ver = cpu_to_be32(old_seb ? old_seb->leb_ver + 1: 0);
291 341
292 /* The EC header is already there, write the VID header */ 342 /* The EC header is already there, write the VID header */
293 err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr); 343 err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr);
@@ -370,7 +420,7 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
370 * to LEB 0. 420 * to LEB 0.
371 */ 421 */
372 422
373 dbg_msg("check layout volume"); 423 dbg_gen("check layout volume");
374 424
375 /* Read both LEB 0 and LEB 1 into memory */ 425 /* Read both LEB 0 and LEB 1 into memory */
376 ubi_rb_for_each_entry(rb, seb, &sv->root, u.rb) { 426 ubi_rb_for_each_entry(rb, seb, &sv->root, u.rb) {
@@ -384,7 +434,16 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
384 err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0, 434 err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0,
385 ubi->vtbl_size); 435 ubi->vtbl_size);
386 if (err == UBI_IO_BITFLIPS || err == -EBADMSG) 436 if (err == UBI_IO_BITFLIPS || err == -EBADMSG)
387 /* Scrub the PEB later */ 437 /*
438 * Scrub the PEB later. Note, -EBADMSG indicates an
439 * uncorrectable ECC error, but we have our own CRC and
440 * the data will be checked later. If the data is OK,
441 * the PEB will be scrubbed (because we set
442 * seb->scrub). If the data is not OK, the contents of
443 * the PEB will be recovered from the second copy, and
444 * seb->scrub will be cleared in
445 * 'ubi_scan_add_used()'.
446 */
388 seb->scrub = 1; 447 seb->scrub = 1;
389 else if (err) 448 else if (err)
390 goto out_free; 449 goto out_free;
@@ -400,7 +459,8 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
400 if (!leb_corrupted[0]) { 459 if (!leb_corrupted[0]) {
401 /* LEB 0 is OK */ 460 /* LEB 0 is OK */
402 if (leb[1]) 461 if (leb[1])
403 leb_corrupted[1] = memcmp(leb[0], leb[1], ubi->vtbl_size); 462 leb_corrupted[1] = memcmp(leb[0], leb[1],
463 ubi->vtbl_size);
404 if (leb_corrupted[1]) { 464 if (leb_corrupted[1]) {
405 ubi_warn("volume table copy #2 is corrupted"); 465 ubi_warn("volume table copy #2 is corrupted");
406 err = create_vtbl(ubi, si, 1, leb[0]); 466 err = create_vtbl(ubi, si, 1, leb[0]);
@@ -620,30 +680,32 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si,
620static int check_sv(const struct ubi_volume *vol, 680static int check_sv(const struct ubi_volume *vol,
621 const struct ubi_scan_volume *sv) 681 const struct ubi_scan_volume *sv)
622{ 682{
683 int err;
684
623 if (sv->highest_lnum >= vol->reserved_pebs) { 685 if (sv->highest_lnum >= vol->reserved_pebs) {
624 dbg_err("bad highest_lnum"); 686 err = 1;
625 goto bad; 687 goto bad;
626 } 688 }
627 if (sv->leb_count > vol->reserved_pebs) { 689 if (sv->leb_count > vol->reserved_pebs) {
628 dbg_err("bad leb_count"); 690 err = 2;
629 goto bad; 691 goto bad;
630 } 692 }
631 if (sv->vol_type != vol->vol_type) { 693 if (sv->vol_type != vol->vol_type) {
632 dbg_err("bad vol_type"); 694 err = 3;
633 goto bad; 695 goto bad;
634 } 696 }
635 if (sv->used_ebs > vol->reserved_pebs) { 697 if (sv->used_ebs > vol->reserved_pebs) {
636 dbg_err("bad used_ebs"); 698 err = 4;
637 goto bad; 699 goto bad;
638 } 700 }
639 if (sv->data_pad != vol->data_pad) { 701 if (sv->data_pad != vol->data_pad) {
640 dbg_err("bad data_pad"); 702 err = 5;
641 goto bad; 703 goto bad;
642 } 704 }
643 return 0; 705 return 0;
644 706
645bad: 707bad:
646 ubi_err("bad scanning information"); 708 ubi_err("bad scanning information, error %d", err);
647 ubi_dbg_dump_sv(sv); 709 ubi_dbg_dump_sv(sv);
648 ubi_dbg_dump_vol_info(vol); 710 ubi_dbg_dump_vol_info(vol);
649 return -EINVAL; 711 return -EINVAL;
@@ -672,14 +734,13 @@ static int check_scanning_info(const struct ubi_device *ubi,
672 return -EINVAL; 734 return -EINVAL;
673 } 735 }
674 736
675 if (si->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT&& 737 if (si->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT &&
676 si->highest_vol_id < UBI_INTERNAL_VOL_START) { 738 si->highest_vol_id < UBI_INTERNAL_VOL_START) {
677 ubi_err("too large volume ID %d found by scanning", 739 ubi_err("too large volume ID %d found by scanning",
678 si->highest_vol_id); 740 si->highest_vol_id);
679 return -EINVAL; 741 return -EINVAL;
680 } 742 }
681 743
682
683 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { 744 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
684 cond_resched(); 745 cond_resched();
685 746
@@ -717,8 +778,7 @@ static int check_scanning_info(const struct ubi_device *ubi,
717} 778}
718 779
719/** 780/**
720 * ubi_read_volume_table - read volume table. 781 * ubi_read_volume_table - read the volume table.
721 * information.
722 * @ubi: UBI device description object 782 * @ubi: UBI device description object
723 * @si: scanning information 783 * @si: scanning information
724 * 784 *
@@ -797,11 +857,10 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si)
797 857
798out_free: 858out_free:
799 vfree(ubi->vtbl); 859 vfree(ubi->vtbl);
800 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) 860 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
801 if (ubi->volumes[i]) { 861 kfree(ubi->volumes[i]);
802 kfree(ubi->volumes[i]); 862 ubi->volumes[i] = NULL;
803 ubi->volumes[i] = NULL; 863 }
804 }
805 return err; 864 return err;
806} 865}
807 866
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index a471a491f0ab..05d70937b543 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -19,22 +19,22 @@
19 */ 19 */
20 20
21/* 21/*
22 * UBI wear-leveling unit. 22 * UBI wear-leveling sub-system.
23 * 23 *
24 * This unit is responsible for wear-leveling. It works in terms of physical 24 * This sub-system is responsible for wear-leveling. It works in terms of
25 * eraseblocks and erase counters and knows nothing about logical eraseblocks, 25 * physical* eraseblocks and erase counters and knows nothing about logical
26 * volumes, etc. From this unit's perspective all physical eraseblocks are of 26 * eraseblocks, volumes, etc. From this sub-system's perspective all physical
27 * two types - used and free. Used physical eraseblocks are those that were 27 * eraseblocks are of two types - used and free. Used physical eraseblocks are
28 * "get" by the 'ubi_wl_get_peb()' function, and free physical eraseblocks are 28 * those that were "get" by the 'ubi_wl_get_peb()' function, and free physical
29 * those that were put by the 'ubi_wl_put_peb()' function. 29 * eraseblocks are those that were put by the 'ubi_wl_put_peb()' function.
30 * 30 *
31 * Physical eraseblocks returned by 'ubi_wl_get_peb()' have only erase counter 31 * Physical eraseblocks returned by 'ubi_wl_get_peb()' have only erase counter
32 * header. The rest of the physical eraseblock contains only 0xFF bytes. 32 * header. The rest of the physical eraseblock contains only %0xFF bytes.
33 * 33 *
34 * When physical eraseblocks are returned to the WL unit by means of the 34 * When physical eraseblocks are returned to the WL sub-system by means of the
35 * 'ubi_wl_put_peb()' function, they are scheduled for erasure. The erasure is 35 * 'ubi_wl_put_peb()' function, they are scheduled for erasure. The erasure is
36 * done asynchronously in context of the per-UBI device background thread, 36 * done asynchronously in context of the per-UBI device background thread,
37 * which is also managed by the WL unit. 37 * which is also managed by the WL sub-system.
38 * 38 *
39 * The wear-leveling is ensured by means of moving the contents of used 39 * The wear-leveling is ensured by means of moving the contents of used
40 * physical eraseblocks with low erase counter to free physical eraseblocks 40 * physical eraseblocks with low erase counter to free physical eraseblocks
@@ -43,34 +43,36 @@
43 * The 'ubi_wl_get_peb()' function accepts data type hints which help to pick 43 * The 'ubi_wl_get_peb()' function accepts data type hints which help to pick
44 * an "optimal" physical eraseblock. For example, when it is known that the 44 * an "optimal" physical eraseblock. For example, when it is known that the
45 * physical eraseblock will be "put" soon because it contains short-term data, 45 * physical eraseblock will be "put" soon because it contains short-term data,
46 * the WL unit may pick a free physical eraseblock with low erase counter, and 46 * the WL sub-system may pick a free physical eraseblock with low erase
47 * so forth. 47 * counter, and so forth.
48 * 48 *
49 * If the WL unit fails to erase a physical eraseblock, it marks it as bad. 49 * If the WL sub-system fails to erase a physical eraseblock, it marks it as
50 * bad.
50 * 51 *
51 * This unit is also responsible for scrubbing. If a bit-flip is detected in a 52 * This sub-system is also responsible for scrubbing. If a bit-flip is detected
52 * physical eraseblock, it has to be moved. Technically this is the same as 53 * in a physical eraseblock, it has to be moved. Technically this is the same
53 * moving it for wear-leveling reasons. 54 * as moving it for wear-leveling reasons.
54 * 55 *
55 * As it was said, for the UBI unit all physical eraseblocks are either "free" 56 * As it was said, for the UBI sub-system all physical eraseblocks are either
56 * or "used". Free eraseblock are kept in the @wl->free RB-tree, while used 57 * "free" or "used". Free eraseblock are kept in the @wl->free RB-tree, while
57 * eraseblocks are kept in a set of different RB-trees: @wl->used, 58 * used eraseblocks are kept in a set of different RB-trees: @wl->used,
58 * @wl->prot.pnum, @wl->prot.aec, and @wl->scrub. 59 * @wl->prot.pnum, @wl->prot.aec, and @wl->scrub.
59 * 60 *
60 * Note, in this implementation, we keep a small in-RAM object for each physical 61 * Note, in this implementation, we keep a small in-RAM object for each physical
61 * eraseblock. This is surely not a scalable solution. But it appears to be good 62 * eraseblock. This is surely not a scalable solution. But it appears to be good
62 * enough for moderately large flashes and it is simple. In future, one may 63 * enough for moderately large flashes and it is simple. In future, one may
63 * re-work this unit and make it more scalable. 64 * re-work this sub-system and make it more scalable.
64 * 65 *
65 * At the moment this unit does not utilize the sequence number, which was 66 * At the moment this sub-system does not utilize the sequence number, which
66 * introduced relatively recently. But it would be wise to do this because the 67 * was introduced relatively recently. But it would be wise to do this because
67 * sequence number of a logical eraseblock characterizes how old is it. For 68 * the sequence number of a logical eraseblock characterizes how old is it. For
68 * example, when we move a PEB with low erase counter, and we need to pick the 69 * example, when we move a PEB with low erase counter, and we need to pick the
69 * target PEB, we pick a PEB with the highest EC if our PEB is "old" and we 70 * target PEB, we pick a PEB with the highest EC if our PEB is "old" and we
70 * pick target PEB with an average EC if our PEB is not very "old". This is a 71 * pick target PEB with an average EC if our PEB is not very "old". This is a
71 * room for future re-works of the WL unit. 72 * room for future re-works of the WL sub-system.
72 * 73 *
73 * FIXME: looks too complex, should be simplified (later). 74 * Note: the stuff with protection trees looks too complex and is difficult to
75 * understand. Should be fixed.
74 */ 76 */
75 77
76#include <linux/slab.h> 78#include <linux/slab.h>
@@ -92,20 +94,21 @@
92 94
93/* 95/*
94 * Maximum difference between two erase counters. If this threshold is 96 * Maximum difference between two erase counters. If this threshold is
95 * exceeded, the WL unit starts moving data from used physical eraseblocks with 97 * exceeded, the WL sub-system starts moving data from used physical
96 * low erase counter to free physical eraseblocks with high erase counter. 98 * eraseblocks with low erase counter to free physical eraseblocks with high
99 * erase counter.
97 */ 100 */
98#define UBI_WL_THRESHOLD CONFIG_MTD_UBI_WL_THRESHOLD 101#define UBI_WL_THRESHOLD CONFIG_MTD_UBI_WL_THRESHOLD
99 102
100/* 103/*
101 * When a physical eraseblock is moved, the WL unit has to pick the target 104 * When a physical eraseblock is moved, the WL sub-system has to pick the target
102 * physical eraseblock to move to. The simplest way would be just to pick the 105 * physical eraseblock to move to. The simplest way would be just to pick the
103 * one with the highest erase counter. But in certain workloads this could lead 106 * one with the highest erase counter. But in certain workloads this could lead
104 * to an unlimited wear of one or few physical eraseblock. Indeed, imagine a 107 * to an unlimited wear of one or few physical eraseblock. Indeed, imagine a
105 * situation when the picked physical eraseblock is constantly erased after the 108 * situation when the picked physical eraseblock is constantly erased after the
106 * data is written to it. So, we have a constant which limits the highest erase 109 * data is written to it. So, we have a constant which limits the highest erase
107 * counter of the free physical eraseblock to pick. Namely, the WL unit does 110 * counter of the free physical eraseblock to pick. Namely, the WL sub-system
108 * not pick eraseblocks with erase counter greater then the lowest erase 111 * does not pick eraseblocks with erase counter greater then the lowest erase
109 * counter plus %WL_FREE_MAX_DIFF. 112 * counter plus %WL_FREE_MAX_DIFF.
110 */ 113 */
111#define WL_FREE_MAX_DIFF (2*UBI_WL_THRESHOLD) 114#define WL_FREE_MAX_DIFF (2*UBI_WL_THRESHOLD)
@@ -123,11 +126,11 @@
123 * @abs_ec: the absolute erase counter value when the protection ends 126 * @abs_ec: the absolute erase counter value when the protection ends
124 * @e: the wear-leveling entry of the physical eraseblock under protection 127 * @e: the wear-leveling entry of the physical eraseblock under protection
125 * 128 *
126 * When the WL unit returns a physical eraseblock, the physical eraseblock is 129 * When the WL sub-system returns a physical eraseblock, the physical
127 * protected from being moved for some "time". For this reason, the physical 130 * eraseblock is protected from being moved for some "time". For this reason,
128 * eraseblock is not directly moved from the @wl->free tree to the @wl->used 131 * the physical eraseblock is not directly moved from the @wl->free tree to the
129 * tree. There is one more tree in between where this physical eraseblock is 132 * @wl->used tree. There is one more tree in between where this physical
130 * temporarily stored (@wl->prot). 133 * eraseblock is temporarily stored (@wl->prot).
131 * 134 *
132 * All this protection stuff is needed because: 135 * All this protection stuff is needed because:
133 * o we don't want to move physical eraseblocks just after we have given them 136 * o we don't want to move physical eraseblocks just after we have given them
@@ -175,7 +178,6 @@ struct ubi_wl_prot_entry {
175 * @list: a link in the list of pending works 178 * @list: a link in the list of pending works
176 * @func: worker function 179 * @func: worker function
177 * @priv: private data of the worker function 180 * @priv: private data of the worker function
178 *
179 * @e: physical eraseblock to erase 181 * @e: physical eraseblock to erase
180 * @torture: if the physical eraseblock has to be tortured 182 * @torture: if the physical eraseblock has to be tortured
181 * 183 *
@@ -473,52 +475,47 @@ retry:
473 } 475 }
474 476
475 switch (dtype) { 477 switch (dtype) {
476 case UBI_LONGTERM: 478 case UBI_LONGTERM:
477 /* 479 /*
478 * For long term data we pick a physical eraseblock 480 * For long term data we pick a physical eraseblock with high
479 * with high erase counter. But the highest erase 481 * erase counter. But the highest erase counter we can pick is
480 * counter we can pick is bounded by the the lowest 482 * bounded by the the lowest erase counter plus
481 * erase counter plus %WL_FREE_MAX_DIFF. 483 * %WL_FREE_MAX_DIFF.
482 */ 484 */
483 e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF); 485 e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF);
484 protect = LT_PROTECTION; 486 protect = LT_PROTECTION;
485 break; 487 break;
486 case UBI_UNKNOWN: 488 case UBI_UNKNOWN:
487 /* 489 /*
488 * For unknown data we pick a physical eraseblock with 490 * For unknown data we pick a physical eraseblock with medium
489 * medium erase counter. But we by no means can pick a 491 * erase counter. But we by no means can pick a physical
490 * physical eraseblock with erase counter greater or 492 * eraseblock with erase counter greater or equivalent than the
491 * equivalent than the lowest erase counter plus 493 * lowest erase counter plus %WL_FREE_MAX_DIFF.
492 * %WL_FREE_MAX_DIFF. 494 */
493 */ 495 first = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, rb);
494 first = rb_entry(rb_first(&ubi->free), 496 last = rb_entry(rb_last(&ubi->free), struct ubi_wl_entry, rb);
495 struct ubi_wl_entry, rb);
496 last = rb_entry(rb_last(&ubi->free),
497 struct ubi_wl_entry, rb);
498 497
499 if (last->ec - first->ec < WL_FREE_MAX_DIFF) 498 if (last->ec - first->ec < WL_FREE_MAX_DIFF)
500 e = rb_entry(ubi->free.rb_node, 499 e = rb_entry(ubi->free.rb_node,
501 struct ubi_wl_entry, rb); 500 struct ubi_wl_entry, rb);
502 else { 501 else {
503 medium_ec = (first->ec + WL_FREE_MAX_DIFF)/2; 502 medium_ec = (first->ec + WL_FREE_MAX_DIFF)/2;
504 e = find_wl_entry(&ubi->free, medium_ec); 503 e = find_wl_entry(&ubi->free, medium_ec);
505 } 504 }
506 protect = U_PROTECTION; 505 protect = U_PROTECTION;
507 break; 506 break;
508 case UBI_SHORTTERM: 507 case UBI_SHORTTERM:
509 /* 508 /*
510 * For short term data we pick a physical eraseblock 509 * For short term data we pick a physical eraseblock with the
511 * with the lowest erase counter as we expect it will 510 * lowest erase counter as we expect it will be erased soon.
512 * be erased soon. 511 */
513 */ 512 e = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, rb);
514 e = rb_entry(rb_first(&ubi->free), 513 protect = ST_PROTECTION;
515 struct ubi_wl_entry, rb); 514 break;
516 protect = ST_PROTECTION; 515 default:
517 break; 516 protect = 0;
518 default: 517 e = NULL;
519 protect = 0; 518 BUG();
520 e = NULL;
521 BUG();
522 } 519 }
523 520
524 /* 521 /*
@@ -582,7 +579,8 @@ found:
582 * This function returns zero in case of success and a negative error code in 579 * This function returns zero in case of success and a negative error code in
583 * case of failure. 580 * case of failure.
584 */ 581 */
585static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int torture) 582static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
583 int torture)
586{ 584{
587 int err; 585 int err;
588 struct ubi_ec_hdr *ec_hdr; 586 struct ubi_ec_hdr *ec_hdr;
@@ -634,8 +632,7 @@ out_free:
634} 632}
635 633
636/** 634/**
637 * check_protection_over - check if it is time to stop protecting some 635 * check_protection_over - check if it is time to stop protecting some PEBs.
638 * physical eraseblocks.
639 * @ubi: UBI device description object 636 * @ubi: UBI device description object
640 * 637 *
641 * This function is called after each erase operation, when the absolute erase 638 * This function is called after each erase operation, when the absolute erase
@@ -871,6 +868,10 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
871 } 868 }
872 869
873 ubi_free_vid_hdr(ubi, vid_hdr); 870 ubi_free_vid_hdr(ubi, vid_hdr);
871 if (scrubbing && !protect)
872 ubi_msg("scrubbed PEB %d, data moved to PEB %d",
873 e1->pnum, e2->pnum);
874
874 spin_lock(&ubi->wl_lock); 875 spin_lock(&ubi->wl_lock);
875 if (protect) 876 if (protect)
876 prot_tree_add(ubi, e1, pe, protect); 877 prot_tree_add(ubi, e1, pe, protect);
@@ -1054,8 +1055,8 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
1054 spin_unlock(&ubi->wl_lock); 1055 spin_unlock(&ubi->wl_lock);
1055 1056
1056 /* 1057 /*
1057 * One more erase operation has happened, take care about protected 1058 * One more erase operation has happened, take care about
1058 * physical eraseblocks. 1059 * protected physical eraseblocks.
1059 */ 1060 */
1060 check_protection_over(ubi); 1061 check_protection_over(ubi);
1061 1062
@@ -1136,7 +1137,7 @@ out_ro:
1136} 1137}
1137 1138
1138/** 1139/**
1139 * ubi_wl_put_peb - return a physical eraseblock to the wear-leveling unit. 1140 * ubi_wl_put_peb - return a PEB to the wear-leveling sub-system.
1140 * @ubi: UBI device description object 1141 * @ubi: UBI device description object
1141 * @pnum: physical eraseblock to return 1142 * @pnum: physical eraseblock to return
1142 * @torture: if this physical eraseblock has to be tortured 1143 * @torture: if this physical eraseblock has to be tortured
@@ -1175,11 +1176,11 @@ retry:
1175 /* 1176 /*
1176 * User is putting the physical eraseblock which was selected 1177 * User is putting the physical eraseblock which was selected
1177 * as the target the data is moved to. It may happen if the EBA 1178 * as the target the data is moved to. It may happen if the EBA
1178 * unit already re-mapped the LEB in 'ubi_eba_copy_leb()' but 1179 * sub-system already re-mapped the LEB in 'ubi_eba_copy_leb()'
1179 * the WL unit has not put the PEB to the "used" tree yet, but 1180 * but the WL sub-system has not put the PEB to the "used" tree
1180 * it is about to do this. So we just set a flag which will 1181 * yet, but it is about to do this. So we just set a flag which
1181 * tell the WL worker that the PEB is not needed anymore and 1182 * will tell the WL worker that the PEB is not needed anymore
1182 * should be scheduled for erasure. 1183 * and should be scheduled for erasure.
1183 */ 1184 */
1184 dbg_wl("PEB %d is the target of data moving", pnum); 1185 dbg_wl("PEB %d is the target of data moving", pnum);
1185 ubi_assert(!ubi->move_to_put); 1186 ubi_assert(!ubi->move_to_put);
@@ -1229,7 +1230,7 @@ int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum)
1229{ 1230{
1230 struct ubi_wl_entry *e; 1231 struct ubi_wl_entry *e;
1231 1232
1232 ubi_msg("schedule PEB %d for scrubbing", pnum); 1233 dbg_msg("schedule PEB %d for scrubbing", pnum);
1233 1234
1234retry: 1235retry:
1235 spin_lock(&ubi->wl_lock); 1236 spin_lock(&ubi->wl_lock);
@@ -1368,7 +1369,7 @@ int ubi_thread(void *u)
1368 int err; 1369 int err;
1369 1370
1370 if (kthread_should_stop()) 1371 if (kthread_should_stop())
1371 goto out; 1372 break;
1372 1373
1373 if (try_to_freeze()) 1374 if (try_to_freeze())
1374 continue; 1375 continue;
@@ -1403,7 +1404,6 @@ int ubi_thread(void *u)
1403 cond_resched(); 1404 cond_resched();
1404 } 1405 }
1405 1406
1406out:
1407 dbg_wl("background thread \"%s\" is killed", ubi->bgt_name); 1407 dbg_wl("background thread \"%s\" is killed", ubi->bgt_name);
1408 return 0; 1408 return 0;
1409} 1409}
@@ -1426,8 +1426,7 @@ static void cancel_pending(struct ubi_device *ubi)
1426} 1426}
1427 1427
1428/** 1428/**
1429 * ubi_wl_init_scan - initialize the wear-leveling unit using scanning 1429 * ubi_wl_init_scan - initialize the WL sub-system using scanning information.
1430 * information.
1431 * @ubi: UBI device description object 1430 * @ubi: UBI device description object
1432 * @si: scanning information 1431 * @si: scanning information
1433 * 1432 *
@@ -1584,13 +1583,12 @@ static void protection_trees_destroy(struct ubi_device *ubi)
1584} 1583}
1585 1584
1586/** 1585/**
1587 * ubi_wl_close - close the wear-leveling unit. 1586 * ubi_wl_close - close the wear-leveling sub-system.
1588 * @ubi: UBI device description object 1587 * @ubi: UBI device description object
1589 */ 1588 */
1590void ubi_wl_close(struct ubi_device *ubi) 1589void ubi_wl_close(struct ubi_device *ubi)
1591{ 1590{
1592 dbg_wl("close the UBI wear-leveling unit"); 1591 dbg_wl("close the WL sub-system");
1593
1594 cancel_pending(ubi); 1592 cancel_pending(ubi);
1595 protection_trees_destroy(ubi); 1593 protection_trees_destroy(ubi);
1596 tree_destroy(&ubi->used); 1594 tree_destroy(&ubi->used);
@@ -1602,8 +1600,7 @@ void ubi_wl_close(struct ubi_device *ubi)
1602#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 1600#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
1603 1601
1604/** 1602/**
1605 * paranoid_check_ec - make sure that the erase counter of a physical eraseblock 1603 * paranoid_check_ec - make sure that the erase counter of a PEB is correct.
1606 * is correct.
1607 * @ubi: UBI device description object 1604 * @ubi: UBI device description object
1608 * @pnum: the physical eraseblock number to check 1605 * @pnum: the physical eraseblock number to check
1609 * @ec: the erase counter to check 1606 * @ec: the erase counter to check
@@ -1644,13 +1641,12 @@ out_free:
1644} 1641}
1645 1642
1646/** 1643/**
1647 * paranoid_check_in_wl_tree - make sure that a wear-leveling entry is present 1644 * paranoid_check_in_wl_tree - check that wear-leveling entry is in WL RB-tree.
1648 * in a WL RB-tree.
1649 * @e: the wear-leveling entry to check 1645 * @e: the wear-leveling entry to check
1650 * @root: the root of the tree 1646 * @root: the root of the tree
1651 * 1647 *
1652 * This function returns zero if @e is in the @root RB-tree and %1 if it 1648 * This function returns zero if @e is in the @root RB-tree and %1 if it is
1653 * is not. 1649 * not.
1654 */ 1650 */
1655static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, 1651static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
1656 struct rb_root *root) 1652 struct rb_root *root)
diff --git a/drivers/net/arm/ep93xx_eth.c b/drivers/net/arm/ep93xx_eth.c
index 7a14980f3472..18d3eeb7eab2 100644
--- a/drivers/net/arm/ep93xx_eth.c
+++ b/drivers/net/arm/ep93xx_eth.c
@@ -482,7 +482,7 @@ static int ep93xx_alloc_buffers(struct ep93xx_priv *ep)
482 goto err; 482 goto err;
483 483
484 d = dma_map_single(NULL, page, PAGE_SIZE, DMA_FROM_DEVICE); 484 d = dma_map_single(NULL, page, PAGE_SIZE, DMA_FROM_DEVICE);
485 if (dma_mapping_error(d)) { 485 if (dma_mapping_error(NULL, d)) {
486 free_page((unsigned long)page); 486 free_page((unsigned long)page);
487 goto err; 487 goto err;
488 } 488 }
@@ -505,7 +505,7 @@ static int ep93xx_alloc_buffers(struct ep93xx_priv *ep)
505 goto err; 505 goto err;
506 506
507 d = dma_map_single(NULL, page, PAGE_SIZE, DMA_TO_DEVICE); 507 d = dma_map_single(NULL, page, PAGE_SIZE, DMA_TO_DEVICE);
508 if (dma_mapping_error(d)) { 508 if (dma_mapping_error(NULL, d)) {
509 free_page((unsigned long)page); 509 free_page((unsigned long)page);
510 goto err; 510 goto err;
511 } 511 }
diff --git a/drivers/net/bnx2x_main.c b/drivers/net/bnx2x_main.c
index 0263bef9cc6d..af251a5df844 100644
--- a/drivers/net/bnx2x_main.c
+++ b/drivers/net/bnx2x_main.c
@@ -814,7 +814,7 @@ static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fastpath *fp,
814 } 814 }
815 815
816 /* release skb */ 816 /* release skb */
817 BUG_TRAP(skb); 817 WARN_ON(!skb);
818 dev_kfree_skb(skb); 818 dev_kfree_skb(skb);
819 tx_buf->first_bd = 0; 819 tx_buf->first_bd = 0;
820 tx_buf->skb = NULL; 820 tx_buf->skb = NULL;
@@ -837,9 +837,9 @@ static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp)
837 used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS; 837 used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS;
838 838
839#ifdef BNX2X_STOP_ON_ERROR 839#ifdef BNX2X_STOP_ON_ERROR
840 BUG_TRAP(used >= 0); 840 WARN_ON(used < 0);
841 BUG_TRAP(used <= fp->bp->tx_ring_size); 841 WARN_ON(used > fp->bp->tx_ring_size);
842 BUG_TRAP((fp->bp->tx_ring_size - used) <= MAX_TX_AVAIL); 842 WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL);
843#endif 843#endif
844 844
845 return (s16)(fp->bp->tx_ring_size) - used; 845 return (s16)(fp->bp->tx_ring_size) - used;
@@ -1020,7 +1020,7 @@ static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp,
1020 1020
1021 mapping = pci_map_page(bp->pdev, page, 0, BCM_PAGE_SIZE*PAGES_PER_SGE, 1021 mapping = pci_map_page(bp->pdev, page, 0, BCM_PAGE_SIZE*PAGES_PER_SGE,
1022 PCI_DMA_FROMDEVICE); 1022 PCI_DMA_FROMDEVICE);
1023 if (unlikely(dma_mapping_error(mapping))) { 1023 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
1024 __free_pages(page, PAGES_PER_SGE_SHIFT); 1024 __free_pages(page, PAGES_PER_SGE_SHIFT);
1025 return -ENOMEM; 1025 return -ENOMEM;
1026 } 1026 }
@@ -1048,7 +1048,7 @@ static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp,
1048 1048
1049 mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size, 1049 mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size,
1050 PCI_DMA_FROMDEVICE); 1050 PCI_DMA_FROMDEVICE);
1051 if (unlikely(dma_mapping_error(mapping))) { 1051 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
1052 dev_kfree_skb(skb); 1052 dev_kfree_skb(skb);
1053 return -ENOMEM; 1053 return -ENOMEM;
1054 } 1054 }
@@ -4374,7 +4374,7 @@ static void bnx2x_init_rx_rings(struct bnx2x *bp)
4374 } 4374 }
4375 ring_prod = NEXT_RX_IDX(ring_prod); 4375 ring_prod = NEXT_RX_IDX(ring_prod);
4376 cqe_ring_prod = NEXT_RCQ_IDX(cqe_ring_prod); 4376 cqe_ring_prod = NEXT_RCQ_IDX(cqe_ring_prod);
4377 BUG_TRAP(ring_prod > i); 4377 WARN_ON(ring_prod <= i);
4378 } 4378 }
4379 4379
4380 fp->rx_bd_prod = ring_prod; 4380 fp->rx_bd_prod = ring_prod;
diff --git a/drivers/net/cassini.c b/drivers/net/cassini.c
index 83768df27806..f1936d51b458 100644
--- a/drivers/net/cassini.c
+++ b/drivers/net/cassini.c
@@ -576,6 +576,18 @@ static void cas_spare_recover(struct cas *cp, const gfp_t flags)
576 list_for_each_safe(elem, tmp, &list) { 576 list_for_each_safe(elem, tmp, &list) {
577 cas_page_t *page = list_entry(elem, cas_page_t, list); 577 cas_page_t *page = list_entry(elem, cas_page_t, list);
578 578
579 /*
580 * With the lockless pagecache, cassini buffering scheme gets
581 * slightly less accurate: we might find that a page has an
582 * elevated reference count here, due to a speculative ref,
583 * and skip it as in-use. Ideally we would be able to reclaim
584 * it. However this would be such a rare case, it doesn't
585 * matter too much as we should pick it up the next time round.
586 *
587 * Importantly, if we find that the page has a refcount of 1
588 * here (our refcount), then we know it is definitely not inuse
589 * so we can reuse it.
590 */
579 if (page_count(page->buffer) > 1) 591 if (page_count(page->buffer) > 1)
580 continue; 592 continue;
581 593
diff --git a/drivers/net/cxgb3/sge.c b/drivers/net/cxgb3/sge.c
index a96331c875e6..1b0861d73ab7 100644
--- a/drivers/net/cxgb3/sge.c
+++ b/drivers/net/cxgb3/sge.c
@@ -386,7 +386,7 @@ static inline int add_one_rx_buf(void *va, unsigned int len,
386 dma_addr_t mapping; 386 dma_addr_t mapping;
387 387
388 mapping = pci_map_single(pdev, va, len, PCI_DMA_FROMDEVICE); 388 mapping = pci_map_single(pdev, va, len, PCI_DMA_FROMDEVICE);
389 if (unlikely(pci_dma_mapping_error(mapping))) 389 if (unlikely(pci_dma_mapping_error(pdev, mapping)))
390 return -ENOMEM; 390 return -ENOMEM;
391 391
392 pci_unmap_addr_set(sd, dma_addr, mapping); 392 pci_unmap_addr_set(sd, dma_addr, mapping);
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index 1037b1332312..19d32a227be1 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -1790,7 +1790,7 @@ static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
1790 rx->dma_addr = pci_map_single(nic->pdev, rx->skb->data, 1790 rx->dma_addr = pci_map_single(nic->pdev, rx->skb->data,
1791 RFD_BUF_LEN, PCI_DMA_BIDIRECTIONAL); 1791 RFD_BUF_LEN, PCI_DMA_BIDIRECTIONAL);
1792 1792
1793 if (pci_dma_mapping_error(rx->dma_addr)) { 1793 if (pci_dma_mapping_error(nic->pdev, rx->dma_addr)) {
1794 dev_kfree_skb_any(rx->skb); 1794 dev_kfree_skb_any(rx->skb);
1795 rx->skb = NULL; 1795 rx->skb = NULL;
1796 rx->dma_addr = 0; 1796 rx->dma_addr = 0;
diff --git a/drivers/net/e1000e/ethtool.c b/drivers/net/e1000e/ethtool.c
index a14561f40db0..9350564065e7 100644
--- a/drivers/net/e1000e/ethtool.c
+++ b/drivers/net/e1000e/ethtool.c
@@ -1090,7 +1090,7 @@ static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1090 tx_ring->buffer_info[i].dma = 1090 tx_ring->buffer_info[i].dma =
1091 pci_map_single(pdev, skb->data, skb->len, 1091 pci_map_single(pdev, skb->data, skb->len,
1092 PCI_DMA_TODEVICE); 1092 PCI_DMA_TODEVICE);
1093 if (pci_dma_mapping_error(tx_ring->buffer_info[i].dma)) { 1093 if (pci_dma_mapping_error(pdev, tx_ring->buffer_info[i].dma)) {
1094 ret_val = 4; 1094 ret_val = 4;
1095 goto err_nomem; 1095 goto err_nomem;
1096 } 1096 }
@@ -1153,7 +1153,7 @@ static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1153 rx_ring->buffer_info[i].dma = 1153 rx_ring->buffer_info[i].dma =
1154 pci_map_single(pdev, skb->data, 2048, 1154 pci_map_single(pdev, skb->data, 2048,
1155 PCI_DMA_FROMDEVICE); 1155 PCI_DMA_FROMDEVICE);
1156 if (pci_dma_mapping_error(rx_ring->buffer_info[i].dma)) { 1156 if (pci_dma_mapping_error(pdev, rx_ring->buffer_info[i].dma)) {
1157 ret_val = 8; 1157 ret_val = 8;
1158 goto err_nomem; 1158 goto err_nomem;
1159 } 1159 }
diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c
index 869544b8c05c..d13677899767 100644
--- a/drivers/net/e1000e/netdev.c
+++ b/drivers/net/e1000e/netdev.c
@@ -195,7 +195,7 @@ map_skb:
195 buffer_info->dma = pci_map_single(pdev, skb->data, 195 buffer_info->dma = pci_map_single(pdev, skb->data,
196 adapter->rx_buffer_len, 196 adapter->rx_buffer_len,
197 PCI_DMA_FROMDEVICE); 197 PCI_DMA_FROMDEVICE);
198 if (pci_dma_mapping_error(buffer_info->dma)) { 198 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
199 dev_err(&pdev->dev, "RX DMA map failed\n"); 199 dev_err(&pdev->dev, "RX DMA map failed\n");
200 adapter->rx_dma_failed++; 200 adapter->rx_dma_failed++;
201 break; 201 break;
@@ -265,7 +265,7 @@ static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
265 ps_page->page, 265 ps_page->page,
266 0, PAGE_SIZE, 266 0, PAGE_SIZE,
267 PCI_DMA_FROMDEVICE); 267 PCI_DMA_FROMDEVICE);
268 if (pci_dma_mapping_error(ps_page->dma)) { 268 if (pci_dma_mapping_error(pdev, ps_page->dma)) {
269 dev_err(&adapter->pdev->dev, 269 dev_err(&adapter->pdev->dev,
270 "RX DMA page map failed\n"); 270 "RX DMA page map failed\n");
271 adapter->rx_dma_failed++; 271 adapter->rx_dma_failed++;
@@ -300,7 +300,7 @@ static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
300 buffer_info->dma = pci_map_single(pdev, skb->data, 300 buffer_info->dma = pci_map_single(pdev, skb->data,
301 adapter->rx_ps_bsize0, 301 adapter->rx_ps_bsize0,
302 PCI_DMA_FROMDEVICE); 302 PCI_DMA_FROMDEVICE);
303 if (pci_dma_mapping_error(buffer_info->dma)) { 303 if (pci_dma_mapping_error(pdev, buffer_info->dma)) {
304 dev_err(&pdev->dev, "RX DMA map failed\n"); 304 dev_err(&pdev->dev, "RX DMA map failed\n");
305 adapter->rx_dma_failed++; 305 adapter->rx_dma_failed++;
306 /* cleanup skb */ 306 /* cleanup skb */
@@ -3344,7 +3344,7 @@ static int e1000_tx_map(struct e1000_adapter *adapter,
3344 skb->data + offset, 3344 skb->data + offset,
3345 size, 3345 size,
3346 PCI_DMA_TODEVICE); 3346 PCI_DMA_TODEVICE);
3347 if (pci_dma_mapping_error(buffer_info->dma)) { 3347 if (pci_dma_mapping_error(adapter->pdev, buffer_info->dma)) {
3348 dev_err(&adapter->pdev->dev, "TX DMA map failed\n"); 3348 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
3349 adapter->tx_dma_failed++; 3349 adapter->tx_dma_failed++;
3350 return -1; 3350 return -1;
@@ -3382,7 +3382,8 @@ static int e1000_tx_map(struct e1000_adapter *adapter,
3382 offset, 3382 offset,
3383 size, 3383 size,
3384 PCI_DMA_TODEVICE); 3384 PCI_DMA_TODEVICE);
3385 if (pci_dma_mapping_error(buffer_info->dma)) { 3385 if (pci_dma_mapping_error(adapter->pdev,
3386 buffer_info->dma)) {
3386 dev_err(&adapter->pdev->dev, 3387 dev_err(&adapter->pdev->dev,
3387 "TX DMA page map failed\n"); 3388 "TX DMA page map failed\n");
3388 adapter->tx_dma_failed++; 3389 adapter->tx_dma_failed++;
@@ -4067,8 +4068,6 @@ static void e1000_netpoll(struct net_device *netdev)
4067 disable_irq(adapter->pdev->irq); 4068 disable_irq(adapter->pdev->irq);
4068 e1000_intr(adapter->pdev->irq, netdev); 4069 e1000_intr(adapter->pdev->irq, netdev);
4069 4070
4070 e1000_clean_tx_irq(adapter);
4071
4072 enable_irq(adapter->pdev->irq); 4071 enable_irq(adapter->pdev->irq);
4073} 4072}
4074#endif 4073#endif
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 32a4f17d35fc..ecd5c71a7a8a 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -2,12 +2,6 @@
2 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx. 2 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
3 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net) 3 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
4 * 4 *
5 * This version of the driver is specific to the FADS implementation,
6 * since the board contains control registers external to the processor
7 * for the control of the LevelOne LXT970 transceiver. The MPC860T manual
8 * describes connections using the internal parallel port I/O, which
9 * is basically all of Port D.
10 *
11 * Right now, I am very wasteful with the buffers. I allocate memory 5 * Right now, I am very wasteful with the buffers. I allocate memory
12 * pages and then divide them into 2K frame buffers. This way I know I 6 * pages and then divide them into 2K frame buffers. This way I know I
13 * have buffers large enough to hold one frame within one buffer descriptor. 7 * have buffers large enough to hold one frame within one buffer descriptor.
@@ -49,17 +43,9 @@
49#include <asm/pgtable.h> 43#include <asm/pgtable.h>
50#include <asm/cacheflush.h> 44#include <asm/cacheflush.h>
51 45
52#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || \
53 defined(CONFIG_M5272) || defined(CONFIG_M528x) || \
54 defined(CONFIG_M520x) || defined(CONFIG_M532x)
55#include <asm/coldfire.h> 46#include <asm/coldfire.h>
56#include <asm/mcfsim.h> 47#include <asm/mcfsim.h>
57#include "fec.h" 48#include "fec.h"
58#else
59#include <asm/8xx_immap.h>
60#include <asm/mpc8xx.h>
61#include "commproc.h"
62#endif
63 49
64#if defined(CONFIG_FEC2) 50#if defined(CONFIG_FEC2)
65#define FEC_MAX_PORTS 2 51#define FEC_MAX_PORTS 2
@@ -67,7 +53,7 @@
67#define FEC_MAX_PORTS 1 53#define FEC_MAX_PORTS 1
68#endif 54#endif
69 55
70#if defined(CONFIG_FADS) || defined(CONFIG_RPXCLASSIC) || defined(CONFIG_M5272) 56#if defined(CONFIG_M5272)
71#define HAVE_mii_link_interrupt 57#define HAVE_mii_link_interrupt
72#endif 58#endif
73 59
@@ -1235,14 +1221,9 @@ static phy_info_t const * const phy_info[] = {
1235 1221
1236/* ------------------------------------------------------------------------- */ 1222/* ------------------------------------------------------------------------- */
1237#ifdef HAVE_mii_link_interrupt 1223#ifdef HAVE_mii_link_interrupt
1238#ifdef CONFIG_RPXCLASSIC
1239static void
1240mii_link_interrupt(void *dev_id);
1241#else
1242static irqreturn_t 1224static irqreturn_t
1243mii_link_interrupt(int irq, void * dev_id); 1225mii_link_interrupt(int irq, void * dev_id);
1244#endif 1226#endif
1245#endif
1246 1227
1247#if defined(CONFIG_M5272) 1228#if defined(CONFIG_M5272)
1248/* 1229/*
@@ -1795,24 +1776,6 @@ static void __inline__ fec_request_intrs(struct net_device *dev)
1795 1776
1796 if (request_8xxirq(FEC_INTERRUPT, fec_enet_interrupt, 0, "fec", dev) != 0) 1777 if (request_8xxirq(FEC_INTERRUPT, fec_enet_interrupt, 0, "fec", dev) != 0)
1797 panic("Could not allocate FEC IRQ!"); 1778 panic("Could not allocate FEC IRQ!");
1798
1799#ifdef CONFIG_RPXCLASSIC
1800 /* Make Port C, bit 15 an input that causes interrupts.
1801 */
1802 immap->im_ioport.iop_pcpar &= ~0x0001;
1803 immap->im_ioport.iop_pcdir &= ~0x0001;
1804 immap->im_ioport.iop_pcso &= ~0x0001;
1805 immap->im_ioport.iop_pcint |= 0x0001;
1806 cpm_install_handler(CPMVEC_PIO_PC15, mii_link_interrupt, dev);
1807
1808 /* Make LEDS reflect Link status.
1809 */
1810 *((uint *) RPX_CSR_ADDR) &= ~BCSR2_FETHLEDMODE;
1811#endif
1812#ifdef CONFIG_FADS
1813 if (request_8xxirq(SIU_IRQ2, mii_link_interrupt, 0, "mii", dev) != 0)
1814 panic("Could not allocate MII IRQ!");
1815#endif
1816} 1779}
1817 1780
1818static void __inline__ fec_get_mac(struct net_device *dev) 1781static void __inline__ fec_get_mac(struct net_device *dev)
@@ -1821,16 +1784,6 @@ static void __inline__ fec_get_mac(struct net_device *dev)
1821 1784
1822 bd = (bd_t *)__res; 1785 bd = (bd_t *)__res;
1823 memcpy(dev->dev_addr, bd->bi_enetaddr, ETH_ALEN); 1786 memcpy(dev->dev_addr, bd->bi_enetaddr, ETH_ALEN);
1824
1825#ifdef CONFIG_RPXCLASSIC
1826 /* The Embedded Planet boards have only one MAC address in
1827 * the EEPROM, but can have two Ethernet ports. For the
1828 * FEC port, we create another address by setting one of
1829 * the address bits above something that would have (up to
1830 * now) been allocated.
1831 */
1832 dev->dev_adrd[3] |= 0x80;
1833#endif
1834} 1787}
1835 1788
1836static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep) 1789static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
@@ -2109,13 +2062,8 @@ mii_discover_phy(uint mii_reg, struct net_device *dev)
2109/* This interrupt occurs when the PHY detects a link change. 2062/* This interrupt occurs when the PHY detects a link change.
2110*/ 2063*/
2111#ifdef HAVE_mii_link_interrupt 2064#ifdef HAVE_mii_link_interrupt
2112#ifdef CONFIG_RPXCLASSIC
2113static void
2114mii_link_interrupt(void *dev_id)
2115#else
2116static irqreturn_t 2065static irqreturn_t
2117mii_link_interrupt(int irq, void * dev_id) 2066mii_link_interrupt(int irq, void * dev_id)
2118#endif
2119{ 2067{
2120 struct net_device *dev = dev_id; 2068 struct net_device *dev = dev_id;
2121 struct fec_enet_private *fep = netdev_priv(dev); 2069 struct fec_enet_private *fep = netdev_priv(dev);
diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
index 00527805e4f1..91ec9fdc7184 100644
--- a/drivers/net/ibmveth.c
+++ b/drivers/net/ibmveth.c
@@ -33,6 +33,7 @@
33*/ 33*/
34 34
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/moduleparam.h>
36#include <linux/types.h> 37#include <linux/types.h>
37#include <linux/errno.h> 38#include <linux/errno.h>
38#include <linux/ioport.h> 39#include <linux/ioport.h>
@@ -52,7 +53,9 @@
52#include <asm/hvcall.h> 53#include <asm/hvcall.h>
53#include <asm/atomic.h> 54#include <asm/atomic.h>
54#include <asm/vio.h> 55#include <asm/vio.h>
56#include <asm/iommu.h>
55#include <asm/uaccess.h> 57#include <asm/uaccess.h>
58#include <asm/firmware.h>
56#include <linux/seq_file.h> 59#include <linux/seq_file.h>
57 60
58#include "ibmveth.h" 61#include "ibmveth.h"
@@ -94,8 +97,10 @@ static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter);
94static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter); 97static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter);
95static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance); 98static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance);
96static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter); 99static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter);
100static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev);
97static struct kobj_type ktype_veth_pool; 101static struct kobj_type ktype_veth_pool;
98 102
103
99#ifdef CONFIG_PROC_FS 104#ifdef CONFIG_PROC_FS
100#define IBMVETH_PROC_DIR "ibmveth" 105#define IBMVETH_PROC_DIR "ibmveth"
101static struct proc_dir_entry *ibmveth_proc_dir; 106static struct proc_dir_entry *ibmveth_proc_dir;
@@ -226,16 +231,16 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struc
226 u32 i; 231 u32 i;
227 u32 count = pool->size - atomic_read(&pool->available); 232 u32 count = pool->size - atomic_read(&pool->available);
228 u32 buffers_added = 0; 233 u32 buffers_added = 0;
234 struct sk_buff *skb;
235 unsigned int free_index, index;
236 u64 correlator;
237 unsigned long lpar_rc;
238 dma_addr_t dma_addr;
229 239
230 mb(); 240 mb();
231 241
232 for(i = 0; i < count; ++i) { 242 for(i = 0; i < count; ++i) {
233 struct sk_buff *skb;
234 unsigned int free_index, index;
235 u64 correlator;
236 union ibmveth_buf_desc desc; 243 union ibmveth_buf_desc desc;
237 unsigned long lpar_rc;
238 dma_addr_t dma_addr;
239 244
240 skb = alloc_skb(pool->buff_size, GFP_ATOMIC); 245 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
241 246
@@ -255,6 +260,9 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struc
255 dma_addr = dma_map_single(&adapter->vdev->dev, skb->data, 260 dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
256 pool->buff_size, DMA_FROM_DEVICE); 261 pool->buff_size, DMA_FROM_DEVICE);
257 262
263 if (dma_mapping_error((&adapter->vdev->dev, dma_addr))
264 goto failure;
265
258 pool->free_map[free_index] = IBM_VETH_INVALID_MAP; 266 pool->free_map[free_index] = IBM_VETH_INVALID_MAP;
259 pool->dma_addr[index] = dma_addr; 267 pool->dma_addr[index] = dma_addr;
260 pool->skbuff[index] = skb; 268 pool->skbuff[index] = skb;
@@ -267,20 +275,9 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struc
267 275
268 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc); 276 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
269 277
270 if(lpar_rc != H_SUCCESS) { 278 if (lpar_rc != H_SUCCESS)
271 pool->free_map[free_index] = index; 279 goto failure;
272 pool->skbuff[index] = NULL; 280 else {
273 if (pool->consumer_index == 0)
274 pool->consumer_index = pool->size - 1;
275 else
276 pool->consumer_index--;
277 dma_unmap_single(&adapter->vdev->dev,
278 pool->dma_addr[index], pool->buff_size,
279 DMA_FROM_DEVICE);
280 dev_kfree_skb_any(skb);
281 adapter->replenish_add_buff_failure++;
282 break;
283 } else {
284 buffers_added++; 281 buffers_added++;
285 adapter->replenish_add_buff_success++; 282 adapter->replenish_add_buff_success++;
286 } 283 }
@@ -288,6 +285,24 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struc
288 285
289 mb(); 286 mb();
290 atomic_add(buffers_added, &(pool->available)); 287 atomic_add(buffers_added, &(pool->available));
288 return;
289
290failure:
291 pool->free_map[free_index] = index;
292 pool->skbuff[index] = NULL;
293 if (pool->consumer_index == 0)
294 pool->consumer_index = pool->size - 1;
295 else
296 pool->consumer_index--;
297 if (!dma_mapping_error((&adapter->vdev->dev, dma_addr))
298 dma_unmap_single(&adapter->vdev->dev,
299 pool->dma_addr[index], pool->buff_size,
300 DMA_FROM_DEVICE);
301 dev_kfree_skb_any(skb);
302 adapter->replenish_add_buff_failure++;
303
304 mb();
305 atomic_add(buffers_added, &(pool->available));
291} 306}
292 307
293/* replenish routine */ 308/* replenish routine */
@@ -297,7 +312,7 @@ static void ibmveth_replenish_task(struct ibmveth_adapter *adapter)
297 312
298 adapter->replenish_task_cycles++; 313 adapter->replenish_task_cycles++;
299 314
300 for(i = 0; i < IbmVethNumBufferPools; i++) 315 for (i = (IbmVethNumBufferPools - 1); i >= 0; i--)
301 if(adapter->rx_buff_pool[i].active) 316 if(adapter->rx_buff_pool[i].active)
302 ibmveth_replenish_buffer_pool(adapter, 317 ibmveth_replenish_buffer_pool(adapter,
303 &adapter->rx_buff_pool[i]); 318 &adapter->rx_buff_pool[i]);
@@ -433,11 +448,11 @@ static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter)
433static void ibmveth_cleanup(struct ibmveth_adapter *adapter) 448static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
434{ 449{
435 int i; 450 int i;
451 struct device *dev = &adapter->vdev->dev;
436 452
437 if(adapter->buffer_list_addr != NULL) { 453 if(adapter->buffer_list_addr != NULL) {
438 if(!dma_mapping_error(adapter->buffer_list_dma)) { 454 if (!dma_mapping_error(dev, adapter->buffer_list_dma)) {
439 dma_unmap_single(&adapter->vdev->dev, 455 dma_unmap_single(dev, adapter->buffer_list_dma, 4096,
440 adapter->buffer_list_dma, 4096,
441 DMA_BIDIRECTIONAL); 456 DMA_BIDIRECTIONAL);
442 adapter->buffer_list_dma = DMA_ERROR_CODE; 457 adapter->buffer_list_dma = DMA_ERROR_CODE;
443 } 458 }
@@ -446,9 +461,8 @@ static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
446 } 461 }
447 462
448 if(adapter->filter_list_addr != NULL) { 463 if(adapter->filter_list_addr != NULL) {
449 if(!dma_mapping_error(adapter->filter_list_dma)) { 464 if (!dma_mapping_error(dev, adapter->filter_list_dma)) {
450 dma_unmap_single(&adapter->vdev->dev, 465 dma_unmap_single(dev, adapter->filter_list_dma, 4096,
451 adapter->filter_list_dma, 4096,
452 DMA_BIDIRECTIONAL); 466 DMA_BIDIRECTIONAL);
453 adapter->filter_list_dma = DMA_ERROR_CODE; 467 adapter->filter_list_dma = DMA_ERROR_CODE;
454 } 468 }
@@ -457,8 +471,8 @@ static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
457 } 471 }
458 472
459 if(adapter->rx_queue.queue_addr != NULL) { 473 if(adapter->rx_queue.queue_addr != NULL) {
460 if(!dma_mapping_error(adapter->rx_queue.queue_dma)) { 474 if (!dma_mapping_error(dev, adapter->rx_queue.queue_dma)) {
461 dma_unmap_single(&adapter->vdev->dev, 475 dma_unmap_single(dev,
462 adapter->rx_queue.queue_dma, 476 adapter->rx_queue.queue_dma,
463 adapter->rx_queue.queue_len, 477 adapter->rx_queue.queue_len,
464 DMA_BIDIRECTIONAL); 478 DMA_BIDIRECTIONAL);
@@ -472,6 +486,18 @@ static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
472 if (adapter->rx_buff_pool[i].active) 486 if (adapter->rx_buff_pool[i].active)
473 ibmveth_free_buffer_pool(adapter, 487 ibmveth_free_buffer_pool(adapter,
474 &adapter->rx_buff_pool[i]); 488 &adapter->rx_buff_pool[i]);
489
490 if (adapter->bounce_buffer != NULL) {
491 if (!dma_mapping_error(adapter->bounce_buffer_dma)) {
492 dma_unmap_single(&adapter->vdev->dev,
493 adapter->bounce_buffer_dma,
494 adapter->netdev->mtu + IBMVETH_BUFF_OH,
495 DMA_BIDIRECTIONAL);
496 adapter->bounce_buffer_dma = DMA_ERROR_CODE;
497 }
498 kfree(adapter->bounce_buffer);
499 adapter->bounce_buffer = NULL;
500 }
475} 501}
476 502
477static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter, 503static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
@@ -508,6 +534,7 @@ static int ibmveth_open(struct net_device *netdev)
508 int rc; 534 int rc;
509 union ibmveth_buf_desc rxq_desc; 535 union ibmveth_buf_desc rxq_desc;
510 int i; 536 int i;
537 struct device *dev;
511 538
512 ibmveth_debug_printk("open starting\n"); 539 ibmveth_debug_printk("open starting\n");
513 540
@@ -536,17 +563,19 @@ static int ibmveth_open(struct net_device *netdev)
536 return -ENOMEM; 563 return -ENOMEM;
537 } 564 }
538 565
539 adapter->buffer_list_dma = dma_map_single(&adapter->vdev->dev, 566 dev = &adapter->vdev->dev;
567
568 adapter->buffer_list_dma = dma_map_single(dev,
540 adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL); 569 adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL);
541 adapter->filter_list_dma = dma_map_single(&adapter->vdev->dev, 570 adapter->filter_list_dma = dma_map_single(dev,
542 adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL); 571 adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL);
543 adapter->rx_queue.queue_dma = dma_map_single(&adapter->vdev->dev, 572 adapter->rx_queue.queue_dma = dma_map_single(dev,
544 adapter->rx_queue.queue_addr, 573 adapter->rx_queue.queue_addr,
545 adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL); 574 adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL);
546 575
547 if((dma_mapping_error(adapter->buffer_list_dma) ) || 576 if ((dma_mapping_error(dev, adapter->buffer_list_dma)) ||
548 (dma_mapping_error(adapter->filter_list_dma)) || 577 (dma_mapping_error(dev, adapter->filter_list_dma)) ||
549 (dma_mapping_error(adapter->rx_queue.queue_dma))) { 578 (dma_mapping_error(dev, adapter->rx_queue.queue_dma))) {
550 ibmveth_error_printk("unable to map filter or buffer list pages\n"); 579 ibmveth_error_printk("unable to map filter or buffer list pages\n");
551 ibmveth_cleanup(adapter); 580 ibmveth_cleanup(adapter);
552 napi_disable(&adapter->napi); 581 napi_disable(&adapter->napi);
@@ -607,6 +636,24 @@ static int ibmveth_open(struct net_device *netdev)
607 return rc; 636 return rc;
608 } 637 }
609 638
639 adapter->bounce_buffer =
640 kmalloc(netdev->mtu + IBMVETH_BUFF_OH, GFP_KERNEL);
641 if (!adapter->bounce_buffer) {
642 ibmveth_error_printk("unable to allocate bounce buffer\n");
643 ibmveth_cleanup(adapter);
644 napi_disable(&adapter->napi);
645 return -ENOMEM;
646 }
647 adapter->bounce_buffer_dma =
648 dma_map_single(&adapter->vdev->dev, adapter->bounce_buffer,
649 netdev->mtu + IBMVETH_BUFF_OH, DMA_BIDIRECTIONAL);
650 if (dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
651 ibmveth_error_printk("unable to map bounce buffer\n");
652 ibmveth_cleanup(adapter);
653 napi_disable(&adapter->napi);
654 return -ENOMEM;
655 }
656
610 ibmveth_debug_printk("initial replenish cycle\n"); 657 ibmveth_debug_printk("initial replenish cycle\n");
611 ibmveth_interrupt(netdev->irq, netdev); 658 ibmveth_interrupt(netdev->irq, netdev);
612 659
@@ -853,10 +900,12 @@ static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev)
853 unsigned int tx_packets = 0; 900 unsigned int tx_packets = 0;
854 unsigned int tx_send_failed = 0; 901 unsigned int tx_send_failed = 0;
855 unsigned int tx_map_failed = 0; 902 unsigned int tx_map_failed = 0;
903 int used_bounce = 0;
904 unsigned long data_dma_addr;
856 905
857 desc.fields.flags_len = IBMVETH_BUF_VALID | skb->len; 906 desc.fields.flags_len = IBMVETH_BUF_VALID | skb->len;
858 desc.fields.address = dma_map_single(&adapter->vdev->dev, skb->data, 907 data_dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
859 skb->len, DMA_TO_DEVICE); 908 skb->len, DMA_TO_DEVICE);
860 909
861 if (skb->ip_summed == CHECKSUM_PARTIAL && 910 if (skb->ip_summed == CHECKSUM_PARTIAL &&
862 ip_hdr(skb)->protocol != IPPROTO_TCP && skb_checksum_help(skb)) { 911 ip_hdr(skb)->protocol != IPPROTO_TCP && skb_checksum_help(skb)) {
@@ -875,12 +924,16 @@ static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev)
875 buf[1] = 0; 924 buf[1] = 0;
876 } 925 }
877 926
878 if (dma_mapping_error(desc.fields.address)) { 927 if (dma_mapping_error((&adapter->vdev->dev, data_dma_addr)) {
879 ibmveth_error_printk("tx: unable to map xmit buffer\n"); 928 if (!firmware_has_feature(FW_FEATURE_CMO))
929 ibmveth_error_printk("tx: unable to map xmit buffer\n");
930 skb_copy_from_linear_data(skb, adapter->bounce_buffer,
931 skb->len);
932 desc.fields.address = adapter->bounce_buffer_dma;
880 tx_map_failed++; 933 tx_map_failed++;
881 tx_dropped++; 934 used_bounce = 1;
882 goto out; 935 } else
883 } 936 desc.fields.address = data_dma_addr;
884 937
885 /* send the frame. Arbitrarily set retrycount to 1024 */ 938 /* send the frame. Arbitrarily set retrycount to 1024 */
886 correlator = 0; 939 correlator = 0;
@@ -904,8 +957,9 @@ static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev)
904 netdev->trans_start = jiffies; 957 netdev->trans_start = jiffies;
905 } 958 }
906 959
907 dma_unmap_single(&adapter->vdev->dev, desc.fields.address, 960 if (!used_bounce)
908 skb->len, DMA_TO_DEVICE); 961 dma_unmap_single(&adapter->vdev->dev, data_dma_addr,
962 skb->len, DMA_TO_DEVICE);
909 963
910out: spin_lock_irqsave(&adapter->stats_lock, flags); 964out: spin_lock_irqsave(&adapter->stats_lock, flags);
911 netdev->stats.tx_dropped += tx_dropped; 965 netdev->stats.tx_dropped += tx_dropped;
@@ -1053,9 +1107,9 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
1053static int ibmveth_change_mtu(struct net_device *dev, int new_mtu) 1107static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1054{ 1108{
1055 struct ibmveth_adapter *adapter = dev->priv; 1109 struct ibmveth_adapter *adapter = dev->priv;
1110 struct vio_dev *viodev = adapter->vdev;
1056 int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH; 1111 int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH;
1057 int reinit = 0; 1112 int i;
1058 int i, rc;
1059 1113
1060 if (new_mtu < IBMVETH_MAX_MTU) 1114 if (new_mtu < IBMVETH_MAX_MTU)
1061 return -EINVAL; 1115 return -EINVAL;
@@ -1067,23 +1121,34 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1067 if (i == IbmVethNumBufferPools) 1121 if (i == IbmVethNumBufferPools)
1068 return -EINVAL; 1122 return -EINVAL;
1069 1123
1124 /* Deactivate all the buffer pools so that the next loop can activate
1125 only the buffer pools necessary to hold the new MTU */
1126 for (i = 0; i < IbmVethNumBufferPools; i++)
1127 if (adapter->rx_buff_pool[i].active) {
1128 ibmveth_free_buffer_pool(adapter,
1129 &adapter->rx_buff_pool[i]);
1130 adapter->rx_buff_pool[i].active = 0;
1131 }
1132
1070 /* Look for an active buffer pool that can hold the new MTU */ 1133 /* Look for an active buffer pool that can hold the new MTU */
1071 for(i = 0; i<IbmVethNumBufferPools; i++) { 1134 for(i = 0; i<IbmVethNumBufferPools; i++) {
1072 if (!adapter->rx_buff_pool[i].active) { 1135 adapter->rx_buff_pool[i].active = 1;
1073 adapter->rx_buff_pool[i].active = 1;
1074 reinit = 1;
1075 }
1076 1136
1077 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) { 1137 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
1078 if (reinit && netif_running(adapter->netdev)) { 1138 if (netif_running(adapter->netdev)) {
1079 adapter->pool_config = 1; 1139 adapter->pool_config = 1;
1080 ibmveth_close(adapter->netdev); 1140 ibmveth_close(adapter->netdev);
1081 adapter->pool_config = 0; 1141 adapter->pool_config = 0;
1082 dev->mtu = new_mtu; 1142 dev->mtu = new_mtu;
1083 if ((rc = ibmveth_open(adapter->netdev))) 1143 vio_cmo_set_dev_desired(viodev,
1084 return rc; 1144 ibmveth_get_desired_dma
1085 } else 1145 (viodev));
1086 dev->mtu = new_mtu; 1146 return ibmveth_open(adapter->netdev);
1147 }
1148 dev->mtu = new_mtu;
1149 vio_cmo_set_dev_desired(viodev,
1150 ibmveth_get_desired_dma
1151 (viodev));
1087 return 0; 1152 return 0;
1088 } 1153 }
1089 } 1154 }
@@ -1098,6 +1163,46 @@ static void ibmveth_poll_controller(struct net_device *dev)
1098} 1163}
1099#endif 1164#endif
1100 1165
1166/**
1167 * ibmveth_get_desired_dma - Calculate IO memory desired by the driver
1168 *
1169 * @vdev: struct vio_dev for the device whose desired IO mem is to be returned
1170 *
1171 * Return value:
1172 * Number of bytes of IO data the driver will need to perform well.
1173 */
1174static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev)
1175{
1176 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
1177 struct ibmveth_adapter *adapter;
1178 unsigned long ret;
1179 int i;
1180 int rxqentries = 1;
1181
1182 /* netdev inits at probe time along with the structures we need below*/
1183 if (netdev == NULL)
1184 return IOMMU_PAGE_ALIGN(IBMVETH_IO_ENTITLEMENT_DEFAULT);
1185
1186 adapter = netdev_priv(netdev);
1187
1188 ret = IBMVETH_BUFF_LIST_SIZE + IBMVETH_FILT_LIST_SIZE;
1189 ret += IOMMU_PAGE_ALIGN(netdev->mtu);
1190
1191 for (i = 0; i < IbmVethNumBufferPools; i++) {
1192 /* add the size of the active receive buffers */
1193 if (adapter->rx_buff_pool[i].active)
1194 ret +=
1195 adapter->rx_buff_pool[i].size *
1196 IOMMU_PAGE_ALIGN(adapter->rx_buff_pool[i].
1197 buff_size);
1198 rxqentries += adapter->rx_buff_pool[i].size;
1199 }
1200 /* add the size of the receive queue entries */
1201 ret += IOMMU_PAGE_ALIGN(rxqentries * sizeof(struct ibmveth_rx_q_entry));
1202
1203 return ret;
1204}
1205
1101static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) 1206static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1102{ 1207{
1103 int rc, i; 1208 int rc, i;
@@ -1242,6 +1347,8 @@ static int __devexit ibmveth_remove(struct vio_dev *dev)
1242 ibmveth_proc_unregister_adapter(adapter); 1347 ibmveth_proc_unregister_adapter(adapter);
1243 1348
1244 free_netdev(netdev); 1349 free_netdev(netdev);
1350 dev_set_drvdata(&dev->dev, NULL);
1351
1245 return 0; 1352 return 0;
1246} 1353}
1247 1354
@@ -1402,14 +1509,15 @@ const char * buf, size_t count)
1402 return -EPERM; 1509 return -EPERM;
1403 } 1510 }
1404 1511
1405 pool->active = 0;
1406 if (netif_running(netdev)) { 1512 if (netif_running(netdev)) {
1407 adapter->pool_config = 1; 1513 adapter->pool_config = 1;
1408 ibmveth_close(netdev); 1514 ibmveth_close(netdev);
1515 pool->active = 0;
1409 adapter->pool_config = 0; 1516 adapter->pool_config = 0;
1410 if ((rc = ibmveth_open(netdev))) 1517 if ((rc = ibmveth_open(netdev)))
1411 return rc; 1518 return rc;
1412 } 1519 }
1520 pool->active = 0;
1413 } 1521 }
1414 } else if (attr == &veth_num_attr) { 1522 } else if (attr == &veth_num_attr) {
1415 if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT) 1523 if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT)
@@ -1485,6 +1593,7 @@ static struct vio_driver ibmveth_driver = {
1485 .id_table = ibmveth_device_table, 1593 .id_table = ibmveth_device_table,
1486 .probe = ibmveth_probe, 1594 .probe = ibmveth_probe,
1487 .remove = ibmveth_remove, 1595 .remove = ibmveth_remove,
1596 .get_desired_dma = ibmveth_get_desired_dma,
1488 .driver = { 1597 .driver = {
1489 .name = ibmveth_driver_name, 1598 .name = ibmveth_driver_name,
1490 .owner = THIS_MODULE, 1599 .owner = THIS_MODULE,
diff --git a/drivers/net/ibmveth.h b/drivers/net/ibmveth.h
index 41f61cd18852..d28186948752 100644
--- a/drivers/net/ibmveth.h
+++ b/drivers/net/ibmveth.h
@@ -93,9 +93,12 @@ static inline long h_illan_attributes(unsigned long unit_address,
93 plpar_hcall_norets(H_CHANGE_LOGICAL_LAN_MAC, ua, mac) 93 plpar_hcall_norets(H_CHANGE_LOGICAL_LAN_MAC, ua, mac)
94 94
95#define IbmVethNumBufferPools 5 95#define IbmVethNumBufferPools 5
96#define IBMVETH_IO_ENTITLEMENT_DEFAULT 4243456 /* MTU of 1500 needs 4.2Mb */
96#define IBMVETH_BUFF_OH 22 /* Overhead: 14 ethernet header + 8 opaque handle */ 97#define IBMVETH_BUFF_OH 22 /* Overhead: 14 ethernet header + 8 opaque handle */
97#define IBMVETH_MAX_MTU 68 98#define IBMVETH_MAX_MTU 68
98#define IBMVETH_MAX_POOL_COUNT 4096 99#define IBMVETH_MAX_POOL_COUNT 4096
100#define IBMVETH_BUFF_LIST_SIZE 4096
101#define IBMVETH_FILT_LIST_SIZE 4096
99#define IBMVETH_MAX_BUF_SIZE (1024 * 128) 102#define IBMVETH_MAX_BUF_SIZE (1024 * 128)
100 103
101static int pool_size[] = { 512, 1024 * 2, 1024 * 16, 1024 * 32, 1024 * 64 }; 104static int pool_size[] = { 512, 1024 * 2, 1024 * 16, 1024 * 32, 1024 * 64 };
@@ -143,6 +146,8 @@ struct ibmveth_adapter {
143 struct ibmveth_rx_q rx_queue; 146 struct ibmveth_rx_q rx_queue;
144 int pool_config; 147 int pool_config;
145 int rx_csum; 148 int rx_csum;
149 void *bounce_buffer;
150 dma_addr_t bounce_buffer_dma;
146 151
147 /* adapter specific stats */ 152 /* adapter specific stats */
148 u64 replenish_task_cycles; 153 u64 replenish_task_cycles;
diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index b8d0639c1cdf..c46864d626b2 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -1128,7 +1128,7 @@ static int veth_transmit_to_one(struct sk_buff *skb, HvLpIndex rlp,
1128 msg->data.addr[0] = dma_map_single(port->dev, skb->data, 1128 msg->data.addr[0] = dma_map_single(port->dev, skb->data,
1129 skb->len, DMA_TO_DEVICE); 1129 skb->len, DMA_TO_DEVICE);
1130 1130
1131 if (dma_mapping_error(msg->data.addr[0])) 1131 if (dma_mapping_error(port->dev, msg->data.addr[0]))
1132 goto recycle_and_drop; 1132 goto recycle_and_drop;
1133 1133
1134 msg->dev = port->dev; 1134 msg->dev = port->dev;
@@ -1226,7 +1226,7 @@ static void veth_recycle_msg(struct veth_lpar_connection *cnx,
1226 dma_address = msg->data.addr[0]; 1226 dma_address = msg->data.addr[0];
1227 dma_length = msg->data.len[0]; 1227 dma_length = msg->data.len[0];
1228 1228
1229 if (!dma_mapping_error(dma_address)) 1229 if (!dma_mapping_error(msg->dev, dma_address))
1230 dma_unmap_single(msg->dev, dma_address, dma_length, 1230 dma_unmap_single(msg->dev, dma_address, dma_length,
1231 DMA_TO_DEVICE); 1231 DMA_TO_DEVICE);
1232 1232
diff --git a/drivers/net/mlx4/cmd.c b/drivers/net/mlx4/cmd.c
index 70dff94a8bc6..04d5bc69a6f8 100644
--- a/drivers/net/mlx4/cmd.c
+++ b/drivers/net/mlx4/cmd.c
@@ -67,6 +67,8 @@ enum {
67 CMD_STAT_BAD_INDEX = 0x0a, 67 CMD_STAT_BAD_INDEX = 0x0a,
68 /* FW image corrupted: */ 68 /* FW image corrupted: */
69 CMD_STAT_BAD_NVMEM = 0x0b, 69 CMD_STAT_BAD_NVMEM = 0x0b,
70 /* Error in ICM mapping (e.g. not enough auxiliary ICM pages to execute command): */
71 CMD_STAT_ICM_ERROR = 0x0c,
70 /* Attempt to modify a QP/EE which is not in the presumed state: */ 72 /* Attempt to modify a QP/EE which is not in the presumed state: */
71 CMD_STAT_BAD_QP_STATE = 0x10, 73 CMD_STAT_BAD_QP_STATE = 0x10,
72 /* Bad segment parameters (Address/Size): */ 74 /* Bad segment parameters (Address/Size): */
@@ -119,6 +121,7 @@ static int mlx4_status_to_errno(u8 status)
119 [CMD_STAT_BAD_RES_STATE] = -EBADF, 121 [CMD_STAT_BAD_RES_STATE] = -EBADF,
120 [CMD_STAT_BAD_INDEX] = -EBADF, 122 [CMD_STAT_BAD_INDEX] = -EBADF,
121 [CMD_STAT_BAD_NVMEM] = -EFAULT, 123 [CMD_STAT_BAD_NVMEM] = -EFAULT,
124 [CMD_STAT_ICM_ERROR] = -ENFILE,
122 [CMD_STAT_BAD_QP_STATE] = -EINVAL, 125 [CMD_STAT_BAD_QP_STATE] = -EINVAL,
123 [CMD_STAT_BAD_SEG_PARAM] = -EFAULT, 126 [CMD_STAT_BAD_SEG_PARAM] = -EFAULT,
124 [CMD_STAT_REG_BOUND] = -EBUSY, 127 [CMD_STAT_REG_BOUND] = -EBUSY,
diff --git a/drivers/net/mlx4/eq.c b/drivers/net/mlx4/eq.c
index e141a1513f07..7df928d3a3d8 100644
--- a/drivers/net/mlx4/eq.c
+++ b/drivers/net/mlx4/eq.c
@@ -33,6 +33,7 @@
33 33
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <linux/mm.h>
36#include <linux/dma-mapping.h> 37#include <linux/dma-mapping.h>
37 38
38#include <linux/mlx4/cmd.h> 39#include <linux/mlx4/cmd.h>
@@ -525,7 +526,7 @@ int mlx4_map_eq_icm(struct mlx4_dev *dev, u64 icm_virt)
525 return -ENOMEM; 526 return -ENOMEM;
526 priv->eq_table.icm_dma = pci_map_page(dev->pdev, priv->eq_table.icm_page, 0, 527 priv->eq_table.icm_dma = pci_map_page(dev->pdev, priv->eq_table.icm_page, 0,
527 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 528 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
528 if (pci_dma_mapping_error(priv->eq_table.icm_dma)) { 529 if (pci_dma_mapping_error(dev->pdev, priv->eq_table.icm_dma)) {
529 __free_page(priv->eq_table.icm_page); 530 __free_page(priv->eq_table.icm_page);
530 return -ENOMEM; 531 return -ENOMEM;
531 } 532 }
diff --git a/drivers/net/mlx4/fw.c b/drivers/net/mlx4/fw.c
index 2b5006b9be67..57278224ba1e 100644
--- a/drivers/net/mlx4/fw.c
+++ b/drivers/net/mlx4/fw.c
@@ -46,6 +46,10 @@ enum {
46extern void __buggy_use_of_MLX4_GET(void); 46extern void __buggy_use_of_MLX4_GET(void);
47extern void __buggy_use_of_MLX4_PUT(void); 47extern void __buggy_use_of_MLX4_PUT(void);
48 48
49static int enable_qos;
50module_param(enable_qos, bool, 0444);
51MODULE_PARM_DESC(enable_qos, "Enable Quality of Service support in the HCA (default: off)");
52
49#define MLX4_GET(dest, source, offset) \ 53#define MLX4_GET(dest, source, offset) \
50 do { \ 54 do { \
51 void *__p = (char *) (source) + (offset); \ 55 void *__p = (char *) (source) + (offset); \
@@ -198,7 +202,7 @@ int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
198#define QUERY_DEV_CAP_C_MPT_ENTRY_SZ_OFFSET 0x8e 202#define QUERY_DEV_CAP_C_MPT_ENTRY_SZ_OFFSET 0x8e
199#define QUERY_DEV_CAP_MTT_ENTRY_SZ_OFFSET 0x90 203#define QUERY_DEV_CAP_MTT_ENTRY_SZ_OFFSET 0x90
200#define QUERY_DEV_CAP_D_MPT_ENTRY_SZ_OFFSET 0x92 204#define QUERY_DEV_CAP_D_MPT_ENTRY_SZ_OFFSET 0x92
201#define QUERY_DEV_CAP_BMME_FLAGS_OFFSET 0x97 205#define QUERY_DEV_CAP_BMME_FLAGS_OFFSET 0x94
202#define QUERY_DEV_CAP_RSVD_LKEY_OFFSET 0x98 206#define QUERY_DEV_CAP_RSVD_LKEY_OFFSET 0x98
203#define QUERY_DEV_CAP_MAX_ICM_SZ_OFFSET 0xa0 207#define QUERY_DEV_CAP_MAX_ICM_SZ_OFFSET 0xa0
204 208
@@ -373,12 +377,8 @@ int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
373 } 377 }
374 } 378 }
375 379
376 if (dev_cap->bmme_flags & 1) 380 mlx4_dbg(dev, "Base MM extensions: flags %08x, rsvd L_Key %08x\n",
377 mlx4_dbg(dev, "Base MM extensions: yes " 381 dev_cap->bmme_flags, dev_cap->reserved_lkey);
378 "(flags %d, rsvd L_Key %08x)\n",
379 dev_cap->bmme_flags, dev_cap->reserved_lkey);
380 else
381 mlx4_dbg(dev, "Base MM extensions: no\n");
382 382
383 /* 383 /*
384 * Each UAR has 4 EQ doorbells; so if a UAR is reserved, then 384 * Each UAR has 4 EQ doorbells; so if a UAR is reserved, then
@@ -737,6 +737,10 @@ int mlx4_INIT_HCA(struct mlx4_dev *dev, struct mlx4_init_hca_param *param)
737 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_IPOIB_CSUM) 737 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_IPOIB_CSUM)
738 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 3); 738 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 3);
739 739
740 /* Enable QoS support if module parameter set */
741 if (enable_qos)
742 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 2);
743
740 /* QPC/EEC/CQC/EQC/RDMARC attributes */ 744 /* QPC/EEC/CQC/EQC/RDMARC attributes */
741 745
742 MLX4_PUT(inbox, param->qpc_base, INIT_HCA_QPC_BASE_OFFSET); 746 MLX4_PUT(inbox, param->qpc_base, INIT_HCA_QPC_BASE_OFFSET);
diff --git a/drivers/net/mlx4/fw.h b/drivers/net/mlx4/fw.h
index a0e046c149b7..fbf0e22be122 100644
--- a/drivers/net/mlx4/fw.h
+++ b/drivers/net/mlx4/fw.h
@@ -98,7 +98,7 @@ struct mlx4_dev_cap {
98 int cmpt_entry_sz; 98 int cmpt_entry_sz;
99 int mtt_entry_sz; 99 int mtt_entry_sz;
100 int resize_srq; 100 int resize_srq;
101 u8 bmme_flags; 101 u32 bmme_flags;
102 u32 reserved_lkey; 102 u32 reserved_lkey;
103 u64 max_icm_sz; 103 u64 max_icm_sz;
104 int max_gso_sz; 104 int max_gso_sz;
diff --git a/drivers/net/mlx4/main.c b/drivers/net/mlx4/main.c
index d3736013fe9b..8e1d24cda1b0 100644
--- a/drivers/net/mlx4/main.c
+++ b/drivers/net/mlx4/main.c
@@ -158,6 +158,8 @@ static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
158 dev->caps.max_msg_sz = dev_cap->max_msg_sz; 158 dev->caps.max_msg_sz = dev_cap->max_msg_sz;
159 dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1); 159 dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1);
160 dev->caps.flags = dev_cap->flags; 160 dev->caps.flags = dev_cap->flags;
161 dev->caps.bmme_flags = dev_cap->bmme_flags;
162 dev->caps.reserved_lkey = dev_cap->reserved_lkey;
161 dev->caps.stat_rate_support = dev_cap->stat_rate_support; 163 dev->caps.stat_rate_support = dev_cap->stat_rate_support;
162 dev->caps.max_gso_sz = dev_cap->max_gso_sz; 164 dev->caps.max_gso_sz = dev_cap->max_gso_sz;
163 165
diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h
index a4023c2dd050..78038499cff5 100644
--- a/drivers/net/mlx4/mlx4.h
+++ b/drivers/net/mlx4/mlx4.h
@@ -118,6 +118,7 @@ struct mlx4_bitmap {
118 118
119struct mlx4_buddy { 119struct mlx4_buddy {
120 unsigned long **bits; 120 unsigned long **bits;
121 unsigned int *num_free;
121 int max_order; 122 int max_order;
122 spinlock_t lock; 123 spinlock_t lock;
123}; 124};
diff --git a/drivers/net/mlx4/mr.c b/drivers/net/mlx4/mr.c
index 03a9abcce524..a3c04c5f12c2 100644
--- a/drivers/net/mlx4/mr.c
+++ b/drivers/net/mlx4/mr.c
@@ -47,7 +47,7 @@ struct mlx4_mpt_entry {
47 __be32 flags; 47 __be32 flags;
48 __be32 qpn; 48 __be32 qpn;
49 __be32 key; 49 __be32 key;
50 __be32 pd; 50 __be32 pd_flags;
51 __be64 start; 51 __be64 start;
52 __be64 length; 52 __be64 length;
53 __be32 lkey; 53 __be32 lkey;
@@ -61,11 +61,15 @@ struct mlx4_mpt_entry {
61} __attribute__((packed)); 61} __attribute__((packed));
62 62
63#define MLX4_MPT_FLAG_SW_OWNS (0xfUL << 28) 63#define MLX4_MPT_FLAG_SW_OWNS (0xfUL << 28)
64#define MLX4_MPT_FLAG_FREE (0x3UL << 28)
64#define MLX4_MPT_FLAG_MIO (1 << 17) 65#define MLX4_MPT_FLAG_MIO (1 << 17)
65#define MLX4_MPT_FLAG_BIND_ENABLE (1 << 15) 66#define MLX4_MPT_FLAG_BIND_ENABLE (1 << 15)
66#define MLX4_MPT_FLAG_PHYSICAL (1 << 9) 67#define MLX4_MPT_FLAG_PHYSICAL (1 << 9)
67#define MLX4_MPT_FLAG_REGION (1 << 8) 68#define MLX4_MPT_FLAG_REGION (1 << 8)
68 69
70#define MLX4_MPT_PD_FLAG_FAST_REG (1 << 26)
71#define MLX4_MPT_PD_FLAG_EN_INV (3 << 24)
72
69#define MLX4_MTT_FLAG_PRESENT 1 73#define MLX4_MTT_FLAG_PRESENT 1
70 74
71#define MLX4_MPT_STATUS_SW 0xF0 75#define MLX4_MPT_STATUS_SW 0xF0
@@ -79,23 +83,26 @@ static u32 mlx4_buddy_alloc(struct mlx4_buddy *buddy, int order)
79 83
80 spin_lock(&buddy->lock); 84 spin_lock(&buddy->lock);
81 85
82 for (o = order; o <= buddy->max_order; ++o) { 86 for (o = order; o <= buddy->max_order; ++o)
83 m = 1 << (buddy->max_order - o); 87 if (buddy->num_free[o]) {
84 seg = find_first_bit(buddy->bits[o], m); 88 m = 1 << (buddy->max_order - o);
85 if (seg < m) 89 seg = find_first_bit(buddy->bits[o], m);
86 goto found; 90 if (seg < m)
87 } 91 goto found;
92 }
88 93
89 spin_unlock(&buddy->lock); 94 spin_unlock(&buddy->lock);
90 return -1; 95 return -1;
91 96
92 found: 97 found:
93 clear_bit(seg, buddy->bits[o]); 98 clear_bit(seg, buddy->bits[o]);
99 --buddy->num_free[o];
94 100
95 while (o > order) { 101 while (o > order) {
96 --o; 102 --o;
97 seg <<= 1; 103 seg <<= 1;
98 set_bit(seg ^ 1, buddy->bits[o]); 104 set_bit(seg ^ 1, buddy->bits[o]);
105 ++buddy->num_free[o];
99 } 106 }
100 107
101 spin_unlock(&buddy->lock); 108 spin_unlock(&buddy->lock);
@@ -113,11 +120,13 @@ static void mlx4_buddy_free(struct mlx4_buddy *buddy, u32 seg, int order)
113 120
114 while (test_bit(seg ^ 1, buddy->bits[order])) { 121 while (test_bit(seg ^ 1, buddy->bits[order])) {
115 clear_bit(seg ^ 1, buddy->bits[order]); 122 clear_bit(seg ^ 1, buddy->bits[order]);
123 --buddy->num_free[order];
116 seg >>= 1; 124 seg >>= 1;
117 ++order; 125 ++order;
118 } 126 }
119 127
120 set_bit(seg, buddy->bits[order]); 128 set_bit(seg, buddy->bits[order]);
129 ++buddy->num_free[order];
121 130
122 spin_unlock(&buddy->lock); 131 spin_unlock(&buddy->lock);
123} 132}
@@ -131,7 +140,9 @@ static int mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order)
131 140
132 buddy->bits = kzalloc((buddy->max_order + 1) * sizeof (long *), 141 buddy->bits = kzalloc((buddy->max_order + 1) * sizeof (long *),
133 GFP_KERNEL); 142 GFP_KERNEL);
134 if (!buddy->bits) 143 buddy->num_free = kzalloc((buddy->max_order + 1) * sizeof (int *),
144 GFP_KERNEL);
145 if (!buddy->bits || !buddy->num_free)
135 goto err_out; 146 goto err_out;
136 147
137 for (i = 0; i <= buddy->max_order; ++i) { 148 for (i = 0; i <= buddy->max_order; ++i) {
@@ -143,6 +154,7 @@ static int mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order)
143 } 154 }
144 155
145 set_bit(0, buddy->bits[buddy->max_order]); 156 set_bit(0, buddy->bits[buddy->max_order]);
157 buddy->num_free[buddy->max_order] = 1;
146 158
147 return 0; 159 return 0;
148 160
@@ -150,9 +162,10 @@ err_out_free:
150 for (i = 0; i <= buddy->max_order; ++i) 162 for (i = 0; i <= buddy->max_order; ++i)
151 kfree(buddy->bits[i]); 163 kfree(buddy->bits[i]);
152 164
165err_out:
153 kfree(buddy->bits); 166 kfree(buddy->bits);
167 kfree(buddy->num_free);
154 168
155err_out:
156 return -ENOMEM; 169 return -ENOMEM;
157} 170}
158 171
@@ -164,6 +177,7 @@ static void mlx4_buddy_cleanup(struct mlx4_buddy *buddy)
164 kfree(buddy->bits[i]); 177 kfree(buddy->bits[i]);
165 178
166 kfree(buddy->bits); 179 kfree(buddy->bits);
180 kfree(buddy->num_free);
167} 181}
168 182
169static u32 mlx4_alloc_mtt_range(struct mlx4_dev *dev, int order) 183static u32 mlx4_alloc_mtt_range(struct mlx4_dev *dev, int order)
@@ -314,21 +328,30 @@ int mlx4_mr_enable(struct mlx4_dev *dev, struct mlx4_mr *mr)
314 328
315 memset(mpt_entry, 0, sizeof *mpt_entry); 329 memset(mpt_entry, 0, sizeof *mpt_entry);
316 330
317 mpt_entry->flags = cpu_to_be32(MLX4_MPT_FLAG_SW_OWNS | 331 mpt_entry->flags = cpu_to_be32(MLX4_MPT_FLAG_MIO |
318 MLX4_MPT_FLAG_MIO |
319 MLX4_MPT_FLAG_REGION | 332 MLX4_MPT_FLAG_REGION |
320 mr->access); 333 mr->access);
321 334
322 mpt_entry->key = cpu_to_be32(key_to_hw_index(mr->key)); 335 mpt_entry->key = cpu_to_be32(key_to_hw_index(mr->key));
323 mpt_entry->pd = cpu_to_be32(mr->pd); 336 mpt_entry->pd_flags = cpu_to_be32(mr->pd | MLX4_MPT_PD_FLAG_EN_INV);
324 mpt_entry->start = cpu_to_be64(mr->iova); 337 mpt_entry->start = cpu_to_be64(mr->iova);
325 mpt_entry->length = cpu_to_be64(mr->size); 338 mpt_entry->length = cpu_to_be64(mr->size);
326 mpt_entry->entity_size = cpu_to_be32(mr->mtt.page_shift); 339 mpt_entry->entity_size = cpu_to_be32(mr->mtt.page_shift);
340
327 if (mr->mtt.order < 0) { 341 if (mr->mtt.order < 0) {
328 mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_PHYSICAL); 342 mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_PHYSICAL);
329 mpt_entry->mtt_seg = 0; 343 mpt_entry->mtt_seg = 0;
330 } else 344 } else {
331 mpt_entry->mtt_seg = cpu_to_be64(mlx4_mtt_addr(dev, &mr->mtt)); 345 mpt_entry->mtt_seg = cpu_to_be64(mlx4_mtt_addr(dev, &mr->mtt));
346 }
347
348 if (mr->mtt.order >= 0 && mr->mtt.page_shift == 0) {
349 /* fast register MR in free state */
350 mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_FREE);
351 mpt_entry->pd_flags |= cpu_to_be32(MLX4_MPT_PD_FLAG_FAST_REG);
352 } else {
353 mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_SW_OWNS);
354 }
332 355
333 err = mlx4_SW2HW_MPT(dev, mailbox, 356 err = mlx4_SW2HW_MPT(dev, mailbox,
334 key_to_hw_index(mr->key) & (dev->caps.num_mpts - 1)); 357 key_to_hw_index(mr->key) & (dev->caps.num_mpts - 1));
diff --git a/drivers/net/mlx4/pd.c b/drivers/net/mlx4/pd.c
index 3a93c5f0f7ab..aa616892d09c 100644
--- a/drivers/net/mlx4/pd.c
+++ b/drivers/net/mlx4/pd.c
@@ -91,6 +91,13 @@ EXPORT_SYMBOL_GPL(mlx4_uar_free);
91 91
92int mlx4_init_uar_table(struct mlx4_dev *dev) 92int mlx4_init_uar_table(struct mlx4_dev *dev)
93{ 93{
94 if (dev->caps.num_uars <= 128) {
95 mlx4_err(dev, "Only %d UAR pages (need more than 128)\n",
96 dev->caps.num_uars);
97 mlx4_err(dev, "Increase firmware log2_uar_bar_megabytes?\n");
98 return -ENODEV;
99 }
100
94 return mlx4_bitmap_init(&mlx4_priv(dev)->uar_table.bitmap, 101 return mlx4_bitmap_init(&mlx4_priv(dev)->uar_table.bitmap,
95 dev->caps.num_uars, dev->caps.num_uars - 1, 102 dev->caps.num_uars, dev->caps.num_uars - 1,
96 max(128, dev->caps.reserved_uars)); 103 max(128, dev->caps.reserved_uars));
diff --git a/drivers/net/pasemi_mac.c b/drivers/net/pasemi_mac.c
index 993d87c9296f..edc0fd588985 100644
--- a/drivers/net/pasemi_mac.c
+++ b/drivers/net/pasemi_mac.c
@@ -650,7 +650,7 @@ static void pasemi_mac_replenish_rx_ring(const struct net_device *dev,
650 mac->bufsz - LOCAL_SKB_ALIGN, 650 mac->bufsz - LOCAL_SKB_ALIGN,
651 PCI_DMA_FROMDEVICE); 651 PCI_DMA_FROMDEVICE);
652 652
653 if (unlikely(dma_mapping_error(dma))) { 653 if (unlikely(pci_dma_mapping_error(mac->dma_pdev, dma))) {
654 dev_kfree_skb_irq(info->skb); 654 dev_kfree_skb_irq(info->skb);
655 break; 655 break;
656 } 656 }
@@ -1519,7 +1519,7 @@ static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
1519 map[0] = pci_map_single(mac->dma_pdev, skb->data, skb_headlen(skb), 1519 map[0] = pci_map_single(mac->dma_pdev, skb->data, skb_headlen(skb),
1520 PCI_DMA_TODEVICE); 1520 PCI_DMA_TODEVICE);
1521 map_size[0] = skb_headlen(skb); 1521 map_size[0] = skb_headlen(skb);
1522 if (dma_mapping_error(map[0])) 1522 if (pci_dma_mapping_error(mac->dma_pdev, map[0]))
1523 goto out_err_nolock; 1523 goto out_err_nolock;
1524 1524
1525 for (i = 0; i < nfrags; i++) { 1525 for (i = 0; i < nfrags; i++) {
@@ -1529,7 +1529,7 @@ static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
1529 frag->page_offset, frag->size, 1529 frag->page_offset, frag->size,
1530 PCI_DMA_TODEVICE); 1530 PCI_DMA_TODEVICE);
1531 map_size[i+1] = frag->size; 1531 map_size[i+1] = frag->size;
1532 if (dma_mapping_error(map[i+1])) { 1532 if (pci_dma_mapping_error(mac->dma_pdev, map[i+1])) {
1533 nfrags = i; 1533 nfrags = i;
1534 goto out_err_nolock; 1534 goto out_err_nolock;
1535 } 1535 }
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 739b3ab7bccc..ddccc074a76a 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -581,12 +581,12 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
581 if (file == ppp->owner) 581 if (file == ppp->owner)
582 ppp_shutdown_interface(ppp); 582 ppp_shutdown_interface(ppp);
583 } 583 }
584 if (atomic_read(&file->f_count) <= 2) { 584 if (atomic_long_read(&file->f_count) <= 2) {
585 ppp_release(NULL, file); 585 ppp_release(NULL, file);
586 err = 0; 586 err = 0;
587 } else 587 } else
588 printk(KERN_DEBUG "PPPIOCDETACH file->f_count=%d\n", 588 printk(KERN_DEBUG "PPPIOCDETACH file->f_count=%ld\n",
589 atomic_read(&file->f_count)); 589 atomic_long_read(&file->f_count));
590 unlock_kernel(); 590 unlock_kernel();
591 return err; 591 return err;
592 } 592 }
diff --git a/drivers/net/qla3xxx.c b/drivers/net/qla3xxx.c
index e7d48a352beb..e82b37bbd6c3 100644
--- a/drivers/net/qla3xxx.c
+++ b/drivers/net/qla3xxx.c
@@ -328,7 +328,7 @@ static void ql_release_to_lrg_buf_free_list(struct ql3_adapter *qdev,
328 qdev->lrg_buffer_len - 328 qdev->lrg_buffer_len -
329 QL_HEADER_SPACE, 329 QL_HEADER_SPACE,
330 PCI_DMA_FROMDEVICE); 330 PCI_DMA_FROMDEVICE);
331 err = pci_dma_mapping_error(map); 331 err = pci_dma_mapping_error(qdev->pdev, map);
332 if(err) { 332 if(err) {
333 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n", 333 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n",
334 qdev->ndev->name, err); 334 qdev->ndev->name, err);
@@ -1919,7 +1919,7 @@ static int ql_populate_free_queue(struct ql3_adapter *qdev)
1919 QL_HEADER_SPACE, 1919 QL_HEADER_SPACE,
1920 PCI_DMA_FROMDEVICE); 1920 PCI_DMA_FROMDEVICE);
1921 1921
1922 err = pci_dma_mapping_error(map); 1922 err = pci_dma_mapping_error(qdev->pdev, map);
1923 if(err) { 1923 if(err) {
1924 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n", 1924 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n",
1925 qdev->ndev->name, err); 1925 qdev->ndev->name, err);
@@ -2454,7 +2454,7 @@ static int ql_send_map(struct ql3_adapter *qdev,
2454 */ 2454 */
2455 map = pci_map_single(qdev->pdev, skb->data, len, PCI_DMA_TODEVICE); 2455 map = pci_map_single(qdev->pdev, skb->data, len, PCI_DMA_TODEVICE);
2456 2456
2457 err = pci_dma_mapping_error(map); 2457 err = pci_dma_mapping_error(qdev->pdev, map);
2458 if(err) { 2458 if(err) {
2459 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n", 2459 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n",
2460 qdev->ndev->name, err); 2460 qdev->ndev->name, err);
@@ -2487,7 +2487,7 @@ static int ql_send_map(struct ql3_adapter *qdev,
2487 sizeof(struct oal), 2487 sizeof(struct oal),
2488 PCI_DMA_TODEVICE); 2488 PCI_DMA_TODEVICE);
2489 2489
2490 err = pci_dma_mapping_error(map); 2490 err = pci_dma_mapping_error(qdev->pdev, map);
2491 if(err) { 2491 if(err) {
2492 2492
2493 printk(KERN_ERR "%s: PCI mapping outbound address list with error: %d\n", 2493 printk(KERN_ERR "%s: PCI mapping outbound address list with error: %d\n",
@@ -2514,7 +2514,7 @@ static int ql_send_map(struct ql3_adapter *qdev,
2514 frag->page_offset, frag->size, 2514 frag->page_offset, frag->size,
2515 PCI_DMA_TODEVICE); 2515 PCI_DMA_TODEVICE);
2516 2516
2517 err = pci_dma_mapping_error(map); 2517 err = pci_dma_mapping_error(qdev->pdev, map);
2518 if(err) { 2518 if(err) {
2519 printk(KERN_ERR "%s: PCI mapping frags failed with error: %d\n", 2519 printk(KERN_ERR "%s: PCI mapping frags failed with error: %d\n",
2520 qdev->ndev->name, err); 2520 qdev->ndev->name, err);
@@ -2916,7 +2916,7 @@ static int ql_alloc_large_buffers(struct ql3_adapter *qdev)
2916 QL_HEADER_SPACE, 2916 QL_HEADER_SPACE,
2917 PCI_DMA_FROMDEVICE); 2917 PCI_DMA_FROMDEVICE);
2918 2918
2919 err = pci_dma_mapping_error(map); 2919 err = pci_dma_mapping_error(qdev->pdev, map);
2920 if(err) { 2920 if(err) {
2921 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n", 2921 printk(KERN_ERR "%s: PCI mapping failed with error: %d\n",
2922 qdev->ndev->name, err); 2922 qdev->ndev->name, err);
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 9dae40ccf048..86d77d05190a 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -2512,8 +2512,8 @@ static void stop_nic(struct s2io_nic *nic)
2512 * Return Value: 2512 * Return Value:
2513 * SUCCESS on success or an appropriate -ve value on failure. 2513 * SUCCESS on success or an appropriate -ve value on failure.
2514 */ 2514 */
2515 2515static int fill_rx_buffers(struct s2io_nic *nic, struct ring_info *ring,
2516static int fill_rx_buffers(struct ring_info *ring, int from_card_up) 2516 int from_card_up)
2517{ 2517{
2518 struct sk_buff *skb; 2518 struct sk_buff *skb;
2519 struct RxD_t *rxdp; 2519 struct RxD_t *rxdp;
@@ -2602,7 +2602,8 @@ static int fill_rx_buffers(struct ring_info *ring, int from_card_up)
2602 rxdp1->Buffer0_ptr = pci_map_single 2602 rxdp1->Buffer0_ptr = pci_map_single
2603 (ring->pdev, skb->data, size - NET_IP_ALIGN, 2603 (ring->pdev, skb->data, size - NET_IP_ALIGN,
2604 PCI_DMA_FROMDEVICE); 2604 PCI_DMA_FROMDEVICE);
2605 if(pci_dma_mapping_error(rxdp1->Buffer0_ptr)) 2605 if (pci_dma_mapping_error(nic->pdev,
2606 rxdp1->Buffer0_ptr))
2606 goto pci_map_failed; 2607 goto pci_map_failed;
2607 2608
2608 rxdp->Control_2 = 2609 rxdp->Control_2 =
@@ -2636,7 +2637,8 @@ static int fill_rx_buffers(struct ring_info *ring, int from_card_up)
2636 rxdp3->Buffer0_ptr = 2637 rxdp3->Buffer0_ptr =
2637 pci_map_single(ring->pdev, ba->ba_0, 2638 pci_map_single(ring->pdev, ba->ba_0,
2638 BUF0_LEN, PCI_DMA_FROMDEVICE); 2639 BUF0_LEN, PCI_DMA_FROMDEVICE);
2639 if (pci_dma_mapping_error(rxdp3->Buffer0_ptr)) 2640 if (pci_dma_mapping_error(nic->pdev,
2641 rxdp3->Buffer0_ptr))
2640 goto pci_map_failed; 2642 goto pci_map_failed;
2641 } else 2643 } else
2642 pci_dma_sync_single_for_device(ring->pdev, 2644 pci_dma_sync_single_for_device(ring->pdev,
@@ -2655,7 +2657,8 @@ static int fill_rx_buffers(struct ring_info *ring, int from_card_up)
2655 (ring->pdev, skb->data, ring->mtu + 4, 2657 (ring->pdev, skb->data, ring->mtu + 4,
2656 PCI_DMA_FROMDEVICE); 2658 PCI_DMA_FROMDEVICE);
2657 2659
2658 if (pci_dma_mapping_error(rxdp3->Buffer2_ptr)) 2660 if (pci_dma_mapping_error(nic->pdev,
2661 rxdp3->Buffer2_ptr))
2659 goto pci_map_failed; 2662 goto pci_map_failed;
2660 2663
2661 if (from_card_up) { 2664 if (from_card_up) {
@@ -2664,8 +2667,8 @@ static int fill_rx_buffers(struct ring_info *ring, int from_card_up)
2664 ba->ba_1, BUF1_LEN, 2667 ba->ba_1, BUF1_LEN,
2665 PCI_DMA_FROMDEVICE); 2668 PCI_DMA_FROMDEVICE);
2666 2669
2667 if (pci_dma_mapping_error 2670 if (pci_dma_mapping_error(nic->pdev,
2668 (rxdp3->Buffer1_ptr)) { 2671 rxdp3->Buffer1_ptr)) {
2669 pci_unmap_single 2672 pci_unmap_single
2670 (ring->pdev, 2673 (ring->pdev,
2671 (dma_addr_t)(unsigned long) 2674 (dma_addr_t)(unsigned long)
@@ -2806,9 +2809,9 @@ static void free_rx_buffers(struct s2io_nic *sp)
2806 } 2809 }
2807} 2810}
2808 2811
2809static int s2io_chk_rx_buffers(struct ring_info *ring) 2812static int s2io_chk_rx_buffers(struct s2io_nic *nic, struct ring_info *ring)
2810{ 2813{
2811 if (fill_rx_buffers(ring, 0) == -ENOMEM) { 2814 if (fill_rx_buffers(nic, ring, 0) == -ENOMEM) {
2812 DBG_PRINT(INFO_DBG, "%s:Out of memory", ring->dev->name); 2815 DBG_PRINT(INFO_DBG, "%s:Out of memory", ring->dev->name);
2813 DBG_PRINT(INFO_DBG, " in Rx Intr!!\n"); 2816 DBG_PRINT(INFO_DBG, " in Rx Intr!!\n");
2814 } 2817 }
@@ -2848,7 +2851,7 @@ static int s2io_poll_msix(struct napi_struct *napi, int budget)
2848 return 0; 2851 return 0;
2849 2852
2850 pkts_processed = rx_intr_handler(ring, budget); 2853 pkts_processed = rx_intr_handler(ring, budget);
2851 s2io_chk_rx_buffers(ring); 2854 s2io_chk_rx_buffers(nic, ring);
2852 2855
2853 if (pkts_processed < budget_org) { 2856 if (pkts_processed < budget_org) {
2854 netif_rx_complete(dev, napi); 2857 netif_rx_complete(dev, napi);
@@ -2882,7 +2885,7 @@ static int s2io_poll_inta(struct napi_struct *napi, int budget)
2882 for (i = 0; i < config->rx_ring_num; i++) { 2885 for (i = 0; i < config->rx_ring_num; i++) {
2883 ring = &mac_control->rings[i]; 2886 ring = &mac_control->rings[i];
2884 ring_pkts_processed = rx_intr_handler(ring, budget); 2887 ring_pkts_processed = rx_intr_handler(ring, budget);
2885 s2io_chk_rx_buffers(ring); 2888 s2io_chk_rx_buffers(nic, ring);
2886 pkts_processed += ring_pkts_processed; 2889 pkts_processed += ring_pkts_processed;
2887 budget -= ring_pkts_processed; 2890 budget -= ring_pkts_processed;
2888 if (budget <= 0) 2891 if (budget <= 0)
@@ -2939,7 +2942,8 @@ static void s2io_netpoll(struct net_device *dev)
2939 rx_intr_handler(&mac_control->rings[i], 0); 2942 rx_intr_handler(&mac_control->rings[i], 0);
2940 2943
2941 for (i = 0; i < config->rx_ring_num; i++) { 2944 for (i = 0; i < config->rx_ring_num; i++) {
2942 if (fill_rx_buffers(&mac_control->rings[i], 0) == -ENOMEM) { 2945 if (fill_rx_buffers(nic, &mac_control->rings[i], 0) ==
2946 -ENOMEM) {
2943 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name); 2947 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name);
2944 DBG_PRINT(INFO_DBG, " in Rx Netpoll!!\n"); 2948 DBG_PRINT(INFO_DBG, " in Rx Netpoll!!\n");
2945 break; 2949 break;
@@ -4235,14 +4239,14 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
4235 txdp->Buffer_Pointer = pci_map_single(sp->pdev, 4239 txdp->Buffer_Pointer = pci_map_single(sp->pdev,
4236 fifo->ufo_in_band_v, 4240 fifo->ufo_in_band_v,
4237 sizeof(u64), PCI_DMA_TODEVICE); 4241 sizeof(u64), PCI_DMA_TODEVICE);
4238 if (pci_dma_mapping_error(txdp->Buffer_Pointer)) 4242 if (pci_dma_mapping_error(sp->pdev, txdp->Buffer_Pointer))
4239 goto pci_map_failed; 4243 goto pci_map_failed;
4240 txdp++; 4244 txdp++;
4241 } 4245 }
4242 4246
4243 txdp->Buffer_Pointer = pci_map_single 4247 txdp->Buffer_Pointer = pci_map_single
4244 (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE); 4248 (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
4245 if (pci_dma_mapping_error(txdp->Buffer_Pointer)) 4249 if (pci_dma_mapping_error(sp->pdev, txdp->Buffer_Pointer))
4246 goto pci_map_failed; 4250 goto pci_map_failed;
4247 4251
4248 txdp->Host_Control = (unsigned long) skb; 4252 txdp->Host_Control = (unsigned long) skb;
@@ -4345,7 +4349,7 @@ static irqreturn_t s2io_msix_ring_handle(int irq, void *dev_id)
4345 netif_rx_schedule(dev, &ring->napi); 4349 netif_rx_schedule(dev, &ring->napi);
4346 } else { 4350 } else {
4347 rx_intr_handler(ring, 0); 4351 rx_intr_handler(ring, 0);
4348 s2io_chk_rx_buffers(ring); 4352 s2io_chk_rx_buffers(sp, ring);
4349 } 4353 }
4350 4354
4351 return IRQ_HANDLED; 4355 return IRQ_HANDLED;
@@ -4826,7 +4830,7 @@ static irqreturn_t s2io_isr(int irq, void *dev_id)
4826 */ 4830 */
4827 if (!config->napi) { 4831 if (!config->napi) {
4828 for (i = 0; i < config->rx_ring_num; i++) 4832 for (i = 0; i < config->rx_ring_num; i++)
4829 s2io_chk_rx_buffers(&mac_control->rings[i]); 4833 s2io_chk_rx_buffers(sp, &mac_control->rings[i]);
4830 } 4834 }
4831 writeq(sp->general_int_mask, &bar0->general_int_mask); 4835 writeq(sp->general_int_mask, &bar0->general_int_mask);
4832 readl(&bar0->general_int_status); 4836 readl(&bar0->general_int_status);
@@ -6859,7 +6863,7 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
6859 pci_map_single( sp->pdev, (*skb)->data, 6863 pci_map_single( sp->pdev, (*skb)->data,
6860 size - NET_IP_ALIGN, 6864 size - NET_IP_ALIGN,
6861 PCI_DMA_FROMDEVICE); 6865 PCI_DMA_FROMDEVICE);
6862 if (pci_dma_mapping_error(rxdp1->Buffer0_ptr)) 6866 if (pci_dma_mapping_error(sp->pdev, rxdp1->Buffer0_ptr))
6863 goto memalloc_failed; 6867 goto memalloc_failed;
6864 rxdp->Host_Control = (unsigned long) (*skb); 6868 rxdp->Host_Control = (unsigned long) (*skb);
6865 } 6869 }
@@ -6886,12 +6890,13 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
6886 pci_map_single(sp->pdev, (*skb)->data, 6890 pci_map_single(sp->pdev, (*skb)->data,
6887 dev->mtu + 4, 6891 dev->mtu + 4,
6888 PCI_DMA_FROMDEVICE); 6892 PCI_DMA_FROMDEVICE);
6889 if (pci_dma_mapping_error(rxdp3->Buffer2_ptr)) 6893 if (pci_dma_mapping_error(sp->pdev, rxdp3->Buffer2_ptr))
6890 goto memalloc_failed; 6894 goto memalloc_failed;
6891 rxdp3->Buffer0_ptr = *temp0 = 6895 rxdp3->Buffer0_ptr = *temp0 =
6892 pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN, 6896 pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN,
6893 PCI_DMA_FROMDEVICE); 6897 PCI_DMA_FROMDEVICE);
6894 if (pci_dma_mapping_error(rxdp3->Buffer0_ptr)) { 6898 if (pci_dma_mapping_error(sp->pdev,
6899 rxdp3->Buffer0_ptr)) {
6895 pci_unmap_single (sp->pdev, 6900 pci_unmap_single (sp->pdev,
6896 (dma_addr_t)rxdp3->Buffer2_ptr, 6901 (dma_addr_t)rxdp3->Buffer2_ptr,
6897 dev->mtu + 4, PCI_DMA_FROMDEVICE); 6902 dev->mtu + 4, PCI_DMA_FROMDEVICE);
@@ -6903,7 +6908,8 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
6903 rxdp3->Buffer1_ptr = *temp1 = 6908 rxdp3->Buffer1_ptr = *temp1 =
6904 pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN, 6909 pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN,
6905 PCI_DMA_FROMDEVICE); 6910 PCI_DMA_FROMDEVICE);
6906 if (pci_dma_mapping_error(rxdp3->Buffer1_ptr)) { 6911 if (pci_dma_mapping_error(sp->pdev,
6912 rxdp3->Buffer1_ptr)) {
6907 pci_unmap_single (sp->pdev, 6913 pci_unmap_single (sp->pdev,
6908 (dma_addr_t)rxdp3->Buffer0_ptr, 6914 (dma_addr_t)rxdp3->Buffer0_ptr,
6909 BUF0_LEN, PCI_DMA_FROMDEVICE); 6915 BUF0_LEN, PCI_DMA_FROMDEVICE);
@@ -7187,7 +7193,7 @@ static int s2io_card_up(struct s2io_nic * sp)
7187 7193
7188 for (i = 0; i < config->rx_ring_num; i++) { 7194 for (i = 0; i < config->rx_ring_num; i++) {
7189 mac_control->rings[i].mtu = dev->mtu; 7195 mac_control->rings[i].mtu = dev->mtu;
7190 ret = fill_rx_buffers(&mac_control->rings[i], 1); 7196 ret = fill_rx_buffers(sp, &mac_control->rings[i], 1);
7191 if (ret) { 7197 if (ret) {
7192 DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n", 7198 DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n",
7193 dev->name); 7199 dev->name);
diff --git a/drivers/net/sfc/rx.c b/drivers/net/sfc/rx.c
index 601b001437c0..0d27dd39bc09 100644
--- a/drivers/net/sfc/rx.c
+++ b/drivers/net/sfc/rx.c
@@ -233,7 +233,7 @@ static inline int efx_init_rx_buffer_skb(struct efx_rx_queue *rx_queue,
233 rx_buf->data, rx_buf->len, 233 rx_buf->data, rx_buf->len,
234 PCI_DMA_FROMDEVICE); 234 PCI_DMA_FROMDEVICE);
235 235
236 if (unlikely(pci_dma_mapping_error(rx_buf->dma_addr))) { 236 if (unlikely(pci_dma_mapping_error(efx->pci_dev, rx_buf->dma_addr))) {
237 dev_kfree_skb_any(rx_buf->skb); 237 dev_kfree_skb_any(rx_buf->skb);
238 rx_buf->skb = NULL; 238 rx_buf->skb = NULL;
239 return -EIO; 239 return -EIO;
@@ -275,7 +275,7 @@ static inline int efx_init_rx_buffer_page(struct efx_rx_queue *rx_queue,
275 0, efx_rx_buf_size(efx), 275 0, efx_rx_buf_size(efx),
276 PCI_DMA_FROMDEVICE); 276 PCI_DMA_FROMDEVICE);
277 277
278 if (unlikely(pci_dma_mapping_error(dma_addr))) { 278 if (unlikely(pci_dma_mapping_error(efx->pci_dev, dma_addr))) {
279 __free_pages(rx_buf->page, efx->rx_buffer_order); 279 __free_pages(rx_buf->page, efx->rx_buffer_order);
280 rx_buf->page = NULL; 280 rx_buf->page = NULL;
281 return -EIO; 281 return -EIO;
diff --git a/drivers/net/sfc/tx.c b/drivers/net/sfc/tx.c
index 5cdd082ab8f6..5e8374ab28ee 100644
--- a/drivers/net/sfc/tx.c
+++ b/drivers/net/sfc/tx.c
@@ -172,7 +172,7 @@ static inline int efx_enqueue_skb(struct efx_tx_queue *tx_queue,
172 172
173 /* Process all fragments */ 173 /* Process all fragments */
174 while (1) { 174 while (1) {
175 if (unlikely(pci_dma_mapping_error(dma_addr))) 175 if (unlikely(pci_dma_mapping_error(pci_dev, dma_addr)))
176 goto pci_err; 176 goto pci_err;
177 177
178 /* Store fields for marking in the per-fragment final 178 /* Store fields for marking in the per-fragment final
@@ -661,7 +661,8 @@ efx_tsoh_heap_alloc(struct efx_tx_queue *tx_queue, size_t header_len)
661 tsoh->dma_addr = pci_map_single(tx_queue->efx->pci_dev, 661 tsoh->dma_addr = pci_map_single(tx_queue->efx->pci_dev,
662 TSOH_BUFFER(tsoh), header_len, 662 TSOH_BUFFER(tsoh), header_len,
663 PCI_DMA_TODEVICE); 663 PCI_DMA_TODEVICE);
664 if (unlikely(pci_dma_mapping_error(tsoh->dma_addr))) { 664 if (unlikely(pci_dma_mapping_error(tx_queue->efx->pci_dev,
665 tsoh->dma_addr))) {
665 kfree(tsoh); 666 kfree(tsoh);
666 return NULL; 667 return NULL;
667 } 668 }
@@ -863,7 +864,7 @@ static inline int tso_get_fragment(struct tso_state *st, struct efx_nic *efx,
863 864
864 st->ifc.unmap_addr = pci_map_page(efx->pci_dev, page, page_off, 865 st->ifc.unmap_addr = pci_map_page(efx->pci_dev, page, page_off,
865 len, PCI_DMA_TODEVICE); 866 len, PCI_DMA_TODEVICE);
866 if (likely(!pci_dma_mapping_error(st->ifc.unmap_addr))) { 867 if (likely(!pci_dma_mapping_error(efx->pci_dev, st->ifc.unmap_addr))) {
867 st->ifc.unmap_len = len; 868 st->ifc.unmap_len = len;
868 st->ifc.len = len; 869 st->ifc.len = len;
869 st->ifc.dma_addr = st->ifc.unmap_addr; 870 st->ifc.dma_addr = st->ifc.unmap_addr;
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index 711e4a8948e0..5257cf464f1a 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -1829,9 +1829,6 @@ static int sky2_down(struct net_device *dev)
1829 if (netif_msg_ifdown(sky2)) 1829 if (netif_msg_ifdown(sky2))
1830 printk(KERN_INFO PFX "%s: disabling interface\n", dev->name); 1830 printk(KERN_INFO PFX "%s: disabling interface\n", dev->name);
1831 1831
1832 /* Stop more packets from being queued */
1833 netif_stop_queue(dev);
1834
1835 /* Disable port IRQ */ 1832 /* Disable port IRQ */
1836 imask = sky2_read32(hw, B0_IMSK); 1833 imask = sky2_read32(hw, B0_IMSK);
1837 imask &= ~portirq_msk[port]; 1834 imask &= ~portirq_msk[port];
@@ -1887,8 +1884,6 @@ static int sky2_down(struct net_device *dev)
1887 1884
1888 sky2_phy_power_down(hw, port); 1885 sky2_phy_power_down(hw, port);
1889 1886
1890 netif_carrier_off(dev);
1891
1892 /* turn off LED's */ 1887 /* turn off LED's */
1893 sky2_write16(hw, B0_Y2LED, LED_STAT_OFF); 1888 sky2_write16(hw, B0_Y2LED, LED_STAT_OFF);
1894 1889
diff --git a/drivers/net/smc91x.c b/drivers/net/smc91x.c
index f2051b209da2..2040965d7724 100644
--- a/drivers/net/smc91x.c
+++ b/drivers/net/smc91x.c
@@ -308,7 +308,7 @@ static void smc_reset(struct net_device *dev)
308 * can't handle it then there will be no recovery except for 308 * can't handle it then there will be no recovery except for
309 * a hard reset or power cycle 309 * a hard reset or power cycle
310 */ 310 */
311 if (nowait) 311 if (lp->cfg.flags & SMC91X_NOWAIT)
312 cfg |= CONFIG_NO_WAIT; 312 cfg |= CONFIG_NO_WAIT;
313 313
314 /* 314 /*
@@ -1939,8 +1939,11 @@ static int __init smc_probe(struct net_device *dev, void __iomem *ioaddr,
1939 if (retval) 1939 if (retval)
1940 goto err_out; 1940 goto err_out;
1941 1941
1942#ifdef SMC_USE_PXA_DMA 1942#ifdef CONFIG_ARCH_PXA
1943 { 1943# ifdef SMC_USE_PXA_DMA
1944 lp->cfg.flags |= SMC91X_USE_DMA;
1945# endif
1946 if (lp->cfg.flags & SMC91X_USE_DMA) {
1944 int dma = pxa_request_dma(dev->name, DMA_PRIO_LOW, 1947 int dma = pxa_request_dma(dev->name, DMA_PRIO_LOW,
1945 smc_pxa_dma_irq, NULL); 1948 smc_pxa_dma_irq, NULL);
1946 if (dma >= 0) 1949 if (dma >= 0)
@@ -1980,7 +1983,7 @@ static int __init smc_probe(struct net_device *dev, void __iomem *ioaddr,
1980 } 1983 }
1981 1984
1982err_out: 1985err_out:
1983#ifdef SMC_USE_PXA_DMA 1986#ifdef CONFIG_ARCH_PXA
1984 if (retval && dev->dma != (unsigned char)-1) 1987 if (retval && dev->dma != (unsigned char)-1)
1985 pxa_free_dma(dev->dma); 1988 pxa_free_dma(dev->dma);
1986#endif 1989#endif
@@ -2050,9 +2053,11 @@ static int smc_enable_device(struct platform_device *pdev)
2050 return 0; 2053 return 0;
2051} 2054}
2052 2055
2053static int smc_request_attrib(struct platform_device *pdev) 2056static int smc_request_attrib(struct platform_device *pdev,
2057 struct net_device *ndev)
2054{ 2058{
2055 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib"); 2059 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib");
2060 struct smc_local *lp = netdev_priv(ndev);
2056 2061
2057 if (!res) 2062 if (!res)
2058 return 0; 2063 return 0;
@@ -2063,9 +2068,11 @@ static int smc_request_attrib(struct platform_device *pdev)
2063 return 0; 2068 return 0;
2064} 2069}
2065 2070
2066static void smc_release_attrib(struct platform_device *pdev) 2071static void smc_release_attrib(struct platform_device *pdev,
2072 struct net_device *ndev)
2067{ 2073{
2068 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib"); 2074 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib");
2075 struct smc_local *lp = netdev_priv(ndev);
2069 2076
2070 if (res) 2077 if (res)
2071 release_mem_region(res->start, ATTRIB_SIZE); 2078 release_mem_region(res->start, ATTRIB_SIZE);
@@ -2123,27 +2130,14 @@ static int smc_drv_probe(struct platform_device *pdev)
2123 struct net_device *ndev; 2130 struct net_device *ndev;
2124 struct resource *res, *ires; 2131 struct resource *res, *ires;
2125 unsigned int __iomem *addr; 2132 unsigned int __iomem *addr;
2133 unsigned long irq_flags = SMC_IRQ_FLAGS;
2126 int ret; 2134 int ret;
2127 2135
2128 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs");
2129 if (!res)
2130 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2131 if (!res) {
2132 ret = -ENODEV;
2133 goto out;
2134 }
2135
2136
2137 if (!request_mem_region(res->start, SMC_IO_EXTENT, CARDNAME)) {
2138 ret = -EBUSY;
2139 goto out;
2140 }
2141
2142 ndev = alloc_etherdev(sizeof(struct smc_local)); 2136 ndev = alloc_etherdev(sizeof(struct smc_local));
2143 if (!ndev) { 2137 if (!ndev) {
2144 printk("%s: could not allocate device.\n", CARDNAME); 2138 printk("%s: could not allocate device.\n", CARDNAME);
2145 ret = -ENOMEM; 2139 ret = -ENOMEM;
2146 goto out_release_io; 2140 goto out;
2147 } 2141 }
2148 SET_NETDEV_DEV(ndev, &pdev->dev); 2142 SET_NETDEV_DEV(ndev, &pdev->dev);
2149 2143
@@ -2152,37 +2146,47 @@ static int smc_drv_probe(struct platform_device *pdev)
2152 */ 2146 */
2153 2147
2154 lp = netdev_priv(ndev); 2148 lp = netdev_priv(ndev);
2155 lp->cfg.irq_flags = SMC_IRQ_FLAGS;
2156 2149
2157#ifdef SMC_DYNAMIC_BUS_CONFIG 2150 if (pd) {
2158 if (pd)
2159 memcpy(&lp->cfg, pd, sizeof(lp->cfg)); 2151 memcpy(&lp->cfg, pd, sizeof(lp->cfg));
2160 else { 2152 lp->io_shift = SMC91X_IO_SHIFT(lp->cfg.flags);
2161 lp->cfg.flags = SMC91X_USE_8BIT; 2153 } else {
2162 lp->cfg.flags |= SMC91X_USE_16BIT; 2154 lp->cfg.flags |= (SMC_CAN_USE_8BIT) ? SMC91X_USE_8BIT : 0;
2163 lp->cfg.flags |= SMC91X_USE_32BIT; 2155 lp->cfg.flags |= (SMC_CAN_USE_16BIT) ? SMC91X_USE_16BIT : 0;
2156 lp->cfg.flags |= (SMC_CAN_USE_32BIT) ? SMC91X_USE_32BIT : 0;
2157 lp->cfg.flags |= (nowait) ? SMC91X_NOWAIT : 0;
2164 } 2158 }
2165 2159
2166 lp->cfg.flags &= ~(SMC_CAN_USE_8BIT ? 0 : SMC91X_USE_8BIT);
2167 lp->cfg.flags &= ~(SMC_CAN_USE_16BIT ? 0 : SMC91X_USE_16BIT);
2168 lp->cfg.flags &= ~(SMC_CAN_USE_32BIT ? 0 : SMC91X_USE_32BIT);
2169#endif
2170
2171 ndev->dma = (unsigned char)-1; 2160 ndev->dma = (unsigned char)-1;
2172 2161
2162 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs");
2163 if (!res)
2164 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2165 if (!res) {
2166 ret = -ENODEV;
2167 goto out_free_netdev;
2168 }
2169
2170
2171 if (!request_mem_region(res->start, SMC_IO_EXTENT, CARDNAME)) {
2172 ret = -EBUSY;
2173 goto out_free_netdev;
2174 }
2175
2173 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 2176 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
2174 if (!ires) { 2177 if (!ires) {
2175 ret = -ENODEV; 2178 ret = -ENODEV;
2176 goto out_free_netdev; 2179 goto out_release_io;
2177 } 2180 }
2178 2181
2179 ndev->irq = ires->start; 2182 ndev->irq = ires->start;
2180 if (SMC_IRQ_FLAGS == -1)
2181 lp->cfg.irq_flags = ires->flags & IRQF_TRIGGER_MASK;
2182 2183
2183 ret = smc_request_attrib(pdev); 2184 if (ires->flags & IRQF_TRIGGER_MASK)
2185 irq_flags = ires->flags & IRQF_TRIGGER_MASK;
2186
2187 ret = smc_request_attrib(pdev, ndev);
2184 if (ret) 2188 if (ret)
2185 goto out_free_netdev; 2189 goto out_release_io;
2186#if defined(CONFIG_SA1100_ASSABET) 2190#if defined(CONFIG_SA1100_ASSABET)
2187 NCR_0 |= NCR_ENET_OSC_EN; 2191 NCR_0 |= NCR_ENET_OSC_EN;
2188#endif 2192#endif
@@ -2197,7 +2201,7 @@ static int smc_drv_probe(struct platform_device *pdev)
2197 goto out_release_attrib; 2201 goto out_release_attrib;
2198 } 2202 }
2199 2203
2200#ifdef SMC_USE_PXA_DMA 2204#ifdef CONFIG_ARCH_PXA
2201 { 2205 {
2202 struct smc_local *lp = netdev_priv(ndev); 2206 struct smc_local *lp = netdev_priv(ndev);
2203 lp->device = &pdev->dev; 2207 lp->device = &pdev->dev;
@@ -2205,7 +2209,7 @@ static int smc_drv_probe(struct platform_device *pdev)
2205 } 2209 }
2206#endif 2210#endif
2207 2211
2208 ret = smc_probe(ndev, addr, lp->cfg.irq_flags); 2212 ret = smc_probe(ndev, addr, irq_flags);
2209 if (ret != 0) 2213 if (ret != 0)
2210 goto out_iounmap; 2214 goto out_iounmap;
2211 2215
@@ -2217,11 +2221,11 @@ static int smc_drv_probe(struct platform_device *pdev)
2217 platform_set_drvdata(pdev, NULL); 2221 platform_set_drvdata(pdev, NULL);
2218 iounmap(addr); 2222 iounmap(addr);
2219 out_release_attrib: 2223 out_release_attrib:
2220 smc_release_attrib(pdev); 2224 smc_release_attrib(pdev, ndev);
2221 out_free_netdev:
2222 free_netdev(ndev);
2223 out_release_io: 2225 out_release_io:
2224 release_mem_region(res->start, SMC_IO_EXTENT); 2226 release_mem_region(res->start, SMC_IO_EXTENT);
2227 out_free_netdev:
2228 free_netdev(ndev);
2225 out: 2229 out:
2226 printk("%s: not found (%d).\n", CARDNAME, ret); 2230 printk("%s: not found (%d).\n", CARDNAME, ret);
2227 2231
@@ -2240,14 +2244,14 @@ static int smc_drv_remove(struct platform_device *pdev)
2240 2244
2241 free_irq(ndev->irq, ndev); 2245 free_irq(ndev->irq, ndev);
2242 2246
2243#ifdef SMC_USE_PXA_DMA 2247#ifdef CONFIG_ARCH_PXA
2244 if (ndev->dma != (unsigned char)-1) 2248 if (ndev->dma != (unsigned char)-1)
2245 pxa_free_dma(ndev->dma); 2249 pxa_free_dma(ndev->dma);
2246#endif 2250#endif
2247 iounmap(lp->base); 2251 iounmap(lp->base);
2248 2252
2249 smc_release_datacs(pdev,ndev); 2253 smc_release_datacs(pdev,ndev);
2250 smc_release_attrib(pdev); 2254 smc_release_attrib(pdev,ndev);
2251 2255
2252 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs"); 2256 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs");
2253 if (!res) 2257 if (!res)
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index 8606818653f8..22209b6f1405 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -40,23 +40,46 @@
40 * Define your architecture specific bus configuration parameters here. 40 * Define your architecture specific bus configuration parameters here.
41 */ 41 */
42 42
43#if defined(CONFIG_ARCH_LUBBOCK) 43#if defined(CONFIG_ARCH_LUBBOCK) ||\
44 defined(CONFIG_MACH_MAINSTONE) ||\
45 defined(CONFIG_MACH_ZYLONITE) ||\
46 defined(CONFIG_MACH_LITTLETON)
44 47
45/* We can only do 16-bit reads and writes in the static memory space. */ 48#include <asm/mach-types.h>
46#define SMC_CAN_USE_8BIT 0 49
50/* Now the bus width is specified in the platform data
51 * pretend here to support all I/O access types
52 */
53#define SMC_CAN_USE_8BIT 1
47#define SMC_CAN_USE_16BIT 1 54#define SMC_CAN_USE_16BIT 1
48#define SMC_CAN_USE_32BIT 0 55#define SMC_CAN_USE_32BIT 1
49#define SMC_NOWAIT 1 56#define SMC_NOWAIT 1
50 57
51/* The first two address lines aren't connected... */ 58#define SMC_IO_SHIFT (lp->io_shift)
52#define SMC_IO_SHIFT 2
53 59
60#define SMC_inb(a, r) readb((a) + (r))
54#define SMC_inw(a, r) readw((a) + (r)) 61#define SMC_inw(a, r) readw((a) + (r))
55#define SMC_outw(v, a, r) writew(v, (a) + (r)) 62#define SMC_inl(a, r) readl((a) + (r))
63#define SMC_outb(v, a, r) writeb(v, (a) + (r))
64#define SMC_outl(v, a, r) writel(v, (a) + (r))
56#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l) 65#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
57#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l) 66#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
67#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
68#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
58#define SMC_IRQ_FLAGS (-1) /* from resource */ 69#define SMC_IRQ_FLAGS (-1) /* from resource */
59 70
71/* We actually can't write halfwords properly if not word aligned */
72static inline void SMC_outw(u16 val, void __iomem *ioaddr, int reg)
73{
74 if (machine_is_mainstone() && reg & 2) {
75 unsigned int v = val << 16;
76 v |= readl(ioaddr + (reg & ~2)) & 0xffff;
77 writel(v, ioaddr + (reg & ~2));
78 } else {
79 writew(val, ioaddr + reg);
80 }
81}
82
60#elif defined(CONFIG_BLACKFIN) 83#elif defined(CONFIG_BLACKFIN)
61 84
62#define SMC_IRQ_FLAGS IRQF_TRIGGER_HIGH 85#define SMC_IRQ_FLAGS IRQF_TRIGGER_HIGH
@@ -195,7 +218,6 @@
195#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l) 218#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
196 219
197#elif defined(CONFIG_ARCH_INNOKOM) || \ 220#elif defined(CONFIG_ARCH_INNOKOM) || \
198 defined(CONFIG_MACH_MAINSTONE) || \
199 defined(CONFIG_ARCH_PXA_IDP) || \ 221 defined(CONFIG_ARCH_PXA_IDP) || \
200 defined(CONFIG_ARCH_RAMSES) || \ 222 defined(CONFIG_ARCH_RAMSES) || \
201 defined(CONFIG_ARCH_PCM027) 223 defined(CONFIG_ARCH_PCM027)
@@ -229,22 +251,6 @@ SMC_outw(u16 val, void __iomem *ioaddr, int reg)
229 } 251 }
230} 252}
231 253
232#elif defined(CONFIG_MACH_ZYLONITE)
233
234#define SMC_CAN_USE_8BIT 1
235#define SMC_CAN_USE_16BIT 1
236#define SMC_CAN_USE_32BIT 0
237#define SMC_IO_SHIFT 0
238#define SMC_NOWAIT 1
239#define SMC_USE_PXA_DMA 1
240#define SMC_inb(a, r) readb((a) + (r))
241#define SMC_inw(a, r) readw((a) + (r))
242#define SMC_insw(a, r, p, l) insw((a) + (r), p, l)
243#define SMC_outsw(a, r, p, l) outsw((a) + (r), p, l)
244#define SMC_outb(v, a, r) writeb(v, (a) + (r))
245#define SMC_outw(v, a, r) writew(v, (a) + (r))
246#define SMC_IRQ_FLAGS (-1) /* from resource */
247
248#elif defined(CONFIG_ARCH_OMAP) 254#elif defined(CONFIG_ARCH_OMAP)
249 255
250/* We can only do 16-bit reads and writes in the static memory space. */ 256/* We can only do 16-bit reads and writes in the static memory space. */
@@ -454,7 +460,6 @@ static inline void LPD7_SMC_outsw (unsigned char* a, int r,
454#define RPC_LSA_DEFAULT RPC_LED_100_10 460#define RPC_LSA_DEFAULT RPC_LED_100_10
455#define RPC_LSB_DEFAULT RPC_LED_TX_RX 461#define RPC_LSB_DEFAULT RPC_LED_TX_RX
456 462
457#define SMC_DYNAMIC_BUS_CONFIG
458#endif 463#endif
459 464
460 465
@@ -493,7 +498,7 @@ struct smc_local {
493 498
494 spinlock_t lock; 499 spinlock_t lock;
495 500
496#ifdef SMC_USE_PXA_DMA 501#ifdef CONFIG_ARCH_PXA
497 /* DMA needs the physical address of the chip */ 502 /* DMA needs the physical address of the chip */
498 u_long physaddr; 503 u_long physaddr;
499 struct device *device; 504 struct device *device;
@@ -501,20 +506,17 @@ struct smc_local {
501 void __iomem *base; 506 void __iomem *base;
502 void __iomem *datacs; 507 void __iomem *datacs;
503 508
509 /* the low address lines on some platforms aren't connected... */
510 int io_shift;
511
504 struct smc91x_platdata cfg; 512 struct smc91x_platdata cfg;
505}; 513};
506 514
507#ifdef SMC_DYNAMIC_BUS_CONFIG 515#define SMC_8BIT(p) ((p)->cfg.flags & SMC91X_USE_8BIT)
508#define SMC_8BIT(p) (((p)->cfg.flags & SMC91X_USE_8BIT) && SMC_CAN_USE_8BIT) 516#define SMC_16BIT(p) ((p)->cfg.flags & SMC91X_USE_16BIT)
509#define SMC_16BIT(p) (((p)->cfg.flags & SMC91X_USE_16BIT) && SMC_CAN_USE_16BIT) 517#define SMC_32BIT(p) ((p)->cfg.flags & SMC91X_USE_32BIT)
510#define SMC_32BIT(p) (((p)->cfg.flags & SMC91X_USE_32BIT) && SMC_CAN_USE_32BIT)
511#else
512#define SMC_8BIT(p) SMC_CAN_USE_8BIT
513#define SMC_16BIT(p) SMC_CAN_USE_16BIT
514#define SMC_32BIT(p) SMC_CAN_USE_32BIT
515#endif
516 518
517#ifdef SMC_USE_PXA_DMA 519#ifdef CONFIG_ARCH_PXA
518/* 520/*
519 * Let's use the DMA engine on the XScale PXA2xx for RX packets. This is 521 * Let's use the DMA engine on the XScale PXA2xx for RX packets. This is
520 * always happening in irq context so no need to worry about races. TX is 522 * always happening in irq context so no need to worry about races. TX is
@@ -608,7 +610,7 @@ smc_pxa_dma_irq(int dma, void *dummy)
608{ 610{
609 DCSR(dma) = 0; 611 DCSR(dma) = 0;
610} 612}
611#endif /* SMC_USE_PXA_DMA */ 613#endif /* CONFIG_ARCH_PXA */
612 614
613 615
614/* 616/*
diff --git a/drivers/net/spider_net.c b/drivers/net/spider_net.c
index 00aa0b108cb9..b6435d0d71f9 100644
--- a/drivers/net/spider_net.c
+++ b/drivers/net/spider_net.c
@@ -452,7 +452,7 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
452 /* iommu-map the skb */ 452 /* iommu-map the skb */
453 buf = pci_map_single(card->pdev, descr->skb->data, 453 buf = pci_map_single(card->pdev, descr->skb->data,
454 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE); 454 SPIDER_NET_MAX_FRAME, PCI_DMA_FROMDEVICE);
455 if (pci_dma_mapping_error(buf)) { 455 if (pci_dma_mapping_error(card->pdev, buf)) {
456 dev_kfree_skb_any(descr->skb); 456 dev_kfree_skb_any(descr->skb);
457 descr->skb = NULL; 457 descr->skb = NULL;
458 if (netif_msg_rx_err(card) && net_ratelimit()) 458 if (netif_msg_rx_err(card) && net_ratelimit())
@@ -691,7 +691,7 @@ spider_net_prepare_tx_descr(struct spider_net_card *card,
691 unsigned long flags; 691 unsigned long flags;
692 692
693 buf = pci_map_single(card->pdev, skb->data, skb->len, PCI_DMA_TODEVICE); 693 buf = pci_map_single(card->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
694 if (pci_dma_mapping_error(buf)) { 694 if (pci_dma_mapping_error(card->pdev, buf)) {
695 if (netif_msg_tx_err(card) && net_ratelimit()) 695 if (netif_msg_tx_err(card) && net_ratelimit())
696 dev_err(&card->netdev->dev, "could not iommu-map packet (%p, %i). " 696 dev_err(&card->netdev->dev, "could not iommu-map packet (%p, %i). "
697 "Dropping packet\n", skb->data, skb->len); 697 "Dropping packet\n", skb->data, skb->len);
diff --git a/drivers/net/tc35815.c b/drivers/net/tc35815.c
index a645e5028c14..8487ace9d2e3 100644
--- a/drivers/net/tc35815.c
+++ b/drivers/net/tc35815.c
@@ -506,7 +506,7 @@ static void *alloc_rxbuf_page(struct pci_dev *hwdev, dma_addr_t *dma_handle)
506 return NULL; 506 return NULL;
507 *dma_handle = pci_map_single(hwdev, buf, PAGE_SIZE, 507 *dma_handle = pci_map_single(hwdev, buf, PAGE_SIZE,
508 PCI_DMA_FROMDEVICE); 508 PCI_DMA_FROMDEVICE);
509 if (pci_dma_mapping_error(*dma_handle)) { 509 if (pci_dma_mapping_error(hwdev, *dma_handle)) {
510 free_page((unsigned long)buf); 510 free_page((unsigned long)buf);
511 return NULL; 511 return NULL;
512 } 512 }
@@ -536,7 +536,7 @@ static struct sk_buff *alloc_rxbuf_skb(struct net_device *dev,
536 return NULL; 536 return NULL;
537 *dma_handle = pci_map_single(hwdev, skb->data, RX_BUF_SIZE, 537 *dma_handle = pci_map_single(hwdev, skb->data, RX_BUF_SIZE,
538 PCI_DMA_FROMDEVICE); 538 PCI_DMA_FROMDEVICE);
539 if (pci_dma_mapping_error(*dma_handle)) { 539 if (pci_dma_mapping_error(hwdev, *dma_handle)) {
540 dev_kfree_skb_any(skb); 540 dev_kfree_skb_any(skb);
541 return NULL; 541 return NULL;
542 } 542 }
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index c28d7cb2035b..0196a0df9021 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -19,6 +19,7 @@
19//#define DEBUG 19//#define DEBUG
20#include <linux/netdevice.h> 20#include <linux/netdevice.h>
21#include <linux/etherdevice.h> 21#include <linux/etherdevice.h>
22#include <linux/ethtool.h>
22#include <linux/module.h> 23#include <linux/module.h>
23#include <linux/virtio.h> 24#include <linux/virtio.h>
24#include <linux/virtio_net.h> 25#include <linux/virtio_net.h>
@@ -54,9 +55,15 @@ struct virtnet_info
54 struct tasklet_struct tasklet; 55 struct tasklet_struct tasklet;
55 bool free_in_tasklet; 56 bool free_in_tasklet;
56 57
58 /* I like... big packets and I cannot lie! */
59 bool big_packets;
60
57 /* Receive & send queues. */ 61 /* Receive & send queues. */
58 struct sk_buff_head recv; 62 struct sk_buff_head recv;
59 struct sk_buff_head send; 63 struct sk_buff_head send;
64
65 /* Chain pages by the private ptr. */
66 struct page *pages;
60}; 67};
61 68
62static inline struct virtio_net_hdr *skb_vnet_hdr(struct sk_buff *skb) 69static inline struct virtio_net_hdr *skb_vnet_hdr(struct sk_buff *skb)
@@ -69,6 +76,23 @@ static inline void vnet_hdr_to_sg(struct scatterlist *sg, struct sk_buff *skb)
69 sg_init_one(sg, skb_vnet_hdr(skb), sizeof(struct virtio_net_hdr)); 76 sg_init_one(sg, skb_vnet_hdr(skb), sizeof(struct virtio_net_hdr));
70} 77}
71 78
79static void give_a_page(struct virtnet_info *vi, struct page *page)
80{
81 page->private = (unsigned long)vi->pages;
82 vi->pages = page;
83}
84
85static struct page *get_a_page(struct virtnet_info *vi, gfp_t gfp_mask)
86{
87 struct page *p = vi->pages;
88
89 if (p)
90 vi->pages = (struct page *)p->private;
91 else
92 p = alloc_page(gfp_mask);
93 return p;
94}
95
72static void skb_xmit_done(struct virtqueue *svq) 96static void skb_xmit_done(struct virtqueue *svq)
73{ 97{
74 struct virtnet_info *vi = svq->vdev->priv; 98 struct virtnet_info *vi = svq->vdev->priv;
@@ -88,6 +112,7 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
88 unsigned len) 112 unsigned len)
89{ 113{
90 struct virtio_net_hdr *hdr = skb_vnet_hdr(skb); 114 struct virtio_net_hdr *hdr = skb_vnet_hdr(skb);
115 int err;
91 116
92 if (unlikely(len < sizeof(struct virtio_net_hdr) + ETH_HLEN)) { 117 if (unlikely(len < sizeof(struct virtio_net_hdr) + ETH_HLEN)) {
93 pr_debug("%s: short packet %i\n", dev->name, len); 118 pr_debug("%s: short packet %i\n", dev->name, len);
@@ -95,10 +120,23 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,
95 goto drop; 120 goto drop;
96 } 121 }
97 len -= sizeof(struct virtio_net_hdr); 122 len -= sizeof(struct virtio_net_hdr);
98 BUG_ON(len > MAX_PACKET_LEN);
99 123
100 skb_trim(skb, len); 124 if (len <= MAX_PACKET_LEN) {
125 unsigned int i;
101 126
127 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
128 give_a_page(dev->priv, skb_shinfo(skb)->frags[i].page);
129 skb->data_len = 0;
130 skb_shinfo(skb)->nr_frags = 0;
131 }
132
133 err = pskb_trim(skb, len);
134 if (err) {
135 pr_debug("%s: pskb_trim failed %i %d\n", dev->name, len, err);
136 dev->stats.rx_dropped++;
137 goto drop;
138 }
139 skb->truesize += skb->data_len;
102 dev->stats.rx_bytes += skb->len; 140 dev->stats.rx_bytes += skb->len;
103 dev->stats.rx_packets++; 141 dev->stats.rx_packets++;
104 142
@@ -160,7 +198,7 @@ static void try_fill_recv(struct virtnet_info *vi)
160{ 198{
161 struct sk_buff *skb; 199 struct sk_buff *skb;
162 struct scatterlist sg[2+MAX_SKB_FRAGS]; 200 struct scatterlist sg[2+MAX_SKB_FRAGS];
163 int num, err; 201 int num, err, i;
164 202
165 sg_init_table(sg, 2+MAX_SKB_FRAGS); 203 sg_init_table(sg, 2+MAX_SKB_FRAGS);
166 for (;;) { 204 for (;;) {
@@ -170,6 +208,24 @@ static void try_fill_recv(struct virtnet_info *vi)
170 208
171 skb_put(skb, MAX_PACKET_LEN); 209 skb_put(skb, MAX_PACKET_LEN);
172 vnet_hdr_to_sg(sg, skb); 210 vnet_hdr_to_sg(sg, skb);
211
212 if (vi->big_packets) {
213 for (i = 0; i < MAX_SKB_FRAGS; i++) {
214 skb_frag_t *f = &skb_shinfo(skb)->frags[i];
215 f->page = get_a_page(vi, GFP_ATOMIC);
216 if (!f->page)
217 break;
218
219 f->page_offset = 0;
220 f->size = PAGE_SIZE;
221
222 skb->data_len += PAGE_SIZE;
223 skb->len += PAGE_SIZE;
224
225 skb_shinfo(skb)->nr_frags++;
226 }
227 }
228
173 num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1; 229 num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1;
174 skb_queue_head(&vi->recv, skb); 230 skb_queue_head(&vi->recv, skb);
175 231
@@ -335,16 +391,11 @@ again:
335 free_old_xmit_skbs(vi); 391 free_old_xmit_skbs(vi);
336 392
337 /* If we has a buffer left over from last time, send it now. */ 393 /* If we has a buffer left over from last time, send it now. */
338 if (unlikely(vi->last_xmit_skb)) { 394 if (unlikely(vi->last_xmit_skb) &&
339 if (xmit_skb(vi, vi->last_xmit_skb) != 0) { 395 xmit_skb(vi, vi->last_xmit_skb) != 0)
340 /* Drop this skb: we only queue one. */ 396 goto stop_queue;
341 vi->dev->stats.tx_dropped++; 397
342 kfree_skb(skb); 398 vi->last_xmit_skb = NULL;
343 skb = NULL;
344 goto stop_queue;
345 }
346 vi->last_xmit_skb = NULL;
347 }
348 399
349 /* Put new one in send queue and do transmit */ 400 /* Put new one in send queue and do transmit */
350 if (likely(skb)) { 401 if (likely(skb)) {
@@ -370,6 +421,11 @@ stop_queue:
370 netif_start_queue(dev); 421 netif_start_queue(dev);
371 goto again; 422 goto again;
372 } 423 }
424 if (skb) {
425 /* Drop this skb: we only queue one. */
426 vi->dev->stats.tx_dropped++;
427 kfree_skb(skb);
428 }
373 goto done; 429 goto done;
374} 430}
375 431
@@ -408,6 +464,22 @@ static int virtnet_close(struct net_device *dev)
408 return 0; 464 return 0;
409} 465}
410 466
467static int virtnet_set_tx_csum(struct net_device *dev, u32 data)
468{
469 struct virtnet_info *vi = netdev_priv(dev);
470 struct virtio_device *vdev = vi->vdev;
471
472 if (data && !virtio_has_feature(vdev, VIRTIO_NET_F_CSUM))
473 return -ENOSYS;
474
475 return ethtool_op_set_tx_hw_csum(dev, data);
476}
477
478static struct ethtool_ops virtnet_ethtool_ops = {
479 .set_tx_csum = virtnet_set_tx_csum,
480 .set_sg = ethtool_op_set_sg,
481};
482
411static int virtnet_probe(struct virtio_device *vdev) 483static int virtnet_probe(struct virtio_device *vdev)
412{ 484{
413 int err; 485 int err;
@@ -427,6 +499,7 @@ static int virtnet_probe(struct virtio_device *vdev)
427#ifdef CONFIG_NET_POLL_CONTROLLER 499#ifdef CONFIG_NET_POLL_CONTROLLER
428 dev->poll_controller = virtnet_netpoll; 500 dev->poll_controller = virtnet_netpoll;
429#endif 501#endif
502 SET_ETHTOOL_OPS(dev, &virtnet_ethtool_ops);
430 SET_NETDEV_DEV(dev, &vdev->dev); 503 SET_NETDEV_DEV(dev, &vdev->dev);
431 504
432 /* Do we support "hardware" checksums? */ 505 /* Do we support "hardware" checksums? */
@@ -462,11 +535,18 @@ static int virtnet_probe(struct virtio_device *vdev)
462 vi->dev = dev; 535 vi->dev = dev;
463 vi->vdev = vdev; 536 vi->vdev = vdev;
464 vdev->priv = vi; 537 vdev->priv = vi;
538 vi->pages = NULL;
465 539
466 /* If they give us a callback when all buffers are done, we don't need 540 /* If they give us a callback when all buffers are done, we don't need
467 * the timer. */ 541 * the timer. */
468 vi->free_in_tasklet = virtio_has_feature(vdev,VIRTIO_F_NOTIFY_ON_EMPTY); 542 vi->free_in_tasklet = virtio_has_feature(vdev,VIRTIO_F_NOTIFY_ON_EMPTY);
469 543
544 /* If we can receive ANY GSO packets, we must allocate large ones. */
545 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4)
546 || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6)
547 || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN))
548 vi->big_packets = true;
549
470 /* We expect two virtqueues, receive then send. */ 550 /* We expect two virtqueues, receive then send. */
471 vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done); 551 vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done);
472 if (IS_ERR(vi->rvq)) { 552 if (IS_ERR(vi->rvq)) {
@@ -541,6 +621,10 @@ static void virtnet_remove(struct virtio_device *vdev)
541 vdev->config->del_vq(vi->svq); 621 vdev->config->del_vq(vi->svq);
542 vdev->config->del_vq(vi->rvq); 622 vdev->config->del_vq(vi->rvq);
543 unregister_netdev(vi->dev); 623 unregister_netdev(vi->dev);
624
625 while (vi->pages)
626 __free_pages(get_a_page(vi, GFP_KERNEL), 0);
627
544 free_netdev(vi->dev); 628 free_netdev(vi->dev);
545} 629}
546 630
@@ -553,7 +637,9 @@ static unsigned int features[] = {
553 VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM, 637 VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM,
554 VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC, 638 VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC,
555 VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6, 639 VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6,
556 VIRTIO_NET_F_HOST_ECN, VIRTIO_F_NOTIFY_ON_EMPTY, 640 VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
641 VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */
642 VIRTIO_F_NOTIFY_ON_EMPTY,
557}; 643};
558 644
559static struct virtio_driver virtio_net = { 645static struct virtio_driver virtio_net = {
diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath5k/base.c
index 217d506527a9..d9769c527346 100644
--- a/drivers/net/wireless/ath5k/base.c
+++ b/drivers/net/wireless/ath5k/base.c
@@ -1166,7 +1166,7 @@ ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
1166 bf->skb = skb; 1166 bf->skb = skb;
1167 bf->skbaddr = pci_map_single(sc->pdev, 1167 bf->skbaddr = pci_map_single(sc->pdev,
1168 skb->data, sc->rxbufsize, PCI_DMA_FROMDEVICE); 1168 skb->data, sc->rxbufsize, PCI_DMA_FROMDEVICE);
1169 if (unlikely(pci_dma_mapping_error(bf->skbaddr))) { 1169 if (unlikely(pci_dma_mapping_error(sc->pdev, bf->skbaddr))) {
1170 ATH5K_ERR(sc, "%s: DMA mapping failed\n", __func__); 1170 ATH5K_ERR(sc, "%s: DMA mapping failed\n", __func__);
1171 dev_kfree_skb(skb); 1171 dev_kfree_skb(skb);
1172 bf->skb = NULL; 1172 bf->skb = NULL;
@@ -1918,7 +1918,7 @@ ath5k_beacon_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
1918 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, "skb %p [data %p len %u] " 1918 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, "skb %p [data %p len %u] "
1919 "skbaddr %llx\n", skb, skb->data, skb->len, 1919 "skbaddr %llx\n", skb, skb->data, skb->len,
1920 (unsigned long long)bf->skbaddr); 1920 (unsigned long long)bf->skbaddr);
1921 if (pci_dma_mapping_error(bf->skbaddr)) { 1921 if (pci_dma_mapping_error(sc->pdev, bf->skbaddr)) {
1922 ATH5K_ERR(sc, "beacon DMA mapping failed\n"); 1922 ATH5K_ERR(sc, "beacon DMA mapping failed\n");
1923 return -EIO; 1923 return -EIO;
1924 } 1924 }
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 3a7a11a75fb4..1d7ec3129349 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -4,7 +4,7 @@ config OF_DEVICE
4 4
5config OF_GPIO 5config OF_GPIO
6 def_bool y 6 def_bool y
7 depends on OF && PPC_OF && HAVE_GPIO_LIB 7 depends on OF && PPC_OF && GPIOLIB
8 help 8 help
9 OpenFirmware GPIO accessors 9 OpenFirmware GPIO accessors
10 10
diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c
index 5c015d310d4a..344e1b03dd8b 100644
--- a/drivers/of/of_i2c.c
+++ b/drivers/of/of_i2c.c
@@ -91,8 +91,6 @@ void of_register_i2c_devices(struct i2c_adapter *adap,
91 } 91 }
92 92
93 info.irq = irq_of_parse_and_map(node, 0); 93 info.irq = irq_of_parse_and_map(node, 0);
94 if (info.irq == NO_IRQ)
95 info.irq = -1;
96 94
97 if (of_find_i2c_driver(node, &info) < 0) { 95 if (of_find_i2c_driver(node, &info) < 0) {
98 irq_dispose_mapping(info.irq); 96 irq_dispose_mapping(info.irq);
diff --git a/drivers/parport/ieee1284.c b/drivers/parport/ieee1284.c
index 0338b0912674..e97059415ab4 100644
--- a/drivers/parport/ieee1284.c
+++ b/drivers/parport/ieee1284.c
@@ -199,8 +199,6 @@ int parport_wait_peripheral(struct parport *port,
199 /* 40ms of slow polling. */ 199 /* 40ms of slow polling. */
200 deadline = jiffies + msecs_to_jiffies(40); 200 deadline = jiffies + msecs_to_jiffies(40);
201 while (time_before (jiffies, deadline)) { 201 while (time_before (jiffies, deadline)) {
202 int ret;
203
204 if (signal_pending (current)) 202 if (signal_pending (current))
205 return -EINTR; 203 return -EINTR;
206 204
diff --git a/drivers/parport/parport_ax88796.c b/drivers/parport/parport_ax88796.c
index 4ec220b2eae7..6938d2e9f18f 100644
--- a/drivers/parport/parport_ax88796.c
+++ b/drivers/parport/parport_ax88796.c
@@ -406,6 +406,8 @@ static int parport_ax88796_resume(struct platform_device *dev)
406#define parport_ax88796_resume NULL 406#define parport_ax88796_resume NULL
407#endif 407#endif
408 408
409MODULE_ALIAS("platform:ax88796-pp");
410
409static struct platform_driver axdrv = { 411static struct platform_driver axdrv = {
410 .driver = { 412 .driver = {
411 .name = "ax88796-pp", 413 .name = "ax88796-pp",
diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c
index 802a81d47367..00e1d9620f7c 100644
--- a/drivers/parport/parport_cs.c
+++ b/drivers/parport/parport_cs.c
@@ -235,7 +235,7 @@ failed:
235 235
236======================================================================*/ 236======================================================================*/
237 237
238void parport_cs_release(struct pcmcia_device *link) 238static void parport_cs_release(struct pcmcia_device *link)
239{ 239{
240 parport_info_t *info = link->priv; 240 parport_info_t *info = link->priv;
241 241
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index e0c2a4584ec6..8a846adf1dcf 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -2867,7 +2867,7 @@ static struct parport_pc_pci {
2867 * and 840 locks up if you write 1 to bit 2! */ 2867 * and 840 locks up if you write 1 to bit 2! */
2868 /* oxsemi_952 */ { 1, { { 0, 1 }, } }, 2868 /* oxsemi_952 */ { 1, { { 0, 1 }, } },
2869 /* oxsemi_954 */ { 1, { { 0, -1 }, } }, 2869 /* oxsemi_954 */ { 1, { { 0, -1 }, } },
2870 /* oxsemi_840 */ { 1, { { 0, -1 }, } }, 2870 /* oxsemi_840 */ { 1, { { 0, 1 }, } },
2871 /* aks_0100 */ { 1, { { 0, -1 }, } }, 2871 /* aks_0100 */ { 1, { { 0, -1 }, } },
2872 /* mobility_pp */ { 1, { { 0, 1 }, } }, 2872 /* mobility_pp */ { 1, { { 0, 1 }, } },
2873 /* netmos_9705 */ { 1, { { 0, -1 }, } }, /* untested */ 2873 /* netmos_9705 */ { 1, { { 0, -1 }, } }, /* untested */
diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
index d950fc34320a..554e11f9e1ce 100644
--- a/drivers/parport/procfs.c
+++ b/drivers/parport/procfs.c
@@ -429,9 +429,6 @@ struct parport_default_sysctl_table
429 ctl_table dev_dir[2]; 429 ctl_table dev_dir[2];
430}; 430};
431 431
432extern unsigned long parport_default_timeslice;
433extern int parport_default_spintime;
434
435static struct parport_default_sysctl_table 432static struct parport_default_sysctl_table
436parport_default_sysctl_table = { 433parport_default_sysctl_table = {
437 .sysctl_header = NULL, 434 .sysctl_header = NULL,
diff --git a/drivers/pci/dmar.c b/drivers/pci/dmar.c
index f941f609dbf3..8bf86ae2333f 100644
--- a/drivers/pci/dmar.c
+++ b/drivers/pci/dmar.c
@@ -317,10 +317,8 @@ int __init dmar_table_init(void)
317 return -ENODEV; 317 return -ENODEV;
318 } 318 }
319 319
320 if (list_empty(&dmar_rmrr_units)) { 320 if (list_empty(&dmar_rmrr_units))
321 printk(KERN_INFO PREFIX "No RMRR found\n"); 321 printk(KERN_INFO PREFIX "No RMRR found\n");
322 return -ENODEV;
323 }
324 322
325 return 0; 323 return 0;
326} 324}
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index d00f0e0d8453..e9c356236d27 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1040,7 +1040,7 @@ int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
1040 * @dev: PCI device to handle. 1040 * @dev: PCI device to handle.
1041 * @state: PCI state from which device will issue PME#. 1041 * @state: PCI state from which device will issue PME#.
1042 */ 1042 */
1043static bool pci_pme_capable(struct pci_dev *dev, pci_power_t state) 1043bool pci_pme_capable(struct pci_dev *dev, pci_power_t state)
1044{ 1044{
1045 if (!dev->pm_cap) 1045 if (!dev->pm_cap)
1046 return false; 1046 return false;
@@ -1123,17 +1123,10 @@ int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
1123} 1123}
1124 1124
1125/** 1125/**
1126 * pci_prepare_to_sleep - prepare PCI device for system-wide transition into a sleep state
1127 * @dev: Device to handle.
1128 *
1129 * Choose the power state appropriate for the device depending on whether
1130 * it can wake up the system and/or is power manageable by the platform
1131 * (PCI_D3hot is the default) and put the device into that state.
1132 */ 1126 */
1133int pci_prepare_to_sleep(struct pci_dev *dev) 1127pci_power_t pci_target_state(struct pci_dev *dev)
1134{ 1128{
1135 pci_power_t target_state = PCI_D3hot; 1129 pci_power_t target_state = PCI_D3hot;
1136 int error;
1137 1130
1138 if (platform_pci_power_manageable(dev)) { 1131 if (platform_pci_power_manageable(dev)) {
1139 /* 1132 /*
@@ -1160,7 +1153,7 @@ int pci_prepare_to_sleep(struct pci_dev *dev)
1160 * to generate PME#. 1153 * to generate PME#.
1161 */ 1154 */
1162 if (!dev->pm_cap) 1155 if (!dev->pm_cap)
1163 return -EIO; 1156 return PCI_POWER_ERROR;
1164 1157
1165 if (dev->pme_support) { 1158 if (dev->pme_support) {
1166 while (target_state 1159 while (target_state
@@ -1169,6 +1162,25 @@ int pci_prepare_to_sleep(struct pci_dev *dev)
1169 } 1162 }
1170 } 1163 }
1171 1164
1165 return target_state;
1166}
1167
1168/**
1169 * pci_prepare_to_sleep - prepare PCI device for system-wide transition into a sleep state
1170 * @dev: Device to handle.
1171 *
1172 * Choose the power state appropriate for the device depending on whether
1173 * it can wake up the system and/or is power manageable by the platform
1174 * (PCI_D3hot is the default) and put the device into that state.
1175 */
1176int pci_prepare_to_sleep(struct pci_dev *dev)
1177{
1178 pci_power_t target_state = pci_target_state(dev);
1179 int error;
1180
1181 if (target_state == PCI_POWER_ERROR)
1182 return -EIO;
1183
1172 pci_enable_wake(dev, target_state, true); 1184 pci_enable_wake(dev, target_state, true);
1173 1185
1174 error = pci_set_power_state(dev, target_state); 1186 error = pci_set_power_state(dev, target_state);
@@ -1918,7 +1930,9 @@ EXPORT_SYMBOL(pci_select_bars);
1918EXPORT_SYMBOL(pci_set_power_state); 1930EXPORT_SYMBOL(pci_set_power_state);
1919EXPORT_SYMBOL(pci_save_state); 1931EXPORT_SYMBOL(pci_save_state);
1920EXPORT_SYMBOL(pci_restore_state); 1932EXPORT_SYMBOL(pci_restore_state);
1933EXPORT_SYMBOL(pci_pme_capable);
1921EXPORT_SYMBOL(pci_enable_wake); 1934EXPORT_SYMBOL(pci_enable_wake);
1935EXPORT_SYMBOL(pci_target_state);
1922EXPORT_SYMBOL(pci_prepare_to_sleep); 1936EXPORT_SYMBOL(pci_prepare_to_sleep);
1923EXPORT_SYMBOL(pci_back_from_sleep); 1937EXPORT_SYMBOL(pci_back_from_sleep);
1924EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state); 1938EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state);
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 4400dffbd93a..e1098c302c45 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -88,7 +88,7 @@ proc_bus_pci_read(struct file *file, char __user *buf, size_t nbytes, loff_t *pp
88 if ((pos & 3) && cnt > 2) { 88 if ((pos & 3) && cnt > 2) {
89 unsigned short val; 89 unsigned short val;
90 pci_user_read_config_word(dev, pos, &val); 90 pci_user_read_config_word(dev, pos, &val);
91 __put_user(cpu_to_le16(val), (unsigned short __user *) buf); 91 __put_user(cpu_to_le16(val), (__le16 __user *) buf);
92 buf += 2; 92 buf += 2;
93 pos += 2; 93 pos += 2;
94 cnt -= 2; 94 cnt -= 2;
@@ -97,7 +97,7 @@ proc_bus_pci_read(struct file *file, char __user *buf, size_t nbytes, loff_t *pp
97 while (cnt >= 4) { 97 while (cnt >= 4) {
98 unsigned int val; 98 unsigned int val;
99 pci_user_read_config_dword(dev, pos, &val); 99 pci_user_read_config_dword(dev, pos, &val);
100 __put_user(cpu_to_le32(val), (unsigned int __user *) buf); 100 __put_user(cpu_to_le32(val), (__le32 __user *) buf);
101 buf += 4; 101 buf += 4;
102 pos += 4; 102 pos += 4;
103 cnt -= 4; 103 cnt -= 4;
@@ -106,7 +106,7 @@ proc_bus_pci_read(struct file *file, char __user *buf, size_t nbytes, loff_t *pp
106 if (cnt >= 2) { 106 if (cnt >= 2) {
107 unsigned short val; 107 unsigned short val;
108 pci_user_read_config_word(dev, pos, &val); 108 pci_user_read_config_word(dev, pos, &val);
109 __put_user(cpu_to_le16(val), (unsigned short __user *) buf); 109 __put_user(cpu_to_le16(val), (__le16 __user *) buf);
110 buf += 2; 110 buf += 2;
111 pos += 2; 111 pos += 2;
112 cnt -= 2; 112 cnt -= 2;
@@ -156,8 +156,8 @@ proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, lof
156 } 156 }
157 157
158 if ((pos & 3) && cnt > 2) { 158 if ((pos & 3) && cnt > 2) {
159 unsigned short val; 159 __le16 val;
160 __get_user(val, (unsigned short __user *) buf); 160 __get_user(val, (__le16 __user *) buf);
161 pci_user_write_config_word(dev, pos, le16_to_cpu(val)); 161 pci_user_write_config_word(dev, pos, le16_to_cpu(val));
162 buf += 2; 162 buf += 2;
163 pos += 2; 163 pos += 2;
@@ -165,8 +165,8 @@ proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, lof
165 } 165 }
166 166
167 while (cnt >= 4) { 167 while (cnt >= 4) {
168 unsigned int val; 168 __le32 val;
169 __get_user(val, (unsigned int __user *) buf); 169 __get_user(val, (__le32 __user *) buf);
170 pci_user_write_config_dword(dev, pos, le32_to_cpu(val)); 170 pci_user_write_config_dword(dev, pos, le32_to_cpu(val));
171 buf += 4; 171 buf += 4;
172 pos += 4; 172 pos += 4;
@@ -174,8 +174,8 @@ proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, lof
174 } 174 }
175 175
176 if (cnt >= 2) { 176 if (cnt >= 2) {
177 unsigned short val; 177 __le16 val;
178 __get_user(val, (unsigned short __user *) buf); 178 __get_user(val, (__le16 __user *) buf);
179 pci_user_write_config_word(dev, pos, le16_to_cpu(val)); 179 pci_user_write_config_word(dev, pos, le16_to_cpu(val));
180 buf += 2; 180 buf += 2;
181 pos += 2; 181 pos += 2;
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index e45402adac3f..e0f884034c9f 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -219,7 +219,8 @@ config PCMCIA_SA1111
219config PCMCIA_PXA2XX 219config PCMCIA_PXA2XX
220 tristate "PXA2xx support" 220 tristate "PXA2xx support"
221 depends on ARM && ARCH_PXA && PCMCIA 221 depends on ARM && ARCH_PXA && PCMCIA
222 depends on ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL || MACH_ARMCORE 222 depends on (ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL \
223 || MACH_ARMCORE || ARCH_PXA_PALM)
223 help 224 help
224 Say Y here to include support for the PXA2xx PCMCIA controller 225 Say Y here to include support for the PXA2xx PCMCIA controller
225 226
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index 85c6cc931f97..269a9e913ba2 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -72,4 +72,5 @@ pxa2xx_cs-$(CONFIG_ARCH_LUBBOCK) += pxa2xx_lubbock.o sa1111_generic.o
72pxa2xx_cs-$(CONFIG_MACH_MAINSTONE) += pxa2xx_mainstone.o 72pxa2xx_cs-$(CONFIG_MACH_MAINSTONE) += pxa2xx_mainstone.o
73pxa2xx_cs-$(CONFIG_PXA_SHARPSL) += pxa2xx_sharpsl.o 73pxa2xx_cs-$(CONFIG_PXA_SHARPSL) += pxa2xx_sharpsl.o
74pxa2xx_cs-$(CONFIG_MACH_ARMCORE) += pxa2xx_cm_x270.o 74pxa2xx_cs-$(CONFIG_MACH_ARMCORE) += pxa2xx_cm_x270.o
75pxa2xx_cs-$(CONFIG_MACH_PALMTX) += pxa2xx_palmtx.o
75 76
diff --git a/drivers/pcmcia/electra_cf.c b/drivers/pcmcia/electra_cf.c
index c21f9a9c3e3f..a34284b1482a 100644
--- a/drivers/pcmcia/electra_cf.c
+++ b/drivers/pcmcia/electra_cf.c
@@ -28,6 +28,7 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/mm.h>
31#include <linux/vmalloc.h> 32#include <linux/vmalloc.h>
32#include <linux/of_platform.h> 33#include <linux/of_platform.h>
33 34
diff --git a/drivers/pcmcia/pxa2xx_cm_x270.c b/drivers/pcmcia/pxa2xx_cm_x270.c
index f123fce65f2e..bb95db7d2b76 100644
--- a/drivers/pcmcia/pxa2xx_cm_x270.c
+++ b/drivers/pcmcia/pxa2xx_cm_x270.c
@@ -5,83 +5,60 @@
5 * it under the terms of the GNU General Public License version 2 as 5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation. 6 * published by the Free Software Foundation.
7 * 7 *
8 * Compulab Ltd., 2003, 2007 8 * Compulab Ltd., 2003, 2007, 2008
9 * Mike Rapoport <mike@compulab.co.il> 9 * Mike Rapoport <mike@compulab.co.il>
10 * 10 *
11 */ 11 */
12 12
13#include <linux/kernel.h>
14#include <linux/sched.h>
15#include <linux/platform_device.h> 13#include <linux/platform_device.h>
16#include <linux/irq.h> 14#include <linux/irq.h>
17#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/gpio.h>
18 17
19#include <pcmcia/ss.h>
20#include <asm/hardware.h>
21#include <asm/mach-types.h> 18#include <asm/mach-types.h>
22
23#include <asm/arch/pxa-regs.h> 19#include <asm/arch/pxa-regs.h>
24#include <asm/arch/pxa2xx-gpio.h>
25#include <asm/arch/cm-x270.h>
26 20
27#include "soc_common.h" 21#include "soc_common.h"
28 22
23#define GPIO_PCMCIA_S0_CD_VALID (84)
24#define GPIO_PCMCIA_S0_RDYINT (82)
25#define GPIO_PCMCIA_RESET (53)
26
27#define PCMCIA_S0_CD_VALID IRQ_GPIO(GPIO_PCMCIA_S0_CD_VALID)
28#define PCMCIA_S0_RDYINT IRQ_GPIO(GPIO_PCMCIA_S0_RDYINT)
29
30
29static struct pcmcia_irqs irqs[] = { 31static struct pcmcia_irqs irqs[] = {
30 { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" }, 32 { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" },
31 { 1, PCMCIA_S1_CD_VALID, "PCMCIA1 CD" },
32}; 33};
33 34
34static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt) 35static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
35{ 36{
36 GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) | 37 int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset");
37 GPIO_bit(GPIO49_nPWE) | 38 if (ret)
38 GPIO_bit(GPIO50_nPIOR) | 39 return ret;
39 GPIO_bit(GPIO51_nPIOW) | 40 gpio_direction_output(GPIO_PCMCIA_RESET, 0);
40 GPIO_bit(GPIO85_nPCE_1) | 41
41 GPIO_bit(GPIO54_nPCE_2); 42 skt->irq = PCMCIA_S0_RDYINT;
42 43 ret = soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
43 pxa_gpio_mode(GPIO48_nPOE_MD); 44 if (!ret)
44 pxa_gpio_mode(GPIO49_nPWE_MD); 45 gpio_free(GPIO_PCMCIA_RESET);
45 pxa_gpio_mode(GPIO50_nPIOR_MD); 46
46 pxa_gpio_mode(GPIO51_nPIOW_MD); 47 return ret;
47 pxa_gpio_mode(GPIO85_nPCE_1_MD);
48 pxa_gpio_mode(GPIO54_nPCE_2_MD);
49 pxa_gpio_mode(GPIO55_nPREG_MD);
50 pxa_gpio_mode(GPIO56_nPWAIT_MD);
51 pxa_gpio_mode(GPIO57_nIOIS16_MD);
52
53 /* Reset signal */
54 pxa_gpio_mode(GPIO53_nPCE_2 | GPIO_OUT);
55 GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
56
57 set_irq_type(PCMCIA_S0_CD_VALID, IRQ_TYPE_EDGE_BOTH);
58 set_irq_type(PCMCIA_S1_CD_VALID, IRQ_TYPE_EDGE_BOTH);
59
60 /* irq's for slots: */
61 set_irq_type(PCMCIA_S0_RDYINT, IRQ_TYPE_EDGE_FALLING);
62 set_irq_type(PCMCIA_S1_RDYINT, IRQ_TYPE_EDGE_FALLING);
63
64 skt->irq = (skt->nr == 0) ? PCMCIA_S0_RDYINT : PCMCIA_S1_RDYINT;
65 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
66} 48}
67 49
68static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt) 50static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
69{ 51{
70 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); 52 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
71 53 gpio_free(GPIO_PCMCIA_RESET);
72 set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_CD_VALID), IRQ_TYPE_NONE);
73 set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_CD_VALID), IRQ_TYPE_NONE);
74
75 set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_RDYINT), IRQ_TYPE_NONE);
76 set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_RDYINT), IRQ_TYPE_NONE);
77} 54}
78 55
79 56
80static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt, 57static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
81 struct pcmcia_state *state) 58 struct pcmcia_state *state)
82{ 59{
83 state->detect = (PCC_DETECT(skt->nr) == 0) ? 1 : 0; 60 state->detect = (gpio_get_value(GPIO_PCMCIA_S0_CD_VALID) == 0) ? 1 : 0;
84 state->ready = (PCC_READY(skt->nr) == 0) ? 0 : 1; 61 state->ready = (gpio_get_value(GPIO_PCMCIA_S0_RDYINT) == 0) ? 0 : 1;
85 state->bvd1 = 1; 62 state->bvd1 = 1;
86 state->bvd2 = 1; 63 state->bvd2 = 1;
87 state->vs_3v = 0; 64 state->vs_3v = 0;
@@ -93,32 +70,16 @@ static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
93static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, 70static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
94 const socket_state_t *state) 71 const socket_state_t *state)
95{ 72{
96 GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
97 pxa_gpio_mode(GPIO49_nPWE | GPIO_OUT);
98
99 switch (skt->nr) { 73 switch (skt->nr) {
100 case 0: 74 case 0:
101 if (state->flags & SS_RESET) { 75 if (state->flags & SS_RESET) {
102 GPCR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE); 76 gpio_set_value(GPIO_PCMCIA_RESET, 1);
103 GPSR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
104 udelay(10);
105 GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
106 GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
107 }
108 break;
109 case 1:
110 if (state->flags & SS_RESET) {
111 GPCR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
112 GPSR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
113 udelay(10); 77 udelay(10);
114 GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2); 78 gpio_set_value(GPIO_PCMCIA_RESET, 0);
115 GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
116 } 79 }
117 break; 80 break;
118 } 81 }
119 82
120 pxa_gpio_mode(GPIO49_nPWE_MD);
121
122 return 0; 83 return 0;
123} 84}
124 85
@@ -139,7 +100,7 @@ static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = {
139 .configure_socket = cmx270_pcmcia_configure_socket, 100 .configure_socket = cmx270_pcmcia_configure_socket,
140 .socket_init = cmx270_pcmcia_socket_init, 101 .socket_init = cmx270_pcmcia_socket_init,
141 .socket_suspend = cmx270_pcmcia_socket_suspend, 102 .socket_suspend = cmx270_pcmcia_socket_suspend,
142 .nr = 2, 103 .nr = 1,
143}; 104};
144 105
145static struct platform_device *cmx270_pcmcia_device; 106static struct platform_device *cmx270_pcmcia_device;
diff --git a/drivers/pcmcia/pxa2xx_palmtx.c b/drivers/pcmcia/pxa2xx_palmtx.c
new file mode 100644
index 000000000000..4abde190c1f5
--- /dev/null
+++ b/drivers/pcmcia/pxa2xx_palmtx.c
@@ -0,0 +1,118 @@
1/*
2 * linux/drivers/pcmcia/pxa2xx_palmtx.c
3 *
4 * Driver for Palm T|X PCMCIA
5 *
6 * Copyright (C) 2007-2008 Marek Vasut <marek.vasut@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/platform_device.h>
16
17#include <asm/mach-types.h>
18
19#include <asm/arch/gpio.h>
20#include <asm/arch/palmtx.h>
21
22#include "soc_common.h"
23
24static int palmtx_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
25{
26 skt->irq = IRQ_GPIO(GPIO_NR_PALMTX_PCMCIA_READY);
27 return 0;
28}
29
30static void palmtx_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
31{
32}
33
34static void palmtx_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
35 struct pcmcia_state *state)
36{
37 state->detect = 1; /* always inserted */
38 state->ready = !!gpio_get_value(GPIO_NR_PALMTX_PCMCIA_READY);
39 state->bvd1 = 1;
40 state->bvd2 = 1;
41 state->wrprot = 0;
42 state->vs_3v = 1;
43 state->vs_Xv = 0;
44}
45
46static int
47palmtx_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
48 const socket_state_t *state)
49{
50 gpio_set_value(GPIO_NR_PALMTX_PCMCIA_POWER1, 1);
51 gpio_set_value(GPIO_NR_PALMTX_PCMCIA_POWER2, 1);
52 gpio_set_value(GPIO_NR_PALMTX_PCMCIA_RESET,
53 !!(state->flags & SS_RESET));
54
55 return 0;
56}
57
58static void palmtx_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
59{
60}
61
62static void palmtx_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
63{
64}
65
66static struct pcmcia_low_level palmtx_pcmcia_ops = {
67 .owner = THIS_MODULE,
68
69 .first = 0,
70 .nr = 1,
71
72 .hw_init = palmtx_pcmcia_hw_init,
73 .hw_shutdown = palmtx_pcmcia_hw_shutdown,
74
75 .socket_state = palmtx_pcmcia_socket_state,
76 .configure_socket = palmtx_pcmcia_configure_socket,
77
78 .socket_init = palmtx_pcmcia_socket_init,
79 .socket_suspend = palmtx_pcmcia_socket_suspend,
80};
81
82static struct platform_device *palmtx_pcmcia_device;
83
84static int __init palmtx_pcmcia_init(void)
85{
86 int ret;
87
88 if (!machine_is_palmtx())
89 return -ENODEV;
90
91 palmtx_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
92 if (!palmtx_pcmcia_device)
93 return -ENOMEM;
94
95 ret = platform_device_add_data(palmtx_pcmcia_device, &palmtx_pcmcia_ops,
96 sizeof(palmtx_pcmcia_ops));
97
98 if (!ret)
99 ret = platform_device_add(palmtx_pcmcia_device);
100
101 if (ret)
102 platform_device_put(palmtx_pcmcia_device);
103
104 return ret;
105}
106
107static void __exit palmtx_pcmcia_exit(void)
108{
109 platform_device_unregister(palmtx_pcmcia_device);
110}
111
112fs_initcall(palmtx_pcmcia_init);
113module_exit(palmtx_pcmcia_exit);
114
115MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
116MODULE_DESCRIPTION("PCMCIA support for Palm T|X");
117MODULE_ALIAS("platform:pxa2xx-pcmcia");
118MODULE_LICENSE("GPL");
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h
index e3fa9a2d9a3d..9fd7bb9b7dce 100644
--- a/drivers/pnp/base.h
+++ b/drivers/pnp/base.h
@@ -19,7 +19,6 @@ struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
19int pnp_interface_attach_device(struct pnp_dev *dev); 19int pnp_interface_attach_device(struct pnp_dev *dev);
20 20
21int pnp_add_card(struct pnp_card *card); 21int pnp_add_card(struct pnp_card *card);
22struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id);
23void pnp_remove_card(struct pnp_card *card); 22void pnp_remove_card(struct pnp_card *card);
24int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev); 23int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
25void pnp_remove_card_device(struct pnp_dev *dev); 24void pnp_remove_card_device(struct pnp_dev *dev);
diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c
index a762a4176736..e75b060daa95 100644
--- a/drivers/pnp/card.c
+++ b/drivers/pnp/card.c
@@ -8,6 +8,7 @@
8#include <linux/ctype.h> 8#include <linux/ctype.h>
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/pnp.h> 10#include <linux/pnp.h>
11#include <linux/dma-mapping.h>
11#include "base.h" 12#include "base.h"
12 13
13LIST_HEAD(pnp_cards); 14LIST_HEAD(pnp_cards);
@@ -101,7 +102,7 @@ static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv)
101 * @id: pointer to a pnp_id structure 102 * @id: pointer to a pnp_id structure
102 * @card: pointer to the desired card 103 * @card: pointer to the desired card
103 */ 104 */
104struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id) 105static struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id)
105{ 106{
106 struct pnp_id *dev_id, *ptr; 107 struct pnp_id *dev_id, *ptr;
107 108
@@ -167,6 +168,9 @@ struct pnp_card *pnp_alloc_card(struct pnp_protocol *protocol, int id, char *pnp
167 sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number, 168 sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
168 card->number); 169 card->number);
169 170
171 card->dev.coherent_dma_mask = DMA_24BIT_MASK;
172 card->dev.dma_mask = &card->dev.coherent_dma_mask;
173
170 dev_id = pnp_add_card_id(card, pnpid); 174 dev_id = pnp_add_card_id(card, pnpid);
171 if (!dev_id) { 175 if (!dev_id) {
172 kfree(card); 176 kfree(card);
diff --git a/drivers/pnp/quirks.c b/drivers/pnp/quirks.c
index 55f55ed72dc7..0bdf9b8a5e58 100644
--- a/drivers/pnp/quirks.c
+++ b/drivers/pnp/quirks.c
@@ -245,15 +245,17 @@ static void quirk_system_pci_resources(struct pnp_dev *dev)
245 */ 245 */
246 for_each_pci_dev(pdev) { 246 for_each_pci_dev(pdev) {
247 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 247 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
248 if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM) || 248 unsigned int type;
249 pci_resource_len(pdev, i) == 0) 249
250 type = pci_resource_flags(pdev, i) &
251 (IORESOURCE_IO | IORESOURCE_MEM);
252 if (!type || pci_resource_len(pdev, i) == 0)
250 continue; 253 continue;
251 254
252 pci_start = pci_resource_start(pdev, i); 255 pci_start = pci_resource_start(pdev, i);
253 pci_end = pci_resource_end(pdev, i); 256 pci_end = pci_resource_end(pdev, i);
254 for (j = 0; 257 for (j = 0;
255 (res = pnp_get_resource(dev, IORESOURCE_MEM, j)); 258 (res = pnp_get_resource(dev, type, j)); j++) {
256 j++) {
257 if (res->start == 0 && res->end == 0) 259 if (res->start == 0 && res->end == 0)
258 continue; 260 continue;
259 261
@@ -283,9 +285,10 @@ static void quirk_system_pci_resources(struct pnp_dev *dev)
283 * the PCI region, and that might prevent a PCI 285 * the PCI region, and that might prevent a PCI
284 * driver from requesting its resources. 286 * driver from requesting its resources.
285 */ 287 */
286 dev_warn(&dev->dev, "mem resource " 288 dev_warn(&dev->dev, "%s resource "
287 "(0x%llx-0x%llx) overlaps %s BAR %d " 289 "(0x%llx-0x%llx) overlaps %s BAR %d "
288 "(0x%llx-0x%llx), disabling\n", 290 "(0x%llx-0x%llx), disabling\n",
291 pnp_resource_type_name(res),
289 (unsigned long long) pnp_start, 292 (unsigned long long) pnp_start,
290 (unsigned long long) pnp_end, 293 (unsigned long long) pnp_end,
291 pci_name(pdev), i, 294 pci_name(pdev), i,
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 58c806e9c58a..4d17d384578d 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -49,4 +49,10 @@ config BATTERY_OLPC
49 help 49 help
50 Say Y to enable support for the battery on the OLPC laptop. 50 Say Y to enable support for the battery on the OLPC laptop.
51 51
52config BATTERY_PALMTX
53 tristate "Palm T|X battery"
54 depends on MACH_PALMTX
55 help
56 Say Y to enable support for the battery in Palm T|X.
57
52endif # POWER_SUPPLY 58endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 6413ded5fe5f..6f43a54ee420 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -20,3 +20,4 @@ obj-$(CONFIG_APM_POWER) += apm_power.o
20obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o 20obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o
21obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o 21obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o
22obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o 22obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o
23obj-$(CONFIG_BATTERY_PALMTX) += palmtx_battery.o
diff --git a/drivers/power/ds2760_battery.c b/drivers/power/ds2760_battery.c
index 71be36f18709..308ddb201b66 100644
--- a/drivers/power/ds2760_battery.c
+++ b/drivers/power/ds2760_battery.c
@@ -433,6 +433,8 @@ static int ds2760_battery_resume(struct platform_device *pdev)
433 433
434#endif /* CONFIG_PM */ 434#endif /* CONFIG_PM */
435 435
436MODULE_ALIAS("platform:ds2760-battery");
437
436static struct platform_driver ds2760_battery_driver = { 438static struct platform_driver ds2760_battery_driver = {
437 .driver = { 439 .driver = {
438 .name = "ds2760-battery", 440 .name = "ds2760-battery",
diff --git a/drivers/power/palmtx_battery.c b/drivers/power/palmtx_battery.c
new file mode 100644
index 000000000000..244bb273a637
--- /dev/null
+++ b/drivers/power/palmtx_battery.c
@@ -0,0 +1,198 @@
1/*
2 * linux/drivers/power/palmtx_battery.c
3 *
4 * Battery measurement code for Palm T|X Handheld computer
5 *
6 * based on tosa_battery.c
7 *
8 * Copyright (C) 2008 Marek Vasut <marek.vasut@gmail.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/power_supply.h>
18#include <linux/wm97xx.h>
19#include <linux/delay.h>
20#include <linux/spinlock.h>
21#include <linux/interrupt.h>
22#include <linux/gpio.h>
23
24#include <asm/mach-types.h>
25#include <asm/arch/palmtx.h>
26
27static DEFINE_MUTEX(bat_lock);
28static struct work_struct bat_work;
29struct mutex work_lock;
30int bat_status = POWER_SUPPLY_STATUS_DISCHARGING;
31
32static unsigned long palmtx_read_bat(struct power_supply *bat_ps)
33{
34 return wm97xx_read_aux_adc(bat_ps->dev->parent->driver_data,
35 WM97XX_AUX_ID3) * 1000 / 414;
36}
37
38static unsigned long palmtx_read_temp(struct power_supply *bat_ps)
39{
40 return wm97xx_read_aux_adc(bat_ps->dev->parent->driver_data,
41 WM97XX_AUX_ID2);
42}
43
44static int palmtx_bat_get_property(struct power_supply *bat_ps,
45 enum power_supply_property psp,
46 union power_supply_propval *val)
47{
48 switch (psp) {
49 case POWER_SUPPLY_PROP_STATUS:
50 val->intval = bat_status;
51 break;
52 case POWER_SUPPLY_PROP_TECHNOLOGY:
53 val->intval = POWER_SUPPLY_TECHNOLOGY_LIPO;
54 break;
55 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
56 val->intval = palmtx_read_bat(bat_ps);
57 break;
58 case POWER_SUPPLY_PROP_VOLTAGE_MAX:
59 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
60 val->intval = PALMTX_BAT_MAX_VOLTAGE;
61 break;
62 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
63 val->intval = PALMTX_BAT_MIN_VOLTAGE;
64 break;
65 case POWER_SUPPLY_PROP_TEMP:
66 val->intval = palmtx_read_temp(bat_ps);
67 break;
68 case POWER_SUPPLY_PROP_PRESENT:
69 val->intval = 1;
70 break;
71 default:
72 return -EINVAL;
73 }
74 return 0;
75}
76
77static void palmtx_bat_external_power_changed(struct power_supply *bat_ps)
78{
79 schedule_work(&bat_work);
80}
81
82static char *status_text[] = {
83 [POWER_SUPPLY_STATUS_UNKNOWN] = "Unknown",
84 [POWER_SUPPLY_STATUS_CHARGING] = "Charging",
85 [POWER_SUPPLY_STATUS_DISCHARGING] = "Discharging",
86};
87
88static void palmtx_bat_update(struct power_supply *bat_ps)
89{
90 int old_status = bat_status;
91
92 mutex_lock(&work_lock);
93
94 bat_status = gpio_get_value(GPIO_NR_PALMTX_POWER_DETECT) ?
95 POWER_SUPPLY_STATUS_CHARGING :
96 POWER_SUPPLY_STATUS_DISCHARGING;
97
98 if (old_status != bat_status) {
99 pr_debug("%s %s -> %s\n", bat_ps->name,
100 status_text[old_status],
101 status_text[bat_status]);
102 power_supply_changed(bat_ps);
103 }
104
105 mutex_unlock(&work_lock);
106}
107
108static enum power_supply_property palmtx_bat_main_props[] = {
109 POWER_SUPPLY_PROP_STATUS,
110 POWER_SUPPLY_PROP_TECHNOLOGY,
111 POWER_SUPPLY_PROP_VOLTAGE_NOW,
112 POWER_SUPPLY_PROP_VOLTAGE_MAX,
113 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
114 POWER_SUPPLY_PROP_TEMP,
115 POWER_SUPPLY_PROP_PRESENT,
116};
117
118struct power_supply bat_ps = {
119 .name = "main-battery",
120 .type = POWER_SUPPLY_TYPE_BATTERY,
121 .properties = palmtx_bat_main_props,
122 .num_properties = ARRAY_SIZE(palmtx_bat_main_props),
123 .get_property = palmtx_bat_get_property,
124 .external_power_changed = palmtx_bat_external_power_changed,
125 .use_for_apm = 1,
126};
127
128static void palmtx_bat_work(struct work_struct *work)
129{
130 palmtx_bat_update(&bat_ps);
131}
132
133#ifdef CONFIG_PM
134static int palmtx_bat_suspend(struct platform_device *dev, pm_message_t state)
135{
136 flush_scheduled_work();
137 return 0;
138}
139
140static int palmtx_bat_resume(struct platform_device *dev)
141{
142 schedule_work(&bat_work);
143 return 0;
144}
145#else
146#define palmtx_bat_suspend NULL
147#define palmtx_bat_resume NULL
148#endif
149
150static int __devinit palmtx_bat_probe(struct platform_device *dev)
151{
152 int ret = 0;
153
154 if (!machine_is_palmtx())
155 return -ENODEV;
156
157 mutex_init(&work_lock);
158
159 INIT_WORK(&bat_work, palmtx_bat_work);
160
161 ret = power_supply_register(&dev->dev, &bat_ps);
162 if (!ret)
163 schedule_work(&bat_work);
164
165 return ret;
166}
167
168static int __devexit palmtx_bat_remove(struct platform_device *dev)
169{
170 power_supply_unregister(&bat_ps);
171 return 0;
172}
173
174static struct platform_driver palmtx_bat_driver = {
175 .driver.name = "wm97xx-battery",
176 .driver.owner = THIS_MODULE,
177 .probe = palmtx_bat_probe,
178 .remove = __devexit_p(palmtx_bat_remove),
179 .suspend = palmtx_bat_suspend,
180 .resume = palmtx_bat_resume,
181};
182
183static int __init palmtx_bat_init(void)
184{
185 return platform_driver_register(&palmtx_bat_driver);
186}
187
188static void __exit palmtx_bat_exit(void)
189{
190 platform_driver_unregister(&palmtx_bat_driver);
191}
192
193module_init(palmtx_bat_init);
194module_exit(palmtx_bat_exit);
195
196MODULE_LICENSE("GPL");
197MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
198MODULE_DESCRIPTION("Palm T|X battery driver");
diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
index 82810b7bff9c..0471ec743ab9 100644
--- a/drivers/power/pda_power.c
+++ b/drivers/power/pda_power.c
@@ -362,6 +362,8 @@ static int pda_power_resume(struct platform_device *pdev)
362#define pda_power_resume NULL 362#define pda_power_resume NULL
363#endif /* CONFIG_PM */ 363#endif /* CONFIG_PM */
364 364
365MODULE_ALIAS("platform:pda-power");
366
365static struct platform_driver pda_power_pdrv = { 367static struct platform_driver pda_power_pdrv = {
366 .driver = { 368 .driver = {
367 .name = "pda-power", 369 .name = "pda-power",
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index fc85bf2e4a97..90ab73825401 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -273,6 +273,25 @@ comment "SPI RTC drivers"
273 273
274if SPI_MASTER 274if SPI_MASTER
275 275
276config RTC_DRV_M41T94
277 tristate "ST M41T94"
278 help
279 If you say yes here you will get support for the
280 ST M41T94 SPI RTC chip.
281
282 This driver can also be built as a module. If so, the module
283 will be called rtc-m41t94.
284
285config RTC_DRV_DS1305
286 tristate "Dallas/Maxim DS1305/DS1306"
287 help
288 Select this driver to get support for the Dallas/Maxim DS1305
289 and DS1306 real time clock chips. These support a trickle
290 charger, alarms, and NVRAM in addition to the clock.
291
292 This driver can also be built as a module. If so, the module
293 will be called rtc-ds1305.
294
276config RTC_DRV_MAX6902 295config RTC_DRV_MAX6902
277 tristate "Maxim MAX6902" 296 tristate "Maxim MAX6902"
278 help 297 help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index b5d9d67df887..18622ef84cab 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_RTC_DRV_BFIN) += rtc-bfin.o
24obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o 24obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
25obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o 25obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o
26obj-$(CONFIG_RTC_DRV_DS1302) += rtc-ds1302.o 26obj-$(CONFIG_RTC_DRV_DS1302) += rtc-ds1302.o
27obj-$(CONFIG_RTC_DRV_DS1305) += rtc-ds1305.o
27obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o 28obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o
28obj-$(CONFIG_RTC_DRV_DS1374) += rtc-ds1374.o 29obj-$(CONFIG_RTC_DRV_DS1374) += rtc-ds1374.o
29obj-$(CONFIG_RTC_DRV_DS1511) += rtc-ds1511.o 30obj-$(CONFIG_RTC_DRV_DS1511) += rtc-ds1511.o
@@ -34,6 +35,7 @@ obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
34obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o 35obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o
35obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 36obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
36obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o 37obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
38obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o
37obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o 39obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o
38obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o 40obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o
39obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o 41obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 9c3db934cc24..cd32d05db773 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -171,8 +171,10 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
171 | BIN2BCD(tm.tm_mday) << 24 171 | BIN2BCD(tm.tm_mday) << 24
172 | AT91_RTC_DATEEN | AT91_RTC_MTHEN); 172 | AT91_RTC_DATEEN | AT91_RTC_MTHEN);
173 173
174 if (alrm->enabled) 174 if (alrm->enabled) {
175 at91_sys_write(AT91_RTC_SCCR, AT91_RTC_ALARM);
175 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM); 176 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM);
177 }
176 178
177 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 179 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
178 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, 180 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour,
@@ -191,28 +193,22 @@ static int at91_rtc_ioctl(struct device *dev, unsigned int cmd,
191 193
192 pr_debug("%s(): cmd=%08x, arg=%08lx.\n", __func__, cmd, arg); 194 pr_debug("%s(): cmd=%08x, arg=%08lx.\n", __func__, cmd, arg);
193 195
196 /* important: scrub old status before enabling IRQs */
194 switch (cmd) { 197 switch (cmd) {
195 case RTC_AIE_OFF: /* alarm off */ 198 case RTC_AIE_OFF: /* alarm off */
196 at91_sys_write(AT91_RTC_IDR, AT91_RTC_ALARM); 199 at91_sys_write(AT91_RTC_IDR, AT91_RTC_ALARM);
197 break; 200 break;
198 case RTC_AIE_ON: /* alarm on */ 201 case RTC_AIE_ON: /* alarm on */
202 at91_sys_write(AT91_RTC_SCCR, AT91_RTC_ALARM);
199 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM); 203 at91_sys_write(AT91_RTC_IER, AT91_RTC_ALARM);
200 break; 204 break;
201 case RTC_UIE_OFF: /* update off */ 205 case RTC_UIE_OFF: /* update off */
202 case RTC_PIE_OFF: /* periodic off */
203 at91_sys_write(AT91_RTC_IDR, AT91_RTC_SECEV); 206 at91_sys_write(AT91_RTC_IDR, AT91_RTC_SECEV);
204 break; 207 break;
205 case RTC_UIE_ON: /* update on */ 208 case RTC_UIE_ON: /* update on */
206 case RTC_PIE_ON: /* periodic on */ 209 at91_sys_write(AT91_RTC_SCCR, AT91_RTC_SECEV);
207 at91_sys_write(AT91_RTC_IER, AT91_RTC_SECEV); 210 at91_sys_write(AT91_RTC_IER, AT91_RTC_SECEV);
208 break; 211 break;
209 case RTC_IRQP_READ: /* read periodic alarm frequency */
210 ret = put_user(AT91_RTC_FREQ, (unsigned long *) arg);
211 break;
212 case RTC_IRQP_SET: /* set periodic alarm frequency */
213 if (arg != AT91_RTC_FREQ)
214 ret = -EINVAL;
215 break;
216 default: 212 default:
217 ret = -ENOIOCTLCMD; 213 ret = -ENOIOCTLCMD;
218 break; 214 break;
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index d7bb9bac71df..6ea349aba3ba 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -36,25 +36,9 @@
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37#include <linux/mod_devicetable.h> 37#include <linux/mod_devicetable.h>
38 38
39#ifdef CONFIG_HPET_EMULATE_RTC
40#include <asm/hpet.h>
41#endif
42
43/* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ 39/* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */
44#include <asm-generic/rtc.h> 40#include <asm-generic/rtc.h>
45 41
46#ifndef CONFIG_HPET_EMULATE_RTC
47#define is_hpet_enabled() 0
48#define hpet_set_alarm_time(hrs, min, sec) do { } while (0)
49#define hpet_set_periodic_freq(arg) 0
50#define hpet_mask_rtc_irq_bit(arg) do { } while (0)
51#define hpet_set_rtc_irq_bit(arg) do { } while (0)
52#define hpet_rtc_timer_init() do { } while (0)
53#define hpet_register_irq_handler(h) 0
54#define hpet_unregister_irq_handler(h) do { } while (0)
55extern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id);
56#endif
57
58struct cmos_rtc { 42struct cmos_rtc {
59 struct rtc_device *rtc; 43 struct rtc_device *rtc;
60 struct device *dev; 44 struct device *dev;
@@ -93,6 +77,72 @@ static inline int is_intr(u8 rtc_intr)
93 77
94/*----------------------------------------------------------------*/ 78/*----------------------------------------------------------------*/
95 79
80/* Much modern x86 hardware has HPETs (10+ MHz timers) which, because
81 * many BIOS programmers don't set up "sane mode" IRQ routing, are mostly
82 * used in a broken "legacy replacement" mode. The breakage includes
83 * HPET #1 hijacking the IRQ for this RTC, and being unavailable for
84 * other (better) use.
85 *
86 * When that broken mode is in use, platform glue provides a partial
87 * emulation of hardware RTC IRQ facilities using HPET #1. We don't
88 * want to use HPET for anything except those IRQs though...
89 */
90#ifdef CONFIG_HPET_EMULATE_RTC
91#include <asm/hpet.h>
92#else
93
94static inline int is_hpet_enabled(void)
95{
96 return 0;
97}
98
99static inline int hpet_mask_rtc_irq_bit(unsigned long mask)
100{
101 return 0;
102}
103
104static inline int hpet_set_rtc_irq_bit(unsigned long mask)
105{
106 return 0;
107}
108
109static inline int
110hpet_set_alarm_time(unsigned char hrs, unsigned char min, unsigned char sec)
111{
112 return 0;
113}
114
115static inline int hpet_set_periodic_freq(unsigned long freq)
116{
117 return 0;
118}
119
120static inline int hpet_rtc_dropped_irq(void)
121{
122 return 0;
123}
124
125static inline int hpet_rtc_timer_init(void)
126{
127 return 0;
128}
129
130extern irq_handler_t hpet_rtc_interrupt;
131
132static inline int hpet_register_irq_handler(irq_handler_t handler)
133{
134 return 0;
135}
136
137static inline int hpet_unregister_irq_handler(irq_handler_t handler)
138{
139 return 0;
140}
141
142#endif
143
144/*----------------------------------------------------------------*/
145
96static int cmos_read_time(struct device *dev, struct rtc_time *t) 146static int cmos_read_time(struct device *dev, struct rtc_time *t)
97{ 147{
98 /* REVISIT: if the clock has a "century" register, use 148 /* REVISIT: if the clock has a "century" register, use
@@ -185,11 +235,56 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
185 return 0; 235 return 0;
186} 236}
187 237
238static void cmos_checkintr(struct cmos_rtc *cmos, unsigned char rtc_control)
239{
240 unsigned char rtc_intr;
241
242 /* NOTE after changing RTC_xIE bits we always read INTR_FLAGS;
243 * allegedly some older rtcs need that to handle irqs properly
244 */
245 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
246
247 if (is_hpet_enabled())
248 return;
249
250 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
251 if (is_intr(rtc_intr))
252 rtc_update_irq(cmos->rtc, 1, rtc_intr);
253}
254
255static void cmos_irq_enable(struct cmos_rtc *cmos, unsigned char mask)
256{
257 unsigned char rtc_control;
258
259 /* flush any pending IRQ status, notably for update irqs,
260 * before we enable new IRQs
261 */
262 rtc_control = CMOS_READ(RTC_CONTROL);
263 cmos_checkintr(cmos, rtc_control);
264
265 rtc_control |= mask;
266 CMOS_WRITE(rtc_control, RTC_CONTROL);
267 hpet_set_rtc_irq_bit(mask);
268
269 cmos_checkintr(cmos, rtc_control);
270}
271
272static void cmos_irq_disable(struct cmos_rtc *cmos, unsigned char mask)
273{
274 unsigned char rtc_control;
275
276 rtc_control = CMOS_READ(RTC_CONTROL);
277 rtc_control &= ~mask;
278 CMOS_WRITE(rtc_control, RTC_CONTROL);
279 hpet_mask_rtc_irq_bit(mask);
280
281 cmos_checkintr(cmos, rtc_control);
282}
283
188static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) 284static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
189{ 285{
190 struct cmos_rtc *cmos = dev_get_drvdata(dev); 286 struct cmos_rtc *cmos = dev_get_drvdata(dev);
191 unsigned char mon, mday, hrs, min, sec; 287 unsigned char mon, mday, hrs, min, sec;
192 unsigned char rtc_control, rtc_intr;
193 288
194 if (!is_valid_irq(cmos->irq)) 289 if (!is_valid_irq(cmos->irq))
195 return -EIO; 290 return -EIO;
@@ -213,17 +308,10 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
213 sec = t->time.tm_sec; 308 sec = t->time.tm_sec;
214 sec = (sec < 60) ? BIN2BCD(sec) : 0xff; 309 sec = (sec < 60) ? BIN2BCD(sec) : 0xff;
215 310
216 hpet_set_alarm_time(t->time.tm_hour, t->time.tm_min, t->time.tm_sec);
217 spin_lock_irq(&rtc_lock); 311 spin_lock_irq(&rtc_lock);
218 312
219 /* next rtc irq must not be from previous alarm setting */ 313 /* next rtc irq must not be from previous alarm setting */
220 rtc_control = CMOS_READ(RTC_CONTROL); 314 cmos_irq_disable(cmos, RTC_AIE);
221 rtc_control &= ~RTC_AIE;
222 CMOS_WRITE(rtc_control, RTC_CONTROL);
223 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
224 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
225 if (is_intr(rtc_intr))
226 rtc_update_irq(cmos->rtc, 1, rtc_intr);
227 315
228 /* update alarm */ 316 /* update alarm */
229 CMOS_WRITE(hrs, RTC_HOURS_ALARM); 317 CMOS_WRITE(hrs, RTC_HOURS_ALARM);
@@ -237,14 +325,13 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
237 CMOS_WRITE(mon, cmos->mon_alrm); 325 CMOS_WRITE(mon, cmos->mon_alrm);
238 } 326 }
239 327
240 if (t->enabled) { 328 /* FIXME the HPET alarm glue currently ignores day_alrm
241 rtc_control |= RTC_AIE; 329 * and mon_alrm ...
242 CMOS_WRITE(rtc_control, RTC_CONTROL); 330 */
243 rtc_intr = CMOS_READ(RTC_INTR_FLAGS); 331 hpet_set_alarm_time(t->time.tm_hour, t->time.tm_min, t->time.tm_sec);
244 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; 332
245 if (is_intr(rtc_intr)) 333 if (t->enabled)
246 rtc_update_irq(cmos->rtc, 1, rtc_intr); 334 cmos_irq_enable(cmos, RTC_AIE);
247 }
248 335
249 spin_unlock_irq(&rtc_lock); 336 spin_unlock_irq(&rtc_lock);
250 337
@@ -267,8 +354,8 @@ static int cmos_irq_set_freq(struct device *dev, int freq)
267 f = 16 - f; 354 f = 16 - f;
268 355
269 spin_lock_irqsave(&rtc_lock, flags); 356 spin_lock_irqsave(&rtc_lock, flags);
270 if (!hpet_set_periodic_freq(freq)) 357 hpet_set_periodic_freq(freq);
271 CMOS_WRITE(RTC_REF_CLCK_32KHZ | f, RTC_FREQ_SELECT); 358 CMOS_WRITE(RTC_REF_CLCK_32KHZ | f, RTC_FREQ_SELECT);
272 spin_unlock_irqrestore(&rtc_lock, flags); 359 spin_unlock_irqrestore(&rtc_lock, flags);
273 360
274 return 0; 361 return 0;
@@ -277,26 +364,17 @@ static int cmos_irq_set_freq(struct device *dev, int freq)
277static int cmos_irq_set_state(struct device *dev, int enabled) 364static int cmos_irq_set_state(struct device *dev, int enabled)
278{ 365{
279 struct cmos_rtc *cmos = dev_get_drvdata(dev); 366 struct cmos_rtc *cmos = dev_get_drvdata(dev);
280 unsigned char rtc_control, rtc_intr;
281 unsigned long flags; 367 unsigned long flags;
282 368
283 if (!is_valid_irq(cmos->irq)) 369 if (!is_valid_irq(cmos->irq))
284 return -ENXIO; 370 return -ENXIO;
285 371
286 spin_lock_irqsave(&rtc_lock, flags); 372 spin_lock_irqsave(&rtc_lock, flags);
287 rtc_control = CMOS_READ(RTC_CONTROL);
288 373
289 if (enabled) 374 if (enabled)
290 rtc_control |= RTC_PIE; 375 cmos_irq_enable(cmos, RTC_PIE);
291 else 376 else
292 rtc_control &= ~RTC_PIE; 377 cmos_irq_disable(cmos, RTC_PIE);
293
294 CMOS_WRITE(rtc_control, RTC_CONTROL);
295
296 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
297 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
298 if (is_intr(rtc_intr))
299 rtc_update_irq(cmos->rtc, 1, rtc_intr);
300 378
301 spin_unlock_irqrestore(&rtc_lock, flags); 379 spin_unlock_irqrestore(&rtc_lock, flags);
302 return 0; 380 return 0;
@@ -308,7 +386,6 @@ static int
308cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 386cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
309{ 387{
310 struct cmos_rtc *cmos = dev_get_drvdata(dev); 388 struct cmos_rtc *cmos = dev_get_drvdata(dev);
311 unsigned char rtc_control, rtc_intr;
312 unsigned long flags; 389 unsigned long flags;
313 390
314 switch (cmd) { 391 switch (cmd) {
@@ -316,51 +393,29 @@ cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
316 case RTC_AIE_ON: 393 case RTC_AIE_ON:
317 case RTC_UIE_OFF: 394 case RTC_UIE_OFF:
318 case RTC_UIE_ON: 395 case RTC_UIE_ON:
319 case RTC_PIE_OFF:
320 case RTC_PIE_ON:
321 if (!is_valid_irq(cmos->irq)) 396 if (!is_valid_irq(cmos->irq))
322 return -EINVAL; 397 return -EINVAL;
323 break; 398 break;
399 /* PIE ON/OFF is handled by cmos_irq_set_state() */
324 default: 400 default:
325 return -ENOIOCTLCMD; 401 return -ENOIOCTLCMD;
326 } 402 }
327 403
328 spin_lock_irqsave(&rtc_lock, flags); 404 spin_lock_irqsave(&rtc_lock, flags);
329 rtc_control = CMOS_READ(RTC_CONTROL);
330 switch (cmd) { 405 switch (cmd) {
331 case RTC_AIE_OFF: /* alarm off */ 406 case RTC_AIE_OFF: /* alarm off */
332 rtc_control &= ~RTC_AIE; 407 cmos_irq_disable(cmos, RTC_AIE);
333 hpet_mask_rtc_irq_bit(RTC_AIE);
334 break; 408 break;
335 case RTC_AIE_ON: /* alarm on */ 409 case RTC_AIE_ON: /* alarm on */
336 rtc_control |= RTC_AIE; 410 cmos_irq_enable(cmos, RTC_AIE);
337 hpet_set_rtc_irq_bit(RTC_AIE);
338 break; 411 break;
339 case RTC_UIE_OFF: /* update off */ 412 case RTC_UIE_OFF: /* update off */
340 rtc_control &= ~RTC_UIE; 413 cmos_irq_disable(cmos, RTC_UIE);
341 hpet_mask_rtc_irq_bit(RTC_UIE);
342 break; 414 break;
343 case RTC_UIE_ON: /* update on */ 415 case RTC_UIE_ON: /* update on */
344 rtc_control |= RTC_UIE; 416 cmos_irq_enable(cmos, RTC_UIE);
345 hpet_set_rtc_irq_bit(RTC_UIE);
346 break;
347 case RTC_PIE_OFF: /* periodic off */
348 rtc_control &= ~RTC_PIE;
349 hpet_mask_rtc_irq_bit(RTC_PIE);
350 break;
351 case RTC_PIE_ON: /* periodic on */
352 rtc_control |= RTC_PIE;
353 hpet_set_rtc_irq_bit(RTC_PIE);
354 break; 417 break;
355 } 418 }
356 if (!is_hpet_enabled())
357 CMOS_WRITE(rtc_control, RTC_CONTROL);
358
359 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
360 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
361 if (is_intr(rtc_intr))
362 rtc_update_irq(cmos->rtc, 1, rtc_intr);
363
364 spin_unlock_irqrestore(&rtc_lock, flags); 419 spin_unlock_irqrestore(&rtc_lock, flags);
365 return 0; 420 return 0;
366} 421}
@@ -502,27 +557,29 @@ static irqreturn_t cmos_interrupt(int irq, void *p)
502 u8 rtc_control; 557 u8 rtc_control;
503 558
504 spin_lock(&rtc_lock); 559 spin_lock(&rtc_lock);
505 /* 560
506 * In this case it is HPET RTC interrupt handler 561 /* When the HPET interrupt handler calls us, the interrupt
507 * calling us, with the interrupt information 562 * status is passed as arg1 instead of the irq number. But
508 * passed as arg1, instead of irq. 563 * always clear irq status, even when HPET is in the way.
564 *
565 * Note that HPET and RTC are almost certainly out of phase,
566 * giving different IRQ status ...
509 */ 567 */
568 irqstat = CMOS_READ(RTC_INTR_FLAGS);
569 rtc_control = CMOS_READ(RTC_CONTROL);
510 if (is_hpet_enabled()) 570 if (is_hpet_enabled())
511 irqstat = (unsigned long)irq & 0xF0; 571 irqstat = (unsigned long)irq & 0xF0;
512 else { 572 irqstat &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
513 irqstat = CMOS_READ(RTC_INTR_FLAGS);
514 rtc_control = CMOS_READ(RTC_CONTROL);
515 irqstat &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
516 }
517 573
518 /* All Linux RTC alarms should be treated as if they were oneshot. 574 /* All Linux RTC alarms should be treated as if they were oneshot.
519 * Similar code may be needed in system wakeup paths, in case the 575 * Similar code may be needed in system wakeup paths, in case the
520 * alarm woke the system. 576 * alarm woke the system.
521 */ 577 */
522 if (irqstat & RTC_AIE) { 578 if (irqstat & RTC_AIE) {
523 rtc_control = CMOS_READ(RTC_CONTROL);
524 rtc_control &= ~RTC_AIE; 579 rtc_control &= ~RTC_AIE;
525 CMOS_WRITE(rtc_control, RTC_CONTROL); 580 CMOS_WRITE(rtc_control, RTC_CONTROL);
581 hpet_mask_rtc_irq_bit(RTC_AIE);
582
526 CMOS_READ(RTC_INTR_FLAGS); 583 CMOS_READ(RTC_INTR_FLAGS);
527 } 584 }
528 spin_unlock(&rtc_lock); 585 spin_unlock(&rtc_lock);
@@ -629,18 +686,13 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
629 * do something about other clock frequencies. 686 * do something about other clock frequencies.
630 */ 687 */
631 cmos_rtc.rtc->irq_freq = 1024; 688 cmos_rtc.rtc->irq_freq = 1024;
632 if (!hpet_set_periodic_freq(cmos_rtc.rtc->irq_freq)) 689 hpet_set_periodic_freq(cmos_rtc.rtc->irq_freq);
633 CMOS_WRITE(RTC_REF_CLCK_32KHZ | 0x06, RTC_FREQ_SELECT); 690 CMOS_WRITE(RTC_REF_CLCK_32KHZ | 0x06, RTC_FREQ_SELECT);
691
692 /* disable irqs */
693 cmos_irq_disable(&cmos_rtc, RTC_PIE | RTC_AIE | RTC_UIE);
634 694
635 /* disable irqs.
636 *
637 * NOTE after changing RTC_xIE bits we always read INTR_FLAGS;
638 * allegedly some older rtcs need that to handle irqs properly
639 */
640 rtc_control = CMOS_READ(RTC_CONTROL); 695 rtc_control = CMOS_READ(RTC_CONTROL);
641 rtc_control &= ~(RTC_PIE | RTC_AIE | RTC_UIE);
642 CMOS_WRITE(rtc_control, RTC_CONTROL);
643 CMOS_READ(RTC_INTR_FLAGS);
644 696
645 spin_unlock_irq(&rtc_lock); 697 spin_unlock_irq(&rtc_lock);
646 698
@@ -687,7 +739,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
687 goto cleanup2; 739 goto cleanup2;
688 } 740 }
689 741
690 pr_info("%s: alarms up to one %s%s\n", 742 pr_info("%s: alarms up to one %s%s%s\n",
691 cmos_rtc.rtc->dev.bus_id, 743 cmos_rtc.rtc->dev.bus_id,
692 is_valid_irq(rtc_irq) 744 is_valid_irq(rtc_irq)
693 ? (cmos_rtc.mon_alrm 745 ? (cmos_rtc.mon_alrm
@@ -695,8 +747,8 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
695 : (cmos_rtc.day_alrm 747 : (cmos_rtc.day_alrm
696 ? "month" : "day")) 748 ? "month" : "day"))
697 : "no", 749 : "no",
698 cmos_rtc.century ? ", y3k" : "" 750 cmos_rtc.century ? ", y3k" : "",
699 ); 751 is_hpet_enabled() ? ", hpet irqs" : "");
700 752
701 return 0; 753 return 0;
702 754
@@ -713,13 +765,8 @@ cleanup0:
713 765
714static void cmos_do_shutdown(void) 766static void cmos_do_shutdown(void)
715{ 767{
716 unsigned char rtc_control;
717
718 spin_lock_irq(&rtc_lock); 768 spin_lock_irq(&rtc_lock);
719 rtc_control = CMOS_READ(RTC_CONTROL); 769 cmos_irq_disable(&cmos_rtc, RTC_IRQMASK);
720 rtc_control &= ~(RTC_PIE|RTC_AIE|RTC_UIE);
721 CMOS_WRITE(rtc_control, RTC_CONTROL);
722 CMOS_READ(RTC_INTR_FLAGS);
723 spin_unlock_irq(&rtc_lock); 770 spin_unlock_irq(&rtc_lock);
724} 771}
725 772
@@ -760,17 +807,17 @@ static int cmos_suspend(struct device *dev, pm_message_t mesg)
760 spin_lock_irq(&rtc_lock); 807 spin_lock_irq(&rtc_lock);
761 cmos->suspend_ctrl = tmp = CMOS_READ(RTC_CONTROL); 808 cmos->suspend_ctrl = tmp = CMOS_READ(RTC_CONTROL);
762 if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) { 809 if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) {
763 unsigned char irqstat; 810 unsigned char mask;
764 811
765 if (do_wake) 812 if (do_wake)
766 tmp &= ~(RTC_PIE|RTC_UIE); 813 mask = RTC_IRQMASK & ~RTC_AIE;
767 else 814 else
768 tmp &= ~(RTC_PIE|RTC_AIE|RTC_UIE); 815 mask = RTC_IRQMASK;
816 tmp &= ~mask;
769 CMOS_WRITE(tmp, RTC_CONTROL); 817 CMOS_WRITE(tmp, RTC_CONTROL);
770 irqstat = CMOS_READ(RTC_INTR_FLAGS); 818 hpet_mask_rtc_irq_bit(mask);
771 irqstat &= (tmp & RTC_IRQMASK) | RTC_IRQF; 819
772 if (is_intr(irqstat)) 820 cmos_checkintr(cmos, tmp);
773 rtc_update_irq(cmos->rtc, 1, irqstat);
774 } 821 }
775 spin_unlock_irq(&rtc_lock); 822 spin_unlock_irq(&rtc_lock);
776 823
@@ -796,7 +843,8 @@ static int cmos_resume(struct device *dev)
796 unsigned char tmp = cmos->suspend_ctrl; 843 unsigned char tmp = cmos->suspend_ctrl;
797 844
798 /* re-enable any irqs previously active */ 845 /* re-enable any irqs previously active */
799 if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) { 846 if (tmp & RTC_IRQMASK) {
847 unsigned char mask;
800 848
801 if (cmos->enabled_wake) { 849 if (cmos->enabled_wake) {
802 if (cmos->wake_off) 850 if (cmos->wake_off)
@@ -807,18 +855,28 @@ static int cmos_resume(struct device *dev)
807 } 855 }
808 856
809 spin_lock_irq(&rtc_lock); 857 spin_lock_irq(&rtc_lock);
810 CMOS_WRITE(tmp, RTC_CONTROL); 858 do {
811 tmp = CMOS_READ(RTC_INTR_FLAGS); 859 CMOS_WRITE(tmp, RTC_CONTROL);
812 tmp &= (cmos->suspend_ctrl & RTC_IRQMASK) | RTC_IRQF; 860 hpet_set_rtc_irq_bit(tmp & RTC_IRQMASK);
813 if (is_intr(tmp)) 861
814 rtc_update_irq(cmos->rtc, 1, tmp); 862 mask = CMOS_READ(RTC_INTR_FLAGS);
863 mask &= (tmp & RTC_IRQMASK) | RTC_IRQF;
864 if (!is_hpet_enabled() || !is_intr(mask))
865 break;
866
867 /* force one-shot behavior if HPET blocked
868 * the wake alarm's irq
869 */
870 rtc_update_irq(cmos->rtc, 1, mask);
871 tmp &= ~RTC_AIE;
872 hpet_mask_rtc_irq_bit(RTC_AIE);
873 } while (mask & RTC_AIE);
815 spin_unlock_irq(&rtc_lock); 874 spin_unlock_irq(&rtc_lock);
816 } 875 }
817 876
818 pr_debug("%s: resume, ctrl %02x\n", 877 pr_debug("%s: resume, ctrl %02x\n",
819 cmos_rtc.rtc->dev.bus_id, 878 cmos_rtc.rtc->dev.bus_id,
820 cmos->suspend_ctrl); 879 tmp);
821
822 880
823 return 0; 881 return 0;
824} 882}
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index 0114a78b7cbb..0a870b7e5c32 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -209,7 +209,7 @@ static unsigned int rtc_dev_poll(struct file *file, poll_table *wait)
209 return (data != 0) ? (POLLIN | POLLRDNORM) : 0; 209 return (data != 0) ? (POLLIN | POLLRDNORM) : 0;
210} 210}
211 211
212static int rtc_dev_ioctl(struct inode *inode, struct file *file, 212static long rtc_dev_ioctl(struct file *file,
213 unsigned int cmd, unsigned long arg) 213 unsigned int cmd, unsigned long arg)
214{ 214{
215 int err = 0; 215 int err = 0;
@@ -219,6 +219,10 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
219 struct rtc_wkalrm alarm; 219 struct rtc_wkalrm alarm;
220 void __user *uarg = (void __user *) arg; 220 void __user *uarg = (void __user *) arg;
221 221
222 err = mutex_lock_interruptible(&rtc->ops_lock);
223 if (err)
224 return -EBUSY;
225
222 /* check that the calling task has appropriate permissions 226 /* check that the calling task has appropriate permissions
223 * for certain ioctls. doing this check here is useful 227 * for certain ioctls. doing this check here is useful
224 * to avoid duplicate code in each driver. 228 * to avoid duplicate code in each driver.
@@ -227,26 +231,31 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
227 case RTC_EPOCH_SET: 231 case RTC_EPOCH_SET:
228 case RTC_SET_TIME: 232 case RTC_SET_TIME:
229 if (!capable(CAP_SYS_TIME)) 233 if (!capable(CAP_SYS_TIME))
230 return -EACCES; 234 err = -EACCES;
231 break; 235 break;
232 236
233 case RTC_IRQP_SET: 237 case RTC_IRQP_SET:
234 if (arg > rtc->max_user_freq && !capable(CAP_SYS_RESOURCE)) 238 if (arg > rtc->max_user_freq && !capable(CAP_SYS_RESOURCE))
235 return -EACCES; 239 err = -EACCES;
236 break; 240 break;
237 241
238 case RTC_PIE_ON: 242 case RTC_PIE_ON:
239 if (rtc->irq_freq > rtc->max_user_freq && 243 if (rtc->irq_freq > rtc->max_user_freq &&
240 !capable(CAP_SYS_RESOURCE)) 244 !capable(CAP_SYS_RESOURCE))
241 return -EACCES; 245 err = -EACCES;
242 break; 246 break;
243 } 247 }
244 248
249 if (err)
250 goto done;
251
245 /* try the driver's ioctl interface */ 252 /* try the driver's ioctl interface */
246 if (ops->ioctl) { 253 if (ops->ioctl) {
247 err = ops->ioctl(rtc->dev.parent, cmd, arg); 254 err = ops->ioctl(rtc->dev.parent, cmd, arg);
248 if (err != -ENOIOCTLCMD) 255 if (err != -ENOIOCTLCMD) {
256 mutex_unlock(&rtc->ops_lock);
249 return err; 257 return err;
258 }
250 } 259 }
251 260
252 /* if the driver does not provide the ioctl interface 261 /* if the driver does not provide the ioctl interface
@@ -265,15 +274,19 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
265 274
266 switch (cmd) { 275 switch (cmd) {
267 case RTC_ALM_READ: 276 case RTC_ALM_READ:
277 mutex_unlock(&rtc->ops_lock);
278
268 err = rtc_read_alarm(rtc, &alarm); 279 err = rtc_read_alarm(rtc, &alarm);
269 if (err < 0) 280 if (err < 0)
270 return err; 281 return err;
271 282
272 if (copy_to_user(uarg, &alarm.time, sizeof(tm))) 283 if (copy_to_user(uarg, &alarm.time, sizeof(tm)))
273 return -EFAULT; 284 err = -EFAULT;
274 break; 285 return err;
275 286
276 case RTC_ALM_SET: 287 case RTC_ALM_SET:
288 mutex_unlock(&rtc->ops_lock);
289
277 if (copy_from_user(&alarm.time, uarg, sizeof(tm))) 290 if (copy_from_user(&alarm.time, uarg, sizeof(tm)))
278 return -EFAULT; 291 return -EFAULT;
279 292
@@ -321,24 +334,26 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
321 } 334 }
322 } 335 }
323 336
324 err = rtc_set_alarm(rtc, &alarm); 337 return rtc_set_alarm(rtc, &alarm);
325 break;
326 338
327 case RTC_RD_TIME: 339 case RTC_RD_TIME:
340 mutex_unlock(&rtc->ops_lock);
341
328 err = rtc_read_time(rtc, &tm); 342 err = rtc_read_time(rtc, &tm);
329 if (err < 0) 343 if (err < 0)
330 return err; 344 return err;
331 345
332 if (copy_to_user(uarg, &tm, sizeof(tm))) 346 if (copy_to_user(uarg, &tm, sizeof(tm)))
333 return -EFAULT; 347 err = -EFAULT;
334 break; 348 return err;
335 349
336 case RTC_SET_TIME: 350 case RTC_SET_TIME:
351 mutex_unlock(&rtc->ops_lock);
352
337 if (copy_from_user(&tm, uarg, sizeof(tm))) 353 if (copy_from_user(&tm, uarg, sizeof(tm)))
338 return -EFAULT; 354 return -EFAULT;
339 355
340 err = rtc_set_time(rtc, &tm); 356 return rtc_set_time(rtc, &tm);
341 break;
342 357
343 case RTC_PIE_ON: 358 case RTC_PIE_ON:
344 err = rtc_irq_set_state(rtc, NULL, 1); 359 err = rtc_irq_set_state(rtc, NULL, 1);
@@ -376,34 +391,37 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
376 break; 391 break;
377#endif 392#endif
378 case RTC_WKALM_SET: 393 case RTC_WKALM_SET:
394 mutex_unlock(&rtc->ops_lock);
379 if (copy_from_user(&alarm, uarg, sizeof(alarm))) 395 if (copy_from_user(&alarm, uarg, sizeof(alarm)))
380 return -EFAULT; 396 return -EFAULT;
381 397
382 err = rtc_set_alarm(rtc, &alarm); 398 return rtc_set_alarm(rtc, &alarm);
383 break;
384 399
385 case RTC_WKALM_RD: 400 case RTC_WKALM_RD:
401 mutex_unlock(&rtc->ops_lock);
386 err = rtc_read_alarm(rtc, &alarm); 402 err = rtc_read_alarm(rtc, &alarm);
387 if (err < 0) 403 if (err < 0)
388 return err; 404 return err;
389 405
390 if (copy_to_user(uarg, &alarm, sizeof(alarm))) 406 if (copy_to_user(uarg, &alarm, sizeof(alarm)))
391 return -EFAULT; 407 err = -EFAULT;
392 break; 408 return err;
393 409
394#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 410#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
395 case RTC_UIE_OFF: 411 case RTC_UIE_OFF:
396 clear_uie(rtc); 412 clear_uie(rtc);
397 return 0; 413 break;
398 414
399 case RTC_UIE_ON: 415 case RTC_UIE_ON:
400 return set_uie(rtc); 416 err = set_uie(rtc);
401#endif 417#endif
402 default: 418 default:
403 err = -ENOTTY; 419 err = -ENOTTY;
404 break; 420 break;
405 } 421 }
406 422
423done:
424 mutex_unlock(&rtc->ops_lock);
407 return err; 425 return err;
408} 426}
409 427
@@ -432,7 +450,7 @@ static const struct file_operations rtc_dev_fops = {
432 .llseek = no_llseek, 450 .llseek = no_llseek,
433 .read = rtc_dev_read, 451 .read = rtc_dev_read,
434 .poll = rtc_dev_poll, 452 .poll = rtc_dev_poll,
435 .ioctl = rtc_dev_ioctl, 453 .unlocked_ioctl = rtc_dev_ioctl,
436 .open = rtc_dev_open, 454 .open = rtc_dev_open,
437 .release = rtc_dev_release, 455 .release = rtc_dev_release,
438 .fasync = rtc_dev_fasync, 456 .fasync = rtc_dev_fasync,
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
new file mode 100644
index 000000000000..b91d02a3ace9
--- /dev/null
+++ b/drivers/rtc/rtc-ds1305.c
@@ -0,0 +1,847 @@
1/*
2 * rtc-ds1305.c -- driver for DS1305 and DS1306 SPI RTC chips
3 *
4 * Copyright (C) 2008 David Brownell
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/bcd.h>
14#include <linux/rtc.h>
15#include <linux/workqueue.h>
16
17#include <linux/spi/spi.h>
18#include <linux/spi/ds1305.h>
19
20
21/*
22 * Registers ... mask DS1305_WRITE into register address to write,
23 * otherwise you're reading it. All non-bitmask values are BCD.
24 */
25#define DS1305_WRITE 0x80
26
27
28/* RTC date/time ... the main special cases are that we:
29 * - Need fancy "hours" encoding in 12hour mode
30 * - Don't rely on the "day-of-week" field (or tm_wday)
31 * - Are a 21st-century clock (2000 <= year < 2100)
32 */
33#define DS1305_RTC_LEN 7 /* bytes for RTC regs */
34
35#define DS1305_SEC 0x00 /* register addresses */
36#define DS1305_MIN 0x01
37#define DS1305_HOUR 0x02
38# define DS1305_HR_12 0x40 /* set == 12 hr mode */
39# define DS1305_HR_PM 0x20 /* set == PM (12hr mode) */
40#define DS1305_WDAY 0x03
41#define DS1305_MDAY 0x04
42#define DS1305_MON 0x05
43#define DS1305_YEAR 0x06
44
45
46/* The two alarms have only sec/min/hour/wday fields (ALM_LEN).
47 * DS1305_ALM_DISABLE disables a match field (some combos are bad).
48 *
49 * NOTE that since we don't use WDAY, we limit ourselves to alarms
50 * only one day into the future (vs potentially up to a week).
51 *
52 * NOTE ALSO that while we could generate once-a-second IRQs (UIE), we
53 * don't currently support them. We'd either need to do it only when
54 * no alarm is pending (not the standard model), or to use the second
55 * alarm (implying that this is a DS1305 not DS1306, *and* that either
56 * it's wired up a second IRQ we know, or that INTCN is set)
57 */
58#define DS1305_ALM_LEN 4 /* bytes for ALM regs */
59#define DS1305_ALM_DISABLE 0x80
60
61#define DS1305_ALM0(r) (0x07 + (r)) /* register addresses */
62#define DS1305_ALM1(r) (0x0b + (r))
63
64
65/* three control registers */
66#define DS1305_CONTROL_LEN 3 /* bytes of control regs */
67
68#define DS1305_CONTROL 0x0f /* register addresses */
69# define DS1305_nEOSC 0x80 /* low enables oscillator */
70# define DS1305_WP 0x40 /* write protect */
71# define DS1305_INTCN 0x04 /* clear == only int0 used */
72# define DS1306_1HZ 0x04 /* enable 1Hz output */
73# define DS1305_AEI1 0x02 /* enable ALM1 IRQ */
74# define DS1305_AEI0 0x01 /* enable ALM0 IRQ */
75#define DS1305_STATUS 0x10
76/* status has just AEIx bits, mirrored as IRQFx */
77#define DS1305_TRICKLE 0x11
78/* trickle bits are defined in <linux/spi/ds1305.h> */
79
80/* a bunch of NVRAM */
81#define DS1305_NVRAM_LEN 96 /* bytes of NVRAM */
82
83#define DS1305_NVRAM 0x20 /* register addresses */
84
85
86struct ds1305 {
87 struct spi_device *spi;
88 struct rtc_device *rtc;
89
90 struct work_struct work;
91
92 unsigned long flags;
93#define FLAG_EXITING 0
94
95 bool hr12;
96 u8 ctrl[DS1305_CONTROL_LEN];
97};
98
99
100/*----------------------------------------------------------------------*/
101
102/*
103 * Utilities ... tolerate 12-hour AM/PM notation in case of non-Linux
104 * software (like a bootloader) which may require it.
105 */
106
107static unsigned bcd2hour(u8 bcd)
108{
109 if (bcd & DS1305_HR_12) {
110 unsigned hour = 0;
111
112 bcd &= ~DS1305_HR_12;
113 if (bcd & DS1305_HR_PM) {
114 hour = 12;
115 bcd &= ~DS1305_HR_PM;
116 }
117 hour += BCD2BIN(bcd);
118 return hour - 1;
119 }
120 return BCD2BIN(bcd);
121}
122
123static u8 hour2bcd(bool hr12, int hour)
124{
125 if (hr12) {
126 hour++;
127 if (hour <= 12)
128 return DS1305_HR_12 | BIN2BCD(hour);
129 hour -= 12;
130 return DS1305_HR_12 | DS1305_HR_PM | BIN2BCD(hour);
131 }
132 return BIN2BCD(hour);
133}
134
135/*----------------------------------------------------------------------*/
136
137/*
138 * Interface to RTC framework
139 */
140
141#ifdef CONFIG_RTC_INTF_DEV
142
143/*
144 * Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
145 */
146static int ds1305_ioctl(struct device *dev, unsigned cmd, unsigned long arg)
147{
148 struct ds1305 *ds1305 = dev_get_drvdata(dev);
149 u8 buf[2];
150 int status = -ENOIOCTLCMD;
151
152 buf[0] = DS1305_WRITE | DS1305_CONTROL;
153 buf[1] = ds1305->ctrl[0];
154
155 switch (cmd) {
156 case RTC_AIE_OFF:
157 status = 0;
158 if (!(buf[1] & DS1305_AEI0))
159 goto done;
160 buf[1] &= ~DS1305_AEI0;
161 break;
162
163 case RTC_AIE_ON:
164 status = 0;
165 if (ds1305->ctrl[0] & DS1305_AEI0)
166 goto done;
167 buf[1] |= DS1305_AEI0;
168 break;
169 }
170 if (status == 0) {
171 status = spi_write_then_read(ds1305->spi, buf, sizeof buf,
172 NULL, 0);
173 if (status >= 0)
174 ds1305->ctrl[0] = buf[1];
175 }
176
177done:
178 return status;
179}
180
181#else
182#define ds1305_ioctl NULL
183#endif
184
185/*
186 * Get/set of date and time is pretty normal.
187 */
188
189static int ds1305_get_time(struct device *dev, struct rtc_time *time)
190{
191 struct ds1305 *ds1305 = dev_get_drvdata(dev);
192 u8 addr = DS1305_SEC;
193 u8 buf[DS1305_RTC_LEN];
194 int status;
195
196 /* Use write-then-read to get all the date/time registers
197 * since dma from stack is nonportable
198 */
199 status = spi_write_then_read(ds1305->spi, &addr, sizeof addr,
200 buf, sizeof buf);
201 if (status < 0)
202 return status;
203
204 dev_vdbg(dev, "%s: %02x %02x %02x, %02x %02x %02x %02x\n",
205 "read", buf[0], buf[1], buf[2], buf[3],
206 buf[4], buf[5], buf[6]);
207
208 /* Decode the registers */
209 time->tm_sec = BCD2BIN(buf[DS1305_SEC]);
210 time->tm_min = BCD2BIN(buf[DS1305_MIN]);
211 time->tm_hour = bcd2hour(buf[DS1305_HOUR]);
212 time->tm_wday = buf[DS1305_WDAY] - 1;
213 time->tm_mday = BCD2BIN(buf[DS1305_MDAY]);
214 time->tm_mon = BCD2BIN(buf[DS1305_MON]) - 1;
215 time->tm_year = BCD2BIN(buf[DS1305_YEAR]) + 100;
216
217 dev_vdbg(dev, "%s secs=%d, mins=%d, "
218 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
219 "read", time->tm_sec, time->tm_min,
220 time->tm_hour, time->tm_mday,
221 time->tm_mon, time->tm_year, time->tm_wday);
222
223 /* Time may not be set */
224 return rtc_valid_tm(time);
225}
226
227static int ds1305_set_time(struct device *dev, struct rtc_time *time)
228{
229 struct ds1305 *ds1305 = dev_get_drvdata(dev);
230 u8 buf[1 + DS1305_RTC_LEN];
231 u8 *bp = buf;
232
233 dev_vdbg(dev, "%s secs=%d, mins=%d, "
234 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
235 "write", time->tm_sec, time->tm_min,
236 time->tm_hour, time->tm_mday,
237 time->tm_mon, time->tm_year, time->tm_wday);
238
239 /* Write registers starting at the first time/date address. */
240 *bp++ = DS1305_WRITE | DS1305_SEC;
241
242 *bp++ = BIN2BCD(time->tm_sec);
243 *bp++ = BIN2BCD(time->tm_min);
244 *bp++ = hour2bcd(ds1305->hr12, time->tm_hour);
245 *bp++ = (time->tm_wday < 7) ? (time->tm_wday + 1) : 1;
246 *bp++ = BIN2BCD(time->tm_mday);
247 *bp++ = BIN2BCD(time->tm_mon + 1);
248 *bp++ = BIN2BCD(time->tm_year - 100);
249
250 dev_dbg(dev, "%s: %02x %02x %02x, %02x %02x %02x %02x\n",
251 "write", buf[1], buf[2], buf[3],
252 buf[4], buf[5], buf[6], buf[7]);
253
254 /* use write-then-read since dma from stack is nonportable */
255 return spi_write_then_read(ds1305->spi, buf, sizeof buf,
256 NULL, 0);
257}
258
259/*
260 * Get/set of alarm is a bit funky:
261 *
262 * - First there's the inherent raciness of getting the (partitioned)
263 * status of an alarm that could trigger while we're reading parts
264 * of that status.
265 *
266 * - Second there's its limited range (we could increase it a bit by
267 * relying on WDAY), which means it will easily roll over.
268 *
269 * - Third there's the choice of two alarms and alarm signals.
270 * Here we use ALM0 and expect that nINT0 (open drain) is used;
271 * that's the only real option for DS1306 runtime alarms, and is
272 * natural on DS1305.
273 *
274 * - Fourth, there's also ALM1, and a second interrupt signal:
275 * + On DS1305 ALM1 uses nINT1 (when INTCN=1) else nINT0;
276 * + On DS1306 ALM1 only uses INT1 (an active high pulse)
277 * and it won't work when VCC1 is active.
278 *
279 * So to be most general, we should probably set both alarms to the
280 * same value, letting ALM1 be the wakeup event source on DS1306
281 * and handling several wiring options on DS1305.
282 *
283 * - Fifth, we support the polled mode (as well as possible; why not?)
284 * even when no interrupt line is wired to an IRQ.
285 */
286
287/*
288 * Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
289 */
290static int ds1305_get_alarm(struct device *dev, struct rtc_wkalrm *alm)
291{
292 struct ds1305 *ds1305 = dev_get_drvdata(dev);
293 struct spi_device *spi = ds1305->spi;
294 u8 addr;
295 int status;
296 u8 buf[DS1305_ALM_LEN];
297
298 /* Refresh control register cache BEFORE reading ALM0 registers,
299 * since reading alarm registers acks any pending IRQ. That
300 * makes returning "pending" status a bit of a lie, but that bit
301 * of EFI status is at best fragile anyway (given IRQ handlers).
302 */
303 addr = DS1305_CONTROL;
304 status = spi_write_then_read(spi, &addr, sizeof addr,
305 ds1305->ctrl, sizeof ds1305->ctrl);
306 if (status < 0)
307 return status;
308
309 alm->enabled = !!(ds1305->ctrl[0] & DS1305_AEI0);
310 alm->pending = !!(ds1305->ctrl[1] & DS1305_AEI0);
311
312 /* get and check ALM0 registers */
313 addr = DS1305_ALM0(DS1305_SEC);
314 status = spi_write_then_read(spi, &addr, sizeof addr,
315 buf, sizeof buf);
316 if (status < 0)
317 return status;
318
319 dev_vdbg(dev, "%s: %02x %02x %02x %02x\n",
320 "alm0 read", buf[DS1305_SEC], buf[DS1305_MIN],
321 buf[DS1305_HOUR], buf[DS1305_WDAY]);
322
323 if ((DS1305_ALM_DISABLE & buf[DS1305_SEC])
324 || (DS1305_ALM_DISABLE & buf[DS1305_MIN])
325 || (DS1305_ALM_DISABLE & buf[DS1305_HOUR]))
326 return -EIO;
327
328 /* Stuff these values into alm->time and let RTC framework code
329 * fill in the rest ... and also handle rollover to tomorrow when
330 * that's needed.
331 */
332 alm->time.tm_sec = BCD2BIN(buf[DS1305_SEC]);
333 alm->time.tm_min = BCD2BIN(buf[DS1305_MIN]);
334 alm->time.tm_hour = bcd2hour(buf[DS1305_HOUR]);
335 alm->time.tm_mday = -1;
336 alm->time.tm_mon = -1;
337 alm->time.tm_year = -1;
338 /* next three fields are unused by Linux */
339 alm->time.tm_wday = -1;
340 alm->time.tm_mday = -1;
341 alm->time.tm_isdst = -1;
342
343 return 0;
344}
345
346/*
347 * Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
348 */
349static int ds1305_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
350{
351 struct ds1305 *ds1305 = dev_get_drvdata(dev);
352 struct spi_device *spi = ds1305->spi;
353 unsigned long now, later;
354 struct rtc_time tm;
355 int status;
356 u8 buf[1 + DS1305_ALM_LEN];
357
358 /* convert desired alarm to time_t */
359 status = rtc_tm_to_time(&alm->time, &later);
360 if (status < 0)
361 return status;
362
363 /* Read current time as time_t */
364 status = ds1305_get_time(dev, &tm);
365 if (status < 0)
366 return status;
367 status = rtc_tm_to_time(&tm, &now);
368 if (status < 0)
369 return status;
370
371 /* make sure alarm fires within the next 24 hours */
372 if (later <= now)
373 return -EINVAL;
374 if ((later - now) > 24 * 60 * 60)
375 return -EDOM;
376
377 /* disable alarm if needed */
378 if (ds1305->ctrl[0] & DS1305_AEI0) {
379 ds1305->ctrl[0] &= ~DS1305_AEI0;
380
381 buf[0] = DS1305_WRITE | DS1305_CONTROL;
382 buf[1] = ds1305->ctrl[0];
383 status = spi_write_then_read(ds1305->spi, buf, 2, NULL, 0);
384 if (status < 0)
385 return status;
386 }
387
388 /* write alarm */
389 buf[0] = DS1305_WRITE | DS1305_ALM0(DS1305_SEC);
390 buf[1 + DS1305_SEC] = BIN2BCD(alm->time.tm_sec);
391 buf[1 + DS1305_MIN] = BIN2BCD(alm->time.tm_min);
392 buf[1 + DS1305_HOUR] = hour2bcd(ds1305->hr12, alm->time.tm_hour);
393 buf[1 + DS1305_WDAY] = DS1305_ALM_DISABLE;
394
395 dev_dbg(dev, "%s: %02x %02x %02x %02x\n",
396 "alm0 write", buf[1 + DS1305_SEC], buf[1 + DS1305_MIN],
397 buf[1 + DS1305_HOUR], buf[1 + DS1305_WDAY]);
398
399 status = spi_write_then_read(spi, buf, sizeof buf, NULL, 0);
400 if (status < 0)
401 return status;
402
403 /* enable alarm if requested */
404 if (alm->enabled) {
405 ds1305->ctrl[0] |= DS1305_AEI0;
406
407 buf[0] = DS1305_WRITE | DS1305_CONTROL;
408 buf[1] = ds1305->ctrl[0];
409 status = spi_write_then_read(ds1305->spi, buf, 2, NULL, 0);
410 }
411
412 return status;
413}
414
415#ifdef CONFIG_PROC_FS
416
417static int ds1305_proc(struct device *dev, struct seq_file *seq)
418{
419 struct ds1305 *ds1305 = dev_get_drvdata(dev);
420 char *diodes = "no";
421 char *resistors = "";
422
423 /* ctrl[2] is treated as read-only; no locking needed */
424 if ((ds1305->ctrl[2] & 0xf0) == DS1305_TRICKLE_MAGIC) {
425 switch (ds1305->ctrl[2] & 0x0c) {
426 case DS1305_TRICKLE_DS2:
427 diodes = "2 diodes, ";
428 break;
429 case DS1305_TRICKLE_DS1:
430 diodes = "1 diode, ";
431 break;
432 default:
433 goto done;
434 }
435 switch (ds1305->ctrl[2] & 0x03) {
436 case DS1305_TRICKLE_2K:
437 resistors = "2k Ohm";
438 break;
439 case DS1305_TRICKLE_4K:
440 resistors = "4k Ohm";
441 break;
442 case DS1305_TRICKLE_8K:
443 resistors = "8k Ohm";
444 break;
445 default:
446 diodes = "no";
447 break;
448 }
449 }
450
451done:
452 return seq_printf(seq,
453 "trickle_charge\t: %s%s\n",
454 diodes, resistors);
455}
456
457#else
458#define ds1305_proc NULL
459#endif
460
461static const struct rtc_class_ops ds1305_ops = {
462 .ioctl = ds1305_ioctl,
463 .read_time = ds1305_get_time,
464 .set_time = ds1305_set_time,
465 .read_alarm = ds1305_get_alarm,
466 .set_alarm = ds1305_set_alarm,
467 .proc = ds1305_proc,
468};
469
470static void ds1305_work(struct work_struct *work)
471{
472 struct ds1305 *ds1305 = container_of(work, struct ds1305, work);
473 struct mutex *lock = &ds1305->rtc->ops_lock;
474 struct spi_device *spi = ds1305->spi;
475 u8 buf[3];
476 int status;
477
478 /* lock to protect ds1305->ctrl */
479 mutex_lock(lock);
480
481 /* Disable the IRQ, and clear its status ... for now, we "know"
482 * that if more than one alarm is active, they're in sync.
483 * Note that reading ALM data registers also clears IRQ status.
484 */
485 ds1305->ctrl[0] &= ~(DS1305_AEI1 | DS1305_AEI0);
486 ds1305->ctrl[1] = 0;
487
488 buf[0] = DS1305_WRITE | DS1305_CONTROL;
489 buf[1] = ds1305->ctrl[0];
490 buf[2] = 0;
491
492 status = spi_write_then_read(spi, buf, sizeof buf,
493 NULL, 0);
494 if (status < 0)
495 dev_dbg(&spi->dev, "clear irq --> %d\n", status);
496
497 mutex_unlock(lock);
498
499 if (!test_bit(FLAG_EXITING, &ds1305->flags))
500 enable_irq(spi->irq);
501
502 /* rtc_update_irq() requires an IRQ-disabled context */
503 local_irq_disable();
504 rtc_update_irq(ds1305->rtc, 1, RTC_AF | RTC_IRQF);
505 local_irq_enable();
506}
507
508/*
509 * This "real" IRQ handler hands off to a workqueue mostly to allow
510 * mutex locking for ds1305->ctrl ... unlike I2C, we could issue async
511 * I/O requests in IRQ context (to clear the IRQ status).
512 */
513static irqreturn_t ds1305_irq(int irq, void *p)
514{
515 struct ds1305 *ds1305 = p;
516
517 disable_irq(irq);
518 schedule_work(&ds1305->work);
519 return IRQ_HANDLED;
520}
521
522/*----------------------------------------------------------------------*/
523
524/*
525 * Interface for NVRAM
526 */
527
528static void msg_init(struct spi_message *m, struct spi_transfer *x,
529 u8 *addr, size_t count, char *tx, char *rx)
530{
531 spi_message_init(m);
532 memset(x, 0, 2 * sizeof(*x));
533
534 x->tx_buf = addr;
535 x->len = 1;
536 spi_message_add_tail(x, m);
537
538 x++;
539
540 x->tx_buf = tx;
541 x->rx_buf = rx;
542 x->len = count;
543 spi_message_add_tail(x, m);
544}
545
546static ssize_t
547ds1305_nvram_read(struct kobject *kobj, struct bin_attribute *attr,
548 char *buf, loff_t off, size_t count)
549{
550 struct spi_device *spi;
551 u8 addr;
552 struct spi_message m;
553 struct spi_transfer x[2];
554 int status;
555
556 spi = container_of(kobj, struct spi_device, dev.kobj);
557
558 if (unlikely(off >= DS1305_NVRAM_LEN))
559 return 0;
560 if (count >= DS1305_NVRAM_LEN)
561 count = DS1305_NVRAM_LEN;
562 if ((off + count) > DS1305_NVRAM_LEN)
563 count = DS1305_NVRAM_LEN - off;
564 if (unlikely(!count))
565 return count;
566
567 addr = DS1305_NVRAM + off;
568 msg_init(&m, x, &addr, count, NULL, buf);
569
570 status = spi_sync(spi, &m);
571 if (status < 0)
572 dev_err(&spi->dev, "nvram %s error %d\n", "read", status);
573 return (status < 0) ? status : count;
574}
575
576static ssize_t
577ds1305_nvram_write(struct kobject *kobj, struct bin_attribute *attr,
578 char *buf, loff_t off, size_t count)
579{
580 struct spi_device *spi;
581 u8 addr;
582 struct spi_message m;
583 struct spi_transfer x[2];
584 int status;
585
586 spi = container_of(kobj, struct spi_device, dev.kobj);
587
588 if (unlikely(off >= DS1305_NVRAM_LEN))
589 return -EFBIG;
590 if (count >= DS1305_NVRAM_LEN)
591 count = DS1305_NVRAM_LEN;
592 if ((off + count) > DS1305_NVRAM_LEN)
593 count = DS1305_NVRAM_LEN - off;
594 if (unlikely(!count))
595 return count;
596
597 addr = (DS1305_WRITE | DS1305_NVRAM) + off;
598 msg_init(&m, x, &addr, count, buf, NULL);
599
600 status = spi_sync(spi, &m);
601 if (status < 0)
602 dev_err(&spi->dev, "nvram %s error %d\n", "write", status);
603 return (status < 0) ? status : count;
604}
605
606static struct bin_attribute nvram = {
607 .attr.name = "nvram",
608 .attr.mode = S_IRUGO | S_IWUSR,
609 .attr.owner = THIS_MODULE,
610 .read = ds1305_nvram_read,
611 .write = ds1305_nvram_write,
612 .size = DS1305_NVRAM_LEN,
613};
614
615/*----------------------------------------------------------------------*/
616
617/*
618 * Interface to SPI stack
619 */
620
621static int __devinit ds1305_probe(struct spi_device *spi)
622{
623 struct ds1305 *ds1305;
624 struct rtc_device *rtc;
625 int status;
626 u8 addr, value;
627 struct ds1305_platform_data *pdata = spi->dev.platform_data;
628 bool write_ctrl = false;
629
630 /* Sanity check board setup data. This may be hooked up
631 * in 3wire mode, but we don't care. Note that unless
632 * there's an inverter in place, this needs SPI_CS_HIGH!
633 */
634 if ((spi->bits_per_word && spi->bits_per_word != 8)
635 || (spi->max_speed_hz > 2000000)
636 || !(spi->mode & SPI_CPHA))
637 return -EINVAL;
638
639 /* set up driver data */
640 ds1305 = kzalloc(sizeof *ds1305, GFP_KERNEL);
641 if (!ds1305)
642 return -ENOMEM;
643 ds1305->spi = spi;
644 spi_set_drvdata(spi, ds1305);
645
646 /* read and cache control registers */
647 addr = DS1305_CONTROL;
648 status = spi_write_then_read(spi, &addr, sizeof addr,
649 ds1305->ctrl, sizeof ds1305->ctrl);
650 if (status < 0) {
651 dev_dbg(&spi->dev, "can't %s, %d\n",
652 "read", status);
653 goto fail0;
654 }
655
656 dev_dbg(&spi->dev, "ctrl %s: %02x %02x %02x\n",
657 "read", ds1305->ctrl[0],
658 ds1305->ctrl[1], ds1305->ctrl[2]);
659
660 /* Sanity check register values ... partially compensating for the
661 * fact that SPI has no device handshake. A pullup on MISO would
662 * make these tests fail; but not all systems will have one. If
663 * some register is neither 0x00 nor 0xff, a chip is likely there.
664 */
665 if ((ds1305->ctrl[0] & 0x38) != 0 || (ds1305->ctrl[1] & 0xfc) != 0) {
666 dev_dbg(&spi->dev, "RTC chip is not present\n");
667 status = -ENODEV;
668 goto fail0;
669 }
670 if (ds1305->ctrl[2] == 0)
671 dev_dbg(&spi->dev, "chip may not be present\n");
672
673 /* enable writes if needed ... if we were paranoid it would
674 * make sense to enable them only when absolutely necessary.
675 */
676 if (ds1305->ctrl[0] & DS1305_WP) {
677 u8 buf[2];
678
679 ds1305->ctrl[0] &= ~DS1305_WP;
680
681 buf[0] = DS1305_WRITE | DS1305_CONTROL;
682 buf[1] = ds1305->ctrl[0];
683 status = spi_write_then_read(spi, buf, sizeof buf, NULL, 0);
684
685 dev_dbg(&spi->dev, "clear WP --> %d\n", status);
686 if (status < 0)
687 goto fail0;
688 }
689
690 /* on DS1305, maybe start oscillator; like most low power
691 * oscillators, it may take a second to stabilize
692 */
693 if (ds1305->ctrl[0] & DS1305_nEOSC) {
694 ds1305->ctrl[0] &= ~DS1305_nEOSC;
695 write_ctrl = true;
696 dev_warn(&spi->dev, "SET TIME!\n");
697 }
698
699 /* ack any pending IRQs */
700 if (ds1305->ctrl[1]) {
701 ds1305->ctrl[1] = 0;
702 write_ctrl = true;
703 }
704
705 /* this may need one-time (re)init */
706 if (pdata) {
707 /* maybe enable trickle charge */
708 if (((ds1305->ctrl[2] & 0xf0) != DS1305_TRICKLE_MAGIC)) {
709 ds1305->ctrl[2] = DS1305_TRICKLE_MAGIC
710 | pdata->trickle;
711 write_ctrl = true;
712 }
713
714 /* on DS1306, configure 1 Hz signal */
715 if (pdata->is_ds1306) {
716 if (pdata->en_1hz) {
717 if (!(ds1305->ctrl[0] & DS1306_1HZ)) {
718 ds1305->ctrl[0] |= DS1306_1HZ;
719 write_ctrl = true;
720 }
721 } else {
722 if (ds1305->ctrl[0] & DS1306_1HZ) {
723 ds1305->ctrl[0] &= ~DS1306_1HZ;
724 write_ctrl = true;
725 }
726 }
727 }
728 }
729
730 if (write_ctrl) {
731 u8 buf[4];
732
733 buf[0] = DS1305_WRITE | DS1305_CONTROL;
734 buf[1] = ds1305->ctrl[0];
735 buf[2] = ds1305->ctrl[1];
736 buf[3] = ds1305->ctrl[2];
737 status = spi_write_then_read(spi, buf, sizeof buf, NULL, 0);
738 if (status < 0) {
739 dev_dbg(&spi->dev, "can't %s, %d\n",
740 "write", status);
741 goto fail0;
742 }
743
744 dev_dbg(&spi->dev, "ctrl %s: %02x %02x %02x\n",
745 "write", ds1305->ctrl[0],
746 ds1305->ctrl[1], ds1305->ctrl[2]);
747 }
748
749 /* see if non-Linux software set up AM/PM mode */
750 addr = DS1305_HOUR;
751 status = spi_write_then_read(spi, &addr, sizeof addr,
752 &value, sizeof value);
753 if (status < 0) {
754 dev_dbg(&spi->dev, "read HOUR --> %d\n", status);
755 goto fail0;
756 }
757
758 ds1305->hr12 = (DS1305_HR_12 & value) != 0;
759 if (ds1305->hr12)
760 dev_dbg(&spi->dev, "AM/PM\n");
761
762 /* register RTC ... from here on, ds1305->ctrl needs locking */
763 rtc = rtc_device_register("ds1305", &spi->dev,
764 &ds1305_ops, THIS_MODULE);
765 if (IS_ERR(rtc)) {
766 status = PTR_ERR(rtc);
767 dev_dbg(&spi->dev, "register rtc --> %d\n", status);
768 goto fail0;
769 }
770 ds1305->rtc = rtc;
771
772 /* Maybe set up alarm IRQ; be ready to handle it triggering right
773 * away. NOTE that we don't share this. The signal is active low,
774 * and we can't ack it before a SPI message delay. We temporarily
775 * disable the IRQ until it's acked, which lets us work with more
776 * IRQ trigger modes (not all IRQ controllers can do falling edge).
777 */
778 if (spi->irq) {
779 INIT_WORK(&ds1305->work, ds1305_work);
780 status = request_irq(spi->irq, ds1305_irq,
781 0, dev_name(&rtc->dev), ds1305);
782 if (status < 0) {
783 dev_dbg(&spi->dev, "request_irq %d --> %d\n",
784 spi->irq, status);
785 goto fail1;
786 }
787 }
788
789 /* export NVRAM */
790 status = sysfs_create_bin_file(&spi->dev.kobj, &nvram);
791 if (status < 0) {
792 dev_dbg(&spi->dev, "register nvram --> %d\n", status);
793 goto fail2;
794 }
795
796 return 0;
797
798fail2:
799 free_irq(spi->irq, ds1305);
800fail1:
801 rtc_device_unregister(rtc);
802fail0:
803 kfree(ds1305);
804 return status;
805}
806
807static int __devexit ds1305_remove(struct spi_device *spi)
808{
809 struct ds1305 *ds1305 = spi_get_drvdata(spi);
810
811 sysfs_remove_bin_file(&spi->dev.kobj, &nvram);
812
813 /* carefully shut down irq and workqueue, if present */
814 if (spi->irq) {
815 set_bit(FLAG_EXITING, &ds1305->flags);
816 free_irq(spi->irq, ds1305);
817 flush_scheduled_work();
818 }
819
820 rtc_device_unregister(ds1305->rtc);
821 spi_set_drvdata(spi, NULL);
822 kfree(ds1305);
823 return 0;
824}
825
826static struct spi_driver ds1305_driver = {
827 .driver.name = "rtc-ds1305",
828 .driver.owner = THIS_MODULE,
829 .probe = ds1305_probe,
830 .remove = __devexit_p(ds1305_remove),
831 /* REVISIT add suspend/resume */
832};
833
834static int __init ds1305_init(void)
835{
836 return spi_register_driver(&ds1305_driver);
837}
838module_init(ds1305_init);
839
840static void __exit ds1305_exit(void)
841{
842 spi_unregister_driver(&ds1305_driver);
843}
844module_exit(ds1305_exit);
845
846MODULE_DESCRIPTION("RTC driver for DS1305 and DS1306 chips");
847MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 0a19c06019be..24bc1689fc74 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -13,21 +13,21 @@
13 * 13 *
14 */ 14 */
15 15
16#include <linux/module.h> 16#include <linux/bcd.h>
17#include <linux/i2c.h>
17#include <linux/init.h> 18#include <linux/init.h>
18#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/rtc.h>
19#include <linux/slab.h> 22#include <linux/slab.h>
20#include <linux/smp_lock.h> 23#include <linux/smp_lock.h>
21#include <linux/string.h> 24#include <linux/string.h>
22#include <linux/i2c.h>
23#include <linux/rtc.h>
24#include <linux/bcd.h>
25#ifdef CONFIG_RTC_DRV_M41T80_WDT 25#ifdef CONFIG_RTC_DRV_M41T80_WDT
26#include <linux/miscdevice.h>
27#include <linux/watchdog.h>
28#include <linux/reboot.h>
29#include <linux/fs.h> 26#include <linux/fs.h>
30#include <linux/ioctl.h> 27#include <linux/ioctl.h>
28#include <linux/miscdevice.h>
29#include <linux/reboot.h>
30#include <linux/watchdog.h>
31#endif 31#endif
32 32
33#define M41T80_REG_SSEC 0 33#define M41T80_REG_SSEC 0
@@ -631,14 +631,12 @@ static int wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
631 return -EFAULT; 631 return -EFAULT;
632 632
633 if (rv & WDIOS_DISABLECARD) { 633 if (rv & WDIOS_DISABLECARD) {
634 printk(KERN_INFO 634 pr_info("rtc-m41t80: disable watchdog\n");
635 "rtc-m41t80: disable watchdog\n");
636 wdt_disable(); 635 wdt_disable();
637 } 636 }
638 637
639 if (rv & WDIOS_ENABLECARD) { 638 if (rv & WDIOS_ENABLECARD) {
640 printk(KERN_INFO 639 pr_info("rtc-m41t80: enable watchdog\n");
641 "rtc-m41t80: enable watchdog\n");
642 wdt_ping(); 640 wdt_ping();
643 } 641 }
644 642
diff --git a/drivers/rtc/rtc-m41t94.c b/drivers/rtc/rtc-m41t94.c
new file mode 100644
index 000000000000..9b19499c829e
--- /dev/null
+++ b/drivers/rtc/rtc-m41t94.c
@@ -0,0 +1,173 @@
1/*
2 * Driver for ST M41T94 SPI RTC
3 *
4 * Copyright (C) 2008 Kim B. Heino
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/platform_device.h>
14#include <linux/rtc.h>
15#include <linux/spi/spi.h>
16#include <linux/bcd.h>
17
18#define M41T94_REG_SECONDS 0x01
19#define M41T94_REG_MINUTES 0x02
20#define M41T94_REG_HOURS 0x03
21#define M41T94_REG_WDAY 0x04
22#define M41T94_REG_DAY 0x05
23#define M41T94_REG_MONTH 0x06
24#define M41T94_REG_YEAR 0x07
25#define M41T94_REG_HT 0x0c
26
27#define M41T94_BIT_HALT 0x40
28#define M41T94_BIT_STOP 0x80
29#define M41T94_BIT_CB 0x40
30#define M41T94_BIT_CEB 0x80
31
32static int m41t94_set_time(struct device *dev, struct rtc_time *tm)
33{
34 struct spi_device *spi = to_spi_device(dev);
35 u8 buf[8]; /* write cmd + 7 registers */
36
37 dev_dbg(dev, "%s secs=%d, mins=%d, "
38 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
39 "write", tm->tm_sec, tm->tm_min,
40 tm->tm_hour, tm->tm_mday,
41 tm->tm_mon, tm->tm_year, tm->tm_wday);
42
43 buf[0] = 0x80 | M41T94_REG_SECONDS; /* write time + date */
44 buf[M41T94_REG_SECONDS] = BIN2BCD(tm->tm_sec);
45 buf[M41T94_REG_MINUTES] = BIN2BCD(tm->tm_min);
46 buf[M41T94_REG_HOURS] = BIN2BCD(tm->tm_hour);
47 buf[M41T94_REG_WDAY] = BIN2BCD(tm->tm_wday + 1);
48 buf[M41T94_REG_DAY] = BIN2BCD(tm->tm_mday);
49 buf[M41T94_REG_MONTH] = BIN2BCD(tm->tm_mon + 1);
50
51 buf[M41T94_REG_HOURS] |= M41T94_BIT_CEB;
52 if (tm->tm_year >= 100)
53 buf[M41T94_REG_HOURS] |= M41T94_BIT_CB;
54 buf[M41T94_REG_YEAR] = BIN2BCD(tm->tm_year % 100);
55
56 return spi_write(spi, buf, 8);
57}
58
59static int m41t94_read_time(struct device *dev, struct rtc_time *tm)
60{
61 struct spi_device *spi = to_spi_device(dev);
62 u8 buf[2];
63 int ret, hour;
64
65 /* clear halt update bit */
66 ret = spi_w8r8(spi, M41T94_REG_HT);
67 if (ret < 0)
68 return ret;
69 if (ret & M41T94_BIT_HALT) {
70 buf[0] = 0x80 | M41T94_REG_HT;
71 buf[1] = ret & ~M41T94_BIT_HALT;
72 spi_write(spi, buf, 2);
73 }
74
75 /* clear stop bit */
76 ret = spi_w8r8(spi, M41T94_REG_SECONDS);
77 if (ret < 0)
78 return ret;
79 if (ret & M41T94_BIT_STOP) {
80 buf[0] = 0x80 | M41T94_REG_SECONDS;
81 buf[1] = ret & ~M41T94_BIT_STOP;
82 spi_write(spi, buf, 2);
83 }
84
85 tm->tm_sec = BCD2BIN(spi_w8r8(spi, M41T94_REG_SECONDS));
86 tm->tm_min = BCD2BIN(spi_w8r8(spi, M41T94_REG_MINUTES));
87 hour = spi_w8r8(spi, M41T94_REG_HOURS);
88 tm->tm_hour = BCD2BIN(hour & 0x3f);
89 tm->tm_wday = BCD2BIN(spi_w8r8(spi, M41T94_REG_WDAY)) - 1;
90 tm->tm_mday = BCD2BIN(spi_w8r8(spi, M41T94_REG_DAY));
91 tm->tm_mon = BCD2BIN(spi_w8r8(spi, M41T94_REG_MONTH)) - 1;
92 tm->tm_year = BCD2BIN(spi_w8r8(spi, M41T94_REG_YEAR));
93 if ((hour & M41T94_BIT_CB) || !(hour & M41T94_BIT_CEB))
94 tm->tm_year += 100;
95
96 dev_dbg(dev, "%s secs=%d, mins=%d, "
97 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
98 "read", tm->tm_sec, tm->tm_min,
99 tm->tm_hour, tm->tm_mday,
100 tm->tm_mon, tm->tm_year, tm->tm_wday);
101
102 /* initial clock setting can be undefined */
103 return rtc_valid_tm(tm);
104}
105
106static const struct rtc_class_ops m41t94_rtc_ops = {
107 .read_time = m41t94_read_time,
108 .set_time = m41t94_set_time,
109};
110
111static struct spi_driver m41t94_driver;
112
113static int __devinit m41t94_probe(struct spi_device *spi)
114{
115 struct rtc_device *rtc;
116 int res;
117
118 spi->bits_per_word = 8;
119 spi_setup(spi);
120
121 res = spi_w8r8(spi, M41T94_REG_SECONDS);
122 if (res < 0) {
123 dev_err(&spi->dev, "not found.\n");
124 return res;
125 }
126
127 rtc = rtc_device_register(m41t94_driver.driver.name,
128 &spi->dev, &m41t94_rtc_ops, THIS_MODULE);
129 if (IS_ERR(rtc))
130 return PTR_ERR(rtc);
131
132 dev_set_drvdata(&spi->dev, rtc);
133
134 return 0;
135}
136
137static int __devexit m41t94_remove(struct spi_device *spi)
138{
139 struct rtc_device *rtc = platform_get_drvdata(spi);
140
141 if (rtc)
142 rtc_device_unregister(rtc);
143
144 return 0;
145}
146
147static struct spi_driver m41t94_driver = {
148 .driver = {
149 .name = "rtc-m41t94",
150 .bus = &spi_bus_type,
151 .owner = THIS_MODULE,
152 },
153 .probe = m41t94_probe,
154 .remove = __devexit_p(m41t94_remove),
155};
156
157static __init int m41t94_init(void)
158{
159 return spi_register_driver(&m41t94_driver);
160}
161
162module_init(m41t94_init);
163
164static __exit void m41t94_exit(void)
165{
166 spi_unregister_driver(&m41t94_driver);
167}
168
169module_exit(m41t94_exit);
170
171MODULE_AUTHOR("Kim B. Heino <Kim.Heino@bluegiga.com>");
172MODULE_DESCRIPTION("Driver for ST M41T94 SPI RTC");
173MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index eb23d8423f42..8876605d4d4b 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -92,18 +92,6 @@
92#define rtc_write(val, addr) omap_writeb(val, OMAP_RTC_BASE + (addr)) 92#define rtc_write(val, addr) omap_writeb(val, OMAP_RTC_BASE + (addr))
93 93
94 94
95/* platform_bus isn't hotpluggable, so for static linkage it'd be safe
96 * to get rid of probe() and remove() code ... too bad the driver struct
97 * remembers probe(), that's about 25% of the runtime footprint!!
98 */
99#ifndef MODULE
100#undef __devexit
101#undef __devexit_p
102#define __devexit __exit
103#define __devexit_p __exit_p
104#endif
105
106
107/* we rely on the rtc framework to handle locking (rtc->ops_lock), 95/* we rely on the rtc framework to handle locking (rtc->ops_lock),
108 * so the only other requirement is that register accesses which 96 * so the only other requirement is that register accesses which
109 * require BUSY to be clear are made with IRQs locally disabled 97 * require BUSY to be clear are made with IRQs locally disabled
@@ -324,7 +312,7 @@ static struct rtc_class_ops omap_rtc_ops = {
324static int omap_rtc_alarm; 312static int omap_rtc_alarm;
325static int omap_rtc_timer; 313static int omap_rtc_timer;
326 314
327static int __devinit omap_rtc_probe(struct platform_device *pdev) 315static int __init omap_rtc_probe(struct platform_device *pdev)
328{ 316{
329 struct resource *res, *mem; 317 struct resource *res, *mem;
330 struct rtc_device *rtc; 318 struct rtc_device *rtc;
@@ -440,7 +428,7 @@ fail:
440 return -EIO; 428 return -EIO;
441} 429}
442 430
443static int __devexit omap_rtc_remove(struct platform_device *pdev) 431static int __exit omap_rtc_remove(struct platform_device *pdev)
444{ 432{
445 struct rtc_device *rtc = platform_get_drvdata(pdev);; 433 struct rtc_device *rtc = platform_get_drvdata(pdev);;
446 434
@@ -498,8 +486,7 @@ static void omap_rtc_shutdown(struct platform_device *pdev)
498 486
499MODULE_ALIAS("platform:omap_rtc"); 487MODULE_ALIAS("platform:omap_rtc");
500static struct platform_driver omap_rtc_driver = { 488static struct platform_driver omap_rtc_driver = {
501 .probe = omap_rtc_probe, 489 .remove = __exit_p(omap_rtc_remove),
502 .remove = __devexit_p(omap_rtc_remove),
503 .suspend = omap_rtc_suspend, 490 .suspend = omap_rtc_suspend,
504 .resume = omap_rtc_resume, 491 .resume = omap_rtc_resume,
505 .shutdown = omap_rtc_shutdown, 492 .shutdown = omap_rtc_shutdown,
@@ -511,7 +498,7 @@ static struct platform_driver omap_rtc_driver = {
511 498
512static int __init rtc_init(void) 499static int __init rtc_init(void)
513{ 500{
514 return platform_driver_register(&omap_rtc_driver); 501 return platform_driver_probe(&omap_rtc_driver, omap_rtc_probe);
515} 502}
516module_init(rtc_init); 503module_init(rtc_init);
517 504
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index 3d09d8f0b1f0..d388c662bf4b 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -2,6 +2,7 @@
2 * drivers/rtc/rtc-pcf8583.c 2 * drivers/rtc/rtc-pcf8583.c
3 * 3 *
4 * Copyright (C) 2000 Russell King 4 * Copyright (C) 2000 Russell King
5 * Copyright (C) 2008 Wolfram Sang & Juergen Beisert, Pengutronix
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -14,7 +15,6 @@
14#include <linux/module.h> 15#include <linux/module.h>
15#include <linux/i2c.h> 16#include <linux/i2c.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
17#include <linux/string.h>
18#include <linux/rtc.h> 18#include <linux/rtc.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/errno.h> 20#include <linux/errno.h>
@@ -27,7 +27,6 @@ struct rtc_mem {
27}; 27};
28 28
29struct pcf8583 { 29struct pcf8583 {
30 struct i2c_client client;
31 struct rtc_device *rtc; 30 struct rtc_device *rtc;
32 unsigned char ctrl; 31 unsigned char ctrl;
33}; 32};
@@ -40,10 +39,6 @@ struct pcf8583 {
40#define CTRL_ALARM 0x02 39#define CTRL_ALARM 0x02
41#define CTRL_TIMER 0x01 40#define CTRL_TIMER 0x01
42 41
43static const unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END };
44
45/* Module parameters */
46I2C_CLIENT_INSMOD;
47 42
48static struct i2c_driver pcf8583_driver; 43static struct i2c_driver pcf8583_driver;
49 44
@@ -269,106 +264,60 @@ static const struct rtc_class_ops pcf8583_rtc_ops = {
269 .set_time = pcf8583_rtc_set_time, 264 .set_time = pcf8583_rtc_set_time,
270}; 265};
271 266
272static int pcf8583_probe(struct i2c_adapter *adap, int addr, int kind); 267static int pcf8583_probe(struct i2c_client *client,
273 268 const struct i2c_device_id *id)
274static int pcf8583_attach(struct i2c_adapter *adap)
275{
276 return i2c_probe(adap, &addr_data, pcf8583_probe);
277}
278
279static int pcf8583_detach(struct i2c_client *client)
280{
281 int err;
282 struct pcf8583 *pcf = i2c_get_clientdata(client);
283 struct rtc_device *rtc = pcf->rtc;
284
285 if (rtc)
286 rtc_device_unregister(rtc);
287
288 if ((err = i2c_detach_client(client)))
289 return err;
290
291 kfree(pcf);
292 return 0;
293}
294
295static struct i2c_driver pcf8583_driver = {
296 .driver = {
297 .name = "pcf8583",
298 },
299 .id = I2C_DRIVERID_PCF8583,
300 .attach_adapter = pcf8583_attach,
301 .detach_client = pcf8583_detach,
302};
303
304static int pcf8583_probe(struct i2c_adapter *adap, int addr, int kind)
305{ 269{
306 struct pcf8583 *pcf; 270 struct pcf8583 *pcf8583;
307 struct i2c_client *client;
308 struct rtc_device *rtc;
309 unsigned char buf[1], ad[1] = { 0 };
310 int err; 271 int err;
311 struct i2c_msg msgs[2] = {
312 {
313 .addr = addr,
314 .flags = 0,
315 .len = 1,
316 .buf = ad,
317 }, {
318 .addr = addr,
319 .flags = I2C_M_RD,
320 .len = 1,
321 .buf = buf,
322 }
323 };
324 272
325 if (!i2c_check_functionality(adap, I2C_FUNC_I2C)) 273 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
326 return 0; 274 return -ENODEV;
327 275
328 pcf = kzalloc(sizeof(*pcf), GFP_KERNEL); 276 pcf8583 = kzalloc(sizeof(struct pcf8583), GFP_KERNEL);
329 if (!pcf) 277 if (!pcf8583)
330 return -ENOMEM; 278 return -ENOMEM;
331 279
332 client = &pcf->client; 280 pcf8583->rtc = rtc_device_register(pcf8583_driver.driver.name,
281 &client->dev, &pcf8583_rtc_ops, THIS_MODULE);
333 282
334 client->addr = addr; 283 if (IS_ERR(pcf8583->rtc)) {
335 client->adapter = adap; 284 err = PTR_ERR(pcf8583->rtc);
336 client->driver = &pcf8583_driver;
337
338 strlcpy(client->name, pcf8583_driver.driver.name, I2C_NAME_SIZE);
339
340 if (i2c_transfer(client->adapter, msgs, 2) != 2) {
341 err = -EIO;
342 goto exit_kfree; 285 goto exit_kfree;
343 } 286 }
344 287
345 err = i2c_attach_client(client); 288 i2c_set_clientdata(client, pcf8583);
346 289 return 0;
347 if (err)
348 goto exit_kfree;
349
350 rtc = rtc_device_register(pcf8583_driver.driver.name, &client->dev,
351 &pcf8583_rtc_ops, THIS_MODULE);
352 290
353 if (IS_ERR(rtc)) { 291exit_kfree:
354 err = PTR_ERR(rtc); 292 kfree(pcf8583);
355 goto exit_detach; 293 return err;
356 } 294}
357 295
358 pcf->rtc = rtc; 296static int __devexit pcf8583_remove(struct i2c_client *client)
359 i2c_set_clientdata(client, pcf); 297{
360 set_ctrl(client, buf[0]); 298 struct pcf8583 *pcf8583 = i2c_get_clientdata(client);
361 299
300 if (pcf8583->rtc)
301 rtc_device_unregister(pcf8583->rtc);
302 kfree(pcf8583);
362 return 0; 303 return 0;
304}
363 305
364exit_detach: 306static const struct i2c_device_id pcf8583_id[] = {
365 i2c_detach_client(client); 307 { "pcf8583", 0 },
366 308 { }
367exit_kfree: 309};
368 kfree(pcf); 310MODULE_DEVICE_TABLE(i2c, pcf8583_id);
369 311
370 return err; 312static struct i2c_driver pcf8583_driver = {
371} 313 .driver = {
314 .name = "pcf8583",
315 .owner = THIS_MODULE,
316 },
317 .probe = pcf8583_probe,
318 .remove = __devexit_p(pcf8583_remove),
319 .id_table = pcf8583_id,
320};
372 321
373static __init int pcf8583_init(void) 322static __init int pcf8583_init(void)
374{ 323{
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index fed86e507fdf..54b1ebb01502 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -36,10 +36,8 @@ static struct resource *s3c_rtc_mem;
36static void __iomem *s3c_rtc_base; 36static void __iomem *s3c_rtc_base;
37static int s3c_rtc_alarmno = NO_IRQ; 37static int s3c_rtc_alarmno = NO_IRQ;
38static int s3c_rtc_tickno = NO_IRQ; 38static int s3c_rtc_tickno = NO_IRQ;
39static int s3c_rtc_freq = 1;
40 39
41static DEFINE_SPINLOCK(s3c_rtc_pie_lock); 40static DEFINE_SPINLOCK(s3c_rtc_pie_lock);
42static unsigned int tick_count;
43 41
44/* IRQ Handlers */ 42/* IRQ Handlers */
45 43
@@ -55,7 +53,7 @@ static irqreturn_t s3c_rtc_tickirq(int irq, void *id)
55{ 53{
56 struct rtc_device *rdev = id; 54 struct rtc_device *rdev = id;
57 55
58 rtc_update_irq(rdev, tick_count++, RTC_PF | RTC_IRQF); 56 rtc_update_irq(rdev, 1, RTC_PF | RTC_IRQF);
59 return IRQ_HANDLED; 57 return IRQ_HANDLED;
60} 58}
61 59
@@ -74,35 +72,37 @@ static void s3c_rtc_setaie(int to)
74 writeb(tmp, s3c_rtc_base + S3C2410_RTCALM); 72 writeb(tmp, s3c_rtc_base + S3C2410_RTCALM);
75} 73}
76 74
77static void s3c_rtc_setpie(int to) 75static int s3c_rtc_setpie(struct device *dev, int enabled)
78{ 76{
79 unsigned int tmp; 77 unsigned int tmp;
80 78
81 pr_debug("%s: pie=%d\n", __func__, to); 79 pr_debug("%s: pie=%d\n", __func__, enabled);
82 80
83 spin_lock_irq(&s3c_rtc_pie_lock); 81 spin_lock_irq(&s3c_rtc_pie_lock);
84 tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE; 82 tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
85 83
86 if (to) 84 if (enabled)
87 tmp |= S3C2410_TICNT_ENABLE; 85 tmp |= S3C2410_TICNT_ENABLE;
88 86
89 writeb(tmp, s3c_rtc_base + S3C2410_TICNT); 87 writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
90 spin_unlock_irq(&s3c_rtc_pie_lock); 88 spin_unlock_irq(&s3c_rtc_pie_lock);
89
90 return 0;
91} 91}
92 92
93static void s3c_rtc_setfreq(int freq) 93static int s3c_rtc_setfreq(struct device *dev, int freq)
94{ 94{
95 unsigned int tmp; 95 unsigned int tmp;
96 96
97 spin_lock_irq(&s3c_rtc_pie_lock); 97 spin_lock_irq(&s3c_rtc_pie_lock);
98 tmp = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
99
100 s3c_rtc_freq = freq;
101 98
99 tmp = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
102 tmp |= (128 / freq)-1; 100 tmp |= (128 / freq)-1;
103 101
104 writeb(tmp, s3c_rtc_base + S3C2410_TICNT); 102 writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
105 spin_unlock_irq(&s3c_rtc_pie_lock); 103 spin_unlock_irq(&s3c_rtc_pie_lock);
104
105 return 0;
106} 106}
107 107
108/* Time read/write */ 108/* Time read/write */
@@ -267,12 +267,7 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
267 267
268 writeb(alrm_en, base + S3C2410_RTCALM); 268 writeb(alrm_en, base + S3C2410_RTCALM);
269 269
270 if (0) { 270 s3c_rtc_setaie(alrm->enabled);
271 alrm_en = readb(base + S3C2410_RTCALM);
272 alrm_en &= ~S3C2410_RTCALM_ALMEN;
273 writeb(alrm_en, base + S3C2410_RTCALM);
274 disable_irq_wake(s3c_rtc_alarmno);
275 }
276 271
277 if (alrm->enabled) 272 if (alrm->enabled)
278 enable_irq_wake(s3c_rtc_alarmno); 273 enable_irq_wake(s3c_rtc_alarmno);
@@ -282,59 +277,12 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
282 return 0; 277 return 0;
283} 278}
284 279
285static int s3c_rtc_ioctl(struct device *dev,
286 unsigned int cmd, unsigned long arg)
287{
288 unsigned int ret = -ENOIOCTLCMD;
289
290 switch (cmd) {
291 case RTC_AIE_OFF:
292 case RTC_AIE_ON:
293 s3c_rtc_setaie((cmd == RTC_AIE_ON) ? 1 : 0);
294 ret = 0;
295 break;
296
297 case RTC_PIE_OFF:
298 case RTC_PIE_ON:
299 tick_count = 0;
300 s3c_rtc_setpie((cmd == RTC_PIE_ON) ? 1 : 0);
301 ret = 0;
302 break;
303
304 case RTC_IRQP_READ:
305 ret = put_user(s3c_rtc_freq, (unsigned long __user *)arg);
306 break;
307
308 case RTC_IRQP_SET:
309 if (!is_power_of_2(arg)) {
310 ret = -EINVAL;
311 goto exit;
312 }
313
314 pr_debug("s3c2410_rtc: setting frequency %ld\n", arg);
315
316 s3c_rtc_setfreq(arg);
317 ret = 0;
318 break;
319
320 case RTC_UIE_ON:
321 case RTC_UIE_OFF:
322 ret = -EINVAL;
323 }
324
325 exit:
326 return ret;
327}
328
329static int s3c_rtc_proc(struct device *dev, struct seq_file *seq) 280static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
330{ 281{
331 unsigned int ticnt = readb(s3c_rtc_base + S3C2410_TICNT); 282 unsigned int ticnt = readb(s3c_rtc_base + S3C2410_TICNT);
332 283
333 seq_printf(seq, "periodic_IRQ\t: %s\n", 284 seq_printf(seq, "periodic_IRQ\t: %s\n",
334 (ticnt & S3C2410_TICNT_ENABLE) ? "yes" : "no" ); 285 (ticnt & S3C2410_TICNT_ENABLE) ? "yes" : "no" );
335
336 seq_printf(seq, "periodic_freq\t: %d\n", s3c_rtc_freq);
337
338 return 0; 286 return 0;
339} 287}
340 288
@@ -374,7 +322,7 @@ static void s3c_rtc_release(struct device *dev)
374 322
375 /* do not clear AIE here, it may be needed for wake */ 323 /* do not clear AIE here, it may be needed for wake */
376 324
377 s3c_rtc_setpie(0); 325 s3c_rtc_setpie(dev, 0);
378 free_irq(s3c_rtc_alarmno, rtc_dev); 326 free_irq(s3c_rtc_alarmno, rtc_dev);
379 free_irq(s3c_rtc_tickno, rtc_dev); 327 free_irq(s3c_rtc_tickno, rtc_dev);
380} 328}
@@ -382,11 +330,12 @@ static void s3c_rtc_release(struct device *dev)
382static const struct rtc_class_ops s3c_rtcops = { 330static const struct rtc_class_ops s3c_rtcops = {
383 .open = s3c_rtc_open, 331 .open = s3c_rtc_open,
384 .release = s3c_rtc_release, 332 .release = s3c_rtc_release,
385 .ioctl = s3c_rtc_ioctl,
386 .read_time = s3c_rtc_gettime, 333 .read_time = s3c_rtc_gettime,
387 .set_time = s3c_rtc_settime, 334 .set_time = s3c_rtc_settime,
388 .read_alarm = s3c_rtc_getalarm, 335 .read_alarm = s3c_rtc_getalarm,
389 .set_alarm = s3c_rtc_setalarm, 336 .set_alarm = s3c_rtc_setalarm,
337 .irq_set_freq = s3c_rtc_setfreq,
338 .irq_set_state = s3c_rtc_setpie,
390 .proc = s3c_rtc_proc, 339 .proc = s3c_rtc_proc,
391}; 340};
392 341
@@ -430,14 +379,14 @@ static void s3c_rtc_enable(struct platform_device *pdev, int en)
430 } 379 }
431} 380}
432 381
433static int s3c_rtc_remove(struct platform_device *dev) 382static int __devexit s3c_rtc_remove(struct platform_device *dev)
434{ 383{
435 struct rtc_device *rtc = platform_get_drvdata(dev); 384 struct rtc_device *rtc = platform_get_drvdata(dev);
436 385
437 platform_set_drvdata(dev, NULL); 386 platform_set_drvdata(dev, NULL);
438 rtc_device_unregister(rtc); 387 rtc_device_unregister(rtc);
439 388
440 s3c_rtc_setpie(0); 389 s3c_rtc_setpie(&dev->dev, 0);
441 s3c_rtc_setaie(0); 390 s3c_rtc_setaie(0);
442 391
443 iounmap(s3c_rtc_base); 392 iounmap(s3c_rtc_base);
@@ -447,7 +396,7 @@ static int s3c_rtc_remove(struct platform_device *dev)
447 return 0; 396 return 0;
448} 397}
449 398
450static int s3c_rtc_probe(struct platform_device *pdev) 399static int __devinit s3c_rtc_probe(struct platform_device *pdev)
451{ 400{
452 struct rtc_device *rtc; 401 struct rtc_device *rtc;
453 struct resource *res; 402 struct resource *res;
@@ -504,7 +453,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
504 pr_debug("s3c2410_rtc: RTCCON=%02x\n", 453 pr_debug("s3c2410_rtc: RTCCON=%02x\n",
505 readb(s3c_rtc_base + S3C2410_RTCCON)); 454 readb(s3c_rtc_base + S3C2410_RTCCON));
506 455
507 s3c_rtc_setfreq(s3c_rtc_freq); 456 s3c_rtc_setfreq(&pdev->dev, 1);
508 457
509 /* register RTC and exit */ 458 /* register RTC and exit */
510 459
@@ -560,7 +509,7 @@ static int s3c_rtc_resume(struct platform_device *pdev)
560 509
561static struct platform_driver s3c2410_rtcdrv = { 510static struct platform_driver s3c2410_rtcdrv = {
562 .probe = s3c_rtc_probe, 511 .probe = s3c_rtc_probe,
563 .remove = s3c_rtc_remove, 512 .remove = __devexit_p(s3c_rtc_remove),
564 .suspend = s3c_rtc_suspend, 513 .suspend = s3c_rtc_suspend,
565 .resume = s3c_rtc_resume, 514 .resume = s3c_rtc_resume,
566 .driver = { 515 .driver = {
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index be9c70d0b193..884b635f028b 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for NEC VR4100 series Real Time Clock unit. 2 * Driver for NEC VR4100 series Real Time Clock unit.
3 * 3 *
4 * Copyright (C) 2003-2006 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2003-2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@
34 34
35MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>"); 35MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>");
36MODULE_DESCRIPTION("NEC VR4100 series RTC driver"); 36MODULE_DESCRIPTION("NEC VR4100 series RTC driver");
37MODULE_LICENSE("GPL"); 37MODULE_LICENSE("GPL v2");
38 38
39/* RTC 1 registers */ 39/* RTC 1 registers */
40#define ETIMELREG 0x00 40#define ETIMELREG 0x00
@@ -82,7 +82,6 @@ static unsigned long epoch = 1970; /* Jan 1 1970 00:00:00 */
82 82
83static DEFINE_SPINLOCK(rtc_lock); 83static DEFINE_SPINLOCK(rtc_lock);
84static char rtc_name[] = "RTC"; 84static char rtc_name[] = "RTC";
85static unsigned long periodic_frequency;
86static unsigned long periodic_count; 85static unsigned long periodic_count;
87static unsigned int alarm_enabled; 86static unsigned int alarm_enabled;
88static int aie_irq = -1; 87static int aie_irq = -1;
@@ -207,10 +206,37 @@ static int vr41xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
207 return 0; 206 return 0;
208} 207}
209 208
210static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 209static int vr41xx_rtc_irq_set_freq(struct device *dev, int freq)
211{ 210{
212 unsigned long count; 211 unsigned long count;
213 212
213 count = RTC_FREQUENCY;
214 do_div(count, freq);
215
216 periodic_count = count;
217
218 spin_lock_irq(&rtc_lock);
219
220 rtc1_write(RTCL1LREG, count);
221 rtc1_write(RTCL1HREG, count >> 16);
222
223 spin_unlock_irq(&rtc_lock);
224
225 return 0;
226}
227
228static int vr41xx_rtc_irq_set_state(struct device *dev, int enabled)
229{
230 if (enabled)
231 enable_irq(pie_irq);
232 else
233 disable_irq(pie_irq);
234
235 return 0;
236}
237
238static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
239{
214 switch (cmd) { 240 switch (cmd) {
215 case RTC_AIE_ON: 241 case RTC_AIE_ON:
216 spin_lock_irq(&rtc_lock); 242 spin_lock_irq(&rtc_lock);
@@ -232,33 +258,6 @@ static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long
232 258
233 spin_unlock_irq(&rtc_lock); 259 spin_unlock_irq(&rtc_lock);
234 break; 260 break;
235 case RTC_PIE_ON:
236 enable_irq(pie_irq);
237 break;
238 case RTC_PIE_OFF:
239 disable_irq(pie_irq);
240 break;
241 case RTC_IRQP_READ:
242 return put_user(periodic_frequency, (unsigned long __user *)arg);
243 break;
244 case RTC_IRQP_SET:
245 if (arg > MAX_PERIODIC_RATE)
246 return -EINVAL;
247
248 periodic_frequency = arg;
249
250 count = RTC_FREQUENCY;
251 do_div(count, arg);
252
253 periodic_count = count;
254
255 spin_lock_irq(&rtc_lock);
256
257 rtc1_write(RTCL1LREG, count);
258 rtc1_write(RTCL1HREG, count >> 16);
259
260 spin_unlock_irq(&rtc_lock);
261 break;
262 case RTC_EPOCH_READ: 261 case RTC_EPOCH_READ:
263 return put_user(epoch, (unsigned long __user *)arg); 262 return put_user(epoch, (unsigned long __user *)arg);
264 case RTC_EPOCH_SET: 263 case RTC_EPOCH_SET:
@@ -309,6 +308,8 @@ static const struct rtc_class_ops vr41xx_rtc_ops = {
309 .set_time = vr41xx_rtc_set_time, 308 .set_time = vr41xx_rtc_set_time,
310 .read_alarm = vr41xx_rtc_read_alarm, 309 .read_alarm = vr41xx_rtc_read_alarm,
311 .set_alarm = vr41xx_rtc_set_alarm, 310 .set_alarm = vr41xx_rtc_set_alarm,
311 .irq_set_freq = vr41xx_rtc_irq_set_freq,
312 .irq_set_state = vr41xx_rtc_irq_set_state,
312}; 313};
313 314
314static int __devinit rtc_probe(struct platform_device *pdev) 315static int __devinit rtc_probe(struct platform_device *pdev)
@@ -346,6 +347,8 @@ static int __devinit rtc_probe(struct platform_device *pdev)
346 goto err_iounmap_all; 347 goto err_iounmap_all;
347 } 348 }
348 349
350 rtc->max_user_freq = MAX_PERIODIC_RATE;
351
349 spin_lock_irq(&rtc_lock); 352 spin_lock_irq(&rtc_lock);
350 353
351 rtc1_write(ECMPLREG, 0); 354 rtc1_write(ECMPLREG, 0);
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 5ab34340919b..79954bd6bfa5 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -15,6 +15,7 @@
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/virtio.h> 16#include <linux/virtio.h>
17#include <linux/virtio_config.h> 17#include <linux/virtio_config.h>
18#include <linux/virtio_console.h>
18#include <linux/interrupt.h> 19#include <linux/interrupt.h>
19#include <linux/virtio_ring.h> 20#include <linux/virtio_ring.h>
20#include <linux/pfn.h> 21#include <linux/pfn.h>
@@ -87,16 +88,20 @@ static u32 kvm_get_features(struct virtio_device *vdev)
87 return features; 88 return features;
88} 89}
89 90
90static void kvm_set_features(struct virtio_device *vdev, u32 features) 91static void kvm_finalize_features(struct virtio_device *vdev)
91{ 92{
92 unsigned int i; 93 unsigned int i, bits;
93 struct kvm_device_desc *desc = to_kvmdev(vdev)->desc; 94 struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
94 /* Second half of bitmap is features we accept. */ 95 /* Second half of bitmap is features we accept. */
95 u8 *out_features = kvm_vq_features(desc) + desc->feature_len; 96 u8 *out_features = kvm_vq_features(desc) + desc->feature_len;
96 97
98 /* Give virtio_ring a chance to accept features. */
99 vring_transport_features(vdev);
100
97 memset(out_features, 0, desc->feature_len); 101 memset(out_features, 0, desc->feature_len);
98 for (i = 0; i < min(desc->feature_len * 8, 32); i++) { 102 bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
99 if (features & (1 << i)) 103 for (i = 0; i < bits; i++) {
104 if (test_bit(i, vdev->features))
100 out_features[i / 8] |= (1 << (i % 8)); 105 out_features[i / 8] |= (1 << (i % 8));
101 } 106 }
102} 107}
@@ -222,7 +227,7 @@ static void kvm_del_vq(struct virtqueue *vq)
222 */ 227 */
223static struct virtio_config_ops kvm_vq_configspace_ops = { 228static struct virtio_config_ops kvm_vq_configspace_ops = {
224 .get_features = kvm_get_features, 229 .get_features = kvm_get_features,
225 .set_features = kvm_set_features, 230 .finalize_features = kvm_finalize_features,
226 .get = kvm_get, 231 .get = kvm_get,
227 .set = kvm_set, 232 .set = kvm_set,
228 .get_status = kvm_get_status, 233 .get_status = kvm_get_status,
@@ -333,6 +338,25 @@ static int __init kvm_devices_init(void)
333 return 0; 338 return 0;
334} 339}
335 340
341/* code for early console output with virtio_console */
342static __init int early_put_chars(u32 vtermno, const char *buf, int count)
343{
344 char scratch[17];
345 unsigned int len = count;
346
347 if (len > sizeof(scratch) - 1)
348 len = sizeof(scratch) - 1;
349 scratch[len] = '\0';
350 memcpy(scratch, buf, len);
351 kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, __pa(scratch));
352 return len;
353}
354
355void s390_virtio_console_init(void)
356{
357 virtio_cons_early_init(early_put_chars);
358}
359
336/* 360/*
337 * We do this after core stuff, but before the drivers. 361 * We do this after core stuff, but before the drivers.
338 */ 362 */
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index c3ad89e302bd..cebb25e36e82 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -3321,7 +3321,7 @@ int qeth_change_mtu(struct net_device *dev, int new_mtu)
3321 struct qeth_card *card; 3321 struct qeth_card *card;
3322 char dbf_text[15]; 3322 char dbf_text[15];
3323 3323
3324 card = netdev_priv(dev); 3324 card = dev->ml_priv;
3325 3325
3326 QETH_DBF_TEXT(TRACE, 4, "chgmtu"); 3326 QETH_DBF_TEXT(TRACE, 4, "chgmtu");
3327 sprintf(dbf_text, "%8x", new_mtu); 3327 sprintf(dbf_text, "%8x", new_mtu);
@@ -3343,7 +3343,7 @@ struct net_device_stats *qeth_get_stats(struct net_device *dev)
3343{ 3343{
3344 struct qeth_card *card; 3344 struct qeth_card *card;
3345 3345
3346 card = netdev_priv(dev); 3346 card = dev->ml_priv;
3347 3347
3348 QETH_DBF_TEXT(TRACE, 5, "getstat"); 3348 QETH_DBF_TEXT(TRACE, 5, "getstat");
3349 3349
@@ -3395,7 +3395,7 @@ void qeth_tx_timeout(struct net_device *dev)
3395{ 3395{
3396 struct qeth_card *card; 3396 struct qeth_card *card;
3397 3397
3398 card = netdev_priv(dev); 3398 card = dev->ml_priv;
3399 card->stats.tx_errors++; 3399 card->stats.tx_errors++;
3400 qeth_schedule_recovery(card); 3400 qeth_schedule_recovery(card);
3401} 3401}
@@ -3403,7 +3403,7 @@ EXPORT_SYMBOL_GPL(qeth_tx_timeout);
3403 3403
3404int qeth_mdio_read(struct net_device *dev, int phy_id, int regnum) 3404int qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
3405{ 3405{
3406 struct qeth_card *card = netdev_priv(dev); 3406 struct qeth_card *card = dev->ml_priv;
3407 int rc = 0; 3407 int rc = 0;
3408 3408
3409 switch (regnum) { 3409 switch (regnum) {
@@ -4253,7 +4253,7 @@ EXPORT_SYMBOL_GPL(qeth_core_get_stats_count);
4253void qeth_core_get_ethtool_stats(struct net_device *dev, 4253void qeth_core_get_ethtool_stats(struct net_device *dev,
4254 struct ethtool_stats *stats, u64 *data) 4254 struct ethtool_stats *stats, u64 *data)
4255{ 4255{
4256 struct qeth_card *card = netdev_priv(dev); 4256 struct qeth_card *card = dev->ml_priv;
4257 data[0] = card->stats.rx_packets - 4257 data[0] = card->stats.rx_packets -
4258 card->perf_stats.initial_rx_packets; 4258 card->perf_stats.initial_rx_packets;
4259 data[1] = card->perf_stats.bufs_rec; 4259 data[1] = card->perf_stats.bufs_rec;
@@ -4313,7 +4313,7 @@ EXPORT_SYMBOL_GPL(qeth_core_get_strings);
4313void qeth_core_get_drvinfo(struct net_device *dev, 4313void qeth_core_get_drvinfo(struct net_device *dev,
4314 struct ethtool_drvinfo *info) 4314 struct ethtool_drvinfo *info)
4315{ 4315{
4316 struct qeth_card *card = netdev_priv(dev); 4316 struct qeth_card *card = dev->ml_priv;
4317 if (card->options.layer2) 4317 if (card->options.layer2)
4318 strcpy(info->driver, "qeth_l2"); 4318 strcpy(info->driver, "qeth_l2");
4319 else 4319 else
@@ -4331,7 +4331,7 @@ EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo);
4331int qeth_core_ethtool_get_settings(struct net_device *netdev, 4331int qeth_core_ethtool_get_settings(struct net_device *netdev,
4332 struct ethtool_cmd *ecmd) 4332 struct ethtool_cmd *ecmd)
4333{ 4333{
4334 struct qeth_card *card = netdev_priv(netdev); 4334 struct qeth_card *card = netdev->ml_priv;
4335 enum qeth_link_types link_type; 4335 enum qeth_link_types link_type;
4336 4336
4337 if ((card->info.type == QETH_CARD_TYPE_IQD) || (card->info.guestlan)) 4337 if ((card->info.type == QETH_CARD_TYPE_IQD) || (card->info.guestlan))
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 3fbc3bdec0c5..a8b069cd9a4c 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -35,7 +35,7 @@ static int qeth_l2_recover(void *);
35 35
36static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 36static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37{ 37{
38 struct qeth_card *card = netdev_priv(dev); 38 struct qeth_card *card = dev->ml_priv;
39 struct mii_ioctl_data *mii_data; 39 struct mii_ioctl_data *mii_data;
40 int rc = 0; 40 int rc = 0;
41 41
@@ -317,7 +317,7 @@ static void qeth_l2_process_vlans(struct qeth_card *card, int clear)
317 317
318static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) 318static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
319{ 319{
320 struct qeth_card *card = netdev_priv(dev); 320 struct qeth_card *card = dev->ml_priv;
321 struct qeth_vlan_vid *id; 321 struct qeth_vlan_vid *id;
322 322
323 QETH_DBF_TEXT_(TRACE, 4, "aid:%d", vid); 323 QETH_DBF_TEXT_(TRACE, 4, "aid:%d", vid);
@@ -334,7 +334,7 @@ static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
334static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) 334static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
335{ 335{
336 struct qeth_vlan_vid *id, *tmpid = NULL; 336 struct qeth_vlan_vid *id, *tmpid = NULL;
337 struct qeth_card *card = netdev_priv(dev); 337 struct qeth_card *card = dev->ml_priv;
338 338
339 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid); 339 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
340 spin_lock_bh(&card->vlanlock); 340 spin_lock_bh(&card->vlanlock);
@@ -566,7 +566,7 @@ static int qeth_l2_request_initial_mac(struct qeth_card *card)
566static int qeth_l2_set_mac_address(struct net_device *dev, void *p) 566static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
567{ 567{
568 struct sockaddr *addr = p; 568 struct sockaddr *addr = p;
569 struct qeth_card *card = netdev_priv(dev); 569 struct qeth_card *card = dev->ml_priv;
570 int rc = 0; 570 int rc = 0;
571 571
572 QETH_DBF_TEXT(TRACE, 3, "setmac"); 572 QETH_DBF_TEXT(TRACE, 3, "setmac");
@@ -590,7 +590,7 @@ static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
590 590
591static void qeth_l2_set_multicast_list(struct net_device *dev) 591static void qeth_l2_set_multicast_list(struct net_device *dev)
592{ 592{
593 struct qeth_card *card = netdev_priv(dev); 593 struct qeth_card *card = dev->ml_priv;
594 struct dev_mc_list *dm; 594 struct dev_mc_list *dm;
595 595
596 if (card->info.type == QETH_CARD_TYPE_OSN) 596 if (card->info.type == QETH_CARD_TYPE_OSN)
@@ -612,7 +612,7 @@ static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
612 int rc; 612 int rc;
613 struct qeth_hdr *hdr = NULL; 613 struct qeth_hdr *hdr = NULL;
614 int elements = 0; 614 int elements = 0;
615 struct qeth_card *card = netdev_priv(dev); 615 struct qeth_card *card = dev->ml_priv;
616 struct sk_buff *new_skb = skb; 616 struct sk_buff *new_skb = skb;
617 int ipv = qeth_get_ip_version(skb); 617 int ipv = qeth_get_ip_version(skb);
618 int cast_type = qeth_get_cast_type(card, skb); 618 int cast_type = qeth_get_cast_type(card, skb);
@@ -767,7 +767,7 @@ static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev,
767 767
768static int qeth_l2_open(struct net_device *dev) 768static int qeth_l2_open(struct net_device *dev)
769{ 769{
770 struct qeth_card *card = netdev_priv(dev); 770 struct qeth_card *card = dev->ml_priv;
771 771
772 QETH_DBF_TEXT(TRACE, 4, "qethopen"); 772 QETH_DBF_TEXT(TRACE, 4, "qethopen");
773 if (card->state != CARD_STATE_SOFTSETUP) 773 if (card->state != CARD_STATE_SOFTSETUP)
@@ -791,7 +791,7 @@ static int qeth_l2_open(struct net_device *dev)
791 791
792static int qeth_l2_stop(struct net_device *dev) 792static int qeth_l2_stop(struct net_device *dev)
793{ 793{
794 struct qeth_card *card = netdev_priv(dev); 794 struct qeth_card *card = dev->ml_priv;
795 795
796 QETH_DBF_TEXT(TRACE, 4, "qethstop"); 796 QETH_DBF_TEXT(TRACE, 4, "qethstop");
797 netif_tx_disable(dev); 797 netif_tx_disable(dev);
@@ -838,7 +838,7 @@ static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
838 838
839static int qeth_l2_ethtool_set_tso(struct net_device *dev, u32 data) 839static int qeth_l2_ethtool_set_tso(struct net_device *dev, u32 data)
840{ 840{
841 struct qeth_card *card = netdev_priv(dev); 841 struct qeth_card *card = dev->ml_priv;
842 842
843 if (data) { 843 if (data) {
844 if (card->options.large_send == QETH_LARGE_SEND_NO) { 844 if (card->options.large_send == QETH_LARGE_SEND_NO) {
@@ -894,7 +894,7 @@ static int qeth_l2_setup_netdev(struct qeth_card *card)
894 if (!card->dev) 894 if (!card->dev)
895 return -ENODEV; 895 return -ENODEV;
896 896
897 card->dev->priv = card; 897 card->dev->ml_priv = card;
898 card->dev->tx_timeout = &qeth_tx_timeout; 898 card->dev->tx_timeout = &qeth_tx_timeout;
899 card->dev->watchdog_timeo = QETH_TX_TIMEOUT; 899 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
900 card->dev->open = qeth_l2_open; 900 card->dev->open = qeth_l2_open;
@@ -1178,7 +1178,7 @@ int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1178 QETH_DBF_TEXT(TRACE, 2, "osnsdmc"); 1178 QETH_DBF_TEXT(TRACE, 2, "osnsdmc");
1179 if (!dev) 1179 if (!dev)
1180 return -ENODEV; 1180 return -ENODEV;
1181 card = netdev_priv(dev); 1181 card = dev->ml_priv;
1182 if (!card) 1182 if (!card)
1183 return -ENODEV; 1183 return -ENODEV;
1184 if ((card->state != CARD_STATE_UP) && 1184 if ((card->state != CARD_STATE_UP) &&
@@ -1201,7 +1201,7 @@ int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1201 *dev = qeth_l2_netdev_by_devno(read_dev_no); 1201 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1202 if (*dev == NULL) 1202 if (*dev == NULL)
1203 return -ENODEV; 1203 return -ENODEV;
1204 card = netdev_priv(*dev); 1204 card = (*dev)->ml_priv;
1205 if (!card) 1205 if (!card)
1206 return -ENODEV; 1206 return -ENODEV;
1207 if ((assist_cb == NULL) || (data_cb == NULL)) 1207 if ((assist_cb == NULL) || (data_cb == NULL))
@@ -1219,7 +1219,7 @@ void qeth_osn_deregister(struct net_device *dev)
1219 QETH_DBF_TEXT(TRACE, 2, "osndereg"); 1219 QETH_DBF_TEXT(TRACE, 2, "osndereg");
1220 if (!dev) 1220 if (!dev)
1221 return; 1221 return;
1222 card = netdev_priv(dev); 1222 card = dev->ml_priv;
1223 if (!card) 1223 if (!card)
1224 return; 1224 return;
1225 card->osn_info.assist_cb = NULL; 1225 card->osn_info.assist_cb = NULL;
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index 38de31b55708..3e1d13857350 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -1813,7 +1813,7 @@ static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
1813static void qeth_l3_vlan_rx_register(struct net_device *dev, 1813static void qeth_l3_vlan_rx_register(struct net_device *dev,
1814 struct vlan_group *grp) 1814 struct vlan_group *grp)
1815{ 1815{
1816 struct qeth_card *card = netdev_priv(dev); 1816 struct qeth_card *card = dev->ml_priv;
1817 unsigned long flags; 1817 unsigned long flags;
1818 1818
1819 QETH_DBF_TEXT(TRACE, 4, "vlanreg"); 1819 QETH_DBF_TEXT(TRACE, 4, "vlanreg");
@@ -1825,7 +1825,7 @@ static void qeth_l3_vlan_rx_register(struct net_device *dev,
1825static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) 1825static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1826{ 1826{
1827 struct net_device *vlandev; 1827 struct net_device *vlandev;
1828 struct qeth_card *card = (struct qeth_card *) dev->priv; 1828 struct qeth_card *card = dev->ml_priv;
1829 struct in_device *in_dev; 1829 struct in_device *in_dev;
1830 1830
1831 if (card->info.type == QETH_CARD_TYPE_IQD) 1831 if (card->info.type == QETH_CARD_TYPE_IQD)
@@ -1851,7 +1851,7 @@ static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1851 1851
1852static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) 1852static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1853{ 1853{
1854 struct qeth_card *card = netdev_priv(dev); 1854 struct qeth_card *card = dev->ml_priv;
1855 unsigned long flags; 1855 unsigned long flags;
1856 1856
1857 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid); 1857 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
@@ -2013,7 +2013,7 @@ static int qeth_l3_verify_vlan_dev(struct net_device *dev,
2013 } 2013 }
2014 } 2014 }
2015 2015
2016 if (rc && !(netdev_priv(vlan_dev_real_dev(dev)) == (void *)card)) 2016 if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
2017 return 0; 2017 return 0;
2018 2018
2019 return rc; 2019 return rc;
@@ -2047,9 +2047,9 @@ static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2047 2047
2048 rc = qeth_l3_verify_dev(dev); 2048 rc = qeth_l3_verify_dev(dev);
2049 if (rc == QETH_REAL_CARD) 2049 if (rc == QETH_REAL_CARD)
2050 card = netdev_priv(dev); 2050 card = dev->ml_priv;
2051 else if (rc == QETH_VLAN_CARD) 2051 else if (rc == QETH_VLAN_CARD)
2052 card = netdev_priv(vlan_dev_real_dev(dev)); 2052 card = vlan_dev_real_dev(dev)->ml_priv;
2053 if (card && card->options.layer2) 2053 if (card && card->options.layer2)
2054 card = NULL; 2054 card = NULL;
2055 QETH_DBF_TEXT_(TRACE, 4, "%d", rc); 2055 QETH_DBF_TEXT_(TRACE, 4, "%d", rc);
@@ -2110,7 +2110,7 @@ static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2110 2110
2111static void qeth_l3_set_multicast_list(struct net_device *dev) 2111static void qeth_l3_set_multicast_list(struct net_device *dev)
2112{ 2112{
2113 struct qeth_card *card = netdev_priv(dev); 2113 struct qeth_card *card = dev->ml_priv;
2114 2114
2115 QETH_DBF_TEXT(TRACE, 3, "setmulti"); 2115 QETH_DBF_TEXT(TRACE, 3, "setmulti");
2116 qeth_l3_delete_mc_addresses(card); 2116 qeth_l3_delete_mc_addresses(card);
@@ -2438,7 +2438,7 @@ static int qeth_l3_arp_flush_cache(struct qeth_card *card)
2438 2438
2439static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 2439static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2440{ 2440{
2441 struct qeth_card *card = netdev_priv(dev); 2441 struct qeth_card *card = dev->ml_priv;
2442 struct qeth_arp_cache_entry arp_entry; 2442 struct qeth_arp_cache_entry arp_entry;
2443 struct mii_ioctl_data *mii_data; 2443 struct mii_ioctl_data *mii_data;
2444 int rc = 0; 2444 int rc = 0;
@@ -2595,7 +2595,7 @@ static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2595 u16 *tag; 2595 u16 *tag;
2596 struct qeth_hdr *hdr = NULL; 2596 struct qeth_hdr *hdr = NULL;
2597 int elements_needed = 0; 2597 int elements_needed = 0;
2598 struct qeth_card *card = netdev_priv(dev); 2598 struct qeth_card *card = dev->ml_priv;
2599 struct sk_buff *new_skb = NULL; 2599 struct sk_buff *new_skb = NULL;
2600 int ipv = qeth_get_ip_version(skb); 2600 int ipv = qeth_get_ip_version(skb);
2601 int cast_type = qeth_get_cast_type(card, skb); 2601 int cast_type = qeth_get_cast_type(card, skb);
@@ -2763,7 +2763,7 @@ tx_drop:
2763 2763
2764static int qeth_l3_open(struct net_device *dev) 2764static int qeth_l3_open(struct net_device *dev)
2765{ 2765{
2766 struct qeth_card *card = netdev_priv(dev); 2766 struct qeth_card *card = dev->ml_priv;
2767 2767
2768 QETH_DBF_TEXT(TRACE, 4, "qethopen"); 2768 QETH_DBF_TEXT(TRACE, 4, "qethopen");
2769 if (card->state != CARD_STATE_SOFTSETUP) 2769 if (card->state != CARD_STATE_SOFTSETUP)
@@ -2780,7 +2780,7 @@ static int qeth_l3_open(struct net_device *dev)
2780 2780
2781static int qeth_l3_stop(struct net_device *dev) 2781static int qeth_l3_stop(struct net_device *dev)
2782{ 2782{
2783 struct qeth_card *card = netdev_priv(dev); 2783 struct qeth_card *card = dev->ml_priv;
2784 2784
2785 QETH_DBF_TEXT(TRACE, 4, "qethstop"); 2785 QETH_DBF_TEXT(TRACE, 4, "qethstop");
2786 netif_tx_disable(dev); 2786 netif_tx_disable(dev);
@@ -2792,14 +2792,14 @@ static int qeth_l3_stop(struct net_device *dev)
2792 2792
2793static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev) 2793static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev)
2794{ 2794{
2795 struct qeth_card *card = netdev_priv(dev); 2795 struct qeth_card *card = dev->ml_priv;
2796 2796
2797 return (card->options.checksum_type == HW_CHECKSUMMING); 2797 return (card->options.checksum_type == HW_CHECKSUMMING);
2798} 2798}
2799 2799
2800static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data) 2800static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
2801{ 2801{
2802 struct qeth_card *card = netdev_priv(dev); 2802 struct qeth_card *card = dev->ml_priv;
2803 enum qeth_card_states old_state; 2803 enum qeth_card_states old_state;
2804 enum qeth_checksum_types csum_type; 2804 enum qeth_checksum_types csum_type;
2805 2805
@@ -2825,7 +2825,7 @@ static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data)
2825 2825
2826static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data) 2826static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data)
2827{ 2827{
2828 struct qeth_card *card = netdev_priv(dev); 2828 struct qeth_card *card = dev->ml_priv;
2829 2829
2830 if (data) { 2830 if (data) {
2831 if (card->options.large_send == QETH_LARGE_SEND_NO) { 2831 if (card->options.large_send == QETH_LARGE_SEND_NO) {
@@ -2915,7 +2915,7 @@ static int qeth_l3_setup_netdev(struct qeth_card *card)
2915 return -ENODEV; 2915 return -ENODEV;
2916 2916
2917 card->dev->hard_start_xmit = qeth_l3_hard_start_xmit; 2917 card->dev->hard_start_xmit = qeth_l3_hard_start_xmit;
2918 card->dev->priv = card; 2918 card->dev->ml_priv = card;
2919 card->dev->tx_timeout = &qeth_tx_timeout; 2919 card->dev->tx_timeout = &qeth_tx_timeout;
2920 card->dev->watchdog_timeo = QETH_TX_TIMEOUT; 2920 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
2921 card->dev->open = qeth_l3_open; 2921 card->dev->open = qeth_l3_open;
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index eb702b96d57c..61f8fdea2d96 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -3525,7 +3525,7 @@ static int ibmvfc_init_crq(struct ibmvfc_host *vhost)
3525 crq->msg_token = dma_map_single(dev, crq->msgs, 3525 crq->msg_token = dma_map_single(dev, crq->msgs,
3526 PAGE_SIZE, DMA_BIDIRECTIONAL); 3526 PAGE_SIZE, DMA_BIDIRECTIONAL);
3527 3527
3528 if (dma_mapping_error(crq->msg_token)) 3528 if (dma_mapping_error(dev, crq->msg_token))
3529 goto map_failed; 3529 goto map_failed;
3530 3530
3531 retrc = rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address, 3531 retrc = rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
@@ -3618,7 +3618,7 @@ static int ibmvfc_alloc_mem(struct ibmvfc_host *vhost)
3618 async_q->size * sizeof(*async_q->msgs), 3618 async_q->size * sizeof(*async_q->msgs),
3619 DMA_BIDIRECTIONAL); 3619 DMA_BIDIRECTIONAL);
3620 3620
3621 if (dma_mapping_error(async_q->msg_token)) { 3621 if (dma_mapping_error(dev, async_q->msg_token)) {
3622 dev_err(dev, "Failed to map async queue\n"); 3622 dev_err(dev, "Failed to map async queue\n");
3623 goto free_async_crq; 3623 goto free_async_crq;
3624 } 3624 }
@@ -3819,6 +3819,20 @@ static int ibmvfc_remove(struct vio_dev *vdev)
3819 return 0; 3819 return 0;
3820} 3820}
3821 3821
3822/**
3823 * ibmvfc_get_desired_dma - Calculate DMA resources needed by the driver
3824 * @vdev: vio device struct
3825 *
3826 * Return value:
3827 * Number of bytes the driver will need to DMA map at the same time in
3828 * order to perform well.
3829 */
3830static unsigned long ibmvfc_get_desired_dma(struct vio_dev *vdev)
3831{
3832 unsigned long pool_dma = max_requests * sizeof(union ibmvfc_iu);
3833 return pool_dma + ((512 * 1024) * driver_template.cmd_per_lun);
3834}
3835
3822static struct vio_device_id ibmvfc_device_table[] __devinitdata = { 3836static struct vio_device_id ibmvfc_device_table[] __devinitdata = {
3823 {"fcp", "IBM,vfc-client"}, 3837 {"fcp", "IBM,vfc-client"},
3824 { "", "" } 3838 { "", "" }
@@ -3829,6 +3843,7 @@ static struct vio_driver ibmvfc_driver = {
3829 .id_table = ibmvfc_device_table, 3843 .id_table = ibmvfc_device_table,
3830 .probe = ibmvfc_probe, 3844 .probe = ibmvfc_probe,
3831 .remove = ibmvfc_remove, 3845 .remove = ibmvfc_remove,
3846 .get_desired_dma = ibmvfc_get_desired_dma,
3832 .driver = { 3847 .driver = {
3833 .name = IBMVFC_NAME, 3848 .name = IBMVFC_NAME,
3834 .owner = THIS_MODULE, 3849 .owner = THIS_MODULE,
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 5d23368a1bce..6b24b9cdb04c 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -72,6 +72,7 @@
72#include <linux/delay.h> 72#include <linux/delay.h>
73#include <asm/firmware.h> 73#include <asm/firmware.h>
74#include <asm/vio.h> 74#include <asm/vio.h>
75#include <asm/firmware.h>
75#include <scsi/scsi.h> 76#include <scsi/scsi.h>
76#include <scsi/scsi_cmnd.h> 77#include <scsi/scsi_cmnd.h>
77#include <scsi/scsi_host.h> 78#include <scsi/scsi_host.h>
@@ -426,8 +427,10 @@ static int map_sg_data(struct scsi_cmnd *cmd,
426 SG_ALL * sizeof(struct srp_direct_buf), 427 SG_ALL * sizeof(struct srp_direct_buf),
427 &evt_struct->ext_list_token, 0); 428 &evt_struct->ext_list_token, 0);
428 if (!evt_struct->ext_list) { 429 if (!evt_struct->ext_list) {
429 sdev_printk(KERN_ERR, cmd->device, 430 if (!firmware_has_feature(FW_FEATURE_CMO))
430 "Can't allocate memory for indirect table\n"); 431 sdev_printk(KERN_ERR, cmd->device,
432 "Can't allocate memory "
433 "for indirect table\n");
431 return 0; 434 return 0;
432 } 435 }
433 } 436 }
@@ -743,7 +746,9 @@ static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
743 srp_cmd->lun = ((u64) lun) << 48; 746 srp_cmd->lun = ((u64) lun) << 48;
744 747
745 if (!map_data_for_srp_cmd(cmnd, evt_struct, srp_cmd, hostdata->dev)) { 748 if (!map_data_for_srp_cmd(cmnd, evt_struct, srp_cmd, hostdata->dev)) {
746 sdev_printk(KERN_ERR, cmnd->device, "couldn't convert cmd to srp_cmd\n"); 749 if (!firmware_has_feature(FW_FEATURE_CMO))
750 sdev_printk(KERN_ERR, cmnd->device,
751 "couldn't convert cmd to srp_cmd\n");
747 free_event_struct(&hostdata->pool, evt_struct); 752 free_event_struct(&hostdata->pool, evt_struct);
748 return SCSI_MLQUEUE_HOST_BUSY; 753 return SCSI_MLQUEUE_HOST_BUSY;
749 } 754 }
@@ -854,8 +859,11 @@ static void send_mad_adapter_info(struct ibmvscsi_host_data *hostdata)
854 sizeof(hostdata->madapter_info), 859 sizeof(hostdata->madapter_info),
855 DMA_BIDIRECTIONAL); 860 DMA_BIDIRECTIONAL);
856 861
857 if (dma_mapping_error(req->buffer)) { 862 if (dma_mapping_error(hostdata->dev, req->buffer)) {
858 dev_err(hostdata->dev, "Unable to map request_buffer for adapter_info!\n"); 863 if (!firmware_has_feature(FW_FEATURE_CMO))
864 dev_err(hostdata->dev,
865 "Unable to map request_buffer for "
866 "adapter_info!\n");
859 free_event_struct(&hostdata->pool, evt_struct); 867 free_event_struct(&hostdata->pool, evt_struct);
860 return; 868 return;
861 } 869 }
@@ -1399,8 +1407,10 @@ static int ibmvscsi_do_host_config(struct ibmvscsi_host_data *hostdata,
1399 length, 1407 length,
1400 DMA_BIDIRECTIONAL); 1408 DMA_BIDIRECTIONAL);
1401 1409
1402 if (dma_mapping_error(host_config->buffer)) { 1410 if (dma_mapping_error(hostdata->dev, host_config->buffer)) {
1403 dev_err(hostdata->dev, "dma_mapping error getting host config\n"); 1411 if (!firmware_has_feature(FW_FEATURE_CMO))
1412 dev_err(hostdata->dev,
1413 "dma_mapping error getting host config\n");
1404 free_event_struct(&hostdata->pool, evt_struct); 1414 free_event_struct(&hostdata->pool, evt_struct);
1405 return -1; 1415 return -1;
1406 } 1416 }
@@ -1604,7 +1614,7 @@ static struct scsi_host_template driver_template = {
1604 .eh_host_reset_handler = ibmvscsi_eh_host_reset_handler, 1614 .eh_host_reset_handler = ibmvscsi_eh_host_reset_handler,
1605 .slave_configure = ibmvscsi_slave_configure, 1615 .slave_configure = ibmvscsi_slave_configure,
1606 .change_queue_depth = ibmvscsi_change_queue_depth, 1616 .change_queue_depth = ibmvscsi_change_queue_depth,
1607 .cmd_per_lun = 16, 1617 .cmd_per_lun = IBMVSCSI_CMDS_PER_LUN_DEFAULT,
1608 .can_queue = IBMVSCSI_MAX_REQUESTS_DEFAULT, 1618 .can_queue = IBMVSCSI_MAX_REQUESTS_DEFAULT,
1609 .this_id = -1, 1619 .this_id = -1,
1610 .sg_tablesize = SG_ALL, 1620 .sg_tablesize = SG_ALL,
@@ -1613,6 +1623,26 @@ static struct scsi_host_template driver_template = {
1613}; 1623};
1614 1624
1615/** 1625/**
1626 * ibmvscsi_get_desired_dma - Calculate IO memory desired by the driver
1627 *
1628 * @vdev: struct vio_dev for the device whose desired IO mem is to be returned
1629 *
1630 * Return value:
1631 * Number of bytes of IO data the driver will need to perform well.
1632 */
1633static unsigned long ibmvscsi_get_desired_dma(struct vio_dev *vdev)
1634{
1635 /* iu_storage data allocated in initialize_event_pool */
1636 unsigned long desired_io = max_requests * sizeof(union viosrp_iu);
1637
1638 /* add io space for sg data */
1639 desired_io += (IBMVSCSI_MAX_SECTORS_DEFAULT *
1640 IBMVSCSI_CMDS_PER_LUN_DEFAULT);
1641
1642 return desired_io;
1643}
1644
1645/**
1616 * Called by bus code for each adapter 1646 * Called by bus code for each adapter
1617 */ 1647 */
1618static int ibmvscsi_probe(struct vio_dev *vdev, const struct vio_device_id *id) 1648static int ibmvscsi_probe(struct vio_dev *vdev, const struct vio_device_id *id)
@@ -1641,7 +1671,7 @@ static int ibmvscsi_probe(struct vio_dev *vdev, const struct vio_device_id *id)
1641 hostdata->host = host; 1671 hostdata->host = host;
1642 hostdata->dev = dev; 1672 hostdata->dev = dev;
1643 atomic_set(&hostdata->request_limit, -1); 1673 atomic_set(&hostdata->request_limit, -1);
1644 hostdata->host->max_sectors = 32 * 8; /* default max I/O 32 pages */ 1674 hostdata->host->max_sectors = IBMVSCSI_MAX_SECTORS_DEFAULT;
1645 1675
1646 rc = ibmvscsi_ops->init_crq_queue(&hostdata->queue, hostdata, max_requests); 1676 rc = ibmvscsi_ops->init_crq_queue(&hostdata->queue, hostdata, max_requests);
1647 if (rc != 0 && rc != H_RESOURCE) { 1677 if (rc != 0 && rc != H_RESOURCE) {
@@ -1735,6 +1765,7 @@ static struct vio_driver ibmvscsi_driver = {
1735 .id_table = ibmvscsi_device_table, 1765 .id_table = ibmvscsi_device_table,
1736 .probe = ibmvscsi_probe, 1766 .probe = ibmvscsi_probe,
1737 .remove = ibmvscsi_remove, 1767 .remove = ibmvscsi_remove,
1768 .get_desired_dma = ibmvscsi_get_desired_dma,
1738 .driver = { 1769 .driver = {
1739 .name = "ibmvscsi", 1770 .name = "ibmvscsi",
1740 .owner = THIS_MODULE, 1771 .owner = THIS_MODULE,
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.h b/drivers/scsi/ibmvscsi/ibmvscsi.h
index 46e850e302c7..2d4339d5e16e 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.h
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.h
@@ -45,6 +45,8 @@ struct Scsi_Host;
45#define MAX_INDIRECT_BUFS 10 45#define MAX_INDIRECT_BUFS 10
46 46
47#define IBMVSCSI_MAX_REQUESTS_DEFAULT 100 47#define IBMVSCSI_MAX_REQUESTS_DEFAULT 100
48#define IBMVSCSI_CMDS_PER_LUN_DEFAULT 16
49#define IBMVSCSI_MAX_SECTORS_DEFAULT 256 /* 32 * 8 = default max I/O 32 pages */
48#define IBMVSCSI_MAX_CMDS_PER_LUN 64 50#define IBMVSCSI_MAX_CMDS_PER_LUN 64
49 51
50/* ------------------------------------------------------------ 52/* ------------------------------------------------------------
diff --git a/drivers/scsi/ibmvscsi/ibmvstgt.c b/drivers/scsi/ibmvscsi/ibmvstgt.c
index 3b9514c8f1f1..2e13ec00172a 100644
--- a/drivers/scsi/ibmvscsi/ibmvstgt.c
+++ b/drivers/scsi/ibmvscsi/ibmvstgt.c
@@ -564,7 +564,7 @@ static int crq_queue_create(struct crq_queue *queue, struct srp_target *target)
564 queue->size * sizeof(*queue->msgs), 564 queue->size * sizeof(*queue->msgs),
565 DMA_BIDIRECTIONAL); 565 DMA_BIDIRECTIONAL);
566 566
567 if (dma_mapping_error(queue->msg_token)) 567 if (dma_mapping_error(target->dev, queue->msg_token))
568 goto map_failed; 568 goto map_failed;
569 569
570 err = h_reg_crq(vport->dma_dev->unit_address, queue->msg_token, 570 err = h_reg_crq(vport->dma_dev->unit_address, queue->msg_token,
diff --git a/drivers/scsi/ibmvscsi/rpa_vscsi.c b/drivers/scsi/ibmvscsi/rpa_vscsi.c
index 182146100dc1..462a8574dad9 100644
--- a/drivers/scsi/ibmvscsi/rpa_vscsi.c
+++ b/drivers/scsi/ibmvscsi/rpa_vscsi.c
@@ -253,7 +253,7 @@ static int rpavscsi_init_crq_queue(struct crq_queue *queue,
253 queue->size * sizeof(*queue->msgs), 253 queue->size * sizeof(*queue->msgs),
254 DMA_BIDIRECTIONAL); 254 DMA_BIDIRECTIONAL);
255 255
256 if (dma_mapping_error(queue->msg_token)) 256 if (dma_mapping_error(hostdata->dev, queue->msg_token))
257 goto map_failed; 257 goto map_failed;
258 258
259 gather_partition_info(); 259 gather_partition_info();
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 538552495d48..b40a673985aa 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -101,8 +101,13 @@ static struct ide_scsi_obj *ide_scsi_get(struct gendisk *disk)
101 101
102 mutex_lock(&idescsi_ref_mutex); 102 mutex_lock(&idescsi_ref_mutex);
103 scsi = ide_scsi_g(disk); 103 scsi = ide_scsi_g(disk);
104 if (scsi) 104 if (scsi) {
105 scsi_host_get(scsi->host); 105 scsi_host_get(scsi->host);
106 if (ide_device_get(scsi->drive)) {
107 scsi_host_put(scsi->host);
108 scsi = NULL;
109 }
110 }
106 mutex_unlock(&idescsi_ref_mutex); 111 mutex_unlock(&idescsi_ref_mutex);
107 return scsi; 112 return scsi;
108} 113}
@@ -110,6 +115,7 @@ static struct ide_scsi_obj *ide_scsi_get(struct gendisk *disk)
110static void ide_scsi_put(struct ide_scsi_obj *scsi) 115static void ide_scsi_put(struct ide_scsi_obj *scsi)
111{ 116{
112 mutex_lock(&idescsi_ref_mutex); 117 mutex_lock(&idescsi_ref_mutex);
118 ide_device_put(scsi->drive);
113 scsi_host_put(scsi->host); 119 scsi_host_put(scsi->host);
114 mutex_unlock(&idescsi_ref_mutex); 120 mutex_unlock(&idescsi_ref_mutex);
115} 121}
@@ -201,15 +207,15 @@ static int idescsi_check_condition(ide_drive_t *drive,
201 207
202 /* stuff a sense request in front of our current request */ 208 /* stuff a sense request in front of our current request */
203 pc = kzalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC); 209 pc = kzalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC);
204 rq = kmalloc(sizeof(struct request), GFP_ATOMIC); 210 rq = blk_get_request(drive->queue, READ, GFP_ATOMIC);
205 buf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC); 211 buf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC);
206 if (!pc || !rq || !buf) { 212 if (!pc || !rq || !buf) {
207 kfree(buf); 213 kfree(buf);
208 kfree(rq); 214 if (rq)
215 blk_put_request(rq);
209 kfree(pc); 216 kfree(pc);
210 return -ENOMEM; 217 return -ENOMEM;
211 } 218 }
212 blk_rq_init(NULL, rq);
213 rq->special = (char *) pc; 219 rq->special = (char *) pc;
214 pc->rq = rq; 220 pc->rq = rq;
215 pc->buf = buf; 221 pc->buf = buf;
@@ -226,6 +232,7 @@ static int idescsi_check_condition(ide_drive_t *drive,
226 ide_scsi_hex_dump(pc->c, 6); 232 ide_scsi_hex_dump(pc->c, 6);
227 } 233 }
228 rq->rq_disk = scsi->disk; 234 rq->rq_disk = scsi->disk;
235 rq->ref_count++;
229 memcpy(rq->cmd, pc->c, 12); 236 memcpy(rq->cmd, pc->c, 12);
230 ide_do_drive_cmd(drive, rq); 237 ide_do_drive_cmd(drive, rq);
231 return 0; 238 return 0;
@@ -272,7 +279,7 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
272 SCSI_SENSE_BUFFERSIZE); 279 SCSI_SENSE_BUFFERSIZE);
273 kfree(pc->buf); 280 kfree(pc->buf);
274 kfree(pc); 281 kfree(pc);
275 kfree(rq); 282 blk_put_request(rq);
276 pc = opc; 283 pc = opc;
277 rq = pc->rq; 284 rq = pc->rq;
278 pc->scsi_cmd->result = (CHECK_CONDITION << 1) | 285 pc->scsi_cmd->result = (CHECK_CONDITION << 1) |
@@ -303,7 +310,7 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
303 pc->done(pc->scsi_cmd); 310 pc->done(pc->scsi_cmd);
304 spin_unlock_irqrestore(host->host_lock, flags); 311 spin_unlock_irqrestore(host->host_lock, flags);
305 kfree(pc); 312 kfree(pc);
306 kfree(rq); 313 blk_put_request(rq);
307 scsi->pc = NULL; 314 scsi->pc = NULL;
308 return 0; 315 return 0;
309} 316}
@@ -577,6 +584,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
577 ide_drive_t *drive = scsi->drive; 584 ide_drive_t *drive = scsi->drive;
578 struct request *rq = NULL; 585 struct request *rq = NULL;
579 struct ide_atapi_pc *pc = NULL; 586 struct ide_atapi_pc *pc = NULL;
587 int write = cmd->sc_data_direction == DMA_TO_DEVICE;
580 588
581 if (!drive) { 589 if (!drive) {
582 scmd_printk (KERN_ERR, cmd, "drive not present\n"); 590 scmd_printk (KERN_ERR, cmd, "drive not present\n");
@@ -584,7 +592,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
584 } 592 }
585 scsi = drive_to_idescsi(drive); 593 scsi = drive_to_idescsi(drive);
586 pc = kmalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC); 594 pc = kmalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC);
587 rq = kmalloc(sizeof(struct request), GFP_ATOMIC); 595 rq = blk_get_request(drive->queue, write, GFP_ATOMIC);
588 if (rq == NULL || pc == NULL) { 596 if (rq == NULL || pc == NULL) {
589 printk (KERN_ERR "ide-scsi: %s: out of memory\n", drive->name); 597 printk (KERN_ERR "ide-scsi: %s: out of memory\n", drive->name);
590 goto abort; 598 goto abort;
@@ -614,17 +622,18 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
614 } 622 }
615 } 623 }
616 624
617 blk_rq_init(NULL, rq);
618 rq->special = (char *) pc; 625 rq->special = (char *) pc;
619 rq->cmd_type = REQ_TYPE_SPECIAL; 626 rq->cmd_type = REQ_TYPE_SPECIAL;
620 spin_unlock_irq(host->host_lock); 627 spin_unlock_irq(host->host_lock);
628 rq->ref_count++;
621 memcpy(rq->cmd, pc->c, 12); 629 memcpy(rq->cmd, pc->c, 12);
622 blk_execute_rq_nowait(drive->queue, scsi->disk, rq, 0, NULL); 630 blk_execute_rq_nowait(drive->queue, scsi->disk, rq, 0, NULL);
623 spin_lock_irq(host->host_lock); 631 spin_lock_irq(host->host_lock);
624 return 0; 632 return 0;
625abort: 633abort:
626 kfree (pc); 634 kfree (pc);
627 kfree (rq); 635 if (rq)
636 blk_put_request(rq);
628 cmd->result = DID_ERROR << 16; 637 cmd->result = DID_ERROR << 16;
629 done(cmd); 638 done(cmd);
630 return 0; 639 return 0;
@@ -672,7 +681,9 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
672 681
673 if (blk_sense_request(scsi->pc->rq)) 682 if (blk_sense_request(scsi->pc->rq))
674 kfree(scsi->pc->buf); 683 kfree(scsi->pc->buf);
675 kfree(scsi->pc->rq); 684 /* we need to call blk_put_request twice. */
685 blk_put_request(scsi->pc->rq);
686 blk_put_request(scsi->pc->rq);
676 kfree(scsi->pc); 687 kfree(scsi->pc);
677 scsi->pc = NULL; 688 scsi->pc = NULL;
678 689
@@ -724,7 +735,7 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
724 kfree(scsi->pc->buf); 735 kfree(scsi->pc->buf);
725 kfree(scsi->pc); 736 kfree(scsi->pc);
726 scsi->pc = NULL; 737 scsi->pc = NULL;
727 kfree(req); 738 blk_put_request(req);
728 739
729 /* now nuke the drive queue */ 740 /* now nuke the drive queue */
730 while ((req = elv_next_request(drive->queue))) { 741 while ((req = elv_next_request(drive->queue))) {
diff --git a/drivers/scsi/sun_esp.c b/drivers/scsi/sun_esp.c
index 2c87db98cdfb..f9cf70151366 100644
--- a/drivers/scsi/sun_esp.c
+++ b/drivers/scsi/sun_esp.c
@@ -7,6 +7,7 @@
7#include <linux/types.h> 7#include <linux/types.h>
8#include <linux/delay.h> 8#include <linux/delay.h>
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/mm.h>
10#include <linux/init.h> 11#include <linux/init.h>
11 12
12#include <asm/irq.h> 13#include <asm/irq.h>
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 27f34a9f9cb7..a97f1ae11f78 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -1293,7 +1293,18 @@ receive_chars(struct uart_8250_port *up, unsigned int *status)
1293 char flag; 1293 char flag;
1294 1294
1295 do { 1295 do {
1296 ch = serial_inp(up, UART_RX); 1296 if (likely(lsr & UART_LSR_DR))
1297 ch = serial_inp(up, UART_RX);
1298 else
1299 /*
1300 * Intel 82571 has a Serial Over Lan device that will
1301 * set UART_LSR_BI without setting UART_LSR_DR when
1302 * it receives a break. To avoid reading from the
1303 * receive buffer without UART_LSR_DR bit set, we
1304 * just force the read character to be 0
1305 */
1306 ch = 0;
1307
1297 flag = TTY_NORMAL; 1308 flag = TTY_NORMAL;
1298 up->port.icount.rx++; 1309 up->port.icount.rx++;
1299 1310
@@ -1342,7 +1353,7 @@ receive_chars(struct uart_8250_port *up, unsigned int *status)
1342 1353
1343ignore_char: 1354ignore_char:
1344 lsr = serial_inp(up, UART_LSR); 1355 lsr = serial_inp(up, UART_LSR);
1345 } while ((lsr & UART_LSR_DR) && (max_count-- > 0)); 1356 } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0));
1346 spin_unlock(&up->port.lock); 1357 spin_unlock(&up->port.lock);
1347 tty_flip_buffer_push(tty); 1358 tty_flip_buffer_push(tty);
1348 spin_lock(&up->port.lock); 1359 spin_lock(&up->port.lock);
@@ -1425,7 +1436,7 @@ serial8250_handle_port(struct uart_8250_port *up)
1425 1436
1426 DEBUG_INTR("status = %x...", status); 1437 DEBUG_INTR("status = %x...", status);
1427 1438
1428 if (status & UART_LSR_DR) 1439 if (status & (UART_LSR_DR | UART_LSR_BI))
1429 receive_chars(up, &status); 1440 receive_chars(up, &status);
1430 check_modem_status(up); 1441 check_modem_status(up);
1431 if (status & UART_LSR_THRE) 1442 if (status & UART_LSR_THRE)
diff --git a/drivers/serial/8250_gsc.c b/drivers/serial/8250_gsc.c
index 4eb7437a404a..0416ad3bc127 100644
--- a/drivers/serial/8250_gsc.c
+++ b/drivers/serial/8250_gsc.c
@@ -119,3 +119,5 @@ int __init probe_serial_gsc(void)
119} 119}
120 120
121module_init(probe_serial_gsc); 121module_init(probe_serial_gsc);
122
123MODULE_LICENSE("GPL");
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index 1b36087665a2..c2f23933155b 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -767,6 +767,9 @@ pci_default_setup(struct serial_private *priv, struct pciserial_board *board,
767#define PCI_SUBDEVICE_ID_POCTAL232 0x0308 767#define PCI_SUBDEVICE_ID_POCTAL232 0x0308
768#define PCI_SUBDEVICE_ID_POCTAL422 0x0408 768#define PCI_SUBDEVICE_ID_POCTAL422 0x0408
769 769
770/* Unknown vendors/cards - this should not be in linux/pci_ids.h */
771#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584
772
770/* 773/*
771 * Master list of serial port init/setup/exit quirks. 774 * Master list of serial port init/setup/exit quirks.
772 * This does not describe the general nature of the port. 775 * This does not describe the general nature of the port.
@@ -882,6 +885,15 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
882 }, 885 },
883 { 886 {
884 .vendor = PCI_VENDOR_ID_PLX, 887 .vendor = PCI_VENDOR_ID_PLX,
888 .device = PCI_DEVICE_ID_PLX_9050,
889 .subvendor = PCI_VENDOR_ID_PLX,
890 .subdevice = PCI_SUBDEVICE_ID_UNKNOWN_0x1584,
891 .init = pci_plx9050_init,
892 .setup = pci_default_setup,
893 .exit = __devexit_p(pci_plx9050_exit),
894 },
895 {
896 .vendor = PCI_VENDOR_ID_PLX,
885 .device = PCI_DEVICE_ID_PLX_ROMULUS, 897 .device = PCI_DEVICE_ID_PLX_ROMULUS,
886 .subvendor = PCI_VENDOR_ID_PLX, 898 .subvendor = PCI_VENDOR_ID_PLX,
887 .subdevice = PCI_DEVICE_ID_PLX_ROMULUS, 899 .subdevice = PCI_DEVICE_ID_PLX_ROMULUS,
@@ -2197,6 +2209,11 @@ static struct pci_device_id serial_pci_tbl[] = {
2197 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_1077, 2209 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_1077,
2198 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2210 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
2199 pbn_b2_4_921600 }, 2211 pbn_b2_4_921600 },
2212 /* Unknown card - subdevice 0x1584 */
2213 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
2214 PCI_VENDOR_ID_PLX,
2215 PCI_SUBDEVICE_ID_UNKNOWN_0x1584, 0, 0,
2216 pbn_b0_4_115200 },
2200 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, 2217 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
2201 PCI_SUBVENDOR_ID_KEYSPAN, 2218 PCI_SUBVENDOR_ID_KEYSPAN,
2202 PCI_SUBDEVICE_ID_KEYSPAN_SX2, 0, 0, 2219 PCI_SUBDEVICE_ID_KEYSPAN_SX2, 0, 0,
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 8fc7451c0049..3b4a14e355c1 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -942,22 +942,6 @@ config SERIAL_IP22_ZILOG_CONSOLE
942 depends on SERIAL_IP22_ZILOG=y 942 depends on SERIAL_IP22_ZILOG=y
943 select SERIAL_CORE_CONSOLE 943 select SERIAL_CORE_CONSOLE
944 944
945config V850E_UART
946 bool "NEC V850E on-chip UART support"
947 depends on V850E_MA1 || V850E_ME2 || V850E_TEG || V850E2_ANNA || V850E_AS85EP1
948 select SERIAL_CORE
949 default y
950
951config V850E_UARTB
952 bool
953 depends on V850E_UART && V850E_ME2
954 default y
955
956config V850E_UART_CONSOLE
957 bool "Use NEC V850E on-chip UART for console"
958 depends on V850E_UART
959 select SERIAL_CORE_CONSOLE
960
961config SERIAL_SH_SCI 945config SERIAL_SH_SCI
962 tristate "SuperH SCI(F) serial port support" 946 tristate "SuperH SCI(F) serial port support"
963 depends on SUPERH || H8300 947 depends on SUPERH || H8300
diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c
index 1ff80de177db..a4f86927a74b 100644
--- a/drivers/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/serial/cpm_uart/cpm_uart_core.c
@@ -435,10 +435,13 @@ static void cpm_uart_shutdown(struct uart_port *port)
435 } 435 }
436 436
437 /* Shut them really down and reinit buffer descriptors */ 437 /* Shut them really down and reinit buffer descriptors */
438 if (IS_SMC(pinfo)) 438 if (IS_SMC(pinfo)) {
439 out_be16(&pinfo->smcup->smc_brkcr, 0);
439 cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX); 440 cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX);
440 else 441 } else {
442 out_be16(&pinfo->sccup->scc_brkcr, 0);
441 cpm_line_cr_cmd(pinfo, CPM_CR_GRA_STOP_TX); 443 cpm_line_cr_cmd(pinfo, CPM_CR_GRA_STOP_TX);
444 }
442 445
443 cpm_uart_initbd(pinfo); 446 cpm_uart_initbd(pinfo);
444 } 447 }
@@ -554,9 +557,11 @@ static void cpm_uart_set_termios(struct uart_port *port,
554 * enables, because we want to put them back if they were 557 * enables, because we want to put them back if they were
555 * present. 558 * present.
556 */ 559 */
557 prev_mode = in_be16(&smcp->smc_smcmr); 560 prev_mode = in_be16(&smcp->smc_smcmr) & (SMCMR_REN | SMCMR_TEN);
558 out_be16(&smcp->smc_smcmr, smcr_mk_clen(bits) | cval | SMCMR_SM_UART); 561 /* Output in *one* operation, so we don't interrupt RX/TX if they
559 setbits16(&smcp->smc_smcmr, (prev_mode & (SMCMR_REN | SMCMR_TEN))); 562 * were already enabled. */
563 out_be16(&smcp->smc_smcmr, smcr_mk_clen(bits) | cval |
564 SMCMR_SM_UART | prev_mode);
560 } else { 565 } else {
561 out_be16(&sccp->scc_psmr, (sbits << 12) | scval); 566 out_be16(&sccp->scc_psmr, (sbits << 12) | scval);
562 } 567 }
@@ -1198,12 +1203,14 @@ static int __init cpm_uart_console_setup(struct console *co, char *options)
1198 udbg_putc = NULL; 1203 udbg_putc = NULL;
1199#endif 1204#endif
1200 1205
1201 cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX);
1202
1203 if (IS_SMC(pinfo)) { 1206 if (IS_SMC(pinfo)) {
1207 out_be16(&pinfo->smcup->smc_brkcr, 0);
1208 cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX);
1204 clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX | SMCM_TX); 1209 clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX | SMCM_TX);
1205 clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN); 1210 clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN);
1206 } else { 1211 } else {
1212 out_be16(&pinfo->sccup->scc_brkcr, 0);
1213 cpm_line_cr_cmd(pinfo, CPM_CR_GRA_STOP_TX);
1207 clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX); 1214 clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX);
1208 clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); 1215 clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
1209 } 1216 }
diff --git a/drivers/serial/dz.c b/drivers/serial/dz.c
index a81d2c2ff8a2..6042b87797a1 100644
--- a/drivers/serial/dz.c
+++ b/drivers/serial/dz.c
@@ -642,6 +642,26 @@ static void dz_set_termios(struct uart_port *uport, struct ktermios *termios,
642 spin_unlock_irqrestore(&dport->port.lock, flags); 642 spin_unlock_irqrestore(&dport->port.lock, flags);
643} 643}
644 644
645/*
646 * Hack alert!
647 * Required solely so that the initial PROM-based console
648 * works undisturbed in parallel with this one.
649 */
650static void dz_pm(struct uart_port *uport, unsigned int state,
651 unsigned int oldstate)
652{
653 struct dz_port *dport = to_dport(uport);
654 unsigned long flags;
655
656 spin_lock_irqsave(&dport->port.lock, flags);
657 if (state < 3)
658 dz_start_tx(&dport->port);
659 else
660 dz_stop_tx(&dport->port);
661 spin_unlock_irqrestore(&dport->port.lock, flags);
662}
663
664
645static const char *dz_type(struct uart_port *uport) 665static const char *dz_type(struct uart_port *uport)
646{ 666{
647 return "DZ"; 667 return "DZ";
@@ -738,6 +758,7 @@ static struct uart_ops dz_ops = {
738 .startup = dz_startup, 758 .startup = dz_startup,
739 .shutdown = dz_shutdown, 759 .shutdown = dz_shutdown,
740 .set_termios = dz_set_termios, 760 .set_termios = dz_set_termios,
761 .pm = dz_pm,
741 .type = dz_type, 762 .type = dz_type,
742 .release_port = dz_release_port, 763 .release_port = dz_release_port,
743 .request_port = dz_request_port, 764 .request_port = dz_request_port,
@@ -861,7 +882,10 @@ static int __init dz_console_setup(struct console *co, char *options)
861 if (ret) 882 if (ret)
862 return ret; 883 return ret;
863 884
885 spin_lock_init(&dport->port.lock); /* For dz_pm(). */
886
864 dz_reset(dport); 887 dz_reset(dport);
888 dz_pm(uport, 0, -1);
865 889
866 if (options) 890 if (options)
867 uart_parse_options(options, &baud, &parity, &bits, &flow); 891 uart_parse_options(options, &baud, &parity, &bits, &flow);
diff --git a/drivers/serial/zs.c b/drivers/serial/zs.c
index bd45b6230fd8..9e6a873f8203 100644
--- a/drivers/serial/zs.c
+++ b/drivers/serial/zs.c
@@ -787,7 +787,6 @@ static int zs_startup(struct uart_port *uport)
787 zport->regs[1] &= ~RxINT_MASK; 787 zport->regs[1] &= ~RxINT_MASK;
788 zport->regs[1] |= RxINT_ALL | TxINT_ENAB | EXT_INT_ENAB; 788 zport->regs[1] |= RxINT_ALL | TxINT_ENAB | EXT_INT_ENAB;
789 zport->regs[3] |= RxENABLE; 789 zport->regs[3] |= RxENABLE;
790 zport->regs[5] |= TxENAB;
791 zport->regs[15] |= BRKIE; 790 zport->regs[15] |= BRKIE;
792 write_zsreg(zport, R1, zport->regs[1]); 791 write_zsreg(zport, R1, zport->regs[1]);
793 write_zsreg(zport, R3, zport->regs[3]); 792 write_zsreg(zport, R3, zport->regs[3]);
@@ -814,7 +813,6 @@ static void zs_shutdown(struct uart_port *uport)
814 813
815 spin_lock_irqsave(&scc->zlock, flags); 814 spin_lock_irqsave(&scc->zlock, flags);
816 815
817 zport->regs[5] &= ~TxENAB;
818 zport->regs[3] &= ~RxENABLE; 816 zport->regs[3] &= ~RxENABLE;
819 write_zsreg(zport, R5, zport->regs[5]); 817 write_zsreg(zport, R5, zport->regs[5]);
820 write_zsreg(zport, R3, zport->regs[3]); 818 write_zsreg(zport, R3, zport->regs[3]);
@@ -959,6 +957,23 @@ static void zs_set_termios(struct uart_port *uport, struct ktermios *termios,
959 spin_unlock_irqrestore(&scc->zlock, flags); 957 spin_unlock_irqrestore(&scc->zlock, flags);
960} 958}
961 959
960/*
961 * Hack alert!
962 * Required solely so that the initial PROM-based console
963 * works undisturbed in parallel with this one.
964 */
965static void zs_pm(struct uart_port *uport, unsigned int state,
966 unsigned int oldstate)
967{
968 struct zs_port *zport = to_zport(uport);
969
970 if (state < 3)
971 zport->regs[5] |= TxENAB;
972 else
973 zport->regs[5] &= ~TxENAB;
974 write_zsreg(zport, R5, zport->regs[5]);
975}
976
962 977
963static const char *zs_type(struct uart_port *uport) 978static const char *zs_type(struct uart_port *uport)
964{ 979{
@@ -1041,6 +1056,7 @@ static struct uart_ops zs_ops = {
1041 .startup = zs_startup, 1056 .startup = zs_startup,
1042 .shutdown = zs_shutdown, 1057 .shutdown = zs_shutdown,
1043 .set_termios = zs_set_termios, 1058 .set_termios = zs_set_termios,
1059 .pm = zs_pm,
1044 .type = zs_type, 1060 .type = zs_type,
1045 .release_port = zs_release_port, 1061 .release_port = zs_release_port,
1046 .request_port = zs_request_port, 1062 .request_port = zs_request_port,
@@ -1190,6 +1206,7 @@ static int __init zs_console_setup(struct console *co, char *options)
1190 return ret; 1206 return ret;
1191 1207
1192 zs_reset(zport); 1208 zs_reset(zport);
1209 zs_pm(uport, 0, -1);
1193 1210
1194 if (options) 1211 if (options)
1195 uart_parse_options(options, &baud, &parity, &bits, &flow); 1212 uart_parse_options(options, &baud, &parity, &bits, &flow);
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 66ec5d8808de..2303521b4f09 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -49,25 +49,26 @@ config SPI_MASTER
49 controller and the protocol drivers for the SPI slave chips 49 controller and the protocol drivers for the SPI slave chips
50 that are connected. 50 that are connected.
51 51
52if SPI_MASTER
53
52comment "SPI Master Controller Drivers" 54comment "SPI Master Controller Drivers"
53 depends on SPI_MASTER
54 55
55config SPI_ATMEL 56config SPI_ATMEL
56 tristate "Atmel SPI Controller" 57 tristate "Atmel SPI Controller"
57 depends on (ARCH_AT91 || AVR32) && SPI_MASTER 58 depends on (ARCH_AT91 || AVR32)
58 help 59 help
59 This selects a driver for the Atmel SPI Controller, present on 60 This selects a driver for the Atmel SPI Controller, present on
60 many AT32 (AVR32) and AT91 (ARM) chips. 61 many AT32 (AVR32) and AT91 (ARM) chips.
61 62
62config SPI_BFIN 63config SPI_BFIN
63 tristate "SPI controller driver for ADI Blackfin5xx" 64 tristate "SPI controller driver for ADI Blackfin5xx"
64 depends on SPI_MASTER && BLACKFIN 65 depends on BLACKFIN
65 help 66 help
66 This is the SPI controller master driver for Blackfin 5xx processor. 67 This is the SPI controller master driver for Blackfin 5xx processor.
67 68
68config SPI_AU1550 69config SPI_AU1550
69 tristate "Au1550/Au12x0 SPI Controller" 70 tristate "Au1550/Au12x0 SPI Controller"
70 depends on SPI_MASTER && (SOC_AU1550 || SOC_AU1200) && EXPERIMENTAL 71 depends on (SOC_AU1550 || SOC_AU1200) && EXPERIMENTAL
71 select SPI_BITBANG 72 select SPI_BITBANG
72 help 73 help
73 If you say yes to this option, support will be included for the 74 If you say yes to this option, support will be included for the
@@ -78,7 +79,6 @@ config SPI_AU1550
78 79
79config SPI_BITBANG 80config SPI_BITBANG
80 tristate "Bitbanging SPI master" 81 tristate "Bitbanging SPI master"
81 depends on SPI_MASTER && EXPERIMENTAL
82 help 82 help
83 With a few GPIO pins, your system can bitbang the SPI protocol. 83 With a few GPIO pins, your system can bitbang the SPI protocol.
84 Select this to get SPI support through I/O pins (GPIO, parallel 84 Select this to get SPI support through I/O pins (GPIO, parallel
@@ -92,7 +92,7 @@ config SPI_BITBANG
92 92
93config SPI_BUTTERFLY 93config SPI_BUTTERFLY
94 tristate "Parallel port adapter for AVR Butterfly (DEVELOPMENT)" 94 tristate "Parallel port adapter for AVR Butterfly (DEVELOPMENT)"
95 depends on SPI_MASTER && PARPORT && EXPERIMENTAL 95 depends on PARPORT
96 select SPI_BITBANG 96 select SPI_BITBANG
97 help 97 help
98 This uses a custom parallel port cable to connect to an AVR 98 This uses a custom parallel port cable to connect to an AVR
@@ -102,14 +102,14 @@ config SPI_BUTTERFLY
102 102
103config SPI_IMX 103config SPI_IMX
104 tristate "Freescale iMX SPI controller" 104 tristate "Freescale iMX SPI controller"
105 depends on SPI_MASTER && ARCH_IMX && EXPERIMENTAL 105 depends on ARCH_IMX && EXPERIMENTAL
106 help 106 help
107 This enables using the Freescale iMX SPI controller in master 107 This enables using the Freescale iMX SPI controller in master
108 mode. 108 mode.
109 109
110config SPI_LM70_LLP 110config SPI_LM70_LLP
111 tristate "Parallel port adapter for LM70 eval board (DEVELOPMENT)" 111 tristate "Parallel port adapter for LM70 eval board (DEVELOPMENT)"
112 depends on SPI_MASTER && PARPORT && EXPERIMENTAL 112 depends on PARPORT && EXPERIMENTAL
113 select SPI_BITBANG 113 select SPI_BITBANG
114 help 114 help
115 This driver supports the NS LM70 LLP Evaluation Board, 115 This driver supports the NS LM70 LLP Evaluation Board,
@@ -118,14 +118,14 @@ config SPI_LM70_LLP
118 118
119config SPI_MPC52xx_PSC 119config SPI_MPC52xx_PSC
120 tristate "Freescale MPC52xx PSC SPI controller" 120 tristate "Freescale MPC52xx PSC SPI controller"
121 depends on SPI_MASTER && PPC_MPC52xx && EXPERIMENTAL 121 depends on PPC_MPC52xx && EXPERIMENTAL
122 help 122 help
123 This enables using the Freescale MPC52xx Programmable Serial 123 This enables using the Freescale MPC52xx Programmable Serial
124 Controller in master SPI mode. 124 Controller in master SPI mode.
125 125
126config SPI_MPC83xx 126config SPI_MPC83xx
127 tristate "Freescale MPC83xx/QUICC Engine SPI controller" 127 tristate "Freescale MPC83xx/QUICC Engine SPI controller"
128 depends on SPI_MASTER && (PPC_83xx || QUICC_ENGINE) && EXPERIMENTAL 128 depends on (PPC_83xx || QUICC_ENGINE) && EXPERIMENTAL
129 help 129 help
130 This enables using the Freescale MPC83xx and QUICC Engine SPI 130 This enables using the Freescale MPC83xx and QUICC Engine SPI
131 controllers in master mode. 131 controllers in master mode.
@@ -137,21 +137,21 @@ config SPI_MPC83xx
137 137
138config SPI_OMAP_UWIRE 138config SPI_OMAP_UWIRE
139 tristate "OMAP1 MicroWire" 139 tristate "OMAP1 MicroWire"
140 depends on SPI_MASTER && ARCH_OMAP1 140 depends on ARCH_OMAP1
141 select SPI_BITBANG 141 select SPI_BITBANG
142 help 142 help
143 This hooks up to the MicroWire controller on OMAP1 chips. 143 This hooks up to the MicroWire controller on OMAP1 chips.
144 144
145config SPI_OMAP24XX 145config SPI_OMAP24XX
146 tristate "McSPI driver for OMAP24xx/OMAP34xx" 146 tristate "McSPI driver for OMAP24xx/OMAP34xx"
147 depends on SPI_MASTER && (ARCH_OMAP24XX || ARCH_OMAP34XX) 147 depends on ARCH_OMAP24XX || ARCH_OMAP34XX
148 help 148 help
149 SPI master controller for OMAP24xx/OMAP34xx Multichannel SPI 149 SPI master controller for OMAP24xx/OMAP34xx Multichannel SPI
150 (McSPI) modules. 150 (McSPI) modules.
151 151
152config SPI_PXA2XX 152config SPI_PXA2XX
153 tristate "PXA2xx SSP SPI master" 153 tristate "PXA2xx SSP SPI master"
154 depends on SPI_MASTER && ARCH_PXA && EXPERIMENTAL 154 depends on ARCH_PXA && EXPERIMENTAL
155 select PXA_SSP 155 select PXA_SSP
156 help 156 help
157 This enables using a PXA2xx SSP port as a SPI master controller. 157 This enables using a PXA2xx SSP port as a SPI master controller.
@@ -160,14 +160,14 @@ config SPI_PXA2XX
160 160
161config SPI_S3C24XX 161config SPI_S3C24XX
162 tristate "Samsung S3C24XX series SPI" 162 tristate "Samsung S3C24XX series SPI"
163 depends on SPI_MASTER && ARCH_S3C2410 && EXPERIMENTAL 163 depends on ARCH_S3C2410 && EXPERIMENTAL
164 select SPI_BITBANG 164 select SPI_BITBANG
165 help 165 help
166 SPI driver for Samsung S3C24XX series ARM SoCs 166 SPI driver for Samsung S3C24XX series ARM SoCs
167 167
168config SPI_S3C24XX_GPIO 168config SPI_S3C24XX_GPIO
169 tristate "Samsung S3C24XX series SPI by GPIO" 169 tristate "Samsung S3C24XX series SPI by GPIO"
170 depends on SPI_MASTER && ARCH_S3C2410 && EXPERIMENTAL 170 depends on ARCH_S3C2410 && EXPERIMENTAL
171 select SPI_BITBANG 171 select SPI_BITBANG
172 help 172 help
173 SPI driver for Samsung S3C24XX series ARM SoCs using 173 SPI driver for Samsung S3C24XX series ARM SoCs using
@@ -177,20 +177,20 @@ config SPI_S3C24XX_GPIO
177 177
178config SPI_SH_SCI 178config SPI_SH_SCI
179 tristate "SuperH SCI SPI controller" 179 tristate "SuperH SCI SPI controller"
180 depends on SPI_MASTER && SUPERH 180 depends on SUPERH
181 select SPI_BITBANG 181 select SPI_BITBANG
182 help 182 help
183 SPI driver for SuperH SCI blocks. 183 SPI driver for SuperH SCI blocks.
184 184
185config SPI_TXX9 185config SPI_TXX9
186 tristate "Toshiba TXx9 SPI controller" 186 tristate "Toshiba TXx9 SPI controller"
187 depends on SPI_MASTER && GENERIC_GPIO && CPU_TX49XX 187 depends on GENERIC_GPIO && CPU_TX49XX
188 help 188 help
189 SPI driver for Toshiba TXx9 MIPS SoCs 189 SPI driver for Toshiba TXx9 MIPS SoCs
190 190
191config SPI_XILINX 191config SPI_XILINX
192 tristate "Xilinx SPI controller" 192 tristate "Xilinx SPI controller"
193 depends on SPI_MASTER && XILINX_VIRTEX && EXPERIMENTAL 193 depends on XILINX_VIRTEX && EXPERIMENTAL
194 select SPI_BITBANG 194 select SPI_BITBANG
195 help 195 help
196 This exposes the SPI controller IP from the Xilinx EDK. 196 This exposes the SPI controller IP from the Xilinx EDK.
@@ -207,11 +207,10 @@ config SPI_XILINX
207# being probably the most widely used ones. 207# being probably the most widely used ones.
208# 208#
209comment "SPI Protocol Masters" 209comment "SPI Protocol Masters"
210 depends on SPI_MASTER
211 210
212config SPI_AT25 211config SPI_AT25
213 tristate "SPI EEPROMs from most vendors" 212 tristate "SPI EEPROMs from most vendors"
214 depends on SPI_MASTER && SYSFS 213 depends on SYSFS
215 help 214 help
216 Enable this driver to get read/write support to most SPI EEPROMs, 215 Enable this driver to get read/write support to most SPI EEPROMs,
217 after you configure the board init code to know about each eeprom 216 after you configure the board init code to know about each eeprom
@@ -222,7 +221,7 @@ config SPI_AT25
222 221
223config SPI_SPIDEV 222config SPI_SPIDEV
224 tristate "User mode SPI device driver support" 223 tristate "User mode SPI device driver support"
225 depends on SPI_MASTER && EXPERIMENTAL 224 depends on EXPERIMENTAL
226 help 225 help
227 This supports user mode SPI protocol drivers. 226 This supports user mode SPI protocol drivers.
228 227
@@ -231,7 +230,7 @@ config SPI_SPIDEV
231 230
232config SPI_TLE62X0 231config SPI_TLE62X0
233 tristate "Infineon TLE62X0 (for power switching)" 232 tristate "Infineon TLE62X0 (for power switching)"
234 depends on SPI_MASTER && SYSFS 233 depends on SYSFS
235 help 234 help
236 SPI driver for Infineon TLE62X0 series line driver chips, 235 SPI driver for Infineon TLE62X0 series line driver chips,
237 such as the TLE6220, TLE6230 and TLE6240. This provides a 236 such as the TLE6220, TLE6230 and TLE6240. This provides a
@@ -242,6 +241,8 @@ config SPI_TLE62X0
242# Add new SPI protocol masters in alphabetical order above this line 241# Add new SPI protocol masters in alphabetical order above this line
243# 242#
244 243
244endif # SPI_MASTER
245
245# (slave support would go here) 246# (slave support would go here)
246 247
247endif # SPI 248endif # SPI
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index e81d59d78910..0c7165660853 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -313,14 +313,14 @@ atmel_spi_dma_map_xfer(struct atmel_spi *as, struct spi_transfer *xfer)
313 xfer->tx_dma = dma_map_single(dev, 313 xfer->tx_dma = dma_map_single(dev,
314 (void *) xfer->tx_buf, xfer->len, 314 (void *) xfer->tx_buf, xfer->len,
315 DMA_TO_DEVICE); 315 DMA_TO_DEVICE);
316 if (dma_mapping_error(xfer->tx_dma)) 316 if (dma_mapping_error(dev, xfer->tx_dma))
317 return -ENOMEM; 317 return -ENOMEM;
318 } 318 }
319 if (xfer->rx_buf) { 319 if (xfer->rx_buf) {
320 xfer->rx_dma = dma_map_single(dev, 320 xfer->rx_dma = dma_map_single(dev,
321 xfer->rx_buf, xfer->len, 321 xfer->rx_buf, xfer->len,
322 DMA_FROM_DEVICE); 322 DMA_FROM_DEVICE);
323 if (dma_mapping_error(xfer->rx_dma)) { 323 if (dma_mapping_error(dev, xfer->rx_dma)) {
324 if (xfer->tx_buf) 324 if (xfer->tx_buf)
325 dma_unmap_single(dev, 325 dma_unmap_single(dev,
326 xfer->tx_dma, xfer->len, 326 xfer->tx_dma, xfer->len,
diff --git a/drivers/spi/au1550_spi.c b/drivers/spi/au1550_spi.c
index 072c4a595334..87b73e0169c5 100644
--- a/drivers/spi/au1550_spi.c
+++ b/drivers/spi/au1550_spi.c
@@ -26,6 +26,7 @@
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/device.h> 27#include <linux/device.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/resource.h>
29#include <linux/spi/spi.h> 30#include <linux/spi/spi.h>
30#include <linux/spi/spi_bitbang.h> 31#include <linux/spi/spi_bitbang.h>
31#include <linux/dma-mapping.h> 32#include <linux/dma-mapping.h>
@@ -81,6 +82,7 @@ struct au1550_spi {
81 struct spi_master *master; 82 struct spi_master *master;
82 struct device *dev; 83 struct device *dev;
83 struct au1550_spi_info *pdata; 84 struct au1550_spi_info *pdata;
85 struct resource *ioarea;
84}; 86};
85 87
86 88
@@ -96,6 +98,8 @@ static dbdev_tab_t au1550_spi_mem_dbdev =
96 .dev_intpolarity = 0 98 .dev_intpolarity = 0
97}; 99};
98 100
101static int ddma_memid; /* id to above mem dma device */
102
99static void au1550_spi_bits_handlers_set(struct au1550_spi *hw, int bpw); 103static void au1550_spi_bits_handlers_set(struct au1550_spi *hw, int bpw);
100 104
101 105
@@ -330,7 +334,7 @@ static int au1550_spi_dma_rxtmp_alloc(struct au1550_spi *hw, unsigned size)
330 hw->dma_rx_tmpbuf_size = size; 334 hw->dma_rx_tmpbuf_size = size;
331 hw->dma_rx_tmpbuf_addr = dma_map_single(hw->dev, hw->dma_rx_tmpbuf, 335 hw->dma_rx_tmpbuf_addr = dma_map_single(hw->dev, hw->dma_rx_tmpbuf,
332 size, DMA_FROM_DEVICE); 336 size, DMA_FROM_DEVICE);
333 if (dma_mapping_error(hw->dma_rx_tmpbuf_addr)) { 337 if (dma_mapping_error(hw->dev, hw->dma_rx_tmpbuf_addr)) {
334 kfree(hw->dma_rx_tmpbuf); 338 kfree(hw->dma_rx_tmpbuf);
335 hw->dma_rx_tmpbuf = 0; 339 hw->dma_rx_tmpbuf = 0;
336 hw->dma_rx_tmpbuf_size = 0; 340 hw->dma_rx_tmpbuf_size = 0;
@@ -374,7 +378,7 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t)
374 dma_rx_addr = dma_map_single(hw->dev, 378 dma_rx_addr = dma_map_single(hw->dev,
375 (void *)t->rx_buf, 379 (void *)t->rx_buf,
376 t->len, DMA_FROM_DEVICE); 380 t->len, DMA_FROM_DEVICE);
377 if (dma_mapping_error(dma_rx_addr)) 381 if (dma_mapping_error(hw->dev, dma_rx_addr))
378 dev_err(hw->dev, "rx dma map error\n"); 382 dev_err(hw->dev, "rx dma map error\n");
379 } 383 }
380 } else { 384 } else {
@@ -397,7 +401,7 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t)
397 dma_tx_addr = dma_map_single(hw->dev, 401 dma_tx_addr = dma_map_single(hw->dev,
398 (void *)t->tx_buf, 402 (void *)t->tx_buf,
399 t->len, DMA_TO_DEVICE); 403 t->len, DMA_TO_DEVICE);
400 if (dma_mapping_error(dma_tx_addr)) 404 if (dma_mapping_error(hw->dev, dma_tx_addr))
401 dev_err(hw->dev, "tx dma map error\n"); 405 dev_err(hw->dev, "tx dma map error\n");
402 } 406 }
403 } else { 407 } else {
@@ -480,9 +484,13 @@ static irqreturn_t au1550_spi_dma_irq_callback(struct au1550_spi *hw)
480 au1xxx_dbdma_reset(hw->dma_tx_ch); 484 au1xxx_dbdma_reset(hw->dma_tx_ch);
481 au1550_spi_reset_fifos(hw); 485 au1550_spi_reset_fifos(hw);
482 486
483 dev_err(hw->dev, 487 if (evnt == PSC_SPIEVNT_RO)
484 "Unexpected SPI error: event=0x%x stat=0x%x!\n", 488 dev_err(hw->dev,
485 evnt, stat); 489 "dma transfer: receive FIFO overflow!\n");
490 else
491 dev_err(hw->dev,
492 "dma transfer: unexpected SPI error "
493 "(event=0x%x stat=0x%x)!\n", evnt, stat);
486 494
487 complete(&hw->master_done); 495 complete(&hw->master_done);
488 return IRQ_HANDLED; 496 return IRQ_HANDLED;
@@ -592,17 +600,17 @@ static irqreturn_t au1550_spi_pio_irq_callback(struct au1550_spi *hw)
592 600
593 if ((evnt & (PSC_SPIEVNT_MM | PSC_SPIEVNT_RO 601 if ((evnt & (PSC_SPIEVNT_MM | PSC_SPIEVNT_RO
594 | PSC_SPIEVNT_RU | PSC_SPIEVNT_TO 602 | PSC_SPIEVNT_RU | PSC_SPIEVNT_TO
595 | PSC_SPIEVNT_TU | PSC_SPIEVNT_SD)) 603 | PSC_SPIEVNT_SD))
596 != 0) { 604 != 0) {
597 dev_err(hw->dev,
598 "Unexpected SPI error: event=0x%x stat=0x%x!\n",
599 evnt, stat);
600 /* 605 /*
601 * due to an error we consider transfer as done, 606 * due to an error we consider transfer as done,
602 * so mask all events until before next transfer start 607 * so mask all events until before next transfer start
603 */ 608 */
604 au1550_spi_mask_ack_all(hw); 609 au1550_spi_mask_ack_all(hw);
605 au1550_spi_reset_fifos(hw); 610 au1550_spi_reset_fifos(hw);
611 dev_err(hw->dev,
612 "pio transfer: unexpected SPI error "
613 "(event=0x%x stat=0x%x)!\n", evnt, stat);
606 complete(&hw->master_done); 614 complete(&hw->master_done);
607 return IRQ_HANDLED; 615 return IRQ_HANDLED;
608 } 616 }
@@ -616,27 +624,50 @@ static irqreturn_t au1550_spi_pio_irq_callback(struct au1550_spi *hw)
616 stat = hw->regs->psc_spistat; 624 stat = hw->regs->psc_spistat;
617 au_sync(); 625 au_sync();
618 626
619 if ((stat & PSC_SPISTAT_RE) == 0 && hw->rx_count < hw->len) { 627 /*
628 * Take care to not let the Rx FIFO overflow.
629 *
630 * We only write a byte if we have read one at least. Initially,
631 * the write fifo is full, so we should read from the read fifo
632 * first.
633 * In case we miss a word from the read fifo, we should get a
634 * RO event and should back out.
635 */
636 if (!(stat & PSC_SPISTAT_RE) && hw->rx_count < hw->len) {
620 hw->rx_word(hw); 637 hw->rx_word(hw);
621 /* ack the receive request event */
622 hw->regs->psc_spievent = PSC_SPIEVNT_RR;
623 au_sync();
624 busy = 1; 638 busy = 1;
625 }
626 639
627 if ((stat & PSC_SPISTAT_TF) == 0 && hw->tx_count < hw->len) { 640 if (!(stat & PSC_SPISTAT_TF) && hw->tx_count < hw->len)
628 hw->tx_word(hw); 641 hw->tx_word(hw);
629 /* ack the transmit request event */
630 hw->regs->psc_spievent = PSC_SPIEVNT_TR;
631 au_sync();
632 busy = 1;
633 } 642 }
634 } while (busy); 643 } while (busy);
635 644
636 evnt = hw->regs->psc_spievent; 645 hw->regs->psc_spievent = PSC_SPIEVNT_RR | PSC_SPIEVNT_TR;
637 au_sync(); 646 au_sync();
638 647
639 if (hw->rx_count >= hw->len || (evnt & PSC_SPIEVNT_MD) != 0) { 648 /*
649 * Restart the SPI transmission in case of a transmit underflow.
650 * This seems to work despite the notes in the Au1550 data book
651 * of Figure 8-4 with flowchart for SPI master operation:
652 *
653 * """Note 1: An XFR Error Interrupt occurs, unless masked,
654 * for any of the following events: Tx FIFO Underflow,
655 * Rx FIFO Overflow, or Multiple-master Error
656 * Note 2: In case of a Tx Underflow Error, all zeroes are
657 * transmitted."""
658 *
659 * By simply restarting the spi transfer on Tx Underflow Error,
660 * we assume that spi transfer was paused instead of zeroes
661 * transmittion mentioned in the Note 2 of Au1550 data book.
662 */
663 if (evnt & PSC_SPIEVNT_TU) {
664 hw->regs->psc_spievent = PSC_SPIEVNT_TU | PSC_SPIEVNT_MD;
665 au_sync();
666 hw->regs->psc_spipcr = PSC_SPIPCR_MS;
667 au_sync();
668 }
669
670 if (hw->rx_count >= hw->len) {
640 /* transfer completed successfully */ 671 /* transfer completed successfully */
641 au1550_spi_mask_ack_all(hw); 672 au1550_spi_mask_ack_all(hw);
642 complete(&hw->master_done); 673 complete(&hw->master_done);
@@ -725,6 +756,8 @@ static void __init au1550_spi_setup_psc_as_spi(struct au1550_spi *hw)
725 stat = hw->regs->psc_spistat; 756 stat = hw->regs->psc_spistat;
726 au_sync(); 757 au_sync();
727 } while ((stat & PSC_SPISTAT_DR) == 0); 758 } while ((stat & PSC_SPISTAT_DR) == 0);
759
760 au1550_spi_reset_fifos(hw);
728} 761}
729 762
730 763
@@ -732,6 +765,7 @@ static int __init au1550_spi_probe(struct platform_device *pdev)
732{ 765{
733 struct au1550_spi *hw; 766 struct au1550_spi *hw;
734 struct spi_master *master; 767 struct spi_master *master;
768 struct resource *r;
735 int err = 0; 769 int err = 0;
736 770
737 master = spi_alloc_master(&pdev->dev, sizeof(struct au1550_spi)); 771 master = spi_alloc_master(&pdev->dev, sizeof(struct au1550_spi));
@@ -753,76 +787,64 @@ static int __init au1550_spi_probe(struct platform_device *pdev)
753 goto err_no_pdata; 787 goto err_no_pdata;
754 } 788 }
755 789
756 platform_set_drvdata(pdev, hw); 790 r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
757 791 if (!r) {
758 init_completion(&hw->master_done); 792 dev_err(&pdev->dev, "no IRQ\n");
759 793 err = -ENODEV;
760 hw->bitbang.master = hw->master; 794 goto err_no_iores;
761 hw->bitbang.setup_transfer = au1550_spi_setupxfer; 795 }
762 hw->bitbang.chipselect = au1550_spi_chipsel; 796 hw->irq = r->start;
763 hw->bitbang.master->setup = au1550_spi_setup; 797
764 hw->bitbang.txrx_bufs = au1550_spi_txrx_bufs; 798 hw->usedma = 0;
799 r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
800 if (r) {
801 hw->dma_tx_id = r->start;
802 r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
803 if (r) {
804 hw->dma_rx_id = r->start;
805 if (usedma && ddma_memid) {
806 if (pdev->dev.dma_mask == NULL)
807 dev_warn(&pdev->dev, "no dma mask\n");
808 else
809 hw->usedma = 1;
810 }
811 }
812 }
765 813
766 switch (hw->pdata->bus_num) { 814 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
767 case 0: 815 if (!r) {
768 hw->irq = AU1550_PSC0_INT; 816 dev_err(&pdev->dev, "no mmio resource\n");
769 hw->regs = (volatile psc_spi_t *)PSC0_BASE_ADDR; 817 err = -ENODEV;
770 hw->dma_rx_id = DSCR_CMD0_PSC0_RX; 818 goto err_no_iores;
771 hw->dma_tx_id = DSCR_CMD0_PSC0_TX;
772 break;
773 case 1:
774 hw->irq = AU1550_PSC1_INT;
775 hw->regs = (volatile psc_spi_t *)PSC1_BASE_ADDR;
776 hw->dma_rx_id = DSCR_CMD0_PSC1_RX;
777 hw->dma_tx_id = DSCR_CMD0_PSC1_TX;
778 break;
779 case 2:
780 hw->irq = AU1550_PSC2_INT;
781 hw->regs = (volatile psc_spi_t *)PSC2_BASE_ADDR;
782 hw->dma_rx_id = DSCR_CMD0_PSC2_RX;
783 hw->dma_tx_id = DSCR_CMD0_PSC2_TX;
784 break;
785 case 3:
786 hw->irq = AU1550_PSC3_INT;
787 hw->regs = (volatile psc_spi_t *)PSC3_BASE_ADDR;
788 hw->dma_rx_id = DSCR_CMD0_PSC3_RX;
789 hw->dma_tx_id = DSCR_CMD0_PSC3_TX;
790 break;
791 default:
792 dev_err(&pdev->dev, "Wrong bus_num of SPI\n");
793 err = -ENOENT;
794 goto err_no_pdata;
795 } 819 }
796 820
797 if (request_mem_region((unsigned long)hw->regs, sizeof(psc_spi_t), 821 hw->ioarea = request_mem_region(r->start, sizeof(psc_spi_t),
798 pdev->name) == NULL) { 822 pdev->name);
823 if (!hw->ioarea) {
799 dev_err(&pdev->dev, "Cannot reserve iomem region\n"); 824 dev_err(&pdev->dev, "Cannot reserve iomem region\n");
800 err = -ENXIO; 825 err = -ENXIO;
801 goto err_no_iores; 826 goto err_no_iores;
802 } 827 }
803 828
804 829 hw->regs = (psc_spi_t __iomem *)ioremap(r->start, sizeof(psc_spi_t));
805 if (usedma) { 830 if (!hw->regs) {
806 if (pdev->dev.dma_mask == NULL) 831 dev_err(&pdev->dev, "cannot ioremap\n");
807 dev_warn(&pdev->dev, "no dma mask\n"); 832 err = -ENXIO;
808 else 833 goto err_ioremap;
809 hw->usedma = 1;
810 } 834 }
811 835
812 if (hw->usedma) { 836 platform_set_drvdata(pdev, hw);
813 /* 837
814 * create memory device with 8 bits dev_devwidth 838 init_completion(&hw->master_done);
815 * needed for proper byte ordering to spi fifo 839
816 */ 840 hw->bitbang.master = hw->master;
817 int memid = au1xxx_ddma_add_device(&au1550_spi_mem_dbdev); 841 hw->bitbang.setup_transfer = au1550_spi_setupxfer;
818 if (!memid) { 842 hw->bitbang.chipselect = au1550_spi_chipsel;
819 dev_err(&pdev->dev, 843 hw->bitbang.master->setup = au1550_spi_setup;
820 "Cannot create dma 8 bit mem device\n"); 844 hw->bitbang.txrx_bufs = au1550_spi_txrx_bufs;
821 err = -ENXIO;
822 goto err_dma_add_dev;
823 }
824 845
825 hw->dma_tx_ch = au1xxx_dbdma_chan_alloc(memid, 846 if (hw->usedma) {
847 hw->dma_tx_ch = au1xxx_dbdma_chan_alloc(ddma_memid,
826 hw->dma_tx_id, NULL, (void *)hw); 848 hw->dma_tx_id, NULL, (void *)hw);
827 if (hw->dma_tx_ch == 0) { 849 if (hw->dma_tx_ch == 0) {
828 dev_err(&pdev->dev, 850 dev_err(&pdev->dev,
@@ -841,7 +863,7 @@ static int __init au1550_spi_probe(struct platform_device *pdev)
841 863
842 864
843 hw->dma_rx_ch = au1xxx_dbdma_chan_alloc(hw->dma_rx_id, 865 hw->dma_rx_ch = au1xxx_dbdma_chan_alloc(hw->dma_rx_id,
844 memid, NULL, (void *)hw); 866 ddma_memid, NULL, (void *)hw);
845 if (hw->dma_rx_ch == 0) { 867 if (hw->dma_rx_ch == 0) {
846 dev_err(&pdev->dev, 868 dev_err(&pdev->dev,
847 "Cannot allocate rx dma channel\n"); 869 "Cannot allocate rx dma channel\n");
@@ -874,7 +896,7 @@ static int __init au1550_spi_probe(struct platform_device *pdev)
874 goto err_no_irq; 896 goto err_no_irq;
875 } 897 }
876 898
877 master->bus_num = hw->pdata->bus_num; 899 master->bus_num = pdev->id;
878 master->num_chipselect = hw->pdata->num_chipselect; 900 master->num_chipselect = hw->pdata->num_chipselect;
879 901
880 /* 902 /*
@@ -924,8 +946,11 @@ err_no_txdma_descr:
924 au1xxx_dbdma_chan_free(hw->dma_tx_ch); 946 au1xxx_dbdma_chan_free(hw->dma_tx_ch);
925 947
926err_no_txdma: 948err_no_txdma:
927err_dma_add_dev: 949 iounmap((void __iomem *)hw->regs);
928 release_mem_region((unsigned long)hw->regs, sizeof(psc_spi_t)); 950
951err_ioremap:
952 release_resource(hw->ioarea);
953 kfree(hw->ioarea);
929 954
930err_no_iores: 955err_no_iores:
931err_no_pdata: 956err_no_pdata:
@@ -944,7 +969,9 @@ static int __exit au1550_spi_remove(struct platform_device *pdev)
944 969
945 spi_bitbang_stop(&hw->bitbang); 970 spi_bitbang_stop(&hw->bitbang);
946 free_irq(hw->irq, hw); 971 free_irq(hw->irq, hw);
947 release_mem_region((unsigned long)hw->regs, sizeof(psc_spi_t)); 972 iounmap((void __iomem *)hw->regs);
973 release_resource(hw->ioarea);
974 kfree(hw->ioarea);
948 975
949 if (hw->usedma) { 976 if (hw->usedma) {
950 au1550_spi_dma_rxtmp_free(hw); 977 au1550_spi_dma_rxtmp_free(hw);
@@ -971,12 +998,24 @@ static struct platform_driver au1550_spi_drv = {
971 998
972static int __init au1550_spi_init(void) 999static int __init au1550_spi_init(void)
973{ 1000{
1001 /*
1002 * create memory device with 8 bits dev_devwidth
1003 * needed for proper byte ordering to spi fifo
1004 */
1005 if (usedma) {
1006 ddma_memid = au1xxx_ddma_add_device(&au1550_spi_mem_dbdev);
1007 if (!ddma_memid)
1008 printk(KERN_ERR "au1550-spi: cannot add memory"
1009 "dbdma device\n");
1010 }
974 return platform_driver_probe(&au1550_spi_drv, au1550_spi_probe); 1011 return platform_driver_probe(&au1550_spi_drv, au1550_spi_probe);
975} 1012}
976module_init(au1550_spi_init); 1013module_init(au1550_spi_init);
977 1014
978static void __exit au1550_spi_exit(void) 1015static void __exit au1550_spi_exit(void)
979{ 1016{
1017 if (usedma && ddma_memid)
1018 au1xxx_ddma_del_device(ddma_memid);
980 platform_driver_unregister(&au1550_spi_drv); 1019 platform_driver_unregister(&au1550_spi_drv);
981} 1020}
982module_exit(au1550_spi_exit); 1021module_exit(au1550_spi_exit);
diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c
index b1cc148036c1..f6f987bb71ca 100644
--- a/drivers/spi/omap2_mcspi.c
+++ b/drivers/spi/omap2_mcspi.c
@@ -836,7 +836,7 @@ static int omap2_mcspi_transfer(struct spi_device *spi, struct spi_message *m)
836 if (tx_buf != NULL) { 836 if (tx_buf != NULL) {
837 t->tx_dma = dma_map_single(&spi->dev, (void *) tx_buf, 837 t->tx_dma = dma_map_single(&spi->dev, (void *) tx_buf,
838 len, DMA_TO_DEVICE); 838 len, DMA_TO_DEVICE);
839 if (dma_mapping_error(t->tx_dma)) { 839 if (dma_mapping_error(&spi->dev, t->tx_dma)) {
840 dev_dbg(&spi->dev, "dma %cX %d bytes error\n", 840 dev_dbg(&spi->dev, "dma %cX %d bytes error\n",
841 'T', len); 841 'T', len);
842 return -EINVAL; 842 return -EINVAL;
@@ -845,7 +845,7 @@ static int omap2_mcspi_transfer(struct spi_device *spi, struct spi_message *m)
845 if (rx_buf != NULL) { 845 if (rx_buf != NULL) {
846 t->rx_dma = dma_map_single(&spi->dev, rx_buf, t->len, 846 t->rx_dma = dma_map_single(&spi->dev, rx_buf, t->len,
847 DMA_FROM_DEVICE); 847 DMA_FROM_DEVICE);
848 if (dma_mapping_error(t->rx_dma)) { 848 if (dma_mapping_error(&spi->dev, t->rx_dma)) {
849 dev_dbg(&spi->dev, "dma %cX %d bytes error\n", 849 dev_dbg(&spi->dev, "dma %cX %d bytes error\n",
850 'R', len); 850 'R', len);
851 if (tx_buf != NULL) 851 if (tx_buf != NULL)
diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
index 0c452c46ab07..067299d6d192 100644
--- a/drivers/spi/pxa2xx_spi.c
+++ b/drivers/spi/pxa2xx_spi.c
@@ -353,7 +353,7 @@ static int map_dma_buffers(struct driver_data *drv_data)
353 drv_data->rx_dma = dma_map_single(dev, drv_data->rx, 353 drv_data->rx_dma = dma_map_single(dev, drv_data->rx,
354 drv_data->rx_map_len, 354 drv_data->rx_map_len,
355 DMA_FROM_DEVICE); 355 DMA_FROM_DEVICE);
356 if (dma_mapping_error(drv_data->rx_dma)) 356 if (dma_mapping_error(dev, drv_data->rx_dma))
357 return 0; 357 return 0;
358 358
359 /* Stream map the tx buffer */ 359 /* Stream map the tx buffer */
@@ -361,7 +361,7 @@ static int map_dma_buffers(struct driver_data *drv_data)
361 drv_data->tx_map_len, 361 drv_data->tx_map_len,
362 DMA_TO_DEVICE); 362 DMA_TO_DEVICE);
363 363
364 if (dma_mapping_error(drv_data->tx_dma)) { 364 if (dma_mapping_error(dev, drv_data->tx_dma)) {
365 dma_unmap_single(dev, drv_data->rx_dma, 365 dma_unmap_single(dev, drv_data->rx_dma,
366 drv_data->rx_map_len, DMA_FROM_DEVICE); 366 drv_data->rx_map_len, DMA_FROM_DEVICE);
367 return 0; 367 return 0;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 1771b2456bfa..ecca4a6a6f94 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -218,6 +218,8 @@ struct spi_device *spi_new_device(struct spi_master *master,
218 if (!spi_master_get(master)) 218 if (!spi_master_get(master))
219 return NULL; 219 return NULL;
220 220
221 WARN_ON(strlen(chip->modalias) >= sizeof(proxy->modalias));
222
221 proxy = kzalloc(sizeof *proxy, GFP_KERNEL); 223 proxy = kzalloc(sizeof *proxy, GFP_KERNEL);
222 if (!proxy) { 224 if (!proxy) {
223 dev_err(dev, "can't alloc dev for cs%d\n", 225 dev_err(dev, "can't alloc dev for cs%d\n",
@@ -229,7 +231,7 @@ struct spi_device *spi_new_device(struct spi_master *master,
229 proxy->max_speed_hz = chip->max_speed_hz; 231 proxy->max_speed_hz = chip->max_speed_hz;
230 proxy->mode = chip->mode; 232 proxy->mode = chip->mode;
231 proxy->irq = chip->irq; 233 proxy->irq = chip->irq;
232 proxy->modalias = chip->modalias; 234 strlcpy(proxy->modalias, chip->modalias, sizeof(proxy->modalias));
233 235
234 snprintf(proxy->dev.bus_id, sizeof proxy->dev.bus_id, 236 snprintf(proxy->dev.bus_id, sizeof proxy->dev.bus_id,
235 "%s.%u", master->dev.bus_id, 237 "%s.%u", master->dev.bus_id,
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
index 54ac7bea5f8c..6fb77fcc4971 100644
--- a/drivers/spi/spi_imx.c
+++ b/drivers/spi/spi_imx.c
@@ -491,7 +491,7 @@ static int map_dma_buffers(struct driver_data *drv_data)
491 buf, 491 buf,
492 drv_data->tx_map_len, 492 drv_data->tx_map_len,
493 DMA_TO_DEVICE); 493 DMA_TO_DEVICE);
494 if (dma_mapping_error(drv_data->tx_dma)) 494 if (dma_mapping_error(dev, drv_data->tx_dma))
495 return -1; 495 return -1;
496 496
497 drv_data->tx_dma_needs_unmap = 1; 497 drv_data->tx_dma_needs_unmap = 1;
@@ -516,7 +516,7 @@ static int map_dma_buffers(struct driver_data *drv_data)
516 buf, 516 buf,
517 drv_data->len, 517 drv_data->len,
518 DMA_FROM_DEVICE); 518 DMA_FROM_DEVICE);
519 if (dma_mapping_error(drv_data->rx_dma)) 519 if (dma_mapping_error(dev, drv_data->rx_dma))
520 return -1; 520 return -1;
521 drv_data->rx_dma_needs_unmap = 1; 521 drv_data->rx_dma_needs_unmap = 1;
522 } 522 }
@@ -534,7 +534,7 @@ static int map_dma_buffers(struct driver_data *drv_data)
534 buf, 534 buf,
535 drv_data->tx_map_len, 535 drv_data->tx_map_len,
536 DMA_TO_DEVICE); 536 DMA_TO_DEVICE);
537 if (dma_mapping_error(drv_data->tx_dma)) { 537 if (dma_mapping_error(dev, drv_data->tx_dma)) {
538 if (drv_data->rx_dma) { 538 if (drv_data->rx_dma) {
539 dma_unmap_single(dev, 539 dma_unmap_single(dev,
540 drv_data->rx_dma, 540 drv_data->rx_dma,
diff --git a/drivers/spi/spi_mpc83xx.c b/drivers/spi/spi_mpc83xx.c
index 6832da6f7109..070c6219e2d6 100644
--- a/drivers/spi/spi_mpc83xx.c
+++ b/drivers/spi/spi_mpc83xx.c
@@ -266,21 +266,24 @@ int mpc83xx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
266 266
267 cs->hw_mode |= SPMODE_LEN(bits_per_word); 267 cs->hw_mode |= SPMODE_LEN(bits_per_word);
268 268
269 if ((mpc83xx_spi->spibrg / hz) >= 64) { 269 if ((mpc83xx_spi->spibrg / hz) > 64) {
270 pm = mpc83xx_spi->spibrg / (hz * 64) - 1; 270 pm = mpc83xx_spi->spibrg / (hz * 64);
271 if (pm > 0x0f) { 271 if (pm > 16) {
272 dev_err(&spi->dev, "Requested speed is too " 272 cs->hw_mode |= SPMODE_DIV16;
273 "low: %d Hz. Will use %d Hz instead.\n", 273 pm /= 16;
274 hz, mpc83xx_spi->spibrg / 1024); 274 if (pm > 16) {
275 pm = 0x0f; 275 dev_err(&spi->dev, "Requested speed is too "
276 "low: %d Hz. Will use %d Hz instead.\n",
277 hz, mpc83xx_spi->spibrg / 1024);
278 pm = 16;
279 }
276 } 280 }
277 cs->hw_mode |= SPMODE_PM(pm) | SPMODE_DIV16; 281 } else
278 } else {
279 pm = mpc83xx_spi->spibrg / (hz * 4); 282 pm = mpc83xx_spi->spibrg / (hz * 4);
280 if (pm) 283 if (pm)
281 pm--; 284 pm--;
282 cs->hw_mode |= SPMODE_PM(pm); 285
283 } 286 cs->hw_mode |= SPMODE_PM(pm);
284 regval = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode); 287 regval = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode);
285 if (cs->hw_mode != regval) { 288 if (cs->hw_mode != regval) {
286 unsigned long flags; 289 unsigned long flags;
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 2833fd772a24..e5e0cfed5e3b 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -228,7 +228,6 @@ static int spidev_message(struct spidev_data *spidev,
228 * We walk the array of user-provided transfers, using each one 228 * We walk the array of user-provided transfers, using each one
229 * to initialize a kernel version of the same transfer. 229 * to initialize a kernel version of the same transfer.
230 */ 230 */
231 mutex_lock(&spidev->buf_lock);
232 buf = spidev->buffer; 231 buf = spidev->buffer;
233 total = 0; 232 total = 0;
234 for (n = n_xfers, k_tmp = k_xfers, u_tmp = u_xfers; 233 for (n = n_xfers, k_tmp = k_xfers, u_tmp = u_xfers;
@@ -296,14 +295,12 @@ static int spidev_message(struct spidev_data *spidev,
296 status = total; 295 status = total;
297 296
298done: 297done:
299 mutex_unlock(&spidev->buf_lock);
300 kfree(k_xfers); 298 kfree(k_xfers);
301 return status; 299 return status;
302} 300}
303 301
304static int 302static long
305spidev_ioctl(struct inode *inode, struct file *filp, 303spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
306 unsigned int cmd, unsigned long arg)
307{ 304{
308 int err = 0; 305 int err = 0;
309 int retval = 0; 306 int retval = 0;
@@ -341,6 +338,14 @@ spidev_ioctl(struct inode *inode, struct file *filp,
341 if (spi == NULL) 338 if (spi == NULL)
342 return -ESHUTDOWN; 339 return -ESHUTDOWN;
343 340
341 /* use the buffer lock here for triple duty:
342 * - prevent I/O (from us) so calling spi_setup() is safe;
343 * - prevent concurrent SPI_IOC_WR_* from morphing
344 * data fields while SPI_IOC_RD_* reads them;
345 * - SPI_IOC_MESSAGE needs the buffer locked "normally".
346 */
347 mutex_lock(&spidev->buf_lock);
348
344 switch (cmd) { 349 switch (cmd) {
345 /* read requests */ 350 /* read requests */
346 case SPI_IOC_RD_MODE: 351 case SPI_IOC_RD_MODE:
@@ -456,6 +461,8 @@ spidev_ioctl(struct inode *inode, struct file *filp,
456 kfree(ioc); 461 kfree(ioc);
457 break; 462 break;
458 } 463 }
464
465 mutex_unlock(&spidev->buf_lock);
459 spi_dev_put(spi); 466 spi_dev_put(spi);
460 return retval; 467 return retval;
461} 468}
@@ -533,7 +540,7 @@ static struct file_operations spidev_fops = {
533 */ 540 */
534 .write = spidev_write, 541 .write = spidev_write,
535 .read = spidev_read, 542 .read = spidev_read,
536 .ioctl = spidev_ioctl, 543 .unlocked_ioctl = spidev_ioctl,
537 .open = spidev_open, 544 .open = spidev_open,
538 .release = spidev_release, 545 .release = spidev_release,
539}; 546};
diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c
index 113a0468ffcb..68d6f4988fb5 100644
--- a/drivers/spi/xilinx_spi.c
+++ b/drivers/spi/xilinx_spi.c
@@ -353,11 +353,12 @@ static int __init xilinx_spi_probe(struct platform_device *dev)
353 goto put_master; 353 goto put_master;
354 } 354 }
355 355
356 xspi->irq = platform_get_irq(dev, 0); 356 ret = platform_get_irq(dev, 0);
357 if (xspi->irq < 0) { 357 if (ret < 0) {
358 ret = -ENXIO; 358 ret = -ENXIO;
359 goto unmap_io; 359 goto unmap_io;
360 } 360 }
361 xspi->irq = ret;
361 362
362 master->bus_num = pdata->bus_num; 363 master->bus_num = pdata->bus_num;
363 master->num_chipselect = pdata->num_chipselect; 364 master->num_chipselect = pdata->num_chipselect;
diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
index 49cd9793404f..ec7aeb502d15 100644
--- a/drivers/telephony/ixj.c
+++ b/drivers/telephony/ixj.c
@@ -6095,15 +6095,15 @@ static int capabilities_check(IXJ *j, struct phone_capability *pcreq)
6095 return retval; 6095 return retval;
6096} 6096}
6097 6097
6098static int ixj_ioctl(struct inode *inode, struct file *file_p, unsigned int cmd, unsigned long arg) 6098static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg)
6099{ 6099{
6100 IXJ_TONE ti; 6100 IXJ_TONE ti;
6101 IXJ_FILTER jf; 6101 IXJ_FILTER jf;
6102 IXJ_FILTER_RAW jfr; 6102 IXJ_FILTER_RAW jfr;
6103 void __user *argp = (void __user *)arg; 6103 void __user *argp = (void __user *)arg;
6104 6104 struct inode *inode = file_p->f_path.dentry->d_inode;
6105 unsigned int raise, mant;
6106 unsigned int minor = iminor(inode); 6105 unsigned int minor = iminor(inode);
6106 unsigned int raise, mant;
6107 int board = NUM(inode); 6107 int board = NUM(inode);
6108 6108
6109 IXJ *j = get_ixj(NUM(inode)); 6109 IXJ *j = get_ixj(NUM(inode));
@@ -6661,6 +6661,15 @@ static int ixj_ioctl(struct inode *inode, struct file *file_p, unsigned int cmd,
6661 return retval; 6661 return retval;
6662} 6662}
6663 6663
6664static long ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg)
6665{
6666 long ret;
6667 lock_kernel();
6668 ret = do_ixj_ioctl(file_p, cmd, arg);
6669 unlock_kernel();
6670 return ret;
6671}
6672
6664static int ixj_fasync(int fd, struct file *file_p, int mode) 6673static int ixj_fasync(int fd, struct file *file_p, int mode)
6665{ 6674{
6666 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode)); 6675 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
@@ -6674,7 +6683,7 @@ static const struct file_operations ixj_fops =
6674 .read = ixj_enhanced_read, 6683 .read = ixj_enhanced_read,
6675 .write = ixj_enhanced_write, 6684 .write = ixj_enhanced_write,
6676 .poll = ixj_poll, 6685 .poll = ixj_poll,
6677 .ioctl = ixj_ioctl, 6686 .unlocked_ioctl = ixj_ioctl,
6678 .release = ixj_release, 6687 .release = ixj_release,
6679 .fasync = ixj_fasync 6688 .fasync = ixj_fasync
6680}; 6689};
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
index a973f2a50fb9..c65d62295890 100644
--- a/drivers/usb/gadget/at91_udc.h
+++ b/drivers/usb/gadget/at91_udc.h
@@ -171,7 +171,7 @@ struct at91_request {
171#endif 171#endif
172 172
173#define ERR(stuff...) pr_err("udc: " stuff) 173#define ERR(stuff...) pr_err("udc: " stuff)
174#define WARN(stuff...) pr_warning("udc: " stuff) 174#define WARNING(stuff...) pr_warning("udc: " stuff)
175#define INFO(stuff...) pr_info("udc: " stuff) 175#define INFO(stuff...) pr_info("udc: " stuff)
176#define DBG(stuff...) pr_debug("udc: " stuff) 176#define DBG(stuff...) pr_debug("udc: " stuff)
177 177
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index d490d0289507..a39a4b940c33 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -170,7 +170,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
170 * but if the controller isn't recognized at all then 170 * but if the controller isn't recognized at all then
171 * that assumption is a bit more likely to be wrong. 171 * that assumption is a bit more likely to be wrong.
172 */ 172 */
173 WARN(cdev, "controller '%s' not recognized; trying %s\n", 173 WARNING(cdev, "controller '%s' not recognized; trying %s\n",
174 gadget->name, 174 gadget->name,
175 cdc_config_driver.label); 175 cdc_config_driver.label);
176 device_desc.bcdDevice = 176 device_desc.bcdDevice =
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index d7aaaa29b1e1..bcac2e68660d 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -293,7 +293,7 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
293 * but if the controller isn't recognized at all then 293 * but if the controller isn't recognized at all then
294 * that assumption is a bit more likely to be wrong. 294 * that assumption is a bit more likely to be wrong.
295 */ 295 */
296 WARN(cdev, "controller '%s' not recognized; trying %s\n", 296 WARNING(cdev, "controller '%s' not recognized; trying %s\n",
297 gadget->name, 297 gadget->name,
298 eth_config_driver.label); 298 eth_config_driver.label);
299 device_desc.bcdDevice = 299 device_desc.bcdDevice =
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 15c24edbb61a..ea2c31d18080 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -308,7 +308,7 @@ MODULE_LICENSE("Dual BSD/GPL");
308 dev_vdbg(&(d)->gadget->dev , fmt , ## args) 308 dev_vdbg(&(d)->gadget->dev , fmt , ## args)
309#define ERROR(d, fmt, args...) \ 309#define ERROR(d, fmt, args...) \
310 dev_err(&(d)->gadget->dev , fmt , ## args) 310 dev_err(&(d)->gadget->dev , fmt , ## args)
311#define WARN(d, fmt, args...) \ 311#define WARNING(d, fmt, args...) \
312 dev_warn(&(d)->gadget->dev , fmt , ## args) 312 dev_warn(&(d)->gadget->dev , fmt , ## args)
313#define INFO(d, fmt, args...) \ 313#define INFO(d, fmt, args...) \
314 dev_info(&(d)->gadget->dev , fmt , ## args) 314 dev_info(&(d)->gadget->dev , fmt , ## args)
@@ -1091,7 +1091,7 @@ static int ep0_queue(struct fsg_dev *fsg)
1091 if (rc != 0 && rc != -ESHUTDOWN) { 1091 if (rc != 0 && rc != -ESHUTDOWN) {
1092 1092
1093 /* We can't do much more than wait for a reset */ 1093 /* We can't do much more than wait for a reset */
1094 WARN(fsg, "error in submission: %s --> %d\n", 1094 WARNING(fsg, "error in submission: %s --> %d\n",
1095 fsg->ep0->name, rc); 1095 fsg->ep0->name, rc);
1096 } 1096 }
1097 return rc; 1097 return rc;
@@ -1227,7 +1227,7 @@ static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1227 1227
1228 /* Save the command for later */ 1228 /* Save the command for later */
1229 if (fsg->cbbuf_cmnd_size) 1229 if (fsg->cbbuf_cmnd_size)
1230 WARN(fsg, "CB[I] overwriting previous command\n"); 1230 WARNING(fsg, "CB[I] overwriting previous command\n");
1231 fsg->cbbuf_cmnd_size = req->actual; 1231 fsg->cbbuf_cmnd_size = req->actual;
1232 memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size); 1232 memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
1233 1233
@@ -1506,7 +1506,7 @@ static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
1506 * submissions if DMA is enabled. */ 1506 * submissions if DMA is enabled. */
1507 if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP && 1507 if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
1508 req->length == 0)) 1508 req->length == 0))
1509 WARN(fsg, "error in submission: %s --> %d\n", 1509 WARNING(fsg, "error in submission: %s --> %d\n",
1510 ep->name, rc); 1510 ep->name, rc);
1511 } 1511 }
1512} 1512}
@@ -2294,7 +2294,7 @@ static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
2294 VDBG(fsg, "delayed bulk-in endpoint halt\n"); 2294 VDBG(fsg, "delayed bulk-in endpoint halt\n");
2295 while (rc != 0) { 2295 while (rc != 0) {
2296 if (rc != -EAGAIN) { 2296 if (rc != -EAGAIN) {
2297 WARN(fsg, "usb_ep_set_halt -> %d\n", rc); 2297 WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
2298 rc = 0; 2298 rc = 0;
2299 break; 2299 break;
2300 } 2300 }
@@ -2317,7 +2317,7 @@ static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
2317 VDBG(fsg, "delayed bulk-in endpoint wedge\n"); 2317 VDBG(fsg, "delayed bulk-in endpoint wedge\n");
2318 while (rc != 0) { 2318 while (rc != 0) {
2319 if (rc != -EAGAIN) { 2319 if (rc != -EAGAIN) {
2320 WARN(fsg, "usb_ep_set_wedge -> %d\n", rc); 2320 WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
2321 rc = 0; 2321 rc = 0;
2322 break; 2322 break;
2323 } 2323 }
@@ -3755,7 +3755,7 @@ static int __init check_parameters(struct fsg_dev *fsg)
3755 if (gcnum >= 0) 3755 if (gcnum >= 0)
3756 mod_data.release = 0x0300 + gcnum; 3756 mod_data.release = 0x0300 + gcnum;
3757 else { 3757 else {
3758 WARN(fsg, "controller '%s' not recognized\n", 3758 WARNING(fsg, "controller '%s' not recognized\n",
3759 fsg->gadget->name); 3759 fsg->gadget->name);
3760 mod_data.release = 0x0399; 3760 mod_data.release = 0x0399;
3761 } 3761 }
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c
index 1695382f30fe..1cfccf102a2d 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -1538,7 +1538,7 @@ static void dtd_complete_irq(struct fsl_udc *udc)
1538 1538
1539 /* If the ep is configured */ 1539 /* If the ep is configured */
1540 if (curr_ep->name == NULL) { 1540 if (curr_ep->name == NULL) {
1541 WARN("Invalid EP?"); 1541 WARNING("Invalid EP?");
1542 continue; 1542 continue;
1543 } 1543 }
1544 1544
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index 98b1483ef6a5..6131752a38bc 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -552,7 +552,7 @@ static void dump_msg(const char *label, const u8 * buf, unsigned int length)
552#endif 552#endif
553 553
554#define ERR(stuff...) pr_err("udc: " stuff) 554#define ERR(stuff...) pr_err("udc: " stuff)
555#define WARN(stuff...) pr_warning("udc: " stuff) 555#define WARNING(stuff...) pr_warning("udc: " stuff)
556#define INFO(stuff...) pr_info("udc: " stuff) 556#define INFO(stuff...) pr_info("udc: " stuff)
557 557
558/*-------------------------------------------------------------------------*/ 558/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 7f4d4828e3aa..ea8651e3da1a 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -138,8 +138,6 @@ static void gmidi_transmit(struct gmidi_device* dev, struct usb_request* req);
138 dev_vdbg(&(d)->gadget->dev , fmt , ## args) 138 dev_vdbg(&(d)->gadget->dev , fmt , ## args)
139#define ERROR(d, fmt, args...) \ 139#define ERROR(d, fmt, args...) \
140 dev_err(&(d)->gadget->dev , fmt , ## args) 140 dev_err(&(d)->gadget->dev , fmt , ## args)
141#define WARN(d, fmt, args...) \
142 dev_warn(&(d)->gadget->dev , fmt , ## args)
143#define INFO(d, fmt, args...) \ 141#define INFO(d, fmt, args...) \
144 dev_info(&(d)->gadget->dev , fmt , ## args) 142 dev_info(&(d)->gadget->dev , fmt , ## args)
145 143
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 48f1c63b7013..60aa04847b18 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -1768,7 +1768,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1768 * usb_gadget_driver_{register,unregister}() must change. 1768 * usb_gadget_driver_{register,unregister}() must change.
1769 */ 1769 */
1770 if (the_controller) { 1770 if (the_controller) {
1771 WARN(dev, "ignoring %s\n", pci_name(pdev)); 1771 WARNING(dev, "ignoring %s\n", pci_name(pdev));
1772 return -EBUSY; 1772 return -EBUSY;
1773 } 1773 }
1774 if (!pdev->irq) { 1774 if (!pdev->irq) {
diff --git a/drivers/usb/gadget/goku_udc.h b/drivers/usb/gadget/goku_udc.h
index bc4eb1e0b507..566cb2319056 100644
--- a/drivers/usb/gadget/goku_udc.h
+++ b/drivers/usb/gadget/goku_udc.h
@@ -285,7 +285,7 @@ struct goku_udc {
285 285
286#define ERROR(dev,fmt,args...) \ 286#define ERROR(dev,fmt,args...) \
287 xprintk(dev , KERN_ERR , fmt , ## args) 287 xprintk(dev , KERN_ERR , fmt , ## args)
288#define WARN(dev,fmt,args...) \ 288#define WARNING(dev,fmt,args...) \
289 xprintk(dev , KERN_WARNING , fmt , ## args) 289 xprintk(dev , KERN_WARNING , fmt , ## args)
290#define INFO(dev,fmt,args...) \ 290#define INFO(dev,fmt,args...) \
291 xprintk(dev , KERN_INFO , fmt , ## args) 291 xprintk(dev , KERN_INFO , fmt , ## args)
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 04692d59fc1c..f4585d3e90d7 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -262,8 +262,6 @@ static const char *CHIP;
262 262
263#define ERROR(dev,fmt,args...) \ 263#define ERROR(dev,fmt,args...) \
264 xprintk(dev , KERN_ERR , fmt , ## args) 264 xprintk(dev , KERN_ERR , fmt , ## args)
265#define WARN(dev,fmt,args...) \
266 xprintk(dev , KERN_WARNING , fmt , ## args)
267#define INFO(dev,fmt,args...) \ 265#define INFO(dev,fmt,args...) \
268 xprintk(dev , KERN_INFO , fmt , ## args) 266 xprintk(dev , KERN_INFO , fmt , ## args)
269 267
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index b67ab677af72..5cfb5ebf3881 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -1007,7 +1007,7 @@ static void scan_dma_completions (struct net2280_ep *ep)
1007 * 0122, and 0124; not all cases trigger the warning. 1007 * 0122, and 0124; not all cases trigger the warning.
1008 */ 1008 */
1009 if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) { 1009 if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) {
1010 WARN (ep->dev, "%s lost packet sync!\n", 1010 WARNING (ep->dev, "%s lost packet sync!\n",
1011 ep->ep.name); 1011 ep->ep.name);
1012 req->req.status = -EOVERFLOW; 1012 req->req.status = -EOVERFLOW;
1013 } else if ((tmp = readl (&ep->regs->ep_avail)) != 0) { 1013 } else if ((tmp = readl (&ep->regs->ep_avail)) != 0) {
diff --git a/drivers/usb/gadget/net2280.h b/drivers/usb/gadget/net2280.h
index 1f2af398a9a4..81a71dbdc2c6 100644
--- a/drivers/usb/gadget/net2280.h
+++ b/drivers/usb/gadget/net2280.h
@@ -272,7 +272,7 @@ static inline void net2280_led_shutdown (struct net2280 *dev)
272 272
273#define ERROR(dev,fmt,args...) \ 273#define ERROR(dev,fmt,args...) \
274 xprintk(dev , KERN_ERR , fmt , ## args) 274 xprintk(dev , KERN_ERR , fmt , ## args)
275#define WARN(dev,fmt,args...) \ 275#define WARNING(dev,fmt,args...) \
276 xprintk(dev , KERN_WARNING , fmt , ## args) 276 xprintk(dev , KERN_WARNING , fmt , ## args)
277#define INFO(dev,fmt,args...) \ 277#define INFO(dev,fmt,args...) \
278 xprintk(dev , KERN_INFO , fmt , ## args) 278 xprintk(dev , KERN_INFO , fmt , ## args)
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 4b79a8509e84..395bd1844482 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -1120,7 +1120,7 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value)
1120 status = -EINVAL; 1120 status = -EINVAL;
1121 else if (value) { 1121 else if (value) {
1122 if (ep->udc->ep0_set_config) { 1122 if (ep->udc->ep0_set_config) {
1123 WARN("error changing config?\n"); 1123 WARNING("error changing config?\n");
1124 omap_writew(UDC_CLR_CFG, UDC_SYSCON2); 1124 omap_writew(UDC_CLR_CFG, UDC_SYSCON2);
1125 } 1125 }
1126 omap_writew(UDC_STALL_CMD, UDC_SYSCON2); 1126 omap_writew(UDC_STALL_CMD, UDC_SYSCON2);
@@ -1764,7 +1764,7 @@ do_stall:
1764 u.r.bRequestType, u.r.bRequest, status); 1764 u.r.bRequestType, u.r.bRequest, status);
1765 if (udc->ep0_set_config) { 1765 if (udc->ep0_set_config) {
1766 if (udc->ep0_reset_config) 1766 if (udc->ep0_reset_config)
1767 WARN("error resetting config?\n"); 1767 WARNING("error resetting config?\n");
1768 else 1768 else
1769 omap_writew(UDC_CLR_CFG, UDC_SYSCON2); 1769 omap_writew(UDC_CLR_CFG, UDC_SYSCON2);
1770 } 1770 }
@@ -3076,7 +3076,7 @@ static int omap_udc_suspend(struct platform_device *dev, pm_message_t message)
3076 * which would prevent entry to deep sleep... 3076 * which would prevent entry to deep sleep...
3077 */ 3077 */
3078 if ((devstat & UDC_ATT) != 0 && (devstat & UDC_SUS) == 0) { 3078 if ((devstat & UDC_ATT) != 0 && (devstat & UDC_SUS) == 0) {
3079 WARN("session active; suspend requires disconnect\n"); 3079 WARNING("session active; suspend requires disconnect\n");
3080 omap_pullup(&udc->gadget, 0); 3080 omap_pullup(&udc->gadget, 0);
3081 } 3081 }
3082 3082
diff --git a/drivers/usb/gadget/omap_udc.h b/drivers/usb/gadget/omap_udc.h
index 8522bbb12278..29edc51b6b22 100644
--- a/drivers/usb/gadget/omap_udc.h
+++ b/drivers/usb/gadget/omap_udc.h
@@ -188,7 +188,7 @@ struct omap_udc {
188#endif 188#endif
189 189
190#define ERR(stuff...) pr_err("udc: " stuff) 190#define ERR(stuff...) pr_err("udc: " stuff)
191#define WARN(stuff...) pr_warning("udc: " stuff) 191#define WARNING(stuff...) pr_warning("udc: " stuff)
192#define INFO(stuff...) pr_info("udc: " stuff) 192#define INFO(stuff...) pr_info("udc: " stuff)
193#define DBG(stuff...) pr_debug("udc: " stuff) 193#define DBG(stuff...) pr_debug("udc: " stuff)
194 194
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index 49cd9e145a9b..e0090085b78e 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -179,7 +179,7 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR);
179 179
180#define ERROR(dev, fmt, args...) \ 180#define ERROR(dev, fmt, args...) \
181 xprintk(dev, KERN_ERR, fmt, ## args) 181 xprintk(dev, KERN_ERR, fmt, ## args)
182#define WARN(dev, fmt, args...) \ 182#define WARNING(dev, fmt, args...) \
183 xprintk(dev, KERN_WARNING, fmt, ## args) 183 xprintk(dev, KERN_WARNING, fmt, ## args)
184#define INFO(dev, fmt, args...) \ 184#define INFO(dev, fmt, args...) \
185 xprintk(dev, KERN_INFO, fmt, ## args) 185 xprintk(dev, KERN_INFO, fmt, ## args)
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index fbd6289977c8..7e6725d89976 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -152,9 +152,10 @@ static int is_vbus_present(void)
152static void pullup_off(void) 152static void pullup_off(void)
153{ 153{
154 struct pxa2xx_udc_mach_info *mach = the_controller->mach; 154 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
155 int off_level = mach->gpio_pullup_inverted;
155 156
156 if (mach->gpio_pullup) 157 if (mach->gpio_pullup)
157 gpio_set_value(mach->gpio_pullup, 0); 158 gpio_set_value(mach->gpio_pullup, off_level);
158 else if (mach->udc_command) 159 else if (mach->udc_command)
159 mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); 160 mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
160} 161}
@@ -162,9 +163,10 @@ static void pullup_off(void)
162static void pullup_on(void) 163static void pullup_on(void)
163{ 164{
164 struct pxa2xx_udc_mach_info *mach = the_controller->mach; 165 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
166 int on_level = !mach->gpio_pullup_inverted;
165 167
166 if (mach->gpio_pullup) 168 if (mach->gpio_pullup)
167 gpio_set_value(mach->gpio_pullup, 1); 169 gpio_set_value(mach->gpio_pullup, on_level);
168 else if (mach->udc_command) 170 else if (mach->udc_command)
169 mach->udc_command(PXA2XX_UDC_CMD_CONNECT); 171 mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
170} 172}
@@ -340,7 +342,7 @@ pxa25x_ep_free_request (struct usb_ep *_ep, struct usb_request *_req)
340 struct pxa25x_request *req; 342 struct pxa25x_request *req;
341 343
342 req = container_of (_req, struct pxa25x_request, req); 344 req = container_of (_req, struct pxa25x_request, req);
343 WARN_ON (!list_empty (&req->queue)); 345 WARN_ON(!list_empty (&req->queue));
344 kfree(req); 346 kfree(req);
345} 347}
346 348
@@ -1554,7 +1556,7 @@ config_change:
1554 * tell us about config change events, 1556 * tell us about config change events,
1555 * so later ones may fail... 1557 * so later ones may fail...
1556 */ 1558 */
1557 WARN("config change %02x fail %d?\n", 1559 WARNING("config change %02x fail %d?\n",
1558 u.r.bRequest, i); 1560 u.r.bRequest, i);
1559 return; 1561 return;
1560 /* TODO experiment: if has_cfr, 1562 /* TODO experiment: if has_cfr,
@@ -2328,7 +2330,7 @@ static int pxa25x_udc_suspend(struct platform_device *dev, pm_message_t state)
2328 unsigned long flags; 2330 unsigned long flags;
2329 2331
2330 if (!udc->mach->gpio_pullup && !udc->mach->udc_command) 2332 if (!udc->mach->gpio_pullup && !udc->mach->udc_command)
2331 WARN("USB host won't detect disconnect!\n"); 2333 WARNING("USB host won't detect disconnect!\n");
2332 udc->suspended = 1; 2334 udc->suspended = 1;
2333 2335
2334 local_irq_save(flags); 2336 local_irq_save(flags);
diff --git a/drivers/usb/gadget/pxa25x_udc.h b/drivers/usb/gadget/pxa25x_udc.h
index 4d11ece7c95f..c8a13215e02c 100644
--- a/drivers/usb/gadget/pxa25x_udc.h
+++ b/drivers/usb/gadget/pxa25x_udc.h
@@ -259,7 +259,7 @@ dump_state(struct pxa25x_udc *dev)
259#define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0) 259#define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0)
260 260
261#define ERR(stuff...) pr_err("udc: " stuff) 261#define ERR(stuff...) pr_err("udc: " stuff)
262#define WARN(stuff...) pr_warning("udc: " stuff) 262#define WARNING(stuff...) pr_warning("udc: " stuff)
263#define INFO(stuff...) pr_info("udc: " stuff) 263#define INFO(stuff...) pr_info("udc: " stuff)
264 264
265 265
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 5458f43a8668..3791e6271903 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -116,7 +116,6 @@ static inline int qlen(struct usb_gadget *gadget)
116#undef DBG 116#undef DBG
117#undef VDBG 117#undef VDBG
118#undef ERROR 118#undef ERROR
119#undef WARN
120#undef INFO 119#undef INFO
121 120
122#define xprintk(d, level, fmt, args...) \ 121#define xprintk(d, level, fmt, args...) \
@@ -140,8 +139,6 @@ static inline int qlen(struct usb_gadget *gadget)
140 139
141#define ERROR(dev, fmt, args...) \ 140#define ERROR(dev, fmt, args...) \
142 xprintk(dev , KERN_ERR , fmt , ## args) 141 xprintk(dev , KERN_ERR , fmt , ## args)
143#define WARN(dev, fmt, args...) \
144 xprintk(dev , KERN_WARNING , fmt , ## args)
145#define INFO(dev, fmt, args...) \ 142#define INFO(dev, fmt, args...) \
146 xprintk(dev , KERN_INFO , fmt , ## args) 143 xprintk(dev , KERN_INFO , fmt , ## args)
147 144
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 31178e10cbbe..ce1ca0ba0515 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -882,7 +882,7 @@ static void isp116x_endpoint_disable(struct usb_hcd *hcd,
882 for (i = 0; i < 100 && !list_empty(&hep->urb_list); i++) 882 for (i = 0; i < 100 && !list_empty(&hep->urb_list); i++)
883 msleep(3); 883 msleep(3);
884 if (!list_empty(&hep->urb_list)) 884 if (!list_empty(&hep->urb_list))
885 WARN("ep %p not empty?\n", ep); 885 WARNING("ep %p not empty?\n", ep);
886 886
887 kfree(ep); 887 kfree(ep);
888 hep->hcpriv = NULL; 888 hep->hcpriv = NULL;
diff --git a/drivers/usb/host/isp116x.h b/drivers/usb/host/isp116x.h
index 595b90a99848..aa211bafcff9 100644
--- a/drivers/usb/host/isp116x.h
+++ b/drivers/usb/host/isp116x.h
@@ -338,7 +338,7 @@ struct isp116x_ep {
338#endif 338#endif
339 339
340#define ERR(stuff...) printk(KERN_ERR "116x: " stuff) 340#define ERR(stuff...) printk(KERN_ERR "116x: " stuff)
341#define WARN(stuff...) printk(KERN_WARNING "116x: " stuff) 341#define WARNING(stuff...) printk(KERN_WARNING "116x: " stuff)
342#define INFO(stuff...) printk(KERN_INFO "116x: " stuff) 342#define INFO(stuff...) printk(KERN_INFO "116x: " stuff)
343 343
344/* ------------------------------------------------- */ 344/* ------------------------------------------------- */
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 340d72da554a..8a74bbb57d08 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -1026,7 +1026,7 @@ sl811h_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
1026 if (!list_empty(&hep->urb_list)) 1026 if (!list_empty(&hep->urb_list))
1027 msleep(3); 1027 msleep(3);
1028 if (!list_empty(&hep->urb_list)) 1028 if (!list_empty(&hep->urb_list))
1029 WARN("ep %p not empty?\n", ep); 1029 WARNING("ep %p not empty?\n", ep);
1030 1030
1031 kfree(ep); 1031 kfree(ep);
1032 hep->hcpriv = NULL; 1032 hep->hcpriv = NULL;
diff --git a/drivers/usb/host/sl811.h b/drivers/usb/host/sl811.h
index 7690d98e42a7..b6b8c1f233dd 100644
--- a/drivers/usb/host/sl811.h
+++ b/drivers/usb/host/sl811.h
@@ -261,6 +261,6 @@ sl811_read_buf(struct sl811 *sl811, int addr, void *buf, size_t count)
261#endif 261#endif
262 262
263#define ERR(stuff...) printk(KERN_ERR "sl811: " stuff) 263#define ERR(stuff...) printk(KERN_ERR "sl811: " stuff)
264#define WARN(stuff...) printk(KERN_WARNING "sl811: " stuff) 264#define WARNING(stuff...) printk(KERN_WARNING "sl811: " stuff)
265#define INFO(stuff...) printk(KERN_INFO "sl811: " stuff) 265#define INFO(stuff...) printk(KERN_INFO "sl811: " stuff)
266 266
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 054dedd28127..b358c4e1cf21 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -81,7 +81,7 @@ static struct usb_device *testdev_to_usbdev (struct usbtest_dev *test)
81 81
82#define ERROR(tdev, fmt, args...) \ 82#define ERROR(tdev, fmt, args...) \
83 dev_err(&(tdev)->intf->dev , fmt , ## args) 83 dev_err(&(tdev)->intf->dev , fmt , ## args)
84#define WARN(tdev, fmt, args...) \ 84#define WARNING(tdev, fmt, args...) \
85 dev_warn(&(tdev)->intf->dev , fmt , ## args) 85 dev_warn(&(tdev)->intf->dev , fmt , ## args)
86 86
87/*-------------------------------------------------------------------------*/ 87/*-------------------------------------------------------------------------*/
@@ -1946,7 +1946,7 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1946 1946
1947 status = get_endpoints (dev, intf); 1947 status = get_endpoints (dev, intf);
1948 if (status < 0) { 1948 if (status < 0) {
1949 WARN(dev, "couldn't get endpoints, %d\n", 1949 WARNING(dev, "couldn't get endpoints, %d\n",
1950 status); 1950 status);
1951 return status; 1951 return status;
1952 } 1952 }
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index 5e3e4e9b6c77..1f715436d6d3 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -87,7 +87,7 @@ struct mon_reader_text {
87 87
88static struct dentry *mon_dir; /* Usually /sys/kernel/debug/usbmon */ 88static struct dentry *mon_dir; /* Usually /sys/kernel/debug/usbmon */
89 89
90static void mon_text_ctor(struct kmem_cache *, void *); 90static void mon_text_ctor(void *);
91 91
92struct mon_text_ptr { 92struct mon_text_ptr {
93 int cnt, limit; 93 int cnt, limit;
@@ -720,7 +720,7 @@ void mon_text_del(struct mon_bus *mbus)
720/* 720/*
721 * Slab interface: constructor. 721 * Slab interface: constructor.
722 */ 722 */
723static void mon_text_ctor(struct kmem_cache *slab, void *mem) 723static void mon_text_ctor(void *mem)
724{ 724{
725 /* 725 /*
726 * Nothing to initialize. No, really! 726 * Nothing to initialize. No, really!
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 9b887ef64ff1..70d135e0cc47 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -1658,6 +1658,32 @@ config FB_PM3
1658 similar boards, 3DLabs Permedia3 Create!, Appian Jeronimo 2000 1658 similar boards, 3DLabs Permedia3 Create!, Appian Jeronimo 2000
1659 and maybe other boards. 1659 and maybe other boards.
1660 1660
1661config FB_CARMINE
1662 tristate "Fujitsu carmine frame buffer support"
1663 depends on FB && PCI
1664 select FB_CFB_FILLRECT
1665 select FB_CFB_COPYAREA
1666 select FB_CFB_IMAGEBLIT
1667 help
1668 This is the frame buffer device driver for the Fujitsu Carmine chip.
1669 The driver provides two independent frame buffer devices.
1670
1671choice
1672 depends on FB_CARMINE
1673 prompt "DRAM timing"
1674 default FB_CARMINE_DRAM_EVAL
1675
1676config FB_CARMINE_DRAM_EVAL
1677 bool "Eval board timings"
1678 help
1679 Use timings which work on the eval card.
1680
1681config CARMINE_DRAM_CUSTOM
1682 bool "Custom board timings"
1683 help
1684 Use custom board timings.
1685endchoice
1686
1661config FB_AU1100 1687config FB_AU1100
1662 bool "Au1100 LCD Driver" 1688 bool "Au1100 LCD Driver"
1663 depends on (FB = y) && MIPS && SOC_AU1100 1689 depends on (FB = y) && MIPS && SOC_AU1100
@@ -1840,6 +1866,16 @@ config FB_W100
1840 1866
1841 If unsure, say N. 1867 If unsure, say N.
1842 1868
1869config FB_SH_MOBILE_LCDC
1870 tristate "SuperH Mobile LCDC framebuffer support"
1871 depends on FB && SUPERH
1872 select FB_CFB_FILLRECT
1873 select FB_CFB_COPYAREA
1874 select FB_CFB_IMAGEBLIT
1875 default m
1876 ---help---
1877 Frame buffer driver for the on-chip SH-Mobile LCD controller.
1878
1843config FB_S3C2410 1879config FB_S3C2410
1844 tristate "S3C2410 LCD framebuffer support" 1880 tristate "S3C2410 LCD framebuffer support"
1845 depends on FB && ARCH_S3C2410 1881 depends on FB && ARCH_S3C2410
@@ -1951,6 +1987,23 @@ config FB_AM200EPD
1951 This enables support for the Metronome display controller used on 1987 This enables support for the Metronome display controller used on
1952 the E-Ink AM-200 EPD devkit. 1988 the E-Ink AM-200 EPD devkit.
1953 1989
1990config FB_COBALT
1991 tristate "Cobalt server LCD frame buffer support"
1992 depends on FB && MIPS_COBALT
1993
1994config FB_SH7760
1995 bool "SH7760/SH7763 LCDC support"
1996 depends on FB && (CPU_SUBTYPE_SH7760 || CPU_SUBTYPE_SH7763)
1997 select FB_CFB_FILLRECT
1998 select FB_CFB_COPYAREA
1999 select FB_CFB_IMAGEBLIT
2000 help
2001 Support for the SH7760/SH7763 integrated (D)STN/TFT LCD Controller.
2002 Supports display resolutions up to 1024x1024 pixel, grayscale and
2003 color operation, with depths ranging from 1 bpp to 8 bpp monochrome
2004 and 8, 15 or 16 bpp color; 90 degrees clockwise display rotation for
2005 panels <= 320 pixel horizontal resolution.
2006
1954config FB_VIRTUAL 2007config FB_VIRTUAL
1955 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)" 2008 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)"
1956 depends on FB 2009 depends on FB
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 04bca35403ff..0ebc1bfd2514 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -106,17 +106,22 @@ obj-$(CONFIG_FB_PMAGB_B) += pmagb-b-fb.o
106obj-$(CONFIG_FB_MAXINE) += maxinefb.o 106obj-$(CONFIG_FB_MAXINE) += maxinefb.o
107obj-$(CONFIG_FB_METRONOME) += metronomefb.o 107obj-$(CONFIG_FB_METRONOME) += metronomefb.o
108obj-$(CONFIG_FB_S1D13XXX) += s1d13xxxfb.o 108obj-$(CONFIG_FB_S1D13XXX) += s1d13xxxfb.o
109obj-$(CONFIG_FB_SH7760) += sh7760fb.o
109obj-$(CONFIG_FB_IMX) += imxfb.o 110obj-$(CONFIG_FB_IMX) += imxfb.o
110obj-$(CONFIG_FB_S3C2410) += s3c2410fb.o 111obj-$(CONFIG_FB_S3C2410) += s3c2410fb.o
111obj-$(CONFIG_FB_FSL_DIU) += fsl-diu-fb.o 112obj-$(CONFIG_FB_FSL_DIU) += fsl-diu-fb.o
113obj-$(CONFIG_FB_COBALT) += cobalt_lcdfb.o
112obj-$(CONFIG_FB_PNX4008_DUM) += pnx4008/ 114obj-$(CONFIG_FB_PNX4008_DUM) += pnx4008/
113obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnx4008/ 115obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnx4008/
114obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o 116obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o
115obj-$(CONFIG_FB_PS3) += ps3fb.o 117obj-$(CONFIG_FB_PS3) += ps3fb.o
116obj-$(CONFIG_FB_SM501) += sm501fb.o 118obj-$(CONFIG_FB_SM501) += sm501fb.o
117obj-$(CONFIG_FB_XILINX) += xilinxfb.o 119obj-$(CONFIG_FB_XILINX) += xilinxfb.o
120obj-$(CONFIG_FB_SH_MOBILE_LCDC) += sh_mobile_lcdcfb.o
121obj-$(CONFIG_FB_SH7343VOU) += sh7343_voufb.o
118obj-$(CONFIG_FB_OMAP) += omap/ 122obj-$(CONFIG_FB_OMAP) += omap/
119obj-$(CONFIG_XEN_FBDEV_FRONTEND) += xen-fbfront.o 123obj-$(CONFIG_XEN_FBDEV_FRONTEND) += xen-fbfront.o
124obj-$(CONFIG_FB_CARMINE) += carminefb.o
120 125
121# Platform or fallback drivers go here 126# Platform or fallback drivers go here
122obj-$(CONFIG_FB_UVESA) += uvesafb.o 127obj-$(CONFIG_FB_UVESA) += uvesafb.o
diff --git a/drivers/video/acornfb.c b/drivers/video/acornfb.c
index eedb8285e32f..017233d0c481 100644
--- a/drivers/video/acornfb.c
+++ b/drivers/video/acornfb.c
@@ -23,6 +23,7 @@
23#include <linux/string.h> 23#include <linux/string.h>
24#include <linux/ctype.h> 24#include <linux/ctype.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/mm.h>
26#include <linux/init.h> 27#include <linux/init.h>
27#include <linux/fb.h> 28#include <linux/fb.h>
28#include <linux/platform_device.h> 29#include <linux/platform_device.h>
diff --git a/drivers/video/amifb.c b/drivers/video/amifb.c
index 45c154ade9ca..b8e9a8682f2d 100644
--- a/drivers/video/amifb.c
+++ b/drivers/video/amifb.c
@@ -1136,7 +1136,6 @@ static int amifb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg
1136 * Interface to the low level console driver 1136 * Interface to the low level console driver
1137 */ 1137 */
1138 1138
1139int amifb_init(void);
1140static void amifb_deinit(void); 1139static void amifb_deinit(void);
1141 1140
1142 /* 1141 /*
@@ -2048,13 +2047,16 @@ static void amifb_copyarea(struct fb_info *info,
2048 width = x2 - dx; 2047 width = x2 - dx;
2049 height = y2 - dy; 2048 height = y2 - dy;
2050 2049
2050 if (area->sx + dx < area->dx || area->sy + dy < area->dy)
2051 return;
2052
2051 /* update sx,sy */ 2053 /* update sx,sy */
2052 sx = area->sx + (dx - area->dx); 2054 sx = area->sx + (dx - area->dx);
2053 sy = area->sy + (dy - area->dy); 2055 sy = area->sy + (dy - area->dy);
2054 2056
2055 /* the source must be completely inside the virtual screen */ 2057 /* the source must be completely inside the virtual screen */
2056 if (sx < 0 || sy < 0 || (sx + width) > info->var.xres_virtual || 2058 if (sx + width > info->var.xres_virtual ||
2057 (sy + height) > info->var.yres_virtual) 2059 sy + height > info->var.yres_virtual)
2058 return; 2060 return;
2059 2061
2060 if (dy > sy || (dy == sy && dx > sx)) { 2062 if (dy > sy || (dy == sy && dx > sx)) {
@@ -2245,7 +2247,7 @@ static inline void chipfree(void)
2245 * Initialisation 2247 * Initialisation
2246 */ 2248 */
2247 2249
2248int __init amifb_init(void) 2250static int __init amifb_init(void)
2249{ 2251{
2250 int tag, i, err = 0; 2252 int tag, i, err = 0;
2251 u_long chipptr; 2253 u_long chipptr;
@@ -3790,16 +3792,14 @@ static void ami_rebuild_copper(void)
3790 } 3792 }
3791} 3793}
3792 3794
3793 3795static void __exit amifb_exit(void)
3794module_init(amifb_init);
3795
3796#ifdef MODULE
3797MODULE_LICENSE("GPL");
3798
3799void cleanup_module(void)
3800{ 3796{
3801 unregister_framebuffer(&fb_info); 3797 unregister_framebuffer(&fb_info);
3802 amifb_deinit(); 3798 amifb_deinit();
3803 amifb_video_off(); 3799 amifb_video_off();
3804} 3800}
3805#endif /* MODULE */ 3801
3802module_init(amifb_init);
3803module_exit(amifb_exit);
3804
3805MODULE_LICENSE("GPL");
diff --git a/drivers/video/atafb.c b/drivers/video/atafb.c
index fa55d356b535..77eb8b34fbfa 100644
--- a/drivers/video/atafb.c
+++ b/drivers/video/atafb.c
@@ -2593,13 +2593,16 @@ static void atafb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
2593 width = x2 - dx; 2593 width = x2 - dx;
2594 height = y2 - dy; 2594 height = y2 - dy;
2595 2595
2596 if (area->sx + dx < area->dx || area->sy + dy < area->dy)
2597 return;
2598
2596 /* update sx,sy */ 2599 /* update sx,sy */
2597 sx = area->sx + (dx - area->dx); 2600 sx = area->sx + (dx - area->dx);
2598 sy = area->sy + (dy - area->dy); 2601 sy = area->sy + (dy - area->dy);
2599 2602
2600 /* the source must be completely inside the virtual screen */ 2603 /* the source must be completely inside the virtual screen */
2601 if (sx < 0 || sy < 0 || (sx + width) > info->var.xres_virtual || 2604 if (sx + width > info->var.xres_virtual ||
2602 (sy + height) > info->var.yres_virtual) 2605 sy + height > info->var.yres_virtual)
2603 return; 2606 return;
2604 2607
2605 if (dy > sy || (dy == sy && dx > sx)) { 2608 if (dy > sy || (dy == sy && dx > sx)) {
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
index b004036d4087..5b3a15dffb5f 100644
--- a/drivers/video/atmel_lcdfb.c
+++ b/drivers/video/atmel_lcdfb.c
@@ -256,6 +256,20 @@ static int atmel_lcdfb_alloc_video_memory(struct atmel_lcdfb_info *sinfo)
256 return 0; 256 return 0;
257} 257}
258 258
259static const struct fb_videomode *atmel_lcdfb_choose_mode(struct fb_var_screeninfo *var,
260 struct fb_info *info)
261{
262 struct fb_videomode varfbmode;
263 const struct fb_videomode *fbmode = NULL;
264
265 fb_var_to_videomode(&varfbmode, var);
266 fbmode = fb_find_nearest_mode(&varfbmode, &info->modelist);
267 if (fbmode)
268 fb_videomode_to_var(var, fbmode);
269 return fbmode;
270}
271
272
259/** 273/**
260 * atmel_lcdfb_check_var - Validates a var passed in. 274 * atmel_lcdfb_check_var - Validates a var passed in.
261 * @var: frame buffer variable screen structure 275 * @var: frame buffer variable screen structure
@@ -289,6 +303,15 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
289 clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000; 303 clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
290 304
291 dev_dbg(dev, "%s:\n", __func__); 305 dev_dbg(dev, "%s:\n", __func__);
306
307 if (!(var->pixclock && var->bits_per_pixel)) {
308 /* choose a suitable mode if possible */
309 if (!atmel_lcdfb_choose_mode(var, info)) {
310 dev_err(dev, "needed value not specified\n");
311 return -EINVAL;
312 }
313 }
314
292 dev_dbg(dev, " resolution: %ux%u\n", var->xres, var->yres); 315 dev_dbg(dev, " resolution: %ux%u\n", var->xres, var->yres);
293 dev_dbg(dev, " pixclk: %lu KHz\n", PICOS2KHZ(var->pixclock)); 316 dev_dbg(dev, " pixclk: %lu KHz\n", PICOS2KHZ(var->pixclock));
294 dev_dbg(dev, " bpp: %u\n", var->bits_per_pixel); 317 dev_dbg(dev, " bpp: %u\n", var->bits_per_pixel);
@@ -299,6 +322,13 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
299 return -EINVAL; 322 return -EINVAL;
300 } 323 }
301 324
325 /* Do not allow to have real resoulution larger than virtual */
326 if (var->xres > var->xres_virtual)
327 var->xres_virtual = var->xres;
328
329 if (var->yres > var->yres_virtual)
330 var->yres_virtual = var->yres;
331
302 /* Force same alignment for each line */ 332 /* Force same alignment for each line */
303 var->xres = (var->xres + 3) & ~3UL; 333 var->xres = (var->xres + 3) & ~3UL;
304 var->xres_virtual = (var->xres_virtual + 3) & ~3UL; 334 var->xres_virtual = (var->xres_virtual + 3) & ~3UL;
@@ -379,6 +409,35 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
379 return 0; 409 return 0;
380} 410}
381 411
412/*
413 * LCD reset sequence
414 */
415static void atmel_lcdfb_reset(struct atmel_lcdfb_info *sinfo)
416{
417 might_sleep();
418
419 /* LCD power off */
420 lcdc_writel(sinfo, ATMEL_LCDC_PWRCON, sinfo->guard_time << ATMEL_LCDC_GUARDT_OFFSET);
421
422 /* wait for the LCDC core to become idle */
423 while (lcdc_readl(sinfo, ATMEL_LCDC_PWRCON) & ATMEL_LCDC_BUSY)
424 msleep(10);
425
426 /* DMA disable */
427 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, 0);
428
429 /* wait for DMA engine to become idle */
430 while (lcdc_readl(sinfo, ATMEL_LCDC_DMACON) & ATMEL_LCDC_DMABUSY)
431 msleep(10);
432
433 /* LCD power on */
434 lcdc_writel(sinfo, ATMEL_LCDC_PWRCON,
435 (sinfo->guard_time << ATMEL_LCDC_GUARDT_OFFSET) | ATMEL_LCDC_PWR);
436
437 /* DMA enable */
438 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, sinfo->default_dmacon);
439}
440
382/** 441/**
383 * atmel_lcdfb_set_par - Alters the hardware state. 442 * atmel_lcdfb_set_par - Alters the hardware state.
384 * @info: frame buffer structure that represents a single frame buffer 443 * @info: frame buffer structure that represents a single frame buffer
@@ -401,6 +460,8 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
401 unsigned long clk_value_khz; 460 unsigned long clk_value_khz;
402 unsigned long bits_per_line; 461 unsigned long bits_per_line;
403 462
463 might_sleep();
464
404 dev_dbg(info->device, "%s:\n", __func__); 465 dev_dbg(info->device, "%s:\n", __func__);
405 dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n", 466 dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n",
406 info->var.xres, info->var.yres, 467 info->var.xres, info->var.yres,
@@ -511,6 +572,8 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
511 572
512 /* Disable all interrupts */ 573 /* Disable all interrupts */
513 lcdc_writel(sinfo, ATMEL_LCDC_IDR, ~0UL); 574 lcdc_writel(sinfo, ATMEL_LCDC_IDR, ~0UL);
575 /* Enable FIFO & DMA errors */
576 lcdc_writel(sinfo, ATMEL_LCDC_IER, ATMEL_LCDC_UFLWI | ATMEL_LCDC_OWRI | ATMEL_LCDC_MERI);
514 577
515 /* ...wait for DMA engine to become idle... */ 578 /* ...wait for DMA engine to become idle... */
516 while (lcdc_readl(sinfo, ATMEL_LCDC_DMACON) & ATMEL_LCDC_DMABUSY) 579 while (lcdc_readl(sinfo, ATMEL_LCDC_DMACON) & ATMEL_LCDC_DMABUSY)
@@ -645,10 +708,26 @@ static irqreturn_t atmel_lcdfb_interrupt(int irq, void *dev_id)
645 u32 status; 708 u32 status;
646 709
647 status = lcdc_readl(sinfo, ATMEL_LCDC_ISR); 710 status = lcdc_readl(sinfo, ATMEL_LCDC_ISR);
648 lcdc_writel(sinfo, ATMEL_LCDC_IDR, status); 711 if (status & ATMEL_LCDC_UFLWI) {
712 dev_warn(info->device, "FIFO underflow %#x\n", status);
713 /* reset DMA and FIFO to avoid screen shifting */
714 schedule_work(&sinfo->task);
715 }
716 lcdc_writel(sinfo, ATMEL_LCDC_ICR, status);
649 return IRQ_HANDLED; 717 return IRQ_HANDLED;
650} 718}
651 719
720/*
721 * LCD controller task (to reset the LCD)
722 */
723static void atmel_lcdfb_task(struct work_struct *work)
724{
725 struct atmel_lcdfb_info *sinfo =
726 container_of(work, struct atmel_lcdfb_info, task);
727
728 atmel_lcdfb_reset(sinfo);
729}
730
652static int __init atmel_lcdfb_init_fbinfo(struct atmel_lcdfb_info *sinfo) 731static int __init atmel_lcdfb_init_fbinfo(struct atmel_lcdfb_info *sinfo)
653{ 732{
654 struct fb_info *info = sinfo->info; 733 struct fb_info *info = sinfo->info;
@@ -691,6 +770,7 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev)
691 struct fb_info *info; 770 struct fb_info *info;
692 struct atmel_lcdfb_info *sinfo; 771 struct atmel_lcdfb_info *sinfo;
693 struct atmel_lcdfb_info *pdata_sinfo; 772 struct atmel_lcdfb_info *pdata_sinfo;
773 struct fb_videomode fbmode;
694 struct resource *regs = NULL; 774 struct resource *regs = NULL;
695 struct resource *map = NULL; 775 struct resource *map = NULL;
696 int ret; 776 int ret;
@@ -824,6 +904,10 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev)
824 goto unmap_mmio; 904 goto unmap_mmio;
825 } 905 }
826 906
907 /* Some operations on the LCDC might sleep and
908 * require a preemptible task context */
909 INIT_WORK(&sinfo->task, atmel_lcdfb_task);
910
827 ret = atmel_lcdfb_init_fbinfo(sinfo); 911 ret = atmel_lcdfb_init_fbinfo(sinfo);
828 if (ret < 0) { 912 if (ret < 0) {
829 dev_err(dev, "init fbinfo failed: %d\n", ret); 913 dev_err(dev, "init fbinfo failed: %d\n", ret);
@@ -853,6 +937,10 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev)
853 goto free_cmap; 937 goto free_cmap;
854 } 938 }
855 939
940 /* add selected videomode to modelist */
941 fb_var_to_videomode(&fbmode, &info->var);
942 fb_add_videomode(&fbmode, &info->modelist);
943
856 /* Power up the LCDC screen */ 944 /* Power up the LCDC screen */
857 if (sinfo->atmel_lcdfb_power_control) 945 if (sinfo->atmel_lcdfb_power_control)
858 sinfo->atmel_lcdfb_power_control(1); 946 sinfo->atmel_lcdfb_power_control(1);
@@ -866,6 +954,7 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev)
866free_cmap: 954free_cmap:
867 fb_dealloc_cmap(&info->cmap); 955 fb_dealloc_cmap(&info->cmap);
868unregister_irqs: 956unregister_irqs:
957 cancel_work_sync(&sinfo->task);
869 free_irq(sinfo->irq_base, info); 958 free_irq(sinfo->irq_base, info);
870unmap_mmio: 959unmap_mmio:
871 exit_backlight(sinfo); 960 exit_backlight(sinfo);
@@ -903,6 +992,7 @@ static int __exit atmel_lcdfb_remove(struct platform_device *pdev)
903 if (!sinfo) 992 if (!sinfo)
904 return 0; 993 return 0;
905 994
995 cancel_work_sync(&sinfo->task);
906 exit_backlight(sinfo); 996 exit_backlight(sinfo);
907 if (sinfo->atmel_lcdfb_power_control) 997 if (sinfo->atmel_lcdfb_power_control)
908 sinfo->atmel_lcdfb_power_control(0); 998 sinfo->atmel_lcdfb_power_control(0);
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 07b6addbb3c1..243ea4ab20c8 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -1339,10 +1339,8 @@ static int aty128_var_to_pll(u32 period_in_ps, struct aty128_pll *pll,
1339 if (vclk * 12 < c.ppll_min) 1339 if (vclk * 12 < c.ppll_min)
1340 vclk = c.ppll_min/12; 1340 vclk = c.ppll_min/12;
1341 1341
1342 pll->post_divider = -1;
1343
1344 /* now, find an acceptable divider */ 1342 /* now, find an acceptable divider */
1345 for (i = 0; i < sizeof(post_dividers); i++) { 1343 for (i = 0; i < ARRAY_SIZE(post_dividers); i++) {
1346 output_freq = post_dividers[i] * vclk; 1344 output_freq = post_dividers[i] * vclk;
1347 if (output_freq >= c.ppll_min && output_freq <= c.ppll_max) { 1345 if (output_freq >= c.ppll_min && output_freq <= c.ppll_max) {
1348 pll->post_divider = post_dividers[i]; 1346 pll->post_divider = post_dividers[i];
@@ -1350,7 +1348,7 @@ static int aty128_var_to_pll(u32 period_in_ps, struct aty128_pll *pll,
1350 } 1348 }
1351 } 1349 }
1352 1350
1353 if (pll->post_divider < 0) 1351 if (i == ARRAY_SIZE(post_dividers))
1354 return -EINVAL; 1352 return -EINVAL;
1355 1353
1356 /* calculate feedback divider */ 1354 /* calculate feedback divider */
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index bd4ac0bafecb..620ba8120368 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -424,7 +424,6 @@ static struct {
424#endif /* CONFIG_FB_ATY_CT */ 424#endif /* CONFIG_FB_ATY_CT */
425}; 425};
426 426
427/* can not fail */
428static int __devinit correct_chipset(struct atyfb_par *par) 427static int __devinit correct_chipset(struct atyfb_par *par)
429{ 428{
430 u8 rev; 429 u8 rev;
@@ -437,6 +436,9 @@ static int __devinit correct_chipset(struct atyfb_par *par)
437 if (par->pci_id == aty_chips[i].pci_id) 436 if (par->pci_id == aty_chips[i].pci_id)
438 break; 437 break;
439 438
439 if (i < 0)
440 return -ENODEV;
441
440 name = aty_chips[i].name; 442 name = aty_chips[i].name;
441 par->pll_limits.pll_max = aty_chips[i].pll; 443 par->pll_limits.pll_max = aty_chips[i].pll;
442 par->pll_limits.mclk = aty_chips[i].mclk; 444 par->pll_limits.mclk = aty_chips[i].mclk;
@@ -2229,6 +2231,7 @@ static int __devinit aty_init(struct fb_info *info)
2229 const char *ramname = NULL, *xtal; 2231 const char *ramname = NULL, *xtal;
2230 int gtb_memsize, has_var = 0; 2232 int gtb_memsize, has_var = 0;
2231 struct fb_var_screeninfo var; 2233 struct fb_var_screeninfo var;
2234 int ret;
2232 2235
2233 init_waitqueue_head(&par->vblank.wait); 2236 init_waitqueue_head(&par->vblank.wait);
2234 spin_lock_init(&par->int_lock); 2237 spin_lock_init(&par->int_lock);
@@ -2610,7 +2613,8 @@ static int __devinit aty_init(struct fb_info *info)
2610 var.yres_virtual = var.yres; 2613 var.yres_virtual = var.yres;
2611 } 2614 }
2612 2615
2613 if (atyfb_check_var(&var, info)) { 2616 ret = atyfb_check_var(&var, info);
2617 if (ret) {
2614 PRINTKE("can't set default video mode\n"); 2618 PRINTKE("can't set default video mode\n");
2615 goto aty_init_exit; 2619 goto aty_init_exit;
2616 } 2620 }
@@ -2621,10 +2625,12 @@ static int __devinit aty_init(struct fb_info *info)
2621#endif /* CONFIG_FB_ATY_CT */ 2625#endif /* CONFIG_FB_ATY_CT */
2622 info->var = var; 2626 info->var = var;
2623 2627
2624 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) 2628 ret = fb_alloc_cmap(&info->cmap, 256, 0);
2629 if (ret < 0)
2625 goto aty_init_exit; 2630 goto aty_init_exit;
2626 2631
2627 if (register_framebuffer(info) < 0) { 2632 ret = register_framebuffer(info);
2633 if (ret < 0) {
2628 fb_dealloc_cmap(&info->cmap); 2634 fb_dealloc_cmap(&info->cmap);
2629 goto aty_init_exit; 2635 goto aty_init_exit;
2630 } 2636 }
@@ -2650,7 +2656,7 @@ aty_init_exit:
2650 par->mtrr_aper = -1; 2656 par->mtrr_aper = -1;
2651 } 2657 }
2652#endif 2658#endif
2653 return -1; 2659 return ret;
2654} 2660}
2655 2661
2656static void aty_resume_chip(struct fb_info *info) 2662static void aty_resume_chip(struct fb_info *info)
@@ -2709,8 +2715,7 @@ static int atyfb_blank(int blank, struct fb_info *info)
2709 if (par->lock_blank || par->asleep) 2715 if (par->lock_blank || par->asleep)
2710 return 0; 2716 return 0;
2711 2717
2712#ifdef CONFIG_FB_ATY_BACKLIGHT 2718#ifdef CONFIG_FB_ATY_GENERIC_LCD
2713#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
2714 if (par->lcd_table && blank > FB_BLANK_NORMAL && 2719 if (par->lcd_table && blank > FB_BLANK_NORMAL &&
2715 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) { 2720 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
2716 u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par); 2721 u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par);
@@ -2739,8 +2744,7 @@ static int atyfb_blank(int blank, struct fb_info *info)
2739 } 2744 }
2740 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par); 2745 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par);
2741 2746
2742#ifdef CONFIG_FB_ATY_BACKLIGHT 2747#ifdef CONFIG_FB_ATY_GENERIC_LCD
2743#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
2744 if (par->lcd_table && blank <= FB_BLANK_NORMAL && 2748 if (par->lcd_table && blank <= FB_BLANK_NORMAL &&
2745 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) { 2749 (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
2746 u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par); 2750 u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par);
@@ -3331,7 +3335,7 @@ static int __devinit init_from_bios(struct atyfb_par *par)
3331 PRINTKE("no BIOS frequency table found, use parameters\n"); 3335 PRINTKE("no BIOS frequency table found, use parameters\n");
3332 ret = -ENXIO; 3336 ret = -ENXIO;
3333 } 3337 }
3334 iounmap((void* __iomem )bios_base); 3338 iounmap((void __iomem *)bios_base);
3335 3339
3336 return ret; 3340 return ret;
3337} 3341}
@@ -3418,14 +3422,7 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
3418 struct fb_info *info; 3422 struct fb_info *info;
3419 struct resource *rp; 3423 struct resource *rp;
3420 struct atyfb_par *par; 3424 struct atyfb_par *par;
3421 int i, rc = -ENOMEM; 3425 int rc = -ENOMEM;
3422
3423 for (i = ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
3424 if (pdev->device == aty_chips[i].pci_id)
3425 break;
3426
3427 if (i < 0)
3428 return -ENODEV;
3429 3426
3430 /* Enable device in PCI config */ 3427 /* Enable device in PCI config */
3431 if (pci_enable_device(pdev)) { 3428 if (pci_enable_device(pdev)) {
@@ -3456,7 +3453,7 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
3456 par = info->par; 3453 par = info->par;
3457 info->fix = atyfb_fix; 3454 info->fix = atyfb_fix;
3458 info->device = &pdev->dev; 3455 info->device = &pdev->dev;
3459 par->pci_id = aty_chips[i].pci_id; 3456 par->pci_id = pdev->device;
3460 par->res_start = res_start; 3457 par->res_start = res_start;
3461 par->res_size = res_size; 3458 par->res_size = res_size;
3462 par->irq = pdev->irq; 3459 par->irq = pdev->irq;
@@ -3474,7 +3471,8 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
3474 pci_set_drvdata(pdev, info); 3471 pci_set_drvdata(pdev, info);
3475 3472
3476 /* Init chip & register framebuffer */ 3473 /* Init chip & register framebuffer */
3477 if (aty_init(info)) 3474 rc = aty_init(info);
3475 if (rc)
3478 goto err_release_io; 3476 goto err_release_io;
3479 3477
3480#ifdef __sparc__ 3478#ifdef __sparc__
@@ -3655,18 +3653,62 @@ static void __devexit atyfb_pci_remove(struct pci_dev *pdev)
3655 atyfb_remove(info); 3653 atyfb_remove(info);
3656} 3654}
3657 3655
3658/*
3659 * This driver uses its own matching table. That will be more difficult
3660 * to fix, so for now, we just match against any ATI ID and let the
3661 * probe() function find out what's up. That also mean we don't have
3662 * a module ID table though.
3663 */
3664static struct pci_device_id atyfb_pci_tbl[] = { 3656static struct pci_device_id atyfb_pci_tbl[] = {
3665 { PCI_VENDOR_ID_ATI, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 3657#ifdef CONFIG_FB_ATY_GX
3666 PCI_BASE_CLASS_DISPLAY << 16, 0xff0000, 0 }, 3658 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GX) },
3667 { 0, } 3659 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64CX) },
3660#endif /* CONFIG_FB_ATY_GX */
3661
3662#ifdef CONFIG_FB_ATY_CT
3663 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64CT) },
3664 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64ET) },
3665
3666 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LT) },
3667
3668 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64VT) },
3669 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GT) },
3670
3671 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64VU) },
3672 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GU) },
3673
3674 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LG) },
3675
3676 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64VV) },
3677
3678 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GV) },
3679 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GW) },
3680 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GY) },
3681 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GZ) },
3682
3683 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GB) },
3684 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GD) },
3685 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GI) },
3686 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GP) },
3687 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GQ) },
3688
3689 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LB) },
3690 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LD) },
3691 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LI) },
3692 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LP) },
3693 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LQ) },
3694
3695 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GM) },
3696 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GN) },
3697 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GO) },
3698 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GL) },
3699 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GR) },
3700 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GS) },
3701
3702 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LM) },
3703 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LN) },
3704 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LR) },
3705 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LS) },
3706#endif /* CONFIG_FB_ATY_CT */
3707 { }
3668}; 3708};
3669 3709
3710MODULE_DEVICE_TABLE(pci, atyfb_pci_tbl);
3711
3670static struct pci_driver atyfb_driver = { 3712static struct pci_driver atyfb_driver = {
3671 .name = "atyfb", 3713 .name = "atyfb",
3672 .id_table = atyfb_pci_tbl, 3714 .id_table = atyfb_pci_tbl,
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index 400e9264e456..652273e9f5f9 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -2098,15 +2098,7 @@ static void radeon_identify_vram(struct radeonfb_info *rinfo)
2098 2098
2099static ssize_t radeon_show_one_edid(char *buf, loff_t off, size_t count, const u8 *edid) 2099static ssize_t radeon_show_one_edid(char *buf, loff_t off, size_t count, const u8 *edid)
2100{ 2100{
2101 if (off > EDID_LENGTH) 2101 return memory_read_from_buffer(buf, count, &off, edid, EDID_LENGTH);
2102 return 0;
2103
2104 if (off + count > EDID_LENGTH)
2105 count = EDID_LENGTH - off;
2106
2107 memcpy(buf, edid + off, count);
2108
2109 return count;
2110} 2102}
2111 2103
2112 2104
@@ -2161,6 +2153,7 @@ static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
2161 struct radeonfb_info *rinfo; 2153 struct radeonfb_info *rinfo;
2162 int ret; 2154 int ret;
2163 unsigned char c1, c2; 2155 unsigned char c1, c2;
2156 int err = 0;
2164 2157
2165 pr_debug("radeonfb_pci_register BEGIN\n"); 2158 pr_debug("radeonfb_pci_register BEGIN\n");
2166 2159
@@ -2340,9 +2333,14 @@ static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
2340 2333
2341 /* Register some sysfs stuff (should be done better) */ 2334 /* Register some sysfs stuff (should be done better) */
2342 if (rinfo->mon1_EDID) 2335 if (rinfo->mon1_EDID)
2343 sysfs_create_bin_file(&rinfo->pdev->dev.kobj, &edid1_attr); 2336 err |= sysfs_create_bin_file(&rinfo->pdev->dev.kobj,
2337 &edid1_attr);
2344 if (rinfo->mon2_EDID) 2338 if (rinfo->mon2_EDID)
2345 sysfs_create_bin_file(&rinfo->pdev->dev.kobj, &edid2_attr); 2339 err |= sysfs_create_bin_file(&rinfo->pdev->dev.kobj,
2340 &edid2_attr);
2341 if (err)
2342 pr_warning("%s() Creating sysfs files failed, continuing\n",
2343 __func__);
2346 2344
2347 /* save current mode regs before we switch into the new one 2345 /* save current mode regs before we switch into the new one
2348 * so we can restore this upon __exit 2346 * so we can restore this upon __exit
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 30bf7f2f1635..452b770d8cc9 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -36,6 +36,30 @@ config LCD_LTV350QV
36 36
37 The LTV350QV panel is present on all ATSTK1000 boards. 37 The LTV350QV panel is present on all ATSTK1000 boards.
38 38
39config LCD_ILI9320
40 tristate
41 depends on LCD_CLASS_DEVICE && BACKLIGHT_LCD_SUPPORT
42 default n
43 help
44 If you have a panel based on the ILI9320 controller chip
45 then say y to include a power driver for it.
46
47config LCD_VGG2432A4
48 tristate "VGG2432A4 LCM device support"
49 depends on BACKLIGHT_LCD_SUPPORT && LCD_CLASS_DEVICE && SPI_MASTER
50 select LCD_ILI9320
51 default n
52 help
53 If you have a VGG2432A4 panel based on the ILI9320 controller chip
54 then say y to include a power driver for it.
55
56config LCD_PLATFORM
57 tristate "Platform LCD controls"
58 depends on LCD_CLASS_DEVICE
59 help
60 This driver provides a platform-device registered LCD power
61 control interface.
62
39# 63#
40# Backlight 64# Backlight
41# 65#
@@ -63,6 +87,18 @@ config BACKLIGHT_ATMEL_LCDC
63 If in doubt, it's safe to enable this option; it doesn't kick 87 If in doubt, it's safe to enable this option; it doesn't kick
64 in unless the board's description says it's wired that way. 88 in unless the board's description says it's wired that way.
65 89
90config BACKLIGHT_ATMEL_PWM
91 tristate "Atmel PWM backlight control"
92 depends on BACKLIGHT_CLASS_DEVICE && ATMEL_PWM
93 default n
94 help
95 Say Y here if you want to use the PWM peripheral in Atmel AT91 and
96 AVR32 devices. This driver will need additional platform data to know
97 which PWM instance to use and how to configure it.
98
99 To compile this driver as a module, choose M here: the module will be
100 called atmel-pwm-bl.
101
66config BACKLIGHT_CORGI 102config BACKLIGHT_CORGI
67 tristate "Generic (aka Sharp Corgi) Backlight Driver" 103 tristate "Generic (aka Sharp Corgi) Backlight Driver"
68 depends on BACKLIGHT_CLASS_DEVICE 104 depends on BACKLIGHT_CLASS_DEVICE
@@ -119,3 +155,12 @@ config BACKLIGHT_PWM
119 help 155 help
120 If you have a LCD backlight adjustable by PWM, say Y to enable 156 If you have a LCD backlight adjustable by PWM, say Y to enable
121 this driver. 157 this driver.
158
159config BACKLIGHT_MBP_NVIDIA
160 tristate "MacBook Pro Nvidia Backlight Driver"
161 depends on BACKLIGHT_CLASS_DEVICE && X86
162 default n
163 help
164 If you have an Apple Macbook Pro with Nvidia graphics hardware say Y
165 to enable a driver for its backlight
166
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index b51a7cd12500..b405aace803f 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -1,9 +1,13 @@
1# Backlight & LCD drivers 1# Backlight & LCD drivers
2 2
3obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o 3obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o
4obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o 4obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o
5obj-$(CONFIG_LCD_ILI9320) += ili9320.o
6obj-$(CONFIG_LCD_PLATFORM) += platform_lcd.o
7obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o
5 8
6obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o 9obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
10obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o
7obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o 11obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o
8obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o 12obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o
9obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o 13obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
@@ -11,3 +15,5 @@ obj-$(CONFIG_BACKLIGHT_OMAP1) += omap1_bl.o
11obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o 15obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o
12obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o 16obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o
13obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o 17obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o
18obj-$(CONFIG_BACKLIGHT_MBP_NVIDIA) += mbp_nvidia_bl.o
19
diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
new file mode 100644
index 000000000000..505c0823a105
--- /dev/null
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -0,0 +1,244 @@
1/*
2 * Copyright (C) 2008 Atmel Corporation
3 *
4 * Backlight driver using Atmel PWM peripheral.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10#include <linux/init.h>
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/platform_device.h>
14#include <linux/fb.h>
15#include <linux/clk.h>
16#include <linux/gpio.h>
17#include <linux/backlight.h>
18#include <linux/atmel_pwm.h>
19#include <linux/atmel-pwm-bl.h>
20
21struct atmel_pwm_bl {
22 const struct atmel_pwm_bl_platform_data *pdata;
23 struct backlight_device *bldev;
24 struct platform_device *pdev;
25 struct pwm_channel pwmc;
26 int gpio_on;
27};
28
29static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
30{
31 struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
32 int intensity = bd->props.brightness;
33 int pwm_duty;
34
35 if (bd->props.power != FB_BLANK_UNBLANK)
36 intensity = 0;
37 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
38 intensity = 0;
39
40 if (pwmbl->pdata->pwm_active_low)
41 pwm_duty = pwmbl->pdata->pwm_duty_min + intensity;
42 else
43 pwm_duty = pwmbl->pdata->pwm_duty_max - intensity;
44
45 if (pwm_duty > pwmbl->pdata->pwm_duty_max)
46 pwm_duty = pwmbl->pdata->pwm_duty_max;
47 if (pwm_duty < pwmbl->pdata->pwm_duty_min)
48 pwm_duty = pwmbl->pdata->pwm_duty_min;
49
50 if (!intensity) {
51 if (pwmbl->gpio_on != -1) {
52 gpio_set_value(pwmbl->gpio_on,
53 0 ^ pwmbl->pdata->on_active_low);
54 }
55 pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
56 pwm_channel_disable(&pwmbl->pwmc);
57 } else {
58 pwm_channel_enable(&pwmbl->pwmc);
59 pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
60 if (pwmbl->gpio_on != -1) {
61 gpio_set_value(pwmbl->gpio_on,
62 1 ^ pwmbl->pdata->on_active_low);
63 }
64 }
65
66 return 0;
67}
68
69static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
70{
71 struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
72 u8 intensity;
73
74 if (pwmbl->pdata->pwm_active_low) {
75 intensity = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY) -
76 pwmbl->pdata->pwm_duty_min;
77 } else {
78 intensity = pwmbl->pdata->pwm_duty_max -
79 pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
80 }
81
82 return intensity;
83}
84
85static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
86{
87 unsigned long pwm_rate = pwmbl->pwmc.mck;
88 unsigned long prescale = DIV_ROUND_UP(pwm_rate,
89 (pwmbl->pdata->pwm_frequency *
90 pwmbl->pdata->pwm_compare_max)) - 1;
91
92 /*
93 * Prescale must be power of two and maximum 0xf in size because of
94 * hardware limit. PWM speed will be:
95 * PWM module clock speed / (2 ^ prescale).
96 */
97 prescale = fls(prescale);
98 if (prescale > 0xf)
99 prescale = 0xf;
100
101 pwm_channel_writel(&pwmbl->pwmc, PWM_CMR, prescale);
102 pwm_channel_writel(&pwmbl->pwmc, PWM_CDTY,
103 pwmbl->pdata->pwm_duty_min +
104 pwmbl->bldev->props.brightness);
105 pwm_channel_writel(&pwmbl->pwmc, PWM_CPRD,
106 pwmbl->pdata->pwm_compare_max);
107
108 dev_info(&pwmbl->pdev->dev, "Atmel PWM backlight driver "
109 "(%lu Hz)\n", pwmbl->pwmc.mck /
110 pwmbl->pdata->pwm_compare_max /
111 (1 << prescale));
112
113 return pwm_channel_enable(&pwmbl->pwmc);
114}
115
116static struct backlight_ops atmel_pwm_bl_ops = {
117 .get_brightness = atmel_pwm_bl_get_intensity,
118 .update_status = atmel_pwm_bl_set_intensity,
119};
120
121static int atmel_pwm_bl_probe(struct platform_device *pdev)
122{
123 const struct atmel_pwm_bl_platform_data *pdata;
124 struct backlight_device *bldev;
125 struct atmel_pwm_bl *pwmbl;
126 int retval;
127
128 pwmbl = kzalloc(sizeof(struct atmel_pwm_bl), GFP_KERNEL);
129 if (!pwmbl)
130 return -ENOMEM;
131
132 pwmbl->pdev = pdev;
133
134 pdata = pdev->dev.platform_data;
135 if (!pdata) {
136 retval = -ENODEV;
137 goto err_free_mem;
138 }
139
140 if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
141 pdata->pwm_duty_min > pdata->pwm_duty_max ||
142 pdata->pwm_frequency == 0) {
143 retval = -EINVAL;
144 goto err_free_mem;
145 }
146
147 pwmbl->pdata = pdata;
148 pwmbl->gpio_on = pdata->gpio_on;
149
150 retval = pwm_channel_alloc(pdata->pwm_channel, &pwmbl->pwmc);
151 if (retval)
152 goto err_free_mem;
153
154 if (pwmbl->gpio_on != -1) {
155 retval = gpio_request(pwmbl->gpio_on, "gpio_atmel_pwm_bl");
156 if (retval) {
157 pwmbl->gpio_on = -1;
158 goto err_free_pwm;
159 }
160
161 /* Turn display off by defatult. */
162 retval = gpio_direction_output(pwmbl->gpio_on,
163 0 ^ pdata->on_active_low);
164 if (retval)
165 goto err_free_gpio;
166 }
167
168 bldev = backlight_device_register("atmel-pwm-bl",
169 &pdev->dev, pwmbl, &atmel_pwm_bl_ops);
170 if (IS_ERR(bldev)) {
171 retval = PTR_ERR(bldev);
172 goto err_free_gpio;
173 }
174
175 pwmbl->bldev = bldev;
176
177 platform_set_drvdata(pdev, pwmbl);
178
179 /* Power up the backlight by default at middle intesity. */
180 bldev->props.power = FB_BLANK_UNBLANK;
181 bldev->props.max_brightness = pdata->pwm_duty_max - pdata->pwm_duty_min;
182 bldev->props.brightness = bldev->props.max_brightness / 2;
183
184 retval = atmel_pwm_bl_init_pwm(pwmbl);
185 if (retval)
186 goto err_free_bl_dev;
187
188 atmel_pwm_bl_set_intensity(bldev);
189
190 return 0;
191
192err_free_bl_dev:
193 platform_set_drvdata(pdev, NULL);
194 backlight_device_unregister(bldev);
195err_free_gpio:
196 if (pwmbl->gpio_on != -1)
197 gpio_free(pwmbl->gpio_on);
198err_free_pwm:
199 pwm_channel_free(&pwmbl->pwmc);
200err_free_mem:
201 kfree(pwmbl);
202 return retval;
203}
204
205static int __exit atmel_pwm_bl_remove(struct platform_device *pdev)
206{
207 struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
208
209 if (pwmbl->gpio_on != -1) {
210 gpio_set_value(pwmbl->gpio_on, 0);
211 gpio_free(pwmbl->gpio_on);
212 }
213 pwm_channel_disable(&pwmbl->pwmc);
214 pwm_channel_free(&pwmbl->pwmc);
215 backlight_device_unregister(pwmbl->bldev);
216 platform_set_drvdata(pdev, NULL);
217 kfree(pwmbl);
218
219 return 0;
220}
221
222static struct platform_driver atmel_pwm_bl_driver = {
223 .driver = {
224 .name = "atmel-pwm-bl",
225 },
226 /* REVISIT add suspend() and resume() */
227 .remove = __exit_p(atmel_pwm_bl_remove),
228};
229
230static int __init atmel_pwm_bl_init(void)
231{
232 return platform_driver_probe(&atmel_pwm_bl_driver, atmel_pwm_bl_probe);
233}
234module_init(atmel_pwm_bl_init);
235
236static void __exit atmel_pwm_bl_exit(void)
237{
238 platform_driver_unregister(&atmel_pwm_bl_driver);
239}
240module_exit(atmel_pwm_bl_exit);
241
242MODULE_AUTHOR("Hans-Christian egtvedt <hans-christian.egtvedt@atmel.com>");
243MODULE_DESCRIPTION("Atmel PWM backlight driver");
244MODULE_LICENSE("GPL");
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 39394757679c..fab0bc874b58 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -191,6 +191,7 @@ static struct device_attribute bl_device_attributes[] = {
191 * backlight_device class. 191 * backlight_device class.
192 * @name: the name of the new object(must be the same as the name of the 192 * @name: the name of the new object(must be the same as the name of the
193 * respective framebuffer device). 193 * respective framebuffer device).
194 * @parent: a pointer to the parent device
194 * @devdata: an optional pointer to be stored for private driver use. The 195 * @devdata: an optional pointer to be stored for private driver use. The
195 * methods may retrieve it by using bl_get_data(bd). 196 * methods may retrieve it by using bl_get_data(bd).
196 * @ops: the backlight operations structure. 197 * @ops: the backlight operations structure.
diff --git a/drivers/video/backlight/ili9320.c b/drivers/video/backlight/ili9320.c
new file mode 100644
index 000000000000..ba89b41b639c
--- /dev/null
+++ b/drivers/video/backlight/ili9320.c
@@ -0,0 +1,330 @@
1/* drivers/video/backlight/ili9320.c
2 *
3 * ILI9320 LCD controller driver core.
4 *
5 * Copyright 2007 Simtec Electronics
6 * http://armlinux.simtec.co.uk/
7 * Ben Dooks <ben@simtec.co.uk>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/delay.h>
15#include <linux/err.h>
16#include <linux/fb.h>
17#include <linux/init.h>
18#include <linux/lcd.h>
19#include <linux/module.h>
20
21#include <linux/spi/spi.h>
22
23#include <video/ili9320.h>
24
25#include "ili9320.h"
26
27
28static inline int ili9320_write_spi(struct ili9320 *ili,
29 unsigned int reg,
30 unsigned int value)
31{
32 struct ili9320_spi *spi = &ili->access.spi;
33 unsigned char *addr = spi->buffer_addr;
34 unsigned char *data = spi->buffer_data;
35
36 /* spi message consits of:
37 * first byte: ID and operation
38 */
39
40 addr[0] = spi->id | ILI9320_SPI_INDEX | ILI9320_SPI_WRITE;
41 addr[1] = reg >> 8;
42 addr[2] = reg;
43
44 /* second message is the data to transfer */
45
46 data[0] = spi->id | ILI9320_SPI_DATA | ILI9320_SPI_WRITE;
47 data[1] = value >> 8;
48 data[2] = value;
49
50 return spi_sync(spi->dev, &spi->message);
51}
52
53int ili9320_write(struct ili9320 *ili, unsigned int reg, unsigned int value)
54{
55 dev_dbg(ili->dev, "write: reg=%02x, val=%04x\n", reg, value);
56 return ili->write(ili, reg, value);
57}
58
59EXPORT_SYMBOL_GPL(ili9320_write);
60
61int ili9320_write_regs(struct ili9320 *ili,
62 struct ili9320_reg *values,
63 int nr_values)
64{
65 int index;
66 int ret;
67
68 for (index = 0; index < nr_values; index++, values++) {
69 ret = ili9320_write(ili, values->address, values->value);
70 if (ret != 0)
71 return ret;
72 }
73
74 return 0;
75}
76
77EXPORT_SYMBOL_GPL(ili9320_write_regs);
78
79static void ili9320_reset(struct ili9320 *lcd)
80{
81 struct ili9320_platdata *cfg = lcd->platdata;
82
83 cfg->reset(1);
84 mdelay(50);
85
86 cfg->reset(0);
87 mdelay(50);
88
89 cfg->reset(1);
90 mdelay(100);
91}
92
93static inline int ili9320_init_chip(struct ili9320 *lcd)
94{
95 int ret;
96
97 ili9320_reset(lcd);
98
99 ret = lcd->client->init(lcd, lcd->platdata);
100 if (ret != 0) {
101 dev_err(lcd->dev, "failed to initialise display\n");
102 return ret;
103 }
104
105 lcd->initialised = 1;
106 return 0;
107}
108
109static inline int ili9320_power_on(struct ili9320 *lcd)
110{
111 if (!lcd->initialised)
112 ili9320_init_chip(lcd);
113
114 lcd->display1 |= (ILI9320_DISPLAY1_D(3) | ILI9320_DISPLAY1_BASEE);
115 ili9320_write(lcd, ILI9320_DISPLAY1, lcd->display1);
116
117 return 0;
118}
119
120static inline int ili9320_power_off(struct ili9320 *lcd)
121{
122 lcd->display1 &= ~(ILI9320_DISPLAY1_D(3) | ILI9320_DISPLAY1_BASEE);
123 ili9320_write(lcd, ILI9320_DISPLAY1, lcd->display1);
124
125 return 0;
126}
127
128#define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
129
130static int ili9320_power(struct ili9320 *lcd, int power)
131{
132 int ret = 0;
133
134 dev_dbg(lcd->dev, "power %d => %d\n", lcd->power, power);
135
136 if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
137 ret = ili9320_power_on(lcd);
138 else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
139 ret = ili9320_power_off(lcd);
140
141 if (ret == 0)
142 lcd->power = power;
143 else
144 dev_warn(lcd->dev, "failed to set power mode %d\n", power);
145
146 return ret;
147}
148
149static inline struct ili9320 *to_our_lcd(struct lcd_device *lcd)
150{
151 return lcd_get_data(lcd);
152}
153
154static int ili9320_set_power(struct lcd_device *ld, int power)
155{
156 struct ili9320 *lcd = to_our_lcd(ld);
157
158 return ili9320_power(lcd, power);
159}
160
161static int ili9320_get_power(struct lcd_device *ld)
162{
163 struct ili9320 *lcd = to_our_lcd(ld);
164
165 return lcd->power;
166}
167
168static struct lcd_ops ili9320_ops = {
169 .get_power = ili9320_get_power,
170 .set_power = ili9320_set_power,
171};
172
173static void __devinit ili9320_setup_spi(struct ili9320 *ili,
174 struct spi_device *dev)
175{
176 struct ili9320_spi *spi = &ili->access.spi;
177
178 ili->write = ili9320_write_spi;
179 spi->dev = dev;
180
181 /* fill the two messages we are going to use to send the data
182 * with, the first the address followed by the data. The datasheet
183 * says they should be done as two distinct cycles of the SPI CS line.
184 */
185
186 spi->xfer[0].tx_buf = spi->buffer_addr;
187 spi->xfer[1].tx_buf = spi->buffer_data;
188 spi->xfer[0].len = 3;
189 spi->xfer[1].len = 3;
190 spi->xfer[0].bits_per_word = 8;
191 spi->xfer[1].bits_per_word = 8;
192 spi->xfer[0].cs_change = 1;
193
194 spi_message_init(&spi->message);
195 spi_message_add_tail(&spi->xfer[0], &spi->message);
196 spi_message_add_tail(&spi->xfer[1], &spi->message);
197}
198
199int __devinit ili9320_probe_spi(struct spi_device *spi,
200 struct ili9320_client *client)
201{
202 struct ili9320_platdata *cfg = spi->dev.platform_data;
203 struct device *dev = &spi->dev;
204 struct ili9320 *ili;
205 struct lcd_device *lcd;
206 int ret = 0;
207
208 /* verify we where given some information */
209
210 if (cfg == NULL) {
211 dev_err(dev, "no platform data supplied\n");
212 return -EINVAL;
213 }
214
215 if (cfg->hsize <= 0 || cfg->vsize <= 0 || cfg->reset == NULL) {
216 dev_err(dev, "invalid platform data supplied\n");
217 return -EINVAL;
218 }
219
220 /* allocate and initialse our state */
221
222 ili = kzalloc(sizeof(struct ili9320), GFP_KERNEL);
223 if (ili == NULL) {
224 dev_err(dev, "no memory for device\n");
225 return -ENOMEM;
226 }
227
228 ili->access.spi.id = ILI9320_SPI_IDCODE | ILI9320_SPI_ID(1);
229
230 ili->dev = dev;
231 ili->client = client;
232 ili->power = FB_BLANK_POWERDOWN;
233 ili->platdata = cfg;
234
235 dev_set_drvdata(&spi->dev, ili);
236
237 ili9320_setup_spi(ili, spi);
238
239 lcd = lcd_device_register("ili9320", dev, ili, &ili9320_ops);
240 if (IS_ERR(lcd)) {
241 dev_err(dev, "failed to register lcd device\n");
242 ret = PTR_ERR(lcd);
243 goto err_free;
244 }
245
246 ili->lcd = lcd;
247
248 dev_info(dev, "initialising %s\n", client->name);
249
250 ret = ili9320_power(ili, FB_BLANK_UNBLANK);
251 if (ret != 0) {
252 dev_err(dev, "failed to set lcd power state\n");
253 goto err_unregister;
254 }
255
256 return 0;
257
258 err_unregister:
259 lcd_device_unregister(lcd);
260
261 err_free:
262 kfree(ili);
263
264 return ret;
265}
266
267EXPORT_SYMBOL_GPL(ili9320_probe_spi);
268
269int __devexit ili9320_remove(struct ili9320 *ili)
270{
271 ili9320_power(ili, FB_BLANK_POWERDOWN);
272
273 lcd_device_unregister(ili->lcd);
274 kfree(ili);
275
276 return 0;
277}
278
279EXPORT_SYMBOL_GPL(ili9320_remove);
280
281#ifdef CONFIG_PM
282int ili9320_suspend(struct ili9320 *lcd, pm_message_t state)
283{
284 int ret;
285
286 dev_dbg(lcd->dev, "%s: event %d\n", __func__, state.event);
287
288 if (state.event == PM_EVENT_SUSPEND) {
289 ret = ili9320_power(lcd, FB_BLANK_POWERDOWN);
290
291 if (lcd->platdata->suspend == ILI9320_SUSPEND_DEEP) {
292 ili9320_write(lcd, ILI9320_POWER1, lcd->power1 |
293 ILI9320_POWER1_SLP |
294 ILI9320_POWER1_DSTB);
295 lcd->initialised = 0;
296 }
297
298 return ret;
299 }
300
301 return 0;
302}
303
304EXPORT_SYMBOL_GPL(ili9320_suspend);
305
306int ili9320_resume(struct ili9320 *lcd)
307{
308 dev_info(lcd->dev, "resuming from power state %d\n", lcd->power);
309
310 if (lcd->platdata->suspend == ILI9320_SUSPEND_DEEP) {
311 ili9320_write(lcd, ILI9320_POWER1, 0x00);
312 }
313
314 return ili9320_power(lcd, FB_BLANK_UNBLANK);
315}
316
317EXPORT_SYMBOL_GPL(ili9320_resume);
318#endif
319
320/* Power down all displays on reboot, poweroff or halt */
321void ili9320_shutdown(struct ili9320 *lcd)
322{
323 ili9320_power(lcd, FB_BLANK_POWERDOWN);
324}
325
326EXPORT_SYMBOL_GPL(ili9320_shutdown);
327
328MODULE_AUTHOR("Ben Dooks <ben-linux@fluff.org>");
329MODULE_DESCRIPTION("ILI9320 LCD Driver");
330MODULE_LICENSE("GPL v2");
diff --git a/drivers/video/backlight/ili9320.h b/drivers/video/backlight/ili9320.h
new file mode 100644
index 000000000000..e388eca7cac5
--- /dev/null
+++ b/drivers/video/backlight/ili9320.h
@@ -0,0 +1,80 @@
1/* drivers/video/backlight/ili9320.h
2 *
3 * ILI9320 LCD controller driver core.
4 *
5 * Copyright 2007 Simtec Electronics
6 * Ben Dooks <ben@simtec.co.uk>
7 *
8 * http://armlinux.simtec.co.uk/
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13*/
14
15/* Holder for register and value pairs. */
16struct ili9320_reg {
17 unsigned short address;
18 unsigned short value;
19};
20
21struct ili9320;
22
23struct ili9320_client {
24 const char *name;
25 int (*init)(struct ili9320 *ili, struct ili9320_platdata *cfg);
26
27};
28/* Device attached via an SPI bus. */
29struct ili9320_spi {
30 struct spi_device *dev;
31 struct spi_message message;
32 struct spi_transfer xfer[2];
33
34 unsigned char id;
35 unsigned char buffer_addr[4];
36 unsigned char buffer_data[4];
37};
38
39/* ILI9320 device state. */
40struct ili9320 {
41 union {
42 struct ili9320_spi spi; /* SPI attachged device. */
43 } access; /* Register access method. */
44
45 struct device *dev;
46 struct lcd_device *lcd; /* LCD device we created. */
47 struct ili9320_client *client;
48 struct ili9320_platdata *platdata;
49
50 int power; /* current power state. */
51 int initialised;
52
53 unsigned short display1;
54 unsigned short power1;
55
56 int (*write)(struct ili9320 *ili, unsigned int reg, unsigned int val);
57};
58
59
60/* ILI9320 register access routines */
61
62extern int ili9320_write(struct ili9320 *ili,
63 unsigned int reg, unsigned int value);
64
65extern int ili9320_write_regs(struct ili9320 *ili,
66 struct ili9320_reg *values,
67 int nr_values);
68
69/* Device probe */
70
71extern int ili9320_probe_spi(struct spi_device *spi,
72 struct ili9320_client *cli);
73
74extern int ili9320_remove(struct ili9320 *lcd);
75extern void ili9320_shutdown(struct ili9320 *lcd);
76
77/* PM */
78
79extern int ili9320_suspend(struct ili9320 *lcd, pm_message_t state);
80extern int ili9320_resume(struct ili9320 *lcd);
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
index 299fd318dd45..b15b2b84a6f7 100644
--- a/drivers/video/backlight/lcd.c
+++ b/drivers/video/backlight/lcd.c
@@ -33,7 +33,7 @@ static int fb_notifier_callback(struct notifier_block *self,
33 ld = container_of(self, struct lcd_device, fb_notif); 33 ld = container_of(self, struct lcd_device, fb_notif);
34 mutex_lock(&ld->ops_lock); 34 mutex_lock(&ld->ops_lock);
35 if (ld->ops) 35 if (ld->ops)
36 if (!ld->ops->check_fb || ld->ops->check_fb(evdata->info)) 36 if (!ld->ops->check_fb || ld->ops->check_fb(ld, evdata->info))
37 ld->ops->set_power(ld, *(int *)evdata->data); 37 ld->ops->set_power(ld, *(int *)evdata->data);
38 mutex_unlock(&ld->ops_lock); 38 mutex_unlock(&ld->ops_lock);
39 return 0; 39 return 0;
diff --git a/drivers/video/backlight/mbp_nvidia_bl.c b/drivers/video/backlight/mbp_nvidia_bl.c
new file mode 100644
index 000000000000..385cba40ea87
--- /dev/null
+++ b/drivers/video/backlight/mbp_nvidia_bl.c
@@ -0,0 +1,116 @@
1/*
2 * Backlight Driver for Nvidia 8600 in Macbook Pro
3 *
4 * Copyright (c) Red Hat <mjg@redhat.com>
5 * Based on code from Pommed:
6 * Copyright (C) 2006 Nicolas Boichat <nicolas @boichat.ch>
7 * Copyright (C) 2006 Felipe Alfaro Solana <felipe_alfaro @linuxmail.org>
8 * Copyright (C) 2007 Julien BLACHE <jb@jblache.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This driver triggers SMIs which cause the firmware to change the
15 * backlight brightness. This is icky in many ways, but it's impractical to
16 * get at the firmware code in order to figure out what it's actually doing.
17 */
18
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/platform_device.h>
23#include <linux/backlight.h>
24#include <linux/err.h>
25#include <linux/dmi.h>
26#include <linux/io.h>
27
28static struct backlight_device *mbp_backlight_device;
29
30static struct dmi_system_id __initdata mbp_device_table[] = {
31 {
32 .ident = "3,1",
33 .matches = {
34 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
35 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3,1"),
36 },
37 },
38 {
39 .ident = "3,2",
40 .matches = {
41 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
42 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3,2"),
43 },
44 },
45 {
46 .ident = "4,1",
47 .matches = {
48 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
49 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro4,1"),
50 },
51 },
52 { }
53};
54
55static int mbp_send_intensity(struct backlight_device *bd)
56{
57 int intensity = bd->props.brightness;
58
59 outb(0x04 | (intensity << 4), 0xb3);
60 outb(0xbf, 0xb2);
61
62 return 0;
63}
64
65static int mbp_get_intensity(struct backlight_device *bd)
66{
67 outb(0x03, 0xb3);
68 outb(0xbf, 0xb2);
69 return inb(0xb3) >> 4;
70}
71
72static struct backlight_ops mbp_ops = {
73 .get_brightness = mbp_get_intensity,
74 .update_status = mbp_send_intensity,
75};
76
77static int __init mbp_init(void)
78{
79 if (!dmi_check_system(mbp_device_table))
80 return -ENODEV;
81
82 if (!request_region(0xb2, 2, "Macbook Pro backlight"))
83 return -ENXIO;
84
85 mbp_backlight_device = backlight_device_register("mbp_backlight",
86 NULL, NULL,
87 &mbp_ops);
88 if (IS_ERR(mbp_backlight_device)) {
89 release_region(0xb2, 2);
90 return PTR_ERR(mbp_backlight_device);
91 }
92
93 mbp_backlight_device->props.max_brightness = 15;
94 mbp_backlight_device->props.brightness =
95 mbp_get_intensity(mbp_backlight_device);
96 backlight_update_status(mbp_backlight_device);
97
98 return 0;
99}
100
101static void __exit mbp_exit(void)
102{
103 backlight_device_unregister(mbp_backlight_device);
104
105 release_region(0xb2, 2);
106}
107
108module_init(mbp_init);
109module_exit(mbp_exit);
110
111MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
112MODULE_DESCRIPTION("Nvidia-based Macbook Pro Backlight Driver");
113MODULE_LICENSE("GPL");
114MODULE_ALIAS("svnAppleInc.:pnMacBookPro3,1");
115MODULE_ALIAS("svnAppleInc.:pnMacBookPro3,2");
116MODULE_ALIAS("svnAppleInc.:pnMacBookPro4,1");
diff --git a/drivers/video/backlight/platform_lcd.c b/drivers/video/backlight/platform_lcd.c
new file mode 100644
index 000000000000..72d44dbfce82
--- /dev/null
+++ b/drivers/video/backlight/platform_lcd.c
@@ -0,0 +1,172 @@
1/* drivers/video/backlight/platform_lcd.c
2 *
3 * Copyright 2008 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * Generic platform-device LCD power control interface.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12*/
13
14#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/fb.h>
17#include <linux/backlight.h>
18#include <linux/lcd.h>
19
20#include <video/platform_lcd.h>
21
22struct platform_lcd {
23 struct device *us;
24 struct lcd_device *lcd;
25 struct plat_lcd_data *pdata;
26
27 unsigned int power;
28 unsigned int suspended : 1;
29};
30
31static inline struct platform_lcd *to_our_lcd(struct lcd_device *lcd)
32{
33 return lcd_get_data(lcd);
34}
35
36static int platform_lcd_get_power(struct lcd_device *lcd)
37{
38 struct platform_lcd *plcd = to_our_lcd(lcd);
39
40 return plcd->power;
41}
42
43static int platform_lcd_set_power(struct lcd_device *lcd, int power)
44{
45 struct platform_lcd *plcd = to_our_lcd(lcd);
46 int lcd_power = 1;
47
48 if (power == FB_BLANK_POWERDOWN || plcd->suspended)
49 lcd_power = 0;
50
51 plcd->pdata->set_power(plcd->pdata, lcd_power);
52 plcd->power = power;
53
54 return 0;
55}
56
57static int platform_lcd_match(struct lcd_device *lcd, struct fb_info *info)
58{
59 struct platform_lcd *plcd = to_our_lcd(lcd);
60 struct plat_lcd_data *pdata = plcd->pdata;
61
62 if (pdata->match_fb)
63 return pdata->match_fb(pdata, info);
64
65 return plcd->us->parent == info->device;
66}
67
68static struct lcd_ops platform_lcd_ops = {
69 .get_power = platform_lcd_get_power,
70 .set_power = platform_lcd_set_power,
71 .check_fb = platform_lcd_match,
72};
73
74static int __devinit platform_lcd_probe(struct platform_device *pdev)
75{
76 struct plat_lcd_data *pdata;
77 struct platform_lcd *plcd;
78 struct device *dev = &pdev->dev;
79 int err;
80
81 pdata = pdev->dev.platform_data;
82 if (!pdata) {
83 dev_err(dev, "no platform data supplied\n");
84 return -EINVAL;
85 }
86
87 plcd = kzalloc(sizeof(struct platform_lcd), GFP_KERNEL);
88 if (!plcd) {
89 dev_err(dev, "no memory for state\n");
90 return -ENOMEM;
91 }
92
93 plcd->us = dev;
94 plcd->pdata = pdata;
95 plcd->lcd = lcd_device_register("platform-lcd", dev,
96 plcd, &platform_lcd_ops);
97 if (IS_ERR(plcd->lcd)) {
98 dev_err(dev, "cannot register lcd device\n");
99 err = PTR_ERR(plcd->lcd);
100 goto err_mem;
101 }
102
103 platform_set_drvdata(pdev, plcd);
104 return 0;
105
106 err_mem:
107 kfree(plcd);
108 return err;
109}
110
111static int __devexit platform_lcd_remove(struct platform_device *pdev)
112{
113 struct platform_lcd *plcd = platform_get_drvdata(pdev);
114
115 lcd_device_unregister(plcd->lcd);
116 kfree(plcd);
117
118 return 0;
119}
120
121#ifdef CONFIG_PM
122static int platform_lcd_suspend(struct platform_device *pdev, pm_message_t st)
123{
124 struct platform_lcd *plcd = platform_get_drvdata(pdev);
125
126 plcd->suspended = 1;
127 platform_lcd_set_power(plcd->lcd, plcd->power);
128
129 return 0;
130}
131
132static int platform_lcd_resume(struct platform_device *pdev)
133{
134 struct platform_lcd *plcd = platform_get_drvdata(pdev);
135
136 plcd->suspended = 0;
137 platform_lcd_set_power(plcd->lcd, plcd->power);
138
139 return 0;
140}
141#else
142#define platform_lcd_suspend NULL
143#define platform_lcd_resume NULL
144#endif
145
146static struct platform_driver platform_lcd_driver = {
147 .driver = {
148 .name = "platform-lcd",
149 .owner = THIS_MODULE,
150 },
151 .probe = platform_lcd_probe,
152 .remove = __devexit_p(platform_lcd_remove),
153 .suspend = platform_lcd_suspend,
154 .resume = platform_lcd_resume,
155};
156
157static int __init platform_lcd_init(void)
158{
159 return platform_driver_register(&platform_lcd_driver);
160}
161
162static void __exit platform_lcd_cleanup(void)
163{
164 platform_driver_unregister(&platform_lcd_driver);
165}
166
167module_init(platform_lcd_init);
168module_exit(platform_lcd_cleanup);
169
170MODULE_AUTHOR("Ben Dooks <ben-linux@fluff.org>");
171MODULE_LICENSE("GPL v2");
172MODULE_ALIAS("platform:platform-lcd");
diff --git a/drivers/video/backlight/vgg2432a4.c b/drivers/video/backlight/vgg2432a4.c
new file mode 100644
index 000000000000..593c7687d54a
--- /dev/null
+++ b/drivers/video/backlight/vgg2432a4.c
@@ -0,0 +1,284 @@
1/* drivers/video/backlight/vgg2432a4.c
2 *
3 * VGG2432A4 (ILI9320) LCD controller driver.
4 *
5 * Copyright 2007 Simtec Electronics
6 * http://armlinux.simtec.co.uk/
7 * Ben Dooks <ben@simtec.co.uk>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/delay.h>
15#include <linux/err.h>
16#include <linux/fb.h>
17#include <linux/init.h>
18#include <linux/lcd.h>
19#include <linux/module.h>
20
21#include <linux/spi/spi.h>
22
23#include <video/ili9320.h>
24
25#include "ili9320.h"
26
27/* Device initialisation sequences */
28
29static struct ili9320_reg vgg_init1[] = {
30 {
31 .address = ILI9320_POWER1,
32 .value = ILI9320_POWER1_AP(0) | ILI9320_POWER1_BT(0),
33 }, {
34 .address = ILI9320_POWER2,
35 .value = (ILI9320_POWER2_VC(7) |
36 ILI9320_POWER2_DC0(0) | ILI9320_POWER2_DC1(0)),
37 }, {
38 .address = ILI9320_POWER3,
39 .value = ILI9320_POWER3_VRH(0),
40 }, {
41 .address = ILI9320_POWER4,
42 .value = ILI9320_POWER4_VREOUT(0),
43 },
44};
45
46static struct ili9320_reg vgg_init2[] = {
47 {
48 .address = ILI9320_POWER1,
49 .value = (ILI9320_POWER1_AP(3) | ILI9320_POWER1_APE |
50 ILI9320_POWER1_BT(7) | ILI9320_POWER1_SAP),
51 }, {
52 .address = ILI9320_POWER2,
53 .value = ILI9320_POWER2_VC(7) | ILI9320_POWER2_DC0(3),
54 }
55};
56
57static struct ili9320_reg vgg_gamma[] = {
58 {
59 .address = ILI9320_GAMMA1,
60 .value = 0x0000,
61 }, {
62 .address = ILI9320_GAMMA2,
63 .value = 0x0505,
64 }, {
65 .address = ILI9320_GAMMA3,
66 .value = 0x0004,
67 }, {
68 .address = ILI9320_GAMMA4,
69 .value = 0x0006,
70 }, {
71 .address = ILI9320_GAMMA5,
72 .value = 0x0707,
73 }, {
74 .address = ILI9320_GAMMA6,
75 .value = 0x0105,
76 }, {
77 .address = ILI9320_GAMMA7,
78 .value = 0x0002,
79 }, {
80 .address = ILI9320_GAMMA8,
81 .value = 0x0707,
82 }, {
83 .address = ILI9320_GAMMA9,
84 .value = 0x0704,
85 }, {
86 .address = ILI9320_GAMMA10,
87 .value = 0x807,
88 }
89
90};
91
92static struct ili9320_reg vgg_init0[] = {
93 [0] = {
94 /* set direction and scan mode gate */
95 .address = ILI9320_DRIVER,
96 .value = ILI9320_DRIVER_SS,
97 }, {
98 .address = ILI9320_DRIVEWAVE,
99 .value = (ILI9320_DRIVEWAVE_MUSTSET |
100 ILI9320_DRIVEWAVE_EOR | ILI9320_DRIVEWAVE_BC),
101 }, {
102 .address = ILI9320_ENTRYMODE,
103 .value = ILI9320_ENTRYMODE_ID(3) | ILI9320_ENTRYMODE_BGR,
104 }, {
105 .address = ILI9320_RESIZING,
106 .value = 0x0,
107 },
108};
109
110
111static int vgg2432a4_lcd_init(struct ili9320 *lcd,
112 struct ili9320_platdata *cfg)
113{
114 unsigned int addr;
115 int ret;
116
117 /* Set VCore before anything else (VGG243237-6UFLWA) */
118 ret = ili9320_write(lcd, 0x00e5, 0x8000);
119 if (ret)
120 goto err_initial;
121
122 /* Start the oscillator up before we can do anything else. */
123 ret = ili9320_write(lcd, ILI9320_OSCILATION, ILI9320_OSCILATION_OSC);
124 if (ret)
125 goto err_initial;
126
127 /* must wait at-lesat 10ms after starting */
128 mdelay(15);
129
130 ret = ili9320_write_regs(lcd, vgg_init0, ARRAY_SIZE(vgg_init0));
131 if (ret != 0)
132 goto err_initial;
133
134 ili9320_write(lcd, ILI9320_DISPLAY2, cfg->display2);
135 ili9320_write(lcd, ILI9320_DISPLAY3, cfg->display3);
136 ili9320_write(lcd, ILI9320_DISPLAY4, cfg->display4);
137
138 ili9320_write(lcd, ILI9320_RGB_IF1, cfg->rgb_if1);
139 ili9320_write(lcd, ILI9320_FRAMEMAKER, 0x0);
140 ili9320_write(lcd, ILI9320_RGB_IF2, ILI9320_RGBIF2_DPL);
141
142 ret = ili9320_write_regs(lcd, vgg_init1, ARRAY_SIZE(vgg_init1));
143 if (ret != 0)
144 goto err_vgg;
145
146 mdelay(300);
147
148 ret = ili9320_write_regs(lcd, vgg_init2, ARRAY_SIZE(vgg_init2));
149 if (ret != 0)
150 goto err_vgg2;
151
152 mdelay(100);
153
154 ili9320_write(lcd, ILI9320_POWER3, 0x13c);
155
156 mdelay(100);
157
158 ili9320_write(lcd, ILI9320_POWER4, 0x1c00);
159 ili9320_write(lcd, ILI9320_POWER7, 0x000e);
160
161 mdelay(100);
162
163 ili9320_write(lcd, ILI9320_GRAM_HORIZ_ADDR, 0x00);
164 ili9320_write(lcd, ILI9320_GRAM_VERT_ADD, 0x00);
165
166 ret = ili9320_write_regs(lcd, vgg_gamma, ARRAY_SIZE(vgg_gamma));
167 if (ret != 0)
168 goto err_vgg3;
169
170 ili9320_write(lcd, ILI9320_HORIZ_START, 0x0);
171 ili9320_write(lcd, ILI9320_HORIZ_END, cfg->hsize - 1);
172 ili9320_write(lcd, ILI9320_VERT_START, 0x0);
173 ili9320_write(lcd, ILI9320_VERT_END, cfg->vsize - 1);
174
175 ili9320_write(lcd, ILI9320_DRIVER2,
176 ILI9320_DRIVER2_NL(((cfg->vsize - 240) / 8) + 0x1D));
177
178 ili9320_write(lcd, ILI9320_BASE_IMAGE, 0x1);
179 ili9320_write(lcd, ILI9320_VERT_SCROLL, 0x00);
180
181 for (addr = ILI9320_PARTIAL1_POSITION; addr <= ILI9320_PARTIAL2_END;
182 addr++) {
183 ili9320_write(lcd, addr, 0x0);
184 }
185
186 ili9320_write(lcd, ILI9320_INTERFACE1, 0x10);
187 ili9320_write(lcd, ILI9320_INTERFACE2, cfg->interface2);
188 ili9320_write(lcd, ILI9320_INTERFACE3, cfg->interface3);
189 ili9320_write(lcd, ILI9320_INTERFACE4, cfg->interface4);
190 ili9320_write(lcd, ILI9320_INTERFACE5, cfg->interface5);
191 ili9320_write(lcd, ILI9320_INTERFACE6, cfg->interface6);
192
193 lcd->display1 = (ILI9320_DISPLAY1_D(3) | ILI9320_DISPLAY1_DTE |
194 ILI9320_DISPLAY1_GON | ILI9320_DISPLAY1_BASEE |
195 0x40);
196
197 ili9320_write(lcd, ILI9320_DISPLAY1, lcd->display1);
198
199 return 0;
200
201 err_vgg3:
202 err_vgg2:
203 err_vgg:
204 err_initial:
205 return ret;
206}
207
208#ifdef CONFIG_PM
209static int vgg2432a4_suspend(struct spi_device *spi, pm_message_t state)
210{
211 return ili9320_suspend(dev_get_drvdata(&spi->dev), state);
212}
213
214static int vgg2432a4_resume(struct spi_device *spi)
215{
216 return ili9320_resume(dev_get_drvdata(&spi->dev));
217}
218#else
219#define vgg2432a4_suspend NULL
220#define vgg2432a4_resume NULL
221#endif
222
223static struct ili9320_client vgg2432a4_client = {
224 .name = "VGG2432A4",
225 .init = vgg2432a4_lcd_init,
226};
227
228/* Device probe */
229
230static int __devinit vgg2432a4_probe(struct spi_device *spi)
231{
232 int ret;
233
234 ret = ili9320_probe_spi(spi, &vgg2432a4_client);
235 if (ret != 0) {
236 dev_err(&spi->dev, "failed to initialise ili9320\n");
237 return ret;
238 }
239
240 return 0;
241}
242
243static int __devexit vgg2432a4_remove(struct spi_device *spi)
244{
245 return ili9320_remove(dev_get_drvdata(&spi->dev));
246}
247
248static void vgg2432a4_shutdown(struct spi_device *spi)
249{
250 ili9320_shutdown(dev_get_drvdata(&spi->dev));
251}
252
253static struct spi_driver vgg2432a4_driver = {
254 .driver = {
255 .name = "VGG2432A4",
256 .owner = THIS_MODULE,
257 },
258 .probe = vgg2432a4_probe,
259 .remove = __devexit_p(vgg2432a4_remove),
260 .shutdown = vgg2432a4_shutdown,
261 .suspend = vgg2432a4_suspend,
262 .resume = vgg2432a4_resume,
263};
264
265/* Device driver initialisation */
266
267static int __init vgg2432a4_init(void)
268{
269 return spi_register_driver(&vgg2432a4_driver);
270}
271
272static void __exit vgg2432a4_exit(void)
273{
274 spi_unregister_driver(&vgg2432a4_driver);
275}
276
277module_init(vgg2432a4_init);
278module_exit(vgg2432a4_exit);
279
280MODULE_AUTHOR("Ben Dooks <ben-linux@fluff.org>");
281MODULE_DESCRIPTION("VGG2432A4 LCD Driver");
282MODULE_LICENSE("GPL v2");
283
284
diff --git a/drivers/video/bf54x-lq043fb.c b/drivers/video/bf54x-lq043fb.c
index 49834a67a623..940467aed13f 100644
--- a/drivers/video/bf54x-lq043fb.c
+++ b/drivers/video/bf54x-lq043fb.c
@@ -478,7 +478,7 @@ static int bfin_lcd_set_contrast(struct lcd_device *dev, int contrast)
478 return 0; 478 return 0;
479} 479}
480 480
481static int bfin_lcd_check_fb(struct fb_info *fi) 481static int bfin_lcd_check_fb(struct lcd_device *dev, struct fb_info *fi)
482{ 482{
483 if (!fi || (fi == &bfin_bf54x_fb)) 483 if (!fi || (fi == &bfin_bf54x_fb))
484 return 1; 484 return 1;
diff --git a/drivers/video/bfin-t350mcqb-fb.c b/drivers/video/bfin-t350mcqb-fb.c
index 135d6dd7e672..7d1b819e501c 100644
--- a/drivers/video/bfin-t350mcqb-fb.c
+++ b/drivers/video/bfin-t350mcqb-fb.c
@@ -396,7 +396,7 @@ static int bfin_lcd_set_contrast(struct lcd_device *dev, int contrast)
396 return 0; 396 return 0;
397} 397}
398 398
399static int bfin_lcd_check_fb(struct fb_info *fi) 399static int bfin_lcd_check_fb(struct lcd_device *dev, struct fb_info *fi)
400{ 400{
401 if (!fi || (fi == &bfin_t350mcqb_fb)) 401 if (!fi || (fi == &bfin_t350mcqb_fb))
402 return 1; 402 return 1;
diff --git a/drivers/video/carminefb.c b/drivers/video/carminefb.c
new file mode 100644
index 000000000000..e15bb447440a
--- /dev/null
+++ b/drivers/video/carminefb.c
@@ -0,0 +1,790 @@
1/*
2 * Frame buffer driver for the Carmine GPU.
3 *
4 * The driver configures the GPU as follows
5 * - FB0 is display 0 with unique memory area
6 * - FB1 is display 1 with unique memory area
7 * - both display use 32 bit colors
8 */
9#include <linux/delay.h>
10#include <linux/errno.h>
11#include <linux/fb.h>
12#include <linux/interrupt.h>
13#include <linux/pci.h>
14
15#include "carminefb.h"
16#include "carminefb_regs.h"
17
18#if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
19#error "The endianness of the target host has not been defined."
20#endif
21
22/*
23 * The initial video mode can be supplied via two different ways:
24 * - as a string that is passed to fb_find_mode() (module option fb_mode_str)
25 * - as an integer that picks the video mode from carmine_modedb[] (module
26 * option fb_mode)
27 *
28 * If nothing is used than the initial video mode will be the
29 * CARMINEFB_DEFAULT_VIDEO_MODE member of the carmine_modedb[].
30 */
31#define CARMINEFB_DEFAULT_VIDEO_MODE 1
32
33static unsigned int fb_mode = CARMINEFB_DEFAULT_VIDEO_MODE;
34module_param(fb_mode, uint, 444);
35MODULE_PARM_DESC(fb_mode, "Initial video mode as integer.");
36
37static char *fb_mode_str;
38module_param(fb_mode_str, charp, 444);
39MODULE_PARM_DESC(fb_mode_str, "Initial video mode in characters.");
40
41/*
42 * Carminefb displays:
43 * 0b000 None
44 * 0b001 Display 0
45 * 0b010 Display 1
46 */
47static int fb_displays = CARMINE_USE_DISPLAY0 | CARMINE_USE_DISPLAY1;
48module_param(fb_displays, int, 444);
49MODULE_PARM_DESC(fb_displays, "Bit mode, which displays are used");
50
51struct carmine_hw {
52 void __iomem *v_regs;
53 void __iomem *screen_mem;
54 struct fb_info *fb[MAX_DISPLAY];
55};
56
57struct carmine_resolution {
58 u32 htp;
59 u32 hsp;
60 u32 hsw;
61 u32 hdp;
62 u32 vtr;
63 u32 vsp;
64 u32 vsw;
65 u32 vdp;
66 u32 disp_mode;
67};
68
69struct carmine_fb {
70 void __iomem *display_reg;
71 void __iomem *screen_base;
72 u32 smem_offset;
73 u32 cur_mode;
74 u32 new_mode;
75 struct carmine_resolution *res;
76 u32 pseudo_palette[16];
77};
78
79static struct fb_fix_screeninfo carminefb_fix __devinitdata = {
80 .id = "Carmine",
81 .type = FB_TYPE_PACKED_PIXELS,
82 .visual = FB_VISUAL_TRUECOLOR,
83 .accel = FB_ACCEL_NONE,
84};
85
86static const struct fb_videomode carmine_modedb[] = {
87 {
88 .name = "640x480",
89 .xres = 640,
90 .yres = 480,
91 }, {
92 .name = "800x600",
93 .xres = 800,
94 .yres = 600,
95 },
96};
97
98static struct carmine_resolution car_modes[] = {
99 {
100 /* 640x480 */
101 .htp = 800,
102 .hsp = 672,
103 .hsw = 96,
104 .hdp = 640,
105 .vtr = 525,
106 .vsp = 490,
107 .vsw = 2,
108 .vdp = 480,
109 .disp_mode = 0x1400,
110 },
111 {
112 /* 800x600 */
113 .htp = 1060,
114 .hsp = 864,
115 .hsw = 72,
116 .hdp = 800,
117 .vtr = 628,
118 .vsp = 601,
119 .vsw = 2,
120 .vdp = 600,
121 .disp_mode = 0x0d00,
122 }
123};
124
125static int carmine_find_mode(const struct fb_var_screeninfo *var)
126{
127 int i;
128
129 for (i = 0; i < ARRAY_SIZE(car_modes); i++)
130 if (car_modes[i].hdp == var->xres &&
131 car_modes[i].vdp == var->yres)
132 return i;
133 return -EINVAL;
134}
135
136static void c_set_disp_reg(const struct carmine_fb *par,
137 u32 offset, u32 val)
138{
139 writel(val, par->display_reg + offset);
140}
141
142static u32 c_get_disp_reg(const struct carmine_fb *par,
143 u32 offset)
144{
145 return readl(par->display_reg + offset);
146}
147
148static void c_set_hw_reg(const struct carmine_hw *hw,
149 u32 offset, u32 val)
150{
151 writel(val, hw->v_regs + offset);
152}
153
154static u32 c_get_hw_reg(const struct carmine_hw *hw,
155 u32 offset)
156{
157 return readl(hw->v_regs + offset);
158}
159
160static int carmine_setcolreg(unsigned regno, unsigned red, unsigned green,
161 unsigned blue, unsigned transp, struct fb_info *info)
162{
163 if (regno >= 16)
164 return 1;
165
166 red >>= 8;
167 green >>= 8;
168 blue >>= 8;
169 transp >>= 8;
170
171 ((u32 *)info->pseudo_palette)[regno] = be32_to_cpu(transp << 24 |
172 red << 0 | green << 8 | blue << 16);
173 return 0;
174}
175
176static int carmine_check_var(struct fb_var_screeninfo *var,
177 struct fb_info *info)
178{
179 int ret;
180
181 ret = carmine_find_mode(var);
182 if (ret < 0)
183 return ret;
184
185 if (var->grayscale || var->rotate || var->nonstd)
186 return -EINVAL;
187
188 var->xres_virtual = var->xres;
189 var->yres_virtual = var->yres;
190
191 var->bits_per_pixel = 32;
192
193#ifdef __BIG_ENDIAN
194 var->transp.offset = 24;
195 var->red.offset = 0;
196 var->green.offset = 8;
197 var->blue.offset = 16;
198#else
199 var->transp.offset = 24;
200 var->red.offset = 16;
201 var->green.offset = 8;
202 var->blue.offset = 0;
203#endif
204
205 var->red.length = 8;
206 var->green.length = 8;
207 var->blue.length = 8;
208 var->transp.length = 8;
209
210 var->red.msb_right = 0;
211 var->green.msb_right = 0;
212 var->blue.msb_right = 0;
213 var->transp.msb_right = 0;
214 return 0;
215}
216
217static void carmine_init_display_param(struct carmine_fb *par)
218{
219 u32 width;
220 u32 height;
221 u32 param;
222 u32 window_size;
223 u32 soffset = par->smem_offset;
224
225 c_set_disp_reg(par, CARMINE_DISP_REG_C_TRANS, 0);
226 c_set_disp_reg(par, CARMINE_DISP_REG_MLMR_TRANS, 0);
227 c_set_disp_reg(par, CARMINE_DISP_REG_CURSOR_MODE,
228 CARMINE_CURSOR0_PRIORITY_MASK |
229 CARMINE_CURSOR1_PRIORITY_MASK |
230 CARMINE_CURSOR_CUTZ_MASK);
231
232 /* Set default cursor position */
233 c_set_disp_reg(par, CARMINE_DISP_REG_CUR1_POS, 0 << 16 | 0);
234 c_set_disp_reg(par, CARMINE_DISP_REG_CUR2_POS, 0 << 16 | 0);
235
236 /* Set default display mode */
237 c_set_disp_reg(par, CARMINE_DISP_REG_L0_EXT_MODE, CARMINE_WINDOW_MODE |
238 CARMINE_EXT_CMODE_DIRECT24_RGBA);
239 c_set_disp_reg(par, CARMINE_DISP_REG_L1_EXT_MODE,
240 CARMINE_EXT_CMODE_DIRECT24_RGBA);
241 c_set_disp_reg(par, CARMINE_DISP_REG_L2_EXT_MODE, CARMINE_EXTEND_MODE |
242 CARMINE_EXT_CMODE_DIRECT24_RGBA);
243 c_set_disp_reg(par, CARMINE_DISP_REG_L3_EXT_MODE, CARMINE_EXTEND_MODE |
244 CARMINE_EXT_CMODE_DIRECT24_RGBA);
245 c_set_disp_reg(par, CARMINE_DISP_REG_L4_EXT_MODE, CARMINE_EXTEND_MODE |
246 CARMINE_EXT_CMODE_DIRECT24_RGBA);
247 c_set_disp_reg(par, CARMINE_DISP_REG_L5_EXT_MODE, CARMINE_EXTEND_MODE |
248 CARMINE_EXT_CMODE_DIRECT24_RGBA);
249 c_set_disp_reg(par, CARMINE_DISP_REG_L6_EXT_MODE, CARMINE_EXTEND_MODE |
250 CARMINE_EXT_CMODE_DIRECT24_RGBA);
251 c_set_disp_reg(par, CARMINE_DISP_REG_L7_EXT_MODE, CARMINE_EXTEND_MODE |
252 CARMINE_EXT_CMODE_DIRECT24_RGBA);
253
254 /* Set default frame size to layer mode register */
255 width = par->res->hdp * 4 / CARMINE_DISP_WIDTH_UNIT;
256 width = width << CARMINE_DISP_WIDTH_SHIFT;
257
258 height = par->res->vdp - 1;
259 param = width | height;
260
261 c_set_disp_reg(par, CARMINE_DISP_REG_L0_MODE_W_H, param);
262 c_set_disp_reg(par, CARMINE_DISP_REG_L1_WIDTH, width);
263 c_set_disp_reg(par, CARMINE_DISP_REG_L2_MODE_W_H, param);
264 c_set_disp_reg(par, CARMINE_DISP_REG_L3_MODE_W_H, param);
265 c_set_disp_reg(par, CARMINE_DISP_REG_L4_MODE_W_H, param);
266 c_set_disp_reg(par, CARMINE_DISP_REG_L5_MODE_W_H, param);
267 c_set_disp_reg(par, CARMINE_DISP_REG_L6_MODE_W_H, param);
268 c_set_disp_reg(par, CARMINE_DISP_REG_L7_MODE_W_H, param);
269
270 /* Set default pos and size */
271 window_size = (par->res->vdp - 1) << CARMINE_DISP_WIN_H_SHIFT;
272 window_size |= par->res->hdp;
273
274 c_set_disp_reg(par, CARMINE_DISP_REG_L0_WIN_POS, 0);
275 c_set_disp_reg(par, CARMINE_DISP_REG_L0_WIN_SIZE, window_size);
276 c_set_disp_reg(par, CARMINE_DISP_REG_L1_WIN_POS, 0);
277 c_set_disp_reg(par, CARMINE_DISP_REG_L1_WIN_SIZE, window_size);
278 c_set_disp_reg(par, CARMINE_DISP_REG_L2_WIN_POS, 0);
279 c_set_disp_reg(par, CARMINE_DISP_REG_L2_WIN_SIZE, window_size);
280 c_set_disp_reg(par, CARMINE_DISP_REG_L3_WIN_POS, 0);
281 c_set_disp_reg(par, CARMINE_DISP_REG_L3_WIN_SIZE, window_size);
282 c_set_disp_reg(par, CARMINE_DISP_REG_L4_WIN_POS, 0);
283 c_set_disp_reg(par, CARMINE_DISP_REG_L4_WIN_SIZE, window_size);
284 c_set_disp_reg(par, CARMINE_DISP_REG_L5_WIN_POS, 0);
285 c_set_disp_reg(par, CARMINE_DISP_REG_L5_WIN_SIZE, window_size);
286 c_set_disp_reg(par, CARMINE_DISP_REG_L6_WIN_POS, 0);
287 c_set_disp_reg(par, CARMINE_DISP_REG_L6_WIN_SIZE, window_size);
288 c_set_disp_reg(par, CARMINE_DISP_REG_L7_WIN_POS, 0);
289 c_set_disp_reg(par, CARMINE_DISP_REG_L7_WIN_SIZE, window_size);
290
291 /* Set default origin address */
292 c_set_disp_reg(par, CARMINE_DISP_REG_L0_ORG_ADR, soffset);
293 c_set_disp_reg(par, CARMINE_DISP_REG_L1_ORG_ADR, soffset);
294 c_set_disp_reg(par, CARMINE_DISP_REG_L2_ORG_ADR1, soffset);
295 c_set_disp_reg(par, CARMINE_DISP_REG_L3_ORG_ADR1, soffset);
296 c_set_disp_reg(par, CARMINE_DISP_REG_L4_ORG_ADR1, soffset);
297 c_set_disp_reg(par, CARMINE_DISP_REG_L5_ORG_ADR1, soffset);
298 c_set_disp_reg(par, CARMINE_DISP_REG_L6_ORG_ADR1, soffset);
299 c_set_disp_reg(par, CARMINE_DISP_REG_L7_ORG_ADR1, soffset);
300
301 /* Set default display address */
302 c_set_disp_reg(par, CARMINE_DISP_REG_L0_DISP_ADR, soffset);
303 c_set_disp_reg(par, CARMINE_DISP_REG_L2_DISP_ADR1, soffset);
304 c_set_disp_reg(par, CARMINE_DISP_REG_L3_DISP_ADR1, soffset);
305 c_set_disp_reg(par, CARMINE_DISP_REG_L4_DISP_ADR1, soffset);
306 c_set_disp_reg(par, CARMINE_DISP_REG_L5_DISP_ADR1, soffset);
307 c_set_disp_reg(par, CARMINE_DISP_REG_L6_DISP_ADR0, soffset);
308 c_set_disp_reg(par, CARMINE_DISP_REG_L7_DISP_ADR0, soffset);
309
310 /* Set default display position */
311 c_set_disp_reg(par, CARMINE_DISP_REG_L0_DISP_POS, 0);
312 c_set_disp_reg(par, CARMINE_DISP_REG_L2_DISP_POS, 0);
313 c_set_disp_reg(par, CARMINE_DISP_REG_L3_DISP_POS, 0);
314 c_set_disp_reg(par, CARMINE_DISP_REG_L4_DISP_POS, 0);
315 c_set_disp_reg(par, CARMINE_DISP_REG_L5_DISP_POS, 0);
316 c_set_disp_reg(par, CARMINE_DISP_REG_L6_DISP_POS, 0);
317 c_set_disp_reg(par, CARMINE_DISP_REG_L7_DISP_POS, 0);
318
319 /* Set default blend mode */
320 c_set_disp_reg(par, CARMINE_DISP_REG_BLEND_MODE_L0, 0);
321 c_set_disp_reg(par, CARMINE_DISP_REG_BLEND_MODE_L1, 0);
322 c_set_disp_reg(par, CARMINE_DISP_REG_BLEND_MODE_L2, 0);
323 c_set_disp_reg(par, CARMINE_DISP_REG_BLEND_MODE_L3, 0);
324 c_set_disp_reg(par, CARMINE_DISP_REG_BLEND_MODE_L4, 0);
325 c_set_disp_reg(par, CARMINE_DISP_REG_BLEND_MODE_L5, 0);
326 c_set_disp_reg(par, CARMINE_DISP_REG_BLEND_MODE_L6, 0);
327 c_set_disp_reg(par, CARMINE_DISP_REG_BLEND_MODE_L7, 0);
328
329 /* default transparency mode */
330 c_set_disp_reg(par, CARMINE_DISP_REG_L0_TRANS, 0);
331 c_set_disp_reg(par, CARMINE_DISP_REG_L1_TRANS, 0);
332 c_set_disp_reg(par, CARMINE_DISP_REG_L2_TRANS, 0);
333 c_set_disp_reg(par, CARMINE_DISP_REG_L3_TRANS, 0);
334 c_set_disp_reg(par, CARMINE_DISP_REG_L4_TRANS, 0);
335 c_set_disp_reg(par, CARMINE_DISP_REG_L5_TRANS, 0);
336 c_set_disp_reg(par, CARMINE_DISP_REG_L6_TRANS, 0);
337 c_set_disp_reg(par, CARMINE_DISP_REG_L7_TRANS, 0);
338
339 /* Set default read skip parameter */
340 c_set_disp_reg(par, CARMINE_DISP_REG_L0RM, 0);
341 c_set_disp_reg(par, CARMINE_DISP_REG_L2RM, 0);
342 c_set_disp_reg(par, CARMINE_DISP_REG_L3RM, 0);
343 c_set_disp_reg(par, CARMINE_DISP_REG_L4RM, 0);
344 c_set_disp_reg(par, CARMINE_DISP_REG_L5RM, 0);
345 c_set_disp_reg(par, CARMINE_DISP_REG_L6RM, 0);
346 c_set_disp_reg(par, CARMINE_DISP_REG_L7RM, 0);
347
348 c_set_disp_reg(par, CARMINE_DISP_REG_L0PX, 0);
349 c_set_disp_reg(par, CARMINE_DISP_REG_L2PX, 0);
350 c_set_disp_reg(par, CARMINE_DISP_REG_L3PX, 0);
351 c_set_disp_reg(par, CARMINE_DISP_REG_L4PX, 0);
352 c_set_disp_reg(par, CARMINE_DISP_REG_L5PX, 0);
353 c_set_disp_reg(par, CARMINE_DISP_REG_L6PX, 0);
354 c_set_disp_reg(par, CARMINE_DISP_REG_L7PX, 0);
355
356 c_set_disp_reg(par, CARMINE_DISP_REG_L0PY, 0);
357 c_set_disp_reg(par, CARMINE_DISP_REG_L2PY, 0);
358 c_set_disp_reg(par, CARMINE_DISP_REG_L3PY, 0);
359 c_set_disp_reg(par, CARMINE_DISP_REG_L4PY, 0);
360 c_set_disp_reg(par, CARMINE_DISP_REG_L5PY, 0);
361 c_set_disp_reg(par, CARMINE_DISP_REG_L6PY, 0);
362 c_set_disp_reg(par, CARMINE_DISP_REG_L7PY, 0);
363}
364
365static void set_display_parameters(struct carmine_fb *par)
366{
367 u32 mode;
368 u32 hdp, vdp, htp, hsp, hsw, vtr, vsp, vsw;
369
370 /*
371 * display timing. Parameters are decreased by one because hardware
372 * spec is 0 to (n - 1)
373 * */
374 hdp = par->res->hdp - 1;
375 vdp = par->res->vdp - 1;
376 htp = par->res->htp - 1;
377 hsp = par->res->hsp - 1;
378 hsw = par->res->hsw - 1;
379 vtr = par->res->vtr - 1;
380 vsp = par->res->vsp - 1;
381 vsw = par->res->vsw - 1;
382
383 c_set_disp_reg(par, CARMINE_DISP_REG_H_TOTAL,
384 htp << CARMINE_DISP_HTP_SHIFT);
385 c_set_disp_reg(par, CARMINE_DISP_REG_H_PERIOD,
386 (hdp << CARMINE_DISP_HDB_SHIFT) | hdp);
387 c_set_disp_reg(par, CARMINE_DISP_REG_V_H_W_H_POS,
388 (vsw << CARMINE_DISP_VSW_SHIFT) |
389 (hsw << CARMINE_DISP_HSW_SHIFT) |
390 (hsp));
391 c_set_disp_reg(par, CARMINE_DISP_REG_V_TOTAL,
392 vtr << CARMINE_DISP_VTR_SHIFT);
393 c_set_disp_reg(par, CARMINE_DISP_REG_V_PERIOD_POS,
394 (vdp << CARMINE_DISP_VDP_SHIFT) | vsp);
395
396 /* clock */
397 mode = c_get_disp_reg(par, CARMINE_DISP_REG_DCM1);
398 mode = (mode & ~CARMINE_DISP_DCM_MASK) |
399 (par->res->disp_mode & CARMINE_DISP_DCM_MASK);
400 /* enable video output and layer 0 */
401 mode |= CARMINE_DEN | CARMINE_L0E;
402 c_set_disp_reg(par, CARMINE_DISP_REG_DCM1, mode);
403}
404
405static int carmine_set_par(struct fb_info *info)
406{
407 struct carmine_fb *par = info->par;
408 int ret;
409
410 ret = carmine_find_mode(&info->var);
411 if (ret < 0)
412 return ret;
413
414 par->new_mode = ret;
415 if (par->cur_mode != par->new_mode) {
416
417 par->cur_mode = par->new_mode;
418 par->res = &car_modes[par->new_mode];
419
420 carmine_init_display_param(par);
421 set_display_parameters(par);
422 }
423
424 info->fix.line_length = info->var.xres * info->var.bits_per_pixel / 8;
425 return 0;
426}
427
428static int init_hardware(struct carmine_hw *hw)
429{
430 u32 flags;
431 u32 loops;
432 u32 ret;
433
434 /* Initalize Carmine */
435 /* Sets internal clock */
436 c_set_hw_reg(hw, CARMINE_CTL_REG + CARMINE_CTL_REG_CLOCK_ENABLE,
437 CARMINE_DFLT_IP_CLOCK_ENABLE);
438
439 /* Video signal output is turned off */
440 c_set_hw_reg(hw, CARMINE_DISP0_REG + CARMINE_DISP_REG_DCM1, 0);
441 c_set_hw_reg(hw, CARMINE_DISP1_REG + CARMINE_DISP_REG_DCM1, 0);
442
443 /* Software reset */
444 c_set_hw_reg(hw, CARMINE_CTL_REG + CARMINE_CTL_REG_SOFTWARE_RESET, 1);
445 c_set_hw_reg(hw, CARMINE_CTL_REG + CARMINE_CTL_REG_SOFTWARE_RESET, 0);
446
447 /* I/O mode settings */
448 flags = CARMINE_DFLT_IP_DCTL_IO_CONT1 << 16 |
449 CARMINE_DFLT_IP_DCTL_IO_CONT0;
450 c_set_hw_reg(hw, CARMINE_DCTL_REG + CARMINE_DCTL_REG_IOCONT1_IOCONT0,
451 flags);
452
453 /* DRAM initial sequence */
454 flags = CARMINE_DFLT_IP_DCTL_MODE << 16 | CARMINE_DFLT_IP_DCTL_ADD;
455 c_set_hw_reg(hw, CARMINE_DCTL_REG + CARMINE_DCTL_REG_MODE_ADD,
456 flags);
457
458 flags = CARMINE_DFLT_IP_DCTL_SET_TIME1 << 16 |
459 CARMINE_DFLT_IP_DCTL_EMODE;
460 c_set_hw_reg(hw, CARMINE_DCTL_REG + CARMINE_DCTL_REG_SETTIME1_EMODE,
461 flags);
462
463 flags = CARMINE_DFLT_IP_DCTL_REFRESH << 16 |
464 CARMINE_DFLT_IP_DCTL_SET_TIME2;
465 c_set_hw_reg(hw, CARMINE_DCTL_REG + CARMINE_DCTL_REG_REFRESH_SETTIME2,
466 flags);
467
468 flags = CARMINE_DFLT_IP_DCTL_RESERVE2 << 16 |
469 CARMINE_DFLT_IP_DCTL_FIFO_DEPTH;
470 c_set_hw_reg(hw, CARMINE_DCTL_REG + CARMINE_DCTL_REG_RSV2_RSV1, flags);
471
472 flags = CARMINE_DFLT_IP_DCTL_DDRIF2 << 16 | CARMINE_DFLT_IP_DCTL_DDRIF1;
473 c_set_hw_reg(hw, CARMINE_DCTL_REG + CARMINE_DCTL_REG_DDRIF2_DDRIF1,
474 flags);
475
476 flags = CARMINE_DFLT_IP_DCTL_RESERVE0 << 16 |
477 CARMINE_DFLT_IP_DCTL_STATES;
478 c_set_hw_reg(hw, CARMINE_DCTL_REG + CARMINE_DCTL_REG_RSV0_STATES,
479 flags);
480
481 /* Executes DLL reset */
482 if (CARMINE_DCTL_DLL_RESET) {
483 for (loops = 0; loops < CARMINE_DCTL_INIT_WAIT_LIMIT; loops++) {
484
485 ret = c_get_hw_reg(hw, CARMINE_DCTL_REG +
486 CARMINE_DCTL_REG_RSV0_STATES);
487 ret &= CARMINE_DCTL_REG_STATES_MASK;
488 if (!ret)
489 break;
490
491 mdelay(CARMINE_DCTL_INIT_WAIT_INTERVAL);
492 }
493
494 if (loops >= CARMINE_DCTL_INIT_WAIT_LIMIT) {
495 printk(KERN_ERR "DRAM init failed\n");
496 return -EIO;
497 }
498 }
499
500 flags = CARMINE_DFLT_IP_DCTL_MODE_AFT_RST << 16 |
501 CARMINE_DFLT_IP_DCTL_ADD;
502 c_set_hw_reg(hw, CARMINE_DCTL_REG + CARMINE_DCTL_REG_MODE_ADD, flags);
503
504 flags = CARMINE_DFLT_IP_DCTL_RESERVE0 << 16 |
505 CARMINE_DFLT_IP_DCTL_STATES_AFT_RST;
506 c_set_hw_reg(hw, CARMINE_DCTL_REG + CARMINE_DCTL_REG_RSV0_STATES,
507 flags);
508
509 /* Initialize the write back register */
510 c_set_hw_reg(hw, CARMINE_WB_REG + CARMINE_WB_REG_WBM,
511 CARMINE_WB_REG_WBM_DEFAULT);
512
513 /* Initialize the Kottos registers */
514 c_set_hw_reg(hw, CARMINE_GRAPH_REG + CARMINE_GRAPH_REG_VRINTM, 0);
515 c_set_hw_reg(hw, CARMINE_GRAPH_REG + CARMINE_GRAPH_REG_VRERRM, 0);
516
517 /* Set DC offsets */
518 c_set_hw_reg(hw, CARMINE_GRAPH_REG + CARMINE_GRAPH_REG_DC_OFFSET_PX, 0);
519 c_set_hw_reg(hw, CARMINE_GRAPH_REG + CARMINE_GRAPH_REG_DC_OFFSET_PY, 0);
520 c_set_hw_reg(hw, CARMINE_GRAPH_REG + CARMINE_GRAPH_REG_DC_OFFSET_LX, 0);
521 c_set_hw_reg(hw, CARMINE_GRAPH_REG + CARMINE_GRAPH_REG_DC_OFFSET_LY, 0);
522 c_set_hw_reg(hw, CARMINE_GRAPH_REG + CARMINE_GRAPH_REG_DC_OFFSET_TX, 0);
523 c_set_hw_reg(hw, CARMINE_GRAPH_REG + CARMINE_GRAPH_REG_DC_OFFSET_TY, 0);
524 return 0;
525}
526
527static struct fb_ops carminefb_ops = {
528 .owner = THIS_MODULE,
529 .fb_fillrect = cfb_fillrect,
530 .fb_copyarea = cfb_copyarea,
531 .fb_imageblit = cfb_imageblit,
532
533 .fb_check_var = carmine_check_var,
534 .fb_set_par = carmine_set_par,
535 .fb_setcolreg = carmine_setcolreg,
536};
537
538static int alloc_carmine_fb(void __iomem *regs, void __iomem *smem_base,
539 int smem_offset, struct device *device, struct fb_info **rinfo)
540{
541 int ret;
542 struct fb_info *info;
543 struct carmine_fb *par;
544
545 info = framebuffer_alloc(sizeof *par, device);
546 if (!info)
547 return -ENOMEM;
548
549 par = info->par;
550 par->display_reg = regs;
551 par->smem_offset = smem_offset;
552
553 info->screen_base = smem_base + smem_offset;
554 info->screen_size = CARMINE_DISPLAY_MEM;
555 info->fbops = &carminefb_ops;
556
557 info->fix = carminefb_fix;
558 info->pseudo_palette = par->pseudo_palette;
559 info->flags = FBINFO_DEFAULT;
560
561 ret = fb_alloc_cmap(&info->cmap, 256, 1);
562 if (ret < 0)
563 goto err_free_fb;
564
565 if (fb_mode > ARRAY_SIZE(carmine_modedb))
566 fb_mode = CARMINEFB_DEFAULT_VIDEO_MODE;
567
568 par->cur_mode = par->new_mode = ~0;
569
570 ret = fb_find_mode(&info->var, info, fb_mode_str, carmine_modedb,
571 ARRAY_SIZE(carmine_modedb),
572 &carmine_modedb[fb_mode], 32);
573 if (!ret || ret == 4) {
574 ret = -EINVAL;
575 goto err_dealloc_cmap;
576 }
577
578 fb_videomode_to_modelist(carmine_modedb, ARRAY_SIZE(carmine_modedb),
579 &info->modelist);
580
581 ret = register_framebuffer(info);
582 if (ret < 0)
583 goto err_dealloc_cmap;
584
585 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
586 info->fix.id);
587
588 *rinfo = info;
589 return 0;
590
591err_dealloc_cmap:
592 fb_dealloc_cmap(&info->cmap);
593err_free_fb:
594 framebuffer_release(info);
595 return ret;
596}
597
598static void cleanup_fb_device(struct fb_info *info)
599{
600 if (info) {
601 unregister_framebuffer(info);
602 fb_dealloc_cmap(&info->cmap);
603 framebuffer_release(info);
604 }
605}
606
607static int __devinit carminefb_probe(struct pci_dev *dev,
608 const struct pci_device_id *ent)
609{
610 struct carmine_hw *hw;
611 struct device *device = &dev->dev;
612 struct fb_info *info;
613 int ret;
614
615 ret = pci_enable_device(dev);
616 if (ret)
617 return ret;
618
619 ret = -ENOMEM;
620 hw = kzalloc(sizeof *hw, GFP_KERNEL);
621 if (!hw)
622 goto err_enable_pci;
623
624 carminefb_fix.mmio_start = pci_resource_start(dev, CARMINE_CONFIG_BAR);
625 carminefb_fix.mmio_len = pci_resource_len(dev, CARMINE_CONFIG_BAR);
626
627 if (!request_mem_region(carminefb_fix.mmio_start,
628 carminefb_fix.mmio_len,
629 "carminefb regbase")) {
630 printk(KERN_ERR "carminefb: Can't reserve regbase.\n");
631 ret = -EBUSY;
632 goto err_free_hw;
633 }
634 hw->v_regs = ioremap_nocache(carminefb_fix.mmio_start,
635 carminefb_fix.mmio_len);
636 if (!hw->v_regs) {
637 printk(KERN_ERR "carminefb: Can't remap %s register.\n",
638 carminefb_fix.id);
639 goto err_free_reg_mmio;
640 }
641
642 carminefb_fix.smem_start = pci_resource_start(dev, CARMINE_MEMORY_BAR);
643 carminefb_fix.smem_len = pci_resource_len(dev, CARMINE_MEMORY_BAR);
644
645 /* The memory area tends to be very large (256 MiB). Remap only what
646 * is required for that largest resolution to avoid remaps at run
647 * time
648 */
649 if (carminefb_fix.smem_len > CARMINE_TOTAL_DIPLAY_MEM)
650 carminefb_fix.smem_len = CARMINE_TOTAL_DIPLAY_MEM;
651
652 else if (carminefb_fix.smem_len < CARMINE_TOTAL_DIPLAY_MEM) {
653 printk(KERN_ERR "carminefb: Memory bar is only %d bytes, %d "
654 "are required.", carminefb_fix.smem_len,
655 CARMINE_TOTAL_DIPLAY_MEM);
656 goto err_free_reg_mmio;
657 }
658
659 if (!request_mem_region(carminefb_fix.smem_start,
660 carminefb_fix.smem_len, "carminefb smem")) {
661 printk(KERN_ERR "carminefb: Can't reserve smem.\n");
662 goto err_unmap_vregs;
663 }
664
665 hw->screen_mem = ioremap_nocache(carminefb_fix.smem_start,
666 carminefb_fix.smem_len);
667 if (!hw->screen_mem) {
668 printk(KERN_ERR "carmine: Can't ioremap smem area.\n");
669 release_mem_region(carminefb_fix.smem_start,
670 carminefb_fix.smem_len);
671 goto err_reg_smem;
672 }
673
674 ret = init_hardware(hw);
675 if (ret)
676 goto err_unmap_screen;
677
678 info = NULL;
679 if (fb_displays & CARMINE_USE_DISPLAY0) {
680 ret = alloc_carmine_fb(hw->v_regs + CARMINE_DISP0_REG,
681 hw->screen_mem, CARMINE_DISPLAY_MEM * 0,
682 device, &info);
683 if (ret)
684 goto err_deinit_hw;
685 }
686
687 hw->fb[0] = info;
688
689 info = NULL;
690 if (fb_displays & CARMINE_USE_DISPLAY1) {
691 ret = alloc_carmine_fb(hw->v_regs + CARMINE_DISP1_REG,
692 hw->screen_mem, CARMINE_DISPLAY_MEM * 1,
693 device, &info);
694 if (ret)
695 goto err_cleanup_fb0;
696 }
697
698 hw->fb[1] = info;
699 info = NULL;
700
701 pci_set_drvdata(dev, hw);
702 return 0;
703
704err_cleanup_fb0:
705 cleanup_fb_device(hw->fb[0]);
706err_deinit_hw:
707 /* disable clock, etc */
708 c_set_hw_reg(hw, CARMINE_CTL_REG + CARMINE_CTL_REG_CLOCK_ENABLE, 0);
709err_unmap_screen:
710 iounmap(hw->screen_mem);
711err_reg_smem:
712 release_mem_region(carminefb_fix.mmio_start, carminefb_fix.mmio_len);
713err_unmap_vregs:
714 iounmap(hw->v_regs);
715err_free_reg_mmio:
716 release_mem_region(carminefb_fix.mmio_start, carminefb_fix.mmio_len);
717err_free_hw:
718 kfree(hw);
719err_enable_pci:
720 pci_disable_device(dev);
721 return ret;
722}
723
724static void __devexit carminefb_remove(struct pci_dev *dev)
725{
726 struct carmine_hw *hw = pci_get_drvdata(dev);
727 struct fb_fix_screeninfo fix;
728 int i;
729
730 /* in case we use only fb1 and not fb1 */
731 if (hw->fb[0])
732 fix = hw->fb[0]->fix;
733 else
734 fix = hw->fb[1]->fix;
735
736 /* deactivate display(s) and switch clocks */
737 c_set_hw_reg(hw, CARMINE_DISP0_REG + CARMINE_DISP_REG_DCM1, 0);
738 c_set_hw_reg(hw, CARMINE_DISP1_REG + CARMINE_DISP_REG_DCM1, 0);
739 c_set_hw_reg(hw, CARMINE_CTL_REG + CARMINE_CTL_REG_CLOCK_ENABLE, 0);
740
741 for (i = 0; i < MAX_DISPLAY; i++)
742 cleanup_fb_device(hw->fb[i]);
743
744 iounmap(hw->screen_mem);
745 release_mem_region(fix.smem_start, fix.smem_len);
746 iounmap(hw->v_regs);
747 release_mem_region(fix.mmio_start, fix.mmio_len);
748
749 pci_set_drvdata(dev, NULL);
750 pci_disable_device(dev);
751 kfree(hw);
752}
753
754#define PCI_VENDOR_ID_FUJITU_LIMITED 0x10cf
755static struct pci_device_id carmine_devices[] __devinitdata = {
756{
757 PCI_DEVICE(PCI_VENDOR_ID_FUJITU_LIMITED, 0x202b)},
758 {0, 0, 0, 0, 0, 0, 0}
759};
760
761MODULE_DEVICE_TABLE(pci, carmine_devices);
762
763static struct pci_driver carmine_pci_driver = {
764 .name = "carminefb",
765 .id_table = carmine_devices,
766 .probe = carminefb_probe,
767 .remove = __devexit_p(carminefb_remove),
768};
769
770static int __init carminefb_init(void)
771{
772 if (!(fb_displays &
773 (CARMINE_USE_DISPLAY0 | CARMINE_USE_DISPLAY1))) {
774 printk(KERN_ERR "If you disable both displays than you don't "
775 "need the driver at all\n");
776 return -EINVAL;
777 }
778 return pci_register_driver(&carmine_pci_driver);
779}
780module_init(carminefb_init);
781
782static void __exit carminefb_cleanup(void)
783{
784 pci_unregister_driver(&carmine_pci_driver);
785}
786module_exit(carminefb_cleanup);
787
788MODULE_AUTHOR("Sebastian Siewior <bigeasy@linutronix.de>");
789MODULE_DESCRIPTION("Framebuffer driver for Fujitsu Carmine based devices");
790MODULE_LICENSE("GPL v2");
diff --git a/drivers/video/carminefb.h b/drivers/video/carminefb.h
new file mode 100644
index 000000000000..05306de0c6b6
--- /dev/null
+++ b/drivers/video/carminefb.h
@@ -0,0 +1,64 @@
1#ifndef CARMINE_CARMINE_H
2#define CARMINE_CARMINE_H
3
4#define CARMINE_MEMORY_BAR 2
5#define CARMINE_CONFIG_BAR 3
6
7#define MAX_DISPLAY 2
8#define CARMINE_DISPLAY_MEM (800 * 600 * 4)
9#define CARMINE_TOTAL_DIPLAY_MEM (CARMINE_DISPLAY_MEM * MAX_DISPLAY)
10
11#define CARMINE_USE_DISPLAY0 (1 << 0)
12#define CARMINE_USE_DISPLAY1 (1 << 1)
13
14/*
15 * This values work on the eval card. Custom boards may use different timings,
16 * here an example :)
17 */
18
19/* DRAM initialization values */
20#ifdef CONFIG_FB_CARMINE_DRAM_EVAL
21
22#define CARMINE_DFLT_IP_CLOCK_ENABLE (0x03ff)
23#define CARMINE_DFLT_IP_DCTL_ADD (0x05c3)
24#define CARMINE_DFLT_IP_DCTL_MODE (0x0121)
25#define CARMINE_DFLT_IP_DCTL_EMODE (0x8000)
26#define CARMINE_DFLT_IP_DCTL_SET_TIME1 (0x4749)
27#define CARMINE_DFLT_IP_DCTL_SET_TIME2 (0x2a22)
28#define CARMINE_DFLT_IP_DCTL_REFRESH (0x0042)
29#define CARMINE_DFLT_IP_DCTL_STATES (0x0003)
30#define CARMINE_DFLT_IP_DCTL_RESERVE0 (0x0020)
31#define CARMINE_DFLT_IP_DCTL_FIFO_DEPTH (0x000f)
32#define CARMINE_DFLT_IP_DCTL_RESERVE2 (0x0000)
33#define CARMINE_DFLT_IP_DCTL_DDRIF1 (0x6646)
34#define CARMINE_DFLT_IP_DCTL_DDRIF2 (0x0055)
35#define CARMINE_DFLT_IP_DCTL_MODE_AFT_RST (0x0021)
36#define CARMINE_DFLT_IP_DCTL_STATES_AFT_RST (0x0002)
37#define CARMINE_DFLT_IP_DCTL_IO_CONT0 (0x0555)
38#define CARMINE_DFLT_IP_DCTL_IO_CONT1 (0x0555)
39#define CARMINE_DCTL_DLL_RESET (1)
40#endif
41
42#ifdef CONFIG_CARMINE_DRAM_CUSTOM
43
44#define CARMINE_DFLT_IP_CLOCK_ENABLE (0x03ff)
45#define CARMINE_DFLT_IP_DCTL_ADD (0x03b2)
46#define CARMINE_DFLT_IP_DCTL_MODE (0x0161)
47#define CARMINE_DFLT_IP_DCTL_EMODE (0x8000)
48#define CARMINE_DFLT_IP_DCTL_SET_TIME1 (0x2628)
49#define CARMINE_DFLT_IP_DCTL_SET_TIME2 (0x1a09)
50#define CARMINE_DFLT_IP_DCTL_REFRESH (0x00fe)
51#define CARMINE_DFLT_IP_DCTL_STATES (0x0003)
52#define CARMINE_DFLT_IP_DCTL_RESERVE0 (0x0020)
53#define CARMINE_DFLT_IP_DCTL_FIFO_DEPTH (0x000f)
54#define CARMINE_DFLT_IP_DCTL_RESERVE2 (0x0000)
55#define CARMINE_DFLT_IP_DCTL_DDRIF1 (0x0646)
56#define CARMINE_DFLT_IP_DCTL_DDRIF2 (0x55aa)
57#define CARMINE_DFLT_IP_DCTL_MODE_AFT_RST (0x0061)
58#define CARMINE_DFLT_IP_DCTL_STATES_AFT_RST (0x0002)
59#define CARMINE_DFLT_IP_DCTL_IO_CONT0 (0x0555)
60#define CARMINE_DFLT_IP_DCTL_IO_CONT1 (0x0555)
61#define CARMINE_DCTL_DLL_RESET (1)
62#endif
63
64#endif
diff --git a/drivers/video/carminefb_regs.h b/drivers/video/carminefb_regs.h
new file mode 100644
index 000000000000..045215600b73
--- /dev/null
+++ b/drivers/video/carminefb_regs.h
@@ -0,0 +1,159 @@
1#ifndef _CARMINEFB_REGS_H
2#define _CARMINEFB_REGS_H
3
4#define CARMINE_OVERLAY_EXT_MODE (0x00000002)
5#define CARMINE_GRAPH_REG (0x00000000)
6#define CARMINE_DISP0_REG (0x00100000)
7#define CARMINE_DISP1_REG (0x00140000)
8#define CARMINE_WB_REG (0x00180000)
9#define CARMINE_DCTL_REG (0x00300000)
10#define CARMINE_CTL_REG (0x00400000)
11#define CARMINE_WINDOW_MODE (0x00000001)
12#define CARMINE_EXTEND_MODE (CARMINE_WINDOW_MODE | \
13 CARMINE_OVERLAY_EXT_MODE)
14#define CARMINE_L0E (1 << 16)
15#define CARMINE_L2E (1 << 18)
16#define CARMINE_DEN (1 << 31)
17
18#define CARMINE_EXT_CMODE_DIRECT24_RGBA (0xC0000000)
19#define CARMINE_DCTL_REG_MODE_ADD (0x00)
20#define CARMINE_DCTL_REG_SETTIME1_EMODE (0x04)
21#define CARMINE_DCTL_REG_REFRESH_SETTIME2 (0x08)
22#define CARMINE_DCTL_REG_RSV0_STATES (0x0C)
23#define CARMINE_DCTL_REG_RSV2_RSV1 (0x10)
24#define CARMINE_DCTL_REG_DDRIF2_DDRIF1 (0x14)
25#define CARMINE_DCTL_REG_IOCONT1_IOCONT0 (0x24)
26#define CARMINE_DCTL_REG_STATES_MASK (0x000F)
27#define CARMINE_DCTL_INIT_WAIT_INTERVAL (1)
28#define CARMINE_DCTL_INIT_WAIT_LIMIT (5000)
29#define CARMINE_WB_REG_WBM_DEFAULT (0x0001c020)
30#define CARMINE_DISP_REG_L0RM (0x1880)
31#define CARMINE_DISP_REG_L0PX (0x1884)
32#define CARMINE_DISP_REG_L0PY (0x1888)
33#define CARMINE_DISP_REG_L2RM (0x18A0)
34#define CARMINE_DISP_REG_L2PX (0x18A4)
35#define CARMINE_DISP_REG_L2PY (0x18A8)
36#define CARMINE_DISP_REG_L3RM (0x18B0)
37#define CARMINE_DISP_REG_L3PX (0x18B4)
38#define CARMINE_DISP_REG_L3PY (0x18B8)
39#define CARMINE_DISP_REG_L4RM (0x18C0)
40#define CARMINE_DISP_REG_L4PX (0x18C4)
41#define CARMINE_DISP_REG_L4PY (0x18C8)
42#define CARMINE_DISP_REG_L5RM (0x18D0)
43#define CARMINE_DISP_REG_L5PX (0x18D4)
44#define CARMINE_DISP_REG_L5PY (0x18D8)
45#define CARMINE_DISP_REG_L6RM (0x1924)
46#define CARMINE_DISP_REG_L6PX (0x1928)
47#define CARMINE_DISP_REG_L6PY (0x192C)
48#define CARMINE_DISP_REG_L7RM (0x1964)
49#define CARMINE_DISP_REG_L7PX (0x1968)
50#define CARMINE_DISP_REG_L7PY (0x196C)
51#define CARMINE_WB_REG_WBM (0x0004)
52#define CARMINE_DISP_HTP_SHIFT (16)
53#define CARMINE_DISP_HDB_SHIFT (16)
54#define CARMINE_DISP_HSW_SHIFT (16)
55#define CARMINE_DISP_VSW_SHIFT (24)
56#define CARMINE_DISP_VTR_SHIFT (16)
57#define CARMINE_DISP_VDP_SHIFT (16)
58#define CARMINE_CURSOR_CUTZ_MASK (0x00000100)
59#define CARMINE_CURSOR0_PRIORITY_MASK (0x00010000)
60#define CARMINE_CURSOR1_PRIORITY_MASK (0x00020000)
61#define CARMINE_DISP_WIDTH_SHIFT (16)
62#define CARMINE_DISP_WIN_H_SHIFT (16)
63#define CARMINE_DISP_REG_H_TOTAL (0x0004)
64#define CARMINE_DISP_REG_H_PERIOD (0x0008)
65#define CARMINE_DISP_REG_V_H_W_H_POS (0x000C)
66#define CARMINE_DISP_REG_V_TOTAL (0x0010)
67#define CARMINE_DISP_REG_V_PERIOD_POS (0x0014)
68#define CARMINE_DISP_REG_L0_MODE_W_H (0x0020)
69#define CARMINE_DISP_REG_L0_ORG_ADR (0x0024)
70#define CARMINE_DISP_REG_L0_DISP_ADR (0x0028)
71#define CARMINE_DISP_REG_L0_DISP_POS (0x002C)
72#define CARMINE_DISP_REG_L1_WIDTH (0x0030)
73#define CARMINE_DISP_REG_L1_ORG_ADR (0x0034)
74#define CARMINE_DISP_REG_L2_MODE_W_H (0x0040)
75#define CARMINE_DISP_REG_L2_ORG_ADR1 (0x0044)
76#define CARMINE_DISP_REG_L2_DISP_ADR1 (0x0048)
77#define CARMINE_DISP_REG_L2_DISP_POS (0x0054)
78#define CARMINE_DISP_REG_L3_MODE_W_H (0x0058)
79#define CARMINE_DISP_REG_L3_ORG_ADR1 (0x005C)
80#define CARMINE_DISP_REG_L3_DISP_ADR1 (0x0060)
81#define CARMINE_DISP_REG_L3_DISP_POS (0x006C)
82#define CARMINE_DISP_REG_L4_MODE_W_H (0x0070)
83#define CARMINE_DISP_REG_L4_ORG_ADR1 (0x0074)
84#define CARMINE_DISP_REG_L4_DISP_ADR1 (0x0078)
85#define CARMINE_DISP_REG_L4_DISP_POS (0x0084)
86#define CARMINE_DISP_REG_L5_MODE_W_H (0x0088)
87#define CARMINE_DISP_REG_L5_ORG_ADR1 (0x008C)
88#define CARMINE_DISP_REG_L5_DISP_ADR1 (0x0090)
89#define CARMINE_DISP_REG_L5_DISP_POS (0x009C)
90#define CARMINE_DISP_REG_CURSOR_MODE (0x00A0)
91#define CARMINE_DISP_REG_CUR1_POS (0x00A8)
92#define CARMINE_DISP_REG_CUR2_POS (0x00B0)
93#define CARMINE_DISP_REG_C_TRANS (0x00BC)
94#define CARMINE_DISP_REG_MLMR_TRANS (0x00C0)
95#define CARMINE_DISP_REG_L0_EXT_MODE (0x0110)
96#define CARMINE_DISP_REG_L0_WIN_POS (0x0114)
97#define CARMINE_DISP_REG_L0_WIN_SIZE (0x0118)
98#define CARMINE_DISP_REG_L1_EXT_MODE (0x0120)
99#define CARMINE_DISP_REG_L1_WIN_POS (0x0124)
100#define CARMINE_DISP_REG_L1_WIN_SIZE (0x0128)
101#define CARMINE_DISP_REG_L2_EXT_MODE (0x0130)
102#define CARMINE_DISP_REG_L2_WIN_POS (0x0134)
103#define CARMINE_DISP_REG_L2_WIN_SIZE (0x0138)
104#define CARMINE_DISP_REG_L3_EXT_MODE (0x0140)
105#define CARMINE_DISP_REG_L3_WIN_POS (0x0144)
106#define CARMINE_DISP_REG_L3_WIN_SIZE (0x0148)
107#define CARMINE_DISP_REG_L4_EXT_MODE (0x0150)
108#define CARMINE_DISP_REG_L4_WIN_POS (0x0154)
109#define CARMINE_DISP_REG_L4_WIN_SIZE (0x0158)
110#define CARMINE_DISP_REG_L5_EXT_MODE (0x0160)
111#define CARMINE_DISP_REG_L5_WIN_POS (0x0164)
112#define CARMINE_DISP_REG_L5_WIN_SIZE (0x0168)
113#define CARMINE_DISP_REG_L6_EXT_MODE (0x1918)
114#define CARMINE_DISP_REG_L6_WIN_POS (0x191c)
115#define CARMINE_DISP_REG_L6_WIN_SIZE (0x1920)
116#define CARMINE_DISP_REG_L7_EXT_MODE (0x1958)
117#define CARMINE_DISP_REG_L7_WIN_POS (0x195c)
118#define CARMINE_DISP_REG_L7_WIN_SIZE (0x1960)
119#define CARMINE_DISP_REG_BLEND_MODE_L0 (0x00B4)
120#define CARMINE_DISP_REG_BLEND_MODE_L1 (0x0188)
121#define CARMINE_DISP_REG_BLEND_MODE_L2 (0x018C)
122#define CARMINE_DISP_REG_BLEND_MODE_L3 (0x0190)
123#define CARMINE_DISP_REG_BLEND_MODE_L4 (0x0194)
124#define CARMINE_DISP_REG_BLEND_MODE_L5 (0x0198)
125#define CARMINE_DISP_REG_BLEND_MODE_L6 (0x1990)
126#define CARMINE_DISP_REG_BLEND_MODE_L7 (0x1994)
127#define CARMINE_DISP_REG_L0_TRANS (0x01A0)
128#define CARMINE_DISP_REG_L1_TRANS (0x01A4)
129#define CARMINE_DISP_REG_L2_TRANS (0x01A8)
130#define CARMINE_DISP_REG_L3_TRANS (0x01AC)
131#define CARMINE_DISP_REG_L4_TRANS (0x01B0)
132#define CARMINE_DISP_REG_L5_TRANS (0x01B4)
133#define CARMINE_DISP_REG_L6_TRANS (0x1998)
134#define CARMINE_DISP_REG_L7_TRANS (0x199c)
135#define CARMINE_EXTEND_MODE_MASK (0x00000003)
136#define CARMINE_DISP_DCM_MASK (0x0000FFFF)
137#define CARMINE_DISP_REG_DCM1 (0x0100)
138#define CARMINE_DISP_WIDTH_UNIT (64)
139#define CARMINE_DISP_REG_L6_MODE_W_H (0x1900)
140#define CARMINE_DISP_REG_L6_ORG_ADR1 (0x1904)
141#define CARMINE_DISP_REG_L6_DISP_ADR0 (0x1908)
142#define CARMINE_DISP_REG_L6_DISP_POS (0x1914)
143#define CARMINE_DISP_REG_L7_MODE_W_H (0x1940)
144#define CARMINE_DISP_REG_L7_ORG_ADR1 (0x1944)
145#define CARMINE_DISP_REG_L7_DISP_ADR0 (0x1948)
146#define CARMINE_DISP_REG_L7_DISP_POS (0x1954)
147#define CARMINE_CTL_REG_CLOCK_ENABLE (0x000C)
148#define CARMINE_CTL_REG_SOFTWARE_RESET (0x0010)
149#define CARMINE_CTL_REG_IST_MASK_ALL (0x07FFFFFF)
150#define CARMINE_GRAPH_REG_VRINTM (0x00028064)
151#define CARMINE_GRAPH_REG_VRERRM (0x0002806C)
152#define CARMINE_GRAPH_REG_DC_OFFSET_PX (0x0004005C)
153#define CARMINE_GRAPH_REG_DC_OFFSET_PY (0x00040060)
154#define CARMINE_GRAPH_REG_DC_OFFSET_LX (0x00040064)
155#define CARMINE_GRAPH_REG_DC_OFFSET_LY (0x00040068)
156#define CARMINE_GRAPH_REG_DC_OFFSET_TX (0x0004006C)
157#define CARMINE_GRAPH_REG_DC_OFFSET_TY (0x00040070)
158
159#endif
diff --git a/drivers/video/cobalt_lcdfb.c b/drivers/video/cobalt_lcdfb.c
new file mode 100644
index 000000000000..7bad24ed04ef
--- /dev/null
+++ b/drivers/video/cobalt_lcdfb.c
@@ -0,0 +1,371 @@
1/*
2 * Cobalt server LCD frame buffer driver.
3 *
4 * Copyright (C) 2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20#include <linux/delay.h>
21#include <linux/fb.h>
22#include <linux/init.h>
23#include <linux/io.h>
24#include <linux/ioport.h>
25#include <linux/uaccess.h>
26#include <linux/platform_device.h>
27
28/*
29 * Cursor position address
30 * \X 0 1 2 ... 14 15
31 * Y+----+----+----+---+----+----+
32 * 0|0x00|0x01|0x02|...|0x0e|0x0f|
33 * +----+----+----+---+----+----+
34 * 1|0x40|0x41|0x42|...|0x4e|0x4f|
35 * +----+----+----+---+----+----+
36 */
37#define LCD_DATA_REG_OFFSET 0x10
38#define LCD_XRES_MAX 16
39#define LCD_YRES_MAX 2
40#define LCD_CHARS_MAX 32
41
42#define LCD_CLEAR 0x01
43#define LCD_CURSOR_MOVE_HOME 0x02
44#define LCD_RESET 0x06
45#define LCD_OFF 0x08
46#define LCD_CURSOR_OFF 0x0c
47#define LCD_CURSOR_BLINK_OFF 0x0e
48#define LCD_CURSOR_ON 0x0f
49#define LCD_ON LCD_CURSOR_ON
50#define LCD_CURSOR_MOVE_LEFT 0x10
51#define LCD_CURSOR_MOVE_RIGHT 0x14
52#define LCD_DISPLAY_LEFT 0x18
53#define LCD_DISPLAY_RIGHT 0x1c
54#define LCD_PRERESET 0x3f /* execute 4 times continuously */
55#define LCD_BUSY 0x80
56
57#define LCD_GRAPHIC_MODE 0x40
58#define LCD_TEXT_MODE 0x80
59#define LCD_CUR_POS_MASK 0x7f
60
61#define LCD_CUR_POS(x) ((x) & LCD_CUR_POS_MASK)
62#define LCD_TEXT_POS(x) ((x) | LCD_TEXT_MODE)
63
64static inline void lcd_write_control(struct fb_info *info, u8 control)
65{
66 writel((u32)control << 24, info->screen_base);
67}
68
69static inline u8 lcd_read_control(struct fb_info *info)
70{
71 return readl(info->screen_base) >> 24;
72}
73
74static inline void lcd_write_data(struct fb_info *info, u8 data)
75{
76 writel((u32)data << 24, info->screen_base + LCD_DATA_REG_OFFSET);
77}
78
79static inline u8 lcd_read_data(struct fb_info *info)
80{
81 return readl(info->screen_base + LCD_DATA_REG_OFFSET) >> 24;
82}
83
84static int lcd_busy_wait(struct fb_info *info)
85{
86 u8 val = 0;
87 int timeout = 10, retval = 0;
88
89 do {
90 val = lcd_read_control(info);
91 val &= LCD_BUSY;
92 if (val != LCD_BUSY)
93 break;
94
95 if (msleep_interruptible(1))
96 return -EINTR;
97
98 timeout--;
99 } while (timeout);
100
101 if (val == LCD_BUSY)
102 retval = -EBUSY;
103
104 return retval;
105}
106
107static void lcd_clear(struct fb_info *info)
108{
109 int i;
110
111 for (i = 0; i < 4; i++) {
112 udelay(150);
113
114 lcd_write_control(info, LCD_PRERESET);
115 }
116
117 udelay(150);
118
119 lcd_write_control(info, LCD_CLEAR);
120
121 udelay(150);
122
123 lcd_write_control(info, LCD_RESET);
124}
125
126static struct fb_fix_screeninfo cobalt_lcdfb_fix __initdata = {
127 .id = "cobalt-lcd",
128 .type = FB_TYPE_TEXT,
129 .type_aux = FB_AUX_TEXT_MDA,
130 .visual = FB_VISUAL_MONO01,
131 .line_length = LCD_XRES_MAX,
132 .accel = FB_ACCEL_NONE,
133};
134
135static ssize_t cobalt_lcdfb_read(struct fb_info *info, char __user *buf,
136 size_t count, loff_t *ppos)
137{
138 char src[LCD_CHARS_MAX];
139 unsigned long pos;
140 int len, retval = 0;
141
142 pos = *ppos;
143 if (pos >= LCD_CHARS_MAX || count == 0)
144 return 0;
145
146 if (count > LCD_CHARS_MAX)
147 count = LCD_CHARS_MAX;
148
149 if (pos + count > LCD_CHARS_MAX)
150 count = LCD_CHARS_MAX - pos;
151
152 for (len = 0; len < count; len++) {
153 retval = lcd_busy_wait(info);
154 if (retval < 0)
155 break;
156
157 lcd_write_control(info, LCD_TEXT_POS(pos));
158
159 retval = lcd_busy_wait(info);
160 if (retval < 0)
161 break;
162
163 src[len] = lcd_read_data(info);
164 if (pos == 0x0f)
165 pos = 0x40;
166 else
167 pos++;
168 }
169
170 if (retval < 0 && signal_pending(current))
171 return -ERESTARTSYS;
172
173 if (copy_to_user(buf, src, len))
174 return -EFAULT;
175
176 *ppos += len;
177
178 return len;
179}
180
181static ssize_t cobalt_lcdfb_write(struct fb_info *info, const char __user *buf,
182 size_t count, loff_t *ppos)
183{
184 char dst[LCD_CHARS_MAX];
185 unsigned long pos;
186 int len, retval = 0;
187
188 pos = *ppos;
189 if (pos >= LCD_CHARS_MAX || count == 0)
190 return 0;
191
192 if (count > LCD_CHARS_MAX)
193 count = LCD_CHARS_MAX;
194
195 if (pos + count > LCD_CHARS_MAX)
196 count = LCD_CHARS_MAX - pos;
197
198 if (copy_from_user(dst, buf, count))
199 return -EFAULT;
200
201 for (len = 0; len < count; len++) {
202 retval = lcd_busy_wait(info);
203 if (retval < 0)
204 break;
205
206 lcd_write_control(info, LCD_TEXT_POS(pos));
207
208 retval = lcd_busy_wait(info);
209 if (retval < 0)
210 break;
211
212 lcd_write_data(info, dst[len]);
213 if (pos == 0x0f)
214 pos = 0x40;
215 else
216 pos++;
217 }
218
219 if (retval < 0 && signal_pending(current))
220 return -ERESTARTSYS;
221
222 *ppos += len;
223
224 return len;
225}
226
227static int cobalt_lcdfb_blank(int blank_mode, struct fb_info *info)
228{
229 int retval;
230
231 retval = lcd_busy_wait(info);
232 if (retval < 0)
233 return retval;
234
235 switch (blank_mode) {
236 case FB_BLANK_UNBLANK:
237 lcd_write_control(info, LCD_ON);
238 break;
239 default:
240 lcd_write_control(info, LCD_OFF);
241 break;
242 }
243
244 return 0;
245}
246
247static int cobalt_lcdfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
248{
249 u32 x, y;
250 int retval;
251
252 switch (cursor->set) {
253 case FB_CUR_SETPOS:
254 x = cursor->image.dx;
255 y = cursor->image.dy;
256 if (x >= LCD_XRES_MAX || y >= LCD_YRES_MAX)
257 return -EINVAL;
258
259 retval = lcd_busy_wait(info);
260 if (retval < 0)
261 return retval;
262
263 lcd_write_control(info,
264 LCD_TEXT_POS(info->fix.line_length * y + x));
265 break;
266 default:
267 return -EINVAL;
268 }
269
270 retval = lcd_busy_wait(info);
271 if (retval < 0)
272 return retval;
273
274 if (cursor->enable)
275 lcd_write_control(info, LCD_CURSOR_ON);
276 else
277 lcd_write_control(info, LCD_CURSOR_OFF);
278
279 return 0;
280}
281
282static struct fb_ops cobalt_lcd_fbops = {
283 .owner = THIS_MODULE,
284 .fb_read = cobalt_lcdfb_read,
285 .fb_write = cobalt_lcdfb_write,
286 .fb_blank = cobalt_lcdfb_blank,
287 .fb_cursor = cobalt_lcdfb_cursor,
288};
289
290static int __init cobalt_lcdfb_probe(struct platform_device *dev)
291{
292 struct fb_info *info;
293 struct resource *res;
294 int retval;
295
296 info = framebuffer_alloc(0, &dev->dev);
297 if (!info)
298 return -ENOMEM;
299
300 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
301 if (!res) {
302 framebuffer_release(info);
303 return -EBUSY;
304 }
305
306 info->screen_size = res->end - res->start + 1;
307 info->screen_base = ioremap(res->start, info->screen_size);
308 info->fbops = &cobalt_lcd_fbops;
309 info->fix = cobalt_lcdfb_fix;
310 info->fix.smem_start = res->start;
311 info->fix.smem_len = info->screen_size;
312 info->pseudo_palette = NULL;
313 info->par = NULL;
314 info->flags = FBINFO_DEFAULT;
315
316 retval = register_framebuffer(info);
317 if (retval < 0) {
318 iounmap(info->screen_base);
319 framebuffer_release(info);
320 return retval;
321 }
322
323 platform_set_drvdata(dev, info);
324
325 lcd_clear(info);
326
327 printk(KERN_INFO "fb%d: Cobalt server LCD frame buffer device\n",
328 info->node);
329
330 return 0;
331}
332
333static int __devexit cobalt_lcdfb_remove(struct platform_device *dev)
334{
335 struct fb_info *info;
336
337 info = platform_get_drvdata(dev);
338 if (info) {
339 iounmap(info->screen_base);
340 unregister_framebuffer(info);
341 framebuffer_release(info);
342 }
343
344 return 0;
345}
346
347static struct platform_driver cobalt_lcdfb_driver = {
348 .probe = cobalt_lcdfb_probe,
349 .remove = __devexit_p(cobalt_lcdfb_remove),
350 .driver = {
351 .name = "cobalt-lcd",
352 .owner = THIS_MODULE,
353 },
354};
355
356static int __init cobalt_lcdfb_init(void)
357{
358 return platform_driver_register(&cobalt_lcdfb_driver);
359}
360
361static void __exit cobalt_lcdfb_exit(void)
362{
363 platform_driver_unregister(&cobalt_lcdfb_driver);
364}
365
366module_init(cobalt_lcdfb_init);
367module_exit(cobalt_lcdfb_exit);
368
369MODULE_LICENSE("GPL v2");
370MODULE_AUTHOR("Yoichi Yuasa");
371MODULE_DESCRIPTION("Cobalt server LCD frame buffer driver");
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 4be3b46c069b..3ccfa76d9b2a 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -107,9 +107,7 @@ static struct display fb_display[MAX_NR_CONSOLES];
107 107
108static signed char con2fb_map[MAX_NR_CONSOLES]; 108static signed char con2fb_map[MAX_NR_CONSOLES];
109static signed char con2fb_map_boot[MAX_NR_CONSOLES]; 109static signed char con2fb_map_boot[MAX_NR_CONSOLES];
110#ifndef MODULE 110
111static int logo_height;
112#endif
113static int logo_lines; 111static int logo_lines;
114/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO 112/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
115 enums. */ 113 enums. */
@@ -607,6 +605,7 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
607 struct fbcon_ops *ops = info->fbcon_par; 605 struct fbcon_ops *ops = info->fbcon_par;
608 int cnt, erase = vc->vc_video_erase_char, step; 606 int cnt, erase = vc->vc_video_erase_char, step;
609 unsigned short *save = NULL, *r, *q; 607 unsigned short *save = NULL, *r, *q;
608 int logo_height;
610 609
611 if (info->flags & FBINFO_MODULE) { 610 if (info->flags & FBINFO_MODULE) {
612 logo_shown = FBCON_LOGO_DONTSHOW; 611 logo_shown = FBCON_LOGO_DONTSHOW;
diff --git a/drivers/video/console/fbcon.h b/drivers/video/console/fbcon.h
index 0135e0395456..de1b1365279b 100644
--- a/drivers/video/console/fbcon.h
+++ b/drivers/video/console/fbcon.h
@@ -92,7 +92,7 @@ struct fbcon_ops {
92#define attr_fgcol(fgshift,s) \ 92#define attr_fgcol(fgshift,s) \
93 (((s) >> (fgshift)) & 0x0f) 93 (((s) >> (fgshift)) & 0x0f)
94#define attr_bgcol(bgshift,s) \ 94#define attr_bgcol(bgshift,s) \
95 (((s) >> (bgshift)) & 0x0f) 95 (((s) >> (bgshift)) & 0x07)
96 96
97/* Monochrome */ 97/* Monochrome */
98#define attr_bold(s) \ 98#define attr_bold(s) \
@@ -146,10 +146,8 @@ static inline int attr_col_ec(int shift, struct vc_data *vc,
146 return is_fg ? fg : bg; 146 return is_fg ? fg : bg;
147} 147}
148 148
149#define attr_bgcol_ec(bgshift,vc,info) \ 149#define attr_bgcol_ec(bgshift, vc, info) attr_col_ec(bgshift, vc, info, 0)
150 attr_col_ec(bgshift,vc,info,0); 150#define attr_fgcol_ec(fgshift, vc, info) attr_col_ec(fgshift, vc, info, 1)
151#define attr_fgcol_ec(fgshift,vc,info) \
152 attr_col_ec(fgshift,vc,info,1);
153 151
154/* Font */ 152/* Font */
155#define REFCOUNT(fd) (((int *)(fd))[-1]) 153#define REFCOUNT(fd) (((int *)(fd))[-1])
diff --git a/drivers/video/console/mdacon.c b/drivers/video/console/mdacon.c
index 38a296bbdfc9..9901064199bd 100644
--- a/drivers/video/console/mdacon.c
+++ b/drivers/video/console/mdacon.c
@@ -71,13 +71,15 @@ static char *mda_type_name;
71 71
72/* console information */ 72/* console information */
73 73
74static int mda_first_vc = 1; 74static int mda_first_vc = 13;
75static int mda_last_vc = 16; 75static int mda_last_vc = 16;
76 76
77static struct vc_data *mda_display_fg = NULL; 77static struct vc_data *mda_display_fg = NULL;
78 78
79module_param(mda_first_vc, int, 0); 79module_param(mda_first_vc, int, 0);
80MODULE_PARM_DESC(mda_first_vc, "First virtual console. Default: 13");
80module_param(mda_last_vc, int, 0); 81module_param(mda_last_vc, int, 0);
82MODULE_PARM_DESC(mda_last_vc, "Last virtual console. Default: 16");
81 83
82/* MDA register values 84/* MDA register values
83 */ 85 */
diff --git a/drivers/video/console/sticon.c b/drivers/video/console/sticon.c
index a11cc2fdd4cd..4055dbdd1b42 100644
--- a/drivers/video/console/sticon.c
+++ b/drivers/video/console/sticon.c
@@ -370,7 +370,7 @@ static const struct consw sti_con = {
370 370
371 371
372 372
373int __init sticonsole_init(void) 373static int __init sticonsole_init(void)
374{ 374{
375 /* already initialized ? */ 375 /* already initialized ? */
376 if (sticon_sti) 376 if (sticon_sti)
diff --git a/drivers/video/console/sticore.c b/drivers/video/console/sticore.c
index e9ab657f0bb7..d7822af0e00a 100644
--- a/drivers/video/console/sticore.c
+++ b/drivers/video/console/sticore.c
@@ -29,7 +29,7 @@
29 29
30#define STI_DRIVERVERSION "Version 0.9a" 30#define STI_DRIVERVERSION "Version 0.9a"
31 31
32struct sti_struct *default_sti __read_mostly; 32static struct sti_struct *default_sti __read_mostly;
33 33
34/* number of STI ROMS found and their ptrs to each struct */ 34/* number of STI ROMS found and their ptrs to each struct */
35static int num_sti_roms __read_mostly; 35static int num_sti_roms __read_mostly;
@@ -68,8 +68,7 @@ static const struct sti_init_flags default_init_flags = {
68 .init_cmap_tx = 1, 68 .init_cmap_tx = 1,
69}; 69};
70 70
71int 71static int sti_init_graph(struct sti_struct *sti)
72sti_init_graph(struct sti_struct *sti)
73{ 72{
74 struct sti_init_inptr_ext inptr_ext = { 0, }; 73 struct sti_init_inptr_ext inptr_ext = { 0, };
75 struct sti_init_inptr inptr = { 74 struct sti_init_inptr inptr = {
@@ -100,8 +99,7 @@ static const struct sti_conf_flags default_conf_flags = {
100 .wait = STI_WAIT, 99 .wait = STI_WAIT,
101}; 100};
102 101
103void 102static void sti_inq_conf(struct sti_struct *sti)
104sti_inq_conf(struct sti_struct *sti)
105{ 103{
106 struct sti_conf_inptr inptr = { 0, }; 104 struct sti_conf_inptr inptr = { 0, };
107 unsigned long flags; 105 unsigned long flags;
@@ -237,8 +235,8 @@ static void sti_flush(unsigned long start, unsigned long end)
237 flush_icache_range(start, end); 235 flush_icache_range(start, end);
238} 236}
239 237
240void __devinit 238static void __devinit sti_rom_copy(unsigned long base, unsigned long count,
241sti_rom_copy(unsigned long base, unsigned long count, void *dest) 239 void *dest)
242{ 240{
243 unsigned long dest_start = (unsigned long) dest; 241 unsigned long dest_start = (unsigned long) dest;
244 242
@@ -478,8 +476,8 @@ sti_init_glob_cfg(struct sti_struct *sti,
478} 476}
479 477
480#ifdef CONFIG_FB 478#ifdef CONFIG_FB
481struct sti_cooked_font * __devinit 479static struct sti_cooked_font __devinit
482sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name) 480*sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
483{ 481{
484 const struct font_desc *fbfont; 482 const struct font_desc *fbfont;
485 unsigned int size, bpc; 483 unsigned int size, bpc;
@@ -534,16 +532,16 @@ sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
534 return cooked_font; 532 return cooked_font;
535} 533}
536#else 534#else
537struct sti_cooked_font * __devinit 535static struct sti_cooked_font __devinit
538sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name) 536*sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
539{ 537{
540 return NULL; 538 return NULL;
541} 539}
542#endif 540#endif
543 541
544struct sti_cooked_font * __devinit 542static struct sti_cooked_font __devinit
545sti_select_font(struct sti_cooked_rom *rom, 543*sti_select_font(struct sti_cooked_rom *rom,
546 int (*search_font_fnc) (struct sti_cooked_rom *,int,int) ) 544 int (*search_font_fnc)(struct sti_cooked_rom *, int, int))
547{ 545{
548 struct sti_cooked_font *font; 546 struct sti_cooked_font *font;
549 int i; 547 int i;
@@ -707,8 +705,7 @@ sti_get_bmode_rom (unsigned long address)
707 return raw; 705 return raw;
708} 706}
709 707
710struct sti_rom * __devinit 708static struct sti_rom __devinit *sti_get_wmode_rom(unsigned long address)
711sti_get_wmode_rom (unsigned long address)
712{ 709{
713 struct sti_rom *raw; 710 struct sti_rom *raw;
714 unsigned long size; 711 unsigned long size;
@@ -723,8 +720,8 @@ sti_get_wmode_rom (unsigned long address)
723 return raw; 720 return raw;
724} 721}
725 722
726int __devinit 723static int __devinit sti_read_rom(int wordmode, struct sti_struct *sti,
727sti_read_rom(int wordmode, struct sti_struct *sti, unsigned long address) 724 unsigned long address)
728{ 725{
729 struct sti_cooked_rom *cooked; 726 struct sti_cooked_rom *cooked;
730 struct sti_rom *raw = NULL; 727 struct sti_rom *raw = NULL;
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 1cd5071e5362..6b487801eeae 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -848,9 +848,8 @@ int
848fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var) 848fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
849{ 849{
850 struct fb_fix_screeninfo *fix = &info->fix; 850 struct fb_fix_screeninfo *fix = &info->fix;
851 int xoffset = var->xoffset; 851 unsigned int yres = info->var.yres;
852 int yoffset = var->yoffset; 852 int err = 0;
853 int err = 0, yres = info->var.yres;
854 853
855 if (var->yoffset > 0) { 854 if (var->yoffset > 0) {
856 if (var->vmode & FB_VMODE_YWRAP) { 855 if (var->vmode & FB_VMODE_YWRAP) {
@@ -866,8 +865,8 @@ fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
866 (var->xoffset % fix->xpanstep))) 865 (var->xoffset % fix->xpanstep)))
867 err = -EINVAL; 866 err = -EINVAL;
868 867
869 if (err || !info->fbops->fb_pan_display || xoffset < 0 || 868 if (err || !info->fbops->fb_pan_display ||
870 yoffset < 0 || var->yoffset + yres > info->var.yres_virtual || 869 var->yoffset + yres > info->var.yres_virtual ||
871 var->xoffset + info->var.xres > info->var.xres_virtual) 870 var->xoffset + info->var.xres > info->var.xres_virtual)
872 return -EINVAL; 871 return -EINVAL;
873 872
diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 052e18058498..6a0aa180c266 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -879,7 +879,7 @@ int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
879 if (edid_is_timing_block(block)) { 879 if (edid_is_timing_block(block)) {
880 var->xres = var->xres_virtual = H_ACTIVE; 880 var->xres = var->xres_virtual = H_ACTIVE;
881 var->yres = var->yres_virtual = V_ACTIVE; 881 var->yres = var->yres_virtual = V_ACTIVE;
882 var->height = var->width = -1; 882 var->height = var->width = 0;
883 var->right_margin = H_SYNC_OFFSET; 883 var->right_margin = H_SYNC_OFFSET;
884 var->left_margin = (H_ACTIVE + H_BLANKING) - 884 var->left_margin = (H_ACTIVE + H_BLANKING) -
885 (H_ACTIVE + H_SYNC_OFFSET + H_SYNC_WIDTH); 885 (H_ACTIVE + H_SYNC_OFFSET + H_SYNC_WIDTH);
diff --git a/drivers/video/fsl-diu-fb.c b/drivers/video/fsl-diu-fb.c
index 09d7e22c6fef..9cd36c223d33 100644
--- a/drivers/video/fsl-diu-fb.c
+++ b/drivers/video/fsl-diu-fb.c
@@ -279,58 +279,42 @@ static struct diu_hw dr = {
279 279
280static struct diu_pool pool; 280static struct diu_pool pool;
281 281
282/* To allocate memory for framebuffer. First try __get_free_pages(). If it 282/**
283 * fails, try rh_alloc. The reason is __get_free_pages() cannot allocate 283 * fsl_diu_alloc - allocate memory for the DIU
284 * very large memory (more than 4MB). We don't want to allocate all memory 284 * @size: number of bytes to allocate
285 * in rheap since small memory allocation/deallocation will fragment the 285 * @param: returned physical address of memory
286 * rheap and make the furture large allocation fail. 286 *
287 * This function allocates a physically-contiguous block of memory.
287 */ 288 */
288 289static void *fsl_diu_alloc(size_t size, phys_addr_t *phys)
289static void *fsl_diu_alloc(unsigned long size, phys_addr_t *phys)
290{ 290{
291 void *virt; 291 void *virt;
292 292
293 pr_debug("size=%lu\n", size); 293 pr_debug("size=%zu\n", size);
294 294
295 virt = (void *)__get_free_pages(GFP_DMA | __GFP_ZERO, get_order(size)); 295 virt = alloc_pages_exact(size, GFP_DMA | __GFP_ZERO);
296 if (virt) { 296 if (virt) {
297 *phys = virt_to_phys(virt); 297 *phys = virt_to_phys(virt);
298 pr_debug("virt %p, phys=%llx\n", virt, (uint64_t) *phys); 298 pr_debug("virt=%p phys=%llx\n", virt,
299 return virt; 299 (unsigned long long)*phys);
300 }
301 if (!diu_ops.diu_mem) {
302 printk(KERN_INFO "%s: no diu_mem."
303 " To reserve more memory, put 'diufb=15M' "
304 "in the command line\n", __func__);
305 return NULL;
306 }
307
308 virt = (void *)rh_alloc(&diu_ops.diu_rh_info, size, "DIU");
309 if (virt) {
310 *phys = virt_to_bus(virt);
311 memset(virt, 0, size);
312 } 300 }
313 301
314 pr_debug("rh virt=%p phys=%llx\n", virt, (unsigned long long)*phys);
315
316 return virt; 302 return virt;
317} 303}
318 304
319static void fsl_diu_free(void *p, unsigned long size) 305/**
306 * fsl_diu_free - release DIU memory
307 * @virt: pointer returned by fsl_diu_alloc()
308 * @size: number of bytes allocated by fsl_diu_alloc()
309 *
310 * This function releases memory allocated by fsl_diu_alloc().
311 */
312static void fsl_diu_free(void *virt, size_t size)
320{ 313{
321 pr_debug("p=%p size=%lu\n", p, size); 314 pr_debug("virt=%p size=%zu\n", virt, size);
322 315
323 if (!p) 316 if (virt && size)
324 return; 317 free_pages_exact(virt, size);
325
326 if ((p >= diu_ops.diu_mem) &&
327 (p < (diu_ops.diu_mem + diu_ops.diu_size))) {
328 pr_debug("rh\n");
329 rh_free(&diu_ops.diu_rh_info, (unsigned long) p);
330 } else {
331 pr_debug("dma\n");
332 free_pages((unsigned long)p, get_order(size));
333 }
334} 318}
335 319
336static int fsl_diu_enable_panel(struct fb_info *info) 320static int fsl_diu_enable_panel(struct fb_info *info)
diff --git a/drivers/video/geode/lxfb.h b/drivers/video/geode/lxfb.h
index 3b9416f4ee20..6a51448fd3f7 100644
--- a/drivers/video/geode/lxfb.h
+++ b/drivers/video/geode/lxfb.h
@@ -51,8 +51,6 @@ static inline unsigned int lx_get_pitch(unsigned int xres, int bpp)
51} 51}
52 52
53void lx_set_mode(struct fb_info *); 53void lx_set_mode(struct fb_info *);
54void lx_get_gamma(struct fb_info *, unsigned int *, int);
55void lx_set_gamma(struct fb_info *, unsigned int *, int);
56unsigned int lx_framebuffer_size(void); 54unsigned int lx_framebuffer_size(void);
57int lx_blank_display(struct fb_info *, int); 55int lx_blank_display(struct fb_info *, int);
58void lx_set_palette_reg(struct fb_info *, unsigned int, unsigned int, 56void lx_set_palette_reg(struct fb_info *, unsigned int, unsigned int,
diff --git a/drivers/video/geode/lxfb_ops.c b/drivers/video/geode/lxfb_ops.c
index aaef9165ec9b..b1cd49c99356 100644
--- a/drivers/video/geode/lxfb_ops.c
+++ b/drivers/video/geode/lxfb_ops.c
@@ -517,25 +517,25 @@ void lx_set_palette_reg(struct fb_info *info, unsigned regno,
517int lx_blank_display(struct fb_info *info, int blank_mode) 517int lx_blank_display(struct fb_info *info, int blank_mode)
518{ 518{
519 struct lxfb_par *par = info->par; 519 struct lxfb_par *par = info->par;
520 u32 dcfg, fp_pm; 520 u32 dcfg, misc, fp_pm;
521 int blank, hsync, vsync, crt; 521 int blank, hsync, vsync;
522 522
523 /* CRT power saving modes. */ 523 /* CRT power saving modes. */
524 switch (blank_mode) { 524 switch (blank_mode) {
525 case FB_BLANK_UNBLANK: 525 case FB_BLANK_UNBLANK:
526 blank = 0; hsync = 1; vsync = 1; crt = 1; 526 blank = 0; hsync = 1; vsync = 1;
527 break; 527 break;
528 case FB_BLANK_NORMAL: 528 case FB_BLANK_NORMAL:
529 blank = 1; hsync = 1; vsync = 1; crt = 1; 529 blank = 1; hsync = 1; vsync = 1;
530 break; 530 break;
531 case FB_BLANK_VSYNC_SUSPEND: 531 case FB_BLANK_VSYNC_SUSPEND:
532 blank = 1; hsync = 1; vsync = 0; crt = 1; 532 blank = 1; hsync = 1; vsync = 0;
533 break; 533 break;
534 case FB_BLANK_HSYNC_SUSPEND: 534 case FB_BLANK_HSYNC_SUSPEND:
535 blank = 1; hsync = 0; vsync = 1; crt = 1; 535 blank = 1; hsync = 0; vsync = 1;
536 break; 536 break;
537 case FB_BLANK_POWERDOWN: 537 case FB_BLANK_POWERDOWN:
538 blank = 1; hsync = 0; vsync = 0; crt = 0; 538 blank = 1; hsync = 0; vsync = 0;
539 break; 539 break;
540 default: 540 default:
541 return -EINVAL; 541 return -EINVAL;
@@ -545,15 +545,23 @@ int lx_blank_display(struct fb_info *info, int blank_mode)
545 dcfg &= ~(VP_DCFG_DAC_BL_EN | VP_DCFG_HSYNC_EN | VP_DCFG_VSYNC_EN | 545 dcfg &= ~(VP_DCFG_DAC_BL_EN | VP_DCFG_HSYNC_EN | VP_DCFG_VSYNC_EN |
546 VP_DCFG_CRT_EN); 546 VP_DCFG_CRT_EN);
547 if (!blank) 547 if (!blank)
548 dcfg |= VP_DCFG_DAC_BL_EN; 548 dcfg |= VP_DCFG_DAC_BL_EN | VP_DCFG_CRT_EN;
549 if (hsync) 549 if (hsync)
550 dcfg |= VP_DCFG_HSYNC_EN; 550 dcfg |= VP_DCFG_HSYNC_EN;
551 if (vsync) 551 if (vsync)
552 dcfg |= VP_DCFG_VSYNC_EN; 552 dcfg |= VP_DCFG_VSYNC_EN;
553 if (crt) 553
554 dcfg |= VP_DCFG_CRT_EN;
555 write_vp(par, VP_DCFG, dcfg); 554 write_vp(par, VP_DCFG, dcfg);
556 555
556 misc = read_vp(par, VP_MISC);
557
558 if (vsync && hsync)
559 misc &= ~VP_MISC_DACPWRDN;
560 else
561 misc |= VP_MISC_DACPWRDN;
562
563 write_vp(par, VP_MISC, misc);
564
557 /* Power on/off flat panel */ 565 /* Power on/off flat panel */
558 566
559 if (par->output & OUTPUT_PANEL) { 567 if (par->output & OUTPUT_PANEL) {
diff --git a/drivers/video/hgafb.c b/drivers/video/hgafb.c
index c18880d9db1f..0129c044f6d6 100644
--- a/drivers/video/hgafb.c
+++ b/drivers/video/hgafb.c
@@ -551,7 +551,7 @@ static struct fb_ops hgafb_ops = {
551 * Initialization 551 * Initialization
552 */ 552 */
553 553
554static int __init hgafb_probe(struct device *device) 554static int __init hgafb_probe(struct platform_device *pdev)
555{ 555{
556 struct fb_info *info; 556 struct fb_info *info;
557 557
@@ -565,7 +565,7 @@ static int __init hgafb_probe(struct device *device)
565 printk(KERN_INFO "hgafb: %s with %ldK of memory detected.\n", 565 printk(KERN_INFO "hgafb: %s with %ldK of memory detected.\n",
566 hga_type_name, hga_vram_len/1024); 566 hga_type_name, hga_vram_len/1024);
567 567
568 info = framebuffer_alloc(0, NULL); 568 info = framebuffer_alloc(0, &pdev->dev);
569 if (!info) { 569 if (!info) {
570 iounmap(hga_vram); 570 iounmap(hga_vram);
571 return -ENOMEM; 571 return -ENOMEM;
@@ -593,13 +593,13 @@ static int __init hgafb_probe(struct device *device)
593 593
594 printk(KERN_INFO "fb%d: %s frame buffer device\n", 594 printk(KERN_INFO "fb%d: %s frame buffer device\n",
595 info->node, info->fix.id); 595 info->node, info->fix.id);
596 dev_set_drvdata(device, info); 596 platform_set_drvdata(pdev, info);
597 return 0; 597 return 0;
598} 598}
599 599
600static int hgafb_remove(struct device *device) 600static int hgafb_remove(struct platform_device *pdev)
601{ 601{
602 struct fb_info *info = dev_get_drvdata(device); 602 struct fb_info *info = platform_get_drvdata(pdev);
603 603
604 hga_txt_mode(); 604 hga_txt_mode();
605 hga_clear_screen(); 605 hga_clear_screen();
@@ -620,16 +620,15 @@ static int hgafb_remove(struct device *device)
620 return 0; 620 return 0;
621} 621}
622 622
623static struct device_driver hgafb_driver = { 623static struct platform_driver hgafb_driver = {
624 .name = "hgafb",
625 .bus = &platform_bus_type,
626 .probe = hgafb_probe, 624 .probe = hgafb_probe,
627 .remove = hgafb_remove, 625 .remove = hgafb_remove,
626 .driver = {
627 .name = "hgafb",
628 },
628}; 629};
629 630
630static struct platform_device hgafb_device = { 631static struct platform_device *hgafb_device;
631 .name = "hgafb",
632};
633 632
634static int __init hgafb_init(void) 633static int __init hgafb_init(void)
635{ 634{
@@ -638,12 +637,15 @@ static int __init hgafb_init(void)
638 if (fb_get_options("hgafb", NULL)) 637 if (fb_get_options("hgafb", NULL))
639 return -ENODEV; 638 return -ENODEV;
640 639
641 ret = driver_register(&hgafb_driver); 640 ret = platform_driver_register(&hgafb_driver);
642 641
643 if (!ret) { 642 if (!ret) {
644 ret = platform_device_register(&hgafb_device); 643 hgafb_device = platform_device_register_simple("hgafb", 0, NULL, 0);
645 if (ret) 644
646 driver_unregister(&hgafb_driver); 645 if (IS_ERR(hgafb_device)) {
646 platform_driver_unregister(&hgafb_driver);
647 ret = PTR_ERR(hgafb_device);
648 }
647 } 649 }
648 650
649 return ret; 651 return ret;
@@ -651,8 +653,8 @@ static int __init hgafb_init(void)
651 653
652static void __exit hgafb_exit(void) 654static void __exit hgafb_exit(void)
653{ 655{
654 platform_device_unregister(&hgafb_device); 656 platform_device_unregister(hgafb_device);
655 driver_unregister(&hgafb_driver); 657 platform_driver_unregister(&hgafb_driver);
656} 658}
657 659
658/* ------------------------------------------------------------------------- 660/* -------------------------------------------------------------------------
diff --git a/drivers/video/imxfb.c b/drivers/video/imxfb.c
index 94e4d3ac1a05..0c5a475c1cae 100644
--- a/drivers/video/imxfb.c
+++ b/drivers/video/imxfb.c
@@ -24,6 +24,7 @@
24#include <linux/string.h> 24#include <linux/string.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/mm.h>
27#include <linux/fb.h> 28#include <linux/fb.h>
28#include <linux/delay.h> 29#include <linux/delay.h>
29#include <linux/init.h> 30#include <linux/init.h>
diff --git a/drivers/video/macfb.c b/drivers/video/macfb.c
index aa8c714d6245..b790ddff76f9 100644
--- a/drivers/video/macfb.c
+++ b/drivers/video/macfb.c
@@ -596,7 +596,7 @@ static struct fb_ops macfb_ops = {
596 .fb_imageblit = cfb_imageblit, 596 .fb_imageblit = cfb_imageblit,
597}; 597};
598 598
599void __init macfb_setup(char *options) 599static void __init macfb_setup(char *options)
600{ 600{
601 char *this_opt; 601 char *this_opt;
602 602
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c
index 5246b0402d76..25172b2a2a94 100644
--- a/drivers/video/neofb.c
+++ b/drivers/video/neofb.c
@@ -201,7 +201,6 @@ static int neoFindMode(int xres, int yres, int depth)
201 * 201 *
202 * Determine the closest clock frequency to the one requested. 202 * Determine the closest clock frequency to the one requested.
203 */ 203 */
204#define REF_FREQ 0xe517 /* 14.31818 in 20.12 fixed point */
205#define MAX_N 127 204#define MAX_N 127
206#define MAX_D 31 205#define MAX_D 31
207#define MAX_F 1 206#define MAX_F 1
@@ -211,27 +210,24 @@ static void neoCalcVCLK(const struct fb_info *info,
211{ 210{
212 int n, d, f; 211 int n, d, f;
213 int n_best = 0, d_best = 0, f_best = 0; 212 int n_best = 0, d_best = 0, f_best = 0;
214 long f_best_diff = (0x7ffff << 12); /* 20.12 */ 213 long f_best_diff = 0x7ffff;
215 long f_target = (freq << 12) / 1000; /* 20.12 */
216 214
217 for (f = 0; f <= MAX_F; f++) 215 for (f = 0; f <= MAX_F; f++)
218 for (n = 0; n <= MAX_N; n++) 216 for (d = 0; d <= MAX_D; d++)
219 for (d = 0; d <= MAX_D; d++) { 217 for (n = 0; n <= MAX_N; n++) {
220 long f_out; /* 20.12 */ 218 long f_out;
221 long f_diff; /* 20.12 */ 219 long f_diff;
222 220
223 f_out = 221 f_out = ((14318 * (n + 1)) / (d + 1)) >> f;
224 ((((n + 1) << 12) / ((d + 222 f_diff = abs(f_out - freq);
225 1) * 223 if (f_diff <= f_best_diff) {
226 (1 << f))) >> 12)
227 * REF_FREQ;
228 f_diff = abs(f_out - f_target);
229 if (f_diff < f_best_diff) {
230 f_best_diff = f_diff; 224 f_best_diff = f_diff;
231 n_best = n; 225 n_best = n;
232 d_best = d; 226 d_best = d;
233 f_best = f; 227 f_best = f;
234 } 228 }
229 if (f_out > freq)
230 break;
235 } 231 }
236 232
237 if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 || 233 if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
@@ -248,11 +244,11 @@ static void neoCalcVCLK(const struct fb_info *info,
248 par->VCLK3Denominator = d_best; 244 par->VCLK3Denominator = d_best;
249 245
250#ifdef NEOFB_DEBUG 246#ifdef NEOFB_DEBUG
251 printk("neoVCLK: f:%d NumLow=%d NumHi=%d Den=%d Df=%d\n", 247 printk(KERN_DEBUG "neoVCLK: f:%ld NumLow=%d NumHi=%d Den=%d Df=%ld\n",
252 f_target >> 12, 248 freq,
253 par->VCLK3NumeratorLow, 249 par->VCLK3NumeratorLow,
254 par->VCLK3NumeratorHigh, 250 par->VCLK3NumeratorHigh,
255 par->VCLK3Denominator, f_best_diff >> 12); 251 par->VCLK3Denominator, f_best_diff);
256#endif 252#endif
257} 253}
258 254
@@ -263,15 +259,20 @@ static void neoCalcVCLK(const struct fb_info *info,
263 */ 259 */
264 260
265static int vgaHWInit(const struct fb_var_screeninfo *var, 261static int vgaHWInit(const struct fb_var_screeninfo *var,
266 const struct fb_info *info, 262 struct neofb_par *par)
267 struct neofb_par *par, struct xtimings *timings)
268{ 263{
264 int hsync_end = var->xres + var->right_margin + var->hsync_len;
265 int htotal = (hsync_end + var->left_margin) >> 3;
266 int vsync_start = var->yres + var->lower_margin;
267 int vsync_end = vsync_start + var->vsync_len;
268 int vtotal = vsync_end + var->upper_margin;
269
269 par->MiscOutReg = 0x23; 270 par->MiscOutReg = 0x23;
270 271
271 if (!(timings->sync & FB_SYNC_HOR_HIGH_ACT)) 272 if (!(var->sync & FB_SYNC_HOR_HIGH_ACT))
272 par->MiscOutReg |= 0x40; 273 par->MiscOutReg |= 0x40;
273 274
274 if (!(timings->sync & FB_SYNC_VERT_HIGH_ACT)) 275 if (!(var->sync & FB_SYNC_VERT_HIGH_ACT))
275 par->MiscOutReg |= 0x80; 276 par->MiscOutReg |= 0x80;
276 277
277 /* 278 /*
@@ -286,25 +287,25 @@ static int vgaHWInit(const struct fb_var_screeninfo *var,
286 /* 287 /*
287 * CRTC Controller 288 * CRTC Controller
288 */ 289 */
289 par->CRTC[0] = (timings->HTotal >> 3) - 5; 290 par->CRTC[0] = htotal - 5;
290 par->CRTC[1] = (timings->HDisplay >> 3) - 1; 291 par->CRTC[1] = (var->xres >> 3) - 1;
291 par->CRTC[2] = (timings->HDisplay >> 3) - 1; 292 par->CRTC[2] = (var->xres >> 3) - 1;
292 par->CRTC[3] = (((timings->HTotal >> 3) - 1) & 0x1F) | 0x80; 293 par->CRTC[3] = ((htotal - 1) & 0x1F) | 0x80;
293 par->CRTC[4] = (timings->HSyncStart >> 3); 294 par->CRTC[4] = ((var->xres + var->right_margin) >> 3);
294 par->CRTC[5] = ((((timings->HTotal >> 3) - 1) & 0x20) << 2) 295 par->CRTC[5] = (((htotal - 1) & 0x20) << 2)
295 | (((timings->HSyncEnd >> 3)) & 0x1F); 296 | (((hsync_end >> 3)) & 0x1F);
296 par->CRTC[6] = (timings->VTotal - 2) & 0xFF; 297 par->CRTC[6] = (vtotal - 2) & 0xFF;
297 par->CRTC[7] = (((timings->VTotal - 2) & 0x100) >> 8) 298 par->CRTC[7] = (((vtotal - 2) & 0x100) >> 8)
298 | (((timings->VDisplay - 1) & 0x100) >> 7) 299 | (((var->yres - 1) & 0x100) >> 7)
299 | ((timings->VSyncStart & 0x100) >> 6) 300 | ((vsync_start & 0x100) >> 6)
300 | (((timings->VDisplay - 1) & 0x100) >> 5) 301 | (((var->yres - 1) & 0x100) >> 5)
301 | 0x10 | (((timings->VTotal - 2) & 0x200) >> 4) 302 | 0x10 | (((vtotal - 2) & 0x200) >> 4)
302 | (((timings->VDisplay - 1) & 0x200) >> 3) 303 | (((var->yres - 1) & 0x200) >> 3)
303 | ((timings->VSyncStart & 0x200) >> 2); 304 | ((vsync_start & 0x200) >> 2);
304 par->CRTC[8] = 0x00; 305 par->CRTC[8] = 0x00;
305 par->CRTC[9] = (((timings->VDisplay - 1) & 0x200) >> 4) | 0x40; 306 par->CRTC[9] = (((var->yres - 1) & 0x200) >> 4) | 0x40;
306 307
307 if (timings->dblscan) 308 if (var->vmode & FB_VMODE_DOUBLE)
308 par->CRTC[9] |= 0x80; 309 par->CRTC[9] |= 0x80;
309 310
310 par->CRTC[10] = 0x00; 311 par->CRTC[10] = 0x00;
@@ -313,13 +314,13 @@ static int vgaHWInit(const struct fb_var_screeninfo *var,
313 par->CRTC[13] = 0x00; 314 par->CRTC[13] = 0x00;
314 par->CRTC[14] = 0x00; 315 par->CRTC[14] = 0x00;
315 par->CRTC[15] = 0x00; 316 par->CRTC[15] = 0x00;
316 par->CRTC[16] = timings->VSyncStart & 0xFF; 317 par->CRTC[16] = vsync_start & 0xFF;
317 par->CRTC[17] = (timings->VSyncEnd & 0x0F) | 0x20; 318 par->CRTC[17] = (vsync_end & 0x0F) | 0x20;
318 par->CRTC[18] = (timings->VDisplay - 1) & 0xFF; 319 par->CRTC[18] = (var->yres - 1) & 0xFF;
319 par->CRTC[19] = var->xres_virtual >> 4; 320 par->CRTC[19] = var->xres_virtual >> 4;
320 par->CRTC[20] = 0x00; 321 par->CRTC[20] = 0x00;
321 par->CRTC[21] = (timings->VDisplay - 1) & 0xFF; 322 par->CRTC[21] = (var->yres - 1) & 0xFF;
322 par->CRTC[22] = (timings->VTotal - 1) & 0xFF; 323 par->CRTC[22] = (vtotal - 1) & 0xFF;
323 par->CRTC[23] = 0xC3; 324 par->CRTC[23] = 0xC3;
324 par->CRTC[24] = 0xFF; 325 par->CRTC[24] = 0xFF;
325 326
@@ -483,7 +484,8 @@ static inline int neo2200_sync(struct fb_info *info)
483{ 484{
484 struct neofb_par *par = info->par; 485 struct neofb_par *par = info->par;
485 486
486 while (readl(&par->neo2200->bltStat) & 1); 487 while (readl(&par->neo2200->bltStat) & 1)
488 cpu_relax();
487 return 0; 489 return 0;
488} 490}
489 491
@@ -591,34 +593,14 @@ static int
591neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 593neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
592{ 594{
593 struct neofb_par *par = info->par; 595 struct neofb_par *par = info->par;
594 unsigned int pixclock = var->pixclock;
595 struct xtimings timings;
596 int memlen, vramlen; 596 int memlen, vramlen;
597 int mode_ok = 0; 597 int mode_ok = 0;
598 598
599 DBG("neofb_check_var"); 599 DBG("neofb_check_var");
600 600
601 if (!pixclock) 601 if (PICOS2KHZ(var->pixclock) > par->maxClock)
602 pixclock = 10000; /* 10ns = 100MHz */
603 timings.pixclock = 1000000000 / pixclock;
604 if (timings.pixclock < 1)
605 timings.pixclock = 1;
606
607 if (timings.pixclock > par->maxClock)
608 return -EINVAL; 602 return -EINVAL;
609 603
610 timings.dblscan = var->vmode & FB_VMODE_DOUBLE;
611 timings.interlaced = var->vmode & FB_VMODE_INTERLACED;
612 timings.HDisplay = var->xres;
613 timings.HSyncStart = timings.HDisplay + var->right_margin;
614 timings.HSyncEnd = timings.HSyncStart + var->hsync_len;
615 timings.HTotal = timings.HSyncEnd + var->left_margin;
616 timings.VDisplay = var->yres;
617 timings.VSyncStart = timings.VDisplay + var->lower_margin;
618 timings.VSyncEnd = timings.VSyncStart + var->vsync_len;
619 timings.VTotal = timings.VSyncEnd + var->upper_margin;
620 timings.sync = var->sync;
621
622 /* Is the mode larger than the LCD panel? */ 604 /* Is the mode larger than the LCD panel? */
623 if (par->internal_display && 605 if (par->internal_display &&
624 ((var->xres > par->NeoPanelWidth) || 606 ((var->xres > par->NeoPanelWidth) ||
@@ -759,11 +741,11 @@ neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
759static int neofb_set_par(struct fb_info *info) 741static int neofb_set_par(struct fb_info *info)
760{ 742{
761 struct neofb_par *par = info->par; 743 struct neofb_par *par = info->par;
762 struct xtimings timings;
763 unsigned char temp; 744 unsigned char temp;
764 int i, clock_hi = 0; 745 int i, clock_hi = 0;
765 int lcd_stretch; 746 int lcd_stretch;
766 int hoffset, voffset; 747 int hoffset, voffset;
748 int vsync_start, vtotal;
767 749
768 DBG("neofb_set_par"); 750 DBG("neofb_set_par");
769 751
@@ -771,28 +753,15 @@ static int neofb_set_par(struct fb_info *info)
771 753
772 vgaHWProtect(1); /* Blank the screen */ 754 vgaHWProtect(1); /* Blank the screen */
773 755
774 timings.dblscan = info->var.vmode & FB_VMODE_DOUBLE; 756 vsync_start = info->var.yres + info->var.lower_margin;
775 timings.interlaced = info->var.vmode & FB_VMODE_INTERLACED; 757 vtotal = vsync_start + info->var.vsync_len + info->var.upper_margin;
776 timings.HDisplay = info->var.xres;
777 timings.HSyncStart = timings.HDisplay + info->var.right_margin;
778 timings.HSyncEnd = timings.HSyncStart + info->var.hsync_len;
779 timings.HTotal = timings.HSyncEnd + info->var.left_margin;
780 timings.VDisplay = info->var.yres;
781 timings.VSyncStart = timings.VDisplay + info->var.lower_margin;
782 timings.VSyncEnd = timings.VSyncStart + info->var.vsync_len;
783 timings.VTotal = timings.VSyncEnd + info->var.upper_margin;
784 timings.sync = info->var.sync;
785 timings.pixclock = PICOS2KHZ(info->var.pixclock);
786
787 if (timings.pixclock < 1)
788 timings.pixclock = 1;
789 758
790 /* 759 /*
791 * This will allocate the datastructure and initialize all of the 760 * This will allocate the datastructure and initialize all of the
792 * generic VGA registers. 761 * generic VGA registers.
793 */ 762 */
794 763
795 if (vgaHWInit(&info->var, info, par, &timings)) 764 if (vgaHWInit(&info->var, par))
796 return -EINVAL; 765 return -EINVAL;
797 766
798 /* 767 /*
@@ -831,10 +800,10 @@ static int neofb_set_par(struct fb_info *info)
831 par->ExtCRTDispAddr = 0x10; 800 par->ExtCRTDispAddr = 0x10;
832 801
833 /* Vertical Extension */ 802 /* Vertical Extension */
834 par->VerticalExt = (((timings.VTotal - 2) & 0x400) >> 10) 803 par->VerticalExt = (((vtotal - 2) & 0x400) >> 10)
835 | (((timings.VDisplay - 1) & 0x400) >> 9) 804 | (((info->var.yres - 1) & 0x400) >> 9)
836 | (((timings.VSyncStart) & 0x400) >> 8) 805 | (((vsync_start) & 0x400) >> 8)
837 | (((timings.VSyncStart) & 0x400) >> 7); 806 | (((vsync_start) & 0x400) >> 7);
838 807
839 /* Fast write bursts on unless disabled. */ 808 /* Fast write bursts on unless disabled. */
840 if (par->pci_burst) 809 if (par->pci_burst)
@@ -995,7 +964,7 @@ static int neofb_set_par(struct fb_info *info)
995 * Calculate the VCLK that most closely matches the requested dot 964 * Calculate the VCLK that most closely matches the requested dot
996 * clock. 965 * clock.
997 */ 966 */
998 neoCalcVCLK(info, par, timings.pixclock); 967 neoCalcVCLK(info, par, PICOS2KHZ(info->var.pixclock));
999 968
1000 /* Since we program the clocks ourselves, always use VCLK3. */ 969 /* Since we program the clocks ourselves, always use VCLK3. */
1001 par->MiscOutReg |= 0x0C; 970 par->MiscOutReg |= 0x0C;
@@ -1927,9 +1896,6 @@ static int __devinit neo_init_hw(struct fb_info *info)
1927 int maxClock = 65000; 1896 int maxClock = 65000;
1928 int CursorMem = 1024; 1897 int CursorMem = 1024;
1929 int CursorOff = 0x100; 1898 int CursorOff = 0x100;
1930 int linearSize = 1024;
1931 int maxWidth = 1024;
1932 int maxHeight = 1024;
1933 1899
1934 DBG("neo_init_hw"); 1900 DBG("neo_init_hw");
1935 1901
@@ -1948,81 +1914,52 @@ static int __devinit neo_init_hw(struct fb_info *info)
1948 case FB_ACCEL_NEOMAGIC_NM2070: 1914 case FB_ACCEL_NEOMAGIC_NM2070:
1949 videoRam = 896; 1915 videoRam = 896;
1950 maxClock = 65000; 1916 maxClock = 65000;
1951 CursorMem = 2048;
1952 CursorOff = 0x100;
1953 linearSize = 1024;
1954 maxWidth = 1024;
1955 maxHeight = 1024;
1956 break; 1917 break;
1957 case FB_ACCEL_NEOMAGIC_NM2090: 1918 case FB_ACCEL_NEOMAGIC_NM2090:
1958 case FB_ACCEL_NEOMAGIC_NM2093: 1919 case FB_ACCEL_NEOMAGIC_NM2093:
1959 videoRam = 1152;
1960 maxClock = 80000;
1961 CursorMem = 2048;
1962 CursorOff = 0x100;
1963 linearSize = 2048;
1964 maxWidth = 1024;
1965 maxHeight = 1024;
1966 break;
1967 case FB_ACCEL_NEOMAGIC_NM2097: 1920 case FB_ACCEL_NEOMAGIC_NM2097:
1968 videoRam = 1152; 1921 videoRam = 1152;
1969 maxClock = 80000; 1922 maxClock = 80000;
1970 CursorMem = 1024;
1971 CursorOff = 0x100;
1972 linearSize = 2048;
1973 maxWidth = 1024;
1974 maxHeight = 1024;
1975 break; 1923 break;
1976 case FB_ACCEL_NEOMAGIC_NM2160: 1924 case FB_ACCEL_NEOMAGIC_NM2160:
1977 videoRam = 2048; 1925 videoRam = 2048;
1978 maxClock = 90000; 1926 maxClock = 90000;
1979 CursorMem = 1024;
1980 CursorOff = 0x100;
1981 linearSize = 2048;
1982 maxWidth = 1024;
1983 maxHeight = 1024;
1984 break; 1927 break;
1985 case FB_ACCEL_NEOMAGIC_NM2200: 1928 case FB_ACCEL_NEOMAGIC_NM2200:
1986 videoRam = 2560; 1929 videoRam = 2560;
1987 maxClock = 110000; 1930 maxClock = 110000;
1988 CursorMem = 1024;
1989 CursorOff = 0x1000;
1990 linearSize = 4096;
1991 maxWidth = 1280;
1992 maxHeight = 1024; /* ???? */
1993
1994 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
1995 break; 1931 break;
1996 case FB_ACCEL_NEOMAGIC_NM2230: 1932 case FB_ACCEL_NEOMAGIC_NM2230:
1997 videoRam = 3008; 1933 videoRam = 3008;
1998 maxClock = 110000; 1934 maxClock = 110000;
1999 CursorMem = 1024;
2000 CursorOff = 0x1000;
2001 linearSize = 4096;
2002 maxWidth = 1280;
2003 maxHeight = 1024; /* ???? */
2004
2005 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
2006 break; 1935 break;
2007 case FB_ACCEL_NEOMAGIC_NM2360: 1936 case FB_ACCEL_NEOMAGIC_NM2360:
2008 videoRam = 4096; 1937 videoRam = 4096;
2009 maxClock = 110000; 1938 maxClock = 110000;
2010 CursorMem = 1024;
2011 CursorOff = 0x1000;
2012 linearSize = 4096;
2013 maxWidth = 1280;
2014 maxHeight = 1024; /* ???? */
2015
2016 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
2017 break; 1939 break;
2018 case FB_ACCEL_NEOMAGIC_NM2380: 1940 case FB_ACCEL_NEOMAGIC_NM2380:
2019 videoRam = 6144; 1941 videoRam = 6144;
2020 maxClock = 110000; 1942 maxClock = 110000;
1943 break;
1944 }
1945 switch (info->fix.accel) {
1946 case FB_ACCEL_NEOMAGIC_NM2070:
1947 case FB_ACCEL_NEOMAGIC_NM2090:
1948 case FB_ACCEL_NEOMAGIC_NM2093:
1949 CursorMem = 2048;
1950 CursorOff = 0x100;
1951 break;
1952 case FB_ACCEL_NEOMAGIC_NM2097:
1953 case FB_ACCEL_NEOMAGIC_NM2160:
1954 CursorMem = 1024;
1955 CursorOff = 0x100;
1956 break;
1957 case FB_ACCEL_NEOMAGIC_NM2200:
1958 case FB_ACCEL_NEOMAGIC_NM2230:
1959 case FB_ACCEL_NEOMAGIC_NM2360:
1960 case FB_ACCEL_NEOMAGIC_NM2380:
2021 CursorMem = 1024; 1961 CursorMem = 1024;
2022 CursorOff = 0x1000; 1962 CursorOff = 0x1000;
2023 linearSize = 8192;
2024 maxWidth = 1280;
2025 maxHeight = 1024; /* ???? */
2026 1963
2027 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase; 1964 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
2028 break; 1965 break;
@@ -2036,7 +1973,7 @@ static int __devinit neo_init_hw(struct fb_info *info)
2036*/ 1973*/
2037 par->maxClock = maxClock; 1974 par->maxClock = maxClock;
2038 par->cursorOff = CursorOff; 1975 par->cursorOff = CursorOff;
2039 return ((videoRam * 1024)); 1976 return videoRam * 1024;
2040} 1977}
2041 1978
2042 1979
diff --git a/drivers/video/omap/dispc.c b/drivers/video/omap/dispc.c
index ab32ceb06178..ab77c51fe9d6 100644
--- a/drivers/video/omap/dispc.c
+++ b/drivers/video/omap/dispc.c
@@ -20,6 +20,7 @@
20 */ 20 */
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/dma-mapping.h> 22#include <linux/dma-mapping.h>
23#include <linux/mm.h>
23#include <linux/vmalloc.h> 24#include <linux/vmalloc.h>
24#include <linux/clk.h> 25#include <linux/clk.h>
25#include <linux/io.h> 26#include <linux/io.h>
diff --git a/drivers/video/omap/omapfb_main.c b/drivers/video/omap/omapfb_main.c
index 14d0f7a11145..f85af5c4fa68 100644
--- a/drivers/video/omap/omapfb_main.c
+++ b/drivers/video/omap/omapfb_main.c
@@ -25,6 +25,7 @@
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 */ 26 */
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/mm.h>
28#include <linux/uaccess.h> 29#include <linux/uaccess.h>
29 30
30#include <asm/mach-types.h> 31#include <asm/mach-types.h>
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c
index d0746261c957..2b707a8ce5de 100644
--- a/drivers/video/pxafb.c
+++ b/drivers/video/pxafb.c
@@ -30,6 +30,7 @@
30#include <linux/string.h> 30#include <linux/string.h>
31#include <linux/interrupt.h> 31#include <linux/interrupt.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/mm.h>
33#include <linux/fb.h> 34#include <linux/fb.h>
34#include <linux/delay.h> 35#include <linux/delay.h>
35#include <linux/init.h> 36#include <linux/init.h>
@@ -40,6 +41,7 @@
40#include <linux/clk.h> 41#include <linux/clk.h>
41#include <linux/err.h> 42#include <linux/err.h>
42#include <linux/completion.h> 43#include <linux/completion.h>
44#include <linux/mutex.h>
43#include <linux/kthread.h> 45#include <linux/kthread.h>
44#include <linux/freezer.h> 46#include <linux/freezer.h>
45 47
@@ -227,6 +229,22 @@ static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var)
227 case 4: ret = LCCR3_4BPP; break; 229 case 4: ret = LCCR3_4BPP; break;
228 case 8: ret = LCCR3_8BPP; break; 230 case 8: ret = LCCR3_8BPP; break;
229 case 16: ret = LCCR3_16BPP; break; 231 case 16: ret = LCCR3_16BPP; break;
232 case 24:
233 switch (var->red.length + var->green.length +
234 var->blue.length + var->transp.length) {
235 case 18: ret = LCCR3_18BPP_P | LCCR3_PDFOR_3; break;
236 case 19: ret = LCCR3_19BPP_P; break;
237 }
238 break;
239 case 32:
240 switch (var->red.length + var->green.length +
241 var->blue.length + var->transp.length) {
242 case 18: ret = LCCR3_18BPP | LCCR3_PDFOR_3; break;
243 case 19: ret = LCCR3_19BPP; break;
244 case 24: ret = LCCR3_24BPP | LCCR3_PDFOR_3; break;
245 case 25: ret = LCCR3_25BPP; break;
246 }
247 break;
230 } 248 }
231 return ret; 249 return ret;
232} 250}
@@ -345,6 +363,41 @@ static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
345 var->green.offset = 5; var->green.length = 6; 363 var->green.offset = 5; var->green.length = 6;
346 var->blue.offset = 0; var->blue.length = 5; 364 var->blue.offset = 0; var->blue.length = 5;
347 var->transp.offset = var->transp.length = 0; 365 var->transp.offset = var->transp.length = 0;
366 } else if (var->bits_per_pixel > 16) {
367 struct pxafb_mode_info *mode;
368
369 mode = pxafb_getmode(inf, var);
370 if (!mode)
371 return -EINVAL;
372
373 switch (mode->depth) {
374 case 18: /* RGB666 */
375 var->transp.offset = var->transp.length = 0;
376 var->red.offset = 12; var->red.length = 6;
377 var->green.offset = 6; var->green.length = 6;
378 var->blue.offset = 0; var->blue.length = 6;
379 break;
380 case 19: /* RGBT666 */
381 var->transp.offset = 18; var->transp.length = 1;
382 var->red.offset = 12; var->red.length = 6;
383 var->green.offset = 6; var->green.length = 6;
384 var->blue.offset = 0; var->blue.length = 6;
385 break;
386 case 24: /* RGB888 */
387 var->transp.offset = var->transp.length = 0;
388 var->red.offset = 16; var->red.length = 8;
389 var->green.offset = 8; var->green.length = 8;
390 var->blue.offset = 0; var->blue.length = 8;
391 break;
392 case 25: /* RGBT888 */
393 var->transp.offset = 24; var->transp.length = 1;
394 var->red.offset = 16; var->red.length = 8;
395 var->green.offset = 8; var->green.length = 8;
396 var->blue.offset = 0; var->blue.length = 8;
397 break;
398 default:
399 return -EINVAL;
400 }
348 } else { 401 } else {
349 var->red.offset = var->green.offset = 0; 402 var->red.offset = var->green.offset = 0;
350 var->blue.offset = var->transp.offset = 0; 403 var->blue.offset = var->transp.offset = 0;
@@ -376,7 +429,7 @@ static int pxafb_set_par(struct fb_info *info)
376 struct pxafb_info *fbi = (struct pxafb_info *)info; 429 struct pxafb_info *fbi = (struct pxafb_info *)info;
377 struct fb_var_screeninfo *var = &info->var; 430 struct fb_var_screeninfo *var = &info->var;
378 431
379 if (var->bits_per_pixel == 16) 432 if (var->bits_per_pixel >= 16)
380 fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR; 433 fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
381 else if (!fbi->cmap_static) 434 else if (!fbi->cmap_static)
382 fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR; 435 fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
@@ -391,7 +444,7 @@ static int pxafb_set_par(struct fb_info *info)
391 444
392 fbi->fb.fix.line_length = var->xres_virtual * 445 fbi->fb.fix.line_length = var->xres_virtual *
393 var->bits_per_pixel / 8; 446 var->bits_per_pixel / 8;
394 if (var->bits_per_pixel == 16) 447 if (var->bits_per_pixel >= 16)
395 fbi->palette_size = 0; 448 fbi->palette_size = 0;
396 else 449 else
397 fbi->palette_size = var->bits_per_pixel == 1 ? 450 fbi->palette_size = var->bits_per_pixel == 1 ?
@@ -404,7 +457,7 @@ static int pxafb_set_par(struct fb_info *info)
404 */ 457 */
405 pxafb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR); 458 pxafb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
406 459
407 if (fbi->fb.var.bits_per_pixel == 16) 460 if (fbi->fb.var.bits_per_pixel >= 16)
408 fb_dealloc_cmap(&fbi->fb.cmap); 461 fb_dealloc_cmap(&fbi->fb.cmap);
409 else 462 else
410 fb_alloc_cmap(&fbi->fb.cmap, 1<<fbi->fb.var.bits_per_pixel, 0); 463 fb_alloc_cmap(&fbi->fb.cmap, 1<<fbi->fb.var.bits_per_pixel, 0);
@@ -831,6 +884,8 @@ static int pxafb_activate_var(struct fb_var_screeninfo *var,
831 case 4: 884 case 4:
832 case 8: 885 case 8:
833 case 16: 886 case 16:
887 case 24:
888 case 32:
834 break; 889 break;
835 default: 890 default:
836 printk(KERN_ERR "%s: invalid bit depth %d\n", 891 printk(KERN_ERR "%s: invalid bit depth %d\n",
@@ -968,6 +1023,11 @@ static void pxafb_setup_gpio(struct pxafb_info *fbi)
968 1023
969 for (gpio = 58; ldd_bits; gpio++, ldd_bits--) 1024 for (gpio = 58; ldd_bits; gpio++, ldd_bits--)
970 pxa_gpio_mode(gpio | GPIO_ALT_FN_2_OUT); 1025 pxa_gpio_mode(gpio | GPIO_ALT_FN_2_OUT);
1026 /* 18 bit interface */
1027 if (fbi->fb.var.bits_per_pixel > 16) {
1028 pxa_gpio_mode(86 | GPIO_ALT_FN_2_OUT);
1029 pxa_gpio_mode(87 | GPIO_ALT_FN_2_OUT);
1030 }
971 pxa_gpio_mode(GPIO74_LCD_FCLK_MD); 1031 pxa_gpio_mode(GPIO74_LCD_FCLK_MD);
972 pxa_gpio_mode(GPIO75_LCD_LCLK_MD); 1032 pxa_gpio_mode(GPIO75_LCD_LCLK_MD);
973 pxa_gpio_mode(GPIO76_LCD_PCLK_MD); 1033 pxa_gpio_mode(GPIO76_LCD_PCLK_MD);
@@ -1058,7 +1118,7 @@ static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
1058{ 1118{
1059 u_int old_state; 1119 u_int old_state;
1060 1120
1061 down(&fbi->ctrlr_sem); 1121 mutex_lock(&fbi->ctrlr_lock);
1062 1122
1063 old_state = fbi->state; 1123 old_state = fbi->state;
1064 1124
@@ -1146,7 +1206,7 @@ static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
1146 } 1206 }
1147 break; 1207 break;
1148 } 1208 }
1149 up(&fbi->ctrlr_sem); 1209 mutex_unlock(&fbi->ctrlr_lock);
1150} 1210}
1151 1211
1152/* 1212/*
@@ -1399,7 +1459,7 @@ static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev)
1399 1459
1400 init_waitqueue_head(&fbi->ctrlr_wait); 1460 init_waitqueue_head(&fbi->ctrlr_wait);
1401 INIT_WORK(&fbi->task, pxafb_task); 1461 INIT_WORK(&fbi->task, pxafb_task);
1402 init_MUTEX(&fbi->ctrlr_sem); 1462 mutex_init(&fbi->ctrlr_lock);
1403 init_completion(&fbi->disable_done); 1463 init_completion(&fbi->disable_done);
1404#ifdef CONFIG_FB_PXA_SMARTPANEL 1464#ifdef CONFIG_FB_PXA_SMARTPANEL
1405 init_completion(&fbi->command_done); 1465 init_completion(&fbi->command_done);
diff --git a/drivers/video/pxafb.h b/drivers/video/pxafb.h
index 8238dc826429..31541b86f13d 100644
--- a/drivers/video/pxafb.h
+++ b/drivers/video/pxafb.h
@@ -106,7 +106,7 @@ struct pxafb_info {
106 106
107 volatile u_char state; 107 volatile u_char state;
108 volatile u_char task_state; 108 volatile u_char task_state;
109 struct semaphore ctrlr_sem; 109 struct mutex ctrlr_lock;
110 wait_queue_head_t ctrlr_wait; 110 wait_queue_head_t ctrlr_wait;
111 struct work_struct task; 111 struct work_struct task;
112 112
diff --git a/drivers/video/sa1100fb.c b/drivers/video/sa1100fb.c
index ab2b2110478b..78bcdbc3f484 100644
--- a/drivers/video/sa1100fb.c
+++ b/drivers/video/sa1100fb.c
@@ -167,6 +167,7 @@
167#include <linux/string.h> 167#include <linux/string.h>
168#include <linux/interrupt.h> 168#include <linux/interrupt.h>
169#include <linux/slab.h> 169#include <linux/slab.h>
170#include <linux/mm.h>
170#include <linux/fb.h> 171#include <linux/fb.h>
171#include <linux/delay.h> 172#include <linux/delay.h>
172#include <linux/init.h> 173#include <linux/init.h>
@@ -174,6 +175,7 @@
174#include <linux/cpufreq.h> 175#include <linux/cpufreq.h>
175#include <linux/platform_device.h> 176#include <linux/platform_device.h>
176#include <linux/dma-mapping.h> 177#include <linux/dma-mapping.h>
178#include <linux/mutex.h>
177 179
178#include <asm/hardware.h> 180#include <asm/hardware.h>
179#include <asm/io.h> 181#include <asm/io.h>
@@ -1107,7 +1109,7 @@ static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state)
1107{ 1109{
1108 u_int old_state; 1110 u_int old_state;
1109 1111
1110 down(&fbi->ctrlr_sem); 1112 mutex_lock(&fbi->ctrlr_lock);
1111 1113
1112 old_state = fbi->state; 1114 old_state = fbi->state;
1113 1115
@@ -1192,7 +1194,7 @@ static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state)
1192 } 1194 }
1193 break; 1195 break;
1194 } 1196 }
1195 up(&fbi->ctrlr_sem); 1197 mutex_unlock(&fbi->ctrlr_lock);
1196} 1198}
1197 1199
1198/* 1200/*
@@ -1444,7 +1446,7 @@ static struct sa1100fb_info * __init sa1100fb_init_fbinfo(struct device *dev)
1444 1446
1445 init_waitqueue_head(&fbi->ctrlr_wait); 1447 init_waitqueue_head(&fbi->ctrlr_wait);
1446 INIT_WORK(&fbi->task, sa1100fb_task); 1448 INIT_WORK(&fbi->task, sa1100fb_task);
1447 init_MUTEX(&fbi->ctrlr_sem); 1449 mutex_init(&fbi->ctrlr_lock);
1448 1450
1449 return fbi; 1451 return fbi;
1450} 1452}
diff --git a/drivers/video/sa1100fb.h b/drivers/video/sa1100fb.h
index f465b27ed860..86831db9a042 100644
--- a/drivers/video/sa1100fb.h
+++ b/drivers/video/sa1100fb.h
@@ -100,7 +100,7 @@ struct sa1100fb_info {
100 100
101 volatile u_char state; 101 volatile u_char state;
102 volatile u_char task_state; 102 volatile u_char task_state;
103 struct semaphore ctrlr_sem; 103 struct mutex ctrlr_lock;
104 wait_queue_head_t ctrlr_wait; 104 wait_queue_head_t ctrlr_wait;
105 struct work_struct task; 105 struct work_struct task;
106 106
diff --git a/drivers/video/sh7760fb.c b/drivers/video/sh7760fb.c
new file mode 100644
index 000000000000..4d0e28c5790b
--- /dev/null
+++ b/drivers/video/sh7760fb.c
@@ -0,0 +1,658 @@
1/*
2 * SH7760/SH7763 LCDC Framebuffer driver.
3 *
4 * (c) 2006-2008 MSC Vertriebsges.m.b.H.,
5 * Manuel Lauss <mano@roarinelk.homelinux.net>
6 * (c) 2008 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>
7 *
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file COPYING in the main directory of this
10 * archive for more details.
11 *
12 * PLEASE HAVE A LOOK AT Documentation/fb/sh7760fb.txt!
13 *
14 * Thanks to Siegfried Schaefer <s.schaefer at schaefer-edv.de>
15 * for his original source and testing!
16 */
17
18#include <linux/completion.h>
19#include <linux/delay.h>
20#include <linux/dma-mapping.h>
21#include <linux/fb.h>
22#include <linux/interrupt.h>
23#include <linux/io.h>
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
27
28#include <asm/sh7760fb.h>
29
30struct sh7760fb_par {
31 void __iomem *base;
32 int irq;
33
34 struct sh7760fb_platdata *pd; /* display information */
35
36 dma_addr_t fbdma; /* physical address */
37
38 int rot; /* rotation enabled? */
39
40 u32 pseudo_palette[16];
41
42 struct platform_device *dev;
43 struct resource *ioarea;
44 struct completion vsync; /* vsync irq event */
45};
46
47static irqreturn_t sh7760fb_irq(int irq, void *data)
48{
49 struct completion *c = data;
50
51 complete(c);
52
53 return IRQ_HANDLED;
54}
55
56static void sh7760fb_wait_vsync(struct fb_info *info)
57{
58 struct sh7760fb_par *par = info->par;
59
60 if (par->pd->novsync)
61 return;
62
63 iowrite16(ioread16(par->base + LDINTR) & ~VINT_CHECK,
64 par->base + LDINTR);
65
66 if (par->irq < 0) {
67 /* poll for vert. retrace: status bit is sticky */
68 while (!(ioread16(par->base + LDINTR) & VINT_CHECK))
69 cpu_relax();
70 } else {
71 /* a "wait_for_irq_event(par->irq)" would be extremely nice */
72 init_completion(&par->vsync);
73 enable_irq(par->irq);
74 wait_for_completion(&par->vsync);
75 disable_irq_nosync(par->irq);
76 }
77}
78
79/* wait_for_lps - wait until power supply has reached a certain state. */
80static int wait_for_lps(struct sh7760fb_par *par, int val)
81{
82 int i = 100;
83 while (--i && ((ioread16(par->base + LDPMMR) & 3) != val))
84 msleep(1);
85
86 if (i <= 0)
87 return -ETIMEDOUT;
88
89 return 0;
90}
91
92/* en/disable the LCDC */
93static int sh7760fb_blank(int blank, struct fb_info *info)
94{
95 struct sh7760fb_par *par = info->par;
96 struct sh7760fb_platdata *pd = par->pd;
97 unsigned short cntr = ioread16(par->base + LDCNTR);
98 unsigned short intr = ioread16(par->base + LDINTR);
99 int lps;
100
101 if (blank == FB_BLANK_UNBLANK) {
102 intr |= VINT_START;
103 cntr = LDCNTR_DON2 | LDCNTR_DON;
104 lps = 3;
105 } else {
106 intr &= ~VINT_START;
107 cntr = LDCNTR_DON2;
108 lps = 0;
109 }
110
111 if (pd->blank)
112 pd->blank(blank);
113
114 iowrite16(intr, par->base + LDINTR);
115 iowrite16(cntr, par->base + LDCNTR);
116
117 return wait_for_lps(par, lps);
118}
119
120/* set color registers */
121static int sh7760fb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
122{
123 struct sh7760fb_par *par = info->par;
124 u32 s = cmap->start;
125 u32 l = cmap->len;
126 u16 *r = cmap->red;
127 u16 *g = cmap->green;
128 u16 *b = cmap->blue;
129 u32 col, tmo;
130 int ret;
131
132 ret = 0;
133
134 sh7760fb_wait_vsync(info);
135
136 /* request palette access */
137 iowrite16(LDPALCR_PALEN, par->base + LDPALCR);
138
139 /* poll for access grant */
140 tmo = 100;
141 while (!(ioread16(par->base + LDPALCR) & LDPALCR_PALS) && (--tmo))
142 cpu_relax();
143
144 if (!tmo) {
145 ret = 1;
146 dev_dbg(info->dev, "no palette access!\n");
147 goto out;
148 }
149
150 while (l && (s < 256)) {
151 col = ((*r) & 0xff) << 16;
152 col |= ((*g) & 0xff) << 8;
153 col |= ((*b) & 0xff);
154 col &= SH7760FB_PALETTE_MASK;
155
156 if (s < 16)
157 ((u32 *) (info->pseudo_palette))[s] = s;
158
159 s++;
160 l--;
161 r++;
162 g++;
163 b++;
164 }
165out:
166 iowrite16(0, par->base + LDPALCR);
167 return ret;
168}
169
170static void encode_fix(struct fb_fix_screeninfo *fix, struct fb_info *info,
171 unsigned long stride)
172{
173 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
174 strcpy(fix->id, "sh7760-lcdc");
175
176 fix->smem_start = (unsigned long)info->screen_base;
177 fix->smem_len = info->screen_size;
178
179 fix->line_length = stride;
180}
181
182static int sh7760fb_get_color_info(struct device *dev,
183 u16 lddfr, int *bpp, int *gray)
184{
185 int lbpp, lgray;
186
187 lgray = lbpp = 0;
188
189 switch (lddfr & LDDFR_COLOR_MASK) {
190 case LDDFR_1BPP_MONO:
191 lgray = 1;
192 lbpp = 1;
193 break;
194 case LDDFR_2BPP_MONO:
195 lgray = 1;
196 lbpp = 2;
197 break;
198 case LDDFR_4BPP_MONO:
199 lgray = 1;
200 case LDDFR_4BPP:
201 lbpp = 4;
202 break;
203 case LDDFR_6BPP_MONO:
204 lgray = 1;
205 case LDDFR_8BPP:
206 lbpp = 8;
207 break;
208 case LDDFR_16BPP_RGB555:
209 case LDDFR_16BPP_RGB565:
210 lbpp = 16;
211 lgray = 0;
212 break;
213 default:
214 dev_dbg(dev, "unsupported LDDFR bit depth.\n");
215 return -EINVAL;
216 }
217
218 if (bpp)
219 *bpp = lbpp;
220 if (gray)
221 *gray = lgray;
222
223 return 0;
224}
225
226static int sh7760fb_check_var(struct fb_var_screeninfo *var,
227 struct fb_info *info)
228{
229 struct fb_fix_screeninfo *fix = &info->fix;
230 struct sh7760fb_par *par = info->par;
231 int ret, bpp;
232
233 /* get color info from register value */
234 ret = sh7760fb_get_color_info(info->dev, par->pd->lddfr, &bpp, NULL);
235 if (ret)
236 return ret;
237
238 var->bits_per_pixel = bpp;
239
240 if ((var->grayscale) && (var->bits_per_pixel == 1))
241 fix->visual = FB_VISUAL_MONO10;
242 else if (var->bits_per_pixel >= 15)
243 fix->visual = FB_VISUAL_TRUECOLOR;
244 else
245 fix->visual = FB_VISUAL_PSEUDOCOLOR;
246
247 /* TODO: add some more validation here */
248 return 0;
249}
250
251/*
252 * sh7760fb_set_par - set videomode.
253 *
254 * NOTE: The rotation, grayscale and DSTN codepaths are
255 * totally untested!
256 */
257static int sh7760fb_set_par(struct fb_info *info)
258{
259 struct sh7760fb_par *par = info->par;
260 struct fb_videomode *vm = par->pd->def_mode;
261 unsigned long sbase, dstn_off, ldsarl, stride;
262 unsigned short hsynp, hsynw, htcn, hdcn;
263 unsigned short vsynp, vsynw, vtln, vdln;
264 unsigned short lddfr, ldmtr;
265 int ret, bpp, gray;
266
267 par->rot = par->pd->rotate;
268
269 /* rotate only works with xres <= 320 */
270 if (par->rot && (vm->xres > 320)) {
271 dev_dbg(info->dev, "rotation disabled due to display size\n");
272 par->rot = 0;
273 }
274
275 /* calculate LCDC reg vals from display parameters */
276 hsynp = vm->right_margin + vm->xres;
277 hsynw = vm->hsync_len;
278 htcn = vm->left_margin + hsynp + hsynw;
279 hdcn = vm->xres;
280 vsynp = vm->lower_margin + vm->yres;
281 vsynw = vm->vsync_len;
282 vtln = vm->upper_margin + vsynp + vsynw;
283 vdln = vm->yres;
284
285 /* get color info from register value */
286 ret = sh7760fb_get_color_info(info->dev, par->pd->lddfr, &bpp, &gray);
287 if (ret)
288 return ret;
289
290 dev_dbg(info->dev, "%dx%d %dbpp %s (orientation %s)\n", hdcn,
291 vdln, bpp, gray ? "grayscale" : "color",
292 par->rot ? "rotated" : "normal");
293
294#ifdef CONFIG_CPU_LITTLE_ENDIAN
295 lddfr = par->pd->lddfr | (1 << 8);
296#else
297 lddfr = par->pd->lddfr & ~(1 << 8);
298#endif
299
300 ldmtr = par->pd->ldmtr;
301
302 if (!(vm->sync & FB_SYNC_HOR_HIGH_ACT))
303 ldmtr |= LDMTR_CL1POL;
304 if (!(vm->sync & FB_SYNC_VERT_HIGH_ACT))
305 ldmtr |= LDMTR_FLMPOL;
306
307 /* shut down LCDC before changing display parameters */
308 sh7760fb_blank(FB_BLANK_POWERDOWN, info);
309
310 iowrite16(par->pd->ldickr, par->base + LDICKR); /* pixclock */
311 iowrite16(ldmtr, par->base + LDMTR); /* polarities */
312 iowrite16(lddfr, par->base + LDDFR); /* color/depth */
313 iowrite16((par->rot ? 1 << 13 : 0), par->base + LDSMR); /* rotate */
314 iowrite16(par->pd->ldpmmr, par->base + LDPMMR); /* Power Management */
315 iowrite16(par->pd->ldpspr, par->base + LDPSPR); /* Power Supply Ctrl */
316
317 /* display resolution */
318 iowrite16(((htcn >> 3) - 1) | (((hdcn >> 3) - 1) << 8),
319 par->base + LDHCNR);
320 iowrite16(vdln - 1, par->base + LDVDLNR);
321 iowrite16(vtln - 1, par->base + LDVTLNR);
322 /* h/v sync signals */
323 iowrite16((vsynp - 1) | ((vsynw - 1) << 12), par->base + LDVSYNR);
324 iowrite16(((hsynp >> 3) - 1) | (((hsynw >> 3) - 1) << 12),
325 par->base + LDHSYNR);
326 /* AC modulation sig */
327 iowrite16(par->pd->ldaclnr, par->base + LDACLNR);
328
329 stride = (par->rot) ? vtln : hdcn;
330 if (!gray)
331 stride *= (bpp + 7) >> 3;
332 else {
333 if (bpp == 1)
334 stride >>= 3;
335 else if (bpp == 2)
336 stride >>= 2;
337 else if (bpp == 4)
338 stride >>= 1;
339 /* 6 bpp == 8 bpp */
340 }
341
342 /* if rotated, stride must be power of 2 */
343 if (par->rot) {
344 unsigned long bit = 1 << 31;
345 while (bit) {
346 if (stride & bit)
347 break;
348 bit >>= 1;
349 }
350 if (stride & ~bit)
351 stride = bit << 1; /* not P-o-2, round up */
352 }
353 iowrite16(stride, par->base + LDLAOR);
354
355 /* set display mem start address */
356 sbase = (unsigned long)par->fbdma;
357 if (par->rot)
358 sbase += (hdcn - 1) * stride;
359
360 iowrite32(sbase, par->base + LDSARU);
361
362 /*
363 * for DSTN need to set address for lower half.
364 * I (mlau) don't know which address to set it to,
365 * so I guessed at (stride * yres/2).
366 */
367 if (((ldmtr & 0x003f) >= LDMTR_DSTN_MONO_8) &&
368 ((ldmtr & 0x003f) <= LDMTR_DSTN_COLOR_16)) {
369
370 dev_dbg(info->dev, " ***** DSTN untested! *****\n");
371
372 dstn_off = stride;
373 if (par->rot)
374 dstn_off *= hdcn >> 1;
375 else
376 dstn_off *= vdln >> 1;
377
378 ldsarl = sbase + dstn_off;
379 } else
380 ldsarl = 0;
381
382 iowrite32(ldsarl, par->base + LDSARL); /* mem for lower half of DSTN */
383
384 encode_fix(&info->fix, info, stride);
385 sh7760fb_check_var(&info->var, info);
386
387 sh7760fb_blank(FB_BLANK_UNBLANK, info); /* panel on! */
388
389 dev_dbg(info->dev, "hdcn : %6d htcn : %6d\n", hdcn, htcn);
390 dev_dbg(info->dev, "hsynw : %6d hsynp : %6d\n", hsynw, hsynp);
391 dev_dbg(info->dev, "vdln : %6d vtln : %6d\n", vdln, vtln);
392 dev_dbg(info->dev, "vsynw : %6d vsynp : %6d\n", vsynw, vsynp);
393 dev_dbg(info->dev, "clksrc: %6d clkdiv: %6d\n",
394 (par->pd->ldickr >> 12) & 3, par->pd->ldickr & 0x1f);
395 dev_dbg(info->dev, "ldpmmr: 0x%04x ldpspr: 0x%04x\n", par->pd->ldpmmr,
396 par->pd->ldpspr);
397 dev_dbg(info->dev, "ldmtr : 0x%04x lddfr : 0x%04x\n", ldmtr, lddfr);
398 dev_dbg(info->dev, "ldlaor: %ld\n", stride);
399 dev_dbg(info->dev, "ldsaru: 0x%08lx ldsarl: 0x%08lx\n", sbase, ldsarl);
400
401 return 0;
402}
403
404static struct fb_ops sh7760fb_ops = {
405 .owner = THIS_MODULE,
406 .fb_blank = sh7760fb_blank,
407 .fb_check_var = sh7760fb_check_var,
408 .fb_setcmap = sh7760fb_setcmap,
409 .fb_set_par = sh7760fb_set_par,
410 .fb_fillrect = cfb_fillrect,
411 .fb_copyarea = cfb_copyarea,
412 .fb_imageblit = cfb_imageblit,
413};
414
415static void sh7760fb_free_mem(struct fb_info *info)
416{
417 struct sh7760fb_par *par = info->par;
418
419 if (!info->screen_base)
420 return;
421
422 dma_free_coherent(info->dev, info->screen_size,
423 info->screen_base, par->fbdma);
424
425 par->fbdma = 0;
426 info->screen_base = NULL;
427 info->screen_size = 0;
428}
429
430/* allocate the framebuffer memory. This memory must be in Area3,
431 * (dictated by the DMA engine) and contiguous, at a 512 byte boundary.
432 */
433static int sh7760fb_alloc_mem(struct fb_info *info)
434{
435 struct sh7760fb_par *par = info->par;
436 void *fbmem;
437 unsigned long vram;
438 int ret, bpp;
439
440 if (info->screen_base)
441 return 0;
442
443 /* get color info from register value */
444 ret = sh7760fb_get_color_info(info->dev, par->pd->lddfr, &bpp, NULL);
445 if (ret) {
446 printk(KERN_ERR "colinfo\n");
447 return ret;
448 }
449
450 /* min VRAM: xres_min = 16, yres_min = 1, bpp = 1: 2byte -> 1 page
451 max VRAM: xres_max = 1024, yres_max = 1024, bpp = 16: 2MB */
452
453 vram = info->var.xres * info->var.yres;
454 if (info->var.grayscale) {
455 if (bpp == 1)
456 vram >>= 3;
457 else if (bpp == 2)
458 vram >>= 2;
459 else if (bpp == 4)
460 vram >>= 1;
461 } else if (bpp > 8)
462 vram *= 2;
463 if ((vram < 1) || (vram > 1024 * 2048)) {
464 dev_dbg(info->dev, "too much VRAM required. Check settings\n");
465 return -ENODEV;
466 }
467
468 if (vram < PAGE_SIZE)
469 vram = PAGE_SIZE;
470
471 fbmem = dma_alloc_coherent(info->dev, vram, &par->fbdma, GFP_KERNEL);
472
473 if (!fbmem)
474 return -ENOMEM;
475
476 if ((par->fbdma & SH7760FB_DMA_MASK) != SH7760FB_DMA_MASK) {
477 sh7760fb_free_mem(info);
478 dev_err(info->dev, "kernel gave me memory at 0x%08lx, which is"
479 "unusable for the LCDC\n", (unsigned long)par->fbdma);
480 return -ENOMEM;
481 }
482
483 info->screen_base = fbmem;
484 info->screen_size = vram;
485
486 return 0;
487}
488
489static int __devinit sh7760fb_probe(struct platform_device *pdev)
490{
491 struct fb_info *info;
492 struct resource *res;
493 struct sh7760fb_par *par;
494 int ret;
495
496 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
497 if (unlikely(res == NULL)) {
498 dev_err(&pdev->dev, "invalid resource\n");
499 return -EINVAL;
500 }
501
502 info = framebuffer_alloc(sizeof(struct sh7760fb_par), &pdev->dev);
503 if (!info)
504 return -ENOMEM;
505
506 par = info->par;
507 par->dev = pdev;
508
509 par->pd = pdev->dev.platform_data;
510 if (!par->pd) {
511 dev_dbg(info->dev, "no display setup data!\n");
512 ret = -ENODEV;
513 goto out_fb;
514 }
515
516 par->ioarea = request_mem_region(res->start,
517 (res->end - res->start), pdev->name);
518 if (!par->ioarea) {
519 dev_err(&pdev->dev, "mmio area busy\n");
520 ret = -EBUSY;
521 goto out_fb;
522 }
523
524 par->base = ioremap_nocache(res->start, res->end - res->start + 1);
525 if (!par->base) {
526 dev_err(&pdev->dev, "cannot remap\n");
527 ret = -ENODEV;
528 goto out_res;
529 }
530
531 iowrite16(0, par->base + LDINTR); /* disable vsync irq */
532 par->irq = platform_get_irq(pdev, 0);
533 if (par->irq >= 0) {
534 ret = request_irq(par->irq, sh7760fb_irq, 0,
535 "sh7760-lcdc", &par->vsync);
536 if (ret) {
537 dev_err(&pdev->dev, "cannot grab IRQ\n");
538 par->irq = -ENXIO;
539 } else
540 disable_irq_nosync(par->irq);
541 }
542
543 fb_videomode_to_var(&info->var, par->pd->def_mode);
544
545 ret = sh7760fb_alloc_mem(info);
546 if (ret) {
547 dev_dbg(info->dev, "framebuffer memory allocation failed!\n");
548 goto out_unmap;
549 }
550
551 info->pseudo_palette = par->pseudo_palette;
552
553 /* fixup color register bitpositions. These are fixed by hardware */
554 info->var.red.offset = 11;
555 info->var.red.length = 5;
556 info->var.red.msb_right = 0;
557
558 info->var.green.offset = 5;
559 info->var.green.length = 6;
560 info->var.green.msb_right = 0;
561
562 info->var.blue.offset = 0;
563 info->var.blue.length = 5;
564 info->var.blue.msb_right = 0;
565
566 info->var.transp.offset = 0;
567 info->var.transp.length = 0;
568 info->var.transp.msb_right = 0;
569
570 /* set the DON2 bit now, before cmap allocation, as it will randomize
571 * palette memory.
572 */
573 iowrite16(LDCNTR_DON2, par->base + LDCNTR);
574 info->fbops = &sh7760fb_ops;
575
576 ret = fb_alloc_cmap(&info->cmap, 256, 0);
577 if (ret) {
578 dev_dbg(info->dev, "Unable to allocate cmap memory\n");
579 goto out_mem;
580 }
581
582 ret = register_framebuffer(info);
583 if (ret < 0) {
584 dev_dbg(info->dev, "cannot register fb!\n");
585 goto out_cmap;
586 }
587 platform_set_drvdata(pdev, info);
588
589 printk(KERN_INFO "%s: memory at phys 0x%08lx-0x%08lx, size %ld KiB\n",
590 pdev->name,
591 (unsigned long)par->fbdma,
592 (unsigned long)(par->fbdma + info->screen_size - 1),
593 info->screen_size >> 10);
594
595 return 0;
596
597out_cmap:
598 sh7760fb_blank(FB_BLANK_POWERDOWN, info);
599 fb_dealloc_cmap(&info->cmap);
600out_mem:
601 sh7760fb_free_mem(info);
602out_unmap:
603 if (par->irq >= 0)
604 free_irq(par->irq, &par->vsync);
605 iounmap(par->base);
606out_res:
607 release_resource(par->ioarea);
608 kfree(par->ioarea);
609out_fb:
610 framebuffer_release(info);
611 return ret;
612}
613
614static int __devexit sh7760fb_remove(struct platform_device *dev)
615{
616 struct fb_info *info = platform_get_drvdata(dev);
617 struct sh7760fb_par *par = info->par;
618
619 sh7760fb_blank(FB_BLANK_POWERDOWN, info);
620 unregister_framebuffer(info);
621 fb_dealloc_cmap(&info->cmap);
622 sh7760fb_free_mem(info);
623 if (par->irq >= 0)
624 free_irq(par->irq, par);
625 iounmap(par->base);
626 release_resource(par->ioarea);
627 kfree(par->ioarea);
628 framebuffer_release(info);
629 platform_set_drvdata(dev, NULL);
630
631 return 0;
632}
633
634static struct platform_driver sh7760_lcdc_driver = {
635 .driver = {
636 .name = "sh7760-lcdc",
637 .owner = THIS_MODULE,
638 },
639 .probe = sh7760fb_probe,
640 .remove = __devexit_p(sh7760fb_remove),
641};
642
643static int __init sh7760fb_init(void)
644{
645 return platform_driver_register(&sh7760_lcdc_driver);
646}
647
648static void __exit sh7760fb_exit(void)
649{
650 platform_driver_unregister(&sh7760_lcdc_driver);
651}
652
653module_init(sh7760fb_init);
654module_exit(sh7760fb_exit);
655
656MODULE_AUTHOR("Nobuhiro Iwamatsu, Manuel Lauss");
657MODULE_DESCRIPTION("FBdev for SH7760/63 integrated LCD Controller");
658MODULE_LICENSE("GPL");
diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
new file mode 100644
index 000000000000..f6ef6cca73cd
--- /dev/null
+++ b/drivers/video/sh_mobile_lcdcfb.c
@@ -0,0 +1,725 @@
1/*
2 * SuperH Mobile LCDC Framebuffer
3 *
4 * Copyright (c) 2008 Magnus Damm
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/delay.h>
14#include <linux/mm.h>
15#include <linux/fb.h>
16#include <linux/clk.h>
17#include <linux/platform_device.h>
18#include <linux/dma-mapping.h>
19#include <asm/sh_mobile_lcdc.h>
20
21#define PALETTE_NR 16
22
23struct sh_mobile_lcdc_priv;
24struct sh_mobile_lcdc_chan {
25 struct sh_mobile_lcdc_priv *lcdc;
26 unsigned long *reg_offs;
27 unsigned long ldmt1r_value;
28 unsigned long enabled; /* ME and SE in LDCNT2R */
29 struct sh_mobile_lcdc_chan_cfg cfg;
30 u32 pseudo_palette[PALETTE_NR];
31 struct fb_info info;
32 dma_addr_t dma_handle;
33};
34
35struct sh_mobile_lcdc_priv {
36 void __iomem *base;
37 struct clk *clk;
38 unsigned long lddckr;
39 struct sh_mobile_lcdc_chan ch[2];
40};
41
42/* shared registers */
43#define _LDDCKR 0x410
44#define _LDDCKSTPR 0x414
45#define _LDINTR 0x468
46#define _LDSR 0x46c
47#define _LDCNT1R 0x470
48#define _LDCNT2R 0x474
49#define _LDDDSR 0x47c
50#define _LDDWD0R 0x800
51#define _LDDRDR 0x840
52#define _LDDWAR 0x900
53#define _LDDRAR 0x904
54
55/* per-channel registers */
56enum { LDDCKPAT1R, LDDCKPAT2R, LDMT1R, LDMT2R, LDMT3R, LDDFR, LDSM1R,
57 LDSA1R, LDMLSR, LDHCNR, LDHSYNR, LDVLNR, LDVSYNR, LDPMR };
58
59static unsigned long lcdc_offs_mainlcd[] = {
60 [LDDCKPAT1R] = 0x400,
61 [LDDCKPAT2R] = 0x404,
62 [LDMT1R] = 0x418,
63 [LDMT2R] = 0x41c,
64 [LDMT3R] = 0x420,
65 [LDDFR] = 0x424,
66 [LDSM1R] = 0x428,
67 [LDSA1R] = 0x430,
68 [LDMLSR] = 0x438,
69 [LDHCNR] = 0x448,
70 [LDHSYNR] = 0x44c,
71 [LDVLNR] = 0x450,
72 [LDVSYNR] = 0x454,
73 [LDPMR] = 0x460,
74};
75
76static unsigned long lcdc_offs_sublcd[] = {
77 [LDDCKPAT1R] = 0x408,
78 [LDDCKPAT2R] = 0x40c,
79 [LDMT1R] = 0x600,
80 [LDMT2R] = 0x604,
81 [LDMT3R] = 0x608,
82 [LDDFR] = 0x60c,
83 [LDSM1R] = 0x610,
84 [LDSA1R] = 0x618,
85 [LDMLSR] = 0x620,
86 [LDHCNR] = 0x624,
87 [LDHSYNR] = 0x628,
88 [LDVLNR] = 0x62c,
89 [LDVSYNR] = 0x630,
90 [LDPMR] = 0x63c,
91};
92
93#define START_LCDC 0x00000001
94#define LCDC_RESET 0x00000100
95#define DISPLAY_BEU 0x00000008
96#define LCDC_ENABLE 0x00000001
97
98static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
99 int reg_nr, unsigned long data)
100{
101 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
102}
103
104static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
105 int reg_nr)
106{
107 return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
108}
109
110static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
111 unsigned long reg_offs, unsigned long data)
112{
113 iowrite32(data, priv->base + reg_offs);
114}
115
116static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
117 unsigned long reg_offs)
118{
119 return ioread32(priv->base + reg_offs);
120}
121
122static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
123 unsigned long reg_offs,
124 unsigned long mask, unsigned long until)
125{
126 while ((lcdc_read(priv, reg_offs) & mask) != until)
127 cpu_relax();
128}
129
130static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
131{
132 return chan->cfg.chan == LCDC_CHAN_SUBLCD;
133}
134
135static void lcdc_sys_write_index(void *handle, unsigned long data)
136{
137 struct sh_mobile_lcdc_chan *ch = handle;
138
139 lcdc_write(ch->lcdc, _LDDWD0R, data | 0x10000000);
140 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
141 lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
142}
143
144static void lcdc_sys_write_data(void *handle, unsigned long data)
145{
146 struct sh_mobile_lcdc_chan *ch = handle;
147
148 lcdc_write(ch->lcdc, _LDDWD0R, data | 0x11000000);
149 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
150 lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
151}
152
153static unsigned long lcdc_sys_read_data(void *handle)
154{
155 struct sh_mobile_lcdc_chan *ch = handle;
156
157 lcdc_write(ch->lcdc, _LDDRDR, 0x01000000);
158 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
159 lcdc_write(ch->lcdc, _LDDRAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
160 udelay(1);
161
162 return lcdc_read(ch->lcdc, _LDDRDR) & 0xffff;
163}
164
165struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
166 lcdc_sys_write_index,
167 lcdc_sys_write_data,
168 lcdc_sys_read_data,
169};
170
171static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
172 int start)
173{
174 unsigned long tmp = lcdc_read(priv, _LDCNT2R);
175 int k;
176
177 /* start or stop the lcdc */
178 if (start)
179 lcdc_write(priv, _LDCNT2R, tmp | START_LCDC);
180 else
181 lcdc_write(priv, _LDCNT2R, tmp & ~START_LCDC);
182
183 /* wait until power is applied/stopped on all channels */
184 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
185 if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
186 while (1) {
187 tmp = lcdc_read_chan(&priv->ch[k], LDPMR) & 3;
188 if (start && tmp == 3)
189 break;
190 if (!start && tmp == 0)
191 break;
192 cpu_relax();
193 }
194
195 if (!start)
196 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
197}
198
199static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
200{
201 struct sh_mobile_lcdc_chan *ch;
202 struct fb_videomode *lcd_cfg;
203 struct sh_mobile_lcdc_board_cfg *board_cfg;
204 unsigned long tmp;
205 int k, m;
206 int ret = 0;
207
208 /* reset */
209 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LCDC_RESET);
210 lcdc_wait_bit(priv, _LDCNT2R, LCDC_RESET, 0);
211
212 /* enable LCDC channels */
213 tmp = lcdc_read(priv, _LDCNT2R);
214 tmp |= priv->ch[0].enabled;
215 tmp |= priv->ch[1].enabled;
216 lcdc_write(priv, _LDCNT2R, tmp);
217
218 /* read data from external memory, avoid using the BEU for now */
219 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) & ~DISPLAY_BEU);
220
221 /* stop the lcdc first */
222 sh_mobile_lcdc_start_stop(priv, 0);
223
224 /* configure clocks */
225 tmp = priv->lddckr;
226 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
227 ch = &priv->ch[k];
228
229 if (!priv->ch[k].enabled)
230 continue;
231
232 m = ch->cfg.clock_divider;
233 if (!m)
234 continue;
235
236 if (m == 1)
237 m = 1 << 6;
238 tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
239
240 lcdc_write_chan(ch, LDDCKPAT1R, 0x00000000);
241 lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
242 }
243
244 lcdc_write(priv, _LDDCKR, tmp);
245
246 /* start dotclock again */
247 lcdc_write(priv, _LDDCKSTPR, 0);
248 lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
249
250 /* interrupts are disabled */
251 lcdc_write(priv, _LDINTR, 0);
252
253 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
254 ch = &priv->ch[k];
255 lcd_cfg = &ch->cfg.lcd_cfg;
256
257 if (!ch->enabled)
258 continue;
259
260 tmp = ch->ldmt1r_value;
261 tmp |= (lcd_cfg->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1 << 28;
262 tmp |= (lcd_cfg->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1 << 27;
263 lcdc_write_chan(ch, LDMT1R, tmp);
264
265 /* setup SYS bus */
266 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
267 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
268
269 /* horizontal configuration */
270 tmp = lcd_cfg->xres + lcd_cfg->hsync_len;
271 tmp += lcd_cfg->left_margin;
272 tmp += lcd_cfg->right_margin;
273 tmp /= 8; /* HTCN */
274 tmp |= (lcd_cfg->xres / 8) << 16; /* HDCN */
275 lcdc_write_chan(ch, LDHCNR, tmp);
276
277 tmp = lcd_cfg->xres;
278 tmp += lcd_cfg->right_margin;
279 tmp /= 8; /* HSYNP */
280 tmp |= (lcd_cfg->hsync_len / 8) << 16; /* HSYNW */
281 lcdc_write_chan(ch, LDHSYNR, tmp);
282
283 /* power supply */
284 lcdc_write_chan(ch, LDPMR, 0);
285
286 /* vertical configuration */
287 tmp = lcd_cfg->yres + lcd_cfg->vsync_len;
288 tmp += lcd_cfg->upper_margin;
289 tmp += lcd_cfg->lower_margin; /* VTLN */
290 tmp |= lcd_cfg->yres << 16; /* VDLN */
291 lcdc_write_chan(ch, LDVLNR, tmp);
292
293 tmp = lcd_cfg->yres;
294 tmp += lcd_cfg->lower_margin; /* VSYNP */
295 tmp |= lcd_cfg->vsync_len << 16; /* VSYNW */
296 lcdc_write_chan(ch, LDVSYNR, tmp);
297
298 board_cfg = &ch->cfg.board_cfg;
299 if (board_cfg->setup_sys)
300 ret = board_cfg->setup_sys(board_cfg->board_data, ch,
301 &sh_mobile_lcdc_sys_bus_ops);
302 if (ret)
303 return ret;
304 }
305
306 /* --- display_lcdc_data() --- */
307 lcdc_write(priv, _LDINTR, 0x00000f00);
308
309 /* word and long word swap */
310 lcdc_write(priv, _LDDDSR, lcdc_read(priv, _LDDDSR) | 6);
311
312 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
313 ch = &priv->ch[k];
314
315 if (!priv->ch[k].enabled)
316 continue;
317
318 /* set bpp format in PKF[4:0] */
319 tmp = lcdc_read_chan(ch, LDDFR);
320 tmp &= ~(0x0001001f);
321 tmp |= (priv->ch[k].info.var.bits_per_pixel == 16) ? 3 : 0;
322 lcdc_write_chan(ch, LDDFR, tmp);
323
324 /* point out our frame buffer */
325 lcdc_write_chan(ch, LDSA1R, ch->info.fix.smem_start);
326
327 /* set line size */
328 lcdc_write_chan(ch, LDMLSR, ch->info.fix.line_length);
329
330 /* continuous read mode */
331 lcdc_write_chan(ch, LDSM1R, 0);
332 }
333
334 /* display output */
335 lcdc_write(priv, _LDCNT1R, LCDC_ENABLE);
336
337 /* start the lcdc */
338 sh_mobile_lcdc_start_stop(priv, 1);
339
340 /* tell the board code to enable the panel */
341 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
342 ch = &priv->ch[k];
343 board_cfg = &ch->cfg.board_cfg;
344 if (board_cfg->display_on)
345 board_cfg->display_on(board_cfg->board_data);
346 }
347
348 return 0;
349}
350
351static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
352{
353 struct sh_mobile_lcdc_chan *ch;
354 struct sh_mobile_lcdc_board_cfg *board_cfg;
355 int k;
356
357 /* tell the board code to disable the panel */
358 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
359 ch = &priv->ch[k];
360 board_cfg = &ch->cfg.board_cfg;
361 if (board_cfg->display_off)
362 board_cfg->display_off(board_cfg->board_data);
363 }
364
365 /* stop the lcdc */
366 sh_mobile_lcdc_start_stop(priv, 0);
367}
368
369static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
370{
371 int ifm, miftyp;
372
373 switch (ch->cfg.interface_type) {
374 case RGB8: ifm = 0; miftyp = 0; break;
375 case RGB9: ifm = 0; miftyp = 4; break;
376 case RGB12A: ifm = 0; miftyp = 5; break;
377 case RGB12B: ifm = 0; miftyp = 6; break;
378 case RGB16: ifm = 0; miftyp = 7; break;
379 case RGB18: ifm = 0; miftyp = 10; break;
380 case RGB24: ifm = 0; miftyp = 11; break;
381 case SYS8A: ifm = 1; miftyp = 0; break;
382 case SYS8B: ifm = 1; miftyp = 1; break;
383 case SYS8C: ifm = 1; miftyp = 2; break;
384 case SYS8D: ifm = 1; miftyp = 3; break;
385 case SYS9: ifm = 1; miftyp = 4; break;
386 case SYS12: ifm = 1; miftyp = 5; break;
387 case SYS16A: ifm = 1; miftyp = 7; break;
388 case SYS16B: ifm = 1; miftyp = 8; break;
389 case SYS16C: ifm = 1; miftyp = 9; break;
390 case SYS18: ifm = 1; miftyp = 10; break;
391 case SYS24: ifm = 1; miftyp = 11; break;
392 default: goto bad;
393 }
394
395 /* SUBLCD only supports SYS interface */
396 if (lcdc_chan_is_sublcd(ch)) {
397 if (ifm == 0)
398 goto bad;
399 else
400 ifm = 0;
401 }
402
403 ch->ldmt1r_value = (ifm << 12) | miftyp;
404 return 0;
405 bad:
406 return -EINVAL;
407}
408
409static int sh_mobile_lcdc_setup_clocks(struct device *dev, int clock_source,
410 struct sh_mobile_lcdc_priv *priv)
411{
412 char *str;
413 int icksel;
414
415 switch (clock_source) {
416 case LCDC_CLK_BUS: str = "bus_clk"; icksel = 0; break;
417 case LCDC_CLK_PERIPHERAL: str = "peripheral_clk"; icksel = 1; break;
418 case LCDC_CLK_EXTERNAL: str = NULL; icksel = 2; break;
419 default:
420 return -EINVAL;
421 }
422
423 priv->lddckr = icksel << 16;
424
425 if (str) {
426 priv->clk = clk_get(dev, str);
427 if (IS_ERR(priv->clk)) {
428 dev_err(dev, "cannot get clock %s\n", str);
429 return PTR_ERR(priv->clk);
430 }
431
432 clk_enable(priv->clk);
433 }
434
435 return 0;
436}
437
438static int sh_mobile_lcdc_setcolreg(u_int regno,
439 u_int red, u_int green, u_int blue,
440 u_int transp, struct fb_info *info)
441{
442 u32 *palette = info->pseudo_palette;
443
444 if (regno >= PALETTE_NR)
445 return -EINVAL;
446
447 /* only FB_VISUAL_TRUECOLOR supported */
448
449 red >>= 16 - info->var.red.length;
450 green >>= 16 - info->var.green.length;
451 blue >>= 16 - info->var.blue.length;
452 transp >>= 16 - info->var.transp.length;
453
454 palette[regno] = (red << info->var.red.offset) |
455 (green << info->var.green.offset) |
456 (blue << info->var.blue.offset) |
457 (transp << info->var.transp.offset);
458
459 return 0;
460}
461
462static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
463 .id = "SH Mobile LCDC",
464 .type = FB_TYPE_PACKED_PIXELS,
465 .visual = FB_VISUAL_TRUECOLOR,
466 .accel = FB_ACCEL_NONE,
467};
468
469static struct fb_ops sh_mobile_lcdc_ops = {
470 .fb_setcolreg = sh_mobile_lcdc_setcolreg,
471 .fb_fillrect = cfb_fillrect,
472 .fb_copyarea = cfb_copyarea,
473 .fb_imageblit = cfb_imageblit,
474};
475
476static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp)
477{
478 switch (bpp) {
479 case 16: /* PKF[4:0] = 00011 - RGB 565 */
480 var->red.offset = 11;
481 var->red.length = 5;
482 var->green.offset = 5;
483 var->green.length = 6;
484 var->blue.offset = 0;
485 var->blue.length = 5;
486 var->transp.offset = 0;
487 var->transp.length = 0;
488 break;
489
490 case 32: /* PKF[4:0] = 00000 - RGB 888
491 * sh7722 pdf says 00RRGGBB but reality is GGBB00RR
492 * this may be because LDDDSR has word swap enabled..
493 */
494 var->red.offset = 0;
495 var->red.length = 8;
496 var->green.offset = 24;
497 var->green.length = 8;
498 var->blue.offset = 16;
499 var->blue.length = 8;
500 var->transp.offset = 0;
501 var->transp.length = 0;
502 break;
503 default:
504 return -EINVAL;
505 }
506 var->bits_per_pixel = bpp;
507 var->red.msb_right = 0;
508 var->green.msb_right = 0;
509 var->blue.msb_right = 0;
510 var->transp.msb_right = 0;
511 return 0;
512}
513
514static int sh_mobile_lcdc_remove(struct platform_device *pdev);
515
516static int __init sh_mobile_lcdc_probe(struct platform_device *pdev)
517{
518 struct fb_info *info;
519 struct sh_mobile_lcdc_priv *priv;
520 struct sh_mobile_lcdc_info *pdata;
521 struct sh_mobile_lcdc_chan_cfg *cfg;
522 struct resource *res;
523 int error;
524 void *buf;
525 int i, j;
526
527 if (!pdev->dev.platform_data) {
528 dev_err(&pdev->dev, "no platform data defined\n");
529 error = -EINVAL;
530 goto err0;
531 }
532
533 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
534 if (res == NULL) {
535 dev_err(&pdev->dev, "cannot find IO resource\n");
536 error = -ENOENT;
537 goto err0;
538 }
539
540 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
541 if (!priv) {
542 dev_err(&pdev->dev, "cannot allocate device data\n");
543 error = -ENOMEM;
544 goto err0;
545 }
546
547 platform_set_drvdata(pdev, priv);
548 pdata = pdev->dev.platform_data;
549
550 j = 0;
551 for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
552 priv->ch[j].lcdc = priv;
553 memcpy(&priv->ch[j].cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
554
555 error = sh_mobile_lcdc_check_interface(&priv->ch[i]);
556 if (error) {
557 dev_err(&pdev->dev, "unsupported interface type\n");
558 goto err1;
559 }
560
561 switch (pdata->ch[i].chan) {
562 case LCDC_CHAN_MAINLCD:
563 priv->ch[j].enabled = 1 << 1;
564 priv->ch[j].reg_offs = lcdc_offs_mainlcd;
565 j++;
566 break;
567 case LCDC_CHAN_SUBLCD:
568 priv->ch[j].enabled = 1 << 2;
569 priv->ch[j].reg_offs = lcdc_offs_sublcd;
570 j++;
571 break;
572 }
573 }
574
575 if (!j) {
576 dev_err(&pdev->dev, "no channels defined\n");
577 error = -EINVAL;
578 goto err1;
579 }
580
581 error = sh_mobile_lcdc_setup_clocks(&pdev->dev,
582 pdata->clock_source, priv);
583 if (error) {
584 dev_err(&pdev->dev, "unable to setup clocks\n");
585 goto err1;
586 }
587
588 priv->lddckr = pdata->lddckr;
589 priv->base = ioremap_nocache(res->start, (res->end - res->start) + 1);
590
591 for (i = 0; i < j; i++) {
592 info = &priv->ch[i].info;
593 cfg = &priv->ch[i].cfg;
594
595 info->fbops = &sh_mobile_lcdc_ops;
596 info->var.xres = info->var.xres_virtual = cfg->lcd_cfg.xres;
597 info->var.yres = info->var.yres_virtual = cfg->lcd_cfg.yres;
598 info->var.activate = FB_ACTIVATE_NOW;
599 error = sh_mobile_lcdc_set_bpp(&info->var, cfg->bpp);
600 if (error)
601 break;
602
603 info->fix = sh_mobile_lcdc_fix;
604 info->fix.line_length = cfg->lcd_cfg.xres * (cfg->bpp / 8);
605 info->fix.smem_len = info->fix.line_length * cfg->lcd_cfg.yres;
606
607 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
608 &priv->ch[i].dma_handle, GFP_KERNEL);
609 if (!buf) {
610 dev_err(&pdev->dev, "unable to allocate buffer\n");
611 error = -ENOMEM;
612 break;
613 }
614
615 info->pseudo_palette = &priv->ch[i].pseudo_palette;
616 info->flags = FBINFO_FLAG_DEFAULT;
617
618 error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
619 if (error < 0) {
620 dev_err(&pdev->dev, "unable to allocate cmap\n");
621 dma_free_coherent(&pdev->dev, info->fix.smem_len,
622 buf, priv->ch[i].dma_handle);
623 break;
624 }
625
626 memset(buf, 0, info->fix.smem_len);
627 info->fix.smem_start = priv->ch[i].dma_handle;
628 info->screen_base = buf;
629 info->device = &pdev->dev;
630 }
631
632 if (error)
633 goto err1;
634
635 error = sh_mobile_lcdc_start(priv);
636 if (error) {
637 dev_err(&pdev->dev, "unable to start hardware\n");
638 goto err1;
639 }
640
641 for (i = 0; i < j; i++) {
642 error = register_framebuffer(&priv->ch[i].info);
643 if (error < 0)
644 goto err1;
645 }
646
647 for (i = 0; i < j; i++) {
648 info = &priv->ch[i].info;
649 dev_info(info->dev,
650 "registered %s/%s as %dx%d %dbpp.\n",
651 pdev->name,
652 (priv->ch[i].cfg.chan == LCDC_CHAN_MAINLCD) ?
653 "mainlcd" : "sublcd",
654 (int) priv->ch[i].cfg.lcd_cfg.xres,
655 (int) priv->ch[i].cfg.lcd_cfg.yres,
656 priv->ch[i].cfg.bpp);
657 }
658
659 return 0;
660 err1:
661 sh_mobile_lcdc_remove(pdev);
662 err0:
663 return error;
664}
665
666static int sh_mobile_lcdc_remove(struct platform_device *pdev)
667{
668 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
669 struct fb_info *info;
670 int i;
671
672 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
673 if (priv->ch[i].info.dev)
674 unregister_framebuffer(&priv->ch[i].info);
675
676 sh_mobile_lcdc_stop(priv);
677
678 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
679 info = &priv->ch[i].info;
680
681 if (!info->device)
682 continue;
683
684 dma_free_coherent(&pdev->dev, info->fix.smem_len,
685 info->screen_base, priv->ch[i].dma_handle);
686 fb_dealloc_cmap(&info->cmap);
687 }
688
689 if (priv->clk) {
690 clk_disable(priv->clk);
691 clk_put(priv->clk);
692 }
693
694 if (priv->base)
695 iounmap(priv->base);
696
697 kfree(priv);
698 return 0;
699}
700
701static struct platform_driver sh_mobile_lcdc_driver = {
702 .driver = {
703 .name = "sh_mobile_lcdc_fb",
704 .owner = THIS_MODULE,
705 },
706 .probe = sh_mobile_lcdc_probe,
707 .remove = sh_mobile_lcdc_remove,
708};
709
710static int __init sh_mobile_lcdc_init(void)
711{
712 return platform_driver_register(&sh_mobile_lcdc_driver);
713}
714
715static void __exit sh_mobile_lcdc_exit(void)
716{
717 platform_driver_unregister(&sh_mobile_lcdc_driver);
718}
719
720module_init(sh_mobile_lcdc_init);
721module_exit(sh_mobile_lcdc_exit);
722
723MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
724MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
725MODULE_LICENSE("GPL v2");
diff --git a/drivers/video/sis/init.h b/drivers/video/sis/init.h
index f40a680df86f..b96005c39c67 100644
--- a/drivers/video/sis/init.h
+++ b/drivers/video/sis/init.h
@@ -73,7 +73,6 @@
73#ifdef SIS_CP 73#ifdef SIS_CP
74#undef SIS_CP 74#undef SIS_CP
75#endif 75#endif
76#include <linux/version.h>
77#include <linux/types.h> 76#include <linux/types.h>
78#include <asm/io.h> 77#include <asm/io.h>
79#include <linux/fb.h> 78#include <linux/fb.h>
diff --git a/drivers/video/sis/init301.h b/drivers/video/sis/init301.h
index 7708e1e1d99e..51d99222375d 100644
--- a/drivers/video/sis/init301.h
+++ b/drivers/video/sis/init301.h
@@ -67,7 +67,6 @@
67#ifdef SIS_CP 67#ifdef SIS_CP
68#undef SIS_CP 68#undef SIS_CP
69#endif 69#endif
70#include <linux/version.h>
71#include <linux/types.h> 70#include <linux/types.h>
72#include <asm/io.h> 71#include <asm/io.h>
73#include <linux/fb.h> 72#include <linux/fb.h>
diff --git a/drivers/video/sis/initextlfb.c b/drivers/video/sis/initextlfb.c
index 47a33501549d..99c04a4855d1 100644
--- a/drivers/video/sis/initextlfb.c
+++ b/drivers/video/sis/initextlfb.c
@@ -30,7 +30,6 @@
30#include "vgatypes.h" 30#include "vgatypes.h"
31#include "vstruct.h" 31#include "vstruct.h"
32 32
33#include <linux/version.h>
34#include <linux/types.h> 33#include <linux/types.h>
35#include <linux/fb.h> 34#include <linux/fb.h>
36 35
diff --git a/drivers/video/sis/osdef.h b/drivers/video/sis/osdef.h
index c1492782cb18..6ff8f988a1a7 100644
--- a/drivers/video/sis/osdef.h
+++ b/drivers/video/sis/osdef.h
@@ -87,7 +87,6 @@
87/**********************************************************************/ 87/**********************************************************************/
88 88
89#ifdef SIS_LINUX_KERNEL 89#ifdef SIS_LINUX_KERNEL
90#include <linux/version.h>
91 90
92#ifdef CONFIG_FB_SIS_300 91#ifdef CONFIG_FB_SIS_300
93#define SIS300 92#define SIS300
diff --git a/drivers/video/sis/sis.h b/drivers/video/sis/sis.h
index a14e82211037..7c5710e3fb56 100644
--- a/drivers/video/sis/sis.h
+++ b/drivers/video/sis/sis.h
@@ -24,8 +24,6 @@
24#ifndef _SIS_H_ 24#ifndef _SIS_H_
25#define _SIS_H_ 25#define _SIS_H_
26 26
27#include <linux/version.h>
28
29#include "osdef.h" 27#include "osdef.h"
30#include <video/sisfb.h> 28#include <video/sisfb.h>
31 29
@@ -42,16 +40,6 @@
42#define SIS_NEW_CONFIG_COMPAT 40#define SIS_NEW_CONFIG_COMPAT
43#endif /* CONFIG_COMPAT */ 41#endif /* CONFIG_COMPAT */
44 42
45#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
46#define SIS_IOTYPE1 void __iomem
47#define SIS_IOTYPE2 __iomem
48#define SISINITSTATIC static
49#else
50#define SIS_IOTYPE1 unsigned char
51#define SIS_IOTYPE2
52#define SISINITSTATIC
53#endif
54
55#undef SISFBDEBUG 43#undef SISFBDEBUG
56 44
57#ifdef SISFBDEBUG 45#ifdef SISFBDEBUG
@@ -505,8 +493,8 @@ struct sis_video_info {
505 493
506 unsigned long UMAsize, LFBsize; 494 unsigned long UMAsize, LFBsize;
507 495
508 SIS_IOTYPE1 *video_vbase; 496 void __iomem *video_vbase;
509 SIS_IOTYPE1 *mmio_vbase; 497 void __iomem *mmio_vbase;
510 498
511 unsigned char *bios_abase; 499 unsigned char *bios_abase;
512 500
@@ -533,8 +521,8 @@ struct sis_video_info {
533 int sisfb_nocrt2rate; 521 int sisfb_nocrt2rate;
534 522
535 u32 heapstart; /* offset */ 523 u32 heapstart; /* offset */
536 SIS_IOTYPE1 *sisfb_heap_start; /* address */ 524 void __iomem *sisfb_heap_start; /* address */
537 SIS_IOTYPE1 *sisfb_heap_end; /* address */ 525 void __iomem *sisfb_heap_end; /* address */
538 u32 sisfb_heap_size; 526 u32 sisfb_heap_size;
539 int havenoheap; 527 int havenoheap;
540 528
@@ -612,7 +600,7 @@ struct sis_video_info {
612 u8 detectedpdca; 600 u8 detectedpdca;
613 u8 detectedlcda; 601 u8 detectedlcda;
614 602
615 SIS_IOTYPE1 *hwcursor_vbase; 603 void __iomem *hwcursor_vbase;
616 604
617 int chronteltype; 605 int chronteltype;
618 int tvxpos, tvypos; 606 int tvxpos, tvypos;
diff --git a/drivers/video/sis/sis_accel.c b/drivers/video/sis/sis_accel.c
index 7addf91d2fea..ceb434c95c0d 100644
--- a/drivers/video/sis/sis_accel.c
+++ b/drivers/video/sis/sis_accel.c
@@ -28,7 +28,6 @@
28 * for more information and updates) 28 * for more information and updates)
29 */ 29 */
30 30
31#include <linux/version.h>
32#include <linux/module.h> 31#include <linux/module.h>
33#include <linux/kernel.h> 32#include <linux/kernel.h>
34#include <linux/fb.h> 33#include <linux/fb.h>
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index b9343844cd1f..346d6458cf76 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -33,7 +33,6 @@
33 * 33 *
34 */ 34 */
35 35
36#include <linux/version.h>
37#include <linux/module.h> 36#include <linux/module.h>
38#include <linux/moduleparam.h> 37#include <linux/moduleparam.h>
39#include <linux/kernel.h> 38#include <linux/kernel.h>
@@ -41,13 +40,7 @@
41#include <linux/errno.h> 40#include <linux/errno.h>
42#include <linux/string.h> 41#include <linux/string.h>
43#include <linux/mm.h> 42#include <linux/mm.h>
44
45#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
46#include <linux/tty.h>
47#else
48#include <linux/screen_info.h> 43#include <linux/screen_info.h>
49#endif
50
51#include <linux/slab.h> 44#include <linux/slab.h>
52#include <linux/fb.h> 45#include <linux/fb.h>
53#include <linux/selection.h> 46#include <linux/selection.h>
@@ -1167,11 +1160,7 @@ sisfb_set_mode(struct sis_video_info *ivideo, int clrscrn)
1167 unsigned short modeno = ivideo->mode_no; 1160 unsigned short modeno = ivideo->mode_no;
1168 1161
1169 /* >=2.6.12's fbcon clears the screen anyway */ 1162 /* >=2.6.12's fbcon clears the screen anyway */
1170#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
1171 if(!clrscrn) modeno |= 0x80;
1172#else
1173 modeno |= 0x80; 1163 modeno |= 0x80;
1174#endif
1175 1164
1176 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD); 1165 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
1177 1166
@@ -1436,11 +1425,8 @@ sisfb_set_par(struct fb_info *info)
1436 if((err = sisfb_do_set_var(&info->var, 1, info))) 1425 if((err = sisfb_do_set_var(&info->var, 1, info)))
1437 return err; 1426 return err;
1438 1427
1439#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
1440 sisfb_get_fix(&info->fix, info->currcon, info);
1441#else
1442 sisfb_get_fix(&info->fix, -1, info); 1428 sisfb_get_fix(&info->fix, -1, info);
1443#endif 1429
1444 return 0; 1430 return 0;
1445} 1431}
1446 1432
@@ -1676,14 +1662,8 @@ sisfb_blank(int blank, struct fb_info *info)
1676 1662
1677/* ----------- FBDev related routines for all series ---------- */ 1663/* ----------- FBDev related routines for all series ---------- */
1678 1664
1679#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
1680static int sisfb_ioctl(struct fb_info *info, unsigned int cmd, 1665static int sisfb_ioctl(struct fb_info *info, unsigned int cmd,
1681 unsigned long arg) 1666 unsigned long arg)
1682#else
1683static int sisfb_ioctl(struct inode *inode, struct file *file,
1684 unsigned int cmd, unsigned long arg,
1685 struct fb_info *info)
1686#endif
1687{ 1667{
1688 struct sis_video_info *ivideo = (struct sis_video_info *)info->par; 1668 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
1689 struct sis_memreq sismemreq; 1669 struct sis_memreq sismemreq;
@@ -3986,8 +3966,7 @@ sisfb_handle_command(struct sis_video_info *ivideo, struct sisfb_cmd *sisfb_comm
3986} 3966}
3987 3967
3988#ifndef MODULE 3968#ifndef MODULE
3989SISINITSTATIC int __init 3969static int __init sisfb_setup(char *options)
3990sisfb_setup(char *options)
3991{ 3970{
3992 char *this_opt; 3971 char *this_opt;
3993 3972
@@ -4086,9 +4065,9 @@ sisfb_setup(char *options)
4086#endif 4065#endif
4087 4066
4088static int __devinit 4067static int __devinit
4089sisfb_check_rom(SIS_IOTYPE1 *rom_base, struct sis_video_info *ivideo) 4068sisfb_check_rom(void __iomem *rom_base, struct sis_video_info *ivideo)
4090{ 4069{
4091 SIS_IOTYPE1 *rom; 4070 void __iomem *rom;
4092 int romptr; 4071 int romptr;
4093 4072
4094 if((readb(rom_base) != 0x55) || (readb(rom_base + 1) != 0xaa)) 4073 if((readb(rom_base) != 0x55) || (readb(rom_base + 1) != 0xaa))
@@ -4117,10 +4096,9 @@ static unsigned char * __devinit
4117sisfb_find_rom(struct pci_dev *pdev) 4096sisfb_find_rom(struct pci_dev *pdev)
4118{ 4097{
4119 struct sis_video_info *ivideo = pci_get_drvdata(pdev); 4098 struct sis_video_info *ivideo = pci_get_drvdata(pdev);
4120 SIS_IOTYPE1 *rom_base; 4099 void __iomem *rom_base;
4121 unsigned char *myrombase = NULL; 4100 unsigned char *myrombase = NULL;
4122 u32 temp; 4101 u32 temp;
4123#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
4124 size_t romsize; 4102 size_t romsize;
4125 4103
4126 /* First, try the official pci ROM functions (except 4104 /* First, try the official pci ROM functions (except
@@ -4151,7 +4129,6 @@ sisfb_find_rom(struct pci_dev *pdev)
4151 } 4129 }
4152 4130
4153 if(myrombase) return myrombase; 4131 if(myrombase) return myrombase;
4154#endif
4155 4132
4156 /* Otherwise do it the conventional way. */ 4133 /* Otherwise do it the conventional way. */
4157 4134
@@ -4225,7 +4202,7 @@ sisfb_post_map_vram(struct sis_video_info *ivideo, unsigned int *mapsize,
4225static int __devinit 4202static int __devinit
4226sisfb_post_300_buswidth(struct sis_video_info *ivideo) 4203sisfb_post_300_buswidth(struct sis_video_info *ivideo)
4227{ 4204{
4228 SIS_IOTYPE1 *FBAddress = ivideo->video_vbase; 4205 void __iomem *FBAddress = ivideo->video_vbase;
4229 unsigned short temp; 4206 unsigned short temp;
4230 unsigned char reg; 4207 unsigned char reg;
4231 int i, j; 4208 int i, j;
@@ -4273,7 +4250,7 @@ sisfb_post_300_rwtest(struct sis_video_info *ivideo, int iteration, int buswidth
4273 int PseudoRankCapacity, int PseudoAdrPinCount, 4250 int PseudoRankCapacity, int PseudoAdrPinCount,
4274 unsigned int mapsize) 4251 unsigned int mapsize)
4275{ 4252{
4276 SIS_IOTYPE1 *FBAddr = ivideo->video_vbase; 4253 void __iomem *FBAddr = ivideo->video_vbase;
4277 unsigned short sr14; 4254 unsigned short sr14;
4278 unsigned int k, RankCapacity, PageCapacity, BankNumHigh, BankNumMid; 4255 unsigned int k, RankCapacity, PageCapacity, BankNumHigh, BankNumMid;
4279 unsigned int PhysicalAdrOtherPage, PhysicalAdrHigh, PhysicalAdrHalfPage; 4256 unsigned int PhysicalAdrOtherPage, PhysicalAdrHigh, PhysicalAdrHalfPage;
@@ -5829,7 +5806,7 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5829 ivideo->engineok = 0; 5806 ivideo->engineok = 0;
5830 5807
5831 ivideo->sisfb_was_boot_device = 0; 5808 ivideo->sisfb_was_boot_device = 0;
5832#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)) 5809
5833 if(pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW) { 5810 if(pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW) {
5834 if(ivideo->sisvga_enabled) 5811 if(ivideo->sisvga_enabled)
5835 ivideo->sisfb_was_boot_device = 1; 5812 ivideo->sisfb_was_boot_device = 1;
@@ -5840,7 +5817,6 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5840 "as the primary VGA device\n"); 5817 "as the primary VGA device\n");
5841 } 5818 }
5842 } 5819 }
5843#endif
5844 5820
5845 ivideo->sisfb_parm_mem = sisfb_parm_mem; 5821 ivideo->sisfb_parm_mem = sisfb_parm_mem;
5846 ivideo->sisfb_accel = sisfb_accel; 5822 ivideo->sisfb_accel = sisfb_accel;
@@ -6010,7 +5986,7 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
6010 ivideo->modeprechange = reg & 0x7f; 5986 ivideo->modeprechange = reg & 0x7f;
6011 } else if(ivideo->sisvga_enabled) { 5987 } else if(ivideo->sisvga_enabled) {
6012#if defined(__i386__) || defined(__x86_64__) 5988#if defined(__i386__) || defined(__x86_64__)
6013 unsigned char SIS_IOTYPE2 *tt = ioremap(0x400, 0x100); 5989 unsigned char __iomem *tt = ioremap(0x400, 0x100);
6014 if(tt) { 5990 if(tt) {
6015 ivideo->modeprechange = readb(tt + 0x49); 5991 ivideo->modeprechange = readb(tt + 0x49);
6016 iounmap(tt); 5992 iounmap(tt);
@@ -6503,7 +6479,7 @@ static struct pci_driver sisfb_driver = {
6503 .remove = __devexit_p(sisfb_remove) 6479 .remove = __devexit_p(sisfb_remove)
6504}; 6480};
6505 6481
6506SISINITSTATIC int __init sisfb_init(void) 6482static int __init sisfb_init(void)
6507{ 6483{
6508#ifndef MODULE 6484#ifndef MODULE
6509 char *options = NULL; 6485 char *options = NULL;
diff --git a/drivers/video/sis/sis_main.h b/drivers/video/sis/sis_main.h
index 3e3b7fa05d6c..9540e977270e 100644
--- a/drivers/video/sis/sis_main.h
+++ b/drivers/video/sis/sis_main.h
@@ -665,11 +665,11 @@ static struct _customttable {
665 665
666/* Interface used by the world */ 666/* Interface used by the world */
667#ifndef MODULE 667#ifndef MODULE
668SISINITSTATIC int sisfb_setup(char *options); 668static int sisfb_setup(char *options);
669#endif 669#endif
670 670
671/* Interface to the low level console driver */ 671/* Interface to the low level console driver */
672SISINITSTATIC int sisfb_init(void); 672static int sisfb_init(void);
673 673
674/* fbdev routines */ 674/* fbdev routines */
675static int sisfb_get_fix(struct fb_fix_screeninfo *fix, int con, 675static int sisfb_get_fix(struct fb_fix_screeninfo *fix, int con,
diff --git a/drivers/video/sis/vgatypes.h b/drivers/video/sis/vgatypes.h
index b532fbd2b04c..81a22eaabfde 100644
--- a/drivers/video/sis/vgatypes.h
+++ b/drivers/video/sis/vgatypes.h
@@ -53,10 +53,6 @@
53#ifndef _VGATYPES_H_ 53#ifndef _VGATYPES_H_
54#define _VGATYPES_H_ 54#define _VGATYPES_H_
55 55
56#ifdef SIS_LINUX_KERNEL
57#include <linux/version.h>
58#endif
59
60#define SISIOMEMTYPE 56#define SISIOMEMTYPE
61 57
62#ifdef SIS_LINUX_KERNEL 58#ifdef SIS_LINUX_KERNEL
diff --git a/drivers/video/skeletonfb.c b/drivers/video/skeletonfb.c
index 62321458f71a..df5336561d13 100644
--- a/drivers/video/skeletonfb.c
+++ b/drivers/video/skeletonfb.c
@@ -675,13 +675,13 @@ static struct fb_ops xxxfb_ops = {
675 * Initialization 675 * Initialization
676 */ 676 */
677 677
678/* static int __init xxfb_probe (struct device *device) -- for platform devs */ 678/* static int __init xxfb_probe (struct platform_device *pdev) -- for platform devs */
679static int __devinit xxxfb_probe(struct pci_dev *dev, 679static int __devinit xxxfb_probe(struct pci_dev *dev,
680 const struct pci_device_id *ent) 680 const struct pci_device_id *ent)
681{ 681{
682 struct fb_info *info; 682 struct fb_info *info;
683 struct xxx_par *par; 683 struct xxx_par *par;
684 struct device* device = &dev->dev; /* for pci drivers */ 684 struct device *device = &dev->dev; /* or &pdev->dev */
685 int cmap_len, retval; 685 int cmap_len, retval;
686 686
687 /* 687 /*
@@ -824,18 +824,18 @@ static int __devinit xxxfb_probe(struct pci_dev *dev,
824 return -EINVAL; 824 return -EINVAL;
825 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, 825 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
826 info->fix.id); 826 info->fix.id);
827 pci_set_drvdata(dev, info); /* or dev_set_drvdata(device, info) */ 827 pci_set_drvdata(dev, info); /* or platform_set_drvdata(pdev, info) */
828 return 0; 828 return 0;
829} 829}
830 830
831 /* 831 /*
832 * Cleanup 832 * Cleanup
833 */ 833 */
834/* static void __devexit xxxfb_remove(struct device *device) */ 834/* static void __devexit xxxfb_remove(struct platform_device *pdev) */
835static void __devexit xxxfb_remove(struct pci_dev *dev) 835static void __devexit xxxfb_remove(struct pci_dev *dev)
836{ 836{
837 struct fb_info *info = pci_get_drvdata(dev); 837 struct fb_info *info = pci_get_drvdata(dev);
838 /* or dev_get_drvdata(device); */ 838 /* or platform_get_drvdata(pdev); */
839 839
840 if (info) { 840 if (info) {
841 unregister_framebuffer(info); 841 unregister_framebuffer(info);
@@ -961,18 +961,17 @@ static int xxxfb_resume(struct platform_dev *dev)
961#define xxxfb_resume NULL 961#define xxxfb_resume NULL
962#endif /* CONFIG_PM */ 962#endif /* CONFIG_PM */
963 963
964static struct device_driver xxxfb_driver = { 964static struct platform_device_driver xxxfb_driver = {
965 .name = "xxxfb",
966 .bus = &platform_bus_type,
967 .probe = xxxfb_probe, 965 .probe = xxxfb_probe,
968 .remove = xxxfb_remove, 966 .remove = xxxfb_remove,
969 .suspend = xxxfb_suspend, /* optional but recommended */ 967 .suspend = xxxfb_suspend, /* optional but recommended */
970 .resume = xxxfb_resume, /* optional but recommended */ 968 .resume = xxxfb_resume, /* optional but recommended */
969 .driver = {
970 .name = "xxxfb",
971 },
971}; 972};
972 973
973static struct platform_device xxxfb_device = { 974static struct platform_device *xxxfb_device;
974 .name = "xxxfb",
975};
976 975
977#ifndef MODULE 976#ifndef MODULE
978 /* 977 /*
@@ -1002,12 +1001,16 @@ static int __init xxxfb_init(void)
1002 return -ENODEV; 1001 return -ENODEV;
1003 xxxfb_setup(option); 1002 xxxfb_setup(option);
1004#endif 1003#endif
1005 ret = driver_register(&xxxfb_driver); 1004 ret = platform_driver_register(&xxxfb_driver);
1006 1005
1007 if (!ret) { 1006 if (!ret) {
1008 ret = platform_device_register(&xxxfb_device); 1007 xxxfb_device = platform_device_register_simple("xxxfb", 0,
1009 if (ret) 1008 NULL, 0);
1010 driver_unregister(&xxxfb_driver); 1009
1010 if (IS_ERR(xxxfb_device)) {
1011 platform_driver_unregister(&xxxfb_driver);
1012 ret = PTR_ERR(xxxfb_device);
1013 }
1011 } 1014 }
1012 1015
1013 return ret; 1016 return ret;
@@ -1015,8 +1018,8 @@ static int __init xxxfb_init(void)
1015 1018
1016static void __exit xxxfb_exit(void) 1019static void __exit xxxfb_exit(void)
1017{ 1020{
1018 platform_device_unregister(&xxxfb_device); 1021 platform_device_unregister(xxxfb_device);
1019 driver_unregister(&xxxfb_driver); 1022 platform_driver_unregister(&xxxfb_driver);
1020} 1023}
1021#endif /* CONFIG_PCI */ 1024#endif /* CONFIG_PCI */
1022 1025
diff --git a/drivers/video/sm501fb.c b/drivers/video/sm501fb.c
index 15d4a768b1f6..f94ae84a58cd 100644
--- a/drivers/video/sm501fb.c
+++ b/drivers/video/sm501fb.c
@@ -48,10 +48,15 @@ enum sm501_controller {
48 HEAD_PANEL = 1, 48 HEAD_PANEL = 1,
49}; 49};
50 50
51/* SM501 memory address */ 51/* SM501 memory address.
52 *
53 * This structure is used to track memory usage within the SM501 framebuffer
54 * allocation. The sm_addr field is stored as an offset as it is often used
55 * against both the physical and mapped addresses.
56 */
52struct sm501_mem { 57struct sm501_mem {
53 unsigned long size; 58 unsigned long size;
54 unsigned long sm_addr; 59 unsigned long sm_addr; /* offset from base of sm501 fb. */
55 void __iomem *k_addr; 60 void __iomem *k_addr;
56}; 61};
57 62
@@ -142,31 +147,68 @@ static inline void sm501fb_sync_regs(struct sm501fb_info *info)
142static int sm501_alloc_mem(struct sm501fb_info *inf, struct sm501_mem *mem, 147static int sm501_alloc_mem(struct sm501fb_info *inf, struct sm501_mem *mem,
143 unsigned int why, size_t size) 148 unsigned int why, size_t size)
144{ 149{
145 unsigned int ptr = 0; 150 struct sm501fb_par *par;
151 struct fb_info *fbi;
152 unsigned int ptr;
153 unsigned int end;
146 154
147 switch (why) { 155 switch (why) {
148 case SM501_MEMF_CURSOR: 156 case SM501_MEMF_CURSOR:
149 ptr = inf->fbmem_len - size; 157 ptr = inf->fbmem_len - size;
150 inf->fbmem_len = ptr; 158 inf->fbmem_len = ptr; /* adjust available memory. */
151 break; 159 break;
152 160
153 case SM501_MEMF_PANEL: 161 case SM501_MEMF_PANEL:
154 ptr = inf->fbmem_len - size; 162 ptr = inf->fbmem_len - size;
155 if (ptr < inf->fb[0]->fix.smem_len) 163 fbi = inf->fb[HEAD_CRT];
164
165 /* round down, some programs such as directfb do not draw
166 * 0,0 correctly unless the start is aligned to a page start.
167 */
168
169 if (ptr > 0)
170 ptr &= ~(PAGE_SIZE - 1);
171
172 if (fbi && ptr < fbi->fix.smem_len)
173 return -ENOMEM;
174
175 if (ptr < 0)
156 return -ENOMEM; 176 return -ENOMEM;
157 177
158 break; 178 break;
159 179
160 case SM501_MEMF_CRT: 180 case SM501_MEMF_CRT:
161 ptr = 0; 181 ptr = 0;
182
183 /* check to see if we have panel memory allocated
184 * which would put an limit on available memory. */
185
186 fbi = inf->fb[HEAD_PANEL];
187 if (fbi) {
188 par = fbi->par;
189 end = par->screen.k_addr ? par->screen.sm_addr : inf->fbmem_len;
190 } else
191 end = inf->fbmem_len;
192
193 if ((ptr + size) > end)
194 return -ENOMEM;
195
162 break; 196 break;
163 197
164 case SM501_MEMF_ACCEL: 198 case SM501_MEMF_ACCEL:
165 ptr = inf->fb[0]->fix.smem_len; 199 fbi = inf->fb[HEAD_CRT];
200 ptr = fbi ? fbi->fix.smem_len : 0;
201
202 fbi = inf->fb[HEAD_PANEL];
203 if (fbi) {
204 par = fbi->par;
205 end = par->screen.sm_addr;
206 } else
207 end = inf->fbmem_len;
166 208
167 if ((ptr + size) > 209 if ((ptr + size) > end)
168 (inf->fb[1]->fix.smem_start - inf->fbmem_res->start))
169 return -ENOMEM; 210 return -ENOMEM;
211
170 break; 212 break;
171 213
172 default: 214 default:
@@ -663,15 +705,25 @@ static void sm501fb_panel_power(struct sm501fb_info *fbi, int to)
663 sm501fb_sync_regs(fbi); 705 sm501fb_sync_regs(fbi);
664 mdelay(10); 706 mdelay(10);
665 707
708 /* VBIASEN */
709
666 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_VBIASEN)) { 710 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_VBIASEN)) {
667 control |= SM501_DC_PANEL_CONTROL_BIAS; /* VBIASEN */ 711 if (pd->flags & SM501FB_FLAG_PANEL_INV_VBIASEN)
712 control &= ~SM501_DC_PANEL_CONTROL_BIAS;
713 else
714 control |= SM501_DC_PANEL_CONTROL_BIAS;
715
668 writel(control, ctrl_reg); 716 writel(control, ctrl_reg);
669 sm501fb_sync_regs(fbi); 717 sm501fb_sync_regs(fbi);
670 mdelay(10); 718 mdelay(10);
671 } 719 }
672 720
673 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_FPEN)) { 721 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_FPEN)) {
674 control |= SM501_DC_PANEL_CONTROL_FPEN; 722 if (pd->flags & SM501FB_FLAG_PANEL_INV_FPEN)
723 control &= ~SM501_DC_PANEL_CONTROL_FPEN;
724 else
725 control |= SM501_DC_PANEL_CONTROL_FPEN;
726
675 writel(control, ctrl_reg); 727 writel(control, ctrl_reg);
676 sm501fb_sync_regs(fbi); 728 sm501fb_sync_regs(fbi);
677 mdelay(10); 729 mdelay(10);
@@ -679,14 +731,22 @@ static void sm501fb_panel_power(struct sm501fb_info *fbi, int to)
679 } else if (!to && (control & SM501_DC_PANEL_CONTROL_VDD) != 0) { 731 } else if (!to && (control & SM501_DC_PANEL_CONTROL_VDD) != 0) {
680 /* disable panel power */ 732 /* disable panel power */
681 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_FPEN)) { 733 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_FPEN)) {
682 control &= ~SM501_DC_PANEL_CONTROL_FPEN; 734 if (pd->flags & SM501FB_FLAG_PANEL_INV_FPEN)
735 control |= SM501_DC_PANEL_CONTROL_FPEN;
736 else
737 control &= ~SM501_DC_PANEL_CONTROL_FPEN;
738
683 writel(control, ctrl_reg); 739 writel(control, ctrl_reg);
684 sm501fb_sync_regs(fbi); 740 sm501fb_sync_regs(fbi);
685 mdelay(10); 741 mdelay(10);
686 } 742 }
687 743
688 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_VBIASEN)) { 744 if (!(pd->flags & SM501FB_FLAG_PANEL_NO_VBIASEN)) {
689 control &= ~SM501_DC_PANEL_CONTROL_BIAS; 745 if (pd->flags & SM501FB_FLAG_PANEL_INV_VBIASEN)
746 control |= SM501_DC_PANEL_CONTROL_BIAS;
747 else
748 control &= ~SM501_DC_PANEL_CONTROL_BIAS;
749
690 writel(control, ctrl_reg); 750 writel(control, ctrl_reg);
691 sm501fb_sync_regs(fbi); 751 sm501fb_sync_regs(fbi);
692 mdelay(10); 752 mdelay(10);
@@ -1210,39 +1270,6 @@ static struct fb_ops sm501fb_ops_pnl = {
1210 .fb_imageblit = cfb_imageblit, 1270 .fb_imageblit = cfb_imageblit,
1211}; 1271};
1212 1272
1213/* sm501fb_info_alloc
1214 *
1215 * creates and initialises an sm501fb_info structure
1216*/
1217
1218static struct sm501fb_info *sm501fb_info_alloc(struct fb_info *fbinfo_crt,
1219 struct fb_info *fbinfo_pnl)
1220{
1221 struct sm501fb_info *info;
1222 struct sm501fb_par *par;
1223
1224 info = kzalloc(sizeof(struct sm501fb_info), GFP_KERNEL);
1225 if (info) {
1226 /* set the references back */
1227
1228 par = fbinfo_crt->par;
1229 par->info = info;
1230 par->head = HEAD_CRT;
1231 fbinfo_crt->pseudo_palette = &par->pseudo_palette;
1232
1233 par = fbinfo_pnl->par;
1234 par->info = info;
1235 par->head = HEAD_PANEL;
1236 fbinfo_pnl->pseudo_palette = &par->pseudo_palette;
1237
1238 /* store the two fbs into our info */
1239 info->fb[HEAD_CRT] = fbinfo_crt;
1240 info->fb[HEAD_PANEL] = fbinfo_pnl;
1241 }
1242
1243 return info;
1244}
1245
1246/* sm501_init_cursor 1273/* sm501_init_cursor
1247 * 1274 *
1248 * initialise hw cursor parameters 1275 * initialise hw cursor parameters
@@ -1250,10 +1277,16 @@ static struct sm501fb_info *sm501fb_info_alloc(struct fb_info *fbinfo_crt,
1250 1277
1251static int sm501_init_cursor(struct fb_info *fbi, unsigned int reg_base) 1278static int sm501_init_cursor(struct fb_info *fbi, unsigned int reg_base)
1252{ 1279{
1253 struct sm501fb_par *par = fbi->par; 1280 struct sm501fb_par *par;
1254 struct sm501fb_info *info = par->info; 1281 struct sm501fb_info *info;
1255 int ret; 1282 int ret;
1256 1283
1284 if (fbi == NULL)
1285 return 0;
1286
1287 par = fbi->par;
1288 info = par->info;
1289
1257 par->cursor_regs = info->regs + reg_base; 1290 par->cursor_regs = info->regs + reg_base;
1258 1291
1259 ret = sm501_alloc_mem(info, &par->cursor, SM501_MEMF_CURSOR, 1024); 1292 ret = sm501_alloc_mem(info, &par->cursor, SM501_MEMF_CURSOR, 1024);
@@ -1281,13 +1314,10 @@ static int sm501fb_start(struct sm501fb_info *info,
1281 struct platform_device *pdev) 1314 struct platform_device *pdev)
1282{ 1315{
1283 struct resource *res; 1316 struct resource *res;
1284 struct device *dev; 1317 struct device *dev = &pdev->dev;
1285 int k; 1318 int k;
1286 int ret; 1319 int ret;
1287 1320
1288 info->dev = dev = &pdev->dev;
1289 platform_set_drvdata(pdev, info);
1290
1291 info->irq = ret = platform_get_irq(pdev, 0); 1321 info->irq = ret = platform_get_irq(pdev, 0);
1292 if (ret < 0) { 1322 if (ret < 0) {
1293 /* we currently do not use the IRQ */ 1323 /* we currently do not use the IRQ */
@@ -1390,11 +1420,6 @@ static void sm501fb_stop(struct sm501fb_info *info)
1390 kfree(info->regs_res); 1420 kfree(info->regs_res);
1391} 1421}
1392 1422
1393static void sm501fb_info_release(struct sm501fb_info *info)
1394{
1395 kfree(info);
1396}
1397
1398static int sm501fb_init_fb(struct fb_info *fb, 1423static int sm501fb_init_fb(struct fb_info *fb,
1399 enum sm501_controller head, 1424 enum sm501_controller head,
1400 const char *fbname) 1425 const char *fbname)
@@ -1539,36 +1564,93 @@ static struct sm501_platdata_fb sm501fb_def_pdata = {
1539static char driver_name_crt[] = "sm501fb-crt"; 1564static char driver_name_crt[] = "sm501fb-crt";
1540static char driver_name_pnl[] = "sm501fb-panel"; 1565static char driver_name_pnl[] = "sm501fb-panel";
1541 1566
1542static int __init sm501fb_probe(struct platform_device *pdev) 1567static int __devinit sm501fb_probe_one(struct sm501fb_info *info,
1568 enum sm501_controller head)
1543{ 1569{
1544 struct sm501fb_info *info; 1570 unsigned char *name = (head == HEAD_CRT) ? "crt" : "panel";
1545 struct device *dev = &pdev->dev; 1571 struct sm501_platdata_fbsub *pd;
1546 struct fb_info *fbinfo_crt; 1572 struct sm501fb_par *par;
1547 struct fb_info *fbinfo_pnl; 1573 struct fb_info *fbi;
1548 int ret;
1549 1574
1550 /* allocate our framebuffers */ 1575 pd = (head == HEAD_CRT) ? info->pdata->fb_crt : info->pdata->fb_pnl;
1576
1577 /* Do not initialise if we've not been given any platform data */
1578 if (pd == NULL) {
1579 dev_info(info->dev, "no data for fb %s (disabled)\n", name);
1580 return 0;
1581 }
1551 1582
1552 fbinfo_crt = framebuffer_alloc(sizeof(struct sm501fb_par), dev); 1583 fbi = framebuffer_alloc(sizeof(struct sm501fb_par), info->dev);
1553 if (fbinfo_crt == NULL) { 1584 if (fbi == NULL) {
1554 dev_err(dev, "cannot allocate crt framebuffer\n"); 1585 dev_err(info->dev, "cannot allocate %s framebuffer\n", name);
1555 return -ENOMEM; 1586 return -ENOMEM;
1556 } 1587 }
1557 1588
1558 fbinfo_pnl = framebuffer_alloc(sizeof(struct sm501fb_par), dev); 1589 par = fbi->par;
1559 if (fbinfo_pnl == NULL) { 1590 par->info = info;
1560 dev_err(dev, "cannot allocate panel framebuffer\n"); 1591 par->head = head;
1561 ret = -ENOMEM; 1592 fbi->pseudo_palette = &par->pseudo_palette;
1562 goto fbinfo_crt_alloc_fail; 1593
1594 info->fb[head] = fbi;
1595
1596 return 0;
1597}
1598
1599/* Free up anything allocated by sm501fb_init_fb */
1600
1601static void sm501_free_init_fb(struct sm501fb_info *info,
1602 enum sm501_controller head)
1603{
1604 struct fb_info *fbi = info->fb[head];
1605
1606 fb_dealloc_cmap(&fbi->cmap);
1607}
1608
1609static int __devinit sm501fb_start_one(struct sm501fb_info *info,
1610 enum sm501_controller head,
1611 const char *drvname)
1612{
1613 struct fb_info *fbi = info->fb[head];
1614 int ret;
1615
1616 if (!fbi)
1617 return 0;
1618
1619 ret = sm501fb_init_fb(info->fb[head], head, drvname);
1620 if (ret) {
1621 dev_err(info->dev, "cannot initialise fb %s\n", drvname);
1622 return ret;
1623 }
1624
1625 ret = register_framebuffer(info->fb[head]);
1626 if (ret) {
1627 dev_err(info->dev, "failed to register fb %s\n", drvname);
1628 sm501_free_init_fb(info, head);
1629 return ret;
1563 } 1630 }
1564 1631
1565 info = sm501fb_info_alloc(fbinfo_crt, fbinfo_pnl); 1632 dev_info(info->dev, "fb%d: %s frame buffer\n", fbi->node, fbi->fix.id);
1566 if (info == NULL) { 1633
1567 dev_err(dev, "cannot allocate par\n"); 1634 return 0;
1568 ret = -ENOMEM; 1635}
1569 goto sm501fb_alloc_fail; 1636
1637static int __devinit sm501fb_probe(struct platform_device *pdev)
1638{
1639 struct sm501fb_info *info;
1640 struct device *dev = &pdev->dev;
1641 int ret;
1642
1643 /* allocate our framebuffers */
1644
1645 info = kzalloc(sizeof(struct sm501fb_info), GFP_KERNEL);
1646 if (!info) {
1647 dev_err(dev, "failed to allocate state\n");
1648 return -ENOMEM;
1570 } 1649 }
1571 1650
1651 info->dev = dev = &pdev->dev;
1652 platform_set_drvdata(pdev, info);
1653
1572 if (dev->parent->platform_data) { 1654 if (dev->parent->platform_data) {
1573 struct sm501_platdata *pd = dev->parent->platform_data; 1655 struct sm501_platdata *pd = dev->parent->platform_data;
1574 info->pdata = pd->fb; 1656 info->pdata = pd->fb;
@@ -1579,90 +1661,88 @@ static int __init sm501fb_probe(struct platform_device *pdev)
1579 info->pdata = &sm501fb_def_pdata; 1661 info->pdata = &sm501fb_def_pdata;
1580 } 1662 }
1581 1663
1582 /* start the framebuffers */ 1664 /* probe for the presence of each panel */
1583 1665
1584 ret = sm501fb_start(info, pdev); 1666 ret = sm501fb_probe_one(info, HEAD_CRT);
1585 if (ret) { 1667 if (ret < 0) {
1586 dev_err(dev, "cannot initialise SM501\n"); 1668 dev_err(dev, "failed to probe CRT\n");
1587 goto sm501fb_start_fail; 1669 goto err_alloc;
1588 } 1670 }
1589 1671
1590 /* CRT framebuffer setup */ 1672 ret = sm501fb_probe_one(info, HEAD_PANEL);
1673 if (ret < 0) {
1674 dev_err(dev, "failed to probe PANEL\n");
1675 goto err_probed_crt;
1676 }
1591 1677
1592 ret = sm501fb_init_fb(fbinfo_crt, HEAD_CRT, driver_name_crt); 1678 if (info->fb[HEAD_PANEL] == NULL &&
1593 if (ret) { 1679 info->fb[HEAD_CRT] == NULL) {
1594 dev_err(dev, "cannot initialise CRT fb\n"); 1680 dev_err(dev, "no framebuffers found\n");
1595 goto sm501fb_start_fail; 1681 goto err_alloc;
1596 } 1682 }
1597 1683
1598 /* Panel framebuffer setup */ 1684 /* get the resources for both of the framebuffers */
1599 1685
1600 ret = sm501fb_init_fb(fbinfo_pnl, HEAD_PANEL, driver_name_pnl); 1686 ret = sm501fb_start(info, pdev);
1601 if (ret) { 1687 if (ret) {
1602 dev_err(dev, "cannot initialise Panel fb\n"); 1688 dev_err(dev, "cannot initialise SM501\n");
1603 goto sm501fb_start_fail; 1689 goto err_probed_panel;
1604 } 1690 }
1605 1691
1606 /* register framebuffers */ 1692 ret = sm501fb_start_one(info, HEAD_CRT, driver_name_crt);
1607 1693 if (ret) {
1608 ret = register_framebuffer(fbinfo_crt); 1694 dev_err(dev, "failed to start CRT\n");
1609 if (ret < 0) { 1695 goto err_started;
1610 dev_err(dev, "failed to register CRT fb (%d)\n", ret);
1611 goto register_crt_fail;
1612 } 1696 }
1613 1697
1614 ret = register_framebuffer(fbinfo_pnl); 1698 ret = sm501fb_start_one(info, HEAD_PANEL, driver_name_pnl);
1615 if (ret < 0) { 1699 if (ret) {
1616 dev_err(dev, "failed to register panel fb (%d)\n", ret); 1700 dev_err(dev, "failed to start Panel\n");
1617 goto register_pnl_fail; 1701 goto err_started_crt;
1618 } 1702 }
1619 1703
1620 dev_info(dev, "fb%d: %s frame buffer device\n",
1621 fbinfo_crt->node, fbinfo_crt->fix.id);
1622
1623 dev_info(dev, "fb%d: %s frame buffer device\n",
1624 fbinfo_pnl->node, fbinfo_pnl->fix.id);
1625
1626 /* create device files */ 1704 /* create device files */
1627 1705
1628 ret = device_create_file(dev, &dev_attr_crt_src); 1706 ret = device_create_file(dev, &dev_attr_crt_src);
1629 if (ret) 1707 if (ret)
1630 goto crtsrc_fail; 1708 goto err_started_panel;
1631 1709
1632 ret = device_create_file(dev, &dev_attr_fbregs_pnl); 1710 ret = device_create_file(dev, &dev_attr_fbregs_pnl);
1633 if (ret) 1711 if (ret)
1634 goto fbregs_pnl_fail; 1712 goto err_attached_crtsrc_file;
1635 1713
1636 ret = device_create_file(dev, &dev_attr_fbregs_crt); 1714 ret = device_create_file(dev, &dev_attr_fbregs_crt);
1637 if (ret) 1715 if (ret)
1638 goto fbregs_crt_fail; 1716 goto err_attached_pnlregs_file;
1639 1717
1640 /* we registered, return ok */ 1718 /* we registered, return ok */
1641 return 0; 1719 return 0;
1642 1720
1643 fbregs_crt_fail: 1721err_attached_pnlregs_file:
1644 device_remove_file(dev, &dev_attr_fbregs_pnl); 1722 device_remove_file(dev, &dev_attr_fbregs_pnl);
1645 1723
1646 fbregs_pnl_fail: 1724err_attached_crtsrc_file:
1647 device_remove_file(dev, &dev_attr_crt_src); 1725 device_remove_file(dev, &dev_attr_crt_src);
1648 1726
1649 crtsrc_fail: 1727err_started_panel:
1650 unregister_framebuffer(fbinfo_pnl); 1728 unregister_framebuffer(info->fb[HEAD_PANEL]);
1729 sm501_free_init_fb(info, HEAD_PANEL);
1651 1730
1652 register_pnl_fail: 1731err_started_crt:
1653 unregister_framebuffer(fbinfo_crt); 1732 unregister_framebuffer(info->fb[HEAD_CRT]);
1733 sm501_free_init_fb(info, HEAD_CRT);
1654 1734
1655 register_crt_fail: 1735err_started:
1656 sm501fb_stop(info); 1736 sm501fb_stop(info);
1657 1737
1658 sm501fb_start_fail: 1738err_probed_panel:
1659 sm501fb_info_release(info); 1739 framebuffer_release(info->fb[HEAD_PANEL]);
1660 1740
1661 sm501fb_alloc_fail: 1741err_probed_crt:
1662 framebuffer_release(fbinfo_pnl); 1742 framebuffer_release(info->fb[HEAD_CRT]);
1663 1743
1664 fbinfo_crt_alloc_fail: 1744err_alloc:
1665 framebuffer_release(fbinfo_crt); 1745 kfree(info);
1666 1746
1667 return ret; 1747 return ret;
1668} 1748}
@@ -1681,11 +1761,14 @@ static int sm501fb_remove(struct platform_device *pdev)
1681 device_remove_file(&pdev->dev, &dev_attr_fbregs_pnl); 1761 device_remove_file(&pdev->dev, &dev_attr_fbregs_pnl);
1682 device_remove_file(&pdev->dev, &dev_attr_crt_src); 1762 device_remove_file(&pdev->dev, &dev_attr_crt_src);
1683 1763
1764 sm501_free_init_fb(info, HEAD_CRT);
1765 sm501_free_init_fb(info, HEAD_PANEL);
1766
1684 unregister_framebuffer(fbinfo_crt); 1767 unregister_framebuffer(fbinfo_crt);
1685 unregister_framebuffer(fbinfo_pnl); 1768 unregister_framebuffer(fbinfo_pnl);
1686 1769
1687 sm501fb_stop(info); 1770 sm501fb_stop(info);
1688 sm501fb_info_release(info); 1771 kfree(info);
1689 1772
1690 framebuffer_release(fbinfo_pnl); 1773 framebuffer_release(fbinfo_pnl);
1691 framebuffer_release(fbinfo_crt); 1774 framebuffer_release(fbinfo_crt);
diff --git a/drivers/video/sticore.h b/drivers/video/sticore.h
index 1a9a60c74be3..7fe5be4bc70e 100644
--- a/drivers/video/sticore.h
+++ b/drivers/video/sticore.h
@@ -352,8 +352,6 @@ struct sti_struct *sti_get_rom(unsigned int index); /* 0: default sti */
352 352
353/* functions to call the STI ROM directly */ 353/* functions to call the STI ROM directly */
354 354
355int sti_init_graph(struct sti_struct *sti);
356void sti_inq_conf(struct sti_struct *sti);
357void sti_putc(struct sti_struct *sti, int c, int y, int x); 355void sti_putc(struct sti_struct *sti, int c, int y, int x);
358void sti_set(struct sti_struct *sti, int src_y, int src_x, 356void sti_set(struct sti_struct *sti, int src_y, int src_x,
359 int height, int width, u8 color); 357 int height, int width, u8 color);
diff --git a/drivers/video/stifb.c b/drivers/video/stifb.c
index 598d35eff935..166481402412 100644
--- a/drivers/video/stifb.c
+++ b/drivers/video/stifb.c
@@ -1078,8 +1078,7 @@ static struct fb_ops stifb_ops = {
1078 * Initialization 1078 * Initialization
1079 */ 1079 */
1080 1080
1081int __init 1081static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
1082stifb_init_fb(struct sti_struct *sti, int bpp_pref)
1083{ 1082{
1084 struct fb_fix_screeninfo *fix; 1083 struct fb_fix_screeninfo *fix;
1085 struct fb_var_screeninfo *var; 1084 struct fb_var_screeninfo *var;
@@ -1315,8 +1314,7 @@ static int stifb_disabled __initdata;
1315int __init 1314int __init
1316stifb_setup(char *options); 1315stifb_setup(char *options);
1317 1316
1318int __init 1317static int __init stifb_init(void)
1319stifb_init(void)
1320{ 1318{
1321 struct sti_struct *sti; 1319 struct sti_struct *sti;
1322 struct sti_struct *def_sti; 1320 struct sti_struct *def_sti;
diff --git a/drivers/video/tdfxfb.c b/drivers/video/tdfxfb.c
index ea9f19d25597..77aafcfae037 100644
--- a/drivers/video/tdfxfb.c
+++ b/drivers/video/tdfxfb.c
@@ -836,16 +836,12 @@ static int tdfxfb_pan_display(struct fb_var_screeninfo *var,
836 struct tdfx_par *par = info->par; 836 struct tdfx_par *par = info->par;
837 u32 addr = var->yoffset * info->fix.line_length; 837 u32 addr = var->yoffset * info->fix.line_length;
838 838
839 if (nopan || var->xoffset || (var->yoffset > var->yres_virtual)) 839 if (nopan || var->xoffset)
840 return -EINVAL;
841 if ((var->yoffset + var->yres > var->yres_virtual && nowrap))
842 return -EINVAL; 840 return -EINVAL;
843 841
844 banshee_make_room(par, 1); 842 banshee_make_room(par, 1);
845 tdfx_outl(par, VIDDESKSTART, addr); 843 tdfx_outl(par, VIDDESKSTART, addr);
846 844
847 info->var.xoffset = var->xoffset;
848 info->var.yoffset = var->yoffset;
849 return 0; 845 return 0;
850} 846}
851 847
@@ -1426,6 +1422,8 @@ MODULE_LICENSE("GPL");
1426module_param(hwcursor, int, 0644); 1422module_param(hwcursor, int, 0644);
1427MODULE_PARM_DESC(hwcursor, "Enable hardware cursor " 1423MODULE_PARM_DESC(hwcursor, "Enable hardware cursor "
1428 "(1=enable, 0=disable, default=1)"); 1424 "(1=enable, 0=disable, default=1)");
1425module_param(mode_option, charp, 0);
1426MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
1429#ifdef CONFIG_MTRR 1427#ifdef CONFIG_MTRR
1430module_param(nomtrr, bool, 0); 1428module_param(nomtrr, bool, 0);
1431MODULE_PARM_DESC(nomtrr, "Disable MTRR support (default: enabled)"); 1429MODULE_PARM_DESC(nomtrr, "Disable MTRR support (default: enabled)");
diff --git a/drivers/video/tridentfb.c b/drivers/video/tridentfb.c
index beefab2992c0..479b2e79ad68 100644
--- a/drivers/video/tridentfb.c
+++ b/drivers/video/tridentfb.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Frame buffer driver for Trident Blade and Image series 2 * Frame buffer driver for Trident TGUI, Blade and Image series
3 * 3 *
4 * Copyright 2001, 2002 - Jani Monoses <jani@iv.ro> 4 * Copyright 2001, 2002 - Jani Monoses <jani@iv.ro>
5 * 5 *
@@ -13,7 +13,6 @@
13 * code, suggestions 13 * code, suggestions
14 * TODO: 14 * TODO:
15 * timing value tweaking so it looks good on every monitor in every mode 15 * timing value tweaking so it looks good on every monitor in every mode
16 * TGUI acceleration
17 */ 16 */
18 17
19#include <linux/module.h> 18#include <linux/module.h>
@@ -22,25 +21,26 @@
22#include <linux/pci.h> 21#include <linux/pci.h>
23 22
24#include <linux/delay.h> 23#include <linux/delay.h>
24#include <video/vga.h>
25#include <video/trident.h> 25#include <video/trident.h>
26 26
27#define VERSION "0.7.8-NEWAPI"
28
29struct tridentfb_par { 27struct tridentfb_par {
30 void __iomem *io_virt; /* iospace virtual memory address */ 28 void __iomem *io_virt; /* iospace virtual memory address */
29 u32 pseudo_pal[16];
30 int chip_id;
31 int flatpanel;
32 void (*init_accel) (struct tridentfb_par *, int, int);
33 void (*wait_engine) (struct tridentfb_par *);
34 void (*fill_rect)
35 (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32);
36 void (*copy_rect)
37 (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32);
38 void (*image_blit)
39 (struct tridentfb_par *par, const char*,
40 u32, u32, u32, u32, u32, u32);
41 unsigned char eng_oper; /* engine operation... */
31}; 42};
32 43
33static unsigned char eng_oper; /* engine operation... */
34static struct fb_ops tridentfb_ops;
35
36static struct tridentfb_par default_par;
37
38/* FIXME:kmalloc these 3 instead */
39static struct fb_info fb_info;
40static u32 pseudo_pal[16];
41
42static struct fb_var_screeninfo default_var;
43
44static struct fb_fix_screeninfo tridentfb_fix = { 44static struct fb_fix_screeninfo tridentfb_fix = {
45 .id = "Trident", 45 .id = "Trident",
46 .type = FB_TYPE_PACKED_PIXELS, 46 .type = FB_TYPE_PACKED_PIXELS,
@@ -49,27 +49,22 @@ static struct fb_fix_screeninfo tridentfb_fix = {
49 .accel = FB_ACCEL_NONE, 49 .accel = FB_ACCEL_NONE,
50}; 50};
51 51
52static int chip_id;
53
54static int defaultaccel;
55static int displaytype;
56
57/* defaults which are normally overriden by user values */ 52/* defaults which are normally overriden by user values */
58 53
59/* video mode */ 54/* video mode */
60static char *mode_option __devinitdata = "640x480"; 55static char *mode_option __devinitdata = "640x480-8@60";
61static int bpp = 8; 56static int bpp __devinitdata = 8;
62 57
63static int noaccel; 58static int noaccel __devinitdata;
64 59
65static int center; 60static int center;
66static int stretch; 61static int stretch;
67 62
68static int fp; 63static int fp __devinitdata;
69static int crt; 64static int crt __devinitdata;
70 65
71static int memsize; 66static int memsize __devinitdata;
72static int memdiff; 67static int memdiff __devinitdata;
73static int nativex; 68static int nativex;
74 69
75module_param(mode_option, charp, 0); 70module_param(mode_option, charp, 0);
@@ -84,25 +79,53 @@ module_param(memsize, int, 0);
84module_param(memdiff, int, 0); 79module_param(memdiff, int, 0);
85module_param(nativex, int, 0); 80module_param(nativex, int, 0);
86module_param(fp, int, 0); 81module_param(fp, int, 0);
82MODULE_PARM_DESC(fp, "Define if flatpanel is connected");
87module_param(crt, int, 0); 83module_param(crt, int, 0);
84MODULE_PARM_DESC(crt, "Define if CRT is connected");
85
86static inline int is_oldclock(int id)
87{
88 return (id == TGUI9440) ||
89 (id == TGUI9660) ||
90 (id == CYBER9320);
91}
92
93static inline int is_oldprotect(int id)
94{
95 return is_oldclock(id) ||
96 (id == PROVIDIA9685) ||
97 (id == CYBER9382) ||
98 (id == CYBER9385);
99}
100
101static inline int is_blade(int id)
102{
103 return (id == BLADE3D) ||
104 (id == CYBERBLADEE4) ||
105 (id == CYBERBLADEi7) ||
106 (id == CYBERBLADEi7D) ||
107 (id == CYBERBLADEi1) ||
108 (id == CYBERBLADEi1D) ||
109 (id == CYBERBLADEAi1) ||
110 (id == CYBERBLADEAi1D);
111}
88 112
89static int chip3D; 113static inline int is_xp(int id)
90static int chipcyber; 114{
115 return (id == CYBERBLADEXPAi1) ||
116 (id == CYBERBLADEXPm8) ||
117 (id == CYBERBLADEXPm16);
118}
91 119
92static int is3Dchip(int id) 120static inline int is3Dchip(int id)
93{ 121{
94 return ((id == BLADE3D) || (id == CYBERBLADEE4) || 122 return is_blade(id) || is_xp(id) ||
95 (id == CYBERBLADEi7) || (id == CYBERBLADEi7D) ||
96 (id == CYBER9397) || (id == CYBER9397DVD) || 123 (id == CYBER9397) || (id == CYBER9397DVD) ||
97 (id == CYBER9520) || (id == CYBER9525DVD) || 124 (id == CYBER9520) || (id == CYBER9525DVD) ||
98 (id == IMAGE975) || (id == IMAGE985) || 125 (id == IMAGE975) || (id == IMAGE985);
99 (id == CYBERBLADEi1) || (id == CYBERBLADEi1D) ||
100 (id == CYBERBLADEAi1) || (id == CYBERBLADEAi1D) ||
101 (id == CYBERBLADEXPm8) || (id == CYBERBLADEXPm16) ||
102 (id == CYBERBLADEXPAi1));
103} 126}
104 127
105static int iscyber(int id) 128static inline int iscyber(int id)
106{ 129{
107 switch (id) { 130 switch (id) {
108 case CYBER9388: 131 case CYBER9388:
@@ -122,12 +145,7 @@ static int iscyber(int id)
122 return 1; 145 return 1;
123 146
124 case CYBER9320: 147 case CYBER9320:
125 case TGUI9660:
126 case IMAGE975:
127 case IMAGE985:
128 case BLADE3D:
129 case CYBERBLADEi7: /* VIA MPV4 integrated version */ 148 case CYBERBLADEi7: /* VIA MPV4 integrated version */
130
131 default: 149 default:
132 /* case CYBERBLDAEXPm8: Strange */ 150 /* case CYBERBLDAEXPm8: Strange */
133 /* case CYBERBLDAEXPm16: Strange */ 151 /* case CYBERBLDAEXPm16: Strange */
@@ -135,147 +153,110 @@ static int iscyber(int id)
135 } 153 }
136} 154}
137 155
138#define CRT 0x3D0 /* CRTC registers offset for color display */ 156static inline void t_outb(struct tridentfb_par *p, u8 val, u16 reg)
139 157{
140#ifndef TRIDENT_MMIO 158 fb_writeb(val, p->io_virt + reg);
141 #define TRIDENT_MMIO 1 159}
142#endif
143
144#if TRIDENT_MMIO
145 #define t_outb(val, reg) writeb(val,((struct tridentfb_par *)(fb_info.par))->io_virt + reg)
146 #define t_inb(reg) readb(((struct tridentfb_par*)(fb_info.par))->io_virt + reg)
147#else
148 #define t_outb(val, reg) outb(val, reg)
149 #define t_inb(reg) inb(reg)
150#endif
151 160
161static inline u8 t_inb(struct tridentfb_par *p, u16 reg)
162{
163 return fb_readb(p->io_virt + reg);
164}
152 165
153static struct accel_switch { 166static inline void writemmr(struct tridentfb_par *par, u16 r, u32 v)
154 void (*init_accel) (int, int); 167{
155 void (*wait_engine) (void); 168 fb_writel(v, par->io_virt + r);
156 void (*fill_rect) (u32, u32, u32, u32, u32, u32); 169}
157 void (*copy_rect) (u32, u32, u32, u32, u32, u32);
158} *acc;
159 170
160#define writemmr(r, v) writel(v, ((struct tridentfb_par *)fb_info.par)->io_virt + r) 171static inline u32 readmmr(struct tridentfb_par *par, u16 r)
161#define readmmr(r) readl(((struct tridentfb_par *)fb_info.par)->io_virt + r) 172{
173 return fb_readl(par->io_virt + r);
174}
162 175
163/* 176/*
164 * Blade specific acceleration. 177 * Blade specific acceleration.
165 */ 178 */
166 179
167#define point(x, y) ((y) << 16 | (x)) 180#define point(x, y) ((y) << 16 | (x))
168#define STA 0x2120 181
169#define CMD 0x2144 182static void blade_init_accel(struct tridentfb_par *par, int pitch, int bpp)
170#define ROP 0x2148
171#define CLR 0x2160
172#define SR1 0x2100
173#define SR2 0x2104
174#define DR1 0x2108
175#define DR2 0x210C
176
177#define ROP_S 0xCC
178
179static void blade_init_accel(int pitch, int bpp)
180{ 183{
181 int v1 = (pitch >> 3) << 20; 184 int v1 = (pitch >> 3) << 20;
182 int tmp = 0, v2; 185 int tmp = bpp == 24 ? 2 : (bpp >> 4);
183 switch (bpp) { 186 int v2 = v1 | (tmp << 29);
184 case 8: 187
185 tmp = 0; 188 writemmr(par, 0x21C0, v2);
186 break; 189 writemmr(par, 0x21C4, v2);
187 case 15: 190 writemmr(par, 0x21B8, v2);
188 tmp = 5; 191 writemmr(par, 0x21BC, v2);
189 break; 192 writemmr(par, 0x21D0, v1);
190 case 16: 193 writemmr(par, 0x21D4, v1);
191 tmp = 1; 194 writemmr(par, 0x21C8, v1);
192 break; 195 writemmr(par, 0x21CC, v1);
193 case 24: 196 writemmr(par, 0x216C, 0);
194 case 32:
195 tmp = 2;
196 break;
197 }
198 v2 = v1 | (tmp << 29);
199 writemmr(0x21C0, v2);
200 writemmr(0x21C4, v2);
201 writemmr(0x21B8, v2);
202 writemmr(0x21BC, v2);
203 writemmr(0x21D0, v1);
204 writemmr(0x21D4, v1);
205 writemmr(0x21C8, v1);
206 writemmr(0x21CC, v1);
207 writemmr(0x216C, 0);
208} 197}
209 198
210static void blade_wait_engine(void) 199static void blade_wait_engine(struct tridentfb_par *par)
211{ 200{
212 while (readmmr(STA) & 0xFA800000) ; 201 while (readmmr(par, STATUS) & 0xFA800000)
202 cpu_relax();
213} 203}
214 204
215static void blade_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop) 205static void blade_fill_rect(struct tridentfb_par *par,
206 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
216{ 207{
217 writemmr(CLR, c); 208 writemmr(par, COLOR, c);
218 writemmr(ROP, rop ? 0x66 : ROP_S); 209 writemmr(par, ROP, rop ? ROP_X : ROP_S);
219 writemmr(CMD, 0x20000000 | 1 << 19 | 1 << 4 | 2 << 2); 210 writemmr(par, CMD, 0x20000000 | 1 << 19 | 1 << 4 | 2 << 2);
220 211
221 writemmr(DR1, point(x, y)); 212 writemmr(par, DST1, point(x, y));
222 writemmr(DR2, point(x + w - 1, y + h - 1)); 213 writemmr(par, DST2, point(x + w - 1, y + h - 1));
223} 214}
224 215
225static void blade_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h) 216static void blade_image_blit(struct tridentfb_par *par, const char *data,
217 u32 x, u32 y, u32 w, u32 h, u32 c, u32 b)
218{
219 unsigned size = ((w + 31) >> 5) * h;
220
221 writemmr(par, COLOR, c);
222 writemmr(par, BGCOLOR, b);
223 writemmr(par, CMD, 0xa0000000 | 3 << 19);
224
225 writemmr(par, DST1, point(x, y));
226 writemmr(par, DST2, point(x + w - 1, y + h - 1));
227
228 memcpy(par->io_virt + 0x10000, data, 4 * size);
229}
230
231static void blade_copy_rect(struct tridentfb_par *par,
232 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
226{ 233{
227 u32 s1, s2, d1, d2;
228 int direction = 2; 234 int direction = 2;
229 s1 = point(x1, y1); 235 u32 s1 = point(x1, y1);
230 s2 = point(x1 + w - 1, y1 + h - 1); 236 u32 s2 = point(x1 + w - 1, y1 + h - 1);
231 d1 = point(x2, y2); 237 u32 d1 = point(x2, y2);
232 d2 = point(x2 + w - 1, y2 + h - 1); 238 u32 d2 = point(x2 + w - 1, y2 + h - 1);
233 239
234 if ((y1 > y2) || ((y1 == y2) && (x1 > x2))) 240 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
235 direction = 0; 241 direction = 0;
236 242
237 writemmr(ROP, ROP_S); 243 writemmr(par, ROP, ROP_S);
238 writemmr(CMD, 0xE0000000 | 1 << 19 | 1 << 4 | 1 << 2 | direction); 244 writemmr(par, CMD, 0xE0000000 | 1 << 19 | 1 << 4 | 1 << 2 | direction);
239 245
240 writemmr(SR1, direction ? s2 : s1); 246 writemmr(par, SRC1, direction ? s2 : s1);
241 writemmr(SR2, direction ? s1 : s2); 247 writemmr(par, SRC2, direction ? s1 : s2);
242 writemmr(DR1, direction ? d2 : d1); 248 writemmr(par, DST1, direction ? d2 : d1);
243 writemmr(DR2, direction ? d1 : d2); 249 writemmr(par, DST2, direction ? d1 : d2);
244} 250}
245 251
246static struct accel_switch accel_blade = {
247 blade_init_accel,
248 blade_wait_engine,
249 blade_fill_rect,
250 blade_copy_rect,
251};
252
253/* 252/*
254 * BladeXP specific acceleration functions 253 * BladeXP specific acceleration functions
255 */ 254 */
256 255
257#define ROP_P 0xF0 256static void xp_init_accel(struct tridentfb_par *par, int pitch, int bpp)
258#define masked_point(x, y) ((y & 0xffff)<<16|(x & 0xffff))
259
260static void xp_init_accel(int pitch, int bpp)
261{ 257{
262 int tmp = 0, v1; 258 unsigned char x = bpp == 24 ? 3 : (bpp >> 4);
263 unsigned char x = 0; 259 int v1 = pitch << (bpp == 24 ? 20 : (18 + x));
264
265 switch (bpp) {
266 case 8:
267 x = 0;
268 break;
269 case 16:
270 x = 1;
271 break;
272 case 24:
273 x = 3;
274 break;
275 case 32:
276 x = 2;
277 break;
278 }
279 260
280 switch (pitch << (bpp >> 3)) { 261 switch (pitch << (bpp >> 3)) {
281 case 8192: 262 case 8192:
@@ -293,42 +274,21 @@ static void xp_init_accel(int pitch, int bpp)
293 break; 274 break;
294 } 275 }
295 276
296 t_outb(x, 0x2125); 277 t_outb(par, x, 0x2125);
297
298 eng_oper = x | 0x40;
299
300 switch (bpp) {
301 case 8:
302 tmp = 18;
303 break;
304 case 15:
305 case 16:
306 tmp = 19;
307 break;
308 case 24:
309 case 32:
310 tmp = 20;
311 break;
312 }
313 278
314 v1 = pitch << tmp; 279 par->eng_oper = x | 0x40;
315 280
316 writemmr(0x2154, v1); 281 writemmr(par, 0x2154, v1);
317 writemmr(0x2150, v1); 282 writemmr(par, 0x2150, v1);
318 t_outb(3, 0x2126); 283 t_outb(par, 3, 0x2126);
319} 284}
320 285
321static void xp_wait_engine(void) 286static void xp_wait_engine(struct tridentfb_par *par)
322{ 287{
323 int busy; 288 int count = 0;
324 int count, timeout; 289 int timeout = 0;
325 290
326 count = 0; 291 while (t_inb(par, STATUS) & 0x80) {
327 timeout = 0;
328 for (;;) {
329 busy = t_inb(STA) & 0x80;
330 if (busy != 0x80)
331 return;
332 count++; 292 count++;
333 if (count == 10000000) { 293 if (count == 10000000) {
334 /* Timeout */ 294 /* Timeout */
@@ -336,30 +296,31 @@ static void xp_wait_engine(void)
336 timeout++; 296 timeout++;
337 if (timeout == 8) { 297 if (timeout == 8) {
338 /* Reset engine */ 298 /* Reset engine */
339 t_outb(0x00, 0x2120); 299 t_outb(par, 0x00, STATUS);
340 return; 300 return;
341 } 301 }
342 } 302 }
303 cpu_relax();
343 } 304 }
344} 305}
345 306
346static void xp_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop) 307static void xp_fill_rect(struct tridentfb_par *par,
308 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
347{ 309{
348 writemmr(0x2127, ROP_P); 310 writemmr(par, 0x2127, ROP_P);
349 writemmr(0x2158, c); 311 writemmr(par, 0x2158, c);
350 writemmr(0x2128, 0x4000); 312 writemmr(par, DRAWFL, 0x4000);
351 writemmr(0x2140, masked_point(h, w)); 313 writemmr(par, OLDDIM, point(h, w));
352 writemmr(0x2138, masked_point(y, x)); 314 writemmr(par, OLDDST, point(y, x));
353 t_outb(0x01, 0x2124); 315 t_outb(par, 0x01, OLDCMD);
354 t_outb(eng_oper, 0x2125); 316 t_outb(par, par->eng_oper, 0x2125);
355} 317}
356 318
357static void xp_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h) 319static void xp_copy_rect(struct tridentfb_par *par,
320 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
358{ 321{
359 int direction;
360 u32 x1_tmp, x2_tmp, y1_tmp, y2_tmp; 322 u32 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
361 323 int direction = 0x0004;
362 direction = 0x0004;
363 324
364 if ((x1 < x2) && (y1 == y2)) { 325 if ((x1 < x2) && (y1 == y2)) {
365 direction |= 0x0200; 326 direction |= 0x0200;
@@ -379,103 +340,152 @@ static void xp_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
379 y2_tmp = y2; 340 y2_tmp = y2;
380 } 341 }
381 342
382 writemmr(0x2128, direction); 343 writemmr(par, DRAWFL, direction);
383 t_outb(ROP_S, 0x2127); 344 t_outb(par, ROP_S, 0x2127);
384 writemmr(0x213C, masked_point(y1_tmp, x1_tmp)); 345 writemmr(par, OLDSRC, point(y1_tmp, x1_tmp));
385 writemmr(0x2138, masked_point(y2_tmp, x2_tmp)); 346 writemmr(par, OLDDST, point(y2_tmp, x2_tmp));
386 writemmr(0x2140, masked_point(h, w)); 347 writemmr(par, OLDDIM, point(h, w));
387 t_outb(0x01, 0x2124); 348 t_outb(par, 0x01, OLDCMD);
388} 349}
389 350
390static struct accel_switch accel_xp = {
391 xp_init_accel,
392 xp_wait_engine,
393 xp_fill_rect,
394 xp_copy_rect,
395};
396
397/* 351/*
398 * Image specific acceleration functions 352 * Image specific acceleration functions
399 */ 353 */
400static void image_init_accel(int pitch, int bpp) 354static void image_init_accel(struct tridentfb_par *par, int pitch, int bpp)
401{ 355{
402 int tmp = 0; 356 int tmp = bpp == 24 ? 2: (bpp >> 4);
403 switch (bpp) { 357
404 case 8: 358 writemmr(par, 0x2120, 0xF0000000);
405 tmp = 0; 359 writemmr(par, 0x2120, 0x40000000 | tmp);
406 break; 360 writemmr(par, 0x2120, 0x80000000);
407 case 15: 361 writemmr(par, 0x2144, 0x00000000);
408 tmp = 5; 362 writemmr(par, 0x2148, 0x00000000);
409 break; 363 writemmr(par, 0x2150, 0x00000000);
410 case 16: 364 writemmr(par, 0x2154, 0x00000000);
411 tmp = 1; 365 writemmr(par, 0x2120, 0x60000000 | (pitch << 16) | pitch);
412 break; 366 writemmr(par, 0x216C, 0x00000000);
413 case 24: 367 writemmr(par, 0x2170, 0x00000000);
414 case 32: 368 writemmr(par, 0x217C, 0x00000000);
415 tmp = 2; 369 writemmr(par, 0x2120, 0x10000000);
416 break; 370 writemmr(par, 0x2130, (2047 << 16) | 2047);
417 }
418 writemmr(0x2120, 0xF0000000);
419 writemmr(0x2120, 0x40000000 | tmp);
420 writemmr(0x2120, 0x80000000);
421 writemmr(0x2144, 0x00000000);
422 writemmr(0x2148, 0x00000000);
423 writemmr(0x2150, 0x00000000);
424 writemmr(0x2154, 0x00000000);
425 writemmr(0x2120, 0x60000000 | (pitch << 16) | pitch);
426 writemmr(0x216C, 0x00000000);
427 writemmr(0x2170, 0x00000000);
428 writemmr(0x217C, 0x00000000);
429 writemmr(0x2120, 0x10000000);
430 writemmr(0x2130, (2047 << 16) | 2047);
431} 371}
432 372
433static void image_wait_engine(void) 373static void image_wait_engine(struct tridentfb_par *par)
434{ 374{
435 while (readmmr(0x2164) & 0xF0000000) ; 375 while (readmmr(par, 0x2164) & 0xF0000000)
376 cpu_relax();
436} 377}
437 378
438static void image_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop) 379static void image_fill_rect(struct tridentfb_par *par,
380 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
439{ 381{
440 writemmr(0x2120, 0x80000000); 382 writemmr(par, 0x2120, 0x80000000);
441 writemmr(0x2120, 0x90000000 | ROP_S); 383 writemmr(par, 0x2120, 0x90000000 | ROP_S);
442 384
443 writemmr(0x2144, c); 385 writemmr(par, 0x2144, c);
444 386
445 writemmr(DR1, point(x, y)); 387 writemmr(par, DST1, point(x, y));
446 writemmr(DR2, point(x + w - 1, y + h - 1)); 388 writemmr(par, DST2, point(x + w - 1, y + h - 1));
447 389
448 writemmr(0x2124, 0x80000000 | 3 << 22 | 1 << 10 | 1 << 9); 390 writemmr(par, 0x2124, 0x80000000 | 3 << 22 | 1 << 10 | 1 << 9);
449} 391}
450 392
451static void image_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h) 393static void image_copy_rect(struct tridentfb_par *par,
394 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
452{ 395{
453 u32 s1, s2, d1, d2; 396 int direction = 0x4;
454 int direction = 2; 397 u32 s1 = point(x1, y1);
455 s1 = point(x1, y1); 398 u32 s2 = point(x1 + w - 1, y1 + h - 1);
456 s2 = point(x1 + w - 1, y1 + h - 1); 399 u32 d1 = point(x2, y2);
457 d1 = point(x2, y2); 400 u32 d2 = point(x2 + w - 1, y2 + h - 1);
458 d2 = point(x2 + w - 1, y2 + h - 1);
459 401
460 if ((y1 > y2) || ((y1 == y2) && (x1 > x2))) 402 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
461 direction = 0; 403 direction = 0;
462 404
463 writemmr(0x2120, 0x80000000); 405 writemmr(par, 0x2120, 0x80000000);
464 writemmr(0x2120, 0x90000000 | ROP_S); 406 writemmr(par, 0x2120, 0x90000000 | ROP_S);
465 407
466 writemmr(SR1, direction ? s2 : s1); 408 writemmr(par, SRC1, direction ? s2 : s1);
467 writemmr(SR2, direction ? s1 : s2); 409 writemmr(par, SRC2, direction ? s1 : s2);
468 writemmr(DR1, direction ? d2 : d1); 410 writemmr(par, DST1, direction ? d2 : d1);
469 writemmr(DR2, direction ? d1 : d2); 411 writemmr(par, DST2, direction ? d1 : d2);
470 writemmr(0x2124, 0x80000000 | 1 << 22 | 1 << 10 | 1 << 7 | direction); 412 writemmr(par, 0x2124,
413 0x80000000 | 1 << 22 | 1 << 10 | 1 << 7 | direction);
471} 414}
472 415
473static struct accel_switch accel_image = { 416/*
474 image_init_accel, 417 * TGUI 9440/96XX acceleration
475 image_wait_engine, 418 */
476 image_fill_rect, 419
477 image_copy_rect, 420static void tgui_init_accel(struct tridentfb_par *par, int pitch, int bpp)
478}; 421{
422 unsigned char x = bpp == 24 ? 3 : (bpp >> 4);
423
424 /* disable clipping */
425 writemmr(par, 0x2148, 0);
426 writemmr(par, 0x214C, point(4095, 2047));
427
428 switch ((pitch * bpp) / 8) {
429 case 8192:
430 case 512:
431 x |= 0x00;
432 break;
433 case 1024:
434 x |= 0x04;
435 break;
436 case 2048:
437 x |= 0x08;
438 break;
439 case 4096:
440 x |= 0x0C;
441 break;
442 }
443
444 fb_writew(x, par->io_virt + 0x2122);
445}
446
447static void tgui_fill_rect(struct tridentfb_par *par,
448 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
449{
450 t_outb(par, ROP_P, 0x2127);
451 writemmr(par, OLDCLR, c);
452 writemmr(par, DRAWFL, 0x4020);
453 writemmr(par, OLDDIM, point(w - 1, h - 1));
454 writemmr(par, OLDDST, point(x, y));
455 t_outb(par, 1, OLDCMD);
456}
457
458static void tgui_copy_rect(struct tridentfb_par *par,
459 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
460{
461 int flags = 0;
462 u16 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
463
464 if ((x1 < x2) && (y1 == y2)) {
465 flags |= 0x0200;
466 x1_tmp = x1 + w - 1;
467 x2_tmp = x2 + w - 1;
468 } else {
469 x1_tmp = x1;
470 x2_tmp = x2;
471 }
472
473 if (y1 < y2) {
474 flags |= 0x0100;
475 y1_tmp = y1 + h - 1;
476 y2_tmp = y2 + h - 1;
477 } else {
478 y1_tmp = y1;
479 y2_tmp = y2;
480 }
481
482 writemmr(par, DRAWFL, 0x4 | flags);
483 t_outb(par, ROP_S, 0x2127);
484 writemmr(par, OLDSRC, point(x1_tmp, y1_tmp));
485 writemmr(par, OLDDST, point(x2_tmp, y2_tmp));
486 writemmr(par, OLDDIM, point(w - 1, h - 1));
487 t_outb(par, 1, OLDCMD);
488}
479 489
480/* 490/*
481 * Accel functions called by the upper layers 491 * Accel functions called by the upper layers
@@ -484,129 +494,162 @@ static struct accel_switch accel_image = {
484static void tridentfb_fillrect(struct fb_info *info, 494static void tridentfb_fillrect(struct fb_info *info,
485 const struct fb_fillrect *fr) 495 const struct fb_fillrect *fr)
486{ 496{
487 int bpp = info->var.bits_per_pixel; 497 struct tridentfb_par *par = info->par;
488 int col = 0; 498 int col;
489 499
490 switch (bpp) { 500 if (info->flags & FBINFO_HWACCEL_DISABLED) {
491 default: 501 cfb_fillrect(info, fr);
492 case 8: 502 return;
493 col |= fr->color; 503 }
504 if (info->var.bits_per_pixel == 8) {
505 col = fr->color;
494 col |= col << 8; 506 col |= col << 8;
495 col |= col << 16; 507 col |= col << 16;
496 break; 508 } else
497 case 16:
498 col = ((u32 *)(info->pseudo_palette))[fr->color]; 509 col = ((u32 *)(info->pseudo_palette))[fr->color];
499 break; 510
500 case 32: 511 par->wait_engine(par);
501 col = ((u32 *)(info->pseudo_palette))[fr->color]; 512 par->fill_rect(par, fr->dx, fr->dy, fr->width,
502 break; 513 fr->height, col, fr->rop);
514}
515
516static void tridentfb_imageblit(struct fb_info *info,
517 const struct fb_image *img)
518{
519 struct tridentfb_par *par = info->par;
520 int col, bgcol;
521
522 if ((info->flags & FBINFO_HWACCEL_DISABLED) || img->depth != 1) {
523 cfb_imageblit(info, img);
524 return;
525 }
526 if (info->var.bits_per_pixel == 8) {
527 col = img->fg_color;
528 col |= col << 8;
529 col |= col << 16;
530 bgcol = img->bg_color;
531 bgcol |= bgcol << 8;
532 bgcol |= bgcol << 16;
533 } else {
534 col = ((u32 *)(info->pseudo_palette))[img->fg_color];
535 bgcol = ((u32 *)(info->pseudo_palette))[img->bg_color];
503 } 536 }
504 537
505 acc->fill_rect(fr->dx, fr->dy, fr->width, fr->height, col, fr->rop); 538 par->wait_engine(par);
506 acc->wait_engine(); 539 if (par->image_blit)
540 par->image_blit(par, img->data, img->dx, img->dy,
541 img->width, img->height, col, bgcol);
542 else
543 cfb_imageblit(info, img);
507} 544}
545
508static void tridentfb_copyarea(struct fb_info *info, 546static void tridentfb_copyarea(struct fb_info *info,
509 const struct fb_copyarea *ca) 547 const struct fb_copyarea *ca)
510{ 548{
511 acc->copy_rect(ca->sx, ca->sy, ca->dx, ca->dy, ca->width, ca->height); 549 struct tridentfb_par *par = info->par;
512 acc->wait_engine(); 550
551 if (info->flags & FBINFO_HWACCEL_DISABLED) {
552 cfb_copyarea(info, ca);
553 return;
554 }
555 par->wait_engine(par);
556 par->copy_rect(par, ca->sx, ca->sy, ca->dx, ca->dy,
557 ca->width, ca->height);
558}
559
560static int tridentfb_sync(struct fb_info *info)
561{
562 struct tridentfb_par *par = info->par;
563
564 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
565 par->wait_engine(par);
566 return 0;
513} 567}
514#else /* !CONFIG_FB_TRIDENT_ACCEL */ 568#else
515#define tridentfb_fillrect cfb_fillrect 569#define tridentfb_fillrect cfb_fillrect
516#define tridentfb_copyarea cfb_copyarea 570#define tridentfb_copyarea cfb_copyarea
571#define tridentfb_imageblit cfb_imageblit
517#endif /* CONFIG_FB_TRIDENT_ACCEL */ 572#endif /* CONFIG_FB_TRIDENT_ACCEL */
518 573
519
520/* 574/*
521 * Hardware access functions 575 * Hardware access functions
522 */ 576 */
523 577
524static inline unsigned char read3X4(int reg) 578static inline unsigned char read3X4(struct tridentfb_par *par, int reg)
525{ 579{
526 struct tridentfb_par *par = (struct tridentfb_par *)fb_info.par; 580 return vga_mm_rcrt(par->io_virt, reg);
527 writeb(reg, par->io_virt + CRT + 4);
528 return readb(par->io_virt + CRT + 5);
529} 581}
530 582
531static inline void write3X4(int reg, unsigned char val) 583static inline void write3X4(struct tridentfb_par *par, int reg,
584 unsigned char val)
532{ 585{
533 struct tridentfb_par *par = (struct tridentfb_par *)fb_info.par; 586 vga_mm_wcrt(par->io_virt, reg, val);
534 writeb(reg, par->io_virt + CRT + 4);
535 writeb(val, par->io_virt + CRT + 5);
536} 587}
537 588
538static inline unsigned char read3C4(int reg) 589static inline unsigned char read3CE(struct tridentfb_par *par,
590 unsigned char reg)
539{ 591{
540 t_outb(reg, 0x3C4); 592 return vga_mm_rgfx(par->io_virt, reg);
541 return t_inb(0x3C5);
542} 593}
543 594
544static inline void write3C4(int reg, unsigned char val) 595static inline void writeAttr(struct tridentfb_par *par, int reg,
596 unsigned char val)
545{ 597{
546 t_outb(reg, 0x3C4); 598 fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */
547 t_outb(val, 0x3C5); 599 vga_mm_wattr(par->io_virt, reg, val);
548} 600}
549 601
550static inline unsigned char read3CE(int reg) 602static inline void write3CE(struct tridentfb_par *par, int reg,
603 unsigned char val)
551{ 604{
552 t_outb(reg, 0x3CE); 605 vga_mm_wgfx(par->io_virt, reg, val);
553 return t_inb(0x3CF);
554} 606}
555 607
556static inline void writeAttr(int reg, unsigned char val) 608static void enable_mmio(struct tridentfb_par *par)
557{
558 readb(((struct tridentfb_par *)fb_info.par)->io_virt + CRT + 0x0A); /* flip-flop to index */
559 t_outb(reg, 0x3C0);
560 t_outb(val, 0x3C0);
561}
562
563static inline void write3CE(int reg, unsigned char val)
564{
565 t_outb(reg, 0x3CE);
566 t_outb(val, 0x3CF);
567}
568
569static void enable_mmio(void)
570{ 609{
571 /* Goto New Mode */ 610 /* Goto New Mode */
572 outb(0x0B, 0x3C4); 611 vga_io_rseq(0x0B);
573 inb(0x3C5);
574 612
575 /* Unprotect registers */ 613 /* Unprotect registers */
576 outb(NewMode1, 0x3C4); 614 vga_io_wseq(NewMode1, 0x80);
577 outb(0x80, 0x3C5); 615 if (!is_oldprotect(par->chip_id))
616 vga_io_wseq(Protection, 0x92);
578 617
579 /* Enable MMIO */ 618 /* Enable MMIO */
580 outb(PCIReg, 0x3D4); 619 outb(PCIReg, 0x3D4);
581 outb(inb(0x3D5) | 0x01, 0x3D5); 620 outb(inb(0x3D5) | 0x01, 0x3D5);
582} 621}
583 622
584static void disable_mmio(void) 623static void disable_mmio(struct tridentfb_par *par)
585{ 624{
586 /* Goto New Mode */ 625 /* Goto New Mode */
587 t_outb(0x0B, 0x3C4); 626 vga_mm_rseq(par->io_virt, 0x0B);
588 t_inb(0x3C5);
589 627
590 /* Unprotect registers */ 628 /* Unprotect registers */
591 t_outb(NewMode1, 0x3C4); 629 vga_mm_wseq(par->io_virt, NewMode1, 0x80);
592 t_outb(0x80, 0x3C5); 630 if (!is_oldprotect(par->chip_id))
631 vga_mm_wseq(par->io_virt, Protection, 0x92);
593 632
594 /* Disable MMIO */ 633 /* Disable MMIO */
595 t_outb(PCIReg, 0x3D4); 634 t_outb(par, PCIReg, 0x3D4);
596 t_outb(t_inb(0x3D5) & ~0x01, 0x3D5); 635 t_outb(par, t_inb(par, 0x3D5) & ~0x01, 0x3D5);
597} 636}
598 637
599#define crtc_unlock() write3X4(CRTVSyncEnd, read3X4(CRTVSyncEnd) & 0x7F) 638static inline void crtc_unlock(struct tridentfb_par *par)
639{
640 write3X4(par, VGA_CRTC_V_SYNC_END,
641 read3X4(par, VGA_CRTC_V_SYNC_END) & 0x7F);
642}
600 643
601/* Return flat panel's maximum x resolution */ 644/* Return flat panel's maximum x resolution */
602static int __devinit get_nativex(void) 645static int __devinit get_nativex(struct tridentfb_par *par)
603{ 646{
604 int x, y, tmp; 647 int x, y, tmp;
605 648
606 if (nativex) 649 if (nativex)
607 return nativex; 650 return nativex;
608 651
609 tmp = (read3CE(VertStretch) >> 4) & 3; 652 tmp = (read3CE(par, VertStretch) >> 4) & 3;
610 653
611 switch (tmp) { 654 switch (tmp) {
612 case 0: 655 case 0:
@@ -632,77 +675,92 @@ static int __devinit get_nativex(void)
632} 675}
633 676
634/* Set pitch */ 677/* Set pitch */
635static void set_lwidth(int width) 678static inline void set_lwidth(struct tridentfb_par *par, int width)
636{ 679{
637 write3X4(Offset, width & 0xFF); 680 write3X4(par, VGA_CRTC_OFFSET, width & 0xFF);
638 write3X4(AddColReg, 681 write3X4(par, AddColReg,
639 (read3X4(AddColReg) & 0xCF) | ((width & 0x300) >> 4)); 682 (read3X4(par, AddColReg) & 0xCF) | ((width & 0x300) >> 4));
640} 683}
641 684
642/* For resolutions smaller than FP resolution stretch */ 685/* For resolutions smaller than FP resolution stretch */
643static void screen_stretch(void) 686static void screen_stretch(struct tridentfb_par *par)
644{ 687{
645 if (chip_id != CYBERBLADEXPAi1) 688 if (par->chip_id != CYBERBLADEXPAi1)
646 write3CE(BiosReg, 0); 689 write3CE(par, BiosReg, 0);
647 else 690 else
648 write3CE(BiosReg, 8); 691 write3CE(par, BiosReg, 8);
649 write3CE(VertStretch, (read3CE(VertStretch) & 0x7C) | 1); 692 write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 1);
650 write3CE(HorStretch, (read3CE(HorStretch) & 0x7C) | 1); 693 write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 1);
651} 694}
652 695
653/* For resolutions smaller than FP resolution center */ 696/* For resolutions smaller than FP resolution center */
654static void screen_center(void) 697static inline void screen_center(struct tridentfb_par *par)
655{ 698{
656 write3CE(VertStretch, (read3CE(VertStretch) & 0x7C) | 0x80); 699 write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 0x80);
657 write3CE(HorStretch, (read3CE(HorStretch) & 0x7C) | 0x80); 700 write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 0x80);
658} 701}
659 702
660/* Address of first shown pixel in display memory */ 703/* Address of first shown pixel in display memory */
661static void set_screen_start(int base) 704static void set_screen_start(struct tridentfb_par *par, int base)
662{ 705{
663 write3X4(StartAddrLow, base & 0xFF); 706 u8 tmp;
664 write3X4(StartAddrHigh, (base & 0xFF00) >> 8); 707 write3X4(par, VGA_CRTC_START_LO, base & 0xFF);
665 write3X4(CRTCModuleTest, 708 write3X4(par, VGA_CRTC_START_HI, (base & 0xFF00) >> 8);
666 (read3X4(CRTCModuleTest) & 0xDF) | ((base & 0x10000) >> 11)); 709 tmp = read3X4(par, CRTCModuleTest) & 0xDF;
667 write3X4(CRTHiOrd, 710 write3X4(par, CRTCModuleTest, tmp | ((base & 0x10000) >> 11));
668 (read3X4(CRTHiOrd) & 0xF8) | ((base & 0xE0000) >> 17)); 711 tmp = read3X4(par, CRTHiOrd) & 0xF8;
712 write3X4(par, CRTHiOrd, tmp | ((base & 0xE0000) >> 17));
669} 713}
670 714
671/* Set dotclock frequency */ 715/* Set dotclock frequency */
672static void set_vclk(unsigned long freq) 716static void set_vclk(struct tridentfb_par *par, unsigned long freq)
673{ 717{
674 int m, n, k; 718 int m, n, k;
675 unsigned long f, fi, d, di; 719 unsigned long fi, d, di;
676 unsigned char lo = 0, hi = 0; 720 unsigned char best_m = 0, best_n = 0, best_k = 0;
721 unsigned char hi, lo;
722 unsigned char shift = !is_oldclock(par->chip_id) ? 2 : 1;
677 723
678 d = 20000; 724 d = 20000;
679 for (k = 2; k >= 0; k--) 725 for (k = shift; k >= 0; k--)
680 for (m = 0; m < 63; m++) 726 for (m = 1; m < 32; m++) {
681 for (n = 0; n < 128; n++) { 727 n = ((m + 2) << shift) - 8;
728 for (n = (n < 0 ? 0 : n); n < 122; n++) {
682 fi = ((14318l * (n + 8)) / (m + 2)) >> k; 729 fi = ((14318l * (n + 8)) / (m + 2)) >> k;
683 if ((di = abs(fi - freq)) < d) { 730 di = abs(fi - freq);
731 if (di < d || (di == d && k == best_k)) {
684 d = di; 732 d = di;
685 f = fi; 733 best_n = n;
686 lo = n; 734 best_m = m;
687 hi = (k << 6) | m; 735 best_k = k;
688 } 736 }
689 if (fi > freq) 737 if (fi > freq)
690 break; 738 break;
691 } 739 }
692 if (chip3D) { 740 }
693 write3C4(ClockHigh, hi); 741
694 write3C4(ClockLow, lo); 742 if (is_oldclock(par->chip_id)) {
743 lo = best_n | (best_m << 7);
744 hi = (best_m >> 1) | (best_k << 4);
695 } else { 745 } else {
696 outb(lo, 0x43C8); 746 lo = best_n;
697 outb(hi, 0x43C9); 747 hi = best_m | (best_k << 6);
748 }
749
750 if (is3Dchip(par->chip_id)) {
751 vga_mm_wseq(par->io_virt, ClockHigh, hi);
752 vga_mm_wseq(par->io_virt, ClockLow, lo);
753 } else {
754 t_outb(par, lo, 0x43C8);
755 t_outb(par, hi, 0x43C9);
698 } 756 }
699 debug("VCLK = %X %X\n", hi, lo); 757 debug("VCLK = %X %X\n", hi, lo);
700} 758}
701 759
702/* Set number of lines for flat panels*/ 760/* Set number of lines for flat panels*/
703static void set_number_of_lines(int lines) 761static void set_number_of_lines(struct tridentfb_par *par, int lines)
704{ 762{
705 int tmp = read3CE(CyberEnhance) & 0x8F; 763 int tmp = read3CE(par, CyberEnhance) & 0x8F;
706 if (lines > 1024) 764 if (lines > 1024)
707 tmp |= 0x50; 765 tmp |= 0x50;
708 else if (lines > 768) 766 else if (lines > 768)
@@ -711,24 +769,24 @@ static void set_number_of_lines(int lines)
711 tmp |= 0x20; 769 tmp |= 0x20;
712 else if (lines > 480) 770 else if (lines > 480)
713 tmp |= 0x10; 771 tmp |= 0x10;
714 write3CE(CyberEnhance, tmp); 772 write3CE(par, CyberEnhance, tmp);
715} 773}
716 774
717/* 775/*
718 * If we see that FP is active we assume we have one. 776 * If we see that FP is active we assume we have one.
719 * Otherwise we have a CRT display.User can override. 777 * Otherwise we have a CRT display. User can override.
720 */ 778 */
721static unsigned int __devinit get_displaytype(void) 779static int __devinit is_flatpanel(struct tridentfb_par *par)
722{ 780{
723 if (fp) 781 if (fp)
724 return DISPLAY_FP; 782 return 1;
725 if (crt || !chipcyber) 783 if (crt || !iscyber(par->chip_id))
726 return DISPLAY_CRT; 784 return 0;
727 return (read3CE(FPConfig) & 0x10) ? DISPLAY_FP : DISPLAY_CRT; 785 return (read3CE(par, FPConfig) & 0x10) ? 1 : 0;
728} 786}
729 787
730/* Try detecting the video memory size */ 788/* Try detecting the video memory size */
731static unsigned int __devinit get_memsize(void) 789static unsigned int __devinit get_memsize(struct tridentfb_par *par)
732{ 790{
733 unsigned char tmp, tmp2; 791 unsigned char tmp, tmp2;
734 unsigned int k; 792 unsigned int k;
@@ -737,12 +795,12 @@ static unsigned int __devinit get_memsize(void)
737 if (memsize) 795 if (memsize)
738 k = memsize * Kb; 796 k = memsize * Kb;
739 else 797 else
740 switch (chip_id) { 798 switch (par->chip_id) {
741 case CYBER9525DVD: 799 case CYBER9525DVD:
742 k = 2560 * Kb; 800 k = 2560 * Kb;
743 break; 801 break;
744 default: 802 default:
745 tmp = read3X4(SPR) & 0x0F; 803 tmp = read3X4(par, SPR) & 0x0F;
746 switch (tmp) { 804 switch (tmp) {
747 805
748 case 0x01: 806 case 0x01:
@@ -774,7 +832,7 @@ static unsigned int __devinit get_memsize(void)
774 break; 832 break;
775 case 0x0E: /* XP */ 833 case 0x0E: /* XP */
776 834
777 tmp2 = read3C4(0xC1); 835 tmp2 = vga_mm_rseq(par->io_virt, 0xC1);
778 switch (tmp2) { 836 switch (tmp2) {
779 case 0x00: 837 case 0x00:
780 k = 20 * Mb; 838 k = 20 * Mb;
@@ -812,26 +870,67 @@ static unsigned int __devinit get_memsize(void)
812static int tridentfb_check_var(struct fb_var_screeninfo *var, 870static int tridentfb_check_var(struct fb_var_screeninfo *var,
813 struct fb_info *info) 871 struct fb_info *info)
814{ 872{
873 struct tridentfb_par *par = info->par;
815 int bpp = var->bits_per_pixel; 874 int bpp = var->bits_per_pixel;
875 int line_length;
876 int ramdac = 230000; /* 230MHz for most 3D chips */
816 debug("enter\n"); 877 debug("enter\n");
817 878
818 /* check color depth */ 879 /* check color depth */
819 if (bpp == 24) 880 if (bpp == 24)
820 bpp = var->bits_per_pixel = 32; 881 bpp = var->bits_per_pixel = 32;
882 if (bpp != 8 && bpp != 16 && bpp != 32)
883 return -EINVAL;
884 if (par->chip_id == TGUI9440 && bpp == 32)
885 return -EINVAL;
821 /* check whether resolution fits on panel and in memory */ 886 /* check whether resolution fits on panel and in memory */
822 if (flatpanel && nativex && var->xres > nativex) 887 if (par->flatpanel && nativex && var->xres > nativex)
888 return -EINVAL;
889 /* various resolution checks */
890 var->xres = (var->xres + 7) & ~0x7;
891 if (var->xres > var->xres_virtual)
892 var->xres_virtual = var->xres;
893 if (var->yres > var->yres_virtual)
894 var->yres_virtual = var->yres;
895 if (var->xres_virtual > 4095 || var->yres > 2048)
823 return -EINVAL; 896 return -EINVAL;
824 if (var->xres * var->yres_virtual * bpp / 8 > info->fix.smem_len) 897 /* prevent from position overflow for acceleration */
898 if (var->yres_virtual > 0xffff)
899 return -EINVAL;
900 line_length = var->xres_virtual * bpp / 8;
901
902 if (!is3Dchip(par->chip_id) &&
903 !(info->flags & FBINFO_HWACCEL_DISABLED)) {
904 /* acceleration requires line length to be power of 2 */
905 if (line_length <= 512)
906 var->xres_virtual = 512 * 8 / bpp;
907 else if (line_length <= 1024)
908 var->xres_virtual = 1024 * 8 / bpp;
909 else if (line_length <= 2048)
910 var->xres_virtual = 2048 * 8 / bpp;
911 else if (line_length <= 4096)
912 var->xres_virtual = 4096 * 8 / bpp;
913 else if (line_length <= 8192)
914 var->xres_virtual = 8192 * 8 / bpp;
915 else
916 return -EINVAL;
917
918 line_length = var->xres_virtual * bpp / 8;
919 }
920
921 /* datasheet specifies how to set panning only up to 4 MB */
922 if (line_length * (var->yres_virtual - var->yres) > (4 << 20))
923 var->yres_virtual = ((4 << 20) / line_length) + var->yres;
924
925 if (line_length * var->yres_virtual > info->fix.smem_len)
825 return -EINVAL; 926 return -EINVAL;
826 927
827 switch (bpp) { 928 switch (bpp) {
828 case 8: 929 case 8:
829 var->red.offset = 0; 930 var->red.offset = 0;
830 var->green.offset = 0; 931 var->red.length = 8;
831 var->blue.offset = 0; 932 var->green = var->red;
832 var->red.length = 6; 933 var->blue = var->red;
833 var->green.length = 6;
834 var->blue.length = 6;
835 break; 934 break;
836 case 16: 935 case 16:
837 var->red.offset = 11; 936 var->red.offset = 11;
@@ -852,6 +951,33 @@ static int tridentfb_check_var(struct fb_var_screeninfo *var,
852 default: 951 default:
853 return -EINVAL; 952 return -EINVAL;
854 } 953 }
954
955 if (is_xp(par->chip_id))
956 ramdac = 350000;
957
958 switch (par->chip_id) {
959 case TGUI9440:
960 ramdac = (bpp >= 16) ? 45000 : 90000;
961 break;
962 case CYBER9320:
963 case TGUI9660:
964 ramdac = 135000;
965 break;
966 case PROVIDIA9685:
967 case CYBER9388:
968 case CYBER9382:
969 case CYBER9385:
970 ramdac = 170000;
971 break;
972 }
973
974 /* The clock is doubled for 32 bpp */
975 if (bpp == 32)
976 ramdac /= 2;
977
978 if (PICOS2KHZ(var->pixclock) > ramdac)
979 return -EINVAL;
980
855 debug("exit\n"); 981 debug("exit\n");
856 982
857 return 0; 983 return 0;
@@ -862,25 +988,31 @@ static int tridentfb_check_var(struct fb_var_screeninfo *var,
862static int tridentfb_pan_display(struct fb_var_screeninfo *var, 988static int tridentfb_pan_display(struct fb_var_screeninfo *var,
863 struct fb_info *info) 989 struct fb_info *info)
864{ 990{
991 struct tridentfb_par *par = info->par;
865 unsigned int offset; 992 unsigned int offset;
866 993
867 debug("enter\n"); 994 debug("enter\n");
868 offset = (var->xoffset + (var->yoffset * var->xres)) 995 offset = (var->xoffset + (var->yoffset * var->xres_virtual))
869 * var->bits_per_pixel / 32; 996 * var->bits_per_pixel / 32;
870 info->var.xoffset = var->xoffset; 997 set_screen_start(par, offset);
871 info->var.yoffset = var->yoffset;
872 set_screen_start(offset);
873 debug("exit\n"); 998 debug("exit\n");
874 return 0; 999 return 0;
875} 1000}
876 1001
877#define shadowmode_on() write3CE(CyberControl, read3CE(CyberControl) | 0x81) 1002static inline void shadowmode_on(struct tridentfb_par *par)
878#define shadowmode_off() write3CE(CyberControl, read3CE(CyberControl) & 0x7E) 1003{
1004 write3CE(par, CyberControl, read3CE(par, CyberControl) | 0x81);
1005}
1006
1007static inline void shadowmode_off(struct tridentfb_par *par)
1008{
1009 write3CE(par, CyberControl, read3CE(par, CyberControl) & 0x7E);
1010}
879 1011
880/* Set the hardware to the requested video mode */ 1012/* Set the hardware to the requested video mode */
881static int tridentfb_set_par(struct fb_info *info) 1013static int tridentfb_set_par(struct fb_info *info)
882{ 1014{
883 struct tridentfb_par *par = (struct tridentfb_par *)(info->par); 1015 struct tridentfb_par *par = info->par;
884 u32 htotal, hdispend, hsyncstart, hsyncend, hblankstart, hblankend; 1016 u32 htotal, hdispend, hsyncstart, hsyncend, hblankstart, hblankend;
885 u32 vtotal, vdispend, vsyncstart, vsyncend, vblankstart, vblankend; 1017 u32 vtotal, vdispend, vsyncstart, vsyncend, vblankstart, vblankend;
886 struct fb_var_screeninfo *var = &info->var; 1018 struct fb_var_screeninfo *var = &info->var;
@@ -891,58 +1023,73 @@ static int tridentfb_set_par(struct fb_info *info)
891 debug("enter\n"); 1023 debug("enter\n");
892 hdispend = var->xres / 8 - 1; 1024 hdispend = var->xres / 8 - 1;
893 hsyncstart = (var->xres + var->right_margin) / 8; 1025 hsyncstart = (var->xres + var->right_margin) / 8;
894 hsyncend = var->hsync_len / 8; 1026 hsyncend = (var->xres + var->right_margin + var->hsync_len) / 8;
895 htotal = 1027 htotal = (var->xres + var->left_margin + var->right_margin +
896 (var->xres + var->left_margin + var->right_margin + 1028 var->hsync_len) / 8 - 5;
897 var->hsync_len) / 8 - 10;
898 hblankstart = hdispend + 1; 1029 hblankstart = hdispend + 1;
899 hblankend = htotal + 5; 1030 hblankend = htotal + 3;
900 1031
901 vdispend = var->yres - 1; 1032 vdispend = var->yres - 1;
902 vsyncstart = var->yres + var->lower_margin; 1033 vsyncstart = var->yres + var->lower_margin;
903 vsyncend = var->vsync_len; 1034 vsyncend = vsyncstart + var->vsync_len;
904 vtotal = var->upper_margin + vsyncstart + vsyncend - 2; 1035 vtotal = var->upper_margin + vsyncend - 2;
905 vblankstart = var->yres; 1036 vblankstart = vdispend + 1;
906 vblankend = vtotal + 2; 1037 vblankend = vtotal;
1038
1039 if (info->var.vmode & FB_VMODE_INTERLACED) {
1040 vtotal /= 2;
1041 vdispend /= 2;
1042 vsyncstart /= 2;
1043 vsyncend /= 2;
1044 vblankstart /= 2;
1045 vblankend /= 2;
1046 }
907 1047
908 crtc_unlock(); 1048 enable_mmio(par);
909 write3CE(CyberControl, 8); 1049 crtc_unlock(par);
1050 write3CE(par, CyberControl, 8);
1051 tmp = 0xEB;
1052 if (var->sync & FB_SYNC_HOR_HIGH_ACT)
1053 tmp &= ~0x40;
1054 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
1055 tmp &= ~0x80;
910 1056
911 if (flatpanel && var->xres < nativex) { 1057 if (par->flatpanel && var->xres < nativex) {
912 /* 1058 /*
913 * on flat panels with native size larger 1059 * on flat panels with native size larger
914 * than requested resolution decide whether 1060 * than requested resolution decide whether
915 * we stretch or center 1061 * we stretch or center
916 */ 1062 */
917 t_outb(0xEB, 0x3C2); 1063 t_outb(par, tmp | 0xC0, VGA_MIS_W);
918 1064
919 shadowmode_on(); 1065 shadowmode_on(par);
920 1066
921 if (center) 1067 if (center)
922 screen_center(); 1068 screen_center(par);
923 else if (stretch) 1069 else if (stretch)
924 screen_stretch(); 1070 screen_stretch(par);
925 1071
926 } else { 1072 } else {
927 t_outb(0x2B, 0x3C2); 1073 t_outb(par, tmp, VGA_MIS_W);
928 write3CE(CyberControl, 8); 1074 write3CE(par, CyberControl, 8);
929 } 1075 }
930 1076
931 /* vertical timing values */ 1077 /* vertical timing values */
932 write3X4(CRTVTotal, vtotal & 0xFF); 1078 write3X4(par, VGA_CRTC_V_TOTAL, vtotal & 0xFF);
933 write3X4(CRTVDispEnd, vdispend & 0xFF); 1079 write3X4(par, VGA_CRTC_V_DISP_END, vdispend & 0xFF);
934 write3X4(CRTVSyncStart, vsyncstart & 0xFF); 1080 write3X4(par, VGA_CRTC_V_SYNC_START, vsyncstart & 0xFF);
935 write3X4(CRTVSyncEnd, (vsyncend & 0x0F)); 1081 write3X4(par, VGA_CRTC_V_SYNC_END, (vsyncend & 0x0F));
936 write3X4(CRTVBlankStart, vblankstart & 0xFF); 1082 write3X4(par, VGA_CRTC_V_BLANK_START, vblankstart & 0xFF);
937 write3X4(CRTVBlankEnd, 0 /* p->vblankend & 0xFF */ ); 1083 write3X4(par, VGA_CRTC_V_BLANK_END, vblankend & 0xFF);
938 1084
939 /* horizontal timing values */ 1085 /* horizontal timing values */
940 write3X4(CRTHTotal, htotal & 0xFF); 1086 write3X4(par, VGA_CRTC_H_TOTAL, htotal & 0xFF);
941 write3X4(CRTHDispEnd, hdispend & 0xFF); 1087 write3X4(par, VGA_CRTC_H_DISP, hdispend & 0xFF);
942 write3X4(CRTHSyncStart, hsyncstart & 0xFF); 1088 write3X4(par, VGA_CRTC_H_SYNC_START, hsyncstart & 0xFF);
943 write3X4(CRTHSyncEnd, (hsyncend & 0x1F) | ((hblankend & 0x20) << 2)); 1089 write3X4(par, VGA_CRTC_H_SYNC_END,
944 write3X4(CRTHBlankStart, hblankstart & 0xFF); 1090 (hsyncend & 0x1F) | ((hblankend & 0x20) << 2));
945 write3X4(CRTHBlankEnd, 0 /* (p->hblankend & 0x1F) */ ); 1091 write3X4(par, VGA_CRTC_H_BLANK_START, hblankstart & 0xFF);
1092 write3X4(par, VGA_CRTC_H_BLANK_END, hblankend & 0x1F);
946 1093
947 /* higher bits of vertical timing values */ 1094 /* higher bits of vertical timing values */
948 tmp = 0x10; 1095 tmp = 0x10;
@@ -954,39 +1101,43 @@ static int tridentfb_set_par(struct fb_info *info)
954 if (vtotal & 0x200) tmp |= 0x20; 1101 if (vtotal & 0x200) tmp |= 0x20;
955 if (vdispend & 0x200) tmp |= 0x40; 1102 if (vdispend & 0x200) tmp |= 0x40;
956 if (vsyncstart & 0x200) tmp |= 0x80; 1103 if (vsyncstart & 0x200) tmp |= 0x80;
957 write3X4(CRTOverflow, tmp); 1104 write3X4(par, VGA_CRTC_OVERFLOW, tmp);
958 1105
959 tmp = read3X4(CRTHiOrd) | 0x08; /* line compare bit 10 */ 1106 tmp = read3X4(par, CRTHiOrd) & 0x07;
1107 tmp |= 0x08; /* line compare bit 10 */
960 if (vtotal & 0x400) tmp |= 0x80; 1108 if (vtotal & 0x400) tmp |= 0x80;
961 if (vblankstart & 0x400) tmp |= 0x40; 1109 if (vblankstart & 0x400) tmp |= 0x40;
962 if (vsyncstart & 0x400) tmp |= 0x20; 1110 if (vsyncstart & 0x400) tmp |= 0x20;
963 if (vdispend & 0x400) tmp |= 0x10; 1111 if (vdispend & 0x400) tmp |= 0x10;
964 write3X4(CRTHiOrd, tmp); 1112 write3X4(par, CRTHiOrd, tmp);
965 1113
966 tmp = 0; 1114 tmp = (htotal >> 8) & 0x01;
967 if (htotal & 0x800) tmp |= 0x800 >> 11; 1115 tmp |= (hdispend >> 7) & 0x02;
968 if (hblankstart & 0x800) tmp |= 0x800 >> 7; 1116 tmp |= (hsyncstart >> 5) & 0x08;
969 write3X4(HorizOverflow, tmp); 1117 tmp |= (hblankstart >> 4) & 0x10;
1118 write3X4(par, HorizOverflow, tmp);
970 1119
971 tmp = 0x40; 1120 tmp = 0x40;
972 if (vblankstart & 0x200) tmp |= 0x20; 1121 if (vblankstart & 0x200) tmp |= 0x20;
973//FIXME if (info->var.vmode & FB_VMODE_DOUBLE) tmp |= 0x80; /* double scan for 200 line modes */ 1122//FIXME if (info->var.vmode & FB_VMODE_DOUBLE) tmp |= 0x80; /* double scan for 200 line modes */
974 write3X4(CRTMaxScanLine, tmp); 1123 write3X4(par, VGA_CRTC_MAX_SCAN, tmp);
975 1124
976 write3X4(CRTLineCompare, 0xFF); 1125 write3X4(par, VGA_CRTC_LINE_COMPARE, 0xFF);
977 write3X4(CRTPRowScan, 0); 1126 write3X4(par, VGA_CRTC_PRESET_ROW, 0);
978 write3X4(CRTModeControl, 0xC3); 1127 write3X4(par, VGA_CRTC_MODE, 0xC3);
979 1128
980 write3X4(LinearAddReg, 0x20); /* enable linear addressing */ 1129 write3X4(par, LinearAddReg, 0x20); /* enable linear addressing */
981 1130
982 tmp = (info->var.vmode & FB_VMODE_INTERLACED) ? 0x84 : 0x80; 1131 tmp = (info->var.vmode & FB_VMODE_INTERLACED) ? 0x84 : 0x80;
983 write3X4(CRTCModuleTest, tmp); /* enable access extended memory */ 1132 /* enable access extended memory */
984 1133 write3X4(par, CRTCModuleTest, tmp);
985 write3X4(GraphEngReg, 0x80); /* enable GE for text acceleration */ 1134 tmp = read3CE(par, MiscIntContReg) & ~0x4;
1135 if (info->var.vmode & FB_VMODE_INTERLACED)
1136 tmp |= 0x4;
1137 write3CE(par, MiscIntContReg, tmp);
986 1138
987#ifdef CONFIG_FB_TRIDENT_ACCEL 1139 /* enable GE for text acceleration */
988 acc->init_accel(info->var.xres, bpp); 1140 write3X4(par, GraphEngReg, 0x80);
989#endif
990 1141
991 switch (bpp) { 1142 switch (bpp) {
992 case 8: 1143 case 8:
@@ -1003,57 +1154,59 @@ static int tridentfb_set_par(struct fb_info *info)
1003 break; 1154 break;
1004 } 1155 }
1005 1156
1006 write3X4(PixelBusReg, tmp); 1157 write3X4(par, PixelBusReg, tmp);
1007 1158
1008 tmp = 0x10; 1159 tmp = read3X4(par, DRAMControl);
1009 if (chipcyber) 1160 if (!is_oldprotect(par->chip_id))
1161 tmp |= 0x10;
1162 if (iscyber(par->chip_id))
1010 tmp |= 0x20; 1163 tmp |= 0x20;
1011 write3X4(DRAMControl, tmp); /* both IO, linear enable */ 1164 write3X4(par, DRAMControl, tmp); /* both IO, linear enable */
1012 1165
1013 write3X4(InterfaceSel, read3X4(InterfaceSel) | 0x40); 1166 write3X4(par, InterfaceSel, read3X4(par, InterfaceSel) | 0x40);
1014 write3X4(Performance, 0x92); 1167 if (!is_xp(par->chip_id))
1015 write3X4(PCIReg, 0x07); /* MMIO & PCI read and write burst enable */ 1168 write3X4(par, Performance, read3X4(par, Performance) | 0x10);
1169 /* MMIO & PCI read and write burst enable */
1170 if (par->chip_id != TGUI9440 && par->chip_id != IMAGE975)
1171 write3X4(par, PCIReg, read3X4(par, PCIReg) | 0x06);
1172
1173 vga_mm_wseq(par->io_virt, 0, 3);
1174 vga_mm_wseq(par->io_virt, 1, 1); /* set char clock 8 dots wide */
1175 /* enable 4 maps because needed in chain4 mode */
1176 vga_mm_wseq(par->io_virt, 2, 0x0F);
1177 vga_mm_wseq(par->io_virt, 3, 0);
1178 vga_mm_wseq(par->io_virt, 4, 0x0E); /* memory mode enable bitmaps ?? */
1016 1179
1017 /* convert from picoseconds to kHz */ 1180 /* convert from picoseconds to kHz */
1018 vclk = PICOS2KHZ(info->var.pixclock); 1181 vclk = PICOS2KHZ(info->var.pixclock);
1019 if (bpp == 32) 1182
1183 /* divide clock by 2 if 32bpp chain4 mode display and CPU path */
1184 tmp = read3CE(par, MiscExtFunc) & 0xF0;
1185 if (bpp == 32 || (par->chip_id == TGUI9440 && bpp == 16)) {
1186 tmp |= 8;
1020 vclk *= 2; 1187 vclk *= 2;
1021 set_vclk(vclk);
1022
1023 write3C4(0, 3);
1024 write3C4(1, 1); /* set char clock 8 dots wide */
1025 write3C4(2, 0x0F); /* enable 4 maps because needed in chain4 mode */
1026 write3C4(3, 0);
1027 write3C4(4, 0x0E); /* memory mode enable bitmaps ?? */
1028
1029 write3CE(MiscExtFunc, (bpp == 32) ? 0x1A : 0x12); /* divide clock by 2 if 32bpp */
1030 /* chain4 mode display and CPU path */
1031 write3CE(0x5, 0x40); /* no CGA compat, allow 256 col */
1032 write3CE(0x6, 0x05); /* graphics mode */
1033 write3CE(0x7, 0x0F); /* planes? */
1034
1035 if (chip_id == CYBERBLADEXPAi1) {
1036 /* This fixes snow-effect in 32 bpp */
1037 write3X4(CRTHSyncStart, 0x84);
1038 } 1188 }
1189 set_vclk(par, vclk);
1190 write3CE(par, MiscExtFunc, tmp | 0x12);
1191 write3CE(par, 0x5, 0x40); /* no CGA compat, allow 256 col */
1192 write3CE(par, 0x6, 0x05); /* graphics mode */
1193 write3CE(par, 0x7, 0x0F); /* planes? */
1039 1194
1040 writeAttr(0x10, 0x41); /* graphics mode and support 256 color modes */ 1195 /* graphics mode and support 256 color modes */
1041 writeAttr(0x12, 0x0F); /* planes */ 1196 writeAttr(par, 0x10, 0x41);
1042 writeAttr(0x13, 0); /* horizontal pel panning */ 1197 writeAttr(par, 0x12, 0x0F); /* planes */
1198 writeAttr(par, 0x13, 0); /* horizontal pel panning */
1043 1199
1044 /* colors */ 1200 /* colors */
1045 for (tmp = 0; tmp < 0x10; tmp++) 1201 for (tmp = 0; tmp < 0x10; tmp++)
1046 writeAttr(tmp, tmp); 1202 writeAttr(par, tmp, tmp);
1047 readb(par->io_virt + CRT + 0x0A); /* flip-flop to index */ 1203 fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */
1048 t_outb(0x20, 0x3C0); /* enable attr */ 1204 t_outb(par, 0x20, VGA_ATT_W); /* enable attr */
1049 1205
1050 switch (bpp) { 1206 switch (bpp) {
1051 case 8: 1207 case 8:
1052 tmp = 0; 1208 tmp = 0;
1053 break; 1209 break;
1054 case 15:
1055 tmp = 0x10;
1056 break;
1057 case 16: 1210 case 16:
1058 tmp = 0x30; 1211 tmp = 0x30;
1059 break; 1212 break;
@@ -1063,19 +1216,23 @@ static int tridentfb_set_par(struct fb_info *info)
1063 break; 1216 break;
1064 } 1217 }
1065 1218
1066 t_inb(0x3C8); 1219 t_inb(par, VGA_PEL_IW);
1067 t_inb(0x3C6); 1220 t_inb(par, VGA_PEL_MSK);
1068 t_inb(0x3C6); 1221 t_inb(par, VGA_PEL_MSK);
1069 t_inb(0x3C6); 1222 t_inb(par, VGA_PEL_MSK);
1070 t_inb(0x3C6); 1223 t_inb(par, VGA_PEL_MSK);
1071 t_outb(tmp, 0x3C6); 1224 t_outb(par, tmp, VGA_PEL_MSK);
1072 t_inb(0x3C8); 1225 t_inb(par, VGA_PEL_IW);
1073 1226
1074 if (flatpanel) 1227 if (par->flatpanel)
1075 set_number_of_lines(info->var.yres); 1228 set_number_of_lines(par, info->var.yres);
1076 set_lwidth(info->var.xres * bpp / (4 * 16)); 1229 info->fix.line_length = info->var.xres_virtual * bpp / 8;
1230 set_lwidth(par, info->fix.line_length / 8);
1231
1232 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
1233 par->init_accel(par, info->var.xres_virtual, bpp);
1234
1077 info->fix.visual = (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; 1235 info->fix.visual = (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
1078 info->fix.line_length = info->var.xres * (bpp >> 3);
1079 info->cmap.len = (bpp == 8) ? 256 : 16; 1236 info->cmap.len = (bpp == 8) ? 256 : 16;
1080 debug("exit\n"); 1237 debug("exit\n");
1081 return 0; 1238 return 0;
@@ -1087,17 +1244,18 @@ static int tridentfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1087 struct fb_info *info) 1244 struct fb_info *info)
1088{ 1245{
1089 int bpp = info->var.bits_per_pixel; 1246 int bpp = info->var.bits_per_pixel;
1247 struct tridentfb_par *par = info->par;
1090 1248
1091 if (regno >= info->cmap.len) 1249 if (regno >= info->cmap.len)
1092 return 1; 1250 return 1;
1093 1251
1094 if (bpp == 8) { 1252 if (bpp == 8) {
1095 t_outb(0xFF, 0x3C6); 1253 t_outb(par, 0xFF, VGA_PEL_MSK);
1096 t_outb(regno, 0x3C8); 1254 t_outb(par, regno, VGA_PEL_IW);
1097 1255
1098 t_outb(red >> 10, 0x3C9); 1256 t_outb(par, red >> 10, VGA_PEL_D);
1099 t_outb(green >> 10, 0x3C9); 1257 t_outb(par, green >> 10, VGA_PEL_D);
1100 t_outb(blue >> 10, 0x3C9); 1258 t_outb(par, blue >> 10, VGA_PEL_D);
1101 1259
1102 } else if (regno < 16) { 1260 } else if (regno < 16) {
1103 if (bpp == 16) { /* RGB 565 */ 1261 if (bpp == 16) { /* RGB 565 */
@@ -1108,28 +1266,28 @@ static int tridentfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1108 col |= col << 16; 1266 col |= col << 16;
1109 ((u32 *)(info->pseudo_palette))[regno] = col; 1267 ((u32 *)(info->pseudo_palette))[regno] = col;
1110 } else if (bpp == 32) /* ARGB 8888 */ 1268 } else if (bpp == 32) /* ARGB 8888 */
1111 ((u32*)info->pseudo_palette)[regno] = 1269 ((u32 *)info->pseudo_palette)[regno] =
1112 ((transp & 0xFF00) << 16) | 1270 ((transp & 0xFF00) << 16) |
1113 ((red & 0xFF00) << 8) | 1271 ((red & 0xFF00) << 8) |
1114 ((green & 0xFF00)) | 1272 ((green & 0xFF00)) |
1115 ((blue & 0xFF00) >> 8); 1273 ((blue & 0xFF00) >> 8);
1116 } 1274 }
1117 1275
1118/* debug("exit\n"); */
1119 return 0; 1276 return 0;
1120} 1277}
1121 1278
1122/* Try blanking the screen.For flat panels it does nothing */ 1279/* Try blanking the screen. For flat panels it does nothing */
1123static int tridentfb_blank(int blank_mode, struct fb_info *info) 1280static int tridentfb_blank(int blank_mode, struct fb_info *info)
1124{ 1281{
1125 unsigned char PMCont, DPMSCont; 1282 unsigned char PMCont, DPMSCont;
1283 struct tridentfb_par *par = info->par;
1126 1284
1127 debug("enter\n"); 1285 debug("enter\n");
1128 if (flatpanel) 1286 if (par->flatpanel)
1129 return 0; 1287 return 0;
1130 t_outb(0x04, 0x83C8); /* Read DPMS Control */ 1288 t_outb(par, 0x04, 0x83C8); /* Read DPMS Control */
1131 PMCont = t_inb(0x83C6) & 0xFC; 1289 PMCont = t_inb(par, 0x83C6) & 0xFC;
1132 DPMSCont = read3CE(PowerStatus) & 0xFC; 1290 DPMSCont = read3CE(par, PowerStatus) & 0xFC;
1133 switch (blank_mode) { 1291 switch (blank_mode) {
1134 case FB_BLANK_UNBLANK: 1292 case FB_BLANK_UNBLANK:
1135 /* Screen: On, HSync: On, VSync: On */ 1293 /* Screen: On, HSync: On, VSync: On */
@@ -1155,9 +1313,9 @@ static int tridentfb_blank(int blank_mode, struct fb_info *info)
1155 break; 1313 break;
1156 } 1314 }
1157 1315
1158 write3CE(PowerStatus, DPMSCont); 1316 write3CE(par, PowerStatus, DPMSCont);
1159 t_outb(4, 0x83C8); 1317 t_outb(par, 4, 0x83C8);
1160 t_outb(PMCont, 0x83C6); 1318 t_outb(par, PMCont, 0x83C6);
1161 1319
1162 debug("exit\n"); 1320 debug("exit\n");
1163 1321
@@ -1174,33 +1332,46 @@ static struct fb_ops tridentfb_ops = {
1174 .fb_set_par = tridentfb_set_par, 1332 .fb_set_par = tridentfb_set_par,
1175 .fb_fillrect = tridentfb_fillrect, 1333 .fb_fillrect = tridentfb_fillrect,
1176 .fb_copyarea = tridentfb_copyarea, 1334 .fb_copyarea = tridentfb_copyarea,
1177 .fb_imageblit = cfb_imageblit, 1335 .fb_imageblit = tridentfb_imageblit,
1336#ifdef CONFIG_FB_TRIDENT_ACCEL
1337 .fb_sync = tridentfb_sync,
1338#endif
1178}; 1339};
1179 1340
1180static int __devinit trident_pci_probe(struct pci_dev * dev, 1341static int __devinit trident_pci_probe(struct pci_dev *dev,
1181 const struct pci_device_id * id) 1342 const struct pci_device_id *id)
1182{ 1343{
1183 int err; 1344 int err;
1184 unsigned char revision; 1345 unsigned char revision;
1346 struct fb_info *info;
1347 struct tridentfb_par *default_par;
1348 int chip3D;
1349 int chip_id;
1185 1350
1186 err = pci_enable_device(dev); 1351 err = pci_enable_device(dev);
1187 if (err) 1352 if (err)
1188 return err; 1353 return err;
1189 1354
1190 chip_id = id->device; 1355 info = framebuffer_alloc(sizeof(struct tridentfb_par), &dev->dev);
1356 if (!info)
1357 return -ENOMEM;
1358 default_par = info->par;
1191 1359
1192 if (chip_id == CYBERBLADEi1) 1360 chip_id = id->device;
1193 output("*** Please do use cyblafb, Cyberblade/i1 support "
1194 "will soon be removed from tridentfb!\n");
1195 1361
1362#ifndef CONFIG_FB_TRIDENT_ACCEL
1363 noaccel = 1;
1364#endif
1196 1365
1197 /* If PCI id is 0x9660 then further detect chip type */ 1366 /* If PCI id is 0x9660 then further detect chip type */
1198 1367
1199 if (chip_id == TGUI9660) { 1368 if (chip_id == TGUI9660) {
1200 outb(RevisionID, 0x3C4); 1369 revision = vga_io_rseq(RevisionID);
1201 revision = inb(0x3C5);
1202 1370
1203 switch (revision) { 1371 switch (revision) {
1372 case 0x21:
1373 chip_id = PROVIDIA9685;
1374 break;
1204 case 0x22: 1375 case 0x22:
1205 case 0x23: 1376 case 0x23:
1206 chip_id = CYBER9397; 1377 chip_id = CYBER9397;
@@ -1229,123 +1400,170 @@ static int __devinit trident_pci_probe(struct pci_dev * dev,
1229 } 1400 }
1230 1401
1231 chip3D = is3Dchip(chip_id); 1402 chip3D = is3Dchip(chip_id);
1232 chipcyber = iscyber(chip_id);
1233 1403
1234 if (is_xp(chip_id)) { 1404 if (is_xp(chip_id)) {
1235 acc = &accel_xp; 1405 default_par->init_accel = xp_init_accel;
1406 default_par->wait_engine = xp_wait_engine;
1407 default_par->fill_rect = xp_fill_rect;
1408 default_par->copy_rect = xp_copy_rect;
1409 tridentfb_fix.accel = FB_ACCEL_TRIDENT_BLADEXP;
1236 } else if (is_blade(chip_id)) { 1410 } else if (is_blade(chip_id)) {
1237 acc = &accel_blade; 1411 default_par->init_accel = blade_init_accel;
1238 } else { 1412 default_par->wait_engine = blade_wait_engine;
1239 acc = &accel_image; 1413 default_par->fill_rect = blade_fill_rect;
1414 default_par->copy_rect = blade_copy_rect;
1415 default_par->image_blit = blade_image_blit;
1416 tridentfb_fix.accel = FB_ACCEL_TRIDENT_BLADE3D;
1417 } else if (chip3D) { /* 3DImage family left */
1418 default_par->init_accel = image_init_accel;
1419 default_par->wait_engine = image_wait_engine;
1420 default_par->fill_rect = image_fill_rect;
1421 default_par->copy_rect = image_copy_rect;
1422 tridentfb_fix.accel = FB_ACCEL_TRIDENT_3DIMAGE;
1423 } else { /* TGUI 9440/96XX family */
1424 default_par->init_accel = tgui_init_accel;
1425 default_par->wait_engine = xp_wait_engine;
1426 default_par->fill_rect = tgui_fill_rect;
1427 default_par->copy_rect = tgui_copy_rect;
1428 tridentfb_fix.accel = FB_ACCEL_TRIDENT_TGUI;
1240 } 1429 }
1241 1430
1242 /* acceleration is on by default for 3D chips */ 1431 default_par->chip_id = chip_id;
1243 defaultaccel = chip3D && !noaccel;
1244
1245 fb_info.par = &default_par;
1246 1432
1247 /* setup MMIO region */ 1433 /* setup MMIO region */
1248 tridentfb_fix.mmio_start = pci_resource_start(dev, 1); 1434 tridentfb_fix.mmio_start = pci_resource_start(dev, 1);
1249 tridentfb_fix.mmio_len = chip3D ? 0x20000 : 0x10000; 1435 tridentfb_fix.mmio_len = pci_resource_len(dev, 1);
1250 1436
1251 if (!request_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len, "tridentfb")) { 1437 if (!request_mem_region(tridentfb_fix.mmio_start,
1438 tridentfb_fix.mmio_len, "tridentfb")) {
1252 debug("request_region failed!\n"); 1439 debug("request_region failed!\n");
1440 framebuffer_release(info);
1253 return -1; 1441 return -1;
1254 } 1442 }
1255 1443
1256 default_par.io_virt = ioremap_nocache(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len); 1444 default_par->io_virt = ioremap_nocache(tridentfb_fix.mmio_start,
1445 tridentfb_fix.mmio_len);
1257 1446
1258 if (!default_par.io_virt) { 1447 if (!default_par->io_virt) {
1259 debug("ioremap failed\n"); 1448 debug("ioremap failed\n");
1260 err = -1; 1449 err = -1;
1261 goto out_unmap1; 1450 goto out_unmap1;
1262 } 1451 }
1263 1452
1264 enable_mmio(); 1453 enable_mmio(default_par);
1265 1454
1266 /* setup framebuffer memory */ 1455 /* setup framebuffer memory */
1267 tridentfb_fix.smem_start = pci_resource_start(dev, 0); 1456 tridentfb_fix.smem_start = pci_resource_start(dev, 0);
1268 tridentfb_fix.smem_len = get_memsize(); 1457 tridentfb_fix.smem_len = get_memsize(default_par);
1269 1458
1270 if (!request_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len, "tridentfb")) { 1459 if (!request_mem_region(tridentfb_fix.smem_start,
1460 tridentfb_fix.smem_len, "tridentfb")) {
1271 debug("request_mem_region failed!\n"); 1461 debug("request_mem_region failed!\n");
1272 disable_mmio(); 1462 disable_mmio(info->par);
1273 err = -1; 1463 err = -1;
1274 goto out_unmap1; 1464 goto out_unmap1;
1275 } 1465 }
1276 1466
1277 fb_info.screen_base = ioremap_nocache(tridentfb_fix.smem_start, 1467 info->screen_base = ioremap_nocache(tridentfb_fix.smem_start,
1278 tridentfb_fix.smem_len); 1468 tridentfb_fix.smem_len);
1279 1469
1280 if (!fb_info.screen_base) { 1470 if (!info->screen_base) {
1281 debug("ioremap failed\n"); 1471 debug("ioremap failed\n");
1282 err = -1; 1472 err = -1;
1283 goto out_unmap2; 1473 goto out_unmap2;
1284 } 1474 }
1285 1475
1286 output("%s board found\n", pci_name(dev)); 1476 default_par->flatpanel = is_flatpanel(default_par);
1287 displaytype = get_displaytype();
1288 1477
1289 if (flatpanel) 1478 if (default_par->flatpanel)
1290 nativex = get_nativex(); 1479 nativex = get_nativex(default_par);
1291 1480
1292 fb_info.fix = tridentfb_fix; 1481 info->fix = tridentfb_fix;
1293 fb_info.fbops = &tridentfb_ops; 1482 info->fbops = &tridentfb_ops;
1483 info->pseudo_palette = default_par->pseudo_pal;
1294 1484
1485 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1486 if (!noaccel && default_par->init_accel) {
1487 info->flags &= ~FBINFO_HWACCEL_DISABLED;
1488 info->flags |= FBINFO_HWACCEL_COPYAREA;
1489 info->flags |= FBINFO_HWACCEL_FILLRECT;
1490 } else
1491 info->flags |= FBINFO_HWACCEL_DISABLED;
1295 1492
1296 fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; 1493 info->pixmap.addr = kmalloc(4096, GFP_KERNEL);
1297#ifdef CONFIG_FB_TRIDENT_ACCEL 1494 if (!info->pixmap.addr) {
1298 fb_info.flags |= FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT; 1495 err = -ENOMEM;
1299#endif 1496 goto out_unmap2;
1300 fb_info.pseudo_palette = pseudo_pal; 1497 }
1498
1499 info->pixmap.size = 4096;
1500 info->pixmap.buf_align = 4;
1501 info->pixmap.scan_align = 1;
1502 info->pixmap.access_align = 32;
1503 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1301 1504
1302 if (!fb_find_mode(&default_var, &fb_info, 1505 if (default_par->image_blit) {
1506 info->flags |= FBINFO_HWACCEL_IMAGEBLIT;
1507 info->pixmap.scan_align = 4;
1508 }
1509
1510 if (noaccel) {
1511 printk(KERN_DEBUG "disabling acceleration\n");
1512 info->flags |= FBINFO_HWACCEL_DISABLED;
1513 info->pixmap.scan_align = 1;
1514 }
1515
1516 if (!fb_find_mode(&info->var, info,
1303 mode_option, NULL, 0, NULL, bpp)) { 1517 mode_option, NULL, 0, NULL, bpp)) {
1304 err = -EINVAL; 1518 err = -EINVAL;
1305 goto out_unmap2; 1519 goto out_unmap2;
1306 } 1520 }
1307 err = fb_alloc_cmap(&fb_info.cmap, 256, 0); 1521 err = fb_alloc_cmap(&info->cmap, 256, 0);
1308 if (err < 0) 1522 if (err < 0)
1309 goto out_unmap2; 1523 goto out_unmap2;
1310 1524
1311 if (defaultaccel && acc) 1525 info->var.activate |= FB_ACTIVATE_NOW;
1312 default_var.accel_flags |= FB_ACCELF_TEXT; 1526 info->device = &dev->dev;
1313 else 1527 if (register_framebuffer(info) < 0) {
1314 default_var.accel_flags &= ~FB_ACCELF_TEXT; 1528 printk(KERN_ERR "tridentfb: could not register framebuffer\n");
1315 default_var.activate |= FB_ACTIVATE_NOW; 1529 fb_dealloc_cmap(&info->cmap);
1316 fb_info.var = default_var;
1317 fb_info.device = &dev->dev;
1318 if (register_framebuffer(&fb_info) < 0) {
1319 printk(KERN_ERR "tridentfb: could not register Trident framebuffer\n");
1320 fb_dealloc_cmap(&fb_info.cmap);
1321 err = -EINVAL; 1530 err = -EINVAL;
1322 goto out_unmap2; 1531 goto out_unmap2;
1323 } 1532 }
1324 output("fb%d: %s frame buffer device %dx%d-%dbpp\n", 1533 output("fb%d: %s frame buffer device %dx%d-%dbpp\n",
1325 fb_info.node, fb_info.fix.id, default_var.xres, 1534 info->node, info->fix.id, info->var.xres,
1326 default_var.yres, default_var.bits_per_pixel); 1535 info->var.yres, info->var.bits_per_pixel);
1536
1537 pci_set_drvdata(dev, info);
1327 return 0; 1538 return 0;
1328 1539
1329out_unmap2: 1540out_unmap2:
1330 if (fb_info.screen_base) 1541 kfree(info->pixmap.addr);
1331 iounmap(fb_info.screen_base); 1542 if (info->screen_base)
1543 iounmap(info->screen_base);
1332 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len); 1544 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
1333 disable_mmio(); 1545 disable_mmio(info->par);
1334out_unmap1: 1546out_unmap1:
1335 if (default_par.io_virt) 1547 if (default_par->io_virt)
1336 iounmap(default_par.io_virt); 1548 iounmap(default_par->io_virt);
1337 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len); 1549 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
1550 framebuffer_release(info);
1338 return err; 1551 return err;
1339} 1552}
1340 1553
1341static void __devexit trident_pci_remove(struct pci_dev *dev) 1554static void __devexit trident_pci_remove(struct pci_dev *dev)
1342{ 1555{
1343 struct tridentfb_par *par = (struct tridentfb_par*)fb_info.par; 1556 struct fb_info *info = pci_get_drvdata(dev);
1344 unregister_framebuffer(&fb_info); 1557 struct tridentfb_par *par = info->par;
1558
1559 unregister_framebuffer(info);
1345 iounmap(par->io_virt); 1560 iounmap(par->io_virt);
1346 iounmap(fb_info.screen_base); 1561 iounmap(info->screen_base);
1347 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len); 1562 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
1348 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len); 1563 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
1564 pci_set_drvdata(dev, NULL);
1565 kfree(info->pixmap.addr);
1566 framebuffer_release(info);
1349} 1567}
1350 1568
1351/* List of boards that we are trying to support */ 1569/* List of boards that we are trying to support */
@@ -1358,6 +1576,7 @@ static struct pci_device_id trident_devices[] = {
1358 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 1576 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1359 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 1577 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1360 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEE4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 1578 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEE4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1579 {PCI_VENDOR_ID_TRIDENT, TGUI9440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1361 {PCI_VENDOR_ID_TRIDENT, TGUI9660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 1580 {PCI_VENDOR_ID_TRIDENT, TGUI9660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1362 {PCI_VENDOR_ID_TRIDENT, IMAGE975, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 1581 {PCI_VENDOR_ID_TRIDENT, IMAGE975, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1363 {PCI_VENDOR_ID_TRIDENT, IMAGE985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 1582 {PCI_VENDOR_ID_TRIDENT, IMAGE985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
@@ -1399,9 +1618,9 @@ static int __init tridentfb_setup(char *options)
1399 if (!strncmp(opt, "noaccel", 7)) 1618 if (!strncmp(opt, "noaccel", 7))
1400 noaccel = 1; 1619 noaccel = 1;
1401 else if (!strncmp(opt, "fp", 2)) 1620 else if (!strncmp(opt, "fp", 2))
1402 displaytype = DISPLAY_FP; 1621 fp = 1;
1403 else if (!strncmp(opt, "crt", 3)) 1622 else if (!strncmp(opt, "crt", 3))
1404 displaytype = DISPLAY_CRT; 1623 fp = 0;
1405 else if (!strncmp(opt, "bpp=", 4)) 1624 else if (!strncmp(opt, "bpp=", 4))
1406 bpp = simple_strtoul(opt + 4, NULL, 0); 1625 bpp = simple_strtoul(opt + 4, NULL, 0);
1407 else if (!strncmp(opt, "center", 6)) 1626 else if (!strncmp(opt, "center", 6))
@@ -1430,7 +1649,6 @@ static int __init tridentfb_init(void)
1430 return -ENODEV; 1649 return -ENODEV;
1431 tridentfb_setup(option); 1650 tridentfb_setup(option);
1432#endif 1651#endif
1433 output("Trident framebuffer %s initializing\n", VERSION);
1434 return pci_register_driver(&tridentfb_pci_driver); 1652 return pci_register_driver(&tridentfb_pci_driver);
1435} 1653}
1436 1654
diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
index cdbb56edb6cb..50744229c7a9 100644
--- a/drivers/video/uvesafb.c
+++ b/drivers/video/uvesafb.c
@@ -2054,8 +2054,8 @@ MODULE_PARM_DESC(maxhf,
2054module_param(maxvf, ushort, 0); 2054module_param(maxvf, ushort, 0);
2055MODULE_PARM_DESC(maxvf, 2055MODULE_PARM_DESC(maxvf,
2056 "Maximum vertical frequency [Hz], overrides EDID data"); 2056 "Maximum vertical frequency [Hz], overrides EDID data");
2057module_param_named(mode, mode_option, charp, 0); 2057module_param(mode_option, charp, 0);
2058MODULE_PARM_DESC(mode, 2058MODULE_PARM_DESC(mode_option,
2059 "Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\""); 2059 "Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
2060module_param(vbemode, ushort, 0); 2060module_param(vbemode, ushort, 0);
2061MODULE_PARM_DESC(vbemode, 2061MODULE_PARM_DESC(vbemode,
diff --git a/drivers/video/vfb.c b/drivers/video/vfb.c
index 072638a9528a..93fe08d6c78f 100644
--- a/drivers/video/vfb.c
+++ b/drivers/video/vfb.c
@@ -443,19 +443,29 @@ static int vfb_mmap(struct fb_info *info,
443} 443}
444 444
445#ifndef MODULE 445#ifndef MODULE
446/*
447 * The virtual framebuffer driver is only enabled if explicitly
448 * requested by passing 'video=vfb:' (or any actual options).
449 */
446static int __init vfb_setup(char *options) 450static int __init vfb_setup(char *options)
447{ 451{
448 char *this_opt; 452 char *this_opt;
449 453
454 vfb_enable = 0;
455
456 if (!options)
457 return 1;
458
450 vfb_enable = 1; 459 vfb_enable = 1;
451 460
452 if (!options || !*options) 461 if (!*options)
453 return 1; 462 return 1;
454 463
455 while ((this_opt = strsep(&options, ",")) != NULL) { 464 while ((this_opt = strsep(&options, ",")) != NULL) {
456 if (!*this_opt) 465 if (!*this_opt)
457 continue; 466 continue;
458 if (!strncmp(this_opt, "disable", 7)) 467 /* Test disable for backwards compatibility */
468 if (!strcmp(this_opt, "disable"))
459 vfb_enable = 0; 469 vfb_enable = 0;
460 } 470 }
461 return 1; 471 return 1;
diff --git a/drivers/video/vga16fb.c b/drivers/video/vga16fb.c
index 9b3c5923365e..e31bca8a0cb2 100644
--- a/drivers/video/vga16fb.c
+++ b/drivers/video/vga16fb.c
@@ -26,18 +26,6 @@
26#include <asm/io.h> 26#include <asm/io.h>
27#include <video/vga.h> 27#include <video/vga.h>
28 28
29#define GRAPHICS_ADDR_REG VGA_GFX_I /* Graphics address register. */
30#define GRAPHICS_DATA_REG VGA_GFX_D /* Graphics data register. */
31
32#define SET_RESET_INDEX VGA_GFX_SR_VALUE /* Set/Reset Register index. */
33#define ENABLE_SET_RESET_INDEX VGA_GFX_SR_ENABLE /* Enable Set/Reset Register index. */
34#define DATA_ROTATE_INDEX VGA_GFX_DATA_ROTATE /* Data Rotate Register index. */
35#define GRAPHICS_MODE_INDEX VGA_GFX_MODE /* Graphics Mode Register index. */
36#define BIT_MASK_INDEX VGA_GFX_BIT_MASK /* Bit Mask Register index. */
37
38#define dac_reg (VGA_PEL_IW)
39#define dac_val (VGA_PEL_D)
40
41#define VGA_FB_PHYS 0xA0000 29#define VGA_FB_PHYS 0xA0000
42#define VGA_FB_PHYS_LEN 65536 30#define VGA_FB_PHYS_LEN 65536
43 31
@@ -108,7 +96,7 @@ static struct fb_fix_screeninfo vga16fb_fix __initdata = {
108 .visual = FB_VISUAL_PSEUDOCOLOR, 96 .visual = FB_VISUAL_PSEUDOCOLOR,
109 .xpanstep = 8, 97 .xpanstep = 8,
110 .ypanstep = 1, 98 .ypanstep = 1,
111 .line_length = 640/8, 99 .line_length = 640 / 8,
112 .accel = FB_ACCEL_NONE 100 .accel = FB_ACCEL_NONE
113}; 101};
114 102
@@ -135,23 +123,22 @@ static inline int setmode(int mode)
135{ 123{
136 int oldmode; 124 int oldmode;
137 125
138 vga_io_w(GRAPHICS_ADDR_REG, GRAPHICS_MODE_INDEX); 126 oldmode = vga_io_rgfx(VGA_GFX_MODE);
139 oldmode = vga_io_r(GRAPHICS_DATA_REG); 127 vga_io_w(VGA_GFX_D, mode);
140 vga_io_w(GRAPHICS_DATA_REG, mode);
141 return oldmode; 128 return oldmode;
142} 129}
143 130
144/* Select the Bit Mask Register and return its value. */ 131/* Select the Bit Mask Register and return its value. */
145static inline int selectmask(void) 132static inline int selectmask(void)
146{ 133{
147 return vga_io_rgfx(BIT_MASK_INDEX); 134 return vga_io_rgfx(VGA_GFX_BIT_MASK);
148} 135}
149 136
150/* Set the value of the Bit Mask Register. It must already have been 137/* Set the value of the Bit Mask Register. It must already have been
151 selected with selectmask(). */ 138 selected with selectmask(). */
152static inline void setmask(int mask) 139static inline void setmask(int mask)
153{ 140{
154 vga_io_w(GRAPHICS_DATA_REG, mask); 141 vga_io_w(VGA_GFX_D, mask);
155} 142}
156 143
157/* Set the Data Rotate Register and return its old value. 144/* Set the Data Rotate Register and return its old value.
@@ -161,9 +148,8 @@ static inline int setop(int op)
161{ 148{
162 int oldop; 149 int oldop;
163 150
164 vga_io_w(GRAPHICS_ADDR_REG, DATA_ROTATE_INDEX); 151 oldop = vga_io_rgfx(VGA_GFX_DATA_ROTATE);
165 oldop = vga_io_r(GRAPHICS_DATA_REG); 152 vga_io_w(VGA_GFX_D, op);
166 vga_io_w(GRAPHICS_DATA_REG, op);
167 return oldop; 153 return oldop;
168} 154}
169 155
@@ -173,9 +159,8 @@ static inline int setsr(int sr)
173{ 159{
174 int oldsr; 160 int oldsr;
175 161
176 vga_io_w(GRAPHICS_ADDR_REG, ENABLE_SET_RESET_INDEX); 162 oldsr = vga_io_rgfx(VGA_GFX_SR_ENABLE);
177 oldsr = vga_io_r(GRAPHICS_DATA_REG); 163 vga_io_w(VGA_GFX_D, sr);
178 vga_io_w(GRAPHICS_DATA_REG, sr);
179 return oldsr; 164 return oldsr;
180} 165}
181 166
@@ -184,22 +169,21 @@ static inline int setcolor(int color)
184{ 169{
185 int oldcolor; 170 int oldcolor;
186 171
187 vga_io_w(GRAPHICS_ADDR_REG, SET_RESET_INDEX); 172 oldcolor = vga_io_rgfx(VGA_GFX_SR_VALUE);
188 oldcolor = vga_io_r(GRAPHICS_DATA_REG); 173 vga_io_w(VGA_GFX_D, color);
189 vga_io_w(GRAPHICS_DATA_REG, color);
190 return oldcolor; 174 return oldcolor;
191} 175}
192 176
193/* Return the value in the Graphics Address Register. */ 177/* Return the value in the Graphics Address Register. */
194static inline int getindex(void) 178static inline int getindex(void)
195{ 179{
196 return vga_io_r(GRAPHICS_ADDR_REG); 180 return vga_io_r(VGA_GFX_I);
197} 181}
198 182
199/* Set the value in the Graphics Address Register. */ 183/* Set the value in the Graphics Address Register. */
200static inline void setindex(int index) 184static inline void setindex(int index)
201{ 185{
202 vga_io_w(GRAPHICS_ADDR_REG, index); 186 vga_io_w(VGA_GFX_I, index);
203} 187}
204 188
205static void vga16fb_pan_var(struct fb_info *info, 189static void vga16fb_pan_var(struct fb_info *info,
@@ -672,10 +656,10 @@ static void ega16_setpalette(int regno, unsigned red, unsigned green, unsigned b
672 656
673static void vga16_setpalette(int regno, unsigned red, unsigned green, unsigned blue) 657static void vga16_setpalette(int regno, unsigned red, unsigned green, unsigned blue)
674{ 658{
675 outb(regno, dac_reg); 659 outb(regno, VGA_PEL_IW);
676 outb(red >> 10, dac_val); 660 outb(red >> 10, VGA_PEL_D);
677 outb(green >> 10, dac_val); 661 outb(green >> 10, VGA_PEL_D);
678 outb(blue >> 10, dac_val); 662 outb(blue >> 10, VGA_PEL_D);
679} 663}
680 664
681static int vga16fb_setcolreg(unsigned regno, unsigned red, unsigned green, 665static int vga16fb_setcolreg(unsigned regno, unsigned red, unsigned green,
@@ -719,28 +703,15 @@ static int vga16fb_pan_display(struct fb_var_screeninfo *var,
719 blanking code was originally by Huang shi chao, and modified by 703 blanking code was originally by Huang shi chao, and modified by
720 Christoph Rimek (chrimek@toppoint.de) and todd j. derr 704 Christoph Rimek (chrimek@toppoint.de) and todd j. derr
721 (tjd@barefoot.org) for Linux. */ 705 (tjd@barefoot.org) for Linux. */
722#define attrib_port VGA_ATC_IW
723#define seq_port_reg VGA_SEQ_I
724#define seq_port_val VGA_SEQ_D
725#define gr_port_reg VGA_GFX_I
726#define gr_port_val VGA_GFX_D
727#define video_misc_rd VGA_MIS_R
728#define video_misc_wr VGA_MIS_W
729#define vga_video_port_reg VGA_CRT_IC
730#define vga_video_port_val VGA_CRT_DC
731 706
732static void vga_vesa_blank(struct vga16fb_par *par, int mode) 707static void vga_vesa_blank(struct vga16fb_par *par, int mode)
733{ 708{
734 unsigned char SeqCtrlIndex; 709 unsigned char SeqCtrlIndex = vga_io_r(VGA_SEQ_I);
735 unsigned char CrtCtrlIndex; 710 unsigned char CrtCtrlIndex = vga_io_r(VGA_CRT_IC);
736 711
737 //cli();
738 SeqCtrlIndex = vga_io_r(seq_port_reg);
739 CrtCtrlIndex = vga_io_r(vga_video_port_reg);
740
741 /* save original values of VGA controller registers */ 712 /* save original values of VGA controller registers */
742 if(!par->vesa_blanked) { 713 if(!par->vesa_blanked) {
743 par->vga_state.CrtMiscIO = vga_io_r(video_misc_rd); 714 par->vga_state.CrtMiscIO = vga_io_r(VGA_MIS_R);
744 //sti(); 715 //sti();
745 716
746 par->vga_state.HorizontalTotal = vga_io_rcrt(0x00); /* HorizontalTotal */ 717 par->vga_state.HorizontalTotal = vga_io_rcrt(0x00); /* HorizontalTotal */
@@ -756,12 +727,11 @@ static void vga_vesa_blank(struct vga16fb_par *par, int mode)
756 727
757 /* assure that video is enabled */ 728 /* assure that video is enabled */
758 /* "0x20" is VIDEO_ENABLE_bit in register 01 of sequencer */ 729 /* "0x20" is VIDEO_ENABLE_bit in register 01 of sequencer */
759 //cli();
760 vga_io_wseq(0x01, par->vga_state.ClockingMode | 0x20); 730 vga_io_wseq(0x01, par->vga_state.ClockingMode | 0x20);
761 731
762 /* test for vertical retrace in process.... */ 732 /* test for vertical retrace in process.... */
763 if ((par->vga_state.CrtMiscIO & 0x80) == 0x80) 733 if ((par->vga_state.CrtMiscIO & 0x80) == 0x80)
764 vga_io_w(video_misc_wr, par->vga_state.CrtMiscIO & 0xef); 734 vga_io_w(VGA_MIS_W, par->vga_state.CrtMiscIO & 0xef);
765 735
766 /* 736 /*
767 * Set <End of vertical retrace> to minimum (0) and 737 * Set <End of vertical retrace> to minimum (0) and
@@ -769,12 +739,10 @@ static void vga_vesa_blank(struct vga16fb_par *par, int mode)
769 * Result: turn off vertical sync (VSync) pulse. 739 * Result: turn off vertical sync (VSync) pulse.
770 */ 740 */
771 if (mode & FB_BLANK_VSYNC_SUSPEND) { 741 if (mode & FB_BLANK_VSYNC_SUSPEND) {
772 outb_p(0x10,vga_video_port_reg); /* StartVertRetrace */ 742 vga_io_wcrt(VGA_CRTC_V_SYNC_START, 0xff);
773 outb_p(0xff,vga_video_port_val); /* maximum value */ 743 vga_io_wcrt(VGA_CRTC_V_SYNC_END, 0x40);
774 outb_p(0x11,vga_video_port_reg); /* EndVertRetrace */ 744 /* bits 9,10 of vert. retrace */
775 outb_p(0x40,vga_video_port_val); /* minimum (bits 0..3) */ 745 vga_io_wcrt(VGA_CRTC_OVERFLOW, par->vga_state.Overflow | 0x84);
776 outb_p(0x07,vga_video_port_reg); /* Overflow */
777 outb_p(par->vga_state.Overflow | 0x84,vga_video_port_val); /* bits 9,10 of vert. retrace */
778 } 746 }
779 747
780 if (mode & FB_BLANK_HSYNC_SUSPEND) { 748 if (mode & FB_BLANK_HSYNC_SUSPEND) {
@@ -783,29 +751,22 @@ static void vga_vesa_blank(struct vga16fb_par *par, int mode)
783 * <Start of horizontal Retrace> to maximum 751 * <Start of horizontal Retrace> to maximum
784 * Result: turn off horizontal sync (HSync) pulse. 752 * Result: turn off horizontal sync (HSync) pulse.
785 */ 753 */
786 outb_p(0x04,vga_video_port_reg); /* StartHorizRetrace */ 754 vga_io_wcrt(VGA_CRTC_H_SYNC_START, 0xff);
787 outb_p(0xff,vga_video_port_val); /* maximum */ 755 vga_io_wcrt(VGA_CRTC_H_SYNC_END, 0x00);
788 outb_p(0x05,vga_video_port_reg); /* EndHorizRetrace */
789 outb_p(0x00,vga_video_port_val); /* minimum (0) */
790 } 756 }
791 757
792 /* restore both index registers */ 758 /* restore both index registers */
793 outb_p(SeqCtrlIndex,seq_port_reg); 759 outb_p(SeqCtrlIndex, VGA_SEQ_I);
794 outb_p(CrtCtrlIndex,vga_video_port_reg); 760 outb_p(CrtCtrlIndex, VGA_CRT_IC);
795 //sti();
796} 761}
797 762
798static void vga_vesa_unblank(struct vga16fb_par *par) 763static void vga_vesa_unblank(struct vga16fb_par *par)
799{ 764{
800 unsigned char SeqCtrlIndex; 765 unsigned char SeqCtrlIndex = vga_io_r(VGA_SEQ_I);
801 unsigned char CrtCtrlIndex; 766 unsigned char CrtCtrlIndex = vga_io_r(VGA_CRT_IC);
802 767
803 //cli();
804 SeqCtrlIndex = vga_io_r(seq_port_reg);
805 CrtCtrlIndex = vga_io_r(vga_video_port_reg);
806
807 /* restore original values of VGA controller registers */ 768 /* restore original values of VGA controller registers */
808 vga_io_w(video_misc_wr, par->vga_state.CrtMiscIO); 769 vga_io_w(VGA_MIS_W, par->vga_state.CrtMiscIO);
809 770
810 /* HorizontalTotal */ 771 /* HorizontalTotal */
811 vga_io_wcrt(0x00, par->vga_state.HorizontalTotal); 772 vga_io_wcrt(0x00, par->vga_state.HorizontalTotal);
@@ -827,9 +788,8 @@ static void vga_vesa_unblank(struct vga16fb_par *par)
827 vga_io_wseq(0x01, par->vga_state.ClockingMode); 788 vga_io_wseq(0x01, par->vga_state.ClockingMode);
828 789
829 /* restore index/control registers */ 790 /* restore index/control registers */
830 vga_io_w(seq_port_reg, SeqCtrlIndex); 791 vga_io_w(VGA_SEQ_I, SeqCtrlIndex);
831 vga_io_w(vga_video_port_reg, CrtCtrlIndex); 792 vga_io_w(VGA_CRT_IC, CrtCtrlIndex);
832 //sti();
833} 793}
834 794
835static void vga_pal_blank(void) 795static void vga_pal_blank(void)
@@ -837,10 +797,10 @@ static void vga_pal_blank(void)
837 int i; 797 int i;
838 798
839 for (i=0; i<16; i++) { 799 for (i=0; i<16; i++) {
840 outb_p (i, dac_reg) ; 800 outb_p(i, VGA_PEL_IW);
841 outb_p (0, dac_val) ; 801 outb_p(0, VGA_PEL_D);
842 outb_p (0, dac_val) ; 802 outb_p(0, VGA_PEL_D);
843 outb_p (0, dac_val) ; 803 outb_p(0, VGA_PEL_D);
844 } 804 }
845} 805}
846 806
@@ -1087,12 +1047,15 @@ static void vga16fb_copyarea(struct fb_info *info, const struct fb_copyarea *are
1087 width = x2 - dx; 1047 width = x2 - dx;
1088 height = y2 - dy; 1048 height = y2 - dy;
1089 1049
1050 if (sx + dx < old_dx || sy + dy < old_dy)
1051 return;
1052
1090 /* update sx1,sy1 */ 1053 /* update sx1,sy1 */
1091 sx += (dx - old_dx); 1054 sx += (dx - old_dx);
1092 sy += (dy - old_dy); 1055 sy += (dy - old_dy);
1093 1056
1094 /* the source must be completely inside the virtual screen */ 1057 /* the source must be completely inside the virtual screen */
1095 if (sx < 0 || sy < 0 || (sx + width) > vxres || (sy + height) > vyres) 1058 if (sx + width > vxres || sy + height > vyres)
1096 return; 1059 return;
1097 1060
1098 switch (info->fix.type) { 1061 switch (info->fix.type) {
@@ -1482,6 +1445,7 @@ static void __exit vga16fb_exit(void)
1482 platform_driver_unregister(&vga16fb_driver); 1445 platform_driver_unregister(&vga16fb_driver);
1483} 1446}
1484 1447
1448MODULE_DESCRIPTION("Legacy VGA framebuffer device driver");
1485MODULE_LICENSE("GPL"); 1449MODULE_LICENSE("GPL");
1486module_init(vga16fb_init); 1450module_init(vga16fb_init);
1487module_exit(vga16fb_exit); 1451module_exit(vga16fb_exit);
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 7084e7e146c0..5b78fd0aff0a 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -71,13 +71,6 @@ static int virtio_uevent(struct device *_dv, struct kobj_uevent_env *env)
71 dev->id.device, dev->id.vendor); 71 dev->id.device, dev->id.vendor);
72} 72}
73 73
74static struct bus_type virtio_bus = {
75 .name = "virtio",
76 .match = virtio_dev_match,
77 .dev_attrs = virtio_dev_attrs,
78 .uevent = virtio_uevent,
79};
80
81static void add_status(struct virtio_device *dev, unsigned status) 74static void add_status(struct virtio_device *dev, unsigned status)
82{ 75{
83 dev->config->set_status(dev, dev->config->get_status(dev) | status); 76 dev->config->set_status(dev, dev->config->get_status(dev) | status);
@@ -120,12 +113,16 @@ static int virtio_dev_probe(struct device *_d)
120 set_bit(f, dev->features); 113 set_bit(f, dev->features);
121 } 114 }
122 115
116 /* Transport features always preserved to pass to finalize_features. */
117 for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++)
118 if (device_features & (1 << i))
119 set_bit(i, dev->features);
120
123 err = drv->probe(dev); 121 err = drv->probe(dev);
124 if (err) 122 if (err)
125 add_status(dev, VIRTIO_CONFIG_S_FAILED); 123 add_status(dev, VIRTIO_CONFIG_S_FAILED);
126 else { 124 else {
127 /* They should never have set feature bits beyond 32 */ 125 dev->config->finalize_features(dev);
128 dev->config->set_features(dev, dev->features[0]);
129 add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); 126 add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
130 } 127 }
131 return err; 128 return err;
@@ -147,13 +144,20 @@ static int virtio_dev_remove(struct device *_d)
147 return 0; 144 return 0;
148} 145}
149 146
147static struct bus_type virtio_bus = {
148 .name = "virtio",
149 .match = virtio_dev_match,
150 .dev_attrs = virtio_dev_attrs,
151 .uevent = virtio_uevent,
152 .probe = virtio_dev_probe,
153 .remove = virtio_dev_remove,
154};
155
150int register_virtio_driver(struct virtio_driver *driver) 156int register_virtio_driver(struct virtio_driver *driver)
151{ 157{
152 /* Catch this early. */ 158 /* Catch this early. */
153 BUG_ON(driver->feature_table_size && !driver->feature_table); 159 BUG_ON(driver->feature_table_size && !driver->feature_table);
154 driver->driver.bus = &virtio_bus; 160 driver->driver.bus = &virtio_bus;
155 driver->driver.probe = virtio_dev_probe;
156 driver->driver.remove = virtio_dev_remove;
157 return driver_register(&driver->driver); 161 return driver_register(&driver->driver);
158} 162}
159EXPORT_SYMBOL_GPL(register_virtio_driver); 163EXPORT_SYMBOL_GPL(register_virtio_driver);
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index eae7236310e4..c7dc37c7cce9 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -94,12 +94,17 @@ static u32 vp_get_features(struct virtio_device *vdev)
94 return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES); 94 return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
95} 95}
96 96
97/* virtio config->set_features() implementation */ 97/* virtio config->finalize_features() implementation */
98static void vp_set_features(struct virtio_device *vdev, u32 features) 98static void vp_finalize_features(struct virtio_device *vdev)
99{ 99{
100 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 100 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
101 101
102 iowrite32(features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES); 102 /* Give virtio_ring a chance to accept features. */
103 vring_transport_features(vdev);
104
105 /* We only support 32 feature bits. */
106 BUILD_BUG_ON(ARRAY_SIZE(vdev->features) != 1);
107 iowrite32(vdev->features[0], vp_dev->ioaddr+VIRTIO_PCI_GUEST_FEATURES);
103} 108}
104 109
105/* virtio config->get() implementation */ 110/* virtio config->get() implementation */
@@ -297,7 +302,7 @@ static struct virtio_config_ops virtio_pci_config_ops = {
297 .find_vq = vp_find_vq, 302 .find_vq = vp_find_vq,
298 .del_vq = vp_del_vq, 303 .del_vq = vp_del_vq,
299 .get_features = vp_get_features, 304 .get_features = vp_get_features,
300 .set_features = vp_set_features, 305 .finalize_features = vp_finalize_features,
301}; 306};
302 307
303/* the PCI probing function */ 308/* the PCI probing function */
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 72bf8bc09014..6eb5303fed11 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -18,6 +18,7 @@
18 */ 18 */
19#include <linux/virtio.h> 19#include <linux/virtio.h>
20#include <linux/virtio_ring.h> 20#include <linux/virtio_ring.h>
21#include <linux/virtio_config.h>
21#include <linux/device.h> 22#include <linux/device.h>
22 23
23#ifdef DEBUG 24#ifdef DEBUG
@@ -87,8 +88,11 @@ static int vring_add_buf(struct virtqueue *_vq,
87 if (vq->num_free < out + in) { 88 if (vq->num_free < out + in) {
88 pr_debug("Can't add buf len %i - avail = %i\n", 89 pr_debug("Can't add buf len %i - avail = %i\n",
89 out + in, vq->num_free); 90 out + in, vq->num_free);
90 /* We notify *even if* VRING_USED_F_NO_NOTIFY is set here. */ 91 /* FIXME: for historical reasons, we force a notify here if
91 vq->notify(&vq->vq); 92 * there are outgoing parts to the buffer. Presumably the
93 * host should service the ring ASAP. */
94 if (out)
95 vq->notify(&vq->vq);
92 END_USE(vq); 96 END_USE(vq);
93 return -ENOSPC; 97 return -ENOSPC;
94 } 98 }
@@ -320,4 +324,19 @@ void vring_del_virtqueue(struct virtqueue *vq)
320} 324}
321EXPORT_SYMBOL_GPL(vring_del_virtqueue); 325EXPORT_SYMBOL_GPL(vring_del_virtqueue);
322 326
327/* Manipulates transport-specific feature bits. */
328void vring_transport_features(struct virtio_device *vdev)
329{
330 unsigned int i;
331
332 for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++) {
333 switch (i) {
334 default:
335 /* We don't understand this bit. */
336 clear_bit(i, vdev->features);
337 }
338 }
339}
340EXPORT_SYMBOL_GPL(vring_transport_features);
341
323MODULE_LICENSE("GPL"); 342MODULE_LICENSE("GPL");
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index ccb78f66c2b6..48399e134c0d 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -788,8 +788,6 @@ config WATCHDOG_RIO
788 machines. The watchdog timeout period is normally one minute but 788 machines. The watchdog timeout period is normally one minute but
789 can be changed with a boot-time parameter. 789 can be changed with a boot-time parameter.
790 790
791# V850 Architecture
792
793# XTENSA Architecture 791# XTENSA Architecture
794 792
795# 793#
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 25b352b664d9..edd305a64e63 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -119,8 +119,6 @@ obj-$(CONFIG_SH_WDT) += shwdt.o
119 119
120# SPARC64 Architecture 120# SPARC64 Architecture
121 121
122# V850 Architecture
123
124# XTENSA Architecture 122# XTENSA Architecture
125 123
126# Architecture Independant 124# Architecture Independant
diff --git a/drivers/zorro/zorro-sysfs.c b/drivers/zorro/zorro-sysfs.c
index 3da712cc7708..5290552d2ef7 100644
--- a/drivers/zorro/zorro-sysfs.c
+++ b/drivers/zorro/zorro-sysfs.c
@@ -15,7 +15,6 @@
15#include <linux/zorro.h> 15#include <linux/zorro.h>
16#include <linux/stat.h> 16#include <linux/stat.h>
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/fs.h>
19 18
20#include "zorro.h" 19#include "zorro.h"
21 20