[ARM] pxa: update defconfig for Verdex Pro
[linux-2.6/verdex.git] / drivers / media / dvb / frontends / s921_module.c
blob3156b64cfc9642d2d0c7230716091fc70e38d26f
1 /*
2 * Driver for Sharp s921 driver
4 * Copyright (C) 2008 Markus Rechberger <mrechberger@sundtek.de>
6 * All rights reserved.
8 */
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/delay.h>
13 #include "dvb_frontend.h"
14 #include "s921_module.h"
15 #include "s921_core.h"
17 static unsigned int debug = 0;
18 module_param(debug, int, 0644);
19 MODULE_PARM_DESC(debug,"s921 debugging (default off)");
21 #define dprintk(fmt, args...) if (debug) do {\
22 printk("s921 debug: " fmt, ##args); } while (0)
24 struct s921_state
26 struct dvb_frontend frontend;
27 fe_modulation_t current_modulation;
28 __u32 snr;
29 __u32 current_frequency;
30 __u8 addr;
31 struct s921_isdb_t dev;
32 struct i2c_adapter *i2c;
35 static int s921_set_parameters(struct dvb_frontend *fe, struct dvb_frontend_parameters *param) {
36 struct s921_state *state = (struct s921_state *)fe->demodulator_priv;
37 struct s921_isdb_t_transmission_mode_params params;
38 struct s921_isdb_t_tune_params tune_params;
40 tune_params.frequency = param->frequency;
41 s921_isdb_cmd(&state->dev, ISDB_T_CMD_SET_PARAM, &params);
42 s921_isdb_cmd(&state->dev, ISDB_T_CMD_TUNE, &tune_params);
43 mdelay(100);
44 return 0;
47 static int s921_init(struct dvb_frontend *fe) {
48 printk("s921 init\n");
49 return 0;
52 static int s921_sleep(struct dvb_frontend *fe) {
53 printk("s921 sleep\n");
54 return 0;
57 static int s921_read_status(struct dvb_frontend *fe, fe_status_t *status)
59 struct s921_state *state = (struct s921_state *)fe->demodulator_priv;
60 unsigned int ret;
61 mdelay(5);
62 s921_isdb_cmd(&state->dev, ISDB_T_CMD_GET_STATUS, &ret);
63 *status = 0;
65 printk("status: %02x\n", ret);
66 if (ret == 1) {
67 *status |= FE_HAS_CARRIER;
68 *status |= FE_HAS_VITERBI;
69 *status |= FE_HAS_LOCK;
70 *status |= FE_HAS_SYNC;
71 *status |= FE_HAS_SIGNAL;
74 return 0;
77 static int s921_read_ber(struct dvb_frontend *fe, __u32 *ber)
79 dprintk("read ber\n");
80 return 0;
83 static int s921_read_snr(struct dvb_frontend *fe, __u16 *snr)
85 dprintk("read snr\n");
86 return 0;
89 static int s921_read_ucblocks(struct dvb_frontend *fe, __u32 *ucblocks)
91 dprintk("read ucblocks\n");
92 return 0;
95 static void s921_release(struct dvb_frontend *fe)
97 struct s921_state *state = (struct s921_state *)fe->demodulator_priv;
98 kfree(state);
101 static struct dvb_frontend_ops demod_s921={
102 .info = {
103 .name = "SHARP S921",
104 .type = FE_OFDM,
105 .frequency_min = 473143000,
106 .frequency_max = 767143000,
107 .frequency_stepsize = 6000000,
108 .frequency_tolerance = 0,
109 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
110 FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
111 FE_CAN_FEC_AUTO |
112 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
113 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
114 FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER |
115 FE_CAN_MUTE_TS
117 .init = s921_init,
118 .sleep = s921_sleep,
119 .set_frontend = s921_set_parameters,
120 .read_snr = s921_read_snr,
121 .read_ber = s921_read_ber,
122 .read_status = s921_read_status,
123 .read_ucblocks = s921_read_ucblocks,
124 .release = s921_release,
127 static int s921_write(void *dev, u8 reg, u8 val) {
128 struct s921_state *state = dev;
129 char buf[2]={reg,val};
130 int err;
131 struct i2c_msg i2cmsgs = {
132 .addr = state->addr,
133 .flags = 0,
134 .len = 2,
135 .buf = buf
138 if((err = i2c_transfer(state->i2c, &i2cmsgs, 1))<0) {
139 printk("%s i2c_transfer error %d\n", __func__, err);
140 if (err < 0)
141 return err;
142 else
143 return -EREMOTEIO;
146 return 0;
149 static int s921_read(void *dev, u8 reg) {
150 struct s921_state *state = dev;
151 u8 b1;
152 int ret;
153 struct i2c_msg msg[2] = { { .addr = state->addr,
154 .flags = 0,
155 .buf = &reg, .len = 1 },
156 { .addr = state->addr,
157 .flags = I2C_M_RD,
158 .buf = &b1, .len = 1 } };
160 ret = i2c_transfer(state->i2c, msg, 2);
161 if (ret != 2)
162 return ret;
163 return b1;
166 struct dvb_frontend* s921_attach(const struct s921_config *config,
167 struct i2c_adapter *i2c)
170 struct s921_state *state;
171 state = kzalloc(sizeof(struct s921_state), GFP_KERNEL);
172 if (state == NULL)
173 return NULL;
175 state->addr = config->i2c_address;
176 state->i2c = i2c;
177 state->dev.i2c_write = &s921_write;
178 state->dev.i2c_read = &s921_read;
179 state->dev.priv_dev = state;
181 s921_isdb_cmd(&state->dev, ISDB_T_CMD_INIT, NULL);
183 memcpy(&state->frontend.ops, &demod_s921, sizeof(struct dvb_frontend_ops));
184 state->frontend.demodulator_priv = state;
185 return &state->frontend;
188 EXPORT_SYMBOL_GPL(s921_attach);
189 MODULE_AUTHOR("Markus Rechberger <mrechberger@empiatech.com>");
190 MODULE_DESCRIPTION("Sharp S921 ISDB-T 1Seg");
191 MODULE_LICENSE("GPL");