twl-core.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  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 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 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 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. { .supply = "bci3v1" },
  685. };
  686. /* First add the regulators so that they can be used by transceiver */
  687. if (IS_ENABLED(CONFIG_REGULATOR_TWL4030)) {
  688. /* this is a template that gets copied */
  689. struct regulator_init_data usb_fixed = {
  690. .constraints.valid_modes_mask =
  691. REGULATOR_MODE_NORMAL
  692. | REGULATOR_MODE_STANDBY,
  693. .constraints.valid_ops_mask =
  694. REGULATOR_CHANGE_MODE
  695. | REGULATOR_CHANGE_STATUS,
  696. };
  697. child = add_regulator_linked(TWL4030_REG_VUSB1V5,
  698. &usb_fixed, &usb1v5, 1,
  699. features);
  700. if (IS_ERR(child))
  701. return PTR_ERR(child);
  702. child = add_regulator_linked(TWL4030_REG_VUSB1V8,
  703. &usb_fixed, &usb1v8, 1,
  704. features);
  705. if (IS_ERR(child))
  706. return PTR_ERR(child);
  707. child = add_regulator_linked(TWL4030_REG_VUSB3V1,
  708. &usb_fixed, usb3v1, 2,
  709. features);
  710. if (IS_ERR(child))
  711. return PTR_ERR(child);
  712. }
  713. child = add_child(TWL_MODULE_USB, "twl4030_usb",
  714. pdata->usb, sizeof(*pdata->usb), true,
  715. /* irq0 = USB_PRES, irq1 = USB */
  716. irq_base + USB_PRES_INTR_OFFSET,
  717. irq_base + USB_INTR_OFFSET);
  718. if (IS_ERR(child))
  719. return PTR_ERR(child);
  720. /* we need to connect regulators to this transceiver */
  721. if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && child) {
  722. usb1v5.dev_name = dev_name(child);
  723. usb1v8.dev_name = dev_name(child);
  724. usb3v1[0].dev_name = dev_name(child);
  725. }
  726. }
  727. if (IS_ENABLED(CONFIG_TWL4030_WATCHDOG) && twl_class_is_4030()) {
  728. child = add_child(TWL_MODULE_PM_RECEIVER, "twl4030_wdt", NULL,
  729. 0, false, 0, 0);
  730. if (IS_ERR(child))
  731. return PTR_ERR(child);
  732. }
  733. if (IS_ENABLED(CONFIG_INPUT_TWL4030_PWRBUTTON) && twl_class_is_4030()) {
  734. child = add_child(TWL_MODULE_PM_MASTER, "twl4030_pwrbutton",
  735. NULL, 0, true, irq_base + 8 + 0, 0);
  736. if (IS_ERR(child))
  737. return PTR_ERR(child);
  738. }
  739. if (IS_ENABLED(CONFIG_MFD_TWL4030_AUDIO) && pdata->audio &&
  740. twl_class_is_4030()) {
  741. child = add_child(TWL4030_MODULE_AUDIO_VOICE, "twl4030-audio",
  742. pdata->audio, sizeof(*pdata->audio),
  743. false, 0, 0);
  744. if (IS_ERR(child))
  745. return PTR_ERR(child);
  746. }
  747. /* twl4030 regulators */
  748. if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_4030()) {
  749. child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1,
  750. features);
  751. if (IS_ERR(child))
  752. return PTR_ERR(child);
  753. child = add_regulator(TWL4030_REG_VIO, pdata->vio,
  754. features);
  755. if (IS_ERR(child))
  756. return PTR_ERR(child);
  757. child = add_regulator(TWL4030_REG_VDD1, pdata->vdd1,
  758. features);
  759. if (IS_ERR(child))
  760. return PTR_ERR(child);
  761. child = add_regulator(TWL4030_REG_VDD2, pdata->vdd2,
  762. features);
  763. if (IS_ERR(child))
  764. return PTR_ERR(child);
  765. child = add_regulator(TWL4030_REG_VMMC1, pdata->vmmc1,
  766. features);
  767. if (IS_ERR(child))
  768. return PTR_ERR(child);
  769. child = add_regulator(TWL4030_REG_VDAC, pdata->vdac,
  770. features);
  771. if (IS_ERR(child))
  772. return PTR_ERR(child);
  773. child = add_regulator((features & TWL4030_VAUX2)
  774. ? TWL4030_REG_VAUX2_4030
  775. : TWL4030_REG_VAUX2,
  776. pdata->vaux2, features);
  777. if (IS_ERR(child))
  778. return PTR_ERR(child);
  779. child = add_regulator(TWL4030_REG_VINTANA1, pdata->vintana1,
  780. features);
  781. if (IS_ERR(child))
  782. return PTR_ERR(child);
  783. child = add_regulator(TWL4030_REG_VINTANA2, pdata->vintana2,
  784. features);
  785. if (IS_ERR(child))
  786. return PTR_ERR(child);
  787. child = add_regulator(TWL4030_REG_VINTDIG, pdata->vintdig,
  788. features);
  789. if (IS_ERR(child))
  790. return PTR_ERR(child);
  791. }
  792. /* maybe add LDOs that are omitted on cost-reduced parts */
  793. if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && !(features & TPS_SUBSET)
  794. && twl_class_is_4030()) {
  795. child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2,
  796. features);
  797. if (IS_ERR(child))
  798. return PTR_ERR(child);
  799. child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2,
  800. features);
  801. if (IS_ERR(child))
  802. return PTR_ERR(child);
  803. child = add_regulator(TWL4030_REG_VSIM, pdata->vsim,
  804. features);
  805. if (IS_ERR(child))
  806. return PTR_ERR(child);
  807. child = add_regulator(TWL4030_REG_VAUX1, pdata->vaux1,
  808. features);
  809. if (IS_ERR(child))
  810. return PTR_ERR(child);
  811. child = add_regulator(TWL4030_REG_VAUX3, pdata->vaux3,
  812. features);
  813. if (IS_ERR(child))
  814. return PTR_ERR(child);
  815. child = add_regulator(TWL4030_REG_VAUX4, pdata->vaux4,
  816. features);
  817. if (IS_ERR(child))
  818. return PTR_ERR(child);
  819. }
  820. if (IS_ENABLED(CONFIG_CHARGER_TWL4030) && pdata->bci &&
  821. !(features & (TPS_SUBSET | TWL5031))) {
  822. child = add_child(TWL_MODULE_MAIN_CHARGE, "twl4030_bci",
  823. pdata->bci, sizeof(*pdata->bci), false,
  824. /* irq0 = CHG_PRES, irq1 = BCI */
  825. irq_base + BCI_PRES_INTR_OFFSET,
  826. irq_base + BCI_INTR_OFFSET);
  827. if (IS_ERR(child))
  828. return PTR_ERR(child);
  829. }
  830. if (IS_ENABLED(CONFIG_TWL4030_POWER) && pdata->power) {
  831. child = add_child(TWL_MODULE_PM_MASTER, "twl4030_power",
  832. pdata->power, sizeof(*pdata->power), false,
  833. 0, 0);
  834. if (IS_ERR(child))
  835. return PTR_ERR(child);
  836. }
  837. return 0;
  838. }
  839. /*----------------------------------------------------------------------*/
  840. /*
  841. * These three functions initialize the on-chip clock framework,
  842. * letting it generate the right frequencies for USB, MADC, and
  843. * other purposes.
  844. */
  845. static inline int __init protect_pm_master(void)
  846. {
  847. int e = 0;
  848. e = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 0,
  849. TWL4030_PM_MASTER_PROTECT_KEY);
  850. return e;
  851. }
  852. static inline int __init unprotect_pm_master(void)
  853. {
  854. int e = 0;
  855. e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1,
  856. TWL4030_PM_MASTER_PROTECT_KEY);
  857. e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG2,
  858. TWL4030_PM_MASTER_PROTECT_KEY);
  859. return e;
  860. }
  861. static void clocks_init(struct device *dev,
  862. struct twl4030_clock_init_data *clock)
  863. {
  864. int e = 0;
  865. struct clk *osc;
  866. u32 rate;
  867. u8 ctrl = HFCLK_FREQ_26_MHZ;
  868. osc = clk_get(dev, "fck");
  869. if (IS_ERR(osc)) {
  870. printk(KERN_WARNING "Skipping twl internal clock init and "
  871. "using bootloader value (unknown osc rate)\n");
  872. return;
  873. }
  874. rate = clk_get_rate(osc);
  875. clk_put(osc);
  876. switch (rate) {
  877. case 19200000:
  878. ctrl = HFCLK_FREQ_19p2_MHZ;
  879. break;
  880. case 26000000:
  881. ctrl = HFCLK_FREQ_26_MHZ;
  882. break;
  883. case 38400000:
  884. ctrl = HFCLK_FREQ_38p4_MHZ;
  885. break;
  886. }
  887. ctrl |= HIGH_PERF_SQ;
  888. if (clock && clock->ck32k_lowpwr_enable)
  889. ctrl |= CK32K_LOWPWR_EN;
  890. e |= unprotect_pm_master();
  891. /* effect->MADC+USB ck en */
  892. e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, ctrl, R_CFG_BOOT);
  893. e |= protect_pm_master();
  894. if (e < 0)
  895. pr_err("%s: clock init err [%d]\n", DRIVER_NAME, e);
  896. }
  897. /*----------------------------------------------------------------------*/
  898. static int twl_remove(struct i2c_client *client)
  899. {
  900. unsigned i, num_slaves;
  901. int status;
  902. if (twl_class_is_4030())
  903. status = twl4030_exit_irq();
  904. else
  905. status = twl6030_exit_irq();
  906. if (status < 0)
  907. return status;
  908. num_slaves = twl_get_num_slaves();
  909. for (i = 0; i < num_slaves; i++) {
  910. struct twl_client *twl = &twl_priv->twl_modules[i];
  911. if (twl->client && twl->client != client)
  912. i2c_unregister_device(twl->client);
  913. twl->client = NULL;
  914. }
  915. twl_priv->ready = false;
  916. return 0;
  917. }
  918. static struct of_dev_auxdata twl_auxdata_lookup[] = {
  919. OF_DEV_AUXDATA("ti,twl4030-gpio", 0, "twl4030-gpio", NULL),
  920. { /* sentinel */ },
  921. };
  922. /* NOTE: This driver only handles a single twl4030/tps659x0 chip */
  923. static int
  924. twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
  925. {
  926. struct twl4030_platform_data *pdata = dev_get_platdata(&client->dev);
  927. struct device_node *node = client->dev.of_node;
  928. struct platform_device *pdev;
  929. struct regmap_config *twl_regmap_config;
  930. int irq_base = 0;
  931. int status;
  932. unsigned i, num_slaves;
  933. if (!node && !pdata) {
  934. dev_err(&client->dev, "no platform data\n");
  935. return -EINVAL;
  936. }
  937. if (twl_priv) {
  938. dev_dbg(&client->dev, "only one instance of %s allowed\n",
  939. DRIVER_NAME);
  940. return -EBUSY;
  941. }
  942. pdev = platform_device_alloc(DRIVER_NAME, -1);
  943. if (!pdev) {
  944. dev_err(&client->dev, "can't alloc pdev\n");
  945. return -ENOMEM;
  946. }
  947. status = platform_device_add(pdev);
  948. if (status) {
  949. platform_device_put(pdev);
  950. return status;
  951. }
  952. if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
  953. dev_dbg(&client->dev, "can't talk I2C?\n");
  954. status = -EIO;
  955. goto free;
  956. }
  957. twl_priv = devm_kzalloc(&client->dev, sizeof(struct twl_private),
  958. GFP_KERNEL);
  959. if (!twl_priv) {
  960. status = -ENOMEM;
  961. goto free;
  962. }
  963. if ((id->driver_data) & TWL6030_CLASS) {
  964. twl_priv->twl_id = TWL6030_CLASS_ID;
  965. twl_priv->twl_map = &twl6030_map[0];
  966. /* The charger base address is different in twl6032 */
  967. if ((id->driver_data) & TWL6032_SUBCLASS)
  968. twl_priv->twl_map[TWL_MODULE_MAIN_CHARGE].base =
  969. TWL6032_BASEADD_CHARGER;
  970. twl_regmap_config = twl6030_regmap_config;
  971. } else {
  972. twl_priv->twl_id = TWL4030_CLASS_ID;
  973. twl_priv->twl_map = &twl4030_map[0];
  974. twl_regmap_config = twl4030_regmap_config;
  975. }
  976. num_slaves = twl_get_num_slaves();
  977. twl_priv->twl_modules = devm_kzalloc(&client->dev,
  978. sizeof(struct twl_client) * num_slaves,
  979. GFP_KERNEL);
  980. if (!twl_priv->twl_modules) {
  981. status = -ENOMEM;
  982. goto free;
  983. }
  984. for (i = 0; i < num_slaves; i++) {
  985. struct twl_client *twl = &twl_priv->twl_modules[i];
  986. if (i == 0) {
  987. twl->client = client;
  988. } else {
  989. twl->client = i2c_new_dummy(client->adapter,
  990. client->addr + i);
  991. if (!twl->client) {
  992. dev_err(&client->dev,
  993. "can't attach client %d\n", i);
  994. status = -ENOMEM;
  995. goto fail;
  996. }
  997. }
  998. twl->regmap = devm_regmap_init_i2c(twl->client,
  999. &twl_regmap_config[i]);
  1000. if (IS_ERR(twl->regmap)) {
  1001. status = PTR_ERR(twl->regmap);
  1002. dev_err(&client->dev,
  1003. "Failed to allocate regmap %d, err: %d\n", i,
  1004. status);
  1005. goto fail;
  1006. }
  1007. }
  1008. twl_priv->ready = true;
  1009. /* setup clock framework */
  1010. clocks_init(&pdev->dev, pdata ? pdata->clock : NULL);
  1011. /* read TWL IDCODE Register */
  1012. if (twl_class_is_4030()) {
  1013. status = twl_read_idcode_register();
  1014. WARN(status < 0, "Error: reading twl_idcode register value\n");
  1015. }
  1016. /* Maybe init the T2 Interrupt subsystem */
  1017. if (client->irq) {
  1018. if (twl_class_is_4030()) {
  1019. twl4030_init_chip_irq(id->name);
  1020. irq_base = twl4030_init_irq(&client->dev, client->irq);
  1021. } else {
  1022. irq_base = twl6030_init_irq(&client->dev, client->irq);
  1023. }
  1024. if (irq_base < 0) {
  1025. status = irq_base;
  1026. goto fail;
  1027. }
  1028. }
  1029. /*
  1030. * Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface.
  1031. * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0,
  1032. * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0.
  1033. *
  1034. * Also, always enable SmartReflex bit as that's needed for omaps to
  1035. * to do anything over I2C4 for voltage scaling even if SmartReflex
  1036. * is disabled. Without the SmartReflex bit omap sys_clkreq idle
  1037. * signal will never trigger for retention idle.
  1038. */
  1039. if (twl_class_is_4030()) {
  1040. u8 temp;
  1041. twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1);
  1042. temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \
  1043. I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU);
  1044. twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1);
  1045. twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &temp,
  1046. TWL4030_DCDC_GLOBAL_CFG);
  1047. temp |= SMARTREFLEX_ENABLE;
  1048. twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, temp,
  1049. TWL4030_DCDC_GLOBAL_CFG);
  1050. }
  1051. if (node) {
  1052. if (pdata)
  1053. twl_auxdata_lookup[0].platform_data = pdata->gpio;
  1054. status = of_platform_populate(node, NULL, twl_auxdata_lookup,
  1055. &client->dev);
  1056. } else {
  1057. status = add_children(pdata, irq_base, id->driver_data);
  1058. }
  1059. fail:
  1060. if (status < 0)
  1061. twl_remove(client);
  1062. free:
  1063. if (status < 0)
  1064. platform_device_unregister(pdev);
  1065. return status;
  1066. }
  1067. static const struct i2c_device_id twl_ids[] = {
  1068. { "twl4030", TWL4030_VAUX2 }, /* "Triton 2" */
  1069. { "twl5030", 0 }, /* T2 updated */
  1070. { "twl5031", TWL5031 }, /* TWL5030 updated */
  1071. { "tps65950", 0 }, /* catalog version of twl5030 */
  1072. { "tps65930", TPS_SUBSET }, /* fewer LDOs and DACs; no charger */
  1073. { "tps65920", TPS_SUBSET }, /* fewer LDOs; no codec or charger */
  1074. { "tps65921", TPS_SUBSET }, /* fewer LDOs; no codec, no LED
  1075. and vibrator. Charger in USB module*/
  1076. { "twl6030", TWL6030_CLASS }, /* "Phoenix power chip" */
  1077. { "twl6032", TWL6030_CLASS | TWL6032_SUBCLASS }, /* "Phoenix lite" */
  1078. { /* end of list */ },
  1079. };
  1080. MODULE_DEVICE_TABLE(i2c, twl_ids);
  1081. /* One Client Driver , 4 Clients */
  1082. static struct i2c_driver twl_driver = {
  1083. .driver.name = DRIVER_NAME,
  1084. .id_table = twl_ids,
  1085. .probe = twl_probe,
  1086. .remove = twl_remove,
  1087. };
  1088. module_i2c_driver(twl_driver);
  1089. MODULE_AUTHOR("Texas Instruments, Inc.");
  1090. MODULE_DESCRIPTION("I2C Core interface for TWL");
  1091. MODULE_LICENSE("GPL");