ChipObj.py 13 KB

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