gpio-aspeed.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  1. /*
  2. * Copyright 2015 IBM Corp.
  3. *
  4. * Joel Stanley <joel@jms.id.au>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <asm/div64.h>
  12. #include <linux/clk.h>
  13. #include <linux/gpio/driver.h>
  14. #include <linux/gpio/aspeed.h>
  15. #include <linux/hashtable.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/pinctrl/consumer.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/string.h>
  24. /*
  25. * These two headers aren't meant to be used by GPIO drivers. We need
  26. * them in order to access gpio_chip_hwgpio() which we need to implement
  27. * the aspeed specific API which allows the coprocessor to request
  28. * access to some GPIOs and to arbitrate between coprocessor and ARM.
  29. */
  30. #include <linux/gpio/consumer.h>
  31. #include "gpiolib.h"
  32. struct aspeed_bank_props {
  33. unsigned int bank;
  34. u32 input;
  35. u32 output;
  36. };
  37. struct aspeed_gpio_config {
  38. unsigned int nr_gpios;
  39. const struct aspeed_bank_props *props;
  40. };
  41. /*
  42. * @offset_timer: Maps an offset to an @timer_users index, or zero if disabled
  43. * @timer_users: Tracks the number of users for each timer
  44. *
  45. * The @timer_users has four elements but the first element is unused. This is
  46. * to simplify accounting and indexing, as a zero value in @offset_timer
  47. * represents disabled debouncing for the GPIO. Any other value for an element
  48. * of @offset_timer is used as an index into @timer_users. This behaviour of
  49. * the zero value aligns with the behaviour of zero built from the timer
  50. * configuration registers (i.e. debouncing is disabled).
  51. */
  52. struct aspeed_gpio {
  53. struct gpio_chip chip;
  54. spinlock_t lock;
  55. void __iomem *base;
  56. int irq;
  57. const struct aspeed_gpio_config *config;
  58. u8 *offset_timer;
  59. unsigned int timer_users[4];
  60. struct clk *clk;
  61. u32 *dcache;
  62. u8 *cf_copro_bankmap;
  63. };
  64. struct aspeed_gpio_bank {
  65. uint16_t val_regs; /* +0: Rd: read input value, Wr: set write latch
  66. * +4: Rd/Wr: Direction (0=in, 1=out)
  67. */
  68. uint16_t rdata_reg; /* Rd: read write latch, Wr: <none> */
  69. uint16_t irq_regs;
  70. uint16_t debounce_regs;
  71. uint16_t tolerance_regs;
  72. uint16_t cmdsrc_regs;
  73. const char names[4][3];
  74. };
  75. /*
  76. * Note: The "value" register returns the input value sampled on the
  77. * line even when the GPIO is configured as an output. Since
  78. * that input goes through synchronizers, writing, then reading
  79. * back may not return the written value right away.
  80. *
  81. * The "rdata" register returns the content of the write latch
  82. * and thus can be used to read back what was last written
  83. * reliably.
  84. */
  85. static const int debounce_timers[4] = { 0x00, 0x50, 0x54, 0x58 };
  86. static const struct aspeed_gpio_copro_ops *copro_ops;
  87. static void *copro_data;
  88. static const struct aspeed_gpio_bank aspeed_gpio_banks[] = {
  89. {
  90. .val_regs = 0x0000,
  91. .rdata_reg = 0x00c0,
  92. .irq_regs = 0x0008,
  93. .debounce_regs = 0x0040,
  94. .tolerance_regs = 0x001c,
  95. .cmdsrc_regs = 0x0060,
  96. .names = { "A", "B", "C", "D" },
  97. },
  98. {
  99. .val_regs = 0x0020,
  100. .rdata_reg = 0x00c4,
  101. .irq_regs = 0x0028,
  102. .debounce_regs = 0x0048,
  103. .tolerance_regs = 0x003c,
  104. .cmdsrc_regs = 0x0068,
  105. .names = { "E", "F", "G", "H" },
  106. },
  107. {
  108. .val_regs = 0x0070,
  109. .rdata_reg = 0x00c8,
  110. .irq_regs = 0x0098,
  111. .debounce_regs = 0x00b0,
  112. .tolerance_regs = 0x00ac,
  113. .cmdsrc_regs = 0x0090,
  114. .names = { "I", "J", "K", "L" },
  115. },
  116. {
  117. .val_regs = 0x0078,
  118. .rdata_reg = 0x00cc,
  119. .irq_regs = 0x00e8,
  120. .debounce_regs = 0x0100,
  121. .tolerance_regs = 0x00fc,
  122. .cmdsrc_regs = 0x00e0,
  123. .names = { "M", "N", "O", "P" },
  124. },
  125. {
  126. .val_regs = 0x0080,
  127. .rdata_reg = 0x00d0,
  128. .irq_regs = 0x0118,
  129. .debounce_regs = 0x0130,
  130. .tolerance_regs = 0x012c,
  131. .cmdsrc_regs = 0x0110,
  132. .names = { "Q", "R", "S", "T" },
  133. },
  134. {
  135. .val_regs = 0x0088,
  136. .rdata_reg = 0x00d4,
  137. .irq_regs = 0x0148,
  138. .debounce_regs = 0x0160,
  139. .tolerance_regs = 0x015c,
  140. .cmdsrc_regs = 0x0140,
  141. .names = { "U", "V", "W", "X" },
  142. },
  143. {
  144. .val_regs = 0x01E0,
  145. .rdata_reg = 0x00d8,
  146. .irq_regs = 0x0178,
  147. .debounce_regs = 0x0190,
  148. .tolerance_regs = 0x018c,
  149. .cmdsrc_regs = 0x0170,
  150. .names = { "Y", "Z", "AA", "AB" },
  151. },
  152. {
  153. .val_regs = 0x01e8,
  154. .rdata_reg = 0x00dc,
  155. .irq_regs = 0x01a8,
  156. .debounce_regs = 0x01c0,
  157. .tolerance_regs = 0x01bc,
  158. .cmdsrc_regs = 0x01a0,
  159. .names = { "AC", "", "", "" },
  160. },
  161. };
  162. enum aspeed_gpio_reg {
  163. reg_val,
  164. reg_rdata,
  165. reg_dir,
  166. reg_irq_enable,
  167. reg_irq_type0,
  168. reg_irq_type1,
  169. reg_irq_type2,
  170. reg_irq_status,
  171. reg_debounce_sel1,
  172. reg_debounce_sel2,
  173. reg_tolerance,
  174. reg_cmdsrc0,
  175. reg_cmdsrc1,
  176. };
  177. #define GPIO_VAL_VALUE 0x00
  178. #define GPIO_VAL_DIR 0x04
  179. #define GPIO_IRQ_ENABLE 0x00
  180. #define GPIO_IRQ_TYPE0 0x04
  181. #define GPIO_IRQ_TYPE1 0x08
  182. #define GPIO_IRQ_TYPE2 0x0c
  183. #define GPIO_IRQ_STATUS 0x10
  184. #define GPIO_DEBOUNCE_SEL1 0x00
  185. #define GPIO_DEBOUNCE_SEL2 0x04
  186. #define GPIO_CMDSRC_0 0x00
  187. #define GPIO_CMDSRC_1 0x04
  188. #define GPIO_CMDSRC_ARM 0
  189. #define GPIO_CMDSRC_LPC 1
  190. #define GPIO_CMDSRC_COLDFIRE 2
  191. #define GPIO_CMDSRC_RESERVED 3
  192. /* This will be resolved at compile time */
  193. static inline void __iomem *bank_reg(struct aspeed_gpio *gpio,
  194. const struct aspeed_gpio_bank *bank,
  195. const enum aspeed_gpio_reg reg)
  196. {
  197. switch (reg) {
  198. case reg_val:
  199. return gpio->base + bank->val_regs + GPIO_VAL_VALUE;
  200. case reg_rdata:
  201. return gpio->base + bank->rdata_reg;
  202. case reg_dir:
  203. return gpio->base + bank->val_regs + GPIO_VAL_DIR;
  204. case reg_irq_enable:
  205. return gpio->base + bank->irq_regs + GPIO_IRQ_ENABLE;
  206. case reg_irq_type0:
  207. return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE0;
  208. case reg_irq_type1:
  209. return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE1;
  210. case reg_irq_type2:
  211. return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE2;
  212. case reg_irq_status:
  213. return gpio->base + bank->irq_regs + GPIO_IRQ_STATUS;
  214. case reg_debounce_sel1:
  215. return gpio->base + bank->debounce_regs + GPIO_DEBOUNCE_SEL1;
  216. case reg_debounce_sel2:
  217. return gpio->base + bank->debounce_regs + GPIO_DEBOUNCE_SEL2;
  218. case reg_tolerance:
  219. return gpio->base + bank->tolerance_regs;
  220. case reg_cmdsrc0:
  221. return gpio->base + bank->cmdsrc_regs + GPIO_CMDSRC_0;
  222. case reg_cmdsrc1:
  223. return gpio->base + bank->cmdsrc_regs + GPIO_CMDSRC_1;
  224. }
  225. BUG();
  226. }
  227. #define GPIO_BANK(x) ((x) >> 5)
  228. #define GPIO_OFFSET(x) ((x) & 0x1f)
  229. #define GPIO_BIT(x) BIT(GPIO_OFFSET(x))
  230. #define _GPIO_SET_DEBOUNCE(t, o, i) ((!!((t) & BIT(i))) << GPIO_OFFSET(o))
  231. #define GPIO_SET_DEBOUNCE1(t, o) _GPIO_SET_DEBOUNCE(t, o, 1)
  232. #define GPIO_SET_DEBOUNCE2(t, o) _GPIO_SET_DEBOUNCE(t, o, 0)
  233. static const struct aspeed_gpio_bank *to_bank(unsigned int offset)
  234. {
  235. unsigned int bank = GPIO_BANK(offset);
  236. WARN_ON(bank >= ARRAY_SIZE(aspeed_gpio_banks));
  237. return &aspeed_gpio_banks[bank];
  238. }
  239. static inline bool is_bank_props_sentinel(const struct aspeed_bank_props *props)
  240. {
  241. return !(props->input || props->output);
  242. }
  243. static inline const struct aspeed_bank_props *find_bank_props(
  244. struct aspeed_gpio *gpio, unsigned int offset)
  245. {
  246. const struct aspeed_bank_props *props = gpio->config->props;
  247. while (!is_bank_props_sentinel(props)) {
  248. if (props->bank == GPIO_BANK(offset))
  249. return props;
  250. props++;
  251. }
  252. return NULL;
  253. }
  254. static inline bool have_gpio(struct aspeed_gpio *gpio, unsigned int offset)
  255. {
  256. const struct aspeed_bank_props *props = find_bank_props(gpio, offset);
  257. const struct aspeed_gpio_bank *bank = to_bank(offset);
  258. unsigned int group = GPIO_OFFSET(offset) / 8;
  259. return bank->names[group][0] != '\0' &&
  260. (!props || ((props->input | props->output) & GPIO_BIT(offset)));
  261. }
  262. static inline bool have_input(struct aspeed_gpio *gpio, unsigned int offset)
  263. {
  264. const struct aspeed_bank_props *props = find_bank_props(gpio, offset);
  265. return !props || (props->input & GPIO_BIT(offset));
  266. }
  267. #define have_irq(g, o) have_input((g), (o))
  268. #define have_debounce(g, o) have_input((g), (o))
  269. static inline bool have_output(struct aspeed_gpio *gpio, unsigned int offset)
  270. {
  271. const struct aspeed_bank_props *props = find_bank_props(gpio, offset);
  272. return !props || (props->output & GPIO_BIT(offset));
  273. }
  274. static void aspeed_gpio_change_cmd_source(struct aspeed_gpio *gpio,
  275. const struct aspeed_gpio_bank *bank,
  276. int bindex, int cmdsrc)
  277. {
  278. void __iomem *c0 = bank_reg(gpio, bank, reg_cmdsrc0);
  279. void __iomem *c1 = bank_reg(gpio, bank, reg_cmdsrc1);
  280. u32 bit, reg;
  281. /*
  282. * Each register controls 4 banks, so take the bottom 2
  283. * bits of the bank index, and use them to select the
  284. * right control bit (0, 8, 16 or 24).
  285. */
  286. bit = BIT((bindex & 3) << 3);
  287. /* Source 1 first to avoid illegal 11 combination */
  288. reg = ioread32(c1);
  289. if (cmdsrc & 2)
  290. reg |= bit;
  291. else
  292. reg &= ~bit;
  293. iowrite32(reg, c1);
  294. /* Then Source 0 */
  295. reg = ioread32(c0);
  296. if (cmdsrc & 1)
  297. reg |= bit;
  298. else
  299. reg &= ~bit;
  300. iowrite32(reg, c0);
  301. }
  302. static bool aspeed_gpio_copro_request(struct aspeed_gpio *gpio,
  303. unsigned int offset)
  304. {
  305. const struct aspeed_gpio_bank *bank = to_bank(offset);
  306. if (!copro_ops || !gpio->cf_copro_bankmap)
  307. return false;
  308. if (!gpio->cf_copro_bankmap[offset >> 3])
  309. return false;
  310. if (!copro_ops->request_access)
  311. return false;
  312. /* Pause the coprocessor */
  313. copro_ops->request_access(copro_data);
  314. /* Change command source back to ARM */
  315. aspeed_gpio_change_cmd_source(gpio, bank, offset >> 3, GPIO_CMDSRC_ARM);
  316. /* Update cache */
  317. gpio->dcache[GPIO_BANK(offset)] = ioread32(bank_reg(gpio, bank, reg_rdata));
  318. return true;
  319. }
  320. static void aspeed_gpio_copro_release(struct aspeed_gpio *gpio,
  321. unsigned int offset)
  322. {
  323. const struct aspeed_gpio_bank *bank = to_bank(offset);
  324. if (!copro_ops || !gpio->cf_copro_bankmap)
  325. return;
  326. if (!gpio->cf_copro_bankmap[offset >> 3])
  327. return;
  328. if (!copro_ops->release_access)
  329. return;
  330. /* Change command source back to ColdFire */
  331. aspeed_gpio_change_cmd_source(gpio, bank, offset >> 3,
  332. GPIO_CMDSRC_COLDFIRE);
  333. /* Restart the coprocessor */
  334. copro_ops->release_access(copro_data);
  335. }
  336. static int aspeed_gpio_get(struct gpio_chip *gc, unsigned int offset)
  337. {
  338. struct aspeed_gpio *gpio = gpiochip_get_data(gc);
  339. const struct aspeed_gpio_bank *bank = to_bank(offset);
  340. return !!(ioread32(bank_reg(gpio, bank, reg_val)) & GPIO_BIT(offset));
  341. }
  342. static void __aspeed_gpio_set(struct gpio_chip *gc, unsigned int offset,
  343. int val)
  344. {
  345. struct aspeed_gpio *gpio = gpiochip_get_data(gc);
  346. const struct aspeed_gpio_bank *bank = to_bank(offset);
  347. void __iomem *addr;
  348. u32 reg;
  349. addr = bank_reg(gpio, bank, reg_val);
  350. reg = gpio->dcache[GPIO_BANK(offset)];
  351. if (val)
  352. reg |= GPIO_BIT(offset);
  353. else
  354. reg &= ~GPIO_BIT(offset);
  355. gpio->dcache[GPIO_BANK(offset)] = reg;
  356. iowrite32(reg, addr);
  357. }
  358. static void aspeed_gpio_set(struct gpio_chip *gc, unsigned int offset,
  359. int val)
  360. {
  361. struct aspeed_gpio *gpio = gpiochip_get_data(gc);
  362. unsigned long flags;
  363. bool copro;
  364. spin_lock_irqsave(&gpio->lock, flags);
  365. copro = aspeed_gpio_copro_request(gpio, offset);
  366. __aspeed_gpio_set(gc, offset, val);
  367. if (copro)
  368. aspeed_gpio_copro_release(gpio, offset);
  369. spin_unlock_irqrestore(&gpio->lock, flags);
  370. }
  371. static int aspeed_gpio_dir_in(struct gpio_chip *gc, unsigned int offset)
  372. {
  373. struct aspeed_gpio *gpio = gpiochip_get_data(gc);
  374. const struct aspeed_gpio_bank *bank = to_bank(offset);
  375. void __iomem *addr = bank_reg(gpio, bank, reg_dir);
  376. unsigned long flags;
  377. bool copro;
  378. u32 reg;
  379. if (!have_input(gpio, offset))
  380. return -ENOTSUPP;
  381. spin_lock_irqsave(&gpio->lock, flags);
  382. reg = ioread32(addr);
  383. reg &= ~GPIO_BIT(offset);
  384. copro = aspeed_gpio_copro_request(gpio, offset);
  385. iowrite32(reg, addr);
  386. if (copro)
  387. aspeed_gpio_copro_release(gpio, offset);
  388. spin_unlock_irqrestore(&gpio->lock, flags);
  389. return 0;
  390. }
  391. static int aspeed_gpio_dir_out(struct gpio_chip *gc,
  392. unsigned int offset, int val)
  393. {
  394. struct aspeed_gpio *gpio = gpiochip_get_data(gc);
  395. const struct aspeed_gpio_bank *bank = to_bank(offset);
  396. void __iomem *addr = bank_reg(gpio, bank, reg_dir);
  397. unsigned long flags;
  398. bool copro;
  399. u32 reg;
  400. if (!have_output(gpio, offset))
  401. return -ENOTSUPP;
  402. spin_lock_irqsave(&gpio->lock, flags);
  403. reg = ioread32(addr);
  404. reg |= GPIO_BIT(offset);
  405. copro = aspeed_gpio_copro_request(gpio, offset);
  406. __aspeed_gpio_set(gc, offset, val);
  407. iowrite32(reg, addr);
  408. if (copro)
  409. aspeed_gpio_copro_release(gpio, offset);
  410. spin_unlock_irqrestore(&gpio->lock, flags);
  411. return 0;
  412. }
  413. static int aspeed_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
  414. {
  415. struct aspeed_gpio *gpio = gpiochip_get_data(gc);
  416. const struct aspeed_gpio_bank *bank = to_bank(offset);
  417. unsigned long flags;
  418. u32 val;
  419. if (!have_input(gpio, offset))
  420. return 0;
  421. if (!have_output(gpio, offset))
  422. return 1;
  423. spin_lock_irqsave(&gpio->lock, flags);
  424. val = ioread32(bank_reg(gpio, bank, reg_dir)) & GPIO_BIT(offset);
  425. spin_unlock_irqrestore(&gpio->lock, flags);
  426. return !val;
  427. }
  428. static inline int irqd_to_aspeed_gpio_data(struct irq_data *d,
  429. struct aspeed_gpio **gpio,
  430. const struct aspeed_gpio_bank **bank,
  431. u32 *bit, int *offset)
  432. {
  433. struct aspeed_gpio *internal;
  434. *offset = irqd_to_hwirq(d);
  435. internal = irq_data_get_irq_chip_data(d);
  436. /* This might be a bit of a questionable place to check */
  437. if (!have_irq(internal, *offset))
  438. return -ENOTSUPP;
  439. *gpio = internal;
  440. *bank = to_bank(*offset);
  441. *bit = GPIO_BIT(*offset);
  442. return 0;
  443. }
  444. static void aspeed_gpio_irq_ack(struct irq_data *d)
  445. {
  446. const struct aspeed_gpio_bank *bank;
  447. struct aspeed_gpio *gpio;
  448. unsigned long flags;
  449. void __iomem *status_addr;
  450. int rc, offset;
  451. bool copro;
  452. u32 bit;
  453. rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset);
  454. if (rc)
  455. return;
  456. status_addr = bank_reg(gpio, bank, reg_irq_status);
  457. spin_lock_irqsave(&gpio->lock, flags);
  458. copro = aspeed_gpio_copro_request(gpio, offset);
  459. iowrite32(bit, status_addr);
  460. if (copro)
  461. aspeed_gpio_copro_release(gpio, offset);
  462. spin_unlock_irqrestore(&gpio->lock, flags);
  463. }
  464. static void aspeed_gpio_irq_set_mask(struct irq_data *d, bool set)
  465. {
  466. const struct aspeed_gpio_bank *bank;
  467. struct aspeed_gpio *gpio;
  468. unsigned long flags;
  469. u32 reg, bit;
  470. void __iomem *addr;
  471. int rc, offset;
  472. bool copro;
  473. rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset);
  474. if (rc)
  475. return;
  476. addr = bank_reg(gpio, bank, reg_irq_enable);
  477. spin_lock_irqsave(&gpio->lock, flags);
  478. copro = aspeed_gpio_copro_request(gpio, offset);
  479. reg = ioread32(addr);
  480. if (set)
  481. reg |= bit;
  482. else
  483. reg &= ~bit;
  484. iowrite32(reg, addr);
  485. if (copro)
  486. aspeed_gpio_copro_release(gpio, offset);
  487. spin_unlock_irqrestore(&gpio->lock, flags);
  488. }
  489. static void aspeed_gpio_irq_mask(struct irq_data *d)
  490. {
  491. aspeed_gpio_irq_set_mask(d, false);
  492. }
  493. static void aspeed_gpio_irq_unmask(struct irq_data *d)
  494. {
  495. aspeed_gpio_irq_set_mask(d, true);
  496. }
  497. static int aspeed_gpio_set_type(struct irq_data *d, unsigned int type)
  498. {
  499. u32 type0 = 0;
  500. u32 type1 = 0;
  501. u32 type2 = 0;
  502. u32 bit, reg;
  503. const struct aspeed_gpio_bank *bank;
  504. irq_flow_handler_t handler;
  505. struct aspeed_gpio *gpio;
  506. unsigned long flags;
  507. void __iomem *addr;
  508. int rc, offset;
  509. bool copro;
  510. rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset);
  511. if (rc)
  512. return -EINVAL;
  513. switch (type & IRQ_TYPE_SENSE_MASK) {
  514. case IRQ_TYPE_EDGE_BOTH:
  515. type2 |= bit;
  516. /* fall through */
  517. case IRQ_TYPE_EDGE_RISING:
  518. type0 |= bit;
  519. /* fall through */
  520. case IRQ_TYPE_EDGE_FALLING:
  521. handler = handle_edge_irq;
  522. break;
  523. case IRQ_TYPE_LEVEL_HIGH:
  524. type0 |= bit;
  525. /* fall through */
  526. case IRQ_TYPE_LEVEL_LOW:
  527. type1 |= bit;
  528. handler = handle_level_irq;
  529. break;
  530. default:
  531. return -EINVAL;
  532. }
  533. spin_lock_irqsave(&gpio->lock, flags);
  534. copro = aspeed_gpio_copro_request(gpio, offset);
  535. addr = bank_reg(gpio, bank, reg_irq_type0);
  536. reg = ioread32(addr);
  537. reg = (reg & ~bit) | type0;
  538. iowrite32(reg, addr);
  539. addr = bank_reg(gpio, bank, reg_irq_type1);
  540. reg = ioread32(addr);
  541. reg = (reg & ~bit) | type1;
  542. iowrite32(reg, addr);
  543. addr = bank_reg(gpio, bank, reg_irq_type2);
  544. reg = ioread32(addr);
  545. reg = (reg & ~bit) | type2;
  546. iowrite32(reg, addr);
  547. if (copro)
  548. aspeed_gpio_copro_release(gpio, offset);
  549. spin_unlock_irqrestore(&gpio->lock, flags);
  550. irq_set_handler_locked(d, handler);
  551. return 0;
  552. }
  553. static void aspeed_gpio_irq_handler(struct irq_desc *desc)
  554. {
  555. struct gpio_chip *gc = irq_desc_get_handler_data(desc);
  556. struct irq_chip *ic = irq_desc_get_chip(desc);
  557. struct aspeed_gpio *data = gpiochip_get_data(gc);
  558. unsigned int i, p, girq;
  559. unsigned long reg;
  560. chained_irq_enter(ic, desc);
  561. for (i = 0; i < ARRAY_SIZE(aspeed_gpio_banks); i++) {
  562. const struct aspeed_gpio_bank *bank = &aspeed_gpio_banks[i];
  563. reg = ioread32(bank_reg(data, bank, reg_irq_status));
  564. for_each_set_bit(p, &reg, 32) {
  565. girq = irq_find_mapping(gc->irq.domain, i * 32 + p);
  566. generic_handle_irq(girq);
  567. }
  568. }
  569. chained_irq_exit(ic, desc);
  570. }
  571. static struct irq_chip aspeed_gpio_irqchip = {
  572. .name = "aspeed-gpio",
  573. .irq_ack = aspeed_gpio_irq_ack,
  574. .irq_mask = aspeed_gpio_irq_mask,
  575. .irq_unmask = aspeed_gpio_irq_unmask,
  576. .irq_set_type = aspeed_gpio_set_type,
  577. };
  578. static void set_irq_valid_mask(struct aspeed_gpio *gpio)
  579. {
  580. const struct aspeed_bank_props *props = gpio->config->props;
  581. while (!is_bank_props_sentinel(props)) {
  582. unsigned int offset;
  583. const unsigned long int input = props->input;
  584. /* Pretty crummy approach, but similar to GPIO core */
  585. for_each_clear_bit(offset, &input, 32) {
  586. unsigned int i = props->bank * 32 + offset;
  587. if (i >= gpio->config->nr_gpios)
  588. break;
  589. clear_bit(i, gpio->chip.irq.valid_mask);
  590. }
  591. props++;
  592. }
  593. }
  594. static int aspeed_gpio_setup_irqs(struct aspeed_gpio *gpio,
  595. struct platform_device *pdev)
  596. {
  597. int rc;
  598. rc = platform_get_irq(pdev, 0);
  599. if (rc < 0)
  600. return rc;
  601. gpio->irq = rc;
  602. set_irq_valid_mask(gpio);
  603. rc = gpiochip_irqchip_add(&gpio->chip, &aspeed_gpio_irqchip,
  604. 0, handle_bad_irq, IRQ_TYPE_NONE);
  605. if (rc) {
  606. dev_info(&pdev->dev, "Could not add irqchip\n");
  607. return rc;
  608. }
  609. gpiochip_set_chained_irqchip(&gpio->chip, &aspeed_gpio_irqchip,
  610. gpio->irq, aspeed_gpio_irq_handler);
  611. return 0;
  612. }
  613. static int aspeed_gpio_reset_tolerance(struct gpio_chip *chip,
  614. unsigned int offset, bool enable)
  615. {
  616. struct aspeed_gpio *gpio = gpiochip_get_data(chip);
  617. unsigned long flags;
  618. void __iomem *treg;
  619. bool copro;
  620. u32 val;
  621. treg = bank_reg(gpio, to_bank(offset), reg_tolerance);
  622. spin_lock_irqsave(&gpio->lock, flags);
  623. copro = aspeed_gpio_copro_request(gpio, offset);
  624. val = readl(treg);
  625. if (enable)
  626. val |= GPIO_BIT(offset);
  627. else
  628. val &= ~GPIO_BIT(offset);
  629. writel(val, treg);
  630. if (copro)
  631. aspeed_gpio_copro_release(gpio, offset);
  632. spin_unlock_irqrestore(&gpio->lock, flags);
  633. return 0;
  634. }
  635. static int aspeed_gpio_request(struct gpio_chip *chip, unsigned int offset)
  636. {
  637. if (!have_gpio(gpiochip_get_data(chip), offset))
  638. return -ENODEV;
  639. return pinctrl_gpio_request(chip->base + offset);
  640. }
  641. static void aspeed_gpio_free(struct gpio_chip *chip, unsigned int offset)
  642. {
  643. pinctrl_gpio_free(chip->base + offset);
  644. }
  645. static int usecs_to_cycles(struct aspeed_gpio *gpio, unsigned long usecs,
  646. u32 *cycles)
  647. {
  648. u64 rate;
  649. u64 n;
  650. u32 r;
  651. rate = clk_get_rate(gpio->clk);
  652. if (!rate)
  653. return -ENOTSUPP;
  654. n = rate * usecs;
  655. r = do_div(n, 1000000);
  656. if (n >= U32_MAX)
  657. return -ERANGE;
  658. /* At least as long as the requested time */
  659. *cycles = n + (!!r);
  660. return 0;
  661. }
  662. /* Call under gpio->lock */
  663. static int register_allocated_timer(struct aspeed_gpio *gpio,
  664. unsigned int offset, unsigned int timer)
  665. {
  666. if (WARN(gpio->offset_timer[offset] != 0,
  667. "Offset %d already allocated timer %d\n",
  668. offset, gpio->offset_timer[offset]))
  669. return -EINVAL;
  670. if (WARN(gpio->timer_users[timer] == UINT_MAX,
  671. "Timer user count would overflow\n"))
  672. return -EPERM;
  673. gpio->offset_timer[offset] = timer;
  674. gpio->timer_users[timer]++;
  675. return 0;
  676. }
  677. /* Call under gpio->lock */
  678. static int unregister_allocated_timer(struct aspeed_gpio *gpio,
  679. unsigned int offset)
  680. {
  681. if (WARN(gpio->offset_timer[offset] == 0,
  682. "No timer allocated to offset %d\n", offset))
  683. return -EINVAL;
  684. if (WARN(gpio->timer_users[gpio->offset_timer[offset]] == 0,
  685. "No users recorded for timer %d\n",
  686. gpio->offset_timer[offset]))
  687. return -EINVAL;
  688. gpio->timer_users[gpio->offset_timer[offset]]--;
  689. gpio->offset_timer[offset] = 0;
  690. return 0;
  691. }
  692. /* Call under gpio->lock */
  693. static inline bool timer_allocation_registered(struct aspeed_gpio *gpio,
  694. unsigned int offset)
  695. {
  696. return gpio->offset_timer[offset] > 0;
  697. }
  698. /* Call under gpio->lock */
  699. static void configure_timer(struct aspeed_gpio *gpio, unsigned int offset,
  700. unsigned int timer)
  701. {
  702. const struct aspeed_gpio_bank *bank = to_bank(offset);
  703. const u32 mask = GPIO_BIT(offset);
  704. void __iomem *addr;
  705. u32 val;
  706. /* Note: Debounce timer isn't under control of the command
  707. * source registers, so no need to sync with the coprocessor
  708. */
  709. addr = bank_reg(gpio, bank, reg_debounce_sel1);
  710. val = ioread32(addr);
  711. iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE1(timer, offset), addr);
  712. addr = bank_reg(gpio, bank, reg_debounce_sel2);
  713. val = ioread32(addr);
  714. iowrite32((val & ~mask) | GPIO_SET_DEBOUNCE2(timer, offset), addr);
  715. }
  716. static int enable_debounce(struct gpio_chip *chip, unsigned int offset,
  717. unsigned long usecs)
  718. {
  719. struct aspeed_gpio *gpio = gpiochip_get_data(chip);
  720. u32 requested_cycles;
  721. unsigned long flags;
  722. int rc;
  723. int i;
  724. if (!gpio->clk)
  725. return -EINVAL;
  726. rc = usecs_to_cycles(gpio, usecs, &requested_cycles);
  727. if (rc < 0) {
  728. dev_warn(chip->parent, "Failed to convert %luus to cycles at %luHz: %d\n",
  729. usecs, clk_get_rate(gpio->clk), rc);
  730. return rc;
  731. }
  732. spin_lock_irqsave(&gpio->lock, flags);
  733. if (timer_allocation_registered(gpio, offset)) {
  734. rc = unregister_allocated_timer(gpio, offset);
  735. if (rc < 0)
  736. goto out;
  737. }
  738. /* Try to find a timer already configured for the debounce period */
  739. for (i = 1; i < ARRAY_SIZE(debounce_timers); i++) {
  740. u32 cycles;
  741. cycles = ioread32(gpio->base + debounce_timers[i]);
  742. if (requested_cycles == cycles)
  743. break;
  744. }
  745. if (i == ARRAY_SIZE(debounce_timers)) {
  746. int j;
  747. /*
  748. * As there are no timers configured for the requested debounce
  749. * period, find an unused timer instead
  750. */
  751. for (j = 1; j < ARRAY_SIZE(gpio->timer_users); j++) {
  752. if (gpio->timer_users[j] == 0)
  753. break;
  754. }
  755. if (j == ARRAY_SIZE(gpio->timer_users)) {
  756. dev_warn(chip->parent,
  757. "Debounce timers exhausted, cannot debounce for period %luus\n",
  758. usecs);
  759. rc = -EPERM;
  760. /*
  761. * We already adjusted the accounting to remove @offset
  762. * as a user of its previous timer, so also configure
  763. * the hardware so @offset has timers disabled for
  764. * consistency.
  765. */
  766. configure_timer(gpio, offset, 0);
  767. goto out;
  768. }
  769. i = j;
  770. iowrite32(requested_cycles, gpio->base + debounce_timers[i]);
  771. }
  772. if (WARN(i == 0, "Cannot register index of disabled timer\n")) {
  773. rc = -EINVAL;
  774. goto out;
  775. }
  776. register_allocated_timer(gpio, offset, i);
  777. configure_timer(gpio, offset, i);
  778. out:
  779. spin_unlock_irqrestore(&gpio->lock, flags);
  780. return rc;
  781. }
  782. static int disable_debounce(struct gpio_chip *chip, unsigned int offset)
  783. {
  784. struct aspeed_gpio *gpio = gpiochip_get_data(chip);
  785. unsigned long flags;
  786. int rc;
  787. spin_lock_irqsave(&gpio->lock, flags);
  788. rc = unregister_allocated_timer(gpio, offset);
  789. if (!rc)
  790. configure_timer(gpio, offset, 0);
  791. spin_unlock_irqrestore(&gpio->lock, flags);
  792. return rc;
  793. }
  794. static int set_debounce(struct gpio_chip *chip, unsigned int offset,
  795. unsigned long usecs)
  796. {
  797. struct aspeed_gpio *gpio = gpiochip_get_data(chip);
  798. if (!have_debounce(gpio, offset))
  799. return -ENOTSUPP;
  800. if (usecs)
  801. return enable_debounce(chip, offset, usecs);
  802. return disable_debounce(chip, offset);
  803. }
  804. static int aspeed_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
  805. unsigned long config)
  806. {
  807. unsigned long param = pinconf_to_config_param(config);
  808. u32 arg = pinconf_to_config_argument(config);
  809. if (param == PIN_CONFIG_INPUT_DEBOUNCE)
  810. return set_debounce(chip, offset, arg);
  811. else if (param == PIN_CONFIG_BIAS_DISABLE ||
  812. param == PIN_CONFIG_BIAS_PULL_DOWN ||
  813. param == PIN_CONFIG_DRIVE_STRENGTH)
  814. return pinctrl_gpio_set_config(offset, config);
  815. else if (param == PIN_CONFIG_DRIVE_OPEN_DRAIN ||
  816. param == PIN_CONFIG_DRIVE_OPEN_SOURCE)
  817. /* Return -ENOTSUPP to trigger emulation, as per datasheet */
  818. return -ENOTSUPP;
  819. else if (param == PIN_CONFIG_PERSIST_STATE)
  820. return aspeed_gpio_reset_tolerance(chip, offset, arg);
  821. return -ENOTSUPP;
  822. }
  823. /**
  824. * aspeed_gpio_copro_set_ops - Sets the callbacks used for handhsaking with
  825. * the coprocessor for shared GPIO banks
  826. * @ops: The callbacks
  827. * @data: Pointer passed back to the callbacks
  828. */
  829. int aspeed_gpio_copro_set_ops(const struct aspeed_gpio_copro_ops *ops, void *data)
  830. {
  831. copro_data = data;
  832. copro_ops = ops;
  833. return 0;
  834. }
  835. EXPORT_SYMBOL_GPL(aspeed_gpio_copro_set_ops);
  836. /**
  837. * aspeed_gpio_copro_grab_gpio - Mark a GPIO used by the coprocessor. The entire
  838. * bank gets marked and any access from the ARM will
  839. * result in handshaking via callbacks.
  840. * @desc: The GPIO to be marked
  841. * @vreg_offset: If non-NULL, returns the value register offset in the GPIO space
  842. * @dreg_offset: If non-NULL, returns the data latch register offset in the GPIO space
  843. * @bit: If non-NULL, returns the bit number of the GPIO in the registers
  844. */
  845. int aspeed_gpio_copro_grab_gpio(struct gpio_desc *desc,
  846. u16 *vreg_offset, u16 *dreg_offset, u8 *bit)
  847. {
  848. struct gpio_chip *chip = gpiod_to_chip(desc);
  849. struct aspeed_gpio *gpio = gpiochip_get_data(chip);
  850. int rc = 0, bindex, offset = gpio_chip_hwgpio(desc);
  851. const struct aspeed_gpio_bank *bank = to_bank(offset);
  852. unsigned long flags;
  853. if (!gpio->cf_copro_bankmap)
  854. gpio->cf_copro_bankmap = kzalloc(gpio->config->nr_gpios >> 3, GFP_KERNEL);
  855. if (!gpio->cf_copro_bankmap)
  856. return -ENOMEM;
  857. if (offset < 0 || offset > gpio->config->nr_gpios)
  858. return -EINVAL;
  859. bindex = offset >> 3;
  860. spin_lock_irqsave(&gpio->lock, flags);
  861. /* Sanity check, this shouldn't happen */
  862. if (gpio->cf_copro_bankmap[bindex] == 0xff) {
  863. rc = -EIO;
  864. goto bail;
  865. }
  866. gpio->cf_copro_bankmap[bindex]++;
  867. /* Switch command source */
  868. if (gpio->cf_copro_bankmap[bindex] == 1)
  869. aspeed_gpio_change_cmd_source(gpio, bank, bindex,
  870. GPIO_CMDSRC_COLDFIRE);
  871. if (vreg_offset)
  872. *vreg_offset = bank->val_regs;
  873. if (dreg_offset)
  874. *dreg_offset = bank->rdata_reg;
  875. if (bit)
  876. *bit = GPIO_OFFSET(offset);
  877. bail:
  878. spin_unlock_irqrestore(&gpio->lock, flags);
  879. return rc;
  880. }
  881. EXPORT_SYMBOL_GPL(aspeed_gpio_copro_grab_gpio);
  882. /**
  883. * aspeed_gpio_copro_release_gpio - Unmark a GPIO used by the coprocessor.
  884. * @desc: The GPIO to be marked
  885. */
  886. int aspeed_gpio_copro_release_gpio(struct gpio_desc *desc)
  887. {
  888. struct gpio_chip *chip = gpiod_to_chip(desc);
  889. struct aspeed_gpio *gpio = gpiochip_get_data(chip);
  890. int rc = 0, bindex, offset = gpio_chip_hwgpio(desc);
  891. const struct aspeed_gpio_bank *bank = to_bank(offset);
  892. unsigned long flags;
  893. if (!gpio->cf_copro_bankmap)
  894. return -ENXIO;
  895. if (offset < 0 || offset > gpio->config->nr_gpios)
  896. return -EINVAL;
  897. bindex = offset >> 3;
  898. spin_lock_irqsave(&gpio->lock, flags);
  899. /* Sanity check, this shouldn't happen */
  900. if (gpio->cf_copro_bankmap[bindex] == 0) {
  901. rc = -EIO;
  902. goto bail;
  903. }
  904. gpio->cf_copro_bankmap[bindex]--;
  905. /* Switch command source */
  906. if (gpio->cf_copro_bankmap[bindex] == 0)
  907. aspeed_gpio_change_cmd_source(gpio, bank, bindex,
  908. GPIO_CMDSRC_ARM);
  909. bail:
  910. spin_unlock_irqrestore(&gpio->lock, flags);
  911. return rc;
  912. }
  913. EXPORT_SYMBOL_GPL(aspeed_gpio_copro_release_gpio);
  914. /*
  915. * Any banks not specified in a struct aspeed_bank_props array are assumed to
  916. * have the properties:
  917. *
  918. * { .input = 0xffffffff, .output = 0xffffffff }
  919. */
  920. static const struct aspeed_bank_props ast2400_bank_props[] = {
  921. /* input output */
  922. { 5, 0xffffffff, 0x0000ffff }, /* U/V/W/X */
  923. { 6, 0x0000000f, 0x0fffff0f }, /* Y/Z/AA/AB, two 4-GPIO holes */
  924. { },
  925. };
  926. static const struct aspeed_gpio_config ast2400_config =
  927. /* 220 for simplicity, really 216 with two 4-GPIO holes, four at end */
  928. { .nr_gpios = 220, .props = ast2400_bank_props, };
  929. static const struct aspeed_bank_props ast2500_bank_props[] = {
  930. /* input output */
  931. { 5, 0xffffffff, 0x0000ffff }, /* U/V/W/X */
  932. { 6, 0x0fffffff, 0x0fffffff }, /* Y/Z/AA/AB, 4-GPIO hole */
  933. { 7, 0x000000ff, 0x000000ff }, /* AC */
  934. { },
  935. };
  936. static const struct aspeed_gpio_config ast2500_config =
  937. /* 232 for simplicity, actual number is 228 (4-GPIO hole in GPIOAB) */
  938. { .nr_gpios = 232, .props = ast2500_bank_props, };
  939. static const struct of_device_id aspeed_gpio_of_table[] = {
  940. { .compatible = "aspeed,ast2400-gpio", .data = &ast2400_config, },
  941. { .compatible = "aspeed,ast2500-gpio", .data = &ast2500_config, },
  942. {}
  943. };
  944. MODULE_DEVICE_TABLE(of, aspeed_gpio_of_table);
  945. static int __init aspeed_gpio_probe(struct platform_device *pdev)
  946. {
  947. const struct of_device_id *gpio_id;
  948. struct aspeed_gpio *gpio;
  949. struct resource *res;
  950. int rc, i, banks;
  951. gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
  952. if (!gpio)
  953. return -ENOMEM;
  954. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  955. gpio->base = devm_ioremap_resource(&pdev->dev, res);
  956. if (IS_ERR(gpio->base))
  957. return PTR_ERR(gpio->base);
  958. spin_lock_init(&gpio->lock);
  959. gpio_id = of_match_node(aspeed_gpio_of_table, pdev->dev.of_node);
  960. if (!gpio_id)
  961. return -EINVAL;
  962. gpio->clk = of_clk_get(pdev->dev.of_node, 0);
  963. if (IS_ERR(gpio->clk)) {
  964. dev_warn(&pdev->dev,
  965. "Failed to get clock from devicetree, debouncing disabled\n");
  966. gpio->clk = NULL;
  967. }
  968. gpio->config = gpio_id->data;
  969. gpio->chip.parent = &pdev->dev;
  970. gpio->chip.ngpio = gpio->config->nr_gpios;
  971. gpio->chip.parent = &pdev->dev;
  972. gpio->chip.direction_input = aspeed_gpio_dir_in;
  973. gpio->chip.direction_output = aspeed_gpio_dir_out;
  974. gpio->chip.get_direction = aspeed_gpio_get_direction;
  975. gpio->chip.request = aspeed_gpio_request;
  976. gpio->chip.free = aspeed_gpio_free;
  977. gpio->chip.get = aspeed_gpio_get;
  978. gpio->chip.set = aspeed_gpio_set;
  979. gpio->chip.set_config = aspeed_gpio_set_config;
  980. gpio->chip.label = dev_name(&pdev->dev);
  981. gpio->chip.base = -1;
  982. gpio->chip.irq.need_valid_mask = true;
  983. /* Allocate a cache of the output registers */
  984. banks = DIV_ROUND_UP(gpio->config->nr_gpios, 32);
  985. gpio->dcache = devm_kcalloc(&pdev->dev,
  986. banks, sizeof(u32), GFP_KERNEL);
  987. if (!gpio->dcache)
  988. return -ENOMEM;
  989. /*
  990. * Populate it with initial values read from the HW and switch
  991. * all command sources to the ARM by default
  992. */
  993. for (i = 0; i < banks; i++) {
  994. const struct aspeed_gpio_bank *bank = &aspeed_gpio_banks[i];
  995. void __iomem *addr = bank_reg(gpio, bank, reg_rdata);
  996. gpio->dcache[i] = ioread32(addr);
  997. aspeed_gpio_change_cmd_source(gpio, bank, 0, GPIO_CMDSRC_ARM);
  998. aspeed_gpio_change_cmd_source(gpio, bank, 1, GPIO_CMDSRC_ARM);
  999. aspeed_gpio_change_cmd_source(gpio, bank, 2, GPIO_CMDSRC_ARM);
  1000. aspeed_gpio_change_cmd_source(gpio, bank, 3, GPIO_CMDSRC_ARM);
  1001. }
  1002. rc = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio);
  1003. if (rc < 0)
  1004. return rc;
  1005. gpio->offset_timer =
  1006. devm_kzalloc(&pdev->dev, gpio->chip.ngpio, GFP_KERNEL);
  1007. if (!gpio->offset_timer)
  1008. return -ENOMEM;
  1009. return aspeed_gpio_setup_irqs(gpio, pdev);
  1010. }
  1011. static struct platform_driver aspeed_gpio_driver = {
  1012. .driver = {
  1013. .name = KBUILD_MODNAME,
  1014. .of_match_table = aspeed_gpio_of_table,
  1015. },
  1016. };
  1017. module_platform_driver_probe(aspeed_gpio_driver, aspeed_gpio_probe);
  1018. MODULE_DESCRIPTION("Aspeed GPIO Driver");
  1019. MODULE_LICENSE("GPL");