Skip to content

Commit a484147

Browse files
committed
Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media fixes from Mauro Carvalho Chehab: "For bug fixes, at soc_camera, si470x, uvcvideo, iguanaworks IR driver, radio_shark Kbuild fixes, and at the V4L2 core (radio fixes)." * 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: [media] media: soc_camera: don't clear pix->sizeimage in JPEG mode [media] media: mx2_camera: Fix clock handling for i.MX27 [media] video: mx2_camera: Use clk_prepare_enable/clk_disable_unprepare [media] video: mx1_camera: Use clk_prepare_enable/clk_disable_unprepare [media] media: mx3_camera: buf_init() add buffer state check [media] radio-shark2: Only compile led support when CONFIG_LED_CLASS is set [media] radio-shark: Only compile led support when CONFIG_LED_CLASS is set [media] radio-shark*: Call cancel_work_sync from disconnect rather then release [media] radio-shark*: Remove work-around for dangling pointer in usb intfdata [media] Add USB dependency for IguanaWorks USB IR Transceiver [media] Add missing logging for rangelow/high of hwseek [media] VIDIOC_ENUM_FREQ_BANDS fix [media] mem2mem_testdev: fix querycap regression [media] si470x: v4l2-compliance fixes [media] DocBook: Remove a spurious character [media] uvcvideo: Reset the bytesused field when recycling an erroneous buffer
2 parents 8f8ba75 + 991b313 commit a484147

File tree

15 files changed

+217
-179
lines changed

15 files changed

+217
-179
lines changed

Documentation/DocBook/media/v4l/vidioc-g-tuner.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ the structure refers to a radio tuner the
125125
<constant>V4L2_TUNER_CAP_NORM</constant> flags can't be used.</para>
126126
<para>If multiple frequency bands are supported, then
127127
<structfield>capability</structfield> is the union of all
128-
<structfield>capability></structfield> fields of each &v4l2-frequency-band;.
128+
<structfield>capability</structfield> fields of each &v4l2-frequency-band;.
129129
</para></entry>
130130
</row>
131131
<row>

drivers/media/radio/radio-shark.c

Lines changed: 78 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
#include <media/v4l2-device.h>
3636
#include <sound/tea575x-tuner.h>
3737

38+
#if defined(CONFIG_LEDS_CLASS) || \
39+
(defined(CONFIG_LEDS_CLASS_MODULE) && defined(CONFIG_RADIO_SHARK_MODULE))
40+
#define SHARK_USE_LEDS 1
41+
#endif
42+
3843
/*
3944
* Version Information
4045
*/
@@ -56,44 +61,18 @@ MODULE_LICENSE("GPL");
5661

5762
enum { BLUE_LED, BLUE_PULSE_LED, RED_LED, NO_LEDS };
5863

59-
static void shark_led_set_blue(struct led_classdev *led_cdev,
60-
enum led_brightness value);
61-
static void shark_led_set_blue_pulse(struct led_classdev *led_cdev,
62-
enum led_brightness value);
63-
static void shark_led_set_red(struct led_classdev *led_cdev,
64-
enum led_brightness value);
65-
66-
static const struct led_classdev shark_led_templates[NO_LEDS] = {
67-
[BLUE_LED] = {
68-
.name = "%s:blue:",
69-
.brightness = LED_OFF,
70-
.max_brightness = 127,
71-
.brightness_set = shark_led_set_blue,
72-
},
73-
[BLUE_PULSE_LED] = {
74-
.name = "%s:blue-pulse:",
75-
.brightness = LED_OFF,
76-
.max_brightness = 255,
77-
.brightness_set = shark_led_set_blue_pulse,
78-
},
79-
[RED_LED] = {
80-
.name = "%s:red:",
81-
.brightness = LED_OFF,
82-
.max_brightness = 1,
83-
.brightness_set = shark_led_set_red,
84-
},
85-
};
86-
8764
struct shark_device {
8865
struct usb_device *usbdev;
8966
struct v4l2_device v4l2_dev;
9067
struct snd_tea575x tea;
9168

69+
#ifdef SHARK_USE_LEDS
9270
struct work_struct led_work;
9371
struct led_classdev leds[NO_LEDS];
9472
char led_names[NO_LEDS][32];
9573
atomic_t brightness[NO_LEDS];
9674
unsigned long brightness_new;
75+
#endif
9776

9877
u8 *transfer_buffer;
9978
u32 last_val;
@@ -175,20 +154,13 @@ static struct snd_tea575x_ops shark_tea_ops = {
175154
.read_val = shark_read_val,
176155
};
177156

157+
#ifdef SHARK_USE_LEDS
178158
static void shark_led_work(struct work_struct *work)
179159
{
180160
struct shark_device *shark =
181161
container_of(work, struct shark_device, led_work);
182162
int i, res, brightness, actual_len;
183163

184-
/*
185-
* We use the v4l2_dev lock and registered bit to ensure the device
186-
* does not get unplugged and unreffed while we're running.
187-
*/
188-
mutex_lock(&shark->tea.mutex);
189-
if (!video_is_registered(&shark->tea.vd))
190-
goto leave;
191-
192164
for (i = 0; i < 3; i++) {
193165
if (!test_and_clear_bit(i, &shark->brightness_new))
194166
continue;
@@ -208,8 +180,6 @@ static void shark_led_work(struct work_struct *work)
208180
v4l2_err(&shark->v4l2_dev, "set LED %s error: %d\n",
209181
shark->led_names[i], res);
210182
}
211-
leave:
212-
mutex_unlock(&shark->tea.mutex);
213183
}
214184

215185
static void shark_led_set_blue(struct led_classdev *led_cdev,
@@ -245,19 +215,78 @@ static void shark_led_set_red(struct led_classdev *led_cdev,
245215
schedule_work(&shark->led_work);
246216
}
247217

218+
static const struct led_classdev shark_led_templates[NO_LEDS] = {
219+
[BLUE_LED] = {
220+
.name = "%s:blue:",
221+
.brightness = LED_OFF,
222+
.max_brightness = 127,
223+
.brightness_set = shark_led_set_blue,
224+
},
225+
[BLUE_PULSE_LED] = {
226+
.name = "%s:blue-pulse:",
227+
.brightness = LED_OFF,
228+
.max_brightness = 255,
229+
.brightness_set = shark_led_set_blue_pulse,
230+
},
231+
[RED_LED] = {
232+
.name = "%s:red:",
233+
.brightness = LED_OFF,
234+
.max_brightness = 1,
235+
.brightness_set = shark_led_set_red,
236+
},
237+
};
238+
239+
static int shark_register_leds(struct shark_device *shark, struct device *dev)
240+
{
241+
int i, retval;
242+
243+
INIT_WORK(&shark->led_work, shark_led_work);
244+
for (i = 0; i < NO_LEDS; i++) {
245+
shark->leds[i] = shark_led_templates[i];
246+
snprintf(shark->led_names[i], sizeof(shark->led_names[0]),
247+
shark->leds[i].name, shark->v4l2_dev.name);
248+
shark->leds[i].name = shark->led_names[i];
249+
retval = led_classdev_register(dev, &shark->leds[i]);
250+
if (retval) {
251+
v4l2_err(&shark->v4l2_dev,
252+
"couldn't register led: %s\n",
253+
shark->led_names[i]);
254+
return retval;
255+
}
256+
}
257+
return 0;
258+
}
259+
260+
static void shark_unregister_leds(struct shark_device *shark)
261+
{
262+
int i;
263+
264+
for (i = 0; i < NO_LEDS; i++)
265+
led_classdev_unregister(&shark->leds[i]);
266+
267+
cancel_work_sync(&shark->led_work);
268+
}
269+
#else
270+
static int shark_register_leds(struct shark_device *shark, struct device *dev)
271+
{
272+
v4l2_warn(&shark->v4l2_dev,
273+
"CONFIG_LED_CLASS not enabled, LED support disabled\n");
274+
return 0;
275+
}
276+
static inline void shark_unregister_leds(struct shark_device *shark) { }
277+
#endif
278+
248279
static void usb_shark_disconnect(struct usb_interface *intf)
249280
{
250281
struct v4l2_device *v4l2_dev = usb_get_intfdata(intf);
251282
struct shark_device *shark = v4l2_dev_to_shark(v4l2_dev);
252-
int i;
253283

254284
mutex_lock(&shark->tea.mutex);
255285
v4l2_device_disconnect(&shark->v4l2_dev);
256286
snd_tea575x_exit(&shark->tea);
257287
mutex_unlock(&shark->tea.mutex);
258288

259-
for (i = 0; i < NO_LEDS; i++)
260-
led_classdev_unregister(&shark->leds[i]);
289+
shark_unregister_leds(shark);
261290

262291
v4l2_device_put(&shark->v4l2_dev);
263292
}
@@ -266,7 +295,6 @@ static void usb_shark_release(struct v4l2_device *v4l2_dev)
266295
{
267296
struct shark_device *shark = v4l2_dev_to_shark(v4l2_dev);
268297

269-
cancel_work_sync(&shark->led_work);
270298
v4l2_device_unregister(&shark->v4l2_dev);
271299
kfree(shark->transfer_buffer);
272300
kfree(shark);
@@ -276,7 +304,7 @@ static int usb_shark_probe(struct usb_interface *intf,
276304
const struct usb_device_id *id)
277305
{
278306
struct shark_device *shark;
279-
int i, retval = -ENOMEM;
307+
int retval = -ENOMEM;
280308

281309
shark = kzalloc(sizeof(struct shark_device), GFP_KERNEL);
282310
if (!shark)
@@ -286,17 +314,13 @@ static int usb_shark_probe(struct usb_interface *intf,
286314
if (!shark->transfer_buffer)
287315
goto err_alloc_buffer;
288316

289-
/*
290-
* Work around a bug in usbhid/hid-core.c, where it leaves a dangling
291-
* pointer in intfdata causing v4l2-device.c to not set it. Which
292-
* results in usb_shark_disconnect() referencing the dangling pointer
293-
*
294-
* REMOVE (as soon as the above bug is fixed, patch submitted)
295-
*/
296-
usb_set_intfdata(intf, NULL);
317+
v4l2_device_set_name(&shark->v4l2_dev, DRV_NAME, &shark_instance);
318+
319+
retval = shark_register_leds(shark, &intf->dev);
320+
if (retval)
321+
goto err_reg_leds;
297322

298323
shark->v4l2_dev.release = usb_shark_release;
299-
v4l2_device_set_name(&shark->v4l2_dev, DRV_NAME, &shark_instance);
300324
retval = v4l2_device_register(&intf->dev, &shark->v4l2_dev);
301325
if (retval) {
302326
v4l2_err(&shark->v4l2_dev, "couldn't register v4l2_device\n");
@@ -320,32 +344,13 @@ static int usb_shark_probe(struct usb_interface *intf,
320344
goto err_init_tea;
321345
}
322346

323-
INIT_WORK(&shark->led_work, shark_led_work);
324-
for (i = 0; i < NO_LEDS; i++) {
325-
shark->leds[i] = shark_led_templates[i];
326-
snprintf(shark->led_names[i], sizeof(shark->led_names[0]),
327-
shark->leds[i].name, shark->v4l2_dev.name);
328-
shark->leds[i].name = shark->led_names[i];
329-
/*
330-
* We don't fail the probe if we fail to register the leds,
331-
* because once we've called snd_tea575x_init, the /dev/radio0
332-
* node may be opened from userspace holding a reference to us!
333-
*
334-
* Note we cannot register the leds first instead as
335-
* shark_led_work depends on the v4l2 mutex and registered bit.
336-
*/
337-
retval = led_classdev_register(&intf->dev, &shark->leds[i]);
338-
if (retval)
339-
v4l2_err(&shark->v4l2_dev,
340-
"couldn't register led: %s\n",
341-
shark->led_names[i]);
342-
}
343-
344347
return 0;
345348

346349
err_init_tea:
347350
v4l2_device_unregister(&shark->v4l2_dev);
348351
err_reg_dev:
352+
shark_unregister_leds(shark);
353+
err_reg_leds:
349354
kfree(shark->transfer_buffer);
350355
err_alloc_buffer:
351356
kfree(shark);

0 commit comments

Comments
 (0)