Merge branch 'sched/urgent' into sched/core, to pick up fixes before applying new...
[deliverable/linux.git] / drivers / misc / ti-st / st_ll.c
CommitLineData
1d065ab6
PS
1/*
2 * Shared Transport driver
3 * HCI-LL module responsible for TI proprietary HCI_LL protocol
a0cc2f3b
PS
4 * Copyright (C) 2009-2010 Texas Instruments
5 * Author: Pavan Savoy <pavan_savoy@ti.com>
1d065ab6
PS
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#define pr_fmt(fmt) "(stll) :" fmt
83ef41f0
PS
23#include <linux/skbuff.h>
24#include <linux/module.h>
0d7c5f25 25#include <linux/platform_device.h>
e5558679 26#include <linux/ti_wilink_st.h>
1d065ab6
PS
27
28/**********************************************************************/
46d0d333 29
1d065ab6
PS
30/* internal functions */
31static void send_ll_cmd(struct st_data_s *st_data,
32 unsigned char cmd)
33{
34
6710fcff 35 pr_debug("%s: writing %x", __func__, cmd);
1d065ab6
PS
36 st_int_write(st_data, &cmd, 1);
37 return;
38}
39
40static void ll_device_want_to_sleep(struct st_data_s *st_data)
41{
0d7c5f25
PS
42 struct kim_data_s *kim_data;
43 struct ti_st_plat_data *pdata;
44
e6d9e64e 45 pr_debug("%s", __func__);
1d065ab6
PS
46 /* sanity check */
47 if (st_data->ll_state != ST_LL_AWAKE)
48 pr_err("ERR hcill: ST_LL_GO_TO_SLEEP_IND"
49 "in state %ld", st_data->ll_state);
50
51 send_ll_cmd(st_data, LL_SLEEP_ACK);
52 /* update state */
53 st_data->ll_state = ST_LL_ASLEEP;
0d7c5f25
PS
54
55 /* communicate to platform about chip asleep */
56 kim_data = st_data->kim_data;
46d0d333
GJ
57 if (kim_data->kim_pdev->dev.of_node) {
58 pr_debug("use device tree data");
59 pdata = dt_pdata;
60 } else {
61 pdata = kim_data->kim_pdev->dev.platform_data;
62 }
63
0d7c5f25
PS
64 if (pdata->chip_asleep)
65 pdata->chip_asleep(NULL);
1d065ab6
PS
66}
67
68static void ll_device_want_to_wakeup(struct st_data_s *st_data)
69{
0d7c5f25
PS
70 struct kim_data_s *kim_data;
71 struct ti_st_plat_data *pdata;
72
1d065ab6
PS
73 /* diff actions in diff states */
74 switch (st_data->ll_state) {
75 case ST_LL_ASLEEP:
76 send_ll_cmd(st_data, LL_WAKE_UP_ACK); /* send wake_ack */
77 break;
78 case ST_LL_ASLEEP_TO_AWAKE:
79 /* duplicate wake_ind */
80 pr_err("duplicate wake_ind while waiting for Wake ack");
81 break;
82 case ST_LL_AWAKE:
83 /* duplicate wake_ind */
84 pr_err("duplicate wake_ind already AWAKE");
85 break;
86 case ST_LL_AWAKE_TO_ASLEEP:
87 /* duplicate wake_ind */
88 pr_err("duplicate wake_ind");
89 break;
90 }
91 /* update state */
92 st_data->ll_state = ST_LL_AWAKE;
0d7c5f25
PS
93
94 /* communicate to platform about chip wakeup */
95 kim_data = st_data->kim_data;
46d0d333
GJ
96 if (kim_data->kim_pdev->dev.of_node) {
97 pr_debug("use device tree data");
98 pdata = dt_pdata;
99 } else {
100 pdata = kim_data->kim_pdev->dev.platform_data;
101 }
102
f3d9d365 103 if (pdata->chip_awake)
0d7c5f25 104 pdata->chip_awake(NULL);
1d065ab6
PS
105}
106
107/**********************************************************************/
108/* functions invoked by ST Core */
109
110/* called when ST Core wants to
111 * enable ST LL */
112void st_ll_enable(struct st_data_s *ll)
113{
114 ll->ll_state = ST_LL_AWAKE;
115}
116
117/* called when ST Core /local module wants to
118 * disable ST LL */
119void st_ll_disable(struct st_data_s *ll)
120{
121 ll->ll_state = ST_LL_INVALID;
122}
123
124/* called when ST Core wants to update the state */
125void st_ll_wakeup(struct st_data_s *ll)
126{
127 if (likely(ll->ll_state != ST_LL_AWAKE)) {
128 send_ll_cmd(ll, LL_WAKE_UP_IND); /* WAKE_IND */
129 ll->ll_state = ST_LL_ASLEEP_TO_AWAKE;
130 } else {
131 /* don't send the duplicate wake_indication */
132 pr_err(" Chip already AWAKE ");
133 }
134}
135
136/* called when ST Core wants the state */
137unsigned long st_ll_getstate(struct st_data_s *ll)
138{
e6d9e64e 139 pr_debug(" returning state %ld", ll->ll_state);
1d065ab6
PS
140 return ll->ll_state;
141}
142
143/* called from ST Core, when a PM related packet arrives */
144unsigned long st_ll_sleep_state(struct st_data_s *st_data,
145 unsigned char cmd)
146{
147 switch (cmd) {
148 case LL_SLEEP_IND: /* sleep ind */
6710fcff 149 pr_debug("sleep indication recvd");
1d065ab6
PS
150 ll_device_want_to_sleep(st_data);
151 break;
152 case LL_SLEEP_ACK: /* sleep ack */
153 pr_err("sleep ack rcvd: host shouldn't");
154 break;
155 case LL_WAKE_UP_IND: /* wake ind */
6710fcff 156 pr_debug("wake indication recvd");
1d065ab6
PS
157 ll_device_want_to_wakeup(st_data);
158 break;
159 case LL_WAKE_UP_ACK: /* wake ack */
6710fcff 160 pr_debug("wake ack rcvd");
1d065ab6
PS
161 st_data->ll_state = ST_LL_AWAKE;
162 break;
163 default:
164 pr_err(" unknown input/state ");
70442664 165 return -EINVAL;
1d065ab6 166 }
320920cb 167 return 0;
1d065ab6
PS
168}
169
170/* Called from ST CORE to initialize ST LL */
171long st_ll_init(struct st_data_s *ll)
172{
173 /* set state to invalid */
174 ll->ll_state = ST_LL_INVALID;
175 return 0;
176}
177
178/* Called from ST CORE to de-initialize ST LL */
179long st_ll_deinit(struct st_data_s *ll)
180{
181 return 0;
182}
This page took 0.365482 seconds and 5 git commands to generate.