Merge branch 'fixes' into misc
[sfrench/cifs-2.6.git] / drivers / media / tuners / fc2580_priv.h
1 /*
2  * FCI FC2580 silicon tuner driver
3  *
4  * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
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 as published by
8  *    the Free Software Foundation; either version 2 of the License, or
9  *    (at your option) any later version.
10  *
11  *    This program is distributed in the hope that it will be useful,
12  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *    GNU General Public License for more details.
15  *
16  *    You should have received a copy of the GNU General Public License along
17  *    with this program; if not, write to the Free Software Foundation, Inc.,
18  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #ifndef FC2580_PRIV_H
22 #define FC2580_PRIV_H
23
24 #include "fc2580.h"
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-subdev.h>
27 #include <linux/regmap.h>
28 #include <linux/math64.h>
29
30 struct fc2580_reg_val {
31         u8 reg;
32         u8 val;
33 };
34
35 static const struct fc2580_reg_val fc2580_init_reg_vals[] = {
36         {0x00, 0x00},
37         {0x12, 0x86},
38         {0x14, 0x5c},
39         {0x16, 0x3c},
40         {0x1f, 0xd2},
41         {0x09, 0xd7},
42         {0x0b, 0xd5},
43         {0x0c, 0x32},
44         {0x0e, 0x43},
45         {0x21, 0x0a},
46         {0x22, 0x82},
47         {0x45, 0x10},
48         {0x4c, 0x00},
49         {0x3f, 0x88},
50         {0x02, 0x0e},
51         {0x58, 0x14},
52 };
53
54 struct fc2580_pll {
55         u32 freq;
56         u8 div_out;
57         u8 band;
58 };
59
60 static const struct fc2580_pll fc2580_pll_lut[] = {
61         /*                            VCO min    VCO max */
62         { 400000000, 12, 0x80}, /* .......... 4800000000 */
63         {1000000000,  4, 0x00}, /* 1600000000 4000000000 */
64         {0xffffffff,  2, 0x40}, /* 2000000000 .......... */
65 };
66
67 struct fc2580_if_filter {
68         u32 freq;
69         u8 r36_val;
70         u8 r39_val;
71 };
72
73 static const struct fc2580_if_filter fc2580_if_filter_lut[] = {
74         {   6000000, 0x18, 0x00},
75         {   7000000, 0x18, 0x80},
76         {   8000000, 0x18, 0x80},
77         {0xffffffff, 0x18, 0x80},
78 };
79
80 struct fc2580_freq_regs {
81         u32 freq;
82         u8 r25_val;
83         u8 r27_val;
84         u8 r28_val;
85         u8 r29_val;
86         u8 r2b_val;
87         u8 r2c_val;
88         u8 r2d_val;
89         u8 r30_val;
90         u8 r44_val;
91         u8 r50_val;
92         u8 r53_val;
93         u8 r5f_val;
94         u8 r61_val;
95         u8 r62_val;
96         u8 r63_val;
97         u8 r67_val;
98         u8 r68_val;
99         u8 r69_val;
100         u8 r6a_val;
101         u8 r6b_val;
102         u8 r6c_val;
103         u8 r6d_val;
104         u8 r6e_val;
105         u8 r6f_val;
106 };
107
108 /* XXX: 0xff is used for don't-care! */
109 static const struct fc2580_freq_regs fc2580_freq_regs_lut[] = {
110         { 400000000,
111                 0xff, 0x77, 0x33, 0x40, 0xff, 0xff, 0xff, 0x09, 0xff, 0x8c,
112                 0x50, 0x0f, 0x07, 0x00, 0x15, 0x03, 0x05, 0x10, 0x12, 0x08,
113                 0x0a, 0x78, 0x32, 0x54},
114         { 538000000,
115                 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0x9f, 0x09, 0xff, 0x8c,
116                 0x50, 0x13, 0x07, 0x06, 0x15, 0x06, 0x08, 0x10, 0x12, 0x0b,
117                 0x0c, 0x78, 0x32, 0x14},
118         { 794000000,
119                 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0x9f, 0x09, 0xff, 0x8c,
120                 0x50, 0x15, 0x03, 0x03, 0x15, 0x03, 0x05, 0x0c, 0x0e, 0x0b,
121                 0x0c, 0x78, 0x32, 0x14},
122         {1000000000,
123                 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0x8f, 0x09, 0xff, 0x8c,
124                 0x50, 0x15, 0x07, 0x06, 0x15, 0x07, 0x09, 0x10, 0x12, 0x0b,
125                 0x0c, 0x78, 0x32, 0x14},
126         {0xffffffff,
127                 0xff, 0xff, 0xff, 0xff, 0x70, 0x37, 0xe7, 0x09, 0x20, 0x8c,
128                 0x50, 0x0f, 0x0f, 0x00, 0x13, 0x00, 0x02, 0x0c, 0x0e, 0x08,
129                 0x0a, 0xa0, 0x50, 0x14},
130 };
131
132 struct fc2580_dev {
133         u32 clk;
134         struct i2c_client *client;
135         struct regmap *regmap;
136         struct v4l2_subdev subdev;
137         bool active;
138         unsigned int f_frequency;
139         unsigned int f_bandwidth;
140
141         /* Controls */
142         struct v4l2_ctrl_handler hdl;
143         struct v4l2_ctrl *bandwidth_auto;
144         struct v4l2_ctrl *bandwidth;
145 };
146
147 #endif