linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacek Anaszewski <j.anaszewski@samsung.com>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	kyungmin.park@samsung.com, b.zolnierkie@samsung.com,
	Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash
Date: Thu, 14 Aug 2014 10:25:28 +0200	[thread overview]
Message-ID: <53EC7278.6040101@samsung.com> (raw)
In-Reply-To: <20140814043436.GM16460@valkosipuli.retiisi.org.uk>

On 08/14/2014 06:34 AM, Sakari Ailus wrote:
> Hi Jacek,
>
> On Mon, Aug 11, 2014 at 03:27:22PM +0200, Jacek Anaszewski wrote:
>
> ...
>
>>>>>> diff --git a/include/media/v4l2-flash.h b/include/media/v4l2-flash.h
>>>>>> new file mode 100644
>>>>>> index 0000000..effa46b
>>>>>> --- /dev/null
>>>>>> +++ b/include/media/v4l2-flash.h
>>>>>> @@ -0,0 +1,137 @@
>>>>>> +/*
>>>>>> + * V4L2 Flash LED sub-device registration helpers.
>>>>>> + *
>>>>>> + *	Copyright (C) 2014 Samsung Electronics Co., Ltd
>>>>>> + *	Author: Jacek Anaszewski <j.anaszewski@samsung.com>
>>>>>> + *
>>>>>> + * This program is free software; you can redistribute it and/or modify
>>>>>> + * it under the terms of the GNU General Public License version 2 as
>>>>>> + * published by the Free Software Foundation."
>>>>>> + */
>>>>>> +
>>>>>> +#ifndef _V4L2_FLASH_H
>>>>>> +#define _V4L2_FLASH_H
>>>>>> +
>>>>>> +#include <media/v4l2-ctrls.h>
>>>>>> +#include <media/v4l2-device.h>
>>>>>> +#include <media/v4l2-dev.h>le
>>>>>> +#include <media/v4l2-event.h>
>>>>>> +#include <media/v4l2-ioctl.h>
>>>>>> +
>>>>>> +struct led_classdev_flash;
>>>>>> +struct led_classdev;
>>>>>> +enum led_brightness;
>>>>>> +
>>>>>> +struct v4l2_flash_ops {
>>>>>> +	int (*torch_brightness_set)(struct led_classdev *led_cdev,
>>>>>> +					enum led_brightness brightness);
>>>>>> +	int (*torch_brightness_update)(struct led_classdev *led_cdev);
>>>>>> +	int (*flash_brightness_set)(struct led_classdev_flash *flash,
>>>>>> +					u32 brightness);
>>>>>> +	int (*flash_brightness_update)(struct led_classdev_flash *flash);
>>>>>> +	int (*strobe_set)(struct led_classdev_flash *flash, bool state);
>>>>>> +	int (*strobe_get)(struct led_classdev_flash *flash, bool *state);
>>>>>> +	int (*timeout_set)(struct led_classdev_flash *flash, u32 timeout);
>>>>>> +	int (*indicator_brightness_set)(struct led_classdev_flash *flash,
>>>>>> +					u32 brightness);
>>>>>> +	int (*indicator_brightness_update)(struct led_classdev_flash *flash);
>>>>>> +	int (*external_strobe_set)(struct led_classdev_flash *flash,
>>>>>> +					bool enable);
>>>>>> +	int (*fault_get)(struct led_classdev_flash *flash, u32 *fault);
>>>>>> +	void (*sysfs_lock)(struct led_classdev *led_cdev);
>>>>>> +	void (*sysfs_unlock)(struct led_classdev *led_cdev);
>>>>>
>>>>> These functions are not driver specific and there's going to be just one
>>>>> implementation (I suppose). Could you refresh my memory regarding why
>>>>> the LED framework functions aren't called directly?
>>>>
>>>> These ops are required to make possible building led-class-flash as
>>>> a kernel module.
>>>
>>> Assuming you'd use the actual implementation directly, what would be the
>>> dependencies? I don't think the LED flash framework has any callbacks
>>> towards the V4L2 (LED) flash framework, does it? Please correct my
>>> understanding if I'm missing something. In Makefile format, assume all
>>> targets are .PHONY:
>>>
>>> led-flash-api: led-api
>>>
>>> v4l2-flash: led-flash-api
>>>
>>> driver: led-flash-api v4l2-flash
>>
>> LED Class Flash driver gains V4L2 Flash API when
>> CONFIG_V4L2_FLASH_LED_CLASS is defined. This is accomplished in
>> the probe function by either calling v4l2_flash_init function
>> or the macro of this name, when the CONFIG_V4L2_FLASH_LED_CLASS
>> macro isn't defined.
>>
>> If the v4l2-flash.c was to call the LED API directly, then the
>> led-class-flash module symbols would have to be available at
>> v4l2-flash.o linking time.
>
> Is this an issue? EXPORT_SYMBOL_GPL() for the relevant symbols should be
> enough.

It isn't enough. If I call e.g. led_set_flash_brightness
directly from v4l2-flash.c and configure led-class-flash to be built as
a module then I am getting "undefined reference to
led_set_flash_brightness" error during linking phase.

It happens because the linker doesn't take into account
led-flash-class.ko symbols. It is reasonable because initially
the kernel boots up without led-flash-class.ko module and
the processor wouldn't know the address to jump to in the
result of calling a led API function.
The led-class-flash.ko binary code is loaded into memory not
sooner than after executing "insmod led-class-flash.ko".

After linking dynamically with kernel the LED API function
addresses are relocated, and the LED Flash Class core can
initialize the v4l2_flash_ops structure. Then every LED Flash Class
driver can obtain the address of this structure with
led_get_v4l2_flash_ops and pass it to the v4l2_flash_init.

>> This requirement cannot be met if the led-class-flash is built
>> as a module.
>>
>> Use of function pointers in the v4l2-flash.c allows to compile it
>> into the kernel and enables the possibility of adding the V4L2 Flash
>> support conditionally, during driver probing.
>
> I'd simply decide this during kernel compilation time. If you want
> something, just enable it. v4l2_flash_init() is called directly by the
> driver in any case, so unless that is also called through a wrapper the
> driver is still directly dependent on it.

The problem is that v4l2-flash.o would have to depend on
led-class-flash.o, which when built as a module isn't available
during v4l2-flash.o linking time. In order to avoid v4l2-flash.o linking
problem, it would have to be built as a module.

Nevertheless, in this arrangement, the CONFIG_V4L2_FLASH_LED_CLASS
macro would be defined only in v4l2-flash.ko module, and
a LED Flash Class driver couldn't check whether V4L2 Flash support
is enabled. Its dependence on v4l2-flash.o would have to be fixed,
which is not what we want.

I have tested all these cases.

Best Regards,
Jacek Anaszewski

  reply	other threads:[~2014-08-14  8:25 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-11 14:04 [PATCH/RFC v4 00/21] LED / flash API integration Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 01/21] leds: make brightness type consistent across whole subsystem Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 02/21] leds: implement sysfs interface locking mechanism Jacek Anaszewski
2014-07-16 15:35   ` Sakari Ailus
2014-07-11 14:04 ` [PATCH/RFC v4 03/21] leds: Improve and export led_update_brightness Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 04/21] leds: Reorder include directives Jacek Anaszewski
2014-07-16 15:42   ` Sakari Ailus
2014-07-11 14:04 ` [PATCH/RFC v4 05/21] leds: avoid using deprecated DEVICE_ATTR macro Jacek Anaszewski
2014-07-16 15:46   ` Sakari Ailus
2014-07-11 14:04 ` [PATCH/RFC v4 06/21] leds: add API for setting torch brightness Jacek Anaszewski
2014-07-16 21:54   ` Sakari Ailus
2014-08-04 12:35     ` Jacek Anaszewski
2014-08-04 12:50       ` Sakari Ailus
2014-08-07 13:12         ` Jacek Anaszewski
2014-08-14  4:39           ` Sakari Ailus
2014-08-18 19:55             ` Richard Purdie
2014-08-18 20:06               ` Sakari Ailus
2014-07-11 14:04 ` [PATCH/RFC v4 07/21] of: add of_node_ncmp wrapper Jacek Anaszewski
2014-07-16 22:00   ` Sakari Ailus
2014-07-28 13:41   ` Grant Likely
2014-07-11 14:04 ` [PATCH/RFC v4 08/21] leds: Add sysfs and kernel internal API for flash LEDs Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 09/21] Documentation: leds: Add description of LED Flash Class extension Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 10/21] Documentation: leds: add exemplary asynchronous mux driver Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 11/21] DT: leds: Add flash led devices related properties Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 12/21] DT: Add documentation for LED Class Flash Manger Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 13/21] v4l2-device: add v4l2_device_register_subdev_node API Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 14/21] v4l2-ctrls: add control for flash strobe signal providers Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash Jacek Anaszewski
2014-07-21 11:12   ` Sakari Ailus
2014-08-04 14:43     ` Jacek Anaszewski
2014-08-11 12:26       ` Sakari Ailus
2014-08-11 13:27         ` Jacek Anaszewski
2014-08-11 13:45           ` Jacek Anaszewski
2014-08-14  4:34           ` Sakari Ailus
2014-08-14  8:25             ` Jacek Anaszewski [this message]
2014-08-20 14:41               ` Sakari Ailus
2014-08-21  8:38                 ` Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 16/21] leds: Add support for max77693 mfd flash cell Jacek Anaszewski
2014-07-21 14:12   ` Sakari Ailus
2014-07-11 14:04 ` [PATCH/RFC v4 17/21] DT: Add documentation for the mfd Maxim max77693 Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 18/21] leds: Add driver for AAT1290 current regulator Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 19/21] of: Add Skyworks Solutions, Inc. vendor prefix Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 20/21] DT: Add documentation for the Skyworks AAT1290 Jacek Anaszewski
2014-07-11 14:04 ` [PATCH/RFC v4 21/21] ARM: dts: add aat1290 current regulator device node Jacek Anaszewski
2014-07-16 17:19 ` [PATCH/RFC v4 00/21] LED / flash API integration Bryan Wu
2014-07-16 17:21   ` Bryan Wu
2014-08-08  6:43     ` Jacek Anaszewski
2014-08-08 16:59       ` Bryan Wu
2014-08-11 14:24         ` Jacek Anaszewski
2014-08-06  6:53 ` Sakari Ailus
2014-08-07  8:21   ` Jacek Anaszewski
2014-08-07  8:31     ` Jacek Anaszewski
2014-08-14  5:03     ` Sakari Ailus
2014-08-14 10:35       ` Jacek Anaszewski
2014-08-15  4:48         ` Sakari Ailus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53EC7278.6040101@samsung.com \
    --to=j.anaszewski@samsung.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hans.verkuil@cisco.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=sakari.ailus@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).