18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2012 John Crispin <john@phrozen.org> 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/slab.h> 88c2ecf20Sopenharmony_ci#include <linux/init.h> 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/types.h> 118c2ecf20Sopenharmony_ci#include <linux/of_platform.h> 128c2ecf20Sopenharmony_ci#include <linux/mutex.h> 138c2ecf20Sopenharmony_ci#include <linux/gpio/driver.h> 148c2ecf20Sopenharmony_ci#include <linux/io.h> 158c2ecf20Sopenharmony_ci#include <linux/clk.h> 168c2ecf20Sopenharmony_ci#include <linux/err.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* 198c2ecf20Sopenharmony_ci * The Serial To Parallel (STP) is found on MIPS based Lantiq socs. It is a 208c2ecf20Sopenharmony_ci * peripheral controller used to drive external shift register cascades. At most 218c2ecf20Sopenharmony_ci * 3 groups of 8 bits can be driven. The hardware is able to allow the DSL modem 228c2ecf20Sopenharmony_ci * to drive the 2 LSBs of the cascade automatically. 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* control register 0 */ 268c2ecf20Sopenharmony_ci#define XWAY_STP_CON0 0x00 278c2ecf20Sopenharmony_ci/* control register 1 */ 288c2ecf20Sopenharmony_ci#define XWAY_STP_CON1 0x04 298c2ecf20Sopenharmony_ci/* data register 0 */ 308c2ecf20Sopenharmony_ci#define XWAY_STP_CPU0 0x08 318c2ecf20Sopenharmony_ci/* data register 1 */ 328c2ecf20Sopenharmony_ci#define XWAY_STP_CPU1 0x0C 338c2ecf20Sopenharmony_ci/* access register */ 348c2ecf20Sopenharmony_ci#define XWAY_STP_AR 0x10 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/* software or hardware update select bit */ 378c2ecf20Sopenharmony_ci#define XWAY_STP_CON_SWU BIT(31) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* automatic update rates */ 408c2ecf20Sopenharmony_ci#define XWAY_STP_2HZ 0 418c2ecf20Sopenharmony_ci#define XWAY_STP_4HZ BIT(23) 428c2ecf20Sopenharmony_ci#define XWAY_STP_8HZ BIT(24) 438c2ecf20Sopenharmony_ci#define XWAY_STP_10HZ (BIT(24) | BIT(23)) 448c2ecf20Sopenharmony_ci#define XWAY_STP_SPEED_MASK (BIT(23) | BIT(24) | BIT(25) | BIT(26) | BIT(27)) 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define XWAY_STP_FPIS_VALUE BIT(21) 478c2ecf20Sopenharmony_ci#define XWAY_STP_FPIS_MASK (BIT(20) | BIT(21)) 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* clock source for automatic update */ 508c2ecf20Sopenharmony_ci#define XWAY_STP_UPD_FPI BIT(31) 518c2ecf20Sopenharmony_ci#define XWAY_STP_UPD_MASK (BIT(31) | BIT(30)) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/* let the adsl core drive the 2 LSBs */ 548c2ecf20Sopenharmony_ci#define XWAY_STP_ADSL_SHIFT 24 558c2ecf20Sopenharmony_ci#define XWAY_STP_ADSL_MASK 0x3 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/* 2 groups of 3 bits can be driven by the phys */ 588c2ecf20Sopenharmony_ci#define XWAY_STP_PHY_MASK 0x7 598c2ecf20Sopenharmony_ci#define XWAY_STP_PHY1_SHIFT 27 608c2ecf20Sopenharmony_ci#define XWAY_STP_PHY2_SHIFT 3 618c2ecf20Sopenharmony_ci#define XWAY_STP_PHY3_SHIFT 6 628c2ecf20Sopenharmony_ci#define XWAY_STP_PHY4_SHIFT 15 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* STP has 3 groups of 8 bits */ 658c2ecf20Sopenharmony_ci#define XWAY_STP_GROUP0 BIT(0) 668c2ecf20Sopenharmony_ci#define XWAY_STP_GROUP1 BIT(1) 678c2ecf20Sopenharmony_ci#define XWAY_STP_GROUP2 BIT(2) 688c2ecf20Sopenharmony_ci#define XWAY_STP_GROUP_MASK (0x7) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* Edge configuration bits */ 718c2ecf20Sopenharmony_ci#define XWAY_STP_FALLING BIT(26) 728c2ecf20Sopenharmony_ci#define XWAY_STP_EDGE_MASK BIT(26) 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#define xway_stp_r32(m, reg) __raw_readl(m + reg) 758c2ecf20Sopenharmony_ci#define xway_stp_w32(m, val, reg) __raw_writel(val, m + reg) 768c2ecf20Sopenharmony_ci#define xway_stp_w32_mask(m, clear, set, reg) \ 778c2ecf20Sopenharmony_ci xway_stp_w32(m, (xway_stp_r32(m, reg) & ~(clear)) | (set), reg) 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistruct xway_stp { 808c2ecf20Sopenharmony_ci struct gpio_chip gc; 818c2ecf20Sopenharmony_ci void __iomem *virt; 828c2ecf20Sopenharmony_ci u32 edge; /* rising or falling edge triggered shift register */ 838c2ecf20Sopenharmony_ci u32 shadow; /* shadow the shift registers state */ 848c2ecf20Sopenharmony_ci u8 groups; /* we can drive 1-3 groups of 8bit each */ 858c2ecf20Sopenharmony_ci u8 dsl; /* the 2 LSBs can be driven by the dsl core */ 868c2ecf20Sopenharmony_ci u8 phy1; /* 3 bits can be driven by phy1 */ 878c2ecf20Sopenharmony_ci u8 phy2; /* 3 bits can be driven by phy2 */ 888c2ecf20Sopenharmony_ci u8 phy3; /* 3 bits can be driven by phy3 */ 898c2ecf20Sopenharmony_ci u8 phy4; /* 3 bits can be driven by phy4 */ 908c2ecf20Sopenharmony_ci u8 reserved; /* mask out the hw driven bits in gpio_request */ 918c2ecf20Sopenharmony_ci}; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/** 948c2ecf20Sopenharmony_ci * xway_stp_get() - gpio_chip->get - get gpios. 958c2ecf20Sopenharmony_ci * @gc: Pointer to gpio_chip device structure. 968c2ecf20Sopenharmony_ci * @gpio: GPIO signal number. 978c2ecf20Sopenharmony_ci * 988c2ecf20Sopenharmony_ci * Gets the shadow value. 998c2ecf20Sopenharmony_ci */ 1008c2ecf20Sopenharmony_cistatic int xway_stp_get(struct gpio_chip *gc, unsigned int gpio) 1018c2ecf20Sopenharmony_ci{ 1028c2ecf20Sopenharmony_ci struct xway_stp *chip = gpiochip_get_data(gc); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci return (xway_stp_r32(chip->virt, XWAY_STP_CPU0) & BIT(gpio)); 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci/** 1088c2ecf20Sopenharmony_ci * xway_stp_set() - gpio_chip->set - set gpios. 1098c2ecf20Sopenharmony_ci * @gc: Pointer to gpio_chip device structure. 1108c2ecf20Sopenharmony_ci * @gpio: GPIO signal number. 1118c2ecf20Sopenharmony_ci * @val: Value to be written to specified signal. 1128c2ecf20Sopenharmony_ci * 1138c2ecf20Sopenharmony_ci * Set the shadow value and call ltq_ebu_apply. 1148c2ecf20Sopenharmony_ci */ 1158c2ecf20Sopenharmony_cistatic void xway_stp_set(struct gpio_chip *gc, unsigned gpio, int val) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci struct xway_stp *chip = gpiochip_get_data(gc); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci if (val) 1208c2ecf20Sopenharmony_ci chip->shadow |= BIT(gpio); 1218c2ecf20Sopenharmony_ci else 1228c2ecf20Sopenharmony_ci chip->shadow &= ~BIT(gpio); 1238c2ecf20Sopenharmony_ci xway_stp_w32(chip->virt, chip->shadow, XWAY_STP_CPU0); 1248c2ecf20Sopenharmony_ci if (!chip->reserved) 1258c2ecf20Sopenharmony_ci xway_stp_w32_mask(chip->virt, 0, XWAY_STP_CON_SWU, XWAY_STP_CON0); 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci/** 1298c2ecf20Sopenharmony_ci * xway_stp_dir_out() - gpio_chip->dir_out - set gpio direction. 1308c2ecf20Sopenharmony_ci * @gc: Pointer to gpio_chip device structure. 1318c2ecf20Sopenharmony_ci * @gpio: GPIO signal number. 1328c2ecf20Sopenharmony_ci * @val: Value to be written to specified signal. 1338c2ecf20Sopenharmony_ci * 1348c2ecf20Sopenharmony_ci * Same as xway_stp_set, always returns 0. 1358c2ecf20Sopenharmony_ci */ 1368c2ecf20Sopenharmony_cistatic int xway_stp_dir_out(struct gpio_chip *gc, unsigned gpio, int val) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci xway_stp_set(gc, gpio, val); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci return 0; 1418c2ecf20Sopenharmony_ci} 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci/** 1448c2ecf20Sopenharmony_ci * xway_stp_request() - gpio_chip->request 1458c2ecf20Sopenharmony_ci * @gc: Pointer to gpio_chip device structure. 1468c2ecf20Sopenharmony_ci * @gpio: GPIO signal number. 1478c2ecf20Sopenharmony_ci * 1488c2ecf20Sopenharmony_ci * We mask out the HW driven pins 1498c2ecf20Sopenharmony_ci */ 1508c2ecf20Sopenharmony_cistatic int xway_stp_request(struct gpio_chip *gc, unsigned gpio) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci struct xway_stp *chip = gpiochip_get_data(gc); 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci if ((gpio < 8) && (chip->reserved & BIT(gpio))) { 1558c2ecf20Sopenharmony_ci dev_err(gc->parent, "GPIO %d is driven by hardware\n", gpio); 1568c2ecf20Sopenharmony_ci return -ENODEV; 1578c2ecf20Sopenharmony_ci } 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci return 0; 1608c2ecf20Sopenharmony_ci} 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci/** 1638c2ecf20Sopenharmony_ci * xway_stp_hw_init() - Configure the STP unit and enable the clock gate 1648c2ecf20Sopenharmony_ci * @chip: Pointer to the xway_stp chip structure 1658c2ecf20Sopenharmony_ci */ 1668c2ecf20Sopenharmony_cistatic void xway_stp_hw_init(struct xway_stp *chip) 1678c2ecf20Sopenharmony_ci{ 1688c2ecf20Sopenharmony_ci /* sane defaults */ 1698c2ecf20Sopenharmony_ci xway_stp_w32(chip->virt, 0, XWAY_STP_AR); 1708c2ecf20Sopenharmony_ci xway_stp_w32(chip->virt, 0, XWAY_STP_CPU0); 1718c2ecf20Sopenharmony_ci xway_stp_w32(chip->virt, 0, XWAY_STP_CPU1); 1728c2ecf20Sopenharmony_ci xway_stp_w32(chip->virt, XWAY_STP_CON_SWU, XWAY_STP_CON0); 1738c2ecf20Sopenharmony_ci xway_stp_w32(chip->virt, 0, XWAY_STP_CON1); 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci /* apply edge trigger settings for the shift register */ 1768c2ecf20Sopenharmony_ci xway_stp_w32_mask(chip->virt, XWAY_STP_EDGE_MASK, 1778c2ecf20Sopenharmony_ci chip->edge, XWAY_STP_CON0); 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci /* apply led group settings */ 1808c2ecf20Sopenharmony_ci xway_stp_w32_mask(chip->virt, XWAY_STP_GROUP_MASK, 1818c2ecf20Sopenharmony_ci chip->groups, XWAY_STP_CON1); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci /* tell the hardware which pins are controlled by the dsl modem */ 1848c2ecf20Sopenharmony_ci xway_stp_w32_mask(chip->virt, 1858c2ecf20Sopenharmony_ci XWAY_STP_ADSL_MASK << XWAY_STP_ADSL_SHIFT, 1868c2ecf20Sopenharmony_ci chip->dsl << XWAY_STP_ADSL_SHIFT, 1878c2ecf20Sopenharmony_ci XWAY_STP_CON0); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci /* tell the hardware which pins are controlled by the phys */ 1908c2ecf20Sopenharmony_ci xway_stp_w32_mask(chip->virt, 1918c2ecf20Sopenharmony_ci XWAY_STP_PHY_MASK << XWAY_STP_PHY1_SHIFT, 1928c2ecf20Sopenharmony_ci chip->phy1 << XWAY_STP_PHY1_SHIFT, 1938c2ecf20Sopenharmony_ci XWAY_STP_CON0); 1948c2ecf20Sopenharmony_ci xway_stp_w32_mask(chip->virt, 1958c2ecf20Sopenharmony_ci XWAY_STP_PHY_MASK << XWAY_STP_PHY2_SHIFT, 1968c2ecf20Sopenharmony_ci chip->phy2 << XWAY_STP_PHY2_SHIFT, 1978c2ecf20Sopenharmony_ci XWAY_STP_CON1); 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci if (of_machine_is_compatible("lantiq,grx390") 2008c2ecf20Sopenharmony_ci || of_machine_is_compatible("lantiq,ar10")) { 2018c2ecf20Sopenharmony_ci xway_stp_w32_mask(chip->virt, 2028c2ecf20Sopenharmony_ci XWAY_STP_PHY_MASK << XWAY_STP_PHY3_SHIFT, 2038c2ecf20Sopenharmony_ci chip->phy3 << XWAY_STP_PHY3_SHIFT, 2048c2ecf20Sopenharmony_ci XWAY_STP_CON1); 2058c2ecf20Sopenharmony_ci } 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci if (of_machine_is_compatible("lantiq,grx390")) { 2088c2ecf20Sopenharmony_ci xway_stp_w32_mask(chip->virt, 2098c2ecf20Sopenharmony_ci XWAY_STP_PHY_MASK << XWAY_STP_PHY4_SHIFT, 2108c2ecf20Sopenharmony_ci chip->phy4 << XWAY_STP_PHY4_SHIFT, 2118c2ecf20Sopenharmony_ci XWAY_STP_CON1); 2128c2ecf20Sopenharmony_ci } 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci /* mask out the hw driven bits in gpio_request */ 2158c2ecf20Sopenharmony_ci chip->reserved = (chip->phy4 << 11) | (chip->phy3 << 8) | (chip->phy2 << 5) 2168c2ecf20Sopenharmony_ci | (chip->phy1 << 2) | chip->dsl; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci /* 2198c2ecf20Sopenharmony_ci * if we have pins that are driven by hw, we need to tell the stp what 2208c2ecf20Sopenharmony_ci * clock to use as a timer. 2218c2ecf20Sopenharmony_ci */ 2228c2ecf20Sopenharmony_ci if (chip->reserved) { 2238c2ecf20Sopenharmony_ci xway_stp_w32_mask(chip->virt, XWAY_STP_UPD_MASK, 2248c2ecf20Sopenharmony_ci XWAY_STP_UPD_FPI, XWAY_STP_CON1); 2258c2ecf20Sopenharmony_ci xway_stp_w32_mask(chip->virt, XWAY_STP_SPEED_MASK, 2268c2ecf20Sopenharmony_ci XWAY_STP_10HZ, XWAY_STP_CON1); 2278c2ecf20Sopenharmony_ci xway_stp_w32_mask(chip->virt, XWAY_STP_FPIS_MASK, 2288c2ecf20Sopenharmony_ci XWAY_STP_FPIS_VALUE, XWAY_STP_CON1); 2298c2ecf20Sopenharmony_ci } 2308c2ecf20Sopenharmony_ci} 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cistatic int xway_stp_probe(struct platform_device *pdev) 2338c2ecf20Sopenharmony_ci{ 2348c2ecf20Sopenharmony_ci u32 shadow, groups, dsl, phy; 2358c2ecf20Sopenharmony_ci struct xway_stp *chip; 2368c2ecf20Sopenharmony_ci struct clk *clk; 2378c2ecf20Sopenharmony_ci int ret = 0; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); 2408c2ecf20Sopenharmony_ci if (!chip) 2418c2ecf20Sopenharmony_ci return -ENOMEM; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci chip->virt = devm_platform_ioremap_resource(pdev, 0); 2448c2ecf20Sopenharmony_ci if (IS_ERR(chip->virt)) 2458c2ecf20Sopenharmony_ci return PTR_ERR(chip->virt); 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci chip->gc.parent = &pdev->dev; 2488c2ecf20Sopenharmony_ci chip->gc.label = "stp-xway"; 2498c2ecf20Sopenharmony_ci chip->gc.direction_output = xway_stp_dir_out; 2508c2ecf20Sopenharmony_ci chip->gc.get = xway_stp_get; 2518c2ecf20Sopenharmony_ci chip->gc.set = xway_stp_set; 2528c2ecf20Sopenharmony_ci chip->gc.request = xway_stp_request; 2538c2ecf20Sopenharmony_ci chip->gc.base = -1; 2548c2ecf20Sopenharmony_ci chip->gc.owner = THIS_MODULE; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci /* store the shadow value if one was passed by the devicetree */ 2578c2ecf20Sopenharmony_ci if (!of_property_read_u32(pdev->dev.of_node, "lantiq,shadow", &shadow)) 2588c2ecf20Sopenharmony_ci chip->shadow = shadow; 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci /* find out which gpio groups should be enabled */ 2618c2ecf20Sopenharmony_ci if (!of_property_read_u32(pdev->dev.of_node, "lantiq,groups", &groups)) 2628c2ecf20Sopenharmony_ci chip->groups = groups & XWAY_STP_GROUP_MASK; 2638c2ecf20Sopenharmony_ci else 2648c2ecf20Sopenharmony_ci chip->groups = XWAY_STP_GROUP0; 2658c2ecf20Sopenharmony_ci chip->gc.ngpio = fls(chip->groups) * 8; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci /* find out which gpios are controlled by the dsl core */ 2688c2ecf20Sopenharmony_ci if (!of_property_read_u32(pdev->dev.of_node, "lantiq,dsl", &dsl)) 2698c2ecf20Sopenharmony_ci chip->dsl = dsl & XWAY_STP_ADSL_MASK; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci /* find out which gpios are controlled by the phys */ 2728c2ecf20Sopenharmony_ci if (of_machine_is_compatible("lantiq,ar9") || 2738c2ecf20Sopenharmony_ci of_machine_is_compatible("lantiq,gr9") || 2748c2ecf20Sopenharmony_ci of_machine_is_compatible("lantiq,vr9") || 2758c2ecf20Sopenharmony_ci of_machine_is_compatible("lantiq,ar10") || 2768c2ecf20Sopenharmony_ci of_machine_is_compatible("lantiq,grx390")) { 2778c2ecf20Sopenharmony_ci if (!of_property_read_u32(pdev->dev.of_node, "lantiq,phy1", &phy)) 2788c2ecf20Sopenharmony_ci chip->phy1 = phy & XWAY_STP_PHY_MASK; 2798c2ecf20Sopenharmony_ci if (!of_property_read_u32(pdev->dev.of_node, "lantiq,phy2", &phy)) 2808c2ecf20Sopenharmony_ci chip->phy2 = phy & XWAY_STP_PHY_MASK; 2818c2ecf20Sopenharmony_ci } 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci if (of_machine_is_compatible("lantiq,ar10") || 2848c2ecf20Sopenharmony_ci of_machine_is_compatible("lantiq,grx390")) { 2858c2ecf20Sopenharmony_ci if (!of_property_read_u32(pdev->dev.of_node, "lantiq,phy3", &phy)) 2868c2ecf20Sopenharmony_ci chip->phy3 = phy & XWAY_STP_PHY_MASK; 2878c2ecf20Sopenharmony_ci } 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci if (of_machine_is_compatible("lantiq,grx390")) { 2908c2ecf20Sopenharmony_ci if (!of_property_read_u32(pdev->dev.of_node, "lantiq,phy4", &phy)) 2918c2ecf20Sopenharmony_ci chip->phy4 = phy & XWAY_STP_PHY_MASK; 2928c2ecf20Sopenharmony_ci } 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci /* check which edge trigger we should use, default to a falling edge */ 2958c2ecf20Sopenharmony_ci if (!of_find_property(pdev->dev.of_node, "lantiq,rising", NULL)) 2968c2ecf20Sopenharmony_ci chip->edge = XWAY_STP_FALLING; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci clk = devm_clk_get(&pdev->dev, NULL); 2998c2ecf20Sopenharmony_ci if (IS_ERR(clk)) { 3008c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "Failed to get clock\n"); 3018c2ecf20Sopenharmony_ci return PTR_ERR(clk); 3028c2ecf20Sopenharmony_ci } 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci ret = clk_prepare_enable(clk); 3058c2ecf20Sopenharmony_ci if (ret) 3068c2ecf20Sopenharmony_ci return ret; 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci xway_stp_hw_init(chip); 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci ret = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); 3118c2ecf20Sopenharmony_ci if (ret) { 3128c2ecf20Sopenharmony_ci clk_disable_unprepare(clk); 3138c2ecf20Sopenharmony_ci return ret; 3148c2ecf20Sopenharmony_ci } 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci dev_info(&pdev->dev, "Init done\n"); 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci return 0; 3198c2ecf20Sopenharmony_ci} 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_cistatic const struct of_device_id xway_stp_match[] = { 3228c2ecf20Sopenharmony_ci { .compatible = "lantiq,gpio-stp-xway" }, 3238c2ecf20Sopenharmony_ci {}, 3248c2ecf20Sopenharmony_ci}; 3258c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, xway_stp_match); 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_cistatic struct platform_driver xway_stp_driver = { 3288c2ecf20Sopenharmony_ci .probe = xway_stp_probe, 3298c2ecf20Sopenharmony_ci .driver = { 3308c2ecf20Sopenharmony_ci .name = "gpio-stp-xway", 3318c2ecf20Sopenharmony_ci .of_match_table = xway_stp_match, 3328c2ecf20Sopenharmony_ci }, 3338c2ecf20Sopenharmony_ci}; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_cistatic int __init xway_stp_init(void) 3368c2ecf20Sopenharmony_ci{ 3378c2ecf20Sopenharmony_ci return platform_driver_register(&xway_stp_driver); 3388c2ecf20Sopenharmony_ci} 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_cisubsys_initcall(xway_stp_init); 341