ChipObj.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import collections
  5. import xml.dom.minidom
  6. from GpioObj import GpioObj
  7. from GpioObj import GpioObj_whitney
  8. from GpioObj import GpioObj_MT6759
  9. from GpioObj import GpioObj_MT6739
  10. from GpioObj import GpioObj_MT6771
  11. from GpioObj import GpioObj_MT6763
  12. from GpioObj import GpioObj_MT6768
  13. from GpioObj import GpioObj_MT6785
  14. from EintObj import EintObj
  15. from EintObj import EintObj_MT6750S
  16. from EintObj import EintObj_MT6739
  17. from AdcObj import AdcObj
  18. from AdcObj import AdcObj_MT6785
  19. from ClkObj import ClkObj
  20. from ClkObj import ClkObj_Everest
  21. from ClkObj import ClkObj_Olympus
  22. from ClkObj import ClkObj_Rushmore
  23. from ClkObj import ClkObj_MT6779
  24. from I2cObj import I2cObj
  25. from I2cObj import I2cObj_MT6759
  26. from I2cObj import I2cObj_MT6775
  27. from PmicObj import PmicObj
  28. from PmicObj import PmicObj_MT6758
  29. from Md1EintObj import Md1EintObj
  30. from Md1EintObj import Md1EintObj_MT6739
  31. from PowerObj import PowerObj
  32. from KpdObj import KpdObj
  33. from ModuleObj import ModuleObj
  34. from utility.util import log
  35. from utility.util import LogLevel
  36. para_map = {'adc':['adc_h', 'adc_dtsi'],\
  37. 'clk':['clk_buf_h', 'clk_buf_dtsi'],\
  38. 'i2c':['i2c_h', 'i2c_dtsi'],\
  39. 'eint':['eint_h', 'eint_dtsi'],\
  40. 'gpio':['gpio_usage_h', 'gpio_boot_h', 'gpio_dtsi', 'scp_gpio_usage_h', 'pinfunc_h', \
  41. 'pinctrl_h', 'gpio_usage_mapping_dtsi'],\
  42. 'md1_eint':['md1_eint_h', 'md1_eint_dtsi'],\
  43. 'kpd':['kpd_h', 'kpd_dtsi'],\
  44. 'pmic':['pmic_drv_h', 'pmic_drv_c', 'pmic_h', 'pmic_c', 'pmic_dtsi'],\
  45. 'power':['power_h']}
  46. class ChipObj:
  47. def __init__(self, path, dest):
  48. self.__epFlag = False
  49. self.__path = path
  50. ModuleObj.set_genPath(dest)
  51. self.__objs = collections.OrderedDict()
  52. self.init_objs()
  53. def init_objs(self):
  54. self.__objs['adc'] = AdcObj()
  55. self.__objs['clk'] = ClkObj()
  56. self.__objs["i2c"] = I2cObj()
  57. self.__objs["gpio"] = GpioObj()
  58. # eint obj need gpio data
  59. self.__objs["eint"] = EintObj(self.__objs['gpio'])
  60. self.__objs["md1_eint"] = Md1EintObj()
  61. self.__objs["pmic"] = PmicObj()
  62. self.__objs["power"] = PowerObj()
  63. self.__objs["kpd"] = KpdObj()
  64. def replace_obj(self, tag, obj):
  65. if not tag in self.__objs.keys():
  66. return False
  67. self.__objs[tag] = obj
  68. def get_gpioObj(self):
  69. return self.__objs['gpio']
  70. def refresh_eintGpioMap(self):
  71. self.__objs['eint'].set_gpioObj(self.__objs['gpio'])
  72. def append_obj(self, tag, obj):
  73. if tag in self.__objs.keys():
  74. return False
  75. self.__objs[tag] = obj
  76. @staticmethod
  77. def get_chipId(path):
  78. if not os.path.exists(path):
  79. msg = '%s is not a available path!' %(path)
  80. log(LogLevel.error, msg)
  81. return False
  82. data = xml.dom.minidom.parse(path)
  83. root = data.documentElement
  84. # get 'general' node
  85. node = root.getElementsByTagName('general')
  86. return node[0].getAttribute('chip')
  87. def parse(self):
  88. if not os.path.exists(self.__path):
  89. msg = '%s is not a available path!' %(self.__path)
  90. log(LogLevel.error, msg)
  91. return False
  92. data = xml.dom.minidom.parse(self.__path)
  93. root = data.documentElement
  94. # get 'general' node
  95. node = root.getElementsByTagName('general')
  96. # get chip name and project name
  97. ModuleObj.set_chipId(node[0].getAttribute('chip'))
  98. # get early porting flag
  99. epNode = node[0].getElementsByTagName('ep')
  100. if len(epNode) != 0 and epNode[0].childNodes[0].nodeValue=="True":
  101. self.__epFlag = True
  102. msg = 'Chip ID : %s' %(node[0].getAttribute('chip'))
  103. log(LogLevel.info, msg)
  104. msg = 'Project Info: %s' %(node[0].getElementsByTagName('proj')[0].childNodes[0].nodeValue)
  105. log(LogLevel.info, msg)
  106. # initialize the objects mapping table
  107. self.init_objs()
  108. # get module nodes from DWS file
  109. nodes = node[0].getElementsByTagName('module')
  110. for node in nodes:
  111. tag = node.getAttribute('name')
  112. obj = self.create_obj(tag)
  113. if obj == None:
  114. msg = 'can not find %s node in DWS!' %(tag)
  115. log(LogLevel.error, msg)
  116. return False
  117. obj.parse(node)
  118. return True
  119. def generate(self, paras):
  120. if len(paras) == 0:
  121. for obj in self.__objs.values():
  122. obj.gen_files()
  123. self.gen_custDtsi()
  124. else:
  125. self.gen_spec(paras)
  126. return True
  127. def create_obj(self, tag):
  128. obj = None
  129. if tag in self.__objs.keys():
  130. obj = self.__objs[tag]
  131. return obj
  132. def gen_spec(self, paras):
  133. # if cmp(paras[0], 'cust_dtsi') == 0:
  134. # self.gen_custDtsi()
  135. # return True
  136. for para in paras:
  137. if cmp(para, 'cust_dtsi') == 0:
  138. self.gen_custDtsi()
  139. continue
  140. idx = 0
  141. name = ''
  142. if para.strip() != '':
  143. for value in para_map.values():
  144. if para in value:
  145. name = para_map.keys()[idx]
  146. break
  147. idx += 1
  148. if name != '':
  149. log(LogLevel.info, 'Start to generate %s file...' %(para))
  150. obj = self.__objs[name]
  151. obj.gen_spec(para)
  152. log(LogLevel.info, 'Generate %s file successfully!' %(para))
  153. else:
  154. log(LogLevel.warn, '%s can not be recognized!' %(para))
  155. # sys.exit(-1)
  156. return True
  157. def gen_custDtsi(self):
  158. log(LogLevel.info, 'Start to generate cust_dtsi file...')
  159. fp = open(os.path.join(ModuleObj.get_genPath(), 'cust.dtsi'), 'w')
  160. gen_str = ModuleObj.writeComment()
  161. # if early porting, gen empty dtsi file for kernel
  162. if self.__epFlag:
  163. fp.write(gen_str)
  164. fp.close()
  165. return
  166. #sorted_list = sorted(self.__objs.keys())
  167. #for tag in sorted_list:
  168. for tag in self.__objs.keys():
  169. if cmp(tag, 'gpio') == 0:
  170. gpioObj = self.create_obj(tag)
  171. gen_str += ModuleObj.writeHeader(gpioObj.get_dtsiFileName())
  172. gen_str += gpioObj.fill_mapping_dtsiFile()
  173. gen_str += gpioObj.fill_init_default_dtsiFile()
  174. else:
  175. obj = self.create_obj(tag)
  176. gen_str += ModuleObj.writeHeader(obj.get_dtsiFileName())
  177. gen_str += obj.fill_dtsiFile()
  178. gen_str += '''\n\n'''
  179. fp.write(gen_str)
  180. fp.close()
  181. log(LogLevel.info, 'Generate cust_dtsi file successfully!')
  182. class Everest(ChipObj):
  183. def __init__(self, dws_path, gen_path):
  184. ChipObj.__init__(self, dws_path, gen_path)
  185. self.init_objs()
  186. def init_objs(self):
  187. ChipObj.init_objs(self)
  188. ChipObj.replace_obj(self, 'clk', ClkObj_Everest())
  189. def parse(self):
  190. return ChipObj.parse(self)
  191. def generate(self, paras):
  192. return ChipObj.generate(self, paras)
  193. class Olympus(ChipObj):
  194. def __init__(self, dws_path, gen_path):
  195. ChipObj.__init__(self, dws_path, gen_path)
  196. def init_objs(self):
  197. ChipObj.init_objs(self)
  198. ChipObj.replace_obj(self, 'clk', ClkObj_Olympus())
  199. ChipObj.replace_obj(self, 'i2c', I2cObj_MT6759())
  200. def parse(self):
  201. return ChipObj.parse(self)
  202. def generate(self, paras):
  203. return ChipObj.generate(self, paras)
  204. class MT6757_P25(ChipObj):
  205. def __init__(self, dws_path, gen_path):
  206. ChipObj.__init__(self, dws_path, gen_path)
  207. def init_objs(self):
  208. ChipObj.init_objs(self)
  209. ChipObj.replace_obj(self, 'clk', ClkObj_Olympus())
  210. ChipObj.replace_obj(self, 'i2c', I2cObj_MT6759())
  211. def parse(self):
  212. return ChipObj.parse(self)
  213. def generate(self, paras):
  214. return ChipObj.generate(self, paras)
  215. class Rushmore(ChipObj):
  216. def __init__(self, dws_path, gen_path):
  217. ChipObj.__init__(self, dws_path, gen_path)
  218. def init_objs(self):
  219. ChipObj.init_objs(self)
  220. ChipObj.replace_obj(self, 'clk', ClkObj_Rushmore())
  221. def parse(self):
  222. return ChipObj.parse(self)
  223. def generate(self, paras):
  224. return ChipObj.generate(self, paras)
  225. class Whitney(ChipObj):
  226. def __init__(self, dws_path, gen_path):
  227. ChipObj.__init__(self, dws_path, gen_path)
  228. def init_objs(self):
  229. ChipObj.init_objs(self)
  230. ChipObj.replace_obj(self, 'gpio', GpioObj_whitney())
  231. ChipObj.replace_obj(self, 'i2c', I2cObj_MT6759())
  232. ChipObj.refresh_eintGpioMap(self)
  233. def parse(self):
  234. log(LogLevel.info, 'Whitney parse')
  235. return ChipObj.parse(self)
  236. def generate(self, paras):
  237. return ChipObj.generate(self, paras)
  238. class MT6759(ChipObj):
  239. def __init__(self, dws_path, gen_path):
  240. ChipObj.__init__(self, dws_path, gen_path)
  241. def init_objs(self):
  242. ChipObj.init_objs(self)
  243. ChipObj.replace_obj(self, 'gpio', GpioObj_MT6759())
  244. ChipObj.replace_obj(self, 'i2c', I2cObj_MT6759())
  245. ChipObj.refresh_eintGpioMap(self)
  246. def parse(self):
  247. return ChipObj.parse(self)
  248. def generate(self, paras):
  249. return ChipObj.generate(self, paras)
  250. class MT6758(ChipObj):
  251. def __init__(self, dws_path, gen_path):
  252. ChipObj.__init__(self, dws_path, gen_path)
  253. def init_objs(self):
  254. ChipObj.init_objs(self)
  255. ChipObj.replace_obj(self, 'pmic', PmicObj_MT6758())
  256. ChipObj.replace_obj(self, 'gpio', GpioObj_MT6739())
  257. ChipObj.replace_obj(self, 'eint', EintObj_MT6739(ChipObj.get_gpioObj(self)))
  258. ChipObj.replace_obj(self, 'i2c', I2cObj_MT6759())
  259. ChipObj.replace_obj(self, 'md1_eint', Md1EintObj_MT6739())
  260. ChipObj.refresh_eintGpioMap(self)
  261. def parse(self):
  262. return ChipObj.parse(self)
  263. def generate(self, paras):
  264. return ChipObj.generate(self, paras)
  265. class MT6763(ChipObj):
  266. def __init__(self, dws_path, gen_path):
  267. ChipObj.__init__(self, dws_path, gen_path)
  268. def init_objs(self):
  269. ChipObj.init_objs(self)
  270. ChipObj.replace_obj(self, 'gpio', GpioObj_MT6763())
  271. ChipObj.replace_obj(self, 'i2c', I2cObj_MT6759())
  272. ChipObj.refresh_eintGpioMap(self)
  273. def parse(self):
  274. return ChipObj.parse(self)
  275. def generate(self, paras):
  276. return ChipObj.generate(self, paras)
  277. class MT6739(MT6763):
  278. def __init__(self, dws_path, gen_path):
  279. ChipObj.__init__(self, dws_path, gen_path)
  280. def init_objs(self):
  281. ChipObj.init_objs(self)
  282. ChipObj.replace_obj(self, 'pmic', PmicObj_MT6758())
  283. ChipObj.replace_obj(self, 'gpio', GpioObj_MT6739())
  284. ChipObj.replace_obj(self, 'eint', EintObj_MT6739(ChipObj.get_gpioObj(self)))
  285. ChipObj.replace_obj(self, 'md1_eint', Md1EintObj_MT6739())
  286. ChipObj.replace_obj(self, 'i2c', I2cObj_MT6759())
  287. ChipObj.refresh_eintGpioMap(self)
  288. def parse(self):
  289. return ChipObj.parse(self)
  290. def generate(self, paras):
  291. return ChipObj.generate(self, paras)
  292. class MT6750S(ChipObj):
  293. def __init__(self, dws_path, gen_path):
  294. ChipObj.__init__(self, dws_path, gen_path)
  295. def init_objs(self):
  296. ChipObj.init_objs(self)
  297. ChipObj.replace_obj(self, 'clk', ClkObj_Olympus())
  298. ChipObj.replace_obj(self, 'eint', EintObj_MT6750S(ChipObj.get_gpioObj(self)))
  299. ChipObj.refresh_eintGpioMap(self)
  300. def parse(self):
  301. return ChipObj.parse(self)
  302. def generate(self, paras):
  303. return ChipObj.generate(self, paras)
  304. class MT8695(ChipObj):
  305. def __init__(self, dws_path, gen_path):
  306. ChipObj.__init__(self, dws_path, gen_path)
  307. def init_objs(self):
  308. ChipObj.init_objs(self)
  309. ChipObj.replace_obj(self, 'gpio', GpioObj_whitney())
  310. ChipObj.refresh_eintGpioMap(self)
  311. def parse(self):
  312. return ChipObj.parse(self)
  313. def generate(self, paras):
  314. return ChipObj.generate(self, paras)
  315. class MT6771(ChipObj):
  316. def __init__(self, dws_path, gen_path):
  317. ChipObj.__init__(self, dws_path, gen_path)
  318. def init_objs(self):
  319. ChipObj.init_objs(self)
  320. ChipObj.replace_obj(self, 'pmic', PmicObj_MT6758())
  321. ChipObj.replace_obj(self, 'gpio', GpioObj_MT6771())
  322. ChipObj.replace_obj(self, 'eint', EintObj_MT6739(ChipObj.get_gpioObj(self)))
  323. ChipObj.replace_obj(self, 'md1_eint', Md1EintObj_MT6739())
  324. ChipObj.replace_obj(self, 'i2c', I2cObj_MT6775())
  325. ChipObj.refresh_eintGpioMap(self)
  326. class MT6775(ChipObj):
  327. def __init__(self, dws_path, gen_path):
  328. ChipObj.__init__(self, dws_path, gen_path)
  329. def init_objs(self):
  330. ChipObj.init_objs(self)
  331. ChipObj.replace_obj(self, 'pmic', PmicObj_MT6758())
  332. ChipObj.replace_obj(self, 'gpio', GpioObj_MT6739())
  333. ChipObj.replace_obj(self, 'eint', EintObj_MT6739(ChipObj.get_gpioObj(self)))
  334. ChipObj.replace_obj(self, 'md1_eint', Md1EintObj_MT6739())
  335. ChipObj.replace_obj(self, 'i2c', I2cObj_MT6775())
  336. ChipObj.refresh_eintGpioMap(self)
  337. class MT6779(ChipObj):
  338. def __init__(self, dws_path, gen_path):
  339. ChipObj.__init__(self, dws_path, gen_path)
  340. def init_objs(self):
  341. ChipObj.init_objs(self)
  342. ChipObj.replace_obj(self, 'clk', ClkObj_MT6779())
  343. ChipObj.replace_obj(self, 'pmic', PmicObj_MT6758())
  344. ChipObj.replace_obj(self, 'gpio', GpioObj_MT6771())
  345. ChipObj.replace_obj(self, 'eint', EintObj_MT6739(ChipObj.get_gpioObj(self)))
  346. ChipObj.replace_obj(self, 'md1_eint', Md1EintObj_MT6739())
  347. ChipObj.replace_obj(self, "i2c", I2cObj_MT6775())
  348. ChipObj.refresh_eintGpioMap(self)
  349. class MT6785(ChipObj):
  350. def __init__(self, dws_path, gen_path):
  351. ChipObj.__init__(self, dws_path, gen_path)
  352. def init_objs(self):
  353. ChipObj.init_objs(self)
  354. ChipObj.replace_obj(self, 'adc', AdcObj_MT6785())
  355. ChipObj.replace_obj(self, 'clk', ClkObj_MT6779())
  356. ChipObj.replace_obj(self, 'pmic', PmicObj_MT6758())
  357. ChipObj.replace_obj(self, 'gpio', GpioObj_MT6785())
  358. ChipObj.replace_obj(self, 'eint', EintObj_MT6739(ChipObj.get_gpioObj(self)))
  359. ChipObj.replace_obj(self, 'md1_eint', Md1EintObj_MT6739())
  360. ChipObj.replace_obj(self, "i2c", I2cObj_MT6775())
  361. ChipObj.refresh_eintGpioMap(self)
  362. class MT6768(ChipObj):
  363. def __init__(self, dws_path, gen_path):
  364. ChipObj.__init__(self, dws_path, gen_path)
  365. def init_objs(self):
  366. ChipObj.init_objs(self)
  367. ChipObj.replace_obj(self, 'adc', AdcObj_MT6785())
  368. ChipObj.replace_obj(self, 'pmic', PmicObj_MT6758())
  369. ChipObj.replace_obj(self, 'gpio', GpioObj_MT6768())
  370. ChipObj.replace_obj(self, 'eint', EintObj_MT6739(ChipObj.get_gpioObj(self)))
  371. ChipObj.replace_obj(self, 'md1_eint', Md1EintObj_MT6739())
  372. ChipObj.replace_obj(self, "i2c", I2cObj_MT6775())
  373. ChipObj.refresh_eintGpioMap(self)