mach-crag6410-module.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* Speyside modules for Cragganmore - board data probing
  2. *
  3. * Copyright 2011 Wolfson Microelectronics plc
  4. * Mark Brown <broonie@opensource.wolfsonmicro.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/export.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/i2c.h>
  13. #include <linux/spi/spi.h>
  14. #include <linux/mfd/wm831x/irq.h>
  15. #include <linux/mfd/wm831x/gpio.h>
  16. #include <linux/mfd/wm8994/pdata.h>
  17. #include <linux/regulator/machine.h>
  18. #include <sound/wm5100.h>
  19. #include <sound/wm8996.h>
  20. #include <sound/wm8962.h>
  21. #include <sound/wm9081.h>
  22. #include <plat/s3c64xx-spi.h>
  23. #include <mach/crag6410.h>
  24. static struct s3c64xx_spi_csinfo wm0010_spi_csinfo = {
  25. .set_level = gpio_set_value,
  26. .line = S3C64XX_GPC(3),
  27. };
  28. static struct spi_board_info wm1253_devs[] = {
  29. [0] = {
  30. .modalias = "wm0010",
  31. .bus_num = 0,
  32. .chip_select = 0,
  33. .mode = SPI_MODE_0,
  34. .controller_data = &wm0010_spi_csinfo,
  35. },
  36. };
  37. static struct wm5100_pdata wm5100_pdata = {
  38. .ldo_ena = S3C64XX_GPN(7),
  39. .irq_flags = IRQF_TRIGGER_HIGH,
  40. .gpio_base = CODEC_GPIO_BASE,
  41. .in_mode = {
  42. WM5100_IN_DIFF,
  43. WM5100_IN_DIFF,
  44. WM5100_IN_DIFF,
  45. WM5100_IN_SE,
  46. },
  47. .hp_pol = CODEC_GPIO_BASE + 3,
  48. .jack_modes = {
  49. { WM5100_MICDET_MICBIAS3, 0, 0 },
  50. { WM5100_MICDET_MICBIAS2, 1, 1 },
  51. },
  52. .gpio_defaults = {
  53. 0,
  54. 0,
  55. 0,
  56. 0,
  57. 0x2, /* IRQ: CMOS output */
  58. 0x3, /* CLKOUT: CMOS output */
  59. },
  60. };
  61. static struct wm8996_retune_mobile_config wm8996_retune[] = {
  62. {
  63. .name = "Sub LPF",
  64. .rate = 48000,
  65. .regs = {
  66. 0x6318, 0x6300, 0x1000, 0x0000, 0x0004, 0x2000, 0xF000,
  67. 0x0000, 0x0004, 0x2000, 0xF000, 0x0000, 0x0004, 0x2000,
  68. 0xF000, 0x0000, 0x0004, 0x1000, 0x0800, 0x4000
  69. },
  70. },
  71. {
  72. .name = "Sub HPF",
  73. .rate = 48000,
  74. .regs = {
  75. 0x000A, 0x6300, 0x1000, 0x0000, 0x0004, 0x2000, 0xF000,
  76. 0x0000, 0x0004, 0x2000, 0xF000, 0x0000, 0x0004, 0x2000,
  77. 0xF000, 0x0000, 0x0004, 0x1000, 0x0800, 0x4000
  78. },
  79. },
  80. };
  81. static struct wm8996_pdata wm8996_pdata __initdata = {
  82. .ldo_ena = S3C64XX_GPN(7),
  83. .gpio_base = CODEC_GPIO_BASE,
  84. .micdet_def = 1,
  85. .inl_mode = WM8996_DIFFERRENTIAL_1,
  86. .inr_mode = WM8996_DIFFERRENTIAL_1,
  87. .irq_flags = IRQF_TRIGGER_RISING,
  88. .gpio_default = {
  89. 0x8001, /* GPIO1 == ADCLRCLK1 */
  90. 0x8001, /* GPIO2 == ADCLRCLK2, input due to CPU */
  91. 0x0141, /* GPIO3 == HP_SEL */
  92. 0x0002, /* GPIO4 == IRQ */
  93. 0x020e, /* GPIO5 == CLKOUT */
  94. },
  95. .retune_mobile_cfgs = wm8996_retune,
  96. .num_retune_mobile_cfgs = ARRAY_SIZE(wm8996_retune),
  97. };
  98. static struct wm8962_pdata wm8962_pdata __initdata = {
  99. .gpio_init = {
  100. 0,
  101. WM8962_GPIO_FN_OPCLK,
  102. WM8962_GPIO_FN_DMICCLK,
  103. 0,
  104. 0x8000 | WM8962_GPIO_FN_DMICDAT,
  105. WM8962_GPIO_FN_IRQ, /* Open drain mode */
  106. },
  107. .in4_dc_measure = true,
  108. };
  109. static struct wm9081_pdata wm9081_pdata __initdata = {
  110. .irq_high = false,
  111. .irq_cmos = false,
  112. };
  113. static const struct i2c_board_info wm1254_devs[] = {
  114. { I2C_BOARD_INFO("wm8996", 0x1a),
  115. .platform_data = &wm8996_pdata,
  116. .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
  117. },
  118. { I2C_BOARD_INFO("wm9081", 0x6c),
  119. .platform_data = &wm9081_pdata, },
  120. };
  121. static const struct i2c_board_info wm1255_devs[] = {
  122. { I2C_BOARD_INFO("wm5100", 0x1a),
  123. .platform_data = &wm5100_pdata,
  124. .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
  125. },
  126. { I2C_BOARD_INFO("wm9081", 0x6c),
  127. .platform_data = &wm9081_pdata, },
  128. };
  129. static const struct i2c_board_info wm1259_devs[] = {
  130. { I2C_BOARD_INFO("wm8962", 0x1a),
  131. .platform_data = &wm8962_pdata,
  132. .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
  133. },
  134. };
  135. static struct regulator_init_data wm8994_ldo1 = {
  136. .supply_regulator = "WALLVDD",
  137. };
  138. static struct regulator_init_data wm8994_ldo2 = {
  139. .supply_regulator = "WALLVDD",
  140. };
  141. static struct wm8994_pdata wm8994_pdata = {
  142. .gpio_base = CODEC_GPIO_BASE,
  143. .gpio_defaults = {
  144. 0x3, /* IRQ out, active high, CMOS */
  145. },
  146. .irq_base = CODEC_IRQ_BASE,
  147. .ldo = {
  148. { .init_data = &wm8994_ldo1, },
  149. { .init_data = &wm8994_ldo2, },
  150. },
  151. };
  152. static const struct i2c_board_info wm1277_devs[] = {
  153. { I2C_BOARD_INFO("wm8958", 0x1a), /* WM8958 is the superset */
  154. .platform_data = &wm8994_pdata,
  155. .irq = GLENFARCLAS_PMIC_IRQ_BASE + WM831X_IRQ_GPIO_2,
  156. },
  157. };
  158. static __devinitdata const struct {
  159. u8 id;
  160. const char *name;
  161. const struct i2c_board_info *i2c_devs;
  162. int num_i2c_devs;
  163. const struct spi_board_info *spi_devs;
  164. int num_spi_devs;
  165. } gf_mods[] = {
  166. { .id = 0x01, .name = "1250-EV1 Springbank" },
  167. { .id = 0x02, .name = "1251-EV1 Jura" },
  168. { .id = 0x03, .name = "1252-EV1 Glenlivet" },
  169. { .id = 0x11, .name = "6249-EV2 Glenfarclas", },
  170. { .id = 0x14, .name = "6271-EV1 Lochnagar" },
  171. { .id = 0x15, .name = "XXXX-EV1 Bells" },
  172. { .id = 0x21, .name = "1275-EV1 Mortlach" },
  173. { .id = 0x25, .name = "1274-EV1 Glencadam" },
  174. { .id = 0x31, .name = "1253-EV1 Tomatin",
  175. .spi_devs = wm1253_devs, .num_spi_devs = ARRAY_SIZE(wm1253_devs) },
  176. { .id = 0x32, .name = "XXXX-EV1 Caol Illa" },
  177. { .id = 0x33, .name = "XXXX-EV1 Oban" },
  178. { .id = 0x39, .name = "1254-EV1 Dallas Dhu",
  179. .i2c_devs = wm1254_devs, .num_i2c_devs = ARRAY_SIZE(wm1254_devs) },
  180. { .id = 0x3a, .name = "1259-EV1 Tobermory",
  181. .i2c_devs = wm1259_devs, .num_i2c_devs = ARRAY_SIZE(wm1259_devs) },
  182. { .id = 0x3b, .name = "1255-EV1 Kilchoman",
  183. .i2c_devs = wm1255_devs, .num_i2c_devs = ARRAY_SIZE(wm1255_devs) },
  184. { .id = 0x3c, .name = "1273-EV1 Longmorn" },
  185. { .id = 0x3d, .name = "1277-EV1 Littlemill",
  186. .i2c_devs = wm1277_devs, .num_i2c_devs = ARRAY_SIZE(wm1277_devs) },
  187. };
  188. static __devinit int wlf_gf_module_probe(struct i2c_client *i2c,
  189. const struct i2c_device_id *i2c_id)
  190. {
  191. int ret, i, j, id, rev;
  192. ret = i2c_smbus_read_byte_data(i2c, 0);
  193. if (ret < 0) {
  194. dev_err(&i2c->dev, "Failed to read ID: %d\n", ret);
  195. return ret;
  196. }
  197. id = (ret & 0xfe) >> 2;
  198. rev = ret & 0x3;
  199. for (i = 0; i < ARRAY_SIZE(gf_mods); i++)
  200. if (id == gf_mods[i].id)
  201. break;
  202. if (i < ARRAY_SIZE(gf_mods)) {
  203. dev_info(&i2c->dev, "%s revision %d\n",
  204. gf_mods[i].name, rev + 1);
  205. for (j = 0; j < gf_mods[i].num_i2c_devs; j++) {
  206. if (!i2c_new_device(i2c->adapter,
  207. &(gf_mods[i].i2c_devs[j])))
  208. dev_err(&i2c->dev,
  209. "Failed to register dev: %d\n", ret);
  210. }
  211. spi_register_board_info(gf_mods[i].spi_devs,
  212. gf_mods[i].num_spi_devs);
  213. } else {
  214. dev_warn(&i2c->dev, "Unknown module ID 0x%x revision %d\n",
  215. id, rev + 1);
  216. }
  217. return 0;
  218. }
  219. static const struct i2c_device_id wlf_gf_module_id[] = {
  220. { "wlf-gf-module", 0 },
  221. { }
  222. };
  223. static struct i2c_driver wlf_gf_module_driver = {
  224. .driver = {
  225. .name = "wlf-gf-module",
  226. .owner = THIS_MODULE,
  227. },
  228. .probe = wlf_gf_module_probe,
  229. .id_table = wlf_gf_module_id,
  230. };
  231. static int __init wlf_gf_module_register(void)
  232. {
  233. return i2c_add_driver(&wlf_gf_module_driver);
  234. }
  235. module_init(wlf_gf_module_register);