htc-i2cpld.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /*
  2. * htc-i2cpld.c
  3. * Chip driver for an unknown CPLD chip found on omap850 HTC devices like
  4. * the HTC Wizard and HTC Herald.
  5. * The cpld is located on the i2c bus and acts as an input/output GPIO
  6. * extender.
  7. *
  8. * Copyright (C) 2009 Cory Maccarrone <darkstar6262@gmail.com>
  9. *
  10. * Based on work done in the linwizard project
  11. * Copyright (C) 2008-2009 Angelo Arrifano <miknix@gmail.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */
  27. #include <linux/kernel.h>
  28. #include <linux/init.h>
  29. #include <linux/module.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/i2c.h>
  33. #include <linux/irq.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/htcpld.h>
  36. #include <linux/gpio.h>
  37. #include <linux/slab.h>
  38. struct htcpld_chip {
  39. spinlock_t lock;
  40. /* chip info */
  41. u8 reset;
  42. u8 addr;
  43. struct device *dev;
  44. struct i2c_client *client;
  45. /* Output details */
  46. u8 cache_out;
  47. struct gpio_chip chip_out;
  48. /* Input details */
  49. u8 cache_in;
  50. struct gpio_chip chip_in;
  51. u16 irqs_enabled;
  52. uint irq_start;
  53. int nirqs;
  54. /*
  55. * Work structure to allow for setting values outside of any
  56. * possible interrupt context
  57. */
  58. struct work_struct set_val_work;
  59. };
  60. struct htcpld_data {
  61. /* irq info */
  62. u16 irqs_enabled;
  63. uint irq_start;
  64. int nirqs;
  65. uint chained_irq;
  66. unsigned int int_reset_gpio_hi;
  67. unsigned int int_reset_gpio_lo;
  68. /* htcpld info */
  69. struct htcpld_chip *chip;
  70. unsigned int nchips;
  71. };
  72. /* There does not appear to be a way to proactively mask interrupts
  73. * on the htcpld chip itself. So, we simply ignore interrupts that
  74. * aren't desired. */
  75. static void htcpld_mask(unsigned int irq)
  76. {
  77. struct htcpld_chip *chip = get_irq_chip_data(irq);
  78. chip->irqs_enabled &= ~(1 << (irq - chip->irq_start));
  79. pr_debug("HTCPLD mask %d %04x\n", irq, chip->irqs_enabled);
  80. }
  81. static void htcpld_unmask(unsigned int irq)
  82. {
  83. struct htcpld_chip *chip = get_irq_chip_data(irq);
  84. chip->irqs_enabled |= 1 << (irq - chip->irq_start);
  85. pr_debug("HTCPLD unmask %d %04x\n", irq, chip->irqs_enabled);
  86. }
  87. static int htcpld_set_type(unsigned int irq, unsigned int flags)
  88. {
  89. struct irq_desc *d = irq_to_desc(irq);
  90. if (!d) {
  91. pr_err("HTCPLD invalid IRQ: %d\n", irq);
  92. return -EINVAL;
  93. }
  94. if (flags & ~IRQ_TYPE_SENSE_MASK)
  95. return -EINVAL;
  96. /* We only allow edge triggering */
  97. if (flags & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH))
  98. return -EINVAL;
  99. d->status &= ~IRQ_TYPE_SENSE_MASK;
  100. d->status |= flags;
  101. return 0;
  102. }
  103. static struct irq_chip htcpld_muxed_chip = {
  104. .name = "htcpld",
  105. .mask = htcpld_mask,
  106. .unmask = htcpld_unmask,
  107. .set_type = htcpld_set_type,
  108. };
  109. /* To properly dispatch IRQ events, we need to read from the
  110. * chip. This is an I2C action that could possibly sleep
  111. * (which is bad in interrupt context) -- so we use a threaded
  112. * interrupt handler to get around that.
  113. */
  114. static irqreturn_t htcpld_handler(int irq, void *dev)
  115. {
  116. struct htcpld_data *htcpld = dev;
  117. unsigned int i;
  118. unsigned long flags;
  119. int irqpin;
  120. struct irq_desc *desc;
  121. if (!htcpld) {
  122. pr_debug("htcpld is null in ISR\n");
  123. return IRQ_HANDLED;
  124. }
  125. /*
  126. * For each chip, do a read of the chip and trigger any interrupts
  127. * desired. The interrupts will be triggered from LSB to MSB (i.e.
  128. * bit 0 first, then bit 1, etc.)
  129. *
  130. * For chips that have no interrupt range specified, just skip 'em.
  131. */
  132. for (i = 0; i < htcpld->nchips; i++) {
  133. struct htcpld_chip *chip = &htcpld->chip[i];
  134. struct i2c_client *client;
  135. int val;
  136. unsigned long uval, old_val;
  137. if (!chip) {
  138. pr_debug("chip %d is null in ISR\n", i);
  139. continue;
  140. }
  141. if (chip->nirqs == 0)
  142. continue;
  143. client = chip->client;
  144. if (!client) {
  145. pr_debug("client %d is null in ISR\n", i);
  146. continue;
  147. }
  148. /* Scan the chip */
  149. val = i2c_smbus_read_byte_data(client, chip->cache_out);
  150. if (val < 0) {
  151. /* Throw a warning and skip this chip */
  152. dev_warn(chip->dev, "Unable to read from chip: %d\n",
  153. val);
  154. continue;
  155. }
  156. uval = (unsigned long)val;
  157. spin_lock_irqsave(&chip->lock, flags);
  158. /* Save away the old value so we can compare it */
  159. old_val = chip->cache_in;
  160. /* Write the new value */
  161. chip->cache_in = uval;
  162. spin_unlock_irqrestore(&chip->lock, flags);
  163. /*
  164. * For each bit in the data (starting at bit 0), trigger
  165. * associated interrupts.
  166. */
  167. for (irqpin = 0; irqpin < chip->nirqs; irqpin++) {
  168. unsigned oldb, newb;
  169. int flags;
  170. irq = chip->irq_start + irqpin;
  171. desc = irq_to_desc(irq);
  172. flags = desc->status;
  173. /* Run the IRQ handler, but only if the bit value
  174. * changed, and the proper flags are set */
  175. oldb = (old_val >> irqpin) & 1;
  176. newb = (uval >> irqpin) & 1;
  177. if ((!oldb && newb && (flags & IRQ_TYPE_EDGE_RISING)) ||
  178. (oldb && !newb &&
  179. (flags & IRQ_TYPE_EDGE_FALLING))) {
  180. pr_debug("fire IRQ %d\n", irqpin);
  181. desc->handle_irq(irq, desc);
  182. }
  183. }
  184. }
  185. /*
  186. * In order to continue receiving interrupts, the int_reset_gpio must
  187. * be asserted.
  188. */
  189. if (htcpld->int_reset_gpio_hi)
  190. gpio_set_value(htcpld->int_reset_gpio_hi, 1);
  191. if (htcpld->int_reset_gpio_lo)
  192. gpio_set_value(htcpld->int_reset_gpio_lo, 0);
  193. return IRQ_HANDLED;
  194. }
  195. /*
  196. * The GPIO set routines can be called from interrupt context, especially if,
  197. * for example they're attached to the led-gpio framework and a trigger is
  198. * enabled. As such, we declared work above in the htcpld_chip structure,
  199. * and that work is scheduled in the set routine. The kernel can then run
  200. * the I2C functions, which will sleep, in process context.
  201. */
  202. void htcpld_chip_set(struct gpio_chip *chip, unsigned offset, int val)
  203. {
  204. struct i2c_client *client;
  205. struct htcpld_chip *chip_data;
  206. unsigned long flags;
  207. chip_data = container_of(chip, struct htcpld_chip, chip_out);
  208. if (!chip_data)
  209. return;
  210. client = chip_data->client;
  211. if (client == NULL)
  212. return;
  213. spin_lock_irqsave(&chip_data->lock, flags);
  214. if (val)
  215. chip_data->cache_out |= (1 << offset);
  216. else
  217. chip_data->cache_out &= ~(1 << offset);
  218. spin_unlock_irqrestore(&chip_data->lock, flags);
  219. schedule_work(&(chip_data->set_val_work));
  220. }
  221. void htcpld_chip_set_ni(struct work_struct *work)
  222. {
  223. struct htcpld_chip *chip_data;
  224. struct i2c_client *client;
  225. chip_data = container_of(work, struct htcpld_chip, set_val_work);
  226. client = chip_data->client;
  227. i2c_smbus_read_byte_data(client, chip_data->cache_out);
  228. }
  229. int htcpld_chip_get(struct gpio_chip *chip, unsigned offset)
  230. {
  231. struct htcpld_chip *chip_data;
  232. int val = 0;
  233. int is_input = 0;
  234. /* Try out first */
  235. chip_data = container_of(chip, struct htcpld_chip, chip_out);
  236. if (!chip_data) {
  237. /* Try in */
  238. is_input = 1;
  239. chip_data = container_of(chip, struct htcpld_chip, chip_in);
  240. if (!chip_data)
  241. return -EINVAL;
  242. }
  243. /* Determine if this is an input or output GPIO */
  244. if (!is_input)
  245. /* Use the output cache */
  246. val = (chip_data->cache_out >> offset) & 1;
  247. else
  248. /* Use the input cache */
  249. val = (chip_data->cache_in >> offset) & 1;
  250. if (val)
  251. return 1;
  252. else
  253. return 0;
  254. }
  255. static int htcpld_direction_output(struct gpio_chip *chip,
  256. unsigned offset, int value)
  257. {
  258. htcpld_chip_set(chip, offset, value);
  259. return 0;
  260. }
  261. static int htcpld_direction_input(struct gpio_chip *chip,
  262. unsigned offset)
  263. {
  264. /*
  265. * No-op: this function can only be called on the input chip.
  266. * We do however make sure the offset is within range.
  267. */
  268. return (offset < chip->ngpio) ? 0 : -EINVAL;
  269. }
  270. int htcpld_chip_to_irq(struct gpio_chip *chip, unsigned offset)
  271. {
  272. struct htcpld_chip *chip_data;
  273. chip_data = container_of(chip, struct htcpld_chip, chip_in);
  274. if (offset < chip_data->nirqs)
  275. return chip_data->irq_start + offset;
  276. else
  277. return -EINVAL;
  278. }
  279. void htcpld_chip_reset(struct i2c_client *client)
  280. {
  281. struct htcpld_chip *chip_data = i2c_get_clientdata(client);
  282. if (!chip_data)
  283. return;
  284. i2c_smbus_read_byte_data(
  285. client, (chip_data->cache_out = chip_data->reset));
  286. }
  287. static int __devinit htcpld_setup_chip_irq(
  288. struct platform_device *pdev,
  289. int chip_index)
  290. {
  291. struct htcpld_data *htcpld;
  292. struct device *dev = &pdev->dev;
  293. struct htcpld_core_platform_data *pdata;
  294. struct htcpld_chip *chip;
  295. struct htcpld_chip_platform_data *plat_chip_data;
  296. unsigned int irq, irq_end;
  297. int ret = 0;
  298. /* Get the platform and driver data */
  299. pdata = dev->platform_data;
  300. htcpld = platform_get_drvdata(pdev);
  301. chip = &htcpld->chip[chip_index];
  302. plat_chip_data = &pdata->chip[chip_index];
  303. /* Setup irq handlers */
  304. irq_end = chip->irq_start + chip->nirqs;
  305. for (irq = chip->irq_start; irq < irq_end; irq++) {
  306. set_irq_chip(irq, &htcpld_muxed_chip);
  307. set_irq_chip_data(irq, chip);
  308. set_irq_handler(irq, handle_simple_irq);
  309. #ifdef CONFIG_ARM
  310. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  311. #else
  312. set_irq_probe(irq);
  313. #endif
  314. }
  315. return ret;
  316. }
  317. static int __devinit htcpld_register_chip_i2c(
  318. struct platform_device *pdev,
  319. int chip_index)
  320. {
  321. struct htcpld_data *htcpld;
  322. struct device *dev = &pdev->dev;
  323. struct htcpld_core_platform_data *pdata;
  324. struct htcpld_chip *chip;
  325. struct htcpld_chip_platform_data *plat_chip_data;
  326. struct i2c_adapter *adapter;
  327. struct i2c_client *client;
  328. struct i2c_board_info info;
  329. /* Get the platform and driver data */
  330. pdata = dev->platform_data;
  331. htcpld = platform_get_drvdata(pdev);
  332. chip = &htcpld->chip[chip_index];
  333. plat_chip_data = &pdata->chip[chip_index];
  334. adapter = i2c_get_adapter(pdata->i2c_adapter_id);
  335. if (adapter == NULL) {
  336. /* Eek, no such I2C adapter! Bail out. */
  337. dev_warn(dev, "Chip at i2c address 0x%x: Invalid i2c adapter %d\n",
  338. plat_chip_data->addr, pdata->i2c_adapter_id);
  339. return -ENODEV;
  340. }
  341. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
  342. dev_warn(dev, "i2c adapter %d non-functional\n",
  343. pdata->i2c_adapter_id);
  344. return -EINVAL;
  345. }
  346. memset(&info, 0, sizeof(struct i2c_board_info));
  347. info.addr = plat_chip_data->addr;
  348. strlcpy(info.type, "htcpld-chip", I2C_NAME_SIZE);
  349. info.platform_data = chip;
  350. /* Add the I2C device. This calls the probe() function. */
  351. client = i2c_new_device(adapter, &info);
  352. if (!client) {
  353. /* I2C device registration failed, contineu with the next */
  354. dev_warn(dev, "Unable to add I2C device for 0x%x\n",
  355. plat_chip_data->addr);
  356. return -ENODEV;
  357. }
  358. i2c_set_clientdata(client, chip);
  359. snprintf(client->name, I2C_NAME_SIZE, "Chip_0x%d", client->addr);
  360. chip->client = client;
  361. /* Reset the chip */
  362. htcpld_chip_reset(client);
  363. chip->cache_in = i2c_smbus_read_byte_data(client, chip->cache_out);
  364. return 0;
  365. }
  366. static void __devinit htcpld_unregister_chip_i2c(
  367. struct platform_device *pdev,
  368. int chip_index)
  369. {
  370. struct htcpld_data *htcpld;
  371. struct htcpld_chip *chip;
  372. /* Get the platform and driver data */
  373. htcpld = platform_get_drvdata(pdev);
  374. chip = &htcpld->chip[chip_index];
  375. if (chip->client)
  376. i2c_unregister_device(chip->client);
  377. }
  378. static int __devinit htcpld_register_chip_gpio(
  379. struct platform_device *pdev,
  380. int chip_index)
  381. {
  382. struct htcpld_data *htcpld;
  383. struct device *dev = &pdev->dev;
  384. struct htcpld_core_platform_data *pdata;
  385. struct htcpld_chip *chip;
  386. struct htcpld_chip_platform_data *plat_chip_data;
  387. struct gpio_chip *gpio_chip;
  388. int ret = 0;
  389. /* Get the platform and driver data */
  390. pdata = dev->platform_data;
  391. htcpld = platform_get_drvdata(pdev);
  392. chip = &htcpld->chip[chip_index];
  393. plat_chip_data = &pdata->chip[chip_index];
  394. /* Setup the GPIO chips */
  395. gpio_chip = &(chip->chip_out);
  396. gpio_chip->label = "htcpld-out";
  397. gpio_chip->dev = dev;
  398. gpio_chip->owner = THIS_MODULE;
  399. gpio_chip->get = htcpld_chip_get;
  400. gpio_chip->set = htcpld_chip_set;
  401. gpio_chip->direction_input = NULL;
  402. gpio_chip->direction_output = htcpld_direction_output;
  403. gpio_chip->base = plat_chip_data->gpio_out_base;
  404. gpio_chip->ngpio = plat_chip_data->num_gpios;
  405. gpio_chip = &(chip->chip_in);
  406. gpio_chip->label = "htcpld-in";
  407. gpio_chip->dev = dev;
  408. gpio_chip->owner = THIS_MODULE;
  409. gpio_chip->get = htcpld_chip_get;
  410. gpio_chip->set = NULL;
  411. gpio_chip->direction_input = htcpld_direction_input;
  412. gpio_chip->direction_output = NULL;
  413. gpio_chip->to_irq = htcpld_chip_to_irq;
  414. gpio_chip->base = plat_chip_data->gpio_in_base;
  415. gpio_chip->ngpio = plat_chip_data->num_gpios;
  416. /* Add the GPIO chips */
  417. ret = gpiochip_add(&(chip->chip_out));
  418. if (ret) {
  419. dev_warn(dev, "Unable to register output GPIOs for 0x%x: %d\n",
  420. plat_chip_data->addr, ret);
  421. return ret;
  422. }
  423. ret = gpiochip_add(&(chip->chip_in));
  424. if (ret) {
  425. int error;
  426. dev_warn(dev, "Unable to register input GPIOs for 0x%x: %d\n",
  427. plat_chip_data->addr, ret);
  428. error = gpiochip_remove(&(chip->chip_out));
  429. if (error)
  430. dev_warn(dev, "Error while trying to unregister gpio chip: %d\n", error);
  431. return ret;
  432. }
  433. return 0;
  434. }
  435. static int __devinit htcpld_setup_chips(struct platform_device *pdev)
  436. {
  437. struct htcpld_data *htcpld;
  438. struct device *dev = &pdev->dev;
  439. struct htcpld_core_platform_data *pdata;
  440. int i;
  441. /* Get the platform and driver data */
  442. pdata = dev->platform_data;
  443. htcpld = platform_get_drvdata(pdev);
  444. /* Setup each chip's output GPIOs */
  445. htcpld->nchips = pdata->num_chip;
  446. htcpld->chip = kzalloc(sizeof(struct htcpld_chip) * htcpld->nchips,
  447. GFP_KERNEL);
  448. if (!htcpld->chip) {
  449. dev_warn(dev, "Unable to allocate memory for chips\n");
  450. return -ENOMEM;
  451. }
  452. /* Add the chips as best we can */
  453. for (i = 0; i < htcpld->nchips; i++) {
  454. int ret;
  455. /* Setup the HTCPLD chips */
  456. htcpld->chip[i].reset = pdata->chip[i].reset;
  457. htcpld->chip[i].cache_out = pdata->chip[i].reset;
  458. htcpld->chip[i].cache_in = 0;
  459. htcpld->chip[i].dev = dev;
  460. htcpld->chip[i].irq_start = pdata->chip[i].irq_base;
  461. htcpld->chip[i].nirqs = pdata->chip[i].num_irqs;
  462. INIT_WORK(&(htcpld->chip[i].set_val_work), &htcpld_chip_set_ni);
  463. spin_lock_init(&(htcpld->chip[i].lock));
  464. /* Setup the interrupts for the chip */
  465. if (htcpld->chained_irq) {
  466. ret = htcpld_setup_chip_irq(pdev, i);
  467. if (ret)
  468. continue;
  469. }
  470. /* Register the chip with I2C */
  471. ret = htcpld_register_chip_i2c(pdev, i);
  472. if (ret)
  473. continue;
  474. /* Register the chips with the GPIO subsystem */
  475. ret = htcpld_register_chip_gpio(pdev, i);
  476. if (ret) {
  477. /* Unregister the chip from i2c and continue */
  478. htcpld_unregister_chip_i2c(pdev, i);
  479. continue;
  480. }
  481. dev_info(dev, "Registered chip at 0x%x\n", pdata->chip[i].addr);
  482. }
  483. return 0;
  484. }
  485. static int __devinit htcpld_core_probe(struct platform_device *pdev)
  486. {
  487. struct htcpld_data *htcpld;
  488. struct device *dev = &pdev->dev;
  489. struct htcpld_core_platform_data *pdata;
  490. struct resource *res;
  491. int ret = 0;
  492. if (!dev)
  493. return -ENODEV;
  494. pdata = dev->platform_data;
  495. if (!pdata) {
  496. dev_warn(dev, "Platform data not found for htcpld core!\n");
  497. return -ENXIO;
  498. }
  499. htcpld = kzalloc(sizeof(struct htcpld_data), GFP_KERNEL);
  500. if (!htcpld)
  501. return -ENOMEM;
  502. /* Find chained irq */
  503. ret = -EINVAL;
  504. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  505. if (res) {
  506. int flags;
  507. htcpld->chained_irq = res->start;
  508. /* Setup the chained interrupt handler */
  509. flags = IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING;
  510. ret = request_threaded_irq(htcpld->chained_irq,
  511. NULL, htcpld_handler,
  512. flags, pdev->name, htcpld);
  513. if (ret) {
  514. dev_warn(dev, "Unable to setup chained irq handler: %d\n", ret);
  515. goto fail;
  516. } else
  517. device_init_wakeup(dev, 0);
  518. }
  519. /* Set the driver data */
  520. platform_set_drvdata(pdev, htcpld);
  521. /* Setup the htcpld chips */
  522. ret = htcpld_setup_chips(pdev);
  523. if (ret)
  524. goto fail;
  525. /* Request the GPIO(s) for the int reset and set them up */
  526. if (pdata->int_reset_gpio_hi) {
  527. ret = gpio_request(pdata->int_reset_gpio_hi, "htcpld-core");
  528. if (ret) {
  529. /*
  530. * If it failed, that sucks, but we can probably
  531. * continue on without it.
  532. */
  533. dev_warn(dev, "Unable to request int_reset_gpio_hi -- interrupts may not work\n");
  534. htcpld->int_reset_gpio_hi = 0;
  535. } else {
  536. htcpld->int_reset_gpio_hi = pdata->int_reset_gpio_hi;
  537. gpio_set_value(htcpld->int_reset_gpio_hi, 1);
  538. }
  539. }
  540. if (pdata->int_reset_gpio_lo) {
  541. ret = gpio_request(pdata->int_reset_gpio_lo, "htcpld-core");
  542. if (ret) {
  543. /*
  544. * If it failed, that sucks, but we can probably
  545. * continue on without it.
  546. */
  547. dev_warn(dev, "Unable to request int_reset_gpio_lo -- interrupts may not work\n");
  548. htcpld->int_reset_gpio_lo = 0;
  549. } else {
  550. htcpld->int_reset_gpio_lo = pdata->int_reset_gpio_lo;
  551. gpio_set_value(htcpld->int_reset_gpio_lo, 0);
  552. }
  553. }
  554. dev_info(dev, "Initialized successfully\n");
  555. return 0;
  556. fail:
  557. kfree(htcpld);
  558. return ret;
  559. }
  560. /* The I2C Driver -- used internally */
  561. static const struct i2c_device_id htcpld_chip_id[] = {
  562. { "htcpld-chip", 0 },
  563. { }
  564. };
  565. MODULE_DEVICE_TABLE(i2c, htcpld_chip_id);
  566. static struct i2c_driver htcpld_chip_driver = {
  567. .driver = {
  568. .name = "htcpld-chip",
  569. },
  570. .id_table = htcpld_chip_id,
  571. };
  572. /* The Core Driver */
  573. static struct platform_driver htcpld_core_driver = {
  574. .driver = {
  575. .name = "i2c-htcpld",
  576. },
  577. };
  578. static int __init htcpld_core_init(void)
  579. {
  580. int ret;
  581. /* Register the I2C Chip driver */
  582. ret = i2c_add_driver(&htcpld_chip_driver);
  583. if (ret)
  584. return ret;
  585. /* Probe for our chips */
  586. return platform_driver_probe(&htcpld_core_driver, htcpld_core_probe);
  587. }
  588. static void __exit htcpld_core_exit(void)
  589. {
  590. i2c_del_driver(&htcpld_chip_driver);
  591. platform_driver_unregister(&htcpld_core_driver);
  592. }
  593. module_init(htcpld_core_init);
  594. module_exit(htcpld_core_exit);
  595. MODULE_AUTHOR("Cory Maccarrone <darkstar6262@gmail.com>");
  596. MODULE_DESCRIPTION("I2C HTC PLD Driver");
  597. MODULE_LICENSE("GPL");