msm: camera: Change API to populate regulator name
Some of the camera modules need to know the regulator names to enable based on the use case, Hence change the regulator API to populate regulator names as well. Change-Id: I8205df6ecbeed8eca7ff9a81534edadf51309fe1 Signed-off-by: Lakshmi Narayana Kalavala <lkalaval@codeaurora.org>
This commit is contained in:
parent
5cb6f5f5b4
commit
c39bf2d8f9
11 changed files with 87 additions and 68 deletions
|
@ -9,6 +9,8 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
#ifndef _CAM_HW_OPS_H_
|
||||
#define _CAM_HW_OPS_H_
|
||||
|
||||
enum cam_ahb_clk_vote {
|
||||
/* need to update the voting requests
|
||||
|
@ -37,3 +39,4 @@ enum cam_ahb_clk_client {
|
|||
int cam_config_ahb_clk(struct device *dev, unsigned long freq,
|
||||
enum cam_ahb_clk_client id, enum cam_ahb_clk_vote vote);
|
||||
int cam_ahb_clk_init(struct platform_device *pdev);
|
||||
#endif /* _CAM_HW_OPS_H_ */
|
||||
|
|
|
@ -473,16 +473,16 @@ EXPORT_SYMBOL(msm_camera_put_clk_info_and_rates);
|
|||
|
||||
/* Get regulators from DT */
|
||||
int msm_camera_get_regulator_info(struct platform_device *pdev,
|
||||
struct regulator ***vdd,
|
||||
struct msm_cam_regulator **vdd_info,
|
||||
int *num_reg)
|
||||
{
|
||||
uint32_t cnt;
|
||||
int i, rc;
|
||||
struct device_node *of_node;
|
||||
const char *name;
|
||||
char prop_name[32];
|
||||
struct msm_cam_regulator *tmp_reg;
|
||||
|
||||
if (!pdev || !vdd || !num_reg)
|
||||
if (!pdev || !vdd_info || !num_reg)
|
||||
return -EINVAL;
|
||||
|
||||
of_node = pdev->dev.of_node;
|
||||
|
@ -499,82 +499,95 @@ int msm_camera_get_regulator_info(struct platform_device *pdev,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
*num_reg = cnt;
|
||||
(*vdd) = devm_kcalloc(&pdev->dev, cnt, sizeof(struct regulator *),
|
||||
GFP_KERNEL);
|
||||
if (!*vdd)
|
||||
tmp_reg = devm_kcalloc(&pdev->dev, cnt,
|
||||
sizeof(struct msm_cam_regulator), GFP_KERNEL);
|
||||
if (!tmp_reg)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
rc = of_property_read_string_index(of_node,
|
||||
"qcom,vdd-names", i, &name);
|
||||
"qcom,vdd-names", i, &tmp_reg[i].name);
|
||||
if (rc < 0) {
|
||||
pr_err("Fail to fetch regulators: %d\n", i);
|
||||
rc = -EINVAL;
|
||||
goto err1;
|
||||
}
|
||||
|
||||
CDBG("regulator-names[%d] = %s\n", i, name);
|
||||
CDBG("regulator-names[%d] = %s\n", i, tmp_reg[i].name);
|
||||
|
||||
snprintf(prop_name, 32, "%s-supply", name);
|
||||
snprintf(prop_name, 32, "%s-supply", tmp_reg[i].name);
|
||||
|
||||
if (of_get_property(of_node, prop_name, NULL)) {
|
||||
(*vdd)[i] = devm_regulator_get(&pdev->dev, name);
|
||||
if (IS_ERR((*vdd)[i])) {
|
||||
tmp_reg[i].vdd =
|
||||
devm_regulator_get(&pdev->dev, tmp_reg[i].name);
|
||||
if (IS_ERR(tmp_reg[i].vdd)) {
|
||||
rc = -EINVAL;
|
||||
pr_err("Fail to get regulator :%d\n", i);
|
||||
goto err1;
|
||||
}
|
||||
} else {
|
||||
pr_err("Regulator phandle not found :%s\n", name);
|
||||
pr_err("Regulator phandle not found :%s\n",
|
||||
tmp_reg[i].name);
|
||||
rc = -EINVAL;
|
||||
goto err1;
|
||||
}
|
||||
CDBG("vdd ptr[%d] :%p\n", i, (*vdd)[i]);
|
||||
CDBG("vdd ptr[%d] :%p\n", i, tmp_reg[i].vdd);
|
||||
}
|
||||
|
||||
*num_reg = cnt;
|
||||
*vdd_info = tmp_reg;
|
||||
|
||||
return 0;
|
||||
|
||||
err1:
|
||||
for (--i; i >= 0; i--)
|
||||
devm_regulator_put((*vdd)[i]);
|
||||
devm_kfree(&pdev->dev, *vdd);
|
||||
devm_regulator_put(tmp_reg[i].vdd);
|
||||
devm_kfree(&pdev->dev, tmp_reg);
|
||||
return rc;
|
||||
}
|
||||
EXPORT_SYMBOL(msm_camera_get_regulator_info);
|
||||
|
||||
|
||||
/* Enable/Disable regulators */
|
||||
int msm_camera_regulator_enable(struct regulator **vdd,
|
||||
int msm_camera_regulator_enable(struct msm_cam_regulator *vdd_info,
|
||||
int cnt, int enable)
|
||||
{
|
||||
int i;
|
||||
int rc;
|
||||
struct msm_cam_regulator *tmp = vdd_info;
|
||||
|
||||
CDBG("cnt : %d, enable : %d\n", cnt, enable);
|
||||
if (!vdd) {
|
||||
if (!tmp) {
|
||||
pr_err("Invalid params");
|
||||
return -EINVAL;
|
||||
}
|
||||
CDBG("cnt : %d\n", cnt);
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if (enable) {
|
||||
rc = regulator_enable(vdd[i]);
|
||||
if (rc < 0) {
|
||||
pr_err("regulator enable failed %d\n", i);
|
||||
goto error;
|
||||
if (tmp && !IS_ERR_OR_NULL(tmp->vdd)) {
|
||||
CDBG("name : %s, enable : %d\n", tmp->name, enable);
|
||||
if (enable) {
|
||||
rc = regulator_enable(tmp->vdd);
|
||||
if (rc < 0) {
|
||||
pr_err("regulator enable failed %d\n",
|
||||
i);
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
rc = regulator_disable(tmp->vdd);
|
||||
if (rc < 0)
|
||||
pr_err("regulator disable failed %d\n",
|
||||
i);
|
||||
}
|
||||
} else {
|
||||
rc = regulator_disable(vdd[i]);
|
||||
if (rc < 0)
|
||||
pr_err("regulator disable failed %d\n", i);
|
||||
}
|
||||
tmp++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
error:
|
||||
for (--i; i > 0; i--) {
|
||||
if (!IS_ERR_OR_NULL(vdd[i]))
|
||||
regulator_disable(vdd[i]);
|
||||
--tmp;
|
||||
if (!IS_ERR_OR_NULL(tmp->vdd))
|
||||
regulator_disable(tmp->vdd);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
@ -582,24 +595,23 @@ EXPORT_SYMBOL(msm_camera_regulator_enable);
|
|||
|
||||
/* Put regulators regulators */
|
||||
void msm_camera_put_regulators(struct platform_device *pdev,
|
||||
struct regulator ***vdd,
|
||||
int cnt)
|
||||
struct msm_cam_regulator **vdd_info, int cnt)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!*vdd) {
|
||||
if (!vdd_info || !*vdd_info) {
|
||||
pr_err("Invalid params\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = cnt - 1; i >= 0; i--) {
|
||||
if (!IS_ERR_OR_NULL((*vdd)[i]))
|
||||
devm_regulator_put((*vdd)[i]);
|
||||
CDBG("vdd ptr[%d] :%p\n", i, (*vdd)[i]);
|
||||
if (vdd_info[i] && !IS_ERR_OR_NULL(vdd_info[i]->vdd))
|
||||
devm_regulator_put(vdd_info[i]->vdd);
|
||||
CDBG("vdd ptr[%d] :%p\n", i, vdd_info[i]->vdd);
|
||||
}
|
||||
|
||||
devm_kfree(&pdev->dev, *vdd);
|
||||
*vdd = NULL;
|
||||
devm_kfree(&pdev->dev, *vdd_info);
|
||||
*vdd_info = NULL;
|
||||
}
|
||||
EXPORT_SYMBOL(msm_camera_put_regulators);
|
||||
|
||||
|
@ -643,12 +655,11 @@ EXPORT_SYMBOL(msm_camera_register_irq);
|
|||
int msm_camera_register_threaded_irq(struct platform_device *pdev,
|
||||
struct resource *irq, irq_handler_t handler_fn,
|
||||
irq_handler_t thread_fn, unsigned long irqflags,
|
||||
char *irq_name, void *dev_id)
|
||||
const char *irq_name, void *dev_id)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (!pdev || !irq || !handler_fn || !thread_fn ||
|
||||
!irq_name || !dev_id) {
|
||||
if (!pdev || !irq || !irq_name || !dev_id) {
|
||||
pr_err("Invalid params\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,11 @@ enum cam_bus_client {
|
|||
CAM_BUS_CLIENT_MAX
|
||||
};
|
||||
|
||||
struct msm_cam_regulator {
|
||||
const char *name;
|
||||
struct regulator *vdd;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief : Gets clock information from dtsi
|
||||
*
|
||||
|
@ -154,28 +159,28 @@ long msm_camera_clk_set_rate(struct device *dev,
|
|||
* platform device
|
||||
*
|
||||
* @param pdev : platform device to get regulator information
|
||||
* @param vdd: Pointer to populate the regulator names
|
||||
* @param vdd_info: Pointer to populate the regulator names
|
||||
* @param num_reg: Pointer to populate the number of regulators
|
||||
* extracted from dtsi
|
||||
*
|
||||
* @return Status of operation. Negative in case of error. Zero otherwise.
|
||||
*/
|
||||
int msm_camera_get_regulator_info(struct platform_device *pdev,
|
||||
struct regulator ***vddd, int *num_reg);
|
||||
struct msm_cam_regulator **vdd_info, int *num_reg);
|
||||
/**
|
||||
* @brief : Enable/Disable the regultors
|
||||
*
|
||||
* This function enables/disables the regulators for a specific
|
||||
* platform device
|
||||
*
|
||||
* @param vdd: Pointer to list of regulators
|
||||
* @param vdd_info: Pointer to list of regulators
|
||||
* @param cnt: Number of regulators to enable/disable
|
||||
* @param enable: Flags specifies either enable/disable
|
||||
*
|
||||
* @return Status of operation. Negative in case of error. Zero otherwise.
|
||||
*/
|
||||
|
||||
int msm_camera_regulator_enable(struct regulator **vdd,
|
||||
int msm_camera_regulator_enable(struct msm_cam_regulator *vdd_info,
|
||||
int cnt, int enable);
|
||||
|
||||
/**
|
||||
|
@ -184,13 +189,12 @@ int msm_camera_regulator_enable(struct regulator **vdd,
|
|||
* This function releases the regulator resources.
|
||||
*
|
||||
* @param pdev: Pointer to platform device
|
||||
* @param vdd: Pointer to list of regulators
|
||||
* @param vdd_info: Pointer to list of regulators
|
||||
* @param cnt: Number of regulators to release
|
||||
*/
|
||||
|
||||
void msm_camera_put_regulators(struct platform_device *pdev,
|
||||
struct regulator ***vdd,
|
||||
int cnt);
|
||||
struct msm_cam_regulator **vdd_info, int cnt);
|
||||
/**
|
||||
* @brief : Get the IRQ resource
|
||||
*
|
||||
|
@ -248,7 +252,7 @@ int msm_camera_register_threaded_irq(struct platform_device *pdev,
|
|||
irq_handler_t handler_fn,
|
||||
irq_handler_t thread_fn,
|
||||
unsigned long irqflags,
|
||||
char *irq_name,
|
||||
const char *irq_name,
|
||||
void *dev);
|
||||
|
||||
/**
|
||||
|
|
|
@ -1224,7 +1224,7 @@ static int fd_probe(struct platform_device *pdev)
|
|||
goto error_mem_resources;
|
||||
}
|
||||
|
||||
ret = msm_camera_get_regulator_info(pdev, &fd->vdd,
|
||||
ret = msm_camera_get_regulator_info(pdev, &fd->vdd_info,
|
||||
&fd->num_reg);
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "Fail to get regulators\n");
|
||||
|
@ -1298,7 +1298,7 @@ error_get_bus:
|
|||
msm_camera_put_clk_info_and_rates(pdev, &fd->clk_info,
|
||||
&fd->clk, &fd->clk_rates, fd->clk_rates_num, fd->clk_num);
|
||||
error_get_clocks:
|
||||
msm_camera_put_regulators(pdev, &fd->vdd, fd->num_reg);
|
||||
msm_camera_put_regulators(pdev, &fd->vdd_info, fd->num_reg);
|
||||
error_get_regulator:
|
||||
msm_fd_hw_release_mem_resources(fd);
|
||||
error_mem_resources:
|
||||
|
@ -1325,7 +1325,7 @@ static int fd_device_remove(struct platform_device *pdev)
|
|||
msm_camera_unregister_bus_client(CAM_BUS_CLIENT_FD);
|
||||
msm_camera_put_clk_info_and_rates(pdev, &fd->clk_info,
|
||||
&fd->clk, &fd->clk_rates, fd->clk_rates_num, fd->clk_num);
|
||||
msm_camera_put_regulators(pdev, &fd->vdd, fd->num_reg);
|
||||
msm_camera_put_regulators(pdev, &fd->vdd_info, fd->num_reg);
|
||||
msm_fd_hw_release_mem_resources(fd);
|
||||
kfree(fd);
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ struct msm_fd_device {
|
|||
int irq_num;
|
||||
void __iomem *iomem_base[MSM_FD_IOMEM_LAST];
|
||||
struct msm_cam_clk_info *clk_info;
|
||||
struct regulator **vdd;
|
||||
struct msm_cam_regulator *vdd_info;
|
||||
int num_reg;
|
||||
struct resource *irq;
|
||||
|
||||
|
|
|
@ -838,7 +838,8 @@ int msm_fd_hw_get(struct msm_fd_device *fd, unsigned int clock_rate_idx)
|
|||
|
||||
if (fd->ref_count == 0) {
|
||||
ret =
|
||||
msm_camera_regulator_enable(fd->vdd, fd->num_reg, true);
|
||||
msm_camera_regulator_enable(fd->vdd_info,
|
||||
fd->num_reg, true);
|
||||
if (ret < 0) {
|
||||
dev_err(fd->dev, "Fail to enable vdd\n");
|
||||
goto error;
|
||||
|
@ -881,7 +882,7 @@ error_set_dt:
|
|||
fd->clk, fd->clk_num, false);
|
||||
error_clocks:
|
||||
error_bus_request:
|
||||
msm_camera_regulator_enable(fd->vdd, fd->num_reg, false);
|
||||
msm_camera_regulator_enable(fd->vdd_info, fd->num_reg, false);
|
||||
error:
|
||||
mutex_unlock(&fd->lock);
|
||||
return ret;
|
||||
|
@ -909,7 +910,7 @@ void msm_fd_hw_put(struct msm_fd_device *fd)
|
|||
msm_fd_hw_bus_request(fd, 0);
|
||||
msm_camera_clk_enable(&fd->pdev->dev, fd->clk_info,
|
||||
fd->clk, fd->clk_num, false);
|
||||
msm_camera_regulator_enable(fd->vdd, fd->num_reg, false);
|
||||
msm_camera_regulator_enable(fd->vdd_info, fd->num_reg, false);
|
||||
}
|
||||
mutex_unlock(&fd->lock);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ struct msm_jpeg_device {
|
|||
struct msm_cam_clk_info *jpeg_clk_info;
|
||||
size_t num_clk;
|
||||
int num_reg;
|
||||
struct regulator **jpeg_vdd;
|
||||
struct msm_cam_regulator *jpeg_vdd;
|
||||
uint32_t hw_version;
|
||||
|
||||
struct device *device;
|
||||
|
|
|
@ -1206,7 +1206,7 @@ static int jpegdma_probe(struct platform_device *pdev)
|
|||
goto error_mem_resources;
|
||||
|
||||
/* get all the regulators */
|
||||
ret = msm_camera_get_regulator_info(pdev, &jpegdma->vdd,
|
||||
ret = msm_camera_get_regulator_info(pdev, &jpegdma->dma_vdd,
|
||||
&jpegdma->num_reg);
|
||||
if (ret < 0)
|
||||
goto error_get_regulators;
|
||||
|
@ -1313,7 +1313,7 @@ error_qos_get:
|
|||
msm_camera_put_clk_info(pdev, &jpegdma->jpeg_clk_info,
|
||||
&jpegdma->clk, jpegdma->num_clk);
|
||||
error_get_clocks:
|
||||
msm_camera_put_regulators(pdev, &jpegdma->vdd,
|
||||
msm_camera_put_regulators(pdev, &jpegdma->dma_vdd,
|
||||
jpegdma->num_reg);
|
||||
error_get_regulators:
|
||||
msm_jpegdma_hw_release_mem_resources(jpegdma);
|
||||
|
@ -1341,7 +1341,7 @@ static int jpegdma_device_remove(struct platform_device *pdev)
|
|||
/* unregister bus client */
|
||||
msm_camera_unregister_bus_client(dma->bus_client);
|
||||
/* release all the regulators */
|
||||
msm_camera_put_regulators(dma->pdev, &dma->vdd,
|
||||
msm_camera_put_regulators(dma->pdev, &dma->dma_vdd,
|
||||
dma->num_reg);
|
||||
/* release all the clocks */
|
||||
msm_camera_put_clk_info(dma->pdev, &dma->jpeg_clk_info,
|
||||
|
|
|
@ -334,7 +334,7 @@ struct msm_jpegdma_device {
|
|||
void __iomem *iomem_base[MSM_JPEGDMA_IOMEM_LAST];
|
||||
|
||||
struct resource *irq;
|
||||
struct regulator **vdd;
|
||||
struct msm_cam_regulator *dma_vdd;
|
||||
int num_reg;
|
||||
|
||||
struct clk **clk;
|
||||
|
|
|
@ -1524,7 +1524,7 @@ int msm_jpegdma_hw_get_capabilities(struct msm_jpegdma_device *dma)
|
|||
mutex_lock(&dma->lock);
|
||||
|
||||
/* enable all the regulators */
|
||||
ret = msm_camera_regulator_enable(dma->vdd,
|
||||
ret = msm_camera_regulator_enable(dma->dma_vdd,
|
||||
dma->num_reg, true);
|
||||
if (ret < 0) {
|
||||
dev_err(dma->dev, "Fail to enable regulators\n");
|
||||
|
@ -1547,14 +1547,14 @@ int msm_jpegdma_hw_get_capabilities(struct msm_jpegdma_device *dma)
|
|||
dma->jpeg_clk_info, dma->clk,
|
||||
dma->num_clk, false);
|
||||
/* disable all the regulators */
|
||||
msm_camera_regulator_enable(dma->vdd, dma->num_reg, false);
|
||||
msm_camera_regulator_enable(dma->dma_vdd, dma->num_reg, false);
|
||||
|
||||
mutex_unlock(&dma->lock);
|
||||
|
||||
return 0;
|
||||
|
||||
error_clocks:
|
||||
msm_camera_regulator_enable(dma->vdd, dma->num_reg, false);
|
||||
msm_camera_regulator_enable(dma->dma_vdd, dma->num_reg, false);
|
||||
error_regulators_get:
|
||||
mutex_unlock(&dma->lock);
|
||||
return ret;
|
||||
|
@ -1577,7 +1577,7 @@ int msm_jpegdma_hw_get(struct msm_jpegdma_device *dma)
|
|||
|
||||
dev_dbg(dma->dev, "msm_jpegdma_hw_get E\n");
|
||||
/* enable all the regulators */
|
||||
ret = msm_camera_regulator_enable(dma->vdd,
|
||||
ret = msm_camera_regulator_enable(dma->dma_vdd,
|
||||
dma->num_reg, true);
|
||||
if (ret < 0) {
|
||||
dev_err(dma->dev, "Fail to enable regulators\n");
|
||||
|
@ -1620,7 +1620,7 @@ error_hw_reset:
|
|||
msm_camera_clk_enable(&dma->pdev->dev, dma->jpeg_clk_info,
|
||||
dma->clk, dma->num_clk, false);
|
||||
error_clocks:
|
||||
msm_camera_regulator_enable(dma->vdd, dma->num_reg, false);
|
||||
msm_camera_regulator_enable(dma->dma_vdd, dma->num_reg, false);
|
||||
error_regulators_get:
|
||||
mutex_unlock(&dma->lock);
|
||||
return ret;
|
||||
|
@ -1650,7 +1650,7 @@ void msm_jpegdma_hw_put(struct msm_jpegdma_device *dma)
|
|||
msm_camera_clk_enable(&dma->pdev->dev, dma->jpeg_clk_info,
|
||||
dma->clk, dma->num_clk, false);
|
||||
/* disable all the regulators */
|
||||
msm_camera_regulator_enable(dma->vdd, dma->num_reg, false);
|
||||
msm_camera_regulator_enable(dma->dma_vdd, dma->num_reg, false);
|
||||
}
|
||||
/* Reset clock rate, need to be updated on next processing */
|
||||
dma->active_clock_rate = -1;
|
||||
|
|
|
@ -210,7 +210,7 @@ struct cpp_device {
|
|||
struct clk **cpp_clk;
|
||||
struct msm_cam_clk_info *clk_info;
|
||||
size_t num_clks;
|
||||
struct regulator **cpp_vdd;
|
||||
struct msm_cam_regulator *cpp_vdd;
|
||||
int num_reg;
|
||||
struct mutex mutex;
|
||||
enum cpp_state state;
|
||||
|
|
Loading…
Add table
Reference in a new issue