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	              *)
132		          setprop persist.vendor.usb.config diag,adb
133		      ;;
134                    esac
135		    ;;
136		  esac
137	          ;;
138	      esac
139	      ;;
140	  esac
141      fi
142fi
143
144# set device mode notification to USB driver for SA8150 Auto ADP
145product=`getprop ro.build.product`
146
147case "$product" in
148	"sm6150_au")
149	echo peripheral > /sys/bus/platform/devices/a600000.ssusb/mode
150         ;;
151	*)
152	;;
153esac
154
155# check configfs is mounted or not
156if [ -d /config/usb_gadget ]; then
157	# Chip-serial is used for unique MSM identification in Product string
158	msm_serial=`cat /sys/devices/soc0/serial_number`;
159	msm_serial_hex=`printf %08X $msm_serial`
160	machine_type=`cat /sys/devices/soc0/machine`
161	product_string="$machine_type-$soc_hwplatform _SN:$msm_serial_hex"
162	echo "$product_string" > /config/usb_gadget/g1/strings/0x409/product
163
164	# ADB requires valid iSerialNumber; if ro.serialno is missing, use dummy
165	serialnumber=`cat /config/usb_gadget/g1/strings/0x409/serialnumber` 2> /dev/null
166	if [ "$serialnumber" == "" ]; then
167		serialno=1234567
168		echo $serialno > /config/usb_gadget/g1/strings/0x409/serialnumber
169	fi
170fi
171
172#
173# Initialize RNDIS Diag option. If unset, set it to 'none'.
174#
175diag_extra=`getprop persist.vendor.usb.config.extra`
176if [ "$diag_extra" == "" ]; then
177	setprop persist.vendor.usb.config.extra none
178fi
179
180# enable rps cpus on msm8937 target
181setprop vendor.usb.rps_mask 0
182case "$soc_id" in
183	"294" | "295" | "353" | "354")
184		setprop vendor.usb.rps_mask 40
185	;;
186esac
187
188#
189# Initialize UVC conifguration.
190#
191if [ -d /config/usb_gadget/g1/functions/uvc.0 ]; then
192	cd /config/usb_gadget/g1/functions/uvc.0
193
194	echo 3072 > streaming_maxpacket
195	echo 1 > streaming_maxburst
196	mkdir control/header/h
197	ln -s control/header/h control/class/fs/
198	ln -s control/header/h control/class/ss
199
200	mkdir -p streaming/uncompressed/u/360p
201	echo "666666\n1000000\n5000000\n" > streaming/uncompressed/u/360p/dwFrameInterval
202
203	mkdir -p streaming/uncompressed/u/720p
204	echo 1280 > streaming/uncompressed/u/720p/wWidth
205	echo 720 > streaming/uncompressed/u/720p/wWidth
206	echo 29491200 > streaming/uncompressed/u/720p/dwMinBitRate
207	echo 29491200 > streaming/uncompressed/u/720p/dwMaxBitRate
208	echo 1843200 > streaming/uncompressed/u/720p/dwMaxVideoFrameBufferSize
209	echo 5000000 > streaming/uncompressed/u/720p/dwDefaultFrameInterval
210	echo "5000000\n" > streaming/uncompressed/u/720p/dwFrameInterval
211
212	mkdir -p streaming/mjpeg/m/360p
213	echo "666666\n1000000\n5000000\n" > streaming/mjpeg/m/360p/dwFrameInterval
214
215	mkdir -p streaming/mjpeg/m/720p
216	echo 1280 > streaming/mjpeg/m/720p/wWidth
217	echo 720 > streaming/mjpeg/m/720p/wWidth
218	echo 29491200 > streaming/mjpeg/m/720p/dwMinBitRate
219	echo 29491200 > streaming/mjpeg/m/720p/dwMaxBitRate
220	echo 1843200 > streaming/mjpeg/m/720p/dwMaxVideoFrameBufferSize
221	echo 5000000 > streaming/mjpeg/m/720p/dwDefaultFrameInterval
222	echo "5000000\n" > streaming/mjpeg/m/720p/dwFrameInterval
223
224	echo 0x04 > /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/bmaControls
225
226	mkdir -p streaming/h264/h/960p
227	echo 1920 > streaming/h264/h/960p/wWidth
228	echo 960 > streaming/h264/h/960p/wWidth
229	echo 40 > streaming/h264/h/960p/bLevelIDC
230	echo "333667\n" > streaming/h264/h/960p/dwFrameInterval
231
232	mkdir -p streaming/h264/h/1920p
233	echo "333667\n" > streaming/h264/h/1920p/dwFrameInterval
234
235	mkdir streaming/header/h
236	ln -s streaming/uncompressed/u streaming/header/h
237	ln -s streaming/mjpeg/m streaming/header/h
238	ln -s streaming/h264/h streaming/header/h
239	ln -s streaming/header/h streaming/class/fs/
240	ln -s streaming/header/h streaming/class/hs/
241	ln -s streaming/header/h streaming/class/ss/
242fi
243