2016-02-25 13:52:38 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016, The Linux Foundation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 and
|
|
|
|
* only 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/of_device.h>
|
|
|
|
|
|
|
|
#include "hdmi.h"
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
static int msm_hdmi_phy_resource_init(struct hdmi_phy *phy)
|
2016-02-25 13:52:38 +08:00
|
|
|
{
|
|
|
|
struct hdmi_phy_cfg *cfg = phy->cfg;
|
|
|
|
struct device *dev = &phy->pdev->dev;
|
|
|
|
int i, ret;
|
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:07:58 +08:00
|
|
|
phy->regs = devm_kcalloc(dev, cfg->num_regs, sizeof(phy->regs[0]),
|
2016-02-25 13:52:38 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!phy->regs)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:07:58 +08:00
|
|
|
phy->clks = devm_kcalloc(dev, cfg->num_clks, sizeof(phy->clks[0]),
|
2016-02-25 13:52:38 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!phy->clks)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < cfg->num_regs; i++) {
|
|
|
|
struct regulator *reg;
|
|
|
|
|
|
|
|
reg = devm_regulator_get(dev, cfg->reg_names[i]);
|
|
|
|
if (IS_ERR(reg)) {
|
|
|
|
ret = PTR_ERR(reg);
|
2018-10-21 01:49:26 +08:00
|
|
|
DRM_DEV_ERROR(dev, "failed to get phy regulator: %s (%d)\n",
|
2016-02-25 13:52:38 +08:00
|
|
|
cfg->reg_names[i], ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
phy->regs[i] = reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < cfg->num_clks; i++) {
|
|
|
|
struct clk *clk;
|
|
|
|
|
2017-10-17 04:56:28 +08:00
|
|
|
clk = msm_clk_get(phy->pdev, cfg->clk_names[i]);
|
2016-02-25 13:52:38 +08:00
|
|
|
if (IS_ERR(clk)) {
|
|
|
|
ret = PTR_ERR(clk);
|
2018-10-21 01:49:26 +08:00
|
|
|
DRM_DEV_ERROR(dev, "failed to get phy clock: %s (%d)\n",
|
2016-02-25 13:52:38 +08:00
|
|
|
cfg->clk_names[i], ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
phy->clks[i] = clk;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
int msm_hdmi_phy_resource_enable(struct hdmi_phy *phy)
|
2016-02-25 13:52:38 +08:00
|
|
|
{
|
|
|
|
struct hdmi_phy_cfg *cfg = phy->cfg;
|
|
|
|
struct device *dev = &phy->pdev->dev;
|
|
|
|
int i, ret = 0;
|
|
|
|
|
|
|
|
pm_runtime_get_sync(dev);
|
|
|
|
|
|
|
|
for (i = 0; i < cfg->num_regs; i++) {
|
|
|
|
ret = regulator_enable(phy->regs[i]);
|
|
|
|
if (ret)
|
2018-10-21 01:49:26 +08:00
|
|
|
DRM_DEV_ERROR(dev, "failed to enable regulator: %s (%d)\n",
|
2016-02-25 13:52:38 +08:00
|
|
|
cfg->reg_names[i], ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < cfg->num_clks; i++) {
|
|
|
|
ret = clk_prepare_enable(phy->clks[i]);
|
|
|
|
if (ret)
|
2018-10-21 01:49:26 +08:00
|
|
|
DRM_DEV_ERROR(dev, "failed to enable clock: %s (%d)\n",
|
2016-02-25 13:52:38 +08:00
|
|
|
cfg->clk_names[i], ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
void msm_hdmi_phy_resource_disable(struct hdmi_phy *phy)
|
2016-02-25 13:52:38 +08:00
|
|
|
{
|
|
|
|
struct hdmi_phy_cfg *cfg = phy->cfg;
|
|
|
|
struct device *dev = &phy->pdev->dev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = cfg->num_clks - 1; i >= 0; i--)
|
|
|
|
clk_disable_unprepare(phy->clks[i]);
|
|
|
|
|
|
|
|
for (i = cfg->num_regs - 1; i >= 0; i--)
|
|
|
|
regulator_disable(phy->regs[i]);
|
|
|
|
|
|
|
|
pm_runtime_put_sync(dev);
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
void msm_hdmi_phy_powerup(struct hdmi_phy *phy, unsigned long int pixclock)
|
2016-02-25 13:52:38 +08:00
|
|
|
{
|
|
|
|
if (!phy || !phy->cfg->powerup)
|
|
|
|
return;
|
|
|
|
|
|
|
|
phy->cfg->powerup(phy, pixclock);
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
void msm_hdmi_phy_powerdown(struct hdmi_phy *phy)
|
2016-02-25 13:52:38 +08:00
|
|
|
{
|
|
|
|
if (!phy || !phy->cfg->powerdown)
|
|
|
|
return;
|
|
|
|
|
|
|
|
phy->cfg->powerdown(phy);
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
static int msm_hdmi_phy_pll_init(struct platform_device *pdev,
|
2016-02-25 13:52:39 +08:00
|
|
|
enum hdmi_phy_type type)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MSM_HDMI_PHY_8960:
|
2016-02-23 05:08:35 +08:00
|
|
|
ret = msm_hdmi_pll_8960_init(pdev);
|
2016-02-25 13:52:39 +08:00
|
|
|
break;
|
2016-02-25 13:52:44 +08:00
|
|
|
case MSM_HDMI_PHY_8996:
|
2016-02-23 05:08:35 +08:00
|
|
|
ret = msm_hdmi_pll_8996_init(pdev);
|
2016-02-25 13:52:44 +08:00
|
|
|
break;
|
2016-02-25 13:52:39 +08:00
|
|
|
/*
|
|
|
|
* we don't have PLL support for these, don't report an error for now
|
|
|
|
*/
|
|
|
|
case MSM_HDMI_PHY_8x60:
|
|
|
|
case MSM_HDMI_PHY_8x74:
|
|
|
|
default:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
static int msm_hdmi_phy_probe(struct platform_device *pdev)
|
2016-02-25 13:52:38 +08:00
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct hdmi_phy *phy;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
|
|
|
|
if (!phy)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
phy->cfg = (struct hdmi_phy_cfg *)of_device_get_match_data(dev);
|
|
|
|
if (!phy->cfg)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
phy->mmio = msm_ioremap(pdev, "hdmi_phy", "HDMI_PHY");
|
|
|
|
if (IS_ERR(phy->mmio)) {
|
2018-10-21 01:49:26 +08:00
|
|
|
DRM_DEV_ERROR(dev, "%s: failed to map phy base\n", __func__);
|
2016-02-25 13:52:38 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
phy->pdev = pdev;
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
ret = msm_hdmi_phy_resource_init(phy);
|
2016-02-25 13:52:38 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
pm_runtime_enable(&pdev->dev);
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
ret = msm_hdmi_phy_resource_enable(phy);
|
2016-02-25 13:52:39 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
ret = msm_hdmi_phy_pll_init(pdev, phy->cfg->type);
|
2016-02-25 13:52:39 +08:00
|
|
|
if (ret) {
|
2018-10-21 01:49:26 +08:00
|
|
|
DRM_DEV_ERROR(dev, "couldn't init PLL\n");
|
2016-02-23 05:08:35 +08:00
|
|
|
msm_hdmi_phy_resource_disable(phy);
|
2016-02-25 13:52:39 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
msm_hdmi_phy_resource_disable(phy);
|
2016-02-25 13:52:39 +08:00
|
|
|
|
2016-02-25 13:52:38 +08:00
|
|
|
platform_set_drvdata(pdev, phy);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
static int msm_hdmi_phy_remove(struct platform_device *pdev)
|
2016-02-25 13:52:38 +08:00
|
|
|
{
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
static const struct of_device_id msm_hdmi_phy_dt_match[] = {
|
2016-02-25 13:52:38 +08:00
|
|
|
{ .compatible = "qcom,hdmi-phy-8660",
|
2016-02-23 05:08:35 +08:00
|
|
|
.data = &msm_hdmi_phy_8x60_cfg },
|
2016-02-25 13:52:38 +08:00
|
|
|
{ .compatible = "qcom,hdmi-phy-8960",
|
2016-02-23 05:08:35 +08:00
|
|
|
.data = &msm_hdmi_phy_8960_cfg },
|
2016-02-25 13:52:38 +08:00
|
|
|
{ .compatible = "qcom,hdmi-phy-8974",
|
2016-02-23 05:08:35 +08:00
|
|
|
.data = &msm_hdmi_phy_8x74_cfg },
|
2016-02-25 13:52:38 +08:00
|
|
|
{ .compatible = "qcom,hdmi-phy-8084",
|
2016-02-23 05:08:35 +08:00
|
|
|
.data = &msm_hdmi_phy_8x74_cfg },
|
2016-02-25 13:52:44 +08:00
|
|
|
{ .compatible = "qcom,hdmi-phy-8996",
|
2016-02-23 05:08:35 +08:00
|
|
|
.data = &msm_hdmi_phy_8996_cfg },
|
2016-02-25 13:52:38 +08:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
static struct platform_driver msm_hdmi_phy_platform_driver = {
|
|
|
|
.probe = msm_hdmi_phy_probe,
|
|
|
|
.remove = msm_hdmi_phy_remove,
|
2016-02-25 13:52:38 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "msm_hdmi_phy",
|
2016-02-23 05:08:35 +08:00
|
|
|
.of_match_table = msm_hdmi_phy_dt_match,
|
2016-02-25 13:52:38 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
void __init msm_hdmi_phy_driver_register(void)
|
2016-02-25 13:52:38 +08:00
|
|
|
{
|
2016-02-23 05:08:35 +08:00
|
|
|
platform_driver_register(&msm_hdmi_phy_platform_driver);
|
2016-02-25 13:52:38 +08:00
|
|
|
}
|
|
|
|
|
2016-02-23 05:08:35 +08:00
|
|
|
void __exit msm_hdmi_phy_driver_unregister(void)
|
2016-02-25 13:52:38 +08:00
|
|
|
{
|
2016-02-23 05:08:35 +08:00
|
|
|
platform_driver_unregister(&msm_hdmi_phy_platform_driver);
|
2016-02-25 13:52:38 +08:00
|
|
|
}
|