isl6423.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. Intersil ISL6423 SEC and LNB Power supply controller
  3. Copyright (C) Manu Abraham <abraham.manu@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <linux/delay.h>
  17. #include <linux/errno.h>
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/string.h>
  22. #include <linux/slab.h>
  23. #include "dvb_frontend.h"
  24. #include "isl6423.h"
  25. static unsigned int verbose;
  26. module_param(verbose, int, 0644);
  27. MODULE_PARM_DESC(verbose, "Set Verbosity level");
  28. #define FE_ERROR 0
  29. #define FE_NOTICE 1
  30. #define FE_INFO 2
  31. #define FE_DEBUG 3
  32. #define FE_DEBUGREG 4
  33. #define dprintk(__y, __z, format, arg...) do { \
  34. if (__z) { \
  35. if ((verbose > FE_ERROR) && (verbose > __y)) \
  36. printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \
  37. else if ((verbose > FE_NOTICE) && (verbose > __y)) \
  38. printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \
  39. else if ((verbose > FE_INFO) && (verbose > __y)) \
  40. printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \
  41. else if ((verbose > FE_DEBUG) && (verbose > __y)) \
  42. printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \
  43. } else { \
  44. if (verbose > __y) \
  45. printk(format, ##arg); \
  46. } \
  47. } while (0)
  48. struct isl6423_dev {
  49. const struct isl6423_config *config;
  50. struct i2c_adapter *i2c;
  51. u8 reg_3;
  52. u8 reg_4;
  53. unsigned int verbose;
  54. };
  55. static int isl6423_write(struct isl6423_dev *isl6423, u8 reg)
  56. {
  57. struct i2c_adapter *i2c = isl6423->i2c;
  58. u8 addr = isl6423->config->addr;
  59. int err = 0;
  60. struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = &reg, .len = 1 };
  61. dprintk(FE_DEBUG, 1, "write reg %02X", reg);
  62. err = i2c_transfer(i2c, &msg, 1);
  63. if (err < 0)
  64. goto exit;
  65. return 0;
  66. exit:
  67. dprintk(FE_ERROR, 1, "I/O error <%d>", err);
  68. return err;
  69. }
  70. static int isl6423_set_modulation(struct dvb_frontend *fe)
  71. {
  72. struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv;
  73. const struct isl6423_config *config = isl6423->config;
  74. int err = 0;
  75. u8 reg_2 = 0;
  76. reg_2 = 0x01 << 5;
  77. if (config->mod_extern)
  78. reg_2 |= (1 << 3);
  79. else
  80. reg_2 |= (1 << 4);
  81. err = isl6423_write(isl6423, reg_2);
  82. if (err < 0)
  83. goto exit;
  84. return 0;
  85. exit:
  86. dprintk(FE_ERROR, 1, "I/O error <%d>", err);
  87. return err;
  88. }
  89. static int isl6423_voltage_boost(struct dvb_frontend *fe, long arg)
  90. {
  91. struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv;
  92. u8 reg_3 = isl6423->reg_3;
  93. u8 reg_4 = isl6423->reg_4;
  94. int err = 0;
  95. if (arg) {
  96. /* EN = 1, VSPEN = 1, VBOT = 1 */
  97. reg_4 |= (1 << 4);
  98. reg_4 |= 0x1;
  99. reg_3 |= (1 << 3);
  100. } else {
  101. /* EN = 1, VSPEN = 1, VBOT = 0 */
  102. reg_4 |= (1 << 4);
  103. reg_4 &= ~0x1;
  104. reg_3 |= (1 << 3);
  105. }
  106. err = isl6423_write(isl6423, reg_3);
  107. if (err < 0)
  108. goto exit;
  109. err = isl6423_write(isl6423, reg_4);
  110. if (err < 0)
  111. goto exit;
  112. isl6423->reg_3 = reg_3;
  113. isl6423->reg_4 = reg_4;
  114. return 0;
  115. exit:
  116. dprintk(FE_ERROR, 1, "I/O error <%d>", err);
  117. return err;
  118. }
  119. static int isl6423_set_voltage(struct dvb_frontend *fe,
  120. enum fe_sec_voltage voltage)
  121. {
  122. struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv;
  123. u8 reg_3 = isl6423->reg_3;
  124. u8 reg_4 = isl6423->reg_4;
  125. int err = 0;
  126. switch (voltage) {
  127. case SEC_VOLTAGE_OFF:
  128. /* EN = 0 */
  129. reg_4 &= ~(1 << 4);
  130. break;
  131. case SEC_VOLTAGE_13:
  132. /* EN = 1, VSPEN = 1, VTOP = 0, VBOT = 0 */
  133. reg_4 |= (1 << 4);
  134. reg_4 &= ~0x3;
  135. reg_3 |= (1 << 3);
  136. break;
  137. case SEC_VOLTAGE_18:
  138. /* EN = 1, VSPEN = 1, VTOP = 1, VBOT = 0 */
  139. reg_4 |= (1 << 4);
  140. reg_4 |= 0x2;
  141. reg_4 &= ~0x1;
  142. reg_3 |= (1 << 3);
  143. break;
  144. default:
  145. break;
  146. }
  147. err = isl6423_write(isl6423, reg_3);
  148. if (err < 0)
  149. goto exit;
  150. err = isl6423_write(isl6423, reg_4);
  151. if (err < 0)
  152. goto exit;
  153. isl6423->reg_3 = reg_3;
  154. isl6423->reg_4 = reg_4;
  155. return 0;
  156. exit:
  157. dprintk(FE_ERROR, 1, "I/O error <%d>", err);
  158. return err;
  159. }
  160. static int isl6423_set_current(struct dvb_frontend *fe)
  161. {
  162. struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv;
  163. u8 reg_3 = isl6423->reg_3;
  164. const struct isl6423_config *config = isl6423->config;
  165. int err = 0;
  166. switch (config->current_max) {
  167. case SEC_CURRENT_275m:
  168. /* 275mA */
  169. /* ISELH = 0, ISELL = 0 */
  170. reg_3 &= ~0x3;
  171. break;
  172. case SEC_CURRENT_515m:
  173. /* 515mA */
  174. /* ISELH = 0, ISELL = 1 */
  175. reg_3 &= ~0x2;
  176. reg_3 |= 0x1;
  177. break;
  178. case SEC_CURRENT_635m:
  179. /* 635mA */
  180. /* ISELH = 1, ISELL = 0 */
  181. reg_3 &= ~0x1;
  182. reg_3 |= 0x2;
  183. break;
  184. case SEC_CURRENT_800m:
  185. /* 800mA */
  186. /* ISELH = 1, ISELL = 1 */
  187. reg_3 |= 0x3;
  188. break;
  189. }
  190. err = isl6423_write(isl6423, reg_3);
  191. if (err < 0)
  192. goto exit;
  193. switch (config->curlim) {
  194. case SEC_CURRENT_LIM_ON:
  195. /* DCL = 0 */
  196. reg_3 &= ~0x10;
  197. break;
  198. case SEC_CURRENT_LIM_OFF:
  199. /* DCL = 1 */
  200. reg_3 |= 0x10;
  201. break;
  202. }
  203. err = isl6423_write(isl6423, reg_3);
  204. if (err < 0)
  205. goto exit;
  206. isl6423->reg_3 = reg_3;
  207. return 0;
  208. exit:
  209. dprintk(FE_ERROR, 1, "I/O error <%d>", err);
  210. return err;
  211. }
  212. static void isl6423_release(struct dvb_frontend *fe)
  213. {
  214. isl6423_set_voltage(fe, SEC_VOLTAGE_OFF);
  215. kfree(fe->sec_priv);
  216. fe->sec_priv = NULL;
  217. }
  218. struct dvb_frontend *isl6423_attach(struct dvb_frontend *fe,
  219. struct i2c_adapter *i2c,
  220. const struct isl6423_config *config)
  221. {
  222. struct isl6423_dev *isl6423;
  223. isl6423 = kzalloc(sizeof(struct isl6423_dev), GFP_KERNEL);
  224. if (!isl6423)
  225. return NULL;
  226. isl6423->config = config;
  227. isl6423->i2c = i2c;
  228. fe->sec_priv = isl6423;
  229. /* SR3H = 0, SR3M = 1, SR3L = 0 */
  230. isl6423->reg_3 = 0x02 << 5;
  231. /* SR4H = 0, SR4M = 1, SR4L = 1 */
  232. isl6423->reg_4 = 0x03 << 5;
  233. if (isl6423_set_current(fe))
  234. goto exit;
  235. if (isl6423_set_modulation(fe))
  236. goto exit;
  237. fe->ops.release_sec = isl6423_release;
  238. fe->ops.set_voltage = isl6423_set_voltage;
  239. fe->ops.enable_high_lnb_voltage = isl6423_voltage_boost;
  240. isl6423->verbose = verbose;
  241. return fe;
  242. exit:
  243. kfree(isl6423);
  244. fe->sec_priv = NULL;
  245. return NULL;
  246. }
  247. EXPORT_SYMBOL(isl6423_attach);
  248. MODULE_DESCRIPTION("ISL6423 SEC");
  249. MODULE_AUTHOR("Manu Abraham");
  250. MODULE_LICENSE("GPL");