diff options
| -rw-r--r-- | drivers/hsi/clients/Kconfig | 8 | ||||
| -rw-r--r-- | drivers/hsi/clients/Makefile | 3 | ||||
| -rw-r--r-- | drivers/hsi/clients/ssi_protocol.c | 1191 | ||||
| -rw-r--r-- | include/linux/hsi/ssi_protocol.h | 42 |
4 files changed, 1243 insertions, 1 deletions
diff --git a/drivers/hsi/clients/Kconfig b/drivers/hsi/clients/Kconfig index 3bacd275f479..1457cfb5b453 100644 --- a/drivers/hsi/clients/Kconfig +++ b/drivers/hsi/clients/Kconfig | |||
| @@ -4,6 +4,14 @@ | |||
| 4 | 4 | ||
| 5 | comment "HSI clients" | 5 | comment "HSI clients" |
| 6 | 6 | ||
| 7 | config SSI_PROTOCOL | ||
| 8 | tristate "SSI protocol" | ||
| 9 | depends on HSI && PHONET && (OMAP_SSI=y || OMAP_SSI=m) | ||
| 10 | help | ||
| 11 | If you say Y here, you will enable the SSI protocol aka McSAAB. | ||
| 12 | |||
| 13 | If unsure, say N. | ||
| 14 | |||
| 7 | config HSI_CHAR | 15 | config HSI_CHAR |
| 8 | tristate "HSI/SSI character driver" | 16 | tristate "HSI/SSI character driver" |
| 9 | depends on HSI | 17 | depends on HSI |
diff --git a/drivers/hsi/clients/Makefile b/drivers/hsi/clients/Makefile index 327c0e27c8b0..ccbf768ea42b 100644 --- a/drivers/hsi/clients/Makefile +++ b/drivers/hsi/clients/Makefile | |||
| @@ -2,4 +2,5 @@ | |||
| 2 | # Makefile for HSI clients | 2 | # Makefile for HSI clients |
| 3 | # | 3 | # |
| 4 | 4 | ||
| 5 | obj-$(CONFIG_HSI_CHAR) += hsi_char.o | 5 | obj-$(CONFIG_SSI_PROTOCOL) += ssi_protocol.o |
| 6 | obj-$(CONFIG_HSI_CHAR) += hsi_char.o | ||
diff --git a/drivers/hsi/clients/ssi_protocol.c b/drivers/hsi/clients/ssi_protocol.c new file mode 100644 index 000000000000..ce4be3738d46 --- /dev/null +++ b/drivers/hsi/clients/ssi_protocol.c | |||
| @@ -0,0 +1,1191 @@ | |||
| 1 | /* | ||
| 2 | * ssi_protocol.c | ||
| 3 | * | ||
| 4 | * Implementation of the SSI McSAAB improved protocol. | ||
| 5 | * | ||
| 6 | * Copyright (C) 2010 Nokia Corporation. All rights reserved. | ||
| 7 | * Copyright (C) 2013 Sebastian Reichel <sre@kernel.org> | ||
| 8 | * | ||
| 9 | * Contact: Carlos Chinea <carlos.chinea@nokia.com> | ||
| 10 | * | ||
| 11 | * This program is free software; you can redistribute it and/or | ||
| 12 | * modify it under the terms of the GNU General Public License | ||
| 13 | * version 2 as published by the Free Software Foundation. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, but | ||
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * General Public License for more details. | ||
| 19 | * | ||
| 20 | * You should have received a copy of the GNU General Public License | ||
| 21 | * along with this program; if not, write to the Free Software | ||
| 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| 23 | * 02110-1301 USA | ||
| 24 | */ | ||
| 25 | |||
| 26 | #include <linux/atomic.h> | ||
| 27 | #include <linux/clk.h> | ||
| 28 | #include <linux/device.h> | ||
| 29 | #include <linux/err.h> | ||
| 30 | #include <linux/gpio.h> | ||
| 31 | #include <linux/if_ether.h> | ||
| 32 | #include <linux/if_arp.h> | ||
| 33 | #include <linux/if_phonet.h> | ||
| 34 | #include <linux/init.h> | ||
| 35 | #include <linux/irq.h> | ||
| 36 | #include <linux/list.h> | ||
| 37 | #include <linux/module.h> | ||
| 38 | #include <linux/netdevice.h> | ||
| 39 | #include <linux/notifier.h> | ||
| 40 | #include <linux/scatterlist.h> | ||
| 41 | #include <linux/skbuff.h> | ||
| 42 | #include <linux/slab.h> | ||
| 43 | #include <linux/spinlock.h> | ||
| 44 | #include <linux/timer.h> | ||
| 45 | #include <linux/hsi/hsi.h> | ||
| 46 | #include <linux/hsi/ssi_protocol.h> | ||
| 47 | |||
| 48 | void ssi_waketest(struct hsi_client *cl, unsigned int enable); | ||
| 49 | |||
| 50 | #define SSIP_TXQUEUE_LEN 100 | ||
| 51 | #define SSIP_MAX_MTU 65535 | ||
| 52 | #define SSIP_DEFAULT_MTU 4000 | ||
| 53 | #define PN_MEDIA_SOS 21 | ||
| 54 | #define SSIP_MIN_PN_HDR 6 /* FIXME: Revisit */ | ||
| 55 | #define SSIP_WDTOUT 2000 /* FIXME: has to be 500 msecs */ | ||
| 56 | #define SSIP_KATOUT 15 /* 15 msecs */ | ||
| 57 | #define SSIP_MAX_CMDS 5 /* Number of pre-allocated commands buffers */ | ||
| 58 | #define SSIP_BYTES_TO_FRAMES(x) ((((x) - 1) >> 2) + 1) | ||
| 59 | #define SSIP_CMT_LOADER_SYNC 0x11223344 | ||
| 60 | /* | ||
| 61 | * SSI protocol command definitions | ||
| 62 | */ | ||
| 63 | #define SSIP_COMMAND(data) ((data) >> 28) | ||
| 64 | #define SSIP_PAYLOAD(data) ((data) & 0xfffffff) | ||
| 65 | /* Commands */ | ||
| 66 | #define SSIP_SW_BREAK 0 | ||
| 67 | #define SSIP_BOOTINFO_REQ 1 | ||
| 68 | #define SSIP_BOOTINFO_RESP 2 | ||
| 69 | #define SSIP_WAKETEST_RESULT 3 | ||
| 70 | #define SSIP_START_TRANS 4 | ||
| 71 | #define SSIP_READY 5 | ||
| 72 | /* Payloads */ | ||
| 73 | #define SSIP_DATA_VERSION(data) ((data) & 0xff) | ||
| 74 | #define SSIP_LOCAL_VERID 1 | ||
| 75 | #define SSIP_WAKETEST_OK 0 | ||
| 76 | #define SSIP_WAKETEST_FAILED 1 | ||
| 77 | #define SSIP_PDU_LENGTH(data) (((data) >> 8) & 0xffff) | ||
| 78 | #define SSIP_MSG_ID(data) ((data) & 0xff) | ||
| 79 | /* Generic Command */ | ||
| 80 | #define SSIP_CMD(cmd, payload) (((cmd) << 28) | ((payload) & 0xfffffff)) | ||
| 81 | /* Commands for the control channel */ | ||
| 82 | #define SSIP_BOOTINFO_REQ_CMD(ver) \ | ||
| 83 | SSIP_CMD(SSIP_BOOTINFO_REQ, SSIP_DATA_VERSION(ver)) | ||
| 84 | #define SSIP_BOOTINFO_RESP_CMD(ver) \ | ||
| 85 | SSIP_CMD(SSIP_BOOTINFO_RESP, SSIP_DATA_VERSION(ver)) | ||
| 86 | #define SSIP_START_TRANS_CMD(pdulen, id) \ | ||
| 87 | SSIP_CMD(SSIP_START_TRANS, (((pdulen) << 8) | SSIP_MSG_ID(id))) | ||
| 88 | #define SSIP_READY_CMD SSIP_CMD(SSIP_READY, 0) | ||
| 89 | #define SSIP_SWBREAK_CMD SSIP_CMD(SSIP_SW_BREAK, 0) | ||
| 90 | |||
| 91 | /* Main state machine states */ | ||
| 92 | enum { | ||
| 93 | INIT, | ||
| 94 | HANDSHAKE, | ||
| 95 | ACTIVE, | ||
| 96 | }; | ||
| 97 | |||
| 98 | /* Send state machine states */ | ||
| 99 | enum { | ||
| 100 | SEND_IDLE, | ||
| 101 | WAIT4READY, | ||
| 102 | SEND_READY, | ||
| 103 | SENDING, | ||
| 104 | SENDING_SWBREAK, | ||
| 105 | }; | ||
| 106 | |||
| 107 | /* Receive state machine states */ | ||
| 108 | enum { | ||
| 109 | RECV_IDLE, | ||
| 110 | RECV_READY, | ||
| 111 | RECEIVING, | ||
| 112 | }; | ||
| 113 | |||
| 114 | /** | ||
| 115 | * struct ssi_protocol - SSI protocol (McSAAB) data | ||
| 116 | * @main_state: Main state machine | ||
| 117 | * @send_state: TX state machine | ||
| 118 | * @recv_state: RX state machine | ||
| 119 | * @waketest: Flag to follow wake line test | ||
| 120 | * @rxid: RX data id | ||
| 121 | * @txid: TX data id | ||
| 122 | * @txqueue_len: TX queue length | ||
| 123 | * @tx_wd: TX watchdog | ||
| 124 | * @rx_wd: RX watchdog | ||
| 125 | * @keep_alive: Workaround for SSI HW bug | ||
| 126 | * @lock: To serialize access to this struct | ||
| 127 | * @netdev: Phonet network device | ||
| 128 | * @txqueue: TX data queue | ||
| 129 | * @cmdqueue: Queue of free commands | ||
| 130 | * @cl: HSI client own reference | ||
| 131 | * @link: Link for ssip_list | ||
| 132 | * @tx_usecount: Refcount to keep track the slaves that use the wake line | ||
| 133 | * @channel_id_cmd: HSI channel id for command stream | ||
| 134 | * @channel_id_data: HSI channel id for data stream | ||
| 135 | */ | ||
| 136 | struct ssi_protocol { | ||
| 137 | unsigned int main_state; | ||
| 138 | unsigned int send_state; | ||
| 139 | unsigned int recv_state; | ||
| 140 | unsigned int waketest:1; | ||
| 141 | u8 rxid; | ||
| 142 | u8 txid; | ||
| 143 | unsigned int txqueue_len; | ||
| 144 | struct timer_list tx_wd; | ||
| 145 | struct timer_list rx_wd; | ||
| 146 | struct timer_list keep_alive; /* wake-up workaround */ | ||
| 147 | spinlock_t lock; | ||
| 148 | struct net_device *netdev; | ||
| 149 | struct list_head txqueue; | ||
| 150 | struct list_head cmdqueue; | ||
| 151 | struct hsi_client *cl; | ||
| 152 | struct list_head link; | ||
| 153 | atomic_t tx_usecnt; | ||
| 154 | int channel_id_cmd; | ||
| 155 | int channel_id_data; | ||
| 156 | }; | ||
| 157 | |||
| 158 | /* List of ssi protocol instances */ | ||
| 159 | static LIST_HEAD(ssip_list); | ||
| 160 | |||
| 161 | static void ssip_rxcmd_complete(struct hsi_msg *msg); | ||
| 162 | |||
| 163 | static inline void ssip_set_cmd(struct hsi_msg *msg, u32 cmd) | ||
| 164 | { | ||
| 165 | u32 *data; | ||
| 166 | |||
