Skip to contentSkip to conversation

New drivers from Blackfin Linux Team

PATCH In review Bryan Wu 6 participants 13 messages Oct 11, 2007 – Feb 4, 2008

Subsystems (4)
lore
Share & tools
lore

Bryan Wu

author
#0 lore raw

cover New drivers from Blackfin Linux Team

author
#1 lore raw

PATCH 1/3 Input/Joystick Driver: add support AD7142 joystick driver

From: Michael Hennerich <[email protected]>

---
 drivers/input/joystick/Kconfig  |   16 ++
 drivers/input/joystick/Makefile |    1 +
 drivers/input/joystick/ad7142.c |  450 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 467 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/joystick/ad7142.c
drivers/input/joystick/Kconfig +16 -0
index 7c662ee..aeb7cc9 100644
@@ -282,4 +282,20 @@ config JOYSTICK_XPAD_LEDS
 	  This option enables support for the LED which surrounds the Big X on
 	  XBox 360 controller.
 
+config JOYSTICK_AD7142
+         tristate "Analog Devices AD7142 Joystick support"
+         depends on BFIN && I2C
+         help
+           Say Y here if you want to support an AD7142 joystick
+
+
+ config BFIN_JOYSTICK_IRQ_PFX
+         int "GPIO for Interrupt"
+         depends on (BFIN && JOYSTICK_AD7142)
+         range 33 120
+         default "55" if BFIN537_STAMP
+         default "39" if BFIN533_STAMP
+         help
+           Choose an GPIO as Keypad interrupt.[0..15]
+
 endif
drivers/input/joystick/Makefile +1 -0
index e855abb..8df388f 100644
@@ -5,6 +5,7 @@
 # Each configuration option enables a list of files.
 
 obj-$(CONFIG_JOYSTICK_A3D)		+= a3d.o
+obj-$(CONFIG_JOYSTICK_AD7142)		+= ad7142.o
 obj-$(CONFIG_JOYSTICK_ADI)		+= adi.o
 obj-$(CONFIG_JOYSTICK_AMIGA)		+= amijoy.o
 obj-$(CONFIG_JOYSTICK_ANALOG)		+= analog.o
drivers/input/joystick/ad7142.c new file +450 -0

450 lines not on this page · raw message

Signature · 1 line
1.5.3.4
maintainer
#2 lore raw

Re: [PATCH 1/3] Input/Joystick Driver: add support AD7142 joystick driver

Hi Brian, Michael,

Quoted 4 lines · Bryan Wu

From: Michael Hennerich <[email protected]>

Thank you for the patch. The formatting of the patch is unorthodox, could you please run it through lindent? Also:

drivers/input/joystick/ad7142.c line 54

Quoted 9 lines
drivers/input/joystick/ad7142.c new file +9 -0
+
+#undef  DEBUG
+
+#ifdef DEBUG
+#define DPRINTK(x...)   printk(x)
+#else
+#define DPRINTK(x...)   do { } while (0)
+#endif
+

pr_debug()

drivers/input/joystick/ad7142.c line 66

Quoted 12 lines
drivers/input/joystick/ad7142.c new file +12 -0
+MODULE_AUTHOR("Aubrey Li <[email protected]>");
+MODULE_DESCRIPTION("Driver for AD7142 joysticks");
+MODULE_LICENSE("GPL");
+
+/*
+ * Feeding the output queue to the device is handled by way of a
+ * workqueue.
+ */
+static struct task_struct *ad7142_task;
+static DECLARE_WAIT_QUEUE_HEAD(ad7142_wait);
+
+static int ad7142_used=0;

No need to initialize. In fact, this variable is not needed at all.

drivers/input/joystick/ad7142.c line 71

Quoted 5 lines
drivers/input/joystick/ad7142.c new file +5 -0
+static struct input_dev *ad7142_dev;
+static char *ad7142_phys={"ad7142/input0"};
+
+static char *ad7142_name = "ad7142 joystick";
+

Just use literals right in the _probe() function - that is the only place where they are used as far as I can see.

Quoted 1 line

+static unsigned short stage[5][8]={

const?

Quoted 22 lines
drivers/input/joystick/ad7142.c new file +22 -0
+
+static int
+ad7142_i2c_write(struct i2c_client *client,
+                    unsigned short    offset,
+                     unsigned short    *data,
+                     unsigned int       len)
+{
+        int ret = -1;
+       int i;
+
+       if(len<1 || len>16){
+               printk("AD7142: Write data length error\n");
+               return ret;
+       }
+        /* the adv7142 has an autoincrement function, use it if
+         * the adapter understands raw I2C */
+        if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
+                /* do raw I2C, not smbus compatible */
+               u8 block_data[34];
+
+               block_data[0] = (offset & 0xFF00)>>8;
+               block_data[1] = (offset & 0x00FF);

drivers/input/joystick/ad7142.c line 211

Quoted 10 lines
drivers/input/joystick/ad7142.c new file +10 -0
+               for(i=0;i<len;i++){
+                       block_data[2*i+2] = (*data & 0xFF00)>>8;
+                       block_data[2*i+3] = *data++ & 0x00FF;
+               }
+               if((ret = i2c_master_send(client, block_data,len*2+2))<0){
+                       printk("AD7142: I2C write error\n");
+                       return ret;
+               }
+       } else
+               printk("AD7142: i2c bus doesn't support raw I2C operation\n");

Does not this condition cause driver to fail completely? If so I'd move it in probe function and not even try initializing the device if functionality is missing.

drivers/input/joystick/ad7142.c line 279

Quoted 2 lines
drivers/input/joystick/ad7142.c new file +2 -0
+
+unsigned short old_status_low=0,old_status_high=0;

Initialization is not needed and I'd move these inside ad7142_decode().

drivers/input/joystick/ad7142.c line 283

Quoted 4 lines
drivers/input/joystick/ad7142.c new file +4 -0
+
+static void ad7142_decode(void)
+{
+       unsigned short irqno_low=0,irqno_high=0;

Why do you need to initialize these?

drivers/input/joystick/ad7142.c line 290

Quoted 7 lines
drivers/input/joystick/ad7142.c new file +7 -0
+        unsigned short temp;
+
+        ad7142_i2c_read(ad7142_client,INTSTAT_REG0,&irqno_low,1);
+        temp = irqno_low ^ old_status_low;
+       switch(temp){
+       case 0x0001:    input_report_key(ad7142_dev, BTN_BASE, irqno_low&0x0001);
+                       old_status_low = irqno_low;

This can be moved out of switch statement.

Quoted 6 lines
drivers/input/joystick/ad7142.c new file +6 -0
+                       break;
+       case 0x0002:    input_report_key(ad7142_dev, BTN_BASE4, (irqno_low&0x0002)>>1);
+                        old_status_low = irqno_low;
+                        break;
+       case 0x0004:    input_report_key(ad7142_dev, KEY_UP, (irqno_low&0x0004)>>2);
+                        old_status_low = irqno_low;

drivers/input/joystick/ad7142.c line 306

Quoted 10 lines
drivers/input/joystick/ad7142.c new file +10 -0
+                        break;
+       case 0x0008:    input_report_key(ad7142_dev, KEY_RIGHT, (irqno_low&0x0008)>>3);
+                        old_status_low = irqno_low;
+                        break;
+        }
+        ad7142_i2c_read(ad7142_client,INTSTAT_REG1,&irqno_high,1);
+        temp = irqno_high ^ old_status_high;
+       switch(temp){
+       case 0x0001:    input_report_key(ad7142_dev, BTN_BASE2, irqno_high&0x0001);
+                       old_status_high = irqno_high;

Same here.

Quoted 29 lines
drivers/input/joystick/ad7142.c new file +29 -0
+                       break;
+       case 0x0002:    input_report_key(ad7142_dev, BTN_BASE3, (irqno_high&0x0002)>>1);
+                        old_status_high = irqno_high;
+                        break;
+       case 0x0004:    input_report_key(ad7142_dev, KEY_DOWN, (irqno_high&0x0004)>>2);
+                        old_status_high = irqno_high;
+                        break;
+       case 0x0008:    input_report_key(ad7142_dev, KEY_LEFT, (irqno_high&0x0008)>>3);
+                        old_status_high = irqno_high;
+                        break;
+        }
+        input_sync(ad7142_dev);
+}
+
+
+static int intr_flag = 0;
+static int ad7142_thread(void *nothing)
+{
+        do {
+               wait_event_interruptible(ad7142_wait, kthread_should_stop() || (intr_flag!=0));
+               ad7142_decode();
+                intr_flag = 0;
+               enable_irq(CONFIG_BFIN_JOYSTICK_IRQ_PFX);
+        } while (!kthread_should_stop());
+        printk(KERN_DEBUG "ad7142: kthread exiting\n");
+        return 0;
+}
+
+static irqreturn_t ad7142_interrupt(int irq, void *dummy, struct pt_regs *fp)

drivers/input/joystick/ad7142.c line 345

Quoted 10 lines
drivers/input/joystick/ad7142.c new file +10 -0
+{
+       disable_irq(CONFIG_BFIN_JOYSTICK_IRQ_PFX);
+       intr_flag = 1;
+       wake_up_interruptible(&ad7142_wait);
+       return IRQ_HANDLED;
+}
+
+static int ad7142_open(struct input_dev *dev)
+{
+       int *used = dev->private;

input_get_drvdata()

drivers/input/joystick/ad7142.c line 353

Quoted 8 lines
drivers/input/joystick/ad7142.c new file +8 -0
+       unsigned short id,value;
+       ad7142_i2c_read(ad7142_client, DEVID, &id, 1);
+       if(id != AD7142_I2C_ID){
+               printk(KERN_ERR "Open AD7142 error\n");
+               return -ENODEV;
+       }
+       if ((*used)++)
+               return 0;

No need to count, input core serializes open and close and makes sure they are called only once.

drivers/input/joystick/ad7142.c line 360

Quoted 7 lines
drivers/input/joystick/ad7142.c new file +7 -0
+
+       if (request_irq(CONFIG_BFIN_JOYSTICK_IRQ_PFX, ad7142_interrupt, \
+               IRQF_TRIGGER_LOW, "ad7142_joy", ad7142_interrupt)) {
+               (*used)--;
+               printk(KERN_ERR "ad7142.c: Can't allocate irq %d\n",CONFIG_BFIN_JOYSTICK_IRQ_PFX);
+               return -EBUSY;
+       }

What are the chances for IRQ to be used by 2 drivers? Maybe just request_irq in proble?

Quoted 51 lines
drivers/input/joystick/ad7142.c new file +51 -0
+
+
+       ad7142_i2c_write(ad7142_client,STAGE0_CONNECTION,stage[0],8);
+       ad7142_i2c_write(ad7142_client,STAGE1_CONNECTION,stage[1],8);
+       ad7142_i2c_write(ad7142_client,STAGE2_CONNECTION,stage[2],8);
+       ad7142_i2c_write(ad7142_client,STAGE3_CONNECTION,stage[3],8);
+       ad7142_i2c_write(ad7142_client,STAGE4_CONNECTION,stage[4],8);
+       ad7142_i2c_write(ad7142_client,STAGE5_CONNECTION,stage[4],8);
+       ad7142_i2c_write(ad7142_client,STAGE6_CONNECTION,stage[4],8);
+       ad7142_i2c_write(ad7142_client,STAGE7_CONNECTION,stage[4],8);
+       ad7142_i2c_write(ad7142_client,STAGE8_CONNECTION,stage[4],8);
+       ad7142_i2c_write(ad7142_client,STAGE9_CONNECTION,stage[4],8);
+       ad7142_i2c_write(ad7142_client,STAGE10_CONNECTION,stage[4],8);
+       ad7142_i2c_write(ad7142_client,STAGE11_CONNECTION,stage[4],8);
+
+       value = 0x00B0;
+       ad7142_i2c_write(ad7142_client,PWRCONVCTL,&value,1);
+
+       value = 0x0690;
+       ad7142_i2c_write(ad7142_client,AMBCOMPCTL_REG1,&value,1);
+
+       value = 0x0664;
+       ad7142_i2c_write(ad7142_client,AMBCOMPCTL_REG2,&value,1);
+
+       value = 0x290F;
+       ad7142_i2c_write(ad7142_client,AMBCOMPCTL_REG3,&value,1);
+
+       value = 0x000F;
+       ad7142_i2c_write(ad7142_client,INTEN_REG0,&value,1);
+       ad7142_i2c_write(ad7142_client,INTEN_REG1,&value,1);
+
+       value = 0x0000;
+       ad7142_i2c_write(ad7142_client,INTEN_REG2,&value,1);
+
+       ad7142_i2c_read(ad7142_client,AMBCOMPCTL_REG1,&value,1);
+
+       value = 0x000F;
+       ad7142_i2c_write(ad7142_client,AMBCOMPCTL_REG0,&value,1);
+
+       ad7142_task = kthread_run(ad7142_thread, NULL, "ad7142_task");
+        if (IS_ERR(ad7142_task)) {
+                printk(KERN_ERR "serio: Failed to start kseriod\n");
+                return PTR_ERR(ad7142_task);
+        }
+       return 0;
+}
+
+static void ad7142_close(struct input_dev *dev)
+{
+       int *used = dev->private;
+

drivers/input/joystick/ad7142.c line 421

Quoted 10 lines
drivers/input/joystick/ad7142.c new file +10 -0
+       if (!--(*used))
+               free_irq(CONFIG_BFIN_JOYSTICK_IRQ_PFX, ad7142_interrupt);
+       kthread_stop(ad7142_task);
+}
+
+static int __init ad7142_init(void)
+{
+       ad7142_dev = input_allocate_device();
+       if(!ad7142_dev)
+               return -ENOMEM;

This should be done when you bind to i2c device, not before.

Quoted 4 lines
drivers/input/joystick/ad7142.c new file +4 -0
+       ad7142_dev->open = ad7142_open;
+       ad7142_dev->close = ad7142_close;
+       ad7142_dev->evbit[0] = BIT(EV_KEY);
+       ad7142_dev->keybit[LONG(BTN_BASE)] = BIT(BTN_BASE) | BIT(BTN_BASE2) | BIT(BTN_BASE3) | BIT(BTN_BASE4);

drivers/input/joystick/ad7142.c line 435

Quoted 10 lines
drivers/input/joystick/ad7142.c new file +10 -0
+       ad7142_dev->keybit[LONG(KEY_UP)] |= BIT(KEY_UP) | BIT(KEY_DOWN) | BIT(KEY_LEFT) | BIT(KEY_RIGHT);
+
+       ad7142_dev->name = ad7142_name;
+       ad7142_dev->phys = ad7142_phys;
+       ad7142_dev->id.bustype = BUS_I2C;
+       ad7142_dev->id.vendor = 0x0001;
+       ad7142_dev->id.product = 0x0001;
+       ad7142_dev->id.version = 0x0100;
+
+       ad7142_dev->private = &ad7142_used;

input_set_drvdata();

drivers/input/joystick/ad7142.c line 437

Quoted 2 lines
drivers/input/joystick/ad7142.c new file +2 -0
+
+       input_register_device(ad7142_dev);

Error handling please.

Quoted 14 lines
drivers/input/joystick/ad7142.c new file +13 -1
+       i2c_add_driver (&ad7142_driver);
+
+       return 0;
+}
+
+static void __exit ad7142_exit(void)
+{
+       i2c_del_driver (&ad7142_driver);
+       input_unregister_device(ad7142_dev);
+}
+
+module_init(ad7142_init);
+module_exit(ad7142_exit);
--
Quoted 2 lines

1.5.3.4

Thanks!

Signature · 1 line
Dmitry
author
#3 lore raw

PATCH 2/3 Input/Touchscreen Driver: add support AD7877 touchscreen driver

In reply to Bryan Wu

From: Michael Hennerich <[email protected]>

---
 drivers/input/touchscreen/Kconfig  |   13 +
 drivers/input/touchscreen/Makefile |    1 +
 drivers/input/touchscreen/ad7877.c |  973 ++++++++++++++++++++++++++++++++++++
 3 files changed, 987 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/touchscreen/ad7877.c
drivers/input/touchscreen/Kconfig +13 -0
index f929fcd..d755048 100644
@@ -29,6 +29,19 @@ config TOUCHSCREEN_ADS7846
 	  To compile this driver as a module, choose M here: the
 	  module will be called ads7846.
 
+config TOUCHSCREEN_AD7877
+	tristate "AD7877 based touchscreens"
+	depends on SPI_MASTER
+	help
+	  Say Y here if you have a touchscreen interface using the
+	  AD7877 controller, and your board-specific initialization
+	  code includes that in its table of SPI devices.
+
+	  If unsure, say N (but it's safe to say "Y").
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ad7877.
+
 config TOUCHSCREEN_BITSY
 	tristate "Compaq iPAQ H3600 (Bitsy) touchscreen"
 	depends on SA1100_BITSY
drivers/input/touchscreen/Makefile +1 -0
index 5de8933..5ee3c2b 100644
@@ -4,6 +4,7 @@
 
 # Each configuration option enables a list of files.
 
+obj-$(CONFIG_TOUCHSCREEN_AD7877)	+= ad7877.o
 obj-$(CONFIG_TOUCHSCREEN_ADS7846)	+= ads7846.o
 obj-$(CONFIG_TOUCHSCREEN_BITSY)		+= h3600_ts_input.o
 obj-$(CONFIG_TOUCHSCREEN_CORGI)		+= corgi_ts.o
drivers/input/touchscreen/ad7877.c new file +973 -0

973 lines not on this page · raw message

Signature · 1 line
1.5.3.4
maintainer
#4 lore raw

Re: [PATCH 2/3] Input/Touchscreen Driver: add support AD7877 touchscreen driver

Hi Bryan, Michael,

Review

Quoted 2 lines · Bryan Wu
(quoted diff) +2 -0
+
+static int gpio3 = 0;

No need to initialize.

drivers/input/touchscreen/ad7877.c line 245

Quoted 5 lines
drivers/input/touchscreen/ad7877.c new file +5 -0
+
+static int ad7877_read(struct device *dev, u16 reg)
+{
+       struct spi_device       *spi = to_spi_device(dev);
+       struct ser_req          *req = kzalloc(sizeof *req, GFP_KERNEL);

How many reads can happen at once? Maybe allocate 1 ser_req per touchcsreen when creating it?

Quoted 12 lines
drivers/input/touchscreen/ad7877.c new file +12 -0
+
+       if (likely(x && z1 && !device_suspended(&ts->spi->dev))) {
+               /* compute touch pressure resistance using equation #2 */
+               Rt = z2;
+               Rt -= z1;
+               Rt *= x;
+               Rt *= ts->x_plate_ohms;
+               Rt /= z1;
+               Rt = (Rt + 2047) >> 12;
+       } else
+               Rt = 0;
+

drivers/input/touchscreen/ad7877.c line 572

Quoted 10 lines
drivers/input/touchscreen/ad7877.c new file +10 -0
+       if (Rt) {
+               input_report_abs(input_dev, ABS_X, x);
+               input_report_abs(input_dev, ABS_Y, y);
+               sync = 1;
+       }
+
+       if (sync) {
+               input_report_abs(input_dev, ABS_PRESSURE, Rt);
+               input_sync(input_dev);
+       }

Confused about the logic - you set sync only if Rt != 0 so why don't fold second "if" into the first one?

Quoted 17 lines
drivers/input/touchscreen/ad7877.c new file +17 -0
+/* Must be called with ts->lock held */
+static void ad7877_disable(struct ad7877 *ts)
+{
+       if (ts->disabled)
+               return;
+
+       ts->disabled = 1;
+
+       if (!ts->pending) {
+               ts->irq_disabled = 1;
+               disable_irq(ts->spi->irq);
+       } else {
+               /* the kthread will run at least once more, and
+                * leave everything in a clean state, IRQ disabled
+                */
+               while (ts->pending) {
+                       spin_unlock_irq(&ts->lock);

drivers/input/touchscreen/ad7877.c line 689

Quoted 10 lines
drivers/input/touchscreen/ad7877.c new file +10 -0
+                       msleep(1);
+                       spin_lock_irq(&ts->lock);
+               }
+       }
+
+       /* we know the chip's in lowpower mode since we always
+        * leave it that way after every request
+        */
+
+}

This looks scary. Can you try moving locking inside ad7877_enable and ad7877_disable?

Quoted 56 lines
drivers/input/touchscreen/ad7877.c new file +56 -0
+
+static int __devinit ad7877_probe(struct spi_device *spi)
+{
+       struct ad7877                   *ts;
+       struct input_dev                *input_dev;
+       struct ad7877_platform_data     *pdata = spi->dev.platform_data;
+       struct spi_message              *m;
+       int                             err;
+       u16                             verify;
+
+
+       if (!spi->irq) {
+               dev_dbg(&spi->dev, "no IRQ?\n");
+               return -ENODEV;
+       }
+
+
+       if (!pdata) {
+               dev_dbg(&spi->dev, "no platform data?\n");
+               return -ENODEV;
+       }
+
+
+       /* don't exceed max specified SPI CLK frequency */
+       if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) {
+               dev_dbg(&spi->dev, "SPI CLK %d Hz?\n",spi->max_speed_hz);
+               return -EINVAL;
+       }
+
+       ts = kzalloc(sizeof(struct ad7877), GFP_KERNEL);
+       input_dev = input_allocate_device();
+       if (!ts || !input_dev) {
+               err = -ENOMEM;
+               goto err_free_mem;
+       }
+
+
+       dev_set_drvdata(&spi->dev, ts);
+       spi->dev.power.power_state = PMSG_ON;
+
+       ts->spi = spi;
+       ts->input = input_dev;
+       ts->intr_flag = 0;
+       init_timer(&ts->timer);
+       ts->timer.data = (unsigned long) ts;
+       ts->timer.function = ad7877_timer;
+
+       spin_lock_init(&ts->lock);
+
+       ts->model = pdata->model ? : 7877;
+       ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100;
+       ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
+       ts->pressure_max = pdata->pressure_max ? : ~0;
+
+
+       ts->stopacq_polarity = pdata->stopacq_polarity;

drivers/input/touchscreen/ad7877.c line 795

Quoted 10 lines
drivers/input/touchscreen/ad7877.c new file +10 -0
+       ts->first_conversion_delay = pdata->first_conversion_delay;
+       ts->acquisition_time = pdata->acquisition_time;
+       ts->averaging = pdata->averaging;
+       ts->pen_down_acc_interval = pdata->pen_down_acc_interval;
+
+       snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id);
+
+       input_dev->name = "AD7877 Touchscreen";
+       input_dev->phys = ts->phys;
+       input_dev->cdev.dev = &spi->dev;

Please use input_dev->dev.parent, i will kill 'cdev' soon.

drivers/input/touchscreen/ad7877.c line 895

Quoted 12 lines
drivers/input/touchscreen/ad7877.c new file +12 -0
+
+       err = input_register_device(input_dev);
+       if (err)
+               goto err_remove_attr;
+
+       ts->intr_flag = 0;
+
+       ad7877_task = kthread_run(ad7877_thread, ts, "ad7877_ktsd");
+
+        if (IS_ERR(ad7877_task)) {
+                printk(KERN_ERR "ts: Failed to start ad7877_task\n");
+                goto err_remove_attr;

You shoudl use input_unregister_device() once it was registered. So you need something like

             goto err_unregister_idev;

...
err_unregister_idev:
input_unregister_device(input_dev);
input-dve = NULL; /* so we don't try to free it later */
err_remove_attr:
...

Quoted 20 lines
drivers/input/touchscreen/ad7877.c new file +20 -0
+        }
+
+       return 0;
+
+ err_remove_attr:
+
+       sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group);
+
+       if(gpio3)
+               device_remove_file(&spi->dev, &dev_attr_gpio3);
+       else
+               device_remove_file(&spi->dev, &dev_attr_aux3);
+
+
+       free_irq(spi->irq, ts);
+ err_free_mem:
+       input_free_device(input_dev);
+       kfree(ts);
+       return err;
+}

drivers/input/touchscreen/ad7877.c line 925

Quoted 10 lines
drivers/input/touchscreen/ad7877.c new file +10 -0
+
+static int __devexit ad7877_remove(struct spi_device *spi)
+{
+       struct ad7877           *ts = dev_get_drvdata(&spi->dev);
+
+       input_unregister_device(ts->input);
+
+       ad7877_suspend(spi, PMSG_SUSPEND);
+
+       kthread_stop(ad7877_task);

You don't want to unregister device before stopping interrupts/kthread. Otherwise there is a chance you will try to use just freed device to send event through.

The driver also contains some indenting damage, please re-check.

Thanks!

Signature · 1 line
Dmitry
author
#5 lore raw

PATCH 3/3 Blackfin serial driver: this driver enable SPORTs on Blackfin emulate UART

In reply to Bryan Wu
---
 drivers/serial/Kconfig           |   43 +++
 drivers/serial/Makefile          |    1 +
 drivers/serial/bfin_sport_uart.c |  614 ++++++++++++++++++++++++++++++++++++++
 drivers/serial/bfin_sport_uart.h |   63 ++++
 include/linux/serial_core.h      |    2 +
 5 files changed, 723 insertions(+), 0 deletions(-)
 create mode 100644 drivers/serial/bfin_sport_uart.c
 create mode 100644 drivers/serial/bfin_sport_uart.h
drivers/serial/Kconfig +43 -0
index 81b52b7..f3bfbe1 100644
@@ -1259,4 +1259,47 @@ config SERIAL_OF_PLATFORM
 	  Currently, only 8250 compatible ports are supported, but
 	  others can easily be added.
 
+config SERIAL_BFIN_SPORT
+	tristate "Blackfin SPORT emulate UART (EXPERIMENTAL)"
+	depends on BFIN && EXPERIMENTAL
+	select SERIAL_CORE
+	help
+	  Enble support SPORT emulate UART on Blackfin series.
+
+	  To compile this driver as a module, choose M here: the 
+	  module will be called bfin_sport_uart.
+
+choice
+	prompt "Baud rate for Blackfin SPORT UART"
+	depends on SERIAL_BFIN_SPORT
+	default SERIAL_SPORT_BAUD_RATE_57600
+	help
+	  Choose a baud rate for the SPORT UART, other uart settings are
+	  8 bit, 1 stop bit, no parity, no flow control.
+
+config SERIAL_SPORT_BAUD_RATE_115200
+	bool "115200"
+
+config SERIAL_SPORT_BAUD_RATE_57600
+	bool "57600"
+
+config SERIAL_SPORT_BAUD_RATE_38400
+	bool "38400"
+
+config SERIAL_SPORT_BAUD_RATE_19200
+	bool "19200"
+
+config SERIAL_SPORT_BAUD_RATE_9600
+	bool "9600"
+endchoice
+
+config SPORT_BAUD_RATE
+	int
+	depends on SERIAL_BFIN_SPORT
+	default 115200 if (SERIAL_SPORT_BAUD_RATE_115200)
+	default 57600 if (SERIAL_SPORT_BAUD_RATE_57600)
+	default 38400 if (SERIAL_SPORT_BAUD_RATE_38400)
+	default 19200 if (SERIAL_SPORT_BAUD_RATE_19200)
+	default 9600 if (SERIAL_SPORT_BAUD_RATE_9600)
+
 endmenu
drivers/serial/Makefile +1 -0
index af6377d..05dea96 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_SERIAL_PXA) += pxa.o
 obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
 obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
 obj-$(CONFIG_SERIAL_BFIN) += bfin_5xx.o
+obj-$(CONFIG_SERIAL_BFIN_SPORT) += bfin_sport_uart.o
 obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o
 obj-$(CONFIG_SERIAL_SUNCORE) += suncore.o
 obj-$(CONFIG_SERIAL_SUNHV) += sunhv.o
drivers/serial/bfin_sport_uart.c new file +614 -0

614 lines not on this page · raw message

drivers/serial/bfin_sport_uart.h new file +63 -0

63 lines not on this page · raw message

include/linux/serial_core.h +2 -0
index 09d17b0..e257302 100644
@@ -146,6 +146,8 @@
 /* Broadcom SB1250, etc. SOC */
 #define PORT_SB1250_DUART	77
 
+/* Blackfin SPORT */
+#define PORT_BFIN_SPORT		78
 
 #ifdef __KERNEL__
 
Signature · 1 line
1.5.3.4
#6 lore raw

Re: [PATCH 3/3] Blackfin serial driver: this driver enable SPORTs on Blackfin emulate UART

Quoted 2 lines

Subject: [PATCH 3/3] Blackfin serial driver: this driver enable SPORTs on Blackfin emulate UART

That's a bit hard to parse.

Quoted 16 lines · On Thu, 11 Oct 2007 18:23:40 +0800 Bryan Wu <[email protected]> wrote:
---
 drivers/serial/Kconfig           |   43 +++
 drivers/serial/Makefile          |    1 +
 drivers/serial/bfin_sport_uart.c |  614 ++++++++++++++++++++++++++++++++++++++
 drivers/serial/bfin_sport_uart.h |   63 ++++
 include/linux/serial_core.h      |    2 +
 5 files changed, 723 insertions(+), 0 deletions(-)
 create mode 100644 drivers/serial/bfin_sport_uart.c
 create mode 100644 drivers/serial/bfin_sport_uart.h
drivers/serial/Kconfig +0 -0
index 81b52b7..f3bfbe1 100644

drivers/serial/Kconfig config SERIAL_OF_PLATFORM · line 1267

Quoted 9 lines
drivers/serial/Kconfig +6 -0
@@ -1259,4 +1259,47 @@ config SERIAL_OF_PLATFORM
 	  Currently, only 8250 compatible ports are supported, but
 	  others can easily be added.
 
+config SERIAL_BFIN_SPORT
+	tristate "Blackfin SPORT emulate UART (EXPERIMENTAL)"
+	depends on BFIN && EXPERIMENTAL
+	select SERIAL_CORE
+	help
+	  Enble support SPORT emulate UART on Blackfin series.

There's a typo there. Also the text is pretty meaningless - I'd fix it up but I'm not sure what it's trying to tell us!

drivers/serial/Kconfig config SERIAL_OF_PLATFORM · line 1268

Quoted 1 line
drivers/serial/Kconfig +1 -0
+//#define DEBUG

Probably this shouldn't be here at all - DEBUG is passed in from the gcc command line.

Quoted 12 lines
drivers/serial/Kconfig +12 -0
+#include <linux/module.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/console.h>
+#include <linux/sysrq.h>
+#include <linux/platform_device.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/serial_core.h>
+
+#include <asm/delay.h>
+#include <asm/portmux.h>

drivers/serial/Kconfig config SERIAL_OF_PLATFORM · line 1290

Quoted 10 lines
drivers/serial/Kconfig +10 -0
+
+#include "bfin_sport_uart.h"
+
+unsigned short bfin_uart_pin_req_sport0[] =
+	{P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS, \
+	 P_SPORT0_DRPRI, P_SPORT0_RSCLK, P_SPORT0_DRSEC, P_SPORT0_DTSEC, 0};
+
+unsigned short bfin_uart_pin_req_sport1[] =
+	{P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS, \
+	P_SPORT1_DRPRI, P_SPORT1_RSCLK, P_SPORT1_DRSEC, P_SPORT1_DTSEC, 0};

I don't think these need global scope?

drivers/serial/Kconfig

Quoted 11 lines

...

drivers/serial/Kconfig +9 -0
+/* Reqeust IRQ, Setup clock */
+static int sport_startup(struct uart_port *port)
+{
+	struct sport_uart_port *up = (struct sport_uart_port *)port;
+	char buffer[20];
+	int retval;
+
+	pr_debug("%s enter\n", __FUNCTION__);
+	memset(buffer, 20, '\0');

I don't think this memset is needed.

Quoted 10 lines
drivers/serial/Kconfig +10 -0
+	snprintf(buffer, 20, "%s rx", up->name);
+	retval = request_irq(up->rx_irq, sport_uart_rx_irq, IRQF_SAMPLE_RANDOM, buffer, up);
+	if (retval) {
+		printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
+		return retval;
+	}
+
+	snprintf(buffer, 20, "%s tx", up->name);
+	retval = request_irq(up->tx_irq, sport_uart_tx_irq, IRQF_SAMPLE_RANDOM, buffer, up);
+	if (retval) {

drivers/serial/Kconfig

Quoted 10 lines
drivers/serial/Kconfig +10 -0
+		printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
+		goto fail1;
+	}
+
+	snprintf(buffer, 20, "%s err", up->name);
+	retval = request_irq(up->err_irq, sport_uart_err_irq, IRQF_SAMPLE_RANDOM, buffer, up);
+	if (retval) {
+		printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
+		goto fail2;
+	}

It is not a good idea to create files in /proc which have spaces in their names. Yes, userspace _should_ be able to cope with that in all cases, but all software sucks, even including userspace ;)

I'd suggest that we be defensive here, and avoid using spaces in filenames.

Quoted 10 lines
drivers/serial/Kconfig +10 -0
+	if (port->line) {
+		if (peripheral_request_list(bfin_uart_pin_req_sport1, DRV_NAME))
+			goto fail3;
+	} else {
+		if (peripheral_request_list(bfin_uart_pin_req_sport0, DRV_NAME))
+			goto fail3;
+	}
+
+	sport_uart_setup(up, get_sclk(), port->uartclk);
+

drivers/serial/Kconfig

Quoted 10 lines
drivers/serial/Kconfig +10 -0
+	/* Enable receive interrupt */
+	SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) | RSPEN));
+	SSYNC();
+
+	return 0;
+
+
+fail3:
+	printk(KERN_ERR DRV_NAME
+		": Requesting Peripherals failed\n");

s/P/p/

Quoted 5 lines
drivers/serial/Kconfig +5 -0
+	free_irq(up->err_irq, up);
+fail2:
+	free_irq(up->tx_irq, up);
+fail1:
+	free_irq(up->rx_irq, up);

drivers/serial/Kconfig

Quoted 10 lines
drivers/serial/Kconfig +7 -0
+
+	return retval;
+
+}
 
...
 
+static void sport_shutdown(struct uart_port *port)
+{
+	struct sport_uart_port *up = (struct sport_uart_port *)port;

That's a bit ugly. Perhaps using container_of() would be clearer. it would also remove the requirement that uart_port be the first member of sport_uart_port.

drivers/serial/Kconfig

Quoted 12 lines
drivers/serial/Kconfig +12 -0
+	pr_debug("%s enter\n", __FUNCTION__);
+
+	/* Disable sport */
+	SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) & ~TSPEN));
+	SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) & ~RSPEN));
+	SSYNC();
+
+	if (port->line) {
+		peripheral_free_list(bfin_uart_pin_req_sport1);
+	} else {
+		peripheral_free_list(bfin_uart_pin_req_sport0);
+	}

Please use checkpatch. This patch generates a world record number of warnings.

Quoted 8 lines
drivers/serial/Kconfig +8 -0
+struct uart_ops sport_uart_ops = {
+	.tx_empty	= sport_tx_empty,
+	.set_mctrl	= sport_set_mctrl,
+	.get_mctrl	= sport_get_mctrl,
+	.stop_tx	= sport_stop_tx,
+	.start_tx	= sport_start_tx,
+	.stop_rx	= sport_stop_rx,
+	.enable_ms	= sport_enable_ms,

drivers/serial/Kconfig

Quoted 10 lines
drivers/serial/Kconfig +10 -0
+	.break_ctl	= sport_break_ctl,
+	.startup	= sport_startup,
+	.shutdown	= sport_shutdown,
+	.set_termios	= sport_set_termios,
+	.type		= sport_type,
+	.release_port	= sport_release_port,
+	.request_port	= sport_request_port,
+	.config_port	= sport_config_port,
+	.verify_port	= sport_verify_port,
+};

Does it need to have global scope?

#7 lore raw

Re: [PATCH 3/3] Blackfin serial driver: this driver enable SPORTs on Blackfin emulate UART

Quoted 9 lines · Andrew Morton

drivers/serial/Kconfig config SERIAL_OF_PLATFORM · line 1267

Quoted 6 lines
drivers/serial/Kconfig +6 -0
+config SERIAL_BFIN_SPORT
+     tristate "Blackfin SPORT emulate UART (EXPERIMENTAL)"
+     depends on BFIN && EXPERIMENTAL
+     select SERIAL_CORE
+     help
+       Enble support SPORT emulate UART on Blackfin series.

There's a typo there. Also the text is pretty meaningless - I'd fix it up but I'm not sure what it's trying to tell us!

here it is in english ;)

This driver emulates a standard UART using the SPORT peripherals on a Blackfin processor.

Quoted 25 lines
Quoted 10 lines
drivers/serial/bfin_sport_uart.c new file +10 -0
+     snprintf(buffer, 20, "%s rx", up->name);
+     retval = request_irq(up->rx_irq, sport_uart_rx_irq, IRQF_SAMPLE_RANDOM, buffer, up);
+     if (retval) {
+             printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
+             return retval;
+     }
+
+     snprintf(buffer, 20, "%s tx", up->name);
+     retval = request_irq(up->tx_irq, sport_uart_tx_irq, IRQF_SAMPLE_RANDOM, buffer, up);
+     if (retval) {

drivers/serial/bfin_sport_uart.c line 255

Quoted 10 lines
drivers/serial/bfin_sport_uart.c new file +10 -0
+             printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
+             goto fail1;
+     }
+
+     snprintf(buffer, 20, "%s err", up->name);
+     retval = request_irq(up->err_irq, sport_uart_err_irq, IRQF_SAMPLE_RANDOM, buffer, up);
+     if (retval) {
+             printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
+             goto fail2;
+     }

It is not a good idea to create files in /proc which have spaces in their names. Yes, userspace _should_ be able to cope with that in all cases, but all software sucks, even including userspace ;)

Quoted 1 line

I'd suggest that we be defensive here, and avoid using spaces in filenames.

i'm not sure i follow ... these are the names given to request_irq() which means this is what shows up in /proc/interrupts ... does this function also create an actual file somewhere in /proc that i am not aware of ?

the rest of the comments look good to me, thanks ! -mike

#8 lore raw

Re: [PATCH 3/3] Blackfin serial driver: this driver enable SPORTs on Blackfin emulate UART

Quoted 10 lines · On Mon, 15 Oct 2007 18:03:35 -0400 "Mike Frysinger" <[email protected]>…
Quoted 5 lines

It is not a good idea to create files in /proc which have spaces in their names. Yes, userspace _should_ be able to cope with that in all cases, but all software sucks, even including userspace ;)

I'd suggest that we be defensive here, and avoid using spaces in filenames.

i'm not sure i follow ... these are the names given to request_irq() which means this is what shows up in /proc/interrupts ... does this function also create an actual file somewhere in /proc that i am not aware of ?

err, umm, yeah. But the same argument applies: it is imprudent to have space-containing records in /proc/interrupts.

However it seems that we've already done that in several places so I guess any /proc/interrupts-parsing programs are already coping with it OK.

#9 lore raw

Re: [PATCH 3/3] Blackfin serial driver: this driver enable SPORTs on Blackfin emulate UART

In reply to Andrew Morton

On Mon 15 Oct 2007 16:33, Andrew Morton pondered:

Quoted 6 lines
Quoted 2 lines

Subject: [PATCH 3/3] Blackfin serial driver: this driver enable SPORTs

on Blackfin emulate UART

That's a bit hard to parse.

Blackfin's have a synchronous Serial Peripheral pORT (SPORT).

Unlike SPI, UART, I2C, or CAN interfaces which are designed for specific industry standard compatible communication only, the SPORT support a variety (software programmable) serial data communication protocols:
- A-law or µ-law companding according to G.711 specification
- Multichannel or Time-Division-Multiplexed (TDM) modes
- Stereo Audio I2S Mode
- TDM Modes for Multi-Channel audio codecs
- H.100 Telephony standard support
- others, but if anyone really cares, they need to read the chip specs...

Bryan's patch takes the SPORT, and makes a standard UART out of it (exposing /dev/ttySS0) for those people who don't have enough hardware UARTs in their system.

Is it a SPORT driver that emulates a UART, or a UART driver on the SPORT? I think it is the latter...

Maybe:

[PATCH 3/3] Blackfin serial driver: enables a UART interface for the SPORT

Which still doesn't make any sense, until you know what a SPORT is :)

-Robin

#10 lore raw

Re: [PATCH 3/3] Blackfin serial driver: this driver enable SPORTs on Blackfin emulate UART

In reply to Bryan Wu
Quoted 9 lines · Bryan Wu
drivers/serial/Kconfig +7 -0
+config SERIAL_BFIN_SPORT
+       tristate "Blackfin SPORT emulate UART (EXPERIMENTAL)"
+       depends on BFIN && EXPERIMENTAL
+       select SERIAL_CORE
+       help
+         Enble support SPORT emulate UART on Blackfin series.
+

drivers/serial/Kconfig config SERIAL_OF_PLATFORM · line 1278

Quoted 10 lines
drivers/serial/Kconfig +10 -0
+         To compile this driver as a module, choose M here: the
+         module will be called bfin_sport_uart.
+
+choice
+       prompt "Baud rate for Blackfin SPORT UART"
+       depends on SERIAL_BFIN_SPORT
+       default SERIAL_SPORT_BAUD_RATE_57600
+       help
+         Choose a baud rate for the SPORT UART, other uart settings are
+         8 bit, 1 stop bit, no parity, no flow control.

this looks wrong to me ... why cant the standard infrastructure for managing baud rate be used ?
-mike

#11 lore raw

Re: [PATCH 3/3] Blackfin serial driver: this driver enable SPORTs on Blackfin emulate UART

In reply to Bryan Wu

My review comments for this patch remain unaddressed so I have put it on hold.

#12 lore raw

Re: [PATCH 3/3] Blackfin serial driver: this driver enable SPORTs on Blackfin emulate UART

Quoted 5 lines · Andrew Morton

My review comments for this patch remain unaddressed so I have put it on hold.
--

I forgot to send out the patch. It will be there soon.

Thanks
-Bryan