Commit 1c9f11ed21816290a7cea36fc2dc3b16d5590340
Committed by
Mauro Carvalho Chehab
1 parent
eb27fafef6
Exists in
smarc-imx_3.14.28_1.0.0_ga
and in
1 other branch
[media] radio-aztech: Implement signal strength detection and fix stereo detection
Current stereo detection code is wrong - it reads TUNED bit instead of STEREO bit. Fix that and implement signal strength detection too. Also remove useless s_stereo functionn. Signed-off-by: Ondrej Zary <linux@rainbow-software.org> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Showing 1 changed file with 4 additions and 9 deletions Inline Diff
drivers/media/radio/radio-aztech.c
1 | /* | 1 | /* |
2 | * radio-aztech.c - Aztech radio card driver | 2 | * radio-aztech.c - Aztech radio card driver |
3 | * | 3 | * |
4 | * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@xs4all.nl> | 4 | * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@xs4all.nl> |
5 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> | 5 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
6 | * Adapted to support the Video for Linux API by | 6 | * Adapted to support the Video for Linux API by |
7 | * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by: | 7 | * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by: |
8 | * | 8 | * |
9 | * Quay Ly | 9 | * Quay Ly |
10 | * Donald Song | 10 | * Donald Song |
11 | * Jason Lewis (jlewis@twilight.vtc.vsc.edu) | 11 | * Jason Lewis (jlewis@twilight.vtc.vsc.edu) |
12 | * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) | 12 | * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) |
13 | * William McGrath (wmcgrath@twilight.vtc.vsc.edu) | 13 | * William McGrath (wmcgrath@twilight.vtc.vsc.edu) |
14 | * | 14 | * |
15 | * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool. | 15 | * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/module.h> /* Modules */ | 18 | #include <linux/module.h> /* Modules */ |
19 | #include <linux/init.h> /* Initdata */ | 19 | #include <linux/init.h> /* Initdata */ |
20 | #include <linux/ioport.h> /* request_region */ | 20 | #include <linux/ioport.h> /* request_region */ |
21 | #include <linux/delay.h> /* udelay */ | 21 | #include <linux/delay.h> /* udelay */ |
22 | #include <linux/videodev2.h> /* kernel radio structs */ | 22 | #include <linux/videodev2.h> /* kernel radio structs */ |
23 | #include <linux/io.h> /* outb, outb_p */ | 23 | #include <linux/io.h> /* outb, outb_p */ |
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <media/v4l2-device.h> | 25 | #include <media/v4l2-device.h> |
26 | #include <media/v4l2-ioctl.h> | 26 | #include <media/v4l2-ioctl.h> |
27 | #include <media/v4l2-ctrls.h> | 27 | #include <media/v4l2-ctrls.h> |
28 | #include "radio-isa.h" | 28 | #include "radio-isa.h" |
29 | #include "lm7000.h" | 29 | #include "lm7000.h" |
30 | 30 | ||
31 | MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath"); | 31 | MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath"); |
32 | MODULE_DESCRIPTION("A driver for the Aztech radio card."); | 32 | MODULE_DESCRIPTION("A driver for the Aztech radio card."); |
33 | MODULE_LICENSE("GPL"); | 33 | MODULE_LICENSE("GPL"); |
34 | MODULE_VERSION("1.0.0"); | 34 | MODULE_VERSION("1.0.0"); |
35 | 35 | ||
36 | /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ | 36 | /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ |
37 | #ifndef CONFIG_RADIO_AZTECH_PORT | 37 | #ifndef CONFIG_RADIO_AZTECH_PORT |
38 | #define CONFIG_RADIO_AZTECH_PORT -1 | 38 | #define CONFIG_RADIO_AZTECH_PORT -1 |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | #define AZTECH_MAX 2 | 41 | #define AZTECH_MAX 2 |
42 | 42 | ||
43 | static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT, | 43 | static int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT, |
44 | [1 ... (AZTECH_MAX - 1)] = -1 }; | 44 | [1 ... (AZTECH_MAX - 1)] = -1 }; |
45 | static int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 }; | 45 | static int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 }; |
46 | static const int radio_wait_time = 1000; | 46 | static const int radio_wait_time = 1000; |
47 | 47 | ||
48 | module_param_array(io, int, NULL, 0444); | 48 | module_param_array(io, int, NULL, 0444); |
49 | MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)"); | 49 | MODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)"); |
50 | module_param_array(radio_nr, int, NULL, 0444); | 50 | module_param_array(radio_nr, int, NULL, 0444); |
51 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); | 51 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); |
52 | 52 | ||
53 | struct aztech { | 53 | struct aztech { |
54 | struct radio_isa_card isa; | 54 | struct radio_isa_card isa; |
55 | int curvol; | 55 | int curvol; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | /* bit definitions for register read */ | 58 | /* bit definitions for register read */ |
59 | #define AZTECH_BIT_NOT_TUNED (1 << 0) | 59 | #define AZTECH_BIT_NOT_TUNED (1 << 0) |
60 | #define AZTECH_BIT_MONO (1 << 1) | 60 | #define AZTECH_BIT_MONO (1 << 1) |
61 | /* bit definitions for register write */ | 61 | /* bit definitions for register write */ |
62 | #define AZTECH_BIT_TUN_CE (1 << 1) | 62 | #define AZTECH_BIT_TUN_CE (1 << 1) |
63 | #define AZTECH_BIT_TUN_CLK (1 << 6) | 63 | #define AZTECH_BIT_TUN_CLK (1 << 6) |
64 | #define AZTECH_BIT_TUN_DATA (1 << 7) | 64 | #define AZTECH_BIT_TUN_DATA (1 << 7) |
65 | /* bits 0 and 2 are volume control, bits 3..5 are not connected */ | 65 | /* bits 0 and 2 are volume control, bits 3..5 are not connected */ |
66 | 66 | ||
67 | static void aztech_set_pins(void *handle, u8 pins) | 67 | static void aztech_set_pins(void *handle, u8 pins) |
68 | { | 68 | { |
69 | struct radio_isa_card *isa = handle; | 69 | struct radio_isa_card *isa = handle; |
70 | struct aztech *az = container_of(isa, struct aztech, isa); | 70 | struct aztech *az = container_of(isa, struct aztech, isa); |
71 | u8 bits = az->curvol; | 71 | u8 bits = az->curvol; |
72 | 72 | ||
73 | if (pins & LM7000_DATA) | 73 | if (pins & LM7000_DATA) |
74 | bits |= AZTECH_BIT_TUN_DATA; | 74 | bits |= AZTECH_BIT_TUN_DATA; |
75 | if (pins & LM7000_CLK) | 75 | if (pins & LM7000_CLK) |
76 | bits |= AZTECH_BIT_TUN_CLK; | 76 | bits |= AZTECH_BIT_TUN_CLK; |
77 | if (pins & LM7000_CE) | 77 | if (pins & LM7000_CE) |
78 | bits |= AZTECH_BIT_TUN_CE; | 78 | bits |= AZTECH_BIT_TUN_CE; |
79 | 79 | ||
80 | outb_p(bits, az->isa.io); | 80 | outb_p(bits, az->isa.io); |
81 | } | 81 | } |
82 | 82 | ||
83 | static struct radio_isa_card *aztech_alloc(void) | 83 | static struct radio_isa_card *aztech_alloc(void) |
84 | { | 84 | { |
85 | struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL); | 85 | struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL); |
86 | 86 | ||
87 | return az ? &az->isa : NULL; | 87 | return az ? &az->isa : NULL; |
88 | } | 88 | } |
89 | 89 | ||
90 | static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq) | 90 | static int aztech_s_frequency(struct radio_isa_card *isa, u32 freq) |
91 | { | 91 | { |
92 | lm7000_set_freq(freq, isa, aztech_set_pins); | 92 | lm7000_set_freq(freq, isa, aztech_set_pins); |
93 | 93 | ||
94 | return 0; | 94 | return 0; |
95 | } | 95 | } |
96 | 96 | ||
97 | /* thanks to Michael Dwyer for giving me a dose of clues in | ||
98 | * the signal strength department.. | ||
99 | * | ||
100 | * This card has a stereo bit - bit 0 set = mono, not set = stereo | ||
101 | */ | ||
102 | static u32 aztech_g_rxsubchans(struct radio_isa_card *isa) | 97 | static u32 aztech_g_rxsubchans(struct radio_isa_card *isa) |
103 | { | 98 | { |
104 | if (inb(isa->io) & 1) | 99 | if (inb(isa->io) & AZTECH_BIT_MONO) |
105 | return V4L2_TUNER_SUB_MONO; | 100 | return V4L2_TUNER_SUB_MONO; |
106 | return V4L2_TUNER_SUB_STEREO; | 101 | return V4L2_TUNER_SUB_STEREO; |
107 | } | 102 | } |
108 | 103 | ||
109 | static int aztech_s_stereo(struct radio_isa_card *isa, bool stereo) | 104 | static u32 aztech_g_signal(struct radio_isa_card *isa) |
110 | { | 105 | { |
111 | return aztech_s_frequency(isa, isa->freq); | 106 | return (inb(isa->io) & AZTECH_BIT_NOT_TUNED) ? 0 : 0xffff; |
112 | } | 107 | } |
113 | 108 | ||
114 | static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) | 109 | static int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) |
115 | { | 110 | { |
116 | struct aztech *az = container_of(isa, struct aztech, isa); | 111 | struct aztech *az = container_of(isa, struct aztech, isa); |
117 | 112 | ||
118 | if (mute) | 113 | if (mute) |
119 | vol = 0; | 114 | vol = 0; |
120 | az->curvol = (vol & 1) + ((vol & 2) << 1); | 115 | az->curvol = (vol & 1) + ((vol & 2) << 1); |
121 | outb(az->curvol, isa->io); | 116 | outb(az->curvol, isa->io); |
122 | return 0; | 117 | return 0; |
123 | } | 118 | } |
124 | 119 | ||
125 | static const struct radio_isa_ops aztech_ops = { | 120 | static const struct radio_isa_ops aztech_ops = { |
126 | .alloc = aztech_alloc, | 121 | .alloc = aztech_alloc, |
127 | .s_mute_volume = aztech_s_mute_volume, | 122 | .s_mute_volume = aztech_s_mute_volume, |
128 | .s_frequency = aztech_s_frequency, | 123 | .s_frequency = aztech_s_frequency, |
129 | .s_stereo = aztech_s_stereo, | ||
130 | .g_rxsubchans = aztech_g_rxsubchans, | 124 | .g_rxsubchans = aztech_g_rxsubchans, |
125 | .g_signal = aztech_g_signal, | ||
131 | }; | 126 | }; |
132 | 127 | ||
133 | static const int aztech_ioports[] = { 0x350, 0x358 }; | 128 | static const int aztech_ioports[] = { 0x350, 0x358 }; |
134 | 129 | ||
135 | static struct radio_isa_driver aztech_driver = { | 130 | static struct radio_isa_driver aztech_driver = { |
136 | .driver = { | 131 | .driver = { |
137 | .match = radio_isa_match, | 132 | .match = radio_isa_match, |
138 | .probe = radio_isa_probe, | 133 | .probe = radio_isa_probe, |
139 | .remove = radio_isa_remove, | 134 | .remove = radio_isa_remove, |
140 | .driver = { | 135 | .driver = { |
141 | .name = "radio-aztech", | 136 | .name = "radio-aztech", |
142 | }, | 137 | }, |
143 | }, | 138 | }, |
144 | .io_params = io, | 139 | .io_params = io, |
145 | .radio_nr_params = radio_nr, | 140 | .radio_nr_params = radio_nr, |
146 | .io_ports = aztech_ioports, | 141 | .io_ports = aztech_ioports, |
147 | .num_of_io_ports = ARRAY_SIZE(aztech_ioports), | 142 | .num_of_io_ports = ARRAY_SIZE(aztech_ioports), |
148 | .region_size = 8, | 143 | .region_size = 8, |
149 | .card = "Aztech Radio", | 144 | .card = "Aztech Radio", |
150 | .ops = &aztech_ops, | 145 | .ops = &aztech_ops, |
151 | .has_stereo = true, | 146 | .has_stereo = true, |
152 | .max_volume = 3, | 147 | .max_volume = 3, |
153 | }; | 148 | }; |
154 | 149 | ||
155 | static int __init aztech_init(void) | 150 | static int __init aztech_init(void) |
156 | { | 151 | { |
157 | return isa_register_driver(&aztech_driver.driver, AZTECH_MAX); | 152 | return isa_register_driver(&aztech_driver.driver, AZTECH_MAX); |
158 | } | 153 | } |
159 | 154 | ||
160 | static void __exit aztech_exit(void) | 155 | static void __exit aztech_exit(void) |
161 | { | 156 | { |
162 | isa_unregister_driver(&aztech_driver.driver); | 157 | isa_unregister_driver(&aztech_driver.driver); |
163 | } | 158 | } |
164 | 159 | ||
165 | module_init(aztech_init); | 160 | module_init(aztech_init); |
166 | module_exit(aztech_exit); | 161 | module_exit(aztech_exit); |