Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Shared Transport driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *	HCI-LL module responsible for TI proprietary HCI_LL protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2009-2010 Texas Instruments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Author: Pavan Savoy <pavan_savoy@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define pr_fmt(fmt) "(stll) :" fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/ti_wilink_st.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /**********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) /* internal functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static void send_ll_cmd(struct st_data_s *st_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	unsigned char cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	pr_debug("%s: writing %x", __func__, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	st_int_write(st_data, &cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static void ll_device_want_to_sleep(struct st_data_s *st_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct kim_data_s	*kim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct ti_st_plat_data	*pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	pr_debug("%s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	/* sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	if (st_data->ll_state != ST_LL_AWAKE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		pr_err("ERR hcill: ST_LL_GO_TO_SLEEP_IND"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 			  "in state %ld", st_data->ll_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	send_ll_cmd(st_data, LL_SLEEP_ACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	/* update state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	st_data->ll_state = ST_LL_ASLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	/* communicate to platform about chip asleep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	kim_data = st_data->kim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	pdata = kim_data->kim_pdev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (pdata->chip_asleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		pdata->chip_asleep(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static void ll_device_want_to_wakeup(struct st_data_s *st_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct kim_data_s	*kim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct ti_st_plat_data	*pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	/* diff actions in diff states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	switch (st_data->ll_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	case ST_LL_ASLEEP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		send_ll_cmd(st_data, LL_WAKE_UP_ACK);	/* send wake_ack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	case ST_LL_ASLEEP_TO_AWAKE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		/* duplicate wake_ind */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		pr_err("duplicate wake_ind while waiting for Wake ack");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	case ST_LL_AWAKE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		/* duplicate wake_ind */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		pr_err("duplicate wake_ind already AWAKE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	case ST_LL_AWAKE_TO_ASLEEP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		/* duplicate wake_ind */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		pr_err("duplicate wake_ind");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	/* update state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	st_data->ll_state = ST_LL_AWAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/* communicate to platform about chip wakeup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	kim_data = st_data->kim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	pdata = kim_data->kim_pdev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (pdata->chip_awake)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		pdata->chip_awake(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) /**********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /* functions invoked by ST Core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) /* called when ST Core wants to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * enable ST LL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) void st_ll_enable(struct st_data_s *ll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	ll->ll_state = ST_LL_AWAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) /* called when ST Core /local module wants to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * disable ST LL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) void st_ll_disable(struct st_data_s *ll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	ll->ll_state = ST_LL_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) /* called when ST Core wants to update the state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) void st_ll_wakeup(struct st_data_s *ll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (likely(ll->ll_state != ST_LL_AWAKE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		send_ll_cmd(ll, LL_WAKE_UP_IND);	/* WAKE_IND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		ll->ll_state = ST_LL_ASLEEP_TO_AWAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		/* don't send the duplicate wake_indication */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		pr_err(" Chip already AWAKE ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* called when ST Core wants the state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) unsigned long st_ll_getstate(struct st_data_s *ll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	pr_debug(" returning state %ld", ll->ll_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	return ll->ll_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* called from ST Core, when a PM related packet arrives */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) unsigned long st_ll_sleep_state(struct st_data_s *st_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	unsigned char cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	case LL_SLEEP_IND:	/* sleep ind */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		pr_debug("sleep indication recvd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		ll_device_want_to_sleep(st_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	case LL_SLEEP_ACK:	/* sleep ack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		pr_err("sleep ack rcvd: host shouldn't");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	case LL_WAKE_UP_IND:	/* wake ind */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		pr_debug("wake indication recvd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		ll_device_want_to_wakeup(st_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	case LL_WAKE_UP_ACK:	/* wake ack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		pr_debug("wake ack rcvd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		st_data->ll_state = ST_LL_AWAKE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		pr_err(" unknown input/state ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Called from ST CORE to initialize ST LL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) long st_ll_init(struct st_data_s *ll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	/* set state to invalid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	ll->ll_state = ST_LL_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* Called from ST CORE to de-initialize ST LL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) long st_ll_deinit(struct st_data_s *ll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }