2 * Shared Transport driver
3 * HCI-LL module responsible for TI proprietary HCI_LL protocol
4 * Copyright (C) 2009 Texas Instruments
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define pr_fmt(fmt) "(stll) :" fmt
24 /**********************************************************************/
25 /* internal functions */
26 static void send_ll_cmd(struct st_data_s
*st_data
,
30 pr_info("%s: writing %x", __func__
, cmd
);
31 st_int_write(st_data
, &cmd
, 1);
35 static void ll_device_want_to_sleep(struct st_data_s
*st_data
)
37 pr_info("%s", __func__
);
39 if (st_data
->ll_state
!= ST_LL_AWAKE
)
40 pr_err("ERR hcill: ST_LL_GO_TO_SLEEP_IND"
41 "in state %ld", st_data
->ll_state
);
43 send_ll_cmd(st_data
, LL_SLEEP_ACK
);
45 st_data
->ll_state
= ST_LL_ASLEEP
;
48 static void ll_device_want_to_wakeup(struct st_data_s
*st_data
)
50 /* diff actions in diff states */
51 switch (st_data
->ll_state
) {
53 send_ll_cmd(st_data
, LL_WAKE_UP_ACK
); /* send wake_ack */
55 case ST_LL_ASLEEP_TO_AWAKE
:
56 /* duplicate wake_ind */
57 pr_err("duplicate wake_ind while waiting for Wake ack");
60 /* duplicate wake_ind */
61 pr_err("duplicate wake_ind already AWAKE");
63 case ST_LL_AWAKE_TO_ASLEEP
:
64 /* duplicate wake_ind */
65 pr_err("duplicate wake_ind");
69 st_data
->ll_state
= ST_LL_AWAKE
;
72 /**********************************************************************/
73 /* functions invoked by ST Core */
75 /* called when ST Core wants to
77 void st_ll_enable(struct st_data_s
*ll
)
79 ll
->ll_state
= ST_LL_AWAKE
;
82 /* called when ST Core /local module wants to
84 void st_ll_disable(struct st_data_s
*ll
)
86 ll
->ll_state
= ST_LL_INVALID
;
89 /* called when ST Core wants to update the state */
90 void st_ll_wakeup(struct st_data_s
*ll
)
92 if (likely(ll
->ll_state
!= ST_LL_AWAKE
)) {
93 send_ll_cmd(ll
, LL_WAKE_UP_IND
); /* WAKE_IND */
94 ll
->ll_state
= ST_LL_ASLEEP_TO_AWAKE
;
96 /* don't send the duplicate wake_indication */
97 pr_err(" Chip already AWAKE ");
101 /* called when ST Core wants the state */
102 unsigned long st_ll_getstate(struct st_data_s
*ll
)
104 pr_info(" returning state %ld", ll
->ll_state
);
108 /* called from ST Core, when a PM related packet arrives */
109 unsigned long st_ll_sleep_state(struct st_data_s
*st_data
,
113 case LL_SLEEP_IND
: /* sleep ind */
114 pr_info("sleep indication recvd");
115 ll_device_want_to_sleep(st_data
);
117 case LL_SLEEP_ACK
: /* sleep ack */
118 pr_err("sleep ack rcvd: host shouldn't");
120 case LL_WAKE_UP_IND
: /* wake ind */
121 pr_info("wake indication recvd");
122 ll_device_want_to_wakeup(st_data
);
124 case LL_WAKE_UP_ACK
: /* wake ack */
125 pr_info("wake ack rcvd");
126 st_data
->ll_state
= ST_LL_AWAKE
;
129 pr_err(" unknown input/state ");
130 return ST_ERR_FAILURE
;
135 /* Called from ST CORE to initialize ST LL */
136 long st_ll_init(struct st_data_s
*ll
)
138 /* set state to invalid */
139 ll
->ll_state
= ST_LL_INVALID
;
143 /* Called from ST CORE to de-initialize ST LL */
144 long st_ll_deinit(struct st_data_s
*ll
)