34 #include <linux/kernel.h>
35 #include <linux/slab.h>
36 #include <linux/module.h>
38 #include <linux/videodev2.h>
39 #include <linux/i2c.h>
43 #define DRIVER_VERSION "0.0.2"
46 #define DRIVER_DESC "A driver for the TEA5764 radio chip for EZX Phones."
48 #define PINFO(format, ...)\
49 printk(KERN_INFO KBUILD_MODNAME ": "\
50 DRIVER_VERSION ": " format "\n", ## __VA_ARGS__)
51 #define PWARN(format, ...)\
52 printk(KERN_WARNING KBUILD_MODNAME ": "\
53 DRIVER_VERSION ": " format "\n", ## __VA_ARGS__)
54 # define PDEBUG(format, ...)\
55 printk(KERN_DEBUG KBUILD_MODNAME ": "\
56 DRIVER_VERSION ": " format "\n", ## __VA_ARGS__)
60 #define FREQ_MIN 87500
61 #define FREQ_MAX 108000
65 #define TEA5764_MANID 0x002b
66 #define TEA5764_CHIPID 0x5764
68 #define TEA5764_INTREG_BLMSK 0x0001
69 #define TEA5764_INTREG_FRRMSK 0x0002
70 #define TEA5764_INTREG_LEVMSK 0x0008
71 #define TEA5764_INTREG_IFMSK 0x0010
72 #define TEA5764_INTREG_BLMFLAG 0x0100
73 #define TEA5764_INTREG_FRRFLAG 0x0200
74 #define TEA5764_INTREG_LEVFLAG 0x0800
75 #define TEA5764_INTREG_IFFLAG 0x1000
77 #define TEA5764_FRQSET_SUD 0x8000
78 #define TEA5764_FRQSET_SM 0x4000
80 #define TEA5764_TNCTRL_PUPD1 0x8000
81 #define TEA5764_TNCTRL_PUPD0 0x4000
82 #define TEA5764_TNCTRL_BLIM 0x2000
83 #define TEA5764_TNCTRL_SWPM 0x1000
84 #define TEA5764_TNCTRL_IFCTC 0x0800
85 #define TEA5764_TNCTRL_AFM 0x0400
86 #define TEA5764_TNCTRL_SMUTE 0x0200
87 #define TEA5764_TNCTRL_SNC 0x0100
88 #define TEA5764_TNCTRL_MU 0x0080
89 #define TEA5764_TNCTRL_SSL1 0x0040
90 #define TEA5764_TNCTRL_SSL0 0x0020
91 #define TEA5764_TNCTRL_HLSI 0x0010
92 #define TEA5764_TNCTRL_MST 0x0008
93 #define TEA5764_TNCTRL_SWP 0x0004
94 #define TEA5764_TNCTRL_DTC 0x0002
95 #define TEA5764_TNCTRL_AHLSI 0x0001
97 #define TEA5764_TUNCHK_LEVEL(x) (((x) & 0x00F0) >> 4)
98 #define TEA5764_TUNCHK_IFCNT(x) (((x) & 0xFE00) >> 9)
99 #define TEA5764_TUNCHK_TUNTO 0x0100
100 #define TEA5764_TUNCHK_LD 0x0008
101 #define TEA5764_TUNCHK_STEREO 0x0004
103 #define TEA5764_TESTREG_TRIGFR 0x0800
131 #ifdef CONFIG_RADIO_TEA5764_XTAL
132 #define RADIO_TEA5764_XTAL 1
134 #define RADIO_TEA5764_XTAL 0
137 static int radio_nr = -1;
156 .len =
sizeof(radio->
regs),
157 .buf = (
void *)&radio->
regs
160 if (
i2c_transfer(radio->i2c_client->adapter, msgs, 1) != 1)
235 r->
frqset = (freq + 225000) / 8192;
237 r->
frqset = (freq - 225000) / 8192;
245 return (r->
frqchk * 8192) - 225000;
247 return (r->
frqchk * 8192) + 225000;
253 tea5764_set_freq(radio, freq);
255 PWARN(
"Could not set frequency!");
258 static void tea5764_set_audout_mode(
struct tea5764_device *radio,
int audmode)
300 static int vidioc_querycap(
struct file *
file,
void *
priv,
309 "I2C:%s", dev_name(&dev->
dev));
314 static int vidioc_g_tuner(
struct file *file,
void *priv,
334 v->
audmode = tea5764_get_audout_mode(radio);
341 static int vidioc_s_tuner(
struct file *file,
void *priv,
349 tea5764_set_audout_mode(radio, v->
audmode);
353 static int vidioc_s_frequency(
struct file *file,
void *priv,
362 tea5764_power_down(radio);
368 tea5764_power_up(radio);
369 tea5764_tune(radio, (f->
frequency * 125) / 2);
373 static int vidioc_g_frequency(
struct file *file,
void *priv,
385 f->
frequency = (tea5764_get_freq(radio) * 2) / 125;
392 static int vidioc_queryctrl(
struct file *file,
void *priv,
397 for (i = 0; i <
ARRAY_SIZE(radio_qctrl); i++) {
398 if (qc->
id && qc->
id == radio_qctrl[i].
id) {
399 memcpy(qc, &(radio_qctrl[i]),
sizeof(*qc));
406 static int vidioc_g_ctrl(
struct file *file,
void *priv,
414 ctrl->
value = tea5764_is_muted(radio) ? 1 : 0;
420 static int vidioc_s_ctrl(
struct file *file,
void *priv,
427 tea5764_mute(radio, ctrl->
value);
433 static int vidioc_g_input(
struct file *filp,
void *priv,
unsigned int *i)
439 static int vidioc_s_input(
struct file *filp,
void *priv,
unsigned int i)
446 static int vidioc_g_audio(
struct file *file,
void *priv,
457 static int vidioc_s_audio(
struct file *file,
void *priv,
489 .name =
"TEA5764 FM-Radio",
490 .fops = &tea5764_fops,
491 .ioctl_ops = &tea5764_ioctl_ops,
517 PWARN(
"This chip is not a TEA5764!");
528 sizeof(tea5764_radio_template));
530 i2c_set_clientdata(client, radio);
531 video_set_drvdata(radio->
videodev, radio);
537 tea5764_mute(radio, 1);
538 tea5764_power_down(radio);
542 PWARN(
"Could not register video device!");
546 PINFO(
"registered.");
561 tea5764_power_down(radio);
570 {
"radio-tea5764", 0 },
575 static struct i2c_driver tea5764_i2c_driver = {
577 .name =
"radio-tea5764",
580 .probe = tea5764_i2c_probe,
582 .id_table = tea5764_id,