0001
0002
0003
0004
0005
0006
0007 #include <linux/clk.h>
0008 #include <linux/module.h>
0009 #include <linux/of_device.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/reset.h>
0012 #include <linux/reset/reset-simple.h>
0013
0014 #define MAX_CLKS 2
0015 #define MAX_RSTS 2
0016
0017 struct uniphier_glue_reset_soc_data {
0018 int nclks;
0019 const char * const *clock_names;
0020 int nrsts;
0021 const char * const *reset_names;
0022 };
0023
0024 struct uniphier_glue_reset_priv {
0025 struct clk_bulk_data clk[MAX_CLKS];
0026 struct reset_control_bulk_data rst[MAX_RSTS];
0027 struct reset_simple_data rdata;
0028 const struct uniphier_glue_reset_soc_data *data;
0029 };
0030
0031 static void uniphier_clk_disable(void *_priv)
0032 {
0033 struct uniphier_glue_reset_priv *priv = _priv;
0034
0035 clk_bulk_disable_unprepare(priv->data->nclks, priv->clk);
0036 }
0037
0038 static void uniphier_rst_assert(void *_priv)
0039 {
0040 struct uniphier_glue_reset_priv *priv = _priv;
0041
0042 reset_control_bulk_assert(priv->data->nrsts, priv->rst);
0043 }
0044
0045 static int uniphier_glue_reset_probe(struct platform_device *pdev)
0046 {
0047 struct device *dev = &pdev->dev;
0048 struct uniphier_glue_reset_priv *priv;
0049 struct resource *res;
0050 resource_size_t size;
0051 int i, ret;
0052
0053 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
0054 if (!priv)
0055 return -ENOMEM;
0056
0057 priv->data = of_device_get_match_data(dev);
0058 if (WARN_ON(!priv->data || priv->data->nclks > MAX_CLKS ||
0059 priv->data->nrsts > MAX_RSTS))
0060 return -EINVAL;
0061
0062 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0063 size = resource_size(res);
0064 priv->rdata.membase = devm_ioremap_resource(dev, res);
0065 if (IS_ERR(priv->rdata.membase))
0066 return PTR_ERR(priv->rdata.membase);
0067
0068 for (i = 0; i < priv->data->nclks; i++)
0069 priv->clk[i].id = priv->data->clock_names[i];
0070 ret = devm_clk_bulk_get(dev, priv->data->nclks, priv->clk);
0071 if (ret)
0072 return ret;
0073
0074 for (i = 0; i < priv->data->nrsts; i++)
0075 priv->rst[i].id = priv->data->reset_names[i];
0076 ret = devm_reset_control_bulk_get_shared(dev, priv->data->nrsts,
0077 priv->rst);
0078 if (ret)
0079 return ret;
0080
0081 ret = clk_bulk_prepare_enable(priv->data->nclks, priv->clk);
0082 if (ret)
0083 return ret;
0084
0085 ret = devm_add_action_or_reset(dev, uniphier_clk_disable, priv);
0086 if (ret)
0087 return ret;
0088
0089 ret = reset_control_bulk_deassert(priv->data->nrsts, priv->rst);
0090 if (ret)
0091 return ret;
0092
0093 ret = devm_add_action_or_reset(dev, uniphier_rst_assert, priv);
0094 if (ret)
0095 return ret;
0096
0097 spin_lock_init(&priv->rdata.lock);
0098 priv->rdata.rcdev.owner = THIS_MODULE;
0099 priv->rdata.rcdev.nr_resets = size * BITS_PER_BYTE;
0100 priv->rdata.rcdev.ops = &reset_simple_ops;
0101 priv->rdata.rcdev.of_node = dev->of_node;
0102 priv->rdata.active_low = true;
0103
0104 platform_set_drvdata(pdev, priv);
0105
0106 return devm_reset_controller_register(dev, &priv->rdata.rcdev);
0107 }
0108
0109 static const char * const uniphier_pro4_clock_reset_names[] = {
0110 "gio", "link",
0111 };
0112
0113 static const struct uniphier_glue_reset_soc_data uniphier_pro4_data = {
0114 .nclks = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
0115 .clock_names = uniphier_pro4_clock_reset_names,
0116 .nrsts = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
0117 .reset_names = uniphier_pro4_clock_reset_names,
0118 };
0119
0120 static const char * const uniphier_pxs2_clock_reset_names[] = {
0121 "link",
0122 };
0123
0124 static const struct uniphier_glue_reset_soc_data uniphier_pxs2_data = {
0125 .nclks = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
0126 .clock_names = uniphier_pxs2_clock_reset_names,
0127 .nrsts = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
0128 .reset_names = uniphier_pxs2_clock_reset_names,
0129 };
0130
0131 static const struct of_device_id uniphier_glue_reset_match[] = {
0132 {
0133 .compatible = "socionext,uniphier-pro4-usb3-reset",
0134 .data = &uniphier_pro4_data,
0135 },
0136 {
0137 .compatible = "socionext,uniphier-pro5-usb3-reset",
0138 .data = &uniphier_pro4_data,
0139 },
0140 {
0141 .compatible = "socionext,uniphier-pxs2-usb3-reset",
0142 .data = &uniphier_pxs2_data,
0143 },
0144 {
0145 .compatible = "socionext,uniphier-ld20-usb3-reset",
0146 .data = &uniphier_pxs2_data,
0147 },
0148 {
0149 .compatible = "socionext,uniphier-pxs3-usb3-reset",
0150 .data = &uniphier_pxs2_data,
0151 },
0152 {
0153 .compatible = "socionext,uniphier-nx1-usb3-reset",
0154 .data = &uniphier_pxs2_data,
0155 },
0156 {
0157 .compatible = "socionext,uniphier-pro4-ahci-reset",
0158 .data = &uniphier_pro4_data,
0159 },
0160 {
0161 .compatible = "socionext,uniphier-pxs2-ahci-reset",
0162 .data = &uniphier_pxs2_data,
0163 },
0164 {
0165 .compatible = "socionext,uniphier-pxs3-ahci-reset",
0166 .data = &uniphier_pxs2_data,
0167 },
0168 { }
0169 };
0170 MODULE_DEVICE_TABLE(of, uniphier_glue_reset_match);
0171
0172 static struct platform_driver uniphier_glue_reset_driver = {
0173 .probe = uniphier_glue_reset_probe,
0174 .driver = {
0175 .name = "uniphier-glue-reset",
0176 .of_match_table = uniphier_glue_reset_match,
0177 },
0178 };
0179 module_platform_driver(uniphier_glue_reset_driver);
0180
0181 MODULE_AUTHOR("Kunihiko Hayashi <hayashi.kunihiko@socionext.com>");
0182 MODULE_DESCRIPTION("UniPhier Glue layer reset driver");
0183 MODULE_LICENSE("GPL");