1#!/vendor/bin/sh
2# Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met:
7#     * Redistributions of source code must retain the above copyright
8#       notice, this list of conditions and the following disclaimer.
9#     * Redistributions in binary form must reproduce the above
10#       copyright notice, this list of conditions and the following
11#       disclaimer in the documentation and/or other materials provided
12#       with the distribution.
13#     * Neither the name of The Linux Foundation nor the names of its
14#       contributors may be used to endorse or promote products derived
15#      from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29#
30
31# Set platform variables
32if [ -f /sys/devices/soc0/hw_platform ]; then
33    soc_hwplatform=`cat /sys/devices/soc0/hw_platform` 2> /dev/null
34else
35    soc_hwplatform=`cat /sys/devices/system/soc/soc0/hw_platform` 2> /dev/null
36fi
37
38if [ -f /sys/devices/soc0/machine ]; then
39    soc_machine=`cat /sys/devices/soc0/machine` 2> /dev/null
40else
41    soc_machine=`cat /sys/devices/system/soc/soc0/machine` 2> /dev/null
42fi
43
44#
45# Check ESOC for external MDM
46#
47# Note: currently only a single MDM is supported
48#
49if [ -d /sys/bus/esoc/devices ]; then
50for f in /sys/bus/esoc/devices/*; do
51    if [ -d $f ]; then
52    if [ `grep -e "^MDM" -e "^SDX" $f/esoc_name` ]; then
53            esoc_link=`cat $f/esoc_link`
54            break
55        fi
56    fi
57done
58fi
59
60target=`getprop ro.board.platform`
61
62# soc_ids for 8937
63if [ -f /sys/devices/soc0/soc_id ]; then
64	soc_id=`cat /sys/devices/soc0/soc_id`
65else
66	soc_id=`cat /sys/devices/system/soc/soc0/id`
67fi
68
69#
70# Allow USB enumeration with default PID/VID
71#
72baseband=`getprop ro.baseband`
73
74echo 1  > /sys/class/android_usb/f_mass_storage/lun/nofua
75usb_config=`getprop persist.vendor.usb.config`
76if [ "$usb_config" == "" ]; then #USB persist config not set, select default configuration
77      if [ "$esoc_link" != "" ]; then
78	  setprop persist.vendor.usb.config diag,diag_mdm,qdss,qdss_mdm,serial_cdev,dpl,rmnet,adb
79      else
80	  case "$baseband" in
81	      "apq")
82	          setprop persist.vendor.usb.config diag,adb
83	      ;;
84	      *)
85	      case "$soc_hwplatform" in
86	          "Dragon" | "SBC")
87	              setprop persist.vendor.usb.config diag,adb
88	          ;;
89                  *)
90		  soc_machine=${soc_machine:0:3}
91		  case "$soc_machine" in
92		    "SDA")
93	              setprop persist.vendor.usb.config diag,adb
94		    ;;
95		    *)
96	            case "$target" in
97	              "msm8996")
98	                  setprop persist.vendor.usb.config diag,serial_cdev,serial_tty,rmnet_ipa,mass_storage,adb
99		      ;;
100	              "msm8909")
101		          setprop persist.vendor.usb.config diag,serial_smd,rmnet_qti_bam,adb
102		      ;;
103	              "msm8937")
104			    if [ -d /config/usb_gadget ]; then
105				       setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,adb
106			    else
107			               case "$soc_id" in
108				               "313" | "320")
109						  echo BAM2BAM_IPA > /sys/class/android_usb/android0/f_rndis_qc/rndis_transports
110				                  setprop persist.vendor.usb.config diag,serial_smd,rmnet_ipa,adb
111				               ;;
112				               *)
113				                  setprop persist.vendor.usb.config diag,serial_smd,rmnet_qti_bam,adb
114				               ;;
115			               esac
116			    fi
117		      ;;
118	              "msm8953")
119			      if [ -d /config/usb_gadget ]; then
120				      setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,adb
121			      else
122				      setprop persist.vendor.usb.config diag,serial_smd,rmnet_ipa,adb
123			      fi
124		      ;;
125	              "msm8998" | "sdm660" | "apq8098_latv")
126		          setprop persist.vendor.usb.config diag,serial_cdev,rmnet,adb
127		      ;;
128	              "sdm845" | "sdm710")
129		          setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,adb
130		      ;;
131	              #"msmnile")
132			#  setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,qdss,adb
133		      #;;
134	              *)
135		          setprop persist.vendor.usb.config diag,adb
136		      ;;
137                    esac
138		    ;;
139		  esac
140	          ;;
141	      esac
142	      ;;
143	  esac
144      fi
145fi
146
147# set device mode notification to USB driver for SA8150 Auto ADP
148product=`getprop ro.build.product`
149
150case "$product" in
151	"msmnile_au")
152	echo peripheral > /sys/bus/platform/devices/a600000.ssusb/mode
153         ;;
154	*)
155	;;
156esac
157
158# check configfs is mounted or not
159if [ -d /config/usb_gadget ]; then
160	# Chip-serial is used for unique MSM identification in Product string
161	msm_serial=`cat /sys/devices/soc0/serial_number`;
162	msm_serial_hex=`printf %08X $msm_serial`
163	machine_type=`cat /sys/devices/soc0/machine`
164	product_string="$machine_type-$soc_hwplatform _SN:$msm_serial_hex"
165	echo "$product_string" > /config/usb_gadget/g1/strings/0x409/product
166
167	# ADB requires valid iSerialNumber; if ro.serialno is missing, use dummy
168	serialnumber=`cat /config/usb_gadget/g1/strings/0x409/serialnumber` 2> /dev/null
169	if [ "$serialnumber" == "" ]; then
170		serialno=1234567
171		echo $serialno > /config/usb_gadget/g1/strings/0x409/serialnumber
172	fi
173fi
174
175#
176# Initialize RNDIS Diag option. If unset, set it to 'none'.
177#
178diag_extra=`getprop persist.vendor.usb.config.extra`
179if [ "$diag_extra" == "" ]; then
180	setprop persist.vendor.usb.config.extra none
181fi
182
183# enable rps cpus on msm8937 target
184setprop vendor.usb.rps_mask 0
185case "$soc_id" in
186	"294" | "295" | "353" | "354")
187		setprop vendor.usb.rps_mask 40
188	;;
189esac
190
191#
192# Initialize UVC conifguration.
193#
194if [ -d /config/usb_gadget/g1/functions/uvc.0 ]; then
195	cd /config/usb_gadget/g1/functions/uvc.0
196
197	echo 3072 > streaming_maxpacket
198	echo 1 > streaming_maxburst
199	mkdir control/header/h
200	ln -s control/header/h control/class/fs/
201	ln -s control/header/h control/class/ss
202
203	mkdir -p streaming/uncompressed/u/360p
204	echo "666666\n1000000\n5000000\n" > streaming/uncompressed/u/360p/dwFrameInterval
205
206	mkdir -p streaming/uncompressed/u/720p
207	echo 1280 > streaming/uncompressed/u/720p/wWidth
208	echo 720 > streaming/uncompressed/u/720p/wWidth
209	echo 29491200 > streaming/uncompressed/u/720p/dwMinBitRate
210	echo 29491200 > streaming/uncompressed/u/720p/dwMaxBitRate
211	echo 1843200 > streaming/uncompressed/u/720p/dwMaxVideoFrameBufferSize
212	echo 5000000 > streaming/uncompressed/u/720p/dwDefaultFrameInterval
213	echo "5000000\n" > streaming/uncompressed/u/720p/dwFrameInterval
214
215	mkdir -p streaming/mjpeg/m/360p
216	echo "666666\n1000000\n5000000\n" > streaming/mjpeg/m/360p/dwFrameInterval
217
218	mkdir -p streaming/mjpeg/m/720p
219	echo 1280 > streaming/mjpeg/m/720p/wWidth
220	echo 720 > streaming/mjpeg/m/720p/wWidth
221	echo 29491200 > streaming/mjpeg/m/720p/dwMinBitRate
222	echo 29491200 > streaming/mjpeg/m/720p/dwMaxBitRate
223	echo 1843200 > streaming/mjpeg/m/720p/dwMaxVideoFrameBufferSize
224	echo 5000000 > streaming/mjpeg/m/720p/dwDefaultFrameInterval
225	echo "5000000\n" > streaming/mjpeg/m/720p/dwFrameInterval
226
227	echo 0x04 > /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/bmaControls
228
229	mkdir -p streaming/h264/h/960p
230	echo 1920 > streaming/h264/h/960p/wWidth
231	echo 960 > streaming/h264/h/960p/wWidth
232	echo 40 > streaming/h264/h/960p/bLevelIDC
233	echo "333667\n" > streaming/h264/h/960p/dwFrameInterval
234
235	mkdir -p streaming/h264/h/1920p
236	echo "333667\n" > streaming/h264/h/1920p/dwFrameInterval
237
238	mkdir streaming/header/h
239	ln -s streaming/uncompressed/u streaming/header/h
240	ln -s streaming/mjpeg/m streaming/header/h
241	ln -s streaming/h264/h streaming/header/h
242	ln -s streaming/header/h streaming/class/fs/
243	ln -s streaming/header/h streaming/class/hs/
244	ln -s streaming/header/h streaming/class/ss/
245fi
246