154e991b5SMasahiro Yamada /* 254e991b5SMasahiro Yamada * Copyright (C) 2016 Socionext Inc. 354e991b5SMasahiro Yamada * Author: Masahiro Yamada <yamada.masahiro@socionext.com> 454e991b5SMasahiro Yamada * 554e991b5SMasahiro Yamada * This program is free software; you can redistribute it and/or modify 654e991b5SMasahiro Yamada * it under the terms of the GNU General Public License as published by 754e991b5SMasahiro Yamada * the Free Software Foundation; either version 2 of the License, or 854e991b5SMasahiro Yamada * (at your option) any later version. 954e991b5SMasahiro Yamada * 1054e991b5SMasahiro Yamada * This program is distributed in the hope that it will be useful, 1154e991b5SMasahiro Yamada * but WITHOUT ANY WARRANTY; without even the implied warranty of 1254e991b5SMasahiro Yamada * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1354e991b5SMasahiro Yamada * GNU General Public License for more details. 1454e991b5SMasahiro Yamada */ 1554e991b5SMasahiro Yamada 1654e991b5SMasahiro Yamada #include <linux/mfd/syscon.h> 1754e991b5SMasahiro Yamada #include <linux/module.h> 1854e991b5SMasahiro Yamada #include <linux/of.h> 1954e991b5SMasahiro Yamada #include <linux/of_device.h> 2054e991b5SMasahiro Yamada #include <linux/platform_device.h> 2154e991b5SMasahiro Yamada #include <linux/regmap.h> 2254e991b5SMasahiro Yamada #include <linux/reset-controller.h> 2354e991b5SMasahiro Yamada 2454e991b5SMasahiro Yamada struct uniphier_reset_data { 2554e991b5SMasahiro Yamada unsigned int id; 2654e991b5SMasahiro Yamada unsigned int reg; 2754e991b5SMasahiro Yamada unsigned int bit; 2854e991b5SMasahiro Yamada unsigned int flags; 2954e991b5SMasahiro Yamada #define UNIPHIER_RESET_ACTIVE_LOW BIT(0) 3054e991b5SMasahiro Yamada }; 3154e991b5SMasahiro Yamada 3254e991b5SMasahiro Yamada #define UNIPHIER_RESET_ID_END (unsigned int)(-1) 3354e991b5SMasahiro Yamada 3454e991b5SMasahiro Yamada #define UNIPHIER_RESET_END \ 3554e991b5SMasahiro Yamada { .id = UNIPHIER_RESET_ID_END } 3654e991b5SMasahiro Yamada 3754e991b5SMasahiro Yamada #define UNIPHIER_RESET(_id, _reg, _bit) \ 3854e991b5SMasahiro Yamada { \ 3954e991b5SMasahiro Yamada .id = (_id), \ 4054e991b5SMasahiro Yamada .reg = (_reg), \ 4154e991b5SMasahiro Yamada .bit = (_bit), \ 4254e991b5SMasahiro Yamada } 4354e991b5SMasahiro Yamada 4454e991b5SMasahiro Yamada #define UNIPHIER_RESETX(_id, _reg, _bit) \ 4554e991b5SMasahiro Yamada { \ 4654e991b5SMasahiro Yamada .id = (_id), \ 4754e991b5SMasahiro Yamada .reg = (_reg), \ 4854e991b5SMasahiro Yamada .bit = (_bit), \ 4954e991b5SMasahiro Yamada .flags = UNIPHIER_RESET_ACTIVE_LOW, \ 5054e991b5SMasahiro Yamada } 5154e991b5SMasahiro Yamada 5254e991b5SMasahiro Yamada /* System reset data */ 535281036aSMasahiro Yamada static const struct uniphier_reset_data uniphier_ld4_sys_reset_data[] = { 545281036aSMasahiro Yamada UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */ 555281036aSMasahiro Yamada UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC (Ether, HSC, MIO) */ 5654e991b5SMasahiro Yamada UNIPHIER_RESET_END, 5754e991b5SMasahiro Yamada }; 5854e991b5SMasahiro Yamada 59716adfe3SWei Yongjun static const struct uniphier_reset_data uniphier_pro4_sys_reset_data[] = { 605281036aSMasahiro Yamada UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */ 615281036aSMasahiro Yamada UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC (HSC, MIO, RLE) */ 62dec173ccSMasahiro Yamada UNIPHIER_RESETX(12, 0x2000, 6), /* GIO (Ether, SATA, USB3) */ 63dec173ccSMasahiro Yamada UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */ 64dec173ccSMasahiro Yamada UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */ 6554e991b5SMasahiro Yamada UNIPHIER_RESET_END, 6654e991b5SMasahiro Yamada }; 6754e991b5SMasahiro Yamada 68716adfe3SWei Yongjun static const struct uniphier_reset_data uniphier_pro5_sys_reset_data[] = { 695281036aSMasahiro Yamada UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */ 705281036aSMasahiro Yamada UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC (HSC) */ 71dec173ccSMasahiro Yamada UNIPHIER_RESETX(12, 0x2000, 6), /* GIO (PCIe, USB3) */ 72dec173ccSMasahiro Yamada UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */ 73dec173ccSMasahiro Yamada UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */ 7454e991b5SMasahiro Yamada UNIPHIER_RESET_END, 7554e991b5SMasahiro Yamada }; 7654e991b5SMasahiro Yamada 77716adfe3SWei Yongjun static const struct uniphier_reset_data uniphier_pxs2_sys_reset_data[] = { 785281036aSMasahiro Yamada UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */ 795281036aSMasahiro Yamada UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC (HSC, RLE) */ 80dec173ccSMasahiro Yamada UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */ 81dec173ccSMasahiro Yamada UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */ 8254e991b5SMasahiro Yamada UNIPHIER_RESETX(16, 0x2014, 4), /* USB30-PHY0 */ 8354e991b5SMasahiro Yamada UNIPHIER_RESETX(17, 0x2014, 0), /* USB30-PHY1 */ 8454e991b5SMasahiro Yamada UNIPHIER_RESETX(18, 0x2014, 2), /* USB30-PHY2 */ 8554e991b5SMasahiro Yamada UNIPHIER_RESETX(20, 0x2014, 5), /* USB31-PHY0 */ 8654e991b5SMasahiro Yamada UNIPHIER_RESETX(21, 0x2014, 1), /* USB31-PHY1 */ 8754e991b5SMasahiro Yamada UNIPHIER_RESETX(28, 0x2014, 12), /* SATA */ 8854e991b5SMasahiro Yamada UNIPHIER_RESET(29, 0x2014, 8), /* SATA-PHY (active high) */ 8954e991b5SMasahiro Yamada UNIPHIER_RESET_END, 9054e991b5SMasahiro Yamada }; 9154e991b5SMasahiro Yamada 92716adfe3SWei Yongjun static const struct uniphier_reset_data uniphier_ld11_sys_reset_data[] = { 93dec173ccSMasahiro Yamada UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */ 94dec173ccSMasahiro Yamada UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */ 95dec173ccSMasahiro Yamada UNIPHIER_RESETX(8, 0x200c, 8), /* STDMAC (HSC, MIO) */ 9694e10c22SKatsuhiro Suzuki UNIPHIER_RESETX(40, 0x2008, 0), /* AIO */ 9794e10c22SKatsuhiro Suzuki UNIPHIER_RESETX(41, 0x2008, 1), /* EVEA */ 98*0f195435SKatsuhiro Suzuki UNIPHIER_RESETX(42, 0x2010, 2), /* EXIV */ 9954e991b5SMasahiro Yamada UNIPHIER_RESET_END, 10054e991b5SMasahiro Yamada }; 10154e991b5SMasahiro Yamada 102716adfe3SWei Yongjun static const struct uniphier_reset_data uniphier_ld20_sys_reset_data[] = { 103dec173ccSMasahiro Yamada UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */ 104dec173ccSMasahiro Yamada UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */ 105dec173ccSMasahiro Yamada UNIPHIER_RESETX(8, 0x200c, 8), /* STDMAC (HSC) */ 106dec173ccSMasahiro Yamada UNIPHIER_RESETX(12, 0x200c, 5), /* GIO (PCIe, USB3) */ 10754e991b5SMasahiro Yamada UNIPHIER_RESETX(16, 0x200c, 12), /* USB30-PHY0 */ 10854e991b5SMasahiro Yamada UNIPHIER_RESETX(17, 0x200c, 13), /* USB30-PHY1 */ 10954e991b5SMasahiro Yamada UNIPHIER_RESETX(18, 0x200c, 14), /* USB30-PHY2 */ 11054e991b5SMasahiro Yamada UNIPHIER_RESETX(19, 0x200c, 15), /* USB30-PHY3 */ 11194e10c22SKatsuhiro Suzuki UNIPHIER_RESETX(40, 0x2008, 0), /* AIO */ 11294e10c22SKatsuhiro Suzuki UNIPHIER_RESETX(41, 0x2008, 1), /* EVEA */ 113*0f195435SKatsuhiro Suzuki UNIPHIER_RESETX(42, 0x2010, 2), /* EXIV */ 11454e991b5SMasahiro Yamada UNIPHIER_RESET_END, 11554e991b5SMasahiro Yamada }; 11654e991b5SMasahiro Yamada 11754e991b5SMasahiro Yamada /* Media I/O reset data */ 11854e991b5SMasahiro Yamada #define UNIPHIER_MIO_RESET_SD(id, ch) \ 11954e991b5SMasahiro Yamada UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 0) 12054e991b5SMasahiro Yamada 12154e991b5SMasahiro Yamada #define UNIPHIER_MIO_RESET_SD_BRIDGE(id, ch) \ 12254e991b5SMasahiro Yamada UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 26) 12354e991b5SMasahiro Yamada 12454e991b5SMasahiro Yamada #define UNIPHIER_MIO_RESET_EMMC_HW_RESET(id, ch) \ 12554e991b5SMasahiro Yamada UNIPHIER_RESETX((id), 0x80 + 0x200 * (ch), 0) 12654e991b5SMasahiro Yamada 12754e991b5SMasahiro Yamada #define UNIPHIER_MIO_RESET_USB2(id, ch) \ 12854e991b5SMasahiro Yamada UNIPHIER_RESETX((id), 0x114 + 0x200 * (ch), 0) 12954e991b5SMasahiro Yamada 13054e991b5SMasahiro Yamada #define UNIPHIER_MIO_RESET_USB2_BRIDGE(id, ch) \ 13154e991b5SMasahiro Yamada UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 24) 13254e991b5SMasahiro Yamada 13354e991b5SMasahiro Yamada #define UNIPHIER_MIO_RESET_DMAC(id) \ 13454e991b5SMasahiro Yamada UNIPHIER_RESETX((id), 0x110, 17) 13554e991b5SMasahiro Yamada 1365281036aSMasahiro Yamada static const struct uniphier_reset_data uniphier_ld4_mio_reset_data[] = { 13754e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_SD(0, 0), 13854e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_SD(1, 1), 13954e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_SD(2, 2), 14054e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_SD_BRIDGE(3, 0), 14154e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_SD_BRIDGE(4, 1), 14254e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_SD_BRIDGE(5, 2), 14354e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1), 14454e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_DMAC(7), 14554e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_USB2(8, 0), 14654e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_USB2(9, 1), 14754e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_USB2(10, 2), 14854e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_USB2_BRIDGE(12, 0), 14954e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_USB2_BRIDGE(13, 1), 15054e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_USB2_BRIDGE(14, 2), 15154e991b5SMasahiro Yamada UNIPHIER_RESET_END, 15254e991b5SMasahiro Yamada }; 15354e991b5SMasahiro Yamada 154716adfe3SWei Yongjun static const struct uniphier_reset_data uniphier_pro5_sd_reset_data[] = { 15554e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_SD(0, 0), 15654e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_SD(1, 1), 15754e991b5SMasahiro Yamada UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1), 15854e991b5SMasahiro Yamada UNIPHIER_RESET_END, 15954e991b5SMasahiro Yamada }; 16054e991b5SMasahiro Yamada 16154e991b5SMasahiro Yamada /* Peripheral reset data */ 16254e991b5SMasahiro Yamada #define UNIPHIER_PERI_RESET_UART(id, ch) \ 16354e991b5SMasahiro Yamada UNIPHIER_RESETX((id), 0x114, 19 + (ch)) 16454e991b5SMasahiro Yamada 16554e991b5SMasahiro Yamada #define UNIPHIER_PERI_RESET_I2C(id, ch) \ 16654e991b5SMasahiro Yamada UNIPHIER_RESETX((id), 0x114, 5 + (ch)) 16754e991b5SMasahiro Yamada 16854e991b5SMasahiro Yamada #define UNIPHIER_PERI_RESET_FI2C(id, ch) \ 16954e991b5SMasahiro Yamada UNIPHIER_RESETX((id), 0x114, 24 + (ch)) 17054e991b5SMasahiro Yamada 171716adfe3SWei Yongjun static const struct uniphier_reset_data uniphier_ld4_peri_reset_data[] = { 17254e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_UART(0, 0), 17354e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_UART(1, 1), 17454e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_UART(2, 2), 17554e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_UART(3, 3), 17654e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_I2C(4, 0), 17754e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_I2C(5, 1), 17854e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_I2C(6, 2), 17954e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_I2C(7, 3), 18054e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_I2C(8, 4), 18154e991b5SMasahiro Yamada UNIPHIER_RESET_END, 18254e991b5SMasahiro Yamada }; 18354e991b5SMasahiro Yamada 184716adfe3SWei Yongjun static const struct uniphier_reset_data uniphier_pro4_peri_reset_data[] = { 18554e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_UART(0, 0), 18654e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_UART(1, 1), 18754e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_UART(2, 2), 18854e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_UART(3, 3), 18954e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_FI2C(4, 0), 19054e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_FI2C(5, 1), 19154e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_FI2C(6, 2), 19254e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_FI2C(7, 3), 19354e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_FI2C(8, 4), 19454e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_FI2C(9, 5), 19554e991b5SMasahiro Yamada UNIPHIER_PERI_RESET_FI2C(10, 6), 19654e991b5SMasahiro Yamada UNIPHIER_RESET_END, 19754e991b5SMasahiro Yamada }; 19854e991b5SMasahiro Yamada 19954e991b5SMasahiro Yamada /* core implementaton */ 20054e991b5SMasahiro Yamada struct uniphier_reset_priv { 20154e991b5SMasahiro Yamada struct reset_controller_dev rcdev; 20254e991b5SMasahiro Yamada struct device *dev; 20354e991b5SMasahiro Yamada struct regmap *regmap; 20454e991b5SMasahiro Yamada const struct uniphier_reset_data *data; 20554e991b5SMasahiro Yamada }; 20654e991b5SMasahiro Yamada 20754e991b5SMasahiro Yamada #define to_uniphier_reset_priv(_rcdev) \ 20854e991b5SMasahiro Yamada container_of(_rcdev, struct uniphier_reset_priv, rcdev) 20954e991b5SMasahiro Yamada 21054e991b5SMasahiro Yamada static int uniphier_reset_update(struct reset_controller_dev *rcdev, 21154e991b5SMasahiro Yamada unsigned long id, int assert) 21254e991b5SMasahiro Yamada { 21354e991b5SMasahiro Yamada struct uniphier_reset_priv *priv = to_uniphier_reset_priv(rcdev); 21454e991b5SMasahiro Yamada const struct uniphier_reset_data *p; 21554e991b5SMasahiro Yamada 21654e991b5SMasahiro Yamada for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) { 21754e991b5SMasahiro Yamada unsigned int mask, val; 21854e991b5SMasahiro Yamada 21954e991b5SMasahiro Yamada if (p->id != id) 22054e991b5SMasahiro Yamada continue; 22154e991b5SMasahiro Yamada 22254e991b5SMasahiro Yamada mask = BIT(p->bit); 22354e991b5SMasahiro Yamada 22454e991b5SMasahiro Yamada if (assert) 22554e991b5SMasahiro Yamada val = mask; 22654e991b5SMasahiro Yamada else 22754e991b5SMasahiro Yamada val = ~mask; 22854e991b5SMasahiro Yamada 22954e991b5SMasahiro Yamada if (p->flags & UNIPHIER_RESET_ACTIVE_LOW) 23054e991b5SMasahiro Yamada val = ~val; 23154e991b5SMasahiro Yamada 23254e991b5SMasahiro Yamada return regmap_write_bits(priv->regmap, p->reg, mask, val); 23354e991b5SMasahiro Yamada } 23454e991b5SMasahiro Yamada 23554e991b5SMasahiro Yamada dev_err(priv->dev, "reset_id=%lu was not handled\n", id); 23654e991b5SMasahiro Yamada return -EINVAL; 23754e991b5SMasahiro Yamada } 23854e991b5SMasahiro Yamada 23954e991b5SMasahiro Yamada static int uniphier_reset_assert(struct reset_controller_dev *rcdev, 24054e991b5SMasahiro Yamada unsigned long id) 24154e991b5SMasahiro Yamada { 24254e991b5SMasahiro Yamada return uniphier_reset_update(rcdev, id, 1); 24354e991b5SMasahiro Yamada } 24454e991b5SMasahiro Yamada 24554e991b5SMasahiro Yamada static int uniphier_reset_deassert(struct reset_controller_dev *rcdev, 24654e991b5SMasahiro Yamada unsigned long id) 24754e991b5SMasahiro Yamada { 24854e991b5SMasahiro Yamada return uniphier_reset_update(rcdev, id, 0); 24954e991b5SMasahiro Yamada } 25054e991b5SMasahiro Yamada 25154e991b5SMasahiro Yamada static int uniphier_reset_status(struct reset_controller_dev *rcdev, 25254e991b5SMasahiro Yamada unsigned long id) 25354e991b5SMasahiro Yamada { 25454e991b5SMasahiro Yamada struct uniphier_reset_priv *priv = to_uniphier_reset_priv(rcdev); 25554e991b5SMasahiro Yamada const struct uniphier_reset_data *p; 25654e991b5SMasahiro Yamada 25754e991b5SMasahiro Yamada for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) { 25854e991b5SMasahiro Yamada unsigned int val; 25954e991b5SMasahiro Yamada int ret, asserted; 26054e991b5SMasahiro Yamada 26154e991b5SMasahiro Yamada if (p->id != id) 26254e991b5SMasahiro Yamada continue; 26354e991b5SMasahiro Yamada 26454e991b5SMasahiro Yamada ret = regmap_read(priv->regmap, p->reg, &val); 26554e991b5SMasahiro Yamada if (ret) 26654e991b5SMasahiro Yamada return ret; 26754e991b5SMasahiro Yamada 26854e991b5SMasahiro Yamada asserted = !!(val & BIT(p->bit)); 26954e991b5SMasahiro Yamada 27054e991b5SMasahiro Yamada if (p->flags & UNIPHIER_RESET_ACTIVE_LOW) 27154e991b5SMasahiro Yamada asserted = !asserted; 27254e991b5SMasahiro Yamada 27354e991b5SMasahiro Yamada return asserted; 27454e991b5SMasahiro Yamada } 27554e991b5SMasahiro Yamada 27654e991b5SMasahiro Yamada dev_err(priv->dev, "reset_id=%lu was not found\n", id); 27754e991b5SMasahiro Yamada return -EINVAL; 27854e991b5SMasahiro Yamada } 27954e991b5SMasahiro Yamada 28054e991b5SMasahiro Yamada static const struct reset_control_ops uniphier_reset_ops = { 28154e991b5SMasahiro Yamada .assert = uniphier_reset_assert, 28254e991b5SMasahiro Yamada .deassert = uniphier_reset_deassert, 28354e991b5SMasahiro Yamada .status = uniphier_reset_status, 28454e991b5SMasahiro Yamada }; 28554e991b5SMasahiro Yamada 28654e991b5SMasahiro Yamada static int uniphier_reset_probe(struct platform_device *pdev) 28754e991b5SMasahiro Yamada { 28854e991b5SMasahiro Yamada struct device *dev = &pdev->dev; 28954e991b5SMasahiro Yamada struct uniphier_reset_priv *priv; 29054e991b5SMasahiro Yamada const struct uniphier_reset_data *p, *data; 29154e991b5SMasahiro Yamada struct regmap *regmap; 29254e991b5SMasahiro Yamada struct device_node *parent; 29354e991b5SMasahiro Yamada unsigned int nr_resets = 0; 29454e991b5SMasahiro Yamada 29554e991b5SMasahiro Yamada data = of_device_get_match_data(dev); 29654e991b5SMasahiro Yamada if (WARN_ON(!data)) 29754e991b5SMasahiro Yamada return -EINVAL; 29854e991b5SMasahiro Yamada 29954e991b5SMasahiro Yamada parent = of_get_parent(dev->of_node); /* parent should be syscon node */ 30054e991b5SMasahiro Yamada regmap = syscon_node_to_regmap(parent); 30154e991b5SMasahiro Yamada of_node_put(parent); 30254e991b5SMasahiro Yamada if (IS_ERR(regmap)) { 30354e991b5SMasahiro Yamada dev_err(dev, "failed to get regmap (error %ld)\n", 30454e991b5SMasahiro Yamada PTR_ERR(regmap)); 30554e991b5SMasahiro Yamada return PTR_ERR(regmap); 30654e991b5SMasahiro Yamada } 30754e991b5SMasahiro Yamada 30854e991b5SMasahiro Yamada priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 30954e991b5SMasahiro Yamada if (!priv) 31054e991b5SMasahiro Yamada return -ENOMEM; 31154e991b5SMasahiro Yamada 31254e991b5SMasahiro Yamada for (p = data; p->id != UNIPHIER_RESET_ID_END; p++) 31354e991b5SMasahiro Yamada nr_resets = max(nr_resets, p->id + 1); 31454e991b5SMasahiro Yamada 31554e991b5SMasahiro Yamada priv->rcdev.ops = &uniphier_reset_ops; 31654e991b5SMasahiro Yamada priv->rcdev.owner = dev->driver->owner; 31754e991b5SMasahiro Yamada priv->rcdev.of_node = dev->of_node; 31854e991b5SMasahiro Yamada priv->rcdev.nr_resets = nr_resets; 31954e991b5SMasahiro Yamada priv->dev = dev; 32054e991b5SMasahiro Yamada priv->regmap = regmap; 32154e991b5SMasahiro Yamada priv->data = data; 32254e991b5SMasahiro Yamada 32354e991b5SMasahiro Yamada return devm_reset_controller_register(&pdev->dev, &priv->rcdev); 32454e991b5SMasahiro Yamada } 32554e991b5SMasahiro Yamada 32654e991b5SMasahiro Yamada static const struct of_device_id uniphier_reset_match[] = { 32754e991b5SMasahiro Yamada /* System reset */ 32854e991b5SMasahiro Yamada { 32954e991b5SMasahiro Yamada .compatible = "socionext,uniphier-ld4-reset", 3305281036aSMasahiro Yamada .data = uniphier_ld4_sys_reset_data, 33154e991b5SMasahiro Yamada }, 33254e991b5SMasahiro Yamada { 33354e991b5SMasahiro Yamada .compatible = "socionext,uniphier-pro4-reset", 33454e991b5SMasahiro Yamada .data = uniphier_pro4_sys_reset_data, 33554e991b5SMasahiro Yamada }, 33654e991b5SMasahiro Yamada { 33754e991b5SMasahiro Yamada .compatible = "socionext,uniphier-sld8-reset", 3385281036aSMasahiro Yamada .data = uniphier_ld4_sys_reset_data, 33954e991b5SMasahiro Yamada }, 34054e991b5SMasahiro Yamada { 34154e991b5SMasahiro Yamada .compatible = "socionext,uniphier-pro5-reset", 34254e991b5SMasahiro Yamada .data = uniphier_pro5_sys_reset_data, 34354e991b5SMasahiro Yamada }, 34454e991b5SMasahiro Yamada { 34554e991b5SMasahiro Yamada .compatible = "socionext,uniphier-pxs2-reset", 34654e991b5SMasahiro Yamada .data = uniphier_pxs2_sys_reset_data, 34754e991b5SMasahiro Yamada }, 34854e991b5SMasahiro Yamada { 34954e991b5SMasahiro Yamada .compatible = "socionext,uniphier-ld11-reset", 35054e991b5SMasahiro Yamada .data = uniphier_ld11_sys_reset_data, 35154e991b5SMasahiro Yamada }, 35254e991b5SMasahiro Yamada { 35354e991b5SMasahiro Yamada .compatible = "socionext,uniphier-ld20-reset", 35454e991b5SMasahiro Yamada .data = uniphier_ld20_sys_reset_data, 35554e991b5SMasahiro Yamada }, 35619eb4a47SMasahiro Yamada /* Media I/O reset, SD reset */ 35754e991b5SMasahiro Yamada { 35854e991b5SMasahiro Yamada .compatible = "socionext,uniphier-ld4-mio-reset", 3595281036aSMasahiro Yamada .data = uniphier_ld4_mio_reset_data, 36054e991b5SMasahiro Yamada }, 36154e991b5SMasahiro Yamada { 36254e991b5SMasahiro Yamada .compatible = "socionext,uniphier-pro4-mio-reset", 3635281036aSMasahiro Yamada .data = uniphier_ld4_mio_reset_data, 36454e991b5SMasahiro Yamada }, 36554e991b5SMasahiro Yamada { 36654e991b5SMasahiro Yamada .compatible = "socionext,uniphier-sld8-mio-reset", 3675281036aSMasahiro Yamada .data = uniphier_ld4_mio_reset_data, 36854e991b5SMasahiro Yamada }, 36954e991b5SMasahiro Yamada { 37019eb4a47SMasahiro Yamada .compatible = "socionext,uniphier-pro5-sd-reset", 37119eb4a47SMasahiro Yamada .data = uniphier_pro5_sd_reset_data, 37254e991b5SMasahiro Yamada }, 37354e991b5SMasahiro Yamada { 37419eb4a47SMasahiro Yamada .compatible = "socionext,uniphier-pxs2-sd-reset", 37519eb4a47SMasahiro Yamada .data = uniphier_pro5_sd_reset_data, 37654e991b5SMasahiro Yamada }, 37754e991b5SMasahiro Yamada { 37854e991b5SMasahiro Yamada .compatible = "socionext,uniphier-ld11-mio-reset", 3795281036aSMasahiro Yamada .data = uniphier_ld4_mio_reset_data, 38054e991b5SMasahiro Yamada }, 38154e991b5SMasahiro Yamada { 38288a7f523SMasahiro Yamada .compatible = "socionext,uniphier-ld11-sd-reset", 38388a7f523SMasahiro Yamada .data = uniphier_pro5_sd_reset_data, 38488a7f523SMasahiro Yamada }, 38588a7f523SMasahiro Yamada { 38619eb4a47SMasahiro Yamada .compatible = "socionext,uniphier-ld20-sd-reset", 38719eb4a47SMasahiro Yamada .data = uniphier_pro5_sd_reset_data, 38854e991b5SMasahiro Yamada }, 38954e991b5SMasahiro Yamada /* Peripheral reset */ 39054e991b5SMasahiro Yamada { 39154e991b5SMasahiro Yamada .compatible = "socionext,uniphier-ld4-peri-reset", 39254e991b5SMasahiro Yamada .data = uniphier_ld4_peri_reset_data, 39354e991b5SMasahiro Yamada }, 39454e991b5SMasahiro Yamada { 39554e991b5SMasahiro Yamada .compatible = "socionext,uniphier-pro4-peri-reset", 39654e991b5SMasahiro Yamada .data = uniphier_pro4_peri_reset_data, 39754e991b5SMasahiro Yamada }, 39854e991b5SMasahiro Yamada { 39954e991b5SMasahiro Yamada .compatible = "socionext,uniphier-sld8-peri-reset", 40054e991b5SMasahiro Yamada .data = uniphier_ld4_peri_reset_data, 40154e991b5SMasahiro Yamada }, 40254e991b5SMasahiro Yamada { 40354e991b5SMasahiro Yamada .compatible = "socionext,uniphier-pro5-peri-reset", 40454e991b5SMasahiro Yamada .data = uniphier_pro4_peri_reset_data, 40554e991b5SMasahiro Yamada }, 40654e991b5SMasahiro Yamada { 40754e991b5SMasahiro Yamada .compatible = "socionext,uniphier-pxs2-peri-reset", 40854e991b5SMasahiro Yamada .data = uniphier_pro4_peri_reset_data, 40954e991b5SMasahiro Yamada }, 41054e991b5SMasahiro Yamada { 41154e991b5SMasahiro Yamada .compatible = "socionext,uniphier-ld11-peri-reset", 41254e991b5SMasahiro Yamada .data = uniphier_pro4_peri_reset_data, 41354e991b5SMasahiro Yamada }, 41454e991b5SMasahiro Yamada { 41554e991b5SMasahiro Yamada .compatible = "socionext,uniphier-ld20-peri-reset", 41654e991b5SMasahiro Yamada .data = uniphier_pro4_peri_reset_data, 41754e991b5SMasahiro Yamada }, 41854e991b5SMasahiro Yamada { /* sentinel */ } 41954e991b5SMasahiro Yamada }; 42054e991b5SMasahiro Yamada MODULE_DEVICE_TABLE(of, uniphier_reset_match); 42154e991b5SMasahiro Yamada 42254e991b5SMasahiro Yamada static struct platform_driver uniphier_reset_driver = { 42354e991b5SMasahiro Yamada .probe = uniphier_reset_probe, 42454e991b5SMasahiro Yamada .driver = { 42554e991b5SMasahiro Yamada .name = "uniphier-reset", 42654e991b5SMasahiro Yamada .of_match_table = uniphier_reset_match, 42754e991b5SMasahiro Yamada }, 42854e991b5SMasahiro Yamada }; 42954e991b5SMasahiro Yamada module_platform_driver(uniphier_reset_driver); 43054e991b5SMasahiro Yamada 43154e991b5SMasahiro Yamada MODULE_AUTHOR("Masahiro Yamada <yamada.masahiro@socionext.com>"); 43254e991b5SMasahiro Yamada MODULE_DESCRIPTION("UniPhier Reset Controller Driver"); 43354e991b5SMasahiro Yamada MODULE_LICENSE("GPL"); 434