twl-core.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. /*
  2. * twl_core.c - driver for TWL4030/TWL5030/TWL60X0/TPS659x0 PM
  3. * and audio CODEC devices
  4. *
  5. * Copyright (C) 2005-2006 Texas Instruments, Inc.
  6. *
  7. * Modifications to defer interrupt handling to a kernel thread:
  8. * Copyright (C) 2006 MontaVista Software, Inc.
  9. *
  10. * Based on tlv320aic23.c:
  11. * Copyright (c) by Kai Svahn <kai.svahn@nokia.com>
  12. *
  13. * Code cleanup and modifications to IRQ handler.
  14. * by syed khasim <x0khasim@ti.com>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. */
  30. #include <linux/init.h>
  31. #include <linux/mutex.h>
  32. #include <linux/module.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/regmap.h>
  35. #include <linux/clk.h>
  36. #include <linux/err.h>
  37. #include <linux/device.h>
  38. #include <linux/of.h>
  39. #include <linux/of_irq.h>
  40. #include <linux/of_platform.h>
  41. #include <linux/irq.h>
  42. #include <linux/irqdomain.h>
  43. #include <linux/regulator/machine.h>
  44. #include <linux/i2c.h>
  45. #include <linux/i2c/twl.h>
  46. /* Register descriptions for audio */
  47. #include <linux/mfd/twl4030-audio.h>
  48. #include "twl-core.h"
  49. /*
  50. * The TWL4030 "Triton 2" is one of a family of a multi-function "Power
  51. * Management and System Companion Device" chips originally designed for
  52. * use in OMAP2 and OMAP 3 based systems. Its control interfaces use I2C,
  53. * often at around 3 Mbit/sec, including for interrupt handling.
  54. *
  55. * This driver core provides genirq support for the interrupts emitted,
  56. * by the various modules, and exports register access primitives.
  57. *
  58. * FIXME this driver currently requires use of the first interrupt line
  59. * (and associated registers).
  60. */
  61. #define DRIVER_NAME "twl"
  62. /* Triton Core internal information (BEGIN) */
  63. /* Base Address defns for twl4030_map[] */
  64. /* subchip/slave 0 - USB ID */
  65. #define TWL4030_BASEADD_USB 0x0000
  66. /* subchip/slave 1 - AUD ID */
  67. #define TWL4030_BASEADD_AUDIO_VOICE 0x0000
  68. #define TWL4030_BASEADD_GPIO 0x0098
  69. #define TWL4030_BASEADD_INTBR 0x0085
  70. #define TWL4030_BASEADD_PIH 0x0080
  71. #define TWL4030_BASEADD_TEST 0x004C
  72. /* subchip/slave 2 - AUX ID */
  73. #define TWL4030_BASEADD_INTERRUPTS 0x00B9
  74. #define TWL4030_BASEADD_LED 0x00EE
  75. #define TWL4030_BASEADD_MADC 0x0000
  76. #define TWL4030_BASEADD_MAIN_CHARGE 0x0074
  77. #define TWL4030_BASEADD_PRECHARGE 0x00AA
  78. #define TWL4030_BASEADD_PWM 0x00F8
  79. #define TWL4030_BASEADD_KEYPAD 0x00D2
  80. #define TWL5031_BASEADD_ACCESSORY 0x0074 /* Replaces Main Charge */
  81. #define TWL5031_BASEADD_INTERRUPTS 0x00B9 /* Different than TWL4030's
  82. one */
  83. /* subchip/slave 3 - POWER ID */
  84. #define TWL4030_BASEADD_BACKUP 0x0014
  85. #define TWL4030_BASEADD_INT 0x002E
  86. #define TWL4030_BASEADD_PM_MASTER 0x0036
  87. #define TWL4030_BASEADD_PM_RECEIVER 0x005B
  88. #define TWL4030_DCDC_GLOBAL_CFG 0x06
  89. #define SMARTREFLEX_ENABLE BIT(3)
  90. #define TWL4030_BASEADD_RTC 0x001C
  91. #define TWL4030_BASEADD_SECURED_REG 0x0000
  92. /* Triton Core internal information (END) */
  93. /* subchip/slave 0 0x48 - POWER */
  94. #define TWL6030_BASEADD_RTC 0x0000
  95. #define TWL6030_BASEADD_SECURED_REG 0x0017
  96. #define TWL6030_BASEADD_PM_MASTER 0x001F
  97. #define TWL6030_BASEADD_PM_SLAVE_MISC 0x0030 /* PM_RECEIVER */
  98. #define TWL6030_BASEADD_PM_MISC 0x00E2
  99. #define TWL6030_BASEADD_PM_PUPD 0x00F0
  100. /* subchip/slave 1 0x49 - FEATURE */
  101. #define TWL6030_BASEADD_USB 0x0000
  102. #define TWL6030_BASEADD_GPADC_CTRL 0x002E
  103. #define TWL6030_BASEADD_AUX 0x0090
  104. #define TWL6030_BASEADD_PWM 0x00BA
  105. #define TWL6030_BASEADD_GASGAUGE 0x00C0
  106. #define TWL6030_BASEADD_PIH 0x00D0
  107. #define TWL6030_BASEADD_CHARGER 0x00E0
  108. #define TWL6032_BASEADD_CHARGER 0x00DA
  109. #define TWL6030_BASEADD_LED 0x00F4
  110. /* subchip/slave 2 0x4A - DFT */
  111. #define TWL6030_BASEADD_DIEID 0x00C0
  112. /* subchip/slave 3 0x4B - AUDIO */
  113. #define TWL6030_BASEADD_AUDIO 0x0000
  114. #define TWL6030_BASEADD_RSV 0x0000
  115. #define TWL6030_BASEADD_ZERO 0x0000
  116. /* Few power values */
  117. #define R_CFG_BOOT 0x05
  118. /* some fields in R_CFG_BOOT */
  119. #define HFCLK_FREQ_19p2_MHZ (1 << 0)
  120. #define HFCLK_FREQ_26_MHZ (2 << 0)
  121. #define HFCLK_FREQ_38p4_MHZ (3 << 0)
  122. #define HIGH_PERF_SQ (1 << 3)
  123. #define CK32K_LOWPWR_EN (1 << 7)
  124. /*----------------------------------------------------------------------*/
  125. /* Structure for each TWL4030/TWL6030 Slave */
  126. struct twl_client {
  127. struct i2c_client *client;
  128. struct regmap *regmap;
  129. };
  130. /* mapping the module id to slave id and base address */
  131. struct twl_mapping {
  132. unsigned char sid; /* Slave ID */
  133. unsigned char base; /* base address */
  134. };
  135. struct twl_private {
  136. bool ready; /* The core driver is ready to be used */
  137. u32 twl_idcode; /* TWL IDCODE Register value */
  138. unsigned int twl_id;
  139. struct twl_mapping *twl_map;
  140. struct twl_client *twl_modules;
  141. };
  142. static struct twl_private *twl_priv;
  143. static struct twl_mapping twl4030_map[] = {
  144. /*
  145. * NOTE: don't change this table without updating the
  146. * <linux/i2c/twl.h> defines for TWL4030_MODULE_*
  147. * so they continue to match the order in this table.
  148. */
  149. /* Common IPs */
  150. { 0, TWL4030_BASEADD_USB },
  151. { 1, TWL4030_BASEADD_PIH },
  152. { 2, TWL4030_BASEADD_MAIN_CHARGE },
  153. { 3, TWL4030_BASEADD_PM_MASTER },
  154. { 3, TWL4030_BASEADD_PM_RECEIVER },
  155. { 3, TWL4030_BASEADD_RTC },
  156. { 2, TWL4030_BASEADD_PWM },
  157. { 2, TWL4030_BASEADD_LED },
  158. { 3, TWL4030_BASEADD_SECURED_REG },
  159. /* TWL4030 specific IPs */
  160. { 1, TWL4030_BASEADD_AUDIO_VOICE },
  161. { 1, TWL4030_BASEADD_GPIO },
  162. { 1, TWL4030_BASEADD_INTBR },
  163. { 1, TWL4030_BASEADD_TEST },
  164. { 2, TWL4030_BASEADD_KEYPAD },
  165. { 2, TWL4030_BASEADD_MADC },
  166. { 2, TWL4030_BASEADD_INTERRUPTS },
  167. { 2, TWL4030_BASEADD_PRECHARGE },
  168. { 3, TWL4030_BASEADD_BACKUP },
  169. { 3, TWL4030_BASEADD_INT },
  170. { 2, TWL5031_BASEADD_ACCESSORY },
  171. { 2, TWL5031_BASEADD_INTERRUPTS },
  172. };
  173. static const struct reg_default twl4030_49_defaults[] = {
  174. /* Audio Registers */
  175. { 0x01, 0x00}, /* CODEC_MODE */
  176. { 0x02, 0x00}, /* OPTION */
  177. /* 0x03 Unused */
  178. { 0x04, 0x00}, /* MICBIAS_CTL */
  179. { 0x05, 0x00}, /* ANAMICL */
  180. { 0x06, 0x00}, /* ANAMICR */
  181. { 0x07, 0x00}, /* AVADC_CTL */
  182. { 0x08, 0x00}, /* ADCMICSEL */
  183. { 0x09, 0x00}, /* DIGMIXING */
  184. { 0x0a, 0x0f}, /* ATXL1PGA */
  185. { 0x0b, 0x0f}, /* ATXR1PGA */
  186. { 0x0c, 0x0f}, /* AVTXL2PGA */
  187. { 0x0d, 0x0f}, /* AVTXR2PGA */
  188. { 0x0e, 0x00}, /* AUDIO_IF */
  189. { 0x0f, 0x00}, /* VOICE_IF */
  190. { 0x10, 0x3f}, /* ARXR1PGA */
  191. { 0x11, 0x3f}, /* ARXL1PGA */
  192. { 0x12, 0x3f}, /* ARXR2PGA */
  193. { 0x13, 0x3f}, /* ARXL2PGA */
  194. { 0x14, 0x25}, /* VRXPGA */
  195. { 0x15, 0x00}, /* VSTPGA */
  196. { 0x16, 0x00}, /* VRX2ARXPGA */
  197. { 0x17, 0x00}, /* AVDAC_CTL */
  198. { 0x18, 0x00}, /* ARX2VTXPGA */
  199. { 0x19, 0x32}, /* ARXL1_APGA_CTL*/
  200. { 0x1a, 0x32}, /* ARXR1_APGA_CTL*/
  201. { 0x1b, 0x32}, /* ARXL2_APGA_CTL*/
  202. { 0x1c, 0x32}, /* ARXR2_APGA_CTL*/
  203. { 0x1d, 0x00}, /* ATX2ARXPGA */
  204. { 0x1e, 0x00}, /* BT_IF */
  205. { 0x1f, 0x55}, /* BTPGA */
  206. { 0x20, 0x00}, /* BTSTPGA */
  207. { 0x21, 0x00}, /* EAR_CTL */
  208. { 0x22, 0x00}, /* HS_SEL */
  209. { 0x23, 0x00}, /* HS_GAIN_SET */
  210. { 0x24, 0x00}, /* HS_POPN_SET */
  211. { 0x25, 0x00}, /* PREDL_CTL */
  212. { 0x26, 0x00}, /* PREDR_CTL */
  213. { 0x27, 0x00}, /* PRECKL_CTL */
  214. { 0x28, 0x00}, /* PRECKR_CTL */
  215. { 0x29, 0x00}, /* HFL_CTL */
  216. { 0x2a, 0x00}, /* HFR_CTL */
  217. { 0x2b, 0x05}, /* ALC_CTL */
  218. { 0x2c, 0x00}, /* ALC_SET1 */
  219. { 0x2d, 0x00}, /* ALC_SET2 */
  220. { 0x2e, 0x00}, /* BOOST_CTL */
  221. { 0x2f, 0x00}, /* SOFTVOL_CTL */
  222. { 0x30, 0x13}, /* DTMF_FREQSEL */
  223. { 0x31, 0x00}, /* DTMF_TONEXT1H */
  224. { 0x32, 0x00}, /* DTMF_TONEXT1L */
  225. { 0x33, 0x00}, /* DTMF_TONEXT2H */
  226. { 0x34, 0x00}, /* DTMF_TONEXT2L */
  227. { 0x35, 0x79}, /* DTMF_TONOFF */
  228. { 0x36, 0x11}, /* DTMF_WANONOFF */
  229. { 0x37, 0x00}, /* I2S_RX_SCRAMBLE_H */
  230. { 0x38, 0x00}, /* I2S_RX_SCRAMBLE_M */
  231. { 0x39, 0x00}, /* I2S_RX_SCRAMBLE_L */
  232. { 0x3a, 0x06}, /* APLL_CTL */
  233. { 0x3b, 0x00}, /* DTMF_CTL */
  234. { 0x3c, 0x44}, /* DTMF_PGA_CTL2 (0x3C) */
  235. { 0x3d, 0x69}, /* DTMF_PGA_CTL1 (0x3D) */
  236. { 0x3e, 0x00}, /* MISC_SET_1 */
  237. { 0x3f, 0x00}, /* PCMBTMUX */
  238. /* 0x40 - 0x42 Unused */
  239. { 0x43, 0x00}, /* RX_PATH_SEL */
  240. { 0x44, 0x32}, /* VDL_APGA_CTL */
  241. { 0x45, 0x00}, /* VIBRA_CTL */
  242. { 0x46, 0x00}, /* VIBRA_SET */
  243. { 0x47, 0x00}, /* VIBRA_PWM_SET */
  244. { 0x48, 0x00}, /* ANAMIC_GAIN */
  245. { 0x49, 0x00}, /* MISC_SET_2 */
  246. /* End of Audio Registers */
  247. };
  248. static bool twl4030_49_nop_reg(struct device *dev, unsigned int reg)
  249. {
  250. switch (reg) {
  251. case 0x00:
  252. case 0x03:
  253. case 0x40:
  254. case 0x41:
  255. case 0x42:
  256. return false;
  257. default:
  258. return true;
  259. }
  260. }
  261. static const struct regmap_range twl4030_49_volatile_ranges[] = {
  262. regmap_reg_range(TWL4030_BASEADD_TEST, 0xff),
  263. };
  264. static const struct regmap_access_table twl4030_49_volatile_table = {
  265. .yes_ranges = twl4030_49_volatile_ranges,
  266. .n_yes_ranges = ARRAY_SIZE(twl4030_49_volatile_ranges),
  267. };
  268. static const struct regmap_config twl4030_regmap_config[4] = {
  269. {
  270. /* Address 0x48 */
  271. .reg_bits = 8,
  272. .val_bits = 8,
  273. .max_register = 0xff,
  274. },
  275. {
  276. /* Address 0x49 */
  277. .reg_bits = 8,
  278. .val_bits = 8,
  279. .max_register = 0xff,
  280. .readable_reg = twl4030_49_nop_reg,
  281. .writeable_reg = twl4030_49_nop_reg,
  282. .volatile_table = &twl4030_49_volatile_table,
  283. .reg_defaults = twl4030_49_defaults,
  284. .num_reg_defaults = ARRAY_SIZE(twl4030_49_defaults),
  285. .cache_type = REGCACHE_RBTREE,
  286. },
  287. {
  288. /* Address 0x4a */
  289. .reg_bits = 8,
  290. .val_bits = 8,
  291. .max_register = 0xff,
  292. },
  293. {
  294. /* Address 0x4b */
  295. .reg_bits = 8,
  296. .val_bits = 8,
  297. .max_register = 0xff,
  298. },
  299. };
  300. static struct twl_mapping twl6030_map[] = {
  301. /*
  302. * NOTE: don't change this table without updating the
  303. * <linux/i2c/twl.h> defines for TWL4030_MODULE_*
  304. * so they continue to match the order in this table.
  305. */
  306. /* Common IPs */
  307. { 1, TWL6030_BASEADD_USB },
  308. { 1, TWL6030_BASEADD_PIH },
  309. { 1, TWL6030_BASEADD_CHARGER },
  310. { 0, TWL6030_BASEADD_PM_MASTER },
  311. { 0, TWL6030_BASEADD_PM_SLAVE_MISC },
  312. { 0, TWL6030_BASEADD_RTC },
  313. { 1, TWL6030_BASEADD_PWM },
  314. { 1, TWL6030_BASEADD_LED },
  315. { 0, TWL6030_BASEADD_SECURED_REG },
  316. /* TWL6030 specific IPs */
  317. { 0, TWL6030_BASEADD_ZERO },
  318. { 1, TWL6030_BASEADD_ZERO },
  319. { 2, TWL6030_BASEADD_ZERO },
  320. { 1, TWL6030_BASEADD_GPADC_CTRL },
  321. { 1, TWL6030_BASEADD_GASGAUGE },
  322. };
  323. static const struct regmap_config twl6030_regmap_config[3] = {
  324. {
  325. /* Address 0x48 */
  326. .reg_bits = 8,
  327. .val_bits = 8,
  328. .max_register = 0xff,
  329. },
  330. {
  331. /* Address 0x49 */
  332. .reg_bits = 8,
  333. .val_bits = 8,
  334. .max_register = 0xff,
  335. },
  336. {
  337. /* Address 0x4a */
  338. .reg_bits = 8,
  339. .val_bits = 8,
  340. .max_register = 0xff,
  341. },
  342. };
  343. /*----------------------------------------------------------------------*/
  344. static inline int twl_get_num_slaves(void)
  345. {
  346. if (twl_class_is_4030())
  347. return 4; /* TWL4030 class have four slave address */
  348. else
  349. return 3; /* TWL6030 class have three slave address */
  350. }
  351. static inline int twl_get_last_module(void)
  352. {
  353. if (twl_class_is_4030())
  354. return TWL4030_MODULE_LAST;
  355. else
  356. return TWL6030_MODULE_LAST;
  357. }
  358. /* Exported Functions */
  359. unsigned int twl_rev(void)
  360. {
  361. return twl_priv ? twl_priv->twl_id : 0;
  362. }
  363. EXPORT_SYMBOL(twl_rev);
  364. /**
  365. * twl_get_regmap - Get the regmap associated with the given module
  366. * @mod_no: module number
  367. *
  368. * Returns the regmap pointer or NULL in case of failure.
  369. */
  370. static struct regmap *twl_get_regmap(u8 mod_no)
  371. {
  372. int sid;
  373. struct twl_client *twl;
  374. if (unlikely(!twl_priv || !twl_priv->ready)) {
  375. pr_err("%s: not initialized\n", DRIVER_NAME);
  376. return NULL;
  377. }
  378. if (unlikely(mod_no >= twl_get_last_module())) {
  379. pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
  380. return NULL;
  381. }
  382. sid = twl_priv->twl_map[mod_no].sid;
  383. twl = &twl_priv->twl_modules[sid];
  384. return twl->regmap;
  385. }
  386. /**
  387. * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0
  388. * @mod_no: module number
  389. * @value: an array of num_bytes+1 containing data to write
  390. * @reg: register address (just offset will do)
  391. * @num_bytes: number of bytes to transfer
  392. *
  393. * Returns the result of operation - 0 is success
  394. */
  395. int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
  396. {
  397. struct regmap *regmap = twl_get_regmap(mod_no);
  398. int ret;
  399. if (!regmap)
  400. return -EPERM;
  401. ret = regmap_bulk_write(regmap, twl_priv->twl_map[mod_no].base + reg,
  402. value, num_bytes);
  403. if (ret)
  404. pr_err("%s: Write failed (mod %d, reg 0x%02x count %d)\n",
  405. DRIVER_NAME, mod_no, reg, num_bytes);
  406. return ret;
  407. }
  408. EXPORT_SYMBOL(twl_i2c_write);
  409. /**
  410. * twl_i2c_read - Reads a n bit register in TWL4030/TWL5030/TWL60X0
  411. * @mod_no: module number
  412. * @value: an array of num_bytes containing data to be read
  413. * @reg: register address (just offset will do)
  414. * @num_bytes: number of bytes to transfer
  415. *
  416. * Returns result of operation - num_bytes is success else failure.
  417. */
  418. int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
  419. {
  420. struct regmap *regmap = twl_get_regmap(mod_no);
  421. int ret;
  422. if (!regmap)
  423. return -EPERM;
  424. ret = regmap_bulk_read(regmap, twl_priv->twl_map[mod_no].base + reg,
  425. value, num_bytes);
  426. if (ret)
  427. pr_err("%s: Read failed (mod %d, reg 0x%02x count %d)\n",
  428. DRIVER_NAME, mod_no, reg, num_bytes);
  429. return ret;
  430. }
  431. EXPORT_SYMBOL(twl_i2c_read);
  432. /**
  433. * twl_regcache_bypass - Configure the regcache bypass for the regmap associated
  434. * with the module
  435. * @mod_no: module number
  436. * @enable: Regcache bypass state
  437. *
  438. * Returns 0 else failure.
  439. */
  440. int twl_set_regcache_bypass(u8 mod_no, bool enable)
  441. {
  442. struct regmap *regmap = twl_get_regmap(mod_no);
  443. if (!regmap)
  444. return -EPERM;
  445. regcache_cache_bypass(regmap, enable);
  446. return 0;
  447. }
  448. EXPORT_SYMBOL(twl_set_regcache_bypass);
  449. /*----------------------------------------------------------------------*/
  450. /**
  451. * twl_read_idcode_register - API to read the IDCODE register.
  452. *
  453. * Unlocks the IDCODE register and read the 32 bit value.
  454. */
  455. static int twl_read_idcode_register(void)
  456. {
  457. int err;
  458. err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, TWL_EEPROM_R_UNLOCK,
  459. REG_UNLOCK_TEST_REG);
  460. if (err) {
  461. pr_err("TWL4030 Unable to unlock IDCODE registers -%d\n", err);
  462. goto fail;
  463. }
  464. err = twl_i2c_read(TWL4030_MODULE_INTBR, (u8 *)(&twl_priv->twl_idcode),
  465. REG_IDCODE_7_0, 4);
  466. if (err) {
  467. pr_err("TWL4030: unable to read IDCODE -%d\n", err);
  468. goto fail;
  469. }
  470. err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, 0x0, REG_UNLOCK_TEST_REG);
  471. if (err)
  472. pr_err("TWL4030 Unable to relock IDCODE registers -%d\n", err);
  473. fail:
  474. return err;
  475. }
  476. /**
  477. * twl_get_type - API to get TWL Si type.
  478. *
  479. * Api to get the TWL Si type from IDCODE value.
  480. */
  481. int twl_get_type(void)
  482. {
  483. return TWL_SIL_TYPE(twl_priv->twl_idcode);
  484. }
  485. EXPORT_SYMBOL_GPL(twl_get_type);
  486. /**
  487. * twl_get_version - API to get TWL Si version.
  488. *
  489. * Api to get the TWL Si version from IDCODE value.
  490. */
  491. int twl_get_version(void)
  492. {
  493. return TWL_SIL_REV(twl_priv->twl_idcode);
  494. }
  495. EXPORT_SYMBOL_GPL(twl_get_version);
  496. /**
  497. * twl_get_hfclk_rate - API to get TWL external HFCLK clock rate.
  498. *
  499. * Api to get the TWL HFCLK rate based on BOOT_CFG register.
  500. */
  501. int twl_get_hfclk_rate(void)
  502. {
  503. u8 ctrl;
  504. int rate;
  505. twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &ctrl, R_CFG_BOOT);
  506. switch (ctrl & 0x3) {
  507. case HFCLK_FREQ_19p2_MHZ:
  508. rate = 19200000;
  509. break;
  510. case HFCLK_FREQ_26_MHZ:
  511. rate = 26000000;
  512. break;
  513. case HFCLK_FREQ_38p4_MHZ:
  514. rate = 38400000;
  515. break;
  516. default:
  517. pr_err("TWL4030: HFCLK is not configured\n");
  518. rate = -EINVAL;
  519. break;
  520. }
  521. return rate;
  522. }
  523. EXPORT_SYMBOL_GPL(twl_get_hfclk_rate);
  524. static struct device *
  525. add_numbered_child(unsigned mod_no, const char *name, int num,
  526. void *pdata, unsigned pdata_len,
  527. bool can_wakeup, int irq0, int irq1)
  528. {
  529. struct platform_device *pdev;
  530. struct twl_client *twl;
  531. int status, sid;
  532. if (unlikely(mod_no >= twl_get_last_module())) {
  533. pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
  534. return ERR_PTR(-EPERM);
  535. }
  536. sid = twl_priv->twl_map[mod_no].sid;
  537. twl = &twl_priv->twl_modules[sid];
  538. pdev = platform_device_alloc(name, num);
  539. if (!pdev) {
  540. dev_dbg(&twl->client->dev, "can't alloc dev\n");
  541. status = -ENOMEM;
  542. goto err;
  543. }
  544. pdev->dev.parent = &twl->client->dev;
  545. if (pdata) {
  546. status = platform_device_add_data(pdev, pdata, pdata_len);
  547. if (status < 0) {
  548. dev_dbg(&pdev->dev, "can't add platform_data\n");
  549. goto err;
  550. }
  551. }
  552. if (irq0) {
  553. struct resource r[2] = {
  554. { .start = irq0, .flags = IORESOURCE_IRQ, },
  555. { .start = irq1, .flags = IORESOURCE_IRQ, },
  556. };
  557. status = platform_device_add_resources(pdev, r, irq1 ? 2 : 1);
  558. if (status < 0) {
  559. dev_dbg(&pdev->dev, "can't add irqs\n");
  560. goto err;
  561. }
  562. }
  563. status = platform_device_add(pdev);
  564. if (status == 0)
  565. device_init_wakeup(&pdev->dev, can_wakeup);
  566. err:
  567. if (status < 0) {
  568. platform_device_put(pdev);
  569. dev_err(&twl->client->dev, "can't add %s dev\n", name);
  570. return ERR_PTR(status);
  571. }
  572. return &pdev->dev;
  573. }
  574. static inline struct device *add_child(unsigned mod_no, const char *name,
  575. void *pdata, unsigned pdata_len,
  576. bool can_wakeup, int irq0, int irq1)
  577. {
  578. return add_numbered_child(mod_no, name, -1, pdata, pdata_len,
  579. can_wakeup, irq0, irq1);
  580. }
  581. static struct device *
  582. add_regulator_linked(int num, struct regulator_init_data *pdata,
  583. struct regulator_consumer_supply *consumers,
  584. unsigned num_consumers, unsigned long features)
  585. {
  586. struct twl_regulator_driver_data drv_data;
  587. /* regulator framework demands init_data ... */
  588. if (!pdata)
  589. return NULL;
  590. if (consumers) {
  591. pdata->consumer_supplies = consumers;
  592. pdata->num_consumer_supplies = num_consumers;
  593. }
  594. if (pdata->driver_data) {
  595. /* If we have existing drv_data, just add the flags */
  596. struct twl_regulator_driver_data *tmp;
  597. tmp = pdata->driver_data;
  598. tmp->features |= features;
  599. } else {
  600. /* add new driver data struct, used only during init */
  601. drv_data.features = features;
  602. drv_data.set_voltage = NULL;
  603. drv_data.get_voltage = NULL;
  604. drv_data.data = NULL;
  605. pdata->driver_data = &drv_data;
  606. }
  607. /* NOTE: we currently ignore regulator IRQs, e.g. for short circuits */
  608. return add_numbered_child(TWL_MODULE_PM_MASTER, "twl_reg", num,
  609. pdata, sizeof(*pdata), false, 0, 0);
  610. }
  611. static struct device *
  612. add_regulator(int num, struct regulator_init_data *pdata,
  613. unsigned long features)
  614. {
  615. return add_regulator_linked(num, pdata, NULL, 0, features);
  616. }
  617. /*
  618. * NOTE: We know the first 8 IRQs after pdata->base_irq are
  619. * for the PIH, and the next are for the PWR_INT SIH, since
  620. * that's how twl_init_irq() sets things up.
  621. */
  622. static int
  623. add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
  624. unsigned long features)
  625. {
  626. struct device *child;
  627. if (IS_ENABLED(CONFIG_GPIO_TWL4030) && pdata->gpio) {
  628. child = add_child(TWL4030_MODULE_GPIO, "twl4030_gpio",
  629. pdata->gpio, sizeof(*pdata->gpio),
  630. false, irq_base + GPIO_INTR_OFFSET, 0);
  631. if (IS_ERR(child))
  632. return PTR_ERR(child);
  633. }
  634. if (IS_ENABLED(CONFIG_KEYBOARD_TWL4030) && pdata->keypad) {
  635. child = add_child(TWL4030_MODULE_KEYPAD, "twl4030_keypad",
  636. pdata->keypad, sizeof(*pdata->keypad),
  637. true, irq_base + KEYPAD_INTR_OFFSET, 0);
  638. if (IS_ERR(child))
  639. return PTR_ERR(child);
  640. }
  641. if (IS_ENABLED(CONFIG_TWL4030_MADC) && pdata->madc &&
  642. twl_class_is_4030()) {
  643. child = add_child(TWL4030_MODULE_MADC, "twl4030_madc",
  644. pdata->madc, sizeof(*pdata->madc),
  645. true, irq_base + MADC_INTR_OFFSET, 0);
  646. if (IS_ERR(child))
  647. return PTR_ERR(child);
  648. }
  649. if (IS_ENABLED(CONFIG_RTC_DRV_TWL4030)) {
  650. /*
  651. * REVISIT platform_data here currently might expose the
  652. * "msecure" line ... but for now we just expect board
  653. * setup to tell the chip "it's always ok to SET_TIME".
  654. * Eventually, Linux might become more aware of such
  655. * HW security concerns, and "least privilege".
  656. */
  657. child = add_child(TWL_MODULE_RTC, "twl_rtc", NULL, 0,
  658. true, irq_base + RTC_INTR_OFFSET, 0);
  659. if (IS_ERR(child))
  660. return PTR_ERR(child);
  661. }
  662. if (IS_ENABLED(CONFIG_PWM_TWL)) {
  663. child = add_child(TWL_MODULE_PWM, "twl-pwm", NULL, 0,
  664. false, 0, 0);
  665. if (IS_ERR(child))
  666. return PTR_ERR(child);
  667. }
  668. if (IS_ENABLED(CONFIG_PWM_TWL_LED)) {
  669. child = add_child(TWL_MODULE_LED, "twl-pwmled", NULL, 0,
  670. false, 0, 0);
  671. if (IS_ERR(child))
  672. return PTR_ERR(child);
  673. }
  674. if (IS_ENABLED(CONFIG_TWL4030_USB) && pdata->usb &&
  675. twl_class_is_4030()) {
  676. static struct regulator_consumer_supply usb1v5 = {
  677. .supply = "usb1v5",
  678. };
  679. static struct regulator_consumer_supply usb1v8 = {
  680. .supply = "usb1v8",
  681. };
  682. static struct regulator_consumer_supply usb3v1 = {
  683. .supply = "usb3v1",
  684. };
  685. /* First add the regulators so that they can be used by transceiver */
  686. if (IS_ENABLED(CONFIG_REGULATOR_TWL4030)) {
  687. /* this is a template that gets copied */
  688. struct regulator_init_data usb_fixed = {
  689. .constraints.valid_modes_mask =
  690. REGULATOR_MODE_NORMAL
  691. | REGULATOR_MODE_STANDBY,
  692. .constraints.valid_ops_mask =
  693. REGULATOR_CHANGE_MODE
  694. | REGULATOR_CHANGE_STATUS,
  695. };
  696. child = add_regulator_linked(TWL4030_REG_VUSB1V5,
  697. &usb_fixed, &usb1v5, 1,
  698. features);
  699. if (IS_ERR(child))
  700. return PTR_ERR(child);
  701. child = add_regulator_linked(TWL4030_REG_VUSB1V8,
  702. &usb_fixed, &usb1v8, 1,
  703. features);
  704. if (IS_ERR(child))
  705. return PTR_ERR(child);
  706. child = add_regulator_linked(TWL4030_REG_VUSB3V1,
  707. &usb_fixed, &usb3v1, 1,
  708. features);
  709. if (IS_ERR(child))
  710. return PTR_ERR(child);
  711. }
  712. child = add_child(TWL_MODULE_USB, "twl4030_usb",
  713. pdata->usb, sizeof(*pdata->usb), true,
  714. /* irq0 = USB_PRES, irq1 = USB */
  715. irq_base + USB_PRES_INTR_OFFSET,
  716. irq_base + USB_INTR_OFFSET);
  717. if (IS_ERR(child))
  718. return PTR_ERR(child);
  719. /* we need to connect regulators to this transceiver */
  720. if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && child) {
  721. usb1v5.dev_name = dev_name(child);
  722. usb1v8.dev_name = dev_name(child);
  723. usb3v1.dev_name = dev_name(child);
  724. }
  725. }
  726. if (IS_ENABLED(CONFIG_TWL4030_WATCHDOG) && twl_class_is_4030()) {
  727. child = add_child(TWL_MODULE_PM_RECEIVER, "twl4030_wdt", NULL,
  728. 0, false, 0, 0);
  729. if (IS_ERR(child))
  730. return PTR_ERR(child);
  731. }
  732. if (IS_ENABLED(CONFIG_INPUT_TWL4030_PWRBUTTON) && twl_class_is_4030()) {
  733. child = add_child(TWL_MODULE_PM_MASTER, "twl4030_pwrbutton",
  734. NULL, 0, true, irq_base + 8 + 0, 0);
  735. if (IS_ERR(child))
  736. return PTR_ERR(child);
  737. }
  738. if (IS_ENABLED(CONFIG_MFD_TWL4030_AUDIO) && pdata->audio &&
  739. twl_class_is_4030()) {
  740. child = add_child(TWL4030_MODULE_AUDIO_VOICE, "twl4030-audio",
  741. pdata->audio, sizeof(*pdata->audio),
  742. false, 0, 0);
  743. if (IS_ERR(child))
  744. return PTR_ERR(child);
  745. }
  746. /* twl4030 regulators */
  747. if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_4030()) {
  748. child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1,
  749. features);
  750. if (IS_ERR(child))
  751. return PTR_ERR(child);
  752. child = add_regulator(TWL4030_REG_VIO, pdata->vio,
  753. features);
  754. if (IS_ERR(child))
  755. return PTR_ERR(child);
  756. child = add_regulator(TWL4030_REG_VDD1, pdata->vdd1,
  757. features);
  758. if (IS_ERR(child))
  759. return PTR_ERR(child);
  760. child = add_regulator(TWL4030_REG_VDD2, pdata->vdd2,
  761. features);
  762. if (IS_ERR(child))
  763. return PTR_ERR(child);
  764. child = add_regulator(TWL4030_REG_VMMC1, pdata->vmmc1,
  765. features);
  766. if (IS_ERR(child))
  767. return PTR_ERR(child);
  768. child = add_regulator(TWL4030_REG_VDAC, pdata->vdac,
  769. features);
  770. if (IS_ERR(child))
  771. return PTR_ERR(child);
  772. child = add_regulator((features & TWL4030_VAUX2)
  773. ? TWL4030_REG_VAUX2_4030
  774. : TWL4030_REG_VAUX2,
  775. pdata->vaux2, features);
  776. if (IS_ERR(child))
  777. return PTR_ERR(child);
  778. child = add_regulator(TWL4030_REG_VINTANA1, pdata->vintana1,
  779. features);
  780. if (IS_ERR(child))
  781. return PTR_ERR(child);
  782. child = add_regulator(TWL4030_REG_VINTANA2, pdata->vintana2,
  783. features);
  784. if (IS_ERR(child))
  785. return PTR_ERR(child);
  786. child = add_regulator(TWL4030_REG_VINTDIG, pdata->vintdig,
  787. features);
  788. if (IS_ERR(child))
  789. return PTR_ERR(child);
  790. }
  791. /* maybe add LDOs that are omitted on cost-reduced parts */
  792. if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && !(features & TPS_SUBSET)
  793. && twl_class_is_4030()) {
  794. child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2,
  795. features);
  796. if (IS_ERR(child))
  797. return PTR_ERR(child);
  798. child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2,
  799. features);
  800. if (IS_ERR(child))
  801. return PTR_ERR(child);
  802. child = add_regulator(TWL4030_REG_VSIM, pdata->vsim,
  803. features);
  804. if (IS_ERR(child))
  805. return PTR_ERR(child);
  806. child = add_regulator(TWL4030_REG_VAUX1, pdata->vaux1,
  807. features);
  808. if (IS_ERR(child))
  809. return PTR_ERR(child);
  810. child = add_regulator(TWL4030_REG_VAUX3, pdata->vaux3,
  811. features);
  812. if (IS_ERR(child))
  813. return PTR_ERR(child);
  814. child = add_regulator(TWL4030_REG_VAUX4, pdata->vaux4,
  815. features);
  816. if (IS_ERR(child))
  817. return PTR_ERR(child);
  818. }
  819. if (IS_ENABLED(CONFIG_CHARGER_TWL4030) && pdata->bci &&
  820. !(features & (TPS_SUBSET | TWL5031))) {
  821. child = add_child(TWL_MODULE_MAIN_CHARGE, "twl4030_bci",
  822. pdata->bci, sizeof(*pdata->bci), false,
  823. /* irq0 = CHG_PRES, irq1 = BCI */
  824. irq_base + BCI_PRES_INTR_OFFSET,
  825. irq_base + BCI_INTR_OFFSET);
  826. if (IS_ERR(child))
  827. return PTR_ERR(child);
  828. }
  829. if (IS_ENABLED(CONFIG_TWL4030_POWER) && pdata->power) {
  830. child = add_child(TWL_MODULE_PM_MASTER, "twl4030_power",
  831. pdata->power, sizeof(*pdata->power), false,
  832. 0, 0);
  833. if (IS_ERR(child))
  834. return PTR_ERR(child);
  835. }
  836. return 0;
  837. }
  838. /*----------------------------------------------------------------------*/
  839. /*
  840. * These three functions initialize the on-chip clock framework,
  841. * letting it generate the right frequencies for USB, MADC, and
  842. * other purposes.
  843. */
  844. static inline int protect_pm_master(void)
  845. {
  846. int e = 0;
  847. e = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 0,
  848. TWL4030_PM_MASTER_PROTECT_KEY);
  849. return e;
  850. }
  851. static inline int unprotect_pm_master(void)
  852. {
  853. int e = 0;
  854. e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1,
  855. TWL4030_PM_MASTER_PROTECT_KEY);
  856. e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG2,
  857. TWL4030_PM_MASTER_PROTECT_KEY);
  858. return e;
  859. }
  860. static void clocks_init(struct device *dev,
  861. struct twl4030_clock_init_data *clock)
  862. {
  863. int e = 0;
  864. struct clk *osc;
  865. u32 rate;
  866. u8 ctrl = HFCLK_FREQ_26_MHZ;
  867. osc = clk_get(dev, "fck");
  868. if (IS_ERR(osc)) {
  869. printk(KERN_WARNING "Skipping twl internal clock init and "
  870. "using bootloader value (unknown osc rate)\n");
  871. return;
  872. }
  873. rate = clk_get_rate(osc);
  874. clk_put(osc);
  875. switch (rate) {
  876. case 19200000:
  877. ctrl = HFCLK_FREQ_19p2_MHZ;
  878. break;
  879. case 26000000:
  880. ctrl = HFCLK_FREQ_26_MHZ;
  881. break;
  882. case 38400000:
  883. ctrl = HFCLK_FREQ_38p4_MHZ;
  884. break;
  885. }
  886. ctrl |= HIGH_PERF_SQ;
  887. if (clock && clock->ck32k_lowpwr_enable)
  888. ctrl |= CK32K_LOWPWR_EN;
  889. e |= unprotect_pm_master();
  890. /* effect->MADC+USB ck en */
  891. e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, ctrl, R_CFG_BOOT);
  892. e |= protect_pm_master();
  893. if (e < 0)
  894. pr_err("%s: clock init err [%d]\n", DRIVER_NAME, e);
  895. }
  896. /*----------------------------------------------------------------------*/
  897. static int twl_remove(struct i2c_client *client)
  898. {
  899. unsigned i, num_slaves;
  900. int status;
  901. if (twl_class_is_4030())
  902. status = twl4030_exit_irq();
  903. else
  904. status = twl6030_exit_irq();
  905. if (status < 0)
  906. return status;
  907. num_slaves = twl_get_num_slaves();
  908. for (i = 0; i < num_slaves; i++) {
  909. struct twl_client *twl = &twl_priv->twl_modules[i];
  910. if (twl->client && twl->client != client)
  911. i2c_unregister_device(twl->client);
  912. twl->client = NULL;
  913. }
  914. twl_priv->ready = false;
  915. return 0;
  916. }
  917. static struct of_dev_auxdata twl_auxdata_lookup[] = {
  918. OF_DEV_AUXDATA("ti,twl4030-gpio", 0, "twl4030-gpio", NULL),
  919. { /* sentinel */ },
  920. };
  921. /* NOTE: This driver only handles a single twl4030/tps659x0 chip */
  922. static int
  923. twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
  924. {
  925. struct twl4030_platform_data *pdata = dev_get_platdata(&client->dev);
  926. struct device_node *node = client->dev.of_node;
  927. struct platform_device *pdev;
  928. const struct regmap_config *twl_regmap_config;
  929. int irq_base = 0;
  930. int status;
  931. unsigned i, num_slaves;
  932. if (!node && !pdata) {
  933. dev_err(&client->dev, "no platform data\n");
  934. return -EINVAL;
  935. }
  936. if (twl_priv) {
  937. dev_dbg(&client->dev, "only one instance of %s allowed\n",
  938. DRIVER_NAME);
  939. return -EBUSY;
  940. }
  941. pdev = platform_device_alloc(DRIVER_NAME, -1);
  942. if (!pdev) {
  943. dev_err(&client->dev, "can't alloc pdev\n");
  944. return -ENOMEM;
  945. }
  946. status = platform_device_add(pdev);
  947. if (status) {
  948. platform_device_put(pdev);
  949. return status;
  950. }
  951. if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
  952. dev_dbg(&client->dev, "can't talk I2C?\n");
  953. status = -EIO;
  954. goto free;
  955. }
  956. twl_priv = devm_kzalloc(&client->dev, sizeof(struct twl_private),
  957. GFP_KERNEL);
  958. if (!twl_priv) {
  959. status = -ENOMEM;
  960. goto free;
  961. }
  962. if ((id->driver_data) & TWL6030_CLASS) {
  963. twl_priv->twl_id = TWL6030_CLASS_ID;
  964. twl_priv->twl_map = &twl6030_map[0];
  965. /* The charger base address is different in twl6032 */
  966. if ((id->driver_data) & TWL6032_SUBCLASS)
  967. twl_priv->twl_map[TWL_MODULE_MAIN_CHARGE].base =
  968. TWL6032_BASEADD_CHARGER;
  969. twl_regmap_config = twl6030_regmap_config;
  970. } else {
  971. twl_priv->twl_id = TWL4030_CLASS_ID;
  972. twl_priv->twl_map = &twl4030_map[0];
  973. twl_regmap_config = twl4030_regmap_config;
  974. }
  975. num_slaves = twl_get_num_slaves();
  976. twl_priv->twl_modules = devm_kzalloc(&client->dev,
  977. sizeof(struct twl_client) * num_slaves,
  978. GFP_KERNEL);
  979. if (!twl_priv->twl_modules) {
  980. status = -ENOMEM;
  981. goto free;
  982. }
  983. for (i = 0; i < num_slaves; i++) {
  984. struct twl_client *twl = &twl_priv->twl_modules[i];
  985. if (i == 0) {
  986. twl->client = client;
  987. } else {
  988. twl->client = i2c_new_dummy(client->adapter,
  989. client->addr + i);
  990. if (!twl->client) {
  991. dev_err(&client->dev,
  992. "can't attach client %d\n", i);
  993. status = -ENOMEM;
  994. goto fail;
  995. }
  996. }
  997. twl->regmap = devm_regmap_init_i2c(twl->client,
  998. &twl_regmap_config[i]);
  999. if (IS_ERR(twl->regmap)) {
  1000. status = PTR_ERR(twl->regmap);
  1001. dev_err(&client->dev,
  1002. "Failed to allocate regmap %d, err: %d\n", i,
  1003. status);
  1004. goto fail;
  1005. }
  1006. }
  1007. twl_priv->ready = true;
  1008. /* setup clock framework */
  1009. clocks_init(&pdev->dev, pdata ? pdata->clock : NULL);
  1010. /* read TWL IDCODE Register */
  1011. if (twl_class_is_4030()) {
  1012. status = twl_read_idcode_register();
  1013. WARN(status < 0, "Error: reading twl_idcode register value\n");
  1014. }
  1015. /* Maybe init the T2 Interrupt subsystem */
  1016. if (client->irq) {
  1017. if (twl_class_is_4030()) {
  1018. twl4030_init_chip_irq(id->name);
  1019. irq_base = twl4030_init_irq(&client->dev, client->irq);
  1020. } else {
  1021. irq_base = twl6030_init_irq(&client->dev, client->irq);
  1022. }
  1023. if (irq_base < 0) {
  1024. status = irq_base;
  1025. goto fail;
  1026. }
  1027. }
  1028. /*
  1029. * Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface.
  1030. * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0,
  1031. * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0.
  1032. *
  1033. * Also, always enable SmartReflex bit as that's needed for omaps to
  1034. * to do anything over I2C4 for voltage scaling even if SmartReflex
  1035. * is disabled. Without the SmartReflex bit omap sys_clkreq idle
  1036. * signal will never trigger for retention idle.
  1037. */
  1038. if (twl_class_is_4030()) {
  1039. u8 temp;
  1040. twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1);
  1041. temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \
  1042. I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU);
  1043. twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1);
  1044. twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &temp,
  1045. TWL4030_DCDC_GLOBAL_CFG);
  1046. temp |= SMARTREFLEX_ENABLE;
  1047. twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, temp,
  1048. TWL4030_DCDC_GLOBAL_CFG);
  1049. }
  1050. if (node) {
  1051. if (pdata)
  1052. twl_auxdata_lookup[0].platform_data = pdata->gpio;
  1053. status = of_platform_populate(node, NULL, twl_auxdata_lookup,
  1054. &client->dev);
  1055. } else {
  1056. status = add_children(pdata, irq_base, id->driver_data);
  1057. }
  1058. fail:
  1059. if (status < 0)
  1060. twl_remove(client);
  1061. free:
  1062. if (status < 0)
  1063. platform_device_unregister(pdev);
  1064. return status;
  1065. }
  1066. static const struct i2c_device_id twl_ids[] = {
  1067. { "twl4030", TWL4030_VAUX2 }, /* "Triton 2" */
  1068. { "twl5030", 0 }, /* T2 updated */
  1069. { "twl5031", TWL5031 }, /* TWL5030 updated */
  1070. { "tps65950", 0 }, /* catalog version of twl5030 */
  1071. { "tps65930", TPS_SUBSET }, /* fewer LDOs and DACs; no charger */
  1072. { "tps65920", TPS_SUBSET }, /* fewer LDOs; no codec or charger */
  1073. { "tps65921", TPS_SUBSET }, /* fewer LDOs; no codec, no LED
  1074. and vibrator. Charger in USB module*/
  1075. { "twl6030", TWL6030_CLASS }, /* "Phoenix power chip" */
  1076. { "twl6032", TWL6030_CLASS | TWL6032_SUBCLASS }, /* "Phoenix lite" */
  1077. { /* end of list */ },
  1078. };
  1079. MODULE_DEVICE_TABLE(i2c, twl_ids);
  1080. /* One Client Driver , 4 Clients */
  1081. static struct i2c_driver twl_driver = {
  1082. .driver.name = DRIVER_NAME,
  1083. .id_table = twl_ids,
  1084. .probe = twl_probe,
  1085. .remove = twl_remove,
  1086. };
  1087. module_i2c_driver(twl_driver);
  1088. MODULE_AUTHOR("Texas Instruments, Inc.");
  1089. MODULE_DESCRIPTION("I2C Core interface for TWL");
  1090. MODULE_LICENSE("GPL");