pinctrl-sx150x.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  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 void 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. sx150x_gpio_oscio_set(pctl, value);
  402. else
  403. __sx150x_gpio_set(pctl, offset, value);
  404. }
  405. static void sx150x_gpio_set_multiple(struct gpio_chip *chip,
  406. unsigned long *mask,
  407. unsigned long *bits)
  408. {
  409. struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
  410. regmap_write_bits(pctl->regmap, pctl->data->reg_data, *mask, *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_printf(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_OUTPUT:
  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_OUTPUT:
  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_OUTPUT) {
  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_OUTPUT:
  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. static int sx150x_reset(struct sx150x_pinctrl *pctl)
  740. {
  741. int err;
  742. err = i2c_smbus_write_byte_data(pctl->client,
  743. pctl->data->pri.x789.reg_reset,
  744. SX150X_789_RESET_KEY1);
  745. if (err < 0)
  746. return err;
  747. err = i2c_smbus_write_byte_data(pctl->client,
  748. pctl->data->pri.x789.reg_reset,
  749. SX150X_789_RESET_KEY2);
  750. return err;
  751. }
  752. static int sx150x_init_misc(struct sx150x_pinctrl *pctl)
  753. {
  754. u8 reg, value;
  755. switch (pctl->data->model) {
  756. case SX150X_789:
  757. reg = pctl->data->pri.x789.reg_misc;
  758. value = SX150X_789_REG_MISC_AUTOCLEAR_OFF;
  759. break;
  760. case SX150X_456:
  761. reg = pctl->data->pri.x456.reg_advanced;
  762. value = 0x00;
  763. /*
  764. * Only SX1506 has RegAdvanced, SX1504/5 are expected
  765. * to initialize this offset to zero
  766. */
  767. if (!reg)
  768. return 0;
  769. break;
  770. case SX150X_123:
  771. reg = pctl->data->pri.x123.reg_advanced;
  772. value = 0x00;
  773. break;
  774. default:
  775. WARN(1, "Unknown chip model %d\n", pctl->data->model);
  776. return -EINVAL;
  777. }
  778. return regmap_write(pctl->regmap, reg, value);
  779. }
  780. static int sx150x_init_hw(struct sx150x_pinctrl *pctl)
  781. {
  782. const u8 reg[] = {
  783. [SX150X_789] = pctl->data->pri.x789.reg_polarity,
  784. [SX150X_456] = pctl->data->pri.x456.reg_pld_mode,
  785. [SX150X_123] = pctl->data->pri.x123.reg_pld_mode,
  786. };
  787. int err;
  788. if (pctl->data->model == SX150X_789 &&
  789. of_property_read_bool(pctl->dev->of_node, "semtech,probe-reset")) {
  790. err = sx150x_reset(pctl);
  791. if (err < 0)
  792. return err;
  793. }
  794. err = sx150x_init_misc(pctl);
  795. if (err < 0)
  796. return err;
  797. /* Set all pins to work in normal mode */
  798. return regmap_write(pctl->regmap, reg[pctl->data->model], 0);
  799. }
  800. static int sx150x_regmap_reg_width(struct sx150x_pinctrl *pctl,
  801. unsigned int reg)
  802. {
  803. const struct sx150x_device_data *data = pctl->data;
  804. if (reg == data->reg_sense) {
  805. /*
  806. * RegSense packs two bits of configuration per GPIO,
  807. * so we'd need to read twice as many bits as there
  808. * are GPIO in our chip
  809. */
  810. return 2 * data->ngpios;
  811. } else if ((data->model == SX150X_789 &&
  812. (reg == data->pri.x789.reg_misc ||
  813. reg == data->pri.x789.reg_clock ||
  814. reg == data->pri.x789.reg_reset))
  815. ||
  816. (data->model == SX150X_123 &&
  817. reg == data->pri.x123.reg_advanced)
  818. ||
  819. (data->model == SX150X_456 &&
  820. data->pri.x456.reg_advanced &&
  821. reg == data->pri.x456.reg_advanced)) {
  822. return 8;
  823. } else {
  824. return data->ngpios;
  825. }
  826. }
  827. static unsigned int sx150x_maybe_swizzle(struct sx150x_pinctrl *pctl,
  828. unsigned int reg, unsigned int val)
  829. {
  830. unsigned int a, b;
  831. const struct sx150x_device_data *data = pctl->data;
  832. /*
  833. * Whereas SX1509 presents RegSense in a simple layout as such:
  834. * reg [ f f e e d d c c ]
  835. * reg + 1 [ b b a a 9 9 8 8 ]
  836. * reg + 2 [ 7 7 6 6 5 5 4 4 ]
  837. * reg + 3 [ 3 3 2 2 1 1 0 0 ]
  838. *
  839. * SX1503 and SX1506 deviate from that data layout, instead storing
  840. * their contents as follows:
  841. *
  842. * reg [ f f e e d d c c ]
  843. * reg + 1 [ 7 7 6 6 5 5 4 4 ]
  844. * reg + 2 [ b b a a 9 9 8 8 ]
  845. * reg + 3 [ 3 3 2 2 1 1 0 0 ]
  846. *
  847. * so, taking that into account, we swap two
  848. * inner bytes of a 4-byte result
  849. */
  850. if (reg == data->reg_sense &&
  851. data->ngpios == 16 &&
  852. (data->model == SX150X_123 ||
  853. data->model == SX150X_456)) {
  854. a = val & 0x00ff0000;
  855. b = val & 0x0000ff00;
  856. val &= 0xff0000ff;
  857. val |= b << 8;
  858. val |= a >> 8;
  859. }
  860. return val;
  861. }
  862. /*
  863. * In order to mask the differences between 16 and 8 bit expander
  864. * devices we set up a sligthly ficticious regmap that pretends to be
  865. * a set of 32-bit (to accommodate RegSenseLow/RegSenseHigh
  866. * pair/quartet) registers and transparently reconstructs those
  867. * registers via multiple I2C/SMBus reads
  868. *
  869. * This way the rest of the driver code, interfacing with the chip via
  870. * regmap API, can work assuming that each GPIO pin is represented by
  871. * a group of bits at an offset proportional to GPIO number within a
  872. * given register.
  873. */
  874. static int sx150x_regmap_reg_read(void *context, unsigned int reg,
  875. unsigned int *result)
  876. {
  877. int ret, n;
  878. struct sx150x_pinctrl *pctl = context;
  879. struct i2c_client *i2c = pctl->client;
  880. const int width = sx150x_regmap_reg_width(pctl, reg);
  881. unsigned int idx, val;
  882. /*
  883. * There are four potential cases covered by this function:
  884. *
  885. * 1) 8-pin chip, single configuration bit register
  886. *
  887. * This is trivial the code below just needs to read:
  888. * reg [ 7 6 5 4 3 2 1 0 ]
  889. *
  890. * 2) 8-pin chip, double configuration bit register (RegSense)
  891. *
  892. * The read will be done as follows:
  893. * reg [ 7 7 6 6 5 5 4 4 ]
  894. * reg + 1 [ 3 3 2 2 1 1 0 0 ]
  895. *
  896. * 3) 16-pin chip, single configuration bit register
  897. *
  898. * The read will be done as follows:
  899. * reg [ f e d c b a 9 8 ]
  900. * reg + 1 [ 7 6 5 4 3 2 1 0 ]
  901. *
  902. * 4) 16-pin chip, double configuration bit register (RegSense)
  903. *
  904. * The read will be done as follows:
  905. * reg [ f f e e d d c c ]
  906. * reg + 1 [ b b a a 9 9 8 8 ]
  907. * reg + 2 [ 7 7 6 6 5 5 4 4 ]
  908. * reg + 3 [ 3 3 2 2 1 1 0 0 ]
  909. */
  910. for (n = width, val = 0, idx = reg; n > 0; n -= 8, idx++) {
  911. val <<= 8;
  912. ret = i2c_smbus_read_byte_data(i2c, idx);
  913. if (ret < 0)
  914. return ret;
  915. val |= ret;
  916. }
  917. *result = sx150x_maybe_swizzle(pctl, reg, val);
  918. return 0;
  919. }
  920. static int sx150x_regmap_reg_write(void *context, unsigned int reg,
  921. unsigned int val)
  922. {
  923. int ret, n;
  924. struct sx150x_pinctrl *pctl = context;
  925. struct i2c_client *i2c = pctl->client;
  926. const int width = sx150x_regmap_reg_width(pctl, reg);
  927. val = sx150x_maybe_swizzle(pctl, reg, val);
  928. n = (width - 1) & ~7;
  929. do {
  930. const u8 byte = (val >> n) & 0xff;
  931. ret = i2c_smbus_write_byte_data(i2c, reg, byte);
  932. if (ret < 0)
  933. return ret;
  934. reg++;
  935. n -= 8;
  936. } while (n >= 0);
  937. return 0;
  938. }
  939. static bool sx150x_reg_volatile(struct device *dev, unsigned int reg)
  940. {
  941. struct sx150x_pinctrl *pctl = i2c_get_clientdata(to_i2c_client(dev));
  942. return reg == pctl->data->reg_irq_src || reg == pctl->data->reg_data;
  943. }
  944. static const struct regmap_config sx150x_regmap_config = {
  945. .reg_bits = 8,
  946. .val_bits = 32,
  947. .cache_type = REGCACHE_RBTREE,
  948. .reg_read = sx150x_regmap_reg_read,
  949. .reg_write = sx150x_regmap_reg_write,
  950. .max_register = SX150X_MAX_REGISTER,
  951. .volatile_reg = sx150x_reg_volatile,
  952. };
  953. static int sx150x_probe(struct i2c_client *client)
  954. {
  955. static const u32 i2c_funcs = I2C_FUNC_SMBUS_BYTE_DATA |
  956. I2C_FUNC_SMBUS_WRITE_WORD_DATA;
  957. struct device *dev = &client->dev;
  958. struct sx150x_pinctrl *pctl;
  959. int ret;
  960. if (!i2c_check_functionality(client->adapter, i2c_funcs))
  961. return -ENOSYS;
  962. pctl = devm_kzalloc(dev, sizeof(*pctl), GFP_KERNEL);
  963. if (!pctl)
  964. return -ENOMEM;
  965. i2c_set_clientdata(client, pctl);
  966. pctl->dev = dev;
  967. pctl->client = client;
  968. pctl->data = i2c_get_match_data(client);
  969. if (!pctl->data)
  970. return -EINVAL;
  971. pctl->regmap = devm_regmap_init(dev, NULL, pctl,
  972. &sx150x_regmap_config);
  973. if (IS_ERR(pctl->regmap)) {
  974. ret = PTR_ERR(pctl->regmap);
  975. dev_err(dev, "Failed to allocate register map: %d\n",
  976. ret);
  977. return ret;
  978. }
  979. mutex_init(&pctl->lock);
  980. ret = sx150x_init_hw(pctl);
  981. if (ret)
  982. return ret;
  983. /* Pinctrl_desc */
  984. pctl->pinctrl_desc.name = "sx150x-pinctrl";
  985. pctl->pinctrl_desc.pctlops = &sx150x_pinctrl_ops;
  986. pctl->pinctrl_desc.confops = &sx150x_pinconf_ops;
  987. pctl->pinctrl_desc.pins = pctl->data->pins;
  988. pctl->pinctrl_desc.npins = pctl->data->npins;
  989. pctl->pinctrl_desc.owner = THIS_MODULE;
  990. ret = devm_pinctrl_register_and_init(dev, &pctl->pinctrl_desc,
  991. pctl, &pctl->pctldev);
  992. if (ret) {
  993. dev_err(dev, "Failed to register pinctrl device\n");
  994. return ret;
  995. }
  996. /* Register GPIO controller */
  997. pctl->gpio.base = -1;
  998. pctl->gpio.ngpio = pctl->data->npins;
  999. pctl->gpio.get_direction = sx150x_gpio_get_direction;
  1000. pctl->gpio.direction_input = sx150x_gpio_direction_input;
  1001. pctl->gpio.direction_output = sx150x_gpio_direction_output;
  1002. pctl->gpio.get = sx150x_gpio_get;
  1003. pctl->gpio.set = sx150x_gpio_set;
  1004. pctl->gpio.set_config = gpiochip_generic_config;
  1005. pctl->gpio.parent = dev;
  1006. pctl->gpio.can_sleep = true;
  1007. pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL);
  1008. if (!pctl->gpio.label)
  1009. return -ENOMEM;
  1010. /*
  1011. * Setting multiple pins is not safe when all pins are not
  1012. * handled by the same regmap register. The oscio pin (present
  1013. * on the SX150X_789 chips) lives in its own register, so
  1014. * would require locking that is not in place at this time.
  1015. */
  1016. if (pctl->data->model != SX150X_789)
  1017. pctl->gpio.set_multiple = sx150x_gpio_set_multiple;
  1018. /* Add Interrupt support if an irq is specified */
  1019. if (client->irq > 0) {
  1020. struct gpio_irq_chip *girq;
  1021. pctl->irq.masked = ~0;
  1022. pctl->irq.sense = 0;
  1023. /*
  1024. * Because sx150x_irq_threaded_fn invokes all of the
  1025. * nested interrupt handlers via handle_nested_irq,
  1026. * any "handler" assigned to struct gpio_irq_chip
  1027. * below is going to be ignored, so the choice of the
  1028. * function does not matter that much.
  1029. *
  1030. * We set it to handle_bad_irq to avoid confusion,
  1031. * plus it will be instantly noticeable if it is ever
  1032. * called (should not happen)
  1033. */
  1034. girq = &pctl->gpio.irq;
  1035. gpio_irq_chip_set_chip(girq, &sx150x_irq_chip);
  1036. /* This will let us handle the parent IRQ in the driver */
  1037. girq->parent_handler = NULL;
  1038. girq->num_parents = 0;
  1039. girq->parents = NULL;
  1040. girq->default_type = IRQ_TYPE_NONE;
  1041. girq->handler = handle_bad_irq;
  1042. girq->threaded = true;
  1043. ret = devm_request_threaded_irq(dev, client->irq, NULL,
  1044. sx150x_irq_thread_fn,
  1045. IRQF_ONESHOT | IRQF_SHARED |
  1046. IRQF_TRIGGER_FALLING,
  1047. client->name, pctl);
  1048. if (ret < 0)
  1049. return ret;
  1050. }
  1051. ret = devm_gpiochip_add_data(dev, &pctl->gpio, pctl);
  1052. if (ret)
  1053. return ret;
  1054. /*
  1055. * Pin control functions need to be enabled AFTER registering the
  1056. * GPIO chip because sx150x_pinconf_set() calls
  1057. * sx150x_gpio_direction_output().
  1058. */
  1059. ret = pinctrl_enable(pctl->pctldev);
  1060. if (ret) {
  1061. dev_err(dev, "Failed to enable pinctrl device\n");
  1062. return ret;
  1063. }
  1064. ret = gpiochip_add_pin_range(&pctl->gpio, dev_name(dev),
  1065. 0, 0, pctl->data->npins);
  1066. if (ret)
  1067. return ret;
  1068. return 0;
  1069. }
  1070. static struct i2c_driver sx150x_driver = {
  1071. .driver = {
  1072. .name = "sx150x-pinctrl",
  1073. .of_match_table = sx150x_of_match,
  1074. },
  1075. .probe = sx150x_probe,
  1076. .id_table = sx150x_id,
  1077. };
  1078. static int __init sx150x_init(void)
  1079. {
  1080. return i2c_add_driver(&sx150x_driver);
  1081. }
  1082. subsys_initcall(sx150x_init);