isl6423.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. err = i2c_transfer(i2c, &msg, 1);
  62. if (err < 0)
  63. goto exit;
  64. return 0;
  65. exit:
  66. dprintk(FE_ERROR, 1, "I/O error <%d>", err);
  67. return err;
  68. }
  69. static int isl6423_set_modulation(struct dvb_frontend *fe)
  70. {
  71. struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv;
  72. const struct isl6423_config *config = isl6423->config;
  73. int err = 0;
  74. u8 reg_2 = 0;
  75. reg_2 = 0x01 << 5;
  76. if (config->mod_extern)
  77. reg_2 |= (1 << 3);
  78. else
  79. reg_2 |= (1 << 4);
  80. err = isl6423_write(isl6423, reg_2);
  81. if (err < 0)
  82. goto exit;
  83. return 0;
  84. exit:
  85. dprintk(FE_ERROR, 1, "I/O error <%d>", err);
  86. return err;
  87. }
  88. static int isl6423_voltage_boost(struct dvb_frontend *fe, long arg)
  89. {
  90. struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv;
  91. u8 reg_3 = isl6423->reg_3;
  92. u8 reg_4 = isl6423->reg_4;
  93. int err = 0;
  94. if (arg) {
  95. /* EN = 1, VSPEN = 1, VBOT = 1 */
  96. reg_4 |= (1 << 4);
  97. reg_4 |= 0x1;
  98. reg_3 |= (1 << 3);
  99. } else {
  100. /* EN = 1, VSPEN = 1, VBOT = 0 */
  101. reg_4 |= (1 << 4);
  102. reg_4 &= ~0x1;
  103. reg_3 |= (1 << 3);
  104. }
  105. err = isl6423_write(isl6423, reg_3);
  106. if (err < 0)
  107. goto exit;
  108. err = isl6423_write(isl6423, reg_4);
  109. if (err < 0)
  110. goto exit;
  111. return 0;
  112. exit:
  113. dprintk(FE_ERROR, 1, "I/O error <%d>", err);
  114. return err;
  115. }
  116. static int isl6423_set_voltage(struct dvb_frontend *fe,
  117. enum fe_sec_voltage voltage)
  118. {
  119. struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv;
  120. u8 reg_4 = isl6423->reg_4;
  121. int err = 0;
  122. /* SR4H = 0, SR4M = 1, SR4L = 1 */
  123. reg_4 = 0x03 << 5;
  124. switch (voltage) {
  125. case SEC_VOLTAGE_OFF:
  126. /* EN = 0 */
  127. reg_4 &= ~(1 << 4);
  128. break;
  129. case SEC_VOLTAGE_13:
  130. /* EN = 1, VSPEN = 1, VTOP = 0, VBOT = 0 */
  131. reg_4 |= (1 << 4);
  132. reg_4 &= ~0x3;
  133. break;
  134. case SEC_VOLTAGE_18:
  135. /* EN = 1, VSPEN = 1, VTOP = 1, VBOT = 0 */
  136. reg_4 |= (1 << 4);
  137. reg_4 |= 0x2;
  138. reg_4 &= ~0x1;
  139. break;
  140. default:
  141. break;
  142. }
  143. err = isl6423_write(isl6423, reg_4);
  144. if (err < 0)
  145. goto exit;
  146. return 0;
  147. exit:
  148. dprintk(FE_ERROR, 1, "I/O error <%d>", err);
  149. return err;
  150. }
  151. static int isl6423_set_current(struct dvb_frontend *fe)
  152. {
  153. struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv;
  154. u8 reg_3 = isl6423->reg_3;
  155. const struct isl6423_config *config = isl6423->config;
  156. int err = 0;
  157. /* SR3H = 0, SR3M = 1, SR3L = 0 */
  158. reg_3 = 0x02 << 5;
  159. switch (config->current_max) {
  160. case SEC_CURRENT_275m:
  161. /* 275mA */
  162. /* ISELH = 0, ISELL = 0 */
  163. reg_3 &= ~0x3;
  164. break;
  165. case SEC_CURRENT_515m:
  166. /* 515mA */
  167. /* ISELH = 0, ISELL = 1 */
  168. reg_3 &= ~0x2;
  169. reg_3 |= 0x1;
  170. break;
  171. case SEC_CURRENT_635m:
  172. /* 635mA */
  173. /* ISELH = 1, ISELL = 0 */
  174. reg_3 &= ~0x1;
  175. reg_3 |= 0x2;
  176. break;
  177. case SEC_CURRENT_800m:
  178. /* 800mA */
  179. /* ISELH = 1, ISELL = 1 */
  180. reg_3 |= 0x3;
  181. break;
  182. }
  183. err = isl6423_write(isl6423, reg_3);
  184. if (err < 0)
  185. goto exit;
  186. switch (config->curlim) {
  187. case SEC_CURRENT_LIM_ON:
  188. /* DCL = 1 */
  189. reg_3 |= 0x10;
  190. break;
  191. case SEC_CURRENT_LIM_OFF:
  192. /* DCL = 0 */
  193. reg_3 &= ~0x10;
  194. break;
  195. }
  196. err = isl6423_write(isl6423, reg_3);
  197. if (err < 0)
  198. goto exit;
  199. return 0;
  200. exit:
  201. dprintk(FE_ERROR, 1, "I/O error <%d>", err);
  202. return err;
  203. }
  204. static void isl6423_release(struct dvb_frontend *fe)
  205. {
  206. isl6423_set_voltage(fe, SEC_VOLTAGE_OFF);
  207. kfree(fe->sec_priv);
  208. fe->sec_priv = NULL;
  209. }
  210. struct dvb_frontend *isl6423_attach(struct dvb_frontend *fe,
  211. struct i2c_adapter *i2c,
  212. const struct isl6423_config *config)
  213. {
  214. struct isl6423_dev *isl6423;
  215. isl6423 = kzalloc(sizeof(struct isl6423_dev), GFP_KERNEL);
  216. if (!isl6423)
  217. return NULL;
  218. isl6423->config = config;
  219. isl6423->i2c = i2c;
  220. fe->sec_priv = isl6423;
  221. if (isl6423_set_current(fe))
  222. goto exit;
  223. if (isl6423_set_modulation(fe))
  224. goto exit;
  225. fe->ops.release_sec = isl6423_release;
  226. fe->ops.set_voltage = isl6423_set_voltage;
  227. fe->ops.enable_high_lnb_voltage = isl6423_voltage_boost;
  228. isl6423->verbose = verbose;
  229. return fe;
  230. exit:
  231. kfree(isl6423);
  232. fe->sec_priv = NULL;
  233. return NULL;
  234. }
  235. EXPORT_SYMBOL(isl6423_attach);
  236. MODULE_DESCRIPTION("ISL6423 SEC");
  237. MODULE_AUTHOR("Manu Abraham");
  238. MODULE_LICENSE("GPL");