edp-backlight.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * cypress_touchkey.c - Platform data for edp backlight driver
  3. *
  4. * Copyright (C) 2011 Samsung Electronics
  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. */
  11. #include <linux/kernel.h>
  12. #include <asm/unaligned.h>
  13. //#include <mach/cpufreq.h>
  14. #include <linux/input/mt.h>
  15. #include <linux/of_gpio.h>
  16. #include <linux/regulator/consumer.h>
  17. #include <linux/module.h>
  18. #include <linux/input.h>
  19. #include <linux/init.h>
  20. #include <linux/slab.h>
  21. #include <linux/i2c.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <linux/delay.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/gpio.h>
  27. #include <linux/miscdevice.h>
  28. #include <linux/earlysuspend.h>
  29. #include <linux/regulator/consumer.h>
  30. #include <asm/mach-types.h>
  31. #include <linux/device.h>
  32. /* #include <mach/msm8974-gpio.h> */
  33. #include <linux/of_gpio.h>
  34. #include "mdss.h"
  35. #include "mdss_panel.h"
  36. #include "mdss_mdp.h"
  37. #include "mdss_edp.h"
  38. struct edp_backlight_platform_data {
  39. unsigned int gpio_backlight_en;
  40. u32 en_gpio_flags;
  41. int gpio_sda;
  42. u32 sda_gpio_flags;
  43. int gpio_scl;
  44. u32 scl_gpio_flags;
  45. };
  46. struct edp_backlight_info {
  47. struct i2c_client *client;
  48. struct edp_backlight_platform_data *pdata;
  49. };
  50. static struct edp_backlight_info *pinfo;
  51. #if 0
  52. static int backlight_i2c_read(struct i2c_client *client,
  53. u8 reg, u8 *val, unsigned int len)
  54. {
  55. int err = 0;
  56. int retry = 3;
  57. while (retry--) {
  58. err = i2c_smbus_read_i2c_block_data(client,
  59. reg, len, val);
  60. if (err >= 0)
  61. return err;
  62. dev_info(&client->dev, "%s: i2c transfer error.\n", __func__);
  63. }
  64. return err;
  65. }
  66. #endif
  67. static int backlight_i2c_write(struct i2c_client *client,
  68. u8 reg, u8 val, unsigned int len)
  69. {
  70. int err = 0;
  71. int retry = 3;
  72. u8 temp_val = val;
  73. while (retry--) {
  74. err = i2c_smbus_write_i2c_block_data(client,
  75. reg, len, &temp_val);
  76. if (err >= 0)
  77. return err;
  78. dev_info(&client->dev, "%s: i2c transfer error. %d\n", __func__, err);
  79. }
  80. return err;
  81. }
  82. static void backlight_request_gpio(struct edp_backlight_platform_data *pdata)
  83. {
  84. int ret;
  85. ret = gpio_request(pdata->gpio_backlight_en, "edp_backlight_en");
  86. if (ret) {
  87. printk(KERN_ERR "%s: unable to request backlight_en [%d]\n",
  88. __func__, pdata->gpio_sda);
  89. return;
  90. }
  91. #if 0 //splash booting enable
  92. gpio_tlmm_config(GPIO_CFG(pdata->gpio_backlight_en, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  93. gpio_tlmm_config(GPIO_CFG(pdata->gpio_scl, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  94. gpio_tlmm_config(GPIO_CFG(pdata->gpio_sda, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  95. gpio_set_value(pdata->gpio_backlight_en,0);
  96. pr_info("%s %d", __func__, gpio_get_value(pdata->gpio_backlight_en));
  97. #else
  98. gpio_tlmm_config(GPIO_CFG(pdata->gpio_scl, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  99. gpio_tlmm_config(GPIO_CFG(pdata->gpio_sda, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  100. #endif
  101. }
  102. static int edp_backlight_parse_dt(struct device *dev,
  103. struct edp_backlight_platform_data *pdata)
  104. {
  105. struct device_node *np = dev->of_node;
  106. /* reset, irq gpio info */
  107. pdata->gpio_scl = of_get_named_gpio_flags(np, "edp,scl-gpio",
  108. 0, &pdata->scl_gpio_flags);
  109. pdata->gpio_sda = of_get_named_gpio_flags(np, "edp,sda-gpio",
  110. 0, &pdata->sda_gpio_flags);
  111. pdata->gpio_backlight_en = of_get_named_gpio_flags(np, "edp.en-gpio",
  112. 0, &pdata->en_gpio_flags);
  113. pr_info("%s gpio_scl : %d , gpio_sda : %d en : %d", __func__, pdata->gpio_scl, pdata->gpio_sda, pdata->gpio_backlight_en);
  114. return 0;
  115. }
  116. static u8 ndra_setting[][2] ={
  117. {0x01, 0x80},
  118. #if defined(CONFIG_MACH_VIENNA_LTE) || defined(CONFIG_MACH_LT03EUR)\
  119. || defined(CONFIG_MACH_LT03SKT) || defined(CONFIG_MACH_LT03KTT)\
  120. || defined(CONFIG_MACH_LT03LGT) || defined(CONFIG_MACH_V2LTEEUR)\
  121. || defined(CONFIG_MACH_PICASSO)
  122. {0xA0, 0xFF},
  123. {0xA1, 0x5F},
  124. #else
  125. {0xA0, 0xDD},
  126. {0xA1, 0x6D},
  127. #endif
  128. {0x98, 0xA1},
  129. {0x9E, 0x21},
  130. {0xA2, 0x28},
  131. {0xA3, 0x5E},
  132. {0xA4, 0x72},
  133. {0xA5, 0x04},
  134. {0xA6, 0x40},
  135. {0xA7, 0xFB},
  136. {0xA8, 0x00},
  137. {0xA9, 0xA0},
  138. {0xAA, 0x0F},
  139. {0xAB, 0x00},
  140. {0xAC, 0x00},
  141. {0xAD, 0x00},
  142. {0xAE, 0x0E},
  143. {0xAF, 0x01},
  144. };
  145. extern void restore_set_tcon(void);
  146. void edp_backlight_power_enable(void)
  147. {
  148. int i;
  149. struct edp_backlight_info *info = pinfo;
  150. if (!info) {
  151. pr_info("%s error pinfo", __func__);
  152. return ;
  153. }
  154. gpio_set_value(info->pdata->gpio_backlight_en,1);
  155. for (i = 0; i < ARRAY_SIZE(ndra_setting) ;i++) {
  156. backlight_i2c_write(info->client, ndra_setting[i][0], ndra_setting[i][1], 1);
  157. }
  158. pr_info("%s LSI_NDRA ", __func__);
  159. }
  160. void edp_backlight_enable(void)
  161. {
  162. int i;
  163. struct edp_backlight_info *info = pinfo;
  164. if (!info) {
  165. pr_info("%s error pinfo", __func__);
  166. return ;
  167. }
  168. gpio_set_value(info->pdata->gpio_backlight_en,1);
  169. restore_set_tcon();
  170. for (i = 0; i < ARRAY_SIZE(ndra_setting) ;i++) {
  171. backlight_i2c_write(info->client, ndra_setting[i][0], ndra_setting[i][1], 1);
  172. }
  173. pr_info("%s LSI_NDRA ", __func__);
  174. }
  175. void edp_backlight_disable(void)
  176. {
  177. struct edp_backlight_info *info = pinfo;
  178. if (!info) {
  179. pr_info("%s error pinfo", __func__);
  180. return ;
  181. }
  182. gpio_set_value(info->pdata->gpio_backlight_en, 0);
  183. }
  184. int edp_backlight_status(void)
  185. {
  186. struct edp_backlight_info *info = pinfo;
  187. if (!info) {
  188. pr_info("%s error pinfo", __func__);
  189. return -ENODEV;
  190. }
  191. return gpio_get_value(info->pdata->gpio_backlight_en);
  192. }
  193. static int __devinit edp_backlight_probe(struct i2c_client *client,
  194. const struct i2c_device_id *id)
  195. {
  196. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  197. struct edp_backlight_platform_data *pdata;
  198. struct edp_backlight_info *info;
  199. int error = 0;
  200. pr_info("%s", __func__);
  201. if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
  202. return -EIO;
  203. if (client->dev.of_node) {
  204. pdata = devm_kzalloc(&client->dev,
  205. sizeof(struct edp_backlight_platform_data),
  206. GFP_KERNEL);
  207. if (!pdata) {
  208. dev_info(&client->dev, "Failed to allocate memory\n");
  209. return -ENOMEM;
  210. }
  211. error = edp_backlight_parse_dt(&client->dev, pdata);
  212. if (error)
  213. return error;
  214. } else
  215. pdata = client->dev.platform_data;
  216. backlight_request_gpio(pdata);
  217. pinfo = info = kzalloc(sizeof(*info), GFP_KERNEL);
  218. if (!info) {
  219. dev_info(&client->dev, "%s: fail to memory allocation.\n", __func__);
  220. return -ENOMEM;
  221. }
  222. info->client = client;
  223. info->pdata = pdata;
  224. i2c_set_clientdata(client, info);
  225. return error;
  226. }
  227. static int __devexit edp_backlight_remove(struct i2c_client *client)
  228. {
  229. return 0;
  230. }
  231. static const struct i2c_device_id edp_backlight_id[] = {
  232. {"edp_backlight", 0},
  233. {}
  234. };
  235. MODULE_DEVICE_TABLE(i2c, edp_backlight_id);
  236. static struct of_device_id edp_backlight_match_table[] = {
  237. { .compatible = "edp,backlight-control",},
  238. { },
  239. };
  240. MODULE_DEVICE_TABLE(of, edp_backlight_id);
  241. struct i2c_driver edp_backlight_driver = {
  242. .probe = edp_backlight_probe,
  243. .remove = edp_backlight_remove,
  244. .driver = {
  245. .name = "edp_backlight",
  246. .owner = THIS_MODULE,
  247. .of_match_table = edp_backlight_match_table,
  248. },
  249. .id_table = edp_backlight_id,
  250. };
  251. static int __init edp_backlight_init(void)
  252. {
  253. int ret = 0;
  254. ret = i2c_add_driver(&edp_backlight_driver);
  255. if (ret) {
  256. printk(KERN_ERR "edp_backlight_init registration failed. ret= %d\n",
  257. ret);
  258. }
  259. return ret;
  260. }
  261. static void __exit edp_backlight_exit(void)
  262. {
  263. i2c_del_driver(&edp_backlight_driver);
  264. }
  265. module_init(edp_backlight_init);
  266. module_exit(edp_backlight_exit);
  267. MODULE_DESCRIPTION("edp backlight driver");
  268. MODULE_LICENSE("GPL");