~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/tty/serial/ifx6x60.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *                    Jan Dumon <j.dumon@option.com>
9
9
 *
10
10
 * Copyright (C) 2009, 2010 Intel Corp
11
 
 * Russ Gorby <richardx.r.gorby@intel.com>
 
11
 * Russ Gorby <russ.gorby@intel.com>
12
12
 *
13
13
 * This program is free software; you can redistribute it and/or modify
14
14
 * it under the terms of the GNU General Public License version 2 as
41
41
#include <linux/tty.h>
42
42
#include <linux/device.h>
43
43
#include <linux/spi/spi.h>
44
 
#include <linux/tty.h>
45
44
#include <linux/kfifo.h>
46
45
#include <linux/tty_flip.h>
47
46
#include <linux/timer.h>
56
55
#include <linux/sched.h>
57
56
#include <linux/time.h>
58
57
#include <linux/wait.h>
59
 
#include <linux/tty.h>
60
58
#include <linux/pm.h>
61
59
#include <linux/pm_runtime.h>
62
60
#include <linux/spi/ifx_modem.h>
67
65
#define IFX_SPI_MORE_MASK               0x10
68
66
#define IFX_SPI_MORE_BIT                12      /* bit position in u16 */
69
67
#define IFX_SPI_CTS_BIT                 13      /* bit position in u16 */
 
68
#define IFX_SPI_MODE                    SPI_MODE_1
70
69
#define IFX_SPI_TTY_ID                  0
71
70
#define IFX_SPI_TIMEOUT_SEC             2
72
71
#define IFX_SPI_HEADER_0                (-1)
76
75
static void ifx_spi_handle_srdy(struct ifx_spi_device *ifx_dev);
77
76
 
78
77
/* local variables */
79
 
static int spi_b16 = 1;                 /* 8 or 16 bit word length */
 
78
static int spi_bpw = 16;                /* 8, 16 or 32 bit word length */
80
79
static struct tty_driver *tty_drv;
81
80
static struct ifx_spi_device *saved_ifx_dev;
82
81
static struct lock_class_key ifx_spi_key;
244
243
 *      Map the signal state into Linux modem flags and report the value
245
244
 *      in Linux terms
246
245
 */
247
 
static int ifx_spi_tiocmget(struct tty_struct *tty, struct file *filp)
 
246
static int ifx_spi_tiocmget(struct tty_struct *tty)
248
247
{
249
248
        unsigned int value;
250
249
        struct ifx_spi_device *ifx_dev = tty->driver_data;
262
261
/**
263
262
 *      ifx_spi_tiocmset        -       set modem bits
264
263
 *      @tty: the tty structure
265
 
 *      @filp: file handle issuing the request
266
264
 *      @set: bits to set
267
265
 *      @clear: bits to clear
268
266
 *
271
269
 *
272
270
 *      FIXME: do we need to kick the tranfers when we do this ?
273
271
 */
274
 
static int ifx_spi_tiocmset(struct tty_struct *tty, struct file *filp,
 
272
static int ifx_spi_tiocmset(struct tty_struct *tty,
275
273
                            unsigned int set, unsigned int clear)
276
274
{
277
275
        struct ifx_spi_device *ifx_dev = tty->driver_data;
722
720
                /* note len is BYTES, not transfers */
723
721
                ifx_dev->spi_xfer.len = IFX_SPI_TRANSFER_SIZE;
724
722
                ifx_dev->spi_xfer.cs_change = 0;
725
 
                ifx_dev->spi_xfer.speed_hz = 12500000;
 
723
                ifx_dev->spi_xfer.speed_hz = ifx_dev->spi_dev->max_speed_hz;
726
724
                /* ifx_dev->spi_xfer.speed_hz = 390625; */
727
 
                ifx_dev->spi_xfer.bits_per_word = spi_b16 ? 16 : 8;
 
725
                ifx_dev->spi_xfer.bits_per_word = spi_bpw;
728
726
 
729
727
                ifx_dev->spi_xfer.tx_buf = ifx_dev->tx_buffer;
730
728
                ifx_dev->spi_xfer.rx_buf = ifx_dev->rx_buffer;
732
730
                /*
733
731
                 * setup dma pointers
734
732
                 */
735
 
                if (ifx_dev->is_6160) {
 
733
                if (ifx_dev->use_dma) {
736
734
                        ifx_dev->spi_msg.is_dma_mapped = 1;
737
735
                        ifx_dev->tx_dma = ifx_dev->tx_bus;
738
736
                        ifx_dev->rx_dma = ifx_dev->rx_bus;
798
796
                goto error_ret;
799
797
        }
800
798
 
 
799
        tty_port_init(pport);
801
800
        pport->ops = &ifx_tty_port_ops;
802
 
        tty_port_init(pport);
803
801
        ifx_dev->minor = IFX_SPI_TTY_ID;
804
802
        ifx_dev->tty_dev = tty_register_device(tty_drv, ifx_dev->minor,
805
803
                                               &ifx_dev->spi_dev->dev);
960
958
{
961
959
        int ret;
962
960
        int srdy;
963
 
        struct ifx_modem_platform_data *pl_data = NULL;
 
961
        struct ifx_modem_platform_data *pl_data;
964
962
        struct ifx_spi_device *ifx_dev;
965
963
 
966
964
        if (saved_ifx_dev) {
968
966
                return -ENODEV;
969
967
        }
970
968
 
 
969
        pl_data = (struct ifx_modem_platform_data *)spi->dev.platform_data;
 
970
        if (!pl_data) {
 
971
                dev_err(&spi->dev, "missing platform data!");
 
972
                return -ENODEV;
 
973
        }
 
974
 
971
975
        /* initialize structure to hold our device variables */
972
976
        ifx_dev = kzalloc(sizeof(struct ifx_spi_device), GFP_KERNEL);
973
977
        if (!ifx_dev) {
983
987
        init_timer(&ifx_dev->spi_timer);
984
988
        ifx_dev->spi_timer.function = ifx_spi_timeout;
985
989
        ifx_dev->spi_timer.data = (unsigned long)ifx_dev;
986
 
        ifx_dev->is_6160 = pl_data->is_6160;
 
990
        ifx_dev->modem = pl_data->modem_type;
 
991
        ifx_dev->use_dma = pl_data->use_dma;
 
992
        ifx_dev->max_hz = pl_data->max_hz;
 
993
        /* initialize spi mode, etc */
 
994
        spi->max_speed_hz = ifx_dev->max_hz;
 
995
        spi->mode = IFX_SPI_MODE | (SPI_LOOP & spi->mode);
 
996
        spi->bits_per_word = spi_bpw;
 
997
        ret = spi_setup(spi);
 
998
        if (ret) {
 
999
                dev_err(&spi->dev, "SPI setup wasn't successful %d", ret);
 
1000
                return -ENODEV;
 
1001
        }
987
1002
 
988
1003
        /* ensure SPI protocol flags are initialized to enable transfer */
989
1004
        ifx_dev->spi_more = 0;
990
1005
        ifx_dev->spi_slave_cts = 0;
991
1006
 
992
1007
        /*initialize transfer and dma buffers */
993
 
        ifx_dev->tx_buffer = dma_alloc_coherent(&ifx_dev->spi_dev->dev,
 
1008
        ifx_dev->tx_buffer = dma_alloc_coherent(ifx_dev->spi_dev->dev.parent,
994
1009
                                IFX_SPI_TRANSFER_SIZE,
995
1010
                                &ifx_dev->tx_bus,
996
1011
                                GFP_KERNEL);
999
1014
                ret = -ENOMEM;
1000
1015
                goto error_ret;
1001
1016
        }
1002
 
        ifx_dev->rx_buffer = dma_alloc_coherent(&ifx_dev->spi_dev->dev,
 
1017
        ifx_dev->rx_buffer = dma_alloc_coherent(ifx_dev->spi_dev->dev.parent,
1003
1018
                                IFX_SPI_TRANSFER_SIZE,
1004
1019
                                &ifx_dev->rx_bus,
1005
1020
                                GFP_KERNEL);
1025
1040
                goto error_ret;
1026
1041
        }
1027
1042
 
1028
 
        pl_data = (struct ifx_modem_platform_data *)spi->dev.platform_data;
1029
 
        if (pl_data) {
1030
 
                ifx_dev->gpio.reset = pl_data->rst_pmu;
1031
 
                ifx_dev->gpio.po = pl_data->pwr_on;
1032
 
                ifx_dev->gpio.mrdy = pl_data->mrdy;
1033
 
                ifx_dev->gpio.srdy = pl_data->srdy;
1034
 
                ifx_dev->gpio.reset_out = pl_data->rst_out;
1035
 
        } else {
1036
 
                dev_err(&spi->dev, "missing platform data!");
1037
 
                ret = -ENODEV;
1038
 
                goto error_ret;
1039
 
        }
 
1043
        ifx_dev->gpio.reset = pl_data->rst_pmu;
 
1044
        ifx_dev->gpio.po = pl_data->pwr_on;
 
1045
        ifx_dev->gpio.mrdy = pl_data->mrdy;
 
1046
        ifx_dev->gpio.srdy = pl_data->srdy;
 
1047
        ifx_dev->gpio.reset_out = pl_data->rst_out;
1040
1048
 
1041
1049
        dev_info(&spi->dev, "gpios %d, %d, %d, %d, %d",
1042
1050
                 ifx_dev->gpio.reset, ifx_dev->gpio.po, ifx_dev->gpio.mrdy,
1322
1330
MODULE_DEVICE_TABLE(spi, ifx_id_table);
1323
1331
 
1324
1332
/* spi operations */
1325
 
static const struct spi_driver ifx_spi_driver_6160 = {
 
1333
static const struct spi_driver ifx_spi_driver = {
1326
1334
        .driver = {
1327
 
                .name = "ifx6160",
 
1335
                .name = DRVNAME,
1328
1336
                .bus = &spi_bus_type,
1329
1337
                .pm = &ifx_spi_pm,
1330
1338
                .owner = THIS_MODULE},
1346
1354
{
1347
1355
        /* unregister */
1348
1356
        tty_unregister_driver(tty_drv);
1349
 
        spi_unregister_driver((void *)&ifx_spi_driver_6160);
 
1357
        spi_unregister_driver((void *)&ifx_spi_driver);
1350
1358
}
1351
1359
 
1352
1360
/**
1388
1396
                return result;
1389
1397
        }
1390
1398
 
1391
 
        result = spi_register_driver((void *)&ifx_spi_driver_6160);
 
1399
        result = spi_register_driver((void *)&ifx_spi_driver);
1392
1400
        if (result) {
1393
1401
                pr_err("%s: spi_register_driver failed(%d)",
1394
1402
                        DRVNAME, result);