[PATCH net] rxrpc: Wake up the transmitter if Rx window size increases on the peer

2017-03-09 Thread David Howells
The RxRPC ACK packet may contain an extension that includes the peer's
current Rx window size for this call.  We adjust the local Tx window size
to match.  However, the transmitter can stall if the receive window is
reduced to 0 by the peer and then reopened.

This is because the normal way that the transmitter is re-energised is by
dropping something out of our Tx queue and thus making space.  When a
single gap is made, the transmitter is woken up.  However, because there's
nothing in the Tx queue at this point, this doesn't happen.

To fix this, perform a wake_up() any time we see the peer's Rx window size
increasing.

The observable symptom is that calls start failing on ETIMEDOUT and the
following:

kAFS: SERVER DEAD state=-62

appears in dmesg.

Signed-off-by: David Howells 
---

 net/rxrpc/input.c |   15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/net/rxrpc/input.c b/net/rxrpc/input.c
index d74921c4969b..18b2ad8be8e2 100644
--- a/net/rxrpc/input.c
+++ b/net/rxrpc/input.c
@@ -652,6 +652,7 @@ static void rxrpc_input_ackinfo(struct rxrpc_call *call, 
struct sk_buff *skb,
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
struct rxrpc_peer *peer;
unsigned int mtu;
+   bool wake = false;
u32 rwind = ntohl(ackinfo->rwind);
 
_proto("Rx ACK %%%u Info { rx=%u max=%u rwin=%u jm=%u }",
@@ -659,9 +660,14 @@ static void rxrpc_input_ackinfo(struct rxrpc_call *call, 
struct sk_buff *skb,
   ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU),
   rwind, ntohl(ackinfo->jumbo_max));
 
-   if (rwind > RXRPC_RXTX_BUFF_SIZE - 1)
-   rwind = RXRPC_RXTX_BUFF_SIZE - 1;
-   call->tx_winsize = rwind;
+   if (call->tx_winsize != rwind) {
+   if (rwind > RXRPC_RXTX_BUFF_SIZE - 1)
+   rwind = RXRPC_RXTX_BUFF_SIZE - 1;
+   if (rwind > call->tx_winsize)
+   wake = true;
+   call->tx_winsize = rwind;
+   }
+
if (call->cong_ssthresh > rwind)
call->cong_ssthresh = rwind;
 
@@ -675,6 +681,9 @@ static void rxrpc_input_ackinfo(struct rxrpc_call *call, 
struct sk_buff *skb,
spin_unlock_bh(&peer->lock);
_net("Net MTU %u (maxdata %u)", peer->mtu, peer->maxdata);
}
+
+   if (wake)
+   wake_up(&call->waitq);
 }
 
 /*



Re: [PATCH] powerpc: asm: convert directive .llong to .8byte

2017-03-09 Thread Michael Ellerman
Daniel Axtens  writes:

> Hi Tobin,
>
>> .llong is an undocumented PPC specific directive. The generic
>> equivalent is .quad, but even better (because it's self describing) is
>> .8byte.
>>
>> Convert directives .llong -> .8byte
>>
>> Signed-off-by: Tobin C. Harding 
>> ---
>>
>> Fixes: issue #33 (github)
>
> Thanks for tackling these!
>
> I have applied your patch to my local tree. I ran `git grep '\.llong'`,
> and found:
>
> tools/testing/selftests/powerpc/switch_endian/switch_endian_test.S: .llong 
> 0x
>
> That file is also handled by mpe and the powerpc tree even though it
> doesn't live in arch/powerpc - could you please change that one as well?

I can do that one when I apply it.

cheers


Re: [RFC] mm/compaction: ignore block suitable after check large free page

2017-03-09 Thread Vlastimil Babka
On 03/10/2017 05:20 AM, Yisheng Xie wrote:
> If the migrate target is a large free page and we ignore suitable,
> it may not good for defrag. So move the ignore block suitable after
> check large free page.

Right. But in practice I expect close to no impact, because direct
compaction shouldn't have to be called if there's a >=pageblock_order
page already available.

> Signed-off-by: Yisheng Xie 
> ---
>  mm/compaction.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/compaction.c b/mm/compaction.c
> index 0fdfde0..4bf2a5d 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -991,9 +991,6 @@ static bool too_many_isolated(struct zone *zone)
>  static bool suitable_migration_target(struct compact_control *cc,
>   struct page *page)
>  {
> - if (cc->ignore_block_suitable)
> - return true;
> -
>   /* If the page is a large free page, then disallow migration */
>   if (PageBuddy(page)) {
>   /*
> @@ -1005,6 +1002,9 @@ static bool suitable_migration_target(struct 
> compact_control *cc,
>   return false;
>   }
>  
> + if (cc->ignore_block_suitable)
> + return true;
> +
>   /* If the block is MIGRATE_MOVABLE or MIGRATE_CMA, allow migration */
>   if (migrate_async_suitable(get_pageblock_migratetype(page)))
>   return true;
> 



Re: [PATCH v2 1/2] doc: bindings: Add bindings documentation for mtd nvmem

2017-03-09 Thread Marek Vasut
On 03/10/2017 07:38 AM, Maxime Ripard wrote:
> Hi Marek,
> 
> On Fri, Mar 10, 2017 at 05:52:36AM +0100, Marek Vasut wrote:
>> On 03/10/2017 05:06 AM, Moritz Fischer wrote:
>>> On Thu, Mar 9, 2017 at 7:17 PM, Marek Vasut  wrote:
 On 03/07/2017 09:26 AM, Alban wrote:
> Config data for drivers, like MAC addresses, is often stored in MTD.
> Add a binding that define how such data storage can be represented in
> device tree.
>
> Signed-off-by: Alban 
> ---
> Changelog:
> v2: * Added a "Required properties" section with the nvmem-provider
>   property
> ---
>  .../devicetree/bindings/nvmem/mtd-nvmem.txt| 33 
> ++
>  1 file changed, 33 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
>
> diff --git a/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt 
> b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
> new file mode 100644
> index 000..8ed25e6
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
> @@ -0,0 +1,33 @@
> += NVMEM in MTD =
> +
> +Config data for drivers, like MAC addresses, is often stored in MTD.
> +This binding define how such data storage can be represented in device 
> tree.
> +
> +An MTD can be defined as an NVMEM provider by adding the `nvmem-provider`
> +property to their node. Data cells can then be defined as child nodes
> +of the partition as defined in nvmem.txt.

 Why don't we just read the data from MTD and be done with it ? What's
 the benefit of complicating things by using nvmem ?
>>>
>>> Well because usually stuff like MAC addresses etc are stored in eeproms.
>>
>> But eeproms are already supported, see drivers/misc/ .
> 
> This the old, free for all, way to support eeproms. We have a proper
> framework for them now, and it's called nvmem.

Ha, so that's why this patchset, I see. Thanks for clarifying.

-- 
Best regards,
Marek Vasut


Re: [PATCH] refcount: add refcount_t API kernel-doc comments

2017-03-09 Thread Ingo Molnar

* David Windsor  wrote:

> This adds kernel-doc comments for the new refcount_t API.
> 
> v2: incorporate fixes from Peter Zijlstra and Ingo Molnar
> 
> Signed-off-by: David Windsor 
> ---
>  lib/refcount.c | 122 
> +++--
>  1 file changed, 110 insertions(+), 12 deletions(-)

Patch does not apply cleanly anymore, could you please merge it to Linus's 
latest 
and resend?

Thanks!

Ingo


Re: [GIT pull] CPU hotplug updates for 4.9

2017-03-09 Thread Ingo Molnar

* Bart Van Assche  wrote:

> On Thu, 2017-03-09 at 18:43 +0100, Thomas Gleixner wrote:
> > Ok, so it's random. Now it would be interesting what the rest of the system
> > does when this happens. I still have no idea why that IOAT setting has any
> > influence.
> 
> Hello Thomas,
> 
> The cpuhp_issue_call() hang happens during boot and before I get the chance 
> to log
> in with ssh. Can you be more specific about what information you are looking 
> for?
> 
> Anyway, the result of a new bisect I ran is as follows:
> * good: 631ddaba5905 ("Merge branches 'pm-sleep' and 'powercap'").
> * good: 80f1b3dea9d4 ("Merge branch 'device-properties'").
> * bad:  a67485d4bf97 ("Merge tag 'acpi-4.10-rc1' of
>   git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm").
> 
> Does this make sense to you?

The bisection information is really useful, if the failure mode is 
deterministic.

It would be nice to have more bisection points, the above range is about 5,000 
commits.

Thanks,

Ingo


Re: [PATCH 1/2] x86/nmi: Optimize the check for being in the repeat_nmi code

2017-03-09 Thread Ingo Molnar

* Andy Lutomirski  wrote:

> > It had nothing to do with speedup. Linus said that the current code makes 
> > the 
> > assembly programmer in him die a little. I want to cure that.
> 
> One might argue that the world would be a better place if the assembly 
> programmer in some people died a little.

Joking aside, I'll bite: while in the kernel we try to avoid ever actually 
_writing_ new assembly code, assembly programming is still an invaluable skill, 
because it indirectly improves all the other 99% of non-assembly .c code:

 - Looking at the C compiler's assembly output tells us how close the code is to
   optimal.

 - Being able to tell whether our C abstractions are too far removed from how 
the
   compiler will map it to machine instructions is invaluable.

 - Being able to shape data structures and code in a machine-friendly way.

Much would be lost if the assembly programmer went extinct and it's no 
accident that annotated assembly output is just two  keys away
after launching 'perf top' or 'perf report'. The more developers know
assembly the better, IMHO.

Thanks,

Ingo


Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotation

2017-03-09 Thread Baolin Wang
On 10 March 2017 at 14:30, Jun Li  wrote:
>> >> >
>> >> > Will generic phy need add extcon as well?
>> >>
>> >> Yes, will add a 'struct extcon_dev*' in 'struct usb_phy', which will
>> >> be common code.
>> >>
>> >
>> > I mean the common code need add 'struct extcon_dev' into both 'struct
>> > phy' and 'struct usb_phy', right? as some/new usb phy use that generic phy
>> driver.
>>
>> Ah, you remind me. Seems we need also add one 'struct extcon_dev' into
>> 'struct phy'.
>>
>> >> >
>> >> >> >
>> >> >> >> Secondly, I also agreed with Peter's comments: Not only USB PHY
>> >> >> >> to register an extcon, but also for the drivers which can
>> >> >> >> detect USB charger type, it may be USB controller driver, USB
>> >> >> >> type-c driver, pmic driver, and these drivers may not have an
>> >> >> >> extcon device since the internal part can finish the vbus detect.
>> >> >> >
>> >> >> > Whichever part can detect vbus, the driver for that part must be
>> >> >> > able to find the extcon and trigger a notification.
>> >> >> > Maybe one part can detect VBUS, another can measure the
>> >> >> > resistance on ID and a third can work through the state machine
>> >> >> > to determine if D+ and D- are shorted together.
>> >> >> > Somehow these three need to work together to determine what is
>> >> >> plugged
>> >> >> > in to the external connection port.  Somewhere there much an
>> 'extcon'
>> >> >> > device which represents that port and which the three devices
>> >> >> > can find and can interact with.
>> >> >> > I think it makes sense for the usb_phy to be the connection point.
>> >> >> > Each of the devices can get to the phy, and the phy can get to
>> >> >> > the
>> >> extcon.
>> >> >> > It doesn't matter very much if the usb phy driver creates the
>> >> >> > extcon, or if something else creates the extcon and the phy
>> >> >> > driver performs a lookup to find it (e.g. based on devicetree info).
>> >> >> >
>> >> >> > The point is that there is obviously an external physical
>> >> >> > connection, and so there should be an 'extcon' device that
>> represents it.
>> >> >>
>> >> >> Peter & Jun, is it OK for you every phy has one extcon device to
>> >> >> receive VBUS notification, especially for detecting the charger
>> >> >> type by
>> >> software?
>> >> >>
>> >> >
>> >> > My understanding is phy/usb_phy as the connection point, will send
>> >> > the notification to PMIC driver which actually control the charge
>> >> > current, also this will be done in your common framework, right?
>> >>
>> >> Not in USB charger framework. If we are all agree every usb_phy can
>> >> register one extcon device, can get correct charger type and send out
>> >> correct vbus_draw information, then we don't need USB charger
>> >> framework as Neil suggested. So this will be okay for your case
>> >> (especially for detecting the charger type by software) ?
>> >
>> > In my case, charger detection is done by controller driver and I need
>> > do charger type detection internally, and only pass the current draw
>> > info via phy which will send out, this seems ok for me, but I think it
>> > will be good if you or someone can show us an example user based on the
>> design Neil suggested.
>> > Will you work out that common code if this USB charger framework is not
>> needed?
>>
>> I will add  a 'struct extcon_dev*' in 'struct usb_phy' and struct phy“. 
>> Others
>> are already ready if everyone has no complain about current design, except
>
> Only adding extcon_dev into usb_phy/phy  and all others are ready?
> My understanding you will also do:
> - We need find a central place to send the notification(phy common part).

That will include these implementation when adding extcon_dev.

> - If the extcon_dev is directly added in usb_phy/phy, PMIC needs some API to 
> findup it.

PMIC can find extcon device by phandle.

>
>> my one concern. (I am afraid if it is enough to send out vbus draw
>> information from USB phy driver, for example you will miss super speed
>> (900mA), which need get the speed information from gadget driver.)
>>
>
> Can we handle this in USB(so has super speed information) and just send out
> 900mA directly?

>From Neil's suggestion, we only have one place to send out current
information from usb phy, so I have this concern and doubt if we still
need the USB charger framework.

-- 
Baolin.wang
Best Regards


Re: [RFC PATCH] phy: samsung: move the Samsung specific phy files to "samsung" directory

2017-03-09 Thread Jaehoon Chung
Hi All,

On 03/09/2017 09:10 PM, Krzysztof Kozlowski wrote:
> On Thu, Mar 9, 2017 at 1:56 PM, Kishon Vijay Abraham I  wrote:
>> Hi,
>>
>> On Thursday 09 March 2017 05:03 PM, Jaehoon Chung wrote:
>>> Make the "samsung" directory and move the Samsung specific files to
>>> there for maintaining the files relevant to Samsung.
>>
>> The number of phy drivers in drivers/phy is getting unmanageable. I think 
>> this
>> is a good step to make it a little better. Can you also add a MAINTAINER for
>> drivers/phy/samsung?
> 
> There is such:
> 
> 10903 SAMSUNG USB2 PHY DRIVER
> 10904 M:  Kamil Debski 
> 10905 M:  Sylwester Nawrocki 
> 10906 L:  linux-kernel@vger.kernel.org
> 10907 S:  Supported
> 10908 F:  Documentation/devicetree/bindings/phy/samsung-phy.txt
> 10909 F:  Documentation/phy/samsung-usb2.txt
> 10910 F:  drivers/phy/phy-exynos4210-usb2.c
> 10911 F:  drivers/phy/phy-exynos4x12-usb2.c
> 10912 F:  drivers/phy/phy-exynos5250-usb2.c
> 10913 F:  drivers/phy/phy-s5pv210-usb2.c
> 10914 F:  drivers/phy/phy-samsung-usb2.c
> 10915 F:  drivers/phy/phy-samsung-usb2.h
> 
> but this patchset does not update it. Paths *everywhere* have to be updated.

Will update..How about the below updating?
M:  Kamil Debski 
M:  Sylwester Nawrocki 
M:  Jaehoon Chung 
L:  linux-kernel@vger.kernel.org
S:  Supported
F:  Documentation/devicetree/bindings/phy/samsung-phy.txt
F:  Documentation/phy/samsung-usb2.txt
F:  driver/phy/samsung/

Let me know your opinion.

Best Regards,
Jaehoon Chung

> 
> Best regards,
> Krzysztof
> 
> 
> 



Re: [PATCH] sched: Wake up all non-exclusive waiters in __wake_up_common()

2017-03-09 Thread Byungchul Park
On Wed, Mar 08, 2017 at 09:21:52AM +0900, Byungchul Park wrote:
> __wake_up_common() should wake up all non-exclusive waiters and
> exclusive waiters as many as nr_exclusive, but currently it does not.
> 
> Consider a wait queue like the following for example:
> 
>A(exclusive) -> B(non-exclusive) -> C(non-exclusive)
> 
> Current code will wake up only A when nr_exclusive = 1, but has to wake
> up A, B and C. Make it do as we expect.

I'm wondering if I was wrong. Am I wrong?

> 
> Signed-off-by: Byungchul Park 
> ---
>  kernel/sched/wait.c | 15 +--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c
> index 9453efe..0ea1083 100644
> --- a/kernel/sched/wait.c
> +++ b/kernel/sched/wait.c
> @@ -67,12 +67,23 @@ static void __wake_up_common(wait_queue_head_t *q, 
> unsigned int mode,
>  {
>   wait_queue_t *curr, *next;
>  
> + /*
> +  * We use nr_exclusive = 0 to wake up all no matter whether
> +  * WQ_FLAG_EXCLUSIVE is set. However, we have to distinguish
> +  * between the case and having finished all exclusive wake-up.
> +  * So make nr_exclusive non-zero in advance in the former case.
> +  */
> + nr_exclusive = nr_exclusive ?: -1;
> +
>   list_for_each_entry_safe(curr, next, &q->task_list, task_list) {
>   unsigned flags = curr->flags;
>  
> + if ((flags & WQ_FLAG_EXCLUSIVE) && !nr_exclusive)
> + continue;
> +
>   if (curr->func(curr, mode, wake_flags, key) &&
> - (flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
> - break;
> + (flags & WQ_FLAG_EXCLUSIVE))
> + nr_exclusive--;
>   }
>  }
>  
> -- 
> 1.9.1


Re: [PATCH] leds/trigger/activity: add a system activity LED trigger

2017-03-09 Thread Willy Tarreau
Hi Jacek,

On Thu, Mar 09, 2017 at 09:48:39PM +0100, Jacek Anaszewski wrote:
> Hi Willy,
> 
> Thanks for the patch.
> 
> Unfortunately I'm getting following build break, while trying to
> test it on recent linux-next:
> 
> drivers/leds/trigger/ledtrig-activity.c: In function
> 'led_activity_function':
> drivers/leds/trigger/ledtrig-activity.c:67:14: error: implicit
> declaration of function 'cputime64_to_jiffies64'
> [-Werror=implicit-function-declaration]
>   curr_idle = cputime64_to_jiffies64(curr_idle);

Thanks for letting me know, I'll check this ASAP.

Cheers,
Willy


[PATCH] Fix V8 device information issue

2017-03-09 Thread Masaki Ota
From: Masaki Ota 
-Fix the issue that V8(E7=73 03 28) devices are not assined correct device 
information from OTP.
-Specified correct OTP bit for the V8 device setting of Button pad, DualPoint 
and Touchpad size.

Signed-off-by: Masaki Ota 
---
 drivers/input/mouse/alps.c | 74 --
 drivers/input/mouse/alps.h |  6 
 2 files changed, 64 insertions(+), 16 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index e761955..462871c 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -2467,21 +2467,46 @@ static int alps_update_device_area_ss4_v2(unsigned char 
otp[][4],
int num_y_electrode;
int x_pitch, y_pitch, x_phys, y_phys;
 
-   num_x_electrode = SS4_NUMSENSOR_XOFFSET + (otp[1][0] & 0x0F);
-   num_y_electrode = SS4_NUMSENSOR_YOFFSET + ((otp[1][0] >> 4) & 0x0F);
+   if (priv->dev_id[2] == 0x28) {
+   num_x_electrode =
+   SS4PLUS_NUMSENSOR_XOFFSET + (otp[0][2] & 0x0F);
+   num_y_electrode =
+   SS4PLUS_NUMSENSOR_YOFFSET + ((otp[0][2] >> 4) & 0x0F);
 
-   priv->x_max = (num_x_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
-   priv->y_max = (num_y_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+   priv->x_max =
+   (num_x_electrode - 1) * SS4PLUS_COUNT_PER_ELECTRODE;
+   priv->y_max =
+   (num_y_electrode - 1) * SS4PLUS_COUNT_PER_ELECTRODE;
 
-   x_pitch = ((otp[1][2] >> 2) & 0x07) + SS4_MIN_PITCH_MM;
-   y_pitch = ((otp[1][2] >> 5) & 0x07) + SS4_MIN_PITCH_MM;
+   x_pitch = (otp[0][1] & 0x0F) + SS4PLUS_MIN_PITCH_MM;
+   y_pitch = ((otp[0][1] >> 4) & 0x0F) + SS4PLUS_MIN_PITCH_MM;
 
-   x_phys = x_pitch * (num_x_electrode - 1); /* In 0.1 mm units */
-   y_phys = y_pitch * (num_y_electrode - 1); /* In 0.1 mm units */
+   x_phys = x_pitch * (num_x_electrode - 1); /* In 0.1 mm units */
+   y_phys = y_pitch * (num_y_electrode - 1); /* In 0.1 mm units */
 
-   priv->x_res = priv->x_max * 10 / x_phys; /* units / mm */
-   priv->y_res = priv->y_max * 10 / y_phys; /* units / mm */
+   priv->x_res = priv->x_max * 10 / x_phys; /* units / mm */
+   priv->y_res = priv->y_max * 10 / y_phys; /* units / mm */
+
+   } else {
+   num_x_electrode =
+   SS4_NUMSENSOR_XOFFSET + (otp[1][0] & 0x0F);
+   num_y_electrode =
+   SS4_NUMSENSOR_YOFFSET + ((otp[1][0] >> 4) & 0x0F);
+
+   priv->x_max =
+   (num_x_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+   priv->y_max =
+   (num_y_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+
+   x_pitch = ((otp[1][2] >> 2) & 0x07) + SS4_MIN_PITCH_MM;
+   y_pitch = ((otp[1][2] >> 5) & 0x07) + SS4_MIN_PITCH_MM;
 
+   x_phys = x_pitch * (num_x_electrode - 1); /* In 0.1 mm units */
+   y_phys = y_pitch * (num_y_electrode - 1); /* In 0.1 mm units */
+
+   priv->x_res = priv->x_max * 10 / x_phys; /* units / mm */
+   priv->y_res = priv->y_max * 10 / y_phys; /* units / mm */
+   }
return 0;
 }
 
@@ -2490,7 +2515,10 @@ static int alps_update_btn_info_ss4_v2(unsigned char 
otp[][4],
 {
unsigned char is_btnless;
 
-   is_btnless = (otp[1][1] >> 3) & 0x01;
+   if (priv->dev_id[2] == 0x28)
+   is_btnless = (otp[1][0] >> 1) & 0x01;
+   else
+   is_btnless = (otp[1][1] >> 3) & 0x01;
 
if (is_btnless)
priv->flags |= ALPS_BUTTONPAD;
@@ -2498,6 +2526,21 @@ static int alps_update_btn_info_ss4_v2(unsigned char 
otp[][4],
return 0;
 }
 
+static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
+  struct alps_data *priv)
+{
+   unsigned char is_dual = 0;
+
+   if (priv->dev_id[2] == 0x28)
+   is_dual = (otp[0][0] >> 4) & 0x01;
+
+   if (is_dual)
+   priv->flags |= ALPS_DUALPOINT |
+   ALPS_DUALPOINT_WITH_PRESSURE;
+
+   return 0;
+}
+
 static int alps_set_defaults_ss4_v2(struct psmouse *psmouse,
struct alps_data *priv)
 {
@@ -2513,6 +2556,8 @@ static int alps_set_defaults_ss4_v2(struct psmouse 
*psmouse,
 
alps_update_btn_info_ss4_v2(otp, priv);
 
+   alps_update_dual_info_ss4_v2(otp, priv);
+
return 0;
 }
 
@@ -2758,10 +2803,6 @@ static int alps_set_protocol(struct psmouse *psmouse,
if (alps_set_defaults_ss4_v2(psmouse, priv))
return -EIO;
 
-   if (priv->fw_ver[1] == 0x1)
-   priv->flags |= ALPS_DUALPOINT |
-   ALPS_DUALPOINT_WITH_PRESSURE;
-
break;
}
 
@@ -2850,7 +2891,8 @@ static int alps_id

Re: [PATCH v2 1/2] doc: bindings: Add bindings documentation for mtd nvmem

2017-03-09 Thread Maxime Ripard
Hi Marek,

On Fri, Mar 10, 2017 at 05:52:36AM +0100, Marek Vasut wrote:
> On 03/10/2017 05:06 AM, Moritz Fischer wrote:
> > On Thu, Mar 9, 2017 at 7:17 PM, Marek Vasut  wrote:
> >> On 03/07/2017 09:26 AM, Alban wrote:
> >>> Config data for drivers, like MAC addresses, is often stored in MTD.
> >>> Add a binding that define how such data storage can be represented in
> >>> device tree.
> >>>
> >>> Signed-off-by: Alban 
> >>> ---
> >>> Changelog:
> >>> v2: * Added a "Required properties" section with the nvmem-provider
> >>>   property
> >>> ---
> >>>  .../devicetree/bindings/nvmem/mtd-nvmem.txt| 33 
> >>> ++
> >>>  1 file changed, 33 insertions(+)
> >>>  create mode 100644 Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
> >>>
> >>> diff --git a/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt 
> >>> b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
> >>> new file mode 100644
> >>> index 000..8ed25e6
> >>> --- /dev/null
> >>> +++ b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
> >>> @@ -0,0 +1,33 @@
> >>> += NVMEM in MTD =
> >>> +
> >>> +Config data for drivers, like MAC addresses, is often stored in MTD.
> >>> +This binding define how such data storage can be represented in device 
> >>> tree.
> >>> +
> >>> +An MTD can be defined as an NVMEM provider by adding the `nvmem-provider`
> >>> +property to their node. Data cells can then be defined as child nodes
> >>> +of the partition as defined in nvmem.txt.
> >>
> >> Why don't we just read the data from MTD and be done with it ? What's
> >> the benefit of complicating things by using nvmem ?
> > 
> > Well because usually stuff like MAC addresses etc are stored in eeproms.
> 
> But eeproms are already supported, see drivers/misc/ .

This the old, free for all, way to support eeproms. We have a proper
framework for them now, and it's called nvmem.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


signature.asc
Description: PGP signature


RE: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotation

2017-03-09 Thread Jun Li


> -Original Message-
> From: Baolin Wang [mailto:baolin.w...@linaro.org]
> Sent: Thursday, March 09, 2017 7:23 PM
> To: Jun Li 
> Cc: NeilBrown ; Felipe Balbi ; Greg KH
> ; Sebastian Reichel ; Dmitry
> Eremin-Solenikov ; David Woodhouse
> ; r...@kernel.org; Marek Szyprowski
> ; Ruslan Bilovol ;
> Peter Chen ; Alan Stern
> ; grygorii.stras...@ti.com; Yoshihiro Shimoda
> ; Lee Jones ;
> Mark Brown ; John Stultz ;
> Charles Keepax ;
> patc...@opensource.wolfsonmicro.com; Linux PM list  p...@vger.kernel.org>; USB ; device-
> mainlin...@lists.linuxfoundation.org; LKML 
> Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with
> the usb gadget power negotation
> 
> On 9 March 2017 at 18:34, Jun Li  wrote:
> >
> >
> >> -Original Message-
> >> From: Baolin Wang [mailto:baolin.w...@linaro.org]
> >> Sent: Thursday, March 09, 2017 2:11 PM
> >> To: Jun Li 
> >> Cc: NeilBrown ; Felipe Balbi ; Greg
> >> KH ; Sebastian Reichel ;
> >> Dmitry Eremin-Solenikov ; David Woodhouse
> >> ; r...@kernel.org; Marek Szyprowski
> >> ; Ruslan Bilovol
> >> ; Peter Chen ;
> >> Alan Stern ; grygorii.stras...@ti.com;
> >> Yoshihiro Shimoda ; Lee Jones
> >> ; Mark Brown ; John Stultz
> >> ; Charles Keepax
> >> ;
> >> patc...@opensource.wolfsonmicro.com; Linux PM list  >> p...@vger.kernel.org>; USB ; device-
> >> mainlin...@lists.linuxfoundation.org; LKML
> >> 
> >> Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal
> >> with the usb gadget power negotation
> >>
> >> Hi,
> >>
> >> On 9 March 2017 at 09:50, Jun Li  wrote:
> >> > Hi,
> >> >
> >> >> -Original Message-
> >> >> From: Baolin Wang [mailto:baolin.w...@linaro.org]
> >> >> Sent: Tuesday, March 07, 2017 5:39 PM
> >> >> To: NeilBrown 
> >> >> Cc: Felipe Balbi ; Greg KH
> >> >> ; Sebastian Reichel ;
> >> >> Dmitry Eremin-Solenikov ; David
> Woodhouse
> >> >> ; r...@kernel.org; Jun Li ;
> >> >> Marek Szyprowski ; Ruslan Bilovol
> >> >> ; Peter Chen
> ;
> >> >> Alan Stern ; grygorii.stras...@ti.com;
> >> >> Yoshihiro Shimoda ; Lee Jones
> >> >> ; Mark Brown ; John
> >> >> Stultz ; Charles Keepax
> >> >> ;
> >> >> patc...@opensource.wolfsonmicro.com; Linux PM list  >> >> p...@vger.kernel.org>; USB ; device-
> >> >> mainlin...@lists.linuxfoundation.org; LKML
> >> >> 
> >> >> Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to
> >> >> deal with the usb gadget power negotation
> >> >>
> >> >> On 3 March 2017 at 10:23, NeilBrown  wrote:
> >> >> > On Mon, Feb 20 2017, Baolin Wang wrote:
> >> >> >
> >> >> >> Currently the Linux kernel does not provide any standard
> >> >> >> integration of this feature that integrates the USB subsystem
> >> >> >> with the system power regulation provided by PMICs meaning that
> >> >> >> either vendors must add this in their kernels or USB gadget
> >> >> >> devices based on Linux (such as mobile phones) may not behave as
> they should.
> >> >> >> Thus provide a
> >> >> standard framework for doing this in kernel.
> >> >> >>
> >> >> >> Now introduce one user with wm831x_power to support and test
> >> >> >> the usb
> >> >> charger.
> >> >> >> Another user introduced to support charger detection by Jun Li:
> >> >> >> https://www.spinics.net/lists/linux-usb/msg139425.html
> >> >> >> Moreover there may be other potential users will use it in future.
> >> >> >>
> >> >> >> 1. Before v19 patchset we've fixed below issues in extcon
> >> >> >> subsystem and usb phy driver, now all were merged. (Thanks for
> >> >> >> Neil's
> >> >> >> suggestion)
> >> >> >> (1) Have fixed the inconsistencies with USB connector types in
> >> >> >> extcon subsystem by following links:
> >> >> >> https://lkml.org/lkml/2016/12/21/13
> >> >> >> https://lkml.org/lkml/2016/12/21/15
> >> >> >> https://lkml.org/lkml/2016/12/21/79
> >> >> >> https://lkml.org/lkml/2017/1/3/13
> >> >> >>
> >> >> >> (2) Instead of using 'set_power' callback in phy drivers, we
> >> >> >> will introduce USB charger to set PMIC current drawn from USB
> >> >> >> configuration, moreover some 'set_power' callbacks did not
> >> >> >> implement anything to set PMIC current, thus remove them by
> >> following links:
> >> >> >> https://lkml.org/lkml/2017/1/18/436
> >> >> >> https://lkml.org/lkml/2017/1/18/439
> >> >> >> https://lkml.org/lkml/2017/1/18/438
> >> >> >> Now only two phy drivers (phy-isp1301-omap.c and
> >> >> >> phy-gpio-vbus-usb.c) still used 'set_power' callback to set
> >> >> >> current, we can remove them in future. (I have no platform with
> >> >> >> enabling these two phy drivers, so I can not test them if I
> >> >> >> converted 'set_power' callback to USB
> >> >> >> charger.)
> >> >> >>
> >> >> >> 2. Some issues pointed by Neil Brown were sill kept in this v19
> >> >> >> patchset, and I expalined each issue and may be need discuss again:
> >> >> >> (1) Change all usb phys to register an extcon and to send
> >> >> >> appropriate
> >> >> notifications.
> >> >> >> Firstly, now only 3 USB phy drivers (phy-qcom-8x16-usb.c,
> >> >> >> phy-omap

[PATCH v6 09/11] drivers: perf: hisi: Miscellanous node(MN) event counting in perf

2017-03-09 Thread Anurup M
From: Shaokun Zhang 

1. Add support to count MN hardware events.
2. Mn events are listed in sysfs at /sys/devices/hisi_mn_2/events/
   The events can be selected as shown in perf list
   e.g.: For MN_READ_REQUEST event for Super CPU cluster 2 the
   event format is -e "hisi_mn_2/read_req/"

Signed-off-by: Shaokun Zhang 
Signed-off-by: Anurup M 
---
 drivers/perf/hisilicon/Makefile |   2 +-
 drivers/perf/hisilicon/hisi_uncore_mn.c | 489 
 2 files changed, 490 insertions(+), 1 deletion(-)
 create mode 100644 drivers/perf/hisilicon/hisi_uncore_mn.c

diff --git a/drivers/perf/hisilicon/Makefile b/drivers/perf/hisilicon/Makefile
index 0887b56..26b2507 100644
--- a/drivers/perf/hisilicon/Makefile
+++ b/drivers/perf/hisilicon/Makefile
@@ -1 +1 @@
-obj-$(CONFIG_HISI_PMU) += djtag.o hisi_uncore_pmu.o hisi_uncore_l3c.o
+obj-$(CONFIG_HISI_PMU) += djtag.o hisi_uncore_pmu.o hisi_uncore_l3c.o 
hisi_uncore_mn.o
diff --git a/drivers/perf/hisilicon/hisi_uncore_mn.c 
b/drivers/perf/hisilicon/hisi_uncore_mn.c
new file mode 100644
index 000..18316dc
--- /dev/null
+++ b/drivers/perf/hisilicon/hisi_uncore_mn.c
@@ -0,0 +1,489 @@
+/*
+ * HiSilicon SoC MN Hardware event counters support
+ *
+ * Copyright (C) 2017 Hisilicon Limited
+ * Author: Shaokun Zhang 
+ *
+ * This code is based on the uncore PMU's like arm-cci and
+ * arm-ccn.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "hisi_uncore_pmu.h"
+
+/*
+ * ARMv8 HiSilicon MN event types.
+ */
+enum armv8_hisi_mn_event_types {
+   HISI_HWEVENT_MN_EO_BARR_REQ = 0x0,
+   HISI_HWEVENT_MN_EC_BARR_REQ = 0x01,
+   HISI_HWEVENT_MN_DVM_OP_REQ  = 0x02,
+   HISI_HWEVENT_MN_DVM_SYNC_REQ= 0x03,
+   HISI_HWEVENT_MN_READ_REQ= 0x04,
+   HISI_HWEVENT_MN_WRITE_REQ   = 0x05,
+   HISI_HWEVENT_MN_EVENT_MAX   = 0x08,
+};
+
+/*
+ * ARMv8 HiSilicon Hardware counter Index.
+ */
+enum armv8_hisi_mn_counters {
+   HISI_IDX_MN_COUNTER0= 0x0,
+   HISI_IDX_MN_COUNTER_MAX = 0x4,
+};
+
+#define HISI_MAX_CFG_MN_CNTR   0x04
+#define MN1_EVTYPE_REG_OFF 0x48
+#define MN1_EVCTRL_REG_OFF 0x40
+#define MN1_CNT0_REG_OFF 0x30
+#define MN1_EVENT_EN 0x01
+#define MN1_BANK_SELECT 0x01
+
+#define GET_MODULE_ID(hwmod_data) hwmod_data->mn_hwcfg.module_id
+
+struct hisi_mn_hwcfg {
+   u32 module_id;
+};
+
+struct hisi_mn_data {
+   struct hisi_djtag_client *client;
+   DECLARE_BITMAP(event_used_mask, HISI_MAX_CFG_MN_CNTR);
+   struct hisi_mn_hwcfg mn_hwcfg;
+};
+
+static inline int hisi_mn_counter_valid(int idx)
+{
+   return (idx >= HISI_IDX_MN_COUNTER0 &&
+   idx < HISI_IDX_MN_COUNTER_MAX);
+}
+
+/* Select the counter register offset from the index */
+static inline u32 get_counter_reg_off(int cntr_idx)
+{
+   return (MN1_CNT0_REG_OFF + (cntr_idx * 4));
+}
+
+static u32 hisi_mn_read_counter(struct hisi_mn_data *mn_data, int cntr_idx)
+{
+   struct hisi_djtag_client *client = mn_data->client;
+   u32 module_id = GET_MODULE_ID(mn_data);
+   u32 reg_off, value;
+
+   reg_off = get_counter_reg_off(cntr_idx);
+   hisi_djtag_readreg(module_id, MN1_BANK_SELECT, reg_off,
+  client, &value);
+
+   return value;
+}
+
+static u64 hisi_mn_event_update(struct perf_event *event,
+   struct hw_perf_event *hwc, int idx)
+{
+   struct hisi_pmu *mn_pmu = to_hisi_pmu(event->pmu);
+   struct hisi_mn_data *mn_data = mn_pmu->hwmod_data;
+   u64 delta, prev_raw_count, new_raw_count = 0;
+
+   if (!hisi_mn_counter_valid(idx)) {
+   dev_err(mn_pmu->dev,
+   "Unsupported event index:%d!\n", idx);
+   return 0;
+   }
+
+   do {
+   /* Get count from the MN */
+   prev_raw_count = local64_read(&hwc->prev_count);
+   new_raw_count = hisi_mn_read_counter(mn_data, idx);
+   delta = (new_raw_count - prev_raw_count) & HISI_MAX_PERIOD;
+
+   local64_add(delta, &event->count);
+   } while (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
+new_raw_count) != prev_raw_count);
+
+   return new_raw_count;
+}
+
+static void hisi_mn_set_evtype(struct hisi_pmu *mn_pmu, int idx, u32 val)
+{
+   struct hisi_mn_data *mn_data = mn_pmu->hwmod_data;
+

[PATCH v6 11/11] dts: arm64: hip07: Add Hisilicon SoC PMU support

2017-03-09 Thread Anurup M
Add nodes for djtag, L3 cache and MN to support uncore events.

Signed-off-by: Anurup M 
---
 arch/arm64/boot/dts/hisilicon/hip07.dtsi | 79 
 1 file changed, 79 insertions(+)

diff --git a/arch/arm64/boot/dts/hisilicon/hip07.dtsi 
b/arch/arm64/boot/dts/hisilicon/hip07.dtsi
index 5144eb1..3155ee3 100644
--- a/arch/arm64/boot/dts/hisilicon/hip07.dtsi
+++ b/arch/arm64/boot/dts/hisilicon/hip07.dtsi
@@ -1056,4 +1056,83 @@
status = "disabled";
};
};
+
+   djtag0: djtag@6001 {
+   compatible = "hisilicon,hip07-cpu-djtag-v2";
+   reg = <0x0 0x6001 0x0 0x1>;
+   hisilicon,scl-id = <0x03>;
+
+   /* L3 cache bank 0 for socket0 CPU die scl#3 */
+   pmul3c0 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x01 0x01>;
+   };
+
+   /* L3 cache bank 1 for socket0 CPU die scl#3 */
+   pmul3c1 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x02 0x01>;
+   };
+
+   /* L3 cache bank 2 for socket0 CPU die scl#3 */
+   pmul3c2 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x03 0x01>;
+   };
+
+   /* L3 cache bank 3 for socket0 CPU die scl#3 */
+   pmul3c3 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x04 0x01>;
+   };
+
+   /*
+* Miscellaneous node for socket0
+* CPU die scl#2
+*/
+   pmumn0 {
+   compatible = "hisilicon,hip07-pmu-mn-v2";
+   hisilicon,module-id = <0x21>;
+   };
+   };
+
+   djtag1: djtag@4001 {
+   compatible = "hisilicon,hip07-cpu-djtag-v2";
+   reg = <0x0 0x4001 0x0 0x1>;
+   hisilicon,scl-id = <0x01>;
+
+   /* L3 cache bank 0 for socket0 CPU die scl#1 */
+   pmul3c0 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x01 0x01>;
+   };
+
+   /* L3 cache bank 1 for socket0 CPU die scl#1 */
+   pmul3c1 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x02 0x01>;
+   };
+
+   /* L3 cache bank 2 for socket0 CPU die scl#1 */
+   pmul3c2 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x03 0x01>;
+   };
+
+   /* L3 cache bank 3 for socket0 CPU die scl#1 */
+   pmul3c3 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x04 0x01>;
+   };
+
+   /*
+* Miscellaneous node for socket0
+* CPU die scl#1
+*/
+   pmumn1 {
+   compatible = "hisilicon,hip07-pmu-mn-v2";
+   hisilicon,module-id = <0x21>;
+   };
+   };
+
 };
-- 
2.1.4



[PATCH v6 08/11] drivers: perf: hisi: use poll method to avoid L3C counter overflow

2017-03-09 Thread Anurup M
Add hrtimer support which use poll method to avoid counter overflow
when overflow IRQ is not supported in hardware.
The L3 cache PMU use N-N SPI interrupt which has no support in kernel
mainline. So use hrtimer to poll and update event counter to avoid
overflow condition for L3 cache PMU.
An interval of 10 seconds is used for the hrtimer.

Signed-off-by: Dikshit N 
Signed-off-by: Anurup M 
---
 drivers/perf/hisilicon/hisi_uncore_l3c.c | 47 ++
 drivers/perf/hisilicon/hisi_uncore_pmu.c | 82 
 drivers/perf/hisilicon/hisi_uncore_pmu.h | 17 +++
 3 files changed, 146 insertions(+)

diff --git a/drivers/perf/hisilicon/hisi_uncore_l3c.c 
b/drivers/perf/hisilicon/hisi_uncore_l3c.c
index 7f80d07..f23fbc2 100644
--- a/drivers/perf/hisilicon/hisi_uncore_l3c.c
+++ b/drivers/perf/hisilicon/hisi_uncore_l3c.c
@@ -20,6 +20,8 @@
  * along with this program.  If not, see .
  */
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -53,6 +55,22 @@ enum armv8_hisi_l3c_counters {
 #define L3C_CNT0_REG_OFF 0x170
 #define L3C_EVENT_EN 0x100
 
+/*
+ * Default timer frequency to poll and avoid counter overflow.
+ * CPU speed = 2.4Ghz, Therefore Access time = 0.4ns
+ * L1 cache - 2 way set associative
+ * L2  - 16 way set associative
+ * L3  - 16 way set associative. L3 cache has 4 banks.
+ *
+ * Overflow time = 2^31 * (access time L1 + access time L2 + access time L3)
+ * = 2^31 * ((2 * 0.4ns) + (16 * 0.4ns) + (4 * 16 * 0.4ns)) = 70 seconds
+ *
+ * L3 cache is also used by devices like PCIe, SAS etc. at
+ * the same time. So the overflow time could be even smaller.
+ * So on a safe side we use a timer interval of 10sec
+ */
+#define L3C_HRTIMER_INTERVAL (10LL * MSEC_PER_SEC)
+
 #define GET_MODULE_ID(hwmod_data) hwmod_data->l3c_hwcfg.module_id
 #define GET_BANK_SEL(hwmod_data) hwmod_data->l3c_hwcfg.bank_select
 
@@ -474,11 +492,24 @@ static const struct attribute_group 
hisi_l3c_cpumask_attr_group = {
.attrs = hisi_l3c_cpumask_attrs,
 };
 
+static DEVICE_ATTR(hrtimer_interval, 0444, hisi_hrtimer_interval_sysfs_show,
+  NULL);
+
+static struct attribute *hisi_l3c_hrtimer_interval_attrs[] = {
+   &dev_attr_hrtimer_interval.attr,
+   NULL,
+};
+
+static const struct attribute_group hisi_l3c_hrtimer_interval_attr_group = {
+   .attrs = hisi_l3c_hrtimer_interval_attrs,
+};
+
 static const struct attribute_group *hisi_l3c_pmu_attr_groups[] = {
&hisi_l3c_attr_group,
&hisi_l3c_format_group,
&hisi_l3c_events_group,
&hisi_l3c_cpumask_attr_group,
+   &hisi_l3c_hrtimer_interval_attr_group,
NULL,
 };
 
@@ -494,6 +525,15 @@ static struct hisi_uncore_ops hisi_uncore_l3c_ops = {
.write_counter = hisi_l3c_write_counter,
 };
 
+/* Initialize hrtimer to poll for avoiding counter overflow */
+static void hisi_l3c_hrtimer_init(struct hisi_pmu *l3c_pmu)
+{
+   INIT_LIST_HEAD(&l3c_pmu->active_list);
+   l3c_pmu->ops->start_hrtimer = hisi_hrtimer_start;
+   l3c_pmu->ops->stop_hrtimer = hisi_hrtimer_stop;
+   hisi_hrtimer_init(l3c_pmu, L3C_HRTIMER_INTERVAL);
+}
+
 static int hisi_l3c_pmu_init(struct hisi_pmu *l3c_pmu,
 struct hisi_djtag_client *client)
 {
@@ -503,6 +543,7 @@ static int hisi_l3c_pmu_init(struct hisi_pmu *l3c_pmu,
 
l3c_pmu->num_events = HISI_HWEVENT_L3C_EVENT_MAX;
l3c_pmu->num_counters = HISI_IDX_L3C_COUNTER_MAX;
+   l3c_pmu->num_active = 0;
l3c_pmu->scl_id = hisi_djtag_get_sclid(client);
 
l3c_pmu->name = kasprintf(GFP_KERNEL, "hisi_l3c%u_%u",
@@ -513,6 +554,12 @@ static int hisi_l3c_pmu_init(struct hisi_pmu *l3c_pmu,
/* Pick one core to use for cpumask attributes */
cpumask_set_cpu(smp_processor_id(), &l3c_pmu->cpu);
 
+   /*
+* Use poll method to avoid counter overflow as overflow IRQ
+* is not supported in v1,v2 hardware.
+*/
+   hisi_l3c_hrtimer_init(l3c_pmu);
+
return 0;
 }
 
diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c 
b/drivers/perf/hisilicon/hisi_uncore_pmu.c
index 0e7b5f1..787602b 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
+++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
@@ -65,6 +65,70 @@ ssize_t hisi_cpumask_sysfs_show(struct device *dev,
return cpumap_print_to_pagebuf(true, buf, &hisi_pmu->cpu);
 }
 
+/*
+ * sysfs hrtimer_interval attributes
+ */
+ssize_t hisi_hrtimer_interval_sysfs_show(struct device *dev,
+struct device_attribute *attr,
+char *buf)
+{
+   struct pmu *pmu = dev_get_drvdata(dev);
+   struct hisi_pmu *hisi_pmu = to_hisi_pmu(pmu);
+
+   if (hisi_pmu->hrt_duration)
+   return sprintf(buf, "%llu\n", hisi_pmu->hrt_duration);
+   return 0;
+}
+
+/* The counter overflow IRQ is not supported for some PMUs
+ * use hrtimer to periodically poll and avoid overflow
+ */
+st

[PATCH v6 10/11] drivers: perf: hisi: use poll method when no IRQ for MN counter overflow

2017-03-09 Thread Anurup M
When no IRQ is supported in hardware, use hrtimer to poll and
update event counter and avoid overflow condition for MN PMU.
An interval of 8 seconds is used for the hrtimer.

Signed-off-by: Anurup M 
Signed-off-by: Shaokun Zhang 
Signed-off-by: Dikshit N 
---
 drivers/perf/hisilicon/hisi_uncore_mn.c | 39 +
 1 file changed, 39 insertions(+)

diff --git a/drivers/perf/hisilicon/hisi_uncore_mn.c 
b/drivers/perf/hisilicon/hisi_uncore_mn.c
index 18316dc..55b6165 100644
--- a/drivers/perf/hisilicon/hisi_uncore_mn.c
+++ b/drivers/perf/hisilicon/hisi_uncore_mn.c
@@ -20,6 +20,8 @@
  * along with this program.  If not, see .
  */
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -56,6 +58,15 @@ enum armv8_hisi_mn_counters {
 
 #define GET_MODULE_ID(hwmod_data) hwmod_data->mn_hwcfg.module_id
 
+/*
+ * Default timer frequency to poll and avoid counter overflow.
+ * CPU speed = 2.4Ghz and number of CPU cores in a SCCL is 16.
+ * For a single MN event on a CPU core consumes 200 cycles.
+ * So overflow time = (2^31 * 200) / (16 * 2.4G) which is about 21 seconds
+ * So on a safe side we use a timer interval of 8sec
+ */
+#define MN1_HRTIMER_INTERVAL (8LL * MSEC_PER_SEC)
+
 struct hisi_mn_hwcfg {
u32 module_id;
 };
@@ -272,6 +283,15 @@ static const struct of_device_id mn_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, mn_of_match);
 
+/* Use hrtimer when no IRQ, to poll for avoiding counter overflow */
+static void hisi_mn_hrtimer_init(struct hisi_pmu *mn_pmu)
+{
+   INIT_LIST_HEAD(&mn_pmu->active_list);
+   mn_pmu->ops->start_hrtimer = hisi_hrtimer_start;
+   mn_pmu->ops->stop_hrtimer = hisi_hrtimer_stop;
+   hisi_hrtimer_init(mn_pmu, MN1_HRTIMER_INTERVAL);
+}
+
 static int hisi_mn_init_data(struct hisi_pmu *mn_pmu,
 struct hisi_djtag_client *client)
 {
@@ -314,6 +334,12 @@ static int hisi_mn_init_data(struct hisi_pmu *mn_pmu,
} else
return -EINVAL;
 
+   /*
+* Use poll method to avoid counter overflow as
+* overflow IRQ is not supported in hardware.
+*/
+   hisi_mn_hrtimer_init(mn_pmu);
+
return 0;
 }
 
@@ -361,11 +387,24 @@ static const struct attribute_group 
hisi_mn_cpumask_attr_group = {
.attrs = hisi_mn_cpumask_attrs,
 };
 
+static DEVICE_ATTR(hrtimer_interval, 0444, hisi_hrtimer_interval_sysfs_show,
+  NULL);
+
+static struct attribute *hisi_mn_hrtimer_interval_attrs[] = {
+   &dev_attr_hrtimer_interval.attr,
+   NULL,
+};
+
+static const struct attribute_group hisi_mn_hrtimer_interval_attr_group = {
+   .attrs = hisi_mn_hrtimer_interval_attrs,
+};
+
 static const struct attribute_group *hisi_mn_pmu_attr_groups[] = {
&hisi_mn_attr_group,
&hisi_mn_format_group,
&hisi_mn_events_group,
&hisi_mn_cpumask_attr_group,
+   &hisi_mn_hrtimer_interval_attr_group,
NULL,
 };
 
-- 
2.1.4



[PATCH v6 06/11] drivers: perf: hisi: Add support for Hisilicon Djtag driver

2017-03-09 Thread Anurup M
From: Tan Xiaojun 

The Hisilicon Djtag is an independent component which connects
with some other components in the SoC by Debug Bus. This driver
can be configured to access the registers of connecting components
(like L3 cache) during real time debugging.

Signed-off-by: Tan Xiaojun 
Signed-off-by: John Garry 
Signed-off-by: Anurup M 
---
 drivers/perf/Makefile   |   1 +
 drivers/perf/hisilicon/Makefile |   1 +
 drivers/perf/hisilicon/djtag.c  | 773 
 drivers/perf/hisilicon/djtag.h  |  42 +++
 4 files changed, 817 insertions(+)
 create mode 100644 drivers/perf/hisilicon/Makefile
 create mode 100644 drivers/perf/hisilicon/djtag.c
 create mode 100644 drivers/perf/hisilicon/djtag.h

diff --git a/drivers/perf/Makefile b/drivers/perf/Makefile
index 3a5e22f..d262fff 100644
--- a/drivers/perf/Makefile
+++ b/drivers/perf/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_ARM_PMU) += arm_pmu.o
 obj-$(CONFIG_QCOM_L2_PMU)  += qcom_l2_pmu.o
+obj-$(CONFIG_HISI_PMU) += hisilicon/
 obj-$(CONFIG_XGENE_PMU) += xgene_pmu.o
 obj-$(CONFIG_ARM_PMU_ACPI) += arm_pmu_acpi.o
diff --git a/drivers/perf/hisilicon/Makefile b/drivers/perf/hisilicon/Makefile
new file mode 100644
index 000..be8f093
--- /dev/null
+++ b/drivers/perf/hisilicon/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_HISI_PMU) += djtag.o
diff --git a/drivers/perf/hisilicon/djtag.c b/drivers/perf/hisilicon/djtag.c
new file mode 100644
index 000..88b6a90
--- /dev/null
+++ b/drivers/perf/hisilicon/djtag.c
@@ -0,0 +1,773 @@
+/*
+ * Driver for Hisilicon Djtag r/w which use CPU sysctrl.
+ *
+ * Copyright (C) 2017 Hisilicon Limited
+ * Author: Tan Xiaojun 
+ * Anurup M 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "djtag.h"
+
+#define SC_DJTAG_TIMEOUT_US(100 * USEC_PER_MSEC) /* 100ms */
+
+/* for djtag v1 */
+#define SC_DJTAG_MSTR_EN   0x6800
+#define DJTAG_NOR_CFG  BIT(1)  /* accelerate R,W */
+#define DJTAG_MSTR_EN  BIT(0)
+#define SC_DJTAG_MSTR_START_EN 0x6804
+#define DJTAG_MSTR_START_EN0x1
+#define SC_DJTAG_DEBUG_MODULE_SEL  0x680c
+#define SC_DJTAG_MSTR_WR   0x6810
+#define DJTAG_MSTR_W   0x1
+#define DJTAG_MSTR_R   0x0
+#define SC_DJTAG_CHAIN_UNIT_CFG_EN 0x6814
+#define CHAIN_UNIT_CFG_EN  0x
+#define SC_DJTAG_MSTR_ADDR 0x6818
+#define SC_DJTAG_MSTR_DATA 0x681c
+#define SC_DJTAG_RD_DATA_BASE  0xe800
+
+/* for djtag v2 */
+#define SC_DJTAG_SEC_ACC_EN_EX 0xd800
+#define DJTAG_SEC_ACC_EN_EX0x1
+#define SC_DJTAG_MSTR_CFG_EX   0xd818
+#define DJTAG_MSTR_RW_SHIFT_EX 29
+#define DJTAG_MSTR_RD_EX   (0x0 << DJTAG_MSTR_RW_SHIFT_EX)
+#define DJTAG_MSTR_WR_EX   (0x1 << DJTAG_MSTR_RW_SHIFT_EX)
+#define DEBUG_MODULE_SEL_SHIFT_EX  16
+#define CHAIN_UNIT_CFG_EN_EX   0x
+#define SC_DJTAG_MSTR_ADDR_EX  0xd810
+#define SC_DJTAG_MSTR_DATA_EX  0xd814
+#define SC_DJTAG_MSTR_START_EN_EX  0xd81c
+#define DJTAG_MSTR_START_EN_EX 0x1
+#define SC_DJTAG_RD_DATA_BASE_EX   0xe800
+#define SC_DJTAG_OP_ST_EX  0xe828
+#define DJTAG_OP_DONE_EX   BIT(8)
+
+#define DJTAG_PREFIX "hisi-djtag-dev-"
+
+static DEFINE_IDR(djtag_hosts_idr);
+static DEFINE_IDR(djtag_clients_idr);
+
+struct hisi_djtag_ops {
+   int (*djtag_read)(void __iomem *regs_base, u32 offset,
+ u32 mod_sel, u32 mod_mask, int chain_id, u32 *rval);
+   int (*djtag_write)(void __iomem *regs_base, u32 offset,
+  u32 mod_sel, u32 mod_mask, u32 wval, int chain_id);
+};
+
+struct hisi_djtag_host {
+   spinlock_t lock;
+   int id;
+   u32 scl_id;
+   struct device dev;
+   struct list_head client_list;
+   void __iomem *sysctl_reg_map;
+   struct device_node *of_node;
+   const struct hisi_djtag_ops *djtag_ops;
+};
+
+#define to_hisi_djtag_client(d) container_of(d, struct hisi_djtag_client, dev)
+#define to_hisi_djtag_driver(d) container_of(d, struct hisi_djtag_driver, \
+driver)
+#define MODULE_PREFIX "hisi_djtag:"
+
+static void djtag_prepare_v1(void __iomem *regs_base, u32 offset,
+u32 mod_sel, u32 mod_mask)
+{
+   /* djtag master enable & accelerate R,W */
+   writel(DJTAG_NOR_CFG | DJTAG_MSTR_EN, regs_base + SC_DJTAG_MSTR_EN);
+
+   /* select module */
+   writel(mod_sel, regs_base + SC_DJTAG_DEBUG_MODULE_SEL);
+   writel(mod_mask & CHAIN_UNIT_CFG_EN,
+   regs_base + SC_DJTAG_CHAIN_UNIT_CFG_EN);
+
+   /* addr

[PATCH v6 07/11] drivers: perf: hisi: Add support for Hisilicon SoC event counters

2017-03-09 Thread Anurup M
1. HiP05/06/07 uncore PMU to support different hardware event counters.
2. Hisilicon PMU shall use the DJTAG hardware interface to access
   hardware event counters and configuration register.
3. Routines to enable/disable/add/del/start/stop hardware event counting.
4. Add support to count L3 cache hardware events. Each L3 cache banks will
   be registered as separate PMU with perf.
5. L3C events will be listed at /sys/devices/hisi_l3cX_Y/events/

Signed-off-by: Anurup M 
Signed-off-by: Shaokun Zhang 
Signed-off-by: John Garry 
---
 drivers/perf/hisilicon/Makefile  |   2 +-
 drivers/perf/hisilicon/hisi_uncore_l3c.c | 606 +++
 drivers/perf/hisilicon/hisi_uncore_pmu.c | 363 ++
 drivers/perf/hisilicon/hisi_uncore_pmu.h | 120 ++
 4 files changed, 1090 insertions(+), 1 deletion(-)
 create mode 100644 drivers/perf/hisilicon/hisi_uncore_l3c.c
 create mode 100644 drivers/perf/hisilicon/hisi_uncore_pmu.c
 create mode 100644 drivers/perf/hisilicon/hisi_uncore_pmu.h

diff --git a/drivers/perf/hisilicon/Makefile b/drivers/perf/hisilicon/Makefile
index be8f093..0887b56 100644
--- a/drivers/perf/hisilicon/Makefile
+++ b/drivers/perf/hisilicon/Makefile
@@ -1 +1 @@
-obj-$(CONFIG_HISI_PMU) += djtag.o
+obj-$(CONFIG_HISI_PMU) += djtag.o hisi_uncore_pmu.o hisi_uncore_l3c.o
diff --git a/drivers/perf/hisilicon/hisi_uncore_l3c.c 
b/drivers/perf/hisilicon/hisi_uncore_l3c.c
new file mode 100644
index 000..7f80d07
--- /dev/null
+++ b/drivers/perf/hisilicon/hisi_uncore_l3c.c
@@ -0,0 +1,606 @@
+/*
+ * HiSilicon SoC L3C Hardware event counters support
+ *
+ * Copyright (C) 2017 Hisilicon Limited
+ * Author: Anurup M 
+ *
+ * This code is based on the uncore PMU's like arm-cci and
+ * arm-ccn.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "hisi_uncore_pmu.h"
+
+/*
+ * ARMv8 HiSilicon L3C event types.
+ */
+enum armv8_hisi_l3c_event_types {
+   HISI_HWEVENT_L3C_READ_ALLOCATE  = 0x0,
+   HISI_HWEVENT_L3C_WRITE_ALLOCATE = 0x01,
+   HISI_HWEVENT_L3C_READ_NOALLOCATE= 0x02,
+   HISI_HWEVENT_L3C_WRITE_NOALLOCATE   = 0x03,
+   HISI_HWEVENT_L3C_READ_HIT   = 0x04,
+   HISI_HWEVENT_L3C_WRITE_HIT  = 0x05,
+   HISI_HWEVENT_L3C_EVENT_MAX  = 0x15,
+};
+
+/*
+ * ARMv8 HiSilicon Hardware counter Index.
+ */
+enum armv8_hisi_l3c_counters {
+   HISI_IDX_L3C_COUNTER0   = 0x0,
+   HISI_IDX_L3C_COUNTER_MAX= 0x8,
+};
+
+#define HISI_MAX_CFG_L3C_CNTR  0x08
+#define L3C_EVTYPE_REG_OFF 0x140
+#define L3C_EVCTRL_REG_OFF 0x04
+#define L3C_CNT0_REG_OFF 0x170
+#define L3C_EVENT_EN 0x100
+
+#define GET_MODULE_ID(hwmod_data) hwmod_data->l3c_hwcfg.module_id
+#define GET_BANK_SEL(hwmod_data) hwmod_data->l3c_hwcfg.bank_select
+
+struct hisi_l3c_hwcfg {
+   u32 module_id;
+   u32 bank_select;
+   u32 bank_id;
+};
+
+struct hisi_l3c_data {
+   struct hisi_djtag_client *client;
+   DECLARE_BITMAP(event_used_mask, HISI_MAX_CFG_L3C_CNTR);
+   struct hisi_l3c_hwcfg l3c_hwcfg;
+};
+
+struct hisi_l3c_hw_diff {
+   u32 (*get_bank_id)(u32 module_id, u32 bank_select);
+};
+
+/* hip05/06 chips L3C bank identifier */
+static u32 l3c_bankid_map_v1[MAX_BANKS] = {
+   0x02, 0x04, 0x01, 0x08,
+};
+
+/* hip07 chip L3C bank identifier */
+static u32 l3c_bankid_map_v2[MAX_BANKS] = {
+   0x01, 0x02, 0x03, 0x04,
+};
+
+/* Return the L3C bank index to use in PMU name */
+static u32 get_l3c_bank_v1(u32 module_id, u32 bank_select)
+{
+   u32 i;
+
+   /*
+* For v1 chip (hip05/06) the index of bank_select
+* in the bankid_map gives the bank index.
+*/
+   for (i = 0 ; i < MAX_BANKS; i++)
+   if (l3c_bankid_map_v1[i] == bank_select)
+   break;
+
+   return i;
+}
+
+/* Return the L3C bank index to use in PMU name */
+static u32 get_l3c_bank_v2(u32 module_id, u32 bank_select)
+{
+   u32 i;
+
+   /*
+* For v2 chip (hip07) each bank has different
+* module ID. So index of module ID in the
+* bankid_map gives the bank index.
+*/
+   for (i = 0 ; i < MAX_BANKS; i++)
+   if (l3c_bankid_map_v2[i] == module_id)
+   break;
+
+   return i;
+}
+
+static inline int hisi_l3c_counter_valid(int idx)
+{
+   return (idx >= HISI_IDX_L3C_COUNTE

[PATCH v6 05/11] drivers: perf: hisi: Update Kconfig for Hisilicon PMU support

2017-03-09 Thread Anurup M
Update Kconfig for HiP05/06/07 PMU support.

Signed-off-by: Anurup M 
Signed-off-by: Shaokun Zhang 
Signed-off-by: John Garry 
---
 drivers/perf/Kconfig | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/perf/Kconfig b/drivers/perf/Kconfig
index 1e95d6a..f0aa818 100644
--- a/drivers/perf/Kconfig
+++ b/drivers/perf/Kconfig
@@ -32,4 +32,12 @@ config ARM_PMU_ACPI
def_bool y
depends on ARM_PMU && ACPI
 
+config HISI_PMU
+   bool "HiSilicon SoC PMU"
+   depends on PERF_EVENTS && ARM64
+   help
+ Enable hardware event counter support for hardware event counters
+ in Hisilicon HiP05/06/07 SoC. The hardware modules like L3C and MN
+ have hardware events and counters.
+
 endmenu
-- 
2.1.4



[PATCH v6 04/11] Documentation: perf: hisi: Documentation for HiP05/06/07 PMU event counting.

2017-03-09 Thread Anurup M
Documentation for perf usage and Hisilicon SoC PMU uncore events.
The Hisilicon SOC has event counters for hardware modules like
L3 cache, Miscellaneous node etc. These events are all uncore.

Signed-off-by: Anurup M 
Signed-off-by: Shaokun Zhang 
---
 Documentation/perf/hisi-pmu.txt | 76 +
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/perf/hisi-pmu.txt

diff --git a/Documentation/perf/hisi-pmu.txt b/Documentation/perf/hisi-pmu.txt
new file mode 100644
index 000..e3ac562
--- /dev/null
+++ b/Documentation/perf/hisi-pmu.txt
@@ -0,0 +1,76 @@
+Hisilicon SoC PMU (Performance Monitoring Unit)
+
+The Hisilicon SoC HiP05/06/07 chips consist of various independent system
+device PMU's such as L3 cache(L3C) and Miscellaneous Nodes(MN).
+These PMU devices are independent and have hardware logic to gather
+statistics and performance information.
+
+HiP0x chips are encapsulated by multiple CPU and IO die's. The CPU die is
+called as Super CPU cluster (SCCL) which includes 16 cpu-cores. Every SCCL
+is further grouped as CPU clusters (CCL) which includes 4 cpu-cores each.
+Each SCCL has 1 L3 cache and 1 MN units.
+
+The L3 cache is shared by all CPU cores in a CPU die. The L3C has four banks
+(or instances). Each bank or instance of L3C has Eight 32-bit counter
+registers and also event control registers. The HiP05/06 chip L3 cache has
+22 statistics events. The HiP07 chip has 66 statistics events. These events
+are very useful for debugging.
+
+The MN module is also shared by all CPU cores in a CPU die. It receives
+barriers and DVM(Distributed Virtual Memory) messages from cpu or smmu, and
+perform the required actions and return response messages. These events are
+very useful for debugging. The MN has total 9 statistics events and support
+four 32-bit counter registers in HiP05/06/07 chips.
+
+There is no memory mapping for L3 cache and MN registers. It can be accessed
+by using the Hisilicon djtag interface. The Djtag in a SCCL is an independent
+module which connects with some modules in the SoC by Debug Bus.
+
+Hisilicon SoC (HiP05/06/07) PMU driver
+--
+The HiP0x PMU driver shall register perf PMU drivers like L3 cache, MN, etc.
+The available events and configuration options shall be described in the sysfs.
+The "perf list" shall list the available events from sysfs.
+
+The L3 cache in a SCCL is divided as 4 banks. Each L3 cache bank have separate
+PMU registers for event counting and control. The L3 cache banks also do not
+have any CPU affinity. So each L3 cache banks are registered with perf as a
+separate PMU.
+The PMU name will appear in event listing as hisi_l3c_.
+where "bank-id" is the bank index (0 to 3) and "scl-id" is the SCCL identifier
+e.g. hisi_l3c0_2/read_hit is READ_HIT event of L3 cache bank #0 SCCL ID #2.
+
+The MN in a SCCL is registered as a separate PMU with perf.
+The PMU name will appear in event listing as hisi_mn_.
+e.g. hisi_mn_2/read_req. READ_REQUEST event of MN of Super CPU cluster #2.
+
+The event code is represented by 12 bits.
+   i) event 0-11
+   The event code will be represented using the LSB 12 bits.
+
+The driver also provides a "cpumask" sysfs attribute, which shows the CPU core
+ID used to count the uncore PMU event.
+
+Example usage of perf:
+$# perf list
+hisi_l3c0_2/read_hit/ [kernel PMU event]
+--
+hisi_l3c1_2/write_hit/ [kernel PMU event]
+--
+hisi_l3c0_1/read_hit/ [kernel PMU event]
+--
+hisi_l3c0_1/write_hit/ [kernel PMU event]
+--
+hisi_mn_2/read_req/ [kernel PMU event]
+hisi_mn_2/write_req/ [kernel PMU event]
+--
+
+$# perf stat -a -e "hisi_l3c0_2/read_allocate/" sleep 5
+
+$# perf stat -A -C 0 -e "hisi_l3c0_2/read_allocate/" sleep 5
+
+The current driver doesnot support sampling. so "perf record" is unsupported.
+Also attach to a task is unsupported as the events are all uncore.
+
+Note: Please contact the maintainer for a complete list of events supported for
+the PMU devices in the SoC and its information if needed.
-- 
2.1.4



[PATCH v6 03/11] dt-bindings: perf: hisi: Add Devicetree bindings for Hisilicon SoC PMU

2017-03-09 Thread Anurup M
1) Device tree bindings for Hisilicon SoC PMU.
2) Add example for Hisilicon L3 cache and MN PMU.
3) Add child nodes of L3C and MN in djtag bindings example.

Signed-off-by: Anurup M 
Signed-off-by: Shaokun Zhang 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/arm/hisilicon/djtag.txt| 25 +++
 .../devicetree/bindings/arm/hisilicon/pmu.txt  | 87 ++
 2 files changed, 112 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/hisilicon/pmu.txt

diff --git a/Documentation/devicetree/bindings/arm/hisilicon/djtag.txt 
b/Documentation/devicetree/bindings/arm/hisilicon/djtag.txt
index fde5bab..5c46a9c 100644
--- a/Documentation/devicetree/bindings/arm/hisilicon/djtag.txt
+++ b/Documentation/devicetree/bindings/arm/hisilicon/djtag.txt
@@ -27,6 +27,31 @@ Example 1: Djtag for CPU die in HiP07
hisilicon,scl-id = <0x03>;
 
/* All connecting components will appear as child nodes */
+
+   pmul3c0 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x01 0x01>;
+   };
+
+   pmul3c1 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x02 0x01>;
+   };
+
+   pmul3c2 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x03 0x01>;
+   };
+
+   pmul3c3 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x04 0x01>;
+   };
+
+   pmumn0 {
+   compatible = "hisilicon,hip07-pmu-mn-v2";
+   hisilicon,module-id = <0x21>;
+   };
};
 
 Hisilicon HiP05/06/07 djtag for IO die
diff --git a/Documentation/devicetree/bindings/arm/hisilicon/pmu.txt 
b/Documentation/devicetree/bindings/arm/hisilicon/pmu.txt
new file mode 100644
index 000..ad38cf4
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/hisilicon/pmu.txt
@@ -0,0 +1,87 @@
+Hisilicon SoC HiP05/06/07 ARMv8 PMU
+===
+
+The Hisilicon SoC chips like HiP05/06/07 etc. consist of various independent
+system device PMUs such as L3 cache (L3C) and Miscellaneous Nodes(MN). These
+PMU devices are independent and have hardware logic to gather statistics and
+performance information.
+
+HiSilicon SoC chip is encapsulated by multiple CPU and IO dies. The CPU die
+is called as Super CPU cluster (SCCL) which includes 16 cpu-cores. Every SCCL
+in HiP05/06/07 chips are further grouped as CPU clusters (CCL) which includes
+4 cpu-cores each.
+e.g. In the case of HiP05/06/07, each SCCL has 1 L3 cache and 1 MN PMU device.
+The L3 cache is further grouped as 4 L3 cache banks in a SCCL.
+
+The Hisilicon SoC PMU DT node bindings for uncore PMU devices are as below.
+For PMU devices like L3 cache. MN etc. which are accessed using the djtag,
+the parent node will be the djtag node of the corresponding CPU die (SCCL).
+
+L3 cache
+-
+The L3 cache is dedicated for each SCCL. Each SCCL in HiP05/06/07 chips have 4
+L3 cache banks. Each L3 cache bank have separate DT nodes.
+
+Required properties:
+
+   - compatible : This value should be as follows
+   (a) "hisilicon,hip05-pmu-l3c-v1" for v1 hw in HiP05 chipset
+   (b) "hisilicon,hip06-pmu-l3c-v1" for v1 hw in HiP06 chipset
+   (c) "hisilicon,hip07-pmu-l3c-v2" for v2 hw in HiP07 chipset
+
+   - hisilicon,module-id : This property is a combination of two values
+   in the below order.
+   a) Module ID: The module identifier for djtag.
+   b) Instance or Bank ID: This will identify the L3 cache bank
+or instance.
+
+   *The counter overflow IRQ is not supported in v1, v2 hardware 
(HiP05/06/07).
+
+Miscellaneous Node
+--
+The MN is dedicated for each SCCL and hence there are separate DT nodes for MN
+for each SCCL.
+
+Required properties:
+
+   - compatible : This value should be as follows
+   (a) "hisilicon,hip05-pmu-mn-v1" for v1 hw in HiP05 chipset
+   (b) "hisilicon,hip06-pmu-mn-v1" for v1 hw in HiP06 chipset
+   (c) "hisilicon,hip07-pmu-mn-v2" for v2 hw in HiP07 chipset
+
+   - hisilicon,module-id : Module ID to input for djtag.
+
+   *The counter overflow IRQ is not supported in v1, v2 hardware 
(HiP05/06/07).
+
+Example:
+
+   djtag0: djtag@6001 {
+   compatible = "hisilicon,hip07-cpu-djtag-v2";
+   reg = <0x0 0x6001 0x0 0x1>;
+   hisilicon,scl-id = <0x03>;
+
+   pmul3c0 {
+   compatible = "hisilicon,hip07-pmu-l3c-v2";
+   hisilicon,module-id = <0x01 0x01>;
+   };
+
+   pmul3c1 {
+   compatible = "hisilicon,h

[PATCH v6 02/11] dt-bindings: hisi: Add Hisilicon HiP05/06/07 Djtag dts bindings

2017-03-09 Thread Anurup M
From: Tan Xiaojun 

Add Hisilicon HiP05/06/07 Djtag dts bindings for CPU and IO Die

Signed-off-by: Tan Xiaojun 
Signed-off-by: Anurup M 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/arm/hisilicon/djtag.txt| 51 ++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/hisilicon/djtag.txt

diff --git a/Documentation/devicetree/bindings/arm/hisilicon/djtag.txt 
b/Documentation/devicetree/bindings/arm/hisilicon/djtag.txt
new file mode 100644
index 000..fde5bab
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/hisilicon/djtag.txt
@@ -0,0 +1,51 @@
+The Hisilicon Djtag is an independent component which connects with some other
+components in the SoC by Debug Bus. The djtag is available in CPU and IO dies
+in the chip. The djtag controls access to connecting modules of CPU and IO
+dies.
+The various connecting components in CPU die (like L3 cache, L3 cache PMU etc.)
+are accessed by djtag during real time debugging. In IO die there are 
connecting
+components like RSA. These components appear as devices attached to djtag bus.
+
+Hisilicon HiP05/06/07 djtag for CPU die
+Required properties:
+  - compatible : The value should be as follows
+   (a) "hisilicon,hip05-cpu-djtag-v1" for CPU die which use v1 hw in
+   HiP05 chipset.
+   (b) "hisilicon,hip06-cpu-djtag-v1" for CPU die which use v1 hw in
+   HiP06 chipset.
+   (c) "hisilicon,hip07-cpu-djtag-v2" for CPU die which use v2 hw in
+   HiP07 chipset.
+  - reg : Register address and size
+  - hisilicon,scl-id : The Super Cluster ID for CPU or IO die
+
+Example 1: Djtag for CPU die in HiP07
+
+   /* for Hisilicon HiP07 djtag for CPU Die */
+   djtag0: djtag@6001 {
+   compatible = "hisilicon,hip07-cpu-djtag-v2";
+   reg = <0x0 0x6001 0x0 0x1>;
+   hisilicon,scl-id = <0x03>;
+
+   /* All connecting components will appear as child nodes */
+   };
+
+Hisilicon HiP05/06/07 djtag for IO die
+Required properties:
+  - compatible : The value should be as follows
+   (a) "hisilicon,hip05-io-djtag-v1" for IO die which use v1 hw in
+   HiP05 chipset.
+   (c) "hisilicon,hip06-io-djtag-v2" for IO die which use v2 hw in
+   HiP06 chipset.
+   (d) "hisilicon,hip07-io-djtag-v2" for IO die which use v2 hw in
+   HiP07 chipset
+
+Example 2: Djtag for IO die in HiP05
+
+   /* for Hisilicon HiP05 djtag for IO Die */
+   djtag1: djtag@d000 {
+   compatible = "hisilicon,hip05-io-djtag-v1";
+   reg = <0x0 0xd000 0x0 0x1>;
+   hisilicon,scl-id = <0x0>;
+
+   /* All connecting components will appear as child nodes */
+   };
-- 
2.1.4



[PATCH v6 01/11] arm64: MAINTAINERS: hisi: Add hisilicon SoC PMU support

2017-03-09 Thread Anurup M
Add support for Hisilicon SoC hardware event counters
for HiP05/06/07 chip versions.

Signed-off-by: Anurup M 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 6d7b7a7..c2f9806 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5958,6 +5958,15 @@ S:   Maintained
 F: drivers/net/ethernet/hisilicon/
 F: Documentation/devicetree/bindings/net/hisilicon*.txt
 
+HISILICON SOC PMU
+M: Anurup M 
+W: http://www.hisilicon.com
+S: Supported
+F: drivers/perf/hisilicon/
+F: Documentation/perf/hisi-pmu.txt
+F: Documentation/devicetree/bindings/arm/hisilicon/pmu.txt
+F: Documentation/devicetree/bindings/arm/hisilicon/djtag.txt
+
 HISILICON ROCE DRIVER
 M: Lijun Ou 
 M: Wei Hu(Xavier) 
-- 
2.1.4



[PATCH v6 00/11] perf: arm64: Support for Hisilicon SoC Hardware event counters

2017-03-09 Thread Anurup M
Provide Support for Hisilicon SoC(HiP05/06/07) Hardware event counters.
The Hisilicon SoC HiP0x series has many uncore or non-CPU performance
events and counters units.

This v6 version is rebased to 4.11-rc1.

This patch series is implemented refering to arm-cci, Intel/AMD uncore and
also the cavium thunderX and xgene uncore pmu patches.

Support for Hisilicon L3 cache(L3C) and Miscellaneous nodes(MN) hardware
events and counters are added in this implementation.

The uncore PMU units are registered as separate PMUs. 
e.g. in the case of L3 cache, which consist of 4 banks/instances, each bank
is registered with perf as separate PMU, as each bank have separate control
registers and interrupts. These units are also not CPU affine in the current
chip versions.

The Hisilicon uncore PMUs can be found under /sys/bus/event_source/devices.
The counters are exported via sysfs in the corresponding events files
under the PMU directory so the perf tool can list the event names.

There is no counter overflow IRQ support in hardware for these uncore PMUs.
So the driver use poll method using hrtimer to avoid overflow.

ToDo:
1) ACPI probe and reset support.

Version history
---
v6
--
- Rebase to 4.11-rc1
- Modify Copyright year to 2017.

v5
--
- Use hrtimer to avoid overflow as MN counter overflow IRQ is broken
  in hardware.
- Remove IRQ handling of MN in driver and update pmu dt-bindings.
- Fix reveiw comments in v4 version.

v4
--
- Counter overflow IRQ handling for MN PMU.
- Use hrtimer to avoid counter overflow in L3 Cache PMU.
- Use hisi-cpu- and hisi-io- for djtag compatible field.
- Fix reveiw comments in v3 version.

v3
--
- Fix review comments of v2 version.
- Handle event groups. Do not allow group of mixed PMUs.
- Use hip0x prefix for compatible names.
- Fix all sparse and gcc W=1 warnings.

v2
--
- Fix review comments of v1 version.
- Move djtag driver to drivers/perf/hisilicon.
- Have separate PMU instance for each L3 cache banks.
- Modify device properties in DTS as per review comments.
- Handle hardware version difference.
- Change compatible names of djtag so use prefix hisi-
  and remove chip version as driver only depend on djtag
  hw version.
- use devm_kzalloc.
- Remove DDRC changes in this series. As the DDRC PMU doesnot
  depend on djtag it will be send separately.

v1
--
-Initial version with support for L3C, MN and DDRC event counters
-Djtag driver is used to access registers of L3 cache and MN.

Anurup M (8):
  arm64: MAINTAINERS: hisi: Add hisilicon SoC PMU support
  dt-bindings: perf: hisi: Add Devicetree bindings for Hisilicon SoC PMU
  Documentation: perf: hisi: Documentation for HiP05/06/07 PMU event
counting.
  drivers: perf: hisi: Update Kconfig for Hisilicon PMU support
  drivers: perf: hisi: Add support for Hisilicon SoC event counters
  drivers: perf: hisi: use poll method to avoid L3C counter overflow
  drivers: perf: hisi: use poll method when no IRQ for MN counter
overflow
  dts: arm64: hip07: Add Hisilicon SoC PMU support

Shaokun Zhang (1):
  drivers: perf: hisi: Miscellanous node(MN) event counting in perf

Tan Xiaojun (2):
  dt-bindings: hisi: Add Hisilicon HiP05/06/07 Djtag dts bindings
  drivers: perf: hisi: Add support for Hisilicon Djtag driver

 .../devicetree/bindings/arm/hisilicon/djtag.txt|  76 ++
 .../devicetree/bindings/arm/hisilicon/pmu.txt  |  87 +++
 Documentation/perf/hisi-pmu.txt|  76 ++
 MAINTAINERS|   9 +
 arch/arm64/boot/dts/hisilicon/hip07.dtsi   |  79 +++
 drivers/perf/Kconfig   |   8 +
 drivers/perf/Makefile  |   1 +
 drivers/perf/hisilicon/Makefile|   1 +
 drivers/perf/hisilicon/djtag.c | 773 +
 drivers/perf/hisilicon/djtag.h |  42 ++
 drivers/perf/hisilicon/hisi_uncore_l3c.c   | 653 +
 drivers/perf/hisilicon/hisi_uncore_mn.c| 528 ++
 drivers/perf/hisilicon/hisi_uncore_pmu.c   | 445 
 drivers/perf/hisilicon/hisi_uncore_pmu.h   | 137 
 14 files changed, 2915 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/hisilicon/djtag.txt
 create mode 100644 Documentation/devicetree/bindings/arm/hisilicon/pmu.txt
 create mode 100644 Documentation/perf/hisi-pmu.txt
 create mode 100644 drivers/perf/hisilicon/Makefile
 create mode 100644 drivers/perf/hisilicon/djtag.c
 create mode 100644 drivers/perf/hisilicon/djtag.h
 create mode 100644 drivers/perf/hisilicon/hisi_uncore_l3c.c
 create mode 100644 drivers/perf/hisilicon/hisi_uncore_mn.c
 create mode 100644 drivers/perf/hisilicon/hisi_uncore_pmu.c
 create mode 100644 drivers/perf/hisilicon/hisi_uncore_pmu.h

-- 
2.1.4



Re: [PATCH v5 3/4] dt-bindings: phy: Add support for QMP phy

2017-03-09 Thread Vivek Gautam



On 03/09/2017 04:37 PM, Bjorn Andersson wrote:

On Thu 09 Mar 10:07 CET 2017, Vivek Gautam wrote:

[..]

+   phy@34000 {
+   compatible = "qcom,msm8996-qmp-pcie-phy";
+   reg = <0x034000 0x488>;

Drop the leading 0 from the address.


Okay, will drop it.




+   #clock-cells = <1>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+
+   clocks = <&gcc GCC_PCIE_PHY_AUX_CLK>,
+   <&gcc GCC_PCIE_PHY_CFG_AHB_CLK>,
+   <&gcc GCC_PCIE_CLKREF_CLK>;
+   clock-names = "aux", "cfg_ahb", "ref";
+
+   vdda-phy-supply = <&pm8994_l28>;
+   vdda-pll-supply = <&pm8994_l12>;
+
+   resets = <&gcc GCC_PCIE_PHY_BCR>,
+   <&gcc GCC_PCIE_PHY_COM_BCR>,
+   <&gcc GCC_PCIE_PHY_COM_NOCSR_BCR>;
+   reset-names = "phy", "common", "cfg";
+
+   pciephy_0: lane@0 {

The "@xyz" part should match the first value in "reg", i.e. 35000 here.


Right, i think this came from my older version of patches. Will correct it.

Regards
Vivek



+   reg = <0x035000 0x130>,
+   <0x035200 0x200>,
+   <0x035400 0x1dc>;
+   #phy-cells = <0>;
+
+   clocks = <&gcc GCC_PCIE_0_PIPE_CLK>;
+   clock-names = "pipe0";
+   resets = <&gcc GCC_PCIE_0_PHY_BCR>;
+   reset-names = "lane0";
+   };
+
+   pciephy_1: lane@1 {
+   ...
+   ...
+   };

Regards,
Bjorn


--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH 5/5] block_dev: make blkdev_dio_pool a non-rescuing bioset

2017-03-09 Thread NeilBrown
Allocations from blkdev_dio_pool are never made under
generic_make_request, so this bioset does not need a rescuer thread.

Signed-off-by: NeilBrown 
---
 fs/block_dev.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index c0ca5f0d0369..2eca00ec4370 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -436,7 +436,7 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
 
 static __init int blkdev_init(void)
 {
-   blkdev_dio_pool = bioset_create_rescued(4, offsetof(struct blkdev_dio, 
bio));
+   blkdev_dio_pool = bioset_create(4, offsetof(struct blkdev_dio, bio));
if (!blkdev_dio_pool)
return -ENOMEM;
return 0;




[PATCH 4/5] blk: use non-rescuing bioset for q->bio_split.

2017-03-09 Thread NeilBrown
A rescuing bioset is only useful if there might be bios from
that same bioset on the bio_list_on_stack queue at a time
when bio_alloc_bioset() is called.  This never applies to
q->bio_split.

Allocations from q->bio_split are only ever made from
blk_queue_split() which is only ever called early in each of
various make_request_fn()s.  The original bio (call this A)
is then passed to generic_make_request() and is placed on
the bio_list_on_stack queue, and the bio that was allocated
from q->bio_split (B) is processed.

The processing of this may cause other bios to be passed to
generic_make_request() or may even cause the bio B itself to
be passed, possible after some prefix has been split off
(using some other bioset).

generic_make_request() now guarantees that all of these bios
(B and dependants) will be fully processed before the tail
of the original bio A gets handled.  None of these early bios
can possible trigger an allocation from the original
q->bio_split as they are either too small to require
splitting or (more likely) are destined for a different queue.

The next time that the original q->bio_split might be used
by this thread is when A is processed again, as it might
still be too big to handle directly.  By this time there
cannot be any other bios allocated from q->bio_split in the
generic_make_request() queue.  So no rescuing will ever be
needed.

Signed-off-by: NeilBrown 
---
 block/blk-core.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 430c82f646eb..fae7966e1f98 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -712,7 +712,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, 
int node_id)
if (q->id < 0)
goto fail_q;
 
-   q->bio_split = bioset_create_rescued(BIO_POOL_SIZE, 0);
+   q->bio_split = bioset_create(BIO_POOL_SIZE, 0);
if (!q->bio_split)
goto fail_id;
 




[PATCH 2/5] blk: remove bio_set arg from blk_queue_split()

2017-03-09 Thread NeilBrown
blk_queue_split() is always called with the last arg being q->bio_split,
where 'q' is the first arg.

Also blk_queue_split() sometimes uses the passed-in 'bs' and sometimes uses
q->bio_split.

This is inconsistent and unnecessary.  Remove the last arg and always use
q->bio_split inside blk_queue_split()

Signed-off-by: NeilBrown 
---
 block/blk-core.c  |2 +-
 block/blk-merge.c |7 +++
 block/blk-mq.c|4 ++--
 drivers/block/drbd/drbd_req.c |2 +-
 drivers/block/pktcdvd.c   |2 +-
 drivers/block/ps3vram.c   |2 +-
 drivers/block/rsxx/dev.c  |2 +-
 drivers/block/umem.c  |2 +-
 drivers/block/zram/zram_drv.c |2 +-
 drivers/lightnvm/rrpc.c   |2 +-
 drivers/md/md.c   |2 +-
 drivers/s390/block/dcssblk.c  |2 +-
 drivers/s390/block/xpram.c|2 +-
 include/linux/blkdev.h|3 +--
 14 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index d772c221cc17..fae7966e1f98 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1635,7 +1635,7 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, 
struct bio *bio)
 */
blk_queue_bounce(q, &bio);
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
if (bio_integrity_enabled(bio) && bio_integrity_prep(bio)) {
bio->bi_error = -EIO;
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 2afa262425d1..ce8838aff7f7 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -188,8 +188,7 @@ static struct bio *blk_bio_segment_split(struct 
request_queue *q,
return do_split ? new : NULL;
 }
 
-void blk_queue_split(struct request_queue *q, struct bio **bio,
-struct bio_set *bs)
+void blk_queue_split(struct request_queue *q, struct bio **bio)
 {
struct bio *split, *res;
unsigned nsegs;
@@ -197,14 +196,14 @@ void blk_queue_split(struct request_queue *q, struct bio 
**bio,
switch (bio_op(*bio)) {
case REQ_OP_DISCARD:
case REQ_OP_SECURE_ERASE:
-   split = blk_bio_discard_split(q, *bio, bs, &nsegs);
+   split = blk_bio_discard_split(q, *bio, q->bio_split, &nsegs);
break;
case REQ_OP_WRITE_ZEROES:
split = NULL;
nsegs = (*bio)->bi_phys_segments;
break;
case REQ_OP_WRITE_SAME:
-   split = blk_bio_write_same_split(q, *bio, bs, &nsegs);
+   split = blk_bio_write_same_split(q, *bio, q->bio_split, &nsegs);
break;
default:
split = blk_bio_segment_split(q, *bio, q->bio_split, &nsegs);
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 159187a28d66..e582d7f7511e 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1502,7 +1502,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue 
*q, struct bio *bio)
return BLK_QC_T_NONE;
}
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
if (!is_flush_fua && !blk_queue_nomerges(q) &&
blk_attempt_plug_merge(q, bio, &request_count, &same_queue_rq))
@@ -1624,7 +1624,7 @@ static blk_qc_t blk_sq_make_request(struct request_queue 
*q, struct bio *bio)
return BLK_QC_T_NONE;
}
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
if (!is_flush_fua && !blk_queue_nomerges(q)) {
if (blk_attempt_plug_merge(q, bio, &request_count, NULL))
diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c
index 652114ae1a8a..f6ed6f7f5ab2 100644
--- a/drivers/block/drbd/drbd_req.c
+++ b/drivers/block/drbd/drbd_req.c
@@ -1554,7 +1554,7 @@ blk_qc_t drbd_make_request(struct request_queue *q, 
struct bio *bio)
struct drbd_device *device = (struct drbd_device *) q->queuedata;
unsigned long start_jif;
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
start_jif = jiffies;
 
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 66d846ba85a9..98394d034c29 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -2414,7 +2414,7 @@ static blk_qc_t pkt_make_request(struct request_queue *q, 
struct bio *bio)
 
blk_queue_bounce(q, &bio);
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
pd = q->queuedata;
if (!pd) {
diff --git a/drivers/block/ps3vram.c b/drivers/block/ps3vram.c
index 456b4fe21559..48072c0c1010 100644
--- a/drivers/block/ps3vram.c
+++ b/drivers/block/ps3vram.c
@@ -606,7 +606,7 @@ static blk_qc_t ps3vram_make_request(struct request_queue 
*q, struct bio *bio)
 
dev_dbg(&dev->core, "%s\n", __func__);
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
spin_lock_irq(&priv->lock);
busy = !bio_list_empty(&priv->list)

[PATCH 3/5] blk: make the bioset rescue_workqueue optional.

2017-03-09 Thread NeilBrown
This patch converts bioset_create() and bioset_create_nobvec()
to not create a workqueue so alloctions will never trigger
punt_bios_to_rescuer().
It also introduces bioset_create_rescued() and bioset_create_nobvec_rescued()
which preserve the old behaviour.

*All* callers of bioset_create() and bioset_create_nobvec() are
converted to the _rescued() version, so that no change in behaviour
is experienced.

It is hoped that most, if not all, biosets can end up being the
non-rescued version.

Signed-off-by: NeilBrown 
---
 block/bio.c |   30 +-
 block/blk-core.c|2 +-
 drivers/block/drbd/drbd_main.c  |2 +-
 drivers/md/bcache/super.c   |4 ++--
 drivers/md/dm-crypt.c   |2 +-
 drivers/md/dm-io.c  |2 +-
 drivers/md/dm.c |5 +++--
 drivers/md/md.c |2 +-
 drivers/md/raid5-cache.c|2 +-
 drivers/target/target_core_iblock.c |2 +-
 fs/block_dev.c  |2 +-
 fs/btrfs/extent_io.c|4 ++--
 fs/xfs/xfs_super.c  |2 +-
 include/linux/bio.h |2 ++
 14 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index e75878f8b14a..3790c3f376b6 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -362,6 +362,8 @@ static void punt_bios_to_rescuer(struct bio_set *bs)
struct bio_list punt, nopunt;
struct bio *bio;
 
+   if (!WARN_ON_ONCE(!bs->rescue_workqueue))
+   return;
/*
 * In order to guarantee forward progress we must punt only bios that
 * were allocated from this bio_set; otherwise, if there was a bio on
@@ -472,7 +474,8 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, 
struct bio_set *bs)
 
if (current->bio_list &&
(!bio_list_empty(¤t->bio_list[0]) ||
-!bio_list_empty(¤t->bio_list[1])))
+!bio_list_empty(¤t->bio_list[1])) &&
+   bs->rescue_workqueue)
gfp_mask &= ~__GFP_DIRECT_RECLAIM;
 
p = mempool_alloc(bs->bio_pool, gfp_mask);
@@ -1941,7 +1944,8 @@ EXPORT_SYMBOL(bioset_free);
 
 static struct bio_set *__bioset_create(unsigned int pool_size,
   unsigned int front_pad,
-  bool create_bvec_pool)
+  bool create_bvec_pool,
+  bool create_rescue_workqueue)
 {
unsigned int back_pad = BIO_INLINE_VECS * sizeof(struct bio_vec);
struct bio_set *bs;
@@ -1972,6 +1976,9 @@ static struct bio_set *__bioset_create(unsigned int 
pool_size,
goto bad;
}
 
+   if (!create_rescue_workqueue)
+   return bs;
+
bs->rescue_workqueue = alloc_workqueue("bioset", WQ_MEM_RECLAIM, 0);
if (!bs->rescue_workqueue)
goto bad;
@@ -1997,10 +2004,16 @@ static struct bio_set *__bioset_create(unsigned int 
pool_size,
  */
 struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad)
 {
-   return __bioset_create(pool_size, front_pad, true);
+   return __bioset_create(pool_size, front_pad, true, false);
 }
 EXPORT_SYMBOL(bioset_create);
 
+struct bio_set *bioset_create_rescued(unsigned int pool_size, unsigned int 
front_pad)
+{
+   return __bioset_create(pool_size, front_pad, true, true);
+}
+EXPORT_SYMBOL(bioset_create_rescued);
+
 /**
  * bioset_create_nobvec  - Create a bio_set without bio_vec mempool
  * @pool_size: Number of bio to cache in the mempool
@@ -2012,10 +2025,17 @@ EXPORT_SYMBOL(bioset_create);
  */
 struct bio_set *bioset_create_nobvec(unsigned int pool_size, unsigned int 
front_pad)
 {
-   return __bioset_create(pool_size, front_pad, false);
+   return __bioset_create(pool_size, front_pad, false, false);
 }
 EXPORT_SYMBOL(bioset_create_nobvec);
 
+struct bio_set *bioset_create_nobvec_rescued(unsigned int pool_size,
+unsigned int front_pad)
+{
+   return __bioset_create(pool_size, front_pad, false, true);
+}
+EXPORT_SYMBOL(bioset_create_nobvec_rescued);
+
 #ifdef CONFIG_BLK_CGROUP
 
 /**
@@ -2130,7 +2150,7 @@ static int __init init_bio(void)
bio_integrity_init();
biovec_init_slabs();
 
-   fs_bio_set = bioset_create(BIO_POOL_SIZE, 0);
+   fs_bio_set = bioset_create_rescued(BIO_POOL_SIZE, 0);
if (!fs_bio_set)
panic("bio: can't allocate bios\n");
 
diff --git a/block/blk-core.c b/block/blk-core.c
index fae7966e1f98..430c82f646eb 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -712,7 +712,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, 
int node_id)
if (q->id < 0)
goto fail_q;
 
-   q->bio_split = bioset_create(BIO_POOL_SIZE, 0);
+   q->b

[PATCH 1/5] blk: Ensure users for current->bio_list can see the full list.

2017-03-09 Thread NeilBrown
Commit 79bd99596b73 ("blk: improve order of bio handling in 
generic_make_request()")
changed current->bio_list so that it did not contain *all* of the
queued bios, but only those submitted by the currently running
make_request_fn.

There are two places which walk the list and requeue selected bios,
and others that check if the list is empty.  These are no longer
correct.

So redefine current->bio_list to point to an array of two lists, which
contain all queued bios, and adjust various code to test or walk both
lists.

Signed-off-by: NeilBrown 
---
 block/bio.c |   12 +---
 block/blk-core.c|   30 ++
 drivers/md/dm.c |   29 -
 drivers/md/raid10.c |3 ++-
 4 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index 5eec5e08417f..e75878f8b14a 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -376,10 +376,14 @@ static void punt_bios_to_rescuer(struct bio_set *bs)
bio_list_init(&punt);
bio_list_init(&nopunt);
 
-   while ((bio = bio_list_pop(current->bio_list)))
+   while ((bio = bio_list_pop(¤t->bio_list[0])))
bio_list_add(bio->bi_pool == bs ? &punt : &nopunt, bio);
+   current->bio_list[0] = nopunt;
 
-   *current->bio_list = nopunt;
+   bio_list_init(&nopunt);
+   while ((bio = bio_list_pop(¤t->bio_list[1])))
+   bio_list_add(bio->bi_pool == bs ? &punt : &nopunt, bio);
+   current->bio_list[1] = nopunt;
 
spin_lock(&bs->rescue_lock);
bio_list_merge(&bs->rescue_list, &punt);
@@ -466,7 +470,9 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, 
struct bio_set *bs)
 * we retry with the original gfp_flags.
 */
 
-   if (current->bio_list && !bio_list_empty(current->bio_list))
+   if (current->bio_list &&
+   (!bio_list_empty(¤t->bio_list[0]) ||
+!bio_list_empty(¤t->bio_list[1])))
gfp_mask &= ~__GFP_DIRECT_RECLAIM;
 
p = mempool_alloc(bs->bio_pool, gfp_mask);
diff --git a/block/blk-core.c b/block/blk-core.c
index 0eeb99ef654f..d772c221cc17 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1973,7 +1973,14 @@ generic_make_request_checks(struct bio *bio)
  */
 blk_qc_t generic_make_request(struct bio *bio)
 {
-   struct bio_list bio_list_on_stack;
+   /*
+* bio_list_on_stack[0] contains bios submitted by the current
+* make_request_fn.
+* bio_list_on_stack[1] contains bios that were submitted before
+* the current make_request_fn, but that haven't been processed
+* yet.
+*/
+   struct bio_list bio_list_on_stack[2];
blk_qc_t ret = BLK_QC_T_NONE;
 
if (!generic_make_request_checks(bio))
@@ -1990,7 +1997,7 @@ blk_qc_t generic_make_request(struct bio *bio)
 * should be added at the tail
 */
if (current->bio_list) {
-   bio_list_add(current->bio_list, bio);
+   bio_list_add(¤t->bio_list[0], bio);
goto out;
}
 
@@ -2009,18 +2016,17 @@ blk_qc_t generic_make_request(struct bio *bio)
 * bio_list, and call into ->make_request() again.
 */
BUG_ON(bio->bi_next);
-   bio_list_init(&bio_list_on_stack);
-   current->bio_list = &bio_list_on_stack;
+   bio_list_init(&bio_list_on_stack[0]);
+   current->bio_list = bio_list_on_stack;
do {
struct request_queue *q = bdev_get_queue(bio->bi_bdev);
 
if (likely(blk_queue_enter(q, false) == 0)) {
-   struct bio_list hold;
struct bio_list lower, same;
 
/* Create a fresh bio_list for all subordinate requests 
*/
-   hold = bio_list_on_stack;
-   bio_list_init(&bio_list_on_stack);
+   bio_list_on_stack[1] = bio_list_on_stack[0];
+   bio_list_init(&bio_list_on_stack[0]);
ret = q->make_request_fn(q, bio);
 
blk_queue_exit(q);
@@ -2030,19 +2036,19 @@ blk_qc_t generic_make_request(struct bio *bio)
 */
bio_list_init(&lower);
bio_list_init(&same);
-   while ((bio = bio_list_pop(&bio_list_on_stack)) != NULL)
+   while ((bio = bio_list_pop(&bio_list_on_stack[0])) != 
NULL)
if (q == bdev_get_queue(bio->bi_bdev))
bio_list_add(&same, bio);
else
bio_list_add(&lower, bio);
/* now assemble so we handle the lowest level first */
-   bio_list_merge(&bio_list_on_stack, &lower);
-   bio_list_merge(&bio_list_on_stack, &same);
-   

[PATCH 0/5] Updates following recent generic_make_request improvement

2017-03-09 Thread NeilBrown
This is a rebase of the series I sent earlier, based on the
very latest from Linus, which included my first patch.

The first fixes a problem that patch introduced, and so should go to
Linux promptly.
The others are more general improvements and can go in the normal
course of events.

It is possible that the changes to btrfs and xfs can just be dropped
as a subsequent patch will be needed to revert them anyway.  They are
there only to be able to say that "blk: make the bioset
rescue_workqueue optional." doesn't change any functionality at all.

Thanks,
NeilBrown

---

NeilBrown (5):
  blk: Ensure users for current->bio_list can see the full list.
  blk: remove bio_set arg from blk_queue_split()
  blk: make the bioset rescue_workqueue optional.
  blk: use non-rescuing bioset for q->bio_split.
  block_dev: make blkdev_dio_pool a non-rescuing bioset


 block/bio.c |   40 +--
 block/blk-core.c|   32 +---
 block/blk-merge.c   |7 +++---
 block/blk-mq.c  |4 ++--
 drivers/block/drbd/drbd_main.c  |2 +-
 drivers/block/drbd/drbd_req.c   |2 +-
 drivers/block/pktcdvd.c |2 +-
 drivers/block/ps3vram.c |2 +-
 drivers/block/rsxx/dev.c|2 +-
 drivers/block/umem.c|2 +-
 drivers/block/zram/zram_drv.c   |2 +-
 drivers/lightnvm/rrpc.c |2 +-
 drivers/md/bcache/super.c   |4 ++--
 drivers/md/dm-crypt.c   |2 +-
 drivers/md/dm-io.c  |2 +-
 drivers/md/dm.c |   32 
 drivers/md/md.c |4 ++--
 drivers/md/raid10.c |3 ++-
 drivers/md/raid5-cache.c|2 +-
 drivers/s390/block/dcssblk.c|2 +-
 drivers/s390/block/xpram.c  |2 +-
 drivers/target/target_core_iblock.c |2 +-
 fs/btrfs/extent_io.c|4 ++--
 fs/xfs/xfs_super.c  |2 +-
 include/linux/bio.h |2 ++
 include/linux/blkdev.h  |3 +--
 26 files changed, 101 insertions(+), 64 deletions(-)

--
Signature



Re: outreachy

2017-03-09 Thread Greg KH
On Thu, Mar 09, 2017 at 02:15:21PM -0800, Florian Fainelli wrote:
> On 03/09/2017 01:20 PM, Greg KH wrote:
> > On Thu, Mar 09, 2017 at 01:56:49PM -0700, Stephen Warren wrote:
> >> On 03/09/2017 01:51 PM, Scott Branden wrote:
> >>> Hi Julia,
> >>>
> >>> On 17-03-09 12:36 PM, Julia Lawall wrote:
>  Hello,
> 
>  I discussed the issue of outreachy patches for bcm with Greg, and we are
>  not convinced that not having the patches CCd to you is such a good idea.
>  While we don't want to spam you with noise, some of the applicants are
>  starting to make more significant changes that it could be useful for you
>  to be aware of.
> 
>  Could we try a compromise where you are not CCd on whitespace patches,
>  but
>  you are CCd on patches that actually modify the code?
> >>>
> >>> All I'm asking is you work through your outreachy patches internal first
> >>> to get rid of the most basic mistakes and email traffic it is geerating.
> >>>  Once that learning process is through then they can be sent out like
> >>> any other patches to the kernel mailing lists and maintainers.
> >>
> >> +1 from me too; I find these patches rather high volume and had to add a
> >> filter to keep them out of my primary inbox.
> > 
> > Hah!  That's the joy of being a maintainer of a driver in staging.  Even
> > if you filter out outreachy, you are going to get a lot of "basic
> > mistakes" and other type patches cc:ed to you.
> > 
> > I strongly suggest, that if you all don't like this type of stuff,
> > either:
> > - work to get the code out of staging as soon as possible (i.e.
> >   send me coding style fixes for everything right now, and then
> >   fix up the rest of the stuff.)
> > - take yourself off the maintainer list for this code.
> 
> Keep in mind that most people on this CC list are getting these patches
> because of the bcm283* regular expression, and maybe that's what needs
> fixing here in the first place.

Yes, I suggest the someone fixes that if they do not wish to get these
types of emails.  Having a regex like that in MAINTAINERS is very crazy,
from another thread I don't think it's really doing what you all want it
to do (meaning it's hitting a lot more files than expected.)

> > It's your choice, outreachy right now is a lot of patches, but again,
> > it's not going to keep you from getting the "basic" stuff sent to you
> > in ways that is totally wrong.
> 
> That is absolutely true, but the thing is that we really got a big spike
> of patch submissions lately, and that was totally not accepted. I am not
> asking for a "heads-up" email telling people that they are going to
> receive more traffic than usual (because that would be too much over
> head), but if there was an internal review first on the outreachy
> mailing-list and second a proper submission which is going to pass your
> acceptance criteria, we would be de facto reducing the amount of emails
> that we received.
> 
> The outreachy list obviously has people like you and Julia who are
> willing to help and provide feedback, so I really don't see what's the
> problem in setting up a two tier review here, it does not change
> anything for you, but it does change a lot for us.

Again, even if outreachy isn't happening, you are still going to be
getting these types of patches from all of the "normal" people that send
staging cleanup patches.  So it's not going to buy you all that much of
a reprieve.

So please send in a MAINTAINERS patch if you don't wish to get these
kinds of patches.  Or, again, just spend a day and send me cleanup
patches to keep anyone else from needing to send in basic checkpatch
fixes for this code.

thanks,

greg k-h


[PATCH net, v2] dccp/tcp: fix routing redirect race

2017-03-09 Thread Jon Maxwell
As Eric Dumazet pointed out this also needs to be fixed in IPv6.
v2: Contains the IPv6 tcp/Ipv6 dccp patches as well.

We have seen a few incidents lately where a dst_enty has been freed
with a dangling TCP socket reference (sk->sk_dst_cache) pointing to that
dst_entry. If the conditions/timings are right a crash then ensues when the
freed dst_entry is referenced later on. A Common crashing back trace is:

 #8 [] page_fault at 8163e648
[exception RIP: __tcp_ack_snd_check+74]
.
.
 #9 [] tcp_rcv_established at 81580b64
#10 [] tcp_v4_do_rcv at 8158b54a
#11 [] tcp_v4_rcv at 8158cd02
#12 [] ip_local_deliver_finish at 815668f4
#13 [] ip_local_deliver at 81566bd9
#14 [] ip_rcv_finish at 8156656d
#15 [] ip_rcv at 81566f06
#16 [] __netif_receive_skb_core at 8152b3a2
#17 [] __netif_receive_skb at 8152b608
#18 [] netif_receive_skb at 8152b690
#19 [] vmxnet3_rq_rx_complete at a015eeaf [vmxnet3]
#20 [] vmxnet3_poll_rx_only at a015f32a [vmxnet3]
#21 [] net_rx_action at 8152bac2
#22 [] __do_softirq at 81084b4f
#23 [] call_softirq at 8164845c
#24 [] do_softirq at 81016fc5
#25 [] irq_exit at 81084ee5
#26 [] do_IRQ at 81648ff8

Of course it may happen with other NIC drivers as well.

It's found the freed dst_entry here:

 224 static bool tcp_in_quickack_mode(struct sock *sk)↩
 225 {↩
 226 ▹   const struct inet_connection_sock *icsk = inet_csk(sk);↩
 227 ▹   const struct dst_entry *dst = __sk_dst_get(sk);↩
 228 ↩
 229 ▹   return (dst && dst_metric(dst, RTAX_QUICKACK)) ||↩
 230 ▹   ▹   (icsk->icsk_ack.quick && !icsk->icsk_ack.pingpong);↩
 231 }↩

But there are other backtraces attributed to the same freed dst_entry in
netfilter code as well.

All the vmcores showed 2 significant clues:

- Remote hosts behind the default gateway had always been redirected to a
different gateway. A rtable/dst_entry will be added for that host. Making
more dst_entrys with lower reference counts. Making this more probable.

- All vmcores showed a postitive LockDroppedIcmps value, e.g:

LockDroppedIcmps  267

A closer look at the tcp_v4_err() handler revealed that do_redirect() will run
regardless of whether user space has the socket locked. This can result in a
race condition where the same dst_entry cached in sk->sk_dst_entry can be
decremented twice for the same socket via:

do_redirect()->__sk_dst_check()-> dst_release().

Which leads to the dst_entry being prematurely freed with another socket
pointing to it via sk->sk_dst_cache and a subsequent crash.

To fix this skip do_redirect() if usespace has the socket locked. Instead let
the redirect take place later when user space does not have the socket
locked.

The dccp/IPv6 code is very similar in this respect, so fixing it there too.

As Eric Garver pointed out the following commit now invalidates routes. Which
can set the dst->obsolete flag so that ipv4_dst_check() returns null and
triggers the dst_release().

Fixes: ceb3320610d6 ("ipv4: Kill routes during PMTU/redirect updates.")
Cc: Eric Garver 
Cc: Hannes Sowa 
Signed-off-by: Jon Maxwell 
---
 net/dccp/ipv4.c | 3 ++-
 net/dccp/ipv6.c | 8 +---
 net/ipv4/tcp_ipv4.c | 3 ++-
 net/ipv6/tcp_ipv6.c | 8 +---
 4 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 409d0cf..b99168b 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -289,7 +289,8 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info)
 
switch (type) {
case ICMP_REDIRECT:
-   dccp_do_redirect(skb, sk);
+   if (!sock_owned_by_user(sk))
+   dccp_do_redirect(skb, sk);
goto out;
case ICMP_SOURCE_QUENCH:
/* Just silently ignore these. */
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 233b573..d9b6a4e 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -122,10 +122,12 @@ static void dccp_v6_err(struct sk_buff *skb, struct 
inet6_skb_parm *opt,
np = inet6_sk(sk);
 
if (type == NDISC_REDIRECT) {
-   struct dst_entry *dst = __sk_dst_check(sk, np->dst_cookie);
+   if (!sock_owned_by_user(sk)) {
+   struct dst_entry *dst = __sk_dst_check(sk, 
np->dst_cookie);
 
-   if (dst)
-   dst->ops->redirect(dst, sk, skb);
+   if (dst)
+   dst->ops->redirect(dst, sk, skb);
+   }
goto out;
}
 
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 8f3ec13..575e19d 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -431,7 +431,8 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
 
switch (type) {
case ICMP_REDIRECT:
-   do_redirect(icmp_skb, sk);
+   if (!sock_owned_by_user(sk))
+   do_redirec

Re: [PATCH] Minor coding guideline Fix in lusture module

2017-03-09 Thread Dilger, Andreas
On Mar 9, 2017, at 05:22, Pushkar Jambhlekar  wrote:
> Subject: Minor coding guideline Fix in lusture module

I suspect the patchbot is unhappy with the subject line not containing anything
useful, and not containing the subsystem name. Something like:

staging/lustre/llite: replace "unsigned" with "unsigned int"

> Replacing 'unsigned' with 'unsigned int'  in vvp_pgcache_id.

Remove double space, and reference function names like vvp_pgcache_id().
 
> Checkpath.pl passed.

"checkpatch.pl"

Cheers, Andreas

> Signed-off-by: Pushkar Jambhlekar 
> ---
> drivers/staging/lustre/lustre/llite/vvp_dev.c | 9 -
> 1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/staging/lustre/lustre/llite/vvp_dev.c 
> b/drivers/staging/lustre/lustre/llite/vvp_dev.c
> index 12c129f7e..8d78755 100644
> --- a/drivers/staging/lustre/lustre/llite/vvp_dev.c
> +++ b/drivers/staging/lustre/lustre/llite/vvp_dev.c
> @@ -381,11 +381,10 @@ int cl_sb_fini(struct super_block *sb)
> #define PGC_DEPTH_SHIFT (32)
> 
> struct vvp_pgcache_id {
> - unsigned vpi_bucket;
> - unsigned vpi_depth;
> - uint32_t vpi_index;
> -
> - unsigned vpi_curdep;
> + unsigned intvpi_bucket;
> + unsigned intvpi_depth;
> + uint32_tvpi_index;
> + unsigned intvpi_curdep;
>   struct lu_object_header *vpi_obj;
> };
> 
> -- 
> 2.7.4
> 

Cheers, Andreas
--
Andreas Dilger
Lustre Principal Architect
Intel Corporation









Re: [PATCH v2] blk: improve order of bio handling in generic_make_request()

2017-03-09 Thread NeilBrown
On Thu, Mar 09 2017, Jens Axboe wrote:

> On 03/09/2017 09:32 PM, NeilBrown wrote:
>> 
>> I started looking further at the improvements we can make once
>> generic_make_request is fixed, and realised that I had missed an
>> important detail in this patch.
>> Several places test current->bio_list, and two actually edit the list.
>> With this change, that cannot see the whole lists, so it could cause a
>> regression.
>> 
>> So I've revised the patch to make sure that the entire list of queued
>> bios remains visible, and change the relevant code to look at both
>> the new list and the old list.
>> 
>> Following that there are some patches which make the rescuer thread
>> optional, and then starts removing it from some easy-to-fix places.
>
> Neil, note that the v2 patch is already in Linus tree as of earlier
> today. You need to rebase the series, and if we need fixups on
> top of v2, then that should be done separately and with increased
> urgency.

I had checked linux-next, but not the latest from Linus.
I see it now - thanks!
I'll rebase (and ensure nothing gets mangled)

Thanks,
NeilBrown


signature.asc
Description: PGP signature


Re: [PATCH net, v1] dccp/tcp: fix routing redirect race

2017-03-09 Thread Jonathan Maxwell
On Fri, Mar 10, 2017 at 3:23 PM, Eric Dumazet  wrote:
> On Fri, 2017-03-10 at 14:31 +1100, Jon Maxwell wrote:
>> As Eric Dumazet pointed out this also needs to be fixed in IPv6.
>> v1: Contains the IPv6 patch as well.
>
>> Fixes: ceb3320610d6 ("ipv4: Kill routes during PMTU/redirect updates.")
>> Cc: Eric Garver 
>> Cc: Hannes Sowa 
>> Signed-off-by: Jon Maxwell 
>> ---
>>  net/dccp/ipv4.c | 3 ++-
>>  net/ipv4/tcp_ipv4.c | 3 ++-
>>  net/ipv6/tcp_ipv6.c | 8 +---
>
> Hi Jon.
>
> You forgot net/dccp/ipv6.c
>
> dccp_v6_err() has the same issue.
>
>

Thanks Eric,

My bad. I'll fix that and post another patch.


[PATCH v5 02/39] [media] dt-bindings: Add bindings for i.MX media driver

2017-03-09 Thread Steve Longerbeam
Add bindings documentation for the i.MX media driver.

Signed-off-by: Steve Longerbeam 
---
 Documentation/devicetree/bindings/media/imx.txt | 74 +
 1 file changed, 74 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt

diff --git a/Documentation/devicetree/bindings/media/imx.txt 
b/Documentation/devicetree/bindings/media/imx.txt
new file mode 100644
index 000..3059c06
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/imx.txt
@@ -0,0 +1,74 @@
+Freescale i.MX Media Video Device
+=
+
+Video Media Controller node
+---
+
+This is the media controller node for video capture support. It is a
+virtual device that lists the camera serial interface nodes that the
+media device will control.
+
+Required properties:
+- compatible : "fsl,imx-capture-subsystem";
+- ports  : Should contain a list of phandles pointing to camera
+   sensor interface ports of IPU devices
+
+example:
+
+capture-subsystem {
+   compatible = "fsl,imx-capture-subsystem";
+   ports = <&ipu1_csi0>, <&ipu1_csi1>;
+};
+
+fim child node
+--
+
+This is an optional child node of the ipu_csi port nodes. If present and
+available, it enables the Frame Interval Monitor. Its properties can be
+used to modify the method in which the FIM measures frame intervals.
+Refer to Documentation/media/v4l-drivers/imx.rst for more info on the
+Frame Interval Monitor.
+
+Optional properties:
+- fsl,input-capture-channel: an input capture channel and channel flags,
+specified as . The channel number
+must be 0 or 1. The flags can be
+IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, or
+IRQ_TYPE_EDGE_BOTH, and specify which input
+capture signal edge will trigger the input
+capture event. If an input capture channel is
+specified, the FIM will use this method to
+measure frame intervals instead of via the EOF
+interrupt. The input capture method is much
+preferred over EOF as it is not subject to
+interrupt latency errors. However it requires
+routing the VSYNC or FIELD output signals of
+the camera sensor to one of the i.MX input
+capture pads (SD1_DAT0, SD1_DAT1), which also
+gives up support for SD1.
+
+
+mipi_csi2 node
+--
+
+This is the device node for the MIPI CSI-2 Receiver, required for MIPI
+CSI-2 sensors.
+
+Required properties:
+- compatible   : "fsl,imx6-mipi-csi2", "snps,dw-mipi-csi2";
+- reg   : physical base address and length of the register set;
+- clocks   : the MIPI CSI-2 receiver requires three clocks: hsi_tx
+ (the D-PHY clock), video_27m (D-PHY PLL reference
+ clock), and eim_podf;
+- clock-names  : must contain "dphy", "ref", "pix";
+- port@*: five port nodes must exist, containing endpoints
+ connecting to the source and sink devices according to
+ of_graph bindings. The first port is an input port,
+ connecting with a MIPI CSI-2 source, and ports 1
+ through 4 are output ports connecting with parallel
+ bus sink endpoint nodes and correspond to the four
+ MIPI CSI-2 virtual channel outputs.
+
+Optional properties:
+- interrupts   : must contain two level-triggered interrupts,
+ in order: 100 and 101;
-- 
2.7.4



[PATCH v5 04/39] ARM: dts: imx6qdl: Add compatible, clocks, irqs to MIPI CSI-2 node

2017-03-09 Thread Steve Longerbeam
Add to the MIPI CSI2 receiver node: compatible strings,
interrupt sources, and clocks.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index 6d7bf64..d28a413 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -1134,7 +1134,14 @@
};
 
mipi_csi: mipi@021dc000 {
+   compatible = "fsl,imx6-mipi-csi2", 
"snps,dw-mipi-csi2";
reg = <0x021dc000 0x4000>;
+   interrupts = <0 100 0x04>, <0 101 0x04>;
+   clocks = <&clks IMX6QDL_CLK_HSI_TX>,
+<&clks IMX6QDL_CLK_VIDEO_27M>,
+<&clks IMX6QDL_CLK_EIM_PODF>;
+   clock-names = "dphy", "ref", "pix";
+   status = "disabled";
};
 
mipi_dsi: mipi@021e {
-- 
2.7.4



[PATCH v5 07/39] ARM: dts: imx6qdl-sabrelite: remove erratum ERR006687 workaround

2017-03-09 Thread Steve Longerbeam
There is a pin conflict with GPIO_6. This pin functions as a power
input pin to the OV5642 camera sensor, but ENET uses it as the h/w
workaround for erratum ERR006687, to wake-up the ARM cores on normal
RX and TX packet done events. So we need to remove the h/w workaround
to support the OV5642. The result is that the CPUidle driver will no
longer allow entering the deep idle states on the sabrelite.

This is a partial revert of

commit 6261c4c8f13e ("ARM: dts: imx6qdl-sabrelite: use GPIO_6 for FEC
interrupt.")
commit a28eeb43ee57 ("ARM: dts: imx6: tag boards that have the HW workaround
for ERR006687")

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabrelite.dtsi | 4 
 1 file changed, 4 deletions(-)

diff --git a/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
index 8413179..89dce27 100644
--- a/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
@@ -270,9 +270,6 @@
txd1-skew-ps = <0>;
txd2-skew-ps = <0>;
txd3-skew-ps = <0>;
-   interrupts-extended = <&gpio1 6 IRQ_TYPE_LEVEL_HIGH>,
- <&intc 0 119 IRQ_TYPE_LEVEL_HIGH>;
-   fsl,err006687-workaround-present;
status = "okay";
 };
 
@@ -373,7 +370,6 @@
MX6QDL_PAD_RGMII_RX_CTL__RGMII_RX_CTL   0x1b030
/* Phy reset */
MX6QDL_PAD_EIM_D23__GPIO3_IO23  0x000b0
-   MX6QDL_PAD_GPIO_6__ENET_IRQ 0x000b1
>;
};
 
-- 
2.7.4



[PATCH v5 06/39] ARM: dts: imx6qdl: add capture-subsystem device

2017-03-09 Thread Steve Longerbeam
Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6dl.dtsi | 5 +
 arch/arm/boot/dts/imx6q.dtsi  | 5 +
 2 files changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/imx6dl.dtsi b/arch/arm/boot/dts/imx6dl.dtsi
index 8958c4a..a959c76 100644
--- a/arch/arm/boot/dts/imx6dl.dtsi
+++ b/arch/arm/boot/dts/imx6dl.dtsi
@@ -100,6 +100,11 @@
};
};
 
+   capture-subsystem {
+   compatible = "fsl,imx-capture-subsystem";
+   ports = <&ipu1_csi0>, <&ipu1_csi1>;
+   };
+
display-subsystem {
compatible = "fsl,imx-display-subsystem";
ports = <&ipu1_di0>, <&ipu1_di1>;
diff --git a/arch/arm/boot/dts/imx6q.dtsi b/arch/arm/boot/dts/imx6q.dtsi
index b833b0d..4cc6579 100644
--- a/arch/arm/boot/dts/imx6q.dtsi
+++ b/arch/arm/boot/dts/imx6q.dtsi
@@ -206,6 +206,11 @@
};
};
 
+   capture-subsystem {
+   compatible = "fsl,imx-capture-subsystem";
+   ports = <&ipu1_csi0>, <&ipu1_csi1>, <&ipu2_csi0>, <&ipu2_csi1>;
+   };
+
display-subsystem {
compatible = "fsl,imx-display-subsystem";
ports = <&ipu1_di0>, <&ipu1_di1>, <&ipu2_di0>, <&ipu2_di1>;
-- 
2.7.4



[PATCH v5 12/39] ARM: dts: imx6-sabreauto: add pinctrl for gpt input capture

2017-03-09 Thread Steve Longerbeam
Add pinctrl groups for both GPT input capture channels.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index 21dea5f..1212f82 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -456,6 +456,18 @@
>;
};
 
+   pinctrl_gpt_input_capture0: gptinputcapture0grp {
+   fsl,pins = <
+   MX6QDL_PAD_SD1_DAT0__GPT_CAPTURE1   0x1b0b0
+   >;
+   };
+
+   pinctrl_gpt_input_capture1: gptinputcapture1grp {
+   fsl,pins = <
+   MX6QDL_PAD_SD1_DAT1__GPT_CAPTURE2   0x1b0b0
+   >;
+   };
+
pinctrl_spdif: spdifgrp {
fsl,pins = <
MX6QDL_PAD_KEY_COL3__SPDIF_IN 0x1b0b0
-- 
2.7.4



[PATCH v5 18/39] [media] v4l: subdev: Add function to validate frame interval

2017-03-09 Thread Steve Longerbeam
If the pads on both sides of a link specify a frame interval, then
those frame intervals should match. Create the exported function
v4l2_subdev_link_validate_frame_interval() to verify this. This
function can be called in a subdevice's media_entity_operations
or v4l2_subdev_pad_ops link_validate callbacks.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/v4l2-core/v4l2-subdev.c | 50 +++
 include/media/v4l2-subdev.h   | 10 +++
 2 files changed, 60 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
b/drivers/media/v4l2-core/v4l2-subdev.c
index da78497..7a0f387 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -521,6 +521,25 @@ int v4l2_subdev_link_validate_default(struct v4l2_subdev 
*sd,
 EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate_default);
 
 static int
+v4l2_subdev_link_validate_get_fi(struct media_pad *pad,
+struct v4l2_subdev_frame_interval *fi)
+{
+   if (is_media_entity_v4l2_subdev(pad->entity)) {
+   struct v4l2_subdev *sd =
+   media_entity_to_v4l2_subdev(pad->entity);
+
+   fi->pad = pad->index;
+   return v4l2_subdev_call(sd, video, g_frame_interval, fi);
+   }
+
+   WARN(pad->entity->function != MEDIA_ENT_F_IO_V4L,
+"Driver bug! Wrong media entity type 0x%08x, entity %s\n",
+pad->entity->function, pad->entity->name);
+
+   return -EINVAL;
+}
+
+static int
 v4l2_subdev_link_validate_get_format(struct media_pad *pad,
 struct v4l2_subdev_format *fmt)
 {
@@ -540,6 +559,37 @@ v4l2_subdev_link_validate_get_format(struct media_pad *pad,
return -EINVAL;
 }
 
+int v4l2_subdev_link_validate_frame_interval(struct media_link *link)
+{
+   struct v4l2_subdev_frame_interval src_fi, sink_fi;
+   unsigned long src_usec, sink_usec;
+   int rval;
+
+   rval = v4l2_subdev_link_validate_get_fi(link->source, &src_fi);
+   if (rval < 0)
+   return 0;
+
+   rval = v4l2_subdev_link_validate_get_fi(link->sink, &sink_fi);
+   if (rval < 0)
+   return 0;
+
+   if (src_fi.interval.numerator == 0   ||
+   src_fi.interval.denominator == 0 ||
+   sink_fi.interval.numerator == 0  ||
+   sink_fi.interval.denominator == 0)
+   return -EPIPE;
+
+   src_usec = DIV_ROUND_CLOSEST_ULL(
+   (u64)src_fi.interval.numerator * USEC_PER_SEC,
+   src_fi.interval.denominator);
+   sink_usec = DIV_ROUND_CLOSEST_ULL(
+   (u64)sink_fi.interval.numerator * USEC_PER_SEC,
+   sink_fi.interval.denominator);
+
+   return (src_usec != sink_usec) ? -EPIPE : 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate_frame_interval);
+
 int v4l2_subdev_link_validate(struct media_link *link)
 {
struct v4l2_subdev *sink;
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 0ab1c5d..60c941d 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -929,6 +929,16 @@ int v4l2_subdev_link_validate_default(struct v4l2_subdev 
*sd,
  struct v4l2_subdev_format *sink_fmt);
 
 /**
+ * v4l2_subdev_link_validate_frame_interval - validates a media link
+ *
+ * @link: pointer to &struct media_link
+ *
+ * This function ensures that the frame intervals, if specified by
+ * both the source and sink subdevs of the link, are equal.
+ */
+int v4l2_subdev_link_validate_frame_interval(struct media_link *link);
+
+/**
  * v4l2_subdev_link_validate - validates a media link
  *
  * @link: pointer to &struct media_link
-- 
2.7.4



[PATCH v5 14/39] add mux and video interface bridge entity functions

2017-03-09 Thread Steve Longerbeam
From: Philipp Zabel 

Signed-off-by: Philipp Zabel 

- renamed MEDIA_ENT_F_MUX to MEDIA_ENT_F_VID_MUX

Signed-off-by: Steve Longerbeam 
---
 Documentation/media/uapi/mediactl/media-types.rst | 22 ++
 include/uapi/linux/media.h|  6 ++
 2 files changed, 28 insertions(+)

diff --git a/Documentation/media/uapi/mediactl/media-types.rst 
b/Documentation/media/uapi/mediactl/media-types.rst
index 3e03dc2..9d908fe 100644
--- a/Documentation/media/uapi/mediactl/media-types.rst
+++ b/Documentation/media/uapi/mediactl/media-types.rst
@@ -298,6 +298,28 @@ Types and flags used to represent the media graph elements
  received on its sink pad and outputs the statistics data on
  its source pad.
 
+-  ..  row 29
+
+   ..  _MEDIA-ENT-F-VID-MUX:
+
+   -  ``MEDIA_ENT_F_VID_MUX``
+
+   - Video multiplexer. An entity capable of multiplexing must have at
+ least two sink pads and one source pad, and must pass the video
+ frame(s) received from the active sink pad to the source pad. Video
+ frame(s) from the inactive sink pads are discarded.
+
+-  ..  row 30
+
+   ..  _MEDIA-ENT-F-VID-IF-BRIDGE:
+
+   -  ``MEDIA_ENT_F_VID_IF_BRIDGE``
+
+   - Video interface bridge. A video interface bridge entity must have at
+ least one sink pad and one source pad. It receives video frame(s) on
+ its sink pad in one bus format (HDMI, eDP, MIPI CSI-2, ...) and
+ converts them and outputs them on its source pad in another bus format
+ (eDP, MIPI CSI-2, parallel, ...).
 
 ..  tabularcolumns:: |p{5.5cm}|p{12.0cm}|
 
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 4890787..fac96c6 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -105,6 +105,12 @@ struct media_device_info {
 #define MEDIA_ENT_F_PROC_VIDEO_STATISTICS  (MEDIA_ENT_F_BASE + 0x4006)
 
 /*
+ * Switch and bridge entitites
+ */
+#define MEDIA_ENT_F_VID_MUX(MEDIA_ENT_F_BASE + 0x5001)
+#define MEDIA_ENT_F_VID_IF_BRIDGE  (MEDIA_ENT_F_BASE + 0x5002)
+
+/*
  * Connectors
  */
 /* It is a responsibility of the entity drivers to add connectors and links */
-- 
2.7.4



[PATCH v5 16/39] [media] v4l2: add a new-frame before end-of-frame event

2017-03-09 Thread Steve Longerbeam
Add a NEW_FRAME_BEFORE_EOF event to signal that a video capture or
output device has signaled a new frame is ready before a previous
frame has completed reception or transmission. This usually indicates
a DMA read/write channel is having trouble gaining bus access.

Signed-off-by: Steve Longerbeam 
---
 Documentation/media/uapi/v4l/vidioc-dqevent.rst | 6 ++
 Documentation/media/videodev2.h.rst.exceptions  | 1 +
 include/uapi/linux/videodev2.h  | 1 +
 3 files changed, 8 insertions(+)

diff --git a/Documentation/media/uapi/v4l/vidioc-dqevent.rst 
b/Documentation/media/uapi/v4l/vidioc-dqevent.rst
index dc77363..54bc7ae 100644
--- a/Documentation/media/uapi/v4l/vidioc-dqevent.rst
+++ b/Documentation/media/uapi/v4l/vidioc-dqevent.rst
@@ -203,6 +203,12 @@ call.
has measured an interval between the reception or transmit
completion of two consecutive frames of video that is outside
the nominal frame interval by some tolerance value.
+* - ``V4L2_EVENT_NEW_FRAME_BEFORE_EOF``
+  - 8
+  - This event is triggered when the video capture or output device
+   has signaled a new frame is ready before a previous frame has
+   completed reception or transmission. This usually indicates a
+   DMA read/write channel is having trouble gaining bus access.
 * - ``V4L2_EVENT_PRIVATE_START``
   - 0x0800
   - Base event number for driver-private events.
diff --git a/Documentation/media/videodev2.h.rst.exceptions 
b/Documentation/media/videodev2.h.rst.exceptions
index c7d8fad..be6f332 100644
--- a/Documentation/media/videodev2.h.rst.exceptions
+++ b/Documentation/media/videodev2.h.rst.exceptions
@@ -460,6 +460,7 @@ replace define V4L2_EVENT_FRAME_SYNC event-type
 replace define V4L2_EVENT_SOURCE_CHANGE event-type
 replace define V4L2_EVENT_MOTION_DET event-type
 replace define V4L2_EVENT_FRAME_INTERVAL_ERROR event-type
+replace define V4L2_EVENT_NEW_FRAME_BEFORE_EOF event-type
 replace define V4L2_EVENT_PRIVATE_START event-type
 
 replace define V4L2_EVENT_CTRL_CH_VALUE ctrl-changes-flags
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index cf5a0d0..f54a82a 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -2132,6 +2132,7 @@ struct v4l2_streamparm {
 #define V4L2_EVENT_SOURCE_CHANGE   5
 #define V4L2_EVENT_MOTION_DET  6
 #define V4L2_EVENT_FRAME_INTERVAL_ERROR7
+#define V4L2_EVENT_NEW_FRAME_BEFORE_EOF8
 #define V4L2_EVENT_PRIVATE_START   0x0800
 
 /* Payload for V4L2_EVENT_VSYNC */
-- 
2.7.4



Re: [PATCH v4] soc/imx: Add GPCv2 power gating driver

2017-03-09 Thread Andrey Smirnov
On Wed, Mar 8, 2017 at 3:39 AM, Shawn Guo  wrote:
> On Tue, Feb 28, 2017 at 04:09:16PM -0800, Andrey Smirnov wrote:
>> Add code allowing for control of various power domains managed by GPCv2
>
> GPCv2, is it the name used in i.MX7 SoC manual?

No, the manual refers to it as GPC. GPCv2 came from already existing
irqchip driver

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/irqchip/irq-imx-gpcv2.c?id=refs/tags/v4.11-rc1

Plus, I think, there were a number of LKML patch submission threads
where that IP block was referred to as as GPCv2 by Freescale devs.

>
>> IP block found in i.MX7 series of SoCs. Power domains covered by this
>> patch are:
>>
>> - PCIE PHY
>> - MIPI PHY
>> - USB HSIC PHY
>> - USB OTG1/2 PHY
>>
>> Support for any other power domain controlled by GPC is not present, and
>> can be added at some later point.
>>
>> Testing of this code was done against a PCIe driver.
>>
>> Cc: yurov...@gmail.com
>> Cc: Lucas Stach 
>> Cc: Rob Herring 
>> Cc: Mark Rutland 
>> Cc: Fabio Estevam 
>> Cc: devicet...@vger.kernel.org
>> Cc: linux-arm-ker...@lists.infradead.org
>> Cc: linux-kernel@vger.kernel.org
>> Acked-by: Rob Herring 
>> Signed-off-by: Andrey Smirnov 
>> ---
>>
>> Changes since v3 (see [v3]):
>>
>>   - Minor device tree bindings documentation fixes as per
>>   feedback from Rob Herring
>>   - Collect Acked-by from Rob
>>
>> Changes since v2 (see [v2]):
>>
>>   - Fix a critical bug where incorrect state of a bit was
>>   expected in a busy wait loop (bit set instead of bit
>>   cleared) imx7_gpc_pu_pgc_sw_pxx_req()
>>
>>   - Add missing step (setting of PCR in GPC_PGC_nCTRL) in power
>>   down procedure
>>
>> Changes since v1 (see [v1]):
>>
>>   - Various small DT bindings description fixes as per feedback
>>   from Rob Herring
>>
>>
>> [v1] https://lkml.org/lkml/2017/2/6/554
>> [v2] https://lkml.org/lkml/2017/2/13/489
>> [v3] https://lkml.org/lkml/2017/2/20/338
>>
>>  .../devicetree/bindings/power/fsl,imx-gpcv2.txt|  71 
>>  drivers/soc/imx/Makefile   |   2 +-
>>  drivers/soc/imx/gpcv2.c| 397 
>> +
>>  include/dt-bindings/power/imx7-power.h |  18 +
>
> Please have fsl,imx-gpcv2.txt and imx7-power.h in a separate dt-bindings
> patch, and attach Rob's ACK to it.

OK, will do in v4.

>
>>  4 files changed, 487 insertions(+), 1 deletion(-)
>>  create mode 100644 Documentation/devicetree/bindings/power/fsl,imx-gpcv2.txt
>>  create mode 100644 drivers/soc/imx/gpcv2.c
>>  create mode 100644 include/dt-bindings/power/imx7-power.h
>>
>> diff --git a/Documentation/devicetree/bindings/power/fsl,imx-gpcv2.txt 
>> b/Documentation/devicetree/bindings/power/fsl,imx-gpcv2.txt
>> new file mode 100644
>> index 000..02f45c6
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/power/fsl,imx-gpcv2.txt
>> @@ -0,0 +1,71 @@
>> +Freescale i.MX General Power Controller v2
>> +==
>> +
>> +The i.MX7S/D General Power Control (GPC) block contains Power Gating
>> +Control (PGC) for various power domains.
>> +
>> +Required properties:
>> +
>> +- compatible: Should be "fsl,imx7d-gpc"
>> +
>> +- reg: should be register base and length as documented in the
>> +  datasheet
>> +
>> +- interrupts: Should contain GPC interrupt request 1
>> +
>> +Power domains contained within GPC node are generic power domain
>> +providers, documented in
>> +Documentation/devicetree/bindings/power/power_domain.txt, which are
>> +described as subnodes of the power gating controller 'pgc' node,
>> +which, in turn, is expected to contain the following:
>> +
>> +Required properties:
>> +
>> +- reg: Power domain index. Valid values are defined in
>> +  include/dt-bindings/power/imx7-power.h
>> +
>> +- #power-domain-cells: Should be 0
>> +
>> +Optional properties:
>> +
>> +- power-supply: Power supply used to power the domain
>> +
>> +Example:
>> +
>> + gpc: gpc@303a {
>> + compatible = "fsl,imx7d-gpc";
>> + reg = <0x303a 0x1000>;
>> + interrupt-controller;
>> + interrupts = ;
>> + #interrupt-cells = <3>;
>> + interrupt-parent = <&intc>;
>> +
>> + pgc {
>> + #address-cells = <1>;
>> + #size-cells = <0>;
>> +
>> + pgc_pcie_phy: power-domain@3 {
>> + #power-domain-cells = <0>;
>> +
>> + reg = ;
>> + power-supply = <®_1p0d>;
>> + };
>> + };
>> + };
>> +
>> +
>> +Specifying power domain for IP modules
>> +==
>> +
>> +IP cores belonging to a power domain should contain a 'power-domains'
>> +property that is a phandle for PGC node representing the domain.
>> +
>> +Example of a device that is part of the PCIE_PHY p

[PATCH v5 13/39] ARM: dts: imx6-sabreauto: add the ADV7180 video decoder

2017-03-09 Thread Steve Longerbeam
Enables the ADV7180 decoder sensor. The ADV7180 connects to the
parallel-bus mux input on ipu1_csi0_mux.

The ADV7180 power pin is via max7310_b port expander.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 58 
 1 file changed, 58 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index 1212f82..a712ff1 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -124,6 +124,21 @@
#size-cells = <0>;
reg = <1>;
 
+   adv7180: camera@21 {
+   compatible = "adi,adv7180";
+   reg = <0x21>;
+   powerdown-gpios = <&max7310_b 2 
GPIO_ACTIVE_LOW>;
+   interrupt-parent = <&gpio1>;
+   interrupts = <27 0x8>;
+
+   port {
+   adv7180_to_ipu1_csi0_mux: endpoint {
+   remote-endpoint = 
<&ipu1_csi0_mux_from_parallel_sensor>;
+   bus-width = <8>;
+   };
+   };
+   };
+
max7310_a: gpio@30 {
compatible = "maxim,max7310";
reg = <0x30>;
@@ -151,6 +166,25 @@
};
 };
 
+&ipu1_csi0_from_ipu1_csi0_mux {
+   bus-width = <8>;
+};
+
+&ipu1_csi0_mux_from_parallel_sensor {
+   remote-endpoint = <&adv7180_to_ipu1_csi0_mux>;
+   bus-width = <8>;
+};
+
+&ipu1_csi0 {
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ipu1_csi0>;
+
+   /* enable frame interval monitor on this port */
+   fim {
+   status = "okay";
+   };
+};
+
 &clks {
assigned-clocks = <&clks IMX6QDL_PLL4_BYPASS_SRC>,
  <&clks IMX6QDL_PLL4_BYPASS>,
@@ -444,6 +478,30 @@
>;
};
 
+   pinctrl_ipu1_csi0: ipu1csi0grp {
+   fsl,pins = <
+   MX6QDL_PAD_CSI0_DAT4__IPU1_CSI0_DATA04   0x1b0b0
+   MX6QDL_PAD_CSI0_DAT5__IPU1_CSI0_DATA05   0x1b0b0
+   MX6QDL_PAD_CSI0_DAT6__IPU1_CSI0_DATA06   0x1b0b0
+   MX6QDL_PAD_CSI0_DAT7__IPU1_CSI0_DATA07   0x1b0b0
+   MX6QDL_PAD_CSI0_DAT8__IPU1_CSI0_DATA08   0x1b0b0
+   MX6QDL_PAD_CSI0_DAT9__IPU1_CSI0_DATA09   0x1b0b0
+   MX6QDL_PAD_CSI0_DAT10__IPU1_CSI0_DATA10  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT11__IPU1_CSI0_DATA11  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT12__IPU1_CSI0_DATA12  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT13__IPU1_CSI0_DATA13  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT14__IPU1_CSI0_DATA14  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT15__IPU1_CSI0_DATA15  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT16__IPU1_CSI0_DATA16  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT17__IPU1_CSI0_DATA17  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT18__IPU1_CSI0_DATA18  0x1b0b0
+   MX6QDL_PAD_CSI0_DAT19__IPU1_CSI0_DATA19  0x1b0b0
+   MX6QDL_PAD_CSI0_PIXCLK__IPU1_CSI0_PIXCLK 0x1b0b0
+   MX6QDL_PAD_CSI0_MCLK__IPU1_CSI0_HSYNC0x1b0b0
+   MX6QDL_PAD_CSI0_VSYNC__IPU1_CSI0_VSYNC   0x1b0b0
+   >;
+   };
+
pinctrl_max7310: max7310grp {
fsl,pins = <
MX6QDL_PAD_SD2_DAT0__GPIO1_IO15 0x1b0b0
-- 
2.7.4



[PATCH v5 17/39] [media] v4l2-mc: add a function to inherit controls from a pipeline

2017-03-09 Thread Steve Longerbeam
v4l2_pipeline_inherit_controls() will add the v4l2 controls from
all subdev entities in a pipeline to a given video device.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/v4l2-core/v4l2-mc.c | 48 +++
 include/media/v4l2-mc.h   | 25 
 2 files changed, 73 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-mc.c 
b/drivers/media/v4l2-core/v4l2-mc.c
index 303980b..09d4d97 100644
--- a/drivers/media/v4l2-core/v4l2-mc.c
+++ b/drivers/media/v4l2-core/v4l2-mc.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+struct media_entity *start_entity)
+{
+   struct media_device *mdev = start_entity->graph_obj.mdev;
+   struct media_entity *entity;
+   struct media_graph graph;
+   struct v4l2_subdev *sd;
+   int ret;
+
+   ret = media_graph_walk_init(&graph, mdev);
+   if (ret)
+   return ret;
+
+   media_graph_walk_start(&graph, start_entity);
+
+   while ((entity = media_graph_walk_next(&graph))) {
+   if (!is_media_entity_v4l2_subdev(entity))
+   continue;
+
+   sd = media_entity_to_v4l2_subdev(entity);
+
+   ret = v4l2_ctrl_add_handler(vfd->ctrl_handler,
+   sd->ctrl_handler,
+   NULL);
+   if (ret)
+   break;
+   }
+
+   media_graph_walk_cleanup(&graph);
+   return ret;
+}
+EXPORT_SYMBOL_GPL(__v4l2_pipeline_inherit_controls);
+
+int v4l2_pipeline_inherit_controls(struct video_device *vfd,
+  struct media_entity *start_entity)
+{
+   struct media_device *mdev = start_entity->graph_obj.mdev;
+   int ret;
+
+   mutex_lock(&mdev->graph_mutex);
+   ret = __v4l2_pipeline_inherit_controls(vfd, start_entity);
+   mutex_unlock(&mdev->graph_mutex);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(v4l2_pipeline_inherit_controls);
+
 /* 
-
  * Pipeline power management
  *
diff --git a/include/media/v4l2-mc.h b/include/media/v4l2-mc.h
index 2634d9d..9848e77 100644
--- a/include/media/v4l2-mc.h
+++ b/include/media/v4l2-mc.h
@@ -171,6 +171,17 @@ void v4l_disable_media_source(struct video_device *vdev);
  */
 int v4l_vb2q_enable_media_source(struct vb2_queue *q);
 
+/**
+ * v4l2_pipeline_inherit_controls - Add the v4l2 controls from all
+ * subdev entities in a pipeline to
+ * the given video device.
+ * @vfd: the video device
+ * @start_entity: Starting entity
+ */
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+struct media_entity *start_entity);
+int v4l2_pipeline_inherit_controls(struct video_device *vfd,
+  struct media_entity *start_entity);
 
 /**
  * v4l2_pipeline_pm_use - Update the use count of an entity
@@ -231,6 +242,20 @@ static inline int v4l_vb2q_enable_media_source(struct 
vb2_queue *q)
return 0;
 }
 
+static inline int __v4l2_pipeline_inherit_controls(
+   struct video_device *vfd,
+   struct media_entity *start_entity)
+{
+   return 0;
+}
+
+static inline int v4l2_pipeline_inherit_controls(
+   struct video_device *vfd,
+   struct media_entity *start_entity)
+{
+   return 0;
+}
+
 static inline int v4l2_pipeline_pm_use(struct media_entity *entity, int use)
 {
return 0;
-- 
2.7.4



[PATCH v5 23/39] media: Add i.MX media core driver

2017-03-09 Thread Steve Longerbeam
Add the core media driver for i.MX SOC.

Signed-off-by: Steve Longerbeam 
---
 Documentation/media/v4l-drivers/imx.rst   | 560 
 drivers/staging/media/Kconfig |   2 +
 drivers/staging/media/Makefile|   1 +
 drivers/staging/media/imx/Kconfig |   6 +
 drivers/staging/media/imx/Makefile|   5 +
 drivers/staging/media/imx/TODO|  17 +
 drivers/staging/media/imx/imx-media-dev.c | 522 +++
 drivers/staging/media/imx/imx-media-fim.c | 471 +
 drivers/staging/media/imx/imx-media-internal-sd.c | 349 ++
 drivers/staging/media/imx/imx-media-of.c  | 267 
 drivers/staging/media/imx/imx-media-utils.c   | 766 ++
 drivers/staging/media/imx/imx-media.h | 303 +
 include/media/imx.h   |  15 +
 include/uapi/linux/v4l2-controls.h|   4 +
 14 files changed, 3288 insertions(+)
 create mode 100644 Documentation/media/v4l-drivers/imx.rst
 create mode 100644 drivers/staging/media/imx/Kconfig
 create mode 100644 drivers/staging/media/imx/Makefile
 create mode 100644 drivers/staging/media/imx/TODO
 create mode 100644 drivers/staging/media/imx/imx-media-dev.c
 create mode 100644 drivers/staging/media/imx/imx-media-fim.c
 create mode 100644 drivers/staging/media/imx/imx-media-internal-sd.c
 create mode 100644 drivers/staging/media/imx/imx-media-of.c
 create mode 100644 drivers/staging/media/imx/imx-media-utils.c
 create mode 100644 drivers/staging/media/imx/imx-media.h
 create mode 100644 include/media/imx.h

diff --git a/Documentation/media/v4l-drivers/imx.rst 
b/Documentation/media/v4l-drivers/imx.rst
new file mode 100644
index 000..443e0d0
--- /dev/null
+++ b/Documentation/media/v4l-drivers/imx.rst
@@ -0,0 +1,560 @@
+i.MX Video Capture Driver
+=
+
+Introduction
+
+
+The Freescale i.MX5/6 contains an Image Processing Unit (IPU), which
+handles the flow of image frames to and from capture devices and
+display devices.
+
+For image capture, the IPU contains the following internal subunits:
+
+- Image DMA Controller (IDMAC)
+- Camera Serial Interface (CSI)
+- Image Converter (IC)
+- Sensor Multi-FIFO Controller (SMFC)
+- Image Rotator (IRT)
+- Video De-Interlacing or Combining Block (VDIC)
+
+The IDMAC is the DMA controller for transfer of image frames to and from
+memory. Various dedicated DMA channels exist for both video capture and
+display paths. During transfer, the IDMAC is also capable of vertical
+image flip, 8x8 block transfer (see IRT description), pixel component
+re-ordering (for example UYVY to YUYV) within the same colorspace, and
+even packed <--> planar conversion. It can also perform a simple
+de-interlacing by interleaving even and odd lines during transfer
+(without motion compensation which requires the VDIC).
+
+The CSI is the backend capture unit that interfaces directly with
+camera sensors over Parallel, BT.656/1120, and MIPI CSI-2 busses.
+
+The IC handles color-space conversion, resizing (downscaling and
+upscaling), horizontal flip, and 90/270 degree rotation operations.
+
+There are three independent "tasks" within the IC that can carry out
+conversions concurrently: pre-process encoding, pre-process viewfinder,
+and post-processing. Within each task, conversions are split into three
+sections: downsizing section, main section (upsizing, flip, colorspace
+conversion, and graphics plane combining), and rotation section.
+
+The IPU time-shares the IC task operations. The time-slice granularity
+is one burst of eight pixels in the downsizing section, one image line
+in the main processing section, one image frame in the rotation section.
+
+The SMFC is composed of four independent FIFOs that each can transfer
+captured frames from sensors directly to memory concurrently via four
+IDMAC channels.
+
+The IRT carries out 90 and 270 degree image rotation operations. The
+rotation operation is carried out on 8x8 pixel blocks at a time. This
+operation is supported by the IDMAC which handles the 8x8 block transfer
+along with block reordering, in coordination with vertical flip.
+
+The VDIC handles the conversion of interlaced video to progressive, with
+support for different motion compensation modes (low, medium, and high
+motion). The deinterlaced output frames from the VDIC can be sent to the
+IC pre-process viewfinder task for further conversions. The VDIC also
+contains a Combiner that combines two image planes, with alpha blending
+and color keying.
+
+In addition to the IPU internal subunits, there are also two units
+outside the IPU that are also involved in video capture on i.MX:
+
+- MIPI CSI-2 Receiver for camera sensors with the MIPI CSI-2 bus
+  interface. This is a Synopsys DesignWare core.
+- Two video multiplexers for selecting among multiple sensor inputs
+  to send to a CSI.
+
+For more info, refer to

[PATCH v5 19/39] [media] add Omnivision OV5640 sensor driver

2017-03-09 Thread Steve Longerbeam
This driver is based on ov5640_mipi.c from Freescale imx_3.10.17_1.0.0_beta
branch, modified heavily to bring forward to latest interfaces and code
cleanup.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/Kconfig  |7 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov5640.c | 2231 
 3 files changed, 2239 insertions(+)
 create mode 100644 drivers/media/i2c/ov5640.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index cee1dae..bf67661 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -531,6 +531,13 @@ config VIDEO_OV2659
  To compile this driver as a module, choose M here: the
  module will be called ov2659.
 
+config VIDEO_OV5640
+   tristate "OmniVision OV5640 sensor support"
+   depends on GPIOLIB && VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
+   ---help---
+ This is a V4L2 sensor-level driver for the Omnivision
+ OV5640 camera sensor with a MIPI CSI-2 interface.
+
 config VIDEO_OV7640
tristate "OmniVision OV7640 sensor support"
depends on I2C && VIDEO_V4L2
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 5bc7bbe..3a9d73a 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -57,6 +57,7 @@ obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o
 obj-$(CONFIG_VIDEO_SONY_BTF_MPX) += sony-btf-mpx.o
 obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o
 obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
+obj-$(CONFIG_VIDEO_OV5640) += ov5640.o
 obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
 obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
 obj-$(CONFIG_VIDEO_OV9650) += ov9650.o
diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
new file mode 100644
index 000..2d78ec8
--- /dev/null
+++ b/drivers/media/i2c/ov5640.c
@@ -0,0 +1,2231 @@
+/*
+ * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright (C) 2014-2017 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* min/typical/max system clock (xclk) frequencies */
+#define OV5640_XCLK_MIN  600
+#define OV5640_XCLK_MAX 2400
+
+/*
+ * FIXME: there is no subdev API to set the MIPI CSI-2
+ * virtual channel yet, so this is hardcoded for now.
+ */
+#define OV5640_MIPI_VC 1
+
+#define OV5640_DEFAULT_SLAVE_ID 0x3c
+
+#define OV5640_REG_CHIP_ID 0x300a
+#define OV5640_REG_PAD_OUTPUT000x3019
+#define OV5640_REG_SC_PLL_CTRL00x3034
+#define OV5640_REG_SC_PLL_CTRL10x3035
+#define OV5640_REG_SC_PLL_CTRL20x3036
+#define OV5640_REG_SC_PLL_CTRL30x3037
+#define OV5640_REG_SLAVE_ID0x3100
+#define OV5640_REG_SYS_ROOT_DIVIDER0x3108
+#define OV5640_REG_AWB_R_GAIN  0x3400
+#define OV5640_REG_AWB_G_GAIN  0x3402
+#define OV5640_REG_AWB_B_GAIN  0x3404
+#define OV5640_REG_AWB_MANUAL_CTRL 0x3406
+#define OV5640_REG_AEC_PK_EXPOSURE_HI  0x3500
+#define OV5640_REG_AEC_PK_EXPOSURE_MED 0x3501
+#define OV5640_REG_AEC_PK_EXPOSURE_LO  0x3502
+#define OV5640_REG_AEC_PK_MANUAL   0x3503
+#define OV5640_REG_AEC_PK_REAL_GAIN0x350a
+#define OV5640_REG_AEC_PK_VTS  0x350c
+#define OV5640_REG_TIMING_HTS  0x380c
+#define OV5640_REG_TIMING_VTS  0x380e
+#define OV5640_REG_TIMING_TC_REG21 0x3821
+#define OV5640_REG_AEC_CTRL00  0x3a00
+#define OV5640_REG_AEC_B50_STEP0x3a08
+#define OV5640_REG_AEC_B60_STEP0x3a0a
+#define OV5640_REG_AEC_CTRL0D  0x3a0d
+#define OV5640_REG_AEC_CTRL0E  0x3a0e
+#define OV5640_REG_AEC_CTRL0F  0x3a0f
+#define OV5640_REG_AEC_CTRL10  0x3a10
+#define OV5640_REG_AEC_CTRL11  0x3a11
+#define OV5640_REG_AEC_CTRL1B  0x3a1b
+#define OV5640_REG_AEC_CTRL1E  0x3a1e
+#define OV5640_REG_AEC_CTRL1F  0x3a1f
+#define OV5640_REG_HZ5060_CTRL00   0x3c00
+#define OV5640_REG_HZ5060_CTRL01   0x3c01
+#define OV5640_REG_SIGMADELTA_CTRL0C   0x3c0c
+#define OV5640_REG_FRAME_CTRL010x4202
+#define OV5640_REG_MIPI_CTRL00 0x4800
+#define OV5640_REG_DEBUG_MODE  0x4814
+#define OV5640_REG_PRE_ISP_TEST_SET1   0x503d
+#define OV5640_REG_SDE_CTRL0   0x5580
+#define OV5640_REG_SDE_CTRL1   0x5581
+#define OV5640_REG_SDE_CTRL3   0x5583
+#define OV5640_REG_SDE_CTRL4   0x5584
+#define OV5640_REG_SDE_CTRL5   0x5585
+#define OV5640_REG_AVG_READOUT 0x56a1
+
+enum ov5640_mode_id {
+   OV5640_MODE_Q

Re: [block] BUG: KASAN: use-after-free in rb_erase+0x1431/0x1970

2017-03-09 Thread Mike Galbraith
On Thu, 2017-03-09 at 08:38 -0700, Jens Axboe wrote:
> On 03/09/2017 08:16 AM, Mike Galbraith wrote:
> > Greetings,
> > 
> > Building master.today with kasan enabled (because I saw the same when
> > trying out kasan on rt), the below fell out.
> > 
> > Config is enterprise based (tune for maximum build time), plus PREEMPT.
> > 
> > [5.335444] 
> > ==
> > [5.337030] BUG: KASAN: use-after-free in rb_erase+0x1431/0x1970 at addr 
> > 88035e78abb0
> > [5.338642] Write of size 8 by task swapper/7/0
> > [5.340204] CPU: 7 PID: 0 Comm: swapper/7 Tainted: GE   
> > 4.11.0-kasan #160
> > [5.341774] Hardware name: MEDION MS-7848/MS-7848, BIOS M7848W08.20C 
> > 09/23/2013
> 
> Should be fixed in my for-linus branch, it'll go out soon. If you want
> to verify, pull:
> 
> git://git.kernel.dk/linux-block for-linus
> 
> into master and see if that works for you.

Yup, all better.

-Mike


[PATCH v5 25/39] media: imx: Add CSI subdev driver

2017-03-09 Thread Steve Longerbeam
This is a media entity subdevice for the i.MX Camera
Sensor Interface module.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/Kconfig |   14 +
 drivers/staging/media/imx/Makefile|2 +
 drivers/staging/media/imx/imx-media-csi.c | 1311 +
 3 files changed, 1327 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx-media-csi.c

diff --git a/drivers/staging/media/imx/Kconfig 
b/drivers/staging/media/imx/Kconfig
index 62a3c34..e27ad6d 100644
--- a/drivers/staging/media/imx/Kconfig
+++ b/drivers/staging/media/imx/Kconfig
@@ -4,3 +4,17 @@ config VIDEO_IMX_MEDIA
---help---
  Say yes here to enable support for video4linux media controller
  driver for the i.MX5/6 SOC.
+
+if VIDEO_IMX_MEDIA
+menu "i.MX5/6 Media Sub devices"
+
+config VIDEO_IMX_CSI
+   tristate "i.MX5/6 Camera Sensor Interface driver"
+   depends on VIDEO_IMX_MEDIA && VIDEO_DEV && I2C
+   select VIDEOBUF2_DMA_CONTIG
+   default y
+   ---help---
+ A video4linux camera sensor interface driver for i.MX5/6.
+
+endmenu
+endif
diff --git a/drivers/staging/media/imx/Makefile 
b/drivers/staging/media/imx/Makefile
index 4606a3a..c054490 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -4,3 +4,5 @@ imx-media-common-objs := imx-media-utils.o imx-media-fim.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-capture.o
+
+obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
new file mode 100644
index 000..ab78ff7
--- /dev/null
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -0,0 +1,1311 @@
+/*
+ * V4L2 Capture CSI Subdev for Freescale i.MX5/6 SOC
+ *
+ * Copyright (c) 2014-2016 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "imx-media.h"
+
+/*
+ * Min/Max supported width and heights.
+ *
+ * We allow planar output, so we have to align width by 16 pixels
+ * to meet IDMAC alignment requirements.
+ *
+ * TODO: move this into pad format negotiation, if capture device
+ * has not requested planar formats, we should allow 8 pixel
+ * alignment.
+ */
+#define MIN_W   176
+#define MIN_H   144
+#define MAX_W  4096
+#define MAX_H  4096
+#define W_ALIGN4 /* multiple of 16 pixels */
+#define H_ALIGN1 /* multiple of 2 lines */
+#define S_ALIGN1 /* multiple of 2 */
+
+struct csi_priv {
+   struct device *dev;
+   struct ipu_soc *ipu;
+   struct imx_media_dev *md;
+   struct v4l2_subdev sd;
+   struct media_pad pad[CSI_NUM_PADS];
+   /* the video device at IDMAC output pad */
+   struct imx_media_video_dev *vdev;
+   struct imx_media_fim *fim;
+   int csi_id;
+   int smfc_id;
+
+   /* lock to protect all members below */
+   struct mutex lock;
+
+   int active_output_pad;
+
+   struct ipuv3_channel *idmac_ch;
+   struct ipu_smfc *smfc;
+   struct ipu_csi *csi;
+
+   struct v4l2_mbus_framefmt format_mbus[CSI_NUM_PADS];
+   const struct imx_media_pixfmt *cc[CSI_NUM_PADS];
+   struct v4l2_rect crop;
+
+   /* active vb2 buffers to send to video dev sink */
+   struct imx_media_buffer *active_vb2_buf[2];
+   struct imx_media_dma_buf underrun_buf;
+
+   int ipu_buf_num;  /* ipu double buffer index: 0-1 */
+
+   /* the sink for the captured frames */
+   struct media_entity *sink;
+   enum ipu_csi_dest dest;
+   /* the source subdev */
+   struct v4l2_subdev *src_sd;
+
+   /* the mipi virtual channel number at link validate */
+   int vc_num;
+
+   /* the attached sensor at stream on */
+   struct imx_media_subdev *sensor;
+
+   spinlock_t irqlock; /* protect eof_irq handler */
+   struct timer_list eof_timeout_timer;
+   int eof_irq;
+   int nfb4eof_irq;
+
+   struct v4l2_ctrl_handler ctrl_hdlr;
+
+   int power_count; /* power counter */
+   bool stream_on;  /* streaming is on */
+   bool last_eof;   /* waiting for last EOF at stream off */
+   struct completion last_eof_comp;
+};
+
+static inline struct csi_priv *sd_to_dev(struct v4l2_subdev *sdev)
+{
+   return container_of(sdev, struct csi_priv, sd);
+}
+
+static void csi_idmac_put_ipu_resources(struct csi_priv *priv)
+{
+   if (!IS_ERR_OR_NULL(priv->idmac_ch))
+   ipu_idmac_put(priv->idmac_ch);
+   priv->idmac_ch = NULL;
+
+   if (!IS_ERR_OR_NULL(priv->smfc))
+   ipu_smfc_p

[PATCH v5 22/39] media: Add userspace header file for i.MX

2017-03-09 Thread Steve Longerbeam
This adds a header file for use by userspace programs wanting to interact
with the i.MX media driver. It defines custom v4l2 controls for the
i.MX v4l2 subdevices.

Signed-off-by: Steve Longerbeam 
---
 include/uapi/media/Kbuild |  1 +
 include/uapi/media/imx.h  | 21 +
 2 files changed, 22 insertions(+)
 create mode 100644 include/uapi/media/imx.h

diff --git a/include/uapi/media/Kbuild b/include/uapi/media/Kbuild
index aafaa5a..fa78958 100644
--- a/include/uapi/media/Kbuild
+++ b/include/uapi/media/Kbuild
@@ -1 +1,2 @@
 # UAPI Header export list
+header-y += imx.h
diff --git a/include/uapi/media/imx.h b/include/uapi/media/imx.h
new file mode 100644
index 000..f573de4
--- /dev/null
+++ b/include/uapi/media/imx.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2014-2015 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version
+ */
+
+#ifndef __UAPI_MEDIA_IMX_H__
+#define __UAPI_MEDIA_IMX_H__
+
+enum imx_ctrl_id {
+   V4L2_CID_IMX_FIM_ENABLE = (V4L2_CID_USER_IMX_BASE + 0),
+   V4L2_CID_IMX_FIM_NUM,
+   V4L2_CID_IMX_FIM_TOLERANCE_MIN,
+   V4L2_CID_IMX_FIM_TOLERANCE_MAX,
+   V4L2_CID_IMX_FIM_NUM_SKIP,
+};
+
+#endif
-- 
2.7.4



[PATCH v5 29/39] ARM: imx_v6_v7_defconfig: Enable staging video4linux drivers

2017-03-09 Thread Steve Longerbeam
Enable i.MX v4l2 media staging driver. For video capture on i.MX, the
video multiplexer subdev is required. On the SabreAuto, the ADV7180
video decoder is required along with i2c-mux-gpio. The Sabrelite
and SabreSD require the OV5640 and the SabreLite requires PWM clocks
for the OV5640.

Increase max zoneorder to allow larger video buffer allocations.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/configs/imx_v6_v7_defconfig | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/configs/imx_v6_v7_defconfig 
b/arch/arm/configs/imx_v6_v7_defconfig
index eaba3b1..5d8c94a 100644
--- a/arch/arm/configs/imx_v6_v7_defconfig
+++ b/arch/arm/configs/imx_v6_v7_defconfig
@@ -51,6 +51,7 @@ CONFIG_PREEMPT_VOLUNTARY=y
 CONFIG_AEABI=y
 CONFIG_HIGHMEM=y
 CONFIG_CMA=y
+CONFIG_FORCE_MAX_ZONEORDER=14
 CONFIG_CMDLINE="noinitrd console=ttymxc0,115200"
 CONFIG_KEXEC=y
 CONFIG_CPU_FREQ=y
@@ -181,6 +182,7 @@ CONFIG_SERIAL_FSL_LPUART=y
 CONFIG_SERIAL_FSL_LPUART_CONSOLE=y
 # CONFIG_I2C_COMPAT is not set
 CONFIG_I2C_CHARDEV=y
+CONFIG_I2C_MUX=y
 CONFIG_I2C_MUX_GPIO=y
 # CONFIG_I2C_HELPER_AUTO is not set
 CONFIG_I2C_ALGOPCF=m
@@ -221,14 +223,20 @@ CONFIG_REGULATOR_PFUZE100=y
 CONFIG_MEDIA_SUPPORT=y
 CONFIG_MEDIA_CAMERA_SUPPORT=y
 CONFIG_MEDIA_RC_SUPPORT=y
+CONFIG_MEDIA_CONTROLLER=y
+CONFIG_VIDEO_V4L2_SUBDEV_API=y
 CONFIG_RC_DEVICES=y
 CONFIG_IR_GPIO_CIR=y
 CONFIG_MEDIA_USB_SUPPORT=y
 CONFIG_USB_VIDEO_CLASS=m
 CONFIG_V4L_PLATFORM_DRIVERS=y
+CONFIG_VIDEO_MULTIPLEXER=y
 CONFIG_SOC_CAMERA=y
 CONFIG_V4L_MEM2MEM_DRIVERS=y
 CONFIG_VIDEO_CODA=y
+# CONFIG_MEDIA_SUBDRV_AUTOSELECT is not set
+CONFIG_VIDEO_ADV7180=m
+CONFIG_VIDEO_OV5640=m
 CONFIG_SOC_CAMERA_OV2640=y
 CONFIG_IMX_IPUV3_CORE=y
 CONFIG_DRM=y
@@ -338,6 +346,9 @@ CONFIG_FSL_EDMA=y
 CONFIG_IMX_SDMA=y
 CONFIG_MXS_DMA=y
 CONFIG_STAGING=y
+CONFIG_STAGING_MEDIA=y
+CONFIG_VIDEO_IMX_MEDIA=y
+CONFIG_COMMON_CLK_PWM=y
 CONFIG_IIO=y
 CONFIG_VF610_ADC=y
 CONFIG_MPL3115=y
-- 
2.7.4



[PATCH v5 21/39] UAPI: Add media UAPI Kbuild file

2017-03-09 Thread Steve Longerbeam
Add an empty UAPI Kbuild file for media UAPI headers.

Signed-off-by: Steve Longerbeam 
---
 include/uapi/Kbuild   | 1 +
 include/uapi/media/Kbuild | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 include/uapi/media/Kbuild

diff --git a/include/uapi/Kbuild b/include/uapi/Kbuild
index 245aa6e..9a51957 100644
--- a/include/uapi/Kbuild
+++ b/include/uapi/Kbuild
@@ -6,6 +6,7 @@
 header-y += asm-generic/
 header-y += linux/
 header-y += sound/
+header-y += media/
 header-y += mtd/
 header-y += rdma/
 header-y += video/
diff --git a/include/uapi/media/Kbuild b/include/uapi/media/Kbuild
new file mode 100644
index 000..aafaa5a
--- /dev/null
+++ b/include/uapi/media/Kbuild
@@ -0,0 +1 @@
+# UAPI Header export list
-- 
2.7.4



[PATCH v5 31/39] media: imx: csi: add support for bayer formats

2017-03-09 Thread Steve Longerbeam
From: Russell King 

Bayer formats must be treated as generic data and passthrough mode must
be used.  Add the correct setup for these formats.

Signed-off-by: Russell King 

- added check to csi_link_validate() to verify that destination is
  IDMAC output pad when passthrough conditions exist: bayer formats
  and 16-bit parallel buses.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/imx-media-csi.c | 52 +--
 1 file changed, 43 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
index ab78ff7..a7d04e4 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -276,10 +276,11 @@ static int csi_idmac_setup_channel(struct csi_priv *priv)
struct imx_media_video_dev *vdev = priv->vdev;
struct v4l2_of_endpoint *sensor_ep;
struct v4l2_mbus_framefmt *infmt;
-   unsigned int burst_size;
struct ipu_image image;
+   u32 passthrough_bits;
dma_addr_t phys[2];
bool passthrough;
+   u32 burst_size;
int ret;
 
infmt = &priv->format_mbus[CSI_SINK_PAD];
@@ -306,15 +307,38 @@ static int csi_idmac_setup_channel(struct csi_priv *priv)
ipu_cpmem_set_burstsize(priv->idmac_ch, burst_size);
 
/*
-* If the sensor uses 16-bit parallel CSI bus, we must handle
-* the data internally in the IPU as 16-bit generic, aka
-* passthrough mode.
+* Check for conditions that require the IPU to handle the
+* data internally as generic data, aka passthrough mode:
+* - raw bayer formats
+* - the sensor bus is 16-bit parallel
 */
-   passthrough = (sensor_ep->bus_type != V4L2_MBUS_CSI2 &&
-  sensor_ep->bus.parallel.bus_width >= 16);
+   switch (image.pix.pixelformat) {
+   case V4L2_PIX_FMT_SBGGR8:
+   case V4L2_PIX_FMT_SGBRG8:
+   case V4L2_PIX_FMT_SGRBG8:
+   case V4L2_PIX_FMT_SRGGB8:
+   burst_size = 8;
+   passthrough = true;
+   passthrough_bits = 8;
+   break;
+   case V4L2_PIX_FMT_SBGGR16:
+   case V4L2_PIX_FMT_SGBRG16:
+   case V4L2_PIX_FMT_SGRBG16:
+   case V4L2_PIX_FMT_SRGGB16:
+   burst_size = 4;
+   passthrough = true;
+   passthrough_bits = 16;
+   break;
+   default:
+   passthrough = (sensor_ep->bus_type != V4L2_MBUS_CSI2 &&
+  sensor_ep->bus.parallel.bus_width >= 16);
+   passthrough_bits = 16;
+   break;
+   }
 
if (passthrough)
-   ipu_cpmem_set_format_passthrough(priv->idmac_ch, 16);
+   ipu_cpmem_set_format_passthrough(priv->idmac_ch,
+passthrough_bits);
 
/*
 * Set the channel for the direct CSI-->memory via SMFC
@@ -725,6 +749,7 @@ static int csi_link_validate(struct v4l2_subdev *sd,
 struct v4l2_subdev_format *sink_fmt)
 {
struct csi_priv *priv = v4l2_get_subdevdata(sd);
+   const struct imx_media_pixfmt *incc;
struct v4l2_of_endpoint *sensor_ep;
struct imx_media_subdev *sensor;
bool is_csi2;
@@ -749,8 +774,17 @@ static int csi_link_validate(struct v4l2_subdev *sd,
 
priv->sensor = sensor;
sensor_ep = &priv->sensor->sensor_ep;
-
is_csi2 = (sensor_ep->bus_type == V4L2_MBUS_CSI2);
+   incc = priv->cc[CSI_SINK_PAD];
+
+   if (priv->dest != IPU_CSI_DEST_IDMAC &&
+   (incc->bayer || (!is_csi2 &&
+sensor_ep->bus.parallel.bus_width >= 16))) {
+   v4l2_err(&priv->sd,
+"bayer/16-bit parallel buses must go to IDMAC pad\n");
+   ret = -EINVAL;
+   goto out;
+   }
 
if (is_csi2) {
int vc_num = 0;
@@ -775,7 +809,7 @@ static int csi_link_validate(struct v4l2_subdev *sd,
 
/* select either parallel or MIPI-CSI2 as input to CSI */
ipu_set_csi_src_mux(priv->ipu, priv->csi_id, is_csi2);
-
+out:
mutex_unlock(&priv->lock);
return ret;
 }
-- 
2.7.4



[PATCH v5 26/39] media: imx: Add VDIC subdev driver

2017-03-09 Thread Steve Longerbeam
This is a media entity subdevice driver for the i.MX Video De-Interlacing
or Combining Block. So far this entity does not implement the Combining
function but only motion compensated deinterlacing. Video frames are
received from the CSI and are routed to the IC PRPVF entity.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/Makefile |   1 +
 drivers/staging/media/imx/imx-media-vdic.c | 952 +
 2 files changed, 953 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx-media-vdic.c

diff --git a/drivers/staging/media/imx/Makefile 
b/drivers/staging/media/imx/Makefile
index c054490..1f01520 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -4,5 +4,6 @@ imx-media-common-objs := imx-media-utils.o imx-media-fim.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-capture.o
+obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-vdic.o
 
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
diff --git a/drivers/staging/media/imx/imx-media-vdic.c 
b/drivers/staging/media/imx/imx-media-vdic.c
new file mode 100644
index 000..0e7c24c
--- /dev/null
+++ b/drivers/staging/media/imx/imx-media-vdic.c
@@ -0,0 +1,952 @@
+/*
+ * V4L2 Deinterlacer Subdev for Freescale i.MX5/6 SOC
+ *
+ * Copyright (c) 2017 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "imx-media.h"
+
+/*
+ * This subdev implements two different video pipelines:
+ *
+ * CSI -> VDIC
+ *
+ * In this pipeline, the CSI sends a single interlaced field F(n-1)
+ * directly to the VDIC (and optionally the following field F(n)
+ * can be sent to memory via IDMAC channel 13). This pipeline only works
+ * in VDIC's high motion mode, which only requires a single field for
+ * processing. The other motion modes (low and medium) require three
+ * fields, so this pipeline does not work in those modes. Also, it is
+ * not clear how this pipeline can deal with the various field orders
+ * (sequential BT/TB, interlaced BT/TB).
+ *
+ * MEM -> CH8,9,10 -> VDIC
+ *
+ * In this pipeline, previous field F(n-1), current field F(n), and next
+ * field F(n+1) are transferred to the VDIC via IDMAC channels 8,9,10.
+ * These memory buffers can come from a video output or mem2mem device.
+ * All motion modes are supported by this pipeline.
+ *
+ * The "direct" CSI->VDIC pipeline requires no DMA, but it can only be
+ * used in high motion mode.
+ */
+
+struct vdic_priv;
+
+struct vdic_pipeline_ops {
+   int (*setup)(struct vdic_priv *priv);
+   void (*start)(struct vdic_priv *priv);
+   void (*stop)(struct vdic_priv *priv);
+   void (*disable)(struct vdic_priv *priv);
+};
+
+/*
+ * Min/Max supported width and heights.
+ */
+#define MIN_W   176
+#define MIN_H   144
+#define MAX_W_VDIC  968
+#define MAX_H_VDIC 2048
+#define W_ALIGN4 /* multiple of 16 pixels */
+#define H_ALIGN1 /* multiple of 2 lines */
+#define S_ALIGN1 /* multiple of 2 */
+
+struct vdic_priv {
+   struct device*dev;
+   struct ipu_soc   *ipu;
+   struct imx_media_dev *md;
+   struct v4l2_subdev   sd;
+   struct media_pad pad[VDIC_NUM_PADS];
+   int ipu_id;
+
+   /* lock to protect all members below */
+   struct mutex lock;
+
+   /* IPU units we require */
+   struct ipu_vdi *vdi;
+
+   int active_input_pad;
+
+   struct ipuv3_channel *vdi_in_ch_p; /* F(n-1) transfer channel */
+   struct ipuv3_channel *vdi_in_ch;   /* F(n) transfer channel */
+   struct ipuv3_channel *vdi_in_ch_n; /* F(n+1) transfer channel */
+
+   /* pipeline operations */
+   struct vdic_pipeline_ops *ops;
+
+   /* current and previous input buffers indirect path */
+   struct imx_media_buffer *curr_in_buf;
+   struct imx_media_buffer *prev_in_buf;
+
+   /*
+* translated field type, input line stride, and field size
+* for indirect path
+*/
+   u32 fieldtype;
+   u32 in_stride;
+   u32 field_size;
+
+   /* the source (a video device or subdev) */
+   struct media_entity *src;
+   /* the sink that will receive the progressive out buffers */
+   struct v4l2_subdev *sink_sd;
+
+   struct v4l2_mbus_framefmt format_mbus[VDIC_NUM_PADS];
+   const struct imx_media_pixfmt *cc[VDIC_NUM_PADS];
+   struct v4l2_fract frame_interval;
+
+   /* the video device at IDMAC input pad */
+   struct imx_media_video_dev *vdev;
+
+   bool csi_direct;  /* using direct CSI->VDIC->IC pipeline */
+
+   /* motion 

[PATCH v5 32/39] media: imx: csi: fix crop rectangle changes in set_fmt

2017-03-09 Thread Steve Longerbeam
From: Philipp Zabel 

The cropping rectangle was being modified by the output pad's
set_fmt, which is the wrong pad to do this. The crop rectangle
should not be modified by the output pad set_fmt. It instead
should be reset to the full input frame when the input pad format
is set.

The output pad set_fmt should set width/height to the current
crop dimensions, or 1/2 the crop width/height to enable
downscaling.

So the other part of this patch is to enable downscaling if
the output pad dimension(s) are 1/2 the crop dimension(s) at
csi_setup() time.

Signed-off-by: Philipp Zabel 
Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/imx-media-csi.c | 35 ---
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
index a7d04e4..577038e 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -536,6 +536,10 @@ static int csi_setup(struct csi_priv *priv)
 
ipu_csi_set_window(priv->csi, &priv->crop);
 
+   ipu_csi_set_downsize(priv->csi,
+priv->crop.width == 2 * outfmt->width,
+priv->crop.height == 2 * outfmt->height);
+
ipu_csi_init_interface(priv->csi, &sensor_mbus_cfg, &if_fmt);
 
ipu_csi_set_dest(priv->csi, priv->dest);
@@ -932,15 +936,15 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
switch (sdformat->pad) {
case CSI_SRC_PAD_DIRECT:
case CSI_SRC_PAD_IDMAC:
-   crop.left = priv->crop.left;
-   crop.top = priv->crop.top;
-   crop.width = sdformat->format.width;
-   crop.height = sdformat->format.height;
-   ret = csi_try_crop(priv, &crop, sensor);
-   if (ret)
-   goto out;
-   sdformat->format.width = crop.width;
-   sdformat->format.height = crop.height;
+   if (sdformat->format.width < priv->crop.width * 3 / 4)
+   sdformat->format.width = priv->crop.width / 2;
+   else
+   sdformat->format.width = priv->crop.width;
+
+   if (sdformat->format.height < priv->crop.height * 3 / 4)
+   sdformat->format.height = priv->crop.height / 2;
+   else
+   sdformat->format.height = priv->crop.height;
 
if (sdformat->pad == CSI_SRC_PAD_IDMAC) {
cc = imx_media_find_format(0, sdformat->format.code,
@@ -986,6 +990,14 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
}
break;
case CSI_SINK_PAD:
+   crop.left = 0;
+   crop.top = 0;
+   crop.width = sdformat->format.width;
+   crop.height = sdformat->format.height;
+   ret = csi_try_crop(priv, &crop, sensor);
+   if (ret)
+   goto out;
+
cc = imx_media_find_format(0, sdformat->format.code,
   true, false);
if (!cc) {
@@ -1004,9 +1016,8 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
} else {
priv->format_mbus[sdformat->pad] = sdformat->format;
priv->cc[sdformat->pad] = cc;
-   /* Update the crop window if this is an output pad  */
-   if (sdformat->pad == CSI_SRC_PAD_DIRECT ||
-   sdformat->pad == CSI_SRC_PAD_IDMAC)
+   /* Reset the crop window if this is the input pad */
+   if (sdformat->pad == CSI_SINK_PAD)
priv->crop = crop;
}
 
-- 
2.7.4



[PATCH v5 30/39] media: imx: add support for bayer formats

2017-03-09 Thread Steve Longerbeam
From: Russell King 

Add the bayer formats to imx-media's list of supported pixel and bus
formats.

Signed-off-by: Russell King 

- added a bayer boolean to struct imx_media_pixfmt.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/imx-media-utils.c | 68 +
 drivers/staging/media/imx/imx-media.h   |  1 +
 2 files changed, 69 insertions(+)

diff --git a/drivers/staging/media/imx/imx-media-utils.c 
b/drivers/staging/media/imx/imx-media-utils.c
index ee50b6a..24e3795 100644
--- a/drivers/staging/media/imx/imx-media-utils.c
+++ b/drivers/staging/media/imx/imx-media-utils.c
@@ -61,6 +61,74 @@ static const struct imx_media_pixfmt imx_media_formats[] = {
.cs = IPUV3_COLORSPACE_RGB,
.bpp= 32,
.ipufmt = true,
+   }, {
+   .fourcc = V4L2_PIX_FMT_SBGGR8,
+   .codes  = {MEDIA_BUS_FMT_SBGGR8_1X8},
+   .cs = IPUV3_COLORSPACE_RGB,
+   .bpp= 8,
+   .bayer  = true,
+   }, {
+   .fourcc = V4L2_PIX_FMT_SGBRG8,
+   .codes  = {MEDIA_BUS_FMT_SGBRG8_1X8},
+   .cs = IPUV3_COLORSPACE_RGB,
+   .bpp= 8,
+   .bayer  = true,
+   }, {
+   .fourcc = V4L2_PIX_FMT_SGRBG8,
+   .codes  = {MEDIA_BUS_FMT_SGRBG8_1X8},
+   .cs = IPUV3_COLORSPACE_RGB,
+   .bpp= 8,
+   .bayer  = true,
+   }, {
+   .fourcc = V4L2_PIX_FMT_SRGGB8,
+   .codes  = {MEDIA_BUS_FMT_SRGGB8_1X8},
+   .cs = IPUV3_COLORSPACE_RGB,
+   .bpp= 8,
+   .bayer  = true,
+   }, {
+   .fourcc = V4L2_PIX_FMT_SBGGR16,
+   .codes  = {
+   MEDIA_BUS_FMT_SBGGR10_1X10,
+   MEDIA_BUS_FMT_SBGGR12_1X12,
+   MEDIA_BUS_FMT_SBGGR14_1X14,
+   MEDIA_BUS_FMT_SBGGR16_1X16
+   },
+   .cs = IPUV3_COLORSPACE_RGB,
+   .bpp= 16,
+   .bayer  = true,
+   }, {
+   .fourcc = V4L2_PIX_FMT_SGBRG16,
+   .codes  = {
+   MEDIA_BUS_FMT_SGBRG10_1X10,
+   MEDIA_BUS_FMT_SGBRG12_1X12,
+   MEDIA_BUS_FMT_SGBRG14_1X14,
+   MEDIA_BUS_FMT_SGBRG16_1X16,
+   },
+   .cs = IPUV3_COLORSPACE_RGB,
+   .bpp= 16,
+   .bayer  = true,
+   }, {
+   .fourcc = V4L2_PIX_FMT_SGRBG16,
+   .codes  = {
+   MEDIA_BUS_FMT_SGRBG10_1X10,
+   MEDIA_BUS_FMT_SGRBG12_1X12,
+   MEDIA_BUS_FMT_SGRBG14_1X14,
+   MEDIA_BUS_FMT_SGRBG16_1X16,
+   },
+   .cs = IPUV3_COLORSPACE_RGB,
+   .bpp= 16,
+   .bayer  = true,
+   }, {
+   .fourcc = V4L2_PIX_FMT_SRGGB16,
+   .codes  = {
+   MEDIA_BUS_FMT_SRGGB10_1X10,
+   MEDIA_BUS_FMT_SRGGB12_1X12,
+   MEDIA_BUS_FMT_SRGGB14_1X14,
+   MEDIA_BUS_FMT_SRGGB16_1X16,
+   },
+   .cs = IPUV3_COLORSPACE_RGB,
+   .bpp= 16,
+   .bayer  = true,
},
/*** non-mbus formats start here ***/
{
diff --git a/drivers/staging/media/imx/imx-media.h 
b/drivers/staging/media/imx/imx-media.h
index 2dd48ea..9e865fa 100644
--- a/drivers/staging/media/imx/imx-media.h
+++ b/drivers/staging/media/imx/imx-media.h
@@ -91,6 +91,7 @@ struct imx_media_pixfmt {
int bpp; /* total bpp */
enum ipu_color_space cs;
boolplanar;  /* is a planar format */
+   boolbayer;   /* is a raw bayer format */
boolipufmt;  /* is one of the IPU internal formats */
 };
 
-- 
2.7.4



[PATCH v5 27/39] media: imx: Add IC subdev drivers

2017-03-09 Thread Steve Longerbeam
This is a set of three media entity subdevice drivers for the i.MX
Image Converter:

- Pre-process Router: Takes input frames from CSI0, CSI1, or VDIC.
  Two output pads enable either or both of the preprocess tasks
  below. If the input is from one of the CSIs, both proprocess task
  links can be enabled to process frames from that CSI simultaneously.
  If the input is the VDIC, only the Pre-processing Viewfinder task
  link can be enabled.

- Pre-processing Encode task: video frames are routed directly from
  the CSI and can be scaled, color-space converted, and rotated.
  Scaled output is limited to 1024x1024 resolution. Output frames
  are routed to the capture device.

- Pre-processing Viewfinder task: this task can perform the same
  conversions as the pre-process encode task, but in addition can
  be used for hardware motion compensated deinterlacing. Frames can
  come either directly from the CSI or from the VDIC. Scaled output
  is limited to 1024x1024 resolution. Output frames are routed to
  the capture device.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/Makefile  |2 +
 drivers/staging/media/imx/imx-ic-common.c   |  113 +++
 drivers/staging/media/imx/imx-ic-prp.c  |  475 +++
 drivers/staging/media/imx/imx-ic-prpencvf.c | 1219 +++
 drivers/staging/media/imx/imx-ic.h  |   38 +
 5 files changed, 1847 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx-ic-common.c
 create mode 100644 drivers/staging/media/imx/imx-ic-prp.c
 create mode 100644 drivers/staging/media/imx/imx-ic-prpencvf.c
 create mode 100644 drivers/staging/media/imx/imx-ic.h

diff --git a/drivers/staging/media/imx/Makefile 
b/drivers/staging/media/imx/Makefile
index 1f01520..878a126 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -1,9 +1,11 @@
 imx-media-objs := imx-media-dev.o imx-media-internal-sd.o imx-media-of.o
 imx-media-common-objs := imx-media-utils.o imx-media-fim.o
+imx-media-ic-objs := imx-ic-common.o imx-ic-prp.o imx-ic-prpencvf.o
 
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-capture.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-vdic.o
+obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-ic.o
 
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
diff --git a/drivers/staging/media/imx/imx-ic-common.c 
b/drivers/staging/media/imx/imx-ic-common.c
new file mode 100644
index 000..cfdd490
--- /dev/null
+++ b/drivers/staging/media/imx/imx-ic-common.c
@@ -0,0 +1,113 @@
+/*
+ * V4L2 Image Converter Subdev for Freescale i.MX5/6 SOC
+ *
+ * Copyright (c) 2014-2016 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include 
+#include 
+#include 
+#include 
+#include "imx-media.h"
+#include "imx-ic.h"
+
+#define IC_TASK_PRP IC_NUM_TASKS
+#define IC_NUM_OPS  (IC_NUM_TASKS + 1)
+
+static struct imx_ic_ops *ic_ops[IC_NUM_OPS] = {
+   [IC_TASK_PRP]= &imx_ic_prp_ops,
+   [IC_TASK_ENCODER]= &imx_ic_prpencvf_ops,
+   [IC_TASK_VIEWFINDER] = &imx_ic_prpencvf_ops,
+};
+
+static int imx_ic_probe(struct platform_device *pdev)
+{
+   struct imx_media_internal_sd_platformdata *pdata;
+   struct imx_ic_priv *priv;
+   int ret;
+
+   priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+   if (!priv)
+   return -ENOMEM;
+
+   platform_set_drvdata(pdev, &priv->sd);
+   priv->dev = &pdev->dev;
+
+   /* get our ipu_id, grp_id and IC task id */
+   pdata = priv->dev->platform_data;
+   priv->ipu_id = pdata->ipu_id;
+   switch (pdata->grp_id) {
+   case IMX_MEDIA_GRP_ID_IC_PRP:
+   priv->task_id = IC_TASK_PRP;
+   break;
+   case IMX_MEDIA_GRP_ID_IC_PRPENC:
+   priv->task_id = IC_TASK_ENCODER;
+   break;
+   case IMX_MEDIA_GRP_ID_IC_PRPVF:
+   priv->task_id = IC_TASK_VIEWFINDER;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   v4l2_subdev_init(&priv->sd, ic_ops[priv->task_id]->subdev_ops);
+   v4l2_set_subdevdata(&priv->sd, priv);
+   priv->sd.internal_ops = ic_ops[priv->task_id]->internal_ops;
+   priv->sd.entity.ops = ic_ops[priv->task_id]->entity_ops;
+   priv->sd.entity.function = MEDIA_ENT_F_PROC_VIDEO_SCALER;
+   priv->sd.dev = &pdev->dev;
+   priv->sd.owner = THIS_MODULE;
+   priv->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
+   priv->sd.grp_id = pdata->grp_id;
+   strncpy(priv->sd.name, pdata->sd_name, sizeof(priv->sd.name));
+
+   ret = ic_ops[priv->task_id]->init(priv);
+   if (ret)
+   return ret;
+
+   

[PATCH v5 33/39] media: imx: mipi-csi2: enable setting and getting of frame rates

2017-03-09 Thread Steve Longerbeam
From: Russell King 

Setting and getting frame rates is part of the negotiation mechanism
between subdevs.  The lack of support means that a frame rate at the
sensor can't be negotiated through the subdev path.

Add support at MIPI CSI2 level for handling this part of the
negotiation.

Signed-off-by: Russell King 
Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/imx6-mipi-csi2.c | 36 ++
 1 file changed, 36 insertions(+)

diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c 
b/drivers/staging/media/imx/imx6-mipi-csi2.c
index 1a71b40..d8f931e 100644
--- a/drivers/staging/media/imx/imx6-mipi-csi2.c
+++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
@@ -49,6 +49,7 @@ struct csi2_dev {
struct mutex lock;
 
struct v4l2_mbus_framefmt format_mbus;
+   struct v4l2_fract frame_interval;
 
int power_count;
boolstream_on;
@@ -487,6 +488,35 @@ static int csi2_set_fmt(struct v4l2_subdev *sd,
return ret;
 }
 
+static int csi2_g_frame_interval(struct v4l2_subdev *sd,
+struct v4l2_subdev_frame_interval *fi)
+{
+   struct csi2_dev *csi2 = sd_to_dev(sd);
+
+   mutex_lock(&csi2->lock);
+   fi->interval = csi2->frame_interval;
+   mutex_unlock(&csi2->lock);
+
+   return 0;
+}
+
+static int csi2_s_frame_interval(struct v4l2_subdev *sd,
+struct v4l2_subdev_frame_interval *fi)
+{
+   struct csi2_dev *csi2 = sd_to_dev(sd);
+
+   mutex_lock(&csi2->lock);
+
+   /* Output pads mirror active input pad, no limits on input pads */
+   if (fi->pad != CSI2_SINK_PAD)
+   fi->interval = csi2->frame_interval;
+
+   csi2->frame_interval = fi->interval;
+
+   mutex_unlock(&csi2->lock);
+   return 0;
+}
+
 static int csi2_link_validate(struct v4l2_subdev *sd,
  struct media_link *link,
  struct v4l2_subdev_format *source_fmt,
@@ -535,6 +565,8 @@ static struct v4l2_subdev_core_ops csi2_core_ops = {
 
 static struct v4l2_subdev_video_ops csi2_video_ops = {
.s_stream = csi2_s_stream,
+   .g_frame_interval = csi2_g_frame_interval,
+   .s_frame_interval = csi2_s_frame_interval,
 };
 
 static struct v4l2_subdev_pad_ops csi2_pad_ops = {
@@ -603,6 +635,10 @@ static int csi2_probe(struct platform_device *pdev)
csi2->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
csi2->sd.grp_id = IMX_MEDIA_GRP_ID_CSI2;
 
+   /* init default frame interval */
+   csi2->frame_interval.numerator = 1;
+   csi2->frame_interval.denominator = 30;
+
ret = csi2_parse_endpoints(csi2);
if (ret)
return ret;
-- 
2.7.4



[PATCH v5 34/39] media: imx: csi: add __csi_get_fmt

2017-03-09 Thread Steve Longerbeam
Add __csi_get_fmt() and use it to return the correct mbus format
(active or try) in get_fmt. Use it in other places as well.

Signed-off-by: Steve Longerbeam 
Suggested-by: Russell King 
---
 drivers/staging/media/imx/imx-media-csi.c | 61 ---
 1 file changed, 47 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
index 577038e..6640869 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -830,13 +830,26 @@ static int csi_eof_isr(struct v4l2_subdev *sd, u32 
status, bool *handled)
return 0;
 }
 
-static int csi_try_crop(struct csi_priv *priv, struct v4l2_rect *crop,
+static struct v4l2_mbus_framefmt *
+__csi_get_fmt(struct csi_priv *priv, struct v4l2_subdev_pad_config *cfg,
+ unsigned int pad, enum v4l2_subdev_format_whence which)
+{
+   if (which == V4L2_SUBDEV_FORMAT_TRY)
+   return v4l2_subdev_get_try_format(&priv->sd, cfg, pad);
+   else
+   return &priv->format_mbus[pad];
+}
+
+static int csi_try_crop(struct csi_priv *priv,
+   struct v4l2_rect *crop,
+   struct v4l2_subdev_pad_config *cfg,
+   enum v4l2_subdev_format_whence which,
struct imx_media_subdev *sensor)
 {
struct v4l2_of_endpoint *sensor_ep;
struct v4l2_mbus_framefmt *infmt;
 
-   infmt = &priv->format_mbus[CSI_SINK_PAD];
+   infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, which);
sensor_ep = &sensor->sensor_ep;
 
crop->width = min_t(__u32, infmt->width, crop->width);
@@ -886,17 +899,24 @@ static int csi_get_fmt(struct v4l2_subdev *sd,
   struct v4l2_subdev_format *sdformat)
 {
struct csi_priv *priv = v4l2_get_subdevdata(sd);
+   struct v4l2_mbus_framefmt *fmt;
+   int ret = 0;
 
if (sdformat->pad >= CSI_NUM_PADS)
return -EINVAL;
 
mutex_lock(&priv->lock);
 
-   sdformat->format = priv->format_mbus[sdformat->pad];
+   fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+   if (!fmt) {
+   ret = -EINVAL;
+   goto out;
+   }
 
+   sdformat->format = *fmt;
+out:
mutex_unlock(&priv->lock);
-
-   return 0;
+   return ret;
 }
 
 static int csi_set_fmt(struct v4l2_subdev *sd,
@@ -927,8 +947,6 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
goto out;
}
 
-   infmt = &priv->format_mbus[CSI_SINK_PAD];
-
v4l_bound_align_image(&sdformat->format.width, MIN_W, MAX_W,
  W_ALIGN, &sdformat->format.height,
  MIN_H, MAX_H, H_ALIGN, S_ALIGN);
@@ -936,6 +954,8 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
switch (sdformat->pad) {
case CSI_SRC_PAD_DIRECT:
case CSI_SRC_PAD_IDMAC:
+   infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sdformat->which);
+
if (sdformat->format.width < priv->crop.width * 3 / 4)
sdformat->format.width = priv->crop.width / 2;
else
@@ -994,7 +1014,8 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
crop.top = 0;
crop.width = sdformat->format.width;
crop.height = sdformat->format.height;
-   ret = csi_try_crop(priv, &crop, sensor);
+   ret = csi_try_crop(priv, &crop, cfg,
+  sdformat->which, sensor);
if (ret)
goto out;
 
@@ -1039,7 +1060,11 @@ static int csi_get_selection(struct v4l2_subdev *sd,
 
mutex_lock(&priv->lock);
 
-   infmt = &priv->format_mbus[CSI_SINK_PAD];
+   infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sel->which);
+   if (!infmt) {
+   ret = -EINVAL;
+   goto out;
+   }
 
switch (sel->target) {
case V4L2_SEL_TGT_CROP_BOUNDS:
@@ -1049,12 +1074,20 @@ static int csi_get_selection(struct v4l2_subdev *sd,
sel->r.height = infmt->height;
break;
case V4L2_SEL_TGT_CROP:
-   sel->r = priv->crop;
+   if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
+   struct v4l2_rect *try_crop =
+   v4l2_subdev_get_try_crop(&priv->sd,
+cfg, sel->pad);
+   sel->r = *try_crop;
+   } else {
+   sel->r = priv->crop;
+   }
break;
default:
ret = -EINVAL;
}
 
+out:
mutex_unlock(&priv->lock);
return ret;
 }
@@ -1064,7 +1097,6 @@ static int csi_set_selection(struct v4l2_subdev *sd,
 struct v4l2_subdev_selection *sel)
 {
struct csi_priv *priv = v4l2_get_subdevdata(sd);
-   stru

[PATCH v5 39/39] media: imx: propagate sink pad formats to source pads

2017-03-09 Thread Steve Longerbeam
As part of this, separate format try code from *_set_fmt() into
*_try_fmt(), so that the latter function can be used to propagate
a legal format from sink to source. This also reduces subsequent
bloat in *_set_fmt().

imx-ic-prp never needed separate formats for sink and source pads,
so propagation in this case was easy, just have only a single
format shared by both pads.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/imx-ic-prp.c|  31 +++---
 drivers/staging/media/imx/imx-ic-prpencvf.c   |  86 ++-
 drivers/staging/media/imx/imx-media-capture.c |  12 ++
 drivers/staging/media/imx/imx-media-csi.c | 152 --
 drivers/staging/media/imx/imx-media-vdic.c|  72 +++-
 5 files changed, 224 insertions(+), 129 deletions(-)

diff --git a/drivers/staging/media/imx/imx-ic-prp.c 
b/drivers/staging/media/imx/imx-ic-prp.c
index 83cd2b4..ec742e6 100644
--- a/drivers/staging/media/imx/imx-ic-prp.c
+++ b/drivers/staging/media/imx/imx-ic-prp.c
@@ -56,8 +56,7 @@ struct prp_priv {
/* the CSI id at link validate */
int csi_id;
 
-   struct v4l2_mbus_framefmt format_mbus[PRP_NUM_PADS];
-   const struct imx_media_pixfmt *cc[PRP_NUM_PADS];
+   struct v4l2_mbus_framefmt format_mbus;
struct v4l2_fract frame_interval;
 
bool stream_on; /* streaming is on */
@@ -98,7 +97,7 @@ __prp_get_fmt(struct prp_priv *priv, struct 
v4l2_subdev_pad_config *cfg,
if (which == V4L2_SUBDEV_FORMAT_TRY)
return v4l2_subdev_get_try_format(&ic_priv->sd, cfg, pad);
else
-   return &priv->format_mbus[pad];
+   return &priv->format_mbus;
 }
 
 /*
@@ -167,7 +166,7 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
   struct v4l2_subdev_format *sdformat)
 {
struct prp_priv *priv = sd_to_priv(sd);
-   const struct imx_media_pixfmt *cc = NULL;
+   const struct imx_media_pixfmt *cc;
struct v4l2_mbus_framefmt *infmt;
int ret = 0;
u32 code;
@@ -201,17 +200,14 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
/* Output pads mirror input pad */
infmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD,
  sdformat->which);
-   cc = imx_media_find_ipu_format(infmt->code, CS_SEL_ANY);
sdformat->format = *infmt;
break;
}
 
-   if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
+   if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY)
cfg->try_fmt = sdformat->format;
-   } else {
-   priv->format_mbus[sdformat->pad] = sdformat->format;
-   priv->cc[sdformat->pad] = cc;
-   }
+   else
+   priv->format_mbus = sdformat->format;
 
 out:
mutex_unlock(&priv->lock);
@@ -427,20 +423,19 @@ static int prp_registered(struct v4l2_subdev *sd)
for (i = 0; i < PRP_NUM_PADS; i++) {
priv->pad[i].flags = (i == PRP_SINK_PAD) ?
MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
-
-   /* set a default mbus format  */
-   imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV);
-   ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
- 640, 480, code, V4L2_FIELD_NONE,
- &priv->cc[i]);
-   if (ret)
-   return ret;
}
 
/* init default frame interval */
priv->frame_interval.numerator = 1;
priv->frame_interval.denominator = 30;
 
+   /* set a default mbus format  */
+   imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV);
+   ret = imx_media_init_mbus_fmt(&priv->format_mbus, 640, 480, code,
+ V4L2_FIELD_NONE, NULL);
+   if (ret)
+   return ret;
+
return media_entity_pads_init(&sd->entity, PRP_NUM_PADS, priv->pad);
 }
 
diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c 
b/drivers/staging/media/imx/imx-ic-prpencvf.c
index b42103c..644dd33 100644
--- a/drivers/staging/media/imx/imx-ic-prpencvf.c
+++ b/drivers/staging/media/imx/imx-ic-prpencvf.c
@@ -753,35 +753,23 @@ static int prp_get_fmt(struct v4l2_subdev *sd,
return ret;
 }
 
-static int prp_set_fmt(struct v4l2_subdev *sd,
-  struct v4l2_subdev_pad_config *cfg,
-  struct v4l2_subdev_format *sdformat)
+static void prp_try_fmt(struct prp_priv *priv,
+   struct v4l2_subdev_pad_config *cfg,
+   struct v4l2_subdev_format *sdformat,
+   const struct imx_media_pixfmt **cc)
 {
-   struct prp_priv *priv = sd_to_priv(sd);
-   const struct imx_media_pixfmt *cc;
-   struct v4l2_mbus_framefmt *infmt;
-   int ret = 0;
-   u32 code;
-
-   if (sdformat->pad >= PRPENCVF_NUM_PADS)
-   return -EINVAL;
-
-   mutex_lock(&priv->lock)

[PATCH v5 37/39] media: imx: csi: add frame skipping support

2017-03-09 Thread Steve Longerbeam
From: Philipp Zabel 

The CSI can skip any out of up to 6 input frames, allowing to reduce the
frame rate at the output pads by small fractions.

Signed-off-by: Philipp Zabel 
Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/imx-media-csi.c | 125 --
 1 file changed, 120 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
index a726744..e5105ec 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1,13 +1,15 @@
 /*
  * V4L2 Capture CSI Subdev for Freescale i.MX5/6 SOC
  *
- * Copyright (c) 2014-2016 Mentor Graphics Inc.
+ * Copyright (c) 2014-2017 Mentor Graphics Inc.
+ * Copyright (C) 2017 Pengutronix, Philipp Zabel 
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  */
+#include 
 #include 
 #include 
 #include 
@@ -40,6 +42,18 @@
 #define H_ALIGN1 /* multiple of 2 lines */
 #define S_ALIGN1 /* multiple of 2 */
 
+/*
+ * struct csi_skip_desc - CSI frame skipping descriptor
+ * @keep - number of frames kept per max_ratio frames
+ * @max_ratio - width of skip_smfc, written to MAX_RATIO bitfield
+ * @skip_smfc - skip pattern written to the SKIP_SMFC bitfield
+ */
+struct csi_skip_desc {
+   u8 keep;
+   u8 max_ratio;
+   u8 skip_smfc;
+};
+
 struct csi_priv {
struct device *dev;
struct ipu_soc *ipu;
@@ -65,6 +79,7 @@ struct csi_priv {
const struct imx_media_pixfmt *cc[CSI_NUM_PADS];
struct v4l2_fract frame_interval;
struct v4l2_rect crop;
+   const struct csi_skip_desc *skip[CSI_NUM_PADS - 1];
 
/* active vb2 buffers to send to video dev sink */
struct imx_media_buffer *active_vb2_buf[2];
@@ -517,10 +532,12 @@ static int csi_setup(struct csi_priv *priv)
struct v4l2_mbus_config sensor_mbus_cfg;
struct v4l2_of_endpoint *sensor_ep;
struct v4l2_mbus_framefmt if_fmt;
+   const struct csi_skip_desc *skip;
 
infmt = &priv->format_mbus[CSI_SINK_PAD];
outfmt = &priv->format_mbus[priv->active_output_pad];
sensor_ep = &priv->sensor->sensor_ep;
+   skip = priv->skip[priv->active_output_pad - 1];
 
/* compose mbus_config from sensor endpoint */
sensor_mbus_cfg.type = sensor_ep->bus_type;
@@ -545,6 +562,9 @@ static int csi_setup(struct csi_priv *priv)
 
ipu_csi_set_dest(priv->csi, priv->dest);
 
+   ipu_csi_set_skip_smfc(priv->csi, skip->skip_smfc, skip->max_ratio - 1,
+ 0);
+
ipu_csi_dump(priv->csi);
 
return 0;
@@ -608,6 +628,77 @@ static void csi_stop(struct csi_priv *priv)
ipu_csi_disable(priv->csi);
 }
 
+static const struct csi_skip_desc csi_skip[12] = {
+   { 1, 1, 0x00 }, /* Keep all frames */
+   { 5, 6, 0x10 }, /* Skip every sixth frame */
+   { 4, 5, 0x08 }, /* Skip every fifth frame */
+   { 3, 4, 0x04 }, /* Skip every fourth frame */
+   { 2, 3, 0x02 }, /* Skip every third frame */
+   { 3, 5, 0x0a }, /* Skip frames 1 and 3 of every 5 */
+   { 1, 2, 0x01 }, /* Skip every second frame */
+   { 2, 5, 0x0b }, /* Keep frames 1 and 4 of every 5 */
+   { 1, 3, 0x03 }, /* Keep one in three frames */
+   { 1, 4, 0x07 }, /* Keep one in four frames */
+   { 1, 5, 0x0f }, /* Keep one in five frames */
+   { 1, 6, 0x1f }, /* Keep one in six frames */
+};
+
+static void csi_apply_skip_interval(const struct csi_skip_desc *skip,
+   struct v4l2_fract *interval)
+{
+   unsigned int div;
+
+   interval->numerator *= skip->max_ratio;
+   interval->denominator *= skip->keep;
+
+   /* Reduce fraction to lowest terms */
+   div = gcd(interval->numerator, interval->denominator);
+   if (div > 1) {
+   interval->numerator /= div;
+   interval->denominator /= div;
+   }
+}
+
+/*
+ * Find the skip pattern to produce the output frame interval closest to the
+ * requested one, for the given input frame interval. Updates the output frame
+ * interval to the exact value.
+ */
+static const struct csi_skip_desc *csi_find_best_skip(struct v4l2_fract *in,
+ struct v4l2_fract *out)
+{
+   const struct csi_skip_desc *skip = &csi_skip[0], *best_skip = skip;
+   u32 min_err = UINT_MAX;
+   u64 want_us;
+   int i;
+
+   /* Default to 1:1 ratio */
+   if (out->numerator == 0 || out->denominator == 0 ||
+   in->numerator == 0 || in->denominator == 0)
+   return best_skip;
+
+   want_us = div_u64((u64)USEC_PER_SEC * out->numerator, out->denominator);
+
+   /* Find the reduction closest to the requested time per frame */
+ 

[PATCH v5 35/39] media: imx: csi/fim: add support for frame intervals

2017-03-09 Thread Steve Longerbeam
From: Russell King 

Add support to CSI for negotiation of frame intervals, and use this
information to configure the frame interval monitor.

Signed-off-by: Russell King 
Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/imx-media-csi.c | 46 +--
 drivers/staging/media/imx/imx-media-fim.c | 28 +++
 drivers/staging/media/imx/imx-media.h |  2 +-
 3 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
index 6640869..b556fa4 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -63,6 +63,7 @@ struct csi_priv {
 
struct v4l2_mbus_framefmt format_mbus[CSI_NUM_PADS];
const struct imx_media_pixfmt *cc[CSI_NUM_PADS];
+   struct v4l2_fract frame_interval;
struct v4l2_rect crop;
 
/* active vb2 buffers to send to video dev sink */
@@ -570,7 +571,8 @@ static int csi_start(struct csi_priv *priv)
 
/* start the frame interval monitor */
if (priv->fim) {
-   ret = imx_media_fim_set_stream(priv->fim, priv->sensor, true);
+   ret = imx_media_fim_set_stream(priv->fim,
+  &priv->frame_interval, true);
if (ret)
goto idmac_stop;
}
@@ -585,7 +587,8 @@ static int csi_start(struct csi_priv *priv)
 
 fim_off:
if (priv->fim)
-   imx_media_fim_set_stream(priv->fim, priv->sensor, false);
+   imx_media_fim_set_stream(priv->fim,
+&priv->frame_interval, false);
 idmac_stop:
if (priv->dest == IPU_CSI_DEST_IDMAC)
csi_idmac_stop(priv);
@@ -599,7 +602,8 @@ static void csi_stop(struct csi_priv *priv)
 
/* stop the frame interval monitor */
if (priv->fim)
-   imx_media_fim_set_stream(priv->fim, priv->sensor, false);
+   imx_media_fim_set_stream(priv->fim,
+&priv->frame_interval, false);
 
ipu_csi_disable(priv->csi);
 }
@@ -608,6 +612,36 @@ static void csi_stop(struct csi_priv *priv)
  * V4L2 subdev operations.
  */
 
+static int csi_g_frame_interval(struct v4l2_subdev *sd,
+   struct v4l2_subdev_frame_interval *fi)
+{
+   struct csi_priv *priv = v4l2_get_subdevdata(sd);
+
+   mutex_lock(&priv->lock);
+   fi->interval = priv->frame_interval;
+   mutex_unlock(&priv->lock);
+
+   return 0;
+}
+
+static int csi_s_frame_interval(struct v4l2_subdev *sd,
+   struct v4l2_subdev_frame_interval *fi)
+{
+   struct csi_priv *priv = v4l2_get_subdevdata(sd);
+
+   mutex_lock(&priv->lock);
+
+   /* Output pads mirror active input pad, no limits on input pads */
+   if (fi->pad == CSI_SRC_PAD_IDMAC || fi->pad == CSI_SRC_PAD_DIRECT)
+   fi->interval = priv->frame_interval;
+
+   priv->frame_interval = fi->interval;
+
+   mutex_unlock(&priv->lock);
+
+   return 0;
+}
+
 static int csi_s_stream(struct v4l2_subdev *sd, int enable)
 {
struct csi_priv *priv = v4l2_get_subdevdata(sd);
@@ -1204,6 +1238,10 @@ static int csi_registered(struct v4l2_subdev *sd)
goto put_csi;
}
 
+   /* init default frame interval */
+   priv->frame_interval.numerator = 1;
+   priv->frame_interval.denominator = 30;
+
priv->fim = imx_media_fim_init(&priv->sd);
if (IS_ERR(priv->fim)) {
ret = PTR_ERR(priv->fim);
@@ -1254,6 +1292,8 @@ static struct v4l2_subdev_core_ops csi_core_ops = {
 };
 
 static struct v4l2_subdev_video_ops csi_video_ops = {
+   .g_frame_interval = csi_g_frame_interval,
+   .s_frame_interval = csi_s_frame_interval,
.s_stream = csi_s_stream,
 };
 
diff --git a/drivers/staging/media/imx/imx-media-fim.c 
b/drivers/staging/media/imx/imx-media-fim.c
index 824d257..4fe5ffc 100644
--- a/drivers/staging/media/imx/imx-media-fim.c
+++ b/drivers/staging/media/imx/imx-media-fim.c
@@ -67,26 +67,18 @@ struct imx_media_fim {
 };
 
 static void update_fim_nominal(struct imx_media_fim *fim,
-  struct imx_media_subdev *sensor)
+  const struct v4l2_fract *fi)
 {
-   struct v4l2_streamparm parm;
-   struct v4l2_fract tpf;
-   int ret;
-
-   parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-   ret = v4l2_subdev_call(sensor->sd, video, g_parm, &parm);
-   tpf = parm.parm.capture.timeperframe;
-
-   if (ret || tpf.denominator == 0) {
-   dev_dbg(fim->sd->dev, "no tpf from sensor, FIM disabled\n");
+   if (fi->denominator == 0) {
+   dev_dbg(fim->sd->dev, "no frame interval, FIM disabled\n");
fim->enabled = false;
return;
}
 
-   fim->nominal = DIV_ROUND_CLOSEST(1000 * 1000 * tpf.numer

[PATCH v5 28/39] media: imx: Add MIPI CSI-2 Receiver subdev driver

2017-03-09 Thread Steve Longerbeam
Adds MIPI CSI-2 Receiver subdev driver. This subdev is required
for sensors with a MIPI CSI2 interface.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/Makefile |   1 +
 drivers/staging/media/imx/imx6-mipi-csi2.c | 689 +
 2 files changed, 690 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx6-mipi-csi2.c

diff --git a/drivers/staging/media/imx/Makefile 
b/drivers/staging/media/imx/Makefile
index 878a126..3569625 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-vdic.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-ic.o
 
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
+obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c 
b/drivers/staging/media/imx/imx6-mipi-csi2.c
new file mode 100644
index 000..1a71b40
--- /dev/null
+++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
@@ -0,0 +1,689 @@
+/*
+ * MIPI CSI-2 Receiver Subdev for Freescale i.MX6 SOC.
+ *
+ * Copyright (c) 2012-2017 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "imx-media.h"
+
+/*
+ * there must be 5 pads: 1 input pad from sensor, and
+ * the 4 virtual channel output pads
+ */
+#define CSI2_SINK_PAD   0
+#define CSI2_NUM_SINK_PADS  1
+#define CSI2_NUM_SRC_PADS   4
+#define CSI2_NUM_PADS   5
+
+/*
+ * The default maximum bit-rate per lane in Mbps, if the
+ * source subdev does not provide V4L2_CID_LINK_FREQ.
+ */
+#define CSI2_DEFAULT_MAX_MBPS 849
+
+struct csi2_dev {
+   struct device  *dev;
+   struct v4l2_subdev  sd;
+   struct media_pad   pad[CSI2_NUM_PADS];
+   struct clk *dphy_clk;
+   struct clk *pllref_clk;
+   struct clk *pix_clk; /* what is this? */
+   void __iomem   *base;
+   struct v4l2_of_bus_mipi_csi2 bus;
+
+   /* lock to protect all members below */
+   struct mutex lock;
+
+   struct v4l2_mbus_framefmt format_mbus;
+
+   int power_count;
+   boolstream_on;
+   struct v4l2_subdev  *src_sd;
+   boolsink_linked[CSI2_NUM_SRC_PADS];
+};
+
+#define DEVICE_NAME "imx6-mipi-csi2"
+
+/* Register offsets */
+#define CSI2_VERSION0x000
+#define CSI2_N_LANES0x004
+#define CSI2_PHY_SHUTDOWNZ  0x008
+#define CSI2_DPHY_RSTZ  0x00c
+#define CSI2_RESETN 0x010
+#define CSI2_PHY_STATE  0x014
+#define PHY_STOPSTATEDATA_BIT   4
+#define PHY_STOPSTATEDATA(n)BIT(PHY_STOPSTATEDATA_BIT + (n))
+#define PHY_RXCLKACTIVEHS   BIT(8)
+#define PHY_RXULPSCLKNOTBIT(9)
+#define PHY_STOPSTATECLKBIT(10)
+#define CSI2_DATA_IDS_1 0x018
+#define CSI2_DATA_IDS_2 0x01c
+#define CSI2_ERR1   0x020
+#define CSI2_ERR2   0x024
+#define CSI2_MSK1   0x028
+#define CSI2_MSK2   0x02c
+#define CSI2_PHY_TST_CTRL0  0x030
+#define PHY_TESTCLRBIT(0)
+#define PHY_TESTCLKBIT(1)
+#define CSI2_PHY_TST_CTRL1  0x034
+#define PHY_TESTEN BIT(16)
+#define CSI2_SFT_RESET  0xf00
+
+static inline struct csi2_dev *sd_to_dev(struct v4l2_subdev *sdev)
+{
+   return container_of(sdev, struct csi2_dev, sd);
+}
+
+static void csi2_enable(struct csi2_dev *csi2, bool enable)
+{
+   if (enable) {
+   writel(0x1, csi2->base + CSI2_PHY_SHUTDOWNZ);
+   writel(0x1, csi2->base + CSI2_DPHY_RSTZ);
+   writel(0x1, csi2->base + CSI2_RESETN);
+   } else {
+   writel(0x0, csi2->base + CSI2_PHY_SHUTDOWNZ);
+   writel(0x0, csi2->base + CSI2_DPHY_RSTZ);
+   writel(0x0, csi2->base + CSI2_RESETN);
+   }
+}
+
+static void csi2_set_lanes(struct csi2_dev *csi2)
+{
+   int lanes = csi2->bus.num_data_lanes;
+
+   writel(lanes - 1, csi2->base + CSI2_N_LANES);
+}
+
+static void dw_mipi_csi2_phy_write(struct csi2_dev *csi2,
+  u32 test_code, u32 test_data)
+{
+   /* Clear PHY test interface */
+   writel(PHY_TESTCLR, csi2->base + CSI2_PHY_TST_CTRL0);
+   writel(0x0, csi2->base + CSI2_PHY_TST_CTRL1);
+   writel(0x0, csi2->base + CSI2_PHY_TST_CTRL0);
+
+   /* Raise test interface strobe signal */
+   writel(PHY_TESTCLK, csi2->base + CSI2_PHY_TST_CTRL0);
+
+   /* Configure address write on falling edge and lower strobe signal */
+   writel(PHY_TESTEN | test_code, csi2->base + CSI2_PHY_TST_CTRL1);
+   writel(0x0, csi2->base + C

[PATCH v5 38/39] media: imx: csi: fix crop rectangle reset in sink set_fmt

2017-03-09 Thread Steve Longerbeam
From: Philipp Zabel 

The csi_try_crop call in set_fmt should compare the cropping rectangle
to the currently set input format, not to the previous input format.

Signed-off-by: Philipp Zabel 
Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/imx-media-csi.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
index e5105ec..cf070be 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -989,13 +989,11 @@ __csi_get_fmt(struct csi_priv *priv, struct 
v4l2_subdev_pad_config *cfg,
 static int csi_try_crop(struct csi_priv *priv,
struct v4l2_rect *crop,
struct v4l2_subdev_pad_config *cfg,
-   enum v4l2_subdev_format_whence which,
+   struct v4l2_mbus_framefmt *infmt,
struct imx_media_subdev *sensor)
 {
struct v4l2_of_endpoint *sensor_ep;
-   struct v4l2_mbus_framefmt *infmt;
 
-   infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, which);
sensor_ep = &sensor->sensor_ep;
 
crop->width = min_t(__u32, infmt->width, crop->width);
@@ -1178,8 +1176,7 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
crop.top = 0;
crop.width = sdformat->format.width;
crop.height = sdformat->format.height;
-   ret = csi_try_crop(priv, &crop, cfg,
-  sdformat->which, sensor);
+   ret = csi_try_crop(priv, &crop, cfg, &sdformat->format, sensor);
if (ret)
goto out;
 
@@ -1263,6 +1260,7 @@ static int csi_set_selection(struct v4l2_subdev *sd,
 struct v4l2_subdev_selection *sel)
 {
struct csi_priv *priv = v4l2_get_subdevdata(sd);
+   struct v4l2_mbus_framefmt *infmt;
struct imx_media_subdev *sensor;
int ret = 0;
 
@@ -1296,7 +1294,8 @@ static int csi_set_selection(struct v4l2_subdev *sd,
goto out;
}
 
-   ret = csi_try_crop(priv, &sel->r, cfg, sel->which, sensor);
+   infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sel->which);
+   ret = csi_try_crop(priv, &sel->r, cfg, infmt, sensor);
if (ret)
goto out;
 
-- 
2.7.4



[PATCH v5 24/39] media: imx: Add Capture Device Interface

2017-03-09 Thread Steve Longerbeam
This is the capture device interface driver that provides the v4l2
user interface. Frames can be received from various sources:

- directly from CSI for capturing unconverted images directly from
  camera sensors.

- from the IC pre-process encode task.

- from the IC pre-process viewfinder task.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/Makefile|   1 +
 drivers/staging/media/imx/imx-media-capture.c | 655 ++
 2 files changed, 656 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx-media-capture.c

diff --git a/drivers/staging/media/imx/Makefile 
b/drivers/staging/media/imx/Makefile
index ddd7d94..4606a3a 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -3,3 +3,4 @@ imx-media-common-objs := imx-media-utils.o imx-media-fim.o
 
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
+obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-capture.o
diff --git a/drivers/staging/media/imx/imx-media-capture.c 
b/drivers/staging/media/imx/imx-media-capture.c
new file mode 100644
index 000..704ed85
--- /dev/null
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -0,0 +1,655 @@
+/*
+ * Video Capture Subdev for Freescale i.MX5/6 SOC
+ *
+ * Copyright (c) 2012-2016 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "imx-media.h"
+
+struct capture_priv {
+   struct imx_media_video_dev vdev;
+
+   struct v4l2_subdev*src_sd;
+   int   src_sd_pad;
+   struct device *dev;
+
+   struct media_pipeline mp;
+   struct imx_media_dev  *md;
+
+   struct media_pad  vdev_pad;
+
+   struct mutex  mutex;   /* capture device mutex */
+
+   /* the videobuf2 queue */
+   struct vb2_queue   q;
+   /* list of ready imx_media_buffer's from q */
+   struct list_head   ready_q;
+   /* protect ready_q */
+   spinlock_t q_lock;
+
+   /* controls inherited from subdevs */
+   struct v4l2_ctrl_handler ctrl_hdlr;
+
+   /* misc status */
+   bool  stop;  /* streaming is stopping */
+};
+
+#define to_capture_priv(v) container_of(v, struct capture_priv, vdev)
+
+/* In bytes, per queue */
+#define VID_MEM_LIMIT  SZ_64M
+
+static struct vb2_ops capture_qops;
+
+/*
+ * Video ioctls follow
+ */
+
+static int vidioc_querycap(struct file *file, void *fh,
+  struct v4l2_capability *cap)
+{
+   struct capture_priv *priv = video_drvdata(file);
+
+   strncpy(cap->driver, "imx-media-capture", sizeof(cap->driver) - 1);
+   strncpy(cap->card, "imx-media-capture", sizeof(cap->card) - 1);
+   snprintf(cap->bus_info, sizeof(cap->bus_info),
+"platform:%s", dev_name(priv->dev));
+
+   return 0;
+}
+
+static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
+   struct v4l2_fmtdesc *f)
+{
+   u32 fourcc;
+   int ret;
+
+   ret = imx_media_enum_format(&fourcc, NULL, f->index, true, true);
+   if (ret)
+   return ret;
+
+   f->pixelformat = fourcc;
+
+   return 0;
+}
+
+static int capture_g_fmt_vid_cap(struct file *file, void *fh,
+struct v4l2_format *f)
+{
+   struct capture_priv *priv = video_drvdata(file);
+
+   *f = priv->vdev.fmt;
+
+   return 0;
+}
+
+static int capture_try_fmt_vid_cap(struct file *file, void *fh,
+  struct v4l2_format *f)
+{
+   struct capture_priv *priv = video_drvdata(file);
+   struct v4l2_subdev_format fmt_src;
+   const struct imx_media_pixfmt *cc, *src_cc;
+   u32 fourcc;
+   int ret;
+
+   fourcc = f->fmt.pix.pixelformat;
+   cc = imx_media_find_format(fourcc, 0, true, true);
+   if (!cc) {
+   imx_media_enum_format(&fourcc, NULL, 0, true, true);
+   cc = imx_media_find_format(fourcc, 0, true, true);
+   }
+
+   /*
+* user frame dimensions are the same as src_sd's pad.
+*/
+   fmt_src.pad = priv->src_sd_pad;
+   fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+   ret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL, &fmt_src);
+   if (ret)
+   return ret;
+
+   /*
+* but we can allow planar pixel formats if the src_sd's
+* pad configured a YUV format
+*/
+   src_cc = imx_media_find_format(0, fmt_src.format.code, true, false);
+   

[PATCH v5 15/39] [media] v4l2: add a frame interval error event

2017-03-09 Thread Steve Longerbeam
Add a new FRAME_INTERVAL_ERROR event to signal that a video capture or
output device has measured an interval between the reception or transmit
completion of two consecutive frames of video that is outside the nominal
frame interval by some tolerance value.

Signed-off-by: Steve Longerbeam 
---
 Documentation/media/uapi/v4l/vidioc-dqevent.rst | 6 ++
 Documentation/media/videodev2.h.rst.exceptions  | 1 +
 include/uapi/linux/videodev2.h  | 1 +
 3 files changed, 8 insertions(+)

diff --git a/Documentation/media/uapi/v4l/vidioc-dqevent.rst 
b/Documentation/media/uapi/v4l/vidioc-dqevent.rst
index 8d663a7..dc77363 100644
--- a/Documentation/media/uapi/v4l/vidioc-dqevent.rst
+++ b/Documentation/media/uapi/v4l/vidioc-dqevent.rst
@@ -197,6 +197,12 @@ call.
the regions changes. This event has a struct
:c:type:`v4l2_event_motion_det`
associated with it.
+* - ``V4L2_EVENT_FRAME_INTERVAL_ERROR``
+  - 7
+  - This event is triggered when the video capture or output device
+   has measured an interval between the reception or transmit
+   completion of two consecutive frames of video that is outside
+   the nominal frame interval by some tolerance value.
 * - ``V4L2_EVENT_PRIVATE_START``
   - 0x0800
   - Base event number for driver-private events.
diff --git a/Documentation/media/videodev2.h.rst.exceptions 
b/Documentation/media/videodev2.h.rst.exceptions
index e11a0d0..c7d8fad 100644
--- a/Documentation/media/videodev2.h.rst.exceptions
+++ b/Documentation/media/videodev2.h.rst.exceptions
@@ -459,6 +459,7 @@ replace define V4L2_EVENT_CTRL event-type
 replace define V4L2_EVENT_FRAME_SYNC event-type
 replace define V4L2_EVENT_SOURCE_CHANGE event-type
 replace define V4L2_EVENT_MOTION_DET event-type
+replace define V4L2_EVENT_FRAME_INTERVAL_ERROR event-type
 replace define V4L2_EVENT_PRIVATE_START event-type
 
 replace define V4L2_EVENT_CTRL_CH_VALUE ctrl-changes-flags
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 45184a2..cf5a0d0 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -2131,6 +2131,7 @@ struct v4l2_streamparm {
 #define V4L2_EVENT_FRAME_SYNC  4
 #define V4L2_EVENT_SOURCE_CHANGE   5
 #define V4L2_EVENT_MOTION_DET  6
+#define V4L2_EVENT_FRAME_INTERVAL_ERROR7
 #define V4L2_EVENT_PRIVATE_START   0x0800
 
 /* Payload for V4L2_EVENT_VSYNC */
-- 
2.7.4



[PATCH v5 36/39] media: imx: redo pixel format enumeration and negotiation

2017-03-09 Thread Steve Longerbeam
The previous API and negotiation of mbus codes and pixel formats
was broken, and has been completely redone.

The negotiation of media bus codes should be as follows:

CSI:

sink pad direct src pad  IDMAC src pad
 -
RGB (any)IPU RGB   IPU RGB
YUV (any)IPU YUV   IPU YUV
Bayer  N/A must be same bayer code as sink

VDIC:

direct sink padIDMAC sink paddirect src pad
-------
IPU YUV only   IPU YUV only   IPU YUV only

PRP:

direct sink paddirect src pads
------
IPU (any)  same as sink code

PRP ENC/VF:

direct sink padIDMAC src pads
-----
IPU (any)  IPU RGB or IPU YUV

Given the above, a new internal API is created:

enum codespace_sel {
   CS_SEL_YUV = 0, /* find or enumerate only YUV codes */
   CS_SEL_RGB, /* find or enumerate only RGB codes */
   CS_SEL_ANY, /* find or enumerate both YUV and RGB codes */
};

/* Find and enumerate fourcc pixel formats */
const struct imx_media_pixfmt *
imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel);
int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel);

/* Find and enumerate media bus codes */
const struct imx_media_pixfmt *
imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel,
  bool allow_bayer);
int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel,
  bool allow_bayer);

/* Find and enumerate IPU internal media bus codes */
const struct imx_media_pixfmt *
imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel);
int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel);

The tables have been split into separate tables for YUV and RGB formats
to support the implementation of the above.

The subdev's .enum_mbus_code() and .set_fmt() operations have
been rewritten using the above APIs.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/imx-ic-prp.c|  77 --
 drivers/staging/media/imx/imx-ic-prpencvf.c   |  57 ++--
 drivers/staging/media/imx/imx-media-capture.c |  85 --
 drivers/staging/media/imx/imx-media-csi.c | 108 +---
 drivers/staging/media/imx/imx-media-utils.c   | 371 +++---
 drivers/staging/media/imx/imx-media-vdic.c|  69 ++---
 drivers/staging/media/imx/imx-media.h |  27 +-
 7 files changed, 504 insertions(+), 290 deletions(-)

diff --git a/drivers/staging/media/imx/imx-ic-prp.c 
b/drivers/staging/media/imx/imx-ic-prp.c
index 1832915..83cd2b4 100644
--- a/drivers/staging/media/imx/imx-ic-prp.c
+++ b/drivers/staging/media/imx/imx-ic-prp.c
@@ -89,16 +89,6 @@ static void prp_stop(struct prp_priv *priv)
 {
 }
 
-static int prp_enum_mbus_code(struct v4l2_subdev *sd,
- struct v4l2_subdev_pad_config *cfg,
- struct v4l2_subdev_mbus_code_enum *code)
-{
-   if (code->pad >= PRP_NUM_PADS)
-   return -EINVAL;
-
-   return imx_media_enum_ipu_format(NULL, &code->code, code->index, true);
-}
-
 static struct v4l2_mbus_framefmt *
 __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_pad_config *cfg,
  unsigned int pad, enum v4l2_subdev_format_whence which)
@@ -115,6 +105,38 @@ __prp_get_fmt(struct prp_priv *priv, struct 
v4l2_subdev_pad_config *cfg,
  * V4L2 subdev operations.
  */
 
+static int prp_enum_mbus_code(struct v4l2_subdev *sd,
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_mbus_code_enum *code)
+{
+   struct prp_priv *priv = sd_to_priv(sd);
+   struct v4l2_mbus_framefmt *infmt;
+   int ret = 0;
+
+   mutex_lock(&priv->lock);
+
+   switch (code->pad) {
+   case PRP_SINK_PAD:
+   ret = imx_media_enum_ipu_format(&code->code, code->index,
+   CS_SEL_ANY);
+   break;
+   case PRP_SRC_PAD_PRPENC:
+   case PRP_SRC_PAD_PRPVF:
+   if (code->index != 0) {
+   ret = -EINVAL;
+   goto out;
+   }
+   infmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD, code->which);
+   code->code = infmt->code;
+   break;
+   default:
+   ret = -EINVAL;
+   }
+out:
+   mutex_unlock(&priv->lock);
+   return ret;
+}
+
 static int prp_get_fmt(struct v4l2_subdev *sd,
   struct v4l2_subdev_pad_config *cfg,
   struct v4l2_subdev_format *sdformat)
@@ -160,23 +182,28 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
goto out;
}
 
-   cc = imx_media_find_ipu_format(0, sdformat->format.code, true);
-   if (!cc) {
-   imx_media_enum_ipu_format(NULL, &code, 0, true);
-

[PATCH v5 20/39] platform: add video-multiplexer subdevice driver

2017-03-09 Thread Steve Longerbeam
From: Philipp Zabel 

This driver can handle SoC internal and external video bus multiplexers,
controlled either by register bit fields or by a GPIO. The subdevice
passes through frame interval and mbus configuration of the active input
to the output side.

Signed-off-by: Sascha Hauer 
Signed-off-by: Philipp Zabel 

- fixed a cut&paste error in vidsw_remove(): v4l2_async_register_subdev()
  should be unregister.

- added media_entity_cleanup() to vidsw_remove().

- added missing MODULE_DEVICE_TABLE().
  Suggested-by: Javier Martinez Canillas 

- there was a line left over from a previous iteration that negated
  the new way of determining the pad count just before it which
  has been removed (num_pads = of_get_child_count(np)).

- enforce that output frame interval must mirror input frame interval
  in vidsw_s_frame_interval().

- init frame interval to a default 30 fps.

- add link_validate to media_entity_operations and v4l2_subdev_pad_ops.

- moved devicetree binding doc to a separate commit.

- Philipp Zabel has developed a set of patches that allow adding
  to the subdev async notifier waiting list using a chaining method
  from the async registered callbacks (v4l2_of_subdev_registered()
  and the prep patches for that). For now, I've removed the use of
  v4l2_of_subdev_registered() for the vidmux driver's registered
  callback. This doesn't affect the functionality of this driver,
  but allows for it to be merged now, before adding the chaining
  support.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/platform/Kconfig |   8 +
 drivers/media/platform/Makefile|   2 +
 drivers/media/platform/video-multiplexer.c | 498 +
 3 files changed, 508 insertions(+)
 create mode 100644 drivers/media/platform/video-multiplexer.c

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 53f6f12..3226eb6 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -74,6 +74,14 @@ config VIDEO_M32R_AR_M64278
  To compile this driver as a module, choose M here: the
  module will be called arv.
 
+config VIDEO_MULTIPLEXER
+   tristate "Video Multiplexer"
+   depends on VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER
+   help
+ This driver provides support for SoC internal N:1 video bus
+ multiplexers controlled by register bitfields as well as external
+ 2:1 video multiplexers controlled by a single GPIO.
+
 config VIDEO_OMAP3
tristate "OMAP 3 Camera support"
depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && ARCH_OMAP3
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 8959f6e..d418add 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -27,6 +27,8 @@ obj-$(CONFIG_VIDEO_SH_VEU)+= sh_veu.o
 
 obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE)+= m2m-deinterlace.o
 
+obj-$(CONFIG_VIDEO_MULTIPLEXER)+= video-multiplexer.o
+
 obj-$(CONFIG_VIDEO_S3C_CAMIF)  += s3c-camif/
 obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS4_IS) += exynos4-is/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG)   += s5p-jpeg/
diff --git a/drivers/media/platform/video-multiplexer.c 
b/drivers/media/platform/video-multiplexer.c
new file mode 100644
index 000..02a21072
--- /dev/null
+++ b/drivers/media/platform/video-multiplexer.c
@@ -0,0 +1,498 @@
+/*
+ * video stream multiplexer controlled via gpio or syscon
+ *
+ * Copyright (C) 2013 Pengutronix, Sascha Hauer 
+ * Copyright (C) 2016 Pengutronix, Philipp Zabel 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct vidsw {
+   struct v4l2_subdev subdev;
+   unsigned int num_pads;
+   struct media_pad *pads;
+   struct v4l2_mbus_framefmt *format_mbus;
+   struct v4l2_fract timeperframe;
+   struct v4l2_of_endpoint *endpoint;
+   struct regmap_field *field;
+   struct gpio_desc *gpio;
+   int active;
+};
+
+static inline struct vidsw *v4l2_subdev_to_vidsw(struct v4l2_subdev *sd)
+{
+   return container_of(sd, struct vidsw, subdev);
+}
+
+static void vidsw_set_active(struct vidsw *vidsw, int active)
+{
+   vidsw->active = active;
+   if (active < 0)
+   return;
+
+   dev_dbg(vidsw->subdev.dev, "setting %d active\n", active);
+
+   if (vidsw->field)
+   regmap_field_write(vidsw

[PATCH v5 11/39] ARM: dts: imx6-sabreauto: add reset-gpios property for max7310_b

2017-03-09 Thread Steve Longerbeam
The reset pin to the port expander chip (MAX7310) is controlled by a gpio,
so define a reset-gpios property to control it. There are three MAX7310's
on the SabreAuto CPU card (max7310_[abc]), but all use the same pin for
their reset. Since all can't acquire the same pin, assign it to max7310_b,
that chip is needed by more functions (usb and adv7180).

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index c8e35c4..21dea5f 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -136,6 +136,9 @@
reg = <0x32>;
gpio-controller;
#gpio-cells = <2>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_max7310>;
+   reset-gpios = <&gpio1 15 GPIO_ACTIVE_LOW>;
};
 
max7310_c: gpio@34 {
@@ -441,6 +444,12 @@
>;
};
 
+   pinctrl_max7310: max7310grp {
+   fsl,pins = <
+   MX6QDL_PAD_SD2_DAT0__GPIO1_IO15 0x1b0b0
+   >;
+   };
+
pinctrl_pwm3: pwm1grp {
fsl,pins = <
MX6QDL_PAD_SD4_DAT1__PWM3_OUT   0x1b0b1
-- 
2.7.4



[PATCH v5 10/39] ARM: dts: imx6-sabreauto: create i2cmux for i2c3

2017-03-09 Thread Steve Longerbeam
The sabreauto uses a steering pin to select between the SDA signal on
i2c3 bus, and a data-in pin for an SPI NOR chip. Use i2cmux to control
this steering pin. Idle state of the i2cmux selects SPI NOR. This is not
a classic way to use i2cmux, since one side of the mux selects something
other than an i2c bus, but it works and is probably the cleanest
solution. Note that if one thread is attempting to access SPI NOR while
another thread is accessing i2c3, the SPI NOR access will fail since the
i2cmux has selected the SDA pin rather than SPI NOR data-in. This couldn't
be avoided in any case, the board is not designed to allow concurrent
i2c3 and SPI NOR functions (and the default device-tree does not enable
SPI NOR anyway).

Devices hanging off i2c3 should now be defined under i2cmux, so
that the steering pin can be properly controlled to access those
devices. The port expanders (MAX7310) are thus moved into i2cmux.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 65 +---
 1 file changed, 44 insertions(+), 21 deletions(-)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index a2a714d..c8e35c4 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -108,6 +108,44 @@
default-brightness-level = <7>;
status = "okay";
};
+
+   i2cmux {
+   compatible = "i2c-mux-gpio";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_i2c3mux>;
+   mux-gpios = <&gpio5 4 0>;
+   i2c-parent = <&i2c3>;
+   idle-state = <0>;
+
+   i2c@1 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   reg = <1>;
+
+   max7310_a: gpio@30 {
+   compatible = "maxim,max7310";
+   reg = <0x30>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+
+   max7310_b: gpio@32 {
+   compatible = "maxim,max7310";
+   reg = <0x32>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+
+   max7310_c: gpio@34 {
+   compatible = "maxim,max7310";
+   reg = <0x34>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+   };
+   };
 };
 
 &clks {
@@ -290,27 +328,6 @@
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c3>;
status = "okay";
-
-   max7310_a: gpio@30 {
-   compatible = "maxim,max7310";
-   reg = <0x30>;
-   gpio-controller;
-   #gpio-cells = <2>;
-   };
-
-   max7310_b: gpio@32 {
-   compatible = "maxim,max7310";
-   reg = <0x32>;
-   gpio-controller;
-   #gpio-cells = <2>;
-   };
-
-   max7310_c: gpio@34 {
-   compatible = "maxim,max7310";
-   reg = <0x34>;
-   gpio-controller;
-   #gpio-cells = <2>;
-   };
 };
 
 &iomuxc {
@@ -418,6 +435,12 @@
>;
};
 
+   pinctrl_i2c3mux: i2c3muxgrp {
+   fsl,pins = <
+   MX6QDL_PAD_EIM_A24__GPIO5_IO04 0x0b0b1
+   >;
+   };
+
pinctrl_pwm3: pwm1grp {
fsl,pins = <
MX6QDL_PAD_SD4_DAT1__PWM3_OUT   0x1b0b1
-- 
2.7.4



[PATCH v5 05/39] ARM: dts: imx6qdl: Add mipi_ipu1/2 multiplexers, mipi_csi, and their connections

2017-03-09 Thread Steve Longerbeam
From: Philipp Zabel 

This patch adds the device tree graph connecting the input multiplexers
to the IPU CSIs and the MIPI-CSI2 gasket on i.MX6. The MIPI_IPU
multiplexers are added as children of the iomuxc-gpr syscon device node.
On i.MX6Q/D two two-input multiplexers in front of IPU1 CSI0 and IPU2
CSI1 allow to select between CSI0/1 parallel input pads and the MIPI
CSI-2 virtual channels 0/3.
On i.MX6DL/S two five-input multiplexers in front of IPU1 CSI0 and IPU1
CSI1 allow to select between CSI0/1 parallel input pads and any of the
four MIPI CSI-2 virtual channels.

Signed-off-by: Philipp Zabel 

--

- Removed some dangling/unused endpoints (ipu2_csi0_from_csi2ipu)
- Renamed the mipi virtual channel endpoint labels, from "mipi_csiX_..."
  to "mipi_vcX...".
- Added input endpoint anchors to the video muxes for the connections
  from parallel sensors.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6dl.dtsi  | 180 +
 arch/arm/boot/dts/imx6q.dtsi   | 116 ++
 arch/arm/boot/dts/imx6qdl.dtsi |  10 ++-
 3 files changed, 305 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx6dl.dtsi b/arch/arm/boot/dts/imx6dl.dtsi
index 7aa120f..8958c4a 100644
--- a/arch/arm/boot/dts/imx6dl.dtsi
+++ b/arch/arm/boot/dts/imx6dl.dtsi
@@ -181,6 +181,186 @@
  "di0", "di1";
 };
 
+&gpr {
+   ipu1_csi0_mux: ipu1_csi0_mux@34 {
+   compatible = "video-multiplexer";
+   reg = <0x34>;
+   bit-mask = <0x7>;
+   bit-shift = <0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "okay";
+
+   port@0 {
+   reg = <0>;
+
+   ipu1_csi0_mux_from_mipi_vc0: endpoint {
+   remote-endpoint = <&mipi_vc0_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   ipu1_csi0_mux_from_mipi_vc1: endpoint {
+   remote-endpoint = <&mipi_vc1_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   ipu1_csi0_mux_from_mipi_vc2: endpoint {
+   remote-endpoint = <&mipi_vc2_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@3 {
+   reg = <3>;
+
+   ipu1_csi0_mux_from_mipi_vc3: endpoint {
+   remote-endpoint = <&mipi_vc3_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@4 {
+   reg = <4>;
+
+   ipu1_csi0_mux_from_parallel_sensor: endpoint {
+   };
+   };
+
+   port@5 {
+   reg = <5>;
+
+   ipu1_csi0_mux_to_ipu1_csi0: endpoint {
+   remote-endpoint = 
<&ipu1_csi0_from_ipu1_csi0_mux>;
+   };
+   };
+   };
+
+   ipu1_csi1_mux: ipu1_csi1_mux@34 {
+   compatible = "video-multiplexer";
+   reg = <0x34>;
+   bit-mask = <0x7>;
+   bit-shift = <3>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "okay";
+
+   port@0 {
+   reg = <0>;
+
+   ipu1_csi1_mux_from_mipi_vc0: endpoint {
+   remote-endpoint = <&mipi_vc0_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   ipu1_csi1_mux_from_mipi_vc1: endpoint {
+   remote-endpoint = <&mipi_vc1_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   ipu1_csi1_mux_from_mipi_vc2: endpoint {
+   remote-endpoint = <&mipi_vc2_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@3 {
+   reg = <3>;
+
+   ipu1_csi1_mux_from_mipi_vc3: endpoint {
+   remote-endpoint = <&mipi_vc3_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@4 {
+   reg = <4>;
+
+   ipu1_csi1_mux_from_parallel_sensor: endpoint {
+   };
+   };
+
+   port@5 {
+   reg = <5>;
+
+   ipu1_csi1_mux_to_ipu1_csi1: endpoint {
+   remote-endpoint = 
<&ipu1_csi1_from_ipu1_csi1_mux>;
+   };
+   };
+   };
+};
+
+&ipu1_csi1 {
+   ipu1_csi1_from_ipu1_csi1_mux: endpoint {
+   r

[PATCH v5 03/39] [media] dt/bindings: Add bindings for OV5640

2017-03-09 Thread Steve Longerbeam
Add device tree binding documentation for the OV5640 camera sensor.

Signed-off-by: Steve Longerbeam 
---
 .../devicetree/bindings/media/i2c/ov5640.txt   | 45 ++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov5640.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ov5640.txt 
b/Documentation/devicetree/bindings/media/i2c/ov5640.txt
new file mode 100644
index 000..540b36c
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ov5640.txt
@@ -0,0 +1,45 @@
+* Omnivision OV5640 MIPI CSI-2 sensor
+
+Required Properties:
+- compatible: should be "ovti,ov5640"
+- clocks: reference to the xclk input clock.
+- clock-names: should be "xclk".
+- DOVDD-supply: Digital I/O voltage supply, 1.8 volts
+- AVDD-supply: Analog voltage supply, 2.8 volts
+- DVDD-supply: Digital core voltage supply, 1.5 volts
+
+Optional Properties:
+- reset-gpios: reference to the GPIO connected to the reset pin, if any.
+  This is an active low signal to the OV5640.
+- powerdown-gpios: reference to the GPIO connected to the powerdown pin,
+  if any. This is an active high signal to the OV5640.
+
+The device node must contain one 'port' child node for its digital output
+video port, in accordance with the video interface bindings defined in
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+&i2c1 {
+   ov5640: camera@3c {
+   compatible = "ovti,ov5640";
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ov5640>;
+   reg = <0x3c>;
+   clocks = <&clks IMX6QDL_CLK_CKO>;
+   clock-names = "xclk";
+   DOVDD-supply = <&vgen4_reg>; /* 1.8v */
+   AVDD-supply = <&vgen3_reg>;  /* 2.8v */
+   DVDD-supply = <&vgen2_reg>;  /* 1.5v */
+   powerdown-gpios = <&gpio1 19 GPIO_ACTIVE_HIGH>;
+   reset-gpios = <&gpio1 20 GPIO_ACTIVE_LOW>;
+
+   port {
+   ov5640_to_mipi_csi2: endpoint {
+   remote-endpoint = <&mipi_csi2_from_ov5640>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+   };
+   };
+   };
+};
-- 
2.7.4



[PATCH v5 08/39] ARM: dts: imx6-sabrelite: add OV5642 and OV5640 camera sensors

2017-03-09 Thread Steve Longerbeam
Adds the OV5642 parallel-bus sensor, and the OV5640 MIPI CSI-2 sensor.
Both hang off the same i2c2 bus, so they require different (and non-
default) i2c slave addresses.

The OV5642 connects to the parallel-bus mux input port on ipu1_csi0_mux.

The OV5640 connects to the input port on the MIPI CSI-2 receiver on
mipi_csi.

The OV5642 node is disabled temporarily while the subdev driver is
cleaned up and submitted later.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6dl-sabrelite.dts   |   5 ++
 arch/arm/boot/dts/imx6q-sabrelite.dts|   5 ++
 arch/arm/boot/dts/imx6qdl-sabrelite.dtsi | 148 +++
 3 files changed, 158 insertions(+)

diff --git a/arch/arm/boot/dts/imx6dl-sabrelite.dts 
b/arch/arm/boot/dts/imx6dl-sabrelite.dts
index 2f90452..3304076 100644
--- a/arch/arm/boot/dts/imx6dl-sabrelite.dts
+++ b/arch/arm/boot/dts/imx6dl-sabrelite.dts
@@ -48,3 +48,8 @@
model = "Freescale i.MX6 DualLite SABRE Lite Board";
compatible = "fsl,imx6dl-sabrelite", "fsl,imx6dl";
 };
+
+&ipu1_csi1_from_ipu1_csi1_mux {
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+};
diff --git a/arch/arm/boot/dts/imx6q-sabrelite.dts 
b/arch/arm/boot/dts/imx6q-sabrelite.dts
index 02a7cdf..dc51262e 100644
--- a/arch/arm/boot/dts/imx6q-sabrelite.dts
+++ b/arch/arm/boot/dts/imx6q-sabrelite.dts
@@ -52,3 +52,8 @@
 &sata {
status = "okay";
 };
+
+&ipu1_csi1_from_mipi_vc1 {
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+};
diff --git a/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
index 89dce27..afe7449 100644
--- a/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
@@ -39,6 +39,8 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  */
+
+#include 
 #include 
 #include 
 
@@ -94,6 +96,42 @@
pinctrl-0 = <&pinctrl_can_xcvr>;
gpio = <&gpio1 2 GPIO_ACTIVE_LOW>;
};
+
+   reg_1p5v: regulator@4 {
+   compatible = "regulator-fixed";
+   reg = <4>;
+   regulator-name = "1P5V";
+   regulator-min-microvolt = <150>;
+   regulator-max-microvolt = <150>;
+   regulator-always-on;
+   };
+
+   reg_1p8v: regulator@5 {
+   compatible = "regulator-fixed";
+   reg = <5>;
+   regulator-name = "1P8V";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   regulator-always-on;
+   };
+
+   reg_2p8v: regulator@6 {
+   compatible = "regulator-fixed";
+   reg = <6>;
+   regulator-name = "2P8V";
+   regulator-min-microvolt = <280>;
+   regulator-max-microvolt = <280>;
+   regulator-always-on;
+   };
+   };
+
+   mipi_xclk: mipi_xclk {
+   compatible = "pwm-clock";
+   #clock-cells = <0>;
+   clock-frequency = <2200>;
+   clock-output-names = "mipi_pwm3";
+   pwms = <&pwm3 0 45>; /* 1 / 45 ns = 22 MHz */
+   status = "okay";
};
 
gpio-keys {
@@ -220,6 +258,22 @@
};
 };
 
+&ipu1_csi0_from_ipu1_csi0_mux {
+   bus-width = <8>;
+   data-shift = <12>; /* Lines 19:12 used */
+   hsync-active = <1>;
+   vync-active = <1>;
+};
+
+&ipu1_csi0_mux_from_parallel_sensor {
+   remote-endpoint = <&ov5642_to_ipu1_csi0_mux>;
+};
+
+&ipu1_csi0 {
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ipu1_csi0>;
+};
+
 &audmux {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_audmux>;
@@ -298,6 +352,53 @@
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c2>;
status = "okay";
+
+   ov5640: camera@40 {
+   compatible = "ovti,ov5640";
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ov5640>;
+   reg = <0x40>;
+   clocks = <&mipi_xclk>;
+   clock-names = "xclk";
+   DOVDD-supply = <®_1p8v>;
+   AVDD-supply = <®_2p8v>;
+   DVDD-supply = <®_1p5v>;
+   reset-gpios = <&gpio2 5 GPIO_ACTIVE_LOW>; /* NANDF_D5 */
+   powerdown-gpios = <&gpio6 9 GPIO_ACTIVE_HIGH>; /* NANDF_WP_B */
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   ov5640_to_mipi_csi2: endpoint {
+   remote-endpoint = <&mipi_csi2_in>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+   

[PATCH v5 09/39] ARM: dts: imx6-sabresd: add OV5642 and OV5640 camera sensors

2017-03-09 Thread Steve Longerbeam
Enables the OV5642 parallel-bus sensor, and the OV5640 MIPI CSI-2 sensor.

The OV5642 connects to the parallel-bus mux input port on ipu1_csi0_mux.

The OV5640 connects to the input port on the MIPI CSI-2 receiver on
mipi_csi.

Until the OV5652 sensor module compatible with the SabreSD becomes
available for testing, the ov5642 node is currently disabled.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6dl-sabresd.dts   |   5 ++
 arch/arm/boot/dts/imx6q-sabresd.dts|   5 ++
 arch/arm/boot/dts/imx6qdl-sabresd.dtsi | 114 -
 3 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx6dl-sabresd.dts 
b/arch/arm/boot/dts/imx6dl-sabresd.dts
index 1e45f2f..9607afe 100644
--- a/arch/arm/boot/dts/imx6dl-sabresd.dts
+++ b/arch/arm/boot/dts/imx6dl-sabresd.dts
@@ -15,3 +15,8 @@
model = "Freescale i.MX6 DualLite SABRE Smart Device Board";
compatible = "fsl,imx6dl-sabresd", "fsl,imx6dl";
 };
+
+&ipu1_csi1_from_ipu1_csi1_mux {
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+};
diff --git a/arch/arm/boot/dts/imx6q-sabresd.dts 
b/arch/arm/boot/dts/imx6q-sabresd.dts
index 9cbdfe7..527772b 100644
--- a/arch/arm/boot/dts/imx6q-sabresd.dts
+++ b/arch/arm/boot/dts/imx6q-sabresd.dts
@@ -23,3 +23,8 @@
 &sata {
status = "okay";
 };
+
+&ipu1_csi1_from_mipi_vc1 {
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+};
diff --git a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
index 63bf95e..643c1d4 100644
--- a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
@@ -10,6 +10,7 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
+#include 
 #include 
 #include 
 
@@ -146,6 +147,36 @@
};
 };
 
+&ipu1_csi0_from_ipu1_csi0_mux {
+   bus-width = <8>;
+   data-shift = <12>; /* Lines 19:12 used */
+   hsync-active = <1>;
+   vsync-active = <1>;
+};
+
+&ipu1_csi0_mux_from_parallel_sensor {
+   remote-endpoint = <&ov5642_to_ipu1_csi0_mux>;
+};
+
+&ipu1_csi0 {
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ipu1_csi0>;
+};
+
+&mipi_csi {
+   status = "okay";
+
+   port@0 {
+   reg = <0>;
+
+   mipi_csi2_in: endpoint {
+   remote-endpoint = <&ov5640_to_mipi_csi2>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+   };
+   };
+};
+
 &audmux {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_audmux>;
@@ -213,7 +244,32 @@
0x8014 /* 4:FN_DMICCDAT */
0x /* 5:Default */
>;
-   };
+   };
+
+   ov5642: camera@3c {
+   compatible = "ovti,ov5642";
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ov5642>;
+   clocks = <&clks IMX6QDL_CLK_CKO>;
+   clock-names = "xclk";
+   reg = <0x3c>;
+   DOVDD-supply = <&vgen4_reg>; /* 1.8v */
+   AVDD-supply = <&vgen3_reg>;  /* 2.8v, rev C board is VGEN3
+   rev B board is VGEN5 */
+   DVDD-supply = <&vgen2_reg>;  /* 1.5v*/
+   powerdown-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
+   reset-gpios = <&gpio1 17 GPIO_ACTIVE_LOW>;
+   status = "disabled";
+
+   port {
+   ov5642_to_ipu1_csi0_mux: endpoint {
+   remote-endpoint = 
<&ipu1_csi0_mux_from_parallel_sensor>;
+   bus-width = <8>;
+   hsync-active = <1>;
+   vsync-active = <1>;
+   };
+   };
+   };
 };
 
 &i2c2 {
@@ -222,6 +278,32 @@
pinctrl-0 = <&pinctrl_i2c2>;
status = "okay";
 
+   ov5640: camera@3c {
+   compatible = "ovti,ov5640";
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ov5640>;
+   reg = <0x3c>;
+   clocks = <&clks IMX6QDL_CLK_CKO>;
+   clock-names = "xclk";
+   DOVDD-supply = <&vgen4_reg>; /* 1.8v */
+   AVDD-supply = <&vgen3_reg>;  /* 2.8v, rev C board is VGEN3
+   rev B board is VGEN5 */
+   DVDD-supply = <&vgen2_reg>;  /* 1.5v*/
+   powerdown-gpios = <&gpio1 19 GPIO_ACTIVE_HIGH>;
+   reset-gpios = <&gpio1 20 GPIO_ACTIVE_LOW>;
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   ov5640_to_mipi_csi2: endpoint {
+   remote-endpoint = <&mipi_csi2_in>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+   };
+   };
+   };
+
pmic: pfuze100@08 {
compatib

[PATCH v5 00/39] i.MX Media Driver

2017-03-09 Thread Steve Longerbeam
In version 5:

- ov5640: renamed "pwdn-gpios" to "powerdown-gpios"

- ov5640: add mutex lock around the subdev op entry points.

- ov5640: don't attempt to program the new mode in ov5640_set_fmt().
  Instead set a new flag, pending_mode_change, and program the new
  mode at s_stream() if flag is set.

- ov5640: implement [gs]_frame_interval. As part of that, create
  ov5640_try_frame_interval(), which is used by both [gs]_frame_interval
  and [gs]_parm.

- ov5640: don't attempt to set controls in ov5640_s_ctrl(), or at
  mode change, do it instead after first power-up.

- video-multiplexer: include link_validate in media_entity_operations.

- video-multiplexer: enforce that output pad frame interval must match
  input pad frame interval in vidsw_s_frame_interval().

- video-multiplexer: initialize frame interval to a default 30 fps.

- mipi csi-2: renamed "cfg" clock name property to "ref". This is the
  27 MHz mipi csi-2 PLL reference clock.

- mipi csi-2: create a hsfreq_map[] table based on
  https://community.nxp.com/docs/DOC-94312. Use it to select
  a hsfreqrange_sel value when programming the D-PHY, based on
  a max Mbps per lane. This is computed from the source subdev
  via V4L2_CID_LINK_FREQ control, and if the subdev doesn't implement
  that control, use a default hard-coded max Mbps per lane.

- added required ports property description to imx-media binding doc.

- removed event V4L2_EVENT_FRAME_TIMEOUT. On a frame timeout, which
  is always unrecoverable, call vb2_queue_error() instead.

- export the remaining custom events to V4L2_EVENT_FRAME_INTERVAL_ERROR
  and V4L2_EVENT_NEW_FRAME_BEFORE_EOF.

- vdic: use V4L2_CID_DEINTERLACING_MODE for motion compensation control
  instead of a custom control.

- add v4l2_subdev_link_validate_frame_interval(). Call this in the
  link_validate imx-media subdev callbacks and video-multiplexer.

- fix subdev event registration: implementation of subscribe_event()
  and unsubscribe_event() subdev ops were missing.

- all calls from the pipeline to the sensor subdev have been removed.
  Only the CSI subdev still refers to a sensor, and only to retrieve
  its media bus config, which is necessary to setup the CSI interface.

- add mutex locks around the imx-media subdev op entry points.

- completed the propagation of all pad format parameters from sink
  pads to source pads within every imx-media subdev.

- implement [gs]_frame_interval in all the imx-media subdevs.

- imx-ic-prpencvf: there isn't necessarily a CSI subdev in the pipeline
  in the future, so make sure this is optional when calling the CSI's
  FIM.

- the source pads that attach to capture device nodes now require the
  IPU internal pixel codes. The capture device translates these to
  v4l2 fourcc memory formats.

- fix control inheritance to the capture device. When the pipeline
  was modified, the inherited controls were not being refreshed.
  v4l2_pipeline_inherit_controls() is now called only in imx-media
  link_notify() callback when a pipelink link is disabled or modified.
  imx_media_find_pipeline_video_device() is created to locate the
  capture device in the pipeline.

- fix a possible race when propagating formats to the capture device.
  The subdevs and capture device use different mutex locks when setting
  formats. imx_media_capture_device_set_format() is created which acquires
  the capture device mutex when updating the capture device format.

- verify all subdevs were bound in the async completion callback.
 

Philipp Zabel (7):
  [media] dt-bindings: Add bindings for video-multiplexer device
  ARM: dts: imx6qdl: Add mipi_ipu1/2 multiplexers, mipi_csi, and their
connections
  add mux and video interface bridge entity functions
  platform: add video-multiplexer subdevice driver
  media: imx: csi: fix crop rectangle changes in set_fmt
  media: imx: csi: add frame skipping support
  media: imx: csi: fix crop rectangle reset in sink set_fmt

Russell King (4):
  media: imx: add support for bayer formats
  media: imx: csi: add support for bayer formats
  media: imx: mipi-csi2: enable setting and getting of frame rates
  media: imx: csi/fim: add support for frame intervals

Steve Longerbeam (28):
  [media] dt-bindings: Add bindings for i.MX media driver
  [media] dt/bindings: Add bindings for OV5640
  ARM: dts: imx6qdl: Add compatible, clocks, irqs to MIPI CSI-2 node
  ARM: dts: imx6qdl: add capture-subsystem device
  ARM: dts: imx6qdl-sabrelite: remove erratum ERR006687 workaround
  ARM: dts: imx6-sabrelite: add OV5642 and OV5640 camera sensors
  ARM: dts: imx6-sabresd: add OV5642 and OV5640 camera sensors
  ARM: dts: imx6-sabreauto: create i2cmux for i2c3
  ARM: dts: imx6-sabreauto: add reset-gpios property for max7310_b
  ARM: dts: imx6-sabreauto: add pinctrl for gpt input capture
  ARM: dts: imx6-sabreauto: add the ADV7180 video decoder
  [media] v4l2: add a frame interval error event
  [media] v4l2: add a new-frame before end-of-frame event
  [media] v4l2-mc: add a function to i

[PATCH v5 01/39] [media] dt-bindings: Add bindings for video-multiplexer device

2017-03-09 Thread Steve Longerbeam
From: Philipp Zabel 

Add bindings documentation for the video multiplexer device.

Signed-off-by: Sascha Hauer 
Signed-off-by: Philipp Zabel 
Signed-off-by: Steve Longerbeam 
---
 .../bindings/media/video-multiplexer.txt   | 59 ++
 1 file changed, 59 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/video-multiplexer.txt

diff --git a/Documentation/devicetree/bindings/media/video-multiplexer.txt 
b/Documentation/devicetree/bindings/media/video-multiplexer.txt
new file mode 100644
index 000..9d133d9
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/video-multiplexer.txt
@@ -0,0 +1,59 @@
+Video Multiplexer
+=
+
+Video multiplexers allow to select between multiple input ports. Video received
+on the active input port is passed through to the output port. Muxes described
+by this binding may be controlled by a syscon register bitfield or by a GPIO.
+
+Required properties:
+- compatible : should be "video-multiplexer"
+- reg: should be register base of the register containing the control bitfield
+- bit-mask: bitmask of the control bitfield in the control register
+- bit-shift: bit offset of the control bitfield in the control register
+- gpios: alternatively to reg, bit-mask, and bit-shift, a single GPIO phandle
+  may be given to switch between two inputs
+- #address-cells: should be <1>
+- #size-cells: should be <0>
+- port@*: at least three port nodes containing endpoints connecting to the
+  source and sink devices according to of_graph bindings. The last port is
+  the output port, all others are inputs.
+
+Example:
+
+syscon {
+   compatible = "syscon", "simple-mfd";
+
+   mux {
+   compatible = "video-multiplexer";
+   /* Single bit (1 << 19) in syscon register 0x04: */
+   reg = <0x04>;
+   bit-mask = <1>;
+   bit-shift = <19>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+
+   mux_in0: endpoint {
+   remote-endpoint = <&video_source0_out>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   mux_in1: endpoint {
+   remote-endpoint = <&video_source1_out>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   mux_out: endpoint {
+   remote-endpoint = <&capture_interface_in>;
+   };
+   };
+   };
+};
-- 
2.7.4



[PATCH] irqdomain: handle the per-CPU irq trigger type settings

2017-03-09 Thread gengdongjiu
when devices parse and map an per-cpu interrupt into linux virq space
using irq_of_parse_and_map API, it will always be failed if needs to set
the specified irq trigger type, because irq_set_irq_type is only for 1-N
mode interrupt source, not for per-cpu interrupt source. so handle per-cpu
IRQs for this failure.

Signed-off-by: Dongjiu Geng 
   Zhanghai bin 

diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 9fd618d..8116cf2 100755
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -542,8 +542,16 @@ unsigned int irq_create_of_mapping(struct of_phandle_args 
*irq_data)

/* Set type if specified and different than the current one */
if (type != IRQ_TYPE_NONE &&
-   type != irq_get_trigger_type(virq))
-   irq_set_irq_type(virq, type);
+   type != irq_get_trigger_type(virq)) {
+   int ret = 0;
+   struct irq_data *irq_data = irq_get_irq_data(virq);
+
+   ret = irq_set_irq_type(virq, type);
+
+/* Handle per-cpu IRQ: just save type in irq_data */
+   if (-EINVAL == ret && irq_data)
+   irqd_set_trigger_type(irq_data, type);
+   }
return virq;
 }
 EXPORT_SYMBOL_GPL(irq_create_of_mapping);



Re: [PATCH v2 1/2] doc: bindings: Add bindings documentation for mtd nvmem

2017-03-09 Thread Marek Vasut
On 03/10/2017 05:06 AM, Moritz Fischer wrote:
> On Thu, Mar 9, 2017 at 7:17 PM, Marek Vasut  wrote:
>> On 03/07/2017 09:26 AM, Alban wrote:
>>> Config data for drivers, like MAC addresses, is often stored in MTD.
>>> Add a binding that define how such data storage can be represented in
>>> device tree.
>>>
>>> Signed-off-by: Alban 
>>> ---
>>> Changelog:
>>> v2: * Added a "Required properties" section with the nvmem-provider
>>>   property
>>> ---
>>>  .../devicetree/bindings/nvmem/mtd-nvmem.txt| 33 
>>> ++
>>>  1 file changed, 33 insertions(+)
>>>  create mode 100644 Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
>>>
>>> diff --git a/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt 
>>> b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
>>> new file mode 100644
>>> index 000..8ed25e6
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
>>> @@ -0,0 +1,33 @@
>>> += NVMEM in MTD =
>>> +
>>> +Config data for drivers, like MAC addresses, is often stored in MTD.
>>> +This binding define how such data storage can be represented in device 
>>> tree.
>>> +
>>> +An MTD can be defined as an NVMEM provider by adding the `nvmem-provider`
>>> +property to their node. Data cells can then be defined as child nodes
>>> +of the partition as defined in nvmem.txt.
>>
>> Why don't we just read the data from MTD and be done with it ? What's
>> the benefit of complicating things by using nvmem ?
> 
> Well because usually stuff like MAC addresses etc are stored in eeproms.

But eeproms are already supported, see drivers/misc/ .

> This gives a nice abstraction with making them both look like nvmem (that was 
> my
> reasoning back then when I submitted a patch to support the OTP part in a
> SPI NOR part.

Hm, I am confused here, we're mixing SPI NOR, EEPROMs and OTP devices here.

-- 
Best regards,
Marek Vasut


Re: [PATCH v2] blk: improve order of bio handling in generic_make_request()

2017-03-09 Thread Jens Axboe
On 03/09/2017 09:38 PM, Jens Axboe wrote:
> On 03/09/2017 09:32 PM, NeilBrown wrote:
>>
>> I started looking further at the improvements we can make once
>> generic_make_request is fixed, and realised that I had missed an
>> important detail in this patch.
>> Several places test current->bio_list, and two actually edit the list.
>> With this change, that cannot see the whole lists, so it could cause a
>> regression.
>>
>> So I've revised the patch to make sure that the entire list of queued
>> bios remains visible, and change the relevant code to look at both
>> the new list and the old list.
>>
>> Following that there are some patches which make the rescuer thread
>> optional, and then starts removing it from some easy-to-fix places.
> 
> Neil, note that the v2 patch is already in Linus tree as of earlier
> today. You need to rebase the series, and if we need fixups on
> top of v2, then that should be done separately and with increased
> urgency.

Additionally, at least the first patch appears to be badly mangled.
The formatting is screwed up.

-- 
Jens Axboe



[PATCH 20/41] drm/bridge: analogix_dp: Set PD_INC_BG first when powering up edp phy

2017-03-09 Thread Sean Paul
From: zain wang 

Following the correct power up sequence:
dp_pd=ff => dp_pd=7f => wait 10us => dp_pd=00

Cc: Stéphane Marchesin 
Signed-off-by: zain wang 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c | 10 --
 drivers/gpu/drm/bridge/analogix/analogix_dp_reg.h |  3 +++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c 
b/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c
index b47c5af43560..bb72f8b0e603 100644
--- a/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c
+++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c
@@ -321,10 +321,16 @@ void analogix_dp_set_analog_power_down(struct 
analogix_dp_device *dp,
break;
case POWER_ALL:
if (enable) {
-   reg = DP_PHY_PD | AUX_PD | CH3_PD | CH2_PD |
-   CH1_PD | CH0_PD;
+   reg = DP_ALL_PD;
writel(reg, dp->reg_base + phy_pd_addr);
} else {
+   reg = DP_ALL_PD;
+   writel(reg, dp->reg_base + phy_pd_addr);
+   usleep_range(10, 15);
+   reg &= ~DP_INC_BG;
+   writel(reg, dp->reg_base + phy_pd_addr);
+   usleep_range(10, 15);
+
writel(0x00, dp->reg_base + phy_pd_addr);
}
break;
diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.h 
b/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.h
index 40200c652533..9602668669f4 100644
--- a/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.h
+++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.h
@@ -342,12 +342,15 @@
 #define DP_PLL_REF_BIT_1_2500V (0x7 << 0)
 
 /* ANALOGIX_DP_PHY_PD */
+#define DP_INC_BG  (0x1 << 7)
+#define DP_EXP_BG  (0x1 << 6)
 #define DP_PHY_PD  (0x1 << 5)
 #define AUX_PD (0x1 << 4)
 #define CH3_PD (0x1 << 3)
 #define CH2_PD (0x1 << 2)
 #define CH1_PD (0x1 << 1)
 #define CH0_PD (0x1 << 0)
+#define DP_ALL_PD  (0xff)
 
 /* ANALOGIX_DP_PHY_TEST */
 #define MACRO_RST  (0x1 << 5)
-- 
2.12.0.246.ga2ecc84866-goog



Re: [PATCH v2] blk: improve order of bio handling in generic_make_request()

2017-03-09 Thread Jens Axboe
On 03/09/2017 09:32 PM, NeilBrown wrote:
> 
> I started looking further at the improvements we can make once
> generic_make_request is fixed, and realised that I had missed an
> important detail in this patch.
> Several places test current->bio_list, and two actually edit the list.
> With this change, that cannot see the whole lists, so it could cause a
> regression.
> 
> So I've revised the patch to make sure that the entire list of queued
> bios remains visible, and change the relevant code to look at both
> the new list and the old list.
> 
> Following that there are some patches which make the rescuer thread
> optional, and then starts removing it from some easy-to-fix places.

Neil, note that the v2 patch is already in Linus tree as of earlier
today. You need to rebase the series, and if we need fixups on
top of v2, then that should be done separately and with increased
urgency.

-- 
Jens Axboe



[PATCH] mm/sparse: refine usemap_size() a little

2017-03-09 Thread Wei Yang
Current implementation calculates usemap_size in two steps:
* calculate number of bytes to cover these bits
* calculate number of "unsigned long" to cover these bytes

It would be more clear by:
* calculate number of "unsigned long" to cover these bits
* multiple it with sizeof(unsigned long)

This patch refine usemap_size() a little to make it more easy to
understand.

Signed-off-by: Wei Yang 
---
 mm/sparse.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/mm/sparse.c b/mm/sparse.c
index a0792526adfa..faa36ef9f9bd 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -249,10 +249,7 @@ static int __meminit sparse_init_one_section(struct 
mem_section *ms,
 
 unsigned long usemap_size(void)
 {
-   unsigned long size_bytes;
-   size_bytes = roundup(SECTION_BLOCKFLAGS_BITS, 8) / 8;
-   size_bytes = roundup(size_bytes, sizeof(unsigned long));
-   return size_bytes;
+   return BITS_TO_LONGS(SECTION_BLOCKFLAGS_BITS) * sizeof(unsigned long);
 }
 
 #ifdef CONFIG_MEMORY_HOTPLUG
-- 
2.11.0



[PATCH 5/5] block_dev: make blkdev_dio_pool a non-rescuing bioset

2017-03-09 Thread NeilBrown

Allocations from blkdev_dio_pool are never made under
generic_make_request, so this bioset does not need a rescuer thread.

Signed-off-by: NeilBrown 
---
 fs/block_dev.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index c0ca5f0d0369..2eca00ec4370 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -436,7 +436,7 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
 
 static __init int blkdev_init(void)
 {
-   blkdev_dio_pool = bioset_create_rescued(4, offsetof(struct blkdev_dio, 
bio));
+   blkdev_dio_pool = bioset_create(4, offsetof(struct blkdev_dio, bio));
if (!blkdev_dio_pool)
return -ENOMEM;
return 0;




signature.asc
Description: PGP signature


[PATCH 4/5] blk: use non-rescuing bioset for q->bio_split.

2017-03-09 Thread NeilBrown

A rescuing bioset is only useful if there might be bios from
that same bioset on the bio_list_on_stack queue at a time
when bio_alloc_bioset() is called.  This never applies to
q->bio_split.

Allocations from q->bio_split are only ever made from
blk_queue_split() which is only ever called early in each of
various make_request_fn()s.  The original bio (call this A)
is then passed to generic_make_request() and is placed on
the bio_list_on_stack queue, and the bio that was allocated
from q->bio_split (B) is processed.

The processing of this may cause other bios to be passed to
generic_make_request() or may even cause the bio B itself to
be passed, possible after some prefix has been split off
(using some other bioset).

generic_make_request() now guarantees that all of these bios
(B and dependants) will be fully processed before the tail
of the original bio A gets handled.  None of these early bios
can possible trigger an allocation from the original
q->bio_split as they are either too small to require
splitting or (more likely) are destined for a different queue.

The next time that the original q->bio_split might be used
by this thread is when A is processed again, as it might
still be too big to handle directly.  By this time there
cannot be and other bios allocated fro q->bio_split in the
generic_make_request() queue.  So no rescuing will ever be
needed.

Signed-off-by: NeilBrown 
---
 block/blk-core.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index c3992d17dc2c..375006c94c15 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -714,7 +714,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, 
int node_id)
if (q->id < 0)
goto fail_q;
 
-   q->bio_split = bioset_create_rescued(BIO_POOL_SIZE, 0);
+   q->bio_split = bioset_create(BIO_POOL_SIZE, 0);
if (!q->bio_split)
goto fail_id;
 




signature.asc
Description: PGP signature


[PATCH 3/5] blk: make the bioset rescue_workqueue optional.

2017-03-09 Thread NeilBrown

This patch converts bioset_create() and bioset_create_nobvec()
to not create a workqueue so alloctions will never trigger
punt_bios_to_rescuer().
It also introduces bioset_create_rescued() and bioset_create_nobvec_rescued()
which preserve the old behaviour.

*All* callers of bioset_create() and bioset_create_nobvec() are
converted to the _rescued() version, so that not change in behaviour
is experienced.

It is hoped that most, if not all, bioset can end up being the
non-rescued version.

Signed-off-by: NeilBrown 
---
 block/bio.c |   30 +-
 block/blk-core.c|2 +-
 drivers/block/drbd/drbd_main.c  |2 +-
 drivers/md/bcache/super.c   |4 ++--
 drivers/md/dm-crypt.c   |2 +-
 drivers/md/dm-io.c  |2 +-
 drivers/md/dm.c |5 +++--
 drivers/md/md.c |2 +-
 drivers/md/raid5-cache.c|2 +-
 drivers/target/target_core_iblock.c |2 +-
 fs/block_dev.c  |2 +-
 fs/btrfs/extent_io.c|4 ++--
 fs/xfs/xfs_super.c  |2 +-
 include/linux/bio.h |2 ++
 14 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index 84ae39f06f81..06587f1119f5 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -362,6 +362,8 @@ static void punt_bios_to_rescuer(struct bio_set *bs)
struct bio_list punt, nopunt;
struct bio *bio;
 
+   if (!WARN_ON_ONCE(!bs->rescue_workqueue))
+   return;
/*
 * In order to guarantee forward progress we must punt only bios that
 * were allocated from this bio_set; otherwise, if there was a bio on
@@ -471,7 +473,8 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, 
struct bio_set *bs)
 
if (current->bio_list &&
(!bio_list_empty(¤t->bio_list[0]) ||
-!bio_list_empty(¤t->bio_list[1])))
+!bio_list_empty(¤t->bio_list[1])) &&
+   bs->rescue_workqueue)
gfp_mask &= ~__GFP_DIRECT_RECLAIM;
 
p = mempool_alloc(bs->bio_pool, gfp_mask);
@@ -1940,7 +1943,8 @@ EXPORT_SYMBOL(bioset_free);
 
 static struct bio_set *__bioset_create(unsigned int pool_size,
   unsigned int front_pad,
-  bool create_bvec_pool)
+  bool create_bvec_pool,
+  bool create_rescue_workqueue)
 {
unsigned int back_pad = BIO_INLINE_VECS * sizeof(struct bio_vec);
struct bio_set *bs;
@@ -1971,6 +1975,9 @@ static struct bio_set *__bioset_create(unsigned int 
pool_size,
goto bad;
}
 
+   if (!create_rescue_workqueue)
+   return bs;
+
bs->rescue_workqueue = alloc_workqueue("bioset", WQ_MEM_RECLAIM, 0);
if (!bs->rescue_workqueue)
goto bad;
@@ -1996,10 +2003,16 @@ static struct bio_set *__bioset_create(unsigned int 
pool_size,
  */
 struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad)
 {
-   return __bioset_create(pool_size, front_pad, true);
+   return __bioset_create(pool_size, front_pad, true, false);
 }
 EXPORT_SYMBOL(bioset_create);
 
+struct bio_set *bioset_create_rescued(unsigned int pool_size, unsigned int 
front_pad)
+{
+   return __bioset_create(pool_size, front_pad, true, true);
+}
+EXPORT_SYMBOL(bioset_create_rescued);
+
 /**
  * bioset_create_nobvec  - Create a bio_set without bio_vec mempool
  * @pool_size: Number of bio to cache in the mempool
@@ -2011,10 +2024,17 @@ EXPORT_SYMBOL(bioset_create);
  */
 struct bio_set *bioset_create_nobvec(unsigned int pool_size, unsigned int 
front_pad)
 {
-   return __bioset_create(pool_size, front_pad, false);
+   return __bioset_create(pool_size, front_pad, false, false);
 }
 EXPORT_SYMBOL(bioset_create_nobvec);
 
+struct bio_set *bioset_create_nobvec_rescued(unsigned int pool_size,
+unsigned int front_pad)
+{
+   return __bioset_create(pool_size, front_pad, false, true);
+}
+EXPORT_SYMBOL(bioset_create_nobvec_rescued);
+
 #ifdef CONFIG_BLK_CGROUP
 
 /**
@@ -2129,7 +2149,7 @@ static int __init init_bio(void)
bio_integrity_init();
biovec_init_slabs();
 
-   fs_bio_set = bioset_create(BIO_POOL_SIZE, 0);
+   fs_bio_set = bioset_create_rescued(BIO_POOL_SIZE, 0);
if (!fs_bio_set)
panic("bio: can't allocate bios\n");
 
diff --git a/block/blk-core.c b/block/blk-core.c
index 375006c94c15..c3992d17dc2c 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -714,7 +714,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, 
int node_id)
if (q->id < 0)
goto fail_q;
 
-   q->bio_split = bioset_create(BIO_POOL_SIZE, 0);
+   q->

[PATCH 2/5] blk: remove bio_set arg from blk_queue_split()

2017-03-09 Thread NeilBrown

blk_queue_split() is always called with the last arg being q->bio_split,
where 'q' is the first arg.

Also blk_queue_split() sometimes uses the passed-in 'bs' and sometimes uses
q->bio_split.

This is inconsistent and unnecessary.  Remove the last arg and always use
q->bio_split inside blk_queue_split()

Signed-off-by: NeilBrown 
---
 block/blk-core.c  |2 +-
 block/blk-merge.c |7 +++
 block/blk-mq.c|4 ++--
 drivers/block/drbd/drbd_req.c |2 +-
 drivers/block/pktcdvd.c   |2 +-
 drivers/block/ps3vram.c   |2 +-
 drivers/block/rsxx/dev.c  |2 +-
 drivers/block/umem.c  |2 +-
 drivers/block/zram/zram_drv.c |2 +-
 drivers/lightnvm/rrpc.c   |2 +-
 drivers/md/md.c   |2 +-
 drivers/s390/block/dcssblk.c  |2 +-
 drivers/s390/block/xpram.c|2 +-
 include/linux/blkdev.h|3 +--
 14 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index bd2cb4ba674e..375006c94c15 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1637,7 +1637,7 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, 
struct bio *bio)
 */
blk_queue_bounce(q, &bio);
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
if (bio_integrity_enabled(bio) && bio_integrity_prep(bio)) {
bio->bi_error = -EIO;
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 2afa262425d1..ce8838aff7f7 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -188,8 +188,7 @@ static struct bio *blk_bio_segment_split(struct 
request_queue *q,
return do_split ? new : NULL;
 }
 
-void blk_queue_split(struct request_queue *q, struct bio **bio,
-struct bio_set *bs)
+void blk_queue_split(struct request_queue *q, struct bio **bio)
 {
struct bio *split, *res;
unsigned nsegs;
@@ -197,14 +196,14 @@ void blk_queue_split(struct request_queue *q, struct bio 
**bio,
switch (bio_op(*bio)) {
case REQ_OP_DISCARD:
case REQ_OP_SECURE_ERASE:
-   split = blk_bio_discard_split(q, *bio, bs, &nsegs);
+   split = blk_bio_discard_split(q, *bio, q->bio_split, &nsegs);
break;
case REQ_OP_WRITE_ZEROES:
split = NULL;
nsegs = (*bio)->bi_phys_segments;
break;
case REQ_OP_WRITE_SAME:
-   split = blk_bio_write_same_split(q, *bio, bs, &nsegs);
+   split = blk_bio_write_same_split(q, *bio, q->bio_split, &nsegs);
break;
default:
split = blk_bio_segment_split(q, *bio, q->bio_split, &nsegs);
diff --git a/block/blk-mq.c b/block/blk-mq.c
index b2fd175e84d7..ef7b289e873c 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1502,7 +1502,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue 
*q, struct bio *bio)
return BLK_QC_T_NONE;
}
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
if (!is_flush_fua && !blk_queue_nomerges(q) &&
blk_attempt_plug_merge(q, bio, &request_count, &same_queue_rq))
@@ -1624,7 +1624,7 @@ static blk_qc_t blk_sq_make_request(struct request_queue 
*q, struct bio *bio)
return BLK_QC_T_NONE;
}
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
if (!is_flush_fua && !blk_queue_nomerges(q)) {
if (blk_attempt_plug_merge(q, bio, &request_count, NULL))
diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c
index 652114ae1a8a..f6ed6f7f5ab2 100644
--- a/drivers/block/drbd/drbd_req.c
+++ b/drivers/block/drbd/drbd_req.c
@@ -1554,7 +1554,7 @@ blk_qc_t drbd_make_request(struct request_queue *q, 
struct bio *bio)
struct drbd_device *device = (struct drbd_device *) q->queuedata;
unsigned long start_jif;
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
start_jif = jiffies;
 
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 66d846ba85a9..98394d034c29 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -2414,7 +2414,7 @@ static blk_qc_t pkt_make_request(struct request_queue *q, 
struct bio *bio)
 
blk_queue_bounce(q, &bio);
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
pd = q->queuedata;
if (!pd) {
diff --git a/drivers/block/ps3vram.c b/drivers/block/ps3vram.c
index 456b4fe21559..48072c0c1010 100644
--- a/drivers/block/ps3vram.c
+++ b/drivers/block/ps3vram.c
@@ -606,7 +606,7 @@ static blk_qc_t ps3vram_make_request(struct request_queue 
*q, struct bio *bio)
 
dev_dbg(&dev->core, "%s\n", __func__);
 
-   blk_queue_split(q, &bio, q->bio_split);
+   blk_queue_split(q, &bio);
 
spin_lock_irq(&priv->lock);
busy = !bio_list_empty(&priv->list

[PATCH 1/5 v3] blk: improve order of bio handling in generic_make_request()

2017-03-09 Thread NeilBrown

To avoid recursion on the kernel stack when stacked block devices
are in use, generic_make_request() will, when called recursively,
queue new requests for later handling.  They will be handled when the
make_request_fn for the current bio completes.

If any bios are submitted by a make_request_fn, these will ultimately
be handled seqeuntially.  If the handling of one of those generates
further requests, they will be added to the end of the queue.

This strict first-in-first-out behaviour can lead to deadlocks in
various ways, normally because a request might need to wait for a
previous request to the same device to complete.  This can happen when
they share a mempool, and can happen due to interdependencies
particular to the device.  Both md and dm have examples where this happens.

These deadlocks can be erradicated by more selective ordering of bios.
Specifically by handling them in depth-first order.  That is: when the
handling of one bio generates one or more further bios, they are
handled immediately after the parent, before any siblings of the
parent.  That way, when generic_make_request() calls make_request_fn
for some particular device, we can be certain that all previously
submited requests for that device have been completely handled and are
not waiting for anything in the queue of requests maintained in
generic_make_request().

An easy way to achieve this would be to use a last-in-first-out stack
instead of a queue.  However this will change the order of consecutive
bios submitted by a make_request_fn, which could have unexpected consequences.
Instead we take a slightly more complex approach.
A fresh queue is created for each call to a make_request_fn.  After it 
completes,
any bios for a different device are placed on the front of the main queue, 
followed
by any bios for the same device, followed by all bios that were already on
the queue before the make_request_fn was called.
This provides the depth-first approach without reordering bios on the same 
level.

This, by itself, it not enough to remove all deadlocks.  It just makes
it possible for drivers to take the extra step required themselves.

To avoid deadlocks, drivers must never risk waiting for a request
after submitting one to generic_make_request.  This includes never
allocing from a mempool twice in the one call to a make_request_fn.

A common pattern in drivers is to call bio_split() in a loop, handling
the first part and then looping around to possibly split the next part.
Instead, a driver that finds it needs to split a bio should queue
(with generic_make_request) the second part, handle the first part,
and then return.  The new code in generic_make_request will ensure the
requests to underlying bios are processed first, then the second bio
that was split off.  If it splits again, the same process happens.  In
each case one bio will be completely handled before the next one is attempted.

With this is place, it should be possible to disable the
punt_bios_to_recover() recovery thread for many block devices, and
eventually it may be possible to remove it completely.

Note that as some drivers look inside the bio_list, sometimes to punt
some bios to rescuer threads, we need to make both the pendind list and the
new list visible.  So current->bio_list is now an array of 2 lists,
and relevant code examines both of them.

Ref: http://www.spinics.net/lists/raid/msg54680.html
Tested-by: Jinpu Wang 
Inspired-by: Lars Ellenberg 
Signed-off-by: NeilBrown 
---
 block/bio.c |   11 ---
 block/blk-core.c|   40 
 drivers/md/dm.c |   29 -
 drivers/md/raid10.c |3 ++-
 4 files changed, 58 insertions(+), 25 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index 5eec5e08417f..84ae39f06f81 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -376,10 +376,13 @@ static void punt_bios_to_rescuer(struct bio_set *bs)
bio_list_init(&punt);
bio_list_init(&nopunt);
 
-   while ((bio = bio_list_pop(current->bio_list)))
+   while ((bio = bio_list_pop(¤t->bio_list[0])))
bio_list_add(bio->bi_pool == bs ? &punt : &nopunt, bio);
+   current->bio_list[0] = nopunt;
 
-   *current->bio_list = nopunt;
+   while ((bio = bio_list_pop(¤t->bio_list[1])))
+   bio_list_add(bio->bi_pool == bs ? &punt : &nopunt, bio);
+   current->bio_list[1] = nopunt;
 
spin_lock(&bs->rescue_lock);
bio_list_merge(&bs->rescue_list, &punt);
@@ -466,7 +469,9 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, 
struct bio_set *bs)
 * we retry with the original gfp_flags.
 */
 
-   if (current->bio_list && !bio_list_empty(current->bio_list))
+   if (current->bio_list &&
+   (!bio_list_empty(¤t->bio_list[0]) ||
+!bio_list_empty(¤t->bio_list[1])))
gfp_mask &= ~__GFP_DIRECT_RECLAIM;
 
p 

Re: [PATCH v2] blk: improve order of bio handling in generic_make_request()

2017-03-09 Thread NeilBrown

I started looking further at the improvements we can make once
generic_make_request is fixed, and realised that I had missed an
important detail in this patch.
Several places test current->bio_list, and two actually edit the list.
With this change, that cannot see the whole lists, so it could cause a
regression.

So I've revised the patch to make sure that the entire list of queued
bios remains visible, and change the relevant code to look at both
the new list and the old list.

Following that there are some patches which make the rescuer thread
optional, and then starts removing it from some easy-to-fix places.

The series summary is below.

NeilBrown


NeilBrown (5):
  blk: improve order of bio handling in generic_make_request()
  blk: remove bio_set arg from blk_queue_split()
  blk: make the bioset rescue_workqueue optional.
  blk: use non-rescuing bioset for q->bio_split.
  block_dev: make blkdev_dio_pool a non-rescuing bioset


 block/bio.c |   39 +++--
 block/blk-core.c|   42 ---
 block/blk-merge.c   |7 +++---
 block/blk-mq.c  |4 ++-
 drivers/block/drbd/drbd_main.c  |2 +-
 drivers/block/drbd/drbd_req.c   |2 +-
 drivers/block/pktcdvd.c |2 +-
 drivers/block/ps3vram.c |2 +-
 drivers/block/rsxx/dev.c|2 +-
 drivers/block/umem.c|2 +-
 drivers/block/zram/zram_drv.c   |2 +-
 drivers/lightnvm/rrpc.c |2 +-
 drivers/md/bcache/super.c   |4 ++-
 drivers/md/dm-crypt.c   |2 +-
 drivers/md/dm-io.c  |2 +-
 drivers/md/dm.c |   32 +++
 drivers/md/md.c |4 ++-
 drivers/md/raid10.c |3 ++-
 drivers/md/raid5-cache.c|2 +-
 drivers/s390/block/dcssblk.c|2 +-
 drivers/s390/block/xpram.c  |2 +-
 drivers/target/target_core_iblock.c |2 +-
 fs/btrfs/extent_io.c|4 ++-
 fs/xfs/xfs_super.c  |2 +-
 include/linux/bio.h |2 ++
 include/linux/blkdev.h  |3 +--
 26 files changed, 114 insertions(+), 60 deletions(-)


signature.asc
Description: PGP signature


Re: [PATCH] dma: xilinx: Make Xilinx VDMA support ARC

2017-03-09 Thread Vinod Koul
On Thu, Mar 09, 2017 at 09:55:59AM +, Ramiro Oliveira wrote:
> Hi Mike
> 
> On 3/9/2017 7:37 AM, Mike Looijmans wrote:
> > On 06-03-17 13:27, Ramiro Oliveira wrote:
> >> Add option in Kconfig to use Xilinx VDMA in ARC processors.
> >>
> >> Signed-off-by: Ramiro Oliveira 
> >> ---
> >>  drivers/dma/Kconfig | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
> >> index 263495d0adbd..b6b6c0581ad7 100644
> >> --- a/drivers/dma/Kconfig
> >> +++ b/drivers/dma/Kconfig
> >> @@ -546,7 +546,7 @@ config XGENE_DMA
> >>
> >>  config XILINX_DMA
> >>  tristate "Xilinx AXI DMAS Engine"
> >> -depends on (ARCH_ZYNQ || MICROBLAZE || ARM64)
> >> +depends on (ARCH_ZYNQ || MICROBLAZE || ARM64|| ARC)
> > 
> > One can put a Xilinx FPGA on a PCIe card, instantiate a PCIe-AXI bridge and 
> > then
> > use it on any platform that supports PCIe.
> > 
> > I've had to remove this line in order to be able to use the engine on an x86
> > desktop.
> > 
> > How about plainly removing this "depends on" line and be done with it, 
> > instead
> > of adding platforms one by one?
> > 
> > 
> 
> I agree with you. From my point of view it would be better to remove this line
> entirely. I'm just not sure if everyone agrees.

if it works on others, compiles fine then there should not be an issue to
remove.

Feel free to send the patch.

-- 
~Vinod


[RFC] mm/compaction: ignore block suitable after check large free page

2017-03-09 Thread Yisheng Xie
If the migrate target is a large free page and we ignore suitable,
it may not good for defrag. So move the ignore block suitable after
check large free page.

Signed-off-by: Yisheng Xie 
---
 mm/compaction.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index 0fdfde0..4bf2a5d 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -991,9 +991,6 @@ static bool too_many_isolated(struct zone *zone)
 static bool suitable_migration_target(struct compact_control *cc,
struct page *page)
 {
-   if (cc->ignore_block_suitable)
-   return true;
-
/* If the page is a large free page, then disallow migration */
if (PageBuddy(page)) {
/*
@@ -1005,6 +1002,9 @@ static bool suitable_migration_target(struct 
compact_control *cc,
return false;
}
 
+   if (cc->ignore_block_suitable)
+   return true;
+
/* If the block is MIGRATE_MOVABLE or MIGRATE_CMA, allow migration */
if (migrate_async_suitable(get_pageblock_migratetype(page)))
return true;
-- 
1.7.12.4



Re: [PATCH net, v1] dccp/tcp: fix routing redirect race

2017-03-09 Thread Eric Dumazet
On Fri, 2017-03-10 at 14:31 +1100, Jon Maxwell wrote:
> As Eric Dumazet pointed out this also needs to be fixed in IPv6.
> v1: Contains the IPv6 patch as well.

> Fixes: ceb3320610d6 ("ipv4: Kill routes during PMTU/redirect updates.")
> Cc: Eric Garver 
> Cc: Hannes Sowa 
> Signed-off-by: Jon Maxwell 
> ---
>  net/dccp/ipv4.c | 3 ++-
>  net/ipv4/tcp_ipv4.c | 3 ++-
>  net/ipv6/tcp_ipv6.c | 8 +---

Hi Jon.

You forgot net/dccp/ipv6.c 

dccp_v6_err() has the same issue.




Re: [PATCH v2 3/5] PCI: rockchip: add remove() support

2017-03-09 Thread Shawn Lin

On 2017/3/10 11:22, Shawn Lin wrote:

On 2017/3/10 10:46, Brian Norris wrote:

Currently, if we try to unbind the platform device, the remove will
succeed, but the removal won't undo most of the registration, leaving
partially-configured PCI devices in the system.

This allows, for example, a simple 'lspci' to crash the system, as it
will try to touch the freed (via devm_*) driver structures.

So let's implement device remove().



As this patchset seems to be merged together so I think the following
warning will be ok? if my git-am robot only pick your patch 1->compile->
patch 2->compile->patch 3 then

drivers/pci/host/pcie-rockchip.c: In function 'rockchip_pcie_remove':
drivers/pci/host/pcie-rockchip.c:1435:2: error: implicit declaration of
function 'pci_unmap_iospace' [-Werror=implicit-function-declaration]
  pci_unmap_iospace(rockchip->io);

but I guess you may need to move your patch 4 ahead of patch 3?



Well, I am not sure if something is wrong here.

But when booting up the system for the first time, we got
[0.527263] PCI host bridge /pcie@f800 ranges:
[0.527293]   MEM 0xfa00..0xfa5f -> 0xfa00
[0.527308]IO 0xfa60..0xfa6f -> 0xfa60
[0.527544] rockchip-pcie f800.pcie: PCI host bridge to bus :0

so the hierarchy(lspci -t) looks like:
lspci -t
-[:00]---00.0-[01]00.0

and lspci
:00:00.0 Class 0604: Device 1d87:0100
0001:01:00.0 Class 0108: Device 8086:f1a5 (rev 03)

but if I did unbind and bind, the bus number is different.

lspci
0001:00:00.0 Class 0604: Device 1d87:0100
0001:01:00.0 Class 0108: Device 8086:f1a5 (rev 03)

lspci -t
-+-[0001:00]---00.0-[01]00.0
 \-[:00]-

This hierarchy looks wrong to me.




Signed-off-by: Brian Norris 
---
v2:
* unmap IO space with pci_unmap_iospace()
* remove IRQ domain
---
 drivers/pci/host/pcie-rockchip.c | 36
++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/host/pcie-rockchip.c
b/drivers/pci/host/pcie-rockchip.c
index 5d7b27b1e941..d2e5078ae331 100644
--- a/drivers/pci/host/pcie-rockchip.c
+++ b/drivers/pci/host/pcie-rockchip.c
@@ -223,9 +223,11 @@ struct rockchip_pcie {
 intlink_gen;
 structdevice *dev;
 structirq_domain *irq_domain;
-u32 io_size;
 int offset;
+struct pci_bus *root_bus;
+struct resource *io;
 phys_addr_t io_bus_addr;
+u32 io_size;
 void__iomem *msg_region;
 u32 mem_size;
 phys_addr_t msg_bus_addr;
@@ -1360,6 +1362,7 @@ static int rockchip_pcie_probe(struct
platform_device *pdev)
  err, io);
 continue;
 }
+rockchip->io = io;
 break;
 case IORESOURCE_MEM:
 mem = win->res;
@@ -1391,6 +1394,7 @@ static int rockchip_pcie_probe(struct
platform_device *pdev)
 err = -ENOMEM;
 goto err_free_res;
 }
+rockchip->root_bus = bus;

 pci_bus_size_bridges(bus);
 pci_bus_assign_resources(bus);
@@ -1421,6 +1425,34 @@ static int rockchip_pcie_probe(struct
platform_device *pdev)
 return err;
 }

+static int rockchip_pcie_remove(struct platform_device *pdev)
+{
+struct device *dev = &pdev->dev;
+struct rockchip_pcie *rockchip = dev_get_drvdata(dev);
+
+pci_stop_root_bus(rockchip->root_bus);
+pci_remove_root_bus(rockchip->root_bus);
+pci_unmap_iospace(rockchip->io);
+irq_domain_remove(rockchip->irq_domain);
+
+phy_power_off(rockchip->phy);
+phy_exit(rockchip->phy);
+
+clk_disable_unprepare(rockchip->clk_pcie_pm);
+clk_disable_unprepare(rockchip->hclk_pcie);
+clk_disable_unprepare(rockchip->aclk_perf_pcie);
+clk_disable_unprepare(rockchip->aclk_pcie);
+
+if (!IS_ERR(rockchip->vpcie3v3))
+regulator_disable(rockchip->vpcie3v3);
+if (!IS_ERR(rockchip->vpcie1v8))
+regulator_disable(rockchip->vpcie1v8);
+if (!IS_ERR(rockchip->vpcie0v9))
+regulator_disable(rockchip->vpcie0v9);
+
+return 0;
+}
+
 static const struct dev_pm_ops rockchip_pcie_pm_ops = {
 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(rockchip_pcie_suspend_noirq,
   rockchip_pcie_resume_noirq)
@@ -1438,6 +1470,6 @@ static struct platform_driver
rockchip_pcie_driver = {
 .pm = &rockchip_pcie_pm_ops,
 },
 .probe = rockchip_pcie_probe,
-
+.remove = rockchip_pcie_remove,
 };
 builtin_platform_driver(rockchip_pcie_driver);







--
Best Regards
Shawn Lin



[git pull] drm fixes for 4.11-rc2

2017-03-09 Thread Dave Airlie
Hi Linus,

These are the drm fixes I've collected for rc2. Mostly i915 GVT only
fixes, along with a single EDID fix, some mxsfb fixes and a few minor
amd fixes.

Thanks,
Dave.

The following changes since commit c1ae3cfa0e89fa1a7ecc4c99031f5e9ae99d9201:

  Linux 4.11-rc1 (2017-03-05 12:59:56 -0800)

are available in the git repository at:

  git://people.freedesktop.org/~airlied/linux tags/drm-fixes-for-4.11-rc2

for you to fetch changes up to 3f81e1340706e9a7f854808e2f580c3106805d0c:

  drm: mxsfb: Implement drm_panel handling (2017-03-10 11:11:14 +1000)


intel, amd and mxsfb fixes.


Alex Deucher (2):
  drm/amdgpu: validate paramaters in the gem ioctl
  drm/amdgpu: bump driver version for some new features

Bing Niu (1):
  drm/i915/gvt: set SFUSE_STRAP properly for vitual monitor detection

Changbin Du (1):
  drm/i915/gvt: protect RO and Rsvd bits of virtual vgpu configuration space

Chuanxiao Dong (3):
  drm/i915/gvt: add a NULL pointer check to avoid kernel panic
  drm/i915/gvt: use pfn_valid for better checking
  drm/i915/gvt: handle workload lifecycle properly

Dave Airlie (3):
  Merge tag 'drm-misc-fixes-2017-03-06' of
git://anongit.freedesktop.org/git/drm-misc into drm-fixes
  Merge tag 'drm-intel-fixes-2017-03-09' of
git://anongit.freedesktop.org/git/drm-intel into drm-fixes
  Merge branch 'drm-fixes-4.11' of
git://people.freedesktop.org/~agd5f/linux into drm-fixes

Fabio Estevam (2):
  drm: mxsfb_crtc: Fix the framebuffer misplacement
  drm: mxsfb: Implement drm_panel handling

Jani Nikula (2):
  Merge tag 'gvt-next-2017-02-24' of
https://github.com/01org/gvt-linux into drm-intel-fixes
  Merge tag 'gvt-fixes-2017-03-08' of
https://github.com/01org/gvt-linux into drm-intel-fixes

Jim Qu (1):
  drm/amd/amdgpu: fix console deadlock if late init failed

Marek Vasut (1):
  drm: mxsfb: Fix crash when provided invalid DT bindings

Min He (2):
  drm/i915/gvt: introduced failsafe mode into vgpu
  drm/i915/gvt: enter failsafe mode when guest requires more resources

Pei Zhang (2):
  drm/i915/gvt: add cmd_access to GEN7_HALF_SLICE_CHICKEN1
  drm/i915/gvt: add some new MMIOs to cmd_access white list

Ping Gao (1):
  drm/i915/gvt: clear the vGPU reset logic

Stefan Agner (2):
  drm: mxsfb: use bus_format to determine LCD bus width
  drm: mxsfb: fix pixel clock polarity

Takashi Iwai (1):
  drm/i915/gvt: Fix superfluous newline in GVT_DISPLAY_READY env var

Tina Zhang (1):
  drm/i915/gvt: change some gvt_err to gvt_dbg_cmd

Tomeu Vizoso (1):
  drm/edid: Add EDID_QUIRK_FORCE_8BPC quirk for Rotel RSX-1058

Weinan Li (2):
  drm/i915/gvt: refine pcode write emulation
  drm/i915/gvt: fix pcode mailbox write emulation of BDW

Zhao Yan (8):
  drm/i915/gvt: fix unhandled mmio warnings
  drm/i915/gvt: add more registers to context save/restore list
  drm/i915/gvt: force-nopriv register handling
  drm/i915/gvt: set default value to 0 for unhandled mmio regs
  drm/i915/gvt: have more registers with F_CMD_ACCESS flags set
  drm/i915/gvt: add more registers into handlers list
  drm/i915/gvt: fix an error for one register
  drm/i915/gvt: fix an error for F_RO flag

Zhao, Xinda (3):
  drm/i915/gvt: handle fence reg access during GPU reset
  drm/i915/gvt: decrease priority of output msg for untracked mmio
  drm/i915/gvt: remove unnecessary error msg from gtt write

Zhenyu Wang (4):
  drm/i915/gvt: Fix check error on opregion.c
  drm/i915/gvt: adjust to fixed vGPU types
  drm/i915/gvt: Add more edid definition support
  drm/i915/gvt: add resolution definition for vGPU type

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |   5 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c|   3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c|  21 ++
 drivers/gpu/drm/drm_edid.c |   3 +
 drivers/gpu/drm/i915/gvt/cfg_space.c   |  57 +++-
 drivers/gpu/drm/i915/gvt/cmd_parser.c  |  10 +-
 drivers/gpu/drm/i915/gvt/display.c | 139 ++---
 drivers/gpu/drm/i915/gvt/display.h |  20 +-
 drivers/gpu/drm/i915/gvt/firmware.c|   2 +-
 drivers/gpu/drm/i915/gvt/gtt.c |  40 ++-
 drivers/gpu/drm/i915/gvt/gvt.h |  12 +-
 drivers/gpu/drm/i915/gvt/handlers.c| 439 -
 drivers/gpu/drm/i915/gvt/kvmgt.c   |  12 +-
 drivers/gpu/drm/i915/gvt/mmio.c|  66 -
 drivers/gpu/drm/i915/gvt/opregion.c|   5 +-
 drivers/gpu/drm/i915/gvt/render.c  |  16 ++
 drivers/gpu/drm/i915/gvt/scheduler.c   |  52 ++--
 drivers/gpu/drm/i915/gvt/vgpu.c|  72 +++--
 drivers/gpu/drm/mxsfb/mxsfb_crtc.c |  49 +++-
 drivers/gpu/drm/mxsfb/mxsfb_drv.c  |   4 +
 drivers/gpu/drm/mxsfb/mxsfb_out.c  |   4 +
 drivers/gpu/drm/mxsfb/

Re: [PATCH v2 1/2] doc: bindings: Add bindings documentation for mtd nvmem

2017-03-09 Thread Moritz Fischer
On Thu, Mar 9, 2017 at 7:17 PM, Marek Vasut  wrote:
> On 03/07/2017 09:26 AM, Alban wrote:
>> Config data for drivers, like MAC addresses, is often stored in MTD.
>> Add a binding that define how such data storage can be represented in
>> device tree.
>>
>> Signed-off-by: Alban 
>> ---
>> Changelog:
>> v2: * Added a "Required properties" section with the nvmem-provider
>>   property
>> ---
>>  .../devicetree/bindings/nvmem/mtd-nvmem.txt| 33 
>> ++
>>  1 file changed, 33 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
>>
>> diff --git a/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt 
>> b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
>> new file mode 100644
>> index 000..8ed25e6
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
>> @@ -0,0 +1,33 @@
>> += NVMEM in MTD =
>> +
>> +Config data for drivers, like MAC addresses, is often stored in MTD.
>> +This binding define how such data storage can be represented in device tree.
>> +
>> +An MTD can be defined as an NVMEM provider by adding the `nvmem-provider`
>> +property to their node. Data cells can then be defined as child nodes
>> +of the partition as defined in nvmem.txt.
>
> Why don't we just read the data from MTD and be done with it ? What's
> the benefit of complicating things by using nvmem ?

Well because usually stuff like MAC addresses etc are stored in eeproms.
This gives a nice abstraction with making them both look like nvmem (that was my
reasoning back then when I submitted a patch to support the OTP part in a
SPI NOR part.

>> +Required properties:
>> +nvmem-provider:  Indicate that the device should be registered as
>> + NVMEM provider
>> +
>> +Example:
>> +
>> + flash@0 {
>> + ...
>> +
>> + partition@2 {
>> + label = "art";
>> + reg = <0x7F 0x01>;
>> + read-only;
>> +
>> + nvmem-provider;
>> + #address-cells = <1>;
>> + #size-cells = <1>;
>> +
>> + eeprom@1000 {
>> + label = "wmac-eeprom";
>> + reg = <0x1000 0x1000>;
>> + };
>> + };
>> + };
>>
>
>
> --
> Best regards,
> Marek Vasut

Cheers,
Moritz


[PATCH] Staging: iio: return expression instead of return ret

2017-03-09 Thread Bo Yu

The following Coccinelle script was used to detect this:

@@
local idexpression ret;
expression e;
@@

-ret =
+return
  e;
-return ret;

Signed-off-by: Bo YU 
---
  drivers/staging/iio/meter/ade7754.c |3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/iio/meter/ade7754.c 
b/drivers/staging/iio/meter/ade7754.c
index 024463a11c47..19f8cb144768 100644
--- a/drivers/staging/iio/meter/ade7754.c
+++ b/drivers/staging/iio/meter/ade7754.c
@@ -349,9 +349,8 @@ static int ade7754_set_irq(struct device *dev, bool enable)
else
irqen &= ~BIT(14);

-   ret = ade7754_spi_write_reg_16(dev, ADE7754_IRQEN, irqen);
+   return ade7754_spi_write_reg_16(dev, ADE7754_IRQEN, irqen);

-   return ret;
  }

  /* Power down the device */
--
1.7.10.4



ERROR: "empty_zero_page" [drivers/usb/wusbcore/wusbcore.ko] undefined!

2017-03-09 Thread kbuild test robot
Hi Andy,

First bad commit (maybe != root cause):

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   c1aa905a304e4b5e6a3fe112ec62d9c1c7b0c155
commit: 620f1a632ebcc9811c2f8009ba52297c7006f805 wusbcore: Fix one more 
crypto-on-the-stack bug
date:   8 weeks ago
config: openrisc-allmodconfig (attached as .config)
compiler: or1k-linux-gcc (GCC) 5.4.0
reproduce:
wget 
https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout 620f1a632ebcc9811c2f8009ba52297c7006f805
# save the attached .config to linux build tree
make.cross ARCH=openrisc 

All errors (new ones prefixed by >>):

   ERROR: "empty_zero_page" [net/ceph/libceph.ko] undefined!
   ERROR: "__ucmpdi2" [lib/842/842_decompress.ko] undefined!
   ERROR: "__ioremap" [fs/pstore/ramoops.ko] undefined!
   ERROR: "iounmap" [fs/pstore/ramoops.ko] undefined!
   ERROR: "empty_zero_page" [fs/nfs/objlayout/objlayoutdriver.ko] undefined!
   ERROR: "empty_zero_page" [fs/exofs/exofs.ko] undefined!
   ERROR: "empty_zero_page" [fs/crypto/fscrypto.ko] undefined!
   ERROR: "__ucmpdi2" [fs/btrfs/btrfs.ko] undefined!
   ERROR: "__ioremap" [drivers/video/fbdev/uvesafb.ko] undefined!
   ERROR: "iounmap" [drivers/video/fbdev/uvesafb.ko] undefined!
   ERROR: "__ioremap" [drivers/video/fbdev/tmiofb.ko] undefined!
   ERROR: "iounmap" [drivers/video/fbdev/tmiofb.ko] undefined!
   ERROR: "__ioremap" [drivers/video/fbdev/sm501fb.ko] undefined!
   ERROR: "iounmap" [drivers/video/fbdev/sm501fb.ko] undefined!
   ERROR: "__ioremap" [drivers/video/fbdev/s1d13xxxfb.ko] undefined!
   ERROR: "iounmap" [drivers/video/fbdev/s1d13xxxfb.ko] undefined!
   ERROR: "__ioremap" [drivers/video/fbdev/goldfishfb.ko] undefined!
   ERROR: "iounmap" [drivers/video/fbdev/goldfishfb.ko] undefined!
>> ERROR: "empty_zero_page" [drivers/usb/wusbcore/wusbcore.ko] undefined!
   ERROR: "__ioremap" [drivers/usb/musb/tusb6010.ko] undefined!
   ERROR: "iounmap" [drivers/usb/musb/tusb6010.ko] undefined!
   ERROR: "__ioremap" [drivers/usb/host/xhci-plat-hcd.ko] undefined!
   ERROR: "iounmap" [drivers/usb/host/xhci-plat-hcd.ko] undefined!
   ERROR: "__ioremap" [drivers/usb/host/sl811-hcd.ko] undefined!
   ERROR: "iounmap" [drivers/usb/host/sl811-hcd.ko] undefined!
   ERROR: "__ioremap" [drivers/usb/host/r8a66597-hcd.ko] undefined!
   ERROR: "iounmap" [drivers/usb/host/r8a66597-hcd.ko] undefined!
   ERROR: "__ioremap" [drivers/usb/host/isp116x-hcd.ko] undefined!
   ERROR: "iounmap" [drivers/usb/host/isp116x-hcd.ko] undefined!
   ERROR: "__ioremap" [drivers/usb/gadget/udc/net2272.ko] undefined!
   ERROR: "iounmap" [drivers/usb/gadget/udc/net2272.ko] undefined!
   ERROR: "__ioremap" [drivers/usb/gadget/udc/mv_u3d_core.ko] undefined!
   ERROR: "iounmap" [drivers/usb/gadget/udc/mv_u3d_core.ko] undefined!
   ERROR: "iounmap" [drivers/usb/gadget/udc/m66592-udc.ko] undefined!
   ERROR: "__ioremap" [drivers/usb/gadget/udc/m66592-udc.ko] undefined!
   ERROR: "__ioremap" [drivers/usb/gadget/udc/fusb300_udc.ko] undefined!
   ERROR: "iounmap" [drivers/usb/gadget/udc/fusb300_udc.ko] undefined!
   ERROR: "__ioremap" [drivers/usb/gadget/udc/fotg210-udc.ko] undefined!
   ERROR: "iounmap" [drivers/usb/gadget/udc/fotg210-udc.ko] undefined!
   ERROR: "__ioremap" [drivers/usb/c67x00/c67x00.ko] undefined!
   ERROR: "iounmap" [drivers/usb/c67x00/c67x00.ko] undefined!
   ERROR: "__ioremap" [drivers/uio/uio_pruss.ko] undefined!
   ERROR: "iounmap" [drivers/uio/uio_pruss.ko] undefined!
   ERROR: "iounmap" [drivers/tty/serial/xilinx_uartps.ko] undefined!
   ERROR: "__ioremap" [drivers/tty/serial/xilinx_uartps.ko] undefined!
   ERROR: "iounmap" [drivers/tty/serial/uartlite.ko] undefined!
   ERROR: "__ioremap" [drivers/tty/serial/uartlite.ko] undefined!
   ERROR: "iounmap" [drivers/tty/serial/timbuart.ko] undefined!
   ERROR: "__ioremap" [drivers/tty/serial/timbuart.ko] undefined!
   ERROR: "iounmap" [drivers/tty/serial/sh-sci.ko] undefined!
   ERROR: "__ioremap" [drivers/tty/serial/sh-sci.ko] undefined!
   ERROR: "__ioremap" [drivers/tty/serial/mxs-auart.ko] undefined!
   ERROR: "iounmap" [drivers/tty/serial/men_z135_uart.ko] undefined!
   ERROR: "__ioremap" [drivers/tty/serial/men_z135_uart.ko] undefined!
   ERROR: "__ioremap" [drivers/tty/serial/altera_uart.ko] undefined!
   ERROR: "__ioremap" [drivers/tty/serial/altera_jtaguart.ko] undefined!
   ERROR: "__ioremap" [drivers/tty/serial/8250/8250_base.ko] undefined!
   ERROR: "iounmap" [drivers/tty/serial/8250/8250_base.ko] undefined!
   ERROR: "iounmap" [drivers/thermal/qoriq_thermal.ko] undefined!
   ERROR: "iounmap" [drivers/thermal/qcom/qcom_tsens.ko] undefined!
   ERROR: "__ioremap" [drivers/staging/comedi/drivers/ii_pci20kc.ko] undefined!
   ERROR: "iounmap" [drivers/staging/comedi/drivers/ii_pci20kc.ko] undefined!
   ERROR: "__ioremap" [drivers/ssb/ssb.ko] undefined!
   ERROR: "iounmap" [drivers/ssb/ssb.ko] undefined!
   ERROR: "__ioremap" 

  1   2   3   4   5   6   7   8   9   10   >