hdmiphy_drv.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * Samsung HDMI Physical interface driver
  3. *
  4. * Copyright (C) 2010-2011 Samsung Electronics Co.Ltd
  5. * Author: Tomasz Stanislawski <t.stanislaws@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/i2c.h>
  14. #include <linux/slab.h>
  15. #include <linux/clk.h>
  16. #include <linux/io.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/irq.h>
  19. #include <linux/err.h>
  20. #include <media/v4l2-subdev.h>
  21. MODULE_AUTHOR("Tomasz Stanislawski <t.stanislaws@samsung.com>");
  22. MODULE_DESCRIPTION("Samsung HDMI Physical interface driver");
  23. MODULE_LICENSE("GPL");
  24. struct hdmiphy_conf {
  25. unsigned long pixclk;
  26. const u8 *data;
  27. };
  28. struct hdmiphy_ctx {
  29. struct v4l2_subdev sd;
  30. const struct hdmiphy_conf *conf_tab;
  31. };
  32. static const struct hdmiphy_conf hdmiphy_conf_s5pv210[] = {
  33. { .pixclk = 27000000, .data = (u8 [32]) {
  34. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  35. 0x6B, 0x10, 0x02, 0x52, 0xDF, 0xF2, 0x54, 0x87,
  36. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  37. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00, }
  38. },
  39. { .pixclk = 27027000, .data = (u8 [32]) {
  40. 0x01, 0x05, 0x00, 0xD4, 0x10, 0x9C, 0x09, 0x64,
  41. 0x6B, 0x10, 0x02, 0x52, 0xDF, 0xF2, 0x54, 0x87,
  42. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  43. 0x22, 0x40, 0xE2, 0x26, 0x00, 0x00, 0x00, 0x00, }
  44. },
  45. { .pixclk = 74176000, .data = (u8 [32]) {
  46. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xEF, 0x5B,
  47. 0x6D, 0x10, 0x01, 0x52, 0xEF, 0xF3, 0x54, 0xB9,
  48. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  49. 0x22, 0x40, 0xA5, 0x26, 0x01, 0x00, 0x00, 0x00, }
  50. },
  51. { .pixclk = 74250000, .data = (u8 [32]) {
  52. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xF8, 0x40,
  53. 0x6A, 0x10, 0x01, 0x52, 0xFF, 0xF1, 0x54, 0xBA,
  54. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  55. 0x22, 0x40, 0xA4, 0x26, 0x01, 0x00, 0x00, 0x00, }
  56. },
  57. { /* end marker */ }
  58. };
  59. static const struct hdmiphy_conf hdmiphy_conf_exynos4210[] = {
  60. { .pixclk = 27000000, .data = (u8 [32]) {
  61. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  62. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  63. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  64. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00, }
  65. },
  66. { .pixclk = 27027000, .data = (u8 [32]) {
  67. 0x01, 0x05, 0x00, 0xD4, 0x10, 0x9C, 0x09, 0x64,
  68. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  69. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  70. 0x22, 0x40, 0xE2, 0x26, 0x00, 0x00, 0x00, 0x00, }
  71. },
  72. { .pixclk = 74176000, .data = (u8 [32]) {
  73. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xEF, 0x5B,
  74. 0x6D, 0x10, 0x01, 0x51, 0xEF, 0xF3, 0x54, 0xB9,
  75. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  76. 0x22, 0x40, 0xA5, 0x26, 0x01, 0x00, 0x00, 0x00, }
  77. },
  78. { .pixclk = 74250000, .data = (u8 [32]) {
  79. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xF8, 0x40,
  80. 0x6A, 0x10, 0x01, 0x51, 0xFF, 0xF1, 0x54, 0xBA,
  81. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  82. 0x22, 0x40, 0xA4, 0x26, 0x01, 0x00, 0x00, 0x00, }
  83. },
  84. { .pixclk = 148352000, .data = (u8 [32]) {
  85. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xEF, 0x5B,
  86. 0x6D, 0x18, 0x00, 0x51, 0xEF, 0xF3, 0x54, 0xB9,
  87. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  88. 0x11, 0x40, 0xA5, 0x26, 0x02, 0x00, 0x00, 0x00, }
  89. },
  90. { .pixclk = 148500000, .data = (u8 [32]) {
  91. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xF8, 0x40,
  92. 0x6A, 0x18, 0x00, 0x51, 0xFF, 0xF1, 0x54, 0xBA,
  93. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  94. 0x11, 0x40, 0xA4, 0x26, 0x02, 0x00, 0x00, 0x00, }
  95. },
  96. { /* end marker */ }
  97. };
  98. static const struct hdmiphy_conf hdmiphy_conf_exynos4212[] = {
  99. { .pixclk = 27000000, .data = (u8 [32]) {
  100. 0x01, 0x11, 0x2D, 0x75, 0x00, 0x01, 0x00, 0x08,
  101. 0x82, 0x00, 0x0E, 0xD9, 0x45, 0xA0, 0x34, 0xC0,
  102. 0x0B, 0x80, 0x12, 0x87, 0x08, 0x24, 0x24, 0x71,
  103. 0x54, 0xE3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, }
  104. },
  105. { .pixclk = 27027000, .data = (u8 [32]) {
  106. 0x01, 0x91, 0x2D, 0x72, 0x00, 0x64, 0x12, 0x08,
  107. 0x43, 0x20, 0x0E, 0xD9, 0x45, 0xA0, 0x34, 0xC0,
  108. 0x0B, 0x80, 0x12, 0x87, 0x08, 0x24, 0x24, 0x71,
  109. 0x54, 0xE2, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, }
  110. },
  111. { .pixclk = 74176000, .data = (u8 [32]) {
  112. 0x01, 0x91, 0x3E, 0x35, 0x00, 0x5B, 0xDE, 0x08,
  113. 0x82, 0x20, 0x73, 0xD9, 0x45, 0xA0, 0x34, 0xC0,
  114. 0x0B, 0x80, 0x12, 0x87, 0x08, 0x24, 0x24, 0x52,
  115. 0x54, 0xA5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00, }
  116. },
  117. { .pixclk = 74250000, .data = (u8 [32]) {
  118. 0x01, 0x91, 0x3E, 0x35, 0x00, 0x40, 0xF0, 0x08,
  119. 0x82, 0x20, 0x73, 0xD9, 0x45, 0xA0, 0x34, 0xC0,
  120. 0x0B, 0x80, 0x12, 0x87, 0x08, 0x24, 0x24, 0x52,
  121. 0x54, 0xA4, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00, }
  122. },
  123. { .pixclk = 148500000, .data = (u8 [32]) {
  124. 0x01, 0x91, 0x3E, 0x15, 0x00, 0x40, 0xF0, 0x08,
  125. 0x82, 0x20, 0x73, 0xD9, 0x45, 0xA0, 0x34, 0xC0,
  126. 0x0B, 0x80, 0x12, 0x87, 0x08, 0x24, 0x24, 0xA4,
  127. 0x54, 0x4A, 0x25, 0x03, 0x00, 0x00, 0x01, 0x00, }
  128. },
  129. { /* end marker */ }
  130. };
  131. static const struct hdmiphy_conf hdmiphy_conf_exynos4412[] = {
  132. { .pixclk = 27000000, .data = (u8 [32]) {
  133. 0x01, 0x11, 0x2D, 0x75, 0x40, 0x01, 0x00, 0x08,
  134. 0x82, 0x00, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  135. 0x08, 0x80, 0x11, 0x84, 0x02, 0x22, 0x44, 0x86,
  136. 0x54, 0xE4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, }
  137. },
  138. { .pixclk = 27027000, .data = (u8 [32]) {
  139. 0x01, 0x91, 0x2D, 0x72, 0x40, 0x64, 0x12, 0x08,
  140. 0x43, 0x20, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  141. 0x08, 0x80, 0x11, 0x84, 0x02, 0x22, 0x44, 0x86,
  142. 0x54, 0xE3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, }
  143. },
  144. { .pixclk = 74176000, .data = (u8 [32]) {
  145. 0x01, 0x91, 0x1F, 0x10, 0x40, 0x5B, 0xEF, 0x08,
  146. 0x81, 0x20, 0xB9, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  147. 0x08, 0x80, 0x11, 0x84, 0x02, 0x22, 0x44, 0x86,
  148. 0x54, 0xA6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00, }
  149. },
  150. { .pixclk = 74250000, .data = (u8 [32]) {
  151. 0x01, 0x91, 0x1F, 0x10, 0x40, 0x40, 0xF8, 0x08,
  152. 0x81, 0x20, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  153. 0x08, 0x80, 0x11, 0x84, 0x02, 0x22, 0x44, 0x86,
  154. 0x54, 0xA5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00, }
  155. },
  156. { .pixclk = 148500000, .data = (u8 [32]) {
  157. 0x01, 0x91, 0x1F, 0x00, 0x40, 0x40, 0xF8, 0x08,
  158. 0x81, 0x20, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  159. 0x08, 0x80, 0x11, 0x84, 0x02, 0x22, 0x44, 0x86,
  160. 0x54, 0x4B, 0x25, 0x03, 0x00, 0x00, 0x01, 0x00, }
  161. },
  162. { /* end marker */ }
  163. };
  164. static inline struct hdmiphy_ctx *sd_to_ctx(struct v4l2_subdev *sd)
  165. {
  166. return container_of(sd, struct hdmiphy_ctx, sd);
  167. }
  168. static const u8 *hdmiphy_find_conf(unsigned long pixclk,
  169. const struct hdmiphy_conf *conf)
  170. {
  171. for (; conf->pixclk; ++conf)
  172. if (conf->pixclk == pixclk)
  173. return conf->data;
  174. return NULL;
  175. }
  176. static int hdmiphy_s_power(struct v4l2_subdev *sd, int on)
  177. {
  178. /* to be implemented */
  179. return 0;
  180. }
  181. static int hdmiphy_s_dv_timings(struct v4l2_subdev *sd,
  182. struct v4l2_dv_timings *timings)
  183. {
  184. const u8 *data;
  185. u8 buffer[32];
  186. int ret;
  187. struct hdmiphy_ctx *ctx = sd_to_ctx(sd);
  188. struct i2c_client *client = v4l2_get_subdevdata(sd);
  189. struct device *dev = &client->dev;
  190. unsigned long pixclk = timings->bt.pixelclock;
  191. dev_info(dev, "s_dv_timings\n");
  192. if ((timings->bt.flags & V4L2_DV_FL_REDUCED_FPS) && pixclk == 74250000)
  193. pixclk = 74176000;
  194. data = hdmiphy_find_conf(pixclk, ctx->conf_tab);
  195. if (!data) {
  196. dev_err(dev, "format not supported\n");
  197. return -EINVAL;
  198. }
  199. /* storing configuration to the device */
  200. memcpy(buffer, data, 32);
  201. ret = i2c_master_send(client, buffer, 32);
  202. if (ret != 32) {
  203. dev_err(dev, "failed to configure HDMIPHY via I2C\n");
  204. return -EIO;
  205. }
  206. return 0;
  207. }
  208. static int hdmiphy_dv_timings_cap(struct v4l2_subdev *sd,
  209. struct v4l2_dv_timings_cap *cap)
  210. {
  211. if (cap->pad != 0)
  212. return -EINVAL;
  213. cap->type = V4L2_DV_BT_656_1120;
  214. /* The phy only determines the pixelclock, leave the other values
  215. * at 0 to signify that we have no information for them. */
  216. cap->bt.min_pixelclock = 27000000;
  217. cap->bt.max_pixelclock = 148500000;
  218. return 0;
  219. }
  220. static int hdmiphy_s_stream(struct v4l2_subdev *sd, int enable)
  221. {
  222. struct i2c_client *client = v4l2_get_subdevdata(sd);
  223. struct device *dev = &client->dev;
  224. u8 buffer[2];
  225. int ret;
  226. dev_info(dev, "s_stream(%d)\n", enable);
  227. /* going to/from configuration from/to operation mode */
  228. buffer[0] = 0x1f;
  229. buffer[1] = enable ? 0x80 : 0x00;
  230. ret = i2c_master_send(client, buffer, 2);
  231. if (ret != 2) {
  232. dev_err(dev, "stream (%d) failed\n", enable);
  233. return -EIO;
  234. }
  235. return 0;
  236. }
  237. static const struct v4l2_subdev_core_ops hdmiphy_core_ops = {
  238. .s_power = hdmiphy_s_power,
  239. };
  240. static const struct v4l2_subdev_video_ops hdmiphy_video_ops = {
  241. .s_dv_timings = hdmiphy_s_dv_timings,
  242. .s_stream = hdmiphy_s_stream,
  243. };
  244. static const struct v4l2_subdev_pad_ops hdmiphy_pad_ops = {
  245. .dv_timings_cap = hdmiphy_dv_timings_cap,
  246. };
  247. static const struct v4l2_subdev_ops hdmiphy_ops = {
  248. .core = &hdmiphy_core_ops,
  249. .video = &hdmiphy_video_ops,
  250. .pad = &hdmiphy_pad_ops,
  251. };
  252. static int hdmiphy_probe(struct i2c_client *client,
  253. const struct i2c_device_id *id)
  254. {
  255. struct hdmiphy_ctx *ctx;
  256. ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
  257. if (!ctx)
  258. return -ENOMEM;
  259. ctx->conf_tab = (struct hdmiphy_conf *)id->driver_data;
  260. v4l2_i2c_subdev_init(&ctx->sd, client, &hdmiphy_ops);
  261. dev_info(&client->dev, "probe successful\n");
  262. return 0;
  263. }
  264. static int hdmiphy_remove(struct i2c_client *client)
  265. {
  266. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  267. struct hdmiphy_ctx *ctx = sd_to_ctx(sd);
  268. kfree(ctx);
  269. dev_info(&client->dev, "remove successful\n");
  270. return 0;
  271. }
  272. static const struct i2c_device_id hdmiphy_id[] = {
  273. { "hdmiphy", (unsigned long)hdmiphy_conf_exynos4210 },
  274. { "hdmiphy-s5pv210", (unsigned long)hdmiphy_conf_s5pv210 },
  275. { "hdmiphy-exynos4210", (unsigned long)hdmiphy_conf_exynos4210 },
  276. { "hdmiphy-exynos4212", (unsigned long)hdmiphy_conf_exynos4212 },
  277. { "hdmiphy-exynos4412", (unsigned long)hdmiphy_conf_exynos4412 },
  278. { },
  279. };
  280. MODULE_DEVICE_TABLE(i2c, hdmiphy_id);
  281. static struct i2c_driver hdmiphy_driver = {
  282. .driver = {
  283. .name = "s5p-hdmiphy",
  284. },
  285. .probe = hdmiphy_probe,
  286. .remove = hdmiphy_remove,
  287. .id_table = hdmiphy_id,
  288. };
  289. module_i2c_driver(hdmiphy_driver);