pinctrl-sx150x.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016, BayLibre, SAS. All rights reserved.
  4. * Author: Neil Armstrong <narmstrong@baylibre.com>
  5. *
  6. * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
  7. *
  8. * Driver for Semtech SX150X I2C GPIO Expanders
  9. * The handling of the 4-bit chips (SX1501/SX1504/SX1507) is untested.
  10. *
  11. * Author: Gregory Bean <gbean@codeaurora.org>
  12. */
  13. #include <linux/regmap.h>
  14. #include <linux/i2c.h>
  15. #include <linux/init.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/irq.h>
  18. #include <linux/mutex.h>
  19. #include <linux/slab.h>
  20. #include <linux/of.h>
  21. #include <linux/gpio/driver.h>
  22. #include <linux/pinctrl/pinconf.h>
  23. #include <linux/pinctrl/pinctrl.h>
  24. #include <linux/pinctrl/pinmux.h>
  25. #include <linux/pinctrl/pinconf-generic.h>
  26. #include "core.h"
  27. #include "pinconf.h"
  28. #include "pinctrl-utils.h"
  29. /* The chip models of sx150x */
  30. enum {
  31. SX150X_123 = 0,
  32. SX150X_456,
  33. SX150X_789,
  34. };
  35. enum {
  36. SX150X_789_REG_MISC_AUTOCLEAR_OFF = 1 << 0,
  37. SX150X_MAX_REGISTER = 0xad,
  38. SX150X_IRQ_TYPE_EDGE_RISING = 0x1,
  39. SX150X_IRQ_TYPE_EDGE_FALLING = 0x2,
  40. SX150X_789_RESET_KEY1 = 0x12,
  41. SX150X_789_RESET_KEY2 = 0x34,
  42. };
  43. struct sx150x_123_pri {
  44. u8 reg_pld_mode;
  45. u8 reg_pld_table0;
  46. u8 reg_pld_table1;
  47. u8 reg_pld_table2;
  48. u8 reg_pld_table3;
  49. u8 reg_pld_table4;
  50. u8 reg_advanced;
  51. };
  52. struct sx150x_456_pri {
  53. u8 reg_pld_mode;
  54. u8 reg_pld_table0;
  55. u8 reg_pld_table1;
  56. u8 reg_pld_table2;
  57. u8 reg_pld_table3;
  58. u8 reg_pld_table4;
  59. u8 reg_advanced;
  60. };
  61. struct sx150x_789_pri {
  62. u8 reg_drain;
  63. u8 reg_polarity;
  64. u8 reg_clock;
  65. u8 reg_misc;
  66. u8 reg_reset;
  67. u8 ngpios;
  68. };
  69. struct sx150x_device_data {
  70. u8 model;
  71. u8 reg_pullup;
  72. u8 reg_pulldn;
  73. u8 reg_dir;
  74. u8 reg_data;
  75. u8 reg_irq_mask;
  76. u8 reg_irq_src;
  77. u8 reg_sense;
  78. u8 ngpios;
  79. union {
  80. struct sx150x_123_pri x123;
  81. struct sx150x_456_pri x456;
  82. struct sx150x_789_pri x789;
  83. } pri;
  84. const struct pinctrl_pin_desc *pins;
  85. unsigned int npins;
  86. };
  87. struct sx150x_pinctrl {
  88. struct device *dev;
  89. struct i2c_client *client;
  90. struct pinctrl_dev *pctldev;
  91. struct pinctrl_desc pinctrl_desc;
  92. struct gpio_chip gpio;
  93. struct regmap *regmap;
  94. struct {
  95. u32 sense;
  96. u32 masked;
  97. } irq;
  98. struct mutex lock;
  99. const struct sx150x_device_data *data;
  100. };
  101. static const struct pinctrl_pin_desc sx150x_4_pins[] = {
  102. PINCTRL_PIN(0, "gpio0"),
  103. PINCTRL_PIN(1, "gpio1"),
  104. PINCTRL_PIN(2, "gpio2"),
  105. PINCTRL_PIN(3, "gpio3"),
  106. PINCTRL_PIN(4, "oscio"),
  107. };
  108. static const struct pinctrl_pin_desc sx150x_8_pins[] = {
  109. PINCTRL_PIN(0, "gpio0"),
  110. PINCTRL_PIN(1, "gpio1"),
  111. PINCTRL_PIN(2, "gpio2"),
  112. PINCTRL_PIN(3, "gpio3"),
  113. PINCTRL_PIN(4, "gpio4"),
  114. PINCTRL_PIN(5, "gpio5"),
  115. PINCTRL_PIN(6, "gpio6"),
  116. PINCTRL_PIN(7, "gpio7"),
  117. PINCTRL_PIN(8, "oscio"),
  118. };
  119. static const struct pinctrl_pin_desc sx150x_16_pins[] = {
  120. PINCTRL_PIN(0, "gpio0"),
  121. PINCTRL_PIN(1, "gpio1"),
  122. PINCTRL_PIN(2, "gpio2"),
  123. PINCTRL_PIN(3, "gpio3"),
  124. PINCTRL_PIN(4, "gpio4"),
  125. PINCTRL_PIN(5, "gpio5"),
  126. PINCTRL_PIN(6, "gpio6"),
  127. PINCTRL_PIN(7, "gpio7"),
  128. PINCTRL_PIN(8, "gpio8"),
  129. PINCTRL_PIN(9, "gpio9"),
  130. PINCTRL_PIN(10, "gpio10"),
  131. PINCTRL_PIN(11, "gpio11"),
  132. PINCTRL_PIN(12, "gpio12"),
  133. PINCTRL_PIN(13, "gpio13"),
  134. PINCTRL_PIN(14, "gpio14"),
  135. PINCTRL_PIN(15, "gpio15"),
  136. PINCTRL_PIN(16, "oscio"),
  137. };
  138. static const struct sx150x_device_data sx1501q_device_data = {
  139. .model = SX150X_123,
  140. .reg_pullup = 0x02,
  141. .reg_pulldn = 0x03,
  142. .reg_dir = 0x01,
  143. .reg_data = 0x00,
  144. .reg_irq_mask = 0x05,
  145. .reg_irq_src = 0x08,
  146. .reg_sense = 0x07,
  147. .pri.x123 = {
  148. .reg_pld_mode = 0x10,
  149. .reg_pld_table0 = 0x11,
  150. .reg_pld_table2 = 0x13,
  151. .reg_advanced = 0xad,
  152. },
  153. .ngpios = 4,
  154. .pins = sx150x_4_pins,
  155. .npins = 4, /* oscio not available */
  156. };
  157. static const struct sx150x_device_data sx1502q_device_data = {
  158. .model = SX150X_123,
  159. .reg_pullup = 0x02,
  160. .reg_pulldn = 0x03,
  161. .reg_dir = 0x01,
  162. .reg_data = 0x00,
  163. .reg_irq_mask = 0x05,
  164. .reg_irq_src = 0x08,
  165. .reg_sense = 0x06,
  166. .pri.x123 = {
  167. .reg_pld_mode = 0x10,
  168. .reg_pld_table0 = 0x11,
  169. .reg_pld_table1 = 0x12,
  170. .reg_pld_table2 = 0x13,
  171. .reg_pld_table3 = 0x14,
  172. .reg_pld_table4 = 0x15,
  173. .reg_advanced = 0xad,
  174. },
  175. .ngpios = 8,
  176. .pins = sx150x_8_pins,
  177. .npins = 8, /* oscio not available */
  178. };
  179. static const struct sx150x_device_data sx1503q_device_data = {
  180. .model = SX150X_123,
  181. .reg_pullup = 0x04,
  182. .reg_pulldn = 0x06,
  183. .reg_dir = 0x02,
  184. .reg_data = 0x00,
  185. .reg_irq_mask = 0x08,
  186. .reg_irq_src = 0x0e,
  187. .reg_sense = 0x0a,
  188. .pri.x123 = {
  189. .reg_pld_mode = 0x20,
  190. .reg_pld_table0 = 0x22,
  191. .reg_pld_table1 = 0x24,
  192. .reg_pld_table2 = 0x26,
  193. .reg_pld_table3 = 0x28,
  194. .reg_pld_table4 = 0x2a,
  195. .reg_advanced = 0xad,
  196. },
  197. .ngpios = 16,
  198. .pins = sx150x_16_pins,
  199. .npins = 16, /* oscio not available */
  200. };
  201. static const struct sx150x_device_data sx1504q_device_data = {
  202. .model = SX150X_456,
  203. .reg_pullup = 0x02,
  204. .reg_pulldn = 0x03,
  205. .reg_dir = 0x01,
  206. .reg_data = 0x00,
  207. .reg_irq_mask = 0x05,
  208. .reg_irq_src = 0x08,
  209. .reg_sense = 0x07,
  210. .pri.x456 = {
  211. .reg_pld_mode = 0x10,
  212. .reg_pld_table0 = 0x11,
  213. .reg_pld_table2 = 0x13,
  214. },
  215. .ngpios = 4,
  216. .pins = sx150x_4_pins,
  217. .npins = 4, /* oscio not available */
  218. };
  219. static const struct sx150x_device_data sx1505q_device_data = {
  220. .model = SX150X_456,
  221. .reg_pullup = 0x02,
  222. .reg_pulldn = 0x03,
  223. .reg_dir = 0x01,
  224. .reg_data = 0x00,
  225. .reg_irq_mask = 0x05,
  226. .reg_irq_src = 0x08,
  227. .reg_sense = 0x06,
  228. .pri.x456 = {
  229. .reg_pld_mode = 0x10,
  230. .reg_pld_table0 = 0x11,
  231. .reg_pld_table1 = 0x12,
  232. .reg_pld_table2 = 0x13,
  233. .reg_pld_table3 = 0x14,
  234. .reg_pld_table4 = 0x15,
  235. },
  236. .ngpios = 8,
  237. .pins = sx150x_8_pins,
  238. .npins = 8, /* oscio not available */
  239. };
  240. static const struct sx150x_device_data sx1506q_device_data = {
  241. .model = SX150X_456,
  242. .reg_pullup = 0x04,
  243. .reg_pulldn = 0x06,
  244. .reg_dir = 0x02,
  245. .reg_data = 0x00,
  246. .reg_irq_mask = 0x08,
  247. .reg_irq_src = 0x0e,
  248. .reg_sense = 0x0a,
  249. .pri.x456 = {
  250. .reg_pld_mode = 0x20,
  251. .reg_pld_table0 = 0x22,
  252. .reg_pld_table1 = 0x24,
  253. .reg_pld_table2 = 0x26,
  254. .reg_pld_table3 = 0x28,
  255. .reg_pld_table4 = 0x2a,
  256. .reg_advanced = 0xad,
  257. },
  258. .ngpios = 16,
  259. .pins = sx150x_16_pins,
  260. .npins = 16, /* oscio not available */
  261. };
  262. static const struct sx150x_device_data sx1507q_device_data = {
  263. .model = SX150X_789,
  264. .reg_pullup = 0x03,
  265. .reg_pulldn = 0x04,
  266. .reg_dir = 0x07,
  267. .reg_data = 0x08,
  268. .reg_irq_mask = 0x09,
  269. .reg_irq_src = 0x0b,
  270. .reg_sense = 0x0a,
  271. .pri.x789 = {
  272. .reg_drain = 0x05,
  273. .reg_polarity = 0x06,
  274. .reg_clock = 0x0d,
  275. .reg_misc = 0x0e,
  276. .reg_reset = 0x7d,
  277. },
  278. .ngpios = 4,
  279. .pins = sx150x_4_pins,
  280. .npins = ARRAY_SIZE(sx150x_4_pins),
  281. };
  282. static const struct sx150x_device_data sx1508q_device_data = {
  283. .model = SX150X_789,
  284. .reg_pullup = 0x03,
  285. .reg_pulldn = 0x04,
  286. .reg_dir = 0x07,
  287. .reg_data = 0x08,
  288. .reg_irq_mask = 0x09,
  289. .reg_irq_src = 0x0c,
  290. .reg_sense = 0x0a,
  291. .pri.x789 = {
  292. .reg_drain = 0x05,
  293. .reg_polarity = 0x06,
  294. .reg_clock = 0x0f,
  295. .reg_misc = 0x10,
  296. .reg_reset = 0x7d,
  297. },
  298. .ngpios = 8,
  299. .pins = sx150x_8_pins,
  300. .npins = ARRAY_SIZE(sx150x_8_pins),
  301. };
  302. static const struct sx150x_device_data sx1509q_device_data = {
  303. .model = SX150X_789,
  304. .reg_pullup = 0x06,
  305. .reg_pulldn = 0x08,
  306. .reg_dir = 0x0e,
  307. .reg_data = 0x10,
  308. .reg_irq_mask = 0x12,
  309. .reg_irq_src = 0x18,
  310. .reg_sense = 0x14,
  311. .pri.x789 = {
  312. .reg_drain = 0x0a,
  313. .reg_polarity = 0x0c,
  314. .reg_clock = 0x1e,
  315. .reg_misc = 0x1f,
  316. .reg_reset = 0x7d,
  317. },
  318. .ngpios = 16,
  319. .pins = sx150x_16_pins,
  320. .npins = ARRAY_SIZE(sx150x_16_pins),
  321. };
  322. static int sx150x_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
  323. {
  324. return 0;
  325. }
  326. static const char *sx150x_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
  327. unsigned int group)
  328. {
  329. return NULL;
  330. }
  331. static int sx150x_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
  332. unsigned int group,
  333. const unsigned int **pins,
  334. unsigned int *num_pins)
  335. {
  336. return -ENOTSUPP;
  337. }
  338. static const struct pinctrl_ops sx150x_pinctrl_ops = {
  339. .get_groups_count = sx150x_pinctrl_get_groups_count,
  340. .get_group_name = sx150x_pinctrl_get_group_name,
  341. .get_group_pins = sx150x_pinctrl_get_group_pins,
  342. #ifdef CONFIG_OF
  343. .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
  344. .dt_free_map = pinctrl_utils_free_map,
  345. #endif
  346. };
  347. static bool sx150x_pin_is_oscio(struct sx150x_pinctrl *pctl, unsigned int pin)
  348. {
  349. if (pin >= pctl->data->npins)
  350. return false;
  351. /* OSCIO pin is only present in 789 devices */
  352. if (pctl->data->model != SX150X_789)
  353. return false;
  354. return !strcmp(pctl->data->pins[pin].name, "oscio");
  355. }
  356. static int sx150x_gpio_get_direction(struct gpio_chip *chip,
  357. unsigned int offset)
  358. {
  359. struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
  360. unsigned int value;
  361. int ret;
  362. if (sx150x_pin_is_oscio(pctl, offset))
  363. return GPIO_LINE_DIRECTION_OUT;
  364. ret = regmap_read(pctl->regmap, pctl->data->reg_dir, &value);
  365. if (ret < 0)
  366. return ret;
  367. if (value & BIT(offset))
  368. return GPIO_LINE_DIRECTION_IN;
  369. return GPIO_LINE_DIRECTION_OUT;
  370. }
  371. static int sx150x_gpio_get(struct gpio_chip *chip, unsigned int offset)
  372. {
  373. struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
  374. unsigned int value;
  375. int ret;
  376. if (sx150x_pin_is_oscio(pctl, offset))
  377. return -EINVAL;
  378. ret = regmap_read(pctl->regmap, pctl->data->reg_data, &value);
  379. if (ret < 0)
  380. return ret;
  381. return !!(value & BIT(offset));
  382. }
  383. static int __sx150x_gpio_set(struct sx150x_pinctrl *pctl, unsigned int offset,
  384. int value)
  385. {
  386. return regmap_write_bits(pctl->regmap, pctl->data->reg_data,
  387. BIT(offset), value ? BIT(offset) : 0);
  388. }
  389. static int sx150x_gpio_oscio_set(struct sx150x_pinctrl *pctl,
  390. int value)
  391. {
  392. return regmap_write(pctl->regmap,
  393. pctl->data->pri.x789.reg_clock,
  394. (value ? 0x1f : 0x10));
  395. }
  396. static int sx150x_gpio_set(struct gpio_chip *chip, unsigned int offset,
  397. int value)
  398. {
  399. struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
  400. if (sx150x_pin_is_oscio(pctl, offset))
  401. return sx150x_gpio_oscio_set(pctl, value);
  402. return __sx150x_gpio_set(pctl, offset, value);
  403. }
  404. static int sx150x_gpio_set_multiple(struct gpio_chip *chip,
  405. unsigned long *mask,
  406. unsigned long *bits)
  407. {
  408. struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
  409. return regmap_write_bits(pctl->regmap, pctl->data->reg_data, *mask,
  410. *bits);
  411. }
  412. static int sx150x_gpio_direction_input(struct gpio_chip *chip,
  413. unsigned int offset)
  414. {
  415. struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
  416. if (sx150x_pin_is_oscio(pctl, offset))
  417. return -EINVAL;
  418. return regmap_write_bits(pctl->regmap,
  419. pctl->data->reg_dir,
  420. BIT(offset), BIT(offset));
  421. }
  422. static int sx150x_gpio_direction_output(struct gpio_chip *chip,
  423. unsigned int offset, int value)
  424. {
  425. struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
  426. int ret;
  427. if (sx150x_pin_is_oscio(pctl, offset))
  428. return sx150x_gpio_oscio_set(pctl, value);
  429. ret = __sx150x_gpio_set(pctl, offset, value);
  430. if (ret < 0)
  431. return ret;
  432. return regmap_write_bits(pctl->regmap,
  433. pctl->data->reg_dir,
  434. BIT(offset), 0);
  435. }
  436. static void sx150x_irq_mask(struct irq_data *d)
  437. {
  438. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  439. struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
  440. unsigned int n = irqd_to_hwirq(d);
  441. pctl->irq.masked |= BIT(n);
  442. gpiochip_disable_irq(gc, n);
  443. }
  444. static void sx150x_irq_unmask(struct irq_data *d)
  445. {
  446. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  447. struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
  448. unsigned int n = irqd_to_hwirq(d);
  449. gpiochip_enable_irq(gc, n);
  450. pctl->irq.masked &= ~BIT(n);
  451. }
  452. static void sx150x_irq_set_sense(struct sx150x_pinctrl *pctl,
  453. unsigned int line, unsigned int sense)
  454. {
  455. /*
  456. * Every interrupt line is represented by two bits shifted
  457. * proportionally to the line number
  458. */
  459. const unsigned int n = line * 2;
  460. const unsigned int mask = ~((SX150X_IRQ_TYPE_EDGE_RISING |
  461. SX150X_IRQ_TYPE_EDGE_FALLING) << n);
  462. pctl->irq.sense &= mask;
  463. pctl->irq.sense |= sense << n;
  464. }
  465. static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type)
  466. {
  467. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  468. struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
  469. unsigned int n, val = 0;
  470. if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
  471. return -EINVAL;
  472. n = irqd_to_hwirq(d);
  473. if (flow_type & IRQ_TYPE_EDGE_RISING)
  474. val |= SX150X_IRQ_TYPE_EDGE_RISING;
  475. if (flow_type & IRQ_TYPE_EDGE_FALLING)
  476. val |= SX150X_IRQ_TYPE_EDGE_FALLING;
  477. sx150x_irq_set_sense(pctl, n, val);
  478. return 0;
  479. }
  480. static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id)
  481. {
  482. struct sx150x_pinctrl *pctl = (struct sx150x_pinctrl *)dev_id;
  483. unsigned long n, status;
  484. unsigned int val;
  485. int err;
  486. err = regmap_read(pctl->regmap, pctl->data->reg_irq_src, &val);
  487. if (err < 0)
  488. return IRQ_NONE;
  489. err = regmap_write(pctl->regmap, pctl->data->reg_irq_src, val);
  490. if (err < 0)
  491. return IRQ_NONE;
  492. status = val;
  493. for_each_set_bit(n, &status, pctl->data->ngpios)
  494. handle_nested_irq(irq_find_mapping(pctl->gpio.irq.domain, n));
  495. return IRQ_HANDLED;
  496. }
  497. static void sx150x_irq_bus_lock(struct irq_data *d)
  498. {
  499. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  500. struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
  501. mutex_lock(&pctl->lock);
  502. }
  503. static void sx150x_irq_bus_sync_unlock(struct irq_data *d)
  504. {
  505. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  506. struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
  507. regmap_write(pctl->regmap, pctl->data->reg_irq_mask, pctl->irq.masked);
  508. regmap_write(pctl->regmap, pctl->data->reg_sense, pctl->irq.sense);
  509. mutex_unlock(&pctl->lock);
  510. }
  511. static void sx150x_irq_print_chip(struct irq_data *d, struct seq_file *p)
  512. {
  513. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  514. struct sx150x_pinctrl *pctl = gpiochip_get_data(gc);
  515. seq_puts(p, pctl->client->name);
  516. }
  517. static const struct irq_chip sx150x_irq_chip = {
  518. .irq_mask = sx150x_irq_mask,
  519. .irq_unmask = sx150x_irq_unmask,
  520. .irq_set_type = sx150x_irq_set_type,
  521. .irq_bus_lock = sx150x_irq_bus_lock,
  522. .irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock,
  523. .irq_print_chip = sx150x_irq_print_chip,
  524. .flags = IRQCHIP_IMMUTABLE,
  525. GPIOCHIP_IRQ_RESOURCE_HELPERS,
  526. };
  527. static int sx150x_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
  528. unsigned long *config)
  529. {
  530. struct sx150x_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  531. unsigned int param = pinconf_to_config_param(*config);
  532. int ret;
  533. u32 arg;
  534. unsigned int data;
  535. if (sx150x_pin_is_oscio(pctl, pin)) {
  536. switch (param) {
  537. case PIN_CONFIG_DRIVE_PUSH_PULL:
  538. case PIN_CONFIG_LEVEL:
  539. ret = regmap_read(pctl->regmap,
  540. pctl->data->pri.x789.reg_clock,
  541. &data);
  542. if (ret < 0)
  543. return ret;
  544. if (param == PIN_CONFIG_DRIVE_PUSH_PULL)
  545. arg = (data & 0x1f) ? 1 : 0;
  546. else {
  547. if ((data & 0x1f) == 0x1f)
  548. arg = 1;
  549. else if ((data & 0x1f) == 0x10)
  550. arg = 0;
  551. else
  552. return -EINVAL;
  553. }
  554. break;
  555. default:
  556. return -ENOTSUPP;
  557. }
  558. goto out;
  559. }
  560. switch (param) {
  561. case PIN_CONFIG_BIAS_PULL_DOWN:
  562. ret = regmap_read(pctl->regmap,
  563. pctl->data->reg_pulldn,
  564. &data);
  565. data &= BIT(pin);
  566. if (ret < 0)
  567. return ret;
  568. if (!ret)
  569. return -EINVAL;
  570. arg = 1;
  571. break;
  572. case PIN_CONFIG_BIAS_PULL_UP:
  573. ret = regmap_read(pctl->regmap,
  574. pctl->data->reg_pullup,
  575. &data);
  576. data &= BIT(pin);
  577. if (ret < 0)
  578. return ret;
  579. if (!ret)
  580. return -EINVAL;
  581. arg = 1;
  582. break;
  583. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  584. if (pctl->data->model != SX150X_789)
  585. return -ENOTSUPP;
  586. ret = regmap_read(pctl->regmap,
  587. pctl->data->pri.x789.reg_drain,
  588. &data);
  589. data &= BIT(pin);
  590. if (ret < 0)
  591. return ret;
  592. if (!data)
  593. return -EINVAL;
  594. arg = 1;
  595. break;
  596. case PIN_CONFIG_DRIVE_PUSH_PULL:
  597. if (pctl->data->model != SX150X_789)
  598. arg = true;
  599. else {
  600. ret = regmap_read(pctl->regmap,
  601. pctl->data->pri.x789.reg_drain,
  602. &data);
  603. data &= BIT(pin);
  604. if (ret < 0)
  605. return ret;
  606. if (data)
  607. return -EINVAL;
  608. arg = 1;
  609. }
  610. break;
  611. case PIN_CONFIG_LEVEL:
  612. ret = sx150x_gpio_get_direction(&pctl->gpio, pin);
  613. if (ret < 0)
  614. return ret;
  615. if (ret == GPIO_LINE_DIRECTION_IN)
  616. return -EINVAL;
  617. ret = sx150x_gpio_get(&pctl->gpio, pin);
  618. if (ret < 0)
  619. return ret;
  620. arg = ret;
  621. break;
  622. default:
  623. return -ENOTSUPP;
  624. }
  625. out:
  626. *config = pinconf_to_config_packed(param, arg);
  627. return 0;
  628. }
  629. static int sx150x_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
  630. unsigned long *configs, unsigned int num_configs)
  631. {
  632. struct sx150x_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
  633. enum pin_config_param param;
  634. u32 arg;
  635. int i;
  636. int ret;
  637. for (i = 0; i < num_configs; i++) {
  638. param = pinconf_to_config_param(configs[i]);
  639. arg = pinconf_to_config_argument(configs[i]);
  640. if (sx150x_pin_is_oscio(pctl, pin)) {
  641. if (param == PIN_CONFIG_LEVEL) {
  642. ret = sx150x_gpio_direction_output(&pctl->gpio,
  643. pin, arg);
  644. if (ret < 0)
  645. return ret;
  646. continue;
  647. } else
  648. return -ENOTSUPP;
  649. }
  650. switch (param) {
  651. case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
  652. case PIN_CONFIG_BIAS_DISABLE:
  653. ret = regmap_write_bits(pctl->regmap,
  654. pctl->data->reg_pulldn,
  655. BIT(pin), 0);
  656. if (ret < 0)
  657. return ret;
  658. ret = regmap_write_bits(pctl->regmap,
  659. pctl->data->reg_pullup,
  660. BIT(pin), 0);
  661. if (ret < 0)
  662. return ret;
  663. break;
  664. case PIN_CONFIG_BIAS_PULL_UP:
  665. ret = regmap_write_bits(pctl->regmap,
  666. pctl->data->reg_pullup,
  667. BIT(pin), BIT(pin));
  668. if (ret < 0)
  669. return ret;
  670. break;
  671. case PIN_CONFIG_BIAS_PULL_DOWN:
  672. ret = regmap_write_bits(pctl->regmap,
  673. pctl->data->reg_pulldn,
  674. BIT(pin), BIT(pin));
  675. if (ret < 0)
  676. return ret;
  677. break;
  678. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  679. if (pctl->data->model != SX150X_789 ||
  680. sx150x_pin_is_oscio(pctl, pin))
  681. return -ENOTSUPP;
  682. ret = regmap_write_bits(pctl->regmap,
  683. pctl->data->pri.x789.reg_drain,
  684. BIT(pin), BIT(pin));
  685. if (ret < 0)
  686. return ret;
  687. break;
  688. case PIN_CONFIG_DRIVE_PUSH_PULL:
  689. if (pctl->data->model != SX150X_789 ||
  690. sx150x_pin_is_oscio(pctl, pin))
  691. return 0;
  692. ret = regmap_write_bits(pctl->regmap,
  693. pctl->data->pri.x789.reg_drain,
  694. BIT(pin), 0);
  695. if (ret < 0)
  696. return ret;
  697. break;
  698. case PIN_CONFIG_LEVEL:
  699. ret = sx150x_gpio_direction_output(&pctl->gpio,
  700. pin, arg);
  701. if (ret < 0)
  702. return ret;
  703. break;
  704. default:
  705. return -ENOTSUPP;
  706. }
  707. } /* for each config */
  708. return 0;
  709. }
  710. static const struct pinconf_ops sx150x_pinconf_ops = {
  711. .pin_config_get = sx150x_pinconf_get,
  712. .pin_config_set = sx150x_pinconf_set,
  713. .is_generic = true,
  714. };
  715. static const struct i2c_device_id sx150x_id[] = {
  716. {"sx1501q", (kernel_ulong_t) &sx1501q_device_data },
  717. {"sx1502q", (kernel_ulong_t) &sx1502q_device_data },
  718. {"sx1503q", (kernel_ulong_t) &sx1503q_device_data },
  719. {"sx1504q", (kernel_ulong_t) &sx1504q_device_data },
  720. {"sx1505q", (kernel_ulong_t) &sx1505q_device_data },
  721. {"sx1506q", (kernel_ulong_t) &sx1506q_device_data },
  722. {"sx1507q", (kernel_ulong_t) &sx1507q_device_data },
  723. {"sx1508q", (kernel_ulong_t) &sx1508q_device_data },
  724. {"sx1509q", (kernel_ulong_t) &sx1509q_device_data },
  725. {}
  726. };
  727. static const struct of_device_id sx150x_of_match[] = {
  728. { .compatible = "semtech,sx1501q", .data = &sx1501q_device_data },
  729. { .compatible = "semtech,sx1502q", .data = &sx1502q_device_data },
  730. { .compatible = "semtech,sx1503q", .data = &sx1503q_device_data },
  731. { .compatible = "semtech,sx1504q", .data = &sx1504q_device_data },
  732. { .compatible = "semtech,sx1505q", .data = &sx1505q_device_data },
  733. { .compatible = "semtech,sx1506q", .data = &sx1506q_device_data },
  734. { .compatible = "semtech,sx1507q", .data = &sx1507q_device_data },
  735. { .compatible = "semtech,sx1508q", .data = &sx1508q_device_data },
  736. { .compatible = "semtech,sx1509q", .data = &sx1509q_device_data },
  737. {},
  738. };
  739. MODULE_DEVICE_TABLE(of, sx150x_of_match);
  740. static int sx150x_reset(struct sx150x_pinctrl *pctl)
  741. {
  742. int err;
  743. err = i2c_smbus_write_byte_data(pctl->client,
  744. pctl->data->pri.x789.reg_reset,
  745. SX150X_789_RESET_KEY1);
  746. if (err < 0)
  747. return err;
  748. err = i2c_smbus_write_byte_data(pctl->client,
  749. pctl->data->pri.x789.reg_reset,
  750. SX150X_789_RESET_KEY2);
  751. return err;
  752. }
  753. static int sx150x_init_misc(struct sx150x_pinctrl *pctl)
  754. {
  755. u8 reg, value;
  756. switch (pctl->data->model) {
  757. case SX150X_789:
  758. reg = pctl->data->pri.x789.reg_misc;
  759. value = SX150X_789_REG_MISC_AUTOCLEAR_OFF;
  760. break;
  761. case SX150X_456:
  762. reg = pctl->data->pri.x456.reg_advanced;
  763. value = 0x00;
  764. /*
  765. * Only SX1506 has RegAdvanced, SX1504/5 are expected
  766. * to initialize this offset to zero
  767. */
  768. if (!reg)
  769. return 0;
  770. break;
  771. case SX150X_123:
  772. reg = pctl->data->pri.x123.reg_advanced;
  773. value = 0x00;
  774. break;
  775. default:
  776. WARN(1, "Unknown chip model %d\n", pctl->data->model);
  777. return -EINVAL;
  778. }
  779. return regmap_write(pctl->regmap, reg, value);
  780. }
  781. static int sx150x_init_hw(struct sx150x_pinctrl *pctl)
  782. {
  783. const u8 reg[] = {
  784. [SX150X_789] = pctl->data->pri.x789.reg_polarity,
  785. [SX150X_456] = pctl->data->pri.x456.reg_pld_mode,
  786. [SX150X_123] = pctl->data->pri.x123.reg_pld_mode,
  787. };
  788. int err;
  789. if (pctl->data->model == SX150X_789 &&
  790. of_property_read_bool(pctl->dev->of_node, "semtech,probe-reset")) {
  791. err = sx150x_reset(pctl);
  792. if (err < 0)
  793. return err;
  794. }
  795. err = sx150x_init_misc(pctl);
  796. if (err < 0)
  797. return err;
  798. /* Set all pins to work in normal mode */
  799. return regmap_write(pctl->regmap, reg[pctl->data->model], 0);
  800. }
  801. static int sx150x_regmap_reg_width(struct sx150x_pinctrl *pctl,
  802. unsigned int reg)
  803. {
  804. const struct sx150x_device_data *data = pctl->data;
  805. if (reg == data->reg_sense) {
  806. /*
  807. * RegSense packs two bits of configuration per GPIO,
  808. * so we'd need to read twice as many bits as there
  809. * are GPIO in our chip
  810. */
  811. return 2 * data->ngpios;
  812. } else if ((data->model == SX150X_789 &&
  813. (reg == data->pri.x789.reg_misc ||
  814. reg == data->pri.x789.reg_clock ||
  815. reg == data->pri.x789.reg_reset))
  816. ||
  817. (data->model == SX150X_123 &&
  818. reg == data->pri.x123.reg_advanced)
  819. ||
  820. (data->model == SX150X_456 &&
  821. data->pri.x456.reg_advanced &&
  822. reg == data->pri.x456.reg_advanced)) {
  823. return 8;
  824. } else {
  825. return data->ngpios;
  826. }
  827. }
  828. static unsigned int sx150x_maybe_swizzle(struct sx150x_pinctrl *pctl,
  829. unsigned int reg, unsigned int val)
  830. {
  831. unsigned int a, b;
  832. const struct sx150x_device_data *data = pctl->data;
  833. /*
  834. * Whereas SX1509 presents RegSense in a simple layout as such:
  835. * reg [ f f e e d d c c ]
  836. * reg + 1 [ b b a a 9 9 8 8 ]
  837. * reg + 2 [ 7 7 6 6 5 5 4 4 ]
  838. * reg + 3 [ 3 3 2 2 1 1 0 0 ]
  839. *
  840. * SX1503 and SX1506 deviate from that data layout, instead storing
  841. * their contents as follows:
  842. *
  843. * reg [ f f e e d d c c ]
  844. * reg + 1 [ 7 7 6 6 5 5 4 4 ]
  845. * reg + 2 [ b b a a 9 9 8 8 ]
  846. * reg + 3 [ 3 3 2 2 1 1 0 0 ]
  847. *
  848. * so, taking that into account, we swap two
  849. * inner bytes of a 4-byte result
  850. */
  851. if (reg == data->reg_sense &&
  852. data->ngpios == 16 &&
  853. (data->model == SX150X_123 ||
  854. data->model == SX150X_456)) {
  855. a = val & 0x00ff0000;
  856. b = val & 0x0000ff00;
  857. val &= 0xff0000ff;
  858. val |= b << 8;
  859. val |= a >> 8;
  860. }
  861. return val;
  862. }
  863. /*
  864. * In order to mask the differences between 16 and 8 bit expander
  865. * devices we set up a sligthly ficticious regmap that pretends to be
  866. * a set of 32-bit (to accommodate RegSenseLow/RegSenseHigh
  867. * pair/quartet) registers and transparently reconstructs those
  868. * registers via multiple I2C/SMBus reads
  869. *
  870. * This way the rest of the driver code, interfacing with the chip via
  871. * regmap API, can work assuming that each GPIO pin is represented by
  872. * a group of bits at an offset proportional to GPIO number within a
  873. * given register.
  874. */
  875. static int sx150x_regmap_reg_read(void *context, unsigned int reg,
  876. unsigned int *result)
  877. {
  878. int ret, n;
  879. struct sx150x_pinctrl *pctl = context;
  880. struct i2c_client *i2c = pctl->client;
  881. const int width = sx150x_regmap_reg_width(pctl, reg);
  882. unsigned int idx, val;
  883. /*
  884. * There are four potential cases covered by this function:
  885. *
  886. * 1) 8-pin chip, single configuration bit register
  887. *
  888. * This is trivial the code below just needs to read:
  889. * reg [ 7 6 5 4 3 2 1 0 ]
  890. *
  891. * 2) 8-pin chip, double configuration bit register (RegSense)
  892. *
  893. * The read will be done as follows:
  894. * reg [ 7 7 6 6 5 5 4 4 ]
  895. * reg + 1 [ 3 3 2 2 1 1 0 0 ]
  896. *
  897. * 3) 16-pin chip, single configuration bit register
  898. *
  899. * The read will be done as follows:
  900. * reg [ f e d c b a 9 8 ]
  901. * reg + 1 [ 7 6 5 4 3 2 1 0 ]
  902. *
  903. * 4) 16-pin chip, double configuration bit register (RegSense)
  904. *
  905. * The read will be done as follows:
  906. * reg [ f f e e d d c c ]
  907. * reg + 1 [ b b a a 9 9 8 8 ]
  908. * reg + 2 [ 7 7 6 6 5 5 4 4 ]
  909. * reg + 3 [ 3 3 2 2 1 1 0 0 ]
  910. */
  911. for (n = width, val = 0, idx = reg; n > 0; n -= 8, idx++) {
  912. val <<= 8;
  913. ret = i2c_smbus_read_byte_data(i2c, idx);
  914. if (ret < 0)
  915. return ret;
  916. val |= ret;
  917. }
  918. *result = sx150x_maybe_swizzle(pctl, reg, val);
  919. return 0;
  920. }
  921. static int sx150x_regmap_reg_write(void *context, unsigned int reg,
  922. unsigned int val)
  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. val = sx150x_maybe_swizzle(pctl, reg, val);
  929. n = (width - 1) & ~7;
  930. do {
  931. const u8 byte = (val >> n) & 0xff;
  932. ret = i2c_smbus_write_byte_data(i2c, reg, byte);
  933. if (ret < 0)
  934. return ret;
  935. reg++;
  936. n -= 8;
  937. } while (n >= 0);
  938. return 0;
  939. }
  940. static bool sx150x_reg_volatile(struct device *dev, unsigned int reg)
  941. {
  942. struct sx150x_pinctrl *pctl = i2c_get_clientdata(to_i2c_client(dev));
  943. return reg == pctl->data->reg_irq_src || reg == pctl->data->reg_data;
  944. }
  945. static const struct regmap_config sx150x_regmap_config = {
  946. .reg_bits = 8,
  947. .val_bits = 32,
  948. .cache_type = REGCACHE_MAPLE,
  949. .reg_read = sx150x_regmap_reg_read,
  950. .reg_write = sx150x_regmap_reg_write,
  951. .max_register = SX150X_MAX_REGISTER,
  952. .volatile_reg = sx150x_reg_volatile,
  953. };
  954. static int sx150x_probe(struct i2c_client *client)
  955. {
  956. static const u32 i2c_funcs = I2C_FUNC_SMBUS_BYTE_DATA |
  957. I2C_FUNC_SMBUS_WRITE_WORD_DATA;
  958. struct device *dev = &client->dev;
  959. struct sx150x_pinctrl *pctl;
  960. int ret;
  961. if (!i2c_check_functionality(client->adapter, i2c_funcs))
  962. return -ENOSYS;
  963. pctl = devm_kzalloc(dev, sizeof(*pctl), GFP_KERNEL);
  964. if (!pctl)
  965. return -ENOMEM;
  966. i2c_set_clientdata(client, pctl);
  967. pctl->dev = dev;
  968. pctl->client = client;
  969. pctl->data = i2c_get_match_data(client);
  970. if (!pctl->data)
  971. return -EINVAL;
  972. pctl->regmap = devm_regmap_init(dev, NULL, pctl,
  973. &sx150x_regmap_config);
  974. if (IS_ERR(pctl->regmap)) {
  975. ret = PTR_ERR(pctl->regmap);
  976. dev_err(dev, "Failed to allocate register map: %d\n",
  977. ret);
  978. return ret;
  979. }
  980. mutex_init(&pctl->lock);
  981. ret = sx150x_init_hw(pctl);
  982. if (ret)
  983. return ret;
  984. /* Pinctrl_desc */
  985. pctl->pinctrl_desc.name = "sx150x-pinctrl";
  986. pctl->pinctrl_desc.pctlops = &sx150x_pinctrl_ops;
  987. pctl->pinctrl_desc.confops = &sx150x_pinconf_ops;
  988. pctl->pinctrl_desc.pins = pctl->data->pins;
  989. pctl->pinctrl_desc.npins = pctl->data->npins;
  990. pctl->pinctrl_desc.owner = THIS_MODULE;
  991. ret = devm_pinctrl_register_and_init(dev, &pctl->pinctrl_desc,
  992. pctl, &pctl->pctldev);
  993. if (ret) {
  994. dev_err(dev, "Failed to register pinctrl device\n");
  995. return ret;
  996. }
  997. /* Register GPIO controller */
  998. pctl->gpio.base = -1;
  999. pctl->gpio.ngpio = pctl->data->npins;
  1000. pctl->gpio.get_direction = sx150x_gpio_get_direction;
  1001. pctl->gpio.direction_input = sx150x_gpio_direction_input;
  1002. pctl->gpio.direction_output = sx150x_gpio_direction_output;
  1003. pctl->gpio.get = sx150x_gpio_get;
  1004. pctl->gpio.set = sx150x_gpio_set;
  1005. pctl->gpio.set_config = gpiochip_generic_config;
  1006. pctl->gpio.parent = dev;
  1007. pctl->gpio.can_sleep = true;
  1008. pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL);
  1009. if (!pctl->gpio.label)
  1010. return -ENOMEM;
  1011. /*
  1012. * Setting multiple pins is not safe when all pins are not
  1013. * handled by the same regmap register. The oscio pin (present
  1014. * on the SX150X_789 chips) lives in its own register, so
  1015. * would require locking that is not in place at this time.
  1016. */
  1017. if (pctl->data->model != SX150X_789)
  1018. pctl->gpio.set_multiple = sx150x_gpio_set_multiple;
  1019. /* Add Interrupt support if an irq is specified */
  1020. if (client->irq > 0) {
  1021. struct gpio_irq_chip *girq;
  1022. pctl->irq.masked = ~0;
  1023. pctl->irq.sense = 0;
  1024. /*
  1025. * Because sx150x_irq_threaded_fn invokes all of the
  1026. * nested interrupt handlers via handle_nested_irq,
  1027. * any "handler" assigned to struct gpio_irq_chip
  1028. * below is going to be ignored, so the choice of the
  1029. * function does not matter that much.
  1030. *
  1031. * We set it to handle_bad_irq to avoid confusion,
  1032. * plus it will be instantly noticeable if it is ever
  1033. * called (should not happen)
  1034. */
  1035. girq = &pctl->gpio.irq;
  1036. gpio_irq_chip_set_chip(girq, &sx150x_irq_chip);
  1037. /* This will let us handle the parent IRQ in the driver */
  1038. girq->parent_handler = NULL;
  1039. girq->num_parents = 0;
  1040. girq->parents = NULL;
  1041. girq->default_type = IRQ_TYPE_NONE;
  1042. girq->handler = handle_bad_irq;
  1043. girq->threaded = true;
  1044. ret = devm_request_threaded_irq(dev, client->irq, NULL,
  1045. sx150x_irq_thread_fn,
  1046. IRQF_ONESHOT | IRQF_SHARED |
  1047. IRQF_TRIGGER_FALLING,
  1048. client->name, pctl);
  1049. if (ret < 0)
  1050. return ret;
  1051. }
  1052. ret = devm_gpiochip_add_data(dev, &pctl->gpio, pctl);
  1053. if (ret)
  1054. return ret;
  1055. /*
  1056. * Pin control functions need to be enabled AFTER registering the
  1057. * GPIO chip because sx150x_pinconf_set() calls
  1058. * sx150x_gpio_direction_output().
  1059. */
  1060. ret = pinctrl_enable(pctl->pctldev);
  1061. if (ret) {
  1062. dev_err(dev, "Failed to enable pinctrl device\n");
  1063. return ret;
  1064. }
  1065. ret = gpiochip_add_pin_range(&pctl->gpio, dev_name(dev),
  1066. 0, 0, pctl->data->npins);
  1067. if (ret)
  1068. return ret;
  1069. return 0;
  1070. }
  1071. static struct i2c_driver sx150x_driver = {
  1072. .driver = {
  1073. .name = "sx150x-pinctrl",
  1074. .of_match_table = sx150x_of_match,
  1075. },
  1076. .probe = sx150x_probe,
  1077. .id_table = sx150x_id,
  1078. };
  1079. static int __init sx150x_init(void)
  1080. {
  1081. return i2c_add_driver(&sx150x_driver);
  1082. }
  1083. subsys_initcall(sx150x_init);
  1084. MODULE_DESCRIPTION("Semtech SX150x I2C GPIO expander pinctrl driver");
  1085. MODULE_LICENSE("GPL");