htc-i2cpld.c 18 KB

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