Lines Matching +full:spi +full:- +full:cs +full:- +full:high
1 // SPDX-License-Identifier: GPL-2.0-only
3 * SPEAr platform SPI chipselect abstraction over gpiolib
21 * Provision is available on some SPEAr SoCs to control ARM PL022 spi cs
22 * through system registers. This register lies outside spi (pl022)
25 * It provides control for spi chip select lines so that any chipselect
31 * struct spear_spics - represents spi chip select control
35 * @cs_value_bit: bit to program high or low chipselect
38 * @use_count: use count of a spi controller cs lines
57 return -ENXIO; in spics_get_value()
66 tmp = readl_relaxed(spics->base + spics->perip_cfg); in spics_set_value()
67 if (spics->last_off != offset) { in spics_set_value()
68 spics->last_off = offset; in spics_set_value()
69 tmp &= ~(spics->cs_enable_mask << spics->cs_enable_shift); in spics_set_value()
70 tmp |= offset << spics->cs_enable_shift; in spics_set_value()
74 tmp &= ~(0x1 << spics->cs_value_bit); in spics_set_value()
75 tmp |= value << spics->cs_value_bit; in spics_set_value()
76 writel_relaxed(tmp, spics->base + spics->perip_cfg); in spics_set_value()
81 return -ENXIO; in spics_direction_input()
96 if (!spics->use_count++) { in spics_request()
97 tmp = readl_relaxed(spics->base + spics->perip_cfg); in spics_request()
98 tmp |= 0x1 << spics->sw_enable_bit; in spics_request()
99 tmp |= 0x1 << spics->cs_value_bit; in spics_request()
100 writel_relaxed(tmp, spics->base + spics->perip_cfg); in spics_request()
111 if (!--spics->use_count) { in spics_free()
112 tmp = readl_relaxed(spics->base + spics->perip_cfg); in spics_free()
113 tmp &= ~(0x1 << spics->sw_enable_bit); in spics_free()
114 writel_relaxed(tmp, spics->base + spics->perip_cfg); in spics_free()
120 struct device_node *np = pdev->dev.of_node; in spics_gpio_probe()
123 spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL); in spics_gpio_probe()
125 return -ENOMEM; in spics_gpio_probe()
127 spics->base = devm_platform_ioremap_resource(pdev, 0); in spics_gpio_probe()
128 if (IS_ERR(spics->base)) in spics_gpio_probe()
129 return PTR_ERR(spics->base); in spics_gpio_probe()
131 if (of_property_read_u32(np, "st-spics,peripcfg-reg", in spics_gpio_probe()
132 &spics->perip_cfg)) in spics_gpio_probe()
134 if (of_property_read_u32(np, "st-spics,sw-enable-bit", in spics_gpio_probe()
135 &spics->sw_enable_bit)) in spics_gpio_probe()
137 if (of_property_read_u32(np, "st-spics,cs-value-bit", in spics_gpio_probe()
138 &spics->cs_value_bit)) in spics_gpio_probe()
140 if (of_property_read_u32(np, "st-spics,cs-enable-mask", in spics_gpio_probe()
141 &spics->cs_enable_mask)) in spics_gpio_probe()
143 if (of_property_read_u32(np, "st-spics,cs-enable-shift", in spics_gpio_probe()
144 &spics->cs_enable_shift)) in spics_gpio_probe()
147 spics->chip.ngpio = NUM_OF_GPIO; in spics_gpio_probe()
148 spics->chip.base = -1; in spics_gpio_probe()
149 spics->chip.request = spics_request; in spics_gpio_probe()
150 spics->chip.free = spics_free; in spics_gpio_probe()
151 spics->chip.direction_input = spics_direction_input; in spics_gpio_probe()
152 spics->chip.direction_output = spics_direction_output; in spics_gpio_probe()
153 spics->chip.get = spics_get_value; in spics_gpio_probe()
154 spics->chip.set = spics_set_value; in spics_gpio_probe()
155 spics->chip.label = dev_name(&pdev->dev); in spics_gpio_probe()
156 spics->chip.parent = &pdev->dev; in spics_gpio_probe()
157 spics->chip.owner = THIS_MODULE; in spics_gpio_probe()
158 spics->last_off = -1; in spics_gpio_probe()
160 return devm_gpiochip_add_data(&pdev->dev, &spics->chip, spics); in spics_gpio_probe()
163 dev_err(&pdev->dev, "DT probe failed\n"); in spics_gpio_probe()
164 return -EINVAL; in spics_gpio_probe()
168 { .compatible = "st,spear-spics-gpio" },
175 .name = "spear-spics-gpio",