blob: 56abe36071ed99ec5a65e1a670b2d877e9e76073 [file] [log] [blame]
Neil Armstrong9e80f902016-10-21 11:09:58 +02001/*
2 * Copyright (c) 2016, BayLibre, SAS. All rights reserved.
3 * Author: Neil Armstrong <narmstrong@baylibre.com>
4 *
5 * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
6 *
7 * Driver for Semtech SX150X I2C GPIO Expanders
8 *
9 * Author: Gregory Bean <gbean@codeaurora.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 and
13 * only version 2 as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
Andrey Smirnov0db0f262016-11-07 08:53:16 -080021#include <linux/regmap.h>
Neil Armstrong9e80f902016-10-21 11:09:58 +020022#include <linux/i2c.h>
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/irq.h>
26#include <linux/mutex.h>
27#include <linux/slab.h>
28#include <linux/of.h>
Andrey Smirnove3ba8122016-11-07 08:53:09 -080029#include <linux/of_device.h>
Neil Armstrong9e80f902016-10-21 11:09:58 +020030#include <linux/gpio.h>
31#include <linux/pinctrl/machine.h>
32#include <linux/pinctrl/pinconf.h>
33#include <linux/pinctrl/pinctrl.h>
34#include <linux/pinctrl/pinmux.h>
35#include <linux/pinctrl/pinconf-generic.h>
36
37#include "core.h"
38#include "pinconf.h"
39#include "pinctrl-utils.h"
40
41/* The chip models of sx150x */
42enum {
43 SX150X_123 = 0,
44 SX150X_456,
45 SX150X_789,
46};
Andrey Smirnov7d68a792016-11-07 08:53:12 -080047enum {
48 SX150X_789_REG_MISC_AUTOCLEAR_OFF = 1 << 0,
Andrey Smirnov0db0f262016-11-07 08:53:16 -080049 SX150X_MAX_REGISTER = 0xad,
Andrey Smirnovfd931f22016-11-07 08:53:22 -080050 SX150X_IRQ_TYPE_EDGE_RISING = 0x1,
51 SX150X_IRQ_TYPE_EDGE_FALLING = 0x2,
Andrey Smirnov7d68a792016-11-07 08:53:12 -080052};
Neil Armstrong9e80f902016-10-21 11:09:58 +020053
54struct sx150x_123_pri {
55 u8 reg_pld_mode;
56 u8 reg_pld_table0;
57 u8 reg_pld_table1;
58 u8 reg_pld_table2;
59 u8 reg_pld_table3;
60 u8 reg_pld_table4;
61 u8 reg_advance;
62};
63
64struct sx150x_456_pri {
65 u8 reg_pld_mode;
66 u8 reg_pld_table0;
67 u8 reg_pld_table1;
68 u8 reg_pld_table2;
69 u8 reg_pld_table3;
70 u8 reg_pld_table4;
71 u8 reg_advance;
72};
73
74struct sx150x_789_pri {
75 u8 reg_drain;
76 u8 reg_polarity;
77 u8 reg_clock;
78 u8 reg_misc;
79 u8 reg_reset;
80 u8 ngpios;
81};
82
83struct sx150x_device_data {
84 u8 model;
85 u8 reg_pullup;
86 u8 reg_pulldn;
87 u8 reg_dir;
88 u8 reg_data;
89 u8 reg_irq_mask;
90 u8 reg_irq_src;
91 u8 reg_sense;
92 u8 ngpios;
93 union {
94 struct sx150x_123_pri x123;
95 struct sx150x_456_pri x456;
96 struct sx150x_789_pri x789;
97 } pri;
98 const struct pinctrl_pin_desc *pins;
99 unsigned int npins;
100};
101
102struct sx150x_pinctrl {
103 struct device *dev;
104 struct i2c_client *client;
105 struct pinctrl_dev *pctldev;
106 struct pinctrl_desc pinctrl_desc;
107 struct gpio_chip gpio;
108 struct irq_chip irq_chip;
Andrey Smirnov0db0f262016-11-07 08:53:16 -0800109 struct regmap *regmap;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200110 struct {
Neil Armstrong9e80f902016-10-21 11:09:58 +0200111 u32 sense;
112 u32 masked;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200113 } irq;
114 struct mutex lock;
115 const struct sx150x_device_data *data;
116};
117
118static const struct pinctrl_pin_desc sx150x_8_pins[] = {
119 PINCTRL_PIN(0, "gpio0"),
120 PINCTRL_PIN(1, "gpio1"),
121 PINCTRL_PIN(2, "gpio2"),
122 PINCTRL_PIN(3, "gpio3"),
123 PINCTRL_PIN(4, "gpio4"),
124 PINCTRL_PIN(5, "gpio5"),
125 PINCTRL_PIN(6, "gpio6"),
126 PINCTRL_PIN(7, "gpio7"),
127 PINCTRL_PIN(8, "oscio"),
128};
129
130static const struct pinctrl_pin_desc sx150x_16_pins[] = {
131 PINCTRL_PIN(0, "gpio0"),
132 PINCTRL_PIN(1, "gpio1"),
133 PINCTRL_PIN(2, "gpio2"),
134 PINCTRL_PIN(3, "gpio3"),
135 PINCTRL_PIN(4, "gpio4"),
136 PINCTRL_PIN(5, "gpio5"),
137 PINCTRL_PIN(6, "gpio6"),
138 PINCTRL_PIN(7, "gpio7"),
139 PINCTRL_PIN(8, "gpio8"),
140 PINCTRL_PIN(9, "gpio9"),
141 PINCTRL_PIN(10, "gpio10"),
142 PINCTRL_PIN(11, "gpio11"),
143 PINCTRL_PIN(12, "gpio12"),
144 PINCTRL_PIN(13, "gpio13"),
145 PINCTRL_PIN(14, "gpio14"),
146 PINCTRL_PIN(15, "gpio15"),
147 PINCTRL_PIN(16, "oscio"),
148};
149
150static const struct sx150x_device_data sx1508q_device_data = {
151 .model = SX150X_789,
152 .reg_pullup = 0x03,
153 .reg_pulldn = 0x04,
154 .reg_dir = 0x07,
155 .reg_data = 0x08,
156 .reg_irq_mask = 0x09,
157 .reg_irq_src = 0x0c,
158 .reg_sense = 0x0b,
159 .pri.x789 = {
160 .reg_drain = 0x05,
161 .reg_polarity = 0x06,
162 .reg_clock = 0x0f,
163 .reg_misc = 0x10,
164 .reg_reset = 0x7d,
165 },
166 .ngpios = 8,
167 .pins = sx150x_8_pins,
168 .npins = ARRAY_SIZE(sx150x_8_pins),
169};
170
171static const struct sx150x_device_data sx1509q_device_data = {
172 .model = SX150X_789,
Andrey Smirnov64896772016-11-07 08:53:17 -0800173 .reg_pullup = 0x06,
174 .reg_pulldn = 0x08,
175 .reg_dir = 0x0e,
176 .reg_data = 0x10,
177 .reg_irq_mask = 0x12,
178 .reg_irq_src = 0x18,
179 .reg_sense = 0x14,
Neil Armstrong9e80f902016-10-21 11:09:58 +0200180 .pri.x789 = {
Andrey Smirnov64896772016-11-07 08:53:17 -0800181 .reg_drain = 0x0a,
182 .reg_polarity = 0x0c,
Neil Armstrong9e80f902016-10-21 11:09:58 +0200183 .reg_clock = 0x1e,
184 .reg_misc = 0x1f,
185 .reg_reset = 0x7d,
186 },
187 .ngpios = 16,
188 .pins = sx150x_16_pins,
189 .npins = ARRAY_SIZE(sx150x_16_pins),
190};
191
192static const struct sx150x_device_data sx1506q_device_data = {
193 .model = SX150X_456,
Andrey Smirnov64896772016-11-07 08:53:17 -0800194 .reg_pullup = 0x04,
195 .reg_pulldn = 0x06,
196 .reg_dir = 0x02,
197 .reg_data = 0x00,
198 .reg_irq_mask = 0x08,
199 .reg_irq_src = 0x0e,
200 .reg_sense = 0x0a,
Neil Armstrong9e80f902016-10-21 11:09:58 +0200201 .pri.x456 = {
Andrey Smirnov64896772016-11-07 08:53:17 -0800202 .reg_pld_mode = 0x20,
203 .reg_pld_table0 = 0x22,
204 .reg_pld_table1 = 0x24,
205 .reg_pld_table2 = 0x26,
206 .reg_pld_table3 = 0x28,
207 .reg_pld_table4 = 0x2a,
Neil Armstrong9e80f902016-10-21 11:09:58 +0200208 .reg_advance = 0xad,
209 },
210 .ngpios = 16,
211 .pins = sx150x_16_pins,
212 .npins = 16, /* oscio not available */
213};
214
215static const struct sx150x_device_data sx1502q_device_data = {
216 .model = SX150X_123,
217 .reg_pullup = 0x02,
218 .reg_pulldn = 0x03,
219 .reg_dir = 0x01,
220 .reg_data = 0x00,
221 .reg_irq_mask = 0x05,
222 .reg_irq_src = 0x08,
223 .reg_sense = 0x07,
224 .pri.x123 = {
225 .reg_pld_mode = 0x10,
226 .reg_pld_table0 = 0x11,
227 .reg_pld_table1 = 0x12,
228 .reg_pld_table2 = 0x13,
229 .reg_pld_table3 = 0x14,
230 .reg_pld_table4 = 0x15,
231 .reg_advance = 0xad,
232 },
233 .ngpios = 8,
234 .pins = sx150x_8_pins,
235 .npins = 8, /* oscio not available */
236};
237
Andrey Smirnov66975462016-11-07 08:53:10 -0800238static const struct sx150x_device_data sx1503q_device_data = {
239 .model = SX150X_123,
Andrey Smirnov64896772016-11-07 08:53:17 -0800240 .reg_pullup = 0x04,
241 .reg_pulldn = 0x06,
242 .reg_dir = 0x02,
243 .reg_data = 0x00,
244 .reg_irq_mask = 0x08,
245 .reg_irq_src = 0x0e,
246 .reg_sense = 0x0a,
Andrey Smirnov66975462016-11-07 08:53:10 -0800247 .pri.x123 = {
Andrey Smirnov64896772016-11-07 08:53:17 -0800248 .reg_pld_mode = 0x20,
249 .reg_pld_table0 = 0x22,
250 .reg_pld_table1 = 0x24,
251 .reg_pld_table2 = 0x26,
252 .reg_pld_table3 = 0x28,
253 .reg_pld_table4 = 0x2a,
Andrey Smirnov66975462016-11-07 08:53:10 -0800254 .reg_advance = 0xad,
255 },
256 .ngpios = 16,
257 .pins = sx150x_16_pins,
258 .npins = 16, /* oscio not available */
259};
260
Neil Armstrong9e80f902016-10-21 11:09:58 +0200261static int sx150x_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
262{
263 return 0;
264}
265
266static const char *sx150x_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
267 unsigned int group)
268{
269 return NULL;
270}
271
272static int sx150x_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
273 unsigned int group,
274 const unsigned int **pins,
275 unsigned int *num_pins)
276{
277 return -ENOTSUPP;
278}
279
280static const struct pinctrl_ops sx150x_pinctrl_ops = {
281 .get_groups_count = sx150x_pinctrl_get_groups_count,
282 .get_group_name = sx150x_pinctrl_get_group_name,
283 .get_group_pins = sx150x_pinctrl_get_group_pins,
284#ifdef CONFIG_OF
285 .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
286 .dt_free_map = pinctrl_utils_free_map,
287#endif
288};
289
290static bool sx150x_pin_is_oscio(struct sx150x_pinctrl *pctl, unsigned int pin)
291{
292 if (pin >= pctl->data->npins)
293 return false;
294
295 /* OSCIO pin is only present in 789 devices */
296 if (pctl->data->model != SX150X_789)
297 return false;
298
299 return !strcmp(pctl->data->pins[pin].name, "oscio");
300}
301
302static int sx150x_gpio_get_direction(struct gpio_chip *chip,
303 unsigned int offset)
304{
305 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
Andrey Smirnov64896772016-11-07 08:53:17 -0800306 unsigned int value;
307 int ret;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200308
309 if (sx150x_pin_is_oscio(pctl, offset))
310 return false;
311
Andrey Smirnov64896772016-11-07 08:53:17 -0800312 ret = regmap_read(pctl->regmap, pctl->data->reg_dir, &value);
313 if (ret < 0)
314 return ret;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200315
Andrey Smirnov64896772016-11-07 08:53:17 -0800316 return !!(value & BIT(offset));
Neil Armstrong9e80f902016-10-21 11:09:58 +0200317}
318
319static int sx150x_gpio_get(struct gpio_chip *chip, unsigned int offset)
320{
321 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
Andrey Smirnov64896772016-11-07 08:53:17 -0800322 unsigned int value;
323 int ret;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200324
325 if (sx150x_pin_is_oscio(pctl, offset))
326 return -EINVAL;
327
Andrey Smirnov64896772016-11-07 08:53:17 -0800328 ret = regmap_read(pctl->regmap, pctl->data->reg_data, &value);
329 if (ret < 0)
330 return ret;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200331
Andrey Smirnov64896772016-11-07 08:53:17 -0800332 return !!(value & BIT(offset));
Neil Armstrong9e80f902016-10-21 11:09:58 +0200333}
334
335static int sx150x_gpio_set_single_ended(struct gpio_chip *chip,
336 unsigned int offset,
337 enum single_ended_mode mode)
338{
339 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
340 int ret;
341
342 switch (mode) {
343 case LINE_MODE_PUSH_PULL:
344 if (pctl->data->model != SX150X_789 ||
345 sx150x_pin_is_oscio(pctl, offset))
346 return 0;
347
Andrey Smirnov64896772016-11-07 08:53:17 -0800348 ret = regmap_write_bits(pctl->regmap,
349 pctl->data->pri.x789.reg_drain,
350 BIT(offset), 0);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200351 break;
352
353 case LINE_MODE_OPEN_DRAIN:
354 if (pctl->data->model != SX150X_789 ||
355 sx150x_pin_is_oscio(pctl, offset))
356 return -ENOTSUPP;
357
Andrey Smirnov64896772016-11-07 08:53:17 -0800358 ret = regmap_write_bits(pctl->regmap,
359 pctl->data->pri.x789.reg_drain,
360 BIT(offset), BIT(offset));
Neil Armstrong9e80f902016-10-21 11:09:58 +0200361 break;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200362 default:
Andrey Smirnovd977a872016-11-07 08:53:18 -0800363 ret = -ENOTSUPP;
364 break;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200365 }
366
Andrey Smirnovd977a872016-11-07 08:53:18 -0800367 return ret;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200368}
369
Andrey Smirnov64896772016-11-07 08:53:17 -0800370static int __sx150x_gpio_set(struct sx150x_pinctrl *pctl, unsigned int offset,
371 int value)
372{
373 return regmap_write_bits(pctl->regmap, pctl->data->reg_data,
374 BIT(offset), value ? BIT(offset) : 0);
375}
376
Andrey Smirnovab5bd032016-11-07 08:53:19 -0800377static int sx150x_gpio_oscio_set(struct sx150x_pinctrl *pctl,
378 int value)
379{
380 return regmap_write(pctl->regmap,
381 pctl->data->pri.x789.reg_clock,
382 (value ? 0x1f : 0x10));
383}
384
Neil Armstrong9e80f902016-10-21 11:09:58 +0200385static void sx150x_gpio_set(struct gpio_chip *chip, unsigned int offset,
386 int value)
387{
388 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
389
Andrey Smirnovd977a872016-11-07 08:53:18 -0800390 if (sx150x_pin_is_oscio(pctl, offset))
Andrey Smirnovab5bd032016-11-07 08:53:19 -0800391 sx150x_gpio_oscio_set(pctl, value);
Andrey Smirnovd977a872016-11-07 08:53:18 -0800392 else
Andrey Smirnov64896772016-11-07 08:53:17 -0800393 __sx150x_gpio_set(pctl, offset, value);
Andrey Smirnovd977a872016-11-07 08:53:18 -0800394
Neil Armstrong9e80f902016-10-21 11:09:58 +0200395}
396
397static int sx150x_gpio_direction_input(struct gpio_chip *chip,
398 unsigned int offset)
399{
400 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200401
402 if (sx150x_pin_is_oscio(pctl, offset))
403 return -EINVAL;
404
Andrey Smirnovd977a872016-11-07 08:53:18 -0800405 return regmap_write_bits(pctl->regmap,
406 pctl->data->reg_dir,
407 BIT(offset), BIT(offset));
Neil Armstrong9e80f902016-10-21 11:09:58 +0200408}
409
410static int sx150x_gpio_direction_output(struct gpio_chip *chip,
411 unsigned int offset, int value)
412{
413 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
Andrey Smirnovd977a872016-11-07 08:53:18 -0800414 int ret;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200415
Andrey Smirnovab5bd032016-11-07 08:53:19 -0800416 if (sx150x_pin_is_oscio(pctl, offset))
417 return sx150x_gpio_oscio_set(pctl, value);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200418
Andrey Smirnovd977a872016-11-07 08:53:18 -0800419 ret = __sx150x_gpio_set(pctl, offset, value);
420 if (ret < 0)
421 return ret;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200422
Andrey Smirnovd977a872016-11-07 08:53:18 -0800423 return regmap_write_bits(pctl->regmap,
424 pctl->data->reg_dir,
425 BIT(offset), 0);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200426}
427
428static void sx150x_irq_mask(struct irq_data *d)
429{
430 struct sx150x_pinctrl *pctl =
431 gpiochip_get_data(irq_data_get_irq_chip_data(d));
432 unsigned int n = d->hwirq;
433
Andrey Smirnov64896772016-11-07 08:53:17 -0800434 pctl->irq.masked |= BIT(n);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200435}
436
437static void sx150x_irq_unmask(struct irq_data *d)
438{
439 struct sx150x_pinctrl *pctl =
440 gpiochip_get_data(irq_data_get_irq_chip_data(d));
441 unsigned int n = d->hwirq;
442
Andrey Smirnov64896772016-11-07 08:53:17 -0800443 pctl->irq.masked &= ~BIT(n);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200444}
445
Andrey Smirnovfd931f22016-11-07 08:53:22 -0800446static void sx150x_irq_set_sense(struct sx150x_pinctrl *pctl,
447 unsigned int line, unsigned int sense)
448{
449 /*
450 * Every interrupt line is represented by two bits shifted
451 * proportionally to the line number
452 */
453 const unsigned int n = line * 2;
454 const unsigned int mask = ~((SX150X_IRQ_TYPE_EDGE_RISING |
455 SX150X_IRQ_TYPE_EDGE_FALLING) << n);
456
457 pctl->irq.sense &= mask;
458 pctl->irq.sense |= sense << n;
459}
460
Neil Armstrong9e80f902016-10-21 11:09:58 +0200461static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type)
462{
463 struct sx150x_pinctrl *pctl =
464 gpiochip_get_data(irq_data_get_irq_chip_data(d));
465 unsigned int n, val = 0;
466
467 if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
468 return -EINVAL;
469
470 n = d->hwirq;
471
472 if (flow_type & IRQ_TYPE_EDGE_RISING)
Andrey Smirnovfd931f22016-11-07 08:53:22 -0800473 val |= SX150X_IRQ_TYPE_EDGE_RISING;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200474 if (flow_type & IRQ_TYPE_EDGE_FALLING)
Andrey Smirnovfd931f22016-11-07 08:53:22 -0800475 val |= SX150X_IRQ_TYPE_EDGE_FALLING;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200476
Andrey Smirnovfd931f22016-11-07 08:53:22 -0800477 sx150x_irq_set_sense(pctl, n, val);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200478 return 0;
479}
480
481static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id)
482{
483 struct sx150x_pinctrl *pctl = (struct sx150x_pinctrl *)dev_id;
Andrey Smirnov05a90cc2016-11-07 08:53:20 -0800484 unsigned long n, status;
Andrey Smirnov0db0f262016-11-07 08:53:16 -0800485 unsigned int val;
Andrey Smirnov05a90cc2016-11-07 08:53:20 -0800486 int err;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200487
Andrey Smirnov64896772016-11-07 08:53:17 -0800488 err = regmap_read(pctl->regmap, pctl->data->reg_irq_src, &val);
489 if (err < 0)
490 return IRQ_NONE;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200491
Andrey Smirnov64896772016-11-07 08:53:17 -0800492 err = regmap_write(pctl->regmap, pctl->data->reg_irq_src, val);
493 if (err < 0)
494 return IRQ_NONE;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200495
Andrey Smirnov05a90cc2016-11-07 08:53:20 -0800496 status = val;
497 for_each_set_bit(n, &status, pctl->data->ngpios)
498 handle_nested_irq(irq_find_mapping(pctl->gpio.irqdomain, n));
Neil Armstrong9e80f902016-10-21 11:09:58 +0200499
Andrey Smirnov05a90cc2016-11-07 08:53:20 -0800500 return IRQ_HANDLED;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200501}
502
503static void sx150x_irq_bus_lock(struct irq_data *d)
504{
505 struct sx150x_pinctrl *pctl =
506 gpiochip_get_data(irq_data_get_irq_chip_data(d));
507
508 mutex_lock(&pctl->lock);
509}
510
511static void sx150x_irq_bus_sync_unlock(struct irq_data *d)
512{
513 struct sx150x_pinctrl *pctl =
514 gpiochip_get_data(irq_data_get_irq_chip_data(d));
Neil Armstrong9e80f902016-10-21 11:09:58 +0200515
Andrey Smirnov64896772016-11-07 08:53:17 -0800516 regmap_write(pctl->regmap, pctl->data->reg_irq_mask, pctl->irq.masked);
517 regmap_write(pctl->regmap, pctl->data->reg_sense, pctl->irq.sense);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200518 mutex_unlock(&pctl->lock);
519}
520
521static int sx150x_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
522 unsigned long *config)
523{
524 struct sx150x_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
525 unsigned int param = pinconf_to_config_param(*config);
526 int ret;
527 u32 arg;
Andrey Smirnov64896772016-11-07 08:53:17 -0800528 unsigned int data;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200529
530 if (sx150x_pin_is_oscio(pctl, pin)) {
Neil Armstrong9e80f902016-10-21 11:09:58 +0200531 switch (param) {
532 case PIN_CONFIG_DRIVE_PUSH_PULL:
533 case PIN_CONFIG_OUTPUT:
Andrey Smirnov0db0f262016-11-07 08:53:16 -0800534 ret = regmap_read(pctl->regmap,
535 pctl->data->pri.x789.reg_clock,
536 &data);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200537 if (ret < 0)
538 return ret;
539
540 if (param == PIN_CONFIG_DRIVE_PUSH_PULL)
541 arg = (data & 0x1f) ? 1 : 0;
542 else {
543 if ((data & 0x1f) == 0x1f)
544 arg = 1;
545 else if ((data & 0x1f) == 0x10)
546 arg = 0;
547 else
548 return -EINVAL;
549 }
550
551 break;
552 default:
553 return -ENOTSUPP;
554 }
555
556 goto out;
557 }
558
559 switch (param) {
560 case PIN_CONFIG_BIAS_PULL_DOWN:
Andrey Smirnov64896772016-11-07 08:53:17 -0800561 ret = regmap_read(pctl->regmap,
562 pctl->data->reg_pulldn,
563 &data);
564 data &= BIT(pin);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200565
566 if (ret < 0)
567 return ret;
568
569 if (!ret)
570 return -EINVAL;
571
572 arg = 1;
573 break;
574
575 case PIN_CONFIG_BIAS_PULL_UP:
Andrey Smirnov64896772016-11-07 08:53:17 -0800576 ret = regmap_read(pctl->regmap,
577 pctl->data->reg_pullup,
578 &data);
579 data &= BIT(pin);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200580
581 if (ret < 0)
582 return ret;
583
584 if (!ret)
585 return -EINVAL;
586
587 arg = 1;
588 break;
589
590 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
591 if (pctl->data->model != SX150X_789)
592 return -ENOTSUPP;
593
Andrey Smirnov64896772016-11-07 08:53:17 -0800594 ret = regmap_read(pctl->regmap,
595 pctl->data->pri.x789.reg_drain,
596 &data);
597 data &= BIT(pin);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200598
599 if (ret < 0)
600 return ret;
601
Andrey Smirnov64896772016-11-07 08:53:17 -0800602 if (!data)
Neil Armstrong9e80f902016-10-21 11:09:58 +0200603 return -EINVAL;
604
605 arg = 1;
606 break;
607
608 case PIN_CONFIG_DRIVE_PUSH_PULL:
609 if (pctl->data->model != SX150X_789)
610 arg = true;
611 else {
Andrey Smirnov64896772016-11-07 08:53:17 -0800612 ret = regmap_read(pctl->regmap,
613 pctl->data->pri.x789.reg_drain,
614 &data);
615 data &= BIT(pin);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200616
617 if (ret < 0)
618 return ret;
619
Andrey Smirnov64896772016-11-07 08:53:17 -0800620 if (data)
Neil Armstrong9e80f902016-10-21 11:09:58 +0200621 return -EINVAL;
622
623 arg = 1;
624 }
625 break;
626
627 case PIN_CONFIG_OUTPUT:
628 ret = sx150x_gpio_get_direction(&pctl->gpio, pin);
629 if (ret < 0)
630 return ret;
631
632 if (ret)
633 return -EINVAL;
634
635 ret = sx150x_gpio_get(&pctl->gpio, pin);
636 if (ret < 0)
637 return ret;
638
639 arg = ret;
640 break;
641
642 default:
643 return -ENOTSUPP;
644 }
645
646out:
647 *config = pinconf_to_config_packed(param, arg);
648
649 return 0;
650}
651
652static int sx150x_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
653 unsigned long *configs, unsigned int num_configs)
654{
655 struct sx150x_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
656 enum pin_config_param param;
657 u32 arg;
658 int i;
659 int ret;
660
661 for (i = 0; i < num_configs; i++) {
662 param = pinconf_to_config_param(configs[i]);
663 arg = pinconf_to_config_argument(configs[i]);
664
665 if (sx150x_pin_is_oscio(pctl, pin)) {
666 if (param == PIN_CONFIG_OUTPUT) {
667 ret = sx150x_gpio_direction_output(&pctl->gpio,
668 pin, arg);
669 if (ret < 0)
670 return ret;
671
672 continue;
673 } else
674 return -ENOTSUPP;
675 }
676
677 switch (param) {
678 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
679 case PIN_CONFIG_BIAS_DISABLE:
Andrey Smirnov64896772016-11-07 08:53:17 -0800680 ret = regmap_write_bits(pctl->regmap,
681 pctl->data->reg_pulldn,
682 BIT(pin), 0);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200683 if (ret < 0)
684 return ret;
685
Andrey Smirnov64896772016-11-07 08:53:17 -0800686 ret = regmap_write_bits(pctl->regmap,
687 pctl->data->reg_pullup,
688 BIT(pin), 0);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200689 if (ret < 0)
690 return ret;
691
692 break;
693
694 case PIN_CONFIG_BIAS_PULL_UP:
Andrey Smirnov64896772016-11-07 08:53:17 -0800695 ret = regmap_write_bits(pctl->regmap,
696 pctl->data->reg_pullup,
697 BIT(pin), BIT(pin));
Neil Armstrong9e80f902016-10-21 11:09:58 +0200698 if (ret < 0)
699 return ret;
700
701 break;
702
703 case PIN_CONFIG_BIAS_PULL_DOWN:
Andrey Smirnov64896772016-11-07 08:53:17 -0800704 ret = regmap_write_bits(pctl->regmap,
705 pctl->data->reg_pulldn,
706 BIT(pin), BIT(pin));
Neil Armstrong9e80f902016-10-21 11:09:58 +0200707 if (ret < 0)
708 return ret;
709
710 break;
711
712 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
713 ret = sx150x_gpio_set_single_ended(&pctl->gpio,
714 pin, LINE_MODE_OPEN_DRAIN);
715 if (ret < 0)
716 return ret;
717
718 break;
719
720 case PIN_CONFIG_DRIVE_PUSH_PULL:
721 ret = sx150x_gpio_set_single_ended(&pctl->gpio,
722 pin, LINE_MODE_PUSH_PULL);
723 if (ret < 0)
724 return ret;
725
726 break;
727
728 case PIN_CONFIG_OUTPUT:
729 ret = sx150x_gpio_direction_output(&pctl->gpio,
730 pin, arg);
731 if (ret < 0)
732 return ret;
733
734 break;
735
736 default:
737 return -ENOTSUPP;
738 }
739 } /* for each config */
740
741 return 0;
742}
743
744static const struct pinconf_ops sx150x_pinconf_ops = {
745 .pin_config_get = sx150x_pinconf_get,
746 .pin_config_set = sx150x_pinconf_set,
747 .is_generic = true,
748};
749
750static const struct i2c_device_id sx150x_id[] = {
751 {"sx1508q", (kernel_ulong_t) &sx1508q_device_data },
752 {"sx1509q", (kernel_ulong_t) &sx1509q_device_data },
753 {"sx1506q", (kernel_ulong_t) &sx1506q_device_data },
754 {"sx1502q", (kernel_ulong_t) &sx1502q_device_data },
Andrey Smirnov66975462016-11-07 08:53:10 -0800755 {"sx1503q", (kernel_ulong_t) &sx1503q_device_data },
Neil Armstrong9e80f902016-10-21 11:09:58 +0200756 {}
757};
758
759static const struct of_device_id sx150x_of_match[] = {
Andrey Smirnove3ba8122016-11-07 08:53:09 -0800760 { .compatible = "semtech,sx1508q", .data = &sx1508q_device_data },
761 { .compatible = "semtech,sx1509q", .data = &sx1509q_device_data },
762 { .compatible = "semtech,sx1506q", .data = &sx1506q_device_data },
763 { .compatible = "semtech,sx1502q", .data = &sx1502q_device_data },
Andrey Smirnov66975462016-11-07 08:53:10 -0800764 { .compatible = "semtech,sx1503q", .data = &sx1503q_device_data },
Neil Armstrong9e80f902016-10-21 11:09:58 +0200765 {},
766};
767
Neil Armstrong9e80f902016-10-21 11:09:58 +0200768static int sx150x_reset(struct sx150x_pinctrl *pctl)
769{
770 int err;
771
772 err = i2c_smbus_write_byte_data(pctl->client,
773 pctl->data->pri.x789.reg_reset,
774 0x12);
775 if (err < 0)
776 return err;
777
778 err = i2c_smbus_write_byte_data(pctl->client,
779 pctl->data->pri.x789.reg_reset,
780 0x34);
781 return err;
782}
783
Andrey Smirnov310cdfa2016-11-07 08:53:14 -0800784static int sx150x_init_misc(struct sx150x_pinctrl *pctl)
785{
786 u8 reg, value;
787
788 switch (pctl->data->model) {
789 case SX150X_789:
790 reg = pctl->data->pri.x789.reg_misc;
791 value = SX150X_789_REG_MISC_AUTOCLEAR_OFF;
792 break;
793 case SX150X_456:
794 reg = pctl->data->pri.x456.reg_advance;
795 value = 0x00;
Andrey Smirnovb30d31e2016-11-07 08:53:15 -0800796
797 /*
798 * Only SX1506 has RegAdvanced, SX1504/5 are expected
799 * to initialize this offset to zero
800 */
801 if (!reg)
802 return 0;
Andrey Smirnov310cdfa2016-11-07 08:53:14 -0800803 break;
804 case SX150X_123:
805 reg = pctl->data->pri.x123.reg_advance;
806 value = 0x00;
807 break;
808 default:
809 WARN(1, "Unknown chip model %d\n", pctl->data->model);
810 return -EINVAL;
811 }
812
Andrey Smirnov64896772016-11-07 08:53:17 -0800813 return regmap_write(pctl->regmap, reg, value);
Andrey Smirnov310cdfa2016-11-07 08:53:14 -0800814}
815
Neil Armstrong9e80f902016-10-21 11:09:58 +0200816static int sx150x_init_hw(struct sx150x_pinctrl *pctl)
817{
Andrey Smirnov64896772016-11-07 08:53:17 -0800818 const u8 reg[] = {
819 [SX150X_789] = pctl->data->pri.x789.reg_polarity,
820 [SX150X_456] = pctl->data->pri.x456.reg_pld_mode,
821 [SX150X_123] = pctl->data->pri.x123.reg_pld_mode,
822 };
Neil Armstrong9e80f902016-10-21 11:09:58 +0200823 int err;
824
825 if (pctl->data->model == SX150X_789 &&
826 of_property_read_bool(pctl->dev->of_node, "semtech,probe-reset")) {
827 err = sx150x_reset(pctl);
828 if (err < 0)
829 return err;
830 }
831
Andrey Smirnov310cdfa2016-11-07 08:53:14 -0800832 err = sx150x_init_misc(pctl);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200833 if (err < 0)
834 return err;
835
836 /* Set all pins to work in normal mode */
Andrey Smirnov64896772016-11-07 08:53:17 -0800837 return regmap_write(pctl->regmap, reg[pctl->data->model], 0);
838}
839
840static int sx150x_regmap_reg_width(struct sx150x_pinctrl *pctl,
841 unsigned int reg)
842{
843 const struct sx150x_device_data *data = pctl->data;
844
845 if (reg == data->reg_sense) {
846 /*
847 * RegSense packs two bits of configuration per GPIO,
848 * so we'd need to read twice as many bits as there
849 * are GPIO in our chip
850 */
851 return 2 * data->ngpios;
852 } else if ((data->model == SX150X_789 &&
853 (reg == data->pri.x789.reg_misc ||
854 reg == data->pri.x789.reg_clock ||
855 reg == data->pri.x789.reg_reset))
856 ||
857 (data->model == SX150X_123 &&
858 reg == data->pri.x123.reg_advance)
859 ||
860 (data->model == SX150X_456 &&
861 reg == data->pri.x456.reg_advance)) {
862 return 8;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200863 } else {
Andrey Smirnov64896772016-11-07 08:53:17 -0800864 return data->ngpios;
Neil Armstrong9e80f902016-10-21 11:09:58 +0200865 }
Andrey Smirnov64896772016-11-07 08:53:17 -0800866}
867
868static unsigned int sx150x_maybe_swizzle(struct sx150x_pinctrl *pctl,
869 unsigned int reg, unsigned int val)
870{
871 unsigned int a, b;
872 const struct sx150x_device_data *data = pctl->data;
873
874 /*
875 * Whereas SX1509 presents RegSense in a simple layout as such:
876 * reg [ f f e e d d c c ]
877 * reg + 1 [ b b a a 9 9 8 8 ]
878 * reg + 2 [ 7 7 6 6 5 5 4 4 ]
879 * reg + 3 [ 3 3 2 2 1 1 0 0 ]
880 *
881 * SX1503 and SX1506 deviate from that data layout, instead storing
882 * thier contents as follows:
883 *
884 * reg [ f f e e d d c c ]
885 * reg + 1 [ 7 7 6 6 5 5 4 4 ]
886 * reg + 2 [ b b a a 9 9 8 8 ]
887 * reg + 3 [ 3 3 2 2 1 1 0 0 ]
888 *
889 * so, taking that into account, we swap two
890 * inner bytes of a 4-byte result
891 */
892
893 if (reg == data->reg_sense &&
894 data->ngpios == 16 &&
895 (data->model == SX150X_123 ||
896 data->model == SX150X_456)) {
897 a = val & 0x00ff0000;
898 b = val & 0x0000ff00;
899
900 val &= 0xff0000ff;
901 val |= b << 8;
902 val |= a >> 8;
903 }
904
905 return val;
906}
907
908/*
909 * In order to mask the differences between 16 and 8 bit expander
910 * devices we set up a sligthly ficticious regmap that pretends to be
911 * a set of 32-bit (to accomodate RegSenseLow/RegSenseHigh
912 * pair/quartet) registers and transparently reconstructs those
913 * registers via multiple I2C/SMBus reads
914 *
915 * This way the rest of the driver code, interfacing with the chip via
916 * regmap API, can work assuming that each GPIO pin is represented by
917 * a group of bits at an offset proportioan to GPIO number within a
918 * given register.
919 *
920 */
921static int sx150x_regmap_reg_read(void *context, unsigned int reg,
922 unsigned int *result)
923{
924 int ret, n;
925 struct sx150x_pinctrl *pctl = context;
926 struct i2c_client *i2c = pctl->client;
927 const int width = sx150x_regmap_reg_width(pctl, reg);
928 unsigned int idx, val;
929
930 /*
931 * There are four potential cases coverd by this function:
932 *
933 * 1) 8-pin chip, single configuration bit register
934 *
935 * This is trivial the code below just needs to read:
936 * reg [ 7 6 5 4 3 2 1 0 ]
937 *
938 * 2) 8-pin chip, double configuration bit register (RegSense)
939 *
940 * The read will be done as follows:
941 * reg [ 7 7 6 6 5 5 4 4 ]
942 * reg + 1 [ 3 3 2 2 1 1 0 0 ]
943 *
944 * 3) 16-pin chip, single configuration bit register
945 *
946 * The read will be done as follows:
947 * reg [ f e d c b a 9 8 ]
948 * reg + 1 [ 7 6 5 4 3 2 1 0 ]
949 *
950 * 4) 16-pin chip, double configuration bit register (RegSense)
951 *
952 * The read will be done as follows:
953 * reg [ f f e e d d c c ]
954 * reg + 1 [ b b a a 9 9 8 8 ]
955 * reg + 2 [ 7 7 6 6 5 5 4 4 ]
956 * reg + 3 [ 3 3 2 2 1 1 0 0 ]
957 */
958
959 for (n = width, val = 0, idx = reg; n > 0; n -= 8, idx++) {
960 val <<= 8;
961
962 ret = i2c_smbus_read_byte_data(i2c, idx);
963 if (ret < 0)
964 return ret;
965
966 val |= ret;
967 }
968
969 *result = sx150x_maybe_swizzle(pctl, reg, val);
970
971 return 0;
972}
973
974static int sx150x_regmap_reg_write(void *context, unsigned int reg,
975 unsigned int val)
976{
977 int ret, n;
978 struct sx150x_pinctrl *pctl = context;
979 struct i2c_client *i2c = pctl->client;
980 const int width = sx150x_regmap_reg_width(pctl, reg);
981
982 val = sx150x_maybe_swizzle(pctl, reg, val);
983
984 n = width - 8;
985 do {
986 const u8 byte = (val >> n) & 0xff;
987
988 ret = i2c_smbus_write_byte_data(i2c, reg, byte);
989 if (ret < 0)
990 return ret;
991
992 reg++;
993 n -= 8;
994 } while (n >= 0);
Neil Armstrong9e80f902016-10-21 11:09:58 +0200995
996 return 0;
997}
998
Andrey Smirnov0db0f262016-11-07 08:53:16 -0800999static bool sx150x_reg_volatile(struct device *dev, unsigned int reg)
1000{
1001 struct sx150x_pinctrl *pctl = i2c_get_clientdata(to_i2c_client(dev));
1002
Andrey Smirnov64896772016-11-07 08:53:17 -08001003 return reg == pctl->data->reg_irq_src || reg == pctl->data->reg_data;
Andrey Smirnov0db0f262016-11-07 08:53:16 -08001004}
1005
1006const struct regmap_config sx150x_regmap_config = {
1007 .reg_bits = 8,
Andrey Smirnov64896772016-11-07 08:53:17 -08001008 .val_bits = 32,
Andrey Smirnov0db0f262016-11-07 08:53:16 -08001009
1010 .cache_type = REGCACHE_RBTREE,
1011
Andrey Smirnov64896772016-11-07 08:53:17 -08001012 .reg_read = sx150x_regmap_reg_read,
1013 .reg_write = sx150x_regmap_reg_write,
1014
Andrey Smirnov0db0f262016-11-07 08:53:16 -08001015 .max_register = SX150X_MAX_REGISTER,
1016 .volatile_reg = sx150x_reg_volatile,
1017};
1018
Neil Armstrong9e80f902016-10-21 11:09:58 +02001019static int sx150x_probe(struct i2c_client *client,
1020 const struct i2c_device_id *id)
1021{
1022 static const u32 i2c_funcs = I2C_FUNC_SMBUS_BYTE_DATA |
1023 I2C_FUNC_SMBUS_WRITE_WORD_DATA;
1024 struct device *dev = &client->dev;
1025 struct sx150x_pinctrl *pctl;
1026 int ret;
1027
Neil Armstrong9e80f902016-10-21 11:09:58 +02001028 if (!i2c_check_functionality(client->adapter, i2c_funcs))
1029 return -ENOSYS;
1030
1031 pctl = devm_kzalloc(dev, sizeof(*pctl), GFP_KERNEL);
1032 if (!pctl)
1033 return -ENOMEM;
1034
Andrey Smirnov0db0f262016-11-07 08:53:16 -08001035 i2c_set_clientdata(client, pctl);
1036
Neil Armstrong9e80f902016-10-21 11:09:58 +02001037 pctl->dev = dev;
1038 pctl->client = client;
Andrey Smirnove3ba8122016-11-07 08:53:09 -08001039
1040 if (dev->of_node)
1041 pctl->data = of_device_get_match_data(dev);
1042 else
1043 pctl->data = (struct sx150x_device_data *)id->driver_data;
1044
1045 if (!pctl->data)
1046 return -EINVAL;
Neil Armstrong9e80f902016-10-21 11:09:58 +02001047
Andrey Smirnov64896772016-11-07 08:53:17 -08001048 pctl->regmap = devm_regmap_init(dev, NULL, pctl,
1049 &sx150x_regmap_config);
Andrey Smirnov0db0f262016-11-07 08:53:16 -08001050 if (IS_ERR(pctl->regmap)) {
1051 ret = PTR_ERR(pctl->regmap);
1052 dev_err(dev, "Failed to allocate register map: %d\n",
1053 ret);
1054 return ret;
1055 }
1056
Neil Armstrong9e80f902016-10-21 11:09:58 +02001057 mutex_init(&pctl->lock);
1058
1059 ret = sx150x_init_hw(pctl);
1060 if (ret)
1061 return ret;
1062
1063 /* Register GPIO controller */
1064 pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL);
1065 pctl->gpio.base = -1;
1066 pctl->gpio.ngpio = pctl->data->npins;
1067 pctl->gpio.get_direction = sx150x_gpio_get_direction;
1068 pctl->gpio.direction_input = sx150x_gpio_direction_input;
1069 pctl->gpio.direction_output = sx150x_gpio_direction_output;
1070 pctl->gpio.get = sx150x_gpio_get;
1071 pctl->gpio.set = sx150x_gpio_set;
1072 pctl->gpio.set_single_ended = sx150x_gpio_set_single_ended;
1073 pctl->gpio.parent = dev;
1074#ifdef CONFIG_OF_GPIO
1075 pctl->gpio.of_node = dev->of_node;
1076#endif
1077 pctl->gpio.can_sleep = true;
1078
1079 ret = devm_gpiochip_add_data(dev, &pctl->gpio, pctl);
1080 if (ret)
1081 return ret;
1082
1083 /* Add Interrupt support if an irq is specified */
1084 if (client->irq > 0) {
1085 pctl->irq_chip.name = devm_kstrdup(dev, client->name,
1086 GFP_KERNEL);
1087 pctl->irq_chip.irq_mask = sx150x_irq_mask;
1088 pctl->irq_chip.irq_unmask = sx150x_irq_unmask;
1089 pctl->irq_chip.irq_set_type = sx150x_irq_set_type;
1090 pctl->irq_chip.irq_bus_lock = sx150x_irq_bus_lock;
1091 pctl->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock;
1092
1093 pctl->irq.masked = ~0;
1094 pctl->irq.sense = 0;
Neil Armstrong9e80f902016-10-21 11:09:58 +02001095
Andrey Smirnov080c4892016-11-07 08:53:21 -08001096 /*
1097 * Because sx150x_irq_threaded_fn invokes all of the
1098 * nested interrrupt handlers via handle_nested_irq,
1099 * any "handler" passed to gpiochip_irqchip_add()
1100 * below is going to be ignored, so the choice of the
1101 * function does not matter that much.
1102 *
1103 * We set it to handle_bad_irq to avoid confusion,
1104 * plus it will be instantly noticeable if it is ever
1105 * called (should not happen)
1106 */
Neil Armstrong9e80f902016-10-21 11:09:58 +02001107 ret = gpiochip_irqchip_add(&pctl->gpio,
1108 &pctl->irq_chip, 0,
Andrey Smirnov080c4892016-11-07 08:53:21 -08001109 handle_bad_irq, IRQ_TYPE_NONE);
Neil Armstrong9e80f902016-10-21 11:09:58 +02001110 if (ret) {
1111 dev_err(dev, "could not connect irqchip to gpiochip\n");
1112 return ret;
1113 }
1114
1115 ret = devm_request_threaded_irq(dev, client->irq, NULL,
1116 sx150x_irq_thread_fn,
1117 IRQF_ONESHOT | IRQF_SHARED |
1118 IRQF_TRIGGER_FALLING,
1119 pctl->irq_chip.name, pctl);
1120 if (ret < 0)
1121 return ret;
1122 }
1123
1124 /* Pinctrl_desc */
1125 pctl->pinctrl_desc.name = "sx150x-pinctrl";
1126 pctl->pinctrl_desc.pctlops = &sx150x_pinctrl_ops;
1127 pctl->pinctrl_desc.confops = &sx150x_pinconf_ops;
1128 pctl->pinctrl_desc.pins = pctl->data->pins;
1129 pctl->pinctrl_desc.npins = pctl->data->npins;
1130 pctl->pinctrl_desc.owner = THIS_MODULE;
1131
1132 pctl->pctldev = pinctrl_register(&pctl->pinctrl_desc, dev, pctl);
1133 if (IS_ERR(pctl->pctldev)) {
1134 dev_err(dev, "Failed to register pinctrl device\n");
1135 return PTR_ERR(pctl->pctldev);
1136 }
1137
1138 return 0;
1139}
1140
1141static struct i2c_driver sx150x_driver = {
1142 .driver = {
1143 .name = "sx150x-pinctrl",
1144 .of_match_table = of_match_ptr(sx150x_of_match),
1145 },
1146 .probe = sx150x_probe,
1147 .id_table = sx150x_id,
1148};
1149
1150static int __init sx150x_init(void)
1151{
1152 return i2c_add_driver(&sx150x_driver);
1153}
1154subsys_initcall(sx150x_init);