All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] drivers:staging: sources for ST core
@ 2010-03-31 19:27 Pavan Savoy
  2010-03-31 20:24 ` Greg KH
  0 siblings, 1 reply; 27+ messages in thread
From: Pavan Savoy @ 2010-03-31 19:27 UTC (permalink / raw)
  To: Greg KH; +Cc: Marcel Holtmann, alan, linux-kernel

--- On Wed, 31/3/10, Greg KH <gregkh@suse.de> wrote:

> From: Greg KH <gregkh@suse.de>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: "Pavan Savoy" <pavan_savoy@ti.com>
> Cc: "Marcel Holtmann" <marcel@holtmann.org>, alan@lxorguk.ukuu.org.uk, linux-kernel@vger.kernel.org
> Date: Wednesday, 31 March, 2010, 11:49 PM
> On Wed, Mar 31, 2010 at 11:32:39PM
> +0530, Pavan Savoy wrote:
> > --- On Wed, 31/3/10, Greg KH <gregkh@suse.de>
> wrote:
> > 
> > > From: Greg KH <gregkh@suse.de>
> > > Subject: Re: [PATCH] drivers:staging: sources for
> ST core
> > > To: "Pavan Savoy" <pavan_savoy@ti.com>
> > > Cc: "Marcel Holtmann" <marcel@holtmann.org>,
> alan@lxorguk.ukuu.org.uk,
> linux-kernel@vger.kernel.org
> > > Date: Wednesday, 31 March, 2010, 11:00 PM
> > > On Wed, Mar 31, 2010 at 04:20:22AM
> > > +0530, Pavan Savoy wrote:
> > > > 
> > > > --- On Wed, 31/3/10, Pavan Savoy <pavan_savoy@ti.com>
> > > wrote:
> > > > 
> > > > > From: Pavan Savoy <pavan_savoy@ti.com>
> > > > > Subject: Re: [PATCH] drivers:staging:
> sources for
> > > ST core
> > > > > To: gregkh@suse.de
> > > > > Cc: "Marcel Holtmann" <marcel@holtmann.org>,
> > > alan@lxorguk.ukuu.org.uk
> > > > > Date: Wednesday, 31 March, 2010, 4:11
> AM
> > > > > --- On Wed, 31/3/10, Pavan Savoy
> > > > > <pavan_savoy@yahoo.co.in>
> > > > > wrote:
> > > > > 
> > > > > > From: Pavan Savoy <pavan_savoy@yahoo.co.in>
> > > > > > Subject: Re: [PATCH]
> drivers:staging:
> > > sources for ST
> > > > > core
> > > > > > To: "pavan_savoy@yahoo.co.in"
> > > > > <pavan_savoy@yahoo.co.in>
> > > > > > Date: Wednesday, 31 March, 2010,
> 4:06 AM
> > > > > > > From: Greg KH [gregkh@suse.de]
> > > > > > > Sent: Wednesday, March 31,
> 2010 3:17
> > > AM
> > > > > > > To: Savoy, Pavan
> > > > > > > Cc: Alan Cox; marcel@holtmann.org;
> > > > > > > linux-kernel@vger.kernel.org
> > > > > > > Subject: Re: [PATCH]
> drivers:staging:
> > > sources for
> > > > > ST
> > > > > > core
> > > > > > > 
> > > > > > > On Wed, Mar 31, 2010 at
> 02:35:55AM
> > > +0530, Pavan
> > > > > Savoy
> > > > > > > wrote:
> > > > > > > > So, something like the
> below is
> > > ok, I have
> > > > > > defined my
> > > > > > > own pr_fmt,
> > > > > > > > however default log
> level on my
> > > board is 7,
> > > > > and
> > > > > > hence
> > > > > > > pr_info is a bit
> > > > > > > > more annoying than
> usual.
> > > > > > > 
> > > > > > > No, a driver should use
> dev_dbg() and
> > > other
> > > > > > dev_printk()
> > > > > > > calls, not
> > > > > > > pr_debug() or anything like
> that.
> > > > > > > 
> > > > > > > Please don't roll your own
> formats, use
> > > the ones
> > > > > that
> > > > > > are
> > > > > > > well defined
> > > > > > > and uniquely describe your
> driver and
> > > device in
> > > > > a
> > > > > > format
> > > > > > > that the whole
> > > > > > > kernel uses.
> > > > > > 
> > > > > 
> > > > 
> > > > forgot lkml the last time..
> > > > 
> > > > Nope, I couldn't find any instance of struct
> device at
> > > all,
> > > > I need that to use dev_dbg right ? - None of
> the
> > > tty_*
> > > > structure accessible by ldiscs seems to have
> a
> > > reference to
> > > > it.
> > > > Also I happened to look at other line
> discipline
> > > driver, if
> > > > they have a smarter way of doing this, Nope
> - n_tty,
> > > n_hdlc,
> > > > n_slip all seem to use plain old printks.
> > > >? 
> > > > Any clues ??
> > > 
> > > Sorry, you are correct, we only have a struct
> kref right
> > > now for tty
> > > core objects, not a struct device.? So nevermind,
> this
> > > should be fine.
> > 
> > Oh cool. Thanks, So that leaves me with 1 pending item
> from Alan which is to tie these 3 modules (KIM/Core/LL) up
> onto a TTY device specific context, and avoid all global
> ptrs.
> > 
> > So without that is it good to go in ?
> 
> Yes, care to do that and resubmit?

Oh, But that would take some major re-structuring with the driver, because with the existing driver being a platform_device/driver structure-I can't do that.

I have made it similar to TTY<->LDISCs, LDISCs register to TTY core, here BT/FM/GPS register to ST core.
TTY has a array of ldisc registered which is global, locked resource, I have st_gdata which is global and locked resource.

Each ldisc is to be in context of tty, because multiple UART exist, but this is also a platform device and exports symbols for other drivers to register in, so essentially only 1 such device exist per platform.

I agree it's unlike other device drivers in kernel, But is this unacceptable this way ?
Are there any specific architectural inputs ? is this supposed to be similar to other drivers ? Please suggest...


> thanks,
> 
> greg k-h
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>



      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-31 19:27 [PATCH] drivers:staging: sources for ST core Pavan Savoy
@ 2010-03-31 20:24 ` Greg KH
  2010-03-31 23:57   ` Pavan Savoy
  0 siblings, 1 reply; 27+ messages in thread
From: Greg KH @ 2010-03-31 20:24 UTC (permalink / raw)
  To: Pavan Savoy; +Cc: Marcel Holtmann, alan, linux-kernel

On Thu, Apr 01, 2010 at 12:57:06AM +0530, Pavan Savoy wrote:
> --- On Wed, 31/3/10, Greg KH <gregkh@suse.de> wrote:
> 
> > From: Greg KH <gregkh@suse.de>
> > Subject: Re: [PATCH] drivers:staging: sources for ST core
> > To: "Pavan Savoy" <pavan_savoy@ti.com>
> > Cc: "Marcel Holtmann" <marcel@holtmann.org>, alan@lxorguk.ukuu.org.uk, linux-kernel@vger.kernel.org
> > Date: Wednesday, 31 March, 2010, 11:49 PM
> > On Wed, Mar 31, 2010 at 11:32:39PM
> > +0530, Pavan Savoy wrote:
> > > --- On Wed, 31/3/10, Greg KH <gregkh@suse.de>
> > wrote:
> > > 
> > > > From: Greg KH <gregkh@suse.de>
> > > > Subject: Re: [PATCH] drivers:staging: sources for
> > ST core
> > > > To: "Pavan Savoy" <pavan_savoy@ti.com>
> > > > Cc: "Marcel Holtmann" <marcel@holtmann.org>,
> > alan@lxorguk.ukuu.org.uk,
> > linux-kernel@vger.kernel.org
> > > > Date: Wednesday, 31 March, 2010, 11:00 PM
> > > > On Wed, Mar 31, 2010 at 04:20:22AM
> > > > +0530, Pavan Savoy wrote:
> > > > > 
> > > > > --- On Wed, 31/3/10, Pavan Savoy <pavan_savoy@ti.com>
> > > > wrote:
> > > > > 
> > > > > > From: Pavan Savoy <pavan_savoy@ti.com>
> > > > > > Subject: Re: [PATCH] drivers:staging:
> > sources for
> > > > ST core
> > > > > > To: gregkh@suse.de
> > > > > > Cc: "Marcel Holtmann" <marcel@holtmann.org>,
> > > > alan@lxorguk.ukuu.org.uk
> > > > > > Date: Wednesday, 31 March, 2010, 4:11
> > AM
> > > > > > --- On Wed, 31/3/10, Pavan Savoy
> > > > > > <pavan_savoy@yahoo.co.in>
> > > > > > wrote:
> > > > > > 
> > > > > > > From: Pavan Savoy <pavan_savoy@yahoo.co.in>
> > > > > > > Subject: Re: [PATCH]
> > drivers:staging:
> > > > sources for ST
> > > > > > core
> > > > > > > To: "pavan_savoy@yahoo.co.in"
> > > > > > <pavan_savoy@yahoo.co.in>
> > > > > > > Date: Wednesday, 31 March, 2010,
> > 4:06 AM
> > > > > > > > From: Greg KH [gregkh@suse.de]
> > > > > > > > Sent: Wednesday, March 31,
> > 2010 3:17
> > > > AM
> > > > > > > > To: Savoy, Pavan
> > > > > > > > Cc: Alan Cox; marcel@holtmann.org;
> > > > > > > > linux-kernel@vger.kernel.org
> > > > > > > > Subject: Re: [PATCH]
> > drivers:staging:
> > > > sources for
> > > > > > ST
> > > > > > > core
> > > > > > > > 
> > > > > > > > On Wed, Mar 31, 2010 at
> > 02:35:55AM
> > > > +0530, Pavan
> > > > > > Savoy
> > > > > > > > wrote:
> > > > > > > > > So, something like the
> > below is
> > > > ok, I have
> > > > > > > defined my
> > > > > > > > own pr_fmt,
> > > > > > > > > however default log
> > level on my
> > > > board is 7,
> > > > > > and
> > > > > > > hence
> > > > > > > > pr_info is a bit
> > > > > > > > > more annoying than
> > usual.
> > > > > > > > 
> > > > > > > > No, a driver should use
> > dev_dbg() and
> > > > other
> > > > > > > dev_printk()
> > > > > > > > calls, not
> > > > > > > > pr_debug() or anything like
> > that.
> > > > > > > > 
> > > > > > > > Please don't roll your own
> > formats, use
> > > > the ones
> > > > > > that
> > > > > > > are
> > > > > > > > well defined
> > > > > > > > and uniquely describe your
> > driver and
> > > > device in
> > > > > > a
> > > > > > > format
> > > > > > > > that the whole
> > > > > > > > kernel uses.
> > > > > > > 
> > > > > > 
> > > > > 
> > > > > forgot lkml the last time..
> > > > > 
> > > > > Nope, I couldn't find any instance of struct
> > device at
> > > > all,
> > > > > I need that to use dev_dbg right ? - None of
> > the
> > > > tty_*
> > > > > structure accessible by ldiscs seems to have
> > a
> > > > reference to
> > > > > it.
> > > > > Also I happened to look at other line
> > discipline
> > > > driver, if
> > > > > they have a smarter way of doing this, Nope
> > - n_tty,
> > > > n_hdlc,
> > > > > n_slip all seem to use plain old printks.
> > > > >? 
> > > > > Any clues ??
> > > > 
> > > > Sorry, you are correct, we only have a struct
> > kref right
> > > > now for tty
> > > > core objects, not a struct device.? So nevermind,
> > this
> > > > should be fine.
> > > 
> > > Oh cool. Thanks, So that leaves me with 1 pending item
> > from Alan which is to tie these 3 modules (KIM/Core/LL) up
> > onto a TTY device specific context, and avoid all global
> > ptrs.
> > > 
> > > So without that is it good to go in ?
> > 
> > Yes, care to do that and resubmit?
> 
> Oh, But that would take some major re-structuring with the driver, because with the existing driver being a platform_device/driver structure-I can't do that.
> 
> I have made it similar to TTY<->LDISCs, LDISCs register to TTY core, here BT/FM/GPS register to ST core.
> TTY has a array of ldisc registered which is global, locked resource, I have st_gdata which is global and locked resource.
> 
> Each ldisc is to be in context of tty, because multiple UART exist, but this is also a platform device and exports symbols for other drivers to register in, so essentially only 1 such device exist per platform.
> 
> I agree it's unlike other device drivers in kernel, But is this unacceptable this way ?

Think about what you just said, I think you answered your own question
:)

Please work on the change as requested.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-31 20:24 ` Greg KH
@ 2010-03-31 23:57   ` Pavan Savoy
  2010-04-01  9:20     ` Alan Cox
  0 siblings, 1 reply; 27+ messages in thread
From: Pavan Savoy @ 2010-03-31 23:57 UTC (permalink / raw)
  To: Greg KH; +Cc: Marcel Holtmann, alan, linux-kernel



--- On Thu, 1/4/10, Greg KH <gregkh@suse.de> wrote:

> From: Greg KH <gregkh@suse.de>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: "Pavan Savoy" <pavan_savoy@ti.com>
> Cc: "Marcel Holtmann" <marcel@holtmann.org>, alan@lxorguk.ukuu.org.uk, linux-kernel@vger.kernel.org
> Date: Thursday, 1 April, 2010, 1:54 AM
> On Thu, Apr 01, 2010 at 12:57:06AM
> +0530, Pavan Savoy wrote:
> > --- On Wed, 31/3/10, Greg KH <gregkh@suse.de>
> wrote:
> > 
> > > From: Greg KH <gregkh@suse.de>
> > > Subject: Re: [PATCH] drivers:staging: sources for
> ST core
> > > To: "Pavan Savoy" <pavan_savoy@ti.com>
> > > Cc: "Marcel Holtmann" <marcel@holtmann.org>,
> alan@lxorguk.ukuu.org.uk,
> linux-kernel@vger.kernel.org
> > > Date: Wednesday, 31 March, 2010, 11:49 PM
> > > On Wed, Mar 31, 2010 at 11:32:39PM
> > > +0530, Pavan Savoy wrote:
> > > > --- On Wed, 31/3/10, Greg KH <gregkh@suse.de>
> > > wrote:
> > > > 
> > > > > From: Greg KH <gregkh@suse.de>
> > > > > Subject: Re: [PATCH] drivers:staging:
> sources for
> > > ST core
> > > > > To: "Pavan Savoy" <pavan_savoy@ti.com>
> > > > > Cc: "Marcel Holtmann" <marcel@holtmann.org>,
> > > alan@lxorguk.ukuu.org.uk,
> > > linux-kernel@vger.kernel.org
> > > > > Date: Wednesday, 31 March, 2010, 11:00
> PM
> > > > > On Wed, Mar 31, 2010 at 04:20:22AM
> > > > > +0530, Pavan Savoy wrote:
> > > > > > 
> > > > > > --- On Wed, 31/3/10, Pavan Savoy
> <pavan_savoy@ti.com>
> > > > > wrote:
> > > > > > 
> > > > > > > From: Pavan Savoy <pavan_savoy@ti.com>
> > > > > > > Subject: Re: [PATCH]
> drivers:staging:
> > > sources for
> > > > > ST core
> > > > > > > To: gregkh@suse.de
> > > > > > > Cc: "Marcel Holtmann" <marcel@holtmann.org>,
> > > > > alan@lxorguk.ukuu.org.uk
> > > > > > > Date: Wednesday, 31 March,
> 2010, 4:11
> > > AM
> > > > > > > --- On Wed, 31/3/10, Pavan
> Savoy
> > > > > > > <pavan_savoy@yahoo.co.in>
> > > > > > > wrote:
> > > > > > > 
> > > > > > > > From: Pavan Savoy <pavan_savoy@yahoo.co.in>
> > > > > > > > Subject: Re: [PATCH]
> > > drivers:staging:
> > > > > sources for ST
> > > > > > > core
> > > > > > > > To: "pavan_savoy@yahoo.co.in"
> > > > > > > <pavan_savoy@yahoo.co.in>
> > > > > > > > Date: Wednesday, 31
> March, 2010,
> > > 4:06 AM
> > > > > > > > > From: Greg KH [gregkh@suse.de]
> > > > > > > > > Sent: Wednesday,
> March 31,
> > > 2010 3:17
> > > > > AM
> > > > > > > > > To: Savoy, Pavan
> > > > > > > > > Cc: Alan Cox; marcel@holtmann.org;
> > > > > > > > > linux-kernel@vger.kernel.org
> > > > > > > > > Subject: Re:
> [PATCH]
> > > drivers:staging:
> > > > > sources for
> > > > > > > ST
> > > > > > > > core
> > > > > > > > > 
> > > > > > > > > On Wed, Mar 31,
> 2010 at
> > > 02:35:55AM
> > > > > +0530, Pavan
> > > > > > > Savoy
> > > > > > > > > wrote:
> > > > > > > > > > So, something
> like the
> > > below is
> > > > > ok, I have
> > > > > > > > defined my
> > > > > > > > > own pr_fmt,
> > > > > > > > > > however
> default log
> > > level on my
> > > > > board is 7,
> > > > > > > and
> > > > > > > > hence
> > > > > > > > > pr_info is a bit
> > > > > > > > > > more annoying
> than
> > > usual.
> > > > > > > > > 
> > > > > > > > > No, a driver should
> use
> > > dev_dbg() and
> > > > > other
> > > > > > > > dev_printk()
> > > > > > > > > calls, not
> > > > > > > > > pr_debug() or
> anything like
> > > that.
> > > > > > > > > 
> > > > > > > > > Please don't roll
> your own
> > > formats, use
> > > > > the ones
> > > > > > > that
> > > > > > > > are
> > > > > > > > > well defined
> > > > > > > > > and uniquely
> describe your
> > > driver and
> > > > > device in
> > > > > > > a
> > > > > > > > format
> > > > > > > > > that the whole
> > > > > > > > > kernel uses.
> > > > > > > > 
> > > > > > > 
> > > > > > 
> > > > > > forgot lkml the last time..
> > > > > > 
> > > > > > Nope, I couldn't find any instance
> of struct
> > > device at
> > > > > all,
> > > > > > I need that to use dev_dbg right ?
> - None of
> > > the
> > > > > tty_*
> > > > > > structure accessible by ldiscs
> seems to have
> > > a
> > > > > reference to
> > > > > > it.
> > > > > > Also I happened to look at other
> line
> > > discipline
> > > > > driver, if
> > > > > > they have a smarter way of doing
> this, Nope
> > > - n_tty,
> > > > > n_hdlc,
> > > > > > n_slip all seem to use plain old
> printks.
> > > > > >? 
> > > > > > Any clues ??
> > > > > 
> > > > > Sorry, you are correct, we only have a
> struct
> > > kref right
> > > > > now for tty
> > > > > core objects, not a struct device.? So
> nevermind,
> > > this
> > > > > should be fine.
> > > > 
> > > > Oh cool. Thanks, So that leaves me with 1
> pending item
> > > from Alan which is to tie these 3 modules
> (KIM/Core/LL) up
> > > onto a TTY device specific context, and avoid all
> global
> > > ptrs.
> > > > 
> > > > So without that is it good to go in ?
> > > 
> > > Yes, care to do that and resubmit?
> > 
> > Oh, But that would take some major re-structuring with
> the driver, because with the existing driver being a
> platform_device/driver structure-I can't do that.
> > 
> > I have made it similar to TTY<->LDISCs, LDISCs
> register to TTY core, here BT/FM/GPS register to ST core.
> > TTY has a array of ldisc registered which is global,
> locked resource, I have st_gdata which is global and locked
> resource.
> > 
> > Each ldisc is to be in context of tty, because
> multiple UART exist, but this is also a platform device and
> exports symbols for other drivers to register in, so
> essentially only 1 such device exist per platform.
> > 
> > I agree it's unlike other device drivers in kernel,
> But is this unacceptable this way ?
> 
> Think about what you just said, I think you answered your
> own question
> :)
> 
> Please work on the change as requested.
> 
> thanks,

Ok, fixed up the ST core as suggested, no issues - works as is.
However, I just could not manage the kim_gdata not being global in st_kim.

All I want is an instance of structure I initialize in module_init, during _probe from platform_device.

Find below the patch where I cannot seem to manage without the kim_gdata global variable... - Any clues ?

>From 67cd43a2b3e9eee7fcdbe5185f8ef9b010ae8bdc Mon Sep 17 00:00:00 2001
From: Pavan Savoy <pavan_savoy@ti.com>
Date: Mon, 22 Mar 2010 13:19:39 -0400
Subject: [PATCH] drivers:staging: sources for Init manager module

Kernel Space Init-Manager works along with User-Mode
Init Manager daemon running to maintain the UART state.

Communication between user-space daemon and this module can be
	1. Via the pid written onto sysfs entry
	2. Via the rfkill subsystem

It also is a platform driver with a relevant platform device
in the board-*.c along with the list of BT/FM/GPS chip enable
gpio configuration

Signed-off-by: Pavan Savoy <pavan_savoy@ti.com>
---
 drivers/staging/ti-st/st_kim.c |  754 ++++++++++++++++++++++++++++++++++++++++
 drivers/staging/ti-st/st_kim.h |  150 ++++++++
 2 files changed, 904 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/ti-st/st_kim.c
 create mode 100644 drivers/staging/ti-st/st_kim.h

diff --git a/drivers/staging/ti-st/st_kim.c b/drivers/staging/ti-st/st_kim.c
new file mode 100644
index 0000000..98cbabb
--- /dev/null
+++ b/drivers/staging/ti-st/st_kim.c
@@ -0,0 +1,754 @@
+/*
+ *  Shared Transport Line discipline driver Core
+ *	Init Manager module responsible for GPIO control
+ *	and firmware download
+ *  Copyright (C) 2009 Texas Instruments
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#define pr_fmt(fmt) "(stk) :" fmt
+#include <linux/platform_device.h>
+#include <linux/jiffies.h>
+#include <linux/firmware.h>
+#include <linux/delay.h>
+#include <linux/wait.h>
+#include <linux/gpio.h>
+
+#include <linux/sched.h>
+
+#include "st_kim.h"
+/* understand BT events for fw response */
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+#include <net/bluetooth/hci.h>
+
+
+static int kim_probe(struct platform_device *pdev);
+static int kim_remove(struct platform_device *pdev);
+
+/* KIM platform device driver structure */
+static struct platform_driver kim_platform_driver = {
+	.probe = kim_probe,
+	.remove = kim_remove,
+	/* TODO: ST driver power management during suspend/resume ?
+	 */
+#if 0
+	.suspend = kim_suspend,
+	.resume = kim_resume,
+#endif
+	.driver = {
+		   .name = "kim",
+		   .owner = THIS_MODULE,
+		   },
+};
+
+#ifndef LEGACY_RFKILL_SUPPORT
+static ssize_t show_pid(struct device *dev, struct device_attribute
+			*attr, char *buf);
+static ssize_t store_pid(struct device *dev, struct device_attribute
+			 *devattr, char *buf, size_t count);
+static ssize_t show_list(struct device *dev, struct device_attribute
+			 *attr, char *buf);
+
+/* structures specific for sysfs entries */
+static struct kobj_attribute pid_attr =
+__ATTR(pid, 0644, (void *)show_pid, (void *)store_pid);
+
+static struct kobj_attribute list_protocols =
+__ATTR(protocols, 0444, (void *)show_list, NULL);
+
+static struct attribute *uim_attrs[] = {
+	&pid_attr.attr,
+	/* add more debug sysfs entries */
+	&list_protocols.attr,
+	NULL,
+};
+
+static struct attribute_group uim_attr_grp = {
+	.attrs = uim_attrs,
+};
+#else
+static int kim_toggle_radio(void*, bool);
+static const struct rfkill_ops kim_rfkill_ops = {
+	.set_block = kim_toggle_radio,
+};
+#endif	/* LEGACY_RFKILL_SUPPORT */
+
+/* strings to be used for rfkill entries and by
+ * ST Core to be used for sysfs debug entry
+ */
+#define PROTO_ENTRY(type, name)	name
+const unsigned char *protocol_names[] = {
+	PROTO_ENTRY(ST_BT, "Bluetooth"),
+	PROTO_ENTRY(ST_FM, "FM"),
+	PROTO_ENTRY(ST_GPS, "GPS"),
+};
+
+struct kim_data_s	*kim_gdata;
+
+/**********************************************************************/
+/* internal functions */
+
+/*
+ * function to return whether the firmware response was proper
+ * in case of error don't complete so that waiting for proper
+ * response times out
+ */
+void validate_firmware_response(struct sk_buff *skb)
+{
+	if (unlikely(skb->data[5] != 0)) {
+		pr_err("no proper response during fw download");
+		pr_err("data6 %x", skb->data[5]);
+		return;		/* keep waiting for the proper response */
+	}
+	/* becos of all the script being downloaded */
+	complete_all(&kim_gdata->kim_rcvd);
+	kfree_skb(skb);
+}
+
+/* check for data len received inside kim_int_recv
+ * most often hit the last case to update state to waiting for data
+ */
+static inline int kim_check_data_len(int len)
+{
+	register int room = skb_tailroom(kim_gdata->rx_skb);
+
+	pr_info("len %d room %d", len, room);
+
+	if (!len) {
+		validate_firmware_response(kim_gdata->rx_skb);
+	} else if (len > room) {
+		/* Received packet's payload length is larger.
+		 * We can't accommodate it in created skb.
+		 */
+		pr_err("Data length is too large len %d room %d", len,
+			   room);
+		kfree_skb(kim_gdata->rx_skb);
+	} else {
+		/* Packet header has non-zero payload length and
+		 * we have enough space in created skb. Lets read
+		 * payload data */
+		kim_gdata->rx_state = ST_BT_W4_DATA;
+		kim_gdata->rx_count = len;
+		return len;
+	}
+
+	/* Change ST LL state to continue to process next
+	 * packet */
+	kim_gdata->rx_state = ST_W4_PACKET_TYPE;
+	kim_gdata->rx_skb = NULL;
+	kim_gdata->rx_count = 0;
+
+	return 0;
+}
+
+/* receive function called during firmware download
+ * - firmware download responses on different UART drivers
+ *   have been observed to come in bursts of different
+ *   tty_receive and hence the logic
+ */
+void kim_int_recv(const unsigned char *data, long count)
+{
+	register char *ptr;
+	struct hci_event_hdr *eh;
+	register int len = 0, type = 0;
+
+	pr_info("%s", __func__);
+	/* Decode received bytes here */
+	ptr = (char *)data;
+	if (unlikely(ptr == NULL)) {
+		pr_err(" received null from TTY ");
+		return;
+	}
+	while (count) {
+		if (kim_gdata->rx_count) {
+			len = min_t(unsigned int, kim_gdata->rx_count, count);
+			memcpy(skb_put(kim_gdata->rx_skb, len), ptr, len);
+			kim_gdata->rx_count -= len;
+			count -= len;
+			ptr += len;
+
+			if (kim_gdata->rx_count)
+				continue;
+
+			/* Check ST RX state machine , where are we? */
+			switch (kim_gdata->rx_state) {
+				/* Waiting for complete packet ? */
+			case ST_BT_W4_DATA:
+				pr_info("Complete pkt received");
+				validate_firmware_response(kim_gdata->rx_skb);
+				kim_gdata->rx_state = ST_W4_PACKET_TYPE;
+				kim_gdata->rx_skb = NULL;
+				continue;
+				/* Waiting for Bluetooth event header ? */
+			case ST_BT_W4_EVENT_HDR:
+				eh = (struct hci_event_hdr *)kim_gdata->
+				    rx_skb->data;
+				pr_info("Event header: evt 0x%2.2x"
+					   "plen %d", eh->evt, eh->plen);
+				kim_check_data_len(eh->plen);
+				continue;
+			}	/* end of switch */
+		}		/* end of if rx_state */
+		switch (*ptr) {
+			/* Bluetooth event packet? */
+		case HCI_EVENT_PKT:
+			pr_info("Event packet");
+			kim_gdata->rx_state = ST_BT_W4_EVENT_HDR;
+			kim_gdata->rx_count = HCI_EVENT_HDR_SIZE;
+			type = HCI_EVENT_PKT;
+			break;
+		default:
+			pr_info("unknown packet");
+			ptr++;
+			count--;
+			continue;
+		}		/* end of switch *ptr */
+		ptr++;
+		count--;
+		kim_gdata->rx_skb =
+		    bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
+		if (!kim_gdata->rx_skb) {
+			pr_err("can't allocate mem for new packet");
+			kim_gdata->rx_state = ST_W4_PACKET_TYPE;
+			kim_gdata->rx_count = 0;
+			return;
+		} /* not necessary in this case */
+		bt_cb(kim_gdata->rx_skb)->pkt_type = type;
+	}			/* end of while count */
+	pr_info("done %s", __func__);
+	return;
+}
+
+static long read_local_version(char *bts_scr_name)
+{
+	unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0;
+	char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 };
+
+	pr_info("%s", __func__);
+
+	INIT_COMPLETION(kim_gdata->kim_rcvd);
+	if (4 != st_int_write(kim_gdata->core_data, read_ver_cmd, 4)) {
+		pr_err("kim: couldn't write 4 bytes");
+		return ST_ERR_FAILURE;
+	}
+
+	if (!wait_for_completion_timeout
+	    (&kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) {
+		pr_err(" waiting for ver info- timed out ");
+		return ST_ERR_FAILURE;
+	}
+
+	version =
+	    MAKEWORD(kim_gdata->resp_buffer[13], kim_gdata->resp_buffer[14]);
+	chip = (version & 0x7C00) >> 10;
+	min_ver = (version & 0x007F);
+	maj_ver = (version & 0x0380) >> 7;
+
+	if (version & 0x8000)
+		maj_ver |= 0x0008;
+
+	sprintf(bts_scr_name, "TIInit_%d.%d.%d.bts", chip, maj_ver, min_ver);
+	pr_info("%s", bts_scr_name);
+	return ST_SUCCESS;
+}
+
+/* internal function which parses through the .bts firmware script file
+ * intreprets SEND, DELAY actions only as of now
+ */
+static long download_firmware(void)
+{
+	long err = ST_SUCCESS;
+	long len = 0;
+	register unsigned char *ptr = NULL;
+	register unsigned char *action_ptr = NULL;
+	unsigned char bts_scr_name[30] = { 0 };	/* 30 char long bts scr name? */
+
+	pr_info("%s", __func__);
+
+	err = read_local_version(bts_scr_name);
+	if (err != ST_SUCCESS) {
+		pr_err("kim: failed to read local ver");
+		return err;
+	}
+	err =
+	    request_firmware(&kim_gdata->fw_entry, bts_scr_name,
+			     &kim_gdata->kim_pdev->dev);
+	if (unlikely((err != 0) || (kim_gdata->fw_entry->data == NULL) ||
+		     (kim_gdata->fw_entry->size == 0))) {
+		pr_err(" request_firmware failed(errno %ld) for %s", err,
+			   bts_scr_name);
+		return ST_ERR_FAILURE;
+	}
+	ptr = (void *)kim_gdata->fw_entry->data;
+	len = kim_gdata->fw_entry->size;
+	/* bts_header to remove out magic number and
+	 * version
+	 */
+	ptr += sizeof(struct bts_header);
+	len -= sizeof(struct bts_header);
+
+	while (len > 0 && ptr) {
+		pr_info(" action size %d, type %d ",
+			   ((struct bts_action *)ptr)->size,
+			   ((struct bts_action *)ptr)->type);
+
+		switch (((struct bts_action *)ptr)->type) {
+		case ACTION_SEND_COMMAND:	/* action send */
+			action_ptr = &(((struct bts_action *)ptr)->data[0]);
+			if (unlikely
+			    (((struct hci_command *)action_ptr)->opcode ==
+			     0xFF36)) {
+				/* ignore remote change
+				 * baud rate HCI VS command */
+				pr_err
+				    (" change remote baud\
+				    rate command in firmware");
+				break;
+			}
+
+			INIT_COMPLETION(kim_gdata->kim_rcvd);
+			err = st_int_write(kim_gdata->core_data,
+			((struct bts_action_send *)action_ptr)->data,
+					   ((struct bts_action *)ptr)->size);
+			if (unlikely(err < 0)) {
+				release_firmware(kim_gdata->fw_entry);
+				return ST_ERR_FAILURE;
+			}
+			if (!wait_for_completion_timeout
+			    (&kim_gdata->kim_rcvd,
+			     msecs_to_jiffies(CMD_RESP_TIME))) {
+				pr_err
+				    (" response timeout during fw download ");
+				/* timed out */
+				release_firmware(kim_gdata->fw_entry);
+				return ST_ERR_FAILURE;
+			}
+			break;
+		case ACTION_DELAY:	/* sleep */
+			pr_info("sleep command in scr");
+			action_ptr = &(((struct bts_action *)ptr)->data[0]);
+			mdelay(((struct bts_action_delay *)action_ptr)->msec);
+			break;
+		}
+		len =
+		    len - (sizeof(struct bts_action) +
+			   ((struct bts_action *)ptr)->size);
+		ptr =
+		    ptr + sizeof(struct bts_action) +
+		    ((struct bts_action *)ptr)->size;
+	}
+	/* fw download complete */
+	release_firmware(kim_gdata->fw_entry);
+	return ST_SUCCESS;
+}
+
+/**********************************************************************/
+/* functions called from ST core */
+
+/* function to toggle the GPIO
+ * needs to know whether the GPIO is active high or active low
+ */
+void st_kim_chip_toggle(enum proto_type type, enum kim_gpio_state state)
+{
+	pr_info(" %s ", __func__);
+
+	if (kim_gdata->gpios[type] == -1) {
+		pr_info(" gpio not requested for protocol %s",
+			   protocol_names[type]);
+		return;
+	}
+	switch (type) {
+	case ST_BT:
+		/*Do Nothing */
+		break;
+
+	case ST_FM:
+		if (state == KIM_GPIO_ACTIVE)
+			gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_LOW);
+		else
+			gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_HIGH);
+		break;
+
+	case ST_GPS:
+		if (state == KIM_GPIO_ACTIVE)
+			gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_HIGH);
+		else
+			gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_LOW);
+		break;
+
+	case ST_MAX:
+	default:
+		break;
+	}
+
+	return;
+}
+
+/* called from ST Core, when REG_IN_PROGRESS (registration in progress)
+ * can be because of
+ * 1. response to read local version
+ * 2. during send/recv's of firmware download
+ */
+void st_kim_recv(void *disc_data, const unsigned char *data, long count)
+{
+	pr_info(" %s ", __func__);
+	/* copy to local buffer */
+	if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) {
+		/* must be the read_ver_cmd */
+		memcpy(kim_gdata->resp_buffer, data, count);
+		complete_all(&kim_gdata->kim_rcvd);
+		return;
+	} else {
+		kim_int_recv(data, count);
+		/* either completes or times out */
+	}
+	return;
+}
+
+/* to signal completion of line discipline installation
+ * called from ST Core, upon tty_open
+ */
+void st_kim_complete(void)
+{
+	complete(&kim_gdata->ldisc_installed);
+}
+
+/* called from ST Core upon 1st registration
+*/
+long st_kim_start(void)
+{
+	long err = ST_SUCCESS;
+	long retry = POR_RETRY_COUNT;
+	pr_info(" %s", __func__);
+
+	do {
+#ifdef LEGACY_RFKILL_SUPPORT
+		/* TODO: this is only because rfkill sub-system
+		 * doesn't send events to user-space if the state
+		 * isn't changed
+		 */
+		rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1);
+#endif
+		/* Configure BT nShutdown to HIGH state */
+		gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW);
+		mdelay(5);	/* FIXME: a proper toggle */
+		gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH);
+		mdelay(100);
+		/* re-initialize the completion */
+		INIT_COMPLETION(kim_gdata->ldisc_installed);
+#ifndef LEGACY_RFKILL_SUPPORT
+		/* send signal to UIM */
+		err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 0);
+		if (err != 0) {
+			pr_info(" sending SIGUSR2 to uim failed %ld", err);
+			err = ST_ERR_FAILURE;
+			continue;
+		}
+#else
+		/* unblock and send event to UIM via /dev/rfkill */
+		rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 0);
+#endif
+		/* wait for ldisc to be installed */
+		err = wait_for_completion_timeout(&kim_gdata->ldisc_installed,
+				msecs_to_jiffies(LDISC_TIME));
+		if (!err) {	/* timeout */
+			pr_err("line disc installation timed out ");
+			err = ST_ERR_FAILURE;
+			continue;
+		} else {
+			/* ldisc installed now */
+			pr_info(" line discipline installed ");
+			err = download_firmware();
+			if (err != ST_SUCCESS) {
+				pr_err("download firmware failed");
+				continue;
+			} else {	/* on success don't retry */
+				break;
+			}
+		}
+	} while (retry--);
+	return err;
+}
+
+/* called from ST Core, on the last un-registration
+*/
+long st_kim_stop(void)
+{
+	long err = ST_SUCCESS;
+
+	INIT_COMPLETION(kim_gdata->ldisc_installed);
+#ifndef LEGACY_RFKILL_SUPPORT
+	/* send signal to UIM */
+	err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 1);
+	if (err != 0) {
+		pr_err("sending SIGUSR2 to uim failed %ld", err);
+		return ST_ERR_FAILURE;
+	}
+#else
+	/* set BT rfkill to be blocked */
+	err = rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1);
+#endif
+
+	/* wait for ldisc to be un-installed */
+	err = wait_for_completion_timeout(&kim_gdata->ldisc_installed,
+			msecs_to_jiffies(LDISC_TIME));
+	if (!err) {		/* timeout */
+		pr_err(" timed out waiting for ldisc to be un-installed");
+		return ST_ERR_FAILURE;
+	}
+
+	/* By default configure BT nShutdown to LOW state */
+	gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW);
+	mdelay(1);
+	gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH);
+	mdelay(1);
+	gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW);
+	return err;
+}
+
+/**********************************************************************/
+/* functions called from subsystems */
+
+#ifndef LEGACY_RFKILL_SUPPORT
+/* called when sysfs entry is written to */
+static ssize_t store_pid(struct device *dev, struct device_attribute
+			 *devattr, char *buf, size_t count)
+{
+	pr_info("%s: pid %s ", __func__, buf);
+	sscanf(buf, "%ld", &kim_gdata->uim_pid);
+	/* to be made use by kim_start to signal SIGUSR2
+	 */
+	return strlen(buf);
+}
+
+/* called when sysfs entry is read from */
+static ssize_t show_pid(struct device *dev, struct device_attribute
+			*attr, char *buf)
+{
+	sprintf(buf, "%ld", kim_gdata->uim_pid);
+	return strlen(buf);
+}
+
+/* called when sysfs entry is read from */
+static ssize_t show_list(struct device *dev, struct device_attribute
+			 *attr, char *buf)
+{
+	kim_st_list_protocols(kim_gdata->core_data, buf);
+	return strlen(buf);
+}
+
+#else /* LEGACY_RFKILL_SUPPORT */
+
+/* function called from rfkill subsystem, when someone from
+ * user space would write 0/1 on the sysfs entry
+ * /sys/class/rfkill/rfkill0,1,3/state
+ */
+static int kim_toggle_radio(void *data, bool blocked)
+{
+	enum proto_type type = *((enum proto_type *)data);
+	pr_info(" %s: %d ", __func__, type);
+
+	switch (type) {
+	case ST_BT:
+		/* do nothing */
+	break;
+	case ST_FM:
+	case ST_GPS:
+		if (blocked)
+			st_kim_chip_toggle(type, KIM_GPIO_INACTIVE);
+		else
+			st_kim_chip_toggle(type, KIM_GPIO_ACTIVE);
+	break;
+	case ST_MAX:
+		pr_err(" wrong proto type ");
+	break;
+	}
+	return ST_SUCCESS;
+}
+
+#endif	/* LEGACY_RFKILL_SUPPORT */
+
+void st_kim_ref(struct st_data_s **core_data)
+{
+	*core_data = kim_gdata->core_data;
+}
+
+/**********************************************************************/
+/* functions called from platform device driver subsystem
+ * need to have a relevant platform device entry in the platform's
+ * board-*.c file
+ */
+
+static int kim_probe(struct platform_device *pdev)
+{
+	long status;
+	long proto;
+	long *gpios = pdev->dev.platform_data;
+
+	status = st_core_init(&kim_gdata->core_data);
+	if (status != 0) {
+		pr_err(" ST core init failed");
+		return ST_ERR_FAILURE;
+	}
+
+	for (proto = 0; proto < ST_MAX; proto++) {
+		kim_gdata->gpios[proto] = gpios[proto];
+		pr_info(" %ld gpio to be requested", gpios[proto]);
+	}
+
+	for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) {
+		/* Claim the Bluetooth/FM/GPIO
+		 * nShutdown gpio from the system
+		 */
+		status = gpio_request(gpios[proto], "kim");
+		if (unlikely(status)) {
+			pr_err(" gpio %ld request failed ", gpios[proto]);
+			proto -= 1;
+			while (proto >= 0) {
+				if (gpios[proto] != -1)
+					gpio_free(gpios[proto]);
+			}
+			return status;
+		}
+
+		/* Configure nShutdown GPIO as output=0 */
+		status =
+		    gpio_direction_output(gpios[proto], 0);
+		if (unlikely(status)) {
+			pr_err(" unable to configure gpio %ld",
+				   gpios[proto]);
+			proto -= 1;
+			while (proto >= 0) {
+				if (gpios[proto] != -1)
+					gpio_free(gpios[proto]);
+			}
+			return status;
+		}
+	}
+#ifndef LEGACY_RFKILL_SUPPORT
+	/* pdev to contain BT, FM and GPS enable/N-Shutdown GPIOs
+	 * execute request_gpio, set output direction
+	 */
+	kim_gdata->kim_kobj = kobject_create_and_add("uim", NULL);
+	/* create the sysfs entry for UIM to put in pid */
+	if (sysfs_create_group(kim_gdata->kim_kobj, &uim_attr_grp)) {
+		pr_err(" sysfs entry creation failed");
+		kobject_put(kim_gdata->kim_kobj);
+		/* free requested GPIOs and fail probe */
+		for (proto = ST_BT; proto < ST_MAX; proto++) {
+			if (gpios[proto] != -1)
+				gpio_free(gpios[proto]);
+		}
+		return -1;	/* fail insmod */
+	}
+	pr_info(" sysfs entry created ");
+#endif
+	/* get reference of pdev for request_firmware
+	 */
+	kim_gdata->kim_pdev = pdev;
+	init_completion(&kim_gdata->kim_rcvd);
+	init_completion(&kim_gdata->ldisc_installed);
+#ifdef LEGACY_RFKILL_SUPPORT
+	for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) {
+		/* TODO: should all types be rfkill_type_bt ? */
+		kim_gdata->rf_protos[proto] = proto;
+		kim_gdata->rfkill[proto] = rfkill_alloc(protocol_names[proto],
+			&pdev->dev, RFKILL_TYPE_BLUETOOTH,
+			&kim_rfkill_ops, &kim_gdata->rf_protos[proto]);
+		if (kim_gdata->rfkill[proto] == NULL) {
+			pr_err("cannot create rfkill entry for gpio %ld",
+				   gpios[proto]);
+			continue;
+		}
+		/* block upon creation */
+		rfkill_init_sw_state(kim_gdata->rfkill[proto], 1);
+		status = rfkill_register(kim_gdata->rfkill[proto]);
+		if (unlikely(status)) {
+			pr_err("rfkill registration failed for gpio %ld",
+				   gpios[proto]);
+			rfkill_unregister(kim_gdata->rfkill[proto]);
+			continue;
+		}
+		pr_info("rfkill entry created for %ld", gpios[proto]);
+	}
+#endif
+	return ST_SUCCESS;
+}
+
+static int kim_remove(struct platform_device *pdev)
+{
+	/* free the GPIOs requested
+	 */
+	long *gpios = pdev->dev.platform_data;
+	long proto;
+
+	for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) {
+		/* Claim the Bluetooth/FM/GPIO
+		 * nShutdown gpio from the system
+		 */
+		gpio_free(gpios[proto]);
+#ifdef LEGACY_RFKILL_SUPPORT
+		rfkill_unregister(kim_gdata->rfkill[proto]);
+		rfkill_destroy(kim_gdata->rfkill[proto]);
+		kim_gdata->rfkill[proto] = NULL;
+#endif
+	}
+	pr_info("kim: GPIO Freed");
+#ifndef LEGACY_RFKILL_SUPPORT
+	/* delete the sysfs entries */
+	sysfs_remove_group(kim_gdata->kim_kobj, &uim_attr_grp);
+	kobject_put(kim_gdata->kim_kobj);
+#endif
+	kim_gdata->kim_pdev = NULL;
+	st_core_exit(kim_gdata->core_data);
+	return ST_SUCCESS;
+}
+
+/**********************************************************************/
+/* entry point for ST KIM module, called in from ST Core */
+
+static int __init st_kim_init(void)
+{
+	long ret = ST_SUCCESS;
+	kim_gdata = kzalloc(sizeof(struct kim_data_s), GFP_ATOMIC);
+	if (!kim_gdata) {
+		pr_err("no mem to allocate");
+		return -ENOMEM;
+	}
+
+	ret = platform_driver_register(&kim_platform_driver);
+	if (ret != 0) {
+		pr_err("platform drv registration failed");
+		return ST_ERR_FAILURE;
+	}
+	return ST_SUCCESS;
+}
+
+static void __exit st_kim_deinit(void)
+{
+	/* the following returns void */
+	platform_driver_unregister(&kim_platform_driver);
+	kfree(kim_gdata);
+	kim_gdata = NULL;
+}
+
+
+module_init(st_kim_init);
+module_exit(st_kim_deinit);
+MODULE_AUTHOR("Pavan Savoy <pavan_savoy@ti.com>");
+MODULE_DESCRIPTION("Shared Transport Driver for TI BT/FM/GPS combo chips ");
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/ti-st/st_kim.h b/drivers/staging/ti-st/st_kim.h
new file mode 100644
index 0000000..ff3270e
--- /dev/null
+++ b/drivers/staging/ti-st/st_kim.h
@@ -0,0 +1,150 @@
+/*
+ *  Shared Transport Line discipline driver Core
+ *	Init Manager Module header file
+ *  Copyright (C) 2009 Texas Instruments
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef ST_KIM_H
+#define ST_KIM_H
+
+#include <linux/types.h>
+#include "st.h"
+#include "st_core.h"
+#include "st_ll.h"
+#include <linux/rfkill.h>
+
+/* time in msec to wait for
+ * line discipline to be installed
+ */
+#define LDISC_TIME	500
+#define CMD_RESP_TIME	500
+#define MAKEWORD(a, b)  ((unsigned short)(((unsigned char)(a)) \
+	| ((unsigned short)((unsigned char)(b))) << 8))
+
+#define GPIO_HIGH 1
+#define GPIO_LOW  0
+
+/* the Power-On-Reset logic, requires to attempt
+ * to download firmware onto chip more than once
+ * since the self-test for chip takes a while
+ */
+#define POR_RETRY_COUNT 5
+/*
+ * legacy rfkill support where-in 3 rfkill
+ * devices are created for the 3 gpios
+ * that ST has requested
+ */
+#define LEGACY_RFKILL_SUPPORT
+/*
+ * header file for ST provided by KIM
+ */
+struct kim_data_s {
+	long uim_pid;
+	struct platform_device *kim_pdev;
+	struct completion kim_rcvd, ldisc_installed;
+	/* MAX len of the .bts firmware script name */
+	char resp_buffer[30];
+	const struct firmware *fw_entry;
+	long gpios[ST_MAX];
+	struct kobject *kim_kobj;
+/* used by kim_int_recv to validate fw response */
+	unsigned long rx_state;
+	unsigned long rx_count;
+	struct sk_buff *rx_skb;
+#ifdef LEGACY_RFKILL_SUPPORT
+	struct rfkill *rfkill[ST_MAX];
+	enum proto_type rf_protos[ST_MAX];
+#endif
+	struct st_data_s *core_data;
+};
+
+long st_kim_start(void);
+long st_kim_stop(void);
+/*
+ * called from st_tty_receive to authenticate fw_download
+ */
+void st_kim_recv(void *, const unsigned char *, long count);
+
+void st_kim_chip_toggle(enum proto_type, enum kim_gpio_state);
+
+void st_kim_complete(void);
+
+/* function called from ST KIM to ST Core, to
+ * list out the protocols registered
+ */
+void kim_st_list_protocols(struct st_data_s *, char *);
+
+/*
+ * BTS headers
+ */
+#define ACTION_SEND_COMMAND     1
+#define ACTION_WAIT_EVENT       2
+#define ACTION_SERIAL           3
+#define ACTION_DELAY            4
+#define ACTION_RUN_SCRIPT       5
+#define ACTION_REMARKS          6
+
+/*
+ *  * BRF Firmware header
+ *   */
+struct bts_header {
+	uint32_t magic;
+	uint32_t version;
+	uint8_t future[24];
+	uint8_t actions[0];
+} __attribute__ ((packed));
+
+/*
+ *  * BRF Actions structure
+ *   */
+struct bts_action {
+	uint16_t type;
+	uint16_t size;
+	uint8_t data[0];
+} __attribute__ ((packed));
+
+struct bts_action_send {
+	uint8_t data[0];
+} __attribute__ ((packed));
+
+struct bts_action_wait {
+	uint32_t msec;
+	uint32_t size;
+	uint8_t data[0];
+} __attribute__ ((packed));
+
+struct bts_action_delay {
+	uint32_t msec;
+} __attribute__ ((packed));
+
+struct bts_action_serial {
+	uint32_t baud;
+	uint32_t flow_control;
+} __attribute__ ((packed));
+
+/* for identifying the change speed HCI VS
+ * command
+ */
+struct hci_command {
+	uint8_t prefix;
+	uint16_t opcode;
+	uint8_t plen;
+	uint32_t speed;
+} __attribute__ ((packed));
+
+
+#endif /* ST_KIM_H */
-- 
1.5.4.3






> greg k-h
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-31 23:57   ` Pavan Savoy
@ 2010-04-01  9:20     ` Alan Cox
  0 siblings, 0 replies; 27+ messages in thread
From: Alan Cox @ 2010-04-01  9:20 UTC (permalink / raw)
  To: pavan_savoy; +Cc: Greg KH, Marcel Holtmann, linux-kernel

> +/*
> + * function to return whether the firmware response was proper
> + * in case of error don't complete so that waiting for proper
> + * response times out
> + */
> +void validate_firmware_response(struct sk_buff *skb)
> +{
> +	if (unlikely(skb->data[5] != 0)) {
> +		pr_err("no proper response during fw download");
> +		pr_err("data6 %x", skb->data[5]);

In this driver you do know the device so you need to be using dev_ and
passing around dev (or something that gives you dev).

> +static int kim_probe(struct platform_device *pdev)
> +{
> +	long status;
> +	long proto;
> +	long *gpios = pdev->dev.platform_data;
> +
> +	status = st_core_init(&kim_gdata->core_data);

I would expect any truely global data to be configured in the module init
and then device specific data you want to do something like this

	kim_data = kzalloc(sizeof(something), GFP_KERNEL);

	..

	kim_data_init(&pdev->dev, kim_data);
	dev_set_drvdata(&pdev->dev, kim_data);

Elsewhere you can now do

	kim_data = dev_get_drvdata(&pdev->dev);

to get it back

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
@ 2010-04-27 16:15 Pavan Savoy
  0 siblings, 0 replies; 27+ messages in thread
From: Pavan Savoy @ 2010-04-27 16:15 UTC (permalink / raw)
  To: Alan Cox; +Cc: linux-kernel

Alan,

I have removed the global reference. Please suggest about the other 2 items, 
1. having device contexts.
All of the data now is held in the tty device context.
What I couldn't do was when a particular protocol registers, like say BT driver registers with this driver via st_register, I couldn't pass the device context. even If I did like the hci device context in that case, 
what use do I make of it ?

2. locking ?
What should be done about locking ?

---
 drivers/staging/ti-st/st_core.c | 1058 +++++++++++++++++++++++++++++++++++++++
 drivers/staging/ti-st/st_core.h |   98 ++++
 2 files changed, 1156 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/ti-st/st_core.c
 create mode 100644 drivers/staging/ti-st/st_core.h

diff --git a/drivers/staging/ti-st/st_core.c b/drivers/staging/ti-st/st_core.c
new file mode 100644
index 0000000..cb965b3
--- /dev/null
+++ b/drivers/staging/ti-st/st_core.c
@@ -0,0 +1,1058 @@
+/*
+ *  Shared Transport Line discipline driver Core
+ *	This hooks up ST KIM driver and ST LL driver
+ *  Copyright (C) 2009 Texas Instruments
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#define pr_fmt(fmt)	"(stc): " fmt
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/tty.h>
+
+/* understand BT, FM and GPS for now */
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+#include <net/bluetooth/hci.h>
+#include "fm.h"
+/*
+ * packet formats for fm and gps
+ * #include "gps.h"
+ */
+#include "st_core.h"
+#include "st_kim.h"
+#include "st_ll.h"
+#include "st.h"
+
+#ifdef DEBUG
+/* strings to be used for rfkill entries and by
+ * ST Core to be used for sysfs debug entry
+ */
+#define PROTO_ENTRY(type, name)	name
+const unsigned char *protocol_strngs[] = {
+	PROTO_ENTRY(ST_BT, "Bluetooth"),
+	PROTO_ENTRY(ST_FM, "FM"),
+	PROTO_ENTRY(ST_GPS, "GPS"),
+};
+#endif
+
+/********************************************************************/
+#if 0
+/* internal misc functions */
+bool is_protocol_list_empty(void)
+{
+	unsigned char i = 0;
+	pr_info(" %s ", __func__);
+	for (i = 0; i < ST_MAX; i++) {
+		if (st_gdata->list[i] != NULL)
+			return ST_NOTEMPTY;
+		/* not empty */
+	}
+	/* list empty */
+	return ST_EMPTY;
+}
+#endif
+/* can be called in from
+ * -- KIM (during fw download)
+ * -- ST Core (during st_write)
+ *
+ *  This is the internal write function - a wrapper
+ *  to tty->ops->write
+ */
+int st_int_write(struct st_data_s *st_gdata,
+	const unsigned char *data, int count)
+{
+#ifdef VERBOSE			/* for debug */
+	int i;
+#endif
+	struct tty_struct *tty;
+	if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
+		pr_err("tty unavailable to perform write");
+		return ST_ERR_FAILURE;
+	}
+	tty = st_gdata->tty;
+#ifdef VERBOSE
+	printk(KERN_ERR "start data..\n");
+	for (i = 0; i < count; i++)	/* no newlines for each datum */
+		printk(" %x", data[i]);
+	printk(KERN_ERR "\n ..end data\n");
+#endif
+	return tty->ops->write(tty, data, count);
+
+}
+
+/*
+ * push the skb received to relevant
+ * protocol stacks
+ */
+void st_send_frame(enum proto_type protoid, struct st_data_s *st_gdata)
+{
+	pr_info(" %s(prot:%d) ", __func__, protoid);
+
+	if (unlikely
+	    (st_gdata == NULL || st_gdata->rx_skb == NULL
+	     || st_gdata->list[protoid] == NULL)) {
+		pr_err("protocol %d not registered, no data to send?",
+			   protoid);
+		kfree_skb(st_gdata->rx_skb);
+		return;
+	}
+	/* this cannot fail
+	 * this shouldn't take long
+	 * - should be just skb_queue_tail for the
+	 *   protocol stack driver
+	 */
+	if (likely(st_gdata->list[protoid]->recv != NULL)) {
+		if (unlikely(st_gdata->list[protoid]->recv(st_gdata->rx_skb)
+			     != ST_SUCCESS)) {
+			pr_err(" proto stack %d's ->recv failed", protoid);
+			kfree_skb(st_gdata->rx_skb);
+			return;
+		}
+	} else {
+		pr_err(" proto stack %d's ->recv null", protoid);
+		kfree_skb(st_gdata->rx_skb);
+	}
+	pr_info(" done %s", __func__);
+	return;
+}
+
+/*
+ * to call registration complete callbacks
+ * of all protocol stack drivers
+ */
+void st_reg_complete(struct st_data_s *st_gdata, char err)
+{
+	unsigned char i = 0;
+	pr_info(" %s ", __func__);
+	for (i = 0; i < ST_MAX; i++) {
+		if (likely(st_gdata != NULL && st_gdata->list[i] != NULL &&
+			   st_gdata->list[i]->reg_complete_cb != NULL))
+			st_gdata->list[i]->reg_complete_cb(err);
+	}
+}
+
+static inline int st_check_data_len(struct st_data_s *st_gdata,
+	int protoid, int len)
+{
+	register int room = skb_tailroom(st_gdata->rx_skb);
+
+	pr_info("len %d room %d", len, room);
+
+	if (!len) {
+		/* Received packet has only packet header and
+		 * has zero length payload. So, ask ST CORE to
+		 * forward the packet to protocol driver (BT/FM/GPS)
+		 */
+		st_send_frame(protoid, st_gdata);
+
+	} else if (len > room) {
+		/* Received packet's payload length is larger.
+		 * We can't accommodate it in created skb.
+		 */
+		pr_err("Data length is too large len %d room %d", len,
+			   room);
+		kfree_skb(st_gdata->rx_skb);
+	} else {
+		/* Packet header has non-zero payload length and
+		 * we have enough space in created skb. Lets read
+		 * payload data */
+		st_gdata->rx_state = ST_BT_W4_DATA;
+		st_gdata->rx_count = len;
+		return len;
+	}
+
+	/* Change ST state to continue to process next
+	 * packet */
+	st_gdata->rx_state = ST_W4_PACKET_TYPE;
+	st_gdata->rx_skb = NULL;
+	st_gdata->rx_count = 0;
+
+	return 0;
+}
+
+/* internal function for action when wake-up ack
+ * received
+ */
+static inline void st_wakeup_ack(struct st_data_s *st_gdata,
+	unsigned char cmd)
+{
+	register struct sk_buff *waiting_skb;
+	unsigned long flags = 0;
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	/* de-Q from waitQ and Q in txQ now that the
+	 * chip is awake
+	 */
+	while ((waiting_skb = skb_dequeue(&st_gdata->tx_waitq)))
+		skb_queue_tail(&st_gdata->txq, waiting_skb);
+
+	/* state forwarded to ST LL */
+	st_ll_sleep_state(st_gdata, (unsigned long)cmd);
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	/* wake up to send the recently copied skbs from waitQ */
+	st_tx_wakeup(st_gdata);
+}
+
+/* Decodes received RAW data and forwards to corresponding
+ * client drivers (Bluetooth,FM,GPS..etc).
+ *
+ */
+void st_int_recv(void *disc_data,
+	const unsigned char *data, long count)
+{
+	register char *ptr;
+	struct hci_event_hdr *eh;
+	struct hci_acl_hdr *ah;
+	struct hci_sco_hdr *sh;
+	struct fm_event_hdr *fm;
+	struct gps_event_hdr *gps;
+	register int len = 0, type = 0, dlen = 0;
+	static enum proto_type protoid = ST_MAX;
+	struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
+
+	ptr = (char *)data;
+	/* tty_receive sent null ? */
+	if (unlikely(ptr == NULL) || (st_gdata == NULL)) {
+		pr_err(" received null from TTY ");
+		return;
+	}
+
+	pr_info("count %ld rx_state %ld"
+		   "rx_count %ld", count, st_gdata->rx_state,
+		   st_gdata->rx_count);
+
+	/* Decode received bytes here */
+	while (count) {
+		if (st_gdata->rx_count) {
+			len = min_t(unsigned int, st_gdata->rx_count, count);
+			memcpy(skb_put(st_gdata->rx_skb, len), ptr, len);
+			st_gdata->rx_count -= len;
+			count -= len;
+			ptr += len;
+
+			if (st_gdata->rx_count)
+				continue;
+
+			/* Check ST RX state machine , where are we? */
+			switch (st_gdata->rx_state) {
+
+				/* Waiting for complete packet ? */
+			case ST_BT_W4_DATA:
+				pr_info("Complete pkt received");
+
+				/* Ask ST CORE to forward
+				 * the packet to protocol driver */
+				st_send_frame(protoid, st_gdata);
+
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_skb = NULL;
+				protoid = ST_MAX;	/* is this required ? */
+				continue;
+
+				/* Waiting for Bluetooth event header ? */
+			case ST_BT_W4_EVENT_HDR:
+				eh = (struct hci_event_hdr *)st_gdata->rx_skb->
+				    data;
+
+				pr_info("Event header: evt 0x%2.2x"
+					   "plen %d", eh->evt, eh->plen);
+
+				st_check_data_len(st_gdata, protoid, eh->plen);
+				continue;
+
+				/* Waiting for Bluetooth acl header ? */
+			case ST_BT_W4_ACL_HDR:
+				ah = (struct hci_acl_hdr *)st_gdata->rx_skb->
+				    data;
+				dlen = __le16_to_cpu(ah->dlen);
+
+				pr_info("ACL header: dlen %d", dlen);
+
+				st_check_data_len(st_gdata, protoid, dlen);
+				continue;
+
+				/* Waiting for Bluetooth sco header ? */
+			case ST_BT_W4_SCO_HDR:
+				sh = (struct hci_sco_hdr *)st_gdata->rx_skb->
+				    data;
+
+				pr_info("SCO header: dlen %d", sh->dlen);
+
+				st_check_data_len(st_gdata, protoid, sh->dlen);
+				continue;
+			case ST_FM_W4_EVENT_HDR:
+				fm = (struct fm_event_hdr *)st_gdata->rx_skb->
+				    data;
+				pr_info("FM Header: ");
+				st_check_data_len(st_gdata, ST_FM, fm->plen);
+				continue;
+				/* TODO : Add GPS packet machine logic here */
+			case ST_GPS_W4_EVENT_HDR:
+				/* [0x09 pkt hdr][R/W byte][2 byte len] */
+				gps = (struct gps_event_hdr *)st_gdata->rx_skb->
+				     data;
+				pr_info("GPS Header: ");
+				st_check_data_len(st_gdata, ST_GPS, gps->plen);
+				continue;
+			}	/* end of switch rx_state */
+		}
+
+		/* end of if rx_count */
+		/* Check first byte of packet and identify module
+		 * owner (BT/FM/GPS) */
+		switch (*ptr) {
+
+			/* Bluetooth event packet? */
+		case HCI_EVENT_PKT:
+			pr_info("Event packet");
+			st_gdata->rx_state = ST_BT_W4_EVENT_HDR;
+			st_gdata->rx_count = HCI_EVENT_HDR_SIZE;
+			type = HCI_EVENT_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Bluetooth acl packet? */
+		case HCI_ACLDATA_PKT:
+			pr_info("ACL packet");
+			st_gdata->rx_state = ST_BT_W4_ACL_HDR;
+			st_gdata->rx_count = HCI_ACL_HDR_SIZE;
+			type = HCI_ACLDATA_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Bluetooth sco packet? */
+		case HCI_SCODATA_PKT:
+			pr_info("SCO packet");
+			st_gdata->rx_state = ST_BT_W4_SCO_HDR;
+			st_gdata->rx_count = HCI_SCO_HDR_SIZE;
+			type = HCI_SCODATA_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Channel 8(FM) packet? */
+		case ST_FM_CH8_PKT:
+			pr_info("FM CH8 packet");
+			type = ST_FM_CH8_PKT;
+			st_gdata->rx_state = ST_FM_W4_EVENT_HDR;
+			st_gdata->rx_count = FM_EVENT_HDR_SIZE;
+			protoid = ST_FM;
+			break;
+
+			/* Channel 9(GPS) packet? */
+		case 0x9:	/*ST_LL_GPS_CH9_PKT */
+			pr_info("GPS CH9 packet");
+			type = 0x9;	/* ST_LL_GPS_CH9_PKT; */
+			protoid = ST_GPS;
+			st_gdata->rx_state = ST_GPS_W4_EVENT_HDR;
+			st_gdata->rx_count = 3;	/* GPS_EVENT_HDR_SIZE -1*/
+			break;
+		case LL_SLEEP_IND:
+		case LL_SLEEP_ACK:
+		case LL_WAKE_UP_IND:
+			pr_info("PM packet");
+			/* this takes appropriate action based on
+			 * sleep state received --
+			 */
+			st_ll_sleep_state(st_gdata, *ptr);
+			ptr++;
+			count--;
+			continue;
+		case LL_WAKE_UP_ACK:
+			pr_info("PM packet");
+			/* wake up ack received */
+			st_wakeup_ack(st_gdata, *ptr);
+			ptr++;
+			count--;
+			continue;
+			/* Unknow packet? */
+		default:
+			pr_err("Unknown packet type %2.2x", (__u8) *ptr);
+			ptr++;
+			count--;
+			continue;
+		};
+		ptr++;
+		count--;
+
+		switch (protoid) {
+		case ST_BT:
+			/* Allocate new packet to hold received data */
+			st_gdata->rx_skb =
+			    bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				pr_err("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			bt_cb(st_gdata->rx_skb)->pkt_type = type;
+			break;
+		case ST_FM:	/* for FM */
+			st_gdata->rx_skb =
+			    alloc_skb(FM_MAX_FRAME_SIZE, GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				pr_err("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			/* place holder 0x08 */
+			skb_reserve(st_gdata->rx_skb, 1);
+			st_gdata->rx_skb->cb[0] = ST_FM_CH8_PKT;
+			break;
+		case ST_GPS:
+			/* for GPS */
+			st_gdata->rx_skb =
+			    alloc_skb(100 /*GPS_MAX_FRAME_SIZE */ , GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				pr_err("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			/* place holder 0x09 */
+			skb_reserve(st_gdata->rx_skb, 1);
+			st_gdata->rx_skb->cb[0] = 0x09;	/*ST_GPS_CH9_PKT; */
+			break;
+		case ST_MAX:
+			break;
+		}
+	}
+	pr_info("done %s", __func__);
+	return;
+}
+
+/* internal de-Q function
+ * -- return previous in-completely written skb
+ *  or return the skb in the txQ
+ */
+struct sk_buff *st_int_dequeue(struct st_data_s *st_gdata)
+{
+	struct sk_buff *returning_skb;
+
+	pr_info("%s", __func__);
+	/* if the previous skb wasn't written completely
+	 */
+	if (st_gdata->tx_skb != NULL) {
+		returning_skb = st_gdata->tx_skb;
+		st_gdata->tx_skb = NULL;
+		return returning_skb;
+	}
+
+	/* de-Q from the txQ always if previous write is complete */
+	return skb_dequeue(&st_gdata->txq);
+}
+
+/* internal Q-ing function
+ * will either Q the skb to txq or the tx_waitq
+ * depending on the ST LL state
+ *
+ * lock the whole func - since ll_getstate and Q-ing should happen
+ * in one-shot
+ */
+void st_int_enqueue(struct st_data_s *st_gdata, struct sk_buff *skb)
+{
+	unsigned long flags = 0;
+
+	pr_info("%s", __func__);
+	/* this function can be invoked in more then one context.
+	 * so have a lock */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	switch (st_ll_getstate(st_gdata)) {
+	case ST_LL_AWAKE:
+		pr_info("ST LL is AWAKE, sending normally");
+		skb_queue_tail(&st_gdata->txq, skb);
+		break;
+	case ST_LL_ASLEEP_TO_AWAKE:
+		skb_queue_tail(&st_gdata->tx_waitq, skb);
+		break;
+	case ST_LL_AWAKE_TO_ASLEEP:	/* host cannot be in this state */
+		pr_err("ST LL is illegal state(%ld),"
+			   "purging received skb.", st_ll_getstate(st_gdata));
+		kfree_skb(skb);
+		break;
+
+	case ST_LL_ASLEEP:
+		/* call a function of ST LL to put data
+		 * in tx_waitQ and wake_ind in txQ
+		 */
+		skb_queue_tail(&st_gdata->tx_waitq, skb);
+		st_ll_wakeup(st_gdata);
+		break;
+	default:
+		pr_err("ST LL is illegal state(%ld),"
+			   "purging received skb.", st_ll_getstate(st_gdata));
+		kfree_skb(skb);
+		break;
+	}
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+	pr_info("done %s", __func__);
+	return;
+}
+
+/*
+ * internal wakeup function
+ * called from either
+ * - TTY layer when write's finished
+ * - st_write (in context of the protocol stack)
+ */
+void st_tx_wakeup(struct st_data_s *st_data)
+{
+	struct sk_buff *skb;
+	unsigned long flags;	/* for irq save flags */
+	pr_info("%s", __func__);
+	/* check for sending & set flag sending here */
+	if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) {
+		pr_info("ST already sending");
+		/* keep sending */
+		set_bit(ST_TX_WAKEUP, &st_data->tx_state);
+		return;
+		/* TX_WAKEUP will be checked in another
+		 * context
+		 */
+	}
+	do {			/* come back if st_tx_wakeup is set */
+		/* woke-up to write */
+		clear_bit(ST_TX_WAKEUP, &st_data->tx_state);
+		while ((skb = st_int_dequeue(st_data))) {
+			int len;
+			spin_lock_irqsave(&st_data->lock, flags);
+			/* enable wake-up from TTY */
+			set_bit(TTY_DO_WRITE_WAKEUP, &st_data->tty->flags);
+			len = st_int_write(st_data, skb->data, skb->len);
+			skb_pull(skb, len);
+			/* if skb->len = len as expected, skb->len=0 */
+			if (skb->len) {
+				/* would be the next skb to be sent */
+				st_data->tx_skb = skb;
+				spin_unlock_irqrestore(&st_data->lock, flags);
+				break;
+			}
+			kfree_skb(skb);
+			spin_unlock_irqrestore(&st_data->lock, flags);
+		}
+		/* if wake-up is set in another context- restart sending */
+	} while (test_bit(ST_TX_WAKEUP, &st_data->tx_state));
+
+	/* clear flag sending */
+	clear_bit(ST_TX_SENDING, &st_data->tx_state);
+}
+
+/********************************************************************/
+/* functions called from ST KIM
+*/
+void kim_st_list_protocols(struct st_data_s *st_gdata, char *buf)
+{
+	unsigned long flags = 0;
+#ifdef DEBUG
+	unsigned char i = ST_MAX;
+#endif
+	spin_lock_irqsave(&st_gdata->lock, flags);
+#ifdef DEBUG			/* more detailed log */
+	for (i = 0; i < ST_MAX; i++) {
+		if (i == 0) {
+			sprintf(buf, "%s is %s", protocol_strngs[i],
+				st_gdata->list[i] !=
+				NULL ? "Registered" : "Unregistered");
+		} else {
+			sprintf(buf, "%s\n%s is %s", buf, protocol_strngs[i],
+				st_gdata->list[i] !=
+				NULL ? "Registered" : "Unregistered");
+		}
+	}
+	sprintf(buf, "%s\n", buf);
+#else /* limited info */
+	sprintf(buf, "BT=%c\nFM=%c\nGPS=%c\n",
+		st_gdata->list[ST_BT] != NULL ? 'R' : 'U',
+		st_gdata->list[ST_FM] != NULL ? 'R' : 'U',
+		st_gdata->list[ST_GPS] != NULL ? 'R' : 'U');
+#endif
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+}
+
+/********************************************************************/
+/*
+ * functions called from protocol stack drivers
+ * to be EXPORT-ed
+ */
+long st_register(struct st_proto_s *new_proto)
+{
+	struct st_data_s	*st_gdata;
+	long err = ST_SUCCESS;
+	unsigned long flags = 0;
+
+	st_kim_ref(&st_gdata);
+	pr_info("%s(%d) ", __func__, new_proto->type);
+	if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL
+	    || new_proto->reg_complete_cb == NULL) {
+		pr_err("gdata/new_proto/recv or reg_complete_cb not ready");
+		return ST_ERR_FAILURE;
+	}
+
+	if (new_proto->type < ST_BT || new_proto->type >= ST_MAX) {
+		pr_err("protocol %d not supported", new_proto->type);
+		return ST_ERR_NOPROTO;
+	}
+
+	if (st_gdata->list[new_proto->type] != NULL) {
+		pr_err("protocol %d already registered", new_proto->type);
+		return ST_ERR_ALREADY;
+	}
+
+	/* can be from process context only */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) {
+		pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->type);
+		/* fw download in progress */
+		st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+
+		set_bit(ST_REG_PENDING, &st_gdata->st_state);
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return ST_ERR_PENDING;
+	} else if (st_gdata->protos_registered == ST_EMPTY) {
+		pr_info(" protocol list empty :%d ", new_proto->type);
+		set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+
+		/* release lock previously held - re-locked below */
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+		/* enable the ST LL - to set default chip state */
+		st_ll_enable(st_gdata);
+		/* this may take a while to complete
+		 * since it involves BT fw download
+		 */
+		err = st_kim_start();
+		if (err != ST_SUCCESS) {
+			clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+			if ((st_gdata->protos_registered != ST_EMPTY) &&
+			    (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+				pr_err(" KIM failure complete callback ");
+				st_reg_complete(st_gdata, ST_ERR_FAILURE);
+			}
+
+			return ST_ERR_FAILURE;
+		}
+
+		/* the protocol might require other gpios to be toggled
+		 */
+		st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+		clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+
+		/* this is where all pending registration
+		 * are signalled to be complete by calling callback functions
+		 */
+		if ((st_gdata->protos_registered != ST_EMPTY) &&
+		    (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+			pr_info(" call reg complete callback ");
+			st_gdata->protos_registered++;
+			st_reg_complete(st_gdata, ST_SUCCESS);
+		}
+		clear_bit(ST_REG_PENDING, &st_gdata->st_state);
+
+		/* check for already registered once more,
+		 * since the above check is old
+		 */
+		if (st_gdata->list[new_proto->type] != NULL) {
+			pr_err(" proto %d already registered ",
+				   new_proto->type);
+			return ST_ERR_ALREADY;
+		}
+
+		spin_lock_irqsave(&st_gdata->lock, flags);
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return err;
+	}
+	/* if fw is already downloaded & new stack registers protocol */
+	else {
+		switch (new_proto->type) {
+		case ST_BT:
+			/* do nothing */
+			break;
+		case ST_FM:
+		case ST_GPS:
+			st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+			break;
+		case ST_MAX:
+		default:
+			pr_err("%d protocol not supported",
+				   new_proto->type);
+			err = ST_ERR_NOPROTO;
+			/* something wrong */
+			break;
+		}
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+
+		/* lock already held before entering else */
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return err;
+	}
+	pr_info("done %s(%d) ", __func__, new_proto->type);
+}
+EXPORT_SYMBOL_GPL(st_register);
+
+/* to unregister a protocol -
+ * to be called from protocol stack driver
+ */
+long st_unregister(enum proto_type type)
+{
+	long err = ST_SUCCESS;
+	unsigned long flags = 0;
+	struct st_data_s	*st_gdata;
+
+	pr_info("%s: %d ", __func__, type);
+
+	st_kim_ref(&st_gdata);
+	if (type < ST_BT || type >= ST_MAX) {
+		pr_err(" protocol %d not supported", type);
+		return ST_ERR_NOPROTO;
+	}
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	if (st_gdata->list[type] == NULL) {
+		pr_err(" protocol %d not registered", type);
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return ST_ERR_NOPROTO;
+	}
+
+	st_gdata->protos_registered--;
+	st_gdata->list[type] = NULL;
+
+	/* kim ignores BT in the below function
+	 * and handles the rest, BT is toggled
+	 * only in kim_start and kim_stop
+	 */
+	st_kim_chip_toggle(type, KIM_GPIO_INACTIVE);
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	if ((st_gdata->protos_registered == ST_EMPTY) &&
+	    (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+		pr_info(" all protocols unregistered ");
+
+		/* stop traffic on tty */
+		if (st_gdata->tty) {
+			tty_ldisc_flush(st_gdata->tty);
+			stop_tty(st_gdata->tty);
+		}
+
+		/* all protocols now unregistered */
+		st_kim_stop();
+		/* disable ST LL */
+		st_ll_disable(st_gdata);
+	}
+	return err;
+}
+
+/*
+ * called in protocol stack drivers
+ * via the write function pointer
+ */
+long st_write(struct sk_buff *skb)
+{
+	struct st_data_s *st_gdata;
+#ifdef DEBUG
+	enum proto_type protoid = ST_MAX;
+#endif
+	long len;
+
+	st_kim_ref(&st_gdata);
+	if (unlikely(skb == NULL || st_gdata == NULL
+		|| st_gdata->tty == NULL)) {
+		pr_err("data/tty unavailable to perform write");
+		return ST_ERR_FAILURE;
+	}
+#ifdef DEBUG			/* open-up skb to read the 1st byte */
+	switch (skb->data[0]) {
+	case HCI_COMMAND_PKT:
+	case HCI_ACLDATA_PKT:
+	case HCI_SCODATA_PKT:
+		protoid = ST_BT;
+		break;
+	case ST_FM_CH8_PKT:
+		protoid = ST_FM;
+		break;
+	case 0x09:
+		protoid = ST_GPS;
+		break;
+	}
+	if (unlikely(st_gdata->list[protoid] == NULL)) {
+		pr_err(" protocol %d not registered, and writing? ",
+			   protoid);
+		return ST_ERR_FAILURE;
+	}
+#endif
+	pr_info("%d to be written", skb->len);
+	len = skb->len;
+
+	/* st_ll to decide where to enqueue the skb */
+	st_int_enqueue(st_gdata, skb);
+	/* wake up */
+	st_tx_wakeup(st_gdata);
+
+	/* return number of bytes written */
+	return len;
+}
+
+/* for protocols making use of shared transport */
+EXPORT_SYMBOL_GPL(st_unregister);
+
+/********************************************************************/
+/*
+ * functions called from TTY layer
+ */
+static int st_tty_open(struct tty_struct *tty)
+{
+	int err = ST_SUCCESS;
+	struct st_data_s *st_gdata;
+	pr_info("%s ", __func__);
+
+	st_kim_ref(&st_gdata);
+	st_gdata->tty = tty;
+	tty->disc_data = st_gdata;
+
+	/* don't do an wakeup for now */
+	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+
+	/* mem already allocated
+	 */
+	tty->receive_room = 65536;
+	/* Flush any pending characters in the driver and discipline. */
+	tty_ldisc_flush(tty);
+	tty_driver_flush_buffer(tty);
+	/*
+	 * signal to UIM via KIM that -
+	 * installation of N_TI_WL ldisc is complete
+	 */
+	st_kim_complete();
+	pr_info("done %s", __func__);
+	return err;
+}
+
+static void st_tty_close(struct tty_struct *tty)
+{
+	unsigned char i = ST_MAX;
+	unsigned long flags = 0;
+	struct	st_data_s *st_gdata = tty->disc_data;
+
+	pr_info("%s ", __func__);
+
+	/* TODO:
+	 * if a protocol has been registered & line discipline
+	 * un-installed for some reason - what should be done ?
+	 */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	for (i = ST_BT; i < ST_MAX; i++) {
+		if (st_gdata->list[i] != NULL)
+			pr_err("%d not un-registered", i);
+		st_gdata->list[i] = NULL;
+	}
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+	/*
+	 * signal to UIM via KIM that -
+	 * N_TI_WL ldisc is un-installed
+	 */
+	st_kim_complete();
+	st_gdata->tty = NULL;
+	/* Flush any pending characters in the driver and discipline. */
+	tty_ldisc_flush(tty);
+	tty_driver_flush_buffer(tty);
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	/* empty out txq and tx_waitq */
+	skb_queue_purge(&st_gdata->txq);
+	skb_queue_purge(&st_gdata->tx_waitq);
+	/* reset the TTY Rx states of ST */
+	st_gdata->rx_count = 0;
+	st_gdata->rx_state = ST_W4_PACKET_TYPE;
+	kfree_skb(st_gdata->rx_skb);
+	st_gdata->rx_skb = NULL;
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	pr_info("%s: done ", __func__);
+}
+
+static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
+			   char *tty_flags, int count)
+{
+	struct st_data_s *st_gdata = tty->disc_data;
+#ifdef VERBOSE
+	long i;
+	printk(KERN_ERR "incoming data...\n");
+	for (i = 0; i < count; i++)
+		printk(" %x", data[i]);
+	printk(KERN_ERR "\n.. data end\n");
+#endif
+
+	if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) {
+		/*
+		 * if fw download is in progress then route incoming data
+		 * to KIM for validation
+		 */
+		st_kim_recv(st_gdata, data, count);
+	} else {
+		st_int_recv(st_gdata, data, count);
+	}
+	pr_info("done %s", __func__);
+}
+
+/* wake-up function called in from the TTY layer
+ * inside the internal wakeup function will be called
+ */
+static void st_tty_wakeup(struct tty_struct *tty)
+{
+	struct	st_data_s *st_gdata = tty->disc_data;
+	pr_info("%s ", __func__);
+	/* don't do an wakeup for now */
+	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+
+	/* call our internal wakeup */
+	st_tx_wakeup((void *)st_gdata);
+}
+
+static void st_tty_flush_buffer(struct tty_struct *tty)
+{
+	struct	st_data_s *st_gdata = tty->disc_data;
+	pr_info("%s ", __func__);
+
+	kfree_skb(st_gdata->tx_skb);
+	st_gdata->tx_skb = NULL;
+
+	tty->ops->flush_buffer(tty);
+	return;
+}
+
+/********************************************************************/
+int st_core_init(struct st_data_s **core_data)
+{
+	struct st_data_s *st_gdata;
+	long err;
+	static struct tty_ldisc_ops *st_ldisc_ops;
+
+	/* populate and register to TTY line discipline */
+	st_ldisc_ops = kzalloc(sizeof(*st_ldisc_ops), GFP_KERNEL);
+	if (!st_ldisc_ops) {
+		pr_err("no mem to allocate");
+		return -ENOMEM;
+	}
+
+	st_ldisc_ops->magic = TTY_LDISC_MAGIC;
+	st_ldisc_ops->name = "n_st";	/*"n_hci"; */
+	st_ldisc_ops->open = st_tty_open;
+	st_ldisc_ops->close = st_tty_close;
+	st_ldisc_ops->receive_buf = st_tty_receive;
+	st_ldisc_ops->write_wakeup = st_tty_wakeup;
+	st_ldisc_ops->flush_buffer = st_tty_flush_buffer;
+	st_ldisc_ops->owner = THIS_MODULE;
+
+	err = tty_register_ldisc(N_TI_WL, st_ldisc_ops);
+	if (err) {
+		pr_err("error registering %d line discipline %ld",
+			   N_TI_WL, err);
+		kfree(st_ldisc_ops);
+		return err;
+	}
+	pr_info("registered n_shared line discipline");
+
+	st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL);
+	if (!st_gdata) {
+		pr_err("memory allocation failed");
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc %ld", err);
+		kfree(st_ldisc_ops);
+		err = -ENOMEM;
+		return err;
+	}
+
+	/* Initialize ST TxQ and Tx waitQ queue head. All BT/FM/GPS module skb's
+	 * will be pushed in this queue for actual transmission.
+	 */
+	skb_queue_head_init(&st_gdata->txq);
+	skb_queue_head_init(&st_gdata->tx_waitq);
+
+	/* Locking used in st_int_enqueue() to avoid multiple execution */
+	spin_lock_init(&st_gdata->lock);
+
+	/* ldisc_ops ref to be only used in __exit of module */
+	st_gdata->ldisc_ops = st_ldisc_ops;
+
+#if 0
+	err = st_kim_init();
+	if (err) {
+		pr_err("error during kim initialization(%ld)", err);
+		kfree(st_gdata);
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc");
+		kfree(st_ldisc_ops);
+		return -1;
+	}
+#endif
+
+	err = st_ll_init(st_gdata);
+	if (err) {
+		pr_err("error during st_ll initialization(%ld)", err);
+		kfree(st_gdata);
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc");
+		kfree(st_ldisc_ops);
+		return -1;
+	}
+	*core_data = st_gdata;
+	return 0;
+}
+
+void st_core_exit(struct st_data_s *st_gdata)
+{
+	long err;
+	/* internal module cleanup */
+	err = st_ll_deinit(st_gdata);
+	if (err)
+		pr_err("error during deinit of ST LL %ld", err);
+#if 0
+	err = st_kim_deinit();
+	if (err)
+		pr_err("error during deinit of ST KIM %ld", err);
+#endif
+	if (st_gdata != NULL) {
+		/* Free ST Tx Qs and skbs */
+		skb_queue_purge(&st_gdata->txq);
+		skb_queue_purge(&st_gdata->tx_waitq);
+		kfree_skb(st_gdata->rx_skb);
+		kfree_skb(st_gdata->tx_skb);
+		/* TTY ldisc cleanup */
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc %ld", err);
+		kfree(st_gdata->ldisc_ops);
+		/* free the global data pointer */
+		kfree(st_gdata);
+	}
+}
+
+
diff --git a/drivers/staging/ti-st/st_core.h b/drivers/staging/ti-st/st_core.h
new file mode 100644
index 0000000..f271c88
--- /dev/null
+++ b/drivers/staging/ti-st/st_core.h
@@ -0,0 +1,98 @@
+/*
+ *  Shared Transport Core header file
+ *
+ *  Copyright (C) 2009 Texas Instruments
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef ST_CORE_H
+#define ST_CORE_H
+
+#include <linux/skbuff.h>
+#include "st.h"
+
+/* states of protocol list */
+#define ST_NOTEMPTY	1
+#define ST_EMPTY	0
+
+/*
+ * possible st_states
+ */
+#define ST_INITIALIZING		1
+#define ST_REG_IN_PROGRESS	2
+#define ST_REG_PENDING		3
+#define ST_WAITING_FOR_RESP	4
+
+/*
+ * local data required for ST/KIM/ST-HCI-LL
+ */
+struct st_data_s {
+	unsigned long st_state;
+/*
+ * an instance of tty_struct & ldisc ops to move around
+ */
+	struct tty_struct *tty;
+	struct tty_ldisc_ops *ldisc_ops;
+/*
+ * the tx skb -
+ * if the skb is already dequeued and the tty failed to write the same
+ * maintain the skb to write in the next transaction
+ */
+	struct sk_buff *tx_skb;
+#define ST_TX_SENDING	1
+#define ST_TX_WAKEUP	2
+	unsigned long tx_state;
+/*
+ * list of protocol registered
+ */
+	struct st_proto_s *list[ST_MAX];
+/*
+ * lock
+ */
+	unsigned long rx_state;
+	unsigned long rx_count;
+	struct sk_buff *rx_skb;
+	struct sk_buff_head txq, tx_waitq;
+	spinlock_t lock;	/* ST LL state lock  */
+	unsigned char	protos_registered;
+	unsigned long ll_state;	/* ST LL power state */
+};
+
+/* point this to tty->driver->write or tty->ops->write
+ * depending upon the kernel version
+ */
+int st_int_write(struct st_data_s*, const unsigned char*, int);
+/* internal write function, passed onto protocol drivers
+ * via the write function ptr of protocol struct
+ */
+long st_write(struct sk_buff *);
+/* function to be called from ST-LL
+ */
+void st_ll_send_frame(enum proto_type, struct sk_buff *);
+/* internal wake up function */
+void st_tx_wakeup(struct st_data_s *st_data);
+
+int st_core_init(struct st_data_s **);
+void st_core_exit(struct st_data_s *);
+void st_kim_ref(struct st_data_s **);
+
+#define GPS_STUB_TEST
+#ifdef GPS_STUB_TEST
+int gps_chrdrv_stub_write(const unsigned char*, int);
+void gps_chrdrv_stub_init(void);
+#endif
+
+#endif /*ST_CORE_H */
-- 
1.5.4.3





^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-04-26 22:03     ` Alan Cox
@ 2010-04-26 22:06       ` Pavan Savoy
  0 siblings, 0 replies; 27+ messages in thread
From: Pavan Savoy @ 2010-04-26 22:06 UTC (permalink / raw)
  To: Alan Cox; +Cc: gregkh, linux-kernel, npelly

Alan,

--- On Tue, 27/4/10, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> From: Alan Cox <alan@lxorguk.ukuu.org.uk>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: pavan_savoy@ti.com
> Cc: gregkh@suse.de, linux-kernel@vger.kernel.org, npelly@google.com, pavan_savoy@yahoo.co.in
> Date: Tuesday, 27 April, 2010, 3:33 AM
> 
> > +/* function pointer pointing to either,
> > + * st_kim_recv during registration to receive fw
> download responses
> > + * st_int_recv after registration to receive proto
> stack responses
> > + */
> > +void (*st_recv) (void*, const unsigned char*, long);
> 
> You still need a context of some kind as I said before to
> avoid thse
> globals and single device limits.

The st_recv is a global pointer to a function, and changes only once in lifetime of the driver (after a function called download_firmware).
This can be easily avoided by having a flag in my st_tty_recieve function, as in

if (test_bit(FIRMWARE_DOWNLOADED, st_gdata->st_state)
        /*
         * if fw download is in progress then route incoming data
         * to KIM for validation
         */
        st_int_recv(data, count);
else
        kim_recv(data, count);
        ST_DRV_VER("done %s", __func__);

However, the other global reference which was st_gdata, now is inside the tty->disc_data reference.

Should I put in the above ?

> And all the other issues - no explanation of the locking
> etc don't seem
> to have been touched either.

I have removed most un-wanted locking stuff, I could find.
What else is required ? please suggest.

> I don't really see how I am supposed to review this stuff
> when the
> locking and flow control assumptions are completely opaque

Didn't get what is that is required about flow-control ?
> Alan
> 

Send free SMS to your Friends on Mobile from your Yahoo! Messenger. Download Now! http://messenger.yahoo.com/download.php

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-04-08 18:16   ` [PATCH] drivers:staging: sources for ST core pavan_savoy
  2010-04-13 15:06     ` Pavan Savoy
@ 2010-04-26 22:03     ` Alan Cox
  2010-04-26 22:06       ` Pavan Savoy
  1 sibling, 1 reply; 27+ messages in thread
From: Alan Cox @ 2010-04-26 22:03 UTC (permalink / raw)
  To: pavan_savoy; +Cc: gregkh, linux-kernel, npelly, pavan_savoy


> +/* function pointer pointing to either,
> + * st_kim_recv during registration to receive fw download responses
> + * st_int_recv after registration to receive proto stack responses
> + */
> +void (*st_recv) (void*, const unsigned char*, long);

You still need a context of some kind as I said before to avoid thse
globals and single device limits.

And all the other issues - no explanation of the locking etc don't seem
to have been touched either.

I don't really see how I am supposed to review this stuff when the
locking and flow control assumptions are completely opaque

Alan

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-04-19 18:37         ` Pavan Savoy
@ 2010-04-26 21:24           ` Pavan Savoy
  0 siblings, 0 replies; 27+ messages in thread
From: Pavan Savoy @ 2010-04-26 21:24 UTC (permalink / raw)
  To: Alan Cox; +Cc: linux-kernel

Alan,

--- On Tue, 20/4/10, Pavan Savoy <pavan_savoy@ti.com> wrote:

> From: Pavan Savoy <pavan_savoy@ti.com>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: "Alan Cox" <alan@lxorguk.ukuu.org.uk>
> Cc: linux-kernel@vger.kernel.org
> Date: Tuesday, 20 April, 2010, 12:07 AM
> 
> --- On Tue, 13/4/10, Alan Cox <alan@lxorguk.ukuu.org.uk>
> wrote:
> 
> > From: Alan Cox <alan@lxorguk.ukuu.org.uk>
> > Subject: Re: [PATCH] drivers:staging: sources for ST
> core
> > To: pavan_savoy@ti.com
> > Cc: linux-kernel@vger.kernel.org
> > Date: Tuesday, 13 April, 2010, 8:42 PM
> > > Any comments on these patches ?
> > 
> > Still on my TODO list, busy trying to beat my own
> employers
> > code into
> > sanity for submission right now ;)
> > 
> > Alan
> 
> 
> Hi Alan,
> 
> Hope you have found some time now.
> Thanks.


A gentle reminder to have a look at the patch once more, and suggest what could/should be done.

> > To unsubscribe from this list: send the line
> "unsubscribe
> > linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/
> > 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 



^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-04-13 15:12       ` Alan Cox
@ 2010-04-19 18:37         ` Pavan Savoy
  2010-04-26 21:24           ` Pavan Savoy
  0 siblings, 1 reply; 27+ messages in thread
From: Pavan Savoy @ 2010-04-19 18:37 UTC (permalink / raw)
  To: Alan Cox; +Cc: linux-kernel


--- On Tue, 13/4/10, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> From: Alan Cox <alan@lxorguk.ukuu.org.uk>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: pavan_savoy@ti.com
> Cc: linux-kernel@vger.kernel.org
> Date: Tuesday, 13 April, 2010, 8:42 PM
> > Any comments on these patches ?
> 
> Still on my TODO list, busy trying to beat my own employers
> code into
> sanity for submission right now ;)
> 
> Alan


Hi Alan,

Hope you have found some time now.
Thanks.

> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 



^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-04-13 15:06     ` Pavan Savoy
@ 2010-04-13 15:12       ` Alan Cox
  2010-04-19 18:37         ` Pavan Savoy
  0 siblings, 1 reply; 27+ messages in thread
From: Alan Cox @ 2010-04-13 15:12 UTC (permalink / raw)
  To: pavan_savoy; +Cc: linux-kernel

> Any comments on these patches ?

Still on my TODO list, busy trying to beat my own employers code into
sanity for submission right now ;)

Alan

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-04-08 18:16   ` [PATCH] drivers:staging: sources for ST core pavan_savoy
@ 2010-04-13 15:06     ` Pavan Savoy
  2010-04-13 15:12       ` Alan Cox
  2010-04-26 22:03     ` Alan Cox
  1 sibling, 1 reply; 27+ messages in thread
From: Pavan Savoy @ 2010-04-13 15:06 UTC (permalink / raw)
  To: alan; +Cc: linux-kernel

Alan,

--- On Thu, 8/4/10, pavan_savoy@ti.com <pavan_savoy@ti.com> wrote:

> From: pavan_savoy@ti.com <pavan_savoy@ti.com>
> Subject: [PATCH] drivers:staging: sources for ST core
> To: gregkh@suse.de, alan@lxorguk.ukuu.org.uk
> Cc: linux-kernel@vger.kernel.org, npelly@google.com, pavan_savoy@yahoo.co.in, "Pavan Savoy" <pavan_savoy@ti.com>
> Date: Thursday, 8 April, 2010, 11:46 PM
> From: Pavan Savoy <pavan_savoy@ti.com>
> 
> Texas Instruments BT, FM and GPS combo chips/drivers
> make use of a single TTY to communicate with the chip.
> This module constitutes the core logic, TTY ldisc driver
> and the exported symbols for registering/unregistering of
> the protocol drivers such as BT/FM/GPS.
> 
> Signed-off-by: Pavan Savoy <pavan_savoy@ti.com>
> ---
>  drivers/staging/ti-st/st_core.c | 1062
> +++++++++++++++++++++++++++++++++++++++
>  drivers/staging/ti-st/st_core.h |   98
> ++++
>  2 files changed, 1160 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/staging/ti-st/st_core.c
>  create mode 100644 drivers/staging/ti-st/st_core.h
> 
> diff --git a/drivers/staging/ti-st/st_core.c
> b/drivers/staging/ti-st/st_core.c
> new file mode 100644
> index 0000000..4e93694
> --- /dev/null
> +++ b/drivers/staging/ti-st/st_core.c
> @@ -0,0 +1,1062 @@
> +/*
> + *  Shared Transport Line discipline driver Core
> + *    This hooks up ST KIM driver and ST LL
> driver
> + *  Copyright (C) 2009 Texas Instruments
> + *
> + *  This program is free software; you can
> redistribute it and/or modify
> + *  it under the terms of the GNU General Public
> License version 2 as
> + *  published by the Free Software Foundation.
> + *
> + *  This program is distributed in the hope that it
> will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the
> implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR
> PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU
> General Public License
> + *  along with this program; if not, write to the
> Free Software
> + *  Foundation, Inc., 59 Temple Place, Suite 330,
> Boston, MA  02111-1307  USA
> + *
> + */
> +
> +#define pr_fmt(fmt)    "(stc): " fmt
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/tty.h>
> +
> +/* understand BT, FM and GPS for now */
> +#include <net/bluetooth/bluetooth.h>
> +#include <net/bluetooth/hci_core.h>
> +#include <net/bluetooth/hci.h>
> +#include "fm.h"
> +/*
> + * packet formats for fm and gps
> + * #include "gps.h"
> + */
> +#include "st_core.h"
> +#include "st_kim.h"
> +#include "st_ll.h"
> +#include "st.h"
> +
> +#ifdef DEBUG
> +/* strings to be used for rfkill entries and by
> + * ST Core to be used for sysfs debug entry
> + */
> +#define PROTO_ENTRY(type, name)    name
> +const unsigned char *protocol_strngs[] = {
> +    PROTO_ENTRY(ST_BT, "Bluetooth"),
> +    PROTO_ENTRY(ST_FM, "FM"),
> +    PROTO_ENTRY(ST_GPS, "GPS"),
> +};
> +#endif
> +/* function pointer pointing to either,
> + * st_kim_recv during registration to receive fw download
> responses
> + * st_int_recv after registration to receive proto stack
> responses
> + */
> +void (*st_recv) (void*, const unsigned char*, long);
> +
> +/********************************************************************/
> +#if 0
> +/* internal misc functions */
> +bool is_protocol_list_empty(void)
> +{
> +    unsigned char i = 0;
> +    pr_info(" %s ", __func__);
> +    for (i = 0; i < ST_MAX; i++) {
> +        if
> (st_gdata->list[i] != NULL)
> +           
> return ST_NOTEMPTY;
> +        /* not empty */
> +    }
> +    /* list empty */
> +    return ST_EMPTY;
> +}
> +#endif
> +/* can be called in from
> + * -- KIM (during fw download)
> + * -- ST Core (during st_write)
> + *
> + *  This is the internal write function - a wrapper
> + *  to tty->ops->write
> + */
> +int st_int_write(struct st_data_s *st_gdata,
> +    const unsigned char *data, int count)
> +{
> +#ifdef VERBOSE       
>     /* for debug */
> +    int i;
> +#endif
> +    struct tty_struct *tty;
> +    if (unlikely(st_gdata == NULL ||
> st_gdata->tty == NULL)) {
> +        pr_err("tty
> unavailable to perform write");
> +        return
> ST_ERR_FAILURE;
> +    }
> +    tty = st_gdata->tty;
> +#ifdef VERBOSE
> +    printk(KERN_ERR "start data..\n");
> +    for (i = 0; i < count;
> i++)    /* no newlines for each datum */
> +        printk(" %x",
> data[i]);
> +    printk(KERN_ERR "\n ..end data\n");
> +#endif
> +    return tty->ops->write(tty, data,
> count);
> +
> +}
> +
> +/*
> + * push the skb received to relevant
> + * protocol stacks
> + */
> +void st_send_frame(enum proto_type protoid, struct
> st_data_s *st_gdata)
> +{
> +    pr_info(" %s(prot:%d) ", __func__,
> protoid);
> +
> +    if (unlikely
> +        (st_gdata == NULL ||
> st_gdata->rx_skb == NULL
> +         ||
> st_gdata->list[protoid] == NULL)) {
> +        pr_err("protocol %d
> not registered, no data to send?",
> +           
>    protoid);
> +       
> kfree_skb(st_gdata->rx_skb);
> +        return;
> +    }
> +    /* this cannot fail
> +     * this shouldn't take long
> +     * - should be just
> skb_queue_tail for the
> +     *   protocol
> stack driver
> +     */
> +    if
> (likely(st_gdata->list[protoid]->recv != NULL)) {
> +        if
> (unlikely(st_gdata->list[protoid]->recv(st_gdata->rx_skb)
> +           
>      != ST_SUCCESS)) {
> +           
> pr_err(" proto stack %d's ->recv failed", protoid);
> +           
> kfree_skb(st_gdata->rx_skb);
> +           
> return;
> +        }
> +    } else {
> +        pr_err(" proto stack
> %d's ->recv null", protoid);
> +       
> kfree_skb(st_gdata->rx_skb);
> +    }
> +    pr_info(" done %s", __func__);
> +    return;
> +}
> +
> +/*
> + * to call registration complete callbacks
> + * of all protocol stack drivers
> + */
> +void st_reg_complete(struct st_data_s *st_gdata, char
> err)
> +{
> +    unsigned char i = 0;
> +    pr_info(" %s ", __func__);
> +    for (i = 0; i < ST_MAX; i++) {
> +        if (likely(st_gdata
> != NULL && st_gdata->list[i] != NULL &&
> +           
>    st_gdata->list[i]->reg_complete_cb
> != NULL))
> +           
> st_gdata->list[i]->reg_complete_cb(err);
> +    }
> +}
> +
> +static inline int st_check_data_len(struct st_data_s
> *st_gdata,
> +    int protoid, int len)
> +{
> +    register int room =
> skb_tailroom(st_gdata->rx_skb);
> +
> +    pr_info("len %d room %d", len, room);
> +
> +    if (!len) {
> +        /* Received packet
> has only packet header and
> +         * has
> zero length payload. So, ask ST CORE to
> +         * forward
> the packet to protocol driver (BT/FM/GPS)
> +         */
> +       
> st_send_frame(protoid, st_gdata);
> +
> +    } else if (len > room) {
> +        /* Received packet's
> payload length is larger.
> +         * We
> can't accommodate it in created skb.
> +         */
> +        pr_err("Data length
> is too large len %d room %d", len,
> +           
>    room);
> +       
> kfree_skb(st_gdata->rx_skb);
> +    } else {
> +        /* Packet header has
> non-zero payload length and
> +         * we have
> enough space in created skb. Lets read
> +         * payload
> data */
> +       
> st_gdata->rx_state = ST_BT_W4_DATA;
> +       
> st_gdata->rx_count = len;
> +        return len;
> +    }
> +
> +    /* Change ST state to continue to
> process next
> +     * packet */
> +    st_gdata->rx_state =
> ST_W4_PACKET_TYPE;
> +    st_gdata->rx_skb = NULL;
> +    st_gdata->rx_count = 0;
> +
> +    return 0;
> +}
> +
> +/* internal function for action when wake-up ack
> + * received
> + */
> +static inline void st_wakeup_ack(struct st_data_s
> *st_gdata,
> +    unsigned char cmd)
> +{
> +    register struct sk_buff *waiting_skb;
> +    unsigned long flags = 0;
> +
> +   
> spin_lock_irqsave(&st_gdata->lock, flags);
> +    /* de-Q from waitQ and Q in txQ now
> that the
> +     * chip is awake
> +     */
> +    while ((waiting_skb =
> skb_dequeue(&st_gdata->tx_waitq)))
> +       
> skb_queue_tail(&st_gdata->txq, waiting_skb);
> +
> +    /* state forwarded to ST LL */
> +    st_ll_sleep_state(st_gdata, (unsigned
> long)cmd);
> +   
> spin_unlock_irqrestore(&st_gdata->lock, flags);
> +
> +    /* wake up to send the recently copied
> skbs from waitQ */
> +    st_tx_wakeup(st_gdata);
> +}
> +
> +/* Decodes received RAW data and forwards to
> corresponding
> + * client drivers (Bluetooth,FM,GPS..etc).
> + *
> + */
> +void st_int_recv(void *disc_data,
> +    const unsigned char *data, long count)
> +{
> +    register char *ptr;
> +    struct hci_event_hdr *eh;
> +    struct hci_acl_hdr *ah;
> +    struct hci_sco_hdr *sh;
> +    struct fm_event_hdr *fm;
> +    struct gps_event_hdr *gps;
> +    register int len = 0, type = 0, dlen =
> 0;
> +    static enum proto_type protoid =
> ST_MAX;
> +    struct st_data_s *st_gdata = (struct
> st_data_s *)disc_data;
> +
> +    ptr = (char *)data;
> +    /* tty_receive sent null ? */
> +    if (unlikely(ptr == NULL) || (st_gdata
> == NULL)) {
> +        pr_err(" received
> null from TTY ");
> +        return;
> +    }
> +
> +    pr_info("count %ld rx_state %ld"
> +       
>    "rx_count %ld", count,
> st_gdata->rx_state,
> +       
>    st_gdata->rx_count);
> +
> +    /* Decode received bytes here */
> +    while (count) {
> +        if
> (st_gdata->rx_count) {
> +           
> len = min_t(unsigned int, st_gdata->rx_count, count);
> +           
> memcpy(skb_put(st_gdata->rx_skb, len), ptr, len);
> +           
> st_gdata->rx_count -= len;
> +           
> count -= len;
> +           
> ptr += len;
> +
> +           
> if (st_gdata->rx_count)
> +           
>     continue;
> +
> +           
> /* Check ST RX state machine , where are we? */
> +           
> switch (st_gdata->rx_state) {
> +
> +           
>     /* Waiting for complete packet ? */
> +           
> case ST_BT_W4_DATA:
> +           
>     pr_info("Complete pkt received");
> +
> +           
>     /* Ask ST CORE to forward
> +           
>      * the packet to protocol
> driver */
> +           
>     st_send_frame(protoid, st_gdata);
> +
> +           
>     st_gdata->rx_state =
> ST_W4_PACKET_TYPE;
> +           
>     st_gdata->rx_skb = NULL;
> +           
>     protoid = ST_MAX;    /* is
> this required ? */
> +           
>     continue;
> +
> +           
>     /* Waiting for Bluetooth event header ?
> */
> +           
> case ST_BT_W4_EVENT_HDR:
> +           
>     eh = (struct hci_event_hdr
> *)st_gdata->rx_skb->
> +           
>         data;
> +
> +           
>     pr_info("Event header: evt 0x%2.2x"
> +           
>        
>    "plen %d", eh->evt, eh->plen);
> +
> +           
>     st_check_data_len(st_gdata, protoid,
> eh->plen);
> +           
>     continue;
> +
> +           
>     /* Waiting for Bluetooth acl header ? */
> +           
> case ST_BT_W4_ACL_HDR:
> +           
>     ah = (struct hci_acl_hdr
> *)st_gdata->rx_skb->
> +           
>         data;
> +           
>     dlen = __le16_to_cpu(ah->dlen);
> +
> +           
>     pr_info("ACL header: dlen %d", dlen);
> +
> +           
>     st_check_data_len(st_gdata, protoid,
> dlen);
> +           
>     continue;
> +
> +           
>     /* Waiting for Bluetooth sco header ? */
> +           
> case ST_BT_W4_SCO_HDR:
> +           
>     sh = (struct hci_sco_hdr
> *)st_gdata->rx_skb->
> +           
>         data;
> +
> +           
>     pr_info("SCO header: dlen %d",
> sh->dlen);
> +
> +           
>     st_check_data_len(st_gdata, protoid,
> sh->dlen);
> +           
>     continue;
> +           
> case ST_FM_W4_EVENT_HDR:
> +           
>     fm = (struct fm_event_hdr
> *)st_gdata->rx_skb->
> +           
>         data;
> +           
>     pr_info("FM Header: ");
> +           
>     st_check_data_len(st_gdata, ST_FM,
> fm->plen);
> +           
>     continue;
> +           
>     /* TODO : Add GPS packet machine logic
> here */
> +           
> case ST_GPS_W4_EVENT_HDR:
> +           
>     /* [0x09 pkt hdr][R/W byte][2 byte len]
> */
> +           
>     gps = (struct gps_event_hdr
> *)st_gdata->rx_skb->
> +           
>          data;
> +           
>     pr_info("GPS Header: ");
> +           
>     st_check_data_len(st_gdata, ST_GPS,
> gps->plen);
> +           
>     continue;
> +           
> }    /* end of switch rx_state */
> +        }
> +
> +        /* end of if
> rx_count */
> +        /* Check first byte
> of packet and identify module
> +         * owner
> (BT/FM/GPS) */
> +        switch (*ptr) {
> +
> +           
> /* Bluetooth event packet? */
> +        case HCI_EVENT_PKT:
> +           
> pr_info("Event packet");
> +           
> st_gdata->rx_state = ST_BT_W4_EVENT_HDR;
> +           
> st_gdata->rx_count = HCI_EVENT_HDR_SIZE;
> +           
> type = HCI_EVENT_PKT;
> +           
> protoid = ST_BT;
> +           
> break;
> +
> +           
> /* Bluetooth acl packet? */
> +        case
> HCI_ACLDATA_PKT:
> +           
> pr_info("ACL packet");
> +           
> st_gdata->rx_state = ST_BT_W4_ACL_HDR;
> +           
> st_gdata->rx_count = HCI_ACL_HDR_SIZE;
> +           
> type = HCI_ACLDATA_PKT;
> +           
> protoid = ST_BT;
> +           
> break;
> +
> +           
> /* Bluetooth sco packet? */
> +        case
> HCI_SCODATA_PKT:
> +           
> pr_info("SCO packet");
> +           
> st_gdata->rx_state = ST_BT_W4_SCO_HDR;
> +           
> st_gdata->rx_count = HCI_SCO_HDR_SIZE;
> +           
> type = HCI_SCODATA_PKT;
> +           
> protoid = ST_BT;
> +           
> break;
> +
> +           
> /* Channel 8(FM) packet? */
> +        case ST_FM_CH8_PKT:
> +           
> pr_info("FM CH8 packet");
> +           
> type = ST_FM_CH8_PKT;
> +           
> st_gdata->rx_state = ST_FM_W4_EVENT_HDR;
> +           
> st_gdata->rx_count = FM_EVENT_HDR_SIZE;
> +           
> protoid = ST_FM;
> +           
> break;
> +
> +           
> /* Channel 9(GPS) packet? */
> +        case
> 0x9:    /*ST_LL_GPS_CH9_PKT */
> +           
> pr_info("GPS CH9 packet");
> +           
> type = 0x9;    /* ST_LL_GPS_CH9_PKT; */
> +           
> protoid = ST_GPS;
> +           
> st_gdata->rx_state = ST_GPS_W4_EVENT_HDR;
> +           
> st_gdata->rx_count = 3;    /*
> GPS_EVENT_HDR_SIZE -1*/
> +           
> break;
> +        case LL_SLEEP_IND:
> +        case LL_SLEEP_ACK:
> +        case
> LL_WAKE_UP_IND:
> +           
> pr_info("PM packet");
> +           
> /* this takes appropriate action based on
> +       
>      * sleep state received --
> +       
>      */
> +           
> st_ll_sleep_state(st_gdata, *ptr);
> +           
> ptr++;
> +           
> count--;
> +           
> continue;
> +        case
> LL_WAKE_UP_ACK:
> +           
> pr_info("PM packet");
> +           
> /* wake up ack received */
> +           
> st_wakeup_ack(st_gdata, *ptr);
> +           
> ptr++;
> +           
> count--;
> +           
> continue;
> +           
> /* Unknow packet? */
> +        default:
> +           
> pr_err("Unknown packet type %2.2x", (__u8) *ptr);
> +           
> ptr++;
> +           
> count--;
> +           
> continue;
> +        };
> +        ptr++;
> +        count--;
> +
> +        switch (protoid) {
> +        case ST_BT:
> +           
> /* Allocate new packet to hold received data */
> +           
> st_gdata->rx_skb =
> +           
>     bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
> +           
> if (!st_gdata->rx_skb) {
> +           
>     pr_err("Can't allocate mem for new
> packet");
> +           
>     st_gdata->rx_state =
> ST_W4_PACKET_TYPE;
> +           
>     st_gdata->rx_count = 0;
> +           
>     return;
> +           
> }
> +           
> bt_cb(st_gdata->rx_skb)->pkt_type = type;
> +           
> break;
> +        case
> ST_FM:    /* for FM */
> +           
> st_gdata->rx_skb =
> +           
>     alloc_skb(FM_MAX_FRAME_SIZE, GFP_ATOMIC);
> +           
> if (!st_gdata->rx_skb) {
> +           
>     pr_err("Can't allocate mem for new
> packet");
> +           
>     st_gdata->rx_state =
> ST_W4_PACKET_TYPE;
> +           
>     st_gdata->rx_count = 0;
> +           
>     return;
> +           
> }
> +           
> /* place holder 0x08 */
> +           
> skb_reserve(st_gdata->rx_skb, 1);
> +           
> st_gdata->rx_skb->cb[0] = ST_FM_CH8_PKT;
> +           
> break;
> +        case ST_GPS:
> +           
> /* for GPS */
> +           
> st_gdata->rx_skb =
> +           
>     alloc_skb(100 /*GPS_MAX_FRAME_SIZE */ ,
> GFP_ATOMIC);
> +           
> if (!st_gdata->rx_skb) {
> +           
>     pr_err("Can't allocate mem for new
> packet");
> +           
>     st_gdata->rx_state =
> ST_W4_PACKET_TYPE;
> +           
>     st_gdata->rx_count = 0;
> +           
>     return;
> +           
> }
> +           
> /* place holder 0x09 */
> +           
> skb_reserve(st_gdata->rx_skb, 1);
> +           
> st_gdata->rx_skb->cb[0] = 0x09;   
> /*ST_GPS_CH9_PKT; */
> +           
> break;
> +        case ST_MAX:
> +           
> break;
> +        }
> +    }
> +    pr_info("done %s", __func__);
> +    return;
> +}
> +
> +/* internal de-Q function
> + * -- return previous in-completely written skb
> + *  or return the skb in the txQ
> + */
> +struct sk_buff *st_int_dequeue(struct st_data_s
> *st_gdata)
> +{
> +    struct sk_buff *returning_skb;
> +
> +    pr_info("%s", __func__);
> +    /* if the previous skb wasn't written
> completely
> +     */
> +    if (st_gdata->tx_skb != NULL) {
> +        returning_skb =
> st_gdata->tx_skb;
> +        st_gdata->tx_skb
> = NULL;
> +        return
> returning_skb;
> +    }
> +
> +    /* de-Q from the txQ always if previous
> write is complete */
> +    return
> skb_dequeue(&st_gdata->txq);
> +}
> +
> +/* internal Q-ing function
> + * will either Q the skb to txq or the tx_waitq
> + * depending on the ST LL state
> + *
> + * lock the whole func - since ll_getstate and Q-ing
> should happen
> + * in one-shot
> + */
> +void st_int_enqueue(struct st_data_s *st_gdata, struct
> sk_buff *skb)
> +{
> +    unsigned long flags = 0;
> +
> +    pr_info("%s", __func__);
> +    /* this function can be invoked in more
> then one context.
> +     * so have a lock */
> +   
> spin_lock_irqsave(&st_gdata->lock, flags);
> +
> +    switch (st_ll_getstate(st_gdata)) {
> +    case ST_LL_AWAKE:
> +        pr_info("ST LL is
> AWAKE, sending normally");
> +       
> skb_queue_tail(&st_gdata->txq, skb);
> +        break;
> +    case ST_LL_ASLEEP_TO_AWAKE:
> +       
> skb_queue_tail(&st_gdata->tx_waitq, skb);
> +        break;
> +    case
> ST_LL_AWAKE_TO_ASLEEP:    /* host cannot be
> in this state */
> +        pr_err("ST LL is
> illegal state(%ld),"
> +           
>    "purging received skb.",
> st_ll_getstate(st_gdata));
> +        kfree_skb(skb);
> +        break;
> +
> +    case ST_LL_ASLEEP:
> +        /* call a function
> of ST LL to put data
> +         * in
> tx_waitQ and wake_ind in txQ
> +         */
> +       
> skb_queue_tail(&st_gdata->tx_waitq, skb);
> +       
> st_ll_wakeup(st_gdata);
> +        break;
> +    default:
> +        pr_err("ST LL is
> illegal state(%ld),"
> +           
>    "purging received skb.",
> st_ll_getstate(st_gdata));
> +        kfree_skb(skb);
> +        break;
> +    }
> +   
> spin_unlock_irqrestore(&st_gdata->lock, flags);
> +    pr_info("done %s", __func__);
> +    return;
> +}
> +
> +/*
> + * internal wakeup function
> + * called from either
> + * - TTY layer when write's finished
> + * - st_write (in context of the protocol stack)
> + */
> +void st_tx_wakeup(struct st_data_s *st_data)
> +{
> +    struct sk_buff *skb;
> +    unsigned long flags;   
> /* for irq save flags */
> +    pr_info("%s", __func__);
> +    /* check for sending & set flag
> sending here */
> +    if (test_and_set_bit(ST_TX_SENDING,
> &st_data->tx_state)) {
> +        pr_info("ST already
> sending");
> +        /* keep sending */
> +       
> set_bit(ST_TX_WAKEUP, &st_data->tx_state);
> +        return;
> +        /* TX_WAKEUP will be
> checked in another
> +         *
> context
> +         */
> +    }
> +    do {   
>         /* come back if
> st_tx_wakeup is set */
> +        /* woke-up to write
> */
> +       
> clear_bit(ST_TX_WAKEUP, &st_data->tx_state);
> +        while ((skb =
> st_int_dequeue(st_data))) {
> +           
> int len;
> +           
> spin_lock_irqsave(&st_data->lock, flags);
> +           
> /* enable wake-up from TTY */
> +           
> set_bit(TTY_DO_WRITE_WAKEUP,
> &st_data->tty->flags);
> +           
> len = st_int_write(st_data, skb->data, skb->len);
> +           
> skb_pull(skb, len);
> +           
> /* if skb->len = len as expected, skb->len=0 */
> +           
> if (skb->len) {
> +           
>     /* would be the next skb to be sent */
> +           
>     st_data->tx_skb = skb;
> +           
>    
> spin_unlock_irqrestore(&st_data->lock, flags);
> +           
>     break;
> +           
> }
> +           
> kfree_skb(skb);
> +           
> spin_unlock_irqrestore(&st_data->lock, flags);
> +        }
> +        /* if wake-up is set
> in another context- restart sending */
> +    } while (test_bit(ST_TX_WAKEUP,
> &st_data->tx_state));
> +
> +    /* clear flag sending */
> +    clear_bit(ST_TX_SENDING,
> &st_data->tx_state);
> +}
> +
> +/********************************************************************/
> +/* functions called from ST KIM
> +*/
> +void kim_st_list_protocols(struct st_data_s *st_gdata,
> char *buf)
> +{
> +    unsigned long flags = 0;
> +#ifdef DEBUG
> +    unsigned char i = ST_MAX;
> +#endif
> +   
> spin_lock_irqsave(&st_gdata->lock, flags);
> +#ifdef DEBUG       
>     /* more detailed log */
> +    for (i = 0; i < ST_MAX; i++) {
> +        if (i == 0) {
> +           
> sprintf(buf, "%s is %s", protocol_strngs[i],
> +           
>     st_gdata->list[i] !=
> +           
>     NULL ? "Registered" : "Unregistered");
> +        } else {
> +           
> sprintf(buf, "%s\n%s is %s", buf, protocol_strngs[i],
> +           
>     st_gdata->list[i] !=
> +           
>     NULL ? "Registered" : "Unregistered");
> +        }
> +    }
> +    sprintf(buf, "%s\n", buf);
> +#else /* limited info */
> +    sprintf(buf, "BT=%c\nFM=%c\nGPS=%c\n",
> +       
> st_gdata->list[ST_BT] != NULL ? 'R' : 'U',
> +       
> st_gdata->list[ST_FM] != NULL ? 'R' : 'U',
> +       
> st_gdata->list[ST_GPS] != NULL ? 'R' : 'U');
> +#endif
> +   
> spin_unlock_irqrestore(&st_gdata->lock, flags);
> +}
> +
> +/********************************************************************/
> +/*
> + * functions called from protocol stack drivers
> + * to be EXPORT-ed
> + */
> +long st_register(struct st_proto_s *new_proto)
> +{
> +    struct st_data_s   
> *st_gdata;
> +    long err = ST_SUCCESS;
> +    unsigned long flags = 0;
> +
> +    st_kim_ref(&st_gdata);
> +    pr_info("%s(%d) ", __func__,
> new_proto->type);
> +    if (st_gdata == NULL || new_proto ==
> NULL || new_proto->recv == NULL
> +        ||
> new_proto->reg_complete_cb == NULL) {
> +       
> pr_err("gdata/new_proto/recv or reg_complete_cb not
> ready");
> +        return
> ST_ERR_FAILURE;
> +    }
> +
> +    if (new_proto->type < ST_BT ||
> new_proto->type >= ST_MAX) {
> +        pr_err("protocol %d
> not supported", new_proto->type);
> +        return
> ST_ERR_NOPROTO;
> +    }
> +
> +    if
> (st_gdata->list[new_proto->type] != NULL) {
> +        pr_err("protocol %d
> already registered", new_proto->type);
> +        return
> ST_ERR_ALREADY;
> +    }
> +
> +    /* can be from process context only */
> +   
> spin_lock_irqsave(&st_gdata->lock, flags);
> +
> +    if (test_bit(ST_REG_IN_PROGRESS,
> &st_gdata->st_state)) {
> +        pr_info("
> ST_REG_IN_PROGRESS:%d ", new_proto->type);
> +        /* fw download in
> progress */
> +       
> st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
> +
> +       
> st_gdata->list[new_proto->type] = new_proto;
> +        new_proto->write
> = st_write;
> +
> +       
> set_bit(ST_REG_PENDING, &st_gdata->st_state);
> +       
> spin_unlock_irqrestore(&st_gdata->lock, flags);
> +        return
> ST_ERR_PENDING;
> +    } else if
> (st_gdata->protos_registered == ST_EMPTY) {
> +        pr_info(" protocol
> list empty :%d ", new_proto->type);
> +       
> set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
> +        st_recv =
> st_kim_recv;
> +
> +        /* release lock
> previously held - re-locked below */
> +       
> spin_unlock_irqrestore(&st_gdata->lock, flags);
> +
> +        /* enable the ST LL
> - to set default chip state */
> +       
> st_ll_enable(st_gdata);
> +        /* this may take a
> while to complete
> +         * since
> it involves BT fw download
> +         */
> +        err =
> st_kim_start();
> +        if (err !=
> ST_SUCCESS) {
> +           
> clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
> +           
> if ((st_gdata->protos_registered != ST_EMPTY) &&
> +           
>     (test_bit(ST_REG_PENDING,
> &st_gdata->st_state))) {
> +           
>     pr_err(" KIM failure complete callback
> ");
> +           
>     st_reg_complete(st_gdata,
> ST_ERR_FAILURE);
> +           
> }
> +
> +           
> return ST_ERR_FAILURE;
> +        }
> +
> +        /* the protocol
> might require other gpios to be toggled
> +         */
> +       
> st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
> +
> +       
> clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
> +        st_recv =
> st_int_recv;
> +
> +        /* this is where all
> pending registration
> +         * are
> signalled to be complete by calling callback functions
> +         */
> +        if
> ((st_gdata->protos_registered != ST_EMPTY) &&
> +           
> (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
> +           
> pr_info(" call reg complete callback ");
> +           
> st_gdata->protos_registered++;
> +           
> st_reg_complete(st_gdata, ST_SUCCESS);
> +        }
> +       
> clear_bit(ST_REG_PENDING, &st_gdata->st_state);
> +
> +        /* check for already
> registered once more,
> +         * since
> the above check is old
> +         */
> +        if
> (st_gdata->list[new_proto->type] != NULL) {
> +           
> pr_err(" proto %d already registered ",
> +           
>        new_proto->type);
> +           
> return ST_ERR_ALREADY;
> +        }
> +
> +       
> spin_lock_irqsave(&st_gdata->lock, flags);
> +       
> st_gdata->list[new_proto->type] = new_proto;
> +        new_proto->write
> = st_write;
> +       
> spin_unlock_irqrestore(&st_gdata->lock, flags);
> +        return err;
> +    }
> +    /* if fw is already downloaded &
> new stack registers protocol */
> +    else {
> +        switch
> (new_proto->type) {
> +        case ST_BT:
> +           
> /* do nothing */
> +           
> break;
> +        case ST_FM:
> +        case ST_GPS:
> +           
> st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
> +           
> break;
> +        case ST_MAX:
> +        default:
> +           
> pr_err("%d protocol not supported",
> +           
>        new_proto->type);
> +           
> err = ST_ERR_NOPROTO;
> +           
> /* something wrong */
> +           
> break;
> +        }
> +       
> st_gdata->list[new_proto->type] = new_proto;
> +        new_proto->write
> = st_write;
> +
> +        /* lock already held
> before entering else */
> +       
> spin_unlock_irqrestore(&st_gdata->lock, flags);
> +        return err;
> +    }
> +    pr_info("done %s(%d) ", __func__,
> new_proto->type);
> +}
> +EXPORT_SYMBOL_GPL(st_register);
> +
> +/* to unregister a protocol -
> + * to be called from protocol stack driver
> + */
> +long st_unregister(enum proto_type type)
> +{
> +    long err = ST_SUCCESS;
> +    unsigned long flags = 0;
> +    struct st_data_s   
> *st_gdata;
> +
> +    pr_info("%s: %d ", __func__, type);
> +
> +    st_kim_ref(&st_gdata);
> +    if (type < ST_BT || type >=
> ST_MAX) {
> +        pr_err(" protocol %d
> not supported", type);
> +        return
> ST_ERR_NOPROTO;
> +    }
> +
> +   
> spin_lock_irqsave(&st_gdata->lock, flags);
> +
> +    if (st_gdata->list[type] == NULL) {
> +        pr_err(" protocol %d
> not registered", type);
> +       
> spin_unlock_irqrestore(&st_gdata->lock, flags);
> +        return
> ST_ERR_NOPROTO;
> +    }
> +
> +    st_gdata->protos_registered--;
> +    st_gdata->list[type] = NULL;
> +
> +    /* kim ignores BT in the below
> function
> +     * and handles the rest, BT
> is toggled
> +     * only in kim_start and
> kim_stop
> +     */
> +    st_kim_chip_toggle(type,
> KIM_GPIO_INACTIVE);
> +   
> spin_unlock_irqrestore(&st_gdata->lock, flags);
> +
> +    if ((st_gdata->protos_registered ==
> ST_EMPTY) &&
> +       
> (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
> +        pr_info(" all
> protocols unregistered ");
> +
> +        /* stop traffic on
> tty */
> +        if
> (st_gdata->tty) {
> +           
> tty_ldisc_flush(st_gdata->tty);
> +           
> stop_tty(st_gdata->tty);
> +        }
> +
> +        /* all protocols now
> unregistered */
> +        st_kim_stop();
> +        /* disable ST LL */
> +       
> st_ll_disable(st_gdata);
> +    }
> +    return err;
> +}
> +
> +/*
> + * called in protocol stack drivers
> + * via the write function pointer
> + */
> +long st_write(struct sk_buff *skb)
> +{
> +    struct st_data_s *st_gdata;
> +#ifdef DEBUG
> +    enum proto_type protoid = ST_MAX;
> +#endif
> +    long len;
> +
> +    st_kim_ref(&st_gdata);
> +    if (unlikely(skb == NULL || st_gdata ==
> NULL
> +        || st_gdata->tty
> == NULL)) {
> +        pr_err("data/tty
> unavailable to perform write");
> +        return
> ST_ERR_FAILURE;
> +    }
> +#ifdef DEBUG       
>     /* open-up skb to read the 1st byte */
> +    switch (skb->data[0]) {
> +    case HCI_COMMAND_PKT:
> +    case HCI_ACLDATA_PKT:
> +    case HCI_SCODATA_PKT:
> +        protoid = ST_BT;
> +        break;
> +    case ST_FM_CH8_PKT:
> +        protoid = ST_FM;
> +        break;
> +    case 0x09:
> +        protoid = ST_GPS;
> +        break;
> +    }
> +    if (unlikely(st_gdata->list[protoid]
> == NULL)) {
> +        pr_err(" protocol %d
> not registered, and writing? ",
> +           
>    protoid);
> +        return
> ST_ERR_FAILURE;
> +    }
> +#endif
> +    pr_info("%d to be written",
> skb->len);
> +    len = skb->len;
> +
> +    /* st_ll to decide where to enqueue the
> skb */
> +    st_int_enqueue(st_gdata, skb);
> +    /* wake up */
> +    st_tx_wakeup(st_gdata);
> +
> +    /* return number of bytes written */
> +    return len;
> +}
> +
> +/* for protocols making use of shared transport */
> +EXPORT_SYMBOL_GPL(st_unregister);
> +
> +/********************************************************************/
> +/*
> + * functions called from TTY layer
> + */
> +static int st_tty_open(struct tty_struct *tty)
> +{
> +    int err = ST_SUCCESS;
> +    struct st_data_s *st_gdata;
> +    pr_info("%s ", __func__);
> +
> +    st_kim_ref(&st_gdata);
> +    st_gdata->tty = tty;
> +    tty->disc_data = st_gdata;
> +
> +    /* don't do an wakeup for now */
> +    clear_bit(TTY_DO_WRITE_WAKEUP,
> &tty->flags);
> +
> +    /* mem already allocated
> +     */
> +    tty->receive_room = 65536;
> +    /* Flush any pending characters in the
> driver and discipline. */
> +    tty_ldisc_flush(tty);
> +    tty_driver_flush_buffer(tty);
> +    /*
> +     * signal to UIM via KIM that
> -
> +     * installation of N_TI_WL
> ldisc is complete
> +     */
> +    st_kim_complete();
> +    pr_info("done %s", __func__);
> +    return err;
> +}
> +
> +static void st_tty_close(struct tty_struct *tty)
> +{
> +    unsigned char i = ST_MAX;
> +    unsigned long flags = 0;
> +    struct    st_data_s
> *st_gdata = tty->disc_data;
> +
> +    pr_info("%s ", __func__);
> +
> +    /* TODO:
> +     * if a protocol has been
> registered & line discipline
> +     * un-installed for some
> reason - what should be done ?
> +     */
> +   
> spin_lock_irqsave(&st_gdata->lock, flags);
> +    for (i = ST_BT; i < ST_MAX; i++) {
> +        if
> (st_gdata->list[i] != NULL)
> +           
> pr_err("%d not un-registered", i);
> +        st_gdata->list[i]
> = NULL;
> +    }
> +   
> spin_unlock_irqrestore(&st_gdata->lock, flags);
> +    /*
> +     * signal to UIM via KIM that
> -
> +     * N_TI_WL ldisc is
> un-installed
> +     */
> +    st_kim_complete();
> +    st_gdata->tty = NULL;
> +    /* Flush any pending characters in the
> driver and discipline. */
> +    tty_ldisc_flush(tty);
> +    tty_driver_flush_buffer(tty);
> +
> +   
> spin_lock_irqsave(&st_gdata->lock, flags);
> +    /* empty out txq and tx_waitq */
> +   
> skb_queue_purge(&st_gdata->txq);
> +   
> skb_queue_purge(&st_gdata->tx_waitq);
> +    /* reset the TTY Rx states of ST */
> +    st_gdata->rx_count = 0;
> +    st_gdata->rx_state =
> ST_W4_PACKET_TYPE;
> +    kfree_skb(st_gdata->rx_skb);
> +    st_gdata->rx_skb = NULL;
> +   
> spin_unlock_irqrestore(&st_gdata->lock, flags);
> +
> +    pr_info("%s: done ", __func__);
> +}
> +
> +static void st_tty_receive(struct tty_struct *tty, const
> unsigned char *data,
> +           
>    char *tty_flags, int count)
> +{
> +
> +#ifdef VERBOSE
> +    long i;
> +    printk(KERN_ERR "incoming data...\n");
> +    for (i = 0; i < count; i++)
> +        printk(" %x",
> data[i]);
> +    printk(KERN_ERR "\n.. data end\n");
> +#endif
> +
> +    /*
> +     * if fw download is in
> progress then route incoming data
> +     * to KIM for validation
> +     */
> +    st_recv(tty->disc_data, data,
> count);
> +    pr_info("done %s", __func__);
> +}
> +
> +/* wake-up function called in from the TTY layer
> + * inside the internal wakeup function will be called
> + */
> +static void st_tty_wakeup(struct tty_struct *tty)
> +{
> +    struct    st_data_s
> *st_gdata = tty->disc_data;
> +    pr_info("%s ", __func__);
> +    /* don't do an wakeup for now */
> +    clear_bit(TTY_DO_WRITE_WAKEUP,
> &tty->flags);
> +
> +    /* call our internal wakeup */
> +    st_tx_wakeup((void *)st_gdata);
> +}
> +
> +static void st_tty_flush_buffer(struct tty_struct *tty)
> +{
> +    struct    st_data_s
> *st_gdata = tty->disc_data;
> +    pr_info("%s ", __func__);
> +
> +    kfree_skb(st_gdata->tx_skb);
> +    st_gdata->tx_skb = NULL;
> +
> +    tty->ops->flush_buffer(tty);
> +    return;
> +}
> +
> +/********************************************************************/
> +int st_core_init(struct st_data_s **core_data)
> +{
> +    struct st_data_s *st_gdata;
> +    long err;
> +    static struct tty_ldisc_ops
> *st_ldisc_ops;
> +
> +    /* populate and register to TTY line
> discipline */
> +    st_ldisc_ops =
> kzalloc(sizeof(*st_ldisc_ops), GFP_KERNEL);
> +    if (!st_ldisc_ops) {
> +        pr_err("no mem to
> allocate");
> +        return -ENOMEM;
> +    }
> +
> +    st_ldisc_ops->magic =
> TTY_LDISC_MAGIC;
> +    st_ldisc_ops->name =
> "n_st";    /*"n_hci"; */
> +    st_ldisc_ops->open = st_tty_open;
> +    st_ldisc_ops->close = st_tty_close;
> +    st_ldisc_ops->receive_buf =
> st_tty_receive;
> +    st_ldisc_ops->write_wakeup =
> st_tty_wakeup;
> +    st_ldisc_ops->flush_buffer =
> st_tty_flush_buffer;
> +    st_ldisc_ops->owner = THIS_MODULE;
> +
> +    err = tty_register_ldisc(N_TI_WL,
> st_ldisc_ops);
> +    if (err) {
> +        pr_err("error
> registering %d line discipline %ld",
> +           
>    N_TI_WL, err);
> +       
> kfree(st_ldisc_ops);
> +        return err;
> +    }
> +    pr_info("registered n_shared line
> discipline");
> +
> +    st_gdata = kzalloc(sizeof(struct
> st_data_s), GFP_KERNEL);
> +    if (!st_gdata) {
> +        pr_err("memory
> allocation failed");
> +        err =
> tty_unregister_ldisc(N_TI_WL);
> +        if (err)
> +           
> pr_err("unable to un-register ldisc %ld", err);
> +       
> kfree(st_ldisc_ops);
> +        err = -ENOMEM;
> +        return err;
> +    }
> +
> +    /* Initialize ST TxQ and Tx waitQ queue
> head. All BT/FM/GPS module skb's
> +     * will be pushed in this
> queue for actual transmission.
> +     */
> +   
> skb_queue_head_init(&st_gdata->txq);
> +   
> skb_queue_head_init(&st_gdata->tx_waitq);
> +
> +    /* Locking used in st_int_enqueue() to
> avoid multiple execution */
> +   
> spin_lock_init(&st_gdata->lock);
> +
> +    /* ldisc_ops ref to be only used in
> __exit of module */
> +    st_gdata->ldisc_ops = st_ldisc_ops;
> +
> +#if 0
> +    err = st_kim_init();
> +    if (err) {
> +        pr_err("error during
> kim initialization(%ld)", err);
> +        kfree(st_gdata);
> +        err =
> tty_unregister_ldisc(N_TI_WL);
> +        if (err)
> +           
> pr_err("unable to un-register ldisc");
> +       
> kfree(st_ldisc_ops);
> +        return -1;
> +    }
> +#endif
> +
> +    err = st_ll_init(st_gdata);
> +    if (err) {
> +        pr_err("error during
> st_ll initialization(%ld)", err);
> +        kfree(st_gdata);
> +        err =
> tty_unregister_ldisc(N_TI_WL);
> +        if (err)
> +           
> pr_err("unable to un-register ldisc");
> +       
> kfree(st_ldisc_ops);
> +        return -1;
> +    }
> +    *core_data = st_gdata;
> +    return 0;
> +}
> +
> +void st_core_exit(struct st_data_s *st_gdata)
> +{
> +    long err;
> +    /* internal module cleanup */
> +    err = st_ll_deinit(st_gdata);
> +    if (err)
> +        pr_err("error during
> deinit of ST LL %ld", err);
> +#if 0
> +    err = st_kim_deinit();
> +    if (err)
> +        pr_err("error during
> deinit of ST KIM %ld", err);
> +#endif
> +    if (st_gdata != NULL) {
> +        /* Free ST Tx Qs and
> skbs */
> +       
> skb_queue_purge(&st_gdata->txq);
> +       
> skb_queue_purge(&st_gdata->tx_waitq);
> +       
> kfree_skb(st_gdata->rx_skb);
> +       
> kfree_skb(st_gdata->tx_skb);
> +        /* TTY ldisc cleanup
> */
> +        err =
> tty_unregister_ldisc(N_TI_WL);
> +        if (err)
> +           
> pr_err("unable to un-register ldisc %ld", err);
> +       
> kfree(st_gdata->ldisc_ops);
> +        /* free the global
> data pointer */
> +        kfree(st_gdata);
> +    }
> +}
> +
> +
> diff --git a/drivers/staging/ti-st/st_core.h
> b/drivers/staging/ti-st/st_core.h
> new file mode 100644
> index 0000000..f271c88
> --- /dev/null
> +++ b/drivers/staging/ti-st/st_core.h
> @@ -0,0 +1,98 @@
> +/*
> + *  Shared Transport Core header file
> + *
> + *  Copyright (C) 2009 Texas Instruments
> + *
> + *  This program is free software; you can
> redistribute it and/or modify
> + *  it under the terms of the GNU General Public
> License version 2 as
> + *  published by the Free Software Foundation.
> + *
> + *  This program is distributed in the hope that it
> will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the
> implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR
> PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU
> General Public License
> + *  along with this program; if not, write to the
> Free Software
> + *  Foundation, Inc., 59 Temple Place, Suite 330,
> Boston, MA  02111-1307  USA
> + *
> + */
> +
> +#ifndef ST_CORE_H
> +#define ST_CORE_H
> +
> +#include <linux/skbuff.h>
> +#include "st.h"
> +
> +/* states of protocol list */
> +#define ST_NOTEMPTY    1
> +#define ST_EMPTY    0
> +
> +/*
> + * possible st_states
> + */
> +#define ST_INITIALIZING   
>     1
> +#define ST_REG_IN_PROGRESS    2
> +#define ST_REG_PENDING   
>     3
> +#define ST_WAITING_FOR_RESP    4
> +
> +/*
> + * local data required for ST/KIM/ST-HCI-LL
> + */
> +struct st_data_s {
> +    unsigned long st_state;
> +/*
> + * an instance of tty_struct & ldisc ops to move
> around
> + */
> +    struct tty_struct *tty;
> +    struct tty_ldisc_ops *ldisc_ops;
> +/*
> + * the tx skb -
> + * if the skb is already dequeued and the tty failed to
> write the same
> + * maintain the skb to write in the next transaction
> + */
> +    struct sk_buff *tx_skb;
> +#define ST_TX_SENDING    1
> +#define ST_TX_WAKEUP    2
> +    unsigned long tx_state;
> +/*
> + * list of protocol registered
> + */
> +    struct st_proto_s *list[ST_MAX];
> +/*
> + * lock
> + */
> +    unsigned long rx_state;
> +    unsigned long rx_count;
> +    struct sk_buff *rx_skb;
> +    struct sk_buff_head txq, tx_waitq;
> +    spinlock_t lock;    /*
> ST LL state lock  */
> +    unsigned char   
> protos_registered;
> +    unsigned long
> ll_state;    /* ST LL power state */
> +};
> +
> +/* point this to tty->driver->write or
> tty->ops->write
> + * depending upon the kernel version
> + */
> +int st_int_write(struct st_data_s*, const unsigned char*,
> int);
> +/* internal write function, passed onto protocol drivers
> + * via the write function ptr of protocol struct
> + */
> +long st_write(struct sk_buff *);
> +/* function to be called from ST-LL
> + */
> +void st_ll_send_frame(enum proto_type, struct sk_buff *);
> +/* internal wake up function */
> +void st_tx_wakeup(struct st_data_s *st_data);
> +
> +int st_core_init(struct st_data_s **);
> +void st_core_exit(struct st_data_s *);
> +void st_kim_ref(struct st_data_s **);
> +
> +#define GPS_STUB_TEST
> +#ifdef GPS_STUB_TEST
> +int gps_chrdrv_stub_write(const unsigned char*, int);
> +void gps_chrdrv_stub_init(void);
> +#endif
> +
> +#endif /*ST_CORE_H */
> -- 
> 1.5.4.3
> 
> 

Any comments on these patches ?


      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH] drivers:staging: sources for ST core
  2010-04-08 18:16 ` [PATCH] serial: TTY: new ldiscs for staging pavan_savoy
@ 2010-04-08 18:16   ` pavan_savoy
  2010-04-13 15:06     ` Pavan Savoy
  2010-04-26 22:03     ` Alan Cox
  0 siblings, 2 replies; 27+ messages in thread
From: pavan_savoy @ 2010-04-08 18:16 UTC (permalink / raw)
  To: gregkh, alan; +Cc: linux-kernel, npelly, pavan_savoy, Pavan Savoy

From: Pavan Savoy <pavan_savoy@ti.com>

Texas Instruments BT, FM and GPS combo chips/drivers
make use of a single TTY to communicate with the chip.
This module constitutes the core logic, TTY ldisc driver
and the exported symbols for registering/unregistering of
the protocol drivers such as BT/FM/GPS.

Signed-off-by: Pavan Savoy <pavan_savoy@ti.com>
---
 drivers/staging/ti-st/st_core.c | 1062 +++++++++++++++++++++++++++++++++++++++
 drivers/staging/ti-st/st_core.h |   98 ++++
 2 files changed, 1160 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/ti-st/st_core.c
 create mode 100644 drivers/staging/ti-st/st_core.h

diff --git a/drivers/staging/ti-st/st_core.c b/drivers/staging/ti-st/st_core.c
new file mode 100644
index 0000000..4e93694
--- /dev/null
+++ b/drivers/staging/ti-st/st_core.c
@@ -0,0 +1,1062 @@
+/*
+ *  Shared Transport Line discipline driver Core
+ *	This hooks up ST KIM driver and ST LL driver
+ *  Copyright (C) 2009 Texas Instruments
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#define pr_fmt(fmt)	"(stc): " fmt
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/tty.h>
+
+/* understand BT, FM and GPS for now */
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+#include <net/bluetooth/hci.h>
+#include "fm.h"
+/*
+ * packet formats for fm and gps
+ * #include "gps.h"
+ */
+#include "st_core.h"
+#include "st_kim.h"
+#include "st_ll.h"
+#include "st.h"
+
+#ifdef DEBUG
+/* strings to be used for rfkill entries and by
+ * ST Core to be used for sysfs debug entry
+ */
+#define PROTO_ENTRY(type, name)	name
+const unsigned char *protocol_strngs[] = {
+	PROTO_ENTRY(ST_BT, "Bluetooth"),
+	PROTO_ENTRY(ST_FM, "FM"),
+	PROTO_ENTRY(ST_GPS, "GPS"),
+};
+#endif
+/* function pointer pointing to either,
+ * st_kim_recv during registration to receive fw download responses
+ * st_int_recv after registration to receive proto stack responses
+ */
+void (*st_recv) (void*, const unsigned char*, long);
+
+/********************************************************************/
+#if 0
+/* internal misc functions */
+bool is_protocol_list_empty(void)
+{
+	unsigned char i = 0;
+	pr_info(" %s ", __func__);
+	for (i = 0; i < ST_MAX; i++) {
+		if (st_gdata->list[i] != NULL)
+			return ST_NOTEMPTY;
+		/* not empty */
+	}
+	/* list empty */
+	return ST_EMPTY;
+}
+#endif
+/* can be called in from
+ * -- KIM (during fw download)
+ * -- ST Core (during st_write)
+ *
+ *  This is the internal write function - a wrapper
+ *  to tty->ops->write
+ */
+int st_int_write(struct st_data_s *st_gdata,
+	const unsigned char *data, int count)
+{
+#ifdef VERBOSE			/* for debug */
+	int i;
+#endif
+	struct tty_struct *tty;
+	if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
+		pr_err("tty unavailable to perform write");
+		return ST_ERR_FAILURE;
+	}
+	tty = st_gdata->tty;
+#ifdef VERBOSE
+	printk(KERN_ERR "start data..\n");
+	for (i = 0; i < count; i++)	/* no newlines for each datum */
+		printk(" %x", data[i]);
+	printk(KERN_ERR "\n ..end data\n");
+#endif
+	return tty->ops->write(tty, data, count);
+
+}
+
+/*
+ * push the skb received to relevant
+ * protocol stacks
+ */
+void st_send_frame(enum proto_type protoid, struct st_data_s *st_gdata)
+{
+	pr_info(" %s(prot:%d) ", __func__, protoid);
+
+	if (unlikely
+	    (st_gdata == NULL || st_gdata->rx_skb == NULL
+	     || st_gdata->list[protoid] == NULL)) {
+		pr_err("protocol %d not registered, no data to send?",
+			   protoid);
+		kfree_skb(st_gdata->rx_skb);
+		return;
+	}
+	/* this cannot fail
+	 * this shouldn't take long
+	 * - should be just skb_queue_tail for the
+	 *   protocol stack driver
+	 */
+	if (likely(st_gdata->list[protoid]->recv != NULL)) {
+		if (unlikely(st_gdata->list[protoid]->recv(st_gdata->rx_skb)
+			     != ST_SUCCESS)) {
+			pr_err(" proto stack %d's ->recv failed", protoid);
+			kfree_skb(st_gdata->rx_skb);
+			return;
+		}
+	} else {
+		pr_err(" proto stack %d's ->recv null", protoid);
+		kfree_skb(st_gdata->rx_skb);
+	}
+	pr_info(" done %s", __func__);
+	return;
+}
+
+/*
+ * to call registration complete callbacks
+ * of all protocol stack drivers
+ */
+void st_reg_complete(struct st_data_s *st_gdata, char err)
+{
+	unsigned char i = 0;
+	pr_info(" %s ", __func__);
+	for (i = 0; i < ST_MAX; i++) {
+		if (likely(st_gdata != NULL && st_gdata->list[i] != NULL &&
+			   st_gdata->list[i]->reg_complete_cb != NULL))
+			st_gdata->list[i]->reg_complete_cb(err);
+	}
+}
+
+static inline int st_check_data_len(struct st_data_s *st_gdata,
+	int protoid, int len)
+{
+	register int room = skb_tailroom(st_gdata->rx_skb);
+
+	pr_info("len %d room %d", len, room);
+
+	if (!len) {
+		/* Received packet has only packet header and
+		 * has zero length payload. So, ask ST CORE to
+		 * forward the packet to protocol driver (BT/FM/GPS)
+		 */
+		st_send_frame(protoid, st_gdata);
+
+	} else if (len > room) {
+		/* Received packet's payload length is larger.
+		 * We can't accommodate it in created skb.
+		 */
+		pr_err("Data length is too large len %d room %d", len,
+			   room);
+		kfree_skb(st_gdata->rx_skb);
+	} else {
+		/* Packet header has non-zero payload length and
+		 * we have enough space in created skb. Lets read
+		 * payload data */
+		st_gdata->rx_state = ST_BT_W4_DATA;
+		st_gdata->rx_count = len;
+		return len;
+	}
+
+	/* Change ST state to continue to process next
+	 * packet */
+	st_gdata->rx_state = ST_W4_PACKET_TYPE;
+	st_gdata->rx_skb = NULL;
+	st_gdata->rx_count = 0;
+
+	return 0;
+}
+
+/* internal function for action when wake-up ack
+ * received
+ */
+static inline void st_wakeup_ack(struct st_data_s *st_gdata,
+	unsigned char cmd)
+{
+	register struct sk_buff *waiting_skb;
+	unsigned long flags = 0;
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	/* de-Q from waitQ and Q in txQ now that the
+	 * chip is awake
+	 */
+	while ((waiting_skb = skb_dequeue(&st_gdata->tx_waitq)))
+		skb_queue_tail(&st_gdata->txq, waiting_skb);
+
+	/* state forwarded to ST LL */
+	st_ll_sleep_state(st_gdata, (unsigned long)cmd);
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	/* wake up to send the recently copied skbs from waitQ */
+	st_tx_wakeup(st_gdata);
+}
+
+/* Decodes received RAW data and forwards to corresponding
+ * client drivers (Bluetooth,FM,GPS..etc).
+ *
+ */
+void st_int_recv(void *disc_data,
+	const unsigned char *data, long count)
+{
+	register char *ptr;
+	struct hci_event_hdr *eh;
+	struct hci_acl_hdr *ah;
+	struct hci_sco_hdr *sh;
+	struct fm_event_hdr *fm;
+	struct gps_event_hdr *gps;
+	register int len = 0, type = 0, dlen = 0;
+	static enum proto_type protoid = ST_MAX;
+	struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
+
+	ptr = (char *)data;
+	/* tty_receive sent null ? */
+	if (unlikely(ptr == NULL) || (st_gdata == NULL)) {
+		pr_err(" received null from TTY ");
+		return;
+	}
+
+	pr_info("count %ld rx_state %ld"
+		   "rx_count %ld", count, st_gdata->rx_state,
+		   st_gdata->rx_count);
+
+	/* Decode received bytes here */
+	while (count) {
+		if (st_gdata->rx_count) {
+			len = min_t(unsigned int, st_gdata->rx_count, count);
+			memcpy(skb_put(st_gdata->rx_skb, len), ptr, len);
+			st_gdata->rx_count -= len;
+			count -= len;
+			ptr += len;
+
+			if (st_gdata->rx_count)
+				continue;
+
+			/* Check ST RX state machine , where are we? */
+			switch (st_gdata->rx_state) {
+
+				/* Waiting for complete packet ? */
+			case ST_BT_W4_DATA:
+				pr_info("Complete pkt received");
+
+				/* Ask ST CORE to forward
+				 * the packet to protocol driver */
+				st_send_frame(protoid, st_gdata);
+
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_skb = NULL;
+				protoid = ST_MAX;	/* is this required ? */
+				continue;
+
+				/* Waiting for Bluetooth event header ? */
+			case ST_BT_W4_EVENT_HDR:
+				eh = (struct hci_event_hdr *)st_gdata->rx_skb->
+				    data;
+
+				pr_info("Event header: evt 0x%2.2x"
+					   "plen %d", eh->evt, eh->plen);
+
+				st_check_data_len(st_gdata, protoid, eh->plen);
+				continue;
+
+				/* Waiting for Bluetooth acl header ? */
+			case ST_BT_W4_ACL_HDR:
+				ah = (struct hci_acl_hdr *)st_gdata->rx_skb->
+				    data;
+				dlen = __le16_to_cpu(ah->dlen);
+
+				pr_info("ACL header: dlen %d", dlen);
+
+				st_check_data_len(st_gdata, protoid, dlen);
+				continue;
+
+				/* Waiting for Bluetooth sco header ? */
+			case ST_BT_W4_SCO_HDR:
+				sh = (struct hci_sco_hdr *)st_gdata->rx_skb->
+				    data;
+
+				pr_info("SCO header: dlen %d", sh->dlen);
+
+				st_check_data_len(st_gdata, protoid, sh->dlen);
+				continue;
+			case ST_FM_W4_EVENT_HDR:
+				fm = (struct fm_event_hdr *)st_gdata->rx_skb->
+				    data;
+				pr_info("FM Header: ");
+				st_check_data_len(st_gdata, ST_FM, fm->plen);
+				continue;
+				/* TODO : Add GPS packet machine logic here */
+			case ST_GPS_W4_EVENT_HDR:
+				/* [0x09 pkt hdr][R/W byte][2 byte len] */
+				gps = (struct gps_event_hdr *)st_gdata->rx_skb->
+				     data;
+				pr_info("GPS Header: ");
+				st_check_data_len(st_gdata, ST_GPS, gps->plen);
+				continue;
+			}	/* end of switch rx_state */
+		}
+
+		/* end of if rx_count */
+		/* Check first byte of packet and identify module
+		 * owner (BT/FM/GPS) */
+		switch (*ptr) {
+
+			/* Bluetooth event packet? */
+		case HCI_EVENT_PKT:
+			pr_info("Event packet");
+			st_gdata->rx_state = ST_BT_W4_EVENT_HDR;
+			st_gdata->rx_count = HCI_EVENT_HDR_SIZE;
+			type = HCI_EVENT_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Bluetooth acl packet? */
+		case HCI_ACLDATA_PKT:
+			pr_info("ACL packet");
+			st_gdata->rx_state = ST_BT_W4_ACL_HDR;
+			st_gdata->rx_count = HCI_ACL_HDR_SIZE;
+			type = HCI_ACLDATA_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Bluetooth sco packet? */
+		case HCI_SCODATA_PKT:
+			pr_info("SCO packet");
+			st_gdata->rx_state = ST_BT_W4_SCO_HDR;
+			st_gdata->rx_count = HCI_SCO_HDR_SIZE;
+			type = HCI_SCODATA_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Channel 8(FM) packet? */
+		case ST_FM_CH8_PKT:
+			pr_info("FM CH8 packet");
+			type = ST_FM_CH8_PKT;
+			st_gdata->rx_state = ST_FM_W4_EVENT_HDR;
+			st_gdata->rx_count = FM_EVENT_HDR_SIZE;
+			protoid = ST_FM;
+			break;
+
+			/* Channel 9(GPS) packet? */
+		case 0x9:	/*ST_LL_GPS_CH9_PKT */
+			pr_info("GPS CH9 packet");
+			type = 0x9;	/* ST_LL_GPS_CH9_PKT; */
+			protoid = ST_GPS;
+			st_gdata->rx_state = ST_GPS_W4_EVENT_HDR;
+			st_gdata->rx_count = 3;	/* GPS_EVENT_HDR_SIZE -1*/
+			break;
+		case LL_SLEEP_IND:
+		case LL_SLEEP_ACK:
+		case LL_WAKE_UP_IND:
+			pr_info("PM packet");
+			/* this takes appropriate action based on
+			 * sleep state received --
+			 */
+			st_ll_sleep_state(st_gdata, *ptr);
+			ptr++;
+			count--;
+			continue;
+		case LL_WAKE_UP_ACK:
+			pr_info("PM packet");
+			/* wake up ack received */
+			st_wakeup_ack(st_gdata, *ptr);
+			ptr++;
+			count--;
+			continue;
+			/* Unknow packet? */
+		default:
+			pr_err("Unknown packet type %2.2x", (__u8) *ptr);
+			ptr++;
+			count--;
+			continue;
+		};
+		ptr++;
+		count--;
+
+		switch (protoid) {
+		case ST_BT:
+			/* Allocate new packet to hold received data */
+			st_gdata->rx_skb =
+			    bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				pr_err("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			bt_cb(st_gdata->rx_skb)->pkt_type = type;
+			break;
+		case ST_FM:	/* for FM */
+			st_gdata->rx_skb =
+			    alloc_skb(FM_MAX_FRAME_SIZE, GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				pr_err("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			/* place holder 0x08 */
+			skb_reserve(st_gdata->rx_skb, 1);
+			st_gdata->rx_skb->cb[0] = ST_FM_CH8_PKT;
+			break;
+		case ST_GPS:
+			/* for GPS */
+			st_gdata->rx_skb =
+			    alloc_skb(100 /*GPS_MAX_FRAME_SIZE */ , GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				pr_err("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			/* place holder 0x09 */
+			skb_reserve(st_gdata->rx_skb, 1);
+			st_gdata->rx_skb->cb[0] = 0x09;	/*ST_GPS_CH9_PKT; */
+			break;
+		case ST_MAX:
+			break;
+		}
+	}
+	pr_info("done %s", __func__);
+	return;
+}
+
+/* internal de-Q function
+ * -- return previous in-completely written skb
+ *  or return the skb in the txQ
+ */
+struct sk_buff *st_int_dequeue(struct st_data_s *st_gdata)
+{
+	struct sk_buff *returning_skb;
+
+	pr_info("%s", __func__);
+	/* if the previous skb wasn't written completely
+	 */
+	if (st_gdata->tx_skb != NULL) {
+		returning_skb = st_gdata->tx_skb;
+		st_gdata->tx_skb = NULL;
+		return returning_skb;
+	}
+
+	/* de-Q from the txQ always if previous write is complete */
+	return skb_dequeue(&st_gdata->txq);
+}
+
+/* internal Q-ing function
+ * will either Q the skb to txq or the tx_waitq
+ * depending on the ST LL state
+ *
+ * lock the whole func - since ll_getstate and Q-ing should happen
+ * in one-shot
+ */
+void st_int_enqueue(struct st_data_s *st_gdata, struct sk_buff *skb)
+{
+	unsigned long flags = 0;
+
+	pr_info("%s", __func__);
+	/* this function can be invoked in more then one context.
+	 * so have a lock */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	switch (st_ll_getstate(st_gdata)) {
+	case ST_LL_AWAKE:
+		pr_info("ST LL is AWAKE, sending normally");
+		skb_queue_tail(&st_gdata->txq, skb);
+		break;
+	case ST_LL_ASLEEP_TO_AWAKE:
+		skb_queue_tail(&st_gdata->tx_waitq, skb);
+		break;
+	case ST_LL_AWAKE_TO_ASLEEP:	/* host cannot be in this state */
+		pr_err("ST LL is illegal state(%ld),"
+			   "purging received skb.", st_ll_getstate(st_gdata));
+		kfree_skb(skb);
+		break;
+
+	case ST_LL_ASLEEP:
+		/* call a function of ST LL to put data
+		 * in tx_waitQ and wake_ind in txQ
+		 */
+		skb_queue_tail(&st_gdata->tx_waitq, skb);
+		st_ll_wakeup(st_gdata);
+		break;
+	default:
+		pr_err("ST LL is illegal state(%ld),"
+			   "purging received skb.", st_ll_getstate(st_gdata));
+		kfree_skb(skb);
+		break;
+	}
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+	pr_info("done %s", __func__);
+	return;
+}
+
+/*
+ * internal wakeup function
+ * called from either
+ * - TTY layer when write's finished
+ * - st_write (in context of the protocol stack)
+ */
+void st_tx_wakeup(struct st_data_s *st_data)
+{
+	struct sk_buff *skb;
+	unsigned long flags;	/* for irq save flags */
+	pr_info("%s", __func__);
+	/* check for sending & set flag sending here */
+	if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) {
+		pr_info("ST already sending");
+		/* keep sending */
+		set_bit(ST_TX_WAKEUP, &st_data->tx_state);
+		return;
+		/* TX_WAKEUP will be checked in another
+		 * context
+		 */
+	}
+	do {			/* come back if st_tx_wakeup is set */
+		/* woke-up to write */
+		clear_bit(ST_TX_WAKEUP, &st_data->tx_state);
+		while ((skb = st_int_dequeue(st_data))) {
+			int len;
+			spin_lock_irqsave(&st_data->lock, flags);
+			/* enable wake-up from TTY */
+			set_bit(TTY_DO_WRITE_WAKEUP, &st_data->tty->flags);
+			len = st_int_write(st_data, skb->data, skb->len);
+			skb_pull(skb, len);
+			/* if skb->len = len as expected, skb->len=0 */
+			if (skb->len) {
+				/* would be the next skb to be sent */
+				st_data->tx_skb = skb;
+				spin_unlock_irqrestore(&st_data->lock, flags);
+				break;
+			}
+			kfree_skb(skb);
+			spin_unlock_irqrestore(&st_data->lock, flags);
+		}
+		/* if wake-up is set in another context- restart sending */
+	} while (test_bit(ST_TX_WAKEUP, &st_data->tx_state));
+
+	/* clear flag sending */
+	clear_bit(ST_TX_SENDING, &st_data->tx_state);
+}
+
+/********************************************************************/
+/* functions called from ST KIM
+*/
+void kim_st_list_protocols(struct st_data_s *st_gdata, char *buf)
+{
+	unsigned long flags = 0;
+#ifdef DEBUG
+	unsigned char i = ST_MAX;
+#endif
+	spin_lock_irqsave(&st_gdata->lock, flags);
+#ifdef DEBUG			/* more detailed log */
+	for (i = 0; i < ST_MAX; i++) {
+		if (i == 0) {
+			sprintf(buf, "%s is %s", protocol_strngs[i],
+				st_gdata->list[i] !=
+				NULL ? "Registered" : "Unregistered");
+		} else {
+			sprintf(buf, "%s\n%s is %s", buf, protocol_strngs[i],
+				st_gdata->list[i] !=
+				NULL ? "Registered" : "Unregistered");
+		}
+	}
+	sprintf(buf, "%s\n", buf);
+#else /* limited info */
+	sprintf(buf, "BT=%c\nFM=%c\nGPS=%c\n",
+		st_gdata->list[ST_BT] != NULL ? 'R' : 'U',
+		st_gdata->list[ST_FM] != NULL ? 'R' : 'U',
+		st_gdata->list[ST_GPS] != NULL ? 'R' : 'U');
+#endif
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+}
+
+/********************************************************************/
+/*
+ * functions called from protocol stack drivers
+ * to be EXPORT-ed
+ */
+long st_register(struct st_proto_s *new_proto)
+{
+	struct st_data_s	*st_gdata;
+	long err = ST_SUCCESS;
+	unsigned long flags = 0;
+
+	st_kim_ref(&st_gdata);
+	pr_info("%s(%d) ", __func__, new_proto->type);
+	if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL
+	    || new_proto->reg_complete_cb == NULL) {
+		pr_err("gdata/new_proto/recv or reg_complete_cb not ready");
+		return ST_ERR_FAILURE;
+	}
+
+	if (new_proto->type < ST_BT || new_proto->type >= ST_MAX) {
+		pr_err("protocol %d not supported", new_proto->type);
+		return ST_ERR_NOPROTO;
+	}
+
+	if (st_gdata->list[new_proto->type] != NULL) {
+		pr_err("protocol %d already registered", new_proto->type);
+		return ST_ERR_ALREADY;
+	}
+
+	/* can be from process context only */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) {
+		pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->type);
+		/* fw download in progress */
+		st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+
+		set_bit(ST_REG_PENDING, &st_gdata->st_state);
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return ST_ERR_PENDING;
+	} else if (st_gdata->protos_registered == ST_EMPTY) {
+		pr_info(" protocol list empty :%d ", new_proto->type);
+		set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+		st_recv = st_kim_recv;
+
+		/* release lock previously held - re-locked below */
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+		/* enable the ST LL - to set default chip state */
+		st_ll_enable(st_gdata);
+		/* this may take a while to complete
+		 * since it involves BT fw download
+		 */
+		err = st_kim_start();
+		if (err != ST_SUCCESS) {
+			clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+			if ((st_gdata->protos_registered != ST_EMPTY) &&
+			    (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+				pr_err(" KIM failure complete callback ");
+				st_reg_complete(st_gdata, ST_ERR_FAILURE);
+			}
+
+			return ST_ERR_FAILURE;
+		}
+
+		/* the protocol might require other gpios to be toggled
+		 */
+		st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+
+		clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+		st_recv = st_int_recv;
+
+		/* this is where all pending registration
+		 * are signalled to be complete by calling callback functions
+		 */
+		if ((st_gdata->protos_registered != ST_EMPTY) &&
+		    (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+			pr_info(" call reg complete callback ");
+			st_gdata->protos_registered++;
+			st_reg_complete(st_gdata, ST_SUCCESS);
+		}
+		clear_bit(ST_REG_PENDING, &st_gdata->st_state);
+
+		/* check for already registered once more,
+		 * since the above check is old
+		 */
+		if (st_gdata->list[new_proto->type] != NULL) {
+			pr_err(" proto %d already registered ",
+				   new_proto->type);
+			return ST_ERR_ALREADY;
+		}
+
+		spin_lock_irqsave(&st_gdata->lock, flags);
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return err;
+	}
+	/* if fw is already downloaded & new stack registers protocol */
+	else {
+		switch (new_proto->type) {
+		case ST_BT:
+			/* do nothing */
+			break;
+		case ST_FM:
+		case ST_GPS:
+			st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+			break;
+		case ST_MAX:
+		default:
+			pr_err("%d protocol not supported",
+				   new_proto->type);
+			err = ST_ERR_NOPROTO;
+			/* something wrong */
+			break;
+		}
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+
+		/* lock already held before entering else */
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return err;
+	}
+	pr_info("done %s(%d) ", __func__, new_proto->type);
+}
+EXPORT_SYMBOL_GPL(st_register);
+
+/* to unregister a protocol -
+ * to be called from protocol stack driver
+ */
+long st_unregister(enum proto_type type)
+{
+	long err = ST_SUCCESS;
+	unsigned long flags = 0;
+	struct st_data_s	*st_gdata;
+
+	pr_info("%s: %d ", __func__, type);
+
+	st_kim_ref(&st_gdata);
+	if (type < ST_BT || type >= ST_MAX) {
+		pr_err(" protocol %d not supported", type);
+		return ST_ERR_NOPROTO;
+	}
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	if (st_gdata->list[type] == NULL) {
+		pr_err(" protocol %d not registered", type);
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return ST_ERR_NOPROTO;
+	}
+
+	st_gdata->protos_registered--;
+	st_gdata->list[type] = NULL;
+
+	/* kim ignores BT in the below function
+	 * and handles the rest, BT is toggled
+	 * only in kim_start and kim_stop
+	 */
+	st_kim_chip_toggle(type, KIM_GPIO_INACTIVE);
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	if ((st_gdata->protos_registered == ST_EMPTY) &&
+	    (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+		pr_info(" all protocols unregistered ");
+
+		/* stop traffic on tty */
+		if (st_gdata->tty) {
+			tty_ldisc_flush(st_gdata->tty);
+			stop_tty(st_gdata->tty);
+		}
+
+		/* all protocols now unregistered */
+		st_kim_stop();
+		/* disable ST LL */
+		st_ll_disable(st_gdata);
+	}
+	return err;
+}
+
+/*
+ * called in protocol stack drivers
+ * via the write function pointer
+ */
+long st_write(struct sk_buff *skb)
+{
+	struct st_data_s *st_gdata;
+#ifdef DEBUG
+	enum proto_type protoid = ST_MAX;
+#endif
+	long len;
+
+	st_kim_ref(&st_gdata);
+	if (unlikely(skb == NULL || st_gdata == NULL
+		|| st_gdata->tty == NULL)) {
+		pr_err("data/tty unavailable to perform write");
+		return ST_ERR_FAILURE;
+	}
+#ifdef DEBUG			/* open-up skb to read the 1st byte */
+	switch (skb->data[0]) {
+	case HCI_COMMAND_PKT:
+	case HCI_ACLDATA_PKT:
+	case HCI_SCODATA_PKT:
+		protoid = ST_BT;
+		break;
+	case ST_FM_CH8_PKT:
+		protoid = ST_FM;
+		break;
+	case 0x09:
+		protoid = ST_GPS;
+		break;
+	}
+	if (unlikely(st_gdata->list[protoid] == NULL)) {
+		pr_err(" protocol %d not registered, and writing? ",
+			   protoid);
+		return ST_ERR_FAILURE;
+	}
+#endif
+	pr_info("%d to be written", skb->len);
+	len = skb->len;
+
+	/* st_ll to decide where to enqueue the skb */
+	st_int_enqueue(st_gdata, skb);
+	/* wake up */
+	st_tx_wakeup(st_gdata);
+
+	/* return number of bytes written */
+	return len;
+}
+
+/* for protocols making use of shared transport */
+EXPORT_SYMBOL_GPL(st_unregister);
+
+/********************************************************************/
+/*
+ * functions called from TTY layer
+ */
+static int st_tty_open(struct tty_struct *tty)
+{
+	int err = ST_SUCCESS;
+	struct st_data_s *st_gdata;
+	pr_info("%s ", __func__);
+
+	st_kim_ref(&st_gdata);
+	st_gdata->tty = tty;
+	tty->disc_data = st_gdata;
+
+	/* don't do an wakeup for now */
+	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+
+	/* mem already allocated
+	 */
+	tty->receive_room = 65536;
+	/* Flush any pending characters in the driver and discipline. */
+	tty_ldisc_flush(tty);
+	tty_driver_flush_buffer(tty);
+	/*
+	 * signal to UIM via KIM that -
+	 * installation of N_TI_WL ldisc is complete
+	 */
+	st_kim_complete();
+	pr_info("done %s", __func__);
+	return err;
+}
+
+static void st_tty_close(struct tty_struct *tty)
+{
+	unsigned char i = ST_MAX;
+	unsigned long flags = 0;
+	struct	st_data_s *st_gdata = tty->disc_data;
+
+	pr_info("%s ", __func__);
+
+	/* TODO:
+	 * if a protocol has been registered & line discipline
+	 * un-installed for some reason - what should be done ?
+	 */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	for (i = ST_BT; i < ST_MAX; i++) {
+		if (st_gdata->list[i] != NULL)
+			pr_err("%d not un-registered", i);
+		st_gdata->list[i] = NULL;
+	}
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+	/*
+	 * signal to UIM via KIM that -
+	 * N_TI_WL ldisc is un-installed
+	 */
+	st_kim_complete();
+	st_gdata->tty = NULL;
+	/* Flush any pending characters in the driver and discipline. */
+	tty_ldisc_flush(tty);
+	tty_driver_flush_buffer(tty);
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	/* empty out txq and tx_waitq */
+	skb_queue_purge(&st_gdata->txq);
+	skb_queue_purge(&st_gdata->tx_waitq);
+	/* reset the TTY Rx states of ST */
+	st_gdata->rx_count = 0;
+	st_gdata->rx_state = ST_W4_PACKET_TYPE;
+	kfree_skb(st_gdata->rx_skb);
+	st_gdata->rx_skb = NULL;
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	pr_info("%s: done ", __func__);
+}
+
+static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
+			   char *tty_flags, int count)
+{
+
+#ifdef VERBOSE
+	long i;
+	printk(KERN_ERR "incoming data...\n");
+	for (i = 0; i < count; i++)
+		printk(" %x", data[i]);
+	printk(KERN_ERR "\n.. data end\n");
+#endif
+
+	/*
+	 * if fw download is in progress then route incoming data
+	 * to KIM for validation
+	 */
+	st_recv(tty->disc_data, data, count);
+	pr_info("done %s", __func__);
+}
+
+/* wake-up function called in from the TTY layer
+ * inside the internal wakeup function will be called
+ */
+static void st_tty_wakeup(struct tty_struct *tty)
+{
+	struct	st_data_s *st_gdata = tty->disc_data;
+	pr_info("%s ", __func__);
+	/* don't do an wakeup for now */
+	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+
+	/* call our internal wakeup */
+	st_tx_wakeup((void *)st_gdata);
+}
+
+static void st_tty_flush_buffer(struct tty_struct *tty)
+{
+	struct	st_data_s *st_gdata = tty->disc_data;
+	pr_info("%s ", __func__);
+
+	kfree_skb(st_gdata->tx_skb);
+	st_gdata->tx_skb = NULL;
+
+	tty->ops->flush_buffer(tty);
+	return;
+}
+
+/********************************************************************/
+int st_core_init(struct st_data_s **core_data)
+{
+	struct st_data_s *st_gdata;
+	long err;
+	static struct tty_ldisc_ops *st_ldisc_ops;
+
+	/* populate and register to TTY line discipline */
+	st_ldisc_ops = kzalloc(sizeof(*st_ldisc_ops), GFP_KERNEL);
+	if (!st_ldisc_ops) {
+		pr_err("no mem to allocate");
+		return -ENOMEM;
+	}
+
+	st_ldisc_ops->magic = TTY_LDISC_MAGIC;
+	st_ldisc_ops->name = "n_st";	/*"n_hci"; */
+	st_ldisc_ops->open = st_tty_open;
+	st_ldisc_ops->close = st_tty_close;
+	st_ldisc_ops->receive_buf = st_tty_receive;
+	st_ldisc_ops->write_wakeup = st_tty_wakeup;
+	st_ldisc_ops->flush_buffer = st_tty_flush_buffer;
+	st_ldisc_ops->owner = THIS_MODULE;
+
+	err = tty_register_ldisc(N_TI_WL, st_ldisc_ops);
+	if (err) {
+		pr_err("error registering %d line discipline %ld",
+			   N_TI_WL, err);
+		kfree(st_ldisc_ops);
+		return err;
+	}
+	pr_info("registered n_shared line discipline");
+
+	st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL);
+	if (!st_gdata) {
+		pr_err("memory allocation failed");
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc %ld", err);
+		kfree(st_ldisc_ops);
+		err = -ENOMEM;
+		return err;
+	}
+
+	/* Initialize ST TxQ and Tx waitQ queue head. All BT/FM/GPS module skb's
+	 * will be pushed in this queue for actual transmission.
+	 */
+	skb_queue_head_init(&st_gdata->txq);
+	skb_queue_head_init(&st_gdata->tx_waitq);
+
+	/* Locking used in st_int_enqueue() to avoid multiple execution */
+	spin_lock_init(&st_gdata->lock);
+
+	/* ldisc_ops ref to be only used in __exit of module */
+	st_gdata->ldisc_ops = st_ldisc_ops;
+
+#if 0
+	err = st_kim_init();
+	if (err) {
+		pr_err("error during kim initialization(%ld)", err);
+		kfree(st_gdata);
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc");
+		kfree(st_ldisc_ops);
+		return -1;
+	}
+#endif
+
+	err = st_ll_init(st_gdata);
+	if (err) {
+		pr_err("error during st_ll initialization(%ld)", err);
+		kfree(st_gdata);
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc");
+		kfree(st_ldisc_ops);
+		return -1;
+	}
+	*core_data = st_gdata;
+	return 0;
+}
+
+void st_core_exit(struct st_data_s *st_gdata)
+{
+	long err;
+	/* internal module cleanup */
+	err = st_ll_deinit(st_gdata);
+	if (err)
+		pr_err("error during deinit of ST LL %ld", err);
+#if 0
+	err = st_kim_deinit();
+	if (err)
+		pr_err("error during deinit of ST KIM %ld", err);
+#endif
+	if (st_gdata != NULL) {
+		/* Free ST Tx Qs and skbs */
+		skb_queue_purge(&st_gdata->txq);
+		skb_queue_purge(&st_gdata->tx_waitq);
+		kfree_skb(st_gdata->rx_skb);
+		kfree_skb(st_gdata->tx_skb);
+		/* TTY ldisc cleanup */
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc %ld", err);
+		kfree(st_gdata->ldisc_ops);
+		/* free the global data pointer */
+		kfree(st_gdata);
+	}
+}
+
+
diff --git a/drivers/staging/ti-st/st_core.h b/drivers/staging/ti-st/st_core.h
new file mode 100644
index 0000000..f271c88
--- /dev/null
+++ b/drivers/staging/ti-st/st_core.h
@@ -0,0 +1,98 @@
+/*
+ *  Shared Transport Core header file
+ *
+ *  Copyright (C) 2009 Texas Instruments
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef ST_CORE_H
+#define ST_CORE_H
+
+#include <linux/skbuff.h>
+#include "st.h"
+
+/* states of protocol list */
+#define ST_NOTEMPTY	1
+#define ST_EMPTY	0
+
+/*
+ * possible st_states
+ */
+#define ST_INITIALIZING		1
+#define ST_REG_IN_PROGRESS	2
+#define ST_REG_PENDING		3
+#define ST_WAITING_FOR_RESP	4
+
+/*
+ * local data required for ST/KIM/ST-HCI-LL
+ */
+struct st_data_s {
+	unsigned long st_state;
+/*
+ * an instance of tty_struct & ldisc ops to move around
+ */
+	struct tty_struct *tty;
+	struct tty_ldisc_ops *ldisc_ops;
+/*
+ * the tx skb -
+ * if the skb is already dequeued and the tty failed to write the same
+ * maintain the skb to write in the next transaction
+ */
+	struct sk_buff *tx_skb;
+#define ST_TX_SENDING	1
+#define ST_TX_WAKEUP	2
+	unsigned long tx_state;
+/*
+ * list of protocol registered
+ */
+	struct st_proto_s *list[ST_MAX];
+/*
+ * lock
+ */
+	unsigned long rx_state;
+	unsigned long rx_count;
+	struct sk_buff *rx_skb;
+	struct sk_buff_head txq, tx_waitq;
+	spinlock_t lock;	/* ST LL state lock  */
+	unsigned char	protos_registered;
+	unsigned long ll_state;	/* ST LL power state */
+};
+
+/* point this to tty->driver->write or tty->ops->write
+ * depending upon the kernel version
+ */
+int st_int_write(struct st_data_s*, const unsigned char*, int);
+/* internal write function, passed onto protocol drivers
+ * via the write function ptr of protocol struct
+ */
+long st_write(struct sk_buff *);
+/* function to be called from ST-LL
+ */
+void st_ll_send_frame(enum proto_type, struct sk_buff *);
+/* internal wake up function */
+void st_tx_wakeup(struct st_data_s *st_data);
+
+int st_core_init(struct st_data_s **);
+void st_core_exit(struct st_data_s *);
+void st_kim_ref(struct st_data_s **);
+
+#define GPS_STUB_TEST
+#ifdef GPS_STUB_TEST
+int gps_chrdrv_stub_write(const unsigned char*, int);
+void gps_chrdrv_stub_init(void);
+#endif
+
+#endif /*ST_CORE_H */
-- 
1.5.4.3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-04-01 23:27   ` Alan Cox
@ 2010-04-05 16:18     ` Pavan Savoy
  0 siblings, 0 replies; 27+ messages in thread
From: Pavan Savoy @ 2010-04-05 16:18 UTC (permalink / raw)
  To: Alan Cox; +Cc: Greg KH, Marcel Holtmann, linux-kernel


--- On Fri, 2/4/10, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> From: Alan Cox <alan@lxorguk.ukuu.org.uk>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: "Pavan Savoy" <pavan_savoy@yahoo.co.in>
> Cc: "Greg KH" <gregkh@suse.de>, "Marcel Holtmann" <marcel@holtmann.org>, linux-kernel@vger.kernel.org
> Date: Friday, 2 April, 2010, 4:57 AM
> Sorry but I can't make head or tail
> of this and the code flow you are
> trying to achieve.
> 
> The usual way you do stuff is to put per device stuff in a
> per device
> struct, driver wide stuff in a driver struct (or static
> variables) and
> then run everything from the device end.
> 
> I'd expect a low level driver to do something like
> 
> 
>     probe()
>         create device entry
>         initialise device (eg
> download firmware)
>         register itself with
> anything higher level
> 

What I am trying to achieve is something like this,

HCI-core	V4L2-radio	Char-device=/dev/tigps for fops
 ^		^		^
 |		|		|
 |		|		|
BT		FM		GPS [these register themselves to ST]
\		 |		 /
 \		 |		/
  \		 |		/
    Shared Transport Ldisc driver
  		|
  	TTY Layer	<-- UART driver has already registered.

So, when a BT device try and registers itself to ST (shared transport) driver, I need to toggle chip enable line and 'download_firmware', and in case another _register from FM or GPS happens at  the same time, I need to signal it pending, and call a callback upon completion of firmware download.

Now which are to be identified as per-device or bus or driver ?
Because when an st_register is called, I need to do some tty_* operations from the ldisc driver itself - i.e I cannot embed tty into any of BT, FM or GPS per-device structures.

I also expose a st_write function, where in any of BT, FM and GPS driver upon being ready (fw download completed) sends across an SKB, which I queue up and write.

All of what I wanted to do, could not be done when I tried ST ldisc as a bus and each of BT, FM and GPS as per-device structs registering with type ST as bus.
So again, Now which are to be identified as per-device or bus or driver ?



      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-04-01 22:43 ` Pavan Savoy
@ 2010-04-01 23:27   ` Alan Cox
  2010-04-05 16:18     ` Pavan Savoy
  0 siblings, 1 reply; 27+ messages in thread
From: Alan Cox @ 2010-04-01 23:27 UTC (permalink / raw)
  To: Pavan Savoy; +Cc: Greg KH, Marcel Holtmann, linux-kernel

Sorry but I can't make head or tail of this and the code flow you are
trying to achieve.

The usual way you do stuff is to put per device stuff in a per device
struct, driver wide stuff in a driver struct (or static variables) and
then run everything from the device end.

I'd expect a low level driver to do something like


	probe()
		create device entry
		initialise device (eg download firmware)
		register itself with anything higher level


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-04-01 17:20 Pavan Savoy
@ 2010-04-01 22:43 ` Pavan Savoy
  2010-04-01 23:27   ` Alan Cox
  0 siblings, 1 reply; 27+ messages in thread
From: Pavan Savoy @ 2010-04-01 22:43 UTC (permalink / raw)
  To: Alan Cox; +Cc: Greg KH, Marcel Holtmann, linux-kernel



--- On Thu, 1/4/10, Pavan Savoy <pavan_savoy@ti.com> wrote:

> From: Pavan Savoy <pavan_savoy@ti.com>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: "Alan Cox" <alan@lxorguk.ukuu.org.uk>
> Cc: "Greg KH" <gregkh@suse.de>, "Marcel Holtmann" <marcel@holtmann.org>, linux-kernel@vger.kernel.org
> Date: Thursday, 1 April, 2010, 10:50 PM
> --- On Thu, 1/4/10, Alan Cox <alan@lxorguk.ukuu.org.uk>
> wrote:
> 
> > From: Alan Cox <alan@lxorguk.ukuu.org.uk>
> > Subject: Re: [PATCH] drivers:staging: sources for ST
> core
> > To: pavan_savoy@ti.com
> > Cc: "Greg KH" <gregkh@suse.de>,
> "Marcel Holtmann" <marcel@holtmann.org>,
> linux-kernel@vger.kernel.org
> > Date: Thursday, 1 April, 2010, 2:50 PM
> > > +/*
> > > + * function to return whether the firmware
> response
> > was proper
> > > + * in case of error don't complete so that
> waiting
> > for proper
> > > + * response times out
> > > + */
> > > +void validate_firmware_response(struct sk_buff
> *skb)
> > > +{
> > > +    if (unlikely(skb->data[5] !=
> > 0)) {
> > > +        pr_err("no
> > proper response during fw download");
> > > +        pr_err("data6
> > %x", skb->data[5]);
> > 
> > In this driver you do know the device so you need to
> be
> > using dev_ and
> > passing around dev (or something that gives you dev).
> > 
> > > +static int kim_probe(struct platform_device
> *pdev)
> > > +{
> > > +    long status;
> > > +    long proto;
> > > +    long *gpios =
> > pdev->dev.platform_data;
> > > +
> > > +    status =
> > st_core_init(&kim_gdata->core_data);
> > 
> > I would expect any truely global data to be configured
> in
> > the module init
> > and then device specific data you want to do something
> like
> > this
> > 
> >     kim_data = kzalloc(sizeof(something),
> > GFP_KERNEL);
> > 
> >     ..
> > 
> >     kim_data_init(&pdev->dev,
> > kim_data);
> >     dev_set_drvdata(&pdev->dev,
> > kim_data);
> > 
> > Elsewhere you can now do
> > 
> >     kim_data =
> > dev_get_drvdata(&pdev->dev);
> > 
> > to get it back
> 
> There are 2 sets of data structures here (after removing
> the un-necessary 3rd one),
> 1. st_gdata - which I would want to tie to tty
> 2. kim_gdata - which I "would" like to tie to the pdev.
> 
> Now the problem being, I have reference of st_gdata in
> kim_gdata, and there are about 4 functions in the st_core
> where I would need the st_gdata, as in,
> 
> EXPORTED symbol st_register - because I need to add in
> entries as to who registered,
> +long st_register(struct st_proto_s *new_proto)
> +{
> +    struct st_data_s    *st_gdata;
> +    long err = ST_SUCCESS;
> +    unsigned long flags = 0;
> +
> +    st_kim_ref(&st_gdata);
> +    pr_info("%s(%d) ", __func__, new_proto->type);
> +    if (st_gdata == NULL || new_proto == NULL ||
> new_proto->recv == NULL
> +        || new_proto->reg_complete_cb == NULL) {
> +        pr_err("gdata/new_proto/recv or
> reg_complete_cb not ready");
> +        return ST_ERR_FAILURE;
> +    }
> Also in st_unregister and st_write for similar purposes,
> But I also need it in tty_open, to link it to the
> disc_data,
> 
> +static int st_tty_open(struct tty_struct *tty)
> +{
> +    int err = ST_SUCCESS;
> +    struct st_data_s *st_gdata;
> +    pr_info("%s ", __func__);
> +
> +    st_kim_ref(&st_gdata);
> +    st_gdata->tty = tty;
> +    tty->disc_data = st_gdata;
> 
> So, shouldn't some function like st_kim_ref be enough ?
> 
> +void st_kim_ref(struct st_data_s **core_data)
> +{
> +    *core_data = kim_gdata->core_data;
> +}
> 
> So Now st_gdata is tied to tty, and kim_gdata being purely
> global, as in only 1 platform device of such kind can
> exist.
> 
> Suppose 2 platform devices want to exist - then who's
> EXPORT of st_register is considered ? 
> And If bluetooth or FM wants to use this transport then,
> how would it tell onto which platform device it wants to
> attach to ?
> 
> Why should I tie kim_gdata to a pdev ?

Well, because of the comments on the architecture of this driver, I tried out the bus_ driver method, where I register a new bus type as ST (which also registers the N_TI_WL line discipline) and the different protocols on it, are registered to as devices with the N_TI_WL as bus type.

However, I ended up in some similar mess there on too, where during an st_register when I need to register devices to the bus, status-es like how many devices currently registered, and allowing other devices to register during firmware download all would then on require a data which isn't bound to any device ...

So any ideas ? What should be done ? Find below the test patch...

---
 drivers/staging/ti-st/bus_drv/bt_test_bus.c |   55 +++++++++++
 drivers/staging/ti-st/bus_drv/fm_test_bus.c |   55 +++++++++++
 drivers/staging/ti-st/bus_drv/test_bus.c    |  134 +++++++++++++++++++++++++++
 3 files changed, 244 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/ti-st/bus_drv/bt_test_bus.c
 create mode 100644 drivers/staging/ti-st/bus_drv/fm_test_bus.c
 create mode 100644 drivers/staging/ti-st/bus_drv/test_bus.c

diff --git a/drivers/staging/ti-st/bus_drv/bt_test_bus.c b/drivers/staging/ti-st/bus_drv/bt_test_bus.c
new file mode 100644
index 0000000..02ae812
--- /dev/null
+++ b/drivers/staging/ti-st/bus_drv/bt_test_bus.c
@@ -0,0 +1,55 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/device.h>
+
+#include "st_bus.h"
+
+static int __init st_user_probe(struct device *dev, int cur_bus, int cur_slot)
+{
+	pr_info("%s\n", __func__);
+	return 0;
+}
+static int __exit st_user_remove(struct device *dev, int cur_bus, int cur_slot)
+{
+	pr_info("%s\n", __func__);
+	return 0;
+}
+
+void bt_release(struct device *dev)
+{
+	pr_info("%s\n", __func__);
+}
+
+static struct st_driver st_user_driver = {
+	.dev = {
+		.release = bt_release,
+	},
+	.id = ST_BT,
+	.name = "bluetooth",
+};
+
+static int __init st_user_init(void)
+{
+	int retval;
+	retval = st_register(&st_user_driver);
+	if (retval != 0)
+		pr_err("%s: error registering driver\n", __func__);
+
+	return retval;
+
+}
+
+static void __exit st_user_exit(void)
+{
+	pr_info("%s\n", __func__);
+	st_unregister(&st_user_driver);
+}
+
+
+
+MODULE_LICENSE("GPL");
+
+module_init(st_user_init);
+module_exit(st_user_exit);
+
diff --git a/drivers/staging/ti-st/bus_drv/fm_test_bus.c b/drivers/staging/ti-st/bus_drv/fm_test_bus.c
new file mode 100644
index 0000000..75d9980
--- /dev/null
+++ b/drivers/staging/ti-st/bus_drv/fm_test_bus.c
@@ -0,0 +1,55 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/device.h>
+
+#include "st_bus.h"
+
+static int __init st_user_probe(struct device *dev, int cur_bus, int cur_slot)
+{
+	pr_info("%s\n", __func__);
+	return 0;
+}
+static int __exit st_user_remove(struct device *dev, int cur_bus, int cur_slot)
+{
+	pr_info("%s\n", __func__);
+	return 0;
+}
+
+void fm_release(struct device *dev)
+{
+	pr_info("%s\n", __func__);
+}
+
+static struct st_driver st_user_driver = {
+	.dev = {
+		.release = fm_release,
+	},
+	.id = ST_FM,
+	.name = "fm",
+};
+
+static int __init st_user_init(void)
+{
+	int retval;
+	retval = st_register(&st_user_driver);
+	if (retval != 0)
+		pr_err("%s: error registering driver\n", __func__);
+
+	return retval;
+
+}
+
+static void __exit st_user_exit(void)
+{
+	pr_info("%s\n", __func__);
+	st_unregister(&st_user_driver);
+}
+
+
+
+MODULE_LICENSE("GPL");
+
+module_init(st_user_init);
+module_exit(st_user_exit);
+
diff --git a/drivers/staging/ti-st/bus_drv/test_bus.c b/drivers/staging/ti-st/bus_drv/test_bus.c
new file mode 100644
index 0000000..87aaa94
--- /dev/null
+++ b/drivers/staging/ti-st/bus_drv/test_bus.c
@@ -0,0 +1,134 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+
+#include "st_bus.h"
+#include "st_core.h"
+
+struct bus_type st_bus_type;
+
+static int check_if_registered(struct device *dev, void *data)
+{
+	struct st_driver *drv;
+
+	drv = dev_get_drvdata(dev);
+	pr_info("device is %s, type %d\n", drv->name, drv->id);
+	return 1;
+}
+
+int st_register(struct st_driver *drv)
+{
+	int retval;
+	struct device *dev = &drv->dev;
+
+	if (bus_find_device_by_name(&st_bus_type, NULL,
+				drv->name) != NULL) {
+		pr_err("already registered\n");
+	}
+
+	retval = bus_for_each_dev(&st_bus_type, NULL, NULL,
+		check_if_registered);
+	if (retval != 1) { /* as returned by check_if_registered */
+		/* download_firmware here */
+		pr_info("downloading firmware..\n");
+		/* HOWTO carry on with device_register ? */
+	}

This is 1 place, I would be totally lost because, I should return the flow back to the driver which called the st_register, and allow other driver to do an st_register and return them as pending - and when firmware download completes (takes around 10secs - worst case), I then have to notify all the drivers(devices) registered about the completion of firmware download.


+	dev->bus = &(st_bus_type);
+	dev_set_name(dev, drv->name);
+	dev_set_drvdata(dev, drv);
+
+	/* add device here */
+	retval = device_register(dev);
+	if (retval) {
+		pr_err("device register failed\n");
+		return -1;
+	}
+
+	pr_info("%s: %s\n", __func__, drv->name);
+	return 0;
+}
+EXPORT_SYMBOL(st_register);
+
+void st_unregister(struct st_driver *drv)
+{
+	pr_info("%s\n", __func__);
+	device_unregister(&drv->dev);
+}
+EXPORT_SYMBOL(st_unregister);
+
+
+static int st_bus_probe(struct platform_device *pdev)
+{
+	struct st_data_s *core_data;
+	pr_info("%s\n", __func__);
+	bus_register(&st_bus_type);
+
+	st_core_init(&core_data);
+	dev_set_drvdata(&pdev->dev, core_data);
+	return 0;
+}
+
+static int st_bus_remove(struct platform_device *pdev)
+{
+	struct st_data_s *core_data;
+	pr_info("%s\n", __func__);
+
+	core_data = dev_get_drvdata(&pdev->dev);
+	st_core_exit(core_data);
+	bus_unregister(&st_bus_type);
+	return 0;
+}
+
+#if 0
+static int st_bus_match(struct device *dev, struct device_driver *drv)
+{
+	return 1;
+}
+
+int st_notify(struct notifier_block *notify, unsigned long a, void *b)
+{
+	pr_info("%s \n", __func__);
+	return 0;
+}
+#endif
+
+struct bus_type st_bus_type = {
+	.name = "ti-st",
+};
+EXPORT_SYMBOL(st_bus_type);
+
+struct platform_driver st_bus_driver = {
+	.driver = {
+		.name = "kim",
+		.owner = THIS_MODULE,
+	},
+	.probe = st_bus_probe,
+	.remove = st_bus_remove,
+};
+
+#if 0
+struct notifier_block st_bus_notify = {
+	.notifier_call = st_notify,
+};
+#endif
+
+static int __init test_bus_init(void)
+{
+	platform_driver_register(&st_bus_driver);
+	return 0;
+}
+
+static void __exit test_bus_exit(void)
+{
+	pr_info("%s\n", __func__);
+	platform_driver_unregister(&st_bus_driver);
+}
+
+module_init(test_bus_init);
+module_exit(test_bus_exit);
+MODULE_AUTHOR("Pavan Savoy <pavan_savoy@ti.com>");
+MODULE_DESCRIPTION("Shared Transport Driver for TI BT/FM/GPS combo chips ");
+MODULE_LICENSE("GPL");
-- 
1.5.4.3


> > --
> > To unsubscribe from this list: send the line
> "unsubscribe
> > linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/
> >
> 
> 
> 
>       The INTERNET now has a personality.
> YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


      Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
@ 2010-04-01 17:20 Pavan Savoy
  2010-04-01 22:43 ` Pavan Savoy
  0 siblings, 1 reply; 27+ messages in thread
From: Pavan Savoy @ 2010-04-01 17:20 UTC (permalink / raw)
  To: Alan Cox; +Cc: Greg KH, Marcel Holtmann, linux-kernel

--- On Thu, 1/4/10, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> From: Alan Cox <alan@lxorguk.ukuu.org.uk>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: pavan_savoy@ti.com
> Cc: "Greg KH" <gregkh@suse.de>, "Marcel Holtmann" <marcel@holtmann.org>, linux-kernel@vger.kernel.org
> Date: Thursday, 1 April, 2010, 2:50 PM
> > +/*
> > + * function to return whether the firmware response
> was proper
> > + * in case of error don't complete so that waiting
> for proper
> > + * response times out
> > + */
> > +void validate_firmware_response(struct sk_buff *skb)
> > +{
> > +    if (unlikely(skb->data[5] !=
> 0)) {
> > +        pr_err("no
> proper response during fw download");
> > +        pr_err("data6
> %x", skb->data[5]);
> 
> In this driver you do know the device so you need to be
> using dev_ and
> passing around dev (or something that gives you dev).
> 
> > +static int kim_probe(struct platform_device *pdev)
> > +{
> > +    long status;
> > +    long proto;
> > +    long *gpios =
> pdev->dev.platform_data;
> > +
> > +    status =
> st_core_init(&kim_gdata->core_data);
> 
> I would expect any truely global data to be configured in
> the module init
> and then device specific data you want to do something like
> this
> 
>     kim_data = kzalloc(sizeof(something),
> GFP_KERNEL);
> 
>     ..
> 
>     kim_data_init(&pdev->dev,
> kim_data);
>     dev_set_drvdata(&pdev->dev,
> kim_data);
> 
> Elsewhere you can now do
> 
>     kim_data =
> dev_get_drvdata(&pdev->dev);
> 
> to get it back

There are 2 sets of data structures here (after removing the un-necessary 3rd one),
1. st_gdata - which I would want to tie to tty
2. kim_gdata - which I "would" like to tie to the pdev.

Now the problem being, I have reference of st_gdata in kim_gdata, and there are about 4 functions in the st_core where I would need the st_gdata, as in,

EXPORTED symbol st_register - because I need to add in entries as to who registered,
+long st_register(struct st_proto_s *new_proto)
+{
+    struct st_data_s    *st_gdata;
+    long err = ST_SUCCESS;
+    unsigned long flags = 0;
+
+    st_kim_ref(&st_gdata);
+    pr_info("%s(%d) ", __func__, new_proto->type);
+    if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL
+        || new_proto->reg_complete_cb == NULL) {
+        pr_err("gdata/new_proto/recv or reg_complete_cb not ready");
+        return ST_ERR_FAILURE;
+    }
Also in st_unregister and st_write for similar purposes,
But I also need it in tty_open, to link it to the disc_data,

+static int st_tty_open(struct tty_struct *tty)
+{
+    int err = ST_SUCCESS;
+    struct st_data_s *st_gdata;
+    pr_info("%s ", __func__);
+
+    st_kim_ref(&st_gdata);
+    st_gdata->tty = tty;
+    tty->disc_data = st_gdata;

So, shouldn't some function like st_kim_ref be enough ?

+void st_kim_ref(struct st_data_s **core_data)
+{
+    *core_data = kim_gdata->core_data;
+}

So Now st_gdata is tied to tty, and kim_gdata being purely global, as in only 1 platform device of such kind can exist.

Suppose 2 platform devices want to exist - then who's EXPORT of st_register is considered ? 
And If bluetooth or FM wants to use this transport then, how would it tell onto which platform device it wants to attach to ?

Why should I tie kim_gdata to a pdev ?

> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>



      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-31 18:02   ` Pavan Savoy
@ 2010-03-31 18:19     ` Greg KH
  0 siblings, 0 replies; 27+ messages in thread
From: Greg KH @ 2010-03-31 18:19 UTC (permalink / raw)
  To: Pavan Savoy; +Cc: Marcel Holtmann, alan, linux-kernel

On Wed, Mar 31, 2010 at 11:32:39PM +0530, Pavan Savoy wrote:
> --- On Wed, 31/3/10, Greg KH <gregkh@suse.de> wrote:
> 
> > From: Greg KH <gregkh@suse.de>
> > Subject: Re: [PATCH] drivers:staging: sources for ST core
> > To: "Pavan Savoy" <pavan_savoy@ti.com>
> > Cc: "Marcel Holtmann" <marcel@holtmann.org>, alan@lxorguk.ukuu.org.uk, linux-kernel@vger.kernel.org
> > Date: Wednesday, 31 March, 2010, 11:00 PM
> > On Wed, Mar 31, 2010 at 04:20:22AM
> > +0530, Pavan Savoy wrote:
> > > 
> > > --- On Wed, 31/3/10, Pavan Savoy <pavan_savoy@ti.com>
> > wrote:
> > > 
> > > > From: Pavan Savoy <pavan_savoy@ti.com>
> > > > Subject: Re: [PATCH] drivers:staging: sources for
> > ST core
> > > > To: gregkh@suse.de
> > > > Cc: "Marcel Holtmann" <marcel@holtmann.org>,
> > alan@lxorguk.ukuu.org.uk
> > > > Date: Wednesday, 31 March, 2010, 4:11 AM
> > > > --- On Wed, 31/3/10, Pavan Savoy
> > > > <pavan_savoy@yahoo.co.in>
> > > > wrote:
> > > > 
> > > > > From: Pavan Savoy <pavan_savoy@yahoo.co.in>
> > > > > Subject: Re: [PATCH] drivers:staging:
> > sources for ST
> > > > core
> > > > > To: "pavan_savoy@yahoo.co.in"
> > > > <pavan_savoy@yahoo.co.in>
> > > > > Date: Wednesday, 31 March, 2010, 4:06 AM
> > > > > > From: Greg KH [gregkh@suse.de]
> > > > > > Sent: Wednesday, March 31, 2010 3:17
> > AM
> > > > > > To: Savoy, Pavan
> > > > > > Cc: Alan Cox; marcel@holtmann.org;
> > > > > > linux-kernel@vger.kernel.org
> > > > > > Subject: Re: [PATCH] drivers:staging:
> > sources for
> > > > ST
> > > > > core
> > > > > > 
> > > > > > On Wed, Mar 31, 2010 at 02:35:55AM
> > +0530, Pavan
> > > > Savoy
> > > > > > wrote:
> > > > > > > So, something like the below is
> > ok, I have
> > > > > defined my
> > > > > > own pr_fmt,
> > > > > > > however default log level on my
> > board is 7,
> > > > and
> > > > > hence
> > > > > > pr_info is a bit
> > > > > > > more annoying than usual.
> > > > > > 
> > > > > > No, a driver should use dev_dbg() and
> > other
> > > > > dev_printk()
> > > > > > calls, not
> > > > > > pr_debug() or anything like that.
> > > > > > 
> > > > > > Please don't roll your own formats, use
> > the ones
> > > > that
> > > > > are
> > > > > > well defined
> > > > > > and uniquely describe your driver and
> > device in
> > > > a
> > > > > format
> > > > > > that the whole
> > > > > > kernel uses.
> > > > > 
> > > > 
> > > 
> > > forgot lkml the last time..
> > > 
> > > Nope, I couldn't find any instance of struct device at
> > all,
> > > I need that to use dev_dbg right ? - None of the
> > tty_*
> > > structure accessible by ldiscs seems to have a
> > reference to
> > > it.
> > > Also I happened to look at other line discipline
> > driver, if
> > > they have a smarter way of doing this, Nope - n_tty,
> > n_hdlc,
> > > n_slip all seem to use plain old printks.
> > >? 
> > > Any clues ??
> > 
> > Sorry, you are correct, we only have a struct kref right
> > now for tty
> > core objects, not a struct device.? So nevermind, this
> > should be fine.
> 
> Oh cool. Thanks, So that leaves me with 1 pending item from Alan which is to tie these 3 modules (KIM/Core/LL) up onto a TTY device specific context, and avoid all global ptrs.
> 
> So without that is it good to go in ?

Yes, care to do that and resubmit?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-31 17:30 ` Greg KH
@ 2010-03-31 18:02   ` Pavan Savoy
  2010-03-31 18:19     ` Greg KH
  0 siblings, 1 reply; 27+ messages in thread
From: Pavan Savoy @ 2010-03-31 18:02 UTC (permalink / raw)
  To: Greg KH; +Cc: Marcel Holtmann, alan, linux-kernel

--- On Wed, 31/3/10, Greg KH <gregkh@suse.de> wrote:

> From: Greg KH <gregkh@suse.de>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: "Pavan Savoy" <pavan_savoy@ti.com>
> Cc: "Marcel Holtmann" <marcel@holtmann.org>, alan@lxorguk.ukuu.org.uk, linux-kernel@vger.kernel.org
> Date: Wednesday, 31 March, 2010, 11:00 PM
> On Wed, Mar 31, 2010 at 04:20:22AM
> +0530, Pavan Savoy wrote:
> > 
> > --- On Wed, 31/3/10, Pavan Savoy <pavan_savoy@ti.com>
> wrote:
> > 
> > > From: Pavan Savoy <pavan_savoy@ti.com>
> > > Subject: Re: [PATCH] drivers:staging: sources for
> ST core
> > > To: gregkh@suse.de
> > > Cc: "Marcel Holtmann" <marcel@holtmann.org>,
> alan@lxorguk.ukuu.org.uk
> > > Date: Wednesday, 31 March, 2010, 4:11 AM
> > > --- On Wed, 31/3/10, Pavan Savoy
> > > <pavan_savoy@yahoo.co.in>
> > > wrote:
> > > 
> > > > From: Pavan Savoy <pavan_savoy@yahoo.co.in>
> > > > Subject: Re: [PATCH] drivers:staging:
> sources for ST
> > > core
> > > > To: "pavan_savoy@yahoo.co.in"
> > > <pavan_savoy@yahoo.co.in>
> > > > Date: Wednesday, 31 March, 2010, 4:06 AM
> > > > > From: Greg KH [gregkh@suse.de]
> > > > > Sent: Wednesday, March 31, 2010 3:17
> AM
> > > > > To: Savoy, Pavan
> > > > > Cc: Alan Cox; marcel@holtmann.org;
> > > > > linux-kernel@vger.kernel.org
> > > > > Subject: Re: [PATCH] drivers:staging:
> sources for
> > > ST
> > > > core
> > > > > 
> > > > > On Wed, Mar 31, 2010 at 02:35:55AM
> +0530, Pavan
> > > Savoy
> > > > > wrote:
> > > > > > So, something like the below is
> ok, I have
> > > > defined my
> > > > > own pr_fmt,
> > > > > > however default log level on my
> board is 7,
> > > and
> > > > hence
> > > > > pr_info is a bit
> > > > > > more annoying than usual.
> > > > > 
> > > > > No, a driver should use dev_dbg() and
> other
> > > > dev_printk()
> > > > > calls, not
> > > > > pr_debug() or anything like that.
> > > > > 
> > > > > Please don't roll your own formats, use
> the ones
> > > that
> > > > are
> > > > > well defined
> > > > > and uniquely describe your driver and
> device in
> > > a
> > > > format
> > > > > that the whole
> > > > > kernel uses.
> > > > 
> > > 
> > 
> > forgot lkml the last time..
> > 
> > Nope, I couldn't find any instance of struct device at
> all,
> > I need that to use dev_dbg right ? - None of the
> tty_*
> > structure accessible by ldiscs seems to have a
> reference to
> > it.
> > Also I happened to look at other line discipline
> driver, if
> > they have a smarter way of doing this, Nope - n_tty,
> n_hdlc,
> > n_slip all seem to use plain old printks.
> >  
> > Any clues ??
> 
> Sorry, you are correct, we only have a struct kref right
> now for tty
> core objects, not a struct device.  So nevermind, this
> should be fine.

Oh cool. Thanks, So that leaves me with 1 pending item from Alan which is to tie these 3 modules (KIM/Core/LL) up onto a TTY device specific context, and avoid all global ptrs.

So without that is it good to go in ?

> thanks,
> 
> greg k-h
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


      Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-30 22:50 Pavan Savoy
@ 2010-03-31 17:30 ` Greg KH
  2010-03-31 18:02   ` Pavan Savoy
  0 siblings, 1 reply; 27+ messages in thread
From: Greg KH @ 2010-03-31 17:30 UTC (permalink / raw)
  To: Pavan Savoy; +Cc: Marcel Holtmann, alan, linux-kernel

On Wed, Mar 31, 2010 at 04:20:22AM +0530, Pavan Savoy wrote:
> 
> --- On Wed, 31/3/10, Pavan Savoy <pavan_savoy@ti.com> wrote:
> 
> > From: Pavan Savoy <pavan_savoy@ti.com>
> > Subject: Re: [PATCH] drivers:staging: sources for ST core
> > To: gregkh@suse.de
> > Cc: "Marcel Holtmann" <marcel@holtmann.org>, alan@lxorguk.ukuu.org.uk
> > Date: Wednesday, 31 March, 2010, 4:11 AM
> > --- On Wed, 31/3/10, Pavan Savoy
> > <pavan_savoy@yahoo.co.in>
> > wrote:
> > 
> > > From: Pavan Savoy <pavan_savoy@yahoo.co.in>
> > > Subject: Re: [PATCH] drivers:staging: sources for ST
> > core
> > > To: "pavan_savoy@yahoo.co.in"
> > <pavan_savoy@yahoo.co.in>
> > > Date: Wednesday, 31 March, 2010, 4:06 AM
> > > > From: Greg KH [gregkh@suse.de]
> > > > Sent: Wednesday, March 31, 2010 3:17 AM
> > > > To: Savoy, Pavan
> > > > Cc: Alan Cox; marcel@holtmann.org;
> > > > linux-kernel@vger.kernel.org
> > > > Subject: Re: [PATCH] drivers:staging: sources for
> > ST
> > > core
> > > > 
> > > > On Wed, Mar 31, 2010 at 02:35:55AM +0530, Pavan
> > Savoy
> > > > wrote:
> > > > > So, something like the below is ok, I have
> > > defined my
> > > > own pr_fmt,
> > > > > however default log level on my board is 7,
> > and
> > > hence
> > > > pr_info is a bit
> > > > > more annoying than usual.
> > > > 
> > > > No, a driver should use dev_dbg() and other
> > > dev_printk()
> > > > calls, not
> > > > pr_debug() or anything like that.
> > > > 
> > > > Please don't roll your own formats, use the ones
> > that
> > > are
> > > > well defined
> > > > and uniquely describe your driver and device in
> > a
> > > format
> > > > that the whole
> > > > kernel uses.
> > > 
> > 
> 
> forgot lkml the last time..
> 
> Nope, I couldn't find any instance of struct device at all,
> I need that to use dev_dbg right ? - None of the tty_*
> structure accessible by ldiscs seems to have a reference to
> it.
> Also I happened to look at other line discipline driver, if
> they have a smarter way of doing this, Nope - n_tty, n_hdlc,
> n_slip all seem to use plain old printks.
>  
> Any clues ??

Sorry, you are correct, we only have a struct kref right now for tty
core objects, not a struct device.  So nevermind, this should be fine.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-30 21:05           ` Pavan Savoy
  2010-03-30 21:47             ` Greg KH
@ 2010-03-31  2:24             ` Joe Perches
  1 sibling, 0 replies; 27+ messages in thread
From: Joe Perches @ 2010-03-31  2:24 UTC (permalink / raw)
  To: Pavan Savoy; +Cc: Greg KH, Alan Cox, marcel, linux-kernel

On Wed, 31 Mar 2010, Pavan Savoy wrote:
> +bool is_protocol_list_empty(void)
> +{
> +	unsigned char i = 0;
> +	pr_debug(" %s ", __func__);

You need to add terminating '\n's to most all these messages.
It's also not necessary to have leading or trailing whitespace.

> +#ifdef VERBOSE
> +	printk(KERN_ERR "start data..\n");
> +	for (i = 0; i < count; i++)	/* no newlines for each datum */
> +		printk(" %x", data[i]);
> +	printk(KERN_ERR "\n ..end data\n");
> +#endif

	print_hex_dump(KERN_ERR, "data: ", DUMP_PREFIX_OFFSET, 16, 1,
                       data, count, true);

cheers, Joe


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
@ 2010-03-30 22:50 Pavan Savoy
  2010-03-31 17:30 ` Greg KH
  0 siblings, 1 reply; 27+ messages in thread
From: Pavan Savoy @ 2010-03-30 22:50 UTC (permalink / raw)
  To: gregkh; +Cc: Marcel Holtmann, alan, linux-kernel


--- On Wed, 31/3/10, Pavan Savoy <pavan_savoy@ti.com> wrote:

> From: Pavan Savoy <pavan_savoy@ti.com>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: gregkh@suse.de
> Cc: "Marcel Holtmann" <marcel@holtmann.org>, alan@lxorguk.ukuu.org.uk
> Date: Wednesday, 31 March, 2010, 4:11 AM
> --- On Wed, 31/3/10, Pavan Savoy
> <pavan_savoy@yahoo.co.in>
> wrote:
> 
> > From: Pavan Savoy <pavan_savoy@yahoo.co.in>
> > Subject: Re: [PATCH] drivers:staging: sources for ST
> core
> > To: "pavan_savoy@yahoo.co.in"
> <pavan_savoy@yahoo.co.in>
> > Date: Wednesday, 31 March, 2010, 4:06 AM
> > > From: Greg KH [gregkh@suse.de]
> > > Sent: Wednesday, March 31, 2010 3:17 AM
> > > To: Savoy, Pavan
> > > Cc: Alan Cox; marcel@holtmann.org;
> > > linux-kernel@vger.kernel.org
> > > Subject: Re: [PATCH] drivers:staging: sources for
> ST
> > core
> > > 
> > > On Wed, Mar 31, 2010 at 02:35:55AM +0530, Pavan
> Savoy
> > > wrote:
> > > > So, something like the below is ok, I have
> > defined my
> > > own pr_fmt,
> > > > however default log level on my board is 7,
> and
> > hence
> > > pr_info is a bit
> > > > more annoying than usual.
> > > 
> > > No, a driver should use dev_dbg() and other
> > dev_printk()
> > > calls, not
> > > pr_debug() or anything like that.
> > > 
> > > Please don't roll your own formats, use the ones
> that
> > are
> > > well defined
> > > and uniquely describe your driver and device in
> a
> > format
> > > that the whole
> > > kernel uses.
> > 
> 

forgot lkml the last time..

Nope, I couldn't find any instance of struct device at all,
I need that to use dev_dbg right ? - None of the tty_*
structure accessible by ldiscs seems to have a reference to
it.
Also I happened to look at other line discipline driver, if
they have a smarter way of doing this, Nope - n_tty, n_hdlc,
n_slip all seem to use plain old printks.
 
Any clues ??


> > 
> > > thanks,
> > > 
> > > greg k-h
> > 
> > 
> >       Your Mail works best with the New
> > Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/
> > 
> 
> 
>       Your Mail works best with the New
> Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/
> 


      Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-30 21:05           ` Pavan Savoy
@ 2010-03-30 21:47             ` Greg KH
  2010-03-31  2:24             ` Joe Perches
  1 sibling, 0 replies; 27+ messages in thread
From: Greg KH @ 2010-03-30 21:47 UTC (permalink / raw)
  To: Pavan Savoy; +Cc: Alan Cox, marcel, linux-kernel

On Wed, Mar 31, 2010 at 02:35:55AM +0530, Pavan Savoy wrote:
> So, something like the below is ok, I have defined my own pr_fmt,
> however default log level on my board is 7, and hence pr_info is a bit
> more annoying than usual.

No, a driver should use dev_dbg() and other dev_printk() calls, not
pr_debug() or anything like that.

Please don't roll your own formats, use the ones that are well defined
and uniquely describe your driver and device in a format that the whole
kernel uses.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-30 20:38         ` Greg KH
@ 2010-03-30 21:05           ` Pavan Savoy
  2010-03-30 21:47             ` Greg KH
  2010-03-31  2:24             ` Joe Perches
  0 siblings, 2 replies; 27+ messages in thread
From: Pavan Savoy @ 2010-03-30 21:05 UTC (permalink / raw)
  To: Greg KH; +Cc: Alan Cox, marcel, linux-kernel


--- On Wed, 31/3/10, Greg KH <gregkh@suse.de> wrote:

> From: Greg KH <gregkh@suse.de>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: "Pavan Savoy" <pavan_savoy@ti.com>
> Cc: "Alan Cox" <alan@lxorguk.ukuu.org.uk>, marcel@holtmann.org, linux-kernel@vger.kernel.org
> Date: Wednesday, 31 March, 2010, 2:08 AM
> On Tue, Mar 30, 2010 at 09:23:23PM
> +0530, Pavan Savoy wrote:
> > Alan,
> > 
> > --- On Tue, 30/3/10, Alan Cox <alan@lxorguk.ukuu.org.uk>
> wrote:
> > 
> > > From: Alan Cox <alan@lxorguk.ukuu.org.uk>
> > > Subject: Re: [PATCH] drivers:staging: sources for
> ST core
> > > To: pavan_savoy@ti.com
> > > Cc: marcel@holtmann.org,
> gregkh@suse.de, linux-kernel@vger.kernel.org,
> pavan_savoy@yahoo.co.in
> > > Date: Tuesday, 30 March, 2010, 4:52 PM
> > > > +/* all debug macros go in here
> > > */
> > > > +#define ST_DRV_ERR(fmt, arg...)?
> printk(KERN_ERR
> > > "(stc):"fmt"\n" , ## arg)
> > > > +#if defined(DEBUG)???
> > > ??? /* limited debug messages */
> > > > +#define ST_DRV_DBG(fmt, arg...)?
> > > printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> > > > +#define ST_DRV_VER(fmt, arg...)
> > > > +#elif defined(VERBOSE)???
> > > ??? /* very verbose */
> > > > +#define ST_DRV_DBG(fmt, arg...)?
> > > printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> > > > +#define ST_DRV_VER(fmt, arg...)?
> > > printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> > > > +#else /* error msgs only */
> > > > +#define ST_DRV_DBG(fmt, arg...)
> > > > +#define ST_DRV_VER(fmt, arg...)
> > > > +#endif
> > > 
> > > As Greg said earlier - needs to be using the
> standard debug
> > > macros
> > 
> > Agree - It's all there because of the organization's
> coding standards.
> > Will correct it.
> 
> Might you also want to correct your organization's coding
> standards to
> follow the correct Linux kernel ones?  That way you
> will not have this
> problem in the future.
> 
> thanks,
> 
> greg k-h

So, something like the below is ok, I have defined my own pr_fmt, however default log level on my board is 7, and hence pr_info is a bit more annoying than usual.
So all verbose or debug messages including the data in/out of the UART are pr_debug.

>From 67bdf81bb0a60e2c76a139dc4d39208eaa03bcae Mon Sep 17 00:00:00 2001
From: Pavan Savoy <pavan_savoy@ti.com>
Date: Mon, 22 Mar 2010 13:18:31 -0400
Subject: [PATCH] drivers:staging: sources for ST core

Texas Instruments BT, FM and GPS combo chips/drivers
make use of a single TTY to communicate with the chip.
This module constitutes the core logic, TTY ldisc driver
and the exported symbols for registering/unregistering of
the protocol drivers such as BT/FM/GPS.

Signed-off-by: Pavan Savoy <pavan_savoy@ti.com>
---
 drivers/staging/ti-st/st_core.c | 1045 +++++++++++++++++++++++++++++++++++++++
 drivers/staging/ti-st/st_core.h |   92 ++++
 2 files changed, 1137 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/ti-st/st_core.c
 create mode 100644 drivers/staging/ti-st/st_core.h

diff --git a/drivers/staging/ti-st/st_core.c b/drivers/staging/ti-st/st_core.c
new file mode 100644
index 0000000..50fea1e
--- /dev/null
+++ b/drivers/staging/ti-st/st_core.c
@@ -0,0 +1,1045 @@
+/*
+ *  Shared Transport Line discipline driver Core
+ *	This hooks up ST KIM driver and ST LL driver
+ *  Copyright (C) 2009 Texas Instruments
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#define pr_fmt(fmt)	"(stc): " fmt
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/tty.h>
+
+/* understand BT, FM and GPS for now */
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+#include <net/bluetooth/hci.h>
+#include "fm.h"
+/*
+ * packet formats for fm and gps
+ * #include "gps.h"
+ */
+#include "st_core.h"
+#include "st_kim.h"
+#include "st_ll.h"
+#include "st.h"
+
+#ifdef DEBUG
+/* strings to be used for rfkill entries and by
+ * ST Core to be used for sysfs debug entry
+ */
+#define PROTO_ENTRY(type, name)	name
+const unsigned char *protocol_strngs[] = {
+	PROTO_ENTRY(ST_BT, "Bluetooth"),
+	PROTO_ENTRY(ST_FM, "FM"),
+	PROTO_ENTRY(ST_GPS, "GPS"),
+};
+#endif
+/*
+ * local data instances
+ */
+static struct st_data_s *st_gdata;
+/* function pointer pointing to either,
+ * st_kim_recv during registration to receive fw download responses
+ * st_int_recv after registration to receive proto stack responses
+ */
+void (*st_recv) (const unsigned char *data, long count);
+
+/********************************************************************/
+/* internal misc functions */
+bool is_protocol_list_empty(void)
+{
+	unsigned char i = 0;
+	pr_debug(" %s ", __func__);
+	for (i = 0; i < ST_MAX; i++) {
+		if (st_gdata->list[i] != NULL)
+			return ST_NOTEMPTY;
+		/* not empty */
+	}
+	/* list empty */
+	return ST_EMPTY;
+}
+
+/* can be called in from
+ * -- KIM (during fw download)
+ * -- ST Core (during st_write)
+ *
+ *  This is the internal write function - a wrapper
+ *  to tty->ops->write
+ */
+int st_int_write(const unsigned char *data, int count)
+{
+#ifdef VERBOSE			/* for debug */
+	int i;
+#endif
+	struct tty_struct *tty;
+	if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
+		pr_err("tty unavailable to perform write");
+		return ST_ERR_FAILURE;
+	}
+	tty = st_gdata->tty;
+#ifdef VERBOSE
+	printk(KERN_ERR "start data..\n");
+	for (i = 0; i < count; i++)	/* no newlines for each datum */
+		printk(" %x", data[i]);
+	printk(KERN_ERR "\n ..end data\n");
+#endif
+
+	return tty->ops->write(tty, data, count);
+
+}
+
+/*
+ * push the skb received to relevant
+ * protocol stacks
+ */
+void st_send_frame(enum proto_type protoid, struct sk_buff *skb)
+{
+	pr_debug(" %s(prot:%d) ", __func__, protoid);
+
+	if (unlikely
+	    (st_gdata == NULL || skb == NULL
+	     || st_gdata->list[protoid] == NULL)) {
+		pr_err("protocol %d not registered, no data to send?",
+			   protoid);
+		kfree_skb(skb);
+		return;
+	}
+	/* this cannot fail
+	 * this shouldn't take long
+	 * - should be just skb_queue_tail for the
+	 *   protocol stack driver
+	 */
+	if (likely(st_gdata->list[protoid]->recv != NULL)) {
+		if (unlikely(st_gdata->list[protoid]->recv(skb)
+			     != ST_SUCCESS)) {
+			pr_err(" proto stack %d's ->recv failed", protoid);
+			kfree_skb(skb);
+			return;
+		}
+	} else {
+		pr_err(" proto stack %d's ->recv null", protoid);
+		kfree_skb(skb);
+	}
+	pr_debug(" done %s", __func__);
+	return;
+}
+
+/*
+ * to call registration complete callbacks
+ * of all protocol stack drivers
+ */
+void st_reg_complete(char err)
+{
+	unsigned char i = 0;
+	pr_debug(" %s ", __func__);
+	for (i = 0; i < ST_MAX; i++) {
+		if (likely(st_gdata != NULL && st_gdata->list[i] != NULL &&
+			   st_gdata->list[i]->reg_complete_cb != NULL))
+			st_gdata->list[i]->reg_complete_cb(err);
+	}
+}
+
+static inline int st_check_data_len(int protoid, int len)
+{
+	register int room = skb_tailroom(st_gdata->rx_skb);
+
+	pr_debug("len %d room %d", len, room);
+
+	if (!len) {
+		/* Received packet has only packet header and
+		 * has zero length payload. So, ask ST CORE to
+		 * forward the packet to protocol driver (BT/FM/GPS)
+		 */
+		st_send_frame(protoid, st_gdata->rx_skb);
+
+	} else if (len > room) {
+		/* Received packet's payload length is larger.
+		 * We can't accommodate it in created skb.
+		 */
+		pr_err("Data length is too large len %d room %d", len,
+			   room);
+		kfree_skb(st_gdata->rx_skb);
+	} else {
+		/* Packet header has non-zero payload length and
+		 * we have enough space in created skb. Lets read
+		 * payload data */
+		st_gdata->rx_state = ST_BT_W4_DATA;
+		st_gdata->rx_count = len;
+		return len;
+	}
+
+	/* Change ST state to continue to process next
+	 * packet */
+	st_gdata->rx_state = ST_W4_PACKET_TYPE;
+	st_gdata->rx_skb = NULL;
+	st_gdata->rx_count = 0;
+
+	return 0;
+}
+
+/* internal function for action when wake-up ack
+ * received
+ */
+static inline void st_wakeup_ack(unsigned char cmd)
+{
+	register struct sk_buff *waiting_skb;
+	unsigned long flags = 0;
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	/* de-Q from waitQ and Q in txQ now that the
+	 * chip is awake
+	 */
+	while ((waiting_skb = skb_dequeue(&st_gdata->tx_waitq)))
+		skb_queue_tail(&st_gdata->txq, waiting_skb);
+
+	/* state forwarded to ST LL */
+	st_ll_sleep_state((unsigned long)cmd);
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	/* wake up to send the recently copied skbs from waitQ */
+	st_tx_wakeup(st_gdata);
+}
+
+/* Decodes received RAW data and forwards to corresponding
+ * client drivers (Bluetooth,FM,GPS..etc).
+ *
+ */
+void st_int_recv(const unsigned char *data, long count)
+{
+	register char *ptr;
+	struct hci_event_hdr *eh;
+	struct hci_acl_hdr *ah;
+	struct hci_sco_hdr *sh;
+	struct fm_event_hdr *fm;
+	struct gps_event_hdr *gps;
+	register int len = 0, type = 0, dlen = 0;
+	static enum proto_type protoid = ST_MAX;
+
+	pr_debug("count %ld rx_state %ld"
+		   "rx_count %ld", count, st_gdata->rx_state,
+		   st_gdata->rx_count);
+
+	ptr = (char *)data;
+	/* tty_receive sent null ? */
+	if (unlikely(ptr == NULL)) {
+		pr_err(" received null from TTY ");
+		return;
+	}
+
+	/* Decode received bytes here */
+	while (count) {
+		if (st_gdata->rx_count) {
+			len = min_t(unsigned int, st_gdata->rx_count, count);
+			memcpy(skb_put(st_gdata->rx_skb, len), ptr, len);
+			st_gdata->rx_count -= len;
+			count -= len;
+			ptr += len;
+
+			if (st_gdata->rx_count)
+				continue;
+
+			/* Check ST RX state machine , where are we? */
+			switch (st_gdata->rx_state) {
+
+				/* Waiting for complete packet ? */
+			case ST_BT_W4_DATA:
+				pr_debug("Complete pkt received");
+
+				/* Ask ST CORE to forward
+				 * the packet to protocol driver */
+				st_send_frame(protoid, st_gdata->rx_skb);
+
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_skb = NULL;
+				protoid = ST_MAX;	/* is this required ? */
+				continue;
+
+				/* Waiting for Bluetooth event header ? */
+			case ST_BT_W4_EVENT_HDR:
+				eh = (struct hci_event_hdr *)st_gdata->rx_skb->
+				    data;
+
+				pr_debug("Event header: evt 0x%2.2x"
+					   "plen %d", eh->evt, eh->plen);
+
+				st_check_data_len(protoid, eh->plen);
+				continue;
+
+				/* Waiting for Bluetooth acl header ? */
+			case ST_BT_W4_ACL_HDR:
+				ah = (struct hci_acl_hdr *)st_gdata->rx_skb->
+				    data;
+				dlen = __le16_to_cpu(ah->dlen);
+
+				pr_debug("ACL header: dlen %d", dlen);
+
+				st_check_data_len(protoid, dlen);
+				continue;
+
+				/* Waiting for Bluetooth sco header ? */
+			case ST_BT_W4_SCO_HDR:
+				sh = (struct hci_sco_hdr *)st_gdata->rx_skb->
+				    data;
+
+				pr_debug("SCO header: dlen %d", sh->dlen);
+
+				st_check_data_len(protoid, sh->dlen);
+				continue;
+			case ST_FM_W4_EVENT_HDR:
+				fm = (struct fm_event_hdr *)st_gdata->rx_skb->
+				    data;
+				pr_debug("FM Header: ");
+				st_check_data_len(ST_FM, fm->plen);
+				continue;
+				/* TODO : Add GPS packet machine logic here */
+			case ST_GPS_W4_EVENT_HDR:
+				/* [0x09 pkt hdr][R/W byte][2 byte len] */
+				gps = (struct gps_event_hdr *)st_gdata->rx_skb->
+				     data;
+				pr_debug("GPS Header: ");
+				st_check_data_len(ST_GPS, gps->plen);
+				continue;
+			}	/* end of switch rx_state */
+		}
+
+		/* end of if rx_count */
+		/* Check first byte of packet and identify module
+		 * owner (BT/FM/GPS) */
+		switch (*ptr) {
+
+			/* Bluetooth event packet? */
+		case HCI_EVENT_PKT:
+			pr_debug("Event packet");
+			st_gdata->rx_state = ST_BT_W4_EVENT_HDR;
+			st_gdata->rx_count = HCI_EVENT_HDR_SIZE;
+			type = HCI_EVENT_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Bluetooth acl packet? */
+		case HCI_ACLDATA_PKT:
+			pr_debug("ACL packet");
+			st_gdata->rx_state = ST_BT_W4_ACL_HDR;
+			st_gdata->rx_count = HCI_ACL_HDR_SIZE;
+			type = HCI_ACLDATA_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Bluetooth sco packet? */
+		case HCI_SCODATA_PKT:
+			pr_debug("SCO packet");
+			st_gdata->rx_state = ST_BT_W4_SCO_HDR;
+			st_gdata->rx_count = HCI_SCO_HDR_SIZE;
+			type = HCI_SCODATA_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Channel 8(FM) packet? */
+		case ST_FM_CH8_PKT:
+			pr_debug("FM CH8 packet");
+			type = ST_FM_CH8_PKT;
+			st_gdata->rx_state = ST_FM_W4_EVENT_HDR;
+			st_gdata->rx_count = FM_EVENT_HDR_SIZE;
+			protoid = ST_FM;
+			break;
+
+			/* Channel 9(GPS) packet? */
+		case 0x9:	/*ST_LL_GPS_CH9_PKT */
+			pr_debug("GPS CH9 packet");
+			type = 0x9;	/* ST_LL_GPS_CH9_PKT; */
+			protoid = ST_GPS;
+			st_gdata->rx_state = ST_GPS_W4_EVENT_HDR;
+			st_gdata->rx_count = 3;	/* GPS_EVENT_HDR_SIZE -1*/
+			break;
+		case LL_SLEEP_IND:
+		case LL_SLEEP_ACK:
+		case LL_WAKE_UP_IND:
+			/* this takes appropriate action based on
+			 * sleep state received --
+			 */
+			st_ll_sleep_state(*ptr);
+			ptr++;
+			count--;
+			continue;
+		case LL_WAKE_UP_ACK:
+			/* wake up ack received */
+			st_wakeup_ack(*ptr);
+			ptr++;
+			count--;
+			continue;
+			/* Unknow packet? */
+		default:
+			pr_err("Unknown packet type %2.2x", (__u8) *ptr);
+			ptr++;
+			count--;
+			continue;
+		};
+		ptr++;
+		count--;
+
+		switch (protoid) {
+		case ST_BT:
+			/* Allocate new packet to hold received data */
+			st_gdata->rx_skb =
+			    bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				pr_err("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			bt_cb(st_gdata->rx_skb)->pkt_type = type;
+			break;
+		case ST_FM:	/* for FM */
+			st_gdata->rx_skb =
+			    alloc_skb(FM_MAX_FRAME_SIZE, GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				pr_err("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			/* place holder 0x08 */
+			skb_reserve(st_gdata->rx_skb, 1);
+			st_gdata->rx_skb->cb[0] = ST_FM_CH8_PKT;
+			break;
+		case ST_GPS:
+			/* for GPS */
+			st_gdata->rx_skb =
+			    alloc_skb(100 /*GPS_MAX_FRAME_SIZE */ , GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				pr_err("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			/* place holder 0x09 */
+			skb_reserve(st_gdata->rx_skb, 1);
+			st_gdata->rx_skb->cb[0] = 0x09;	/*ST_GPS_CH9_PKT; */
+			break;
+		case ST_MAX:
+			break;
+		}
+	}
+	pr_debug("done %s", __func__);
+	return;
+}
+
+/* internal de-Q function
+ * -- return previous in-completely written skb
+ *  or return the skb in the txQ
+ */
+struct sk_buff *st_int_dequeue(struct st_data_s *st_data)
+{
+	struct sk_buff *returning_skb;
+
+	pr_debug("%s", __func__);
+	/* if the previous skb wasn't written completely
+	 */
+	if (st_gdata->tx_skb != NULL) {
+		returning_skb = st_gdata->tx_skb;
+		st_gdata->tx_skb = NULL;
+		return returning_skb;
+	}
+
+	/* de-Q from the txQ always if previous write is complete */
+	return skb_dequeue(&st_gdata->txq);
+}
+
+/* internal Q-ing function
+ * will either Q the skb to txq or the tx_waitq
+ * depending on the ST LL state
+ *
+ * lock the whole func - since ll_getstate and Q-ing should happen
+ * in one-shot
+ */
+void st_int_enqueue(struct sk_buff *skb)
+{
+	unsigned long flags = 0;
+
+	pr_debug("%s", __func__);
+	/* this function can be invoked in more then one context.
+	 * so have a lock */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	switch (st_ll_getstate()) {
+	case ST_LL_AWAKE:
+		pr_debug("ST LL is AWAKE, sending normally");
+		skb_queue_tail(&st_gdata->txq, skb);
+		break;
+	case ST_LL_ASLEEP_TO_AWAKE:
+		skb_queue_tail(&st_gdata->tx_waitq, skb);
+		break;
+	case ST_LL_AWAKE_TO_ASLEEP:	/* host cannot be in this state */
+		pr_err("ST LL is illegal state(%ld),"
+			   "purging received skb.", st_ll_getstate());
+		kfree_skb(skb);
+		break;
+
+	case ST_LL_ASLEEP:
+		/* call a function of ST LL to put data
+		 * in tx_waitQ and wake_ind in txQ
+		 */
+		skb_queue_tail(&st_gdata->tx_waitq, skb);
+		st_ll_wakeup();
+		break;
+	default:
+		pr_err("ST LL is illegal state(%ld),"
+			   "purging received skb.", st_ll_getstate());
+		kfree_skb(skb);
+		break;
+	}
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+	pr_debug("done %s", __func__);
+	return;
+}
+
+/*
+ * internal wakeup function
+ * called from either
+ * - TTY layer when write's finished
+ * - st_write (in context of the protocol stack)
+ */
+void st_tx_wakeup(struct st_data_s *st_data)
+{
+	struct sk_buff *skb;
+	unsigned long flags;	/* for irq save flags */
+	pr_debug("%s", __func__);
+	/* check for sending & set flag sending here */
+	if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) {
+		pr_debug("ST already sending");
+		/* keep sending */
+		set_bit(ST_TX_WAKEUP, &st_data->tx_state);
+		return;
+		/* TX_WAKEUP will be checked in another
+		 * context
+		 */
+	}
+	do {			/* come back if st_tx_wakeup is set */
+		/* woke-up to write */
+		clear_bit(ST_TX_WAKEUP, &st_data->tx_state);
+		while ((skb = st_int_dequeue(st_data))) {
+			int len;
+			spin_lock_irqsave(&st_data->lock, flags);
+			/* enable wake-up from TTY */
+			set_bit(TTY_DO_WRITE_WAKEUP, &st_data->tty->flags);
+			len = st_int_write(skb->data, skb->len);
+			skb_pull(skb, len);
+			/* if skb->len = len as expected, skb->len=0 */
+			if (skb->len) {
+				/* would be the next skb to be sent */
+				st_data->tx_skb = skb;
+				spin_unlock_irqrestore(&st_gdata->lock, flags);
+				break;
+			}
+			kfree_skb(skb);
+			spin_unlock_irqrestore(&st_gdata->lock, flags);
+		}
+		/* if wake-up is set in another context- restart sending */
+	} while (test_bit(ST_TX_WAKEUP, &st_data->tx_state));
+
+	/* clear flag sending */
+	clear_bit(ST_TX_SENDING, &st_data->tx_state);
+}
+
+/********************************************************************/
+/* functions called from ST KIM
+*/
+void kim_st_list_protocols(char *buf)
+{
+	unsigned long flags = 0;
+#ifdef DEBUG
+	unsigned char i = ST_MAX;
+#endif
+	spin_lock_irqsave(&st_gdata->lock, flags);
+#ifdef DEBUG			/* more detailed log */
+	for (i = 0; i < ST_MAX; i++) {
+		if (i == 0) {
+			sprintf(buf, "%s is %s", protocol_strngs[i],
+				st_gdata->list[i] !=
+				NULL ? "Registered" : "Unregistered");
+		} else {
+			sprintf(buf, "%s\n%s is %s", buf, protocol_strngs[i],
+				st_gdata->list[i] !=
+				NULL ? "Registered" : "Unregistered");
+		}
+	}
+	sprintf(buf, "%s\n", buf);
+#else /* limited info */
+	sprintf(buf, "BT=%c\nFM=%c\nGPS=%c\n",
+		st_gdata->list[ST_BT] != NULL ? 'R' : 'U',
+		st_gdata->list[ST_FM] != NULL ? 'R' : 'U',
+		st_gdata->list[ST_GPS] != NULL ? 'R' : 'U');
+#endif
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+}
+
+/********************************************************************/
+/*
+ * functions called from protocol stack drivers
+ * to be EXPORT-ed
+ */
+long st_register(struct st_proto_s *new_proto)
+{
+	long err = ST_SUCCESS;
+	unsigned long flags = 0;
+
+	pr_debug("%s(%d) ", __func__, new_proto->type);
+	if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL
+	    || new_proto->reg_complete_cb == NULL) {
+		pr_err("gdata/new_proto/recv or reg_complete_cb not ready");
+		return ST_ERR_FAILURE;
+	}
+
+	if (new_proto->type < ST_BT || new_proto->type >= ST_MAX) {
+		pr_err("protocol %d not supported", new_proto->type);
+		return ST_ERR_NOPROTO;
+	}
+
+	if (st_gdata->list[new_proto->type] != NULL) {
+		pr_err("protocol %d already registered", new_proto->type);
+		return ST_ERR_ALREADY;
+	}
+
+	/* can be from process context only */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) {
+		pr_debug(" ST_REG_IN_PROGRESS:%d ", new_proto->type);
+		/* fw download in progress */
+		st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+
+		set_bit(ST_REG_PENDING, &st_gdata->st_state);
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return ST_ERR_PENDING;
+	} else if (is_protocol_list_empty() == ST_EMPTY) {
+		pr_debug(" protocol list empty :%d ", new_proto->type);
+		set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+		st_recv = st_kim_recv;
+
+		/* release lock previously held - re-locked below */
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+		/* enable the ST LL - to set default chip state */
+		st_ll_enable();
+		/* this may take a while to complete
+		 * since it involves BT fw download
+		 */
+		err = st_kim_start();
+		if (err != ST_SUCCESS) {
+			clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+			if ((is_protocol_list_empty() != ST_EMPTY) &&
+			    (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+				pr_err(" KIM failure complete callback ");
+				st_reg_complete(ST_ERR_FAILURE);
+			}
+
+			return ST_ERR_FAILURE;
+		}
+
+		/* the protocol might require other gpios to be toggled
+		 */
+		st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+
+		clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+		st_recv = st_int_recv;
+
+		/* this is where all pending registration
+		 * are signalled to be complete by calling callback functions
+		 */
+		if ((is_protocol_list_empty() != ST_EMPTY) &&
+		    (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+			pr_debug(" call reg complete callback ");
+			st_reg_complete(ST_SUCCESS);
+		}
+		clear_bit(ST_REG_PENDING, &st_gdata->st_state);
+
+		/* check for already registered once more,
+		 * since the above check is old
+		 */
+		if (st_gdata->list[new_proto->type] != NULL) {
+			pr_err(" proto %d already registered ",
+				   new_proto->type);
+			return ST_ERR_ALREADY;
+		}
+
+		spin_lock_irqsave(&st_gdata->lock, flags);
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return err;
+	}
+	/* if fw is already downloaded & new stack registers protocol */
+	else {
+		switch (new_proto->type) {
+		case ST_BT:
+			/* do nothing */
+			break;
+		case ST_FM:
+		case ST_GPS:
+			st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+			break;
+		case ST_MAX:
+		default:
+			pr_err("%d protocol not supported",
+				   new_proto->type);
+			err = ST_ERR_NOPROTO;
+			/* something wrong */
+			break;
+		}
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+
+		/* lock already held before entering else */
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return err;
+	}
+	pr_debug("done %s(%d) ", __func__, new_proto->type);
+}
+EXPORT_SYMBOL_GPL(st_register);
+
+/* to unregister a protocol -
+ * to be called from protocol stack driver
+ */
+long st_unregister(enum proto_type type)
+{
+	long err = ST_SUCCESS;
+	unsigned long flags = 0;
+
+	pr_debug("%s: %d ", __func__, type);
+
+	if (type < ST_BT || type >= ST_MAX) {
+		pr_err(" protocol %d not supported", type);
+		return ST_ERR_NOPROTO;
+	}
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	if (st_gdata->list[type] == NULL) {
+		pr_err(" protocol %d not registered", type);
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return ST_ERR_NOPROTO;
+	}
+
+	st_gdata->list[type] = NULL;
+
+	/* kim ignores BT in the below function
+	 * and handles the rest, BT is toggled
+	 * only in kim_start and kim_stop
+	 */
+	st_kim_chip_toggle(type, KIM_GPIO_INACTIVE);
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	if ((is_protocol_list_empty() == ST_EMPTY) &&
+	    (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+		pr_debug(" all protocols unregistered ");
+
+		/* stop traffic on tty */
+		if (st_gdata->tty) {
+			tty_ldisc_flush(st_gdata->tty);
+			stop_tty(st_gdata->tty);
+		}
+
+		/* all protocols now unregistered */
+		st_kim_stop();
+		/* disable ST LL */
+		st_ll_disable();
+	}
+	return err;
+}
+
+/*
+ * called in protocol stack drivers
+ * via the write function pointer
+ */
+long st_write(struct sk_buff *skb)
+{
+#ifdef DEBUG
+	enum proto_type protoid = ST_MAX;
+#endif
+	long len;
+	struct st_data_s *st_data = st_gdata;
+
+	if (unlikely(skb == NULL || st_gdata == NULL
+		|| st_gdata->tty == NULL)) {
+		pr_err("data/tty unavailable to perform write");
+		return ST_ERR_FAILURE;
+	}
+#ifdef DEBUG			/* open-up skb to read the 1st byte */
+	switch (skb->data[0]) {
+	case HCI_COMMAND_PKT:
+	case HCI_ACLDATA_PKT:
+	case HCI_SCODATA_PKT:
+		protoid = ST_BT;
+		break;
+	case ST_FM_CH8_PKT:
+		protoid = ST_FM;
+		break;
+	case 0x09:
+		protoid = ST_GPS;
+		break;
+	}
+	if (unlikely(st_gdata->list[protoid] == NULL)) {
+		pr_err(" protocol %d not registered, and writing? ",
+			   protoid);
+		return ST_ERR_FAILURE;
+	}
+#endif
+	pr_debug("%d to be written", skb->len);
+	len = skb->len;
+
+	/* st_ll to decide where to enqueue the skb */
+	st_int_enqueue(skb);
+	/* wake up */
+	st_tx_wakeup(st_data);
+
+	/* return number of bytes written */
+	return len;
+}
+
+/* for protocols making use of shared transport */
+EXPORT_SYMBOL_GPL(st_unregister);
+
+/********************************************************************/
+/*
+ * functions called from TTY layer
+ */
+static int st_tty_open(struct tty_struct *tty)
+{
+	int err = ST_SUCCESS;
+	pr_debug("%s ", __func__);
+
+	st_gdata->tty = tty;
+
+	/* don't do an wakeup for now */
+	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+
+	/* mem already allocated
+	 */
+	tty->receive_room = 65536;
+	/* Flush any pending characters in the driver and discipline. */
+	tty_ldisc_flush(tty);
+	tty_driver_flush_buffer(tty);
+	/*
+	 * signal to UIM via KIM that -
+	 * installation of N_TI_WL ldisc is complete
+	 */
+	st_kim_complete();
+	pr_debug("done %s", __func__);
+	return err;
+}
+
+static void st_tty_close(struct tty_struct *tty)
+{
+	unsigned char i = ST_MAX;
+	unsigned long flags = 0;
+
+	pr_debug("%s ", __func__);
+
+	/* TODO:
+	 * if a protocol has been registered & line discipline
+	 * un-installed for some reason - what should be done ?
+	 */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	for (i = ST_BT; i < ST_MAX; i++) {
+		if (st_gdata->list[i] != NULL)
+			pr_err("%d not un-registered", i);
+		st_gdata->list[i] = NULL;
+	}
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+	/*
+	 * signal to UIM via KIM that -
+	 * N_TI_WL ldisc is un-installed
+	 */
+	st_kim_complete();
+	st_gdata->tty = NULL;
+	/* Flush any pending characters in the driver and discipline. */
+	tty_ldisc_flush(tty);
+	tty_driver_flush_buffer(tty);
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	/* empty out txq and tx_waitq */
+	skb_queue_purge(&st_gdata->txq);
+	skb_queue_purge(&st_gdata->tx_waitq);
+	/* reset the TTY Rx states of ST */
+	st_gdata->rx_count = 0;
+	st_gdata->rx_state = ST_W4_PACKET_TYPE;
+	kfree_skb(st_gdata->rx_skb);
+	st_gdata->rx_skb = NULL;
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	pr_debug("%s: done ", __func__);
+}
+
+static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
+			   char *tty_flags, int count)
+{
+#ifdef VERBOSE
+	long i;
+	printk(KERN_ERR "incoming data...\n");
+	for (i = 0; i < count; i++)
+		printk(" %x", data[i]);
+	printk(KERN_ERR "\n.. data end\n");
+#endif
+
+	/*
+	 * if fw download is in progress then route incoming data
+	 * to KIM for validation
+	 */
+	st_recv(data, count);
+	pr_debug("done %s", __func__);
+}
+
+/* wake-up function called in from the TTY layer
+ * inside the internal wakeup function will be called
+ */
+static void st_tty_wakeup(struct tty_struct *tty)
+{
+	pr_debug("%s ", __func__);
+	/* don't do an wakeup for now */
+	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+
+	/* call our internal wakeup */
+	st_tx_wakeup((void *)st_gdata);
+}
+
+static void st_tty_flush_buffer(struct tty_struct *tty)
+{
+	pr_debug("%s ", __func__);
+
+	kfree_skb(st_gdata->tx_skb);
+	st_gdata->tx_skb = NULL;
+
+	tty->ops->flush_buffer(tty);
+	return;
+}
+
+/********************************************************************/
+static int __init st_core_init(void)
+{
+	long err;
+	static struct tty_ldisc_ops *st_ldisc_ops;
+
+	/* populate and register to TTY line discipline */
+	st_ldisc_ops = kzalloc(sizeof(*st_ldisc_ops), GFP_KERNEL);
+	if (!st_ldisc_ops) {
+		pr_err("no mem to allocate");
+		return -ENOMEM;
+	}
+
+	st_ldisc_ops->magic = TTY_LDISC_MAGIC;
+	st_ldisc_ops->name = "n_st";	/*"n_hci"; */
+	st_ldisc_ops->open = st_tty_open;
+	st_ldisc_ops->close = st_tty_close;
+	st_ldisc_ops->receive_buf = st_tty_receive;
+	st_ldisc_ops->write_wakeup = st_tty_wakeup;
+	st_ldisc_ops->flush_buffer = st_tty_flush_buffer;
+	st_ldisc_ops->owner = THIS_MODULE;
+
+	err = tty_register_ldisc(N_TI_WL, st_ldisc_ops);
+	if (err) {
+		pr_err("error registering %d line discipline %ld",
+			   N_TI_WL, err);
+		kfree(st_ldisc_ops);
+		return err;
+	}
+	pr_debug("registered n_shared line discipline");
+
+	st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL);
+	if (!st_gdata) {
+		pr_err("memory allocation failed");
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc %ld", err);
+		kfree(st_ldisc_ops);
+		err = -ENOMEM;
+		return err;
+	}
+
+	/* Initialize ST TxQ and Tx waitQ queue head. All BT/FM/GPS module skb's
+	 * will be pushed in this queue for actual transmission.
+	 */
+	skb_queue_head_init(&st_gdata->txq);
+	skb_queue_head_init(&st_gdata->tx_waitq);
+
+	/* Locking used in st_int_enqueue() to avoid multiple execution */
+	spin_lock_init(&st_gdata->lock);
+
+	/* ldisc_ops ref to be only used in __exit of module */
+	st_gdata->ldisc_ops = st_ldisc_ops;
+
+	err = st_kim_init();
+	if (err) {
+		pr_err("error during kim initialization(%ld)", err);
+		kfree(st_gdata);
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc");
+		kfree(st_ldisc_ops);
+		return -1;
+	}
+
+	err = st_ll_init();
+	if (err) {
+		pr_err("error during st_ll initialization(%ld)", err);
+		err = st_kim_deinit();
+		kfree(st_gdata);
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc");
+		kfree(st_ldisc_ops);
+		return -1;
+	}
+	return 0;
+}
+
+static void __exit st_core_exit(void)
+{
+	long err;
+	/* internal module cleanup */
+	err = st_ll_deinit();
+	if (err)
+		pr_err("error during deinit of ST LL %ld", err);
+	err = st_kim_deinit();
+	if (err)
+		pr_err("error during deinit of ST KIM %ld", err);
+
+	if (st_gdata != NULL) {
+		/* Free ST Tx Qs and skbs */
+		skb_queue_purge(&st_gdata->txq);
+		skb_queue_purge(&st_gdata->tx_waitq);
+		kfree_skb(st_gdata->rx_skb);
+		kfree_skb(st_gdata->tx_skb);
+		/* TTY ldisc cleanup */
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			pr_err("unable to un-register ldisc %ld", err);
+		kfree(st_gdata->ldisc_ops);
+		/* free the global data pointer */
+		kfree(st_gdata);
+	}
+}
+
+module_init(st_core_init);
+module_exit(st_core_exit);
+MODULE_AUTHOR("Pavan Savoy <pavan_savoy@ti.com>");
+MODULE_DESCRIPTION("Shared Transport Driver for TI BT/FM/GPS combo chips ");
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/ti-st/st_core.h b/drivers/staging/ti-st/st_core.h
new file mode 100644
index 0000000..ff0d9d1
--- /dev/null
+++ b/drivers/staging/ti-st/st_core.h
@@ -0,0 +1,92 @@
+/*
+ *  Shared Transport Core header file
+ *
+ *  Copyright (C) 2009 Texas Instruments
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef ST_CORE_H
+#define ST_CORE_H
+
+#include <linux/skbuff.h>
+#include "st.h"
+
+/* states of protocol list */
+#define ST_NOTEMPTY	1
+#define ST_EMPTY	0
+
+/*
+ * possible st_states
+ */
+#define ST_INITIALIZING		1
+#define ST_REG_IN_PROGRESS	2
+#define ST_REG_PENDING		3
+#define ST_WAITING_FOR_RESP	4
+
+/*
+ * local data required for ST/KIM/ST-HCI-LL
+ */
+struct st_data_s {
+	unsigned long st_state;
+/*
+ * an instance of tty_struct & ldisc ops to move around
+ */
+	struct tty_struct *tty;
+	struct tty_ldisc_ops *ldisc_ops;
+/*
+ * the tx skb -
+ * if the skb is already dequeued and the tty failed to write the same
+ * maintain the skb to write in the next transaction
+ */
+	struct sk_buff *tx_skb;
+#define ST_TX_SENDING	1
+#define ST_TX_WAKEUP	2
+	unsigned long tx_state;
+/*
+ * list of protocol registered
+ */
+	struct st_proto_s *list[ST_MAX];
+/*
+ * lock
+ */
+	unsigned long rx_state;
+	unsigned long rx_count;
+	struct sk_buff *rx_skb;
+	struct sk_buff_head txq, tx_waitq;
+	spinlock_t lock;	/* ST LL state lock  */
+};
+
+/* point this to tty->driver->write or tty->ops->write
+ * depending upon the kernel version
+ */
+int st_int_write(const unsigned char *, int);
+/* internal write function, passed onto protocol drivers
+ * via the write function ptr of protocol struct
+ */
+long st_write(struct sk_buff *);
+/* function to be called from ST-LL
+ */
+void st_ll_send_frame(enum proto_type, struct sk_buff *);
+/* internal wake up function */
+void st_tx_wakeup(struct st_data_s *st_data);
+
+#define GPS_STUB_TEST
+#ifdef GPS_STUB_TEST
+int gps_chrdrv_stub_write(const unsigned char*, int);
+void gps_chrdrv_stub_init(void);
+#endif
+
+#endif /*ST_CORE_H */
-- 
1.5.4.3




> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-30 15:53       ` Pavan Savoy
@ 2010-03-30 20:38         ` Greg KH
  2010-03-30 21:05           ` Pavan Savoy
  0 siblings, 1 reply; 27+ messages in thread
From: Greg KH @ 2010-03-30 20:38 UTC (permalink / raw)
  To: Pavan Savoy; +Cc: Alan Cox, marcel, linux-kernel

On Tue, Mar 30, 2010 at 09:23:23PM +0530, Pavan Savoy wrote:
> Alan,
> 
> --- On Tue, 30/3/10, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> 
> > From: Alan Cox <alan@lxorguk.ukuu.org.uk>
> > Subject: Re: [PATCH] drivers:staging: sources for ST core
> > To: pavan_savoy@ti.com
> > Cc: marcel@holtmann.org, gregkh@suse.de, linux-kernel@vger.kernel.org, pavan_savoy@yahoo.co.in
> > Date: Tuesday, 30 March, 2010, 4:52 PM
> > > +/* all debug macros go in here
> > */
> > > +#define ST_DRV_ERR(fmt, arg...)? printk(KERN_ERR
> > "(stc):"fmt"\n" , ## arg)
> > > +#if defined(DEBUG)???
> > ??? /* limited debug messages */
> > > +#define ST_DRV_DBG(fmt, arg...)?
> > printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> > > +#define ST_DRV_VER(fmt, arg...)
> > > +#elif defined(VERBOSE)???
> > ??? /* very verbose */
> > > +#define ST_DRV_DBG(fmt, arg...)?
> > printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> > > +#define ST_DRV_VER(fmt, arg...)?
> > printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> > > +#else /* error msgs only */
> > > +#define ST_DRV_DBG(fmt, arg...)
> > > +#define ST_DRV_VER(fmt, arg...)
> > > +#endif
> > 
> > As Greg said earlier - needs to be using the standard debug
> > macros
> 
> Agree - It's all there because of the organization's coding standards.
> Will correct it.

Might you also want to correct your organization's coding standards to
follow the correct Linux kernel ones?  That way you will not have this
problem in the future.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-30 11:22     ` Alan Cox
@ 2010-03-30 15:53       ` Pavan Savoy
  2010-03-30 20:38         ` Greg KH
  0 siblings, 1 reply; 27+ messages in thread
From: Pavan Savoy @ 2010-03-30 15:53 UTC (permalink / raw)
  To: Alan Cox; +Cc: marcel, gregkh, linux-kernel

Alan,

--- On Tue, 30/3/10, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> From: Alan Cox <alan@lxorguk.ukuu.org.uk>
> Subject: Re: [PATCH] drivers:staging: sources for ST core
> To: pavan_savoy@ti.com
> Cc: marcel@holtmann.org, gregkh@suse.de, linux-kernel@vger.kernel.org, pavan_savoy@yahoo.co.in
> Date: Tuesday, 30 March, 2010, 4:52 PM
> > +/* all debug macros go in here
> */
> > +#define ST_DRV_ERR(fmt, arg...)  printk(KERN_ERR
> "(stc):"fmt"\n" , ## arg)
> > +#if defined(DEBUG)   
>     /* limited debug messages */
> > +#define ST_DRV_DBG(fmt, arg...) 
> printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> > +#define ST_DRV_VER(fmt, arg...)
> > +#elif defined(VERBOSE)   
>     /* very verbose */
> > +#define ST_DRV_DBG(fmt, arg...) 
> printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> > +#define ST_DRV_VER(fmt, arg...) 
> printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> > +#else /* error msgs only */
> > +#define ST_DRV_DBG(fmt, arg...)
> > +#define ST_DRV_VER(fmt, arg...)
> > +#endif
> 
> As Greg said earlier - needs to be using the standard debug
> macros

Agree - It's all there because of the organization's coding standards.
Will correct it.

> 
> > +/*
> > + * local data instances
> > + */
> > +static struct st_data_s *st_gdata;
> > +/* function pointer pointing to either,
> > + * st_kim_recv during registration to receive fw
> download responses
> > + * st_int_recv after registration to receive proto
> stack responses
> > + */
> > +void (*st_recv) (const unsigned char *data, long
> count);
> 
> Need some form of context so you can have multiple device
> instances and
> avoid games with globals (which always end up in pain)

Yes, platform device context ? as in per-device ?
However, would face a problem (as mentioned in other mail) - 
which is when a BT/FM driver which are like client drivers want to use this line discipline, do they need to know which context this needs to go into ?

> > +
> >
> +/********************************************************************/
> > +/* internal misc functions */
> > +bool is_protocol_list_empty(void)
> > +{
> > +    unsigned char i = 0;
> > +    ST_DRV_DBG(" %s ", __func__);
> > +    for (i = 0; i < ST_MAX; i++) {
> > +        if
> (st_gdata->list[i] != NULL)
> > +       
>     return ST_NOTEMPTY;
> > +        /* not empty
> */
> > +    }
> > +    /* list empty */
> > +    return ST_EMPTY;
> 
> Why not just keep a count of entries you've added/removed
> ?

One more variable ? to st_gdata ? done. Sounds simple.
> 
> > + *  This is the internal write function - a
> wrapper
> > + *  to tty->ops->write
> > + */
> > +int st_int_write(const unsigned char *data, int
> count)
> > +{
> > +#ifdef VERBOSE       
>     /* for debug */
> > +    int i;
> > +#endif
> > +    struct tty_struct *tty;
> > +    if (unlikely(st_gdata == NULL ||
> st_gdata->tty == NULL)) {
> > +        ST_DRV_ERR("tty
> unavailable to perform write");
> 
> You need to use the tty pointer passed, you don't want to
> walk
> tty->something and back because you may race a hangup.
> Plus you would
> need to manage the krefs (object references)

Do I need to do it in tty_open and _release ?
Because I don't have anything much to release when tty closes.
All I have to do is done in tty_close. 

> > +        return
> ST_ERR_FAILURE;
> 
> Should be using Linux error codes for upstream. A global
> search/replace
> of the ST_ERR_xxx for a similar -Efoo code will do the
> trick I think

Ok, But is it ok, to maintain codes, internally among ST/BT/FM drivers ?
 
> > +/*
> > + * push the skb received to relevant
> > + * protocol stacks
> > + */
> > +void st_send_frame(enum proto_type protoid, struct
> sk_buff *skb)
> > +{
> > +    ST_DRV_DBG(" %s(prot:%d) ",
> __func__, protoid);
> > +
> > +    if (unlikely
> > +        (st_gdata == NULL ||
> skb == NULL
> > +         ||
> st_gdata->list[protoid] == NULL)) {
> > +       
> ST_DRV_ERR("protocol %d not registered, no data to send?",
> > +       
>        protoid);
> > +       
> kfree_skb(skb);
> > +        return;
> > +    }
> 
> What is the locking rule to ensure I don't unregister a
> protocol as send
> frame is called ?

send_frame is called from st_int_recv - which is a SOFT-IRQ I believe, So do I really need that ?

> 
> > + * to call registration complete callbacks
> > + * of all protocol stack drivers
> > + */
> > +void st_reg_complete(char err)
> > +{
> > +    unsigned char i = 0;
> > +    ST_DRV_DBG(" %s ", __func__);
> > +    for (i = 0; i < ST_MAX; i++) {
> > +        if
> (likely(st_gdata != NULL && st_gdata->list[i] !=
> NULL &&
> 
> Except on very hot paths that go odd ways likely and
> unlikely are
> normally a loss.

point taken.
> 
> > +static inline int st_check_data_len(int protoid, int
> len)
> > +{
> > +    register int room =
> skb_tailroom(st_gdata->rx_skb);
> 
> No need to use register - gcc is generally smarter than
> humans here,
> especially in the long term. You may optimise perfectly for
> a single
> cpu/compiler revision but not for all

Ha, this one's a copy/paste piece from hci_ll.c's recv function.
 
> 
> > +/* Decodes received RAW data and forwards to
> corresponding
> > + * client drivers (Bluetooth,FM,GPS..etc).
> > + *
> > + */
> > +void st_int_recv(const unsigned char *data, long
> count)
> 
> There are lots of globals here, in part it seems due to the
> lack of any
> kind of context being passed around
> 

This global function pointer as such is not a necessity.
st_recv can point to st_kim_recv (response to firmware download) or st_int_recv (response to commands).

They are sort of mutually exclusive, firmware will be downloaded once.
and once ready, chip will always use cmd/response st_int_recv.

> 
> >
> > +    /* this function can be invoked in
> more then one context.
> > +     * so have a lock */
> 
> It's a good idea to document what data is locked and what
> the data
> locking assumptions are. I'm finding that part of the code
> quite hard to
> follow

Ok.

> 
> > +/*
> > + * internal wakeup function
> > + * called from either
> > + * - TTY layer when write's finished
> > + * - st_write (in context of the protocol stack)
> > + */
> > +void st_tx_wakeup(struct st_data_s *st_data)
> 
> 
> > +        while ((skb =
> st_int_dequeue(st_data))) {
> 
> Called in two paths but st_int_dequeue seems to have no
> internal locking

The 2nd path doesn't come until the int_dequeue at all, i.e it would know ST_TX_SENDING, and would queue the skb and return.
I remember there was one lock here, removed when I started to have problem on SMP.

> 
> > +/* functions called from ST KIM
> > +*/
> > +void kim_st_list_protocols(char *buf)
> > +{
> > +    unsigned long flags = 0;
> > +#ifdef DEBUG
> > +    unsigned char i = ST_MAX;
> > +#endif
> > +   
> spin_lock_irqsave(&st_gdata->lock, flags);
> > +#ifdef DEBUG       
>     /* more detailed log */
> > +    for (i = 0; i < ST_MAX; i++) {
> > +        if (i == 0) {
> > +       
>     sprintf(buf, "%s is %s",
> protocol_strngs[i],
> > +       
>         st_gdata->list[i]
> !=
> > +       
>         NULL ? "Registered" :
> "Unregistered");
> 
> Always a good idea to use snprintf and track size (plus
> pass buffer size)
> it avoida accidents later. Or also see the seq_ interface
> when you want
> to build proc type files.

Ok, the whole thing will go off.
The plan is to use /dev/rfkill and avoid the sysfs entry altogether.

> >
> +/********************************************************************/
> > +/*
> > + * functions called from protocol stack drivers
> > + * to be EXPORT-ed
> > + */
> > +long st_register(struct st_proto_s *new_proto)
> > +{
> > +    long err = ST_SUCCESS;
> 
> >
> > + * functions called from TTY layer
> > + */
> > +static int st_tty_open(struct tty_struct *tty)
> > +{
> > +    int err = ST_SUCCESS;
> > +    ST_DRV_DBG("%s ", __func__);
> > +
> > +    st_gdata->tty = tty;
> 
> If you do this you need to use krefs and manage the
> reference properly
> over open/close/hangup

ok, But can I really put the kref upon tty_close ?
A bluetooth driver, might have registered, but wouldn't have started communication i.e tty_open might not have occurred.

So, I wouldn't have any trouble with that right ?

> 
> > +static void st_tty_close(struct tty_struct *tty)
> > +{
> > +    /* Flush any pending characters in
> the driver and discipline. */
> 
> > +    tty_driver_flush_buffer(tty);
> 
> Close will deal with this anyway

yep, redundant - will remove it.

> 
> > +static void st_tty_receive(struct tty_struct *tty,
> const unsigned char *data,
> > +       
>        char *tty_flags, int
> count)
> > +{
> > +#ifdef VERBOSE
> > +    long i;
> > +    printk(KERN_ERR "incoming
> data...\n");
> > +    for (i = 0; i < count; i++)
> > +        printk(" %x",
> data[i]);
> > +    printk(KERN_ERR "\n.. data
> end\n");
> > +#endif
> > +
> > +    /*
> > +     * if fw download is in
> progress then route incoming data
> > +     * to KIM for
> validation
> > +     */
> > +    st_recv(data, count);
> 
> If you passed tty up and used tty->disc_data you'd be
> able to handle
> multiple devices

Ok, the only problem here is st_int_write, which is called during firmware download. I don't get a tty there, and hence I copy it onto the st_gdata->tty.
For the rest of callbacks from TTY layer, I can make use of the tty coming into the function.

Considering the other way, if st_gdata went into the tty->disc_data, I have EXPORTED functions like st_register and st_unregister, when I can't get hold of the disc_data.


> >
> +/********************************************************************/
> > +static int __init st_core_init(void)
> > +{
> > +    long err;
> > +    static struct tty_ldisc_ops
> *st_ldisc_ops;
> > +
> > +    /* populate and register to TTY
> line discipline */
> > +    st_ldisc_ops =
> kzalloc(sizeof(*st_ldisc_ops), GFP_KERNEL);
> > +    if (!st_ldisc_ops) {
> > +        ST_DRV_ERR("no
> mem to allocate");
> > +        return
> -ENOMEM;
> > +    }
> > +
> > +    st_ldisc_ops->magic =
> TTY_LDISC_MAGIC;
> > +    st_ldisc_ops->name =
> "n_st";    /*"n_hci"; */
> > +    st_ldisc_ops->open =
> st_tty_open;
> > +    st_ldisc_ops->close =
> st_tty_close;
> > +    st_ldisc_ops->receive_buf =
> st_tty_receive;
> > +    st_ldisc_ops->write_wakeup =
> st_tty_wakeup;
> > +    st_ldisc_ops->flush_buffer =
> st_tty_flush_buffer;
> > +    st_ldisc_ops->owner =
> THIS_MODULE;
> 
> You could just declare this as a static struct like other
> drivers do ?
> 

Yep, I remember doing that, and using a couple of goto-s as well.
Organization coding standards and linux Coding Style collided.
- Will do that.


      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH] drivers:staging: sources for ST core
  2010-03-25 23:20   ` [PATCH] drivers:staging: sources for ST core pavan_savoy
@ 2010-03-30 11:22     ` Alan Cox
  2010-03-30 15:53       ` Pavan Savoy
  0 siblings, 1 reply; 27+ messages in thread
From: Alan Cox @ 2010-03-30 11:22 UTC (permalink / raw)
  To: pavan_savoy; +Cc: marcel, gregkh, linux-kernel, pavan_savoy

> +/* all debug macros go in here */
> +#define ST_DRV_ERR(fmt, arg...)  printk(KERN_ERR "(stc):"fmt"\n" , ## arg)
> +#if defined(DEBUG)		/* limited debug messages */
> +#define ST_DRV_DBG(fmt, arg...)  printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> +#define ST_DRV_VER(fmt, arg...)
> +#elif defined(VERBOSE)		/* very verbose */
> +#define ST_DRV_DBG(fmt, arg...)  printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> +#define ST_DRV_VER(fmt, arg...)  printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
> +#else /* error msgs only */
> +#define ST_DRV_DBG(fmt, arg...)
> +#define ST_DRV_VER(fmt, arg...)
> +#endif

As Greg said earlier - needs to be using the standard debug macros

> +/*
> + * local data instances
> + */
> +static struct st_data_s *st_gdata;
> +/* function pointer pointing to either,
> + * st_kim_recv during registration to receive fw download responses
> + * st_int_recv after registration to receive proto stack responses
> + */
> +void (*st_recv) (const unsigned char *data, long count);

Need some form of context so you can have multiple device instances and
avoid games with globals (which always end up in pain)

> +
> +/********************************************************************/
> +/* internal misc functions */
> +bool is_protocol_list_empty(void)
> +{
> +	unsigned char i = 0;
> +	ST_DRV_DBG(" %s ", __func__);
> +	for (i = 0; i < ST_MAX; i++) {
> +		if (st_gdata->list[i] != NULL)
> +			return ST_NOTEMPTY;
> +		/* not empty */
> +	}
> +	/* list empty */
> +	return ST_EMPTY;

Why not just keep a count of entries you've added/removed ?

> + *  This is the internal write function - a wrapper
> + *  to tty->ops->write
> + */
> +int st_int_write(const unsigned char *data, int count)
> +{
> +#ifdef VERBOSE			/* for debug */
> +	int i;
> +#endif
> +	struct tty_struct *tty;
> +	if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
> +		ST_DRV_ERR("tty unavailable to perform write");

You need to use the tty pointer passed, you don't want to walk
tty->something and back because you may race a hangup. Plus you would
need to manage the krefs (object references)

> +		return ST_ERR_FAILURE;

Should be using Linux error codes for upstream. A global search/replace
of the ST_ERR_xxx for a similar -Efoo code will do the trick I think

> +/*
> + * push the skb received to relevant
> + * protocol stacks
> + */
> +void st_send_frame(enum proto_type protoid, struct sk_buff *skb)
> +{
> +	ST_DRV_DBG(" %s(prot:%d) ", __func__, protoid);
> +
> +	if (unlikely
> +	    (st_gdata == NULL || skb == NULL
> +	     || st_gdata->list[protoid] == NULL)) {
> +		ST_DRV_ERR("protocol %d not registered, no data to send?",
> +			   protoid);
> +		kfree_skb(skb);
> +		return;
> +	}

What is the locking rule to ensure I don't unregister a protocol as send
frame is called ?

> + * to call registration complete callbacks
> + * of all protocol stack drivers
> + */
> +void st_reg_complete(char err)
> +{
> +	unsigned char i = 0;
> +	ST_DRV_DBG(" %s ", __func__);
> +	for (i = 0; i < ST_MAX; i++) {
> +		if (likely(st_gdata != NULL && st_gdata->list[i] != NULL &&

Except on very hot paths that go odd ways likely and unlikely are
normally a loss.

> +static inline int st_check_data_len(int protoid, int len)
> +{
> +	register int room = skb_tailroom(st_gdata->rx_skb);

No need to use register - gcc is generally smarter than humans here,
especially in the long term. You may optimise perfectly for a single
cpu/compiler revision but not for all


> +/* Decodes received RAW data and forwards to corresponding
> + * client drivers (Bluetooth,FM,GPS..etc).
> + *
> + */
> +void st_int_recv(const unsigned char *data, long count)

There are lots of globals here, in part it seems due to the lack of any
kind of context being passed around


>
> +	/* this function can be invoked in more then one context.
> +	 * so have a lock */

It's a good idea to document what data is locked and what the data
locking assumptions are. I'm finding that part of the code quite hard to
follow


> +/*
> + * internal wakeup function
> + * called from either
> + * - TTY layer when write's finished
> + * - st_write (in context of the protocol stack)
> + */
> +void st_tx_wakeup(struct st_data_s *st_data)


> +		while ((skb = st_int_dequeue(st_data))) {

Called in two paths but st_int_dequeue seems to have no internal locking


> +/* functions called from ST KIM
> +*/
> +void kim_st_list_protocols(char *buf)
> +{
> +	unsigned long flags = 0;
> +#ifdef DEBUG
> +	unsigned char i = ST_MAX;
> +#endif
> +	spin_lock_irqsave(&st_gdata->lock, flags);
> +#ifdef DEBUG			/* more detailed log */
> +	for (i = 0; i < ST_MAX; i++) {
> +		if (i == 0) {
> +			sprintf(buf, "%s is %s", protocol_strngs[i],
> +				st_gdata->list[i] !=
> +				NULL ? "Registered" : "Unregistered");

Always a good idea to use snprintf and track size (plus pass buffer size)
it avoida accidents later. Or also see the seq_ interface when you want
to build proc type files.

> +/********************************************************************/
> +/*
> + * functions called from protocol stack drivers
> + * to be EXPORT-ed
> + */
> +long st_register(struct st_proto_s *new_proto)
> +{
> +	long err = ST_SUCCESS;

>
> + * functions called from TTY layer
> + */
> +static int st_tty_open(struct tty_struct *tty)
> +{
> +	int err = ST_SUCCESS;
> +	ST_DRV_DBG("%s ", __func__);
> +
> +	st_gdata->tty = tty;

If you do this you need to use krefs and manage the reference properly
over open/close/hangup


> +static void st_tty_close(struct tty_struct *tty)
> +{
> +	/* Flush any pending characters in the driver and discipline. */

> +	tty_driver_flush_buffer(tty);

Close will deal with this anyway

> +static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
> +			   char *tty_flags, int count)
> +{
> +#ifdef VERBOSE
> +	long i;
> +	printk(KERN_ERR "incoming data...\n");
> +	for (i = 0; i < count; i++)
> +		printk(" %x", data[i]);
> +	printk(KERN_ERR "\n.. data end\n");
> +#endif
> +
> +	/*
> +	 * if fw download is in progress then route incoming data
> +	 * to KIM for validation
> +	 */
> +	st_recv(data, count);

If you passed tty up and used tty->disc_data you'd be able to handle
multiple devices

> +/********************************************************************/
> +static int __init st_core_init(void)
> +{
> +	long err;
> +	static struct tty_ldisc_ops *st_ldisc_ops;
> +
> +	/* populate and register to TTY line discipline */
> +	st_ldisc_ops = kzalloc(sizeof(*st_ldisc_ops), GFP_KERNEL);
> +	if (!st_ldisc_ops) {
> +		ST_DRV_ERR("no mem to allocate");
> +		return -ENOMEM;
> +	}
> +
> +	st_ldisc_ops->magic = TTY_LDISC_MAGIC;
> +	st_ldisc_ops->name = "n_st";	/*"n_hci"; */
> +	st_ldisc_ops->open = st_tty_open;
> +	st_ldisc_ops->close = st_tty_close;
> +	st_ldisc_ops->receive_buf = st_tty_receive;
> +	st_ldisc_ops->write_wakeup = st_tty_wakeup;
> +	st_ldisc_ops->flush_buffer = st_tty_flush_buffer;
> +	st_ldisc_ops->owner = THIS_MODULE;

You could just declare this as a static struct like other drivers do ?


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH] drivers:staging: sources for ST core
  2010-03-25 23:20 ` [PATCH] serial: TTY: new ldiscs for staging pavan_savoy
@ 2010-03-25 23:20   ` pavan_savoy
  2010-03-30 11:22     ` Alan Cox
  0 siblings, 1 reply; 27+ messages in thread
From: pavan_savoy @ 2010-03-25 23:20 UTC (permalink / raw)
  To: marcel, gregkh, alan; +Cc: linux-kernel, pavan_savoy, Pavan Savoy

From: Pavan Savoy <pavan_savoy@ti.com>

Texas Instruments BT, FM and GPS combo chips/drivers
make use of a single TTY to communicate with the chip.
This module constitutes the core logic, TTY ldisc driver
and the exported symbols for registering/unregistering of
the protocol drivers such as BT/FM/GPS.

Signed-off-by: Pavan Savoy <pavan_savoy@ti.com>
---
 drivers/staging/ti-st/st_core.c | 1057 +++++++++++++++++++++++++++++++++++++++
 drivers/staging/ti-st/st_core.h |   92 ++++
 2 files changed, 1149 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/ti-st/st_core.c
 create mode 100644 drivers/staging/ti-st/st_core.h

diff --git a/drivers/staging/ti-st/st_core.c b/drivers/staging/ti-st/st_core.c
new file mode 100644
index 0000000..ef07ffa
--- /dev/null
+++ b/drivers/staging/ti-st/st_core.c
@@ -0,0 +1,1057 @@
+/*
+ *  Shared Transport Line discipline driver Core
+ *	This hooks up ST KIM driver and ST LL driver
+ *  Copyright (C) 2009 Texas Instruments
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/tty.h>
+
+/* understand BT, FM and GPS for now */
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+#include <net/bluetooth/hci.h>
+#include "fm.h"
+/*
+ * packet formats for fm and gps
+ * #include "gps.h"
+ */
+#include "st_core.h"
+#include "st_kim.h"
+#include "st_ll.h"
+#include "st.h"
+
+/* all debug macros go in here */
+#define ST_DRV_ERR(fmt, arg...)  printk(KERN_ERR "(stc):"fmt"\n" , ## arg)
+#if defined(DEBUG)		/* limited debug messages */
+#define ST_DRV_DBG(fmt, arg...)  printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
+#define ST_DRV_VER(fmt, arg...)
+#elif defined(VERBOSE)		/* very verbose */
+#define ST_DRV_DBG(fmt, arg...)  printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
+#define ST_DRV_VER(fmt, arg...)  printk(KERN_INFO "(stc):"fmt"\n" , ## arg)
+#else /* error msgs only */
+#define ST_DRV_DBG(fmt, arg...)
+#define ST_DRV_VER(fmt, arg...)
+#endif
+
+#ifdef DEBUG
+/* strings to be used for rfkill entries and by
+ * ST Core to be used for sysfs debug entry
+ */
+#define PROTO_ENTRY(type, name)	name
+const unsigned char *protocol_strngs[] = {
+	PROTO_ENTRY(ST_BT, "Bluetooth"),
+	PROTO_ENTRY(ST_FM, "FM"),
+	PROTO_ENTRY(ST_GPS, "GPS"),
+};
+#endif
+/*
+ * local data instances
+ */
+static struct st_data_s *st_gdata;
+/* function pointer pointing to either,
+ * st_kim_recv during registration to receive fw download responses
+ * st_int_recv after registration to receive proto stack responses
+ */
+void (*st_recv) (const unsigned char *data, long count);
+
+/********************************************************************/
+/* internal misc functions */
+bool is_protocol_list_empty(void)
+{
+	unsigned char i = 0;
+	ST_DRV_DBG(" %s ", __func__);
+	for (i = 0; i < ST_MAX; i++) {
+		if (st_gdata->list[i] != NULL)
+			return ST_NOTEMPTY;
+		/* not empty */
+	}
+	/* list empty */
+	return ST_EMPTY;
+}
+
+/* can be called in from
+ * -- KIM (during fw download)
+ * -- ST Core (during st_write)
+ *
+ *  This is the internal write function - a wrapper
+ *  to tty->ops->write
+ */
+int st_int_write(const unsigned char *data, int count)
+{
+#ifdef VERBOSE			/* for debug */
+	int i;
+#endif
+	struct tty_struct *tty;
+	if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
+		ST_DRV_ERR("tty unavailable to perform write");
+		return ST_ERR_FAILURE;
+	}
+	tty = st_gdata->tty;
+#ifdef VERBOSE
+	printk(KERN_ERR "start data..\n");
+	for (i = 0; i < count; i++)	/* no newlines for each datum */
+		printk(" %x", data[i]);
+	printk(KERN_ERR "\n ..end data\n");
+#endif
+
+	return tty->ops->write(tty, data, count);
+
+}
+
+/*
+ * push the skb received to relevant
+ * protocol stacks
+ */
+void st_send_frame(enum proto_type protoid, struct sk_buff *skb)
+{
+	ST_DRV_DBG(" %s(prot:%d) ", __func__, protoid);
+
+	if (unlikely
+	    (st_gdata == NULL || skb == NULL
+	     || st_gdata->list[protoid] == NULL)) {
+		ST_DRV_ERR("protocol %d not registered, no data to send?",
+			   protoid);
+		kfree_skb(skb);
+		return;
+	}
+	/* this cannot fail
+	 * this shouldn't take long
+	 * - should be just skb_queue_tail for the
+	 *   protocol stack driver
+	 */
+	if (likely(st_gdata->list[protoid]->recv != NULL)) {
+		if (unlikely(st_gdata->list[protoid]->recv(skb)
+			     != ST_SUCCESS)) {
+			ST_DRV_ERR(" proto stack %d's ->recv failed", protoid);
+			kfree_skb(skb);
+			return;
+		}
+	} else {
+		ST_DRV_ERR(" proto stack %d's ->recv null", protoid);
+		kfree_skb(skb);
+	}
+	ST_DRV_DBG(" done %s", __func__);
+	return;
+}
+
+/*
+ * to call registration complete callbacks
+ * of all protocol stack drivers
+ */
+void st_reg_complete(char err)
+{
+	unsigned char i = 0;
+	ST_DRV_DBG(" %s ", __func__);
+	for (i = 0; i < ST_MAX; i++) {
+		if (likely(st_gdata != NULL && st_gdata->list[i] != NULL &&
+			   st_gdata->list[i]->reg_complete_cb != NULL))
+			st_gdata->list[i]->reg_complete_cb(err);
+	}
+}
+
+static inline int st_check_data_len(int protoid, int len)
+{
+	register int room = skb_tailroom(st_gdata->rx_skb);
+
+	ST_DRV_DBG("len %d room %d", len, room);
+
+	if (!len) {
+		/* Received packet has only packet header and
+		 * has zero length payload. So, ask ST CORE to
+		 * forward the packet to protocol driver (BT/FM/GPS)
+		 */
+		st_send_frame(protoid, st_gdata->rx_skb);
+
+	} else if (len > room) {
+		/* Received packet's payload length is larger.
+		 * We can't accommodate it in created skb.
+		 */
+		ST_DRV_ERR("Data length is too large len %d room %d", len,
+			   room);
+		kfree_skb(st_gdata->rx_skb);
+	} else {
+		/* Packet header has non-zero payload length and
+		 * we have enough space in created skb. Lets read
+		 * payload data */
+		st_gdata->rx_state = ST_BT_W4_DATA;
+		st_gdata->rx_count = len;
+		return len;
+	}
+
+	/* Change ST state to continue to process next
+	 * packet */
+	st_gdata->rx_state = ST_W4_PACKET_TYPE;
+	st_gdata->rx_skb = NULL;
+	st_gdata->rx_count = 0;
+
+	return 0;
+}
+
+/* internal function for action when wake-up ack
+ * received
+ */
+static inline void st_wakeup_ack(unsigned char cmd)
+{
+	register struct sk_buff *waiting_skb;
+	unsigned long flags = 0;
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	/* de-Q from waitQ and Q in txQ now that the
+	 * chip is awake
+	 */
+	while ((waiting_skb = skb_dequeue(&st_gdata->tx_waitq)))
+		skb_queue_tail(&st_gdata->txq, waiting_skb);
+
+	/* state forwarded to ST LL */
+	st_ll_sleep_state((unsigned long)cmd);
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	/* wake up to send the recently copied skbs from waitQ */
+	st_tx_wakeup(st_gdata);
+}
+
+/* Decodes received RAW data and forwards to corresponding
+ * client drivers (Bluetooth,FM,GPS..etc).
+ *
+ */
+void st_int_recv(const unsigned char *data, long count)
+{
+	register char *ptr;
+	struct hci_event_hdr *eh;
+	struct hci_acl_hdr *ah;
+	struct hci_sco_hdr *sh;
+	struct fm_event_hdr *fm;
+	struct gps_event_hdr *gps;
+	register int len = 0, type = 0, dlen = 0;
+	static enum proto_type protoid = ST_MAX;
+
+	ST_DRV_DBG("count %ld rx_state %ld"
+		   "rx_count %ld", count, st_gdata->rx_state,
+		   st_gdata->rx_count);
+
+	ptr = (char *)data;
+	/* tty_receive sent null ? */
+	if (unlikely(ptr == NULL)) {
+		ST_DRV_ERR(" received null from TTY ");
+		return;
+	}
+
+	/* Decode received bytes here */
+	while (count) {
+		if (st_gdata->rx_count) {
+			len = min_t(unsigned int, st_gdata->rx_count, count);
+			memcpy(skb_put(st_gdata->rx_skb, len), ptr, len);
+			st_gdata->rx_count -= len;
+			count -= len;
+			ptr += len;
+
+			if (st_gdata->rx_count)
+				continue;
+
+			/* Check ST RX state machine , where are we? */
+			switch (st_gdata->rx_state) {
+
+				/* Waiting for complete packet ? */
+			case ST_BT_W4_DATA:
+				ST_DRV_DBG("Complete pkt received");
+
+				/* Ask ST CORE to forward
+				 * the packet to protocol driver */
+				st_send_frame(protoid, st_gdata->rx_skb);
+
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_skb = NULL;
+				protoid = ST_MAX;	/* is this required ? */
+				continue;
+
+				/* Waiting for Bluetooth event header ? */
+			case ST_BT_W4_EVENT_HDR:
+				eh = (struct hci_event_hdr *)st_gdata->rx_skb->
+				    data;
+
+				ST_DRV_DBG("Event header: evt 0x%2.2x"
+					   "plen %d", eh->evt, eh->plen);
+
+				st_check_data_len(protoid, eh->plen);
+				continue;
+
+				/* Waiting for Bluetooth acl header ? */
+			case ST_BT_W4_ACL_HDR:
+				ah = (struct hci_acl_hdr *)st_gdata->rx_skb->
+				    data;
+				dlen = __le16_to_cpu(ah->dlen);
+
+				ST_DRV_DBG("ACL header: dlen %d", dlen);
+
+				st_check_data_len(protoid, dlen);
+				continue;
+
+				/* Waiting for Bluetooth sco header ? */
+			case ST_BT_W4_SCO_HDR:
+				sh = (struct hci_sco_hdr *)st_gdata->rx_skb->
+				    data;
+
+				ST_DRV_DBG("SCO header: dlen %d", sh->dlen);
+
+				st_check_data_len(protoid, sh->dlen);
+				continue;
+			case ST_FM_W4_EVENT_HDR:
+				fm = (struct fm_event_hdr *)st_gdata->rx_skb->
+				    data;
+				ST_DRV_DBG("FM Header: ");
+				st_check_data_len(ST_FM, fm->plen);
+				continue;
+				/* TODO : Add GPS packet machine logic here */
+			case ST_GPS_W4_EVENT_HDR:
+				/* [0x09 pkt hdr][R/W byte][2 byte len] */
+				gps = (struct gps_event_hdr *)st_gdata->rx_skb->
+				     data;
+				ST_DRV_DBG("GPS Header: ");
+				st_check_data_len(ST_GPS, gps->plen);
+				continue;
+			}	/* end of switch rx_state */
+		}
+
+		/* end of if rx_count */
+		/* Check first byte of packet and identify module
+		 * owner (BT/FM/GPS) */
+		switch (*ptr) {
+
+			/* Bluetooth event packet? */
+		case HCI_EVENT_PKT:
+			ST_DRV_DBG("Event packet");
+			st_gdata->rx_state = ST_BT_W4_EVENT_HDR;
+			st_gdata->rx_count = HCI_EVENT_HDR_SIZE;
+			type = HCI_EVENT_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Bluetooth acl packet? */
+		case HCI_ACLDATA_PKT:
+			ST_DRV_DBG("ACL packet");
+			st_gdata->rx_state = ST_BT_W4_ACL_HDR;
+			st_gdata->rx_count = HCI_ACL_HDR_SIZE;
+			type = HCI_ACLDATA_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Bluetooth sco packet? */
+		case HCI_SCODATA_PKT:
+			ST_DRV_DBG("SCO packet");
+			st_gdata->rx_state = ST_BT_W4_SCO_HDR;
+			st_gdata->rx_count = HCI_SCO_HDR_SIZE;
+			type = HCI_SCODATA_PKT;
+			protoid = ST_BT;
+			break;
+
+			/* Channel 8(FM) packet? */
+		case ST_FM_CH8_PKT:
+			ST_DRV_DBG("FM CH8 packet");
+			type = ST_FM_CH8_PKT;
+			st_gdata->rx_state = ST_FM_W4_EVENT_HDR;
+			st_gdata->rx_count = FM_EVENT_HDR_SIZE;
+			protoid = ST_FM;
+			break;
+
+			/* Channel 9(GPS) packet? */
+		case 0x9:	/*ST_LL_GPS_CH9_PKT */
+			ST_DRV_DBG("GPS CH9 packet");
+			type = 0x9;	/* ST_LL_GPS_CH9_PKT; */
+			protoid = ST_GPS;
+			st_gdata->rx_state = ST_GPS_W4_EVENT_HDR;
+			st_gdata->rx_count = 3;	/* GPS_EVENT_HDR_SIZE -1*/
+			break;
+		case LL_SLEEP_IND:
+		case LL_SLEEP_ACK:
+		case LL_WAKE_UP_IND:
+			/* this takes appropriate action based on
+			 * sleep state received --
+			 */
+			st_ll_sleep_state(*ptr);
+			ptr++;
+			count--;
+			continue;
+		case LL_WAKE_UP_ACK:
+			/* wake up ack received */
+			st_wakeup_ack(*ptr);
+			ptr++;
+			count--;
+			continue;
+			/* Unknow packet? */
+		default:
+			ST_DRV_ERR("Unknown packet type %2.2x", (__u8) *ptr);
+			ptr++;
+			count--;
+			continue;
+		};
+		ptr++;
+		count--;
+
+		switch (protoid) {
+		case ST_BT:
+			/* Allocate new packet to hold received data */
+			st_gdata->rx_skb =
+			    bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				ST_DRV_ERR("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			bt_cb(st_gdata->rx_skb)->pkt_type = type;
+			break;
+		case ST_FM:	/* for FM */
+			st_gdata->rx_skb =
+			    alloc_skb(FM_MAX_FRAME_SIZE, GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				ST_DRV_ERR("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			/* place holder 0x08 */
+			skb_reserve(st_gdata->rx_skb, 1);
+			st_gdata->rx_skb->cb[0] = ST_FM_CH8_PKT;
+			break;
+		case ST_GPS:
+			/* for GPS */
+			st_gdata->rx_skb =
+			    alloc_skb(100 /*GPS_MAX_FRAME_SIZE */ , GFP_ATOMIC);
+			if (!st_gdata->rx_skb) {
+				ST_DRV_ERR("Can't allocate mem for new packet");
+				st_gdata->rx_state = ST_W4_PACKET_TYPE;
+				st_gdata->rx_count = 0;
+				return;
+			}
+			/* place holder 0x09 */
+			skb_reserve(st_gdata->rx_skb, 1);
+			st_gdata->rx_skb->cb[0] = 0x09;	/*ST_GPS_CH9_PKT; */
+			break;
+		case ST_MAX:
+			break;
+		}
+	}
+	ST_DRV_DBG("done %s", __func__);
+	return;
+}
+
+/* internal de-Q function
+ * -- return previous in-completely written skb
+ *  or return the skb in the txQ
+ */
+struct sk_buff *st_int_dequeue(struct st_data_s *st_data)
+{
+	struct sk_buff *returning_skb;
+
+	ST_DRV_VER("%s", __func__);
+	/* if the previous skb wasn't written completely
+	 */
+	if (st_gdata->tx_skb != NULL) {
+		returning_skb = st_gdata->tx_skb;
+		st_gdata->tx_skb = NULL;
+		return returning_skb;
+	}
+
+	/* de-Q from the txQ always if previous write is complete */
+	return skb_dequeue(&st_gdata->txq);
+}
+
+/* internal Q-ing function
+ * will either Q the skb to txq or the tx_waitq
+ * depending on the ST LL state
+ *
+ * lock the whole func - since ll_getstate and Q-ing should happen
+ * in one-shot
+ */
+void st_int_enqueue(struct sk_buff *skb)
+{
+	unsigned long flags = 0;
+
+	ST_DRV_VER("%s", __func__);
+	/* this function can be invoked in more then one context.
+	 * so have a lock */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	switch (st_ll_getstate()) {
+	case ST_LL_AWAKE:
+		ST_DRV_DBG("ST LL is AWAKE, sending normally");
+		skb_queue_tail(&st_gdata->txq, skb);
+		break;
+	case ST_LL_ASLEEP_TO_AWAKE:
+		skb_queue_tail(&st_gdata->tx_waitq, skb);
+		break;
+	case ST_LL_AWAKE_TO_ASLEEP:	/* host cannot be in this state */
+		ST_DRV_ERR("ST LL is illegal state(%ld),"
+			   "purging received skb.", st_ll_getstate());
+		kfree_skb(skb);
+		break;
+
+	case ST_LL_ASLEEP:
+		/* call a function of ST LL to put data
+		 * in tx_waitQ and wake_ind in txQ
+		 */
+		skb_queue_tail(&st_gdata->tx_waitq, skb);
+		st_ll_wakeup();
+		break;
+	default:
+		ST_DRV_ERR("ST LL is illegal state(%ld),"
+			   "purging received skb.", st_ll_getstate());
+		kfree_skb(skb);
+		break;
+	}
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+	ST_DRV_VER("done %s", __func__);
+	return;
+}
+
+/*
+ * internal wakeup function
+ * called from either
+ * - TTY layer when write's finished
+ * - st_write (in context of the protocol stack)
+ */
+void st_tx_wakeup(struct st_data_s *st_data)
+{
+	struct sk_buff *skb;
+	unsigned long flags;	/* for irq save flags */
+	ST_DRV_VER("%s", __func__);
+	/* check for sending & set flag sending here */
+	if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) {
+		ST_DRV_DBG("ST already sending");
+		/* keep sending */
+		set_bit(ST_TX_WAKEUP, &st_data->tx_state);
+		return;
+		/* TX_WAKEUP will be checked in another
+		 * context
+		 */
+	}
+	do {			/* come back if st_tx_wakeup is set */
+		/* woke-up to write */
+		clear_bit(ST_TX_WAKEUP, &st_data->tx_state);
+		while ((skb = st_int_dequeue(st_data))) {
+			int len;
+			spin_lock_irqsave(&st_data->lock, flags);
+			/* enable wake-up from TTY */
+			set_bit(TTY_DO_WRITE_WAKEUP, &st_data->tty->flags);
+			len = st_int_write(skb->data, skb->len);
+			skb_pull(skb, len);
+			/* if skb->len = len as expected, skb->len=0 */
+			if (skb->len) {
+				/* would be the next skb to be sent */
+				st_data->tx_skb = skb;
+				spin_unlock_irqrestore(&st_gdata->lock, flags);
+				break;
+			}
+			kfree_skb(skb);
+			spin_unlock_irqrestore(&st_gdata->lock, flags);
+		}
+		/* if wake-up is set in another context- restart sending */
+	} while (test_bit(ST_TX_WAKEUP, &st_data->tx_state));
+
+	/* clear flag sending */
+	clear_bit(ST_TX_SENDING, &st_data->tx_state);
+}
+
+/********************************************************************/
+/* functions called from ST KIM
+*/
+void kim_st_list_protocols(char *buf)
+{
+	unsigned long flags = 0;
+#ifdef DEBUG
+	unsigned char i = ST_MAX;
+#endif
+	spin_lock_irqsave(&st_gdata->lock, flags);
+#ifdef DEBUG			/* more detailed log */
+	for (i = 0; i < ST_MAX; i++) {
+		if (i == 0) {
+			sprintf(buf, "%s is %s", protocol_strngs[i],
+				st_gdata->list[i] !=
+				NULL ? "Registered" : "Unregistered");
+		} else {
+			sprintf(buf, "%s\n%s is %s", buf, protocol_strngs[i],
+				st_gdata->list[i] !=
+				NULL ? "Registered" : "Unregistered");
+		}
+	}
+	sprintf(buf, "%s\n", buf);
+#else /* limited info */
+	sprintf(buf, "BT=%c\nFM=%c\nGPS=%c\n",
+		st_gdata->list[ST_BT] != NULL ? 'R' : 'U',
+		st_gdata->list[ST_FM] != NULL ? 'R' : 'U',
+		st_gdata->list[ST_GPS] != NULL ? 'R' : 'U');
+#endif
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+}
+
+/********************************************************************/
+/*
+ * functions called from protocol stack drivers
+ * to be EXPORT-ed
+ */
+long st_register(struct st_proto_s *new_proto)
+{
+	long err = ST_SUCCESS;
+	unsigned long flags = 0;
+
+	ST_DRV_DBG("%s(%d) ", __func__, new_proto->type);
+	if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL
+	    || new_proto->reg_complete_cb == NULL) {
+		ST_DRV_ERR("gdata/new_proto/recv or reg_complete_cb not ready");
+		return ST_ERR_FAILURE;
+	}
+
+	if (new_proto->type < ST_BT || new_proto->type >= ST_MAX) {
+		ST_DRV_ERR("protocol %d not supported", new_proto->type);
+		return ST_ERR_NOPROTO;
+	}
+
+	if (st_gdata->list[new_proto->type] != NULL) {
+		ST_DRV_ERR("protocol %d already registered", new_proto->type);
+		return ST_ERR_ALREADY;
+	}
+
+	/* can be from process context only */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) {
+		ST_DRV_DBG(" ST_REG_IN_PROGRESS:%d ", new_proto->type);
+		/* fw download in progress */
+		st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+
+		set_bit(ST_REG_PENDING, &st_gdata->st_state);
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return ST_ERR_PENDING;
+	} else if (is_protocol_list_empty() == ST_EMPTY) {
+		ST_DRV_DBG(" protocol list empty :%d ", new_proto->type);
+		set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+		st_recv = st_kim_recv;
+
+		/* release lock previously held - re-locked below */
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+		/* enable the ST LL - to set default chip state */
+		st_ll_enable();
+		/* this may take a while to complete
+		 * since it involves BT fw download
+		 */
+		err = st_kim_start();
+		if (err != ST_SUCCESS) {
+			clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+			if ((is_protocol_list_empty() != ST_EMPTY) &&
+			    (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+				ST_DRV_ERR(" KIM failure complete callback ");
+				st_reg_complete(ST_ERR_FAILURE);
+			}
+
+			return ST_ERR_FAILURE;
+		}
+
+		/* the protocol might require other gpios to be toggled
+		 */
+		st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+
+		clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
+		st_recv = st_int_recv;
+
+		/* this is where all pending registration
+		 * are signalled to be complete by calling callback functions
+		 */
+		if ((is_protocol_list_empty() != ST_EMPTY) &&
+		    (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+			ST_DRV_VER(" call reg complete callback ");
+			st_reg_complete(ST_SUCCESS);
+		}
+		clear_bit(ST_REG_PENDING, &st_gdata->st_state);
+
+		/* check for already registered once more,
+		 * since the above check is old
+		 */
+		if (st_gdata->list[new_proto->type] != NULL) {
+			ST_DRV_ERR(" proto %d already registered ",
+				   new_proto->type);
+			return ST_ERR_ALREADY;
+		}
+
+		spin_lock_irqsave(&st_gdata->lock, flags);
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return err;
+	}
+	/* if fw is already downloaded & new stack registers protocol */
+	else {
+		switch (new_proto->type) {
+		case ST_BT:
+			/* do nothing */
+			break;
+		case ST_FM:
+		case ST_GPS:
+			st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+			break;
+		case ST_MAX:
+		default:
+			ST_DRV_ERR("%d protocol not supported",
+				   new_proto->type);
+			err = ST_ERR_NOPROTO;
+			/* something wrong */
+			break;
+		}
+		st_gdata->list[new_proto->type] = new_proto;
+		new_proto->write = st_write;
+
+		/* lock already held before entering else */
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return err;
+	}
+	ST_DRV_DBG("done %s(%d) ", __func__, new_proto->type);
+}
+EXPORT_SYMBOL_GPL(st_register);
+
+/* to unregister a protocol -
+ * to be called from protocol stack driver
+ */
+long st_unregister(enum proto_type type)
+{
+	long err = ST_SUCCESS;
+	unsigned long flags = 0;
+
+	ST_DRV_DBG("%s: %d ", __func__, type);
+
+	if (type < ST_BT || type >= ST_MAX) {
+		ST_DRV_ERR(" protocol %d not supported", type);
+		return ST_ERR_NOPROTO;
+	}
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+
+	if (st_gdata->list[type] == NULL) {
+		ST_DRV_ERR(" protocol %d not registered", type);
+		spin_unlock_irqrestore(&st_gdata->lock, flags);
+		return ST_ERR_NOPROTO;
+	}
+
+	st_gdata->list[type] = NULL;
+
+	/* kim ignores BT in the below function
+	 * and handles the rest, BT is toggled
+	 * only in kim_start and kim_stop
+	 */
+	st_kim_chip_toggle(type, KIM_GPIO_INACTIVE);
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	if ((is_protocol_list_empty() == ST_EMPTY) &&
+	    (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
+		ST_DRV_DBG(" all protocols unregistered ");
+
+		/* stop traffic on tty */
+		if (st_gdata->tty) {
+			tty_ldisc_flush(st_gdata->tty);
+			stop_tty(st_gdata->tty);
+		}
+
+		/* all protocols now unregistered */
+		st_kim_stop();
+		/* disable ST LL */
+		st_ll_disable();
+	}
+	return err;
+}
+
+/*
+ * called in protocol stack drivers
+ * via the write function pointer
+ */
+long st_write(struct sk_buff *skb)
+{
+#ifdef DEBUG
+	enum proto_type protoid = ST_MAX;
+#endif
+	long len;
+	struct st_data_s *st_data = st_gdata;
+
+	if (unlikely(skb == NULL || st_gdata == NULL
+		|| st_gdata->tty == NULL)) {
+		ST_DRV_ERR("data/tty unavailable to perform write");
+		return ST_ERR_FAILURE;
+	}
+#ifdef DEBUG			/* open-up skb to read the 1st byte */
+	switch (skb->data[0]) {
+	case HCI_COMMAND_PKT:
+	case HCI_ACLDATA_PKT:
+	case HCI_SCODATA_PKT:
+		protoid = ST_BT;
+		break;
+	case ST_FM_CH8_PKT:
+		protoid = ST_FM;
+		break;
+	case 0x09:
+		protoid = ST_GPS;
+		break;
+	}
+	if (unlikely(st_gdata->list[protoid] == NULL)) {
+		ST_DRV_ERR(" protocol %d not registered, and writing? ",
+			   protoid);
+		return ST_ERR_FAILURE;
+	}
+#endif
+	ST_DRV_DBG("%d to be written", skb->len);
+	len = skb->len;
+
+	/* st_ll to decide where to enqueue the skb */
+	st_int_enqueue(skb);
+	/* wake up */
+	st_tx_wakeup(st_data);
+
+	/* return number of bytes written */
+	return len;
+}
+
+/* for protocols making use of shared transport */
+EXPORT_SYMBOL_GPL(st_unregister);
+
+/********************************************************************/
+/*
+ * functions called from TTY layer
+ */
+static int st_tty_open(struct tty_struct *tty)
+{
+	int err = ST_SUCCESS;
+	ST_DRV_DBG("%s ", __func__);
+
+	st_gdata->tty = tty;
+
+	/* don't do an wakeup for now */
+	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+
+	/* mem already allocated
+	 */
+	tty->receive_room = 65536;
+	/* Flush any pending characters in the driver and discipline. */
+	tty_ldisc_flush(tty);
+	tty_driver_flush_buffer(tty);
+	/*
+	 * signal to UIM via KIM that -
+	 * installation of N_TI_WL ldisc is complete
+	 */
+	st_kim_complete();
+	ST_DRV_DBG("done %s", __func__);
+	return err;
+}
+
+static void st_tty_close(struct tty_struct *tty)
+{
+	unsigned char i = ST_MAX;
+	unsigned long flags = 0;
+
+	ST_DRV_DBG("%s ", __func__);
+
+	/* TODO:
+	 * if a protocol has been registered & line discipline
+	 * un-installed for some reason - what should be done ?
+	 */
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	for (i = ST_BT; i < ST_MAX; i++) {
+		if (st_gdata->list[i] != NULL)
+			ST_DRV_ERR("%d not un-registered", i);
+		st_gdata->list[i] = NULL;
+	}
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+	/*
+	 * signal to UIM via KIM that -
+	 * N_TI_WL ldisc is un-installed
+	 */
+	st_kim_complete();
+	st_gdata->tty = NULL;
+	/* Flush any pending characters in the driver and discipline. */
+	tty_ldisc_flush(tty);
+	tty_driver_flush_buffer(tty);
+
+	spin_lock_irqsave(&st_gdata->lock, flags);
+	/* empty out txq and tx_waitq */
+	skb_queue_purge(&st_gdata->txq);
+	skb_queue_purge(&st_gdata->tx_waitq);
+	/* reset the TTY Rx states of ST */
+	st_gdata->rx_count = 0;
+	st_gdata->rx_state = ST_W4_PACKET_TYPE;
+	kfree_skb(st_gdata->rx_skb);
+	st_gdata->rx_skb = NULL;
+	spin_unlock_irqrestore(&st_gdata->lock, flags);
+
+	ST_DRV_DBG("%s: done ", __func__);
+}
+
+static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
+			   char *tty_flags, int count)
+{
+#ifdef VERBOSE
+	long i;
+	printk(KERN_ERR "incoming data...\n");
+	for (i = 0; i < count; i++)
+		printk(" %x", data[i]);
+	printk(KERN_ERR "\n.. data end\n");
+#endif
+
+	/*
+	 * if fw download is in progress then route incoming data
+	 * to KIM for validation
+	 */
+	st_recv(data, count);
+	ST_DRV_VER("done %s", __func__);
+}
+
+/* wake-up function called in from the TTY layer
+ * inside the internal wakeup function will be called
+ */
+static void st_tty_wakeup(struct tty_struct *tty)
+{
+	ST_DRV_DBG("%s ", __func__);
+	/* don't do an wakeup for now */
+	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+
+	/* call our internal wakeup */
+	st_tx_wakeup((void *)st_gdata);
+}
+
+static void st_tty_flush_buffer(struct tty_struct *tty)
+{
+	ST_DRV_DBG("%s ", __func__);
+
+	kfree_skb(st_gdata->tx_skb);
+	st_gdata->tx_skb = NULL;
+
+	tty->ops->flush_buffer(tty);
+	return;
+}
+
+/********************************************************************/
+static int __init st_core_init(void)
+{
+	long err;
+	static struct tty_ldisc_ops *st_ldisc_ops;
+
+	/* populate and register to TTY line discipline */
+	st_ldisc_ops = kzalloc(sizeof(*st_ldisc_ops), GFP_KERNEL);
+	if (!st_ldisc_ops) {
+		ST_DRV_ERR("no mem to allocate");
+		return -ENOMEM;
+	}
+
+	st_ldisc_ops->magic = TTY_LDISC_MAGIC;
+	st_ldisc_ops->name = "n_st";	/*"n_hci"; */
+	st_ldisc_ops->open = st_tty_open;
+	st_ldisc_ops->close = st_tty_close;
+	st_ldisc_ops->receive_buf = st_tty_receive;
+	st_ldisc_ops->write_wakeup = st_tty_wakeup;
+	st_ldisc_ops->flush_buffer = st_tty_flush_buffer;
+	st_ldisc_ops->owner = THIS_MODULE;
+
+	err = tty_register_ldisc(N_TI_WL, st_ldisc_ops);
+	if (err) {
+		ST_DRV_ERR("error registering %d line discipline %ld",
+			   N_TI_WL, err);
+		kfree(st_ldisc_ops);
+		return err;
+	}
+	ST_DRV_DBG("registered n_shared line discipline");
+
+	st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL);
+	if (!st_gdata) {
+		ST_DRV_ERR("memory allocation failed");
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			ST_DRV_ERR("unable to un-register ldisc %ld", err);
+		kfree(st_ldisc_ops);
+		err = -ENOMEM;
+		return err;
+	}
+
+	/* Initialize ST TxQ and Tx waitQ queue head. All BT/FM/GPS module skb's
+	 * will be pushed in this queue for actual transmission.
+	 */
+	skb_queue_head_init(&st_gdata->txq);
+	skb_queue_head_init(&st_gdata->tx_waitq);
+
+	/* Locking used in st_int_enqueue() to avoid multiple execution */
+	spin_lock_init(&st_gdata->lock);
+
+	/* ldisc_ops ref to be only used in __exit of module */
+	st_gdata->ldisc_ops = st_ldisc_ops;
+
+	err = st_kim_init();
+	if (err) {
+		ST_DRV_ERR("error during kim initialization(%ld)", err);
+		kfree(st_gdata);
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			ST_DRV_ERR("unable to un-register ldisc");
+		kfree(st_ldisc_ops);
+		return -1;
+	}
+
+	err = st_ll_init();
+	if (err) {
+		ST_DRV_ERR("error during st_ll initialization(%ld)", err);
+		err = st_kim_deinit();
+		kfree(st_gdata);
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			ST_DRV_ERR("unable to un-register ldisc");
+		kfree(st_ldisc_ops);
+		return -1;
+	}
+	return 0;
+}
+
+static void __exit st_core_exit(void)
+{
+	long err;
+	/* internal module cleanup */
+	err = st_ll_deinit();
+	if (err)
+		ST_DRV_ERR("error during deinit of ST LL %ld", err);
+	err = st_kim_deinit();
+	if (err)
+		ST_DRV_ERR("error during deinit of ST KIM %ld", err);
+
+	if (st_gdata != NULL) {
+		/* Free ST Tx Qs and skbs */
+		skb_queue_purge(&st_gdata->txq);
+		skb_queue_purge(&st_gdata->tx_waitq);
+		kfree_skb(st_gdata->rx_skb);
+		kfree_skb(st_gdata->tx_skb);
+		/* TTY ldisc cleanup */
+		err = tty_unregister_ldisc(N_TI_WL);
+		if (err)
+			ST_DRV_ERR("unable to un-register ldisc %ld", err);
+		kfree(st_gdata->ldisc_ops);
+		/* free the global data pointer */
+		kfree(st_gdata);
+	}
+}
+
+module_init(st_core_init);
+module_exit(st_core_exit);
+MODULE_AUTHOR("Pavan Savoy <pavan_savoy@ti.com>");
+MODULE_DESCRIPTION("Shared Transport Driver for TI BT/FM/GPS combo chips ");
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/ti-st/st_core.h b/drivers/staging/ti-st/st_core.h
new file mode 100644
index 0000000..ff0d9d1
--- /dev/null
+++ b/drivers/staging/ti-st/st_core.h
@@ -0,0 +1,92 @@
+/*
+ *  Shared Transport Core header file
+ *
+ *  Copyright (C) 2009 Texas Instruments
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef ST_CORE_H
+#define ST_CORE_H
+
+#include <linux/skbuff.h>
+#include "st.h"
+
+/* states of protocol list */
+#define ST_NOTEMPTY	1
+#define ST_EMPTY	0
+
+/*
+ * possible st_states
+ */
+#define ST_INITIALIZING		1
+#define ST_REG_IN_PROGRESS	2
+#define ST_REG_PENDING		3
+#define ST_WAITING_FOR_RESP	4
+
+/*
+ * local data required for ST/KIM/ST-HCI-LL
+ */
+struct st_data_s {
+	unsigned long st_state;
+/*
+ * an instance of tty_struct & ldisc ops to move around
+ */
+	struct tty_struct *tty;
+	struct tty_ldisc_ops *ldisc_ops;
+/*
+ * the tx skb -
+ * if the skb is already dequeued and the tty failed to write the same
+ * maintain the skb to write in the next transaction
+ */
+	struct sk_buff *tx_skb;
+#define ST_TX_SENDING	1
+#define ST_TX_WAKEUP	2
+	unsigned long tx_state;
+/*
+ * list of protocol registered
+ */
+	struct st_proto_s *list[ST_MAX];
+/*
+ * lock
+ */
+	unsigned long rx_state;
+	unsigned long rx_count;
+	struct sk_buff *rx_skb;
+	struct sk_buff_head txq, tx_waitq;
+	spinlock_t lock;	/* ST LL state lock  */
+};
+
+/* point this to tty->driver->write or tty->ops->write
+ * depending upon the kernel version
+ */
+int st_int_write(const unsigned char *, int);
+/* internal write function, passed onto protocol drivers
+ * via the write function ptr of protocol struct
+ */
+long st_write(struct sk_buff *);
+/* function to be called from ST-LL
+ */
+void st_ll_send_frame(enum proto_type, struct sk_buff *);
+/* internal wake up function */
+void st_tx_wakeup(struct st_data_s *st_data);
+
+#define GPS_STUB_TEST
+#ifdef GPS_STUB_TEST
+int gps_chrdrv_stub_write(const unsigned char*, int);
+void gps_chrdrv_stub_init(void);
+#endif
+
+#endif /*ST_CORE_H */
-- 
1.5.4.3


^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2010-04-27 16:15 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-31 19:27 [PATCH] drivers:staging: sources for ST core Pavan Savoy
2010-03-31 20:24 ` Greg KH
2010-03-31 23:57   ` Pavan Savoy
2010-04-01  9:20     ` Alan Cox
  -- strict thread matches above, loose matches on Subject: below --
2010-04-27 16:15 Pavan Savoy
2010-04-08 18:16 New ldisc for WiLink7.0 pavan_savoy
2010-04-08 18:16 ` [PATCH] serial: TTY: new ldiscs for staging pavan_savoy
2010-04-08 18:16   ` [PATCH] drivers:staging: sources for ST core pavan_savoy
2010-04-13 15:06     ` Pavan Savoy
2010-04-13 15:12       ` Alan Cox
2010-04-19 18:37         ` Pavan Savoy
2010-04-26 21:24           ` Pavan Savoy
2010-04-26 22:03     ` Alan Cox
2010-04-26 22:06       ` Pavan Savoy
2010-04-01 17:20 Pavan Savoy
2010-04-01 22:43 ` Pavan Savoy
2010-04-01 23:27   ` Alan Cox
2010-04-05 16:18     ` Pavan Savoy
2010-03-30 22:50 Pavan Savoy
2010-03-31 17:30 ` Greg KH
2010-03-31 18:02   ` Pavan Savoy
2010-03-31 18:19     ` Greg KH
2010-03-25 23:20 [v4] New ldisc for WiLink7.0 pavan_savoy
2010-03-25 23:20 ` [PATCH] serial: TTY: new ldiscs for staging pavan_savoy
2010-03-25 23:20   ` [PATCH] drivers:staging: sources for ST core pavan_savoy
2010-03-30 11:22     ` Alan Cox
2010-03-30 15:53       ` Pavan Savoy
2010-03-30 20:38         ` Greg KH
2010-03-30 21:05           ` Pavan Savoy
2010-03-30 21:47             ` Greg KH
2010-03-31  2:24             ` Joe Perches

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.