st_ll.c 4.6 KB
Newer Older
1 2 3
/*
 *  Shared Transport driver
 *	HCI-LL module responsible for TI proprietary HCI_LL protocol
4 5
 *  Copyright (C) 2009-2010 Texas Instruments
 *  Author: Pavan Savoy <pavan_savoy@ti.com>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 *  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) "(stll) :" fmt
23 24
#include <linux/skbuff.h>
#include <linux/module.h>
25
#include <linux/platform_device.h>
26
#include <linux/ti_wilink_st.h>
27 28

/**********************************************************************/
G
Gigi Joseph 已提交
29

30 31 32 33 34
/* internal functions */
static void send_ll_cmd(struct st_data_s *st_data,
	unsigned char cmd)
{

35
	pr_debug("%s: writing %x", __func__, cmd);
36 37 38 39 40 41
	st_int_write(st_data, &cmd, 1);
	return;
}

static void ll_device_want_to_sleep(struct st_data_s *st_data)
{
42 43 44
	struct kim_data_s	*kim_data;
	struct ti_st_plat_data	*pdata;

45
	pr_debug("%s", __func__);
46 47 48 49 50 51 52 53
	/* sanity check */
	if (st_data->ll_state != ST_LL_AWAKE)
		pr_err("ERR hcill: ST_LL_GO_TO_SLEEP_IND"
			  "in state %ld", st_data->ll_state);

	send_ll_cmd(st_data, LL_SLEEP_ACK);
	/* update state */
	st_data->ll_state = ST_LL_ASLEEP;
54 55 56

	/* communicate to platform about chip asleep */
	kim_data = st_data->kim_data;
G
Gigi Joseph 已提交
57 58 59 60 61 62 63
	if (kim_data->kim_pdev->dev.of_node) {
		pr_debug("use device tree data");
		pdata = dt_pdata;
	} else {
		pdata = kim_data->kim_pdev->dev.platform_data;
	}

64 65
	if (pdata->chip_asleep)
		pdata->chip_asleep(NULL);
66 67 68 69
}

static void ll_device_want_to_wakeup(struct st_data_s *st_data)
{
70 71 72
	struct kim_data_s	*kim_data;
	struct ti_st_plat_data	*pdata;

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
	/* diff actions in diff states */
	switch (st_data->ll_state) {
	case ST_LL_ASLEEP:
		send_ll_cmd(st_data, LL_WAKE_UP_ACK);	/* send wake_ack */
		break;
	case ST_LL_ASLEEP_TO_AWAKE:
		/* duplicate wake_ind */
		pr_err("duplicate wake_ind while waiting for Wake ack");
		break;
	case ST_LL_AWAKE:
		/* duplicate wake_ind */
		pr_err("duplicate wake_ind already AWAKE");
		break;
	case ST_LL_AWAKE_TO_ASLEEP:
		/* duplicate wake_ind */
		pr_err("duplicate wake_ind");
		break;
	}
	/* update state */
	st_data->ll_state = ST_LL_AWAKE;
93 94 95

	/* communicate to platform about chip wakeup */
	kim_data = st_data->kim_data;
G
Gigi Joseph 已提交
96 97 98 99 100 101 102
	if (kim_data->kim_pdev->dev.of_node) {
		pr_debug("use device tree data");
		pdata = dt_pdata;
	} else {
		pdata = kim_data->kim_pdev->dev.platform_data;
	}

103
	if (pdata->chip_awake)
104
		pdata->chip_awake(NULL);
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
}

/**********************************************************************/
/* functions invoked by ST Core */

/* called when ST Core wants to
 * enable ST LL */
void st_ll_enable(struct st_data_s *ll)
{
	ll->ll_state = ST_LL_AWAKE;
}

/* called when ST Core /local module wants to
 * disable ST LL */
void st_ll_disable(struct st_data_s *ll)
{
	ll->ll_state = ST_LL_INVALID;
}

/* called when ST Core wants to update the state */
void st_ll_wakeup(struct st_data_s *ll)
{
	if (likely(ll->ll_state != ST_LL_AWAKE)) {
		send_ll_cmd(ll, LL_WAKE_UP_IND);	/* WAKE_IND */
		ll->ll_state = ST_LL_ASLEEP_TO_AWAKE;
	} else {
		/* don't send the duplicate wake_indication */
		pr_err(" Chip already AWAKE ");
	}
}

/* called when ST Core wants the state */
unsigned long st_ll_getstate(struct st_data_s *ll)
{
139
	pr_debug(" returning state %ld", ll->ll_state);
140 141 142 143 144 145 146 147 148
	return ll->ll_state;
}

/* called from ST Core, when a PM related packet arrives */
unsigned long st_ll_sleep_state(struct st_data_s *st_data,
	unsigned char cmd)
{
	switch (cmd) {
	case LL_SLEEP_IND:	/* sleep ind */
149
		pr_debug("sleep indication recvd");
150 151 152 153 154 155
		ll_device_want_to_sleep(st_data);
		break;
	case LL_SLEEP_ACK:	/* sleep ack */
		pr_err("sleep ack rcvd: host shouldn't");
		break;
	case LL_WAKE_UP_IND:	/* wake ind */
156
		pr_debug("wake indication recvd");
157 158 159
		ll_device_want_to_wakeup(st_data);
		break;
	case LL_WAKE_UP_ACK:	/* wake ack */
160
		pr_debug("wake ack rcvd");
161 162 163 164
		st_data->ll_state = ST_LL_AWAKE;
		break;
	default:
		pr_err(" unknown input/state ");
165
		return -EINVAL;
166
	}
167
	return 0;
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
}

/* Called from ST CORE to initialize ST LL */
long st_ll_init(struct st_data_s *ll)
{
	/* set state to invalid */
	ll->ll_state = ST_LL_INVALID;
	return 0;
}

/* Called from ST CORE to de-initialize ST LL */
long st_ll_deinit(struct st_data_s *ll)
{
	return 0;
}