New ldisc for WiLink7.0
Subsystems (2)
PATCH v4 1/1 New ldisc for WiLink7.0
Greg / Alan,
- moved to staging and completely self-contained
- REMOVed the sysfs entry creation at root and replaced it with sending events via rfkill.
- verified and working with new logic
- patch re-ordered
Note:
Sorry for being annoying (some call it being persistent)
Quoted 15 lines
Moved to staging directory as suggested.
All the patches have been modified to now go intodrivers/staging/Texas Instruments has introduced it's new series of WiLink chipsets which has Bluetooth, WLAN, FM-Rx and FM-Tx and GPS on 1 single chip. This series of chipsets allow apps processor to interface with the chip over a single UART mux-ed for all 3 (BT,FM and GPS) cores on chip and SDIO for WLAN.
The following list of patches introduces a new line discipline which allows such muxing to happen, and 3 different BT, FM and GPS drivers would sit on top of this driver (registering/unregistering) and glue this to relevant s/w stacks.
This has been verified to work on TI's OMAP
platforms(34xx,36xx and 44xx).
PATCH 1/1 serial: TTY: new ldiscs for staging
From: Pavan Savoy <[email protected]>
Push the max ldiscs by a few number to allow ldiscs to exist in the staging directory
--- include/linux/tty.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/tty.h +1 -1
@@ -23,7 +23,7 @@*/ #define NR_UNIX98_PTY_DEFAULT 4096/* Default maximum for Unix98 ptys */ #define NR_UNIX98_PTY_MAX (1 << MINORBITS)/* Absolute limit */ -#define NR_LDISCS 20 +#define NR_LDISCS 25/* add few ldiscs for staging */ /* line disciplines */ #define N_TTY 0
Signature · 1 line
1.5.4.3
PATCH 1/1 drivers:staging: sources for ST core
From: Pavan Savoy <[email protected]>
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.
--- 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
drivers/staging/ti-st/st_core.c new file +1057 -0
@@ -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) +{ + registerint 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) +{ + registerstruct 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) +{ + registerchar *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; + registerint 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 <[email protected]>" ); +MODULE_DESCRIPTION ("Shared Transport Driver for TI BT/FM/GPS combo chips " ); +MODULE_LICENSE ("GPL" );
drivers/staging/ti-st/st_core.h new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
1.5.4.3
PATCH 1/1 drivers:staging: sources for Init manager module
From: Pavan Savoy <[email protected]>
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
--- drivers/staging/ti-st/st_kim.c | 747 ++++++++++++++++++++++++++++++++++++++++ drivers/staging/ti-st/st_kim.h | 152 ++++++++ 2 files changed, 899 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/ti-st/st_kim.c create mode 100644 drivers/staging/ti-st/st_kim.h
drivers/staging/ti-st/st_kim.c new file +747 -0
@@ -0,0 +1,747 @@ +/* +* 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 +* +*/ + +#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> + + +/* all debug macros go in here */ +#define ST_KIM_ERR(fmt, arg...) printk(KERN_ERR "(stk):"fmt"\n" , ## arg) +#if defined(DEBUG )/* limited debug messages */ +#define ST_KIM_DBG(fmt, arg...) printk(KERN_INFO "(stk):"fmt"\n" , ## arg) +#define ST_KIM_VER(fmt, arg...) +#elif defined(VERBOSE )/* very verbose */ +#define ST_KIM_DBG(fmt, arg...) printk(KERN_INFO "(stk):"fmt"\n" , ## arg) +#define ST_KIM_VER(fmt, arg...) printk(KERN_INFO "(stk):"fmt"\n" , ## arg) +#else /* error msgs only */ +#define ST_KIM_DBG(fmt, arg...) +#define ST_KIM_VER(fmt, arg...) +#endif + +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" ), +}; + +static 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 )) { +ST_KIM_ERR ("no proper response during fw download" ); +ST_KIM_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) +{ + registerint room =skb_tailroom (kim_gdata->rx_skb); + +ST_KIM_DBG ("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. +*/ +ST_KIM_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) +{ + registerchar *ptr; +struct hci_event_hdr *eh; + registerint len =0 , type =0 ; + +ST_KIM_DBG ("%s" , __func__); +/* Decode received bytes here */ + ptr = (char *)data; +if (unlikely (ptr ==NULL )) { +ST_KIM_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 : +ST_KIM_DBG ("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; +ST_KIM_DBG ("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 : +ST_KIM_DBG ("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 : +ST_KIM_DBG ("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) { +ST_KIM_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 */ +ST_KIM_DBG ("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 }; + +ST_KIM_DBG ("%s" , __func__); + +INIT_COMPLETION (kim_gdata->kim_rcvd); +if (4 !=st_int_write (read_ver_cmd,4 )) { +ST_KIM_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 ))) { +ST_KIM_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); +ST_KIM_DBG ("%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 ; + registerunsigned char *ptr =NULL ; + registerunsigned char *action_ptr =NULL ; +unsigned char bts_scr_name[30 ] = {0 };/* 30 char long bts scr name? */ + +ST_KIM_VER ("%s" , __func__); + + err =read_local_version (bts_scr_name); +if (err !=ST_SUCCESS ) { +ST_KIM_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 ))) { +ST_KIM_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) { +ST_KIM_VER (" 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 */ +ST_KIM_ERR + (" change remote baud\ +rate command in firmware" ); +break ; + } + +INIT_COMPLETION (kim_gdata->kim_rcvd); + err =st_int_write (((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 ))) { +ST_KIM_ERR + (" response timeout during fw download " ); +/* timed out */ +release_firmware (kim_gdata->fw_entry); +return ST_ERR_FAILURE ; + } +break ; +case ACTION_DELAY :/* sleep */ +ST_KIM_DBG ("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) +{ +ST_KIM_DBG (" %s " , __func__); + +if (kim_gdata->gpios[type] ==-1 ) { +ST_KIM_DBG (" 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 (const unsigned char *data,long count) +{ +ST_KIM_DBG (" %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 ; +ST_KIM_DBG (" %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_sw_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 ) { +ST_KIM_VER (" sending SIGUSR2 to uim failed %ld" , err); + err =ST_ERR_FAILURE ; +continue ; + } +#else +/* unblock and send event to UIM via /dev/rfkill */ +rfkill_set_sw_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 */ +ST_KIM_ERR ("line disc installation timed out " ); + err =ST_ERR_FAILURE ; +continue ; + }else { +/* ldisc installed now */ +ST_KIM_DBG (" line discipline installed " ); + err =download_firmware (); +if (err !=ST_SUCCESS ) { +ST_KIM_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 ) { +ST_KIM_ERR ("sending SIGUSR2 to uim failed %ld" , err); +return ST_ERR_FAILURE ; + } +#else +/* set BT rfkill to be blocked */ + err =rfkill_set_sw_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 */ +ST_KIM_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) +{ +ST_KIM_DBG ("%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 (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); +ST_KIM_DBG (" %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 : +ST_KIM_ERR (" wrong proto type " ); +break ; + } +return ST_SUCCESS ; +} + +#endif /* LEGACY_RFKILL_SUPPORT */ + +/**********************************************************************/ +/* 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; + +for (proto =0 ; proto <ST_MAX ; proto++) { + kim_gdata->gpios[proto] = gpios[proto]; +ST_KIM_VER (" %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)) { +ST_KIM_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)) { +ST_KIM_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)) { +ST_KIM_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 */ + } +ST_KIM_DBG (" 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 ) { +ST_KIM_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)) { +ST_KIM_ERR ("rfkill registration failed for gpio %ld" , + gpios[proto]); +rfkill_unregister (kim_gdata->rfkill[proto]); +continue ; + } +ST_KIM_DBG ("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 + } +ST_KIM_DBG ("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 ; +return ST_SUCCESS ; +} + +/**********************************************************************/ +/* entry point for ST KIM module, called in from ST Core */ + +long st_kim_init (void ) +{ +long ret =ST_SUCCESS ; + kim_gdata =kzalloc (sizeof (struct kim_data_s ),GFP_ATOMIC ); +if (!kim_gdata) { +ST_KIM_ERR ("no mem to allocate" ); +return -ENOMEM ; + } + ret =platform_driver_register (&kim_platform_driver); +if (ret !=0 ) { +ST_KIM_ERR ("platform drv registration failed" ); +return ST_ERR_FAILURE ; + } +return ST_SUCCESS ; +} + +long st_kim_deinit (void ) +{ +/* the following returns void */ +platform_driver_unregister (&kim_platform_driver); +kfree (kim_gdata); + kim_gdata =NULL ; +return ST_SUCCESS ; +}
drivers/staging/ti-st/st_kim.h new file +152 -0
152 lines not on this page · raw message
Signature · 1 line
1.5.4.3
PATCH 1/1 drivers:staging: sources for HCI LL PM protocol
From: Pavan Savoy <[email protected]>
Texas Instruments BT, FM and GPS combo chips/drivers make use of a single TTY to communicate with the chip. This module constitutes the proprietary power management protocol from TI for the BT/FM/GPS combo chips
--- drivers/staging/ti-st/st_ll.c | 169 +++++++++++++++++++++++++++++++++++++++++ drivers/staging/ti-st/st_ll.h | 67 ++++++++++++++++ 2 files changed, 236 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/ti-st/st_ll.c create mode 100644 drivers/staging/ti-st/st_ll.h
drivers/staging/ti-st/st_ll.c new file +169 -0
@@ -0,0 +1,169 @@ +/* +* Shared Transport driver +* HCI-LL module responsible for TI proprietary HCI_LL protocol +* 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 "st_ll.h" + +/* all debug macros go in here */ +#define ST_LL_ERR(fmt, arg...) printk(KERN_ERR "(stll):"fmt"\n" , ## arg) +#if defined(DEBUG )/* limited debug messages */ +#define ST_LL_DBG(fmt, arg...) printk(KERN_INFO "(stll):"fmt"\n" , ## arg) +#define ST_LL_VER(fmt, arg...) +#elif defined(VERBOSE )/* very verbose */ +#define ST_LL_DBG(fmt, arg...) printk(KERN_INFO "(stll):"fmt"\n" , ## arg) +#define ST_LL_VER(fmt, arg...) printk(KERN_INFO "(stll):"fmt"\n" , ## arg) +#else /* error msgs only */ +#define ST_LL_DBG(fmt, arg...) +#define ST_LL_VER(fmt, arg...) +#endif + +static struct ll_struct_s *ll; + +/**********************************************************************/ +/* internal functions */ +static void send_ll_cmd (unsigned char cmd) +{ + +ST_LL_DBG ("%s: writing %x" , __func__, cmd); +st_int_write (&cmd,1 ); +return ; +} + +static void ll_device_want_to_sleep (void ) +{ +ST_LL_DBG ("%s" , __func__); +/* sanity check */ +if (ll->ll_state !=ST_LL_AWAKE ) +ST_LL_ERR ("ERR hcill: ST_LL_GO_TO_SLEEP_IND" +"in state %ld" , ll->ll_state); + +send_ll_cmd (LL_SLEEP_ACK ); +/* update state */ + ll->ll_state =ST_LL_ASLEEP ; +} + +static void ll_device_want_to_wakeup (void ) +{ +/* diff actions in diff states */ +switch (ll->ll_state) { +case ST_LL_ASLEEP : +send_ll_cmd (LL_WAKE_UP_ACK );/* send wake_ack */ +break ; +case ST_LL_ASLEEP_TO_AWAKE : +/* duplicate wake_ind */ +ST_LL_ERR ("duplicate wake_ind while waiting for Wake ack" ); +break ; +case ST_LL_AWAKE : +/* duplicate wake_ind */ +ST_LL_ERR ("duplicate wake_ind already AWAKE" ); +break ; +case ST_LL_AWAKE_TO_ASLEEP : +/* duplicate wake_ind */ +ST_LL_ERR ("duplicate wake_ind" ); +break ; + } +/* update state */ + ll->ll_state =ST_LL_AWAKE ; +} + +/**********************************************************************/ +/* functions invoked by ST Core */ + +/* called when ST Core wants to +* enable ST LL */ +void st_ll_enable (void ) +{ + ll->ll_state =ST_LL_AWAKE ; +} + +/* called when ST Core /local module wants to +* disable ST LL */ +void st_ll_disable (void ) +{ + ll->ll_state =ST_LL_INVALID ; +} + +/* called when ST Core wants to update the state */ +void st_ll_wakeup (void ) +{ +if (likely (ll->ll_state !=ST_LL_AWAKE )) { +send_ll_cmd (LL_WAKE_UP_IND );/* WAKE_IND */ + ll->ll_state =ST_LL_ASLEEP_TO_AWAKE ; + }else { +/* don't send the duplicate wake_indication */ +ST_LL_ERR (" Chip already AWAKE " ); + } +} + +/* called when ST Core wants the state */ +unsigned long st_ll_getstate (void ) +{ +ST_LL_DBG (" returning state %ld" , ll->ll_state); +return ll->ll_state; +} + +/* called from ST Core, when a PM related packet arrives */ +unsigned long st_ll_sleep_state (unsigned char cmd) +{ +switch (cmd) { +case LL_SLEEP_IND :/* sleep ind */ +ST_LL_DBG ("sleep indication recvd" ); +ll_device_want_to_sleep (); +break ; +case LL_SLEEP_ACK :/* sleep ack */ +ST_LL_ERR ("sleep ack rcvd: host shouldn't" ); +break ; +case LL_WAKE_UP_IND :/* wake ind */ +ST_LL_DBG ("wake indication recvd" ); +ll_device_want_to_wakeup (); +break ; +case LL_WAKE_UP_ACK :/* wake ack */ +ST_LL_DBG ("wake ack rcvd" ); + ll->ll_state =ST_LL_AWAKE ; +break ; +default : +ST_LL_ERR (" unknown input/state " ); +return ST_ERR_FAILURE ; + } +return ST_SUCCESS ; +} + +/* Called from ST CORE to initialize ST LL */ +long st_ll_init (void ) +{ +long err =ST_SUCCESS ; + +/* Allocate memory for ST LL private structure */ + ll =kzalloc (sizeof (*ll),GFP_ATOMIC ); +if (!ll) { +ST_LL_ERR ("kzalloc failed to alloc memory for ST LL" ); + err = -ENOMEM ; +return err; + } +/* set state to invalid */ + ll->ll_state =ST_LL_INVALID ; +return err; +} + +/* Called from ST CORE to de-initialize ST LL */ +long st_ll_deinit (void ) +{ +kfree (ll); +return 0 ; +}
drivers/staging/ti-st/st_ll.h new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
1.5.4.3
PATCH 1/1 drivers:staging: sources for ST header file
From: Pavan Savoy <[email protected]>
Texas Instruments BT, FM and GPS combo chips/drivers make use of a single TTY to communicate with the chip. This is the common header file for both the ST driver and the protocol drivers which intend to use ST as their mode of transport.
--- drivers/staging/ti-st/fm.h | 13 ++++++ drivers/staging/ti-st/st.h | 90 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/ti-st/fm.h create mode 100644 drivers/staging/ti-st/st.h
drivers/staging/ti-st/fm.h new file +13 -0
@@ -0,0 +1,13 @@ +struct fm_event_hdr { +unsigned char plen; +} __attribute__ ((packed)); + +#define FM_MAX_FRAME_SIZE 0xFF/* TODO: */ +#define FM_EVENT_HDR_SIZE 1/* size of fm_event_hdr */ +#define ST_FM_CH8_PKT 0x8 + +/* gps stuff */ +struct gps_event_hdr { +unsigned char opcode; +unsigned short plen; +} __attribute__ ((packed));
drivers/staging/ti-st/st.h new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
1.5.4.3
PATCH 1/1 drivers:staging: Kconfig, Makefile for TI's ST ldisc
From: Pavan Savoy <[email protected]>
This change adds the Kconfig and Make file for TI's ST line discipline driver and the BlueZ driver for BT core of the TI BT/FM/GPS combo chip.
--- drivers/staging/Kconfig | 2 ++ drivers/staging/Makefile | 1 + drivers/staging/ti-st/Kconfig | 24 ++++++++++++++++++++++++ drivers/staging/ti-st/Makefile | 7 +++++++ 4 files changed, 34 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/ti-st/Kconfig create mode 100644 drivers/staging/ti-st/Makefile
drivers/staging/Kconfig +2 -0
@@ -141,5 +141,7 @@ source "drivers/staging/dt3155/Kconfig" source "drivers/staging/crystalhd/Kconfig" +source "drivers/staging/ti-st/Kconfig" + endif # !STAGING_EXCLUDE_BUILD endif # STAGING
drivers/staging/Makefile +1 -0
@@ -52,3 +52,4 @@ obj-$(CONFIG_PCMCIA_NETWAVE) += netwave/ obj-$(CONFIG_FB_SM7XX) += sm7xx/ obj-$(CONFIG_DT3155) += dt3155/ obj-$(CONFIG_CRYSTALHD) += crystalhd/ +obj-$(CONFIG_TI_ST) += ti-st/
drivers/staging/ti-st/Kconfig new file +24 -0
@@ -0,0 +1,24 @@ +# +# TI's shared transport line discipline and the protocol +# drivers (BT, FM and GPS) +# +menu "Texas Instruments shared transport line discipline" +config TI_ST + tristate "shared transport core driver" + select FW_LOADER + help + This enables the shared transport core driver for TI + BT / FM and GPS combo chips. This enables protocol drivers + to register themselves with core and send data, the responses + are returned to relevant protocol drivers based on their + packet types. + +config ST_BT + tristate "BlueZ bluetooth driver for ST" + depends on BT + select TI_ST + help + This enables the Bluetooth driver for TI BT/FM/GPS combo devices. + This makes use of shared transport line discipline core driver to + communicate with the BT core of the combo chip. +endmenu
drivers/staging/ti-st/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for TI's shared transport line discipline +# and its protocol drivers (BT, FM, GPS) +# +obj-$(CONFIG_TI_ST) += st_drv.o +st_drv-objs := st_core.o st_kim.o st_ll.o +obj-$(CONFIG_ST_BT) += bt_drv.o
Signature · 1 line
1.5.4.3
PATCH 1/1 Documentation:staging: add TODO and ABI to ti-st
From: Pavan Savoy <[email protected]>
A TODO file and a ABI to list the things to be done, and user-space/kernel-space interface for this ldisc.
--- drivers/staging/ti-st/TODO | 19 +++++++++++++++++++ drivers/staging/ti-st/sysfs-uim | 16 ++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/ti-st/TODO create mode 100644 drivers/staging/ti-st/sysfs-uim
drivers/staging/ti-st/TODO new file +19 -0
@@ -0,0 +1,19 @@ +TODO: + +1. A per-device/tty port context required to support multiple devices +on same platform. + +2. REMOVE the sysfs entry PID passing mechanism, since there should +be a better way to request user-space to install line discipline. + +3. Re-view/Re-work on the locking. + +4. Re-structure to make the ldisc driver more generic for chipsets which mux +multiple connectivity (BT, FM, GPS) upon 1 TTY port. + +5. Step up and maintain this driver to ensure that it continues +to work. Having the hardware for this is pretty much a +requirement. If this does not happen, the will be removed in +the 2.6.35 kernel release. + +Please send patches to Greg Kroah-Hartman <[email protected]>.
drivers/staging/ti-st/sysfs-uim new file +16 -0
@@ -0,0 +1,16 @@ +What: /sys/class/rfkill/rfkill%d/ +Date: March 22 +Contact: Pavan Savoy <[email protected]> +Description: + Creates the rfkill entries for Radio apps like + BT app, FM app or GPS app to toggle corresponding + cores of the chip + +What: /dev/rfkill +Date: March 22 +Contact: Pavan Savoy <[email protected]> +Description: + A daemon which maintains the ldisc installation and + uninstallation would be ppolling on this device and listening + on events which would suggest either to install or un-install + line discipline
Signature · 1 line
1.5.4.3
PATCH 1/1 bluetooth: BT driver using ST for TI combo devices
From: Pavan Savoy <[email protected]>
This is BlueZ driver making use of Shared Transport line discipline to communicate with the chip.
--- drivers/staging/ti-st/bt_drv.c | 502 ++++++++++++++++++++++++++++++++++++++++ drivers/staging/ti-st/bt_drv.h | 61 +++++ 2 files changed, 563 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/ti-st/bt_drv.c create mode 100644 drivers/staging/ti-st/bt_drv.h
drivers/staging/ti-st/bt_drv.c new file +502 -0
@@ -0,0 +1,502 @@ +/* +* Texas Instrument's Bluetooth Driver For Shared Transport. +* +* Bluetooth Driver acts as interface between HCI CORE and +* TI Shared Transport Layer. +* +* 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 <net/bluetooth/bluetooth.h> +#include <net/bluetooth/hci_core.h> + +#include "st.h" +#include "bt_drv.h" + +/* Define this macro to get debug msg */ +#undef DEBUG + +#ifdef DEBUG +#define BT_DRV_DBG(fmt, arg...) printk(KERN_INFO "(btdrv):"fmt"\n" , ## arg) +#define BTDRV_API_START () printk(KERN_INFO "(btdrv): %s Start\n", \ + __func__) +#define BTDRV_API_EXIT (errno) printk(KERN_INFO "(btdrv): %s Exit(%d)\n", \ + __func__, errno) +#else +#define BT_DRV_DBG(fmt, arg...) +#define BTDRV_API_START () +#define BTDRV_API_EXIT (errno) +#endif + +#define BT_DRV_ERR(fmt, arg...) printk(KERN_ERR "(btdrv):"fmt"\n" , ## arg) + +static int reset; +static struct hci_st *hst; + +/* Increments HCI counters based on pocket ID (cmd,acl,sco) */ +static inline void hci_st_tx_complete (struct hci_st *hst,int pkt_type) +{ +struct hci_dev *hdev; + +BTDRV_API_START (); + + hdev = hst->hdev; + +/* Update HCI stat counters */ +switch (pkt_type) { +case HCI_COMMAND_PKT : + hdev->stat.cmd_tx++; +break ; + +case HCI_ACLDATA_PKT : + hdev->stat.acl_tx++; +break ; + +case HCI_SCODATA_PKT : + hdev->stat.cmd_tx++; +break ; + } + +BTDRV_API_EXIT (0 ); +} + +/* ------- Interfaces to Shared Transport ------ */ + +/* Called by ST layer to indicate protocol registration completion +* status.hci_st_open() function will wait for signal from this +* API when st_register() function returns ST_PENDING. +*/ +static void hci_st_registration_completion_cb (char data) +{ +BTDRV_API_START (); + +/* hci_st_open() function needs value of 'data' to know +* the registration status(success/fail),So have a back +* up of it. +*/ + hst->streg_cbdata = data; + +/* Got a feedback from ST for BT driver registration +* request.Wackup hci_st_open() function to continue +* it's open operation. +*/ +complete (&hst->wait_for_btdrv_reg_completion); + +BTDRV_API_EXIT (0 ); +} + +/* Called by Shared Transport layer when receive data is +* available */ +static long hci_st_receive (struct sk_buff *skb) +{ +int err; +int len; + +BTDRV_API_START (); + + err =0 ; + len =0 ; + +if (skb ==NULL ) { +BT_DRV_ERR ("Invalid SKB received from ST" ); +BTDRV_API_EXIT (-EFAULT ); +return -EFAULT ; + } +if (!hst) { +kfree_skb (skb); +BT_DRV_ERR ("Invalid hci_st memory,freeing SKB" ); +BTDRV_API_EXIT (-EFAULT ); +return -EFAULT ; + } +if (!test_bit (BT_DRV_RUNNING , &hst->flags)) { +kfree_skb (skb); +BT_DRV_ERR ("Device is not running,freeing SKB" ); +BTDRV_API_EXIT (-EINVAL ); +return -EINVAL ; + } + + len = skb->len; + skb->dev = (struct net_device *)hst->hdev; + +/* Forward skb to HCI CORE layer */ + err =hci_recv_frame (skb); +if (err) { +kfree_skb (skb); +BT_DRV_ERR ("Unable to push skb to HCI CORE(%d),freeing SKB" , + err); +BTDRV_API_EXIT (err); +return err; + } + hst->hdev->stat.byte_rx += len; + +BTDRV_API_EXIT (0 ); +return 0 ; +} + +/* ------- Interfaces to HCI layer ------ */ + +/* Called from HCI core to initialize the device */ +static int hci_st_open (struct hci_dev *hdev) +{ +static struct st_proto_s hci_st_proto; +unsigned long timeleft; +int err; + +BTDRV_API_START (); + + err =0 ; + +BT_DRV_DBG ("%s %p" , hdev->name, hdev); + +/* Already registered with ST ? */ +if (test_bit (BT_ST_REGISTERED , &hst->flags)) { +BT_DRV_ERR ("Registered with ST already,open called again?" ); +BTDRV_API_EXIT (0 ); +return 0 ; + } + +/* Populate BT driver info required by ST */ +memset (&hci_st_proto,0 ,sizeof (hci_st_proto)); + +/* BT driver ID */ + hci_st_proto.type =ST_BT ; + +/* Receive function which called from ST */ + hci_st_proto.recv = hci_st_receive; + +/* Packet match function may used in future */ + hci_st_proto.match_packet =NULL ; + +/* Callback to be called when registration is pending */ + hci_st_proto.reg_complete_cb = hci_st_registration_completion_cb; + +/* This is write function pointer of ST. BT driver will make use of this +* for sending any packets to chip. ST will assign and give to us, so +* make it as NULL */ + hci_st_proto.write =NULL ; + +/* Register with ST layer */ + err =st_register (&hci_st_proto); +if (err ==ST_ERR_PENDING ) { +/* Prepare wait-for-completion handler data structures. +* Needed to syncronize this and st_registration_completion_cb() +* functions. +*/ +init_completion (&hst->wait_for_btdrv_reg_completion); + +/* Reset ST registration callback status flag , this value +* will be updated in hci_st_registration_completion_cb() +* function whenever it called from ST driver. +*/ + hst->streg_cbdata = -EINPROGRESS ; + +/* ST is busy with other protocol registration(may be busy with +* firmware download).So,Wait till the registration callback +* (passed as a argument to st_register() function) getting +* called from ST. +*/ +BT_DRV_DBG (" %s waiting for reg completion signal from ST" , + __func__); + + timeleft = +wait_for_completion_timeout + (&hst->wait_for_btdrv_reg_completion, +msecs_to_jiffies (BT_REGISTER_TIMEOUT )); +if (!timeleft) { +BT_DRV_ERR ("Timeout(%ld sec),didn't get reg" +"completion signal from ST" , +BT_REGISTER_TIMEOUT /1000 ); +BTDRV_API_EXIT (-ETIMEDOUT ); +return -ETIMEDOUT ; + } + +/* Is ST registration callback called with ERROR value? */ +if (hst->streg_cbdata !=0 ) { +BT_DRV_ERR ("ST reg completion CB called with invalid" +"status %d" , hst->streg_cbdata); +BTDRV_API_EXIT (-EAGAIN ); +return -EAGAIN ; + } + err =0 ; + }else if (err ==ST_ERR_FAILURE ) { +BT_DRV_ERR ("st_register failed %d" , err); +BTDRV_API_EXIT (-EAGAIN ); +return -EAGAIN ; + } + +/* Do we have proper ST write function? */ +if (hci_st_proto.write !=NULL ) { +/* We need this pointer for sending any Bluetooth pkts */ + hst->st_write = hci_st_proto.write; + }else { +BT_DRV_ERR ("failed to get ST write func pointer" ); + +/* Undo registration with ST */ + err =st_unregister (ST_BT ); +if (err <0 ) +BT_DRV_ERR ("st_unregister failed %d" , err); + + hst->st_write =NULL ; +BTDRV_API_EXIT (-EAGAIN ); +return -EAGAIN ; + } + +/* Registration with ST layer is completed successfully, +* now chip is ready to accept commands from HCI CORE. +* Mark HCI Device flag as RUNNING +*/ +set_bit (HCI_RUNNING , &hdev->flags); + +/* Registration with ST successful */ +set_bit (BT_ST_REGISTERED , &hst->flags); + +BTDRV_API_EXIT (err); +return err; +} + +/* Close device */ +static int hci_st_close (struct hci_dev *hdev) +{ +int err; + +BTDRV_API_START (); + + err =0 ; + +/* Unregister from ST layer */ +if (test_and_clear_bit (BT_ST_REGISTERED , &hst->flags)) { + err =st_unregister (ST_BT ); +if (err !=ST_SUCCESS ) { +BT_DRV_ERR ("st_unregister failed %d" , err); +BTDRV_API_EXIT (-EBUSY ); +return -EBUSY ; + } + } + + hst->st_write =NULL ; + +/* ST layer would have moved chip to inactive state. +* So,clear HCI device RUNNING flag. +*/ +if (!test_and_clear_bit (HCI_RUNNING , &hdev->flags)) { +BTDRV_API_EXIT (0 ); +return 0 ; + } + +BTDRV_API_EXIT (err); +return err; +} + +/* Called from HCI CORE , Sends frames to Shared Transport */ +static int hci_st_send_frame (struct sk_buff *skb) +{ +struct hci_dev *hdev; +struct hci_st *hst; +long len; + +BTDRV_API_START (); + +if (skb ==NULL ) { +BT_DRV_ERR ("Invalid skb received from HCI CORE" ); +BTDRV_API_EXIT (-ENOMEM ); +return -ENOMEM ; + } + hdev = (struct hci_dev *)skb->dev; +if (!hdev) { +BT_DRV_ERR ("SKB received for invalid HCI Device (hdev=NULL)" ); +BTDRV_API_EXIT (-ENODEV ); +return -ENODEV ; + } +if (!test_bit (HCI_RUNNING , &hdev->flags)) { +BT_DRV_ERR ("Device is not running" ); +BTDRV_API_EXIT (-EBUSY ); +return -EBUSY ; + } + + hst = (struct hci_st *)hdev->driver_data; + +/* Prepend skb with frame type */ +memcpy (skb_push (skb,1 ), &bt_cb (skb)->pkt_type,1 ); + +BT_DRV_DBG (" %s: type %d len %d" , hdev->name,bt_cb (skb)->pkt_type, + skb->len); + +/* Insert skb to shared transport layer's transmit queue. +* Freeing skb memory is taken care in shared transport layer, +* so don't free skb memory here. +*/ +if (!hst->st_write) { +kfree_skb (skb); +BT_DRV_ERR (" Can't write to ST, st_write null?" ); +BTDRV_API_EXIT (-EAGAIN ); +return -EAGAIN ; + } + len = hst->st_write (skb); +if (len <0 ) { +/* Something went wrong in st write , free skb memory */ +kfree_skb (skb); +BT_DRV_ERR (" ST write failed (%ld)" , len); +BTDRV_API_EXIT (-EAGAIN ); +return -EAGAIN ; + } + +/* ST accepted our skb. So, Go ahead and do rest */ + hdev->stat.byte_tx += len; +hci_st_tx_complete (hst,bt_cb (skb)->pkt_type); + +BTDRV_API_EXIT (0 ); +return 0 ; +} + +static void hci_st_destruct (struct hci_dev *hdev) +{ +BTDRV_API_START (); + +if (!hdev) { +BT_DRV_ERR ("Destruct called with invalid HCI Device" +"(hdev=NULL)" ); +BTDRV_API_EXIT (0 ); +return ; + } + +BT_DRV_DBG ("%s" , hdev->name); + +/* free hci_st memory */ +if (hdev->driver_data !=NULL ) +kfree (hdev->driver_data); + +BTDRV_API_EXIT (0 ); +return ; +} + +/* Creates new HCI device */ +static int hci_st_register_dev (struct hci_st *hst) +{ +struct hci_dev *hdev; + +BTDRV_API_START (); + +/* Initialize and register HCI device */ + hdev =hci_alloc_dev (); +if (!hdev) { +BT_DRV_ERR ("Can't allocate HCI device" ); +BTDRV_API_EXIT (-ENOMEM ); +return -ENOMEM ; + } +BT_DRV_DBG (" HCI device allocated. hdev= %p" , hdev); + + hst->hdev = hdev; + hdev->bus =HCI_UART ; + hdev->driver_data = hst; + hdev->open = hci_st_open; + hdev->close = hci_st_close; + hdev->flush =NULL ; + hdev->send = hci_st_send_frame; + hdev->destruct = hci_st_destruct; + hdev->owner =THIS_MODULE ; + +if (reset) +set_bit (HCI_QUIRK_NO_RESET , &hdev->quirks); + +if (hci_register_dev (hdev) <0 ) { +BT_DRV_ERR ("Can't register HCI device" ); +hci_free_dev (hdev); +BTDRV_API_EXIT (-ENODEV ); +return -ENODEV ; + } + +BT_DRV_DBG (" HCI device registered. hdev= %p" , hdev); +BTDRV_API_EXIT (0 ); +return 0 ; +} + +/* ------- Module Init interface ------ */ + +static int __init bt_drv_init (void ) +{ +int err; + +BTDRV_API_START (); + + err =0 ; + +BT_DRV_DBG (" Bluetooth Driver Version %s" ,VERSION ); + +/* Allocate local resource memory */ + hst =kzalloc (sizeof (struct hci_st ),GFP_KERNEL ); +if (!hst) { +BT_DRV_ERR ("Can't allocate control structure" ); +BTDRV_API_EXIT (-ENFILE ); +return -ENFILE ; + } + +/* Expose "hciX" device to user space */ + err =hci_st_register_dev (hst); +if (err) { +/* Release local resource memory */ +kfree (hst); + +BT_DRV_ERR ("Unable to expose hci0 device(%d)" , err); +BTDRV_API_EXIT (err); +return err; + } +set_bit (BT_DRV_RUNNING , &hst->flags); + +BTDRV_API_EXIT (err); +return err; +} + +/* ------- Module Exit interface ------ */ + +static void __exit bt_drv_exit(void) +{ +BTDRV_API_START (); + +/* Deallocate local resource's memory */ +if (hst) { +struct hci_dev *hdev = hst->hdev; + +if (hdev ==NULL ) { +BT_DRV_ERR ("Invalid hdev memory" ); +kfree (hst); + }else { +hci_st_close (hdev); +if (test_and_clear_bit (BT_DRV_RUNNING , &hst->flags)) { +/* Remove HCI device (hciX) created +* in module init. +*/ +hci_unregister_dev (hdev); + +/* Free HCI device memory */ +hci_free_dev (hdev); + } + } + } +BTDRV_API_EXIT (0 ); +} + +module_init (bt_drv_init); +module_exit (bt_drv_exit); + +/* ------ Module Info ------ */ + +module_param (reset, bool,0644 ); +MODULE_PARM_DESC (reset,"Send HCI reset command on initialization" ); +MODULE_AUTHOR ("Raja Mani <[email protected]>" ); +MODULE_DESCRIPTION ("Bluetooth Driver for TI Shared Transport" VERSION ); +MODULE_VERSION (VERSION ); +MODULE_LICENSE ("GPL" );
drivers/staging/ti-st/bt_drv.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
1.5.4.3
Re: [PATCH] drivers:staging: sources for HCI LL PM protocol
In reply to [email protected]Quoted 2 lines
+static struct
ll_struct_s*ll;
More magic globals. I think this more than anything else demonstrates why you need some kind of proper per device context passed around
Re: [PATCH] drivers:staging: sources for HCI LL PM protocol
Quoted 6 lines · Alan Cox
From: Alan Cox <[email protected]>
Subject: Re: [PATCH] drivers:staging: sources for HCI LL PM protocol
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Date: Tuesday, 30 March, 2010, 4:54 PM
Quoted 7 lines
Quoted 1 line
+static struct
ll_struct_s*ll;More magic globals. I think this more than anything else demonstrates why
you need some kind of proper per device context passed around
The ST KIM module, is a platform device, which I use to pass the GPIO data from the arch/XX/board-XXX.c files, so, suppose we do have 2 devices for a platform, then I would need 2 platform devices right ?
And there-by can I use that platform device context ? However the problem really is,
Suppose a BT driver wants to do an st_register() and use ST as its transport, how can I then tie it to a device ?
Quoted 7 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
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/
Re: [PATCH] drivers:staging: sources for HCI LL PM protocol
Quoted 3 lines
The ST KIM module, is a platform device, which I use to pass the GPIO data from the
arch/XX/board-XXX.cfiles, so, suppose we do have 2 devices for a platform, then I would need 2 platform devices right ?And there-by can I use that platform device context ?
Yes or some struct created in the actual module and passed around in preference to the platform device. A lot of kernel drivers end up creating something per device that looks like
struct my_thing {
struct device *dev; /* or pci_dev etc */
[ all my per device bits ]
};
and sometimes creating linked lists of them (for power management most often)
Quoted 3 lines
However the problem really is,
Suppose a BT driver wants to do an
st_register()and use ST as its transport, how can I then tie it to a device ?
Not sure I follow
If you have some kind of context to kill off all the globals then you can attach that to whatever local object you have for each device you are interested in. That is why IRQ handlers pass a data value, why timers do, why tty has ldisc_data, why workqueues do similar things and so on.
And if there is another layer you need to interface to which doesn't have some kind of pointer for binding to layers above/below - add one.
Re: [PATCH] drivers:staging: sources for ST core
In reply to [email protected]drivers/staging/ti-st/st_core.c line 51
Quoted 12 lines
drivers/staging/ti-st/st_core.c new file +12
-0+/* 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
drivers/staging/ti-st/st_core.c line 72
Quoted 9 lines
drivers/staging/ti-st/st_core.c new file +9
-0+/* +* 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)
Quoted 4 lines
drivers/staging/ti-st/st_core.c new file +4
-0+ +/********************************************************************/ +/* internal misc functions */ +bool is_protocol_list_empty (void )
drivers/staging/ti-st/st_core.c line 86
Quoted 10 lines
drivers/staging/ti-st/st_core.c new file +10
-0+{ +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 ?
drivers/staging/ti-st/st_core.c line 103
Quoted 11 lines
+ * This is the internal write function - a wrapper
+ * totty->ops->write
+ */drivers/staging/ti-st/st_core.c new file +8
-0+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)
Review
Quoted 1 line
(quoted diff) +1
-0+ 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
Quoted 6 lines
drivers/staging/ti-st/st_core.c new file +6
-0+/* +* push the skb received to relevant +* protocol stacks +*/ +void st_send_frame (enum proto_type protoid,struct sk_buff *skb) +{
drivers/staging/ti-st/st_core.c line 133
Quoted 10 lines
drivers/staging/ti-st/st_core.c new file +10
-0+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 ?
drivers/staging/ti-st/st_core.c line 163
Quoted 9 lines
+ * to call registration complete callbacks
+ * of all protocol stack drivers
+ */drivers/staging/ti-st/st_core.c new file +6
-0+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.
drivers/staging/ti-st/st_core.c line 171
Quoted 3 lines
drivers/staging/ti-st/st_core.c new file +3
-0+static inline int st_check_data_len (int protoid,int len) +{ + registerint 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
drivers/staging/ti-st/st_core.c line 234
Quoted 5 lines
drivers/staging/ti-st/st_core.c new file +5
-0+/* 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
drivers/staging/ti-st/st_core.c line 489
Quoted 3 lines
drivers/staging/ti-st/st_core.c new file +2
-0+/* 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
drivers/staging/ti-st/st_core.c line 548
Quoted 10 lines
drivers/staging/ti-st/st_core.c new file +8
-0+/* +* 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
Quoted 5 lines
drivers/staging/ti-st/st_core.c new file +5
-0+/* functions called from ST KIM +*/ +void kim_st_list_protocols (char *buf) +{ +unsigned long flags =0 ;
drivers/staging/ti-st/st_core.c line 587
Quoted 10 lines
drivers/staging/ti-st/st_core.c new file +10
-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.
Quoted 8 lines
drivers/staging/ti-st/st_core.c new file +8
-0+/********************************************************************/ +/* +* functions called from protocol stack drivers +* to be EXPORT-ed +*/ +long st_register (struct st_proto_s *new_proto) +{ +long err =ST_SUCCESS ;
drivers/staging/ti-st/st_core.c line 842
Quoted 10 lines
drivers/staging/ti-st/st_core.c new file +8
-0+* 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
drivers/staging/ti-st/st_core.c line 888
Quoted 5 lines
drivers/staging/ti-st/st_core.c new file +4
-0+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
Quoted 6 lines
drivers/staging/ti-st/st_core.c new file +6
-0+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" );
drivers/staging/ti-st/st_core.c line 919
Quoted 10 lines
drivers/staging/ti-st/st_core.c new file +10
-0+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
Quoted 11 lines
drivers/staging/ti-st/st_core.c new file +11
-0+/********************************************************************/ +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 ;
drivers/staging/ti-st/st_core.c line 967
Quoted 10 lines
drivers/staging/ti-st/st_core.c new file +10
-0+ } + + 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 ?
Re: [PATCH] drivers:staging: sources for ST core
Alan,
Quoted 19 lines · Alan Cox
From: Alan Cox <[email protected]>
Subject: Re: [PATCH] drivers:staging: sources for ST core
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Date: Tuesday, 30 March, 2010, 4:52 PMQuoted 1 line
+/* all debug macros go in here
*/
Quoted 1 line
+#define
ST_DRV_ERR(fmt, arg...)printk(KERN_ERR"(stc):"fmt"\n" , ## arg)
Quoted 1 line
+#if defined(DEBUG)
/* limited debug messages */
Quoted 1 line
+#define
ST_DRV_DBG(fmt, arg...)
printk(KERN_INFO "(stc):"fmt"\n" , ## arg)Review
Quoted 2 lines
(quoted diff) +2
-0+#define ST_DRV_VER(fmt, arg...) +#elif defined(VERBOSE)/* very verbose */
Quoted 1 line
+#define
ST_DRV_DBG(fmt, arg...)
printk(KERN_INFO "(stc):"fmt"\n" , ## arg)Quoted 1 line
+#define
ST_DRV_VER(fmt, arg...)
Quoted 8 lines
printk(KERN_INFO "(stc):"fmt"\n" , ## arg)drivers/staging/ti-st/st_core.c line 51
Quoted 4 lines
drivers/staging/ti-st/st_core.c new file +4
-0+#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.
Quoted 9 lines
drivers/staging/ti-st/st_core.c
Quoted 7 lines
drivers/staging/ti-st/st_core.c new file +6
-0+/* +* 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
Quoted 1 line
+ *
st_int_recvafter registration to receive proto
Quoted 8 lines
stack responses
Quoted 2 lines
+ */
+void (*st_recv) (const unsigned char *data, longcount);
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 ?
Quoted 13 lines
Quoted 2 lines
+
+/********************************************************************/
drivers/staging/ti-st/st_core.c
Quoted 7 lines
drivers/staging/ti-st/st_core.c new file +7
-0+/* 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)
Quoted 1 line
+
return
ST_NOTEMPTY;
Quoted 8 lines
Quoted 1 line
+ /* not empty
*/
Quoted 3 lines
+ }
+ /* list empty */
+ returnST_EMPTY;Why not just keep a count of entries you've added/removed ?
One more variable ? to st_gdata ? done. Sounds simple.
Quoted 15 lines
Quoted 2 lines
+ * This is the internal write function - a
wrapper
Quoted 3 lines
+ * to
tty->ops->write
+ */
+int st_int_write(const unsigned char *data, intcount)
Review
Quoted 2 lines
(quoted diff) +2
-0+{ +#ifdef VERBOSE/* for debug */
Quoted 4 lines
+ int i;
+#endif
+ structtty_struct*tty;
+ if (unlikely(st_gdata == NULL ||
st_gdata->tty== NULL)) {
Quoted 8 lines
Quoted 1 line
+ ST_DRV_ERR("tty
unavailable to perform write");
You need to use the tty pointer passed, you don't want to walk
tty->somethingand 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.
Quoted 7 lines
Quoted 1 line
+ return
ST_ERR_FAILURE;Should be using Linux error codes for upstream. A global search/replace
of theST_ERR_xxxfor a similar -Efoo code will do the trick I think
Ok, But is it ok, to maintain codes, internally among ST/BT/FM drivers ?
Quoted 19 lines
drivers/staging/ti-st/st_core.c
Quoted 5 lines
drivers/staging/ti-st/st_core.c new file +5
-0+/* +* push the skb received to relevant +* protocol stacks +*/ +void st_send_frame(enum proto_type protoid, struct
sk_buff*skb)Quoted 2 lines
+{
+ ST_DRV_DBG(" %s(prot:%d) ",
__func__, protoid);Quoted 3 lines
+
+ if (unlikely
+ (st_gdata== NULL ||skb == NULL
Quoted 1 line
+ ||
st_gdata->list[protoid] == NULL)) {
Quoted 1 line
+
ST_DRV_ERR("protocol %d not registered, no data to send?",
Quoted 1 line
+
protoid);
Quoted 8 lines
Quoted 1 line
+
kfree_skb(skb);Quoted 2 lines
+ 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 ?
Quoted 13 lines
drivers/staging/ti-st/st_core.c
Quoted 10 lines
+ * to call registration complete callbacks
+ * of all protocol stack drivers
+ */drivers/staging/ti-st/st_core.c new file +6
-0+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 &&
Quoted 3 lines
Except on very hot paths that go odd ways likely and unlikely are
normally a loss.
point taken.
Quoted 5 lines
Quoted 2 lines
+static inline int st_check_data_len(int protoid, int
len)
Quoted 2 lines
+{
+ register int room =
Quoted 7 lines
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.
Quoted 7 lines
Quoted 2 lines
+/* Decodes received RAW data and forwards to
corresponding
Quoted 4 lines
+ * client drivers (Bluetooth,FM,GPS..etc).
+ *
+ */
+void st_int_recv(const unsigned char *data, long
Quoted 6 lines
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.
Quoted 11 lines
Quoted 3 lines
+ /* this function can be invoked in
more then one context.
Quoted 1 line
+ * 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.
Quoted 10 lines
Quoted 8 lines
drivers/staging/ti-st/st_core.c new file +7
-0+/* +* 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)
Quoted 5 lines
Quoted 1 line
+ while ((skb =
st_int_dequeue(st_data))) {Called in two paths but
st_int_dequeueseems 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.
Quoted 22 lines
drivers/staging/ti-st/st_core.c line 603
Quoted 10 lines
drivers/staging/ti-st/st_core.c new file +9
-0+/* 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);Quoted 1 line
+#ifdef DEBUG
/* more detailed log */
Quoted 3 lines
+ for (i = 0; i <
ST_MAX; i++) {
+ if (i == 0) {
+sprintf(buf, "%s is %s",
protocol_strngs[i],Quoted 1 line
+
st_gdata->list[i]
!=Quoted 1 line
+
Quoted 8 lines
NULL ? "Registered" :
"Unregistered");Always a good idea to use snprintf and track size (plus pass buffer size)
it avoida accidents later. Or also see theseq_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.
Quoted 11 lines
Quoted 1 line
+/********************************************************************/
Quoted 9 lines
drivers/staging/ti-st/st_core.c new file +7
-0+/* +* functions called from protocol stack drivers +* to be EXPORT-ed +*/ +long st_register (struct st_proto_s *new_proto) +{ + long err = ST_SUCCESS;
Quoted 12 lines
drivers/staging/ti-st/st_core.c line 842
Quoted 8 lines
+ * functions called from TTY layer
+ */drivers/staging/ti-st/st_core.c new file +6
-0+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 ?
Quoted 9 lines
drivers/staging/ti-st/st_core.c
Quoted 4 lines
drivers/staging/ti-st/st_core.c new file +3
-0+static void st_tty_close (struct tty_struct *tty) +{ + /* Flush any pending characters inthe driver and discipline. */
Quoted 1 line
+
tty_driver_flush_buffer(tty);Close will deal with this anyway
yep, redundant - will remove it.
Quoted 21 lines
Quoted 2 lines
+static void st_tty_receive(struct
tty_struct*tty,const unsigned char *data,
Quoted 1 line
+
char
*tty_flags, int
count)drivers/staging/ti-st/st_core.c
Quoted 4 lines
drivers/staging/ti-st/st_core.c new file +4
-0+{ +#ifdef VERBOSE + long i; + printk(KERN_ERR "incomingdata...\n");
Quoted 2 lines
+ for (i = 0; i < count; i++)
+ printk(" %x",data[i]);
Quoted 1 line
+ printk(KERN_ERR "\n.. data
end\n");
drivers/staging/ti-st/st_core.c
Quoted 4 lines
drivers/staging/ti-st/st_core.c new file +4
-0+#endif + + /* +* if fw download is in progress then route incoming data
Quoted 8 lines
Quoted 1 line
+ * to KIM for
validation
Quoted 2 lines
+ */
+st_recv(data, count);If you passed tty up and used
tty->disc_datayou'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.
Quoted 30 lines
Quoted 1 line
+/********************************************************************/
drivers/staging/ti-st/st_core.c
Quoted 4 lines
drivers/staging/ti-st/st_core.c new file +4
-0+static int __init st_core_init (void ) +{ + long err; + static struct tty_ldisc_ops
*st_ldisc_ops;Quoted 2 lines
+
+ /* populate and register to TTYline discipline */
Quoted 1 line
+
st_ldisc_ops=
kzalloc(sizeof(*st_ldisc_ops), GFP_KERNEL);Quoted 2 lines
+ if (!st_ldisc_ops) {
+ ST_DRV_ERR("nomem to allocate");
Quoted 1 line
+ return
-ENOMEM;Quoted 3 lines
+ }
+
+st_ldisc_ops->magic=
TTY_LDISC_MAGIC;Quoted 1 line
+
st_ldisc_ops->name="n_st"; /*"n_hci"; */
Quoted 1 line
+
st_ldisc_ops->open=
st_tty_open;Quoted 1 line
+
st_ldisc_ops->close=
st_tty_close;Quoted 1 line
+
st_ldisc_ops->receive_buf=
st_tty_receive;Quoted 1 line
+
st_ldisc_ops->write_wakeup=
Quoted 9 lines
st_tty_wakeup;Quoted 1 line
+
st_ldisc_ops->flush_buffer=
st_tty_flush_buffer;Quoted 1 line
+
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/
Re: [PATCH] drivers:staging: sources for ST core
Quoted 32 lines · Pavan Savoy
Alan,
Quoted 19 lines · Alan Cox
From: Alan Cox <[email protected]>
Subject: Re: [PATCH] drivers:staging: sources for ST core
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Date: Tuesday, 30 March, 2010, 4:52 PMQuoted 1 line
+/* all debug macros go in here
*/
Quoted 1 line
+#define
ST_DRV_ERR(fmt, arg...)? printk(KERN_ERR"(stc):"fmt"\n" , ## arg)
Quoted 1 line
+#if defined(DEBUG)???
??? /* limited debug messages */
Quoted 1 line
+#define
ST_DRV_DBG(fmt, arg...)?
printk(KERN_INFO "(stc):"fmt"\n" , ## arg)Review
Quoted 2 lines
(quoted diff) +2
-0+#define ST_DRV_VER(fmt, arg...) +#elif defined(VERBOSE)?????? /* very verbose */
Quoted 1 line
+#define
ST_DRV_DBG(fmt, arg...)?
printk(KERN_INFO "(stc):"fmt"\n" , ## arg)Quoted 1 line
+#define
ST_DRV_VER(fmt, arg...)?Quoted 8 lines
printk(KERN_INFO "(stc):"fmt"\n" , ## arg)drivers/staging/ti-st/st_core.c line 51
Quoted 4 lines
drivers/staging/ti-st/st_core.c new file +4
-0+#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
Quoted 2 lines
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
Re: [PATCH] drivers:staging: sources for ST core
Quoted 55 lines · Greg KH
From: Greg KH <[email protected]>
Subject: Re: [PATCH] drivers:staging: sources for ST core
To: "Pavan Savoy" <[email protected]>
Cc: "Alan Cox" <[email protected]>, [email protected], [email protected]
Date: Wednesday, 31 March, 2010, 2:08 AMQuoted 3 lines · Pavan Savoy
Alan,
--- On Tue, 30/3/10, Alan Cox <[email protected]>
Quoted 3 lines · wrote:
Quoted 3 lines
From: Alan Cox <[email protected]>
Subject: Re: [PATCH] drivers:staging: sources forST core
Quoted 2 lines
Quoted 2 lines
To: [email protected]
Cc: [email protected],[email protected], [email protected],
[email protected]Quoted 4 lines
Quoted 4 lines
Date: Tuesday, 30 March, 2010, 4:52 PM
Quoted 1 line
+/* all debug macros go in here
*/
Quoted 1 line
+#define
ST_DRV_ERR(fmt, arg...)?printk(KERN_ERR
Quoted 10 lines
Quoted 10 lines
"(stc):"fmt"\n" , ## arg)
Quoted 1 line
+#if defined(DEBUG)???
??? /* limited debug messages */
Quoted 1 line
+#define
ST_DRV_DBG(fmt, arg...)?
printk(KERN_INFO "(stc):"fmt"\n" , ## arg)Review
Quoted 2 lines
(quoted diff) +2
-0+#define ST_DRV_VER(fmt, arg...) +#elif defined(VERBOSE)?????? /* very verbose */
Quoted 1 line
+#define
ST_DRV_DBG(fmt, arg...)?
printk(KERN_INFO "(stc):"fmt"\n" , ## arg)Quoted 8 lines
Quoted 8 lines
Quoted 1 line
+#define
ST_DRV_VER(fmt, arg...)?
printk(KERN_INFO "(stc):"fmt"\n" , ## arg)Review
Quoted 4 lines
(quoted diff) +4
-0+#else /* error msgs only */ +#define ST_DRV_DBG(fmt, arg...) +#define ST_DRV_VER(fmt, arg...) +#endifAs Greg said earlier - needs to be using the
standard debug
Quoted 3 lines
Quoted 1 line
macros
Agree - It's all there because of the organization's
coding standards.
Quoted 1 line
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.
Quoted 3 lines
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.
Quoted 1 line
From
67bdf81bb0a60e2c76a139dc4d39208eaa03bcaeMon Sep 17 00:00:00 2001
From: Pavan Savoy <[email protected]>
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.
--- 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
drivers/staging/ti-st/st_core.c new file +1045 -0
@@ -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) +{ + registerint 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) +{ + registerstruct 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) +{ + registerchar *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; + registerint 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 <[email protected]>" ); +MODULE_DESCRIPTION ("Shared Transport Driver for TI BT/FM/GPS combo chips " ); +MODULE_LICENSE ("GPL" );
drivers/staging/ti-st/st_core.h new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
1.5.4.3
Quoted 6 lines
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
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/
Re: [PATCH] drivers:staging: sources for ST core
Quoted 3 lines · Pavan Savoy
So, something like the below is ok, I have defined my own
pr_fmt, however default log level on my board is 7, and hencepr_infois 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
Re: [PATCH] drivers:staging: sources for ST core
In reply to Pavan Savoydrivers/staging/ti-st/st_core.c line 67
Quoted 4 lines · Pavan Savoy
drivers/staging/ti-st/st_core.c new file +4
-0+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.
drivers/staging/ti-st/st_core.c line 100
Quoted 6 lines
drivers/staging/ti-st/st_core.c new file +6
-0+#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
Re: [PATCH] serial: TTY: new ldiscs for staging
In reply to [email protected]Quoted 6 lines · On Thu, 25 Mar 2010 18:20:16 -0500 [email protected] wrote:
From: Pavan Savoy <[email protected]>
Push the max ldiscs by a few number to allow ldiscs to exist in the staging directory
Signed-off-by Pavan Savoy <[email protected]>
Re: [PATCH] serial: TTY: new ldiscs for staging
Alan,
Quoted 9 lines · Alan Cox
From: Alan Cox <[email protected]>
Subject: Re: [PATCH] serial: TTY: new ldiscs for staging
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Date: Friday, 26 March, 2010, 5:00 AM
On Thu, 25 Mar 2010 18:20:16 -0500
[email protected]
wrote:
Quoted 9 lines
Quoted 6 lines
From: Pavan Savoy <[email protected]>
Push the max ldiscs by a few number to allow ldiscs to exist in the staging directory
Signed-off-by Pavan Savoy <[email protected]>Acked-by Alan Cox <[email protected]>
What about the rest of the patches ?
Do you have any comments ?
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
Quoted 9 lines · On Thu, Mar 25, 2010 at 06:20:15PM -0500, [email protected] wrote:
Greg / Alan,
- moved to staging and completely self-contained
- REMOVed the sysfs entry creation at root and replaced it with sending events via rfkill.
- verified and working with new logic
- patch re-ordered
Looks good, I'll go over them in more detail next week when I get a solid internet connection and let you know if I can queue them up in my tree or not.
thanks,
greg k-h